Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulation fails for start_time greater than 0 #261

Open
GiuseppeR96 opened this issue Aug 23, 2024 · 5 comments
Open

Simulation fails for start_time greater than 0 #261

GiuseppeR96 opened this issue Aug 23, 2024 · 5 comments
Assignees
Labels
question Issue only concerns a or multiple questions.

Comments

@GiuseppeR96
Copy link

Hi,
I'm encountering an issue when simulating with pyFMI an FMU that was extracted from a Modelica file using OpenModelica. The simulation runs successfully when the start time is set to 0. However, if I set the start time to a value greater than zero (e.g., 3600), the simulation fails, and I receive the following error message:
assimulo.solvers.sundials.CVodeError: 'The linear solvers setup function failed in an unrecoverable manner. At time 3449.640593.'
Note that the function failed at a timestep that is smaller the start time it self (3449). The larger i set the relative tolerance, the closer simulation failed time approaches the start time.

@PeterMeisrimelModelon PeterMeisrimelModelon self-assigned this Aug 23, 2024
@PeterMeisrimelModelon PeterMeisrimelModelon added the question Issue only concerns a or multiple questions. label Aug 23, 2024
@PeterMeisrimelModelon
Copy link
Collaborator

Hi,

can you share your call sequence + model default state & stop times?

By default initialization will be performed to the defaultExperiment->startTime from the modelDescription.xml. If you want to start simulation from a different time-point, you may want to explicitly call fmu.setup_experiment(start_time = 3600) after loading and before simulating your fmu.

/Peter

@GiuseppeR96
Copy link
Author

model = load_fmu("model.fmu", log_level=2)
model.reset()
#simulation options
opts = model.simulate_options()
opts['ncp'] = 4 
opts['initialize'] = True
opts['CVode_options']['rtol'] = 1e-7
opts['CVode_options']['store_event_points'] = False

###Initialize simulation
index=float(3600)
timestep = 3600/4
simulation_length = index + 86400.0*1

while index < simulation_length:

     optimal_control_input = (control)
     input_modelica = ["n"]
     input_object = (input_modelica,  optimal_control_input)

     res = model.simulate(start_time=index, final_time=index + timestep, options=opts,
                                    input=input_object)
                                    
       opts['initialize'] = False
       index = index + timestep

I tried adding model.setup_experiment(start_time = 3600) when I initialize the simulation but I get the same error

@PeterMeisrimelModelon
Copy link
Collaborator

Is there any particular reason for the while loop? Unless there is something missing here in terms of the input being updated, I do not see the need for the loop.

You can try to "manually" initialize the model via the follow sequence:

self.model.setup_experiment(start_time=... stop_time=...)
self.model.initialize(start_time=...)
self.model.event_update()
self.model.enter_continuous_time_mode()

followed by simulation.

Can you try to increase the log level to 7 and paste the log output?

/Peter

@GiuseppeR96
Copy link
Author

The loop is due to the fact that we need to simulate one step at a time to interact with the model to send control actions.

FMIL: module = FMILIB, log level = 5: Allocating FMIL context
FMIL: module = FMILIB, log level = 5: Parsing model description XML
FMIL: module = FMI2XML, log level = 5: Parsing XML element fmiModelDescription
FMIL: module = FMI2XML, log level = 5: Parsing XML element ModelExchange
FMIL: module = FMI2XML, log level = 5: Parsing XML element CoSimulation
FMIL: module = FMI2XML, log level = 5: Parsing XML element UnitDefinitions
FMIL: module = FMI2XML, log level = 5: Parsing XML element TypeDefinitions
FMIL: module = FMI2XML, log level = 5: Parsing XML element LogCategories
FMIL: module = FMI2XML, log level = 5: Parsing XML element ModelVariables
FMIL: module = FMI2XML, log level = 5: Building alias index
FMIL: module = FMI2XML, log level = 5: Variables flo.cor.air.vol.dynBal.U and flo.cor.air.vol.U reference the same vr 0. Marking 'flo.cor.air.vol.U' as alias.
FMIL: module = FMI2XML, log level = 5: Variables flo.cor.air.vol.dynBal.m and flo.cor.air.vol.m reference the same vr 1. Marking 'flo.cor.air.vol.m' as alias.
FMIL: module = FMI2XML, log level = 5: Variables flo.cor.air.vol.dynBal.medium.Xi[1] and flo.cor.air.ports[1].Xi_outflow[1] reference the same vr 2. Marking 'flo.cor.air.ports[1].Xi_outflow[1]' as alias.

