Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update enhanced meshing interface #2606

Merged
merged 41 commits into from
Mar 28, 2024
Merged
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e52d3fd
Return solver session only when switch_to_solver is successful.
prmukherj Mar 22, 2024
8f14376
Fix add_child_and_update
prmukherj Mar 22, 2024
e49dfdb
Add tests for 2D Meshing workflow.
prmukherj Mar 22, 2024
9642013
Fix _add_child
prmukherj Mar 25, 2024
d4e8f2e
Add documentation.
prmukherj Mar 25, 2024
d139593
Update styling.
prmukherj Mar 25, 2024
af752a8
Merge branch 'main' into maint/update_enhanced_meshing_interface
prmukherj Mar 25, 2024
6480b71
Revert changes in switching to solver.
prmukherj Mar 26, 2024
76cca9d
Merge branch 'maint/update_enhanced_meshing_interface' of https://git…
prmukherj Mar 26, 2024
702c48b
Refactoring.
prmukherj Mar 26, 2024
6ccea31
Refactor and update tests.
prmukherj Mar 26, 2024
5407b0e
Fix test import.
prmukherj Mar 26, 2024
72d1098
Bug fixing.
prmukherj Mar 26, 2024
ddfc8f5
Fix behaviour of defer_update
prmukherj Mar 26, 2024
5911280
Update src/ansys/fluent/core/workflow.py
prmukherj Mar 27, 2024
4dd6060
Fix for defer_update.
prmukherj Mar 27, 2024
7c5d32f
Fix doc.
prmukherj Mar 27, 2024
b001e58
Merge branch 'main' into maint/update_enhanced_meshing_interface
prmukherj Mar 27, 2024
08094ab
Update fluent version check.
prmukherj Mar 27, 2024
a4108ac
Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst
prmukherj Mar 28, 2024
f045c42
Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst
prmukherj Mar 28, 2024
5d6763c
Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst
prmukherj Mar 28, 2024
0d1fb06
Update doc style.
prmukherj Mar 28, 2024
eee7d4a
Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst
prmukherj Mar 28, 2024
09d5f07
Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst
prmukherj Mar 28, 2024
eceffb7
Update doc style.
prmukherj Mar 28, 2024
64e4b04
Update doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst
prmukherj Mar 28, 2024
80fbd93
Update doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst
prmukherj Mar 28, 2024
df0a899
Update doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst
prmukherj Mar 28, 2024
30d987a
Update src/ansys/fluent/core/meshing/meshing_workflow.py
prmukherj Mar 28, 2024
4ab4b90
Update src/ansys/fluent/core/meshing/meshing_workflow.py
prmukherj Mar 28, 2024
2fd4601
Update src/ansys/fluent/core/meshing/meshing_workflow.py
prmukherj Mar 28, 2024
cf03daf
Update src/ansys/fluent/core/meshing/meshing_workflow.py
prmukherj Mar 28, 2024
6a04157
Update src/ansys/fluent/core/session_base_meshing.py
prmukherj Mar 28, 2024
fd82e0e
Update src/ansys/fluent/core/workflow.py
prmukherj Mar 28, 2024
ab989c9
Update docs.
prmukherj Mar 28, 2024
ffd09f7
Merge branch 'main' into maint/update_enhanced_meshing_interface
prmukherj Mar 28, 2024
7aa68be
Update meshing test.
prmukherj Mar 28, 2024
8d98dd4
Merge branch 'maint/update_enhanced_meshing_interface' of https://git…
prmukherj Mar 28, 2024
ca83d17
Merge branch 'main' into maint/update_enhanced_meshing_interface
prmukherj Mar 28, 2024
ee713b0
Update const. call from Solver.
prmukherj Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/ansys/fluent/core/session_meshing.py
Original file line number Diff line number Diff line change
@@ -37,13 +37,16 @@ def __init__(

def _switch_to_solver(self) -> Any:
self.tui.switch_to_solution_mode("yes")
solver_session = Solver(
fluent_connection=self._fluent_connection,
file_transfer_service=self._file_transfer_service,
)
delattr(self, "switch_to_solver")
self.switched = True
return solver_session
if self.scheme_eval.scheme_eval("(cx-solver-mode?)"):
solver_session = Solver(
fluent_connection=self._fluent_connection,
file_transfer_service=self._file_transfer_service,
)
delattr(self, "switch_to_solver")
self.switched = True
return solver_session
else:
return

@property
def tui(self):
13 changes: 9 additions & 4 deletions src/ansys/fluent/core/workflow.py
Original file line number Diff line number Diff line change
@@ -984,17 +984,22 @@ def _add_child(self, state: Optional[dict] = None) -> None:
state.update({"AddChild": "yes"})
self._task.Arguments.set_state(state)

def add_child_and_update(self, state=None):
def add_child_and_update(self, state=None, defer_update=None):
"""Add a child to this CompoundTask and update.
prmukherj marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
state : Optional[dict]
Optional state.
defer_update: Optional[bool]
prmukherj marked this conversation as resolved.
Show resolved Hide resolved
Flag to defer update.
"""
self._add_child(state)
self._task.AddChildAndUpdate()
return self.last_child()
if defer_update is None:
self._add_child(state)
self._task.AddChildAndUpdate()
return self.last_child()
else:
prmukherj marked this conversation as resolved.
Show resolved Hide resolved
return self._task.AddChildAndUpdate(DeferUpdate=defer_update)
prmukherj marked this conversation as resolved.
Show resolved Hide resolved

def last_child(self) -> BaseTask:
"""Get the last child of this CompoundTask.
161 changes: 161 additions & 0 deletions tests/test_meshing_workflow.py
Original file line number Diff line number Diff line change
@@ -451,3 +451,164 @@ def test_new_workflow_structure(new_mesh_session):
msg.value.args[0]
== "'WatertightMeshingWorkflow' object has no attribute 'TaskObject'"
)


@pytest.mark.nightly
@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=24.2")
def test_new_2d_meshing_workflow(new_mesh_session):
# Import geometry
# import_file_name = examples.download_file(
# "mixing_elbow.pmdb", "pyfluent/mixing_elbow"
# )
import_file_name = r"C:\ANSYSDev\PyFluent_Dev_01\pyfluent\NACA0012.fmd"
meshing = new_mesh_session
meshing.workflow.InitializeWorkflow(WorkflowType="2D Meshing")
meshing.workflow.TaskObject["Load CAD Geometry"].Arguments.set_state(
{
r"FileName": import_file_name,
r"LengthUnit": r"mm",
r"Refaceting": {
r"Refacet": False,
},
}
)
meshing.workflow.TaskObject["Load CAD Geometry"].Execute()

meshing.workflow.TaskObject["Update Regions"].Execute()
meshing.workflow.TaskObject["Update Boundaries"].Arguments.set_state(
{
r"SelectionType": r"zone",
}
)
meshing.workflow.TaskObject["Update Boundaries"].Execute()

meshing.workflow.TaskObject["Define Global Sizing"].Arguments.set_state(
{
r"CurvatureNormalAngle": 20,
r"MaxSize": 2000,
r"MinSize": 5,
r"SizeFunctions": r"Curvature",
}
)
meshing.workflow.TaskObject["Define Global Sizing"].Execute()

meshing.workflow.TaskObject["Add Local Sizing"].Arguments.set_state(
{
r"AddChild": r"yes",
r"BOIControlName": r"boi_1",
r"BOIExecution": r"Body Of Influence",
r"BOIFaceLabelList": [r"boi"],
r"BOISize": 50,
r"BOIZoneorLabel": r"label",
r"DrawSizeControl": True,
}
)
meshing.workflow.TaskObject["Add Local Sizing"].AddChildAndUpdate(DeferUpdate=False)

meshing.workflow.TaskObject["Add Local Sizing"].Arguments.set_state(
{
r"AddChild": r"yes",
r"BOIControlName": r"edgesize_1",
r"BOIExecution": r"Edge Size",
r"BOISize": 5,
r"BOIZoneorLabel": r"label",
r"DrawSizeControl": True,
r"EdgeLabelList": [r"airfoil-te"],
}
)
meshing.workflow.TaskObject["Add Local Sizing"].AddChildAndUpdate(DeferUpdate=False)
meshing.workflow.TaskObject["Add Local Sizing"].Arguments.set_state(
{
r"AddChild": r"yes",
r"BOIControlName": r"curvature_1",
r"BOICurvatureNormalAngle": 10,
r"BOIExecution": r"Curvature",
r"BOIMaxSize": 2,
r"BOIMinSize": 1.5,
r"BOIScopeTo": r"edges",
r"BOIZoneorLabel": r"label",
r"DrawSizeControl": True,
r"EdgeLabelList": [r"airfoil"],
}
)
meshing.workflow.TaskObject["Add Local Sizing"].AddChildAndUpdate(DeferUpdate=False)

meshing.workflow.TaskObject["Add 2D Boundary Layers"].Arguments.set_state(
{
r"AddChild": r"yes",
r"BLControlName": r"aspect-ratio_1",
r"NumberOfLayers": 4,
r"OffsetMethodType": r"aspect-ratio",
}
)
meshing.workflow.TaskObject["Add 2D Boundary Layers"].AddChildAndUpdate(
DeferUpdate=False
)
meshing.workflow.TaskObject["Generate the Surface Mesh"].Arguments.set_state(
{
r"Surface2DPreferences": {
r"MergeEdgeZonesBasedOnLabels": r"no",
r"MergeFaceZonesBasedOnLabels": r"no",
r"ShowAdvancedOptions": True,
},
}
)
meshing.workflow.TaskObject["Generate the Surface Mesh"].Execute()

meshing.workflow.TaskObject["aspect-ratio_1"].Revert()
meshing.workflow.TaskObject["aspect-ratio_1"].Arguments.set_state(
{
r"AddChild": r"yes",
r"BLControlName": r"uniform_1",
r"FirstLayerHeight": 2,
r"NumberOfLayers": 4,
r"OffsetMethodType": r"uniform",
}
)
meshing.workflow.TaskObject["aspect-ratio_1"].Execute()
meshing.workflow.TaskObject["Generate the Surface Mesh"].Arguments.set_state(None)
meshing.workflow.TaskObject["Generate the Surface Mesh"].Arguments.set_state(
{
r"Surface2DPreferences": {
r"MergeEdgeZonesBasedOnLabels": r"no",
r"MergeFaceZonesBasedOnLabels": r"no",
r"ShowAdvancedOptions": True,
},
}
)
meshing.workflow.TaskObject["Generate the Surface Mesh"].Execute()
meshing.workflow.TaskObject["uniform_1"].Revert()
meshing.workflow.TaskObject["uniform_1"].Arguments.set_state(
{
r"AddChild": r"yes",
r"BLControlName": r"smooth-transition_1",
r"FirstLayerHeight": 2,
r"NumberOfLayers": 7,
r"OffsetMethodType": r"smooth-transition",
}
)
meshing.workflow.TaskObject["uniform_1"].Execute()

meshing.workflow.TaskObject["Generate the Surface Mesh"].Arguments.set_state(None)
meshing.workflow.TaskObject["Generate the Surface Mesh"].Arguments.set_state(
{
r"Surface2DPreferences": {
r"MergeEdgeZonesBasedOnLabels": r"no",
r"MergeFaceZonesBasedOnLabels": r"no",
r"ShowAdvancedOptions": True,
},
}
)
meshing.workflow.TaskObject["Generate the Surface Mesh"].Execute()

meshing.workflow.TaskObject["Export Fluent 2D Mesh"].Arguments.set_state(
{
r"FileName": r"C:\ANSYSDev\PyFluent_Dev_01\pyfluent\out\case1.msh.h5",
}
)
meshing.workflow.TaskObject["Export Fluent 2D Mesh"].Execute()

# Switch to solution mode
solver = meshing.switch_to_solver()
assert not solver
120 changes: 120 additions & 0 deletions tests/test_new_meshing_workflow.py
Original file line number Diff line number Diff line change
@@ -474,6 +474,126 @@ def test_new_fault_tolerant_workflow(new_mesh_session):
assert solver


@pytest.mark.nightly
@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=24.2")
def test_new_2d_meshing_workflow(new_mesh_session):
# Import geometry
# import_file_name = examples.download_file(
# "mixing_elbow.pmdb", "pyfluent/mixing_elbow"
# )
import_file_name = r"C:\ANSYSDev\PyFluent_Dev_01\pyfluent\NACA0012.fmd"
two_dim_mesh = new_mesh_session.two_dimensional_meshing()

two_dim_mesh.load_cad_geometry_2d.file_name = import_file_name
two_dim_mesh.load_cad_geometry_2d.length_unit = "mm"
two_dim_mesh.load_cad_geometry_2d.refaceting.refacet = False
two_dim_mesh.load_cad_geometry_2d()

# Set regions and boundaries
two_dim_mesh.update_regions_2d()
two_dim_mesh.update_boundaries_2d.selection_type = "zone"
two_dim_mesh.update_boundaries_2d()

# Define global sizing
two_dim_mesh.define_global_sizing_2d.curvature_normal_angle = 20
two_dim_mesh.define_global_sizing_2d.max_size = 2000.0
two_dim_mesh.define_global_sizing_2d.min_size = 5.0
two_dim_mesh.define_global_sizing_2d.size_functions = "Curvature"
two_dim_mesh.define_global_sizing_2d()

# Add local sizing
two_dim_mesh.add_local_sizing_2d.add_child = "yes"
two_dim_mesh.add_local_sizing_2d.boi_control_name = "boi_1"
two_dim_mesh.add_local_sizing_2d.boi_execution = "Body Of Influence"
two_dim_mesh.add_local_sizing_2d.boi_face_label_list = ["boi"]
two_dim_mesh.add_local_sizing_2d.boi_size = 50.0
two_dim_mesh.add_local_sizing_2d.boi_zoneor_label = "label"
two_dim_mesh.add_local_sizing_2d.draw_size_control = True
two_dim_mesh.add_local_sizing_2d.add_child_and_update(defer_update=False)

two_dim_mesh.add_local_sizing_2d.add_child = "yes"
two_dim_mesh.add_local_sizing_2d.boi_control_name = "edgesize_1"
two_dim_mesh.add_local_sizing_2d.boi_execution = "Edge Size"
two_dim_mesh.add_local_sizing_2d.boi_size = 5.0
two_dim_mesh.add_local_sizing_2d.boi_zoneor_label = "label"
two_dim_mesh.add_local_sizing_2d.draw_size_control = True
two_dim_mesh.add_local_sizing_2d.edge_label_list = ["airfoil-te"]
two_dim_mesh.add_local_sizing_2d.add_child_and_update(defer_update=False)

two_dim_mesh.add_local_sizing_2d.add_child = "yes"
two_dim_mesh.add_local_sizing_2d.boi_control_name = "curvature_1"
two_dim_mesh.add_local_sizing_2d.boi_curvature_normal_angle = 10
two_dim_mesh.add_local_sizing_2d.boi_execution = "Curvature"
two_dim_mesh.add_local_sizing_2d.boi_max_size = 2
two_dim_mesh.add_local_sizing_2d.boi_min_size = 1.5
two_dim_mesh.add_local_sizing_2d.boi_scope_to = "edges"
two_dim_mesh.add_local_sizing_2d.boi_zoneor_label = "label"
two_dim_mesh.add_local_sizing_2d.draw_size_control = True
two_dim_mesh.add_local_sizing_2d.edge_label_list = ["airfoil"]
two_dim_mesh.add_local_sizing_2d.add_child_and_update(defer_update=False)

# Add boundary layer
two_dim_mesh.add_2d_boundary_layers.add_child = "yes"
two_dim_mesh.add_2d_boundary_layers.bl_control_name = "aspect-ratio_1"
two_dim_mesh.add_2d_boundary_layers.number_of_layers = 4
two_dim_mesh.add_2d_boundary_layers.offset_method_type = "aspect-ratio"
two_dim_mesh.add_2d_boundary_layers.add_child_and_update(defer_update=False)

two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.merge_edge_zones_based_on_labels = (
"no"
)
two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.merge_face_zones_based_on_labels = (
"no"
)
two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.show_advanced_options = (
True
)
two_dim_mesh.generate_initial_surface_mesh()

two_dim_mesh.task("aspect-ratio_1").revert()
two_dim_mesh.task("aspect-ratio_1").add_child = "yes"
two_dim_mesh.task("aspect-ratio_1").bl_control_name = "uniform_1"
two_dim_mesh.task("aspect-ratio_1").first_layer_height = 2
two_dim_mesh.task("aspect-ratio_1").number_of_layers = 4
two_dim_mesh.task("aspect-ratio_1").offset_method_type = "uniform"
two_dim_mesh.task("aspect-ratio_1")()

two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.merge_edge_zones_based_on_labels = (
"no"
)
two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.merge_face_zones_based_on_labels = (
"no"
)
two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.show_advanced_options = (
True
)
two_dim_mesh.generate_initial_surface_mesh()

two_dim_mesh.task("uniform_1").revert()
two_dim_mesh.task("uniform_1").add_child = "yes"
two_dim_mesh.task("uniform_1").bl_control_name = "smooth-transition_1"
two_dim_mesh.task("uniform_1").first_layer_height = 2
two_dim_mesh.task("uniform_1").number_of_layers = 7
two_dim_mesh.task("uniform_1").offset_method_type = "smooth-transition"
two_dim_mesh.task("uniform_1")()

two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.merge_edge_zones_based_on_labels = (
"no"
)
two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.merge_face_zones_based_on_labels = (
"no"
)
two_dim_mesh.generate_initial_surface_mesh.surface2_d_preferences.show_advanced_options = (
True
)
two_dim_mesh.generate_initial_surface_mesh()

# Switch to solution mode
solver = new_mesh_session.switch_to_solver()
assert not solver


@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=23.2")
def test_updating_state_in_new_meshing_workflow(new_mesh_session):
Loading