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
  • Index
  • » Users
  • » lisboalex02
  • » Profile

Posts

Posts

Hello, everyone!

I happen to have the same question!

How can we check the time constant of a given simulation model?

thanks!

FMU is widely used in a python environment thru FMI Library package pyFMI and compilation of modelica models can be done thru pyModelica.

I wonder if there is a way to compile a modelica model in FMU and simulate this FMU doing all this process (compilation -> simulation) in C++?

What would be the packages used for this purpose, if any ?

thanks in advance!

Feb-06-21 12:22:24
Model exported as FMU and imported to a FMI environment

Hello,

I wonder if there is a way to simulate a model indefinitely, ie., to call the "setup_experiment()" FMI method setting an infinite or undefined stop_time parameter?

I am working on a server/client architecture for a model and having a stop_time limit does not work for me!

Thanks in advance!

Jan-24-21 11:12:25
I could not find anything related to this exception. Can someone help me ?

I could not find anything related to this exception. Can someone help me ?

Code:

from pyfmi import load_fmu
import matplotlib.pyplot as plt
import numpy as N

# Simulation parameters:

dt = 0.0001 
tf = 15 
ts = 0 

model="AIMC_Inverter.fmu"
generate_plot = False

# Load model
mod = load_fmu(model, log_level=4) # default setting is 2
mod.set_max_log_size(2073741824) # = 2*1024^3 (about 2GB)

# Get Continuous States and nominal values
x = mod.continuous_states
x_nominal = mod.nominal_continuous_states

mod.setup_experiment(start_time = ts) # Set the start time to ts
mod.initialize()

eInfo = mod.get_event_info()
eInfo.newDiscreteStatesNeeded = True

#Event iteration
while eInfo.newDiscreteStatesNeeded == True:
  mod.enter_event_mode()
  mod.event_update()
  eInfo = mod.get_event_info()

mod.enter_continuous_time_mode()

Error:

  File "src/pyfmi/fmi.pyx", line 7512, in pyfmi.fmi.FMUModelME2.enter_event_mode
pyfmi.fmi.FMUException: Failed to enter event mode.

Jan-12-21 09:51:20
The default linear solver fails, the fallback solver with total pivoting is started at time...

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?

Jan-12-21 07:52:48
Exporting the AIMC_Inverter example model as FMU to python through FMI and trying to simulate...

Problem solved!

It was a offset condition issue!

Jan-06-21 10:22:26
Exporting the AIMC_Inverter example model as FMU to python through FMI and trying to simulate...

Exporting the AIMC_Inverter example model as FMU to python through FMI and trying to simulate throws a division by zero error.  On the other hand, simulating from OMedit GUI works fine!

code:

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

fmodel = pyfmi.load_fmu('.../path/to/Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_Inverter.fmu')


# co-simulation parameters

dt = 50e-6 # simulation step
tf = 10.0 # end time
ts = 0.1 # begin time
x = []
y = []
t = []

while ts <= tf:

# Calculate integration step
    try:
        status = fmodel.do_step(ts, dt)
    except Exception as e:
        print('error: ' + e.args)

# check integration step completed

    if status is not pyfmi.fmi.FMI_OK:
        break

# store target variables values
    x.append( fmodel.get( 'currentQuasiRMSSensor.I' ) )
    y.append( fmodel.get( 'aimc.wMechanical' ) )
    t.append( ts )

# Increments simulation step
    ts += dt

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

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

Error:

assert            | debug   | division by zero at time 0, (a=0) / (b=0), where divisor b expression is: vfController.fNominal
getBestJumpBuffer got mmc_jumper=(nil), globalJumpBuffer=(nil)
Aborted (core dumped)

Dec-20-20 13:40:13
I am trying to simulate an OpenModelica example model using ModelicaSystem python module. But I...

Thank you so much!

Now it works just fine!

Dec-19-20 20:11:51
I am trying to simulate an OpenModelica example model using ModelicaSystem python module. But I...

code:

import numpy as np
from matplotlib import pyplot as plt
import pyfmi
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem

omc = OMCSessionZMQ()

model_path = '/usr/lib/omlibrary/Modelica 3.2.3/Electrical/'

omc.sendExpression('loadModel(model_path + Machines.mo)')

mod = ModelicaSystem(model_path + 'Machines.mo','Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_Inverter')


error:

loadFile Error: Error: Failed to insert class Machines within Modelica.Electrical;

the available classes were:

  • Index
  • » Users
  • » lisboalex02
  • » Profile
You are here: