Class: RoofThermalPropertiesMultiplier

Inherits:
OpenStudio::Measure::ModelMeasure
  • Object
show all
Defined in:
lib/measures/RoofThermalPropertiesMultiplier/measure.rb

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(_model) ⇒ Object

define the arguments that the user will input



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 48

def arguments(_model)
  args = OpenStudio::Measure::OSArgumentVector.new

  # make an argument insulation R-value
  r_value_mult = OpenStudio::Measure::OSArgument.makeDoubleArgument('r_value_mult', true)
  r_value_mult.setDisplayName('Roof total R-value multiplier')
  r_value_mult.setDefaultValue(1)
  args << r_value_mult

  solar_abs_mult = OpenStudio::Measure::OSArgument.makeDoubleArgument('solar_abs_mult', true)
  solar_abs_mult.setDisplayName('Roof solar absorptance multiplier')
  solar_abs_mult.setDefaultValue(1)
  args << solar_abs_mult

  thermal_mass_mult = OpenStudio::Measure::OSArgument.makeDoubleArgument('thermal_mass_mult', true)
  thermal_mass_mult.setDisplayName('Roof thermal mass multiplier')
  thermal_mass_mult.setDefaultValue(1)
  args << thermal_mass_mult

  args
end

#check_multiplier(runner, multiplier) ⇒ Object



40
41
42
43
44
45
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 40

def check_multiplier(runner, multiplier)
  if multiplier < 0
    runner.registerError("Multiplier #{multiplier} cannot be negative.")
    false
  end
end

#descriptionObject

human readable description



14
15
16
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 14

def description
  'Change Roof by altering the thermal resistance, density, and solar absorptance of the wall constructions by a Multiplier'
end

#modeler_descriptionObject

human readable description of modeling approach



19
20
21
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 19

def modeler_description
  'Change Roof by altering the thermal resistance, density, and solar absorptance of the wall constructions by a Multiplier'
end

#nameObject

define the name that a user will see



9
10
11
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 9

def name
  'Roof Thermal Properties Multiplier'
end

#neat_numbers(number, roundto = 2) ⇒ Object

short def to make numbers pretty (converts 4125001.25641 to 4,125,001.26 or 4,125,001). The definition be called through this measure round to 0 or 2)



25
26
27
28
29
30
31
32
33
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 25

def neat_numbers(number, roundto = 2)
  number = if roundto == 2
             format '%.2f', number
           else
             number.round
           end
  # regex to add commas
  number.to_s.reverse.gsub(/([0-9]{3}(?=([0-9])))/, '\\1,').reverse
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 71

