ModelicaRunner

class geojson_modelica_translator.modelica.modelica_runner.ModelicaRunner(modelica_lib_path=None)

Bases: object

Class to run Modelica models. This is a very simple implementation of what needs to be a full CLI to run Modelica easily. At the moment, this probably only works on Linux/Mac and perhaps in Windows with Docker. For Ubuntu, here is the installation instruction: https://docs.docker.com/engine/install/ubuntu/

# TODO: test in windows # Document how to install Docker

__init__(modelica_lib_path=None)

Initialize the runner with data needed for simulation

Parameters

modelica_lib_path – string, Path to the MBL to run against

Methods

__init__([modelica_lib_path])

Initialize the runner with data needed for simulation

cleanup_path(path)

Clean up the files in the path that was presumably used to run the simulation

move_results(from_path, to_path[, project_name])

This method moves the results of the simulation that are known for now.

run_in_docker(file_to_run[, run_path, ...])

Run the Modelica project in a docker-based environment.

cleanup_path(path: pathlib.Path)

Clean up the files in the path that was presumably used to run the simulation

move_results(from_path: pathlib.Path, to_path: pathlib.Path, project_name=None) None

This method moves the results of the simulation that are known for now. This method moves only specific files (stdout.log for now), plus all files and folders beginning with the “{project_name}_” name.

Parameters
  • from_path – pathlib.Path, where the files will move from

  • to_path – pathlib.Path, where the files will be saved. Will be created if does not exist.

  • project_name – string, name of the project ran in run_in_docker method

Returns

None

run_in_docker(file_to_run, run_path=None, project_name=None)

Run the Modelica project in a docker-based environment. Results are saved into the path of the file that was selected to run.

stdout.log will store both stdout and stderr of the simulations

Parameters
  • file_to_run – string, name of the file (could be directory?) to simulate

  • run_path – string, location where the Modelica simulation will start

  • project_name – string, name of the project being simulated. Will be used to determine name of results directory

Returns

tuple(bool, str), success status and path to the results directory