0
votes

Following this question, I'm trying to compare the results of the simulation between JModelica and OpenModelica. The Modelica file is identical to the above-mentioned post and the JModelica wrapper is the corrected version:

#%%
from pymodelica import compile_fmu
from pyfmi import load_fmu
import matplotlib.pylab as plt

#%%
model_name = 'friction1D.fricexample_1'
mofile = 'friction1D.mo'

#%%
fmu_name = compile_fmu(model_name, mofile)
sim = load_fmu(fmu_name)

#%%
opts = sim.simulate_options()
opts["ncp"] = 500
opts['CVode_options']['rtol'] = 1.0e-8
res = sim.simulate(final_time=10, options=opts)

#%%
time = res['time']
vel = res['v']
ffo = res['ffo']
sfo = res['sfo']

#%%
plt.plot(time, vel)
plt.xlabel("Time (s)")
plt.ylabel("Velocity (m/s)")
plt.show()

#%%
plt.plot(time, ffo, label="friction force")
plt.plot(time, sfo, label="shear force")
plt.xlabel("Time (s)")
plt.ylabel("Force (N)")
plt.legend()
plt.show()

resulting in:

               
                      Fig.1 - Velocity versus time solved by JModelica.                

and

               
           Fig.2 - Friction and shear force versus time solved by JModelica.                

but if I set the simulation options in OpenModelica as:

                     
                    Fig.3 - Simulation options in OpenModelica.                

which results in:

               
                   Fig.4 - Velocity versus time solved by OpenModelica.                

and

               
        Fig.5 - Friction and shear force versus time solved by OpenModelica.                

I would appreciate it if you could help me know why the results are so different and how I can achieve a similar simulation with these two different compilers.

P.S. posted a follow-up question here on the OpenModelica forum.

1

1 Answers

0
votes

First of all the code, I had mentioned in my previous post was wrong. In addition to some small issues which have been discussed here, one should use the noEvent function to be sure the conditions of an if-statement are compiled correctly (more info here). The correct version of the code is mentioned here.

For JModelica to deliver similar results as OpenModelica I was instructed by Christian Winther here to play with the opts["CVode_options"]["maxh"] parameter which has a default value of 0. I set the option to:

opts['CVode_options']['maxh'] = 0.01

and JModelica worked fine.