Class: CreateDOEPrototypeBuilding

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

Overview

Start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

Define the arguments that the user will input.



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
110
111
112
113
# File 'lib/measures/create_DOE_prototype_building/measure.rb', line 26

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

  # Make an argument for the building type
  building_type_chs = OpenStudio::StringVector.new
  building_type_chs << 'SecondarySchool'
  building_type_chs << 'PrimarySchool'
  building_type_chs << 'SmallOffice'
  building_type_chs << 'MediumOffice'
  building_type_chs << 'LargeOffice'
  building_type_chs << 'SmallHotel'
  building_type_chs << 'LargeHotel'
  building_type_chs << 'Warehouse'
  building_type_chs << 'RetailStandalone'
  building_type_chs << 'RetailStripmall'
  building_type_chs << 'QuickServiceRestaurant'
  building_type_chs << 'FullServiceRestaurant'
  building_type_chs << 'MidriseApartment'
  building_type_chs << 'HighriseApartment'
  building_type_chs << 'Hospital'
  building_type_chs << 'Outpatient'
  building_type_chs << 'Laboratory'
  building_type_chs << 'LargeDataCenterHighITE'
  building_type_chs << 'LargeDataCenterLowITE'
  building_type_chs << 'SmallDataCenterHighITE'
  building_type_chs << 'SmallDataCenterLowITE'
  building_type_chs << 'Courthouse'
  building_type_chs << 'College'
  building_type = OpenStudio::Measure::OSArgument.makeChoiceArgument('building_type', building_type_chs, true)
  building_type.setDisplayName('Building Type.')
  building_type.setDefaultValue('SmallOffice')
  args << building_type

  # Make an argument for the template
  template_chs = OpenStudio::StringVector.new
  template_chs << 'DOE Ref Pre-1980'
  template_chs << 'DOE Ref 1980-2004'
  template_chs << '90.1-2004'
  template_chs << '90.1-2007'
  # template_chs << '189.1-2009'
  template_chs << '90.1-2010'
  template_chs << '90.1-2013'
  template_chs << '90.1-2016'
  template_chs << '90.1-2019'
  template_chs << 'NECB 2011'
  template = OpenStudio::Measure::OSArgument.makeChoiceArgument('template', template_chs, true)
  template.setDisplayName('Template.')
  template.setDefaultValue('90.1-2010')
  args << template

  # Make an argument for the climate zone
  climate_zone_chs = OpenStudio::StringVector.new
  climate_zone_chs << 'ASHRAE 169-2013-1A'
  # climate_zone_chs << 'ASHRAE 169-2013-1B'
  climate_zone_chs << 'ASHRAE 169-2013-2A'
  climate_zone_chs << 'ASHRAE 169-2013-2B'
  climate_zone_chs << 'ASHRAE 169-2013-3A'
  climate_zone_chs << 'ASHRAE 169-2013-3B'
  climate_zone_chs << 'ASHRAE 169-2013-3C'
  climate_zone_chs << 'ASHRAE 169-2013-4A'
  climate_zone_chs << 'ASHRAE 169-2013-4B'
  climate_zone_chs << 'ASHRAE 169-2013-4C'
  climate_zone_chs << 'ASHRAE 169-2013-5A'
  climate_zone_chs << 'ASHRAE 169-2013-5B'
  # climate_zone_chs << 'ASHRAE 169-2013-5C'
  climate_zone_chs << 'ASHRAE 169-2013-6A'
  climate_zone_chs << 'ASHRAE 169-2013-6B'
  climate_zone_chs << 'ASHRAE 169-2013-7A'
  # climate_zone_chs << 'ASHRAE 169-2013-7B'
  climate_zone_chs << 'ASHRAE 169-2013-8A'
  # climate_zone_chs << 'ASHRAE 169-2013-8B'
  climate_zone_chs << 'NECB HDD Method'
  climate_zone = OpenStudio::Measure::OSArgument.makeChoiceArgument('climate_zone', climate_zone_chs, true)
  climate_zone.setDisplayName('Climate Zone.')
  climate_zone.setDefaultValue('ASHRAE 169-2013-2A')
  args << climate_zone

  # Drop down selector for Canadian weather files.
  epw_files = OpenStudio::StringVector.new
  epw_files << 'Not Applicable'
  #BTAP::Environment.get_canadian_weather_file_names.each { |file| epw_files << file }
  epw_file = OpenStudio::Measure::OSArgument.makeChoiceArgument('epw_file', epw_files, true)
  epw_file.setDisplayName('Climate File (NECB only)')
  epw_file.setDefaultValue('Not Applicable')
  args << epw_file

  return args