def run(model, runner, user_arguments)
  super(model, runner, user_arguments)

  # use the built-in error checking
  unless runner.validateUserArguments(arguments(model), user_arguments)
    return false
  end

  # assign the user inputs to variables
  r_value_mult = runner.getDoubleArgumentValue('r_value_mult', user_arguments)
  check_multiplier(runner, r_value_mult)
  solar_abs_mult = runner.getDoubleArgumentValue('solar_abs_mult', user_arguments)
  check_multiplier(runner, solar_abs_mult)
  thermal_mass_mult = runner.getDoubleArgumentValue('thermal_mass_mult', user_arguments)
  check_multiplier(runner, thermal_mass_mult)

  # create an array of exterior surfaces and construction types
  surfaces = model.getSurfaces
  roof_surfaces = []
  roof_surface_constructions = []
  surfaces.each do |surface|
    next unless surface.outsideBoundaryCondition == 'Outdoors' && surface.surfaceType == 'RoofCeiling'

    roof_surfaces << surface
    roof_surface_const = surface.construction.get
    # only add construction if it hasn't been added yet
    unless roof_surface_constructions.include?(roof_surface_const)
      roof_surface_constructions << roof_surface_const.to_Construction.get
    end
  end

  # nothing will be done if there are no exterior surfaces
  if roof_surfaces.empty?
    runner.registerAsNotApplicable('Model does not have any exterior walls.')
    return true
  end

  # get initial number of surfaces having each construction type
  initial_condition_string = 'Initial number of surfaces of each construction type: '
  roof_surface_construction_numbers = []
  roof_surface_constructions.each_with_index do |construction, index|
    roof_surface_construction_numbers[index] = 0
    initial_condition_string << "'#{construction.name}': "
    roof_surfaces.each do |surface|
      roof_surface_construction_numbers[index] += 1 if surface.construction.get.handle.to_s == construction.handle.to_s
    end
    initial_condition_string << "#{roof_surface_construction_numbers[index]}, "
  end

  runner.registerInitialCondition(initial_condition_string)

  # get initial sets of construction layers and desired values
  initial_layers = []
  initial_r_val = []
  initial_sol_abs = []
  initial_thm_mass = []
  initial_r_val_d = []
  initial_sol_abs_d = []
  initial_thm_mass_d = []
  roof_surface_constructions.each_with_index do |_construction, con_index|
    initial_layers[con_index] = roof_surface_constructions[con_index].layers
    initial_sol_abs[con_index] = initial_layers[con_index][0].to_StandardOpaqueMaterial.get.solarAbsorptance
    initial_r_val[con_index] = []
    initial_thm_mass[con_index] = []
    initial_sol_abs_d[con_index] = neat_numbers(initial_layers[con_index][0].to_StandardOpaqueMaterial.get.solarAbsorptance)
    initial_r_val_d[con_index] = []
    initial_thm_mass_d[con_index] = []
    initial_layers[con_index].each_with_index do |layer, lay_index|
      initial_r_val[con_index][lay_index] = initial_layers[con_index][lay_index].to_OpaqueMaterial.get.thermalResistance
      initial_thm_mass[con_index][lay_index] = initial_layers[con_index][lay_index].to_StandardOpaqueMaterial.get.density if layer.to_StandardOpaqueMaterial.is_initialized
      initial_r_val_d[con_index][lay_index] = neat_numbers(initial_layers[con_index][lay_index].to_OpaqueMaterial.get.thermalResistance) if layer.to_OpaqueMaterial.is_initialized
      initial_thm_mass_d[con_index][lay_index] = neat_numbers(initial_layers[con_index][lay_index].to_StandardOpaqueMaterial.get.density) if layer.to_StandardOpaqueMaterial.is_initialized
    end
  end
  initial_r_val_units = 'm^2*K/W'
  initial_thm_mass_units = 'kg/m3'

  # calculate desired values for each construction and layer
  desired_r_val = []
  desired_sol_abs = []
  desired_thm_mass = []
  initial_r_val.each_index do |index1|
    desired_r_val[index1] = []
    initial_r_val[index1].each_index do |index2|
      desired_r_val[index1][index2] = initial_r_val[index1][index2] * r_value_mult if initial_r_val[index1][index2]
    end
  end
  initial_sol_abs.each_index do |index1|
    next unless initial_sol_abs[index1]

    desired_sol_abs[index1] = initial_sol_abs[index1] * solar_abs_mult
    if desired_sol_abs[index1] > 1
      desired_sol_abs[index1] = 1
      runner.registerWarning("Initial solar absorptance of '#{initial_layers[index1][0].name}' was #{initial_sol_abs[index1]}. Multiplying it by #{solar_abs_mult} results in a number greater than 1, which is outside the allowed range. The value is instead being set to #{desired_sol_abs[index1]}")
    elsif desired_sol_abs[index1] < 0
      desired_sol_abs[index1] = 0
      runner.registerWarning("Initial solar absorptance of '#{initial_layers[index1][0].name}' was #{initial_sol_abs[index1]}. Multiplying it by #{solar_abs_mult} results in a number less than 0, which is outside the allowed range. The value is instead being set to #{desired_sol_abs[index1]}")
    end
  end
  initial_thm_mass.each_index do |index1|
    desired_thm_mass[index1] = []
    initial_thm_mass[index1].each_index do |index2|
      desired_thm_mass[index1][index2] = initial_thm_mass[index1][index2] * thermal_mass_mult if initial_thm_mass[index1][index2]
    end
  end

  # initalize final values arrays
  final_construction = []
  final_r_val = []
  final_sol_abs = []
  final_thm_mass = []
  final_r_val_d = []
  final_sol_abs_d = []
  final_thm_mass_d = []
  initial_r_val.each_with_index { |_, index| final_r_val[index] = [] }
  initial_thm_mass.each_with_index { |_, index| final_thm_mass[index] = [] }
  initial_r_val_d.each_with_index { |_, index| final_r_val_d[index] = [] }
  initial_thm_mass_d.each_with_index { |_, index| final_thm_mass_d[index] = [] }

  # replace exterior surface wall constructions
  roof_surface_constructions.each_with_index do |construction, con_index|
    # create and name new construction
    new_construction = construction.clone
    new_construction = new_construction.to_Construction.get
    new_construction.setName("#{construction.name} (R #{r_value_mult.round(1)}x Solar #{solar_abs_mult.round(1)}x Therm #{thermal_mass_mult.round(1)}x)")
    # replace layers in new construction
    new_construction.layers.each_with_index do |layer, lay_index|
      new_layer = layer.clone
      new_layer = new_layer.to_Material.get
      # update thermal properties for the layer based on desired arrays
      new_layer.to_StandardOpaqueMaterial.get.setSolarAbsorptance(desired_sol_abs[con_index]) if lay_index == 0 && layer.to_StandardOpaqueMaterial.is_initialized # only apply to outer surface
      new_layer.to_OpaqueMaterial.get.setThermalResistance(desired_r_val[con_index][lay_index]) if layer.to_OpaqueMaterial.is_initialized
      new_layer.to_StandardOpaqueMaterial.get.setDensity(desired_thm_mass[con_index][lay_index]) if layer.to_StandardOpaqueMaterial.is_initialized && desired_thm_mass[con_index][lay_index] != 0
      new_layer.setName("#{layer.name} (R #{r_value_mult.round(1)}x Solar #{solar_abs_mult.round(1)}x Therm #{thermal_mass_mult.round(1)}x)")
      new_construction.setLayer(lay_index, new_layer)
      # calculate properties of new layer and output nice names
      final_r_val[con_index][lay_index] = new_construction.layers[lay_index].to_OpaqueMaterial.get.thermalResistance if layer.to_OpaqueMaterial.is_initialized
      final_sol_abs[con_index] = new_construction.layers[lay_index].to_StandardOpaqueMaterial.get.solarAbsorptance if lay_index == 0 && layer.to_StandardOpaqueMaterial.is_initialized
      final_thm_mass[con_index][lay_index] = new_construction.layers[lay_index].to_StandardOpaqueMaterial.get.density if layer.to_StandardOpaqueMaterial.is_initialized
      final_r_val_d[con_index][lay_index] = neat_numbers(final_r_val[con_index][lay_index])
      final_sol_abs_d[con_index] = neat_numbers(final_sol_abs[con_index]) if lay_index == 0 && layer.to_StandardOpaqueMaterial.is_initialized
      final_thm_mass_d[con_index][lay_index] = neat_numbers(final_thm_mass[con_index][lay_index]) if layer.to_StandardOpaqueMaterial.is_initialized
      runner.registerInfo("Updated material '#{layer.name}' in construction '#{new_construction.name}' to '#{new_layer.name}' as follows:")
      final_r_val[con_index][lay_index] ? runner.registerInfo("R-Value updated from #{initial_r_val_d[con_index][lay_index]} to #{final_r_val_d[con_index][lay_index]} (#{(final_r_val[con_index][lay_index] / initial_r_val[con_index][lay_index]).round(2)} mult)") : runner.registerInfo("R-Value was #{initial_r_val_d[con_index][lay_index]} and now is nil_value")
      final_thm_mass[con_index][lay_index] ? runner.registerInfo("Thermal Mass updated from #{initial_thm_mass_d[con_index][lay_index]} to #{final_thm_mass_d[con_index][lay_index]} (#{(final_thm_mass[con_index][lay_index] / initial_thm_mass[con_index][lay_index]).round(2)} mult)") : runner.registerInfo("Thermal Mass was #{initial_thm_mass[con_index][lay_index]} and now is nil_value")
      if lay_index == 0
        final_sol_abs[con_index] ? runner.registerInfo("Solar Absorptance updated from #{initial_sol_abs_d[con_index]} to #{final_sol_abs_d[con_index]} (#{(final_sol_abs[con_index] / initial_sol_abs[con_index]).round(2)} mult)") : runner.registerInfo("Solar Absorptance was #{initial_sol_abs[con_index][lay_index]} and now is nil_value")
      end
    end
    final_construction[con_index] = new_construction
    # update surfaces with construction = construction to new_construction
    roof_surfaces.each do |surface|
      surface.setConstruction(new_construction) if surface.construction.get.handle.to_s == construction.handle.to_s
    end
    runner.registerInfo("Using New Construction #{new_construction.name}")
  end

  # report desired condition
  runner.registerFinalCondition("Applied R #{r_value_mult.round(1)}x Solar #{solar_abs_mult.round(1)}x Therm #{thermal_mass_mult.round(1)}x change")

  true
end

#unit_helper(number, from_unit_string, to_unit_string) ⇒ Object

helper to make it easier to do unit conversions on the fly



36
37
38
# File 'lib/measures/RoofThermalPropertiesMultiplier/measure.rb', line 36

def unit_helper(number, from_unit_string, to_unit_string)
  OpenStudio.convert(OpenStudio::Quantity.new(number, OpenStudio.createUnit(from_unit_string).get), OpenStudio.createUnit(to_unit_string).get).get.value
end