FMPy
FMPy copied to clipboard
CVODE error when simulating ME-FMU with fmpy 0.3.1
When I try to simualate this ME FMU with CVODE, I get this error:
In [8]: fmpy.simulate_fmu(path, start_time = 0.0, stop_time = 5000.0, fmi_type = "ModelExchange", start_values = {"Td0": 343.15, "Tu0": 293.15}, relative_tolerance = 1e-5)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
_ctypes/callbacks.c in 'calling callback function'()
~\anaconda3\lib\site-packages\fmpy\sundials\__init__.py in f(self, t, y, ydot, user_data)
125 """ Right-hand-side function """
126
--> 127 self.set_time(t)
128
129 if self.discrete:
~\anaconda3\lib\site-packages\fmpy\fmi2.py in setTime(self, time)
490
491 def setTime(self, time):
--> 492 return self.fmi2SetTime(self.component, time)
493
494 def setContinuousStates(self, x, nx):
~\anaconda3\lib\site-packages\fmpy\fmi2.py in w(*args)
213 # check the status code
214 if res > fmi2Warning:
--> 215 raise Exception("%s failed with status %d." % (fname, res))
216
217 return res
Exception: fmi2SetTime failed with status 3.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-8-784ed9f40178> in <module>
----> 1 fmpy.simulate_fmu(path, start_time = 0.0, stop_time = 5000.0, fmi_type = "ModelExchange", start_values = {"Td0": 343.15, "Tu0": 293.15}, relative_tolerance = 1e-5)
~\anaconda3\lib\site-packages\fmpy\simulation.py in simulate_fmu(filename, validate, start_time, stop_time, solver, step_size, relative_tolerance, output_interval, record_events, fmi_type, start_values, apply_default_start_values, input, output, timeout, debug_logging, visible, logger, fmi_call_logger, step_finished, model_description, fmu_instance, set_input_derivatives, remote_platform)
785 # simulate_fmu the FMU
786 if fmi_type == 'ModelExchange':
--> 787 result = simulateME(model_description, fmu, start_time, stop_time, solver, step_size, relative_tolerance, start_values, apply_default_start_values, input, output, output_interval, record_events, timeout, step_finished)
788 elif fmi_type == 'CoSimulation':
789 result = simulateCS(model_description, fmu, start_time, stop_time, relative_tolerance, start_values, apply_default_start_values, input, output, output_interval, timeout, step_finished, set_input_derivatives)
~\anaconda3\lib\site-packages\fmpy\simulation.py in simulateME(model_description, fmu, start_time, stop_time, solver_name, step_size, relative_tolerance, start_values, apply_default_start_values, input_signals, output, output_interval, record_events, timeout, step_finished)
1057 if t_next - time > eps:
1058 # do one step
-> 1059 state_event, roots_found, time = solver.step(time, t_next)
1060 else:
1061 # skip
~\anaconda3\lib\site-packages\fmpy\sundials\__init__.py in step(self, t, tNext)
169 _assert_cv_success(CVodeGetRootInfo(self.cvode_mem, p_roots_found))
170 elif flag < 0:
--> 171 raise RuntimeError("CVode error (code %s) in module %s, function %s: %s" % self.error_info)
172
173 return flag > 0, roots_found, tret.value
RuntimeError: CVode error (code -8) in module CVODE, function CVode: At t = 4981.9, the right-hand side routine failed in an unrecoverable manner.
I am not sure if this is a problem with the FMU, or I am missing something.
The problem seems to be that the FMU raises an error if the solver sets a time that is slightly greater than the stop time in fmi2SetTime()
which can happen with variable step solvers.