Class: BuildingSync::Building

Inherits:
LocationElement show all
Includes:
EnergyPlus, OsLib_HelperMethods, OsLib_ModelGeneration
Defined in:
lib/buildingsync/model_articulation/building.rb

Overview

Building class

Instance Attribute Summary collapse

Attributes inherited from SpatialElement

#space_types, #standards_building_type, #system_type, #total_floor_area

Instance Method Summary collapse

Methods inherited from LocationElement

#determine_climate_zone, #get_climate_zone, #read_city_and_state_name, #read_climate_zone, #read_location_values

Methods inherited from SpatialElement

#add_user_defined_field_to_xml_file, #create_space_types, #prepare_final_xml_for_spatial_element, #process_bldg_and_system_type, #read_floor_areas, #set_bldg_and_system_type, #sets_occupancy_bldg_system_types, #validate_positive_number_excluding_zero, #validate_positive_number_including_zero

Methods included from XmlGetSet

#get_prefix, #xget_attribute_for_element, #xget_element, #xget_id, #xget_idrefs, #xget_linked_premises, #xget_name, #xget_or_create, #xget_plurals_text_value, #xget_text, #xget_text_as_bool, #xget_text_as_date, #xget_text_as_dt, #xget_text_as_float, #xget_text_as_integer, #xset_or_create, #xset_text

Methods included from Helper

#help_calculate_hours, #help_convert, #help_count_number_of_days, #help_element_class_type_check, #help_get_attribute_value, #help_get_default_schedule_set, #help_get_duration, #help_get_end_time, #help_get_end_time_sat, #help_get_end_time_sun, #help_get_end_time_weekday, #help_get_or_create, #help_get_schedule_rule_set_from_schedule, #help_get_start_time, #help_get_start_time_sat, #help_get_start_time_sun, #help_get_start_time_weekday, #help_get_text_value, #help_get_text_value_as_bool, #help_get_text_value_as_date, #help_get_text_value_as_datetime, #help_get_text_value_as_float, #help_get_text_value_as_integer, #help_get_zone_name_list, #help_load_doc, #help_print_all_schedules, #help_print_schedule, #help_write_profile

Constructor Details

#initialize(base_xml, site_occupancy_classification, site_total_floor_area, ns) ⇒ Building

initialize

Parameters:

  • building_element (REXML::Element)

    an element corresponding to a single auc:Building

  • site_occupancy_classification (String)
  • site_total_floor_area (String)
  • ns (String)

    namespace, likely 'auc'



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
# File 'lib/buildingsync/model_articulation/building.rb', line 60

def initialize(base_xml, site_occupancy_classification, site_total_floor_area, ns)
  super(base_xml, ns)
  @base_xml = base_xml
  @ns = ns

  help_element_class_type_check(base_xml, 'Building')
  @building_sections = []
  @building_sections_whole_building = []
  @model = nil
  @all_set = false

  # parameter to read and write.
  @epw_file_path = nil
  @standard_template = nil
  @building_rotation = 0.0
  @floor_height = 0.0
  @width = 0.0
  @length = 0.0
  @wwr = 0.0
  @name = nil
  # variables not used during read xml for now
  @party_wall_stories_north = 0
  @party_wall_stories_south = 0
  @party_wall_stories_west = 0
  @party_wall_stories_east = 0
  @party_wall_fraction = 0
  @built_year = 0
  @open_studio_standard = nil
  @occupant_quantity = nil
  @number_of_units = nil
  @fraction_area = 1.0
  # code to initialize
  read_xml(site_occupancy_classification, site_total_floor_area)
end

Instance Attribute Details

#building_rotationObject (readonly)

Returns the value of attribute building_rotation.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def building_rotation
  @building_rotation
end

#building_sectionsObject (readonly)

Returns the value of attribute building_sections.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def building_sections
  @building_sections
end

#built_yearObject (readonly)

Returns the value of attribute built_year.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def built_year
  @built_year
end

#floor_heightObject (readonly)

Returns the value of attribute floor_height.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def floor_height
  @floor_height
end

#lengthObject (readonly)

Returns the value of attribute length.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def name
  @name
end

#num_stories_above_gradeObject (readonly)

Returns the value of attribute num_stories_above_grade.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def num_stories_above_grade
  @num_stories_above_grade
end

#num_stories_below_gradeObject (readonly)

Returns the value of attribute num_stories_below_grade.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def num_stories_below_grade
  @num_stories_below_grade
end

#number_of_unitsObject (readonly)

Returns the value of attribute number_of_units.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def number_of_units
  @number_of_units
end

#occupant_quantityObject (readonly)

Returns the value of attribute occupant_quantity.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def occupant_quantity
  @occupant_quantity
end

#spaceObject (readonly)

Returns the value of attribute space.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def space
  @space
end

#widthObject (readonly)

Returns the value of attribute width.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def width
  @width
end

#wwrObject (readonly)

Returns the value of attribute wwr.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def wwr
  @wwr
end

#year_major_remodelObject (readonly)

Returns the value of attribute year_major_remodel.



1128
1129
1130
# File 'lib/buildingsync/model_articulation/building.rb', line 1128

def year_major_remodel
  @year_major_remodel
end

Instance Method Details

#add_site_water_mains_temperature(stat_file) ⇒ Boolean

add site water mains temperature – via parsing of STAT file.

Parameters:

  • stat_file (String)

Returns:

  • (Boolean)


797
798
799
800
801
802
803
804
# File 'lib/buildingsync/model_articulation/building.rb', line 797

def add_site_water_mains_temperature(stat_file)
  stat_model = ::EnergyPlus::StatFile.new(stat_file)
  water_temp = @model.getSiteWaterMainsTemperature
  water_temp.setAnnualAverageOutdoorAirTemperature(stat_model.mean_dry_bulb)
  water_temp.setMaximumDifferenceInMonthlyAverageOutdoorAirTemperatures(stat_model.delta_dry_bulb)
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.add_site_water_mains_temperature', "mean dry bulb is #{stat_model.mean_dry_bulb}")
  return true
end

#bldg_space_types_floor_area_hashHash

generate building space types floor area hash

Returns:

  • (Hash)


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/buildingsync/model_articulation/building.rb', line 357

def bldg_space_types_floor_area_hash
  new_hash = {}
  if @building_sections.count > 0
    @building_sections.each do |bldg_subsec|
      bldg_subsec.space_types_floor_area.each do |space_type, hash|
        new_hash[space_type] = hash
      end
    end
    # if we have no sections we need to do the same just for the building
  elsif @building_sections.count == 0
    @space_types = get_space_types_from_building_type(@standards_building_type, @standard_template, true)
    puts " Space types: #{@space_types} selected for building type: #{@standards_building_type} and standard template: #{@standard_template}"
    space_types_floor_area = create_space_types(@model, @total_floor_area, num_stories, @standard_template, @open_studio_standard)
    space_types_floor_area.each do |space_type, hash|
      new_hash[space_type] = hash
    end
  end
  return new_hash
