Class: RValueOfInsulationForConstructionMultiplier

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



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

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 insulation R-value
  r_value_multplier = OpenStudio::Measure::OSArgument.makeDoubleArgument('r_value_multplier', true)
  r_value_multplier.setDisplayName('Multiplier for R-value for Insulation Layer of Construction.')
  r_value_multplier.setDefaultValue(1.0)
  args << r_value_multplier

  args
end

#check_multiplier(runner, multiplier) ⇒ Object



23
24
25
26
27
28
# File 'lib/measures/RValueOfInsulationForConstructionMultiplier/measure.rb', line 23

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/RValueOfInsulationForConstructionMultiplier/measure.rb', line 14

def description
  'Change R-value of Insulation Layer for Construction By a Multiplier'
end

#modeler_descriptionObject

human readable description of modeling approach



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

def modeler_description
  'Change R-value of Insulation Layer for Construction By a Multiplier'
end

#nameObject

define the name that a user will see



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

def name
  'Change R-value of Insulation Layer for Construction By a Multiplier'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



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

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
  r_value_multplier = runner.getDoubleArgumentValue('r_value_multplier', user_arguments)
  check_multiplier(runner, r_value_multplier)
  # 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

  # set limit for minimum insulation. This is used to limit input and for inferring insulation layer in construction.
  min_expected_r_value_multplier_ip = 1 # ip units

  # report initial condition
  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')

  # TODO: - find and test insulation
  construction_layers = construction.layers
  max_thermal_resistance_material = construction_layers[0]
  max_thermal_resistance_material_index = 0
  counter = 0
  thermal_resistance_values = []

  # loop through construction layers and infer insulation layer/material
  construction_layers.each do |construction_layer|
    construction_layer_r_value = construction_layer.to_OpaqueMaterial.get.thermalResistance
    if !thermal_resistance_values.empty? && (construction_layer_r_value > thermal_resistance_values.max)
      max_thermal_resistance_material = construction_layer
      max_thermal_resistance_material_index = counter
    end
    thermal_resistance_values << construction_layer_r_value
    counter += 1
  end
  if thermal_resistance_values.max <= OpenStudio.convert(min_expected_r_value_multplier_ip, 'ft^2*h*R/Btu', 'm^2*K/W').get
    runner.registerAsNotApplicable("Construction '#{construction.name}' does not appear to have an insulation layer and was not altered.")
    return true
  end

  # clone insulation material
  new_material = max_thermal_resistance_material.clone(model)
  new_material = new_material.to_OpaqueMaterial.get
  new_material.setName("#{max_thermal_resistance_material.name} (R #{r_value_multplier.round(2)}x Multiplier)") if r_value_multplier != 1
  construction.eraseLayer(max_thermal_resistance_material_index)
  construction.insertLayer(max_thermal_resistance_material_index, new_material)
  runner.registerInfo("For construction'#{construction.name}', '#{max_thermal_resistance_material.name}' was altered.")

  # edit clone material
  new_material_matt = new_material.to_Material
  unless new_material_matt.empty?
    starting_thickness = new_material_matt.get.thickness
    target_thickness = starting_thickness * r_value_multplier
    final_thickness = new_material_matt.get.setThickness(target_thickness)
  end
  new_material_massless = new_material.to_MasslessOpaqueMaterial
  unless new_material_massless.empty?
    starting_thermal_resistance = new_material_massless.get.thermalResistance
    final_thermal_resistance = new_material_massless.get.setThermalResistance(starting_thermal_resistance * r_value_multplier)
  end
  new_material_airgap = new_material.to_AirGap
  unless new_material_airgap.empty?
    starting_thermal_resistance = new_material_airgap.get.thermalResistance
    final_thermal_resistance = new_material_airgap.get.setThermalResistance(starting_thermal_resistance * r_value_multplier)
  end

  # 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