end

#descriptionObject

Human readable description



16
17
18
# File 'lib/measures/create_DOE_prototype_building/measure.rb', line 16

def description
  return ''
end

#log_msgsObject

Get all the log messages and put into output for users to see.



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

def log_msgs
  @msg_log.logMessages.each do |msg|
    # DLM: you can filter on log channel here for now
    if /openstudio.*/.match(msg.logChannel) # /openstudio\.model\..*/
      # Skip certain messages that are irrelevant/misleading
      next if msg.logMessage.include?('Skipping layer') || # Annoying/bogus "Skipping layer" warnings
              msg.logChannel.include?('runmanager') || # RunManager messages
              msg.logChannel.include?('setFileExtension') || # .ddy extension unexpected
              msg.logChannel.include?('Translator') || # Forward translator and geometry translator
              msg.logMessage.include?('UseWeatherFile') # 'UseWeatherFile' is not yet a supported option for YearDescription

      # Report the message in the correct way
      if msg.logLevel == OpenStudio::Info
        @runner.registerInfo(msg.logMessage)
      elsif msg.logLevel == OpenStudio::Warn
        @runner.registerWarning("[#{msg.logChannel}] #{msg.logMessage}")
      elsif msg.logLevel == OpenStudio::Error
        @runner.registerError("[#{msg.logChannel}] #{msg.logMessage}")
      elsif msg.logLevel == OpenStudio::Debug && @debug
        @runner.registerInfo("DEBUG - #{msg.logMessage}")
      end
    end
  end
  @runner.registerInfo("Total Time = #{(Time.new - @start_time).round}sec.")
end

#modeler_descriptionObject

Human readable description of modeling approach



21
22
23
# File 'lib/measures/create_DOE_prototype_building/measure.rb', line 21

def modeler_description
  return ''
end

#nameObject

Define the name of the Measure.



11
12
13
# File 'lib/measures/create_DOE_prototype_building/measure.rb', line 11

def name
  return 'Create DOE Prototype Building'
end

#run(model, runner, user_arguments) ⇒ Object

Define what happens when the measure is run.



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

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

  # Assign the user inputs to variables that can be accessed across the measure
  building_type = runner.getStringArgumentValue('building_type', user_arguments)
  template = runner.getStringArgumentValue('template', user_arguments)
  climate_zone = runner.getStringArgumentValue('climate_zone', user_arguments)
  epw_file = runner.getStringArgumentValue('epw_file', user_arguments)

  # Turn debugging output on/off
  @debug = false

  # Open a channel to log info/warning/error messages
  @msg_log = OpenStudio::StringStreamLogSink.new
  if @debug
    @msg_log.setLogLevel(OpenStudio::Debug)
  else
    @msg_log.setLogLevel(OpenStudio::Info)
  end
  @start_time = Time.new
  @runner = runner

  # Make a directory to save the resulting models for debugging
  build_dir = "#{Dir.pwd}/output"
  if !Dir.exist?(build_dir)
    Dir.mkdir(build_dir)
  end

  # Set OSM folder
  osm_directory = ''
  if template == 'NECB 2011'
    osm_directory = "#{build_dir}/#{building_type}-#{template}-#{climate_zone}-#{epw_file}"
  else
    osm_directory = build_dir
  end
  if !Dir.exist?(osm_directory)
    Dir.mkdir(osm_directory)
  end

  # Versions of OpenStudio greater than 2.4.0 use a modified version of
  # openstudio-standards with different method calls.
  if OpenStudio::VersionString.new(OpenStudio.openStudioVersion) < OpenStudio::VersionString.new('2.4.3')
    model.create_prototype_building(building_type,
                                    template,
                                    climate_zone,
                                    epw_file,
                                    osm_directory,
                                    @debug)
  else
    reset_log
    template = 'NECB2011' if template == 'NECB 2011'
    prototype_creator = Standard.build("#{template}_#{building_type}")
    prototype_creator.model_create_prototype_model(climate_zone, epw_file, osm_directory, @debug, model)
  end

  log_msgs
  reset_log

  return true
end