Skip to content

Commit

Permalink
refactor: update enhanced meshing interface (#2606)
Browse files Browse the repository at this point in the history
* Return solver session only when switch_to_solver is successful.

* Fix add_child_and_update

* Add tests for 2D Meshing workflow.

* Fix _add_child

* Add documentation.

* Update styling.

* Revert changes in switching to solver.

* Refactoring.

* Refactor and update tests.

* Fix test import.

* Bug fixing.

* Fix behaviour of defer_update

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

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

* Fix for defer_update.

* Fix doc.

* Update fluent version check.

* Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc style.

* Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc/source/user_guide/meshing_workflow/meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc style.

* Update doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst

Co-authored-by: Kathy Pippert <[email protected]>

* Update src/ansys/fluent/core/meshing/meshing_workflow.py

Co-authored-by: Kathy Pippert <[email protected]>

* Update src/ansys/fluent/core/meshing/meshing_workflow.py

Co-authored-by: Kathy Pippert <[email protected]>

* Update src/ansys/fluent/core/meshing/meshing_workflow.py

Co-authored-by: Kathy Pippert <[email protected]>

* Update src/ansys/fluent/core/meshing/meshing_workflow.py

Co-authored-by: Kathy Pippert <[email protected]>

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

Co-authored-by: Kathy Pippert <[email protected]>

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

Co-authored-by: Kathy Pippert <[email protected]>

* Update docs.

* Update meshing test.

* Update const. call from Solver.

---------

Co-authored-by: Mainak Kundu <[email protected]>
Co-authored-by: Kathy Pippert <[email protected]>
  • Loading branch information
3 people authored Mar 28, 2024
1 parent 51fc833 commit 80d492e
Show file tree
Hide file tree
Showing 12 changed files with 850 additions and 249 deletions.
220 changes: 217 additions & 3 deletions doc/source/user_guide/meshing_workflow/meshing_workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,223 @@ Switch to solution mode
solver = meshing.switch_to_solver()
Sample use of CommandArguments
------------------------------
This simple example shows you how to use the ``CommandArgument`` attributes and explicit
2D meshing workflow
-------------------
Use the **2D** meshing workflow to mesh specific two-dimensional geometries.
The following example shows how to use the 2D Meshing workflow.

Import geometry
~~~~~~~~~~~~~~~

.. code:: python
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import_file_name = examples.download_file('NACA0012.fmd', 'pyfluent/airfoils')
meshing = pyfluent.launch_fluent(
mode="meshing", precision='double', processor_count=2
)
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()
Set regions and boundaries
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python
meshing.workflow.TaskObject["Update Regions"].Execute()
meshing.workflow.TaskObject["Update Boundaries"].Arguments.set_state(
{
r"SelectionType": r"zone",
}
)
meshing.workflow.TaskObject["Update Boundaries"].Execute()
Define global sizing
~~~~~~~~~~~~~~~~~~~~

.. code:: python
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()
Add body of influence
~~~~~~~~~~~~~~~~~~~~~

.. code:: python
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)
Set edge sizing
~~~~~~~~~~~~~~~

.. code:: python
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)
Set curvature sizing
~~~~~~~~~~~~~~~~~~~~

.. code:: python
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)
Add boundary layer
~~~~~~~~~~~~~~~~~~

.. code:: python
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
)
Generate surface mesh
~~~~~~~~~~~~~~~~~~~~~

.. code:: python
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()
Export Fluent 2D mesh
~~~~~~~~~~~~~~~~~~~~~

.. code:: python
meshing.workflow.TaskObject["Export Fluent 2D Mesh"].Arguments.set_state(
{
r"FileName": r"mesh1.msh.h5",
}
)
meshing.workflow.TaskObject["Export Fluent 2D Mesh"].Execute()
Switch to solver mode
~~~~~~~~~~~~~~~~~~~~~

Switching to solver mode is not allowed in 2D Meshing mode.


Sample use of ``CommandArguments``
----------------------------------
This simple example shows how to use the ``CommandArgument`` attributes and explicit
attribute access methods in a watertight geometry meshing workflow.

.. Note::
Expand Down
160 changes: 160 additions & 0 deletions doc/source/user_guide/meshing_workflow/new_meshing_workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,163 @@ Switch to solution mode
.. code:: python
solver = meshing.switch_to_solver()
2D meshing workflow
-------------------
Use the **2D** meshing workflow to mesh specific two-dimensional geometries.
The following example shows you how to use the 2D meshing workflow.

Import geometry
~~~~~~~~~~~~~~~

.. code:: python
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import_file_name = examples.download_file('NACA0012.fmd', 'pyfluent/airfoils')
meshing = pyfluent.launch_fluent(
mode="meshing", precision='double', processor_count=2
)
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
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python
two_dim_mesh.update_regions_2d()
two_dim_mesh.update_boundaries_2d.selection_type = "zone"
two_dim_mesh.update_boundaries_2d()
Define global sizing
~~~~~~~~~~~~~~~~~~~~

.. code:: python
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()
Adding BOI
~~~~~~~~~~

.. code:: python
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)
Set edge sizing
~~~~~~~~~~~~~~~

.. code:: python
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)
Set curvature sizing
~~~~~~~~~~~~~~~~~~~~

.. code:: python
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
~~~~~~~~~~~~~~~~~~

.. code:: python
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)
Generate surface mesh
~~~~~~~~~~~~~~~~~~~~~

.. code:: python
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
~~~~~~~~~~~~~~~~~~~~~~~

Switching to solver is not allowed in 2D Meshing mode.
Loading

0 comments on commit 80d492e

Please sign in to comment.