Open Modelica, Python, and LaTeX installation on my Mac

After spending nearly a day getting Open Modelica running on my MacBook, I decided to write things down to hopefully help others in the group avoid the problems and ambiguities I encountered. My Mac operating system is OS X 10.11.6 at this time.

At the start of the installation, I had two accounts on my computer: Admin and ray, with admin and regular user privileges, respectively. Following directions on the Open Modelica download page, I downloaded MacPorts, skipping the Xcode installation entirely without any problems so far. I used my own account but made sure MacPorts installed in the root directory. Next,

echo rsync://build.openmodelica.org/macports/ >> /opt/local/etc/macports/sources.conf

which would not work even from the Admin account – permission was denied because the file sources.conf was owned by wheel and so I could not append the path above. To solve this, I enabled my root account, logged into it, and finally was able to execute this command. I then switched to Admin, enabled admin privileges for ray to add that account to the sudo list. I then went back to account ray and did everything from there (not from root as specified on the OpenModelica page). I then

sudo port selfupdate
sudo port install gcc44
sudo port install openmodelica-devel +libraries

which all went well except for some warnings during the gcc installation.

At this point, Modelica was installed as basically a set of libraries – looking in /Applications/MacPorts, no applications were found. So then I went to to the OpenModelica OMEdit page and downloaded from nightly builds/mac/binaries/release the 1.12.0 version .mkpg and installed that. That not only gave me OMEdit.app but also OMNotebook.app, OMShell.app, and Python 2.7 – more on that next. Note that all of the Modelica software above takes about 6-7 GB of space.

To check if things are working, the following should produce a plot of a bouncing ball (note that the location of BouncingBall.mo may be different for you). To start, click on OMShell.app and then enter

loadModel(Modelica)
loadFile(“/opt/openmodelica/share/doc/omc/testmodels/BouncingBall.mo”)
list(BouncingBall)
simulate(BouncingBall, stopTime=3.0)
plot({h})

To test my own ODE model, I first created the file test.mo located on my desktop and containing:

model firstODE “First order initial value problem”
  Real x “State variable”;
initial equation
  x = 2 “Initial condition”;
equation
  der(x) = 1-x;
end firstODE;

and then

cd(“/Users/ray/desktop”)
loadFile(“test.mo”)
simulate(firstODE, startTime=0, stopTime=3)
plot(x)

Note that loadFile() will return a false if there are syntax errors or special characters in the test.mo file.

Python

After adding a 0.5 TB SSD to my laptop I needed to reinstall Python. I’ve used the Enthought distribution in that past because the version of Python that comes with OS X does not have PyLab and other packages we use. Since the previous time I installed it, Enthought seems to have wrapped its Python distribution with a deployment manager environment EDM. This works well for me because I always use Python from the command-line interface. After installation of EDM, I needed to install the packages we use by opening a terminal window and

edm install

to install the edm shell and then

edm install scipy
edm install matplotlib
edm install pyside
edm install networkx

and more. Note that pyside is needed for matplotlib to work because it provides the GUI toolkit Qt necessary to display the plots. To run a python script

edm python myscript.py

and to use python interactively

edm shell
python

I also installed Enthought’s canopy which provides a graphical Python package manager and an interactive analysis environment that includes a code editor,  IPython window, and simplified Jupyter access. I downloaded the 64-bit macOS Python 2.7b distribution which includes everything we need except networkx which can be downloaded using the Canopy package manager. Note that the first time I opened the Canopy editor, I had to Reset the python environment… through Canopy Tools => Troubleshoot menu.

LaTeX

I have been using the same distribution of LaTeX for 10 years. Therefore, I’m going to try MacTeX 2018 since it seems to include every package we use (including ChemFig?) and TeXShop as the front end. After downloading and installing it, everything worked perfectly.

Leave a Reply

Your email address will not be published. Required fields are marked *