Class: BTAP::EQuest::DOEBuilding
- Inherits:
-
Object
- Object
- BTAP::EQuest::DOEBuilding
- Defined in:
- lib/openstudio-standards/btap/equest.rb
Overview
This is the main interface dealing with DOE inp files. You can load, save manipulate doe files with this interface at a command level.
Instance Attribute Summary collapse
-
#commands ⇒ Object
An array to contain all the DOE.
-
#parents ⇒ Object
An array to contain the current parent when reading in the input files.
Instance Method Summary collapse
-
#clone ⇒ Object
This method makes a deep copy of the building object.
-
#create_openstudio_model_new(runner = nil) ⇒ Object
this method will convert a DOE inp file to the OSM file..
-
#determine_current_parents(new_command) ⇒ Object
set_envelope_hierarchy This method determines the current parents of the current command.
-
#find_all_commands(sCOMMAND) ⇒ Object
This method will find all Commands given the command name string.
-
#find_all_regex(sCOMMAND) ⇒ Object
Same as find_all_commands except you can use regular expressions.
-
#find_command_with_utype(utype) ⇒ Object
This method will find all Commands given the command name string.
- #get_building_transformation_matrix ⇒ Object
- #get_materials ⇒ Object
-
#initialize ⇒ DOEBuilding
constructor
The Constructor.
-
#load_inp(filename, runner = nil) ⇒ Object
Will read an input file into memory and store all the commands into the commands array.
-
#organize_data ⇒ Object
This routine organizes the hierarchy of the space <-> zones and the polygon associations that are not formally identified by the sequential relationship like the floor, walls, windows.
-
#save_inp(string) ⇒ Object
This will right a clean output file, meaning no comments.
-
#search_by_keyword_value(keyword, value) ⇒ Object
Find a matching keyword value pair in from an array of commands.
Constructor Details
#initialize ⇒ DOEBuilding
The Constructor.
1999 2000 2001 2002 2003 2004 2005 |
# File 'lib/openstudio-standards/btap/equest.rb', line 1999 def initialize @commands=[] @parents=[] @commandList = Array.new() end |
Instance Attribute Details
#commands ⇒ Object
An array to contain all the DOE
1988 1989 1990 |
# File 'lib/openstudio-standards/btap/equest.rb', line 1988 def commands @commands end |
#parents ⇒ Object
An array to contain the current parent when reading in the input files.
1990 1991 1992 |
# File 'lib/openstudio-standards/btap/equest.rb', line 1990 def parents @parents end |
Instance Method Details
#clone ⇒ Object
This method makes a deep copy of the building object.
1994 1995 1996 |
# File 'lib/openstudio-standards/btap/equest.rb', line 1994 def clone return Marshal::load(Marshal.dump(self)) end |
#create_openstudio_model_new(runner = nil) ⇒ Object
this method will convert a DOE inp file to the OSM file.. This will return and openstudio model object.
2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2272 def create_openstudio_model_new(runner = nil) beginning_time = Time.now end_time = Time.now BTAP::runner_register("Info", "Time elapsed #{(end_time - beginning_time)*1000} milliseconds",runner) model = OpenStudio::Model::Model.new() #add All Materials # find_all_commands( "Materials" ).each do |doe_material| # end # # find_all_commands( "Constructions" ).each do |doe_cons| # end #this block will create OS story objects in the OS model. BTAP::runner_register("Info", "Exporting DOE FLOORS to OS",runner) find_all_commands("FLOOR").each do |doe_floor| doe_floor.convert_to_openstudio(model) end BTAP::runner_register("Info", OpenStudio::Model::getBuildingStorys(model).size.to_s + " floors created",runner) #this block will create OS space objects in the OS model. BTAP::runner_register("Info", "Exporting DOE SPACES to OS",runner) find_all_commands("SPACE").each do |doe_space| doe_space.convert_to_openstudio(model) end BTAP::runner_register("Info", OpenStudio::Model::getSpaces(model).size.to_s + " spaces created",runner) #this block will create OS space objects in the OS model. BTAP::runner_register("Info", "Exporting DOE ZONES to OS",runner) find_all_commands("ZONE").each do |doe_zone| doe_zone.convert_to_openstudio(model) end BTAP::runner_register("Info", OpenStudio::Model::getThermalZones(model).size.to_s + " zones created",runner) #this block will create OS surface objects in the OS model. BTAP::runner_register("Info", "Exporting DOE Surfaces to OS",runner) all_surfaces = Array.new() @commands.each do |command| case command.commandName when "EXTERIOR-WALL","INTERIOR-WALL","UNDERGROUND-WALL","ROOF" all_surfaces.push(command) end end all_surfaces.each do |doe_surface| doe_surface.convert_to_openstudio(model) end BTAP::runner_register("Info", OpenStudio::Model::getSurfaces(model).size.to_s + " surfaces created",runner) BTAP::runner_register("Info", OpenStudio::Model::getSubSurfaces(model).size.to_s + " sub_surfaces created",runner) BTAP::runner_register("Info", "Setting Boundary Conditions for surfaces",runner) BTAP::Geometry::match_surfaces(model) x_scale = y_scale = z_scale = 0.3048 BTAP::runner_register("Info", "scaling model from feet to meters",runner) model.getPlanarSurfaces.sort.each do |surface| new_vertices = OpenStudio::Point3dVector.new surface.vertices.each do |vertex| new_vertices << OpenStudio::Point3d.new(vertex.x * x_scale, vertex.y * y_scale, vertex.z * z_scale) end surface.setVertices(new_vertices) end model.getPlanarSurfaceGroups.sort.each do |surface_group| transformation = surface_group.transformation translation = transformation.translation euler_angles = transformation.eulerAngles new_translation = OpenStudio::Vector3d.new(translation.x * x_scale, translation.y * y_scale, translation.z * z_scale) #TODO these might be in the wrong order new_transformation = OpenStudio::createRotation(euler_angles) * OpenStudio::createTranslation(new_translation) surface_group.setTransformation(new_transformation) end BTAP::runner_register("Info", "DOE2.2 -> OS Geometry Conversion Complete",runner) BTAP::runner_register("Info", "Summary of Conversion",runner) BTAP::runner_register("Info", OpenStudio::Model::getBuildingStorys(model).size.to_s + " floors created",runner) BTAP::runner_register("Info", OpenStudio::Model::getSpaces(model).size.to_s + " spaces created",runner) BTAP::runner_register("Info", OpenStudio::Model::getThermalZones(model).size.to_s + " thermal zones created",runner) BTAP::runner_register("Info", OpenStudio::Model::getSurfaces(model).size.to_s + " surfaces created",runner) BTAP::runner_register("Info", OpenStudio::Model::getSubSurfaces(model).size.to_s + " sub_surfaces created",runner) BTAP::runner_register("Info", "No Contruction were converted.",runner) BTAP::runner_register("Info", "No Materials were converted",runner) BTAP::runner_register("Info", "No HVAC components were converted",runner) BTAP::runner_register("Info", "No Environment or Simulation setting were converted.",runner) end_time = Time.now BTAP::runner_register("Info", "Time elapsed #{(end_time - beginning_time)} seconds",runner) return model end |
#determine_current_parents(new_command) ⇒ Object
set_envelope_hierarchy This method determines the current parents of the current command.
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2144 def determine_current_parents(new_command) if @last_command.nil? @last_command = new_command end #Check to see if scope (HVAC versus Envelope) has changed or the parent depth is undefined "0" if (!@parents.empty? and (new_command.doe_scope != @parents.last.doe_scope or new_command.depth == 0 )) @parents.clear end #no change in parent. if ( (new_command.depth == @last_command.depth)) #no change @last_command = new_command #puts "#{new_command.commandName}" end #Parent depth added if ( new_command.depth > @last_command.depth) @parents.push(@last_command) #puts "Added parent#{@last_command.commandName}" @last_command = new_command end #parent depth removed. if ( new_command.depth < @last_command.depth) parent = @parents.pop #puts "Removed parent #{parent}" @last_command = new_command end array = Array.new(@parents) return array end |
#find_all_commands(sCOMMAND) ⇒ Object
This method will find all Commands given the command name string. Example def find_all_Command(“ZONE”) will return an array of all the ZONE commands used in the building.
2011 2012 2013 2014 2015 2016 2017 2018 2019 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2011 def find_all_commands (sCOMMAND) array = Array.new() @commands.each do |command| if (command.commandName == sCOMMAND) array.push(command) end end return array end |
#find_all_regex(sCOMMAND) ⇒ Object
Same as find_all_commands except you can use regular expressions.
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2037 def find_all_regex(sCOMMAND) array = Array.new() search =/#{sCOMMAND}/ @commands.each do |command| if (command.commandName.match(search) ) array.push(command) end end return array end |
#find_command_with_utype(utype) ⇒ Object
This method will find all Commands given the command name string. Example def find_all_Command(“Default Construction”) will return an array of all the commands with “Default Construction” as the u-type used in the building.
2025 2026 2027 2028 2029 2030 2031 2032 2033 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2025 def find_command_with_utype (utype) array = Array.new() @commands.each do |command| if (command.utype == utype) array.push(command) end end return array end |
#get_building_transformation_matrix ⇒ Object
2258 2259 2260 2261 2262 2263 2264 2265 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2258 def get_building_transformation_matrix() build_params = self.find_all_commands("BUILD-PARAMETERS")[0] building_xref = build_params.check_keyword?("X-REF")? build_params.get_keyword?("X-REF") : 0.0 building_yref = build_params.check_keyword?("Y-REF")? build_params.get_keyword?("Y-REF") : 0.0 building_origin = OpenStudio::Vector3d.new(building_xref,building_yref,0.0) building_azimuth = build_params.check_keyword?("AZIMUTH")? build_params.get_keyword?("AZIMUTH") : 0.0 return OpenStudio::Transformation::rotation(OpenStudio::Vector3d(0.0, 0.0, 1.0), openstudio::degToRad(building_azimuth)) * OpenStudio::Transformation::translation(building_origin) end |
#get_materials ⇒ Object
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2363 def get_materials() BTAP::runner_register("Info", "Spaces",runner) find_all_commands("SPACE").each do |space| BTAP::runner_register("Info", space.get_azimuth(),runner) end BTAP::runner_register("Info", "Materials",runner) find_all_commands("MATERIAL").each do |materials| BTAP::runner_register("Info", materials.get_name(),runner) end BTAP::runner_register("Info", "Layers",runner) find_all_commands("LAYERS").each do |materials| BTAP::runner_register("Info", materials.get_name(),runner) end BTAP::runner_register("Info", "Constructions",runner) find_all_commands("CONSTRUCTION").each do |materials| BTAP::runner_register("Info", materials.get_name(),runner) end end |
#load_inp(filename, runner = nil) ⇒ Object
Will read an input file into memory and store all the commands into the commands array. param filename param runner
2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2070 def load_inp(filename,runner = nil) BTAP::runner_register("Info", "loading file:" + filename, runner) #Open the file. #puts filename iter = 0 File.exist?(filename) f = File.open(filename, "r") #Read the file into an array, line by line. lines = f.readlines #Set up the temp string. command_string ="" lines.each do|line| iter = iter.next #line.forced_encoding("US-ASCII") #Ignore comments (To do!...strip from file as well as in-line comments. if (!line.match(/\$.*/) ) if (myarray = line.match(/(.*?)\.\./) ) #Add the last part of the command to the newline...may be blank." command_string = command_string + myarray[1] #Determine correct command class to create, then populates it." command = DOECommandFactory.command_factory(command_string, self) #Push the command into the command array." @commands.push(command) command_string = "" else myarray = line.match(/(.*)/) command_string = command_string + myarray[1] end end end organize_data() BTAP::runner_register("Info","INP model contains:", runner) #report number of things read in. ["SPACE","ZONE","EXTERIOR-WALL","ROOF","INTERIOR-WALL","UNDERGROUND-WALL","WINDOW","DOOR","MATERIAL","CONSTRUCTION"].each do |item| items = self.find_all_commands(item) = "\t#{item} = #{items.size}" BTAP::runner_register("Info",, runner) end BTAP::runner_register("Info", "\tFinished Loading File:" + filename,runner) end |
#organize_data ⇒ Object
This routine organizes the hierarchy of the space <-> zones and the polygon associations that are not formally identified by the sequential relationship like the floor, walls, windows. It would seem that zones and spaces are 1 to one relationships. So each zone will have a reference to its space and vice versa. If there is a polygon command in the space or floor definition, a reference to the polygon class will be set.
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2141 def organize_data() # set_envelope_hierarchy # This method determines the current parents of the current command. def determine_current_parents(new_command) if @last_command.nil? @last_command = new_command end #Check to see if scope (HVAC versus Envelope) has changed or the parent depth is undefined "0" if (!@parents.empty? and (new_command.doe_scope != @parents.last.doe_scope or new_command.depth == 0 )) @parents.clear end #no change in parent. if ( (new_command.depth == @last_command.depth)) #no change @last_command = new_command #puts "#{new_command.commandName}" end #Parent depth added if ( new_command.depth > @last_command.depth) @parents.push(@last_command) #puts "Added parent#{@last_command.commandName}" @last_command = new_command end #parent depth removed. if ( new_command.depth < @last_command.depth) parent = @parents.pop #puts "Removed parent #{parent}" @last_command = new_command end array = Array.new(@parents) return array end @commands.each do |command| if command.doe_scope() == "envelope" #Sets parents of command. parents = determine_current_parents(command) if (!parents.empty?) command.parents = parents end #inserts current command into the parent's children. if (!command.parents.empty?) command.parents.last.children.push(command) end end end # Associating the polygons with the FLoor and spaces. polygons = find_all_commands("POLYGON") spaces = find_all_commands("SPACE") floors = find_all_commands("FLOOR") zones = find_all_commands("ZONE") ext_walls = find_all_commands("EXTERIOR-WALL") roof = find_all_commands("ROOF") door = find_all_commands("DOOR") int_walls = find_all_commands("INTERIOR-WALL") underground_walls = find_all_commands("UNDERGROUND-WALL") underground_floors = find_all_commands("UNDERGROUND-FLOOR") constructions =find_all_commands("CONSTRUCTION") surface_lists = [ ext_walls, roof, door, int_walls, underground_walls, underground_floors] #Organize surface data. surface_lists.each do |surfaces| surfaces.each do |surface| #Assign constructions to surface objects constructions.each do |construction| if ( construction.utype == surface.get_keyword_value("CONSTRUCTION") ) surface.construction = construction end end #Find Polygons associated with surface. polygons.each do |polygon| if ( surface.check_keyword?("POLYGON") and polygon.utype == surface.get_keyword_value("POLYGON") ) surface.polygon = polygon end end end end #Organize polygon data for space and floors. polygons.each do |polygon| #set up point list in polygon objects polygon.create_point_list() #Find Polygons associated with floor and and reference to floor. floors.each do |floor| if ( polygon.utype == floor.get_keyword_value("POLYGON") ) floor.polygon = polygon end end #Find Polygons for space and add reference to the space. spaces.sort.each do |space| if space.check_keyword?("POLYGON") if ( polygon.utype == space.get_keyword_value("POLYGON") ) space.polygon = polygon end end end end # Find spaces that belong to the zone. zones.each do |zone| spaces.sort.each do |space| if ( space.utype == zone.get_keyword_value("SPACE") ) space.zone = zone zone.space = space end end end end |
#save_inp(string) ⇒ Object
This will right a clean output file, meaning no comments. Good for doing diffs
2124 2125 2126 2127 2128 2129 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2124 def save_inp(string) array = @commands w = File.open(string, 'w') array.each { |command| w.print command.output } w.close end |
#search_by_keyword_value(keyword, value) ⇒ Object
Find a matching keyword value pair in from an array of commands. Example: find_keyword_value(building.commands, “TYPE”, “CONDITIONED”) will return all the commands that have the TYPE = CONDITIONED“ Keyword pair.
2055 2056 2057 2058 2059 2060 2061 2062 2063 |
# File 'lib/openstudio-standards/btap/equest.rb', line 2055 def search_by_keyword_value( keyword, value) returnarray = Array.new() @commands.each do |command| if ( command.keywordPairs[keyword] == value ) returnarray.push(command) end end return returnarray end |