def main():

    starttime = time.time()

    #create a office typebuilding
    prj = Project(load_data=True)
    prj.type_bldg_office(name="Office1",
                         year_of_construction=1988,
                         number_of_floors=2,
                         height_of_floors=3.5,
                         net_leased_area=100,
                         office_layout=1,
                         window_layout=1,
                         with_ahu=True,
                         construction_type="heavy")

    #path where the export is stored
    output_path = os.path.join('D:\Temp', 'OutputData')

    print(os.path.join(output_path, 'OneBuildingSim'))
    prj.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=False,
                      path=os.path.join(output_path, 'OneBuildingSim'))
    """
    Now we need to simulate this, therefore we get the names of the current
    buildings in this project
    """
    buildingNames = []
    for bld in prj.buildings:
        buildingNames.append(bld.name)
    """
    Now we define the output directory where the simulation results should be
    stored, in addition we need to define the path where the exported models
    are"""

    outputDir = "D:/TestCampusSimulation"
    packageDir = output_path + "/OneBuildingSim" + "/Project"
    """
    Now we need to create a simulation list for buildingspy
    """

    li = []
    for bld in prj.buildings:
        #this is necessary for the correct names in the simulation script
        name = "Project." + bld.name + "." + bld.name
        s = si.Simulator(name, "dymola", outputDir, packageDir)
        li.append(s)

    po = Pool(processes=3)
    # i think we can use async here because we do not need a particular order
    # of the results
    po.map(simulateCase, li)

    ### Timer
    endtime = time.time()
    print('Simulation lasts: ', endtime - starttime, ' seconds or ',
          (endtime - starttime) / 60, ' minutes! or',
          (endtime - starttime) / (60 * 60))
Exemplo n.º 2
0
def main():
    ''' Main method that configures and runs all simulations
    '''
    # Build list of cases to run
    li = []
    # First model
    model = 'Buildings.Controls.Continuous.Examples.PIDHysteresis'
    s = si.Simulator(model, 'dymola', 'case1')
    s.addParameters({'con.eOn': 0.1})
    li.append(s)
    # second model
    s = si.Simulator(model, 'dymola', 'case2')
    s.addParameters({'con.eOn': 1})
    li.append(s)

    # Run all cases in parallel
    po = Pool()
    po.map(simulateCase, li)
def main():

    starttime = time.time()
    #Adjust this path to your TEASER teaser Examples path or whatever you want
    this_path = "D:/GIT/TEASER/teaser/Examples"
    #path of the buildings xmls
    input_path = os.path.join(this_path, 'ExampleInputFiles', 'MelatenXML')
    #path where the export is stored
    output_path = os.path.join(os.path.dirname(this_path), 'OutputData')

    info_list = read_XMLs(input_path)

    prj = create_reference_project(info_list)
    print(os.path.join(output_path, 'Reference'))
    prj.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=False,
                      path=os.path.join(output_path, 'Reference'))
    """
    Now we need to simulate this, therefore we get the names of the current
    buildings in this project
    """
    buildingNames = []
    for bld in prj.buildings:
        buildingNames.append(bld.name)
    """
    Now we define the output directory where the simulation results should be
    stored, in addition we need to define the path where the exported models
    are"""

    outputDir = "D:/TestCampusSimulation"
    packageDir = output_path + "/Reference" + "/Project"
    """
    Now we need to create a simulation list for buildingspy
    """

    li = []
    for bld in prj.buildings:
        #this is necessary for the correct names in the simulation script
        name = "Project." + bld.name + "." + bld.name
        s = si.Simulator(name, "dymola", outputDir, packageDir)
        li.append(s)

    po = Pool(processes=3)
    po.map(simulateCase, li)

    ### Timer
    endtime = time.time()
    print('Simulation lasts: ', endtime - starttime, ' seconds or ',
          (endtime - starttime) / 60, ' minutes! or',
          (endtime - starttime) / (60 * 60))
Exemplo n.º 4
0
def main():
    ''' Main method that configures and runs all simulations
    '''
    import shutil
    # Build list of cases to run
    #print 'hi'
    li = []
    model = 'Topology_Analysis_5GDHC.Automated_5GDHC.Test'
    s = si.Simulator(model, 'dymola', 'case1')
    s.addParameters({'Office4.connected': False})

    li.append(s)

    # Run all cases in parallel
    po = Pool()
    po.map(simulateCase, li)
