| Crates.io | rumoca |
| lib.rs | rumoca |
| version | 0.4.5 |
| created_at | 2024-11-11 08:26:14.256591+00 |
| updated_at | 2025-01-09 20:40:18.020639+00 |
| description | A Modelica translator with focus on Casadi, Sympy, JAX, and Collimator generation |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1443600 |
| size | 125,349 |
A Modelica translator with focus on CasADi, Sympy, JAX, and PyCollimator generation.
There are many useful libraries for hybrid systems analysis, but it is difficult to port models between different environments.
There are many excellent tools for analysis of cyber-physical systems, and rumoca aims to allow you to use the best tool for the job at hand.
Compiler and translator are often used interchangeably, but the goal of a compiler is typically to generate low level machine code. The term translator is more general and refers to transformation of source code to some other form. Since we are interested in generaeting models in various languages from a Modelica model, we call Rumoca a translator.
There are several other Modelica compilers/translators in development, and I believe there are challenges that make it compelling to develop a new translator for generation required for this project. These are all my personal opinions and should be taken with a grain of salt.
cargo install rumoca
[!IMPORTANT] Make sure you add your cargo binary directory to your path.
Type the following to test that rumoca is in your path.
$ rumoca --help
Rumoca Modelica Translator
Usage: rumoca [OPTIONS] --template-file <TEMPLATE_FILE> --model-file <MODEL_FILE>
Options:
-t, --template-file <TEMPLATE_FILE> The template
-m, --model-file <MODEL_FILE> The model file to compile
-v, --verbose Verbose output
-h, --help Print help
-V, --version Print version
This package uses the standard cargo conventions for rust.
cargo build
cargo run
cargo test
cargo run -- -t test/templates/casadi_sx.jinja -m test/models/integrator.mo
This package uses the standard cargo installation conventions.
cargo install --path .
Rumoca is currently under development, but some initial results are shown below:
model Integrator
Real x; // test
Real y;
equation
der(x) = 1.0;
der(y) = x;
end Integrator;
$ rumoca -t test/templates/casadi_sx.jinja -m test/models/integrator.mo
import casadi as ca
class Integrator:
def __init__(self):
# declare states
x = ca.SX.sym('x');
y = ca.SX.sym('y');
# declare state vector
self.x = ca.vertcat(
x,
y);
# declare state derivative equations
der_x = 1;
der_y = x;
# declare state derivative vector
self.x_dot = ca.vertcat(
der_x,
der_y);
self.ode = ca.Function('ode', [self.x], [self.x_dot])
Output is highly customizable as the JINJA template engine is used to render the rumoca abstract syntax tree. You can use/modify our example templates in the test directory or create your own using the widely used JINJA template language.