Class: BTAP::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/btap/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, prototype_creator) ⇒ Attributes

Returns a new instance of Attributes.



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
# File 'lib/openstudio-standards/btap/attributes.rb', line 46

def initialize(model, prototype_creator)
  @model             = model
  @prototype_creator = prototype_creator
  @costing_database  = CostingDatabase.instance

  # Surfaces considered for envelope costing and carbon.

  @surface_types = [ 
    "ExteriorWall",
    "ExteriorRoof",
    "ExteriorFloor",
    "ExteriorFixedWindow",
    "ExteriorOperableWindow",
    "ExteriorSkylight",
    "ExteriorTubularDaylightDiffuser",
    "ExteriorTubularDaylightDome",
    "ExteriorDoor",
    "ExteriorGlassDoor",
    "ExteriorOverheadDoor",
    "GroundContactWall",
    "GroundContactRoof",
    "GroundContactFloor"
  ]

  @zones  = [] 
  @spaces = [] 

  self.compile
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



41
42
43
# File 'lib/openstudio-standards/btap/attributes.rb', line 41

def model
  @model
end

#spacesObject (readonly)

Returns the value of attribute spaces.



43
44
45
# File 'lib/openstudio-standards/btap/attributes.rb', line 43

def spaces
  @spaces
end

#surface_typesObject (readonly)

Returns the value of attribute surface_types.



44
45
46
# File 'lib/openstudio-standards/btap/attributes.rb', line 44

def surface_types
  @surface_types
end

#zonesObject (readonly)

Returns the value of attribute zones.



42
43
44
# File 'lib/openstudio-standards/btap/attributes.rb', line 42

def zones
  @zones
end

Instance Method Details

#compileObject

Compile all the pertinent data into the data structures of this class while also appending to the exisitng OpenStudio ones.



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
# File 'lib/openstudio-standards/btap/attributes.rb', line 77

def compile
  template_type = @prototype_creator.template
  num_of_above_ground_stories = @model.getBuilding.standardsNumberOfAboveGroundStories.to_i
  
  # Iterate through the data structures while also saving their sorted order later for reference.

  @model.instance_variable_set(:@zones_sorted, [])

  @model.getThermalZones.sort.each do |zone|
    @model << zone
    @zones << zone
    zone.instance_variable_set(:@spaces_sorted, [])

    zone.spaces.sort.each do |space|
      if space.spaceType.empty? or space.spaceType.get.standardsSpaceType.empty? or space.spaceType.get.standardsBuildingType.empty?
        raise ("standards Space type and building type is not defined for space:#{space.name.get}. Skipping this space.")
      end
      zone    << space
      @spaces << space

      space_type    = space.spaceType.get.standardsSpaceType
      building_type = space.spaceType.get.standardsBuildingType

      # Compile a list of construction sets for each space.

      construction_set = @costing_database["raw"]["construction_sets"].select { |data|
        data["template"].to_s.gsub(/\s*/, "") == template_type               and
        data["building_type"].to_s.downcase   == building_type.to_s.downcase and
        data["space_type"].to_s.downcase      == space_type.to_s.downcase    and
        data["min_stories"].to_i              <= num_of_above_ground_stories and
        data["max_stories"].to_i              >= num_of_above_ground_stories
      }.first
      space.instance_variable_set(:@construction_set, construction_set)
      
      surfaces_hash = {}

      # Exterior

      exterior_surfaces = BTAP::Geometry::Surfaces::filter_by_boundary_condition(space.surfaces, "Outdoors")
      surfaces_hash["ExteriorWall"]  = BTAP::Geometry::Surfaces::filter_by_surface_types(exterior_surfaces, "Wall").sort
      surfaces_hash["ExteriorRoof"]  = BTAP::Geometry::Surfaces::filter_by_surface_types(exterior_surfaces, "RoofCeiling").sort
      surfaces_hash["ExteriorFloor"] = BTAP::Geometry::Surfaces::filter_by_surface_types(exterior_surfaces, "Floor").sort

      # Exterior Subsurfaces

      exterior_subsurfaces = exterior_surfaces.flat_map(&:subSurfaces)
      surfaces_hash["ExteriorFixedWindow"]             = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["FixedWindow"]).sort
      surfaces_hash["ExteriorOperableWindow"]          = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["OperableWindow"]).sort
      surfaces_hash["ExteriorSkylight"]                = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["Skylight"]).sort
      surfaces_hash["ExteriorTubularDaylightDiffuser"] = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["TubularDaylightDiffuser"]).sort
      surfaces_hash["ExteriorTubularDaylightDome"]     = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["TubularDaylightDome"]).sort
      surfaces_hash["ExteriorDoor"]                    = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["Door"]).sort
      surfaces_hash["ExteriorGlassDoor"]               = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["GlassDoor"]).sort
      surfaces_hash["ExteriorOverheadDoor"]            = BTAP::Geometry::Surfaces::filter_subsurfaces_by_types(exterior_subsurfaces, ["OverheadDoor"]).sort

      # Ground Surfaces

      ground_surfaces  = BTAP::Geometry::Surfaces::filter_by_boundary_condition(space.surfaces, "Ground")
      ground_surfaces += BTAP::Geometry::Surfaces::filter_by_boundary_condition(space.surfaces, "Foundation")
      surfaces_hash["GroundContactWall"]  = BTAP::Geometry::Surfaces::filter_by_surface_types(ground_surfaces, "Wall").sort
      surfaces_hash["GroundContactRoof"]  = BTAP::Geometry::Surfaces::filter_by_surface_types(ground_surfaces, "RoofCeiling").sort
      surfaces_hash["GroundContactFloor"] = BTAP::Geometry::Surfaces::filter_by_surface_types(ground_surfaces, "Floor").sort

      space.instance_variable_set(:@surfaces_hash, surfaces_hash)

      if construction_set.nil?
        next
      end

      @surface_types.each do |surface_type|
        space.surfaces_hash[surface_type].each do |surface|

          # Search for a matching opaque or glazing construction and append the type to the hash.

          construction_hash = @costing_database["raw"]["constructions_opaque"].find { |construction|
            construction["construction_type_name"] == construction_set[surface_type]
          }
          if not construction_hash.nil?
            construction_hash["type"] = "opaque"
            surface.instance_variable_set(:@construction_hash, construction_hash)
          else
            construction_hash = @costing_database["raw"]["constructions_glazing"].find { |construction|
              construction["construction_type_name"] == construction_set[surface_type]
            }
            if not construction_hash.nil?
              construction_hash["type"] = "glazing"
              surface.instance_variable_set(:@construction_hash, construction_hash)
            end
          end
        end
      end
    end
  end
end