Closed praseethp closed 7 months ago
Can you share the FMUs and steps to reproduce the problem?
edit: Some issue with the test.py file. Uploading again FMITest.zip
The code is actually from the buildings library. Buildings.Electrical.AC.OnePhase.Sources.Examples.PVPanels
I just added a 'getvariable' on top to access one of the sensor values in the component models. I use Jupyter notebook in VS Code to do this. I have Python 3.10 and FMPy was installed using Mamba
The output
argument to simulate_fmu()
has to be a list of variable names. getvariable
is not a variable of the attached FMU.
But getvariable is there in the Modelica code and I made the FMI using FMI3 in Dymola.
Have you tried to make getvariable
an output?
output Real getvariable;
Yes. Thank you. That works. But is it standard practice?
I never used to designate variables in FMI 2.0 as output and it used to work. But its ok. At least I know now how to make it work.
I have a simple model called Net. That has a component model Gri instantiated as object gri. This is my Modelica code: ` model Net parameter Modelica.Units.SI.Power P[2]= {1e4,2e4}; parameter Integer n[2]={1,1};
// Outputs Modelica.Units.SI.Power Psurp;
Components.Gridactual gri;
equation
// Fetch from object Psurp=gri.gri.y;
end Net;`
And I made FMUs with both FMI 2.0 and FMI 3.0 in Dymola. I used FMPy in Python to simulate using the simulate_fmu function:
result = simulate_fmu( 'TestFMU2.fmu', validate=False, start_time=0, stop_time=10, solver="CVode", output_interval=5, record_events=False, output=['Psurp'], ) df = pd.DataFrame.from_dict(result)
The FMI 2.0 model is simulating correctly. It gives two output columns 'time' and 'Psurp'. But the FMI 3.0 is returning only the time array. In some cases it returns a completely random array with a one letter variable like "m" or "f" as output with random values. This behaviour is only there when I try to access variables which are inside instantiated components. Tried with different FMU combinations. This mostly happens when I try to take out sensor values from models which are two or three layers deep.
In each case, the ones made with FMI 2.0 simulates correctly but not FMI 3.0.
Is there a special way to access variables which are inside components in FMPy for fmus made with FMI 3.0 or am I doing something wrong here?