def save_project(self, file_name=None, path=None): """Saves the project to a tXML file calls the function save_teaser_xml in data.TeaserXML.py Parameters ---------- file_name : string name of the new file path : string if the Files should not be stored in OutputData, an alternative can be specified """ if file_name is None: name = self.name else: name = file_name if path is None: new_path = os.path.join(utilities.get_default_path(), name) else: new_path = os.path.join(utilities.get_default_path(), name) utilities.create_path(utilities.get_full_path(path)) txml_out.save_teaser_xml(new_path, self)
def save_citygml(self, file_name=None, path=None): """Saves the project to a CityGML file calls the function save_gml in data.CityGML we make use of CityGML core and EnergyADE to store semantic information Parameters ---------- file_name : string name of the new file path : string if the Files should not be stored in OutputData, an alternative can be specified """ if file_name is None: name = self.name else: name = file_name if path is None: new_path = os.path.join(utilities.get_default_path(), name) else: new_path = os.path.join(path, name) utilities.create_path(utilities.get_full_path(path)) citygml_out.save_gml(self, new_path)
def export_parameters_txt(prj, path): '''Exports parameters of all buildings in a readable text file Parameters ---------- path : string if the Files should not be stored in OutputData, an alternative can be specified ''' if path is None: path = "OutputData/"+prj.name else: path = path+"/"+prj.name for bldg in prj.buildings: bldg_path = path + "/" + bldg.name + "/" utilitis.create_path(utilitis.get_full_path(bldg_path)) readable_template = Template( filename=utilitis.get_full_path( "data/output/texttemplate/ReadableBuilding")) out_file = open(utilitis.get_full_path (bldg_path+"ReadableOutput.txt"), 'w') out_file.write(readable_template.render_unicode (bldg=bldg, prj=prj)) out_file.close()
def export_parameters_txt(prj, path): '''Exports parameters of all buildings in a readable text file Parameters ---------- path : string if the Files should not be stored in OutputData, an alternative can be specified ''' if path is None: path = "OutputData\\" + prj.name else: path = path + "\\" + prj.name for bldg in prj.buildings: bldg_path = path + "\\" + bldg.name + "\\" utilitis.create_path(utilitis.get_full_path(bldg_path)) readable_template = Template(filename=utilitis.get_full_path( "Data\\Output\\TextTemplate\\ReadableBuilding")) out_file = open( utilitis.get_full_path(bldg_path + "ReadableOutput.txt"), 'w') out_file.write(readable_template.render_unicode(bldg=bldg, prj=prj)) out_file.close()
def save_project(self, file_name=None, path=None): '''Saves the project to a tXML file calls the function save_teaser_xml in data.TeaserXML.py Parameters ---------- file_name : string name of the new file path : string if the Files should not be stored in OutputData, an alternative can be specified ''' if file_name is None: name = self.name else: name = file_name if path is None: new_path = utilitis.get_full_path("OutputData") + "\\" + name else: new_path = path + "\\" + name utilitis.create_path(utilitis.get_full_path(path)) txml_out.save_teaser_xml(new_path, self)
def save_citygml(self, file_name=None, path=None): '''Saves the project to a citygml file calls the function save_gml in data.CityGML we make use of CityGML core and EnergyADE to store semantic information Parameters ---------- file_name : string name of the new file path : string if the Files should not be stored in OutputData, an alternative can be specified ''' if file_name is None: name = self.name else: name = file_name if path is None: new_path = utilitis.get_full_path("OutputData") + "\\" + name else: new_path = path + "\\" + name utilitis.create_path(utilitis.get_full_path(path)) citygml_out.save_gml(self, new_path)
def export_annex(self, internal_id=None, path=None): """Exports values to a record file for Modelica simulation Parameters ---------- internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path """ if path is None: path = utilitis.get_default_path() + "/" + self.name else: path = path + "/" + self.name utilitis.create_path(path) annex60_output.export_annex60(prj=self, number_of_elements=self.number_of_elements_calc, merge_windows=self.merge_windows_calc, internal_id=internal_id, path=path)
def export_aixlib( self, building_model=None, zone_model=None, corG=None, internal_id=None, path=None): """Exports values to a record file for Modelica simulation Exports one (if internal_id is not None) or all buildings for AixLib.ThermalZones.ReducedOrder.Multizone.MultizoneEquipped models using the ThermalZoneEquipped model with a correction of g-value ( double pane glazing) and supporting models, like tables and weather model. In contrast to versions < 0.5 TEASER now does not support any model options, as we observed no need, since single ThermalZones are identically with IBPSA models. If you miss one of the old options please contact us. Parameters ---------- internal_id : float setter of a specific building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in default output path of TEASER, an alternative path can be specified as a full path """ if building_model is not None or zone_model is not None or corG is \ not None: warnings.warn("building_model, zone_model and corG are no longer " "supported for AixLib export and have no effect. " "The keywords will be deleted within the next " "version, consider rewriting your code.") if path is None: path = os.path.join( utilities.get_default_path(), self.name) else: path = os.path.join( path, self.name) utilities.create_path(path) if internal_id is None: aixlib_output.export_multizone( buildings=self.buildings, prj=self, path=path) else: for bldg in self.buildings: if bldg.internal_id == internal_id: aixlib_output.export_multizone( buildings=[bldg], prj=self, path=path)
def modelica_AHU_boundary(self, path=None): """Create .txt file for AHU boundary conditions (building). This function creates a txt for building AHU boundary conditions 1. Column : time step 2. Column : desired AHU profile temperature 3. Column : Desired minimal relative humidity 4. Column : desired maximal relative humidity 5. Column : AHU status (On/Off) Parameters ---------- path : str optional path, when matfile is exported separately Attributes ---------- temperature_profile : [float] timeline of temperatures requirements for AHU simulation min_relative_humidity_profile : [float] timeline of relative humidity requirements for AHU simulation max_relative_humidity_profile : [float] timeline of relative humidity requirements for AHU simulation v_flow_profile : [int] timeline of desired relative v_flow of the AHU simulation (0..1) """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_ahu) if self.parent.with_ahu is True: export = self.parent.central_ahu.schedules else: # Dummy values for Input Table export = pd.DataFrame(index=pd.date_range( "2019-01-01 00:00:00", periods=8760, freq="H").to_series().dt.strftime("%m-%d %H:%M:%S")) export["temperature_profile"] = list( islice(cycle([293.15, 293.15]), 8760)) export["min_relative_humidity_profile"] = list( islice(cycle([0, 0]), 8760)) export["max_relative_humidity_profile"] = list( islice(cycle([1, 1]), 8760)) export["v_flow_profile"] = list(islice(cycle([0, 1]), 8760)) export.index = [(i + 1) * 3600 for i in range(8760)] self._delete_file(path=path) with open(path, "a") as f: f.write("#1\n") f.write("double AHU({}, {})\n".format(8760, 5)) export.to_csv(f, sep="\t", header=False, index_label=False)
def modelica_gains_boundary(self, path=None): """Create .txt file for internal gains boundary conditions. This function creates a matfile (-v4) for building internal gains boundary conditions. It collects all internal gain profiles of the zones and stores them into one file. The file is extended for each zone. Only applicable if zones are defined 1. Column : time step 2,5,8,... Column : profile_persons 3,6,9,... Column : profile_machines 4,7,10,... Column : profile_lighting Note ---------- When time line is created, we need to add a 0 to first element of all boundaries. This is due to to expected format in Modelica. Parameters ---------- path : str optional path, when matfile is exported separately """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_internal_gains) export = pd.DataFrame( index=pd.date_range("2019-01-01 00:00:00", periods=8760, freq="H" ).to_series().dt.strftime("%m-%d %H:%M:%S")) for zone_count in self.parent.thermal_zones: export["person_{}".format( zone_count.name )] = zone_count.use_conditions.schedules["persons_profile"] export["machines_{}".format( zone_count.name )] = zone_count.use_conditions.schedules["machines_profile"] export["lighting_{}".format( zone_count.name )] = zone_count.use_conditions.schedules["lighting_profile"] export.index = [(i + 1) * 3600 for i in range(8760)] self._delete_file(path=path) with open(path, "a") as f: f.write("#1\n") f.write("double Internals({}, {})\n".format( 8760, (len(self.parent.thermal_zones) * 3 + 1))) export.to_csv(f, sep="\t", header=False, index_label=False)
def export_ibpsa(self, library="AixLib", internal_id=None, path=None): """Exports values to a record file for Modelica simulation For Annex 60 Library Parameters ---------- library : str Used library within the framework of IBPSA library. The models are identical in each library, but IBPSA Modelica library is just a core set of models and should not be used standalone. Valid values are 'AixLib' (default), 'Buildings', 'BuildingSystems' and 'IDEAS'. internal_id : float setter of a specific building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in default output path of TEASER, an alternative path can be specified as a full path """ ass_error_1 = ("library for IBPSA export has to be 'AixLib', " "'Buildings', 'BuildingSystems' or 'IDEAS'") assert library in [ "AixLib", "Buildings", "BuildingSystems", "IDEAS", ], ass_error_1 if path is None: path = os.path.join(utilities.get_default_path(), self.name) else: path = os.path.join(path, self.name) utilities.create_path(path) if internal_id is None: ibpsa_output.export_ibpsa(buildings=self.buildings, prj=self, path=path, library=library) else: for bldg in self.buildings: if bldg.internal_id == internal_id: ibpsa_output.export_ibpsa(buildings=[bldg], prj=self, path=path) return path
def export_parameters_txt(prj, path): """Exports parameters of all buildings in a readable text file Parameters ---------- prj : TEASER project Project to export path : string if the Files should not be stored in OutputData, an alternative can be specified """ lookup = TemplateLookup(directories=[ utilities.get_full_path( os.path.join('data', 'output', 'modelicatemplate')) ]) model_template_1 = Template(filename=utilities.get_full_path( os.path.join('data', 'output', 'texttemplate', 'ReadableBuilding_OneElement')), lookup=lookup) model_template_2 = Template(filename=utilities.get_full_path( os.path.join('data', 'output', 'texttemplate', 'ReadableBuilding_TwoElement')), lookup=lookup) model_template_3 = Template(filename=utilities.get_full_path( os.path.join('data', 'output', 'texttemplate', 'ReadableBuilding_ThreeElement')), lookup=lookup) model_template_4 = Template(filename=utilities.get_full_path( os.path.join('data', 'output', 'texttemplate', 'ReadableBuilding_FourElement')), lookup=lookup) for bldg in prj.buildings: bldg_path = os.path.join(path, bldg.name + "_txtOutput") utilities.create_path(bldg_path) out_file = open(os.path.join(bldg_path, bldg.name + ".txt"), 'w') if type(bldg.thermal_zones[0].model_attr).__name__ == "OneElement": out_file.write(model_template_1.render_unicode(bldg=bldg)) elif type(bldg.thermal_zones[0].model_attr).__name__ == "TwoElement": out_file.write(model_template_2.render_unicode(bldg=bldg)) elif type(bldg.thermal_zones[0].model_attr).__name__ == "ThreeElement": out_file.write(model_template_3.render_unicode(bldg=bldg)) elif type(bldg.thermal_zones[0].model_attr).__name__ == "FourElement": out_file.write(model_template_4.render_unicode(bldg=bldg)) out_file.close()
def create_aggregated_RC(path, bldg_list, package_name, model_name, RC_package, RC_model): lookup = TemplateLookup(directories=["code_templates\\"]) aggr_template = Template(filename="code_templates\\Aggregated_R2CW_mpc", lookup=lookup) utilities.create_path(os.path.join(path, package_name)) out_file = open(os.path.join(path, package_name, package_name + ".mo"), 'w') out_file.write( aggr_template.render_unicode(package_name=package_name, model_name=model_name, numbuilds=len(bldg_list), RC_model=RC_model, RC_package=RC_package, bldg_list=bldg_list)) out_file.close()
def export_ibpsa( self, internal_id=None, path=None): """Exports values to a record file for Modelica simulation For Annex 60 Library Parameters ---------- internal_id : float setter of a specific building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in default output path of TEASER, an alternative path can be specified as a full path """ if path is None: path = os.path.join( utilities.get_default_path(), self.name) else: path = os.path.join( path, self.name) utilities.create_path(path) if internal_id is None: ibpsa_output.export_ibpsa( buildings=self.buildings, prj=self, path=path) else: for bldg in self.buildings: if bldg.internal_id == internal_id: ibpsa_output.export_ibpsa( buildings=[bldg], prj=self, path=path)
def export_aixlib(self, building_model="None", zone_model="None", corG=None, internal_id=None, path=None): """Exports values to a record file for Modelica simulation Parameters ---------- building_model : string setter of the used Aixlib building model (None, MultizoneEquipped, Multizone) zone_model : string setter of the used Aixlib zone model (ThermalZoneEquipped, ThermalZone) corG : boolean setter of the used g value calculation in the model internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path """ if path is None: path = utilitis.get_default_path() + "\\" + self.name else: path = path + "\\" + self.name utilitis.create_path(path) aixlib_output.export_aixlib(prj=self, building_model=building_model, zone_model=zone_model, corG=corG, internal_id=internal_id, path=path)
def modelica_set_temp(bldg, path = None): '''creates .mat file for set temperatures for each zone This function creates a matfile (-v4) for set temperatures of each zone !AixLib sepcific! 1. Row: heat set temperature of all zones 2. Row: cool set temperature of all zones Parameters ---------- path : str optional path, when matfile is exported seperately ''' if bldg.file_set_t is None: bldg.file_set_t = "\\Tset_"+bldg.name+".mat" else: pass if path is None: path = utilitis.get_default_path() else: pass utilitis.create_path(path) path = path + bldg.file_set_t t_set_heat = [0] for zone_count in bldg.thermal_zones: t_set_heat.append(zone_count.use_conditions.set_temp_heat) scipy.io.savemat(path, mdict={'Tset': [t_set_heat]}, appendmat = False, format = '4')
def modelica_set_temp_cool(self, path=None): """Create .txt file for set temperatures cooling. This function creates a txt for set temperatures for cooling of each zone, that are all saved into one matrix. Parameters ---------- path : str optional path, when matfile is exported separately """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_set_t_cool) export = pd.DataFrame( index=pd.date_range( "2019-01-01 00:00:00", periods=8760, freq="H").to_series().dt.strftime("%m-%d %H:%M:%S"), columns=[zone.name for zone in self.parent.thermal_zones], ) for zone_count in self.parent.thermal_zones: export[zone_count.name] = zone_count.use_conditions.schedules[ "cooling_profile"] export.index = [(i + 1) * 3600 for i in range(8760)] self._delete_file(path=path) with open(path, "a") as f: f.write("#1\n") f.write("double Tset({}, {})\n".format( 8760, len(self.parent.thermal_zones) + 1)) export.to_csv(f, sep="\t", header=False, index_label=False)
def create_aggregated_IBPSA(prj, path, model_name, template="code_templates\\Aggregated_IBPSA_mpc"): lookup = TemplateLookup( directories=["code_templates\\aggr_code_templates\\"]) aggr_template = Template(filename=template, lookup=lookup) uses = [ 'Modelica(version="' + prj.modelica_info.version + '")', 'IBPSA(version="' + prj.buildings[-1].library_attr.version + '")', str(prj.name) + '(version="1")' ] #print(prj.buildings.name) #print(prj.modelica_info) utilities.create_path(os.path.join(path, model_name)) out_file = open(os.path.join(path, model_name, model_name + ".mo"), 'w') out_file.write( aggr_template.render_unicode(project_name=prj.name, model_name=model_name, numbuilds=len(prj.buildings), bldg_list=prj.buildings, modelica_info=prj.modelica_info)) out_file.close() create_package(path=os.path.join(path, model_name), name=model_name, uses=uses, within=None) create_package_order(path=os.path.join(path, model_name), package_list=[model_name], addition=None, extra=None) with open(os.path.join(path, "package.order"), "a") as myfile: myfile.write(model_name) myfile.close()
def export_annex(self, number_of_elements=2, merge_windows=False, internal_id=None, path=None): """Exports values to a record file for Modelica simulation Parameters ---------- number_of_elements : int defines the number of elements, that area aggregated, between 1 and 4, default is 2 merge_windows : bool True for merging the windows into the outer walls, False for separate resistance for window, default is False internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path """ if path is None: path = utilitis.get_default_path() + "\\" + self.name else: path = path + "\\" + self.name utilitis.create_path(path) annex60_output.export_annex60( prj=self, number_of_elements=self.number_of_elements_calc, merge_windows=self.merge_windows_calc, internal_id=internal_id, path=path)
def export_annex(self, number_of_elements=2, merge_windows=False, internal_id=None, path=None): """Exports values to a record file for Modelica simulation Parameters ---------- number_of_elements : int defines the number of elements, that area aggregated, between 1 and 4, default is 2 merge_windows : bool True for merging the windows into the outer walls, False for separate resistance for window, default is False internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path """ if path is None: path = utilitis.get_default_path() + "\\" + self.name else: path = path + "\\" + self.name utilitis.create_path(path) annex60_output.export_annex60(prj=self, number_of_elements=self.number_of_elements_calc, merge_windows=self.merge_windows_calc, internal_id=internal_id, path=path)
def export_multizone(buildings, prj, path=None): """Exports models for AixLib library Exports a building for AixLib.ThermalZones.ReducedOrder.Multizone.MultizoneEquipped models using the ThermalZoneEquipped and supporting models, like tables and weather model. Depending on chosen calculation method the parameter set to 1,2, 3 or 4 element model. By default it uses the correction for solar glazing (corG) and decoupled heat conduction through windows ( merge_windows=False). In contrast to versions < 0.5 TEASER now does not support any other model options, as we observed no need, since single ThermalZones are identical with IBPSA models. If you miss one of the old options please contact us. This function uses Mako Templates specified in data.output.modelicatemplates.AixLib Parameters ---------- buildings : list of instances of Building list of TEASER instances of a Building that is exported to a AixLib MultizoneEquipped models. If you want to export a single building, please pass it over as a list containing only that building. prj : instance of Project Instance of TEASER Project object to access Project related information, e.g. name or version of used libraries path : string if the Files should not be stored in default output path of TEASER, an alternative path can be specified as a full path Attributes ---------- lookup : TemplateLookup object Instance of mako.TemplateLookup to store general functions for templates zone_template_1 : Template object Template for ThermalZoneRecord using 1 element model zone_template_2 : Template object Template for ThermalZoneRecord using 2 element model zone_template_3 : Template object Template for ThermalZoneRecord using 3 element model zone_template_4 : Template object Template for ThermalZoneRecord using 4 element model model_template : Template object Template for MultiZone model """ lookup = TemplateLookup(directories=[utilities.get_full_path( os.path.join('data', 'output', 'modelicatemplate'))]) zone_template_1 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/AixLib" "/AixLib_ThermalZoneRecord_OneElement"), lookup=lookup) zone_template_2 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/AixLib" "/AixLib_ThermalZoneRecord_TwoElement"), lookup=lookup) zone_template_3 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/AixLib" "/AixLib_ThermalZoneRecord_ThreeElement"), lookup=lookup) zone_template_4 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/AixLib" "/AixLib_ThermalZoneRecord_FourElement"), lookup=lookup) model_template = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/AixLib/AixLib_Multizone"), lookup=lookup) uses = [ 'Modelica(version="' + prj.modelica_info.version + '")', 'AixLib(version="' + prj.buildings[-1].library_attr.version + '")'] _help_package( path=path, name=prj.name, uses=uses, within=None) _help_package_order( path=path, package_list=buildings, addition=None, extra=None) for i, bldg in enumerate(buildings): ass_error = "You chose IBPSA calculation, " \ "but want to export AixLib models, " \ "this is not possible" assert bldg.used_library_calc == 'AixLib', ass_error bldg_path = os.path.join(path, bldg.name) utilities.create_path(utilities.get_full_path(bldg_path)) utilities.create_path(utilities.get_full_path( os.path.join(bldg_path, bldg.name + "_DataBase"))) bldg.library_attr.modelica_set_temp(path=bldg_path) bldg.library_attr.modelica_AHU_boundary( time_line=None, path=bldg_path) bldg.library_attr.modelica_gains_boundary( time_line=None, path=bldg_path) _help_package(path=bldg_path, name=bldg.name, within=bldg.parent.name) _help_package_order( path=bldg_path, package_list=[bldg], addition=None, extra=bldg.name + "_DataBase") if bldg.building_id is None: bldg.building_id = i else: try: bldg.building_id = int(bldg.building_id) except UserWarning: warnings.warn("Cannot convert building_id to integer, " "is set to ", i, "which is the enumeration " "number of the building in " "the project list.") bldg.building_id = i out_file = open(utilities.get_full_path (os.path.join(bldg_path, bldg.name + ".mo")), 'w') out_file.write(model_template.render_unicode( bldg=bldg, weather=bldg.parent.weather_file_path, modelica_info=bldg.parent.modelica_info)) out_file.close() zone_path = os.path.join(bldg_path, bldg.name + "_DataBase") for zone in bldg.thermal_zones: out_file = open(utilities.get_full_path(os.path.join( zone_path, bldg.name + '_' + zone.name + '.mo')), 'w') if type(zone.model_attr).__name__ == "OneElement": out_file.write(zone_template_1.render_unicode(zone=zone)) elif type(zone.model_attr).__name__ == "TwoElement": out_file.write(zone_template_2.render_unicode(zone=zone)) elif type(zone.model_attr).__name__ == "ThreeElement": out_file.write(zone_template_3.render_unicode(zone=zone)) elif type(zone.model_attr).__name__ == "FourElement": out_file.write(zone_template_4.render_unicode(zone=zone)) out_file.close() _help_package( path=zone_path, name=bldg.name + '_DataBase', within=prj.name + '.' + bldg.name) _help_package_order( path=zone_path, package_list=bldg.thermal_zones, addition=bldg.name + "_", extra=None) print("Exports can be found here:") print(path)
def modelica_gains_boundary(bldg, time_line = None, path = None): '''creates .mat file for internal gains boundary conditions (building) This function creates a matfile (-v4) for building internal gains boundary conditions. It collects all internal gain profiles of the zones and stores them into one file. The file is extended for each zone. Only applicable if zones are defined !AixLib sepcific! 1. Column : time step 2,5,8,... Column : profile_persons 3,6,9,... Column : profile_machines 4,7,10,... Column : profile_lighting Note ---------- When time line is created, we need to add a 0 to first element of all boundaries. This is due to to expected format in Modelica. Parameters ---------- time_line :[[int]] list of time steps path : str optional path, when matfile is exported seperately ''' if bldg.file_internal_gains is None: bldg.file_internal_gains = "\\InternalGains_"+bldg.name+".mat" else: pass if path is None: path = utilitis.get_default_path() else: pass utilitis.create_path(path) path = path + bldg.file_internal_gains for zone_count in bldg.thermal_zones: if time_line is None: duration= len(zone_count.use_conditions.profile_persons) * \ 3600 time_line = create_timeline(bldg=bldg, duration_profile = duration) # zone_count.use_conditions.profile_persons.insert(0,0) # zone_count.use_conditions.profile_machines.insert(0,0) # zone_count.use_conditions.profile_lighting.insert(0,0) ass_error_1 = "time line and input have to have the same length" assert len(time_line)-1 == len(zone_count.use_conditions.profile_persons), \ (ass_error_1 + ",profile_persons") assert len(time_line)-1 == len(zone_count.use_conditions.profile_machines), \ (ass_error_1 + ",profile_machines") assert len(time_line)-1 == len(zone_count.use_conditions.profile_lighting), \ (ass_error_1 + ",profile_lighting") for i, time in enumerate(time_line): if i == 0: time.append(0) time.append(0) time.append(0) else: time.append(zone_count.use_conditions.profile_persons[i-1]) time.append(zone_count.use_conditions.profile_machines[i-1]) time.append(zone_count.use_conditions.profile_lighting[i-1]) # zone_count.use_conditions.profile_persons.pop(0) # zone_count.use_conditions.profile_machines.pop(0) # zone_count.use_conditions.profile_lighting.pop(0) internal_boundary = np.array(time_line) scipy.io.savemat(path, mdict={'Internals': internal_boundary}, appendmat=False, format='4')
def modelica_AHU_boundary(bldg, time_line = None, path = None): '''creates .mat file for AHU boundary conditions (building) This function creates a matfile (-v4) for building AHU boundary conditions !AixLib sepcific! Known limitation: 1. Column : time step 2. Column : desired AHU profile temperature 3. Column : Desired minimal relative humidity 4. Column : desired maximal relative humidity 5. Columb : AHU status (On/Off) Parameters ---------- time_line :[[int]] list of time steps path : str optional path, when matfile is exported seperately Attributes ---------- profile_temperature : [float] timeline of temperatures requirements for AHU simulation profile_min_relative_humidity : [float] timeline of relative humidity requirements for AHU simulation profile_max_relative_humidity : [float] timeline of relative humidity requirements for AHU simulation profile_v_flow : [int] timeline of desired relative v_flow of the AHU simulation (0..1) ''' if bldg.file_ahu is None: bldg.file_ahu = "\\AHU_"+bldg.name+".mat" else: pass if path is None: path = utilitis.get_default_path() else: pass utilitis.create_path(path) path = path + bldg.file_ahu if time_line is None: time_line = create_timeline(bldg) if bldg.with_ahu is True: profile_temperature = \ bldg.central_ahu.profile_temperature profile_min_relative_humidity = \ bldg.central_ahu.profile_min_relative_humidity profile_max_relative_humidity = \ bldg.central_ahu.profile_max_relative_humidity profile_v_flow = \ bldg.central_ahu.profile_v_flow else: #Dummy values for Input Table (based on discussion with pme) time_line = [[0],[3600]] profile_temperature = [293.15,293.15] profile_min_relative_humidity = [0,0] profile_max_relative_humidity = [1,1] profile_v_flow = [0,1] ass_error_1 = "time line and input have to have the same length" assert len(time_line) == len(profile_temperature), \ (ass_error_1 + ",profile_temperature_AHU") assert len(time_line) == len(profile_min_relative_humidity), \ (ass_error_1 + ",profile_min_relative_humidity") assert len(time_line) == len(profile_max_relative_humidity), \ (ass_error_1 + ",profile_max_relative_humidity") assert len(time_line) == len(profile_v_flow), \ (ass_error_1 + ",profile_status_AHU") for i, time in enumerate(time_line): time.append(profile_temperature[i]) time.append(profile_min_relative_humidity[i]) time.append(profile_max_relative_humidity[i]) time.append(profile_v_flow[i]) ahu_boundary = np.array(time_line) scipy.io.savemat(path, mdict={'AHU': ahu_boundary}, appendmat = False, format = '4')
def modelica_gains_boundary(self, zone, path=None): """creates .mat file for internal gains boundary conditions This function creates a matfile (-v4) for building internal gains boundary conditions. It collects internal gain profiles of a specific zones and stores them into one file. It also calculates the internal gains from relative presence and values for heat output into W for direct usage in Annex models. Only person (convective and radiative) and machines (convective) are used in the simple Annex 60 examples. 1. Column : time step 2 Column : profile_persons, radiative 3 Column : profile_persons, convective 4 Column : profile_machines, convective Note ---------- When time line is created, we need to add a 0 to first element of all boundaries. This is due to to expected format in Modelica. Parameters ---------- zone : ThermalZone() TEASER instance of ThermalZone. As IBPSA computes single models for single zones, we need to generate individual files for zones and internal gains path : str optional path, when matfile is exported separately """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_internal_gains) export = pd.DataFrame( index=pd.date_range("2019-01-01 00:00:00", periods=8760, freq="H") .to_series() .dt.strftime("%m-%d %H:%M:%S") ) export["person_rad_{}".format(zone.name)] = ( zone.use_conditions.schedules["persons_profile"] * (1 - zone.use_conditions.ratio_conv_rad_persons) * zone.use_conditions.fixed_heat_flow_rate_persons * zone.use_conditions.persons * zone.area ) export["person_conv_{}".format(zone.name)] = ( zone.use_conditions.schedules["persons_profile"] * zone.use_conditions.ratio_conv_rad_persons * zone.use_conditions.fixed_heat_flow_rate_persons * zone.use_conditions.persons * zone.area ) export["machines_conv_{}".format(zone.name)] = ( zone.use_conditions.schedules["machines_profile"] * zone.use_conditions.ratio_conv_rad_machines * zone.use_conditions.machines * zone.area ) export.index = [(i + 1) * 3600 for i in range(8760)] self._delete_file(path=path) with open(path, "a") as f: f.write("#1\n") f.write( "double Internals({}, {})\n".format( 8760, (len(self.parent.thermal_zones) * 3 + 1) ) ) export.to_csv(f, sep="\t", header=False, index_label=False)
def modelica_gains_boundary( self, time_line=None, path=None): """creates .mat file for internal gains boundary conditions This function creates a matfile (-v4) for building internal gains boundary conditions. It collects all internal gain profiles of the zones and stores them into one file. The file is extended for each zone. Only applicable if zones are defined 1. Column : time step 2,5,8,... Column : profile_persons 3,6,9,... Column : profile_machines 4,7,10,... Column : profile_lighting Note ---------- When time line is created, we need to add a 0 to first element of all boundaries. This is due to to expected format in Modelica. Parameters ---------- time_line :[[int]] list of time steps path : str optional path, when matfile is exported separately """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_internal_gains) for zone_count in self.parent.thermal_zones: if time_line is None: duration = len(zone_count.use_conditions.profile_persons) * \ 3600 time_line = self.create_profile(duration_profile=duration) ass_error_1 = "time line and input have to have the same length" assert len(time_line) - 1 == len( zone_count.use_conditions.profile_persons), \ (ass_error_1 + ",profile_persons") assert len(time_line) - 1 == len( zone_count.use_conditions.profile_machines), \ (ass_error_1 + ",profile_machines") assert len(time_line) - 1 == len( zone_count.use_conditions.profile_lighting), \ (ass_error_1 + ",profile_lighting") for i, time in enumerate(time_line): if i == 0: time.append( zone_count.use_conditions.profile_persons[i + 1]) time.append( zone_count.use_conditions.profile_machines[i + 1]) time.append( zone_count.use_conditions.profile_lighting[i + 1]) else: time.append( zone_count.use_conditions.profile_persons[i - 1]) time.append( zone_count.use_conditions.profile_machines[i - 1]) time.append( zone_count.use_conditions.profile_lighting[i - 1]) internal_boundary = np.array(time_line) scipy.io.savemat( path, mdict={'Internals': internal_boundary}, appendmat=False, format='4') return internal_boundary
def modelica_set_temp(self, path=None): """creates .mat file for set temperatures This function creates a matfile (-v4) for set temperatures of each zone, that are all saved into one matrix. 1. Row: heat set temperature of all zones 2. Row: cool set temperature of all zones Parameters ---------- path : str optional path, when matfile is exported separately """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_set_t) time_line = self.create_profile(double=True) for zone_count in self.parent.thermal_zones: for i in range(len(time_line)): if self.use_set_back is False: time_line[i].append(zone_count.use_conditions.set_temp_heat) else: i -= 1 if i % 2 == 0: if zone_count.use_conditions.heating_time[0] == 0: time_line[i].append( zone_count.use_conditions.set_temp_heat) time_line[i + 1].append( zone_count.use_conditions.set_temp_heat) elif time_line[i][0] < \ zone_count.use_conditions.heating_time[0] * 3600: time_line[i].append( zone_count.use_conditions.set_temp_heat - zone_count.use_conditions.temp_set_back) time_line[i + 1].append( zone_count.use_conditions.set_temp_heat - zone_count.use_conditions.temp_set_back) elif time_line[i][0] == \ zone_count.use_conditions.heating_time[0] * 3600: time_line[i].append( zone_count.use_conditions.set_temp_heat - zone_count.use_conditions.temp_set_back) time_line[i + 1].append( zone_count.use_conditions.set_temp_heat) elif time_line[i][0] == \ (zone_count.use_conditions.heating_time[1] + 1) * \ 3600: time_line[i].append( zone_count.use_conditions.set_temp_heat) time_line[i + 1].append( zone_count.use_conditions.set_temp_heat - zone_count.use_conditions.temp_set_back) elif time_line[i][0] > \ (zone_count.use_conditions.heating_time[1] + 1) * \ 3600: time_line[i].append( zone_count.use_conditions.set_temp_heat - zone_count.use_conditions.temp_set_back) time_line[i + 1].append( zone_count.use_conditions.set_temp_heat - zone_count.use_conditions.temp_set_back) else: time_line[i].append( zone_count.use_conditions.set_temp_heat) time_line[i + 1].append( zone_count.use_conditions.set_temp_heat) else: pass scipy.io.savemat( path, mdict={'Tset': time_line}, appendmat=False, format='4')
def export_aixlib(prj, building_model="None", zone_model="None", corG=None, internal_id=None, path=None): '''Exports values to a record file for Modelica simulation The Export function for creating a AixLib LOM Multizone model Parameters ---------- building_model : string setter of the used Aixlib building model (None, MultizoneEquipped, Multizone) zone_model : string setter of the used Aixlib zone model (ThermalZoneEquipped, ThermalZone) corG : boolean setter of the used g value calculation in the model internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path ''' #check the arguments assert building_model in ["None", "MultizoneEquipped", "Multizone"] assert zone_model in ["None", "ThermalZoneEquipped", "ThermalZone"] assert corG in [None, True, False] uses = ['Modelica(version = "3.2.1")', "AixLib(version=\"0.3.1\")"] # use the same zone templates for all exports zone_template = Template( filename=utilitis.get_full_path( "data/output/modelicatemplate/AixLib/AixLib_zone")) model_template = Template( filename=utilitis.get_full_path( "data/output/modelicatemplate/AixLib/AixLib_model")) zone_base_template = Template( filename=utilitis.get_full_path( "data/output/modelicatemplate/AixLib/AixLib_base")) # list which contains exported buildings if internal_id is not None: exported_list_of_buildings = [bldg for bldg in prj.buildings if bldg.internal_id == internal_id] else: exported_list_of_buildings = prj.buildings # here we diff between zonerecord export and full model support if building_model != "None" and zone_model != "None" and\ corG is not None: # full model support here print("full model support") _help_package(path, prj.name, uses, within=None) _help_package_order(path, exported_list_of_buildings) for bldg in exported_list_of_buildings: if bldg.merge_windows_calc is True: calc_method = 'vdi' elif bldg.merge_windows_calc is False: calc_method = 'ebc' bldg_path = path + "/" + bldg.name + "/" utilitis.create_path(utilitis.get_full_path(bldg_path)) utilitis.create_path(utilitis.get_full_path (bldg_path + bldg.name + "_DataBase")) aixlib.modelica_set_temp(bldg=bldg, path=path + "/" + bldg.name) aixlib.modelica_AHU_boundary(bldg=bldg, path=path + "/" + bldg.name) aixlib.modelica_gains_boundary(bldg=bldg, path=path + "/" + bldg.name) _help_package(bldg_path, bldg.name, within=prj.name) _help_package_order(bldg_path, [bldg], None, bldg.name + "_DataBase") out_file = open(utilitis.get_full_path (bldg_path + bldg.name + ".mo"), 'w') out_file.write(model_template.render_unicode( bldg=bldg, mod_prj=prj.modelica_project, weather=prj.weather_file_path, weather_header=prj.weather_file_header, model=building_model, zone=zone_model, physics=calc_method, gFac=corG)) out_file.close() for zone in bldg.thermal_zones: zone_path = bldg_path + bldg.name + "_DataBase" + "/" out_file = open(utilitis.get_full_path( zone_path + "/" + bldg.name + "_" + zone.name.replace(" ", "") + ".mo"), 'w') out_file.write(zone_template.render_unicode( bldg=bldg, zone=zone, mod_prj=prj.modelica_project)) out_file.close() _help_package(zone_path, bldg.name + "_DataBase", within=prj.name + '.' + bldg.name) _help_package_order(zone_path, bldg.thermal_zones, bldg.name + "_", bldg.name + "_base") out_file = open(utilitis.get_full_path (zone_path + bldg.name + "_base.mo"), 'w') if bldg.central_ahu: out_file.write(zone_base_template.render_unicode( bldg=bldg, zone=zone, mod_prj=prj.modelica_project, central_ahu=bldg.central_ahu)) out_file.close() else: out_file.write(zone_base_template.render_unicode( bldg=bldg, zone=zone, mod_prj=prj.modelica_project)) out_file.close() print("Exports can be found here:") print(path) elif building_model == "None" and zone_model == "None" and\ corG is None: # only export the baserecords _help_package(path, prj.name, uses) _help_package_order(path, exported_list_of_buildings) for bldg in exported_list_of_buildings: bldg_path = path + "/" + bldg.name + "/" utilitis.create_path(utilitis.get_full_path(bldg_path)) utilitis.create_path(utilitis.get_full_path (bldg_path + bldg.name + "_DataBase")) _help_package(bldg_path, bldg.name, within=prj.name) _help_package_order(bldg_path, [bldg], None, bldg.name + "_DataBase") for zone in bldg.thermal_zones: zone_path = bldg_path + bldg.name + "_DataBase" + "/" out_file = open(utilitis.get_full_path( zone_path + "/" + bldg.name + "_" + zone.name.replace(" ", "") + ".mo"), 'w') out_file.write(zone_template.render_unicode( bldg=bldg, zone=zone, calc_core=bldg._calculation_method, mod_prj=prj.modelica_project)) out_file.close() _help_package(zone_path, bldg.name + "_DataBase", within=prj.name + '.' + bldg.name) _help_package_order(zone_path, bldg.thermal_zones, bldg.name + "_", bldg.name + "_base") print("Exports can be found here:") print(path) else: # not clearly specified print("please specify you export clearly")
def export_annex60(prj, number_of_elements=2, merge_windows=False, internal_id=None, path=None): """Exports values to a record file for Annex60 simulation The Export function for creating a Annex60 example model Parameters ---------- number_of_elements : int defines the number of elements, that area aggregated, between 1 and 4, default is 2 merge_windows : bool True for merging the windows into the outer walls, False for separate resistance for window, default is False internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path """ uses = ['Modelica(version = "3.2.2")', 'Annex60(version="0.1")'] if internal_id is not None: exported_list_of_buildings = [bldg for bldg in prj.buildings if bldg.internal_id == internal_id] else: exported_list_of_buildings = prj.buildings aixlib_output._help_package(path, prj.name, uses, within=None) aixlib_output._help_package_order(path, exported_list_of_buildings) if number_of_elements == 1: pass elif number_of_elements == 2: zone_template = Template(filename=utilitis.get_full_path( "data/output/modelicatemplate/Annex60/Annex60_TwoElements")) elif number_of_elements == 3: zone_template = Template(filename=utilitis.get_full_path( "data/output/modelicatemplate/Annex60/Annex60_ThreeElements")) elif number_of_elements == 4: zone_template = Template(filename=utilitis.get_full_path( "data/output/modelicatemplate/Annex60/Annex60_FourElements")) for bldg in exported_list_of_buildings: bldg_path = os.path.join(path, bldg.name) utilitis.create_path(utilitis.get_full_path(bldg_path)) utilitis.create_path(utilitis.get_full_path(bldg_path+ "/" + bldg.name + \ "_Models")) aixlib_output._help_package(bldg_path, bldg.name, within=prj.name) aixlib_output._help_package_order(bldg_path, [bldg], None, bldg.name + "_Models") for zone in bldg.thermal_zones: zone_path = os.path.join(bldg_path, bldg.name+"_Models") out_file = open(utilitis.get_full_path( zone_path + "/" + bldg.name + "_" + zone.name.replace(" ", "") + ".mo"), 'w') out_file.write(zone_template.render_unicode(bldg=bldg, zone=zone, merge_windows=merge_windows, within=(prj.name + '.' + bldg.name + '.' + bldg.name + "_Models"), modelica_info=prj.modelica_info)) aixlib_output._help_package(zone_path, bldg.name + "_Models", within=prj.name + '.' + bldg.name) aixlib_output._help_package_order(zone_path, bldg.thermal_zones, (bldg.name + "_")) out_file.close() print("Exports can be found here:") print(path)
def export_aixlib(prj, building_model="None", zone_model="None", corG=None, internal_id=None, path=None): '''Exports values to a record file for Modelica simulation The Export function for creating a AixLib LOM Multizone model Parameters ---------- building_model : string setter of the used Aixlib building model (None, MultizoneEquipped, Multizone) zone_model : string setter of the used Aixlib zone model (ThermalZoneEquipped, ThermalZone) corG : boolean setter of the used g value calculation in the model internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path ''' #check the arguments assert building_model in ["None", "MultizoneEquipped", "Multizone"] assert zone_model in ["None", "ThermalZoneEquipped", "ThermalZone"] assert corG in [None, True, False] uses = ['Modelica(version = "3.2.1")', "AixLib(version=\"0.3.1\")"] # use the same zone templates for all exports zone_template = Template(filename=utilitis.get_full_path( "Data\\Output\\ModelicaTemplate\\AixLib\\AixLib_zone")) model_template = Template(filename=utilitis.get_full_path( "Data\\Output\\ModelicaTemplate\\AixLib\\AixLib_model")) zone_base_template = Template(filename=utilitis.get_full_path( "Data\\Output\\ModelicaTemplate\\AixLib\\AixLib_base")) # list which contains exported buildings if internal_id is not None: exported_list_of_buildings = [ bldg for bldg in prj.buildings if bldg.internal_id == internal_id ] else: exported_list_of_buildings = prj.buildings # here we diff between zonerecord export and full model support if building_model != "None" and zone_model != "None" and\ corG is not None: # full model support here print("full model support") _help_package(path, prj.name, uses) _help_package_order(path, exported_list_of_buildings) for bldg in exported_list_of_buildings: if bldg.merge_windows_calc is True: calc_method = 'vdi' elif bldg.merge_windows_calc is False: calc_method = 'ebc' bldg_path = path + "\\" + bldg.name + "\\" utilitis.create_path(utilitis.get_full_path(bldg_path)) utilitis.create_path( utilitis.get_full_path(bldg_path + bldg.name + "_DataBase")) aixlib.modelica_set_temp(bldg=bldg, path=path + "\\" + bldg.name) aixlib.modelica_AHU_boundary(bldg=bldg, path=path + "\\" + bldg.name) aixlib.modelica_gains_boundary(bldg=bldg, path=path + "\\" + bldg.name) _help_package(bldg_path, bldg.name) _help_package_order(bldg_path, [bldg], None, bldg.name + "_DataBase") out_file = open( utilitis.get_full_path(bldg_path + bldg.name + ".mo"), 'w') out_file.write( model_template.render_unicode( bldg=bldg, mod_prj=prj.modelica_project, weather=prj.weather_file_path, weather_header=prj.weather_file_header, model=building_model, zone=zone_model, physics=calc_method, gFac=corG)) out_file.close() for zone in bldg.thermal_zones: zone_path = bldg_path + bldg.name + "_DataBase" + "\\" out_file = open( utilitis.get_full_path(zone_path + "\\" + bldg.name + "_" + zone.name.replace(" ", "") + ".mo"), 'w') out_file.write( zone_template.render_unicode(bldg=bldg, zone=zone)) out_file.close() _help_package(zone_path, bldg.name + "_DataBase") _help_package_order(zone_path, bldg.thermal_zones, bldg.name + "_", bldg.name + "_base") out_file = open( utilitis.get_full_path(zone_path + bldg.name + "_base.mo"), 'w') if bldg.central_ahu: out_file.write( zone_base_template.render_unicode( bldg=bldg, zone=zone, mod_prj=prj.modelica_project, central_ahu=bldg.central_ahu)) out_file.close() else: out_file.write( zone_base_template.render_unicode( bldg=bldg, zone=zone, mod_prj=prj.modelica_project)) out_file.close() print("Exports can be found here:") print(path) elif building_model == "None" and zone_model == "None" and\ corG is None: # only export the baserecords _help_package(path, prj.name, uses) _help_package_order(path, exported_list_of_buildings) for bldg in exported_list_of_buildings: bldg_path = path + "\\" + bldg.name + "\\" utilitis.create_path(utilitis.get_full_path(bldg_path)) utilitis.create_path( utilitis.get_full_path(bldg_path + bldg.name + "_DataBase")) _help_package(bldg_path, bldg.name) _help_package_order(bldg_path, [bldg], None, bldg.name + "_DataBase") for zone in bldg.thermal_zones: zone_path = bldg_path + bldg.name + "_DataBase" + "\\" out_file = open( utilitis.get_full_path(zone_path + "\\" + bldg.name + "_" + zone.name.replace(" ", "") + ".mo"), 'w') out_file.write( zone_template.render_unicode( bldg=bldg, zone=zone, calc_core=bldg._calculation_method)) out_file.close() print("Exports can be found here:") print(path) else: # not clearly specified print("please specify you export clearly")
def modelica_gains_boundary(self, zone, time_line=None, path=None): """creates .mat file for internal gains boundary conditions This function creates a matfile (-v4) for building internal gains boundary conditions. It collects internal gain profiles of a specific zones and stores them into one file. It also calculates the internal gains from relative presence and values for heat output into W for direct usage in Annex models. Only person (convective and radiative) and machines (convective) are used in the simple Annex 60 examples. 1. Column : time step 2 Column : profile_persons, radiative 3 Column : profile_persons, convective 4 Column : profile_machines, convective Note ---------- When time line is created, we need to add a 0 to first element of all boundaries. This is due to to expected format in Modelica. Parameters ---------- zone : ThermalZone() TEASER instance of ThermalZone. As IBPSA computes single models for single zones, we need to generate individual files for zones and internal gains time_line :[[int]] list of time steps path : str optional path, when matfile is exported separately """ if path is None: path = utilities.get_default_path() else: pass utilities.create_path(path) path = os.path.join(path, self.file_internal_gains) if time_line is None: duration = len(zone.use_conditions.profile_persons) * \ 3600 time_line = self.create_profile(duration_profile=duration) ass_error_1 = "time line and input have to have the same length" assert len(time_line) - 1 == len( zone.use_conditions.profile_persons), \ (ass_error_1 + ",profile_persons") assert len(time_line) - 1 == len( zone.use_conditions.profile_machines), \ (ass_error_1 + ",profile_machines") for i, time in enumerate(time_line): if i == 0: time.append(0) time.append(0) time.append(0) else: time.append(zone.use_conditions.profile_persons[i - 1] * zone.use_conditions.persons * zone.use_conditions.activity_type_persons * 50 * (1 - zone.use_conditions.ratio_conv_rad_persons)) time.append(zone.use_conditions.profile_persons[i - 1] * zone.use_conditions.persons * zone.use_conditions.activity_type_persons * 50 * zone.use_conditions.ratio_conv_rad_persons) time.append(zone.use_conditions.profile_machines[i - 1] * zone.use_conditions.machines * zone.use_conditions.activity_type_machines * 50) internal_boundary = np.array(time_line) scipy.io.savemat(path, mdict={'Internals': internal_boundary}, appendmat=False, format='4')
def export_ibpsa( buildings, prj, path=None): """Exports models for IBPSA library Export a building to several models for IBPSA.ThermalZones.ReducedOrder. Depending on the chosen calculation method models for 1, 2, 3, or 4 element model are exported. In addition you can specify if windows should be lumped into the walls, like it is done in VDI 6007 (merge_windows=True) or not. For each zone, one model is exported, if you want to combine all thermal zones into one model, consider using AixLib. The export includes internal gains from use conditions ( calculated in teaser.logic.calculation.ibpsa) but does not include any heating or cooling equipment. Parameters ---------- buildings : list of instances of Building list of TEASER instances of a Building that are exoirted If you want to export a single building, please pass it over as a list containing only that building. prj : instance of Project Instance of TEASER Project object to access Project related information, e.g. name or version of used libraries path : string if the Files should not be stored in default output path of TEASER, an alternative path can be specified as a full path Attributes ---------- lookup : TemplateLookup object Instance of mako.TemplateLookup to store general functions for templates model_template_1 : Template object Template for ThermalZoneRecord using 1 element model model_template_2 : Template object Template for ThermalZoneRecord using 2 element model model_template_3 : Template object Template for ThermalZoneRecord using 3 element model model_template_4 : Template object Template for ThermalZoneRecord using 4 element model """ uses = uses = [ 'Modelica(version="' + prj.modelica_info.version + '")', 'IBPSA(version="' + prj.buildings[-1].library_attr.version + '")'] lookup = TemplateLookup(directories=[utilities.get_full_path( os.path.join('data', 'output', 'modelicatemplate'))]) model_template_1 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/IBPSA/IBPSA_OneElement"), lookup=lookup) model_template_2 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/IBPSA/IBPSA_TwoElements"), lookup=lookup) model_template_3 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/IBPSA/IBPSA_ThreeElements"), lookup=lookup) model_template_4 = Template( filename=utilities.get_full_path( "data/output/modelicatemplate/IBPSA/IBPSA_FourElements"), lookup=lookup) aixlib_output._help_package( path=path, name=prj.name, uses=uses, within=None) aixlib_output._help_package_order( path=path, package_list=buildings, addition=None, extra=None) for i, bldg in enumerate(buildings): ass_error = "You chose AixLib calculation, " \ "but want to export IBPSA models, " \ "this is not possible" assert bldg.used_library_calc == 'IBPSA', ass_error bldg_path = os.path.join(path, bldg.name) utilities.create_path(utilities.get_full_path(bldg_path)) utilities.create_path(utilities.get_full_path( os.path.join(bldg_path, bldg.name + "_Models"))) aixlib_output._help_package( path=bldg_path, name=bldg.name, within=bldg.parent.name) aixlib_output._help_package_order( path=bldg_path, package_list=[], addition=None, extra=bldg.name + "_Models") zone_path = os.path.join( bldg_path, bldg.name + "_Models") for zone in bldg.thermal_zones: zone.parent.library_attr.file_internal_gains = \ 'InternalGains_' + bldg.name + zone.name + '.mat' bldg.library_attr.modelica_gains_boundary( zone=zone, time_line=None, path=zone_path) out_file = open(utilities.get_full_path(os.path.join( zone_path, bldg.name + '_' + zone.name + '.mo')), 'w') if type(zone.model_attr).__name__ == "OneElement": out_file.write(model_template_1.render_unicode(zone=zone)) elif type(zone.model_attr).__name__ == "TwoElement": out_file.write(model_template_2.render_unicode(zone=zone)) elif type(zone.model_attr).__name__ == "ThreeElement": out_file.write(model_template_3.render_unicode(zone=zone)) elif type(zone.model_attr).__name__ == "FourElement": out_file.write(model_template_4.render_unicode(zone=zone)) out_file.close() aixlib_output._help_package( path=zone_path, name=bldg.name + "_Models", within=prj.name + '.' + bldg.name) aixlib_output._help_package_order( path=zone_path, package_list=bldg.thermal_zones, addition=bldg.name + "_") print("Exports can be found here:") print(path)
def export_annex60(prj, number_of_elements=2, merge_windows=False, internal_id=None, path=None): """Exports values to a record file for Annex60 simulation The Export function for creating a Annex60 example model Parameters ---------- number_of_elements : int defines the number of elements, that area aggregated, between 1 and 4, default is 2 merge_windows : bool True for merging the windows into the outer walls, False for separate resistance for window, default is False internal_id : float setter of the used building which will be exported, if None then all buildings will be exported path : string if the Files should not be stored in OutputData, an alternative path can be specified as a full and absolute path """ uses = ['Modelica(version = "3.2.1")', 'Annex60(version="0.1")'] if internal_id is not None: exported_list_of_buildings = [bldg for bldg in prj.buildings if bldg.internal_id == internal_id] else: exported_list_of_buildings = prj.buildings aixlib_output._help_package(path, prj.name, uses) aixlib_output._help_package_order(path, exported_list_of_buildings) if number_of_elements == 1: pass elif number_of_elements == 2: zone_template = Template(filename=utilitis.get_full_path( "Data\\Output\\ModelicaTemplate\\Annex60\\Annex60_TwoElements")) elif number_of_elements == 3: zone_template = Template(filename=utilitis.get_full_path( "Data\\Output\\ModelicaTemplate\\Annex60\\Annex60_ThreeElements")) elif number_of_elements == 4: zone_template = Template(filename=utilitis.get_full_path( "Data\\Output\\ModelicaTemplate\\Annex60\\Annex60_FourElements")) for bldg in exported_list_of_buildings: bldg_path = os.path.join(path, bldg.name) utilitis.create_path(utilitis.get_full_path(bldg_path)) utilitis.create_path(utilitis.get_full_path(bldg_path+ "\\" + bldg.name + \ "_Models")) aixlib_output._help_package(bldg_path, bldg.name) aixlib_output._help_package_order(bldg_path, [bldg], None, bldg.name + "_Models") for zone in bldg.thermal_zones: zone_path = os.path.join(bldg_path, bldg.name+"_Models") out_file = open(utilitis.get_full_path( zone_path + "\\" + bldg.name + "_" + zone.name.replace(" ", "") + ".mo"), 'w') out_file.write(zone_template.render_unicode(bldg=bldg, zone=zone, merge_windows= merge_windows)) aixlib_output._help_package(zone_path, bldg.name + "_Models") aixlib_output._help_package_order(zone_path, bldg.thermal_zones, (bldg.name + "_")) out_file.close() print("Exports can be found here:") print(path)