Esempio n. 1
0
def main(n_proc=multiprocessing.cpu_count() - 1):

    # Initialize the FMU model empty
    m = Model()

    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)

    # Define the path of the FMU file
    if platform.architecture()[0] == "32bit":
        print("32-bit architecture")
        filePath = os.path.join(dir_path, "..", "..", "modelica",
                                "FmuExamples", "Resources", "FMUs",
                                "FirstOrder.fmu")
    else:
        print("64-bit architecture")
        filePath = os.path.join(dir_path, "..", "..", "modelica",
                                "FmuExamples", "Resources", "FMUs",
                                "FirstOrder_64bit.fmu")

    # Assign an existing FMU to the model
    m.re_init(filePath)

    # Set the CSV file associated to the input
    inputPath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples",
                             "Resources", "data",
                             "SimulationData_FirstOrder.csv")
    input_u = m.get_input_by_name("u")
    input_u.get_csv_reader().open_csv(inputPath)
    input_u.get_csv_reader().set_selected_column("system.u")

    # Select the states to be modified
    m.add_variable(m.get_variable_object("x"))

    # Initialize the simulator
    m.initialize_simulator()

    # Instantiate the pool
    pool = FmuPool(m, processes=n_proc)

    # define the vector of initial conditions for which the simulations
    # have to be performed.
    # values has to be a list of state vectors
    # values = [ [x0_0], [x0_1], ... [x0_n]]
    vector_values = numpy.linspace(1.0, 5.0, 10)
    values = []
    for v in vector_values:
        temp = {"state": numpy.array([v]), "parameters": []}
        values.append(temp)

    # Run simulations in parallel
    pool_results = pool.run(values)

    # plot all the results
    show_results(pool_results)
Esempio n. 2
0
def main(n_proc = multiprocessing.cpu_count()-1):

    # Initialize the FMU model empty
    m = Model()

    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)

    # Define the path of the FMU file
    if platform.architecture()[0]=="32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples", "Resources", "FMUs", "FirstOrder.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples", "Resources", "FMUs", "FirstOrder_64bit.fmu")

    # Assign an existing FMU to the model
    m.re_init(filePath)

    # Set the CSV file associated to the input
    inputPath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples", "Resources", "data", "SimulationData_FirstOrder.csv")
    input_u = m.get_input_by_name("u")
    input_u.get_csv_reader().open_csv(inputPath)
    input_u.get_csv_reader().set_selected_column("system.u")
    
    # Select the states to be modified
    m.add_variable(m.get_variable_object("x"))

    # Initialize the simulator
    m.initialize_simulator()

    # Instantiate the pool
    pool = FmuPool(m, processes = n_proc)

    # define the vector of initial conditions for which the simulations
    # have to be performed.
    # values has to be a list of state vectors
    # values = [ [x0_0], [x0_1], ... [x0_n]]
    vector_values = numpy.linspace(1.0, 5.0, 10)
    values = []
    for v in vector_values:
        temp = {"state":numpy.array([v]), "parameters":[]}
        values.append(temp)
    
    # Run simulations in parallel
    pool_results = pool.run(values)
    
    # plot all the results
    show_results(pool_results)
Esempio n. 3
0
def main():

    # Initialize the FMU model empty
    m = Model()

    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)

    # Define the path of the FMU file
    if platform.architecture()[0] == "32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "modelica",
                                "FmuExamples", "Resources", "FMUs",
                                "FirstOrder.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "modelica",
                                "FmuExamples", "Resources", "FMUs",
                                "FirstOrder_64bit.fmu")

    # ReInit the model with the new FMU
    m.re_init(filePath)

    # Show details
    print m

    # Show the inputs
    print "The names of the FMU inputs are: ", m.get_input_names(), "\n"

    # Show the outputs
    print "The names of the FMU outputs are:", m.get_output_names(), "\n"

    # Set the CSV file associated to the input
    inputPath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples",
                             "Resources", "data",
                             "SimulationData_FirstOrder.csv")
    input_u = m.get_input_by_name("u")
    input_u.get_csv_reader().open_csv(inputPath)
    input_u.get_csv_reader().set_selected_column("system.u")

    # Initialize the model for the simulation
    m.initialize_simulator()

    # Simulate
    time, results = m.simulate()

    # Show the results
    show_results(time, results)
