From 12e41c288280990d45e11831e472a672e6f15e5a Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 20 Sep 2024 12:15:30 -0400 Subject: [PATCH 1/6] feat: Builtin settings classes for Solution section --- src/ansys/fluent/core/codegen/allapigen.py | 2 +- .../core/codegen/builtin_settingsgen.py | 36 ++++++++- .../core/solver/settings_builtin_bases.py | 22 +++++- .../core/solver/settings_builtin_data.py | 26 +++++-- tests/test_settings_api.py | 77 +++++++++++++++++++ 5 files changed, 152 insertions(+), 11 deletions(-) diff --git a/src/ansys/fluent/core/codegen/allapigen.py b/src/ansys/fluent/core/codegen/allapigen.py index 0981b140209..0d66ad23b87 100644 --- a/src/ansys/fluent/core/codegen/allapigen.py +++ b/src/ansys/fluent/core/codegen/allapigen.py @@ -27,7 +27,7 @@ def generate(version: str, static_infos: dict): Path(api_tree_file).parent.mkdir(parents=True, exist_ok=True) with open(api_tree_file, "wb") as f: pickle.dump(api_tree, f) - builtin_settingsgen.generate() + builtin_settingsgen.generate(version) if __name__ == "__main__": diff --git a/src/ansys/fluent/core/codegen/builtin_settingsgen.py b/src/ansys/fluent/core/codegen/builtin_settingsgen.py index 12b631a47b6..88975454a00 100644 --- a/src/ansys/fluent/core/codegen/builtin_settingsgen.py +++ b/src/ansys/fluent/core/codegen/builtin_settingsgen.py @@ -1,19 +1,45 @@ """Generate builtin setting classes.""" from ansys.fluent.core import CODEGEN_OUTDIR, FluentVersion +from ansys.fluent.core.solver.flobject import CreatableNamedObjectMixin from ansys.fluent.core.solver.settings_builtin_data import DATA _PY_FILE = CODEGEN_OUTDIR / "solver" / "settings_builtin.py" _PYI_FILE = CODEGEN_OUTDIR / "solver" / "settings_builtin.pyi" -def generate(): +def _get_settings_root(version: str): + from ansys.fluent.core import CODEGEN_OUTDIR, CODEGEN_ZIP_SETTINGS, utils + + 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", + ) + return settings.root + + +def _get_named_object_type(root, path): + for comp in path.split("."): + root = root._child_classes[comp] + return ( + "Creatable" if issubclass(root, CreatableNamedObjectMixin) else "NonCreatable" + ) + + +def generate(version: str): """Generate builtin setting classes.""" CODEGEN_OUTDIR.mkdir(exist_ok=True) + root = _get_settings_root(version) with open(_PY_FILE, "w") as f: f.write('"""Solver settings."""\n\n') f.write( - "from ansys.fluent.core.solver.settings_builtin_bases import _SingletonSetting, _NamedObjectSetting\n\n\n" + "from ansys.fluent.core.solver.settings_builtin_bases import _SingletonSetting, _CreatableNamedObjectSetting, _NonCreatableNamedObjectSetting\n\n\n" ) f.write("__all__ = [\n") for name, _ in DATA.items(): @@ -21,6 +47,9 @@ def generate(): f.write("]\n\n") for name, v in DATA.items(): kind, path = v + if kind == "NamedObject": + path = path[FluentVersion(version)] if isinstance(path, dict) else path + kind = f"{_get_named_object_type(root, path)}NamedObject" f.write(f"class {name}(_{kind}Setting):\n") f.write(f' """{name} setting."""\n\n') @@ -43,4 +72,5 @@ def generate(): if __name__ == "__main__": - generate() + version = "251" # for development + generate(version) diff --git a/src/ansys/fluent/core/solver/settings_builtin_bases.py b/src/ansys/fluent/core/solver/settings_builtin_bases.py index e5084bd9c53..9ba275a37ca 100644 --- a/src/ansys/fluent/core/solver/settings_builtin_bases.py +++ b/src/ansys/fluent/core/solver/settings_builtin_bases.py @@ -1,5 +1,7 @@ """Base classes for builtin setting classes.""" +from typing import Optional + from ansys.fluent.core.session_solver import Solver from ansys.fluent.core.solver.settings_builtin_data import DATA @@ -20,7 +22,25 @@ def __new__(cls, solver: Solver): return obj -class _NamedObjectSetting(_SingletonSetting): +class _CreatableNamedObjectSetting(_SingletonSetting): + def __new__( + cls, + solver: Solver, + name: Optional[str] = None, + new_instance_name: Optional[str] = None, + ): + if name and new_instance_name: + raise ValueError("Cannot specify both name and new_instance_name.") + obj = super().__new__(cls, solver) + if name: + return obj[name] + elif new_instance_name: + return obj.create(new_instance_name) + else: + return obj.create() + + +class _NonCreatableNamedObjectSetting(_SingletonSetting): def __new__(cls, solver: Solver, name: str): obj = super().__new__(cls, solver) return obj[name] diff --git a/src/ansys/fluent/core/solver/settings_builtin_data.py b/src/ansys/fluent/core/solver/settings_builtin_data.py index 77c96dff2cc..6870d3907f4 100644 --- a/src/ansys/fluent/core/solver/settings_builtin_data.py +++ b/src/ansys/fluent/core/solver/settings_builtin_data.py @@ -142,12 +142,6 @@ "SolidMaterial": ("NamedObject", "setup.materials.solid"), "MixtureMaterials": ("Singleton", "setup.materials.mixture"), "MixtureMaterial": ("NamedObject", "setup.materials.mixture"), - "InertParticles": ("Singleton", "setup.materials.inert_particles"), - "InertParticle": ("NamedObject", "setup.materials.inert_particles"), - "DropletParticles": ("Singleton", "setup.materials.droplet_particles"), - "DropletParticle": ("NamedObject", "setup.materials.droplet_particles"), - "CombustingParticles": ("Singleton", "setup.materials.combusting_particles"), - "CombustingParticle": ("NamedObject", "setup.materials.combusting_particles"), "ParticleMixtureMaterials": ("Singleton", "setup.materials.particle_mixture"), "ParticleMixtureMaterial": ("NamedObject", "setup.materials.particle_mixture"), "CellZoneConditions": ("Singleton", "setup.cell_zone_conditions"), @@ -321,4 +315,24 @@ FluentVersion.v232: "setup.named_expressions", }, ), + "Methods": ("Singleton", "solution.methods"), + "Controls": ("Singleton", "solution.controls"), + "ReportDefinitions": ("Singleton", "solution.report_definitions"), + "Monitor": ("Singleton", "solution.monitor"), + "Residual": ("Singleton", "solution.monitor.residual"), + "ReportFiles": ("Singleton", "solution.monitor.report_files"), + "ReportFile": ("NamedObject", "solution.monitor.report_files"), + "ReportPlots": ("Singleton", "solution.monitor.report_plots"), + "ReportPlot": ("NamedObject", "solution.monitor.report_plots"), + "ConvergenceConditions": ("Singleton", "solution.monitor.convergence_conditions"), + "CellRegisters": ("Singleton", "solution.cell_registers"), + "CellRegister": ("NamedObject", "solution.cell_registers"), + "Initialization": ("Singleton", "solution.initialization"), + "CalculationActivity": ("Singleton", "solution.calculation_activity"), + "ExecuteCommands": ("Singleton", "solution.calculation_activity.execute_commands"), + "CaseModification": ( + "Singleton", + "solution.calculation_activity.case_modification", + ), + "RunCalculation": ("Singleton", "solution.run_calculation"), } diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index e7a9efae298..0acfb35c1e6 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -509,23 +509,33 @@ def test_builtin_settings(static_mixer_case_session): Battery, BoundaryCondition, BoundaryConditions, + CalculationActivity, + CaseModification, + CellRegister, + CellRegisters, CellZoneCondition, CellZoneConditions, + Controls, + ConvergenceConditions, DiscretePhase, DynamicMesh, EChemistry, Energy, + ExecuteCommands, FluidCellZone, FluidCellZones, FluidMaterial, FluidMaterials, General, + Initialization, Injections, InteriorBoundaries, InteriorBoundary, Materials, MeshInterfaces, + Methods, Models, + Monitor, Multiphase, NamedExpressions, Optics, @@ -536,6 +546,13 @@ def test_builtin_settings(static_mixer_case_session): ReferenceFrame, ReferenceFrames, ReferenceValues, + ReportDefinitions, + ReportFile, + ReportFiles, + ReportPlot, + ReportPlots, + Residual, + RunCalculation, Setup, Sofc, SolidMaterial, @@ -687,6 +704,8 @@ def test_builtin_settings(static_mixer_case_session): WallBoundary(solver=solver, name="wall") == solver.setup.boundary_conditions.wall["wall"] ) + with pytest.raises(TypeError): + WallBoundary(solver=solver, new_instance_name="wall-1") if solver.get_fluent_version() >= FluentVersion.v232: assert MeshInterfaces(solver=solver) == solver.setup.mesh_interfaces else: @@ -718,3 +737,61 @@ def test_builtin_settings(static_mixer_case_session): else: with pytest.raises(RuntimeError): NamedExpressions(solver=solver) + assert Methods(solver=solver) == solver.solution.methods + assert Controls(solver=solver) == solver.solution.controls + assert ReportDefinitions(solver=solver) == solver.solution.report_definitions + assert Monitor(solver=solver) == solver.solution.monitor + assert Residual(solver=solver) == solver.solution.monitor.residual + assert ReportFiles(solver=solver) == solver.solution.monitor.report_files + assert ( + ReportFile(solver=solver, new_instance_name="report-file-1") + == solver.solution.monitor.report_files["report-file-1"] + ) + assert ( + ReportFile(solver=solver, name="report-file-1") + == solver.solution.monitor.report_files["report-file-1"] + ) + assert ( + ReportFile(solver=solver) + == solver.solution.monitor.report_files["report-file-2"] + ) + assert ReportPlots(solver=solver) == solver.solution.monitor.report_plots + assert ( + ReportPlot(solver=solver, new_instance_name="report-plot-1") + == solver.solution.monitor.report_plots["report-plot-1"] + ) + assert ( + ReportPlot(solver=solver, name="report-plot-1") + == solver.solution.monitor.report_plots["report-plot-1"] + ) + assert ( + ReportPlot(solver=solver) + == solver.solution.monitor.report_plots["report-plot-2"] + ) + assert ( + ConvergenceConditions(solver=solver) + == solver.solution.monitor.convergence_conditions + ) + assert CellRegisters(solver=solver) == solver.solution.cell_registers + assert ( + CellRegister(solver=solver, new_instance_name="cell_register_1") + == solver.solution.cell_registers["cell_register_1"] + ) + assert ( + CellRegister(solver=solver, name="cell_register_1") + == solver.solution.cell_registers["cell_register_1"] + ) + assert ( + CellRegister(solver=solver) == solver.solution.cell_registers["cell_register_2"] + ) + assert Initialization(solver=solver) == solver.solution.initialization + assert CalculationActivity(solver=solver) == solver.solution.calculation_activity + assert ( + ExecuteCommands(solver=solver) + == solver.solution.calculation_activity.execute_commands + ) + assert ( + CaseModification(solver=solver) + == solver.solution.calculation_activity.case_modification + ) + assert RunCalculation(solver=solver) == solver.solution.run_calculation From b5e1463dad5701f4a33c0354cbec19ec1c710c9b Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 20 Sep 2024 19:08:30 -0400 Subject: [PATCH 2/6] feat: fix codegen for other versions --- .../core/codegen/builtin_settingsgen.py | 8 + tests/test_settings_api.py | 140 ++++++++++-------- 2 files changed, 88 insertions(+), 60 deletions(-) diff --git a/src/ansys/fluent/core/codegen/builtin_settingsgen.py b/src/ansys/fluent/core/codegen/builtin_settingsgen.py index 88975454a00..0cb535b65f3 100644 --- a/src/ansys/fluent/core/codegen/builtin_settingsgen.py +++ b/src/ansys/fluent/core/codegen/builtin_settingsgen.py @@ -49,6 +49,10 @@ def generate(version: str): kind, path = v if kind == "NamedObject": path = path[FluentVersion(version)] if isinstance(path, dict) else path + if isinstance(path, dict): + if FluentVersion(version) not in path: + continue + path = path[FluentVersion(version)] kind = f"{_get_named_object_type(root, path)}NamedObject" f.write(f"class {name}(_{kind}Setting):\n") f.write(f' """{name} setting."""\n\n') @@ -61,6 +65,10 @@ def generate(version: str): f.write("\n\n") for name, v in DATA.items(): kind, path = v + if isinstance(path, dict): + if FluentVersion(version) not in path: + continue + path = path[FluentVersion(version)] f.write(f"class {name}(\n") if isinstance(path, str): path = {v: path for v in FluentVersion} diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index 0acfb35c1e6..58aebe51999 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -505,21 +505,14 @@ def test_exit_not_in_settings(new_solver_session): def test_builtin_settings(static_mixer_case_session): from ansys.fluent.core import ( - Ablation, - Battery, - BoundaryCondition, BoundaryConditions, CalculationActivity, CaseModification, CellRegister, CellRegisters, - CellZoneCondition, CellZoneConditions, Controls, ConvergenceConditions, - DiscretePhase, - DynamicMesh, - EChemistry, Energy, ExecuteCommands, FluidCellZone, @@ -528,23 +521,15 @@ def test_builtin_settings(static_mixer_case_session): FluidMaterials, General, Initialization, - Injections, InteriorBoundaries, InteriorBoundary, Materials, - MeshInterfaces, Methods, Models, Monitor, Multiphase, - NamedExpressions, - Optics, - Pemfc, PressureOutlet, PressureOutlets, - Radiation, - ReferenceFrame, - ReferenceFrames, ReferenceValues, ReportDefinitions, ReportFile, @@ -554,15 +539,10 @@ def test_builtin_settings(static_mixer_case_session): Residual, RunCalculation, Setup, - Sofc, SolidMaterial, SolidMaterials, - Species, - Structure, - SystemCoupling, VelocityInlet, VelocityInlets, - VirtualBladeModel, Viscous, WallBoundaries, WallBoundary, @@ -576,74 +556,100 @@ def test_builtin_settings(static_mixer_case_session): assert Energy(solver=solver) == solver.setup.models.energy assert Viscous(solver=solver) == solver.setup.models.viscous if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import Radiation + assert Radiation(solver=solver) == solver.setup.models.radiation else: - with pytest.raises(RuntimeError): - Radiation(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Radiation if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import Species + assert Species(solver=solver) == solver.setup.models.species else: - with pytest.raises(RuntimeError): - Species(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Species if solver.get_fluent_version() >= FluentVersion.v231: + from ansys.fluent.core import DiscretePhase + assert DiscretePhase(solver=solver) == solver.setup.models.discrete_phase else: - with pytest.raises(RuntimeError): - DiscretePhase(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import DiscretePhase if solver.get_fluent_version() >= FluentVersion.v231: + from ansys.fluent.core import Injections + assert ( Injections(solver=solver) == solver.setup.models.discrete_phase.injections ) else: - with pytest.raises(RuntimeError): - Injections(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Injections if solver.get_fluent_version() >= FluentVersion.v231: + from ansys.fluent.core import VirtualBladeModel + assert ( VirtualBladeModel(solver=solver) == solver.setup.models.virtual_blade_model ) else: - with pytest.raises(RuntimeError): - VirtualBladeModel(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import VirtualBladeModel if solver.get_fluent_version() >= FluentVersion.v231: + from ansys.fluent.core import Optics + assert Optics(solver=solver) == solver.setup.models.optics else: - with pytest.raises(RuntimeError): - Optics(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Optics if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import Structure + assert Structure(solver=solver) == solver.setup.models.structure else: - with pytest.raises(RuntimeError): - Structure(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Structure if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import Ablation + assert Ablation(solver=solver) == solver.setup.models.ablation else: - with pytest.raises(RuntimeError): - Ablation(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Ablation if solver.get_fluent_version() >= FluentVersion.v241: + from ansys.fluent.core import EChemistry + assert EChemistry(solver=solver) == solver.setup.models.echemistry else: - with pytest.raises(RuntimeError): - EChemistry(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import EChemistry if solver.get_fluent_version() >= FluentVersion.v241: + from ansys.fluent.core import Battery + assert Battery(solver=solver) == solver.setup.models.battery else: - with pytest.raises(RuntimeError): - Battery(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Battery if solver.get_fluent_version() >= FluentVersion.v241: + from ansys.fluent.core import SystemCoupling + assert SystemCoupling(solver=solver) == solver.setup.models.system_coupling else: - with pytest.raises(RuntimeError): - SystemCoupling(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import SystemCoupling if solver.get_fluent_version() >= FluentVersion.v241: + from ansys.fluent.core import Sofc + assert Sofc(solver=solver) == solver.setup.models.sofc else: - with pytest.raises(RuntimeError): - Sofc(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Sofc if solver.get_fluent_version() >= FluentVersion.v242: + from ansys.fluent.core import Pemfc + assert Pemfc(solver=solver) == solver.setup.models.pemfc else: - with pytest.raises(RuntimeError): - Pemfc(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import Pemfc assert Materials(solver=solver) == solver.setup.materials assert FluidMaterials(solver=solver) == solver.setup.materials.fluid assert ( @@ -656,13 +662,15 @@ def test_builtin_settings(static_mixer_case_session): ) assert CellZoneConditions(solver=solver) == solver.setup.cell_zone_conditions if solver.get_fluent_version() >= FluentVersion.v231: + from ansys.fluent.core import CellZoneCondition + assert ( CellZoneCondition(solver=solver, name="fluid") == solver.setup.cell_zone_conditions["fluid"] ) else: - with pytest.raises(RuntimeError): - CellZoneCondition(solver=solver, name="fluid") + with pytest.raises(ImportError): + from ansys.fluent.core import CellZoneCondition assert FluidCellZones(solver=solver) == solver.setup.cell_zone_conditions.fluid assert ( FluidCellZone(solver=solver, name="fluid") @@ -670,13 +678,15 @@ def test_builtin_settings(static_mixer_case_session): ) assert BoundaryConditions(solver=solver) == solver.setup.boundary_conditions if solver.get_fluent_version() >= FluentVersion.v231: + from ansys.fluent.core import BoundaryCondition + assert ( BoundaryCondition(solver=solver, name="inlet2") == solver.setup.boundary_conditions["inlet2"] ) else: - with pytest.raises(RuntimeError): - BoundaryCondition(solver=solver, name="inlet2") + with pytest.raises(ImportError): + from ansys.fluent.core import BoundaryCondition assert ( VelocityInlets(solver=solver) == solver.setup.boundary_conditions.velocity_inlet ) @@ -707,22 +717,30 @@ def test_builtin_settings(static_mixer_case_session): with pytest.raises(TypeError): WallBoundary(solver=solver, new_instance_name="wall-1") if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import MeshInterfaces + assert MeshInterfaces(solver=solver) == solver.setup.mesh_interfaces else: - with pytest.raises(RuntimeError): - MeshInterfaces(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import MeshInterfaces if solver.get_fluent_version() >= FluentVersion.v251: + from ansys.fluent.core import DynamicMesh + assert DynamicMesh(solver=solver) == solver.setup.dynamic_mesh else: - with pytest.raises(RuntimeError): - DynamicMesh(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import DynamicMesh assert ReferenceValues(solver=solver) == solver.setup.reference_values if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import ReferenceFrames + assert ReferenceFrames(solver=solver) == solver.setup.reference_frames else: - with pytest.raises(RuntimeError): - ReferenceFrames(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import ReferenceFrames if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import ReferenceFrame + # Fluent 25.1 issue if solver.get_fluent_version() != FluentVersion.v251: assert ( @@ -730,13 +748,15 @@ def test_builtin_settings(static_mixer_case_session): == solver.setup.reference_frames["global"] ) else: - with pytest.raises(RuntimeError): - ReferenceFrame(solver=solver, name="global") + with pytest.raises(ImportError): + from ansys.fluent.core import ReferenceFrame if solver.get_fluent_version() >= FluentVersion.v232: + from ansys.fluent.core import NamedExpressions + assert NamedExpressions(solver=solver) == solver.setup.named_expressions else: - with pytest.raises(RuntimeError): - NamedExpressions(solver=solver) + with pytest.raises(ImportError): + from ansys.fluent.core import NamedExpressions assert Methods(solver=solver) == solver.solution.methods assert Controls(solver=solver) == solver.solution.controls assert ReportDefinitions(solver=solver) == solver.solution.report_definitions From 0a9177890416096d8e0eb575c37eb431392201c7 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 20 Sep 2024 19:15:43 -0400 Subject: [PATCH 3/6] feat: fix codegen for other versions --- src/ansys/fluent/core/codegen/builtin_settingsgen.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ansys/fluent/core/codegen/builtin_settingsgen.py b/src/ansys/fluent/core/codegen/builtin_settingsgen.py index 0cb535b65f3..6232747f3c0 100644 --- a/src/ansys/fluent/core/codegen/builtin_settingsgen.py +++ b/src/ansys/fluent/core/codegen/builtin_settingsgen.py @@ -48,7 +48,6 @@ def generate(version: str): for name, v in DATA.items(): kind, path = v if kind == "NamedObject": - path = path[FluentVersion(version)] if isinstance(path, dict) else path if isinstance(path, dict): if FluentVersion(version) not in path: continue From c13ec34be8e710987c8d518545bdc5208905fe76 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 20 Sep 2024 21:03:32 -0400 Subject: [PATCH 4/6] feat: fix test --- src/ansys/fluent/core/codegen/allapigen.py | 4 +- .../core/codegen/builtin_settingsgen.py | 9 +- .../core/solver/settings_builtin_data.py | 149 ++++++++-- tests/test_settings_api.py | 272 +++++++++--------- 4 files changed, 276 insertions(+), 158 deletions(-) diff --git a/src/ansys/fluent/core/codegen/allapigen.py b/src/ansys/fluent/core/codegen/allapigen.py index 0d66ad23b87..3c1fbcd3bc6 100644 --- a/src/ansys/fluent/core/codegen/allapigen.py +++ b/src/ansys/fluent/core/codegen/allapigen.py @@ -10,6 +10,7 @@ tuigen, ) from ansys.fluent.core.search import get_api_tree_file_name +from ansys.fluent.core.utils.fluent_version import FluentVersion def _update_first_level(d, u): @@ -27,7 +28,8 @@ def generate(version: str, static_infos: dict): Path(api_tree_file).parent.mkdir(parents=True, exist_ok=True) with open(api_tree_file, "wb") as f: pickle.dump(api_tree, f) - builtin_settingsgen.generate(version) + if FluentVersion(version) == next(iter(FluentVersion)): + builtin_settingsgen.generate(version) if __name__ == "__main__": diff --git a/src/ansys/fluent/core/codegen/builtin_settingsgen.py b/src/ansys/fluent/core/codegen/builtin_settingsgen.py index 6232747f3c0..88975454a00 100644 --- a/src/ansys/fluent/core/codegen/builtin_settingsgen.py +++ b/src/ansys/fluent/core/codegen/builtin_settingsgen.py @@ -48,10 +48,7 @@ def generate(version: str): for name, v in DATA.items(): kind, path = v if kind == "NamedObject": - if isinstance(path, dict): - if FluentVersion(version) not in path: - continue - path = path[FluentVersion(version)] + path = path[FluentVersion(version)] if isinstance(path, dict) else path kind = f"{_get_named_object_type(root, path)}NamedObject" f.write(f"class {name}(_{kind}Setting):\n") f.write(f' """{name} setting."""\n\n') @@ -64,10 +61,6 @@ def generate(version: str): f.write("\n\n") for name, v in DATA.items(): kind, path = v - if isinstance(path, dict): - if FluentVersion(version) not in path: - continue - path = path[FluentVersion(version)] f.write(f"class {name}(\n") if isinstance(path, str): path = {v: path for v in FluentVersion} diff --git a/src/ansys/fluent/core/solver/settings_builtin_data.py b/src/ansys/fluent/core/solver/settings_builtin_data.py index 6870d3907f4..c5103c15047 100644 --- a/src/ansys/fluent/core/solver/settings_builtin_data.py +++ b/src/ansys/fluent/core/solver/settings_builtin_data.py @@ -254,19 +254,35 @@ "WallBoundary": ("NamedObject", "setup.boundary_conditions.wall"), "NonReflectingBoundaries": ( "Singleton", - "setup.boundary_conditions.non_reflecting_bc", + { + FluentVersion.v251: "setup.boundary_conditions.non_reflecting_bc", + FluentVersion.v242: "setup.boundary_conditions.non_reflecting_bc", + FluentVersion.v241: "setup.boundary_conditions.non_reflecting_bc", + }, ), "NonReflectingBoundary": ( "NamedObject", - "setup.boundary_conditions.non_reflecting_bc", + { + FluentVersion.v251: "setup.boundary_conditions.non_reflecting_bc", + FluentVersion.v242: "setup.boundary_conditions.non_reflecting_bc", + FluentVersion.v241: "setup.boundary_conditions.non_reflecting_bc", + }, ), "PerforatedWallBoundaries": ( "Singleton", - "setup.boundary_conditions.perforated_wall", + { + FluentVersion.v251: "setup.boundary_conditions.perforated_wall", + FluentVersion.v242: "setup.boundary_conditions.perforated_wall", + FluentVersion.v241: "setup.boundary_conditions.perforated_wall", + }, ), "PerforatedWallBoundary": ( "NamedObject", - "setup.boundary_conditions.perforated_wall", + { + FluentVersion.v251: "setup.boundary_conditions.perforated_wall", + FluentVersion.v242: "setup.boundary_conditions.perforated_wall", + FluentVersion.v241: "setup.boundary_conditions.perforated_wall", + }, ), "MeshInterfaces": ( "Singleton", @@ -318,21 +334,122 @@ "Methods": ("Singleton", "solution.methods"), "Controls": ("Singleton", "solution.controls"), "ReportDefinitions": ("Singleton", "solution.report_definitions"), - "Monitor": ("Singleton", "solution.monitor"), - "Residual": ("Singleton", "solution.monitor.residual"), - "ReportFiles": ("Singleton", "solution.monitor.report_files"), - "ReportFile": ("NamedObject", "solution.monitor.report_files"), - "ReportPlots": ("Singleton", "solution.monitor.report_plots"), - "ReportPlot": ("NamedObject", "solution.monitor.report_plots"), - "ConvergenceConditions": ("Singleton", "solution.monitor.convergence_conditions"), - "CellRegisters": ("Singleton", "solution.cell_registers"), - "CellRegister": ("NamedObject", "solution.cell_registers"), + "Monitor": ( + "Singleton", + { + FluentVersion.v251: "solution.monitor", + FluentVersion.v242: "solution.monitor", + FluentVersion.v241: "solution.monitor", + FluentVersion.v232: "solution.monitor", + FluentVersion.v231: "solution.monitor", + }, + ), + "Residual": ( + "Singleton", + { + FluentVersion.v251: "solution.monitor.residual", + FluentVersion.v242: "solution.monitor.residual", + FluentVersion.v241: "solution.monitor.residual", + }, + ), + "ReportFiles": ( + "Singleton", + { + FluentVersion.v251: "solution.monitor.report_files", + FluentVersion.v242: "solution.monitor.report_files", + FluentVersion.v241: "solution.monitor.report_files", + FluentVersion.v232: "solution.monitor.report_files", + FluentVersion.v231: "solution.monitor.report_files", + }, + ), + "ReportFile": ( + "NamedObject", + { + FluentVersion.v251: "solution.monitor.report_files", + FluentVersion.v242: "solution.monitor.report_files", + FluentVersion.v241: "solution.monitor.report_files", + FluentVersion.v232: "solution.monitor.report_files", + FluentVersion.v231: "solution.monitor.report_files", + }, + ), + "ReportPlots": ( + "Singleton", + { + FluentVersion.v251: "solution.monitor.report_plots", + FluentVersion.v242: "solution.monitor.report_plots", + FluentVersion.v241: "solution.monitor.report_plots", + FluentVersion.v232: "solution.monitor.report_plots", + FluentVersion.v231: "solution.monitor.report_plots", + }, + ), + "ReportPlot": ( + "NamedObject", + { + FluentVersion.v251: "solution.monitor.report_plots", + FluentVersion.v242: "solution.monitor.report_plots", + FluentVersion.v241: "solution.monitor.report_plots", + FluentVersion.v232: "solution.monitor.report_plots", + FluentVersion.v231: "solution.monitor.report_plots", + }, + ), + "ConvergenceConditions": ( + "Singleton", + { + FluentVersion.v251: "solution.monitor.convergence_conditions", + FluentVersion.v242: "solution.monitor.convergence_conditions", + FluentVersion.v241: "solution.monitor.convergence_conditions", + FluentVersion.v232: "solution.monitor.convergence_conditions", + FluentVersion.v231: "solution.monitor.convergence_conditions", + }, + ), + "CellRegisters": ( + "Singleton", + { + FluentVersion.v251: "solution.cell_registers", + FluentVersion.v242: "solution.cell_registers", + FluentVersion.v241: "solution.cell_registers", + FluentVersion.v232: "solution.cell_registers", + FluentVersion.v231: "solution.cell_registers", + }, + ), + "CellRegister": ( + "NamedObject", + { + FluentVersion.v251: "solution.cell_registers", + FluentVersion.v242: "solution.cell_registers", + FluentVersion.v241: "solution.cell_registers", + FluentVersion.v232: "solution.cell_registers", + FluentVersion.v231: "solution.cell_registers", + }, + ), "Initialization": ("Singleton", "solution.initialization"), - "CalculationActivity": ("Singleton", "solution.calculation_activity"), - "ExecuteCommands": ("Singleton", "solution.calculation_activity.execute_commands"), + "CalculationActivity": ( + "Singleton", + { + FluentVersion.v251: "solution.calculation_activity", + FluentVersion.v242: "solution.calculation_activity", + FluentVersion.v241: "solution.calculation_activity", + FluentVersion.v232: "solution.calculation_activity", + FluentVersion.v231: "solution.calculation_activity", + }, + ), + "ExecuteCommands": ( + "Singleton", + { + FluentVersion.v251: "solution.calculation_activity.execute_commands", + FluentVersion.v242: "solution.calculation_activity.execute_commands", + FluentVersion.v241: "solution.calculation_activity.execute_commands", + FluentVersion.v232: "solution.calculation_activity.execute_commands", + FluentVersion.v231: "solution.calculation_activity.execute_commands", + }, + ), "CaseModification": ( "Singleton", - "solution.calculation_activity.case_modification", + { + FluentVersion.v251: "solution.calculation_activity.case_modification", + FluentVersion.v242: "solution.calculation_activity.case_modification", + FluentVersion.v241: "solution.calculation_activity.case_modification", + }, ), "RunCalculation": ("Singleton", "solution.run_calculation"), } diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index 58aebe51999..a6098fb5851 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -505,14 +505,21 @@ def test_exit_not_in_settings(new_solver_session): def test_builtin_settings(static_mixer_case_session): from ansys.fluent.core import ( + Ablation, + Battery, + BoundaryCondition, BoundaryConditions, CalculationActivity, CaseModification, CellRegister, CellRegisters, + CellZoneCondition, CellZoneConditions, Controls, ConvergenceConditions, + DiscretePhase, + DynamicMesh, + EChemistry, Energy, ExecuteCommands, FluidCellZone, @@ -521,15 +528,23 @@ def test_builtin_settings(static_mixer_case_session): FluidMaterials, General, Initialization, + Injections, InteriorBoundaries, InteriorBoundary, Materials, + MeshInterfaces, Methods, Models, Monitor, Multiphase, + NamedExpressions, + Optics, + Pemfc, PressureOutlet, PressureOutlets, + Radiation, + ReferenceFrame, + ReferenceFrames, ReferenceValues, ReportDefinitions, ReportFile, @@ -539,10 +554,15 @@ def test_builtin_settings(static_mixer_case_session): Residual, RunCalculation, Setup, + Sofc, SolidMaterial, SolidMaterials, + Species, + Structure, + SystemCoupling, VelocityInlet, VelocityInlets, + VirtualBladeModel, Viscous, WallBoundaries, WallBoundary, @@ -556,100 +576,74 @@ def test_builtin_settings(static_mixer_case_session): assert Energy(solver=solver) == solver.setup.models.energy assert Viscous(solver=solver) == solver.setup.models.viscous if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import Radiation - assert Radiation(solver=solver) == solver.setup.models.radiation else: - with pytest.raises(ImportError): - from ansys.fluent.core import Radiation + with pytest.raises(RuntimeError): + Radiation(solver=solver) if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import Species - assert Species(solver=solver) == solver.setup.models.species else: - with pytest.raises(ImportError): - from ansys.fluent.core import Species + with pytest.raises(RuntimeError): + Species(solver=solver) if solver.get_fluent_version() >= FluentVersion.v231: - from ansys.fluent.core import DiscretePhase - assert DiscretePhase(solver=solver) == solver.setup.models.discrete_phase else: - with pytest.raises(ImportError): - from ansys.fluent.core import DiscretePhase + with pytest.raises(RuntimeError): + DiscretePhase(solver=solver) if solver.get_fluent_version() >= FluentVersion.v231: - from ansys.fluent.core import Injections - assert ( Injections(solver=solver) == solver.setup.models.discrete_phase.injections ) else: - with pytest.raises(ImportError): - from ansys.fluent.core import Injections + with pytest.raises(RuntimeError): + Injections(solver=solver) if solver.get_fluent_version() >= FluentVersion.v231: - from ansys.fluent.core import VirtualBladeModel - assert ( VirtualBladeModel(solver=solver) == solver.setup.models.virtual_blade_model ) else: - with pytest.raises(ImportError): - from ansys.fluent.core import VirtualBladeModel + with pytest.raises(RuntimeError): + VirtualBladeModel(solver=solver) if solver.get_fluent_version() >= FluentVersion.v231: - from ansys.fluent.core import Optics - assert Optics(solver=solver) == solver.setup.models.optics else: - with pytest.raises(ImportError): - from ansys.fluent.core import Optics + with pytest.raises(RuntimeError): + Optics(solver=solver) if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import Structure - assert Structure(solver=solver) == solver.setup.models.structure else: - with pytest.raises(ImportError): - from ansys.fluent.core import Structure + with pytest.raises(RuntimeError): + Structure(solver=solver) if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import Ablation - assert Ablation(solver=solver) == solver.setup.models.ablation else: - with pytest.raises(ImportError): - from ansys.fluent.core import Ablation + with pytest.raises(RuntimeError): + Ablation(solver=solver) if solver.get_fluent_version() >= FluentVersion.v241: - from ansys.fluent.core import EChemistry - assert EChemistry(solver=solver) == solver.setup.models.echemistry else: - with pytest.raises(ImportError): - from ansys.fluent.core import EChemistry + with pytest.raises(RuntimeError): + EChemistry(solver=solver) if solver.get_fluent_version() >= FluentVersion.v241: - from ansys.fluent.core import Battery - assert Battery(solver=solver) == solver.setup.models.battery else: - with pytest.raises(ImportError): - from ansys.fluent.core import Battery + with pytest.raises(RuntimeError): + Battery(solver=solver) if solver.get_fluent_version() >= FluentVersion.v241: - from ansys.fluent.core import SystemCoupling - assert SystemCoupling(solver=solver) == solver.setup.models.system_coupling else: - with pytest.raises(ImportError): - from ansys.fluent.core import SystemCoupling + with pytest.raises(RuntimeError): + SystemCoupling(solver=solver) if solver.get_fluent_version() >= FluentVersion.v241: - from ansys.fluent.core import Sofc - assert Sofc(solver=solver) == solver.setup.models.sofc else: - with pytest.raises(ImportError): - from ansys.fluent.core import Sofc + with pytest.raises(RuntimeError): + Sofc(solver=solver) if solver.get_fluent_version() >= FluentVersion.v242: - from ansys.fluent.core import Pemfc - assert Pemfc(solver=solver) == solver.setup.models.pemfc else: - with pytest.raises(ImportError): - from ansys.fluent.core import Pemfc + with pytest.raises(RuntimeError): + Pemfc(solver=solver) assert Materials(solver=solver) == solver.setup.materials assert FluidMaterials(solver=solver) == solver.setup.materials.fluid assert ( @@ -662,15 +656,13 @@ def test_builtin_settings(static_mixer_case_session): ) assert CellZoneConditions(solver=solver) == solver.setup.cell_zone_conditions if solver.get_fluent_version() >= FluentVersion.v231: - from ansys.fluent.core import CellZoneCondition - assert ( CellZoneCondition(solver=solver, name="fluid") == solver.setup.cell_zone_conditions["fluid"] ) else: - with pytest.raises(ImportError): - from ansys.fluent.core import CellZoneCondition + with pytest.raises(RuntimeError): + CellZoneCondition(solver=solver, name="fluid") assert FluidCellZones(solver=solver) == solver.setup.cell_zone_conditions.fluid assert ( FluidCellZone(solver=solver, name="fluid") @@ -678,15 +670,13 @@ def test_builtin_settings(static_mixer_case_session): ) assert BoundaryConditions(solver=solver) == solver.setup.boundary_conditions if solver.get_fluent_version() >= FluentVersion.v231: - from ansys.fluent.core import BoundaryCondition - assert ( BoundaryCondition(solver=solver, name="inlet2") == solver.setup.boundary_conditions["inlet2"] ) else: - with pytest.raises(ImportError): - from ansys.fluent.core import BoundaryCondition + with pytest.raises(RuntimeError): + BoundaryCondition(solver=solver, name="inlet2") assert ( VelocityInlets(solver=solver) == solver.setup.boundary_conditions.velocity_inlet ) @@ -717,30 +707,22 @@ def test_builtin_settings(static_mixer_case_session): with pytest.raises(TypeError): WallBoundary(solver=solver, new_instance_name="wall-1") if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import MeshInterfaces - assert MeshInterfaces(solver=solver) == solver.setup.mesh_interfaces else: - with pytest.raises(ImportError): - from ansys.fluent.core import MeshInterfaces + with pytest.raises(RuntimeError): + MeshInterfaces(solver=solver) if solver.get_fluent_version() >= FluentVersion.v251: - from ansys.fluent.core import DynamicMesh - assert DynamicMesh(solver=solver) == solver.setup.dynamic_mesh else: - with pytest.raises(ImportError): - from ansys.fluent.core import DynamicMesh + with pytest.raises(RuntimeError): + DynamicMesh(solver=solver) assert ReferenceValues(solver=solver) == solver.setup.reference_values if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import ReferenceFrames - assert ReferenceFrames(solver=solver) == solver.setup.reference_frames else: - with pytest.raises(ImportError): - from ansys.fluent.core import ReferenceFrames + with pytest.raises(RuntimeError): + ReferenceFrames(solver=solver) if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import ReferenceFrame - # Fluent 25.1 issue if solver.get_fluent_version() != FluentVersion.v251: assert ( @@ -748,70 +730,94 @@ def test_builtin_settings(static_mixer_case_session): == solver.setup.reference_frames["global"] ) else: - with pytest.raises(ImportError): - from ansys.fluent.core import ReferenceFrame + with pytest.raises(RuntimeError): + ReferenceFrame(solver=solver, name="global") if solver.get_fluent_version() >= FluentVersion.v232: - from ansys.fluent.core import NamedExpressions - assert NamedExpressions(solver=solver) == solver.setup.named_expressions else: - with pytest.raises(ImportError): - from ansys.fluent.core import NamedExpressions + with pytest.raises(RuntimeError): + NamedExpressions(solver=solver) assert Methods(solver=solver) == solver.solution.methods assert Controls(solver=solver) == solver.solution.controls assert ReportDefinitions(solver=solver) == solver.solution.report_definitions - assert Monitor(solver=solver) == solver.solution.monitor - assert Residual(solver=solver) == solver.solution.monitor.residual - assert ReportFiles(solver=solver) == solver.solution.monitor.report_files - assert ( - ReportFile(solver=solver, new_instance_name="report-file-1") - == solver.solution.monitor.report_files["report-file-1"] - ) - assert ( - ReportFile(solver=solver, name="report-file-1") - == solver.solution.monitor.report_files["report-file-1"] - ) - assert ( - ReportFile(solver=solver) - == solver.solution.monitor.report_files["report-file-2"] - ) - assert ReportPlots(solver=solver) == solver.solution.monitor.report_plots - assert ( - ReportPlot(solver=solver, new_instance_name="report-plot-1") - == solver.solution.monitor.report_plots["report-plot-1"] - ) - assert ( - ReportPlot(solver=solver, name="report-plot-1") - == solver.solution.monitor.report_plots["report-plot-1"] - ) - assert ( - ReportPlot(solver=solver) - == solver.solution.monitor.report_plots["report-plot-2"] - ) - assert ( - ConvergenceConditions(solver=solver) - == solver.solution.monitor.convergence_conditions - ) - assert CellRegisters(solver=solver) == solver.solution.cell_registers - assert ( - CellRegister(solver=solver, new_instance_name="cell_register_1") - == solver.solution.cell_registers["cell_register_1"] - ) - assert ( - CellRegister(solver=solver, name="cell_register_1") - == solver.solution.cell_registers["cell_register_1"] - ) - assert ( - CellRegister(solver=solver) == solver.solution.cell_registers["cell_register_2"] - ) + if solver.get_fluent_version() >= FluentVersion.v231: + assert Monitor(solver=solver) == solver.solution.monitor + if solver.get_fluent_version() >= FluentVersion.v241: + assert Residual(solver=solver) == solver.solution.monitor.residual + else: + with pytest.raises(RuntimeError): + Residual(solver=solver) + assert ReportFiles(solver=solver) == solver.solution.monitor.report_files + assert ( + ReportFile(solver=solver, new_instance_name="report-file-1") + == solver.solution.monitor.report_files["report-file-1"] + ) + assert ( + ReportFile(solver=solver, name="report-file-1") + == solver.solution.monitor.report_files["report-file-1"] + ) + if solver.get_fluent_version() >= FluentVersion.v251: + assert ( + ReportFile(solver=solver) + == solver.solution.monitor.report_files["report-file-2"] + ) + assert ReportPlots(solver=solver) == solver.solution.monitor.report_plots + assert ( + ReportPlot(solver=solver, new_instance_name="report-plot-1") + == solver.solution.monitor.report_plots["report-plot-1"] + ) + assert ( + ReportPlot(solver=solver, name="report-plot-1") + == solver.solution.monitor.report_plots["report-plot-1"] + ) + if solver.get_fluent_version() >= FluentVersion.v251: + assert ( + ReportPlot(solver=solver) + == solver.solution.monitor.report_plots["report-plot-2"] + ) + assert ( + ConvergenceConditions(solver=solver) + == solver.solution.monitor.convergence_conditions + ) + else: + with pytest.raises(RuntimeError): + Monitor(solver=solver) + if solver.get_fluent_version() >= FluentVersion.v231: + assert CellRegisters(solver=solver) == solver.solution.cell_registers + assert ( + CellRegister(solver=solver, new_instance_name="cell_register_1") + == solver.solution.cell_registers["cell_register_1"] + ) + assert ( + CellRegister(solver=solver, name="cell_register_1") + == solver.solution.cell_registers["cell_register_1"] + ) + if solver.get_fluent_version() >= FluentVersion.v251: + assert ( + CellRegister(solver=solver) + == solver.solution.cell_registers["cell_register_2"] + ) + else: + with pytest.raises(RuntimeError): + CellRegisters(solver=solver) assert Initialization(solver=solver) == solver.solution.initialization - assert CalculationActivity(solver=solver) == solver.solution.calculation_activity - assert ( - ExecuteCommands(solver=solver) - == solver.solution.calculation_activity.execute_commands - ) - assert ( - CaseModification(solver=solver) - == solver.solution.calculation_activity.case_modification - ) + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + CalculationActivity(solver=solver) == solver.solution.calculation_activity + ) + assert ( + ExecuteCommands(solver=solver) + == solver.solution.calculation_activity.execute_commands + ) + if solver.get_fluent_version() >= FluentVersion.v241: + assert ( + CaseModification(solver=solver) + == solver.solution.calculation_activity.case_modification + ) + else: + with pytest.raises(RuntimeError): + CaseModification(solver=solver) + else: + with pytest.raises(RuntimeError): + CalculationActivity(solver=solver) assert RunCalculation(solver=solver) == solver.solution.run_calculation From 46e13e5f4164da4964eb00965792947bc02fa0d4 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Sat, 21 Sep 2024 09:48:39 -0400 Subject: [PATCH 5/6] feat: fix tests --- src/ansys/fluent/core/codegen/__init__.py | 3 +++ src/ansys/fluent/core/codegen/allapigen.py | 5 ++++- src/ansys/fluent/core/codegen/builtin_settingsgen.py | 1 + src/ansys/fluent/core/codegen/tuigen.py | 7 ++++++- tests/conftest.py | 2 ++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ansys/fluent/core/codegen/__init__.py b/src/ansys/fluent/core/codegen/__init__.py index 2dc876be6bf..75c74a2c028 100644 --- a/src/ansys/fluent/core/codegen/__init__.py +++ b/src/ansys/fluent/core/codegen/__init__.py @@ -18,3 +18,6 @@ class StaticInfoType(Enum): DATAMODEL_SOLVER_WORKFLOW = auto() DATAMODEL_MESHING_UTILITIES = auto() SETTINGS = auto() + + +CODEGEN_GENERATE_BUILTIN_SETTINGS = True diff --git a/src/ansys/fluent/core/codegen/allapigen.py b/src/ansys/fluent/core/codegen/allapigen.py index 3c1fbcd3bc6..2b78bb51eef 100644 --- a/src/ansys/fluent/core/codegen/allapigen.py +++ b/src/ansys/fluent/core/codegen/allapigen.py @@ -3,6 +3,7 @@ from pathlib import Path import pickle +from ansys.fluent.core import codegen from ansys.fluent.core.codegen import ( builtin_settingsgen, datamodelgen, @@ -28,7 +29,9 @@ def generate(version: str, static_infos: dict): Path(api_tree_file).parent.mkdir(parents=True, exist_ok=True) with open(api_tree_file, "wb") as f: pickle.dump(api_tree, f) - if FluentVersion(version) == next(iter(FluentVersion)): + if codegen.CODEGEN_GENERATE_BUILTIN_SETTINGS and FluentVersion(version) == next( + iter(FluentVersion) + ): builtin_settingsgen.generate(version) diff --git a/src/ansys/fluent/core/codegen/builtin_settingsgen.py b/src/ansys/fluent/core/codegen/builtin_settingsgen.py index 88975454a00..7ab5976222a 100644 --- a/src/ansys/fluent/core/codegen/builtin_settingsgen.py +++ b/src/ansys/fluent/core/codegen/builtin_settingsgen.py @@ -34,6 +34,7 @@ def _get_named_object_type(root, path): def generate(version: str): """Generate builtin setting classes.""" + print("Generating builtin settings...") CODEGEN_OUTDIR.mkdir(exist_ok=True) root = _get_settings_root(version) with open(_PY_FILE, "w") as f: diff --git a/src/ansys/fluent/core/codegen/tuigen.py b/src/ansys/fluent/core/codegen/tuigen.py index 6e9ab2e1614..ad0efdc94bd 100644 --- a/src/ansys/fluent/core/codegen/tuigen.py +++ b/src/ansys/fluent/core/codegen/tuigen.py @@ -132,7 +132,7 @@ def _populate_xml_helpstrings(): else: v = "".join(node.find("p").itertext()) _XML_HELPSTRINGS[k] = v - _XML_HELP_FILE.unlink() + _XML_HELP_FILE.unlink(missing_ok=True) def _is_valid_tui_menu_name(name): @@ -301,6 +301,11 @@ def generate(self) -> None: def generate(version, static_infos: dict): """Generate TUI API classes.""" api_tree = {} + if ( + StaticInfoType.TUI_MESHING not in static_infos + and StaticInfoType.TUI_SOLVER not in static_infos + ): + return api_tree gt_222 = FluentVersion(version) > FluentVersion.v222 if gt_222: _copy_tui_help_xml_file(version) diff --git a/tests/conftest.py b/tests/conftest.py index 97515f69f7c..c1baafbebd8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ import pytest import ansys.fluent.core as pyfluent +from ansys.fluent.core import codegen from ansys.fluent.core.examples.downloads import download_file from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy from ansys.fluent.core.utils.fluent_version import FluentVersion @@ -73,6 +74,7 @@ def run_before_each_test( monkeypatch.setenv("PYFLUENT_TEST_NAME", request.node.name) pyfluent.CONTAINER_MOUNT_SOURCE = pyfluent.EXAMPLES_PATH pyfluent.CONTAINER_MOUNT_TARGET = pyfluent.EXAMPLES_PATH + codegen.CODEGEN_GENERATE_BUILTIN_SETTINGS = False class Helpers: From faee60037476d1acd4724303669879efd5f877b4 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Mon, 23 Sep 2024 07:16:02 -0400 Subject: [PATCH 6/6] feat: fix tests --- src/ansys/fluent/core/codegen/tuigen.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ansys/fluent/core/codegen/tuigen.py b/src/ansys/fluent/core/codegen/tuigen.py index ad0efdc94bd..d4a47a2c030 100644 --- a/src/ansys/fluent/core/codegen/tuigen.py +++ b/src/ansys/fluent/core/codegen/tuigen.py @@ -301,13 +301,13 @@ def generate(self) -> None: def generate(version, static_infos: dict): """Generate TUI API classes.""" api_tree = {} - if ( - StaticInfoType.TUI_MESHING not in static_infos - and StaticInfoType.TUI_SOLVER not in static_infos - ): - return api_tree gt_222 = FluentVersion(version) > FluentVersion.v222 if gt_222: + if ( + StaticInfoType.TUI_MESHING not in static_infos + and StaticInfoType.TUI_SOLVER not in static_infos + ): + return api_tree _copy_tui_help_xml_file(version) _populate_xml_helpstrings() if not gt_222 or StaticInfoType.TUI_MESHING in static_infos: