From 2c9216ef6d75bf4f34d399a256609b25cc39a0e0 Mon Sep 17 00:00:00 2001 From: Prithwish Mukherjee <109645853+prmukherj@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:04:14 +0530 Subject: [PATCH 1/2] refactor: Remove 'exit' from tui. (#3318) * refactor: Remove 'exit' from tui. * Update test. * Update logic. * Update logic. --- .../fluent/core/services/datamodel_tui.py | 5 +++++ tests/test_tui_api.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ansys/fluent/core/services/datamodel_tui.py b/src/ansys/fluent/core/services/datamodel_tui.py index c22285473fb..979d8192207 100644 --- a/src/ansys/fluent/core/services/datamodel_tui.py +++ b/src/ansys/fluent/core/services/datamodel_tui.py @@ -330,9 +330,14 @@ def __dir__(self) -> list[str]: for x in PyMenu( self._service, self._version, self._mode, self._path ).get_child_names() + if x != "exit" ] def __getattribute__(self, name) -> Any: + if name == "exit" and not self._path: + raise AttributeError( + f"'{self.__class__.__name__}' object has no attribute 'exit'" + ) try: attr = super().__getattribute__(name) if isinstance(attr, TUIMethod): diff --git a/tests/test_tui_api.py b/tests/test_tui_api.py index 9d01c3a4574..193f85c00cd 100644 --- a/tests/test_tui_api.py +++ b/tests/test_tui_api.py @@ -50,3 +50,21 @@ def test_api_upgrade_message(new_solver_session): ) else: assert s.split("\n")[-2].split("(")[0] == r".file.read_case" + + +def test_exit_not_in_meshing_tui(new_meshing_session): + meshing = new_meshing_session + + assert "exit" not in dir(meshing.tui) + + with pytest.raises(AttributeError): + meshing.tui.exit() + + +def test_exit_not_in_solver_tui(new_solver_session): + solver = new_solver_session + + assert "exit" not in dir(solver.tui) + + with pytest.raises(AttributeError): + solver.tui.exit() From fe5937deb8e2276b396dd5b2f4e581e6a032379a Mon Sep 17 00:00:00 2001 From: Mainak Kundu <94432368+mkundu1@users.noreply.github.com> Date: Thu, 26 Sep 2024 08:07:17 -0400 Subject: [PATCH 2/2] feat: Support delayed settings_source assignment for built-in settings objects (#3315) * feat: Support delayed session assignment for builtin objects * feat: fix tests * feat: Can assign either settings root or solver session object * feat: fix test --- src/ansys/fluent/core/solver/flobject.py | 3 + .../core/solver/settings_builtin_bases.py | 137 ++++-- tests/test_builtin_settings.py | 449 ++++++++++++++++++ tests/test_settings_api.py | 320 ------------- 4 files changed, 554 insertions(+), 355 deletions(-) create mode 100644 tests/test_builtin_settings.py diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 4615ece56b4..47fb9987922 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -437,6 +437,9 @@ def _while_executing_command(self): """Avoid additional processing while executing a command.""" return nullcontext() + def __eq__(self, other): + return self.flproxy == other.flproxy and self.path == other.path + StateT = TypeVar("StateT") diff --git a/src/ansys/fluent/core/solver/settings_builtin_bases.py b/src/ansys/fluent/core/solver/settings_builtin_bases.py index 9ba275a37ca..d04fa122cf7 100644 --- a/src/ansys/fluent/core/solver/settings_builtin_bases.py +++ b/src/ansys/fluent/core/solver/settings_builtin_bases.py @@ -1,46 +1,113 @@ """Base classes for builtin setting classes.""" -from typing import Optional +from typing import Protocol, runtime_checkable -from ansys.fluent.core.session_solver import Solver +from ansys.fluent.core.solver.flobject import SettingsBase from ansys.fluent.core.solver.settings_builtin_data import DATA +from ansys.fluent.core.utils.fluent_version import FluentVersion + + +@runtime_checkable +class Solver(Protocol): + """Solver session class for type hinting.""" + + settings: SettingsBase + + +def _get_settings_root(settings_source: SettingsBase | Solver): + def is_root_obj(obj): + return isinstance(obj, SettingsBase) and obj.parent is None + + if is_root_obj(settings_source): + return settings_source + elif isinstance(settings_source, Solver) and is_root_obj(settings_source.settings): + return settings_source.settings + else: + raise TypeError( + f"{settings_source} is not a Settings root or a Solver session object." + ) + + +def _get_settings_obj(settings_source: SettingsBase | Solver, cls_name: str): + obj = _get_settings_root(settings_source) + path = DATA[cls_name][1] + if isinstance(path, dict): + version = FluentVersion(obj.version) + path = path.get(version) + if path is None: + raise RuntimeError( + f"{cls_name} is not supported in Fluent version {version}." + ) + for comp in path.split("."): + obj = SettingsBase.__getattribute__(obj, comp) # bypass InactiveObjectError + return obj class _SingletonSetting: - def __new__(cls, solver: Solver): - obj = solver.settings - path = DATA[cls.__name__][1] - if isinstance(path, dict): - version = solver.get_fluent_version() - path = path.get(version) - if path is None: - raise RuntimeError( - f"{cls.__name__} is not supported in Fluent version {version}." - ) - for comp in path.split("."): - obj = getattr(obj, comp) - return obj - - -class _CreatableNamedObjectSetting(_SingletonSetting): - def __new__( - cls, - solver: Solver, - name: Optional[str] = None, - new_instance_name: Optional[str] = None, + def __init__(self, settings_source: SettingsBase | Solver | None = None): + self.__dict__.update(dict(settings_source=None)) + if settings_source is not None: + self.settings_source = settings_source + + def __setattr__(self, name, value): + if name == "settings_source": + obj = _get_settings_obj(value, self.__class__.__name__) + self.__class__ = obj.__class__ + self.__dict__.clear() + self.__dict__.update( + obj.__dict__ | dict(settings_source=_get_settings_root(value)) + ) + else: + super().__setattr__(name, value) + + +class _NonCreatableNamedObjectSetting: + def __init__(self, name: str, settings_source: SettingsBase | Solver | None = None): + self.__dict__.update(dict(settings_source=None, name=name)) + if settings_source is not None: + self.settings_source = settings_source + + def __setattr__(self, name, value): + if name == "settings_source": + obj = _get_settings_obj(value, self.__class__.__name__) + obj = obj[self.name] + self.__class__ = obj.__class__ + self.__dict__.clear() + self.__dict__.update( + obj.__dict__ | dict(settings_source=_get_settings_root(value)) + ) + else: + super().__setattr__(name, value) + + +class _CreatableNamedObjectSetting: + def __init__( + self, + settings_source: SettingsBase | Solver | None = None, + name: str | None = None, + new_instance_name: str | None = 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() + self.__dict__.update( + dict(settings_source=None, name=name, new_instance_name=new_instance_name) + ) + if settings_source is not None: + self.settings_source = settings_source - -class _NonCreatableNamedObjectSetting(_SingletonSetting): - def __new__(cls, solver: Solver, name: str): - obj = super().__new__(cls, solver) - return obj[name] + def __setattr__(self, name, value): + if name == "settings_source": + obj = _get_settings_obj(value, self.__class__.__name__) + if self.name: + obj = obj[self.name] + elif self.new_instance_name: + obj = obj.create(self.new_instance_name) + else: + obj = obj.create() + self.__class__ = obj.__class__ + self.__dict__.clear() + self.__dict__.update( + obj.__dict__ | dict(settings_source=_get_settings_root(value)) + ) + else: + super().__setattr__(name, value) diff --git a/tests/test_builtin_settings.py b/tests/test_builtin_settings.py new file mode 100644 index 00000000000..d37a63a89db --- /dev/null +++ b/tests/test_builtin_settings.py @@ -0,0 +1,449 @@ +import pytest + +from ansys.fluent.core import ( + Ablation, + 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, + Pemfc, + PressureOutlet, + PressureOutlets, + Radiation, + ReferenceFrame, + ReferenceFrames, + ReferenceValues, + ReportDefinitions, + ReportFile, + ReportFiles, + ReportPlot, + ReportPlots, + Residual, + RunCalculation, + Setup, + Sofc, + SolidMaterial, + SolidMaterials, + Species, + Structure, + SystemCoupling, + VelocityInlet, + VelocityInlets, + VirtualBladeModel, + Viscous, + WallBoundaries, + WallBoundary, +) +from ansys.fluent.core.examples import download_file +from ansys.fluent.core.utils.fluent_version import FluentVersion + + +def test_builtin_settings(static_mixer_case_session): + solver = static_mixer_case_session + assert Setup(settings_source=solver) == solver.setup + assert General(settings_source=solver) == solver.setup.general + assert Models(settings_source=solver) == solver.setup.models + assert Multiphase(settings_source=solver) == solver.setup.models.multiphase + assert Energy(settings_source=solver) == solver.setup.models.energy + assert Viscous(settings_source=solver) == solver.setup.models.viscous + if solver.get_fluent_version() >= FluentVersion.v232: + assert Radiation(settings_source=solver) == solver.setup.models.radiation + else: + with pytest.raises(RuntimeError): + Radiation(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v232: + assert Species(settings_source=solver) == solver.setup.models.species + else: + with pytest.raises(RuntimeError): + Species(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + DiscretePhase(settings_source=solver) == solver.setup.models.discrete_phase + ) + else: + with pytest.raises(RuntimeError): + DiscretePhase(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + Injections(settings_source=solver) + == solver.setup.models.discrete_phase.injections + ) + else: + with pytest.raises(RuntimeError): + Injections(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + VirtualBladeModel(settings_source=solver) + == solver.setup.models.virtual_blade_model + ) + else: + with pytest.raises(RuntimeError): + VirtualBladeModel(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v231: + assert Optics(settings_source=solver) == solver.setup.models.optics + else: + with pytest.raises(RuntimeError): + Optics(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v232: + assert Structure(settings_source=solver) == solver.setup.models.structure + else: + with pytest.raises(RuntimeError): + Structure(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v232: + assert Ablation(settings_source=solver) == solver.setup.models.ablation + else: + with pytest.raises(RuntimeError): + Ablation(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v241: + assert EChemistry(settings_source=solver) == solver.setup.models.echemistry + else: + with pytest.raises(RuntimeError): + EChemistry(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v241: + assert Battery(settings_source=solver) == solver.setup.models.battery + else: + with pytest.raises(RuntimeError): + Battery(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v241: + assert ( + SystemCoupling(settings_source=solver) + == solver.setup.models.system_coupling + ) + else: + with pytest.raises(RuntimeError): + SystemCoupling(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v241: + assert Sofc(settings_source=solver) == solver.setup.models.sofc + else: + with pytest.raises(RuntimeError): + Sofc(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v242: + assert Pemfc(settings_source=solver) == solver.setup.models.pemfc + else: + with pytest.raises(RuntimeError): + Pemfc(settings_source=solver) + assert Materials(settings_source=solver) == solver.setup.materials + assert FluidMaterials(settings_source=solver) == solver.setup.materials.fluid + assert ( + FluidMaterial(settings_source=solver, name="air") + == solver.setup.materials.fluid["air"] + ) + assert SolidMaterials(settings_source=solver) == solver.setup.materials.solid + assert ( + SolidMaterial(settings_source=solver, name="aluminum") + == solver.setup.materials.solid["aluminum"] + ) + assert ( + CellZoneConditions(settings_source=solver) == solver.setup.cell_zone_conditions + ) + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + CellZoneCondition(settings_source=solver, name="fluid") + == solver.setup.cell_zone_conditions["fluid"] + ) + else: + with pytest.raises(RuntimeError): + CellZoneCondition(settings_source=solver, name="fluid") + assert ( + FluidCellZones(settings_source=solver) + == solver.setup.cell_zone_conditions.fluid + ) + assert ( + FluidCellZone(settings_source=solver, name="fluid") + == solver.setup.cell_zone_conditions.fluid["fluid"] + ) + assert ( + BoundaryConditions(settings_source=solver) == solver.setup.boundary_conditions + ) + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + BoundaryCondition(settings_source=solver, name="inlet2") + == solver.setup.boundary_conditions["inlet2"] + ) + else: + with pytest.raises(RuntimeError): + BoundaryCondition(settings_source=solver, name="inlet2") + assert ( + VelocityInlets(settings_source=solver) + == solver.setup.boundary_conditions.velocity_inlet + ) + assert ( + VelocityInlet(settings_source=solver, name="inlet2") + == solver.setup.boundary_conditions.velocity_inlet["inlet2"] + ) + assert ( + InteriorBoundaries(settings_source=solver) + == solver.setup.boundary_conditions.interior + ) + assert ( + InteriorBoundary(settings_source=solver, name="interior--fluid") + == solver.setup.boundary_conditions.interior["interior--fluid"] + ) + assert ( + PressureOutlets(settings_source=solver) + == solver.setup.boundary_conditions.pressure_outlet + ) + assert ( + PressureOutlet(settings_source=solver, name="outlet") + == solver.setup.boundary_conditions.pressure_outlet["outlet"] + ) + assert ( + WallBoundaries(settings_source=solver) == solver.setup.boundary_conditions.wall + ) + assert ( + WallBoundary(settings_source=solver, name="wall") + == solver.setup.boundary_conditions.wall["wall"] + ) + with pytest.raises(TypeError): + WallBoundary(settings_source=solver, new_instance_name="wall-1") + if solver.get_fluent_version() >= FluentVersion.v232: + assert MeshInterfaces(settings_source=solver) == solver.setup.mesh_interfaces + else: + with pytest.raises(RuntimeError): + MeshInterfaces(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v251: + assert DynamicMesh(settings_source=solver) == solver.setup.dynamic_mesh + else: + with pytest.raises(RuntimeError): + DynamicMesh(settings_source=solver) + assert ReferenceValues(settings_source=solver) == solver.setup.reference_values + if solver.get_fluent_version() >= FluentVersion.v232: + assert ReferenceFrames(settings_source=solver) == solver.setup.reference_frames + else: + with pytest.raises(RuntimeError): + ReferenceFrames(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v232: + # Fluent 25.1 issue + if solver.get_fluent_version() != FluentVersion.v251: + assert ( + ReferenceFrame(settings_source=solver, name="global") + == solver.setup.reference_frames["global"] + ) + else: + with pytest.raises(RuntimeError): + ReferenceFrame(settings_source=solver, name="global") + if solver.get_fluent_version() >= FluentVersion.v232: + assert ( + NamedExpressions(settings_source=solver) == solver.setup.named_expressions + ) + else: + with pytest.raises(RuntimeError): + NamedExpressions(settings_source=solver) + assert Methods(settings_source=solver) == solver.solution.methods + assert Controls(settings_source=solver) == solver.solution.controls + assert ( + ReportDefinitions(settings_source=solver) == solver.solution.report_definitions + ) + if solver.get_fluent_version() >= FluentVersion.v231: + assert Monitor(settings_source=solver) == solver.solution.monitor + if solver.get_fluent_version() >= FluentVersion.v241: + assert Residual(settings_source=solver) == solver.solution.monitor.residual + else: + with pytest.raises(RuntimeError): + Residual(settings_source=solver) + assert ( + ReportFiles(settings_source=solver) == solver.solution.monitor.report_files + ) + assert ( + ReportFile(settings_source=solver, new_instance_name="report-file-1") + == solver.solution.monitor.report_files["report-file-1"] + ) + assert ( + ReportFile(settings_source=solver, name="report-file-1") + == solver.solution.monitor.report_files["report-file-1"] + ) + if solver.get_fluent_version() >= FluentVersion.v251: + assert ( + ReportFile(settings_source=solver) + == solver.solution.monitor.report_files["report-file-2"] + ) + assert ( + ReportPlots(settings_source=solver) == solver.solution.monitor.report_plots + ) + assert ( + ReportPlot(settings_source=solver, new_instance_name="report-plot-1") + == solver.solution.monitor.report_plots["report-plot-1"] + ) + assert ( + ReportPlot(settings_source=solver, name="report-plot-1") + == solver.solution.monitor.report_plots["report-plot-1"] + ) + if solver.get_fluent_version() >= FluentVersion.v251: + assert ( + ReportPlot(settings_source=solver) + == solver.solution.monitor.report_plots["report-plot-2"] + ) + assert ( + ConvergenceConditions(settings_source=solver) + == solver.solution.monitor.convergence_conditions + ) + else: + with pytest.raises(RuntimeError): + Monitor(settings_source=solver) + if solver.get_fluent_version() >= FluentVersion.v231: + assert CellRegisters(settings_source=solver) == solver.solution.cell_registers + assert ( + CellRegister(settings_source=solver, new_instance_name="cell_register_1") + == solver.solution.cell_registers["cell_register_1"] + ) + assert ( + CellRegister(settings_source=solver, name="cell_register_1") + == solver.solution.cell_registers["cell_register_1"] + ) + if solver.get_fluent_version() >= FluentVersion.v251: + assert ( + CellRegister(settings_source=solver) + == solver.solution.cell_registers["cell_register_2"] + ) + else: + with pytest.raises(RuntimeError): + CellRegisters(settings_source=solver) + assert Initialization(settings_source=solver) == solver.solution.initialization + if solver.get_fluent_version() >= FluentVersion.v231: + assert ( + CalculationActivity(settings_source=solver) + == solver.solution.calculation_activity + ) + assert ( + ExecuteCommands(settings_source=solver) + == solver.solution.calculation_activity.execute_commands + ) + if solver.get_fluent_version() >= FluentVersion.v241: + assert ( + CaseModification(settings_source=solver) + == solver.solution.calculation_activity.case_modification + ) + else: + with pytest.raises(RuntimeError): + CaseModification(settings_source=solver) + else: + with pytest.raises(RuntimeError): + CalculationActivity(settings_source=solver) + assert RunCalculation(settings_source=solver) == solver.solution.run_calculation + + +@pytest.mark.fluent_version(">=23.2") +def test_builtin_singleton_setting_assign_session( + new_meshing_session, new_solver_session +): + meshing = new_meshing_session + solver = new_solver_session + + models = Models() + assert isinstance(models, Models) + with pytest.raises(TypeError): + models.settings_source = meshing + models.settings_source = solver + assert models.settings_source == solver.settings + assert not isinstance(models, Models) + assert models.path == "setup/models" + assert not models.is_active() + case_name = download_file("Static_Mixer_main.cas.h5", "pyfluent/static_mixer") + solver.file.read( + file_type="case", + file_name=case_name, + lightweight_setup=True, + ) + assert models.is_active() + assert models == solver.setup.models + # TODO: Ideally an AttributeError should be raised here from flobject.py + with pytest.raises(RuntimeError): # re-assignment is not allowed + models.settings_source = solver + + models = Models() + assert isinstance(models, Models) + models.settings_source = solver.settings + assert models == solver.setup.models + assert models.settings_source == solver.settings + + +@pytest.mark.fluent_version(">=23.2") +def test_builtin_non_creatable_named_object_setting_assign_session( + new_meshing_session, static_mixer_case_session +): + meshing = new_meshing_session + solver = static_mixer_case_session + + inlet = BoundaryCondition(name="inlet1") + assert isinstance(inlet, BoundaryCondition) + with pytest.raises(TypeError): + inlet.settings_source = meshing + inlet.settings_source = solver + assert inlet == solver.settings.setup.boundary_conditions["inlet1"] + assert inlet.settings_source == solver.settings + # TODO: Ideally an AttributeError should be raised here from flobject.py + with pytest.raises(RuntimeError): # re-assignment is not allowed + inlet.settings_source = solver + + inlet = BoundaryCondition(name="inlet1") + assert isinstance(inlet, BoundaryCondition) + inlet.settings_source = solver.settings + assert inlet == solver.settings.setup.boundary_conditions["inlet1"] + assert inlet.settings_source == solver.settings + + +@pytest.mark.fluent_version(">=23.2") +def test_builtin_creatable_named_object_setting_assign_session( + new_meshing_session, static_mixer_case_session +): + meshing = new_meshing_session + solver = static_mixer_case_session + + report_file = ReportFile(new_instance_name="report-file-1") + assert isinstance(report_file, ReportFile) + with pytest.raises(TypeError): + report_file.settings_source = meshing + report_file.settings_source = solver + assert report_file == solver.solution.monitor.report_files["report-file-1"] + assert report_file.settings_source == solver.settings + # TODO: Ideally an AttributeError should be raised here from flobject.py + with pytest.raises(RuntimeError): # re-assignment is not allowed + report_file.settings_source = solver + + report_file = ReportFile(name="report-file-1") + assert isinstance(report_file, ReportFile) + report_file.settings_source = solver + assert report_file == solver.solution.monitor.report_files["report-file-1"] + assert report_file.settings_source == solver.settings + + report_file = ReportFile(name="report-file-1") + assert isinstance(report_file, ReportFile) + report_file.settings_source = solver.settings + assert report_file == solver.solution.monitor.report_files["report-file-1"] + assert report_file.settings_source == solver.settings + + if solver.get_fluent_version() >= FluentVersion.v251: + report_file = ReportFile() + assert isinstance(report_file, ReportFile) + report_file.settings_source = solver + assert report_file == solver.solution.monitor.report_files["report-file-2"] + assert report_file.settings_source == solver.settings diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index c8dcccdbfba..5fb85790d7d 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -519,323 +519,3 @@ def test_exit_not_in_settings(new_solver_session): with pytest.raises(AttributeError): solver.settings.exit() - - -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, - FluidCellZones, - FluidMaterial, - FluidMaterials, - General, - Initialization, - Injections, - InteriorBoundaries, - InteriorBoundary, - Materials, - MeshInterfaces, - Methods, - Models, - Monitor, - Multiphase, - NamedExpressions, - Optics, - Pemfc, - PressureOutlet, - PressureOutlets, - Radiation, - ReferenceFrame, - ReferenceFrames, - ReferenceValues, - ReportDefinitions, - ReportFile, - ReportFiles, - ReportPlot, - ReportPlots, - Residual, - RunCalculation, - Setup, - Sofc, - SolidMaterial, - SolidMaterials, - Species, - Structure, - SystemCoupling, - VelocityInlet, - VelocityInlets, - VirtualBladeModel, - Viscous, - WallBoundaries, - WallBoundary, - ) - - solver = static_mixer_case_session - assert Setup(solver=solver) == solver.setup - assert General(solver=solver) == solver.setup.general - assert Models(solver=solver) == solver.setup.models - assert Multiphase(solver=solver) == solver.setup.models.multiphase - assert Energy(solver=solver) == solver.setup.models.energy - assert Viscous(solver=solver) == solver.setup.models.viscous - if solver.get_fluent_version() >= FluentVersion.v232: - assert Radiation(solver=solver) == solver.setup.models.radiation - else: - with pytest.raises(RuntimeError): - Radiation(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v232: - assert Species(solver=solver) == solver.setup.models.species - else: - with pytest.raises(RuntimeError): - Species(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v231: - assert DiscretePhase(solver=solver) == solver.setup.models.discrete_phase - else: - with pytest.raises(RuntimeError): - DiscretePhase(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v231: - assert ( - Injections(solver=solver) == solver.setup.models.discrete_phase.injections - ) - else: - with pytest.raises(RuntimeError): - Injections(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v231: - assert ( - VirtualBladeModel(solver=solver) == solver.setup.models.virtual_blade_model - ) - else: - with pytest.raises(RuntimeError): - VirtualBladeModel(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v231: - assert Optics(solver=solver) == solver.setup.models.optics - else: - with pytest.raises(RuntimeError): - Optics(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v232: - assert Structure(solver=solver) == solver.setup.models.structure - else: - with pytest.raises(RuntimeError): - Structure(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v232: - assert Ablation(solver=solver) == solver.setup.models.ablation - else: - with pytest.raises(RuntimeError): - Ablation(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v241: - assert EChemistry(solver=solver) == solver.setup.models.echemistry - else: - with pytest.raises(RuntimeError): - EChemistry(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v241: - assert Battery(solver=solver) == solver.setup.models.battery - else: - with pytest.raises(RuntimeError): - Battery(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v241: - assert SystemCoupling(solver=solver) == solver.setup.models.system_coupling - else: - with pytest.raises(RuntimeError): - SystemCoupling(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v241: - assert Sofc(solver=solver) == solver.setup.models.sofc - else: - with pytest.raises(RuntimeError): - Sofc(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v242: - assert Pemfc(solver=solver) == solver.setup.models.pemfc - else: - with pytest.raises(RuntimeError): - Pemfc(solver=solver) - assert Materials(solver=solver) == solver.setup.materials - assert FluidMaterials(solver=solver) == solver.setup.materials.fluid - assert ( - FluidMaterial(solver=solver, name="air") == solver.setup.materials.fluid["air"] - ) - assert SolidMaterials(solver=solver) == solver.setup.materials.solid - assert ( - SolidMaterial(solver=solver, name="aluminum") - == solver.setup.materials.solid["aluminum"] - ) - assert CellZoneConditions(solver=solver) == solver.setup.cell_zone_conditions - if solver.get_fluent_version() >= FluentVersion.v231: - assert ( - CellZoneCondition(solver=solver, name="fluid") - == solver.setup.cell_zone_conditions["fluid"] - ) - else: - 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") - == solver.setup.cell_zone_conditions.fluid["fluid"] - ) - assert BoundaryConditions(solver=solver) == solver.setup.boundary_conditions - if solver.get_fluent_version() >= FluentVersion.v231: - assert ( - BoundaryCondition(solver=solver, name="inlet2") - == solver.setup.boundary_conditions["inlet2"] - ) - else: - with pytest.raises(RuntimeError): - BoundaryCondition(solver=solver, name="inlet2") - assert ( - VelocityInlets(solver=solver) == solver.setup.boundary_conditions.velocity_inlet - ) - assert ( - VelocityInlet(solver=solver, name="inlet2") - == solver.setup.boundary_conditions.velocity_inlet["inlet2"] - ) - assert ( - InteriorBoundaries(solver=solver) == solver.setup.boundary_conditions.interior - ) - assert ( - InteriorBoundary(solver=solver, name="interior--fluid") - == solver.setup.boundary_conditions.interior["interior--fluid"] - ) - assert ( - PressureOutlets(solver=solver) - == solver.setup.boundary_conditions.pressure_outlet - ) - assert ( - PressureOutlet(solver=solver, name="outlet") - == solver.setup.boundary_conditions.pressure_outlet["outlet"] - ) - assert WallBoundaries(solver=solver) == solver.setup.boundary_conditions.wall - assert ( - 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: - with pytest.raises(RuntimeError): - MeshInterfaces(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v251: - assert DynamicMesh(solver=solver) == solver.setup.dynamic_mesh - else: - with pytest.raises(RuntimeError): - DynamicMesh(solver=solver) - assert ReferenceValues(solver=solver) == solver.setup.reference_values - if solver.get_fluent_version() >= FluentVersion.v232: - assert ReferenceFrames(solver=solver) == solver.setup.reference_frames - else: - with pytest.raises(RuntimeError): - ReferenceFrames(solver=solver) - if solver.get_fluent_version() >= FluentVersion.v232: - # Fluent 25.1 issue - if solver.get_fluent_version() != FluentVersion.v251: - assert ( - ReferenceFrame(solver=solver, name="global") - == solver.setup.reference_frames["global"] - ) - else: - with pytest.raises(RuntimeError): - ReferenceFrame(solver=solver, name="global") - if solver.get_fluent_version() >= FluentVersion.v232: - assert NamedExpressions(solver=solver) == solver.setup.named_expressions - 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 - 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 - 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