end

#build_space_type_hashhash<string, array<hash<string, string>>]

build space types hash

Returns:

  • (hash<string, array<hash<string, string>>])

    hash<string, array<hash<string, string>>]



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/buildingsync/model_articulation/building.rb', line 336

def build_space_type_hash
  space_type_hash = {}
  if @space_types
    space_type_list = []
    @space_types.each do |space_name, space_type|
      space_type_list << space_type[:space_type]
    end
    space_type_hash[xget_id] = space_type_list
  end
  @building_sections.each do |bldg_subsec|
    space_type_list = []
    bldg_subsec.space_types_floor_area.each do |space_type, hash|
      space_type_list << space_type
    end
    space_type_hash[bldg_subsec.xget_id] = space_type_list
  end
  return space_type_hash
end

#build_zone_hash[hash<string, array<Zone>>]

build zone hash that stores zone lists for buildings and building sections

Returns:

  • ([hash<string, array<Zone>>])


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/buildingsync/model_articulation/building.rb', line 315

def build_zone_hash
  zone_hash = {}
  if @space_types
    zone_list = []
    @space_types.each do |space_name, space_type|
      zone_list.concat(get_zones_per_space_type(space_type[:space_type]))
    end
    zone_hash[xget_id] = zone_list
  end
  @building_sections.each do |bldg_subsec|
    zone_list = []
    bldg_subsec.space_types_floor_area.each do |space_type, hash|
      zone_list.concat(get_zones_per_space_type(space_type))
    end
    zone_hash[bldg_subsec.xget_id] = zone_list
  end
  return zone_hash
end

#check_building_fractionObject

check building fraction



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/buildingsync/model_articulation/building.rb', line 254

def check_building_fraction
  # check that sum of fractions for b,c, and d is less than 1.0 (so something is left for primary building type)
  building_fraction = 1.0
  if @building_sections.count > 0
    # first we check if the building sections do have a fraction
    if @building_sections.count > 1
      areas = []
      floor_area = 0
      @building_sections.each do |section|
        if section.fraction_area.nil?
          areas.push(section.total_floor_area)
          floor_area += section.total_floor_area
        end
      end
      i = 0
      @building_sections.each do |section|
        section.fraction_area = areas[i] / @total_floor_area
        i += 1
      end
    elsif @building_sections.count == 1
      # only if we have just one section the section fraction is set to the building fraction (1)
      @building_sections[0].fraction_area = building_fraction
    end
    @building_sections.each do |section|
      puts "section with ID: #{section.xget_id} and type: '#{section.xget_text('SectionType')}' has fraction: #{section.fraction_area}"
      next if section.fraction_area.nil?
      building_fraction -= section.fraction_area
    end
    if building_fraction.round(3) < 0.0
      puts "building fraction is #{building_fraction}"
      OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.check_building_fraction', 'Primary Building Type fraction of floor area must be greater than 0. Please lower one or more of the fractions for Building Type B-D.')
      raise 'ERROR: Primary Building Type fraction of floor area must be greater than 0. Please lower one or more of the fractions for Building Type B-D.'
    end
  end
end

#check_occupancy_classification(site_occupancy_classification) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'lib/buildingsync/model_articulation/building.rb', line 150

def check_occupancy_classification(site_occupancy_classification)
  # Set the OccupancyClassification text as that defined by the Site
  # ONLY if it is not already defined
  if !site_occupancy_classification.nil?
    xset_or_create('OccupancyClassification', site_occupancy_classification, false)
  end
  if xget_text('OccupancyClassification').nil?
    raise StandardError, "Building ID: #{xget_id}. OccupancyClassification must be defined at either the Site or Building level."
  end
end

#create_bldg_space_types(model) ⇒ Object

create building space types

Parameters:

  • model (OpenStudio::Model)


307
308
309
310
311
# File 'lib/buildingsync/model_articulation/building.rb', line 307

def create_bldg_space_types(model)
  @building_sections.each do |bldg_subsec|
    bldg_subsec.create_space_types(model, @total_floor_area, num_stories, @standard_template, @open_studio_standard)
  end
end

#determine_open_studio_standard(standard_to_be_used) ⇒ Standard

determine the open studio standard and call the set_all function

Parameters:

  • standard_to_be_used (String)

Returns:

  • (Standard)


393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/buildingsync/model_articulation/building.rb', line 393

def determine_open_studio_standard(standard_to_be_used)
  set_all
  begin
    set_standard_template(standard_to_be_used, get_built_year)
    building_type = get_building_type
    @open_studio_standard = Standard.build("#{@standard_template}_#{building_type}")
    update_name
  rescue StandardError => e
    # this error means there's such standard. The default error message is to long to be helpful
    if e.to_s.include?("Did not find a class called")
      message =  e.to_s.split("{", 2).first
      raise StandardError, "BuildingSync.Building.determine_open_studio_standard: #{message}#{standard_to_be_used}"
    end

    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.determine_open_studio_standard', e.message[0..20])
    raise StandardError, "BuildingSync.Building.determine_open_studio_standard: #{e.message[0..20]}"
  end
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.determine_open_studio_standard', "Building Standard with template: #{@standard_template}_#{building_type}") if !@open_studio_standard.nil?
  return @open_studio_standard
end

#generate_baseline_osmObject

generate baseline model in osm file format



807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
# File 'lib/buildingsync/model_articulation/building.rb', line 807

