Skip to content

Commit

Permalink
fix: update enhanced meshing interface (#2563)
Browse files Browse the repository at this point in the history
* refactor: Update enhanced meshing workflow interface.

* Add tests.

* Update src/ansys/fluent/core/workflow.py

Co-authored-by: Mainak Kundu <[email protected]>

* More fixes.

* Refactor.

* Refactor.

* Add tests.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update test marker.

---------

Co-authored-by: Mainak Kundu <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent d811ffd commit 870699a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ansys/fluent/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,15 @@ def _refresh_task_accessors(obj):
def _convert_task_list_to_display_names(workflow_root, task_list):
if pyfluent.DATAMODEL_USE_STATE_CACHE:
workflow_state = DataModelCache.get_state("workflow", workflow_root)
return [workflow_state[f"TaskObject:{x}"]["_name_"] for x in task_list]
else:
workflow_state = workflow_root.get_remote_state()
return [workflow_state[f"TaskObject:{x}"]["_name_"] for x in task_list]
_display_names = []
_org_path = workflow_root.path
for _task_name in task_list:
workflow_root.path = [("TaskObject", _task_name), ("_name_", "")]
_display_names.append(workflow_root())
workflow_root.path = _org_path
return _display_names


class BaseTask:
Expand Down Expand Up @@ -458,6 +464,9 @@ def display_name(self):
"""Display name."""
return self._name_()

def __repr__(self):
return f"<Task '{self.display_name()}'>"


class TaskContainer(PyCallableStateObject):
"""Wrap a workflow TaskObject container.
Expand Down
60 changes: 60 additions & 0 deletions tests/test_new_meshing_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ansys.fluent.core import examples
from ansys.fluent.core.meshing.watertight import watertight_workflow
from ansys.fluent.core.utils.fluent_version import FluentVersion
from tests.test_datamodel_service import disable_datamodel_cache # noqa: F401


@pytest.mark.nightly
Expand Down Expand Up @@ -945,6 +946,25 @@ def test_attrs_in_watertight_meshing_workflow(new_mesh_session):
assert not watertight.import_geometry.file_name()


@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=23.2")
def test_ordered_children_in_enhanced_meshing_workflow(new_mesh_session):
watertight = new_mesh_session.watertight()
assert set([repr(x) for x in watertight.ordered_children()]) == {
"<Task 'Add Boundary Layers'>",
"<Task 'Add Local Sizing'>",
"<Task 'Apply Share Topology'>",
"<Task 'Create Regions'>",
"<Task 'Describe Geometry'>",
"<Task 'Enclose Fluid Regions (Capping)'>",
"<Task 'Generate the Surface Mesh'>",
"<Task 'Generate the Volume Mesh'>",
"<Task 'Import Geometry'>",
"<Task 'Update Boundaries'>",
"<Task 'Update Regions'>",
}


@pytest.mark.skip("Randomly failing in CI")
@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=23.2")
Expand Down Expand Up @@ -1024,3 +1044,43 @@ def test_switch_between_workflows(new_mesh_session):
# Re-initialize fault-tolerant
fault_tolerant.reinitialize()
assert fault_tolerant.import_cad_and_part_management.arguments()


@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=24.1")
def test_new_meshing_workflow_without_dm_caching(
disable_datamodel_cache, new_mesh_session
):
import_file_name = examples.download_file(
"mixing_elbow.pmdb", "pyfluent/mixing_elbow"
)

watertight = new_mesh_session.watertight()
watertight.import_geometry.file_name = import_file_name
watertight.import_geometry.length_unit.set_state("in")
watertight.import_geometry()

watertight.add_local_sizing.add_child_to_task()
watertight.add_local_sizing()

watertight.create_volume_mesh()

watertight.import_geometry.rename(new_name="import_geom_wtm")
assert watertight.task("import_geom_wtm").arguments()

watertight.delete_tasks(list_of_tasks=["add_local_sizing"])
with pytest.raises(AttributeError):
watertight.add_local_sizing
watertight.insert_new_task(command_name="add_local_sizing")
time.sleep(2.5)
assert watertight.add_local_sizing

fault_tolerant = new_mesh_session.fault_tolerant()
with pytest.raises(RuntimeError):
watertight.import_geometry.arguments()
assert fault_tolerant.import_cad_and_part_management.arguments()

watertight.reinitialize()
with pytest.raises(RuntimeError):
fault_tolerant.import_cad_and_part_management.arguments()
assert watertight.import_geometry.arguments()

0 comments on commit 870699a

Please sign in to comment.