Class: ConstructionLayerZeroMaterialProperties

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
# File 'lib/measures/ConstructionLayerZeroMaterialProperties/measure.rb', line 24

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

  # populate choice argument for constructions that are applied to surfaces in the model
  construction_handles = OpenStudio::StringVector.new
  construction_display_names = OpenStudio::StringVector.new

  # putting space types and names into hash
  construction_args = model.getConstructions
  construction_args_hash = {}
  construction_args.each do |construction_arg|
    construction_args_hash[construction_arg.name.to_s] = construction_arg
  end

  # looping through sorted hash of constructions
  construction_args_hash.sort.map do |key, value|
    # only include if construction is used on surface
    if value.getNetArea > 0
      construction_handles << value.handle.to_s
      construction_display_names << key
    end
  end

  # make an argument for construction
  construction = OpenStudio::Measure::OSArgument.makeChoiceArgument('construction', construction_handles, construction_display_names, true)
  construction.setDisplayName('Choose a Construction to Alter.')
  args << construction

  # make an argument thickness
  thickness = OpenStudio::Measure::OSArgument.makeDoubleArgument('thickness', true)
  thickness.setDisplayName('Thickness of Layer 0')
  thickness.setDescription('Set Thickness of Layer 0. 0 value means do not change from default.')
  thickness.setDefaultValue(0)
  thickness.setUnits('m')
  args << thickness

  # make an argument density
  density = OpenStudio::Measure::OSArgument.makeDoubleArgument('density', true)
  density.setDisplayName('Density of Layer 0')
  density.setDescription('Set Density of Layer 0. 0 value means do not change from default.')
  density.setUnits('kg/m^3')
  density.setDefaultValue(0)
  args << density

  # make an argument thermal_absorptance
  thermal_absorptance = OpenStudio::Measure::OSArgument.makeDoubleArgument('thermal_absorptance', true)
  thermal_absorptance.setDisplayName('Thermal Absorptance of Layer 0')
  thermal_absorptance.setDescription('Set Thermal Absorptance of Layer 0. 0 value means do not change from default.')
  thermal_absorptance.setUnits('fraction')
  thermal_absorptance.setDefaultValue(0)
  args << thermal_absorptance

  # make an argument solar_absorptance
  solar_absorptance = OpenStudio::Measure::OSArgument.makeDoubleArgument('solar_absorptance', true)
  solar_absorptance.setDisplayName('Solar Absorptance of Layer 0')
  solar_absorptance.setDescription('Set Solar Absorptance of Layer 0. 0 value means do not change from default.')
  solar_absorptance.setUnits('fraction')
  solar_absorptance.setDefaultValue(0)
  args << solar_absorptance

  # make an argument visible_absorptance
  visible_absorptance = OpenStudio::Measure::OSArgument.makeDoubleArgument('visible_absorptance', true)
  visible_absorptance.setDisplayName('Visible Absorptance of Layer 0')
  visible_absorptance.setDescription('Set Visible Absorptance of Layer 0. 0 value means do not change from default.')
  visible_absorptance.setUnits('fraction')
  visible_absorptance.setDefaultValue(0)
  args << visible_absorptance

  # make an argument conductivity
  thermal_conductivity = OpenStudio::Measure::OSArgument.makeDoubleArgument('thermal_conductivity', true)
  thermal_conductivity.setDisplayName('Thermal Conductivity of Layer 0')
  thermal_conductivity.setDescription('Set Thermal Conductivity of Layer 0. 0 value means do not change from default.')
  thermal_conductivity.setDefaultValue(0)
  thermal_conductivity.setUnits('W/(m*K)')
  args << thermal_conductivity

  # make an argument specific_heat
  specific_heat = OpenStudio::Measure::OSArgument.makeDoubleArgument('specific_heat', true)
  specific_heat.setDisplayName('Specific Heat of Layer 0')
  specific_heat.setDescription('Set Specific Heat of Layer 0. 0 value means do not change from default.')
  specific_heat.setUnits('J/(kg*K)')
  specific_heat.setDefaultValue(0)
  args << specific_heat

  args
end

#descriptionObject

human readable description


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

def description
  'This measure changes properties of Layer 0 for a specific construction.'
end

#modeler_descriptionObject

human readable description of modeling approach


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

