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

Two FMUs using PYFMI and the DoStep method

asked 2021-07-12 13:19:54 -0500

jdominguez94's avatar

updated 2021-07-12 13:29:08 -0500

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.

edit retag flag offensive close merge delete

Comments

What do you mean by the input that triggers the model is not activated? Which variable are you referring to?

Thierry Nouidui's avatar Thierry Nouidui  ( 2021-07-13 02:25:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-20 01:19:37 -0500

siown's avatar

You may try pyfmi.master class for coupled simulation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Careers

Question Tools

2 followers

Stats

Asked: 2021-07-12 13:19:54 -0500

Seen: 383 times

Last updated: Jul 12 '21