Esempio n. 4
0
def main():
    
    # Initialize the FMU model empty
    m = Model()
    
    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)
    
    # Define the path of the FMU file
    if platform.architecture()[0]=="32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples", "Resources", "FMUs", "FirstOrder.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples", "Resources", "FMUs", "FirstOrder_64bit.fmu")
    
    # ReInit the model with the new FMU
    m.re_init(filePath)
    
    # Show details
    print m
    
    # Show the inputs
    print "The names of the FMU inputs are: ", m.get_input_names(), "\n"
    
    # Show the outputs
    print "The names of the FMU outputs are:", m.get_output_names(), "\n"
    
    # Set the CSV file associated to the input
    inputPath = os.path.join(dir_path, "..", "..", "modelica", "FmuExamples", "Resources", "data", "SimulationData_FirstOrder.csv")
    input_u = m.get_input_by_name("u")
    input_u.get_csv_reader().open_csv(inputPath)
    input_u.get_csv_reader().set_selected_column("system.u")
    
    # Initialize the model for the simulation
    m.initialize_simulator()
                      
    # Simulate
    time, results = m.simulate()
    
    # Show the results
    show_results(time, results)
Esempio n. 5
0
def main():
    
    # Initialize the FMU model empty
    m = Model()
    
    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)
    
    # Define the path of the FMU file
    if platform.architecture()[0]=="32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "model", "model_se.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "model", "model_se.fmu")
    
    # ReInit the model with the new FMU
    m.re_init(filePath)
    
    # Show details
    print m
    
    # Show the inputs
    print "The names of the FMU inputs are: ", m.get_input_names(), "\n"
    
    # Show the outputs
    print "The names of the FMU outputs are:", m.get_output_names(), "\n"

    # Set the parameters of the model
    fixpars = OrderedDict([("bui.hva.cHea", 812249.38954445894), ("bui.hva.cTecRoo", 31682287.202939499),
                           ("bui.hva.capHea.TSta", 292.33922569546098), ("bui.hva.capTecRoo.TSta", 293.48308013220799),
                           ("bui.hva.hp1.Intercept", 2.61214752617), ("bui.hva.hp1.TAmb7", 0.054522645537),
                           ("bui.hva.hp1.TSup35", -0.0123192467622), ("bui.hva.hp1.E6500", -0.0001176597066),
                           ("bui.hva.hp1.TAmb7_E6500", -1.53890877556e-05), ("bui.hva.hp2.Intercept", 2.58406557762),
                           ("bui.hva.hp2.TAmb7", 0.0384068602888), ("bui.hva.hp2.TSup35", -0.025053392321),
                           ("bui.hva.hp2.E6500", -0.000141527731896), ("bui.hva.hp2.TAmb7_E6500", -1.50277640388e-05),
                           ("bui.hva.rLos", 0.0087779013329769198),
                           ("bui.hva.rTecRoo", 0.0050198340105892499), ("bui.hva.gb.Intercept", 0.872048186735),
                           ("bui.hva.gb.Q86000", -8.84828553083e-07), ("bui.hva.gb.TAmb7", 0.00481677713153)])
    fixpars.update(OrderedDict([("bui.use.nOcc", 136.67024436265001), ("bui.ven.mFloVen", 1.1072098104391299),
                                ("bui.zon.cInt", 455341540.68018103), ("bui.zon.cZon", 111540557.533288),
                                ("bui.zon.capInt.TSta", 293.61372904158401), ("bui.zon.capZon.TSta", 291.892741044606),
                                ("bui.zon.rInt", 0.00019259685456255999), ("bui.zon.rWal", 0.00094286602169893301),
                                ("bui.hva.fraRad", 0.0)]))

    # Set the values for the parameters
    m.get_fmu().reset()
    m.get_fmu().set(fixpars.keys(),fixpars.values())

    # Set the CSV file associated to the input
    path_monitoring_data = os.path.join(dir_path, "data", "dataset_simulation.csv")

    BXL = pytz.timezone("Europe/Brussels")
    df_data = pd.read_csv(path_monitoring_data, index_col=0, header=0, parse_dates=True)
    df_data = df_data.resample('900S')
    
    # Link the columns of the CSV file to the inputs
    for n in ["Q_HP1", "Q_HP2", "Q_GB", "TAmb", "I_GloHor_sat", "powEle", "QCon", "prfOcc", "prfVen"]:
        input = m.get_input_by_name(n)
        input.set_data_series(df_data[n])

    # Initialize the model for the simulation
    m.initialize_simulator()
                      
    # Simulate
    time, results = m.simulate()
    
    # Show the results and forward the data frame containing the real data
    show_results(time, results, df_data)

    return time, results
