Skip to content

Repository files navigation

optimo

Optimization of Modelica models.

optimo uses OpenModelica for compilation of Modelica models into FMUs. It then relies on CasADi and Rockit to simulate and optimize from those models in Python.

Example

We first define our Modelica model in a .mo script.

model vdp"Van der Pol oscillator model."Real x1(start=0) "The first state"; Real x2(start=1) "The second state"; inputReal u(start=0) "The control signal"; outputReal objectiveIntegrand(start=0) "The objective signal"; equationder(x1) = (1- x2^2) * x1 - x2 + u; der(x2) = x1; objectiveIntegrand = x1^2+ x2^2+ u^2;
end vdp;

Now we use this model for simulation and optimization in a Python script:

importmatplotlib.pyplotaspltfromwedoco_optimo.modelimportOptimoModel# Compile and transfer the Modelica modelmo=OptimoModel()
mo.transfer_model(model="vdp")
# Simulateres_sim_df=mo.simulate()
# Optimize mo.define_optimization(constraints={"u":(-1, 0.75)}, objective_terms=["objectiveIntegrand"])
res_ocp_df=mo.optimize()

If no input trajectories are provided, the simulation runs with the initial input values as defined in the model. When plotting these results (see full example) we obtain the following graphs:

Simulation results

Simulation Results

Optimization results

Optimization Results

About

Optimization of Modelica models

Resources

Stars

21 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages