ModelicaRunner¶
- class geojson_modelica_translator.modelica.modelica_runner.ModelicaRunner¶
Bases:
object
Class to run Modelica models.
- __init__()¶
Initialize the runner with data needed for simulation
Methods
__init__
()Initialize the runner with data needed for simulation
cleanup_path
(path, model_name, **kwargs)Clean up the files in the path that was presumably used to run the simulation.
move_results
(from_path, to_path[, model_name])This method moves the results of the simulation that are known for now.
run_in_docker
(action, model_name[, ...])Run the Modelica project in a docker-based environment.
run_in_dymola
(action, model_name, ...)If running on Windows or Linux, you can run Dymola (assuming you have a license), using the BuildingsPy library.
Attributes
ACTION_LOG_MAP
- cleanup_path(path: Path, model_name: str, **kwargs: dict) None ¶
Clean up the files in the path that was presumably used to run the simulation. If debug is passed, then simulation running files will not be removed, but the intermediate simulation files will be removed (e.g., .c, .h, .o, .bin)
- Parameters:
path (Path) – Path of the folder to clean
model_name (str) – Name of the model, used to remove model-specific intermediate files
kwargs – additional arguments to pass to the runner which can include debug (bool): whether to remove all files or not
- move_results(from_path: Path, to_path: Path, model_name: str | None = 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.
If there are results, they will simply be overwritten (for now).
- Parameters:
from_path (Path) – where the files will move from
to_path (Path) – where the files will be saved. Will be created if does not exist.
model_name (Union[str, None], optional) – name of the project ran in run_in_docker method. Defaults to None.
- run_in_docker(action: str, model_name: str, file_to_load: str | Path | None = None, run_path: str | Path | None = None, **kwargs) tuple[bool, str | Path] ¶
Run the Modelica project in a docker-based environment. The action will determine what type of run will be conducted. This method supports either a file path pointing to the package to load, or a modelica path which is a period separated path. Results are saved into run_path.
stdout.log will store both stdout and stderr of the simulations
- Parameters:
action (str) – The action to run, must be one of compile_and_run, compile, or run
model_name (str) – The name of the model to be simulated (this is the name within Modelica)
file_to_load (str, Path) – The file path or a modelica path to be simulated
run_path (str, optional) – location where the Modelica simulation will start. Defaults to None.
kwargs – additional arguments to pass to the runner which can include project_in_library (bool): whether the project is in a library or not start_time (float): start time of the simulation stop_time (float): stop time of the simulation step_size (float): step size of the simulation number_of_intervals (int): number of intervals to run the simulation debug (bool): whether to run in debug mode or not, prevents files from being deleted.
- Returns:
success status and path to the results directory
- Return type:
tuple[bool, str]
- run_in_dymola(action: str, model_name: str, file_to_load: str | Path, run_path: str | Path, **kwargs) tuple[bool, str | Path] ¶
If running on Windows or Linux, you can run Dymola (assuming you have a license), using the BuildingsPy library. This is not supported on Mac.
For using Dymola with the GMT, you need to ensure that MSL v4.0 are loaded correctly and that the Buildings library is in the MODELICAPATH. I added the MSL openModel via appending it to the Dymola’s /opt/<install>/install/dymola.mos file on Linux.
- Parameters:
action (str) – compile (translate) or simulate
model_name (str) – Name of the model to translate or simulate
package_path (Union[str, Path]) – Name of the package to also load
kwargs – additional arguments to pass to the runner which can include start_time (float): start time of the simulation stop_time (float): stop time of the simulation, in seconds step_size (float): step size of the simulation, in seconds debug (bool): whether to run in debug mode or not, prevents files from being deleted.
- Returns:
success status and path to the results directory
- Return type:
tuple[bool, Union[str, Path]]