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
-
#children_heat_loss_recursive(inside_temperature, outside_temperature, res) ⇒ Array<Hash>
Appends the children's heat loss recursively, excluding this object itself.
-
#get_children_heat_loss(inside_temperature, outside_temperature) ⇒ Numeric
Combined heat loss of all heat loss children (and their own children).
-
#get_heat_loss(inside_temperature, outside_temperature) ⇒ Numeric
Heat loss of this object alone, excluding the area covered by its children.
-
#get_self_and_children_heat_loss(inside_temperature, outside_temperature) ⇒ Numeric
Combined heat loss of this object and all its heat loss children.
-
#get_u_value ⇒ Numeric?
Effective U-value: the user-supplied value, falling back to the insulation type's.
-
#heat_loss_children ⇒ Array
Direct heat loss children of this object.
-
#heat_loss_children_recursive(res) ⇒ Array
Collects this object's heat loss children recursively.
-
#insulation_type ⇒ Object?
Insulation type record for this object, resolved from the model name.
-
#reset_room_last_heat_loss ⇒ true
Clears the cached last heat loss on the associated room configuration.
-
#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.
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.
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).
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.
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.
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_value ⇒ Numeric?
Effective U-value: the user-supplied value, falling back to the insulation type's.
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_children ⇒ Array
Direct heat loss children of this object. Overridden by including models.
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.
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_type ⇒ Object?
Insulation type record for this object, resolved from the model name.
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_loss ⇒ true
Clears the cached last heat loss on the associated room configuration.
Runs after save and before destroy on non-RoomConfiguration includers.
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.
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 |