def test_set_parameters(self): fmupath = os.path.join('resources', 'fmus', 'R1C1', 'R1C1.fmu') parameters = {'C': 2e6, 'R': 0.05} model2 = mshoot.SimFMU( fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor.T'], parameters=parameters, verbose=False) # Inputs t = np.arange(0, 86401, 3600) udf = pd.DataFrame(index=pd.Index(t, name='time'), columns=['q', 'Tout']) udf['q'] = np.full(t.size, 0) udf['Tout'] = np.full(t.size, 273.15) # Initial state x0 = [273.15 + 20] # Simulation ydf1, xdf1 = self.model.simulate(udf, x0) ydf2, xdf2 = model2.simulate(udf, x0) self.assertFalse((ydf1 == ydf2).all().all()) self.assertFalse((xdf1 == xdf2).all().all())
def setUp(self): fmupath = os.path.join('resources', 'fmus', 'R1C1', 'R1C1.fmu') parameters = {'C': 1e6, 'R': 0.01} self.model = mshoot.SimFMU(fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor.T'], parameters=parameters, verbose=False)
def get_model(): fmupath = os.path.join('resources', 'fmus', 'R2C2', 'R2C2.fmu') parameters = {'C': 1e5, 'R': 0.001} model = mshoot.SimFMU( fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor1.T', 'heatCapacitor2.T'], parameters=parameters, verbose=False) return model
import pandas as pd import numpy as np import matplotlib.pyplot as plt import mshoot fmupath = os.path.join('examples', 'tutorial', 'modelica', 'R3C3.fmu') # 1) Emulation model model_emu = mshoot.SimFMU( fmupath, outputs=['y', 'u1_y'], states=['heatCapacitor1.T', 'heatCapacitor2.T', 'heatCapacitor3.T'], parameters={ 'C1': 75000, 'C2': 100000, 'C3': 50000, 'R1': 0.01, 'R2': 0.01, 'R3': 0.01 }) # 2) Control model model_ctr = mshoot.SimFMU( fmupath, outputs=['y', 'u1_y'], states=['heatCapacitor1.T', 'heatCapacitor2.T', 'heatCapacitor3.T'], parameters={ 'C1': 75000, 'C2': 100000, 'C3': 50000,
else: os.makedirs(wdir) fmu_file = os.path.join(fmu_dir, fmu) # Read parameters and modify heating power (used for heating/cooling in this example) pm = pd.read_csv(par_file) parameters = dict() for p in pm: parameters[p] = pm.iloc[0][p] parameters['maxHeat'] = 6000. # [W] # Instantiate emulation and control models model_emu = mshoot.SimFMU(fmu_file, outputs=['T', 'qr', 'vetot'], states=['cair.T'], parameters=parameters, verbose=False) model_ctr = mshoot.SimFMU( fmu_file, outputs=['T', 'qr', 'vetot'], states=[ 'cair.T' ], # States should be initialized with fixed=False parameters=parameters, verbose=False) # Instantiate MPCEmulation mpc = mshoot.MPCEmulation(model_emu, cfun) step = 1
inp_mpc.index = inp_mpc.index - inp_mpc.index[0] # Initial state airT0 = 20. + 273.15 x0 = [airT0] # Instantiate emulation model for training pm = pd.read_csv(par_file) parameters = dict() for p in pm: parameters[p] = pm.iloc[0][p] parameters['maxHeat'] = 2000. # [W] model_emu = mshoot.SimFMU( fmu_file, outputs=['qr'], states=['cair.T'], parameters=parameters, verbose=False) # Simulate to get model outputs for training y_trn, x_trn = model_emu.simulate(inp_trn, x0) y_vld, x_vld = model_emu.simulate(inp_vld, x0) # Find optimal SVM model cgrid = np.arange(0.01, 4., 0.01) err = list() for c in cgrid: print("Testing C={}".format(c)) # Instantiate control model to be tested
# Set up logging logging.basicConfig(filename='test.log', filemode='w', level='DEBUG') # Random seed np.random.seed(1) # Setup # ================= # MPC model definition fmupath = os.path.join('resources', 'fmus', 'R1C1', 'R1C1.fmu') parameters = {'C': 1e6, 'R': 0.01} model_emu = mshoot.SimFMU( fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor.T'], parameters=parameters, verbose=False) model_ctr = mshoot.SimFMU( fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor.T'], parameters=parameters, verbose=False) # Output directory script_name = os.path.splitext(__file__)[0].split(os.path.sep)[-1] outdir = os.path.join('.', 'examples', 'out', script_name) if not os.path.exists(outdir): print('Creating directory: {}'.format(outdir))
wdir = os.path.join('examples', 'bs2019', 'case3', 'results', 'pid') # Skip the case, if results already there if not os.path.exists(wdir): os.makedirs(wdir) # Read parameters and modify Tve to allow cooling pm = pd.read_csv(par_file) parameters = dict() for p in pm: parameters[p] = pm.iloc[0][p] # parameters['Tve'] = 18. # In real building this temperature is higher. # # Here, we assume that the air passes through the # # rotary wheel HX (air preheated to around 18 degC), # # but not through the heating coil. # Instantiate emulation and control models model_pid = mshoot.SimFMU(fmu, outputs=['T', 'Qr', 'vetot', 'vpos', 'dpos'], states=['cair.T', 'co2.balance.CO2ppmv_i'], parameters=parameters, verbose=False) # Run ydf, xdf = model_pid.simulate(inp, x0) # Save results ydf.to_csv(os.path.join(wdir, 'ydf.csv')) xdf.to_csv(os.path.join(wdir, 'xdf.csv'))
# Read parameters and modify Tve to allow cooling pm = pd.read_csv(par_file) parameters = dict() for p in pm: parameters[p] = pm.iloc[0][p] # parameters['Tve'] = 18. # In real building this temperature is higher. # # Here, we assume that the air passes through the # # rotary wheel HX (air preheated to around 18 degC), # # but not through the heating coil. # Instantiate emulation and control models model_emu = mshoot.SimFMU(fmu, outputs=['T', 'Qr', 'vetot'], states=['cair.T', 'co2.balance.CO2ppmv_i'], parameters=parameters, verbose=False) model_ctr = mshoot.SimFMU( fmu, outputs=['T', 'Qr', 'vetot'], states=['cair.T', 'co2.balance.CO2ppmv_i' ], # States should be initialized with fixed=False parameters=parameters, verbose=False) # Instantiate MPCEmulation mpc = mshoot.MPCEmulation(model_emu, cfun) step = 1 horizon = hrz
import mshoot # Set up logging logging.basicConfig(filename='test.log', filemode='w', level='DEBUG') # Random seed np.random.seed(1) # MPC model definition fmu_R1C1_path = os.path.join('resources', 'fmus', 'RCModels_R1C1.fmu') fmu_R2C2_path = os.path.join('resources', 'fmus', 'RCModels_R2C2.fmu') model_emu = mshoot.SimFMU( fmu_R2C2_path, outputs=['q', 'T', 'p'], states=['heatCapacitorC.T'], parameters={'C': 1e6, 'R': 0.01, 'Ci': 1e3}, verbose=False) model_ctr = mshoot.SimFMU( fmu_R1C1_path, outputs=['q', 'T', 'p'], states=['heatCapacitorC.T'], parameters={'C': 1e6, 'R': 0.01}, verbose=False) # Output directory script_name = os.path.splitext(__file__)[0].split(os.path.sep)[-1] outdir = os.path.join('.', 'examples', 'out', script_name) if not os.path.exists(outdir): print('Creating directory: {}'.format(outdir))
# Set up logging logging.basicConfig(filename='test.log', filemode='w', level='INFO') # Random seed np.random.seed(1) # Setup # ================= # MPC model definition fmupath = os.path.join('resources', 'fmus', 'R2C2', 'R2C2.fmu') parameters = {'C': 1e6, 'R': 0.01} model_ctr = mshoot.SimFMU( # First FMU instance for control fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor1.T'], parameters=parameters, verbose=False) model_emu = mshoot.SimFMU( # Second FMU instance for emulation fmupath, outputs=['qout', 'Tr'], states=['heatCapacitor1.T'], parameters=parameters, verbose=False) # Output directory script_name = os.path.splitext(__file__)[0].split(os.path.sep)[-1] outdir = os.path.join('.', 'examples', 'out', script_name) if not os.path.exists(outdir): print('Creating directory: {}'.format(outdir))