79277751

Date: 2024-12-13 09:22:45
Score: 1.5
Natty:
Report link

I would like to reframe your question a little bit as follows:

  1. Make simulation 1 and get the final value x and call it x1
  2. Reload the model
  3. Enter the initial value of x as x1
  4. Optionally change the parameter k
  5. Make simulation 2 and get the final value x and call it x2
  6. Plot the two simulations after each other

The model I change to this

model Test
  parameter Real x_start = 1000;
  parameter Real k = 10;
  Real x(start=x_start, fixed=true);  
equation
  der(x) = -k*x;
end Test;

And the script to this

# Setup framework
from pymodelica import compile_fmu 
from pyfmi import load_fmu

# Compile model
fmu_model = compile_fmu('Test','Test.mo', target='cs')

# Load model
model = load_fmu(fmu_model)

# Simulate
result1 = model.simulate(start_time=0, final_time=1)
x1 = model.get('x')

model.reset() 
model.set('k', 1)
model.set('x_start',x1)
result2 = model.simulate(start_time=1, final_time=2)
x2 = model.get('x')

Hope this address your main question?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: janpeter