A tutorial repo for modeling, simulation and optimization in Modelica/FMU environments
This section talks about how to use Modelia/FMU models to perform different advanced applications, including design optimization (e.g., system sizing, model calibration etc), simulation restart from a given states, pertubation experiment (e.g., system excitation for system identification) and optimal control (e.g., model predictive control of a target system) etc..
states
tunable parameters
Modelica compilers
FMU
perfect model
imperfect model
perfect model
imperfect model
The testing examples are mostly written in Python, and the physical models are written in Modelica. Two integrated software environment are provided here for tutorial purposes. One is a containerized docker environment that contains jModelica for Modelica modeling and simulation, and a Python 3.8 scripting envrionment. The other is a Python 3.8 conda environment, which contains only Python and no Modelica tools. This environment is only designed for examples depending on Dymola or Dymola FMU. Dymola is similar to jModelica but a commercial tool.
The docker contains an integrated Modelica modeling and simulation environment in Python based on jModelica.
-
Install prequirements
Docker: https://docs.docker.com/get-docker/.
Make:
for windows, use cygwin from https://www.cygwin.com/
-
Activate docker. Just open the installed Docker desktop.
-
Make an image for tutorial purposes by opening a terminal, directing to the top folder
modelica-tutorial
, and typing:make build
-
Check the image after build by typing:
docker image ls
If successfully build, this should return a list of images on the local computer with an image repository named
modelica_tutorial
. -
Test the Docker environment by directing to any sub-folders and type:
on windows:
XXXX.bat
on Mac/Ubuntu:
bash XXXX.sh
The library dependency has been configured and listed in the modelica_tutoral.yml
file.
-
Make sure
conda
is installed in the local computer by opening your favorite terminals and typing:conda info
If sucessfully installed, similar messages as follows should be returned:
active environment : base active env location : C:\tools\Anaconda2 shell level : 1 user config file : C:\Users\yangyang.fu\.condarc populated config files : conda version : 4.8.3 conda-build version : 3.18.9 python version : 2.7.16.final.0 virtual packages : __cuda=11.3 base environment : C:\tools\Anaconda2 (writable) channel URLs : https://repo.anaconda.com/pkgs/main/win-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/win-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/msys2/win-64 https://repo.anaconda.com/pkgs/msys2/noarch package cache : C:\tools\Anaconda2\pkgs C:\Users\yangyang.fu\.conda\pkgs C:\Users\yangyang.fu\AppData\Local\conda\conda\pkgs envs directories : C:\tools\Anaconda2\envs C:\Users\yangyang.fu\.conda\envs C:\Users\yangyang.fu\AppData\Local\conda\conda\envs platform : win-64 user-agent : conda/4.8.3 requests/2.22.0 CPython/2.7.16 Windows/10 Windows/10.0.19041 administrator : False netrc file : None offline mode : False
If conda is not sucessfully installed, please check https://conda.io/projects/conda/en/latest/user-guide/install/index.html.
-
Configure the provided environment in
modelica_tutorial.yml
by directing to the top foldermodelica-tutorial
and typing:conda env create -f modelica_tutorial.yml
-
Check the installation by typing:
conda env list
If installed correctly, users should be able to see a conda environment named
modelica_tutorial
being returned. -
Activate
modelica_tutoral
virtual environment if the environment has been successfully installed. Type in the terminal:conda activate modelica_tutoral
-
Test example codes. Now the users can direct to any sub-folders to test the example scripts written in Python by typing
python xxxx.py
If the scripts call FMUs, then the FMUs has to be regenerated on the local computer using Dymola.
Yangyang Fu