Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Model Solver fails

Model Solver fails

Running the simulation from OMedit works just fine. But, when I export the model as FMU to a python script thru the pyfmi module, I get the following error:

The default linear solver fails, the fallback solver with total pivoting is started at time 0.000000. That might raise performance issues, for more information use -lv LOG_LS

Here is the code:

import numpy as np
from matplotlib import pyplot as plt
import pyfmi

fmodel = pyfmi.load_fmu('/tmp/OpenModelica_alexandre/OMEdit/AIMC_Inverter/AIMC_Inverter.fmu')

# Define input ramp signal:

def freq(time):
    if time <= 60:
        f = time
    else:
        f = 60
    return f

# CS parameters

dt = 0.5 #simulation step
tf = 10.0 # final instant
ts = 0.1 # initial instant
x = []
y = []
t = []

while ts <= tf:

# Calculates an integration step

    try:
        status = fmodel.do_step(ts, dt)
    except Exception as e:
        print('erro: ' + e.args)

# checks integrations step completed

    if status is not pyfmi.fmi.FMI_OK:
        break

# set next step input value:

    fmodel.set( 'f', freq(ts) )

    x.append( fmodel.get( 'currentQuasiRMSSensor.I' ) )
    y.append( fmodel.get( 'aimc.wMechanical' ) )
    t.append( ts )

    ts += dt

plt.grid()
plt.xlabel('time[s]')
plt.ylabel('y')

plt.plot(t,y,'r+')
plt.show()


Note: I have tried exporting the model using different solvers, such as: Dassl, Euler, Ida, CVode. But I keep getting the same error message. The error mentions a "default linear solver" which I imagine it to be the Dassl one, so It seems as though I change the solver in the OMEdit simulation setup, the model is still being exported as FMU using the Dassl solver.

Could anyone help me?

Re: Model Solver fails

Hej lisboalex02,

There are multiple ways of exporting Modelica models as FMU from OMEdit. I will restrict myself to the C FMUs here, but you can do most of this (but not all) for C++ FMUs as well.

If you just go File->Export->FMU you will get a 2.0 FMU with ModelExchange (ME) and Co-Simulation(CS) an an explicit Euler as integrator.
If you want to change some FMU export settings you can use the Options from Tools->Options->FMI to export e.g. only a CS FMU and for a specific platform.

When you use the scripting commands `buildModelFMU` or`translateModelFMU`, seeOpenModelica Scripting API, with the OpenModelica Compiler CLI from OMEdit you have more options.

But if you want to change the internal integrator for a CS FMU you have to use the Compiler Flag `--fmiFlags=s:cvode`. Please note that this feature is very new and currently the only setting you can change is the internal integrator used for `fmi2DoStep`.
You can pass it with the CLI

Code:


>setCommandLineOptions("-d=newInst --fmiFlags=s:cvode")
true
>buildModelFMU(Modelica.Electrical.Analog.Examples.CauerLowPassSC,"2.0","cs")
"C:/OMDev/tools/msys/tmp/OpenModelica/OMEdit/Modelica.Electrical.Analog.Examples.CauerLowPassSC.fmu"

You will get outputs from the FMU if you simulate if with CVODE to hint that it worked. Of course only if PyFMI will display outputs from the FMU that are displayed in stdout. They should look like this:

Code:


# OMSimulator Modelica.Electrical.Analog.Examples.CauerLowPassSC.fmu
[...]
LOG_SOLVER        | info    | CVODE linear multistep method CV_BDF
LOG_SOLVER        | info    | CVODE maximum integration order CV_ITER_NEWTON
LOG_SOLVER        | info    | CVODE use equidistant time grid YES
LOG_SOLVER        | info    | CVODE Using relative error tolerance 1.000000e-06
LOG_SOLVER        | info    | CVODE Using dense internal linear solver SUNLinSol_Dense.
LOG_SOLVER        | info    | CVODE Use internal dense numeric jacobian method.
LOG_SOLVER        | info    | CVODE uses internal root finding method NO
LOG_SOLVER        | info    | CVODE maximum absolut step size 0
LOG_SOLVER        | info    | CVODE initial step size is set automatically
LOG_SOLVER        | info    | CVODE maximum integration order 5
LOG_SOLVER        | info    | CVODE maximum number of nonlinear convergence failures permitted during one step 10
LOG_SOLVER        | info    | CVODE BDF stability limit detection algorithm OFF
[...]

By the way, the Integrator method only applies to a CS FMU. ME FMUs don't have one, since the master algorithm has the integrator, in your case PyFMI.

DASSL is also an integrator method, but only available for Modelica model simulations. The linear and non-linear solvers on the other hand are used to solve internal algebraic equation systems. Currently you can't change them.

But since I don't have your FMU I can only guess why it is not working for you, but I guess a step size of `dt = 0.5 #simulation step` is a bit to big. Try reducing it. Since you only used the default CS FMU you have an explicit Euler step that is very large for a problem that could be hard to solve.

There are 0 guests and 0 other users also viewing this topic