use dymola python bridge to run framework on windows#3
use dymola python bridge to run framework on windows#3Honigmelone wants to merge 1 commit intoRWTH-EBC:masterfrom
Conversation
FWuellhorst
left a comment
There was a problem hiding this comment.
Thanks for implementing this and thus contributing to this fork. :)
Please check if you are calling the add_dymola_to_active_environment.py. I could not find it anywhere.
| dymola_search_path1 = os.path.join('C:\\', 'Program Files', | ||
| 'Dymola 2018 FD01', | ||
| 'Modelica', | ||
| 'Library', | ||
| 'python_interface', | ||
| 'dymola.egg') | ||
| dymola_search_path2 = os.path.join('C:\\', 'Program Files', | ||
| 'Dymola 2018', | ||
| 'Modelica', | ||
| 'Library', | ||
| 'python_interface', | ||
| 'dymola.egg') |
There was a problem hiding this comment.
This will work for Dymola 2018 only.
I'm currently using the following function to dynamically find Dymola installations.
Feel free to adapt it to pathlib :)
Note that I tested it for Windows and Linux, not for mac so far.
import sys
import os
def get_dymola_install_path(basedir=None):
"""
Function to get the path of the newest dymola installment
on the used machine. Supported platforms are:
* Windows
* Linux
* Mac OS X
If multiple installation of Dymola are found, the newest version will be returned.
This assumes the names are sortable, e.g. Dymola 2020, Dymola 2019 etc.
:param str basedir:
The base-directory to search for the dymola-installation.
The default value depends on the platform one is using.
On Windows it is "C://Program Files" or "C://Program Files (x86)" (for 64 bit)
On Linux it is "/opt" (based on our ci-Docker configuration
On Mac OS X "/Application" (based on the default)
:return: str
Path to the dymola-installation
"""
if basedir is None:
if "linux" in sys.platform:
basedir = os.path.normpath("/opt")
elif "win" in sys.platform:
basedir = os.path.normpath("C:/Program Files")
elif "darwin" in sys.platform:
basedir = os.path.normpath("/Applications")
else:
raise OSError(f"Your operating system ({sys.platform})does not support "
f"a default basedir. Please provide one.")
syspaths = [basedir]
# Check if 64bit is installed (Windows only)
systempath_64 = os.path.normpath("C://Program Files (x86)")
if os.path.exists(systempath_64):
syspaths.append(systempath_64)
# Get all folders in both path's
temp_list = []
for systempath in syspaths:
temp_list += os.listdir(systempath)
# Filter programs that are not Dymola
dym_versions = []
for folder_name in temp_list:
# Catch both Dymola and dymola folder-names
if "dymola" in folder_name.lower():
dym_versions.append(folder_name)
del temp_list
# Find the newest version and return the egg-file
# This sorting only works with a good Folder structure, eg. Dymola 2020, Dymola 2019 etc.
dym_versions.sort()
for dym_version in reversed(dym_versions):
for system_path in syspaths:
full_path = os.path.join(system_path, dym_version)
if os.path.isdir(full_path):
return full_path
# If still inside the function, no interface was found| try: | ||
| os.mkdir(WORKING_DIR) | ||
| except OSError: | ||
| print("Creation of the directory %s failed" % WORKING_DIR) |
There was a problem hiding this comment.
If the creation fails, isn't the whole script going to fail as well?
|
|
||
|
|
||
| # dymola.ExecuteCommand("Advanced.CompileWith64=2") | ||
| result = dymola.ExecuteCommand('Modelica.Utilities.System.setWorkDirectory("' + Path(WORKING_DIR).as_posix() + '")') |
There was a problem hiding this comment.
Does this achieve something different than simple dymola.cd(Path(WORKING_DIR).as_posix())?
| # dymola.plot(["J1.w", "J2.w", "J3.w", "J4.w"]) | ||
| #dymola.plot(['STABLE_MOTION_G2_PRT.frame_a.f[1]','STABLE_MOTION_G2_PRT.frame_a.f[2]', 'STABLE_MOTION_G2_PRT.frame_a.f[3]']) | ||
| #dymola.ExportPlotAsImage(os.path.join(dir_result, 'tmp.png')) |
There was a problem hiding this comment.
Does not work so far? If so, delete. If it works, add an options at the start, e.g. PLOT_RESULTS = True.
Hi,
thanks for updating this repository for python 3. I wanted to try the code on my machine and was experiencing trouble with the automated simulation execution, due to it only being implemented for linux. In this pull request I want to show a possibility to use this in windows as well. The proposed solution, might also be favourable for runtime optimization.
why
*.mosfile directly with the dymola executable.how
*.moswritertasks left
I would be happy if you would consider such a change.