This repository contains modelica2pyomo.py, a tool to automatically translate Modelica models into Pyomo models.
The Modelica model should be converted into Base Modelica code generated by OpenModelica employing the script exampleInstantiation.mos as a template. The basic flags to generate the right flavour of Base Modelica are already set in the template, you can add more if required, as well as project-specific API calls to load the model and the required libraries. For open-source libraries, it is recommended to use the Package Manager to install them and the uses() annotation, so that they can be loaded automatically.
To obtain the BaseModelica model, run in a terminal window the following command:
omc exampleInstantiation.mos > exampleBaseModelica.momodelica2pyomo.py features a m2p() function, which should be executed to generate the equivalent Pyomo model.
The file example.py shows an example of how to call the m2p() function and which are the inputs to provide. You can use it as a template for your own project.
The generated Pyomo model employes the IDAES Python package to employ the optimization solver IPOPT. For this reason, few lines of code to import the idaes package are included in the generated Pyomo code.
Notice also that the Python packages numpy, scipy, DyMat and regex are required.