Skip to content

Commit

Permalink
Updated OpenModelica version (#2649)
Browse files Browse the repository at this point in the history
* Updated OpenModelica version to 1.18, switched to use of Docker for OMC.
  • Loading branch information
mwetter authored Oct 1, 2021
1 parent d78addc commit d94809c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 14 deletions.
14 changes: 3 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ services:
- docker
- xvfb


addons:
apt:
sources:
- sourceline: "deb https://build.openmodelica.org/omc/builds/linux/releases/1.16.1/ bionic release"
key_url: "http://build.openmodelica.org/apt/openmodelica.asc"
packages:
- omc=1.16.1-1
- omlib-modelica-3.2.2 #3.2.3 is not in https://build.openmodelica.org/omc/builds/linux/releases/1.16.1/dists/bionic/release/binary-amd64/Packages.gz


env:
global:
- ENERGYPLUS_VERSION=EnergyPlus-9.5.0-de239b2e5f-Linux-Ubuntu18.04-x86_64
Expand Down Expand Up @@ -130,6 +119,9 @@ before_install:
cd -;
echo "Installed modelica-json in ${MODELICA_JSON_HOME}";
fi;
- if [[ "$TEST_ARG" == *test-omc* ]]; then
docker pull "$DOCKER_USERNAME"/ubuntu-2004-omc:1.18.0;
fi;

# Install dependencies
# For sphinx, we need to install specific package versions, otherwise
Expand Down
3 changes: 2 additions & 1 deletion Buildings/Resources/Scripts/travis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ test-spawn-portability:
grep "terminated successfully" dslog.txt )

test-omc:
(cd $(ROOT) && $(TRAVIS_BUILD_DIR)/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh)
(cd $(ROOT) && \
$(TRAVIS_BUILD_DIR)/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh)

test-dymola:
(cd $(ROOT)/Buildings && \
Expand Down
97 changes: 97 additions & 0 deletions Buildings/Resources/Scripts/travis/omc/omc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
#################################################
# Shell script that simulates with OpenModelica using
# a docker image of OMC
#
# The main purpose of this script is to export
# MODELICAPATH
# updated for the docker, and to mount the
# required directories.
#################################################
set -e
IMG_NAME=ubuntu-2004-omc:1.18.0
DOCKER_USERNAME=michaelwetter

# Function declarations
function create_mount_command()
{
local pat="$1"
# Each entry in pat will be a mounted read-only volume
local mnt_cmd=""
for ele in ${pat//:/ }; do
mnt_cmd="${mnt_cmd} -v ${ele}:/mnt${ele}:ro"
done

# On Darwin, the exported temporary folder needs to be /private/var/folders, not /var/folders
# see https://askubuntu.com/questions/600018/how-to-display-the-paths-in-path-separately
if [ `uname` == "Darwin" ]; then
mnt_cmd=`echo ${mnt_cmd} | sed -e 's| /var/folders/| /private/var/folders/|g'`
fi
echo "${mnt_cmd}"
}

function update_path_variable()
{
# Prepend /mnt/ in front of each entry of a PATH variable in which the arguments are
# separated by a colon ":"
# This allows for example to create the new MODELICAPATH
local pat="$1"
local new_pat=`(set -f; IFS=:; printf "/mnt%s:" ${pat})`
# Cut the trailing ':'
new_pat=${new_pat%?}
echo "${new_pat}"
}

# Export the MODELICAPATH
if [ -z ${MODELICAPATH+x} ]; then
MODELICAPATH=`pwd`
else
# Add the current directory to the front of the Modelica path.
# This will export the directory to the docker, and also set
# it in the MODELICAPATH so that JModelica finds it.
MODELICAPATH=`pwd`:${MODELICAPATH}
fi

# Create the command to mount all directories in read-only mode
MOD_MOUNT=`create_mount_command ${MODELICAPATH}`

# Prepend /mnt/ in front of each entry, which will then be used as the MODELICAPATH
DOCKER_MODELICAPATH=`update_path_variable ${MODELICAPATH}`

# If the current directory is part of the argument list,
# replace it with . as the docker may have a different file structure
cur_dir=`pwd`
bas_nam=`basename ${cur_dir}`
arg_lis=`echo $@ | sed -e "s|${cur_dir}|.|g"`

# Set variable for shared directory
sha_dir=`dirname ${cur_dir}`

# Check if the python script should be run interactively (if -i is specified)
while [ $# -ne 0 ]
do
arg="$1"
case "$arg" in
-i)
interactive=true
DOCKER_INTERACTIVE=-t
;;
esac
shift
done

# --user=${UID} \

docker run \
--user=${UID} \
-i \
$DOCKER_INTERACTIVE \
--detach=false \
${MOD_MOUNT} \
-v ${sha_dir}:/mnt/shared \
--rm \
${DOCKER_USERNAME}/${IMG_NAME} /bin/bash -c \
"export OPENMODELICALIBRARY=${DOCKER_MODELICAPATH}:/usr/lib/omlibrary && \
cd /mnt/shared/${bas_nam} && \
omc ${arg_lis}"
exit $?
4 changes: 2 additions & 2 deletions Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# This file translates and simulates all models in FILES with omc
# Upon success, it exits with 0, otherwise it exits with a non-zero value.
#
Expand Down Expand Up @@ -40,8 +41,7 @@ done

export OPENMODELICALIBRARY=`pwd`:/usr/lib/omlibrary
#omc +d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection --newBackend $mosScript
omc $mosScript

${TRAVIS_BUILD_DIR}/Buildings/Resources/Scripts/travis/omc/omc.sh $mosScript

# Check for failures
exiFla=0
Expand Down

0 comments on commit d94809c

Please sign in to comment.