def generate_baseline_osm
  # checking that the fractions add up
  check_building_fraction

  # set building rotation
  initial_rotation = @model.getBuilding.northAxis
  if @building_rotation != initial_rotation
    @model.getBuilding.setNorthAxis(building_rotation)
    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.generate_baseline_osm', "Set Building Rotation to #{@model.getBuilding.northAxis}")
  end
  if !@name.nil?
    @model.getBuilding.setName(@name)
  end

  create_bldg_space_types(@model)

  # create envelope
  # populate bar_hash and create envelope with data from envelope_data_hash and user arguments
  bar_hash = {}
  bar_hash[:length] = @length
  bar_hash[:width] = @width
  bar_hash[:num_stories_below_grade] = num_stories_below_grade.to_i
  bar_hash[:num_stories_above_grade] = num_stories_above_grade.to_i
  bar_hash[:floor_height] = floor_height
  bar_hash[:center_of_footprint] = OpenStudio::Point3d.new(0, 0, 0)
  bar_hash[:bar_division_method] = 'Multiple Space Types - Individual Stories Sliced'
  # default for now 'Multiple Space Types - Individual Stories Sliced', 'Multiple Space Types - Simple Sliced', 'Single Space Type - Core and Perimeter'
  bar_hash[:make_mid_story_surfaces_adiabatic] = false
  bar_hash[:space_types] = bldg_space_types_floor_area_hash
  bar_hash[:building_wwr_n] = wwr
  bar_hash[:building_wwr_s] = wwr
  bar_hash[:building_wwr_e] = wwr
  bar_hash[:building_wwr_w] = wwr

  runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
  # remove non-resource objects not removed by removing the building
  remove_non_resource_objects(runner, @model)

  # party_walls_array to be used by orientation specific or fractional party wall values
  party_walls_array = generate_party_walls # this is an array of arrays, where each entry is effective building story with array of directions

  # populate bar hash with story information
  bar_hash[:stories] = {}
  num_stories.ceil.times do |i|
    if party_walls_array.empty?
      party_walls = []
    else
      party_walls = party_walls_array[i]
    end

    # add below_partial_story
    if num_stories.ceil > num_stories && i == num_stories_round_up - 2
      below_partial_story = true
    else
      below_partial_story = false
    end

    # bottom_story_ground_exposed_floor and top_story_exterior_exposed_roof already setup as bool
    bar_hash[:stories]["key #{i}"] = { story_party_walls: party_walls, story_min_multiplier: 1, story_included_in_building_area: true, below_partial_story: below_partial_story, bottom_story_ground_exposed_floor: true, top_story_exterior_exposed_roof: true }
  end

  # store expected floor areas to check after bar made
  target_areas = {}
  bar_hash[:space_types].each do |k, v|
    target_areas[k] = v[:floor_area]
  end

  # create bar
  create_bar(runner, @model, bar_hash, 'Basements Ground Mid Top')
  # using the default value for story multiplier for now 'Basements Ground Mid Top'

  # check expected floor areas against actual
  @model.getSpaceTypes.sort.each do |space_type|
    next if !target_areas.key? space_type

    # convert to IP
    actual_ip = OpenStudio.convert(space_type.floorArea, 'm^2', 'ft^2').get
    target_ip = OpenStudio.convert(target_areas[space_type], 'm^2', 'ft^2').get

    if (space_type.floorArea - target_areas[space_type]).abs >= 1.0
      if !bar_hash[:bar_division_method].include? 'Single Space Type'
        OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.generate_baseline_osm', "#{space_type.name} doesn't have the expected floor area (actual #{OpenStudio.toNeatString(actual_ip, 0, true)} ft^2, target #{OpenStudio.toNeatString(target_ip, 0, true)} ft^2)")
        return false
      else
        # will see this if use Single Space type division method on multi-use building or single building type without whole building space type
        OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.generate_baseline_osm', "WARNING: #{space_type.name} doesn't have the expected floor area (actual #{OpenStudio.toNeatString(actual_ip, 0, true)} ft^2, target #{OpenStudio.toNeatString(target_ip, 0, true)} ft^2)")
      end
    end
  end

  # test for excessive exterior roof area (indication of problem with intersection and or surface matching)
  ext_roof_area = @model.getBuilding.exteriorSurfaceArea - @model.getBuilding.exteriorWallArea
  expected_roof_area = total_floor_area / num_stories.to_f
  if ext_roof_area > expected_roof_area # only test if using whole-building area input
    OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.generate_baseline_osm', 'Roof area larger than expected, may indicate problem with inter-floor surface intersection or matching.')
    return false
  end

  # report final condition of model
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.generate_baseline_osm', "The building finished with #{@model.getSpaces.size} spaces.")

  return true
end

#generate_party_wallsObject

generate party walls



912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/buildingsync/model_articulation/building.rb', line 912

def generate_party_walls
  party_walls_array = []
  if @party_wall_stories_north + @party_wall_stories_south + @party_wall_stories_east + @party_wall_stories_west > 0

    # loop through effective number of stories add orientation specific party walls per user arguments
    num_stories.ceil.times do |i|
      test_value = i + 1 - bar_hash[:num_stories_below_grade]

      array = []
      if @party_wall_stories_north >= test_value
        array << 'north'
      end
      if @party_wall_stories_south >= test_value
        array << 'south'
      end
      if @party_wall_stories_east >= test_value
        array << 'east'
      end
      if @party_wall_stories_west >= test_value
        array << 'west'
      end

      # populate party_wall_array for this story
      party_walls_array << array
    end
  end

  # calculate party walls if using party_wall_fraction method
  if @party_wall_fraction > 0 && !party_walls_array.empty?
    runner.registerWarning('Both orientaiton and fractional party wall values arguments were populated, will ignore fractional party wall input')
  elsif @party_wall_fraction > 0

    # orientation of long and short side of building will vary based on building rotation

    # full story ext wall area
    typical_length_facade_area = @length * floor_height
    typical_width_facade_area = @width * floor_height

    # top story ext wall area, may be partial story
    partial_story_multiplier = (1.0 - @num_stories_above_grade.ceil + @num_stories_above_grade)
    area_multiplier = partial_story_multiplier
    edge_multiplier = Math.sqrt(area_multiplier)
    top_story_length = @length * edge_multiplier
    top_story_width = @width * edge_multiplier
    top_story_length_facade_area = top_story_length * floor_height
    top_story_width_facade_area = top_story_width * floor_height

    total_exterior_wall_area = 2 * (@length + @width) * (@num_stories_above_grade.ceil - 1.0) * floor_height + 2 * (top_story_length + top_story_width) * floor_height
    target_party_wall_area = total_exterior_wall_area * @party_wall_fraction

    width_counter = 0
    width_area = 0.0
    facade_area = typical_width_facade_area
    until (width_area + facade_area >= target_party_wall_area) || (width_counter == @num_stories_above_grade.ceil * 2)
      # update facade area for top story
      if width_counter == @num_stories_above_grade.ceil - 1 || width_counter == @num_stories_above_grade.ceil * 2 - 1
        facade_area = top_story_width_facade_area
      else
        facade_area = typical_width_facade_area
      end

      width_counter += 1
      width_area += facade_area

    end
    width_area_remainder = target_party_wall_area - width_area

    length_counter = 0
    length_area = 0.0
    facade_area = typical_length_facade_area
    until (length_area + facade_area >= target_party_wall_area) || (length_counter == @num_stories_above_grade.ceil * 2)
      # update facade area for top story
      if length_counter == @num_stories_above_grade.ceil - 1 || length_counter == @num_stories_above_grade.ceil * 2 - 1
        facade_area = top_story_length_facade_area
      else
        facade_area = typical_length_facade_area
      end

      length_counter += 1
      length_area += facade_area
    end
    length_area_remainder = target_party_wall_area - length_area

    # get rotation and best fit to adjust orientation for fraction party wall
    rotation = @building_rotation % 360.0 # should result in value between 0 and 360
    card_dir_array = [0.0, 90.0, 180.0, 270.0, 360.0]
    # reverse array to properly handle 45, 135, 225, and 315
    best_fit = card_dir_array.reverse.min_by { |x| (x.to_f - rotation).abs }

    if ![90.0, 270.0].include? best_fit
      width_card_dir = ['east', 'west']
      length_card_dir = ['north', 'south']
    else
      # if rotation is closest to 90 or 270 then reverse which orientation is used for length and width
      width_card_dir = ['north', 'south']
      length_card_dir = ['east', 'west']
    end

    # if dont' find enough on short sides
    if width_area_remainder <= typical_length_facade_area

      num_stories.ceil.times do |i|
        if i + 1 <= @num_stories_below_grade
          party_walls_array << []
          next
        end
        if i + 1 - @num_stories_below_grade <= width_counter
          if i + 1 - @num_stories_below_grade <= width_counter - @num_stories_above_grade
            party_walls_array << width_card_dir
          else
            party_walls_array << [width_card_dir.first]
          end
        else
          party_walls_array << []
        end
      end

    else
      # use long sides instead
      num_stories.ceil.times do |i|
        if i + 1 <= @num_stories_below_grade
          party_walls_array << []
          next
        end
        if i + 1 - @num_stories_below_grade <= length_counter
          if i + 1 - @num_stories_below_grade <= length_counter - @num_stories_above_grade
            party_walls_array << length_card_dir
          else
            party_walls_array << [length_card_dir.first]
          end
        else
          party_walls_array << []
        end
      end
    end
    # TODO: - currently won't go past making two opposing sets of walls party walls. Info and registerValue are after create_bar in measure.rb
  end
  party_walls_array
end

#get_building_typeString

get building type

Returns:

  • (String)


213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/buildingsync/model_articulation/building.rb', line 213

def get_building_type
  set_all
  # try to get the bldg type at the building level, if it is nil then look at the first section
  if !@standards_building_type.nil?
    return @standards_building_type
  else
    if @building_sections.count == 0
      OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.get_building_type', 'There is no occupancy type attached to this building in your BuildingSync file.')
      raise 'Error: There is no occupancy type attached to this building in your BuildingSync file.'
    else
      return @building_sections[0].standards_building_type
    end
  end
end

#get_built_yearInteger

get year building was built

Returns:

  • (Integer)


488
489
490
# File 'lib/buildingsync/model_articulation/building.rb', line 488

def get_built_year
  return @built_year
end

#get_epw_file_pathObject

get full path to epw file return [String]



230
231
232
# File 'lib/buildingsync/model_articulation/building.rb', line 230

def get_epw_file_path
  return @epw_file_path
end

#get_floor_areahash<string, float>

get floor area

Returns:

  • (hash<string, float>)


1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
# File 'lib/buildingsync/model_articulation/building.rb', line 1115

def get_floor_area
  floor_area = {}
  if @total_floor_area
    floor_area[xget_id] = @total_floor_area.to_f
  end
  @building_sections.each do |section|
    if section.get_floor_area
      floor_area[section.xget_id] = section.get_floor_area
    end
  end
  return floor_area
end

#get_modelOpenStudio::Model

get model

Returns:

  • (OpenStudio::Model)


480
481
482
483
484
# File 'lib/buildingsync/model_articulation/building.rb', line 480

def get_model
  # in case the model was not initialized before we create a new model if it is nil
  initialize_model
  return @model
end

#get_peak_occupancyhash<string, float>

get peak occupancy

Returns:

  • (hash<string, float>)


1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
# File 'lib/buildingsync/model_articulation/building.rb', line 1101

def get_peak_occupancy
  peak_occupancy = {}
  if @occupant_quantity
    peak_occupancy[xget_id] = @occupant_quantity.to_f
    return peak_occupancy
  end
  @building_sections.each do |section|
    peak_occupancy[section.xget_id] = section.get_peak_occupancy.to_f if section.get_peak_occupancy
  end
  return peak_occupancy
end

#get_space_typesarray<OpenStudio::Model::SpaceType>

get space types

Returns:

  • (array<OpenStudio::Model::SpaceType>)


1095
1096
1097
# File 'lib/buildingsync/model_articulation/building.rb', line 1095

def get_space_types
  return @model.getSpaceTypes
end

#get_standard_templateString

get @standard_template

Returns:

  • (String)


494
495
496
# File 'lib/buildingsync/model_articulation/building.rb', line 494

def get_standard_template
  return @standard_template
end

#get_stat_file(epw_file) ⇒ String

get stat file path

Parameters:

  • epw_file (String)

Returns:

  • (String)


512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/buildingsync/model_articulation/building.rb', line 512

def get_stat_file(epw_file)
  # Add SiteWaterMainsTemperature -- via parsing of STAT file.
  stat_file = "#{File.join(File.dirname(epw_file.path.to_s), File.basename(epw_file.path.to_s, '.*'))}.stat"
  unless File.exist? stat_file
    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.get_stat_file', 'Could not find STAT file by filename, looking in the directory')
    stat_files = Dir["#{File.dirname(epw_file.path.to_s)}/*.stat"]
    if stat_files.size > 1
      OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.get_stat_file', 'More than one stat file in the EPW directory')
      return nil
    end
    if stat_files.empty?
      OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.get_stat_file', 'Cound not find the stat file in the EPW directory')
      return nil
    end

    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.get_stat_file', "Using STAT file: #{stat_files.first}")
    stat_file = stat_files.first
  end
  unless stat_file
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.get_stat_file', 'Could not find stat file')
    return nil
  end
  return stat_file
end

#get_system_typeString

get system type

Returns:

  • (String)


500
501
502
503
504
505
506
507
# File 'lib/buildingsync/model_articulation/building.rb', line 500

def get_system_type
  set_all
  if !@system_type.nil?
    return @system_type
  else
    return @building_sections[0].system_type
  end
end

#get_zones_per_space_type(space_type) ⇒ array<OpenStudio::Model::ThermalZone>

get zones per space type

Parameters:

  • space_type (OpenStudio::Model::SpaceType)

Returns:

  • (array<OpenStudio::Model::ThermalZone>)


469
470
471
472
473
474
475
476
# File 'lib/buildingsync/model_articulation/building.rb', line 469

def get_zones_per_space_type(space_type)
  list_of_zones = []
  model_space_type = @model.getSpaceTypeByName(space_type.name.get).get
  model_space_type.spaces.each do |space|
    list_of_zones << space.thermalZone.get
  end
  return list_of_zones
end

#initialize_modelObject

in initialize an empty model



378
379
380
381
# File 'lib/buildingsync/model_articulation/building.rb', line 378

def initialize_model
  # let's create our new empty model
  @model = OpenStudio::Model::Model.new if @model.nil?
end

#num_storiesInteger

returns number of stories

Returns:

  • (Integer)


97
98
99
# File 'lib/buildingsync/model_articulation/building.rb', line 97

def num_stories
  return @num_stories_above_grade + @num_stories_below_grade
end

#prepare_final_xmlObject

write parameters to xml file



1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/buildingsync/model_articulation/building.rb', line 1059

def prepare_final_xml
  @base_xml.elements["#{@ns}:OccupancyLevels/#{@ns}:OccupancyLevel/#{@ns}:OccupantQuantity"].text = @occupant_quantity if !@occupant_quantity.nil?
  @base_xml.elements["#{@ns}:SpatialUnits/#{@ns}:SpatialUnit/#{@ns}:NumberOfUnits"].text = @number_of_units if !@number_of_units.nil?

  # Add new element in the XML file
  add_user_defined_field_to_xml_file('OpenStudioModelName', @name)
  add_user_defined_field_to_xml_file('StandardTemplateYearOfConstruction', @built_year)
  add_user_defined_field_to_xml_file('StandardTemplate', @standard_template)
  add_user_defined_field_to_xml_file('BuildingRotation', @building_rotation)
  add_user_defined_field_to_xml_file('FloorHeight', @floor_height)
  add_user_defined_field_to_xml_file('WindowWallRatio', @wwr)
  add_user_defined_field_to_xml_file('PartyWallStoriesNorth', @party_wall_stories_north)
  add_user_defined_field_to_xml_file('PartyWallStoriesSouth', @party_wall_stories_south)
  add_user_defined_field_to_xml_file('PartyWallStoriesEast', @party_wall_stories_east)
  add_user_defined_field_to_xml_file('PartyWallStoriesWest', @party_wall_stories_west)
  add_user_defined_field_to_xml_file('Width', @width)
  add_user_defined_field_to_xml_file('Length', @length)
  add_user_defined_field_to_xml_file('PartyWallFraction', @party_wall_fraction)
  add_user_defined_field_to_xml_file('ModelNumberThermalZones', @model.getThermalZones.size)
  add_user_defined_field_to_xml_file('ModelNumberSpaces', @model.getSpaces.size)
  add_user_defined_field_to_xml_file('ModelNumberStories', @model.getBuildingStorys.size)
  add_user_defined_field_to_xml_file('ModelNumberPeople', @model.getBuilding.numberOfPeople)
  add_user_defined_field_to_xml_file('ModelFloorArea(m2)', @model.getBuilding.floorArea)

  wf = @model.weatherFile.get
  add_user_defined_field_to_xml_file('ModelWeatherFileName', wf.nameString)
  add_user_defined_field_to_xml_file('ModelWeatherFileDataSource', wf.dataSource)
  add_user_defined_field_to_xml_file('ModelWeatherFileCity', wf.city)
  add_user_defined_field_to_xml_file('ModelWeatherFileStateProvinceRegion', wf.stateProvinceRegion)
  add_user_defined_field_to_xml_file('ModelWeatherFileLatitude', wf.latitude)
  add_user_defined_field_to_xml_file('ModelWeatherFileLongitude', wf.longitude)
  prepare_final_xml_for_spatial_element
end

#read_other_building_detailsObject

read other building details



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/buildingsync/model_articulation/building.rb', line 291

def read_other_building_details
  if @base_xml.elements["#{@ns}:OccupancyLevels/#{@ns}:OccupancyLevel/#{@ns}:OccupantQuantity"]
    @occupant_quantity = @base_xml.elements["#{@ns}:OccupancyLevels/#{@ns}:OccupancyLevel/#{@ns}:OccupantQuantity"].text
  else
    @occupant_quantity = nil
  end

  if @base_xml.elements["#{@ns}:SpatialUnits/#{@ns}:SpatialUnit/#{@ns}:NumberOfUnits"]
    @number_of_units = @base_xml.elements["#{@ns}:SpatialUnits/#{@ns}:SpatialUnit/#{@ns}:NumberOfUnits"].text
  else
    @number_of_units = nil
  end
end

#read_stories_above_and_below_gradeObject

read stories above and below grade



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/buildingsync/model_articulation/building.rb', line 179

def read_stories_above_and_below_grade
  if @base_xml.elements["#{@ns}:FloorsAboveGrade"]
    @num_stories_above_grade = @base_xml.elements["#{@ns}:FloorsAboveGrade"].text.to_f
  elsif @base_xml.elements["#{@ns}:ConditionedFloorsAboveGrade"]
    @num_stories_above_grade = @base_xml.elements["#{@ns}:ConditionedFloorsAboveGrade"].text.to_f
  else
    @num_stories_above_grade = 1.0 # setDefaultValue
  end

  if @base_xml.elements["#{@ns}:FloorsBelowGrade"]
    @num_stories_below_grade = @base_xml.elements["#{@ns}:FloorsBelowGrade"].text.to_f
  elsif @base_xml.elements["#{@ns}:ConditionedFloorsBelowGrade"]
    @num_stories_below_grade = @base_xml.elements["#{@ns}:ConditionedFloorsBelowGrade"].text.to_f
  else
    @num_stories_below_grade = 0.0 # setDefaultValue
  end

  if @num_stories_below_grade > 1.0
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.read_stories_above_and_below_grade', "Number of stories below grade is larger than 1: #{@num_stories_below_grade}, currently only one basement story is supported.")
    raise StandardError, "Building ID: #{xget_id}. Number of stories below grade is > 1 (#{num_stories_below_grade}).  Currently, only one story below grade is supported."
  end
end

#read_xml(site_occupancy_classification, site_total_floor_area) ⇒ Object

read xml

Parameters:

  • site_occupancy_classification (String)
  • site_total_floor_area (String)


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
# File 'lib/buildingsync/model_articulation/building.rb', line 104

def read_xml(site_occupancy_classification, site_total_floor_area)
  # floor areas
  @total_floor_area = read_floor_areas(site_total_floor_area)
  # read location specific values
  read_location_values
  check_occupancy_classification(site_occupancy_classification)
  set_built_year

  # deal with stories above and below grade
  read_stories_above_and_below_grade
  # aspect ratio
  set_ns_to_ew_ratio

  # Create the BuildingSections
  @base_xml.elements.each("#{@ns}:Sections/#{@ns}:Section") do |section_element|
    section = BuildingSection.new(section_element, xget_text('OccupancyClassification'), @total_floor_area, num_stories, @ns)
    if section.section_type == 'Whole building'
      @building_sections_whole_building.push(section)
    elsif section.section_type == 'Space function' || section.section_type.nil?
      @building_sections.push(section)
    else
      puts "Unknown section type found:#{section.section_type}:"
    end
  end

  # generate building name
  read_other_building_details
end

#set_allObject

set all function to set all parameters for this building



134
135
136
137
138
139
140
141
# File 'lib/buildingsync/model_articulation/building.rb', line 134

def set_all
  if !@all_set
    @all_set = true
    set_bldg_and_system_type_for_building_and_section
    set_building_form_defaults
    set_width_and_length
  end
end

#set_bldg_and_system_type_for_building_and_sectionObject

set building and system type for building and sections



384
385
386
387
388
# File 'lib/buildingsync/model_articulation/building.rb', line 384

def set_bldg_and_system_type_for_building_and_section
  @building_sections.each(&:set_bldg_and_system_type)

  set_bldg_and_system_type(xget_text('OccupancyClassification'), @total_floor_area, num_stories, true)
end

#set_building_form_defaultsObject

set aspect ratio, floor height, and WWR



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/buildingsync/model_articulation/building.rb', line 235

def set_building_form_defaults
  # if aspect ratio, story height or wwr have argument value of 0 then use smart building type defaults
  building_form_defaults = building_form_defaults(get_building_type)
  if @ns_to_ew_ratio == 0.0 && !building_form_defaults.nil?
    @ns_to_ew_ratio = building_form_defaults[:aspect_ratio]
    OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_building_form_defaults', "0.0 value for aspect ratio will be replaced with smart default for #{get_building_type} of #{building_form_defaults[:aspect_ratio]}.")
  end
  if @floor_height == 0.0 && !building_form_defaults.nil?
    @floor_height = OpenStudio.convert(building_form_defaults[:typical_story], 'ft', 'm').get
    OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_building_form_defaults', "0.0 value for floor height will be replaced with smart default for #{get_building_type} of #{building_form_defaults[:typical_story]}.")
  end
  # because of this can't set wwr to 0.0. If that is desired then we can change this to check for 1.0 instead of 0.0
  if @wwr == 0.0 && !building_form_defaults.nil?
    @wwr = building_form_defaults[:wwr]
    OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_building_form_defaults', "0.0 value for window to wall ratio will be replaced with smart default for #{get_building_type} of #{building_form_defaults[:wwr]}.")
  end
end

#set_built_yearObject

Set the @built_year based on YearOfConstruction / YearOfLastMajorRemodel



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/buildingsync/model_articulation/building.rb', line 162

def set_built_year
  if !@base_xml.elements["#{@ns}:YearOfConstruction"]
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.read_standard_template_based_on_year', 'Year of Construction is blank in your BuildingSync file.')
    raise StandardError, "Building ID: #{xget_id}. Year of Construction is blank in your BuildingSync file, but is required."
  end

  @built_year = xget_text_as_integer('YearOfConstruction')
  remodel_year = xget_text_as_integer('YearOfLastMajorRemodel')
  if !remodel_year.nil? && remodel_year > @built_year
    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_built_year', "built_year for Standards reset from #{@built_year} (YearOfConstruction) to #{remodel_year} (YearOfLastMajorRemodel).")
    @built_year = remodel_year
  else
    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_built_year', "built_year for Standards set to #{@built_year} (YearOfConstruction).")
  end
end

#set_climate_zone(climate_zone, standard_to_be_used, stat_file = nil) ⇒ Boolean

set climate zone

Parameters:

  • climate_zone (String)
  • standard_to_be_used (String)
  • stat_file (String) (defaults to: nil)

Returns:

  • (Boolean)


662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/buildingsync/model_articulation/building.rb', line 662

def set_climate_zone(climate_zone, standard_to_be_used, stat_file = nil)
  # Set climate zone
  if climate_zone.nil?
    OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_climate_zone', 'Climate Zone is nil, trying to get it from stat file')
    # get climate zone from stat file
    text = nil
    File.open(stat_file) do |f|
      text = f.read.force_encoding('iso-8859-1')
    end

    # Get Climate zone.
    # - Climate type "3B" (ASHRAE Standard 196-2006 Climate Zone)**
    # - Climate type "6A" (ASHRAE Standards 90.1-2004 and 90.2-2004 Climate Zone)**
    regex = /Climate type \"(.*?)\" \(ASHRAE Standards?(.*)\)\*\*/
    match_data = text.match(regex)
    if match_data.nil?
      OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_climate_zone', "Can't find ASHRAE climate zone in stat file.")
    else
      climate_zone = match_data[1].to_s.strip
    end
  end

  climate_zones = @model.getClimateZones
  # set climate zone
  climate_zones.clear
  if standard_to_be_used == ASHRAE90_1 && !climate_zone.nil?
    climate_zones.setClimateZone('ASHRAE', climate_zone)
    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_climate_zone', "Setting Climate Zone to #{climate_zones.getClimateZones('ASHRAE').first.value}")
    puts "setting ASHRAE climate zone to: #{climate_zone}"
    return true
  elsif standard_to_be_used == CA_TITLE24 && !climate_zone.nil?
    climate_zone = climate_zone.gsub('CEC', '').strip
    climate_zone = climate_zone.gsub('Climate Zone', '').strip
    climate_zone = climate_zone.delete('A').strip
    climate_zone = climate_zone.delete('B').strip
    climate_zone = climate_zone.delete('C').strip
    climate_zones.setClimateZone('CEC', climate_zone)
    OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_climate_zone', "Setting Climate Zone to #{climate_zone}")
    puts "setting CA_TITLE24 climate zone to: #{climate_zone}"
    return true
  end
  puts "could not set climate_zone #{climate_zone}"
  OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_climate_zone', "Cannot set the #{climate_zone} in context of this standard #{standard_to_be_used}")
  return false
end

#set_ns_to_ew_ratioObject

Set the @ns_to_ew_ratio parameter using the AspectRatio element if present



203
204
205
206
207
208
209
# File 'lib/buildingsync/model_articulation/building.rb', line 203

def set_ns_to_ew_ratio
  if @base_xml.elements["#{@ns}:AspectRatio"]
    @ns_to_ew_ratio = xget_text_as_float('AspectRatio')
  else
    @ns_to_ew_ratio = 0.0 # setDefaultValue
  end
end

#set_standard_template(standard_to_be_used, built_year) ⇒ Object

set standard template

Parameters:

  • standard_to_be_used (String)
  • built_year (Integer)


429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/buildingsync/model_articulation/building.rb', line 429

def set_standard_template(standard_to_be_used, built_year)
  if standard_to_be_used == CA_TITLE24
    if built_year < 1978
      @standard_template = 'CBES Pre-1978'
    elsif built_year >= 1978 && built_year < 1992
      @standard_template = 'CBES T24 1978'
    elsif built_year >= 1992 && built_year < 2001
      @standard_template = 'CBES T24 1992'
    elsif built_year >= 2001 && built_year < 2005
      @standard_template = 'CBES T24 2001'
    elsif built_year >= 2005 && built_year < 2008
      @standard_template = 'CBES T24 2005'
    else
      @standard_template = 'CBES T24 2008'
    end
  elsif standard_to_be_used == ASHRAE90_1
    if built_year < 1980
      @standard_template = 'DOE Ref Pre-1980'
    elsif built_year >= 1980 && built_year < 2004
      @standard_template = 'DOE Ref 1980-2004'
    elsif built_year >= 2004 && built_year < 2007
      @standard_template = '90.1-2004'
    elsif built_year >= 2007 && built_year < 2010
      @standard_template = '90.1-2007'
    elsif built_year >= 2010 && built_year < 2013
      @standard_template = '90.1-2010'
    elsif built_year >= 2013
      @standard_template = '90.1-2013'
    end
    # TODO: add ASHRAE 2016 once it is available
  else
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.get_standard_template', "Unknown standard_to_be_used #{standard_to_be_used}.")
    raise StandardError, "BuildingSync.Building.get_standard_template: Unknown standard_to_be_used #{standard_to_be_used}."
  end
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.get_standard_template', "Using the following standard for default values #{@standard_template}.")
end

#set_weather_and_climate_zone(climate_zone, epw_file_path, standard_to_be_used, latitude, longitude, ddy_file, *weather_argb) ⇒ Object

set weather file and climate zone

Parameters:

  • climate_zone (String)
  • epw_file_path (String)
  • standard_to_be_used (String)
  • latitude (String)
  • longitude (String)
  • ddy_file (String)
  • weather_argb (array)


545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/buildingsync/model_articulation/building.rb', line 545

def set_weather_and_climate_zone(climate_zone, epw_file_path, standard_to_be_used, latitude, longitude, ddy_file, *weather_argb)
  initialize_model

  determine_climate_zone(standard_to_be_used) if climate_zone.nil?

  # here we check if there is an valid EPW file, if there is we use that file otherwise everything will be generated from climate zone
  if !epw_file_path.nil? && File.exist?(epw_file_path)
    @epw_file_path = epw_file_path
    puts "case 1: epw file exists #{epw_file_path} and climate_zone is: #{climate_zone}"
    set_weather_and_climate_zone_from_epw(climate_zone, standard_to_be_used, latitude, longitude, ddy_file)
  elsif climate_zone.nil? && @climate_zone.nil?
    weather_station_id = weather_argb[1]
    state_name = weather_argb[2]
    city_name = weather_argb[3]
    puts 'case 2: climate_zone is nil at the Site and Building level'
    if !weather_station_id.nil?
      puts "case 2.1: weather_station_id is not nil #{weather_station_id}"
      @epw_file_path = BuildingSync::GetBCLWeatherFile.new.download_weather_file_from_weather_id(weather_station_id)
    elsif !city_name.nil? && !state_name.nil?
      puts "case 2.2: SITE LEVEL city_name and state_name is not nil #{city_name} #{state_name}"
      @epw_file_path = BuildingSync::GetBCLWeatherFile.new.download_weather_file_from_city_name(state_name, city_name)
    elsif !@city_name.nil? && !@state_name.nil?
      puts "case 2.3: BUILDING LEVEL city_name and state_name is not nil #{@city_name} #{@state_name}"
      @epw_file_path = BuildingSync::GetBCLWeatherFile.new.download_weather_file_from_city_name(@state_name, @city_name)
    end

  else
    puts "case 3: SITE LEVEL climate zone #{climate_zone} BUILDING LEVEL climate zone #{@climate_zone}."
    puts "lat #{latitude} long #{longitude}"
    if climate_zone.nil?
      climate_zone = @climate_zone
      puts "Climate Zone set at the Building level: #{climate_zone}"
    else
      puts "Climate Zone set at the Site level: #{climate_zone}"
    end
    @epw_file_path = set_weather_and_climate_zone_from_climate_zone(climate_zone, standard_to_be_used, latitude, longitude)
    @epw_file_path = @epw_file_path.to_s
  end

  # Ensure a file path gets set, else raise error
  if @epw_file_path.nil?
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.set_weather_and_climate_zone', 'epw_file_path is nil and no way to set from Site or Building parameters.')
    raise StandardError, 'BuildingSync.Building.set_weather_and_climate_zone: epw_file_path is nil and no way to set from Site or Building parameters.'
  elsif !@epw_file_path
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.set_weather_and_climate_zone', "epw_file_path is false: #{@epw_file_path}")
    raise StandardError, "BuildingSync.Building.set_weather_and_climate_zone: epw_file_path is false: #{@epw_file_path}"
  elsif !File.exist?(@epw_file_path)
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.set_weather_and_climate_zone', "epw_file_path does not exist: #{@epw_file_path}")
    raise StandardError, "BuildingSync.Building.set_weather_and_climate_zone: epw_file_path does not exist: #{@epw_file_path}"
  end

  # setting the current year, so we do not get these annoying log messages:
  # [openstudio.model.YearDescription] <1> 'UseWeatherFile' is not yet a supported option for YearDescription
  year_description = @model.getYearDescription
  year_description.setCalendarYear(::Date.today.year)

  # add final condition
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_weather_and_climate_zone', "The final weather file is #{@model.getWeatherFile.city} and the model has #{@model.getDesignDays.size} design day objects.")
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_weather_and_climate_zone', "The path to the epw file is: #{@epw_file_path}")
end

#set_weather_and_climate_zone_from_climate_zone(climate_zone, standard_to_be_used, latitude, longitude) ⇒ Object

set weather file and climate zone from climate zone

Parameters:

  • climate_zone (String)
  • standard_to_be_used (String)
  • latitude (String)
  • longitude (String)


611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'lib/buildingsync/model_articulation/building.rb', line 611

def set_weather_and_climate_zone_from_climate_zone(climate_zone, standard_to_be_used, latitude, longitude)
  OpenStudio.logFree(OpenStudio::Warn, 'BuildingSync.Building.set_weather_and_climate_zone_from_climate_zone', "Cannot add design days and weather file for climate zone: #{climate_zone}, no epw file provided")
  climate_zone_standard_string = climate_zone
  puts climate_zone
  puts standard_to_be_used
  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_weather_and_climate_zone_from_climate_zone', "climate zone: #{climate_zone}")
  if standard_to_be_used == CA_TITLE24 && !climate_zone.nil?
    climate_zone_standard_string = "CEC T24-CEC#{climate_zone.gsub('Climate Zone', '').strip}"
  elsif standard_to_be_used == ASHRAE90_1 && !climate_zone.nil?
    climate_zone_standard_string = "ASHRAE 169-2006-#{climate_zone.gsub('Climate Zone', '').strip}"
  elsif climate_zone.nil?
    climate_zone_standard_string = ''
  end

  puts @open_studio_standard
  puts @open_studio_standard.class
  puts climate_zone_standard_string

  # set the model's weather file
  begin
    # Note: in future open_studio_standard verisions, model_add_design_days_and_weather_file is replaced with
    # model_set_building_location. I do not know if it's on purpose, but both can "fail" (return False), or error out
    successfully_set_weather_file = @open_studio_standard.model_add_design_days_and_weather_file(@model, climate_zone_standard_string, nil)
  rescue
    raise StandardError, "Could not set weather file because climate zone '#{climate_zone_standard_string}' is not in default weather map."
  end

  # overwrite latitude and longitude if available
  if !latitude.nil? || !longitude.nil?
    site = @model.getSite
    if !latitude.nil?
      site.setLatitude(latitude.to_f)
    end
    if !longitude.nil?
      site.setLongitude(longitude.to_f)
    end
  end

  weather_file = @model.getWeatherFile

  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_weather_and_climate_zone_from_climate_zone', "city is #{weather_file.city}. State is #{weather_file.stateProvinceRegion}")

  set_climate_zone(climate_zone, standard_to_be_used)
  return weather_file.path.get
end

#set_weather_and_climate_zone_from_epw(climate_zone, standard_to_be_used, latitude, longitude, ddy_file = nil) ⇒ Object

set weather file and climate zone from EPW file

Parameters:

  • climate_zone (String)
  • standard_to_be_used (String)
  • latitude (String)
  • longitude (String)
  • ddy_file (String) (defaults to: nil)


714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/buildingsync/model_articulation/building.rb', line 714

def set_weather_and_climate_zone_from_epw(climate_zone, standard_to_be_used, latitude, longitude, ddy_file = nil)
  epw_file = OpenStudio::EpwFile.new(@epw_file_path)

  weather_lat = epw_file.latitude
  if !latitude.nil?
    weather_lat = latitude.to_f
  end
  weather_lon = epw_file.longitude
  if !longitude.nil?
    weather_lon = longitude.to_f
  end

  weather_file = @model.getWeatherFile
  weather_file.setCity(epw_file.city)
  weather_file.setStateProvinceRegion(epw_file.stateProvinceRegion)
  weather_file.setCountry(epw_file.country)
  weather_file.setDataSource(epw_file.dataSource)
  weather_file.setWMONumber(epw_file.wmoNumber.to_s)
  weather_file.setLatitude(weather_lat)
  weather_file.setLongitude(weather_lon)
  weather_file.setTimeZone(epw_file.timeZone)
  weather_file.setElevation(epw_file.elevation)
  weather_file.setString(10, epw_file.path.to_s)

  weather_name = "#{epw_file.city}_#{epw_file.stateProvinceRegion}_#{epw_file.country}"
  weather_time = epw_file.timeZone
  weather_elev = epw_file.elevation

  # Add or update site data
  site = @model.getSite
  site.setName(weather_name)
  site.setLatitude(weather_lat)
  site.setLongitude(weather_lon)
  site.setTimeZone(weather_time)
  site.setElevation(weather_elev)

  OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_weather_and_climate_zone_from_epw', "city is #{epw_file.city}. State is #{epw_file.stateProvinceRegion}")

  stat_file = get_stat_file(epw_file)
  add_site_water_mains_temperature(stat_file) if !stat_file.nil?

  set_climate_zone(climate_zone, standard_to_be_used, stat_file)

  # Remove all the Design Day objects that are in the file
  @model.getObjectsByType('OS:SizingPeriod:DesignDay'.to_IddObjectType).each(&:remove)

  # find the ddy files
  ddy_file = "#{File.join(File.dirname(epw_file.path.to_s), File.basename(epw_file.path.to_s, '.*'))}.ddy" if ddy_file.nil?
  unless File.exist? ddy_file
    ddy_files = Dir["#{File.dirname(epw_file.path.to_s)}/*.ddy"]
    if ddy_files.size > 1
      OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.set_weather_and_climate_zone_from_epw', 'More than one ddy file in the EPW directory')
      return false
    end
    if ddy_files.empty?
      OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.set_weather_and_climate_zone_from_epw', 'could not find the ddy file in the EPW directory')
      return false
    end

    ddy_file = ddy_files.first
  end

  unless ddy_file
    runner.registerError "Could not find DDY file for #{ddy_file}"
    return error
  end

  ddy_model = OpenStudio::EnergyPlus.loadAndTranslateIdf(ddy_file).get
  ddy_model.getObjectsByType('OS:SizingPeriod:DesignDay'.to_IddObjectType).each do |d|
    # grab only the ones that matter
    ddy_list = /(Htg 99.6. Condns DB)|(Clg .4. Condns WB=>MDB)|(Clg .4% Condns DB=>MWB)/
    if d.name.get.match?(ddy_list)
      OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Building.set_weather_and_climate_zone_from_epw', "Adding object #{d.name}")

      # add the object to the existing model
      @model.addObject(d.clone)
    end
  end
end

#set_width_and_lengthObject

set width and length of the building footprint



144
145
146
147
148
# File 'lib/buildingsync/model_articulation/building.rb', line 144

def set_width_and_length
  footprint = @total_floor_area / num_stories.to_f
  @width = Math.sqrt(footprint / @ns_to_ew_ratio)
  @length = footprint / @width
end

#update_nameObject

update the name of the building



415
416
417
418
419
420
421
422
423
424
# File 'lib/buildingsync/model_articulation/building.rb', line 415

def update_name
  # update the name so it includes the standard_template string
  name_array = [@standard_template]
  name_array << get_building_type
  @building_sections.each do |bld_tp|
    name_array << bld_tp.standards_building_type
  end
  name_array << @name if !@name.nil? && !@name == ''
  @name = name_array.join('|').to_s
end

#write_osm(dir) ⇒ Object

write baseline model to osm file

Parameters:

  • dir (String)


1054
1055
1056
# File 'lib/buildingsync/model_articulation/building.rb', line 1054

def write_osm(dir)
  @model.save("#{dir}/in.osm", true)
end