[...]

FMIL: module = FMILIB, log level = 4: Loading 'win64' binary with 'default' platform types
FMIL: module = FMICAPI, log level = 5: Loaded FMU binary from C:\Users\Jarvis\AppData\Local\Temp\JModelica.org\jm_tmpfo4d1tly\binaries\win64\Buildings_for_MPC_2.dll
FMIL: module = FMICAPI, log level = 5: Loading functions for the model exchange interface
FMIL: module = FMILIB, log level = 5: Successfully loaded all the interface functions
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2Instantiate: GUID={bfe7b097-6cc4-4628-8d85-5754a81cfb85}
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2Reset
FMIL: module = FMICAPI, log level = 5: Calling fmi2SetupExperiment
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetupExperiment: toleranceDefined=1 tolerance=1e-06 startTime=3600 stopTimeDefined=0 stopTime=172800
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 1
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: sou = 1000
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 1
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: eas = 1000
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 1
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nor = 1000
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 1
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: wes = 1000
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 1
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: cor = 1000

[...]

FMIL: module = Model, log level = 2: [logFmi2Call][FMU status:Error] fmi2GetReal: terminated by an assertion.
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 18
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.cor.air.vol.dynBal.U = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.cor.conPar[2].opa.lay[1].T[3] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-10
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-10
FMIL: module = Model, log level = 2: [logFmi2Call][FMU status:Error] fmi2GetReal: terminated by an assertion.
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 18
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.cor.air.vol.dynBal.U = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.cor.conPar[2].opa.lay[1].T[3] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conExtWin[1].opa.lay[1].T[1] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conExtWin[1].opa.lay[2].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conPar[2].opa.lay[1].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conPar[2].opa.lay[1].T[5] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conExtWin[1].opa.lay[1].T[1] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conExtWin[1].opa.lay[2].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conPar[2].opa.lay[1].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conPar[2].opa.lay[1].T[5] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conExtWin[1].opa.lay[1].T[1] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conExtWin[1].opa.lay[2].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conPar[2].opa.lay[1].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conPar[2].opa.lay[1].T[5] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conExtWin[1].opa.lay[1].T[1] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conExtWin[1].opa.lay[2].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conPar[2].opa.lay[1].T[2] = 1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conPar[2].opa.lay[1].T[5] = 1.490116119384766e-11
FMIL: module = Model, log level = 2: [logFmi2Call][FMU status:Error] fmi2GetReal: terminated by an assertion.
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: nvr = 18
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.cor.air.vol.dynBal.U = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.cor.conPar[2].opa.lay[1].T[3] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.eas.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.nor.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.sou.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conExtWin[1].opa.lay[1].T[1] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conExtWin[1].opa.lay[2].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conPar[2].opa.lay[1].T[2] = -1.490116119384766e-11
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2SetReal: flo.wes.conPar[2].opa.lay[1].T[5] = -1.490116119384766e-11
FMIL: module = Model, log level = 2: [logFmi2Call][FMU status:Error] fmi2GetReal: terminated by an assertion.
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2Terminate
FMIL: module = Model, log level = 4: [logFmi2Call][FMU status:OK] fmi2FreeInstance
FMIL: module = FMILIB, log level = 5: Releasing FMU CAPI interface
FMIL: module = FMICAPI, log level = 5: Successfully unloaded FMU binary
FMIL: module = FMILIB, log level = 5: Releasing allocated library resources
FMIL: module = JMPRT, log level = 5: Removing C:\Users\Jarvis\AppData\Local\Temp\JModelica.org\jm_tmpfo4d1tly

I only reported some parts of the log file that I got setting log level = 7 because it is too long. The log file only outputs level 2, 4, 5.

@PeterMeisrimelModelon
Copy link
Collaborator

Does OpenModelica do any logging on fmi2setTime?

Setting up the experiment & initializing with the appropriate start time it seems strange that the model would do evaluations at any time smaller than that.

It could be worth asking the same question on the OpenModelica GitHub, since this issue could also be due to the FMU not correctly picking up on values from setting up the experiment or initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issue only concerns a or multiple questions.
Projects
None yet
Development

No branches or pull requests

2 participants