Class: AddInteriorBlindsAndControl

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

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



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

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

  start_time = OpenStudio::Measure::OSArgument.makeStringArgument('start_time', false)
  start_time.setDisplayName('Start Time for Shading')
  start_time.setDescription('In HH:MM:SS format')
  start_time.setDefaultValue('12:00:00')
  args << start_time

  # make an argument for the end time of the reduction
  end_time = OpenStudio::Measure::OSArgument.makeStringArgument('end_time', false)
  end_time.setDisplayName('End Time for Shading')
  end_time.setDescription('In HH:MM:SS format')
  end_time.setDefaultValue('15:00:00')
  args << end_time

  # make an argument for the start date of the reduction
  start_date = OpenStudio::Ruleset::OSArgument.makeStringArgument('start_date', false)
  start_date.setDisplayName('Start date for Shading')
  start_date.setDescription('In MM-DD format')
  start_date.setDefaultValue('07-01')
  args << start_date

  # make an argument for the end date of the reduction
  end_date = OpenStudio::Ruleset::OSArgument.makeStringArgument('end_date', false)
  end_date.setDisplayName('End date for Shading')
  end_date.setDescription('In MM-DD format')
  end_date.setDefaultValue('08-30')
  args << end_date

  return args
end

#descriptionObject

human readable description



23
24
25
# File 'lib/measures/add_interior_blinds_and_control/measure.rb', line 23

def description
  return 'This measure add shading control with interior blinds to all exterior windows of the building. '
end

#modeler_descriptionObject

human readable description of modeling approach



28
29
30
# File 'lib/measures/add_interior_blinds_and_control/measure.rb', line 28

def modeler_description
  return 'The measure will create a new shading control object with interior blinds for each space, and apply that shading control object to all exterior windows within that space. A new shading schedule will be created and applied to all shading control objects based on the active time provided in user inputs.'
end

#nameObject

human readable name



17
18
19
20
# File 'lib/measures/add_interior_blinds_and_control/measure.rb', line 17

def name
  # Measure name should be the title case of the class name.
  return 'add_interior_blinds_and_control'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



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

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

  # use the built-in error checking
  if !runner.validateUserArguments(arguments(model), user_arguments)
    return false
  end
  start_time = runner.getStringArgumentValue('start_time', user_arguments)
  end_time = runner.getStringArgumentValue('end_time', user_arguments)
  start_date = runner.getStringArgumentValue('start_date', user_arguments)
  end_date = runner.getStringArgumentValue('end_date', user_arguments)

  unless /(\d\d):(\d\d):(\d\d)/.match(start_time)
    runner.registerError('Start time must be in HH-MM-SS format.')
    return false
  end

  unless /(\d\d):(\d\d):(\d\d)/.match(end_time)
    runner.registerError('End time must be in HH-MM-SS format.')
    return false
  end

  if start_time.to_f > end_time.to_f
    runner.registerError('The start time cannot be later than the end time.')
    return false
  end


  start_month = nil
  start_day = nil
  md = /(\d\d)-(\d\d)/.match(start_date)
  if md
    start_month = md[1].to_i
    start_day = md[2].to_i
  else
    runner.registerError('Start date must be in MM-DD format.')
    return false
  end
  end_month = nil
  end_day = nil
  md = /(\d\d)-(\d\d)/.match(end_date)
  if md
    end_month = md[1].to_i
    end_day = md[2].to_i
  else
    runner.registerError('End date must be in MM-DD format.')
    return false
  end



  # create a shading control for each space
  # All windows using one shading control object will cause duplicated objects (with the same zone name) when translated into idf,
  # which may crash EP
  windows_applied = 0
  # All shading control objects share one schedule
  global_shading_schedule = nil
  model.getSpaces.each do |space|
    # One shading control object for each space if it has any exterior windows
    space_shading_control = nil
    space.surfaces.each do |surface|
      surface.subSurfaces.each do |sub_surface|
        if (sub_surface.outsideBoundaryCondition == 'Outdoors') && (sub_surface.subSurfaceType.include?'Window')
          # create schedule and shading control object only if an exterior window is found
          # (avoid any modifications if no exterior window exists in the model)
          unless global_shading_schedule
            # create a new shading schedule
            normal_day_data_pairs = [[24, 0]]
            h, m, s  = start_time.split(':')
            start_hour = h.to_i +  m.to_i/60
            h, m, s  = end_time.split(':')
            end_hour = h.to_i +  m.to_i/60
            adjusted_day_data_pairs = [[start_hour, 0], [end_hour, 1], [24, 0]]
            options = { 'name' => "Interior blinds schedule",
                        'winter_design_day' => normal_day_data_pairs,
                        'summer_design_day' => normal_day_data_pairs,
                        'default_day' => ["default day"] + normal_day_data_pairs,
                        'rules' => [['Adjusted days', "#{start_month}/#{start_day}-#{end_month}/#{end_day}",
                                     'Sun/Mon/Tue/Wed/Thu/Fri/Sat'] + adjusted_day_data_pairs] }
            # global_shading_schedule = OsLib_Schedules.createComplexSchedule(model, options)
            global_shading_schedule = OpenstudioStandards::Schedules.create_complex_schedule(model, options)
            runner.registerInfo("A new schedule 'Interior blinds schedule' has been created for new shading control objects.")
          end
          unless space_shading_control
            shading_material = OpenStudio::Model::Blind.new(model)
            # create shading control object
            space_shading_control = OpenStudio::Model::ShadingControl.new(shading_material)
            space_shading_control.setShadingType("InteriorBlind")
            space_shading_control.setName("#{space.name} interior blinds shading control")
            space_shading_control.setShadingControlType('OnIfScheduleAllows')
            space_shading_control.setSchedule(global_shading_schedule)
          end

          sub_surface.setShadingControl(space_shading_control)
          runner.registerInfo("Interior blinds shading '#{space_shading_control.name}' has been added to window #{sub_surface.name}.")
          windows_applied += 1
        end
      end
    end
  end

  if windows_applied == 0
    runner.registerAsNotApplicable("There's no exterior window in the model, so the measure didn't make any change.")
  else
    runner.registerFinalCondition("In total #{windows_applied} exterior windows have been applied with interior blinds shading.")
  end

  return true
end