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

FMU file simulation failed with FMPy

asked 2024-03-21 05:08:27 -0600

Burns's avatar

updated 2024-05-15 11:58:11 -0600

Dear all,

I am trying to export an .fmu fIle out of an .idf file and simulate it (using FMPy python lib) for quiet some time, but I guess I probably did something wrong, hope you can make me aware of the right way to do it.

My first goal is to have the possibility to set the AirCondition Setpoints from Python, simulate it in E+ and have the IndoorMeanAirTemperature and the AC Energy Usage plotted (or similar).

What I did so far:

  • Made a model in SketchUp & OpenStudio (simulation + outputs worked)
  • took the in.idf file and edited it in IDF Editor. Added External Interface Import, Export, following this Tutorial: https://bigladdersoftware.com/epx/doc...
  • Converted the .idf with EnergyPlusToFMU.py to an .fmu (worked, or at least completed without errors)

The fmu generation worked lately, but i am not sure if it's correct, that in the ModelDescribtion.xml the Output is "unknown".

Currently I am facing the error, when trying to simulate:

from fmpy import *

filename = "..path/to/fmu.fmu"
result = simulate_fmu(filename)

[ERROR] fmi2Instantiate: Failed to parse the model description

and the ModelDescribtion.xml part:

<ModelVariables>
<!-- Note valueReferences are (1, 2, 3...) for causality="input" (to E+). -->
<!-- Note valueReferences are (100001, 100002, 100003...) for "output" (from E+). -->
<!-- Note the order of valueReferences should match the order of elements in file 'variables.cfg'. -->
<!-- Index for next variable is '1'. -->
<ScalarVariable  name="Q"  valueReference="1"
  variability="continuous"  causality="input"
  description="IDF line 10719">
  <Real  start="0"/>
</ScalarVariable>
<!-- Index for next variable is '2'. -->
<ScalarVariable  name="TRooMea"  valueReference="100001"
  variability="continuous"  causality="output"
  description="IDF line 10711">
  <Real/>
</ScalarVariable>
</ModelVariables>
<!-- ModelStructure details for co-simulation. -->
<ModelStructure>
<!-- Outputs variables of the FMU. -->
<Outputs>
     <Unknown  index="2"/> 
</Outputs>
</ModelStructure>

idf file snippet about external interface:

!-   ===========  ALL OBJECTS IN CLASS: EXTERNALINTERFACE ===========

ExternalInterface,
  FunctionalMockupUnitExport;  !- Name of External Interface

! --------- ExternalInterface,
! ---------     FunctionalMockupUnitImport;  !- Name of External Interface


!-   ===========  ALL OBJECTS IN CLASS: EXTERNALINTERFACE:FUNCTIONALMOCKUPUNITIMPORT ===========

ExternalInterface:FunctionalMockupUnitImport,
  MeanAir.fmu,             !- FMU File Name
  0,                       !- FMU Timeout {ms}
  0;                       !- FMU LoggingOn


!-   ===========  ALL OBJECTS IN CLASS: EXTERNALINTERFACE:FUNCTIONALMOCKUPUNITIMPORT:FROM:VARIABLE ===========

ExternalInterface:FunctionalMockupUnitImport:From:Variable,
  THERMAL ZONE 1,          !- Output:Variable Index Key Name
  Zone Mean Air Temperature ,  !- Output:Variable Name
  MeanAir.fmu,             !- FMU File Name
  Model_AC40,              !- FMU Instance Name
  TMeanAir;                !- FMU Variable Name


!-   ===========  ALL OBJECTS IN CLASS: EXTERNALINTERFACE:FUNCTIONALMOCKUPUNITIMPORT:TO:SCHEDULE ===========

ExternalInterface:FunctionalMockupUnitImport:To:Schedule,
  FMU_OthEquSen_Zone1,     !- Name
  Thermal Zone 1 Thermostat Schedule Type Limits,  !- Schedule Type Limits Names
  MeanAir.fmu,             !- FMU File Name
  Model_AC40,              !- FMU Instance Name
  QSensible,               !- FMU Variable Name
  0;                       !- Initial Value


!-   ===========  ALL OBJECTS IN CLASS: EXTERNALINTERFACE:FUNCTIONALMOCKUPUNITEXPORT:FROM:VARIABLE ===========

ExternalInterface:FunctionalMockupUnitExport:From:Variable,
  THERMAL ZONE 1,          !- Output:Variable Index Key Name
  Zone Mean Air Temperature,  !- Output:Variable Name
  TRooMea;                 !- FMU Variable Name


!-   ===========  ALL OBJECTS IN CLASS: EXTERNALINTERFACE:FUNCTIONALMOCKUPUNITEXPORT:TO:SCHEDULE ===========

ExternalInterface:FunctionalMockupUnitExport:To:Schedule,
  FMU_OthEquSen_Zone1,     !- Schedule Name
  Thermal Zone 1 Thermostat Schedule Type Limits,  !- Schedule Type Limits Names
  Q,                       !- FMU Variable Name
  0;                       !- Initial Value ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-04-18 07:11:49 -0600

Your system setup may differ from what I understand, but I'm uncertain about the necessity of including the import and export interface in the IDF.

If your aim is to adjust setpoints from Python, there are other approaches to consider. One option is exporting EnergyPlus as an FMU, which would expose the setpoints you want to adjust as inputs of the FMU, while indoor temperature and A/C energy would be exposed as outputs. Once you've exported such an FMU, Python can be used to calculate the desired setpoints and interact with the FMU using a master algorithm like PyFMI.

However, it's important to note that with this approach, recompiling the FMU is necessary every time you modify your building model.

Another option is utilizing the BCVTB (Building Controls Virtual Test Bed). Here, you could employ Python actors or the SystemCommand (calling python script) actor to compute the setpoints using Python, with EnergyPlus exposing the required inputs and outputs for interfacing.

With the BCVTB approach, modifying your building model would only necessitate adjustments to the IDF, offering a more adaptable and efficient workflow.

edit flag offensive delete link more

Comments

Thank you @Thierry for your answers! After I managed to get the FMU running, for sure I will make use of PyFMI and FMPy. My other related Post is here https://unmethours.com/question/98641...

Burns's avatar Burns  ( 2024-05-15 06:24:18 -0600 )edit

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

Stats

Asked: 2024-03-21 05:05:39 -0600

Seen: 229 times

Last updated: May 15