Class: ExteriorWallThermalPropertiesPercentChange

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(_model) ⇒ Object

define the arguments that the user will input



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/measures/ExteriorWallThermalPropertiesPercentChange/measure.rb', line 41

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

  # make an argument insulation R-value
  r_value_perc_change = OpenStudio::Measure::OSArgument.makeDoubleArgument('r_value_perc_change', true)
  r_value_perc_change.setDisplayName('Exterior wall total R-value Percentage Change')
  r_value_perc_change.setDefaultValue(0)
  args << r_value_perc_change

  solar_abs_perc_change = OpenStudio::Measure::OSArgument.makeDoubleArgument('solar_abs_perc_change', true)
  solar_abs_perc_change.setDisplayName('Exterior wall solar absorptance Percentage Change')
  solar_abs_perc_change.setDefaultValue(0)
  args << solar_abs_perc_change

  thermal_mass_perc_change = OpenStudio::Measure::OSArgument.makeDoubleArgument('thermal_mass_perc_change', true)
  thermal_mass_perc_change.setDisplayName('Exterior wall thermal mass Percentage Change')
  thermal_mass_perc_change.setDefaultValue(0)
  args << thermal_mass_perc_change

  args
end

#descriptionObject

human readable description



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

def description
  'Change exterior walls by altering the thermal resistance, density, and solar absorptance of the wall constructions by a Percent Change'
end

#modeler_descriptionObject

human readable description of modeling approach



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

def modeler_description
  'Change exterior walls by altering the thermal resistance, density, and solar absorptance of the wall constructions by a Percent Change'
end

#nameObject

define the name that a user will see



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

def name
  'Exterior Wall Thermal Percent Change'
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/ExteriorWallThermalPropertiesPercentChange/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



64
65
66
67
68
69
70
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
# File 'lib/measures/ExteriorWallThermalPropertiesPercentChange/measure.rb', line 64

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_perc_change = runner.getDoubleArgumentValue('r_value_perc_change', user_arguments)
  solar_abs_perc_change = runner.getDoubleArgumentValue('solar_abs_perc_change', user_arguments)
  thermal_mass_perc_change = runner.getDoubleArgumentValue('thermal_mass_perc_change', user_arguments)

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

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

  # nothing will be done if there are no exterior surfaces
  if exterior_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: '
  exterior_surface_construction_numbers = []
  exterior_surface_constructions.each_with_index do |construction, index|
    exterior_surface_construction_numbers[index] = 0
    initial_condition_string << "'#{construction.name}': "
    exterior_surfaces.each do |surface|
      exterior_surface_construction_numbers[index] += 1 if surface.construction.get.handle.to_s == construction.handle.to_s
    end
    initial_condition_string << "#{exterior_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 = []
  exterior_surface_constructions.each_with_index do |_construction, con_index|
    initial_layers[con_index] = exterior_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] + initial_r_val[index1][index2] * r_value_perc_change * 0.01 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] + initial_sol_abs[index1] * solar_abs_perc_change * 0.01
    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]}. A Percent Change of #{solar_abs_perc_change} 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]}. A Percent Change of #{solar_abs_perc_change} 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] + initial_thm_mass[index1][index2] * thermal_mass_perc_change * 0.01 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
  exterior_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_perc_change.round(1)} Solar #{solar_abs_perc_change.round(1)} Therm #{thermal_mass_perc_change.round(1)} Percent Change)")
    # 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_perc_change.round(1)} Solar #{solar_abs_perc_change.round(1)} Therm #{thermal_mass_perc_change.round(1)} Percent Change)")
      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]) / initial_r_val[con_index][lay_index] * 100).round(2)} percent change)") : 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]) / initial_thm_mass[con_index][lay_index] * 100).round(2)} percent change)") : 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]) / initial_sol_abs[con_index] * 100).round(2)} percent change)") : 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
    exterior_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_perc_change.round(1)} Solar #{solar_abs_perc_change.round(1)} Therm #{thermal_mass_perc_change.round(1)} Percent 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/ExteriorWallThermalPropertiesPercentChange/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