def main():
    li = []
    model = 'Topology_Analysis_5GDHC.Automated_5GDHC.Test'
    i = 0
    scenarios = ta.SetSimulations()
    for activeBuildings in scenarios:
	    for scenario in activeBuildings[3]:
	    	i += 1
	    	name = "case" + str(i)
	    	s = si.Simulator(model, 'dymola', name)
	    	for parameters in scenario:
	    		#print (parameters)
	    		s.addParameters({parameters[0]: parameters[1]})
            	li.append(s)
    
    # Run all cases in parallel
    po = Pool()
    po.map(simulateCase, li)
Exemplo n.º 6
0
def main():
    ''' Main method that configures and runs all simulations
    '''
    import copy
    import shutil

    from multiprocessing import Pool
    # Build list of cases to run
    li = []

    # First model
    model = 'Buildings.Controls.Continuous.Examples.PIDHysteresis'
    s1 = si.Simulator(model, 'dymola')
    s1.setOutputDirectory('case1')
    s1.addParameters({'con.eOn': 0.1})
    s1.setSolver('dassl')
    s1.showGUI(False)
    # Translate the model
    s1.translate()
    # Add the model to the list of models to be simulated
    li.append(s1)

    # Second model
    s2 = copy.deepcopy(s1)
    s2.setOutputDirectory('case2')
    s2.addParameters({'con.eOn': 1})
    li.append(s2)

    # Run both models in parallel
    po = Pool()
    po.map(simulateTranslatedModel, li)
    # Clean up
    # Clean up
    shutil.rmtree('case1')
    shutil.rmtree('case2')
    s1.deleteTranslateDirectory()
Exemplo n.º 7
0
def simulate_in_dymola(heaPum, data, tableName, tableFileName):
    """ Evaluate the heat pump performance from the model in Dymola.

    :param heaPum: Heat pump model (object).
    :param data: Reference performance data (object).
    :param tableName: Name of the combiTimeTable.
    :param tableFileName: Name of the text file containing the combiTimeTable.

    :return: Performance data of the modeled heat pump (object).

    .. note:: Performance data from the model is evaluated at the same
              operating conditions (inlet water temperatures and mass flow
              rates at the source and load sides) as in the reference data.

    """
    import buildingspy.simulate.Simulator as si
    from buildingspy.io.outputfile import Reader
    from scipy.interpolate import interp1d
    from builtins import str
    import getpass
    import os
    import tempfile

    # Find absolute path to buildings library
    packagePath = os.path.normpath(
        os.path.join(os.path.normpath(os.path.dirname(__file__)), '..', '..',
                     '..', '..', '..', '..'))

    # Create temporary directory for simulation files
    dirPrefix = tempfile.gettempprefix()
    tmpDir = tempfile.mkdtemp(prefix=dirPrefix + '-' + 'HeatPumpCalibration' +
                              '-' + getpass.getuser() + '-')

    # Set parameters for simulation in Dymola
    calModelPath = heaPum.modelicaCalibrationModelPath()
    s = si.Simulator(calModelPath,
                     'dymola',
                     outputDirectory=tmpDir,
                     packagePath=packagePath)
    s = heaPum.set_ModelicaParameters(s)
    m1_flow_nominal = min(data.flowSource)
    m2_flow_nominal = min(data.flowLoad)
    tableFilePath = \
        str(os.path.join(tmpDir, tableFileName).replace(os.sep, '/'))
    s.addParameters({
        'm1_flow_nominal': m1_flow_nominal,
        'm2_flow_nominal': m2_flow_nominal,
        'calDat.fileName': tableFilePath
    })

    # Write CombiTimeTable for dymola
    data.write_modelica_combiTimeTable(tableName, tmpDir, tableFileName,
                                       heaPum.CoolingMode)

    # Simulation parameters
    s.setStopTime(len(data.EWT_Source))
    s.setSolver('dassl')
    # Kill the process if it does not finish in 2 minutes
    s.setTimeOut(120)
    s.showProgressBar(False)
    s.printModelAndTime()
    #    s.showGUI(show=True)
    #    s.exitSimulator(exitAfterSimulation=False)
    s.simulate()

    # Read results
    modelName = heaPum.modelicaModelName()
    ofr = Reader(os.path.join(tmpDir, modelName), 'dymola')
    (time1, QCon) = ofr.values('heaPum.QCon_flow')
    (time1, QEva) = ofr.values('heaPum.QEva_flow')
    (time1, P) = ofr.values('heaPum.P')

    t = [float(i) + 0.5 for i in range(len(data.EWT_Source))]

    f_P = interp1d(time1, P)
    P = f_P(t)
    f_QCon = interp1d(time1, QCon)
    QCon = f_QCon(t)
    f_QEva = interp1d(time1, QEva)
    QEva = f_QEva(t)

    #    # Clean up
    #    shutil.rmtree('calibrationModel')
    if heaPum.CoolingMode:
        Capacity = -QEva
        HR = QCon
    else:
        Capacity = QCon
        HR = -QEva
    dymRes = SimulationResults(data.EWT_Source, data.EWT_Load, data.flowSource,
                               data.flowLoad, Capacity, HR, P, 'Modelica')
    return dymRes
    s.showProgressBar(False)
    s.printModelAndTime()
    s.simulate()


