From 68c1f4a9011c073306012e1cb8c8954ccc51ec42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20R=C3=A4bin=C3=A4?= Date: Wed, 7 Feb 2024 11:39:16 +0000 Subject: [PATCH] Support latest ansys electronic executable Use find_ansys_executable to detect ansys executable on the current system looking from default installation locations. Uses latest windows default installation location if Ansys is not found on current machine. This is useful if external simulation machine is used. --- klayout_package/python/kqcircuits/defaults.py | 4 +-- .../python/kqcircuits/util/defaults_helper.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 klayout_package/python/kqcircuits/util/defaults_helper.py diff --git a/klayout_package/python/kqcircuits/defaults.py b/klayout_package/python/kqcircuits/defaults.py index 831f9ade3..9d5bd3768 100644 --- a/klayout_package/python/kqcircuits/defaults.py +++ b/klayout_package/python/kqcircuits/defaults.py @@ -25,6 +25,7 @@ from pathlib import Path from kqcircuits.pya_resolver import pya +from kqcircuits.util.defaults_helper import find_ansys_executable from kqcircuits.util.import_helper import module_from_file @@ -52,8 +53,7 @@ TMP_PATH.mkdir(parents=True, exist_ok=True) # TODO move elsewhere? -ANSYS_EXECUTABLE = r"%PROGRAMFILES%\AnsysEM\v232\Win64\ansysedt.exe" # default Ansys executable location in Windows -# ANSYS_EXECUTABLE = "/opt/AnsysEM/v232/Linux64/ansysedt" # default Ansys executable location in Linux +ANSYS_EXECUTABLE = find_ansys_executable(r"%PROGRAMFILES%\AnsysEM\v241\Win64\ansysedt.exe") ANSYS_SCRIPT_PATHS = [SCRIPTS_PATH.joinpath("simulations").joinpath("ansys")] ELMER_SCRIPT_PATHS = [SCRIPTS_PATH.joinpath("simulations").joinpath("elmer")] XSECTION_PROCESS_PATH = ROOT_PATH.joinpath("xsection/kqc_process.xs") diff --git a/klayout_package/python/kqcircuits/util/defaults_helper.py b/klayout_package/python/kqcircuits/util/defaults_helper.py new file mode 100644 index 000000000..0111adfca --- /dev/null +++ b/klayout_package/python/kqcircuits/util/defaults_helper.py @@ -0,0 +1,34 @@ +# This code is part of KQCircuits +# Copyright (C) 2024 IQM Finland Oy +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program. If not, see +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# The software distribution should follow IQM trademark policy for open-source software +# (meetiqm.com/developers/osstmpolicy). IQM welcomes contributions to the code. Please see our contribution agreements +# for individuals (meetiqm.com/developers/clas/individual) and organizations (meetiqm.com/developers/clas/organization). + +import os +from pathlib import Path + + +def find_ansys_executable(default): + """Finds latest Ansys Electronics executable from default installation locations. Returns 'default' if not found. + """ + paths = [(Path(os.environ.get("ProgramFiles", r"C:\Program Files")).joinpath("AnsysEM"), r"Win64\ansysedt.exe"), + (Path("/opt/AnsysEM"), "Linux64/ansysedt")] + for root, exe in paths: + if os.path.isdir(root): + versions = sorted([f for f in os.listdir(root) if f.startswith("v")], reverse=True) + for version in versions: + executable = root.joinpath(version).joinpath(exe) + if os.path.isfile(executable): + return executable + return default