This repository contains scripts and configuration facilitating compilation of FMU file (with source codes in C of compiled Modelica model and solver) to Javascript with embedded WebAssembly. Such compiled javascript allows to access model simulation via FMI API v 2.0 as specified in FMI standard.
- FMU co-simulation mode with source codes and CVODE solver generated by Dymola is fully supported.
- FMU co-simulation mode with source codes and CVODE solver generated by OpenModelica is supported.
To use Bodylight.js-FMU-Compiler, choose one of these options:
- compiler in docker - needs docker to be installed in environment.
For legacy - older options are available: 2. compiler in virtual machine - Vagrant tool and VirtualBox is needed - see Bodylight-Virtualmachine 3. compiler in local environment - needs to install EMSDK,GLIBC and PYTHON3 manually
You may follow our tutorial at https://bodylight.physiome.cz/Bodylight-docs/tutorial/
Requirements:
- Docker (in linux install
docker.ioin windowsDocker Desktopto be able to execute CLIdocker run) - test if by launching
docker run --rm hello-world
git clone https://github.com/creative-connections/Bodylight.js-FMU-Compiler
cd Bodylight.js-FMU-CompilerFor Modelica models in OpenModelica, in OMEdit, export model as FMU 2.0 in co-simulation with CVODE solver, with source code and with --fmiFlags=s:cvode set in Tools->Options->Simulation->Additional Translation flags
For Modelica models in Dymola, export model as FMU 2.0 in co-simulation with source code and CVODE solver:
With the resulting my_model.fmu launch script in Linux
./compile_docker.sh my_model.fmuor in Windows powershell
./compile_docker.ps1 my_model.fmuOPTIONALLY:
- Use option
-oto enable compilation optimization, producing smaller and faster code (using-O3 --clossure 1), by default it is disabled. - Use option
-wto write resulting WASM embedded in JS into FMU/binaries/wasm32, by default it is disabled. - Use option
-sto generate sample web simulator into index.html, it is in resulting ZIP file
The script compiles FMU to WebAssembly and embeds them into Javascript creates ZIP file with JS and XML with model description. Use it with dbs-webcomponents or bodylight.js web components.
If -s is used, sample index.html is created and further web app development can be made using web components. The JS is compatible with dbs-webcomponents as well as bodylight.js web components.
For legacy options, see legacy\README.md.
The following models were converted to web-based simulators using FMU compiler.
- Hemodynamics - model of hemodynamics of cardiovascular system with simulated volume,presure during cardiac cycle
- Simple Circulation - model published as part of Physiolibrary
- Kulhánek T, Tribula M, Kofránek J, Mateják M: Simple models of the cardiovascular system for educational and research purposes. MEFANET Journal 2014; 2(2); ISSN:1805-9171. Available at WWW: http://mj.mefanet.cz/mj-04140914.
- Nefron Simulation - model and Bodylight.js technology published as
- ŠILAR, Jan, David POLÁK, Arnošt MLÁDEK, Filip JEŽEK, Theodore W KURTZ, Stephen E DICARLO, Jan ŽIVNÝ a Jiri KOFRANEK. Development of In-Browser Simulators for Medical Education: Introduction of a Novel Software Toolchain. Journal of Medical Internet Research [online]. 2019, 21(7) [cit. 2019-11-25]. DOI: 10.2196/14160. ISSN 1438-8871. Dostupné z: https://www.jmir.org/2019/7/e14160
- Bodlight Scenarios - simulators using web components. Section of hemodynamics, blood-gases, iron metabolism and virtual body preparing for publication
- Buddy - experimental simulator of most complex model of physiology Physiomodel
The simple and medium size models compile into Javascript with size 0.5 MB - 2 MB. The embedded WebAssembly is supported by 4 major web browsers (Firefox,Chrome,Ms Edge,Safari). The simulation is nearly native speed (1.5x or 2x slower). One drawback can be memory limit on some mobile devices, which may prevent to run some of the most complex model (see Buddy above) there.