def simulateTranslatedModel(s):
    s.setStopTime(3600 * 24 * 365)
    s.setTimeOut(60 * 20)
    s.showProgressBar(False)
    s.printModelAndTime()
    s.simulate_translated()


def Run_TA(model, case, urbanOptFile, modelicaDir, alwaysActiveProsumers,
           loads, resultDir, dynamics):
    s = si.Simulator(model, 'dymola')
    s.setSolver('dassl')
    s.showGUI(False)
    s.translate()
    li = []
    scenarios = ta.SetSimulations(case=case,
                                  urbanOptFile=urbanOptFile,
                                  modelicaDir=modelicaDir,
                                  alwaysActiveProsumers=alwaysActiveProsumers,
                                  loads=loads,
                                  dynamics=dynamics)
    i = 0

    for activeBuildings in scenarios:
        for topology in activeBuildings[3]:
            i += 1
Exemplo n.º 9
0

# Function to set common parameters and to run the simulation
def simulateCase(s):
    s.setStopTime(86400)
    # Kill the process if it does not finish in 1 minute
    s.setTimeOut(60)
    s.showProgressBar(False)
    s.printModelAndTime()
    s.simulate()


# Main function
if __name__ == '__main__':

    # Build list of cases to run
    li = []
    # First model
    model = 'Buildings.Controls.Continuous.Examples.PIDHysteresis'
    s = si.Simulator(model, 'dymola', 'case1')
    s.addParameters({'con.eOn': 0.1})
    li.append(s)
    # second model
    s = si.Simulator(model, 'dymola', 'case2')
    s.addParameters({'con.eOn': 1})
    li.append(s)

    # Run all cases in parallel
    po = Pool()
    po.map(simulateCase, li)
Exemplo n.º 10
0
FileSimulation = 'PTTL_SF_'

# ----------- DEFINE SIMULATION TIME ------------
# 2016.06.29   #2016.06.30   #2016.07.01  #2016.07.04    #2016.07.05    #2016.07.06
StartModTime = [46000, 40000, 37000, 43000, 43000, 41000]
StopModTime = [58000, 54000, 53000, 57000, 56000, 50000]
Delta_Time = StopModTime[KKK] - StartModTime[KKK]

#----------- LOAD AND TRANSLATE MODELICA MODEL           ------------
model = 'package_PSA_SFERAII.Simulations.PTTL_SF_basic_' + Days[KKK]

PACKAGE = os.path.join(
    'C:\Users\susanna\Documents\GitHub\PSA_SFERAII\Modelling/',
    'package_PSA_SFERAII')
s = si.Simulator(model,
                 'dymola',
                 outputDirectory=StoreModResult,
                 packagePath=PACKAGE)

# Set Time for plot
TimeNoInit = 500  # Set a value to phase out the initialization line
StartPlotTime = [StartModTime[KKK] + TimeNoInit]
StopPlotTime = [StopModTime[KKK]]

if OPTIMIZE == 'True':
    s.setNumberOfIntervals(500)
    s.setSolver('Dassl')
    s.translate()

    def optimizeCoeff(In):
        eps = In[0]
        print 'Current eps:', eps
