Class: UrbanGeometryCreation
- Inherits:
-
OpenStudio::Measure::ModelMeasure
- Object
- OpenStudio::Measure::ModelMeasure
- UrbanGeometryCreation
- Defined in:
- lib/measures/urban_geometry_creation/measure.rb
Overview
start the measure
Instance Attribute Summary collapse
-
#origin_lat_lon ⇒ Object
Returns the value of attribute origin_lat_lon.
Instance Method Summary collapse
- #arguments(model) ⇒ Object
-
#description ⇒ Object
human readable description.
-
#modeler_description ⇒ Object
human readable description of modeling approach.
-
#name ⇒ Object
human readable name.
-
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run.
Instance Attribute Details
#origin_lat_lon ⇒ Object
Returns the value of attribute origin_lat_lon.
15 16 17 |
# File 'lib/measures/urban_geometry_creation/measure.rb', line 15 def origin_lat_lon @origin_lat_lon end |
Instance Method Details
#arguments(model) ⇒ Object
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 |
# File 'lib/measures/urban_geometry_creation/measure.rb', line 32 def arguments(model) args = OpenStudio::Measure::OSArgumentVector.new # geojson file geojson_file = OpenStudio::Measure::OSArgument.makeStringArgument('geojson_file', true) geojson_file.setDisplayName('GeoJSON File') geojson_file.setDescription('GeoJSON File.') args << geojson_file # feature id of the building to create feature_id = OpenStudio::Measure::OSArgument.makeStringArgument('feature_id', true) feature_id.setDisplayName('Feature ID') feature_id.setDescription('Feature ID.') args << feature_id # which surrounding buildings to include chs = OpenStudio::StringVector.new chs << 'None' chs << 'ShadingOnly' surrounding_buildings = OpenStudio::Measure::OSArgument.makeChoiceArgument('surrounding_buildings', chs, true) surrounding_buildings.setDisplayName('Surrounding Buildings') surrounding_buildings.setDescription('Select which surrounding buildings to include.') surrounding_buildings.setDefaultValue('ShadingOnly') args << surrounding_buildings # not a required argument scale_footprint_area_by_floor_area = OpenStudio::Measure::OSArgument.makeBoolArgument('scale_footprint_area_by_floor_area', false) scale_footprint_area_by_floor_area.setDisplayName('Scale Footprint Area by the Floor Area') scale_footprint_area_by_floor_area.setDescription('If true, the footprint area from GeoJSON will be scaled by the floor_area provided by the user in URBANopt.') scale_footprint_area_by_floor_area.setDefaultValue(false) args << scale_footprint_area_by_floor_area return args end |
#description ⇒ Object
human readable description
23 24 25 |
# File 'lib/measures/urban_geometry_creation/measure.rb', line 23 def description return 'This measure reads an URBANopt GeoJSON and creates geometry for a particular building. Surrounding buildings are included as shading structures.' end |
#modeler_description ⇒ Object
human readable description of modeling approach
28 29 30 |
# File 'lib/measures/urban_geometry_creation/measure.rb', line 28 def modeler_description return 'This measure takes in the GeoJSON file, the feature_id of the building and the surrounding buildings as arguments and add has methods to create space types and add default construction sets.' end |
#name ⇒ Object
human readable name
18 19 20 |
# File 'lib/measures/urban_geometry_creation/measure.rb', line 18 def name return 'UrbanGeometryCreation' end |
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run
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 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 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/measures/urban_geometry_creation/measure.rb', line 63 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 geojson_file = runner.getStringArgumentValue('geojson_file', user_arguments) feature_id = runner.getStringArgumentValue('feature_id', user_arguments) surrounding_buildings = runner.getStringArgumentValue('surrounding_buildings', user_arguments) scale_footprint_area_by_floor_area = runner.getBoolArgumentValue('scale_footprint_area_by_floor_area', user_arguments) default_construction_set = URBANopt::GeoJSON::Model.create_construction_set(model, runner) stories = [] model.getBuildingStorys.each { |story| stories << story } stories.sort! { |x, y| x.nominalZCoordinate.to_s.to_f <=> y.nominalZCoordinate.to_s.to_f } space_types = URBANopt::GeoJSON::Helper.create_space_types(stories, model, runner) # delete the previous building model.getBuilding.remove # create new building and transfer default construction set model.getBuilding.setDefaultConstructionSet(default_construction_set) # instance variables @runner = runner @origin_lat_lon = nil all_features = URBANopt::GeoJSON::GeoFile.from_file(geojson_file) feature = all_features.get_feature_by_id(feature_id) # EXPOSE NAME name = feature.feature_json[:properties][:name] model.getBuilding.setName(name) # find min and max x coordinate @origin_lat_lon = feature.create_origin_lat_lon(@runner) site = model.getSite site.setLatitude(@origin_lat_lon.lat) site.setLongitude(@origin_lat_lon.lon) begin surface_elevation = feature.surface_elevation.to_f surface_elevation = OpenStudio.convert(surface_elevation, 'ft', 'm').get site.setElevation(surface_elevation) rescue StandardError @runner.registerWarning("Surface elevation not set for building '#{name}'") end case feature.type when 'Building' # make requested building # pass in scaled_footprint_area (calculated from floor_area / number_of_stories) scaled_footprint_area = 0 if scale_footprint_area_by_floor_area building_hash = feature.to_hash if building_hash[:number_of_stories] && building_hash[:floor_area] scaled_footprint_area = building_hash[:floor_area].to_f / building_hash[:number_of_stories].to_f @runner.registerInfo("Desired footprint area in ft2: #{scaled_footprint_area}") end end spaces = feature.create_building(:space_per_floor, model, @origin_lat_lon, @runner, false, scaled_footprint_area) if spaces.nil? @runner.registerError("Failed to create spaces for building '#{name}'") return false end # DLM: temp hack building_type = feature.building_type if building_type == 'Vacant' shading_surfaces = URBANopt::GeoJSON::Helper.create_shading_surfaces(feature, model, @origin_lat_lon, @runner, spaces) end # make other buildings to convert to shading convert_to_shades = [] if surrounding_buildings == 'ShadingOnly' convert_to_shades = feature.create_other_buildings(surrounding_buildings, all_features.json, model, @origin_lat_lon, @runner) end # intersect surfaces in this building with others @runner.registerInfo('Intersecting surfaces') spaces.each do |space| convert_to_shades.each do |other_space| space.intersectSurfaces(other_space) end end # match surfaces @runner.registerInfo('Matching surfaces') all_spaces = OpenStudio::Model::SpaceVector.new model.getSpaces.each do |space| all_spaces << space end OpenStudio::Model.matchSurfaces(all_spaces) # make windows spaces = feature.create_windows(spaces) # change adjacent surfaces to adiabatic model = URBANopt::GeoJSON::Model.change_adjacent_surfaces_to_adiabatic(model, @runner) # convert other buildings to shading surfaces convert_to_shades.map do |space| URBANopt::GeoJSON::Helper.convert_to_shading_surface_group(space) end when 'District System' district_system_type = feature[:properties][:district_system_type] if district_system_type == 'Community Photovoltaic' shading_surfaces = URBANopt::GeoJSON::Helper.create_photovoltaics(feature, 0, model, @origin_lat_lon, @runner) end else @runner.registerError("Unknown feature type '#{feature.type}'") return false end # transfer data from previous model stories = URBANopt::GeoJSON::Model.transfer_prev_model_data(model, space_types) return true end |