2

I developed for the example a simple Modelica model based on the fluid library of the MSL. I connected a MassFlowSource with a pipe and a Boundary_PT as sink function as in the picture below:

http://www.casimages.com/img.php?i=14061806120359130.png

I generate a FMU package with OpenModelica (in mode model-exchange). I manage this FMU package with python with the code below:

import pyfmi, os
from pyfmi import load_fmu

myModel = load_fmu('PathToFolder\\test3.fmu')
res1 = myModel.simulate() # First simulation with m_flow in source set to [1] Kg/s
x = myModel.get('boundary1.m_flow') # Mass flow rate of the source
y = myModel.get('pipe.port_a.m_flow') # Mass flow rate in pipe
print x, y

myModel.set('boundary1.m_flow', 2)
option = myModel.simulate_options()
option['initialize'] = False # Need to initialize the simulation
res2 = myModel.simulate(options = option) # Second simulation with m_flow in source set to [2] Kg/s
x = myModel.get('boundary1.m_flow') # Mass flow rate of the source
y = myModel.get('pipe.port_a.m_flow') # Mass flow rate in pipe
print x, y

os.system('pause')

The objective is to show a problem when you change a parameter in the model, here the "m_flow" variable in source component. This new set to "2" should change the "m_flow" in pipe but it does not. Results: In the first simulation the both "m_flow" are gotten to "1" and it's normal because the model is set like this. In the second simulation, I set the parameter to "2" in the source but the pipe "m_flow" stay to "1" (It should be "2"). http://www.casimages.com/img.php?i=140618060905759619.png

The model of the fluid source in Modelica is this one (only our interesting part):

equation
 if not use_m_flow_in then
  m_flow_in_internal = m_flow;
 end if;
 connect(m_flow_in, m_flow_in_internal);

I think the FMU don't consider parameter when they are in a if-condition. For me it's a problem because I need to manage FMU and to be sure that if I set a parameter, the simulation will use this new set. How be sure that FMU/FMI works well? Where is the exhaustive list with the type of parameters we can't manage in FMU?

I already know that parameters which change the number of equations can't be consider in FMU management (idem for variables which change the index of DAEs).

Roland
  • 135
  • 1
  • 6
  • You can not generate a Co-Simulation FMU from OpenModelica. How did you do that? – Adeel Asghar Jun 18 '14 at 16:23
  • Oops, I can't. It's a mistake, I generate a Model-exchange FMU with OpenModelica. Thank you for you comment Adeel. – Roland Jun 19 '14 at 08:30
  • So now, I would like to know how the module pyfmi could work with the FMU packages generated by OpenModelica. Does it mean that "pyfmi" launch the OpenModelica simulator? Which one is it? GCC? – Roland Jun 19 '14 at 08:37
  • I don't know how pyfmi works. No its a model-exchange so no OpenModelica simulator. Have you tried importing the same FMU in OpenModelica? – Adeel Asghar Jun 19 '14 at 11:51
  • Yes I tried but when I simulate the model, the process crash and I have to close the simulation. I think import FMU is not supporting yet by OpenModelica. – Roland Jun 20 '14 at 13:44
  • import FMU is supported by OpenModelica. Submit a trac ticket if simulation is crashing https://trac.openmodelica.org/OpenModelica/newticket – Adeel Asghar Jun 20 '14 at 22:59

3 Answers3

3

Note that OpenModelica has a concept of structural parameters and the Evaluate=true annotation. For example, if a parameter is used as an array dimension, it might be evaluated to an Integer value. All uses of that parameter will use the evaluated value, as if it was a constant.

Rather than including a picture of the diagram, the Modelica source code would have been easier to look at in order to find out what OpenModelica did to the system.

I suspect a parameter was evaluated. If you generate non-FMU code, you could inspect the modelName_init.xml generated by OpenModelica and find the entry for a parameter and look for the property isValueChangeable.

You could also use OMEdit to debug the system and view the initial equation (generate the executable including debug information). File->Open Transformations File, then select the modelName_info.xml file. Search for the variable you tried to change and go to the initial equation that defined it. It could very well be that a start-value (set by PyFMI) is ignored because it is not needed to produce a solution.

sjoelund.se
  • 3,468
  • 12
  • 15
  • "isValueChangeable" of the parameter is set to "false". Most of the parameters are set to "false". I don't really understand what does it mean. – Roland Jun 20 '14 at 14:27
  • It means any attempt to set the value in PyFMI will be ignored by the FMU – sjoelund.se Jun 20 '14 at 20:21
  • I resume: I set the parameter with "annotation(Evaluate = false)". Now the attribute "isValueChangeable" is set to "true" and I can manage this parameter in FMU. It works well. If we need to set the annotation in a component already developed we have this solution: http://stackoverflow.com/questions/21957303/change-annotationevaluate-true-false-for-parameters-in-models-from-modelica-s – Roland Jun 23 '14 at 10:02
3

whenever you try to set new values to the parameter, Follow these steps:
1.Reset the model
2.set new values for the parameter
3.Simulate the model.

Abhishek S
  • 75
  • 10
1

I am not familiar with PyFMI, but I kinda encountered the same situation before. You could try a few things below.

  1. Try to terminate/free the instant after your first sim.

  2. As most parameters could not be changed after init, you could make that parameter as an input connector, so that this specific parameter could be changed at any time.

  3. (In FMU from Dymola) I also found that if that parameter involves in your initial nonlinear system of equation, then you will get an error "the model could not be initialized" if you try to init the model on the same instant.

Hang Yu
  • 476
  • 2
  • 14
  • About your 3rd point: I'm not sure to well understand. I add in my python code "option['initialize'] = False" for my second simulation because i have an error "the model could not be initialized" if I don't do it. I do it but I don't really understand why. Is it the same issue? Could you give me more details about your 3rd point? – Roland Jun 20 '14 at 14:32