def example_type_district():
    """"First thing we need to do is to import our Project API module"""

    from teaser.project import Project
    from random import randint
    import buildingspy.simulate.Simulator as Si
    import time
    from multiprocessing import Pool

    """We instantiate the Project class. The parameter load_data = True indicates
    that we load the XML data bases into our Project.
    This can take a few sec."""

    starttime = time.time()

    prj_est1 = Project(load_data=True)
    prj_est1.name = "EST1"
    prj_est4 = Project(load_data=True)
    prj_est4.name = "EST4"
    prj_est7 = Project(load_data=True)
    prj_est7.name = "EST7"
    """The functions starting with type_bldg giving us the opportunity to
    create the specific type building (e.g. type_bldg_residential). The function
    automatically calculates all the necessary parameter. If not specified different
    it uses vdi calculation method."""

    number_of_buildings_est1 = 14

    for building in range(1,round((number_of_buildings_est1)*0.67)+1):
        name_help = "Building" + str(building)
        year_of_construction_help = randint(1960,1980)
        prj_est1.type_bldg_est1a(name=name_help,
                            year_of_construction=year_of_construction_help,
                            number_of_floors=2,
                            height_of_floors=3.15,
                            net_leased_area=92,
                            with_ahu=False,
                            neighbour_buildings=0,
                            construction_type="heavy")

    for building in range(round((number_of_buildings_est1)*0.67)+1,
                          number_of_buildings_est1+1):
        name_help = "Building" + str(building)
        year_of_construction_help = randint(1960,1980)
        prj_est1.type_bldg_est1b(name=name_help,
                            year_of_construction=year_of_construction_help,
                            number_of_floors=2,
                            height_of_floors=3.15,
                            net_leased_area=92*2,
                            with_ahu=False,
                            neighbour_buildings=0,
                            construction_type="heavy",
                            number_of_apartments=2)

    number_of_buildings_est4 = 4

    for building in range(1,number_of_buildings_est4+1):
        name_help = "Building" + str(building)
        year_of_construction_help = randint(1960,1980)
        prj_est4.type_bldg_est4b(name=name_help,
                            year_of_construction=year_of_construction_help,
                            number_of_floors=9,
                            height_of_floors=2.6,
                            net_leased_area=417*9,
                            with_ahu=False,
                            neighbour_buildings=2,
                            construction_type="heavy",
                            number_of_apartments=38)

    number_of_buildings_est7 = 29

    for building in range(1,round((number_of_buildings_est7)*0.45)+1):
        name_help = "Building" + str(building)
        year_of_construction_help = randint(1900,1918)
        prj_est7.type_bldg_est7(name=name_help,
                            year_of_construction=year_of_construction_help,
                            number_of_floors=3,
                            height_of_floors=3.88,
                            net_leased_area=65*3,
                            with_ahu=False,
                            neighbour_buildings=2,
                            construction_type="heavy",
                            number_of_apartments=1)

    for building in range(round((number_of_buildings_est7)*0.45)+1,
                          number_of_buildings_est7+1):
        name_help = "Building" + str(building)
        year_of_construction_help = randint(1900,1918)
        prj_est7.type_bldg_est7(name=name_help,
                            year_of_construction=year_of_construction_help,
                            number_of_floors=3,
                            height_of_floors=3.88,
                            net_leased_area=65*3,
                            with_ahu=False,
                            neighbour_buildings=2,
                            construction_type="heavy",
                            number_of_apartments=2)

    """To export the parameters to a Modelica record, we use the export_record
    function. path = None indicates, that we want to store the records in \
    TEASER'S Output folder"""

    prj_est1.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=True,
                      internal_id=None,
                      path=None)

    prj_est4.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=True,
                      internal_id=None,
                      path=None)

    prj_est7.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=True,
                      internal_id=None,
                      path=None)

    """Now we retrofit all buildings in the year 2015 (EnEV2014). \
    That includes new insulation layer and new windows. The name is changed \
    to Retrofit"""

    prj_est1.name = "EST1_Retrofit"
    prj_est1.retrofit_all_buildings(2015)
    prj_est1.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=True,
                      internal_id=None,
                      path=None)

    prj_est4.name = "EST4_Retrofit"
    prj_est4.retrofit_all_buildings(2015)
    prj_est4.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=True,
                      internal_id=None,
                      path=None)

    prj_est7.name = "EST7_Retrofit"
    prj_est7.retrofit_all_buildings(2015)
    prj_est7.export_aixlib(building_model="MultizoneEquipped",
                      zone_model="ThermalZoneEquipped",
                      corG=True,
                      internal_id=None,
                      path=None)

    endtime = time.time()

    print('Pre-processing lasts: ', endtime - starttime, ' seconds or ',
          (endtime - starttime) / 60, ' minutes! or',
          (endtime - starttime) / (60 * 60), 'hours.')

    starttime = time.time()

    """
    Now we define the output directory where the simulation results should be
    stored, in addition we need to define the path where the exported models
    are"""

    outputdir_est1 = "D:/Dymola_workspace/EST1"
    packagedir_est1 = "C:/Users\mla\TEASEROutput/EST1"
    outputdir_est1_retrofit = "D:/Dymola_workspace/EST1_Retrofit"
    packagedir_est1_retrofit = "C:/Users\mla\TEASEROutput/EST1_Retrofit"
    outputdir_est4 = "D:/Dymola_workspace/EST4"
    packagedir_est4 = "C:/Users\mla\TEASEROutput/EST4"
    outputdir_est4_retrofit = "D:/Dymola_workspace/EST4_Retrofit"
    packagedir_est4_retrofit = "C:/Users\mla\TEASEROutput/EST4_Retrofit"
    outputdir_est7 = "D:/Dymola_workspace/EST7"
    packagedir_est7 = "C:/Users\mla\TEASEROutput/EST7"
    outputdir_est7_retrofit = "D:/Dymola_workspace/EST7_Retrofit"
    packagedir_est7_retrofit = "C:/Users\mla\TEASEROutput/EST7_Retrofit"

    """
    Now we need to create a simulation list for buildingspy
    """

    li_est1 = []
    for bld in prj_est1.buildings:
        # this is necessary for the correct names in the simulation script
        name = "EST1." + bld.name + "." + bld.name
        s = Si.Simulator(name, "dymola", outputdir_est1, packagedir_est1)
        li_est1.append(s)

    li_est1_retrofit = []
    for bld in prj_est1.buildings:
        # this is necessary for the correct names in the simulation script
        name = "EST1_Retrofit." + bld.name + "." + bld.name
        s = Si.Simulator(name, "dymola", outputdir_est1_retrofit,
                         packagedir_est1_retrofit)
        li_est1_retrofit.append(s)

    li_est4 = []
    for bld in prj_est4.buildings:
        # this is necessary for the correct names in the simulation script
        name = "EST4." + bld.name + "." + bld.name
        s = Si.Simulator(name, "dymola", outputdir_est4, packagedir_est4)
        li_est4.append(s)

    li_est4_retrofit = []
    for bld in prj_est4.buildings:
        # this is necessary for the correct names in the simulation script
        name = "EST4_Retrofit." + bld.name + "." + bld.name
        s = Si.Simulator(name, "dymola", outputdir_est4_retrofit,
                         packagedir_est4_retrofit)
        li_est4_retrofit.append(s)

    li_est7 = []
    for bld in prj_est7.buildings:
        # this is necessary for the correct names in the simulation script
        name = "EST7." + bld.name + "." + bld.name
        s = Si.Simulator(name, "dymola", outputdir_est7, packagedir_est7)
        li_est7.append(s)

    li_est7_retrofit = []
    for bld in prj_est7.buildings:
        # this is necessary for the correct names in the simulation script
        name = "EST7_Retrofit." + bld.name + "." + bld.name
        s = Si.Simulator(name, "dymola", outputdir_est7_retrofit,
                         packagedir_est7_retrofit)
        li_est7_retrofit.append(s)

    po = Pool(processes=3)
    po.map(simulate_case, li_est1)
    po.map(simulate_case, li_est1_retrofit)
    po.map(simulate_case, li_est4)
    po.map(simulate_case, li_est4_retrofit)
    po.map(simulate_case, li_est7)
    po.map(simulate_case, li_est7_retrofit)

    # Timer
    endtime = time.time()
    print('Simulation lasts: ', endtime - starttime, ' seconds or ', (endtime - starttime) / 60, ' minutes! or',
          (endtime - starttime) / (60 * 60), 'hours.')
Exemplo n.º 12
0
SIMULATE = 'False'
# SET TIME FOR PLOT
TimeNoInit = 500  # Set a value to phase out the initialization line
StartPlotTime = [StartModTime[0] + TimeNoInit]
StopPlotTime = [StopModTime[0]]

Nodes = [2, 5, 10, 20, 50]

if SIMULATE == 'True':
    # LOAD MODELICA MODEL
    model = 'package_PSA_SFERAII.Simulations.PTTL_SF_basic'
    s = si.Simulator(
        model,
        'dymola',
        outputDirectory=ResultDirectory,
        packagePath=
        'C:\Users\susanna\Documents\GitHub\PSA_SFERAII\Modelling/package_PSA_SFERAII'
    )
    s.setNumberOfIntervals(500)
    s.setSolver('Dassl')
    for kk in range(len(Nodes)):
        s.addParameters({'EuroTrough.N': Nodes[kk]})
        s.addParameters({'EuroTrough.eps6': 0.943771684737})
        s.setResultFile(FileSimulation + str(Nodes[kk]))
        s.setStartTime(StartModTime[0])
        s.setStopTime(StopModTime[0])
        s.printModelAndTime()
        s.simulate()
else:
    s = 'None'