Module: Models::HeatLossable

Extended by:
ActiveSupport::Concern
Includes:
HeatLossableConstants
Included in:
Ceiling, Door, ExteriorWall, RoomConfiguration, Skylight, UnderFloor, Window
Defined in:
app/concerns/models/heat_lossable.rb

Overview

ActiveSupport::Concern mixin: heat lossable.

Constant Summary

Constants included from HeatLossableConstants

HeatLossableConstants::BTU_PER_HOUR_PER_WATT, HeatLossableConstants::HIGH_U_VALUE_THRESHOLD, HeatLossableConstants::HLC_PRIMARY_OK_THRESHOLD, HeatLossableConstants::INFILTRATION_AREA_FACTORS, HeatLossableConstants::INFILTRATION_FIREPLACE_FACTORS, HeatLossableConstants::INFILTRATION_SEALING_FACTORS, HeatLossableConstants::PIE_CHART_FLAG_COLORS, HeatLossableConstants::PIE_CHART_OK_COLORS

Instance Method Summary collapse

Instance Method Details

#children_heat_loss_recursive(inside_temperature, outside_temperature, res) ⇒ Array<Hash>

Appends the children's heat loss recursively, excluding this object itself.

Parameters:

  • inside_temperature (Numeric)

    inside temperature used for the calculation

  • outside_temperature (Numeric)

    outside temperature used for the calculation

  • res (Array<Hash>)

    accumulator of { object:, heat_loss: } entries

Returns:

  • (Array<Hash>)

    the accumulator with entries for all children



46
47
48
49
50
51
# File 'app/concerns/models/heat_lossable.rb', line 46

def children_heat_loss_recursive(inside_temperature, outside_temperature, res)
  heat_loss_children.each do |c|
    res = c.self_and_children_heat_loss_recursive(inside_temperature, outside_temperature, res)
  end
  res
end

#get_children_heat_loss(inside_temperature, outside_temperature) ⇒ Numeric

Combined heat loss of all heat loss children (and their own children).

Parameters:

  • inside_temperature (Numeric)

    inside temperature used for the calculation

  • outside_temperature (Numeric)

    outside temperature used for the calculation

Returns:

  • (Numeric)

    total heat loss across the whole children subtree



58
59
60
# File 'app/concerns/models/heat_lossable.rb', line 58

def get_children_heat_loss(inside_temperature, outside_temperature)
  heat_loss_children.to_a.sum { |c| c.get_self_and_children_heat_loss(inside_temperature, outside_temperature) }
end

#get_heat_loss(inside_temperature, outside_temperature) ⇒ Numeric

Heat loss of this object alone, excluding the area covered by its children.

Parameters:

  • inside_temperature (Numeric)

    inside temperature used for the calculation

  • outside_temperature (Numeric)

    outside temperature used for the calculation

Returns:

  • (Numeric)

    heat loss for this object's effective area



86
87
88
89
# File 'app/concerns/models/heat_lossable.rb', line 86

def get_heat_loss(inside_temperature, outside_temperature)
  effective_area = area - heat_loss_children.to_a.sum(&:area)
  effective_area * (inside_temperature - outside_temperature) * get_u_value
end

#get_self_and_children_heat_loss(inside_temperature, outside_temperature) ⇒ Numeric

Combined heat loss of this object and all its heat loss children.

Parameters:

  • inside_temperature (Numeric)

    inside temperature used for the calculation

  • outside_temperature (Numeric)

    outside temperature used for the calculation

Returns:

  • (Numeric)

    total heat loss for this object and its children



22
23
24
# File 'app/concerns/models/heat_lossable.rb', line 22

def get_self_and_children_heat_loss(inside_temperature, outside_temperature)
  get_heat_loss(inside_temperature, outside_temperature) + get_children_heat_loss(inside_temperature, outside_temperature)
end

#get_u_valueNumeric?

Effective U-value: the user-supplied value, falling back to the insulation type's.

Returns:

  • (Numeric, nil)

    the U-value to use in heat loss calculations



94
95
96
# File 'app/concerns/models/heat_lossable.rb', line 94

def get_u_value
  user_u_value || insulation_type&.u_value
end

#heat_loss_childrenArray

Direct heat loss children of this object. Overridden by including models.

Returns:

  • (Array)

    list of child objects that contribute heat loss



65
66
67
# File 'app/concerns/models/heat_lossable.rb', line 65

def heat_loss_children
  []
end

#heat_loss_children_recursive(res) ⇒ Array

Collects this object's heat loss children recursively.

Parameters:

  • res (Array)

    accumulator of heat loss child objects

Returns:

  • (Array)

    the accumulator with all descendant children added



73
74
75
76
77
78
79
# File 'app/concerns/models/heat_lossable.rb', line 73

def heat_loss_children_recursive(res)
  res += heat_loss_children
  heat_loss_children.each do |c|
    res = c.heat_loss_children_recursive(res)
  end
  res
end

#insulation_typeObject?

Insulation type record for this object, resolved from the model name.

Returns:

  • (Object, nil)

    the associated insulation type



101
102
103
# File 'app/concerns/models/heat_lossable.rb', line 101

def insulation_type
  send("#{self.class.to_s.tableize.singularize}_insulation_type")
end

#reset_room_last_heat_losstrue

Clears the cached last heat loss on the associated room configuration.
Runs after save and before destroy on non-RoomConfiguration includers.

Returns:

  • (true)

    always true so callbacks are not halted



109
110
111
112
113
114
# File 'app/concerns/models/heat_lossable.rb', line 109

def reset_room_last_heat_loss
  logger.info "reset_room_last_heat_loss: self.class.to_s: #{self.class}"
  logger.info "reset_room_last_heat_loss: self.class.to_s != 'RoomConfiguration': #{self.class.to_s != 'RoomConfiguration'}"
  room_configuration.update_column(:last_heat_loss, nil)
  true
end

#self_and_children_heat_loss_recursive(inside_temperature, outside_temperature, res) ⇒ Array<Hash>

Appends this object's heat loss and its children's heat loss recursively.

Parameters:

  • inside_temperature (Numeric)

    inside temperature used for the calculation

  • outside_temperature (Numeric)

    outside temperature used for the calculation

  • res (Array<Hash>)

    accumulator of { object:, heat_loss: } entries

Returns:

  • (Array<Hash>)

    the accumulator with entries for this object and its children



32
33
34
35
36
37
38
# File 'app/concerns/models/heat_lossable.rb', line 32

def self_and_children_heat_loss_recursive(inside_temperature, outside_temperature, res)
  res << { object: self, heat_loss: get_heat_loss(inside_temperature, outside_temperature) }
  heat_loss_children.each do |c|
    res = c.self_and_children_heat_loss_recursive(inside_temperature, outside_temperature, res)
  end
  res
end