Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Two FMUs using PYFMI and the DoStep method

Hello guys,

I am trying to perform co-simulation using two FMUs from Energyplus and OpenModelica. The thing is that I am trying to simulate them through the do_step method, but it seems that PyFMI does not support working with both Models in parallel.

When I simulate the OpenModelica FMU (standalone case) using the below-mentioned code, it works fine

batt = load_fmu("/workspaces/Eplus93/source/Cosim/BattControlB.fmu")
starttime=0
finaltime=3600
batt.initialize(starttime, finaltime,True)
stepsize=0.2
CoreTemp=[]
HeatFlow=[]
In=[]
while t_step < finaltime:
  batt.set('PowerTrigger',int(10))
  status = batt.do_step(current_t=t_step, step_size=stepsize, new_step=True)
  CoreTemp.append(np.float(batt.get('CoreTemp')))
  HeatFlow.append(np.float(batt.get('HeatFlow')))
  In.append(np.float(batt.get('PowerTrigger')))

  t_step +=stepsize

The same happens with the EnergyPlus' FMU, it works fine as a standalone case. However, when I try to join both in the same simulation it does not work as expected. The

 while t_step < final_time:

        #Here I define the "Master" FMU
        i+=1
        house.set('Spoint1',sp1[i]) #Integer array
        house.set('Spoint2',sp2[i]) #Integer array
        troom=np.float(house.get('TRooMea'))
        Troom.append(troom)
        htgsp=np.float(house.get('SP1'))
        HtgSp.append(htgsp)

        status_house = house.do_step(current_t=t_step, step_size=stepsize, new_step=True)

        batt.set('T',troom)

       #Region to define the Slave FMU 

        while t_step2<= t_step
            batt.set('PowerTrigger',1)
            status_batt = batt.do_step(current_t=t_step2, step_size=stepsizeBat, new_step=True)
            current_heat=batt.get('HeatFlow')
            t_step2 += stepsizeBat

        logger.info("Energyplus Step {}, Modelica Step {}".format(t_step, t_step2))
        house.set('Q',current_heat)


        t_step += stepsize

Both (House and Batt) FMUs have different stepsizes being 0.2 and 600 in each case. In a nutshell, when I joined both FMUs the Modelica FMU simulates but the input that triggers the model is not activated. I do not know if these two While loops can be nested as I did, probably over there is the problem.

Two FMUs using PYFMI and the DoStep method

Hello guys,

I am trying to perform co-simulation using two FMUs from Energyplus and OpenModelica. The thing is that I am trying to simulate them through the do_step method, but it seems that PyFMI does not support working with both Models in parallel.

When I simulate the OpenModelica FMU (standalone case) using the below-mentioned code, it works fine

batt = load_fmu("/workspaces/Eplus93/source/Cosim/BattControlB.fmu")
starttime=0
finaltime=3600
batt.initialize(starttime, finaltime,True)
stepsize=0.2
CoreTemp=[]
HeatFlow=[]
In=[]
while t_step < finaltime:
  batt.set('PowerTrigger',int(10))
  status = batt.do_step(current_t=t_step, step_size=stepsize, new_step=True)
  CoreTemp.append(np.float(batt.get('CoreTemp')))
  HeatFlow.append(np.float(batt.get('HeatFlow')))
  In.append(np.float(batt.get('PowerTrigger')))

  t_step +=stepsize

The same happens with the EnergyPlus' FMU, it works fine as a standalone case. However, when I try to join both in the same simulation it does not work as expected. The

 house = load_fmu(fmudir,log_level=0)
 batt = load_fmu(fmudir2,log_level=0)

 batt.initialize(self.start_time, self.final_time, True)
 house.initialize(self.start_time, self.final_time,True)


 while t_step < final_time:

        #Here I define the "Master" FMU
        i+=1
        house.set('Spoint1',sp1[i]) #Integer array
        house.set('Spoint2',sp2[i]) #Integer array
        troom=np.float(house.get('TRooMea'))
        Troom.append(troom)
        htgsp=np.float(house.get('SP1'))
        HtgSp.append(htgsp)

        status_house = house.do_step(current_t=t_step, step_size=stepsize, new_step=True)

        batt.set('T',troom)

       #Region to define the Slave FMU 

        while t_step2<= t_step
            batt.set('PowerTrigger',1)
            status_batt = batt.do_step(current_t=t_step2, step_size=stepsizeBat, new_step=True)
            current_heat=batt.get('HeatFlow')
            t_step2 += stepsizeBat

        logger.info("Energyplus Step {}, Modelica Step {}".format(t_step, t_step2))
        house.set('Q',current_heat)


        t_step += stepsize

Both (House and Batt) FMUs have different stepsizes being 0.2 and 600 in each case. In a nutshell, when I joined both FMUs the Modelica FMU simulates but the input that triggers the model is not activated. I do not know if these two While loops can be nested as I did, probably over there is the problem.