def modeler_description
  'This measure changes the Layer 0 properties of Thickness, Density, Thermal Absorptance, Solar Absorptance, Visible Absoptance, Thermal Conductivity, Specific Heat.'
end

#nameObject

define the name that a user will see


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

def name
  'Change Parameters Of Material (Layer 0 of Construction)'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run


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
# File 'lib/measures/ConstructionLayerZeroMaterialProperties/measure.rb', line 112

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
  construction = runner.getOptionalWorkspaceObjectChoiceValue('construction', user_arguments, model) # model is passed in because of argument type
  thermal_absorptance = runner.getDoubleArgumentValue('thermal_absorptance', user_arguments)
  solar_absorptance = runner.getDoubleArgumentValue('solar_absorptance', user_arguments)
  visible_absorptance = runner.getDoubleArgumentValue('visible_absorptance', user_arguments)
  thermal_conductivity = runner.getDoubleArgumentValue('thermal_conductivity', user_arguments)
  specific_heat = runner.getDoubleArgumentValue('specific_heat', user_arguments)
  thickness = runner.getDoubleArgumentValue('thickness', user_arguments)
  density = runner.getDoubleArgumentValue('density', user_arguments)

  # check the construction for reasonableness
  if construction.empty?
    handle = runner.getStringArgumentValue('construction', user_arguments)
    if handle.empty?
      runner.registerError('No construction was chosen.')
    else
      runner.registerError("The selected construction with handle '#{handle}' was not found in the model. It may have been removed by another measure.")
    end
    return false
  else
    if !construction.get.to_Construction.empty?
      construction = construction.get.to_Construction.get
    else
      runner.registerError('Script Error - argument not showing up as construction.')
      return false
    end
  end

  initial_r_value_ip = OpenStudio.convert(1.0 / construction.thermalConductance.to_f, 'm^2*K/W', 'ft^2*h*R/Btu')
  runner.registerInitialCondition("The Initial R-value of #{construction.name} is #{initial_r_value_ip} (ft^2*h*R/Btu).")
  runner.registerValue('initial_r_value_ip', initial_r_value_ip.to_f, 'ft^2*h*R/Btu')
  # get layers
  layers = construction.layers

  # steel layer is always first layer
  layer = layers[0].to_StandardOpaqueMaterial.get
  runner.registerInfo("Initial thermal_absorptance: #{layer.thermalAbsorptance}")
  runner.registerInfo("Initial solar_absorptance: #{layer.solarAbsorptance}")
  runner.registerInfo("Initial visible_absorptance: #{layer.visibleAbsorptance}")
  runner.registerInfo("Initial thermal_conductivity: #{layer.thermalConductivity}")
  runner.registerInfo("Initial specific_heat: #{layer.specificHeat}")
  runner.registerInfo("Initial thickness: #{layer.thickness}")
  runner.registerInfo("Initial density: #{layer.density}")

  # set layer properties
  layer.setThermalAbsorptance(thermal_absorptance) if thermal_absorptance != 0
  layer.setSolarAbsorptance(solar_absorptance) if solar_absorptance != 0
  layer.setVisibleAbsorptance(visible_absorptance) if visible_absorptance != 0
  layer.setThermalConductivity(thermal_conductivity) if thermal_conductivity != 0
  layer.setSpecificHeat(specific_heat) if specific_heat != 0
  layer.setThickness(thickness) if thickness != 0
  layer.setDensity(density) if density != 0

  runner.registerInfo("Final thermal_absorptance: #{layer.thermalAbsorptance}")
  runner.registerInfo("Final solar_absorptance: #{layer.solarAbsorptance}")
  runner.registerInfo("Final visible_absorptance: #{layer.visibleAbsorptance}")
  runner.registerInfo("Final thermal_conductivity: #{layer.thermalConductivity}")
  runner.registerInfo("Final specific_heat: #{layer.specificHeat}")
  runner.registerInfo("Final thickness: #{layer.thickness}")
  runner.registerInfo("Final density: #{layer.density}")

  # report initial condition
  final_r_value_ip = OpenStudio.convert(1 / construction.thermalConductance.to_f, 'm^2*K/W', 'ft^2*h*R/Btu')
  runner.registerFinalCondition("The Final R-value of #{construction.name} is #{final_r_value_ip} (ft^2*h*R/Btu).")
  runner.registerValue('final_r_value_ip', final_r_value_ip.to_f, 'ft^2*h*R/Btu')

  true
end