From aa9fd9d8369d4619002ffbd3cbada54f374ba09f Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Thu, 24 Oct 2024 20:43:06 -0400 Subject: [PATCH 1/3] fix: Handle unitless parameters --- src/ansys/fluent/core/solver/flobject.py | 44 +++++++------------- tests/parametric/test_parametric_workflow.py | 10 +++++ 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 8939939d64e..e4a274d2aca 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -1756,7 +1756,7 @@ def _fix_parameter_list_return(val): new_val = {} for name, v in val.items(): value, units = v - if len(units) > 0: + if len(units) > 0 and isinstance(units[0], str): unit_labels = _fix_parameter_list_return.scheme_eval( f"(units/inquire-available-label-strings-for-quantity '{units[0]})" ) @@ -2204,42 +2204,28 @@ def get_root( """ from ansys.fluent.core import CODEGEN_OUTDIR, CODEGEN_ZIP_SETTINGS, utils - obj_info = flproxy.get_static_info() - try: - if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": - settings = utils.load_module( - f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", + if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": + settings = utils.load_module( + f"settings_{version}", + CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", + ) + else: + if CODEGEN_ZIP_SETTINGS: + importer = zipimporter( + str(CODEGEN_OUTDIR / "solver" / f"settings_{version}.zip") ) + settings = importer.load_module("settings") else: - if CODEGEN_ZIP_SETTINGS: - importer = zipimporter( - str(CODEGEN_OUTDIR / "solver" / f"settings_{version}.zip") - ) - settings = importer.load_module("settings") - else: - settings = utils.load_module( - f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", - ) - - if settings.SHASH != _gethash(obj_info): - settings_logger.warning( - "Mismatch between generated file and server object " - "info. Dynamically created settings classes will " - "be used." + settings = utils.load_module( + f"settings_{version}", + CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", ) - raise RuntimeError("Mismatch in hash values") - cls = settings.root - except Exception: - cls, _ = get_cls("", obj_info, version=version) - root = cls() + root = settings.root() root.set_flproxy(flproxy) root._set_on_interrupt(interrupt) root._set_file_transfer_service(file_transfer_service) _Alias.scheme_eval = scheme_eval _fix_parameter_list_return.scheme_eval = scheme_eval - root._setattr("_static_info", obj_info) root._setattr("_file_transfer_service", file_transfer_service) return root diff --git a/tests/parametric/test_parametric_workflow.py b/tests/parametric/test_parametric_workflow.py index f582852b96c..db1ae10fef3 100644 --- a/tests/parametric/test_parametric_workflow.py +++ b/tests/parametric/test_parametric_workflow.py @@ -255,6 +255,15 @@ def test_parameters_list_function(static_mixer_settings_session): create_output_param("report-definition", "outlet-temp-avg") create_output_param("report-definition", "outlet-vel-avg") + # Create a unitless output parameter + unitless_quantity = solver.settings.solution.report_definitions.surface.create( + "temp-outlet-uniformity" + ) + unitless_quantity.report_type = "surface-masswtui" + unitless_quantity.field = "temperature" + unitless_quantity.surface_names = ["outlet"] + unitless_quantity.output_parameter = True + input_parameters_list = solver.parameters.input_parameters.list() output_parameters_list = solver.parameters.output_parameters.list() assert input_parameters_list == { @@ -266,4 +275,5 @@ def test_parameters_list_function(static_mixer_settings_session): assert output_parameters_list == { "outlet-temp-avg-op": [0.0, "K"], "outlet-vel-avg-op": [0.0, "m/s"], + "temp-outlet-uniformity-op": [0.0, ""], } From b0321170ad9a47daddae9e63664577b9f6191242 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Thu, 24 Oct 2024 20:45:51 -0400 Subject: [PATCH 2/3] fix: Handle unitless parameters --- src/ansys/fluent/core/solver/flobject.py | 42 ++++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index e4a274d2aca..bd9f6ce020c 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -2204,28 +2204,42 @@ def get_root( """ from ansys.fluent.core import CODEGEN_OUTDIR, CODEGEN_ZIP_SETTINGS, utils - if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": - settings = utils.load_module( - f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", - ) - else: - if CODEGEN_ZIP_SETTINGS: - importer = zipimporter( - str(CODEGEN_OUTDIR / "solver" / f"settings_{version}.zip") - ) - settings = importer.load_module("settings") - else: + obj_info = flproxy.get_static_info() + try: + if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": settings = utils.load_module( f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", + CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", ) - root = settings.root() + else: + if CODEGEN_ZIP_SETTINGS: + importer = zipimporter( + str(CODEGEN_OUTDIR / "solver" / f"settings_{version}.zip") + ) + settings = importer.load_module("settings") + else: + settings = utils.load_module( + f"settings_{version}", + CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", + ) + + if settings.SHASH != _gethash(obj_info): + settings_logger.warning( + "Mismatch between generated file and server object " + "info. Dynamically created settings classes will " + "be used." + ) + raise RuntimeError("Mismatch in hash values") + cls = settings.root + except Exception: + cls, _ = get_cls("", obj_info, version=version) + root = cls() root.set_flproxy(flproxy) root._set_on_interrupt(interrupt) root._set_file_transfer_service(file_transfer_service) _Alias.scheme_eval = scheme_eval _fix_parameter_list_return.scheme_eval = scheme_eval + root._setattr("_static_info", obj_info) root._setattr("_file_transfer_service", file_transfer_service) return root From ca1e49ea6563fa7e9d9f4fe3490d3717567d7531 Mon Sep 17 00:00:00 2001 From: Sean Pearson <93727996+seanpearsonuk@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:00:41 +0100 Subject: [PATCH 3/3] Update flobject.py --- src/ansys/fluent/core/solver/flobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index bd9f6ce020c..674339f3251 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -1750,7 +1750,7 @@ def __call__(self, *args, **kwds): raise KeyboardInterrupt -# TODO: Remove this after paremater list() method is fixed from Fluent side +# TODO: Remove this after parameter list() method is fixed from Fluent side def _fix_parameter_list_return(val): if isinstance(val, dict): new_val = {}