Esempio n. 6
0
def main():

    # Initialize the FMU model empty
    m = Model()

    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)

    # Define the path of the FMU file
    if platform.architecture()[0] == "32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "model", "model_se.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "model", "model_se.fmu")

    # ReInit the model with the new FMU
    m.re_init(filePath)

    # Show details
    print m

    # Show the inputs
    print "The names of the FMU inputs are: ", m.get_input_names(), "\n"

    # Show the outputs
    print "The names of the FMU outputs are:", m.get_output_names(), "\n"

    # Set the parameters of the model
    fixpars = OrderedDict([("bui.hva.cHea", 812249.38954445894),
                           ("bui.hva.cTecRoo", 31682287.202939499),
                           ("bui.hva.capHea.TSta", 292.33922569546098),
                           ("bui.hva.capTecRoo.TSta", 293.48308013220799),
                           ("bui.hva.hp1.Intercept", 2.61214752617),
                           ("bui.hva.hp1.TAmb7", 0.054522645537),
                           ("bui.hva.hp1.TSup35", -0.0123192467622),
                           ("bui.hva.hp1.E6500", -0.0001176597066),
                           ("bui.hva.hp1.TAmb7_E6500", -1.53890877556e-05),
                           ("bui.hva.hp2.Intercept", 2.58406557762),
                           ("bui.hva.hp2.TAmb7", 0.0384068602888),
                           ("bui.hva.hp2.TSup35", -0.025053392321),
                           ("bui.hva.hp2.E6500", -0.000141527731896),
                           ("bui.hva.hp2.TAmb7_E6500", -1.50277640388e-05),
                           ("bui.hva.rLos", 0.0087779013329769198),
                           ("bui.hva.rTecRoo", 0.0050198340105892499),
                           ("bui.hva.gb.Intercept", 0.872048186735),
                           ("bui.hva.gb.Q86000", -8.84828553083e-07),
                           ("bui.hva.gb.TAmb7", 0.00481677713153)])
    fixpars.update(
        OrderedDict([("bui.use.nOcc", 136.67024436265001),
                     ("bui.ven.mFloVen", 1.1072098104391299),
                     ("bui.zon.cInt", 455341540.68018103),
                     ("bui.zon.cZon", 111540557.533288),
                     ("bui.zon.capInt.TSta", 293.61372904158401),
                     ("bui.zon.capZon.TSta", 291.892741044606),
                     ("bui.zon.rInt", 0.00019259685456255999),
                     ("bui.zon.rWal", 0.00094286602169893301),
                     ("bui.hva.fraRad", 0.0)]))

    # Set the values for the parameters
    m.get_fmu().reset()
    m.get_fmu().set(fixpars.keys(), fixpars.values())

    # Set the CSV file associated to the input
    path_monitoring_data = os.path.join(dir_path, "data",
                                        "dataset_simulation.csv")

    BXL = pytz.timezone("Europe/Brussels")
    df_data = pd.read_csv(path_monitoring_data,
                          index_col=0,
                          header=0,
                          parse_dates=True)
    df_data = df_data.resample('900S')

    # Link the columns of the CSV file to the inputs
    for n in [
            "Q_HP1", "Q_HP2", "Q_GB", "TAmb", "I_GloHor_sat", "powEle", "QCon",
            "prfOcc", "prfVen"
    ]:
        input = m.get_input_by_name(n)
        input.set_data_series(df_data[n])

    # Initialize the model for the simulation
    m.initialize_simulator()

    # Simulate
    time, results = m.simulate()

    # Show the results and forward the data frame containing the real data
    show_results(time, results, df_data)

    return time, results