From 498e216d6421b636524bcbe86f34116a965f6dbd Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Fri, 27 Sep 2024 13:22:24 -0500 Subject: [PATCH] FIX: Use "lite" CLR host on windows for 251+ (#920) Co-authored-by: Mohamed Koubaa Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> --- doc/changelog.d/920.fixed.md | 1 + src/ansys/mechanical/core/embedding/addins.py | 6 ------ .../mechanical/core/embedding/initializer.py | 18 ++++++++++++++++-- tests/embedding/test_dyna.py | 4 ++++ 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 doc/changelog.d/920.fixed.md diff --git a/doc/changelog.d/920.fixed.md b/doc/changelog.d/920.fixed.md new file mode 100644 index 000000000..b0b3fbfa4 --- /dev/null +++ b/doc/changelog.d/920.fixed.md @@ -0,0 +1 @@ +Use "lite" CLR host on windows for 251+ \ No newline at end of file diff --git a/src/ansys/mechanical/core/embedding/addins.py b/src/ansys/mechanical/core/embedding/addins.py index 6fc1bec4b..3a865a616 100644 --- a/src/ansys/mechanical/core/embedding/addins.py +++ b/src/ansys/mechanical/core/embedding/addins.py @@ -52,9 +52,3 @@ def addin_configuration(self) -> str: @addin_configuration.setter def addin_configuration(self, value: str): self._addin_configuration = value - - -def configure(configuration: AddinConfiguration): - """Apply the given configuration.""" - if configuration.no_act_addins: - os.environ["ANSYS_MECHANICAL_STANDALONE_NO_ACT_EXTENSIONS"] = "1" diff --git a/src/ansys/mechanical/core/embedding/initializer.py b/src/ansys/mechanical/core/embedding/initializer.py index 2b064287e..2a1b0be22 100644 --- a/src/ansys/mechanical/core/embedding/initializer.py +++ b/src/ansys/mechanical/core/embedding/initializer.py @@ -95,12 +95,24 @@ def _get_default_version() -> int: return int_version -def __check_python_interpreter_architecture(): +def __check_python_interpreter_architecture() -> None: """Embedding support only 64 bit architecture.""" if platform.architecture()[0] != "64bit": raise Exception("Mechanical Embedding requires a 64-bit Python environment.") +def __set_environment(version: int) -> None: + """Set environment variables to configure embedding.""" + if os.name == "nt": # pragma: no cover + if version < 251: + os.environ["MECHANICAL_STARTUP_UNOPTIMIZED"] = "1" + + # TODO - use this on linux as well + if version >= 251: + if "PYMECHANICAL_NO_CLR_HOST_LITE" not in os.environ: + os.environ["ANSYS_MECHANICAL_EMBEDDING_CLR_HOST"] = "1" + + def __check_for_mechanical_env(): """Embedding in linux platform must use mechanical-env.""" if platform.system() == "Linux" and os.environ.get("PYMECHANICAL_EMBEDDING") != "TRUE": @@ -157,7 +169,9 @@ def initialize(version: int = None): INITIALIZED_VERSION = version - __check_loaded_libs(version) # pragma: no cover + __set_environment(version) + + __check_loaded_libs(version) __workaround_material_server(version) diff --git a/tests/embedding/test_dyna.py b/tests/embedding/test_dyna.py index 7427ea707..7348b272a 100644 --- a/tests/embedding/test_dyna.py +++ b/tests/embedding/test_dyna.py @@ -37,6 +37,10 @@ def test_lsdyna(printer, embedded_app, assets): Runs only in Windows environment. This test involves a simple geometry with high velocity hitting on rigid wall. + + Note - In order for standalone Mechanical to use LS-DYNA, + the lsdyna license needs to be at the top of the list. + Use the license preferences in Mechanical to set this up. """ embedded_app.update_globals(globals()) printer("Setting up test - LSDyna system")