Tag Archives: Modelica

Modelica external C functions

This post looks into getting external functions working in OpenModelica and, to an extent, Dymola. There are a couple of approaches and I hope to give you a better idea of what to look out for when you come to implement your functions.

You may have noticed that my series on Modelica socket communication stalled somewhat after only one part. Originally, this post was going to be part 2 of the series, but it has become somewhat more general, so I’m posting it as a separate thing.

Continue reading

Modelica socket communication (Part 1: socket library)

Now that I’ve demonstrated a method of using the OpenModelica CORBA interface to set up and run simulations, I will move on to a way of passing data out of and in to a running simulation (for example, to use a control algorithm that is more easily implemented in another language). I will use sockets for this as they are one of the simplest and most generic communication methods available.

The first step in setting up socket communication within a Modelica simulation is to create a socket library that can be called from the simulation code. Fortunately, this is very simple C code. You can find the relevant code here.

Continue reading

OpenModelica and Python via CORBA (Part 3: Python wrapper)

Part 1 (getting started) | Part 2 (IDL compilation) | Part 3 (Python wrapper)

The final step in the process is to create a wrapper to allow easy programmatic control of OMC. I have posted a simple wrapper that provides the facilities required by the bouncing ball example here. It is not at the same level as the work by Ganeson et al. of course.

Continue reading

Compiling OpenModelica on Mint

When compiling OpenModelica from source on Mint (and possibly on Ubuntu?) the compile cheat sheet in the readme gives working instructions with one exception: several packages, such as libqtwebkit-dev, aren’t installed when you run the sudo apt-get build-dep openmodelica step. I had to use the following commands from the text further down the readme to get everything needed:

sudo apt-get install antlr libantlr-dev
sudo apt-get install libreadline-dev libqt4-dev libqtwebkit-dev libqwt5-qt4-dev
sudo apt-get install sqlite3 libsqlite3-dev

Note that I had to use to libreadline-dev instead of libreadline5-dev. Either way, that particular package was already installed, but I’ve left it here for completeness as the others on the same line weren’t.

I also needed to install bison and flex for the testsuite (not mentioned in the build instructions).

There may be other packages required that I already had installed, so my advice would be to install all of the packages they suggest rather than relying on build-dep.

OpenModelica and Python via CORBA (Part 2: IDL compilation)

Part 1 (getting started) | Part 2 (IDL compilation) | Part 3 (Python wrapper)

In part 1 I showed you how to get set up with the omniORB library/tools to communicate with OMC from Python. This post will show how to compile an IDL file to provide the appropriate interface to your script. This post assumes that the environment variables from last time are still set up and that you have OMC running with the +d=interactiveCorba parameter.

Continue reading

OpenModelica and Python via CORBA (Part 1: getting started)

Part 1 (getting started) | Part 2 (IDL compilation) | Part 3 (Python wrapper)

In this post I’m going to be walking through the process of setting up omniORB with Python for the purpose of interacting with the CORBA interface provided by the OpenModelica compiler (OMC). This allows OMC to be controlled from a Python script (loading simulations, changing parameters, etc). While the intention of this post is specifically that of interacting with OMC, the installation of omniORB will be the same in other situations. Note though that you may require additional setup in these other situations, for omniNames for example. I will be showing the setup process for Linux (and specifically, Mint/Ubuntu). I will assume that OpenModelica is already installed.

Continue reading