From 275152fa7550bffb1e8c3b34276602c5cd576afb Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 10 Jul 2024 10:20:05 +0530 Subject: [PATCH 1/2] fix: Remove non-settings version of example scripts --- examples/00-fluent/exhaust_system.py | 761 ------------------ .../00-fluent/exhaust_system_settings_api.py | 7 - .../00-fluent/external_compressible_flow.py | 9 +- examples/00-fluent/mixing_elbow.py | 602 -------------- examples/00-fluent/modeling_cavitation.py | 7 +- 5 files changed, 3 insertions(+), 1383 deletions(-) delete mode 100644 examples/00-fluent/exhaust_system.py delete mode 100644 examples/00-fluent/mixing_elbow.py diff --git a/examples/00-fluent/exhaust_system.py b/examples/00-fluent/exhaust_system.py deleted file mode 100644 index 1fad1e546187..000000000000 --- a/examples/00-fluent/exhaust_system.py +++ /dev/null @@ -1,761 +0,0 @@ -""".. _ref_exhaust_system_tui_api: - -Fault-tolerant meshing workflow -------------------------------- -This example sets up and solves a three-dimensional turbulent fluid flow -in a manifold exhaust system, which is common in the automotive industry. -Predicting the flow field in the area of the mixing region is important -to designing the junction properly. - -This example uses the guided workflow for fault-tolerant meshing because it -is appropriate for geometries that can have imperfections, such as gaps and -leakages. - -**Workflow tasks** - -The fault-tolerant meshing workflow guides you through these tasks: - -- Import a CAD geometry and manage individual parts -- Generate a surface mesh -- Cap inlets and outlets -- Extract a fluid region -- Define leakages -- Extract edge features -- Set up size controls -- Generate a volume mesh - -**Problem description** - -In the manifold exhaust system, air flows through the three inlets -with a uniform velocity of 1 m/s. The air then exits through the outlet. -A small pipe is placed in the main portion of the manifold where edge -extraction is considered. The example also includes a known small leakage -to demonstrate the automatic leakage detection aspects of the meshing workflow. -""" - -############################################################################### -# Example Setup -# ------------- -# Before you can use the fault-tolerant meshing workflow, you must set up the -# example and initialize this workflow. -# -# Perform required imports -# ~~~~~~~~~~~~~~~~~~~~~~~~ -# Perform required imports, which includes downloading and importing -# the geometry file. - -# sphinx_gallery_thumbnail_path = '_static/exhaust_system.png' -import ansys.fluent.core as pyfluent -from ansys.fluent.core import examples - -import_file_name = examples.download_file( - "exhaust_system.fmd", "pyfluent/exhaust_system" -) - -############################################################################### -# Launch Fluent -# ~~~~~~~~~~~~~ -# Launch Fluent as a service in meshing mode with double precision running on -# two processors. - -meshing = pyfluent.launch_fluent( - precision="double", - processor_count=4, - mode="meshing", -) - -############################################################################### -# Initialize workflow -# ~~~~~~~~~~~~~~~~~~~ -# Initialize the fault-tolerant meshing workflow. - -meshing.workflow.InitializeWorkflow(WorkflowType="Fault-tolerant Meshing") - -############################################################################### -# Fault-folerant meshing workflow -# ------------------------------- -# The fault-tolerant meshing workflow guides you through the many tasks that -# follow. -# -# Import CAD and manage parts -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Import the CAD geometry file (``exhaust_system.fmd``) and selectively manage some -# parts. - -meshing.upload(import_file_name) -meshing.PartManagement.InputFileChanged( - FilePath=import_file_name, IgnoreSolidNames=False, PartPerBody=False -) -meshing.PMFileManagement.FileManager.LoadFiles() -meshing.PartManagement.Node["Meshing Model"].Copy( - Paths=[ - "/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/main,1", - "/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/flow-pipe,1", - "/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/outpipe3,1", - "/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/object2,1", - "/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/object1,1", - ] -) -meshing.PartManagement.ObjectSetting["DefaultObjectSetting"].OneZonePer.set_state( - "part" -) -cad_import = meshing.workflow.TaskObject["Import CAD and Part Management"] -cad_import.Arguments.set_state( - { - "Context": 0, - "CreateObjectPer": "Custom", - "FMDFileName": import_file_name, - "FileLoaded": "yes", - "ObjectSetting": "DefaultObjectSetting", - "Options": { - "Line": False, - "Solid": False, - "Surface": False, - }, - } -) -cad_import.Execute() - -############################################################################### -# Describe geometry and flow -# ~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Describe the geometry and the flow characteristics. - -describe_geom = meshing.workflow.TaskObject["Describe Geometry and Flow"] -describe_geom.Arguments.set_state( - { - "AddEnclosure": "No", - "CloseCaps": "Yes", - "FlowType": "Internal flow through the object", - } -) -describe_geom.UpdateChildTasks(SetupTypeChanged=False) -describe_geom.Arguments.set_state( - { - "AddEnclosure": "No", - "CloseCaps": "Yes", - "DescribeGeometryAndFlowOptions": { - "AdvancedOptions": True, - "ExtractEdgeFeatures": "Yes", - }, - "FlowType": "Internal flow through the object", - } -) -describe_geom.UpdateChildTasks(SetupTypeChanged=False) -describe_geom.Execute() - -############################################################################### -# Enclose openings -# ~~~~~~~~~~~~~~~~ -# Enclose (cap) any openings in the geometry. - -############################################################################### -# .. image:: /_static/exhaust_system_011.png -# :width: 400pt -# :align: center - -############################################################################### -# .. image:: /_static/exhaust_system_012.png -# :width: 400pt -# :align: center -capping = meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"] -capping.Arguments.set_state( - { - "CreatePatchPreferences": { - "ShowCreatePatchPreferences": False, - }, - "PatchName": "inlet-1", - "SelectionType": "zone", - "ZoneSelectionList": ["inlet.1"], - } -) -capping.Arguments.set_state( - { - "CreatePatchPreferences": { - "ShowCreatePatchPreferences": False, - }, - "PatchName": "inlet-1", - "SelectionType": "zone", - "ZoneLocation": [ - "1", - "351.68205", - "-361.34322", - "-301.88668", - "396.96205", - "-332.84759", - "-266.69751", - "inlet.1", - ], - "ZoneSelectionList": ["inlet.1"], - } -) -capping.AddChildToTask() - -capping.InsertCompoundChildTask() -capping.Arguments.set_state({}) -meshing.workflow.TaskObject["inlet-1"].Execute() -capping.Arguments.set_state( - { - "PatchName": "inlet-2", - "SelectionType": "zone", - "ZoneSelectionList": ["inlet.2"], - } -) -capping.Arguments.set_state( - { - "PatchName": "inlet-2", - "SelectionType": "zone", - "ZoneLocation": [ - "1", - "441.68205", - "-361.34322", - "-301.88668", - "486.96205", - "-332.84759", - "-266.69751", - "inlet.2", - ], - "ZoneSelectionList": ["inlet.2"], - } -) -capping.AddChildToTask() - -capping.InsertCompoundChildTask() -capping.Arguments.set_state({}) -meshing.workflow.TaskObject["inlet-2"].Execute() -capping.Arguments.set_state( - { - "PatchName": "inlet-3", - "SelectionType": "zone", - "ZoneSelectionList": ["inlet"], - } -) -capping.Arguments.set_state( - { - "PatchName": "inlet-3", - "SelectionType": "zone", - "ZoneLocation": [ - "1", - "261.68205", - "-361.34322", - "-301.88668", - "306.96205", - "-332.84759", - "-266.69751", - "inlet", - ], - "ZoneSelectionList": ["inlet"], - } -) -capping.AddChildToTask() - -capping.InsertCompoundChildTask() -capping.Arguments.set_state({}) -meshing.workflow.TaskObject["inlet-3"].Execute() -capping.Arguments.set_state( - { - "PatchName": "outlet-1", - "SelectionType": "zone", - "ZoneSelectionList": ["outlet"], - "ZoneType": "pressure-outlet", - } -) -capping.Arguments.set_state( - { - "PatchName": "outlet-1", - "SelectionType": "zone", - "ZoneLocation": [ - "1", - "352.22702", - "-197.8957", - "84.102381", - "394.41707", - "-155.70565", - "84.102381", - "outlet", - ], - "ZoneSelectionList": ["outlet"], - "ZoneType": "pressure-outlet", - } -) -capping.AddChildToTask() - -capping.InsertCompoundChildTask() -capping.Arguments.set_state({}) -meshing.workflow.TaskObject["outlet-1"].Execute() - -############################################################################### -# Extract edge features -# ~~~~~~~~~~~~~~~~~~~~~ -# Extract edge features. -edge_features = meshing.workflow.TaskObject["Extract Edge Features"] -edge_features.Arguments.set_state( - { - "ExtractMethodType": "Intersection Loops", - "ObjectSelectionList": ["flow_pipe", "main"], - } -) -edge_features.AddChildToTask() - -edge_features.InsertCompoundChildTask() -edge_group = meshing.workflow.TaskObject["edge-group-1"] -edge_group.Arguments.set_state( - { - "ExtractEdgesName": "edge-group-1", - "ExtractMethodType": "Intersection Loops", - "ObjectSelectionList": ["flow_pipe", "main"], - } -) -edge_features.Arguments.set_state({}) - -edge_group.Execute() - -############################################################################### -# Identify regions -# ~~~~~~~~~~~~~~~~ -# Identify regions. -identify_regions = meshing.workflow.TaskObject["Identify Regions"] -identify_regions.Arguments.set_state( - { - "SelectionType": "zone", - "X": 377.322045740589, - "Y": -176.800676988458, - "Z": -37.0764628583475, - "ZoneSelectionList": ["main.1"], - } -) -identify_regions.Arguments.set_state( - { - "SelectionType": "zone", - "X": 377.322045740589, - "Y": -176.800676988458, - "Z": -37.0764628583475, - "ZoneLocation": [ - "1", - "213.32205", - "-225.28068", - "-158.25531", - "541.32205", - "-128.32068", - "84.102381", - "main.1", - ], - "ZoneSelectionList": ["main.1"], - } -) -identify_regions.AddChildToTask() - -identify_regions.InsertCompoundChildTask() -fluid_region_1 = meshing.workflow.TaskObject["fluid-region-1"] -fluid_region_1.Arguments.set_state( - { - "MaterialPointsName": "fluid-region-1", - "SelectionType": "zone", - "X": 377.322045740589, - "Y": -176.800676988458, - "Z": -37.0764628583475, - "ZoneLocation": [ - "1", - "213.32205", - "-225.28068", - "-158.25531", - "541.32205", - "-128.32068", - "84.102381", - "main.1", - ], - "ZoneSelectionList": ["main.1"], - } -) -identify_regions.Arguments.set_state({}) - -fluid_region_1.Execute() -identify_regions.Arguments.set_state( - { - "MaterialPointsName": "void-region-1", - "NewRegionType": "void", - "ObjectSelectionList": ["inlet-1", "inlet-2", "inlet-3", "main"], - "X": 374.722045740589, - "Y": -278.9775145640143, - "Z": -161.1700719416913, - } -) -identify_regions.AddChildToTask() - -identify_regions.InsertCompoundChildTask() - -identify_regions.Arguments.set_state({}) - -meshing.workflow.TaskObject["void-region-1"].Execute() - -############################################################################### -# Define thresholds for leakages -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Define thresholds for potential leakages. -leakage_threshold = meshing.workflow.TaskObject["Define Leakage Threshold"] -leakage_threshold.Arguments.set_state( - { - "AddChild": "yes", - "FlipDirection": True, - "PlaneDirection": "X", - "RegionSelectionSingle": "void-region-1", - } -) -leakage_threshold.AddChildToTask() - -leakage_threshold.InsertCompoundChildTask() -leakage_1 = meshing.workflow.TaskObject["leakage-1"] -leakage_1.Arguments.set_state( - { - "AddChild": "yes", - "FlipDirection": True, - "LeakageName": "leakage-1", - "PlaneDirection": "X", - "RegionSelectionSingle": "void-region-1", - } -) -leakage_threshold.Arguments.set_state( - { - "AddChild": "yes", - } -) -leakage_1.Execute() - -############################################################################### -# Review region settings -# ~~~~~~~~~~~~~~~~~~~~~~ -# Review the region settings. -update_region = meshing.workflow.TaskObject["Update Region Settings"] -update_region.Arguments.set_state( - { - "AllRegionFilterCategories": ["2"] * 5 + ["1"] * 2, - "AllRegionLeakageSizeList": ["none"] * 6 + ["6.4"], - "AllRegionLinkedConstructionSurfaceList": ["n/a"] * 6 + ["no"], - "AllRegionMeshMethodList": ["none"] * 6 + ["wrap"], - "AllRegionNameList": [ - "main", - "flow_pipe", - "outpipe3", - "object2", - "object1", - "void-region-1", - "fluid-region-1", - ], - "AllRegionOversetComponenList": ["no"] * 7, - "AllRegionSourceList": ["object"] * 5 + ["mpt"] * 2, - "AllRegionTypeList": ["void"] * 6 + ["fluid"], - "AllRegionVolumeFillList": ["none"] * 6 + ["tet"], - "FilterCategory": "Identified Regions", - "OldRegionLeakageSizeList": [""], - "OldRegionMeshMethodList": ["wrap"], - "OldRegionNameList": ["fluid-region-1"], - "OldRegionOversetComponenList": ["no"], - "OldRegionTypeList": ["fluid"], - "OldRegionVolumeFillList": ["hexcore"], - "RegionLeakageSizeList": [""], - "RegionMeshMethodList": ["wrap"], - "RegionNameList": ["fluid-region-1"], - "RegionOversetComponenList": ["no"], - "RegionTypeList": ["fluid"], - "RegionVolumeFillList": ["tet"], - } -) -update_region.Execute() - - -############################################################################### -# Set mesh control options -# ~~~~~~~~~~~~~~~~~~~~~~~~ -# Set mesh control options. - -meshing.workflow.TaskObject["Choose Mesh Control Options"].Execute() - -############################################################################### -# Generate surface mesh -# ~~~~~~~~~~~~~~~~~~~~~ -# Generate the surface mesh. - -############################################################################### -# .. image:: /_static/exhaust_system_013.png -# :width: 500pt -# :align: center - -meshing.workflow.TaskObject["Generate the Surface Mesh"].Execute() - -############################################################################### -# Confirm and update boundaries -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Confirm and update the boundaries. - -meshing.workflow.TaskObject["Update Boundaries"].Execute() - -############################################################################### -# Add boundary layers -# ~~~~~~~~~~~~~~~~~~~ -# Add boundary layers. - -meshing.workflow.TaskObject["Add Boundary Layers"].AddChildToTask() - -meshing.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask() - -meshing.workflow.TaskObject["aspect-ratio_1"].Arguments.set_state( - { - "BLControlName": "aspect-ratio_1", - } -) -meshing.workflow.TaskObject["Add Boundary Layers"].Arguments.set_state({}) - -meshing.workflow.TaskObject["aspect-ratio_1"].Execute() - -############################################################################### -# Generate volume mesh -# ~~~~~~~~~~~~~~~~~~~~ -# Generate the volume mesh. - -############################################################################### -# .. image:: /_static/exhaust_system_014.png -# :width: 500pt -# :align: center -volume_mesh_gen = meshing.workflow.TaskObject["Generate the Volume Mesh"] -volume_mesh_gen.Arguments.set_state( - { - "AllRegionNameList": [ - "main", - "flow_pipe", - "outpipe3", - "object2", - "object1", - "void-region-1", - "fluid-region-1", - ], - "AllRegionSizeList": ["11.33375"] * 7, - "AllRegionVolumeFillList": ["none"] * 6 + ["tet"], - "EnableParallel": True, - } -) -volume_mesh_gen.Execute() - -############################################################################### -# Check mesh -# ~~~~~~~~~~ -# Check the mesh. - -meshing.tui.mesh.check_mesh() - -############################################################################### -# Solve and postprocess -# --------------------- -# Once you have completed the fault tolerate meshing workflow, you can solve and -# postprcess the results. -# -# Switch to solution mode -# ~~~~~~~~~~~~~~~~~~~~~~~ -# Switch to the solution mode. - -solver = meshing.switch_to_solver() - -solver.tui.mesh.check() - -############################################################################### -# Select turbulence model -# ~~~~~~~~~~~~~~~~~~~~~~~ -# Select the kw sst turbulence model. - -solver.tui.define.models.viscous.kw_sst("yes") - -############################################################################### -# Set velocity and turbulence boundary conditions for first inlet -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Set the velocity and turbulence boundary conditions for the first inlet -# (``inlet-1``). - -solver.tui.define.boundary_conditions.set.velocity_inlet( - "inlet-1", [], "vmag", "no", 1, "quit" -) - -############################################################################### -# Set same boundary conditions for other velocity inlets -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Set the same boundary conditions for the other velocity inlets (``inlet_2`` -# and ``inlet_3``). - -solver.tui.define.boundary_conditions.copy_bc("inlet-1", "inlet-2", "inlet-3", ()) - -############################################################################### -# Set boundary conditions at outlet -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Set the boundary conditions at the outlet (``outlet-1``). - -solver.tui.define.boundary_conditions.set.pressure_outlet( - "outlet-1", [], "turb-intensity", 5, "quit" -) -solver.tui.solve.monitors.residual.plot("yes") - -############################################################################### -# Initialize flow field -# ~~~~~~~~~~~~~~~~~~~~~ -# Initialize the flow field using hybrid initialization. - -solver.tui.solve.initialize.hyb_initialization() - -############################################################################### -# Start calculation -# ~~~~~~~~~~~~~~~~~ -# Start the calculation by requesting 100 iterations. - -############################################################################### -# .. image:: /_static/exhaust_system_015.png -# :width: 500pt -# :align: center - -solver.tui.solve.set.number_of_iterations(100) -solver.tui.solve.iterate() - -# solver.tui.report.volume_integrals.volume("fluid-region-1","()","yes","volume.vrp") - -############################################################################### -# Write the case and data files -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -solver.tui.file.write_case_data("exhaust_system.cas.h5", "yes") - -############################################################################### -# Configure graphics picture export -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Since Fluent is being run without the GUI, we will need to export plots as -# picture files. Edit the picture settings to use a custom resolution so that -# the images are large enough. - -picture = solver.tui.display.set.picture -# use-window-container TUI option not available inside containers or Ansys Lab environment -if "use_window_resolution" in dir(picture): - picture.use_window_resolution("no") -picture.x_resolution("1920") -picture.y_resolution("1440") - -############################################################################### -# Create path lines -# ~~~~~~~~~~~~~~~~~ -# Create path lines highlighting the flow field, display it, then export the -# image for inspection. - -############################################################################### -# .. image:: /_static/exhaust_system_016.png -# :width: 500pt -# :align: center - -solver.tui.display.objects.create( - "pathlines", - "pathlines-1", - "field", - "time", - "accuracy-control", - "tolerance", - "0.001", - "skip", - "5", - "surfaces-list", - "inlet-1", - "inlet-2", - "inlet-3", - "()", - "quit", -) -solver.tui.display.objects.display("pathlines-1") - -views = solver.tui.display.views -views.restore_view("isometric") -views.auto_scale() -solver.tui.display.save_picture("pathlines-1.png") - -############################################################################### -# Create iso-surface -# ~~~~~~~~~~~~~~~~~~ -# Create an iso-surface through the manifold geometry. - -solver.tui.surface.iso_surface( - "x-coordinate", - "surf-x-coordinate", - "()", - "fluid-region-1", - "()", - "0.38", - "()", -) - -############################################################################### -# Create contours of velocity magnitude -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create contours of the velocity magnitude throughout the manifold -# along with the mesh. Display it and export the image for inspection. - -############################################################################### -# .. image:: /_static/exhaust_system_017.png -# :width: 500pt -# :align: center - -solver.tui.display.objects.create( - "contour", - "contour-velocity", - "field", - "velocity-magnitude", - "surfaces-list", - "surf-x-coordinate", - "()", - "node-values?", - "no", - "range-option", - "auto-range-on", - "global-range?", - "no", - "quit", - "quit", -) -solver.tui.display.objects.create("mesh", "mesh-1", "surfaces-list", "*", "()", "quit") - -solver.tui.display.objects.display("contour-velocity") - -views.restore_view("right") -views.auto_scale() -solver.tui.display.save_picture("contour-velocity.png") - -############################################################################### -# Create scene -# ~~~~~~~~~~~~ -# Create a scene containing the mesh and the contours. Display it and export -# the image for inspection. - -############################################################################### -# .. image:: /_static/exhaust_system_018.png -# :width: 500pt -# :align: center - -solver.tui.display.objects.create( - "scene", - "scene-1", - "graphics-objects", - "add", - "mesh-1", - "transparency", - "90", - "quit", - "add", - "contour-velocity", - "quit", - "quit", - "quit", -) -solver.tui.display.objects.display("scene-1") - -camera = solver.tui.display.views.camera -camera.position("1.70", "1.14", "0.29") -camera.up_vector("-0.66", "0.72", "-0.20") -views.auto_scale() -solver.tui.display.save_picture("scene-1.png") - -######################################################################### -# Close Fluent -# ~~~~~~~~~~~~ -# Close Fluent. - -solver.exit() diff --git a/examples/00-fluent/exhaust_system_settings_api.py b/examples/00-fluent/exhaust_system_settings_api.py index ed015072ea99..b158d6bd3fcf 100644 --- a/examples/00-fluent/exhaust_system_settings_api.py +++ b/examples/00-fluent/exhaust_system_settings_api.py @@ -535,13 +535,6 @@ ) volume_mesh_gen.Execute() -############################################################################### -# Check mesh -# ~~~~~~~~~~ -# Check the mesh. - -meshing.tui.mesh.check_mesh() - ############################################################################### # Solve and postprocess # --------------------- diff --git a/examples/00-fluent/external_compressible_flow.py b/examples/00-fluent/external_compressible_flow.py index e7bb000dfd09..f3c95c3d7613 100644 --- a/examples/00-fluent/external_compressible_flow.py +++ b/examples/00-fluent/external_compressible_flow.py @@ -199,19 +199,12 @@ volume_mesh_gen.Execute() -############################################################################### -# Check mesh in meshing mode -# ~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Check the mesh in meshing mode. - -meshing.tui.mesh.check_mesh() - ############################################################################### # Save mesh file # ~~~~~~~~~~~~~~ # Save the mesh file (``wing.msh.h5``). -meshing.tui.file.write_mesh("wing.msh.h5") +meshing.meshing.File.WriteMesh(FileName="wing.msh.h5") ############################################################################### # Solve and postprocess diff --git a/examples/00-fluent/mixing_elbow.py b/examples/00-fluent/mixing_elbow.py deleted file mode 100644 index ba6726b690bc..000000000000 --- a/examples/00-fluent/mixing_elbow.py +++ /dev/null @@ -1,602 +0,0 @@ -""".. _ref_mixing_elbow_tui_api: - -Watertight geometry meshing workflow ------------------------------------- -This example sets up and solves a three-dimensional turbulent fluid flow -and heat transfer problem in a mixing elbow, which is common in piping -systems in power plants and process industries. Predicting the flow field -and temperature field in the area of the mixing region is important to -designing the junction properly. - -This example uses the guided workflow for watertight geometry meshing -because it is appropriate for geometries that can have no imperfections, -such as gaps and leakages. - -**Workflow tasks** - -The watertight geometry meshing workflow guides you through these tasks: - -- Import a CAD geometry -- Generate a surface mesh -- Describe the geometry -- Generate a volume mesh - -**Problem description** - -A cold fluid at 20 deg C flows into the pipe through a large inlet. It then mixes -with a warmer fluid at 40 deg C that enters through a smaller inlet located at -the elbow. The pipe dimensions are in inches, and the fluid properties and -boundary conditions are given in SI units. Because the Reynolds number for the -flow at the larger inlet is ``50, 800``, a turbulent flow model is required. -""" - -############################################################################### -# Example Setup -# ------------- -# Before you can use the watertight geometry meshing workflow, you must set up the -# example and initialize this workflow. -# -# Perform required imports -# ~~~~~~~~~~~~~~~~~~~~~~~~ -# Perform required imports, which includes downloading and importing -# the geometry file. - -# sphinx_gallery_thumbnail_path = '_static/mixing_elbow.png' -import ansys.fluent.core as pyfluent -from ansys.fluent.core import examples - -import_file_name = examples.download_file("mixing_elbow.pmdb", "pyfluent/mixing_elbow") - -############################################################################### -# Launch Fluent -# ~~~~~~~~~~~~~ -# Launch Fluent as a service in meshing mode with double precision running on -# two processors. - -meshing = pyfluent.launch_fluent( - precision="double", - processor_count=2, - mode="meshing", -) - - -############################################################################### -# Initialize workflow -# ~~~~~~~~~~~~~~~~~~~ -# Initialize the watertight geometry meshing workflow. - -meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") - - -############################################################################### -# Watertight geometry meshing workflow -# ------------------------------------ -# The fault-tolerant meshing workflow guides you through the several tasks that -# follow. -# -# Import CAD and set length units -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Import the CAD geometry and set the length units to inches. -geo_import = meshing.workflow.TaskObject["Import Geometry"] -geo_import.Arguments = { - "FileName": import_file_name, - "LengthUnit": "in", -} - -# Import geometry -# ~~~~~~~~~~~~~~~ -# Import the geometry. - -meshing.upload(import_file_name) -geo_import.Execute() - -############################################################################### -# Add local sizing -# ~~~~~~~~~~~~~~~~ -# Add local sizing. This task asks whether you want to add local sizing controls -# to the faceted geometry. You can keep the default settings and execute the task. -add_local_sizing = meshing.workflow.TaskObject["Add Local Sizing"] -add_local_sizing.AddChildToTask() -add_local_sizing.Execute() - -############################################################################### -# Generate surface mesh -# ~~~~~~~~~~~~~~~~~~~~~ -# Generate the surface mash. In this task, you can set various properties of the -# surface mesh for the faceted geometry. For ``"MaxSize"``, set ``0.3``. -surface_mesh_gen = meshing.workflow.TaskObject["Generate the Surface Mesh"] -surface_mesh_gen.Arguments = {"CFDSurfaceMeshControls": {"MaxSize": 0.3}} -surface_mesh_gen.Execute() - -############################################################################### -# Describe geometry -# ~~~~~~~~~~~~~~~~~ -# Describe the geometry. In this task, you are prompted with questions -# relating to the nature of the imported geometry, which defines -# the fluid region. The geometry consists of only fluid regions. -describe_geo = meshing.workflow.TaskObject["Describe Geometry"] -describe_geo.UpdateChildTasks(SetupTypeChanged=False) -describe_geo.Arguments = { - "SetupType": "The geometry consists of only fluid regions with no voids" -} -describe_geo.UpdateChildTasks(SetupTypeChanged=True) -describe_geo.Execute() - -############################################################################### -# Update boundaries -# ~~~~~~~~~~~~~~~~~ -# Update the boundaries. Set ``"BoundaryLabelTypeList"`` to ``"wall"`` and -# update the boundaries. -update_boundaries = meshing.workflow.TaskObject["Update Boundaries"] -update_boundaries.Arguments = { - "BoundaryLabelList": ["wall-inlet"], - "BoundaryLabelTypeList": ["wall"], - "OldBoundaryLabelList": ["wall-inlet"], - "OldBoundaryLabelTypeList": ["velocity-inlet"], -} -update_boundaries.Execute() - -############################################################################### -# Update regions -# ~~~~~~~~~~~~~~ -# Update the regions. In this task, you can review the names and types of -# the various regions that have been generated from your imported geometry and -# change them as needed. You can keep the default settings. - -meshing.workflow.TaskObject["Update Regions"].Execute() - -############################################################################### -# Add boundary layers -# ~~~~~~~~~~~~~~~~~~~ -# Add boundary layers, which consist of setting properties for the -# boundary layer mesh. You can keep the default settings. -add_boundary_layers = meshing.workflow.TaskObject["Add Boundary Layers"] -add_boundary_layers.AddChildToTask() -add_boundary_layers.InsertCompoundChildTask() -smooth_transition_1 = meshing.workflow.TaskObject["smooth-transition_1"] -smooth_transition_1.Arguments = { - "BLControlName": "smooth-transition_1", -} -add_boundary_layers.Arguments = {} -smooth_transition_1.Execute() - -############################################################################### -# Generate volume mesh -# ~~~~~~~~~~~~~~~~~~~~ -# Generate the volume mesh, which consists of setting properties for the -# volume mesh. Set ``"VolumeFill"`` to ``"poly-hexcore"``. -volume_mesh_gen = meshing.workflow.TaskObject["Generate the Volume Mesh"] -volume_mesh_gen.Arguments = { - "VolumeFill": "poly-hexcore", - "VolumeFillControls": { - "HexMaxCellLength": 0.3, - }, -} -volume_mesh_gen.Execute() - -############################################################################### -# .. image:: /_static/mixing_elbow_011.png -# :width: 500pt -# :align: center - -############################################################################### -# Check mesh in meshing mode -# ~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Check the mesh in meshing mode - -meshing.tui.mesh.check_mesh() - -############################################################################### -# Save mesh file -# ~~~~~~~~~~~~~~ -# Save the mesh file (``mixing_elbow.msh.h5``). - -meshing.tui.file.write_mesh("mixing_elbow.msh.h5") - -############################################################################### -# Solve and postprocess -# --------------------- -# Once you have completed the watertight geometry meshing workflow, you can -# solve and postprcess the results. -# -# Switch to solution mode -# ~~~~~~~~~~~~~~~~~~~~~~~ -# Switch to solution mode. Now that a high-quality mesh has been generated -# using Fluent in meshing mode, you can switch to solver mode to complete the -# setup of the simulation. Because you have just checked the mesh, set ``"yes"`` -# to switch to the solution mode. - -solver = meshing.switch_to_solver() - -############################################################################### -# Check mesh in solver mode -# ~~~~~~~~~~~~~~~~~~~~~~~~~ -# Check the mesh in solver mode. The mesh check lists the minimum and maximum -# x, y, and z values from the mesh in the default SI units of meters. It also -# reports a number of other mesh features that are checked. Any errors in the -# mesh are reported. Ensure that the minimum volume is not negative because -# Fluent cannot begin a calculation when this is the case. - -solver.tui.mesh.check() - -############################################################################### -# Enable heat transfer -# ~~~~~~~~~~~~~~~~~~~~ -# Enable heat transfer by activating the energy equation. - -solver.tui.define.models.energy("yes", ", ", ", ", ", ", ", ") - -############################################################################### -# Create material -# ~~~~~~~~~~~~~~~ -# Create a material named ``"water-liquid"``. - -solver.tui.define.materials.copy("fluid", "water-liquid") - -############################################################################### -# Set up cell zone conditions -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Set up the cell zone conditions for the fluid zone (``elbow-fluid``)``. Set the -# material to ``"water-liquid"``. - -solver.tui.define.boundary_conditions.fluid( - "elbow-fluid", - "yes", - "water-liquid", - "no", - "no", - "no", - "no", - "0", - "no", - "0", - "no", - "0", - "no", - "0", - "no", - "0", - "no", - "1", - "no", - "no", - "no", - "no", - "no", -) - -############################################################################### -# Set up boundary conditions for CFD analysis -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Set up the boundary conditions for the inlets, outlet, and walls for CFD -# analysis. - -# cold inlet (cold-inlet), Setting: Value: -# Velocity Specification Method: Magnitude, Normal to Boundary -velocity_inlet = solver.tui.define.boundary_conditions.set.velocity_inlet -velocity_inlet("cold-inlet", [], "vmag", "no", 0.4, "quit") -velocity_inlet("cold-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit") -velocity_inlet("cold-inlet", [], "turb-intensity", 5, "quit") -velocity_inlet("cold-inlet", [], "turb-hydraulic-diam", 4, "quit") -velocity_inlet("cold-inlet", [], "temperature", "no", 293.15, "quit") - -# hot inlet (hot-inlet), Setting: Value: -# Velocity Specification Method: Magnitude, Normal to Boundary - -velocity_inlet("hot-inlet", [], "vmag", "no", 1.2, "quit") -velocity_inlet("hot-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit") -velocity_inlet("hot-inlet", [], "turb-intensity", 5, "quit") -velocity_inlet("hot-inlet", [], "turb-hydraulic-diam", 1, "quit") -velocity_inlet("hot-inlet", [], "temperature", "no", 313.15, "quit") - -# pressure outlet (outlet), Setting: Value: -# Backflow Turbulent Intensity: 5 [%] -# Backflow Turbulent Viscosity Ratio: 4 -pressure_outlet = solver.tui.define.boundary_conditions.set.pressure_outlet -pressure_outlet("outlet", [], "turb-intensity", 5, "quit") -pressure_outlet("outlet", [], "turb-viscosity-ratio", 4, "quit") - -############################################################################### -# Enable plotting of residuals during calculation -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Enable plotting of residuals during the calculation. - -solver.tui.solve.monitors.residual.plot("yes") - -############################################################################### -# Create surface report definition -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create a surface report definition of the average temperature at the outlet -# named ``"outlet-temp-avg"``. - -solver.tui.solve.report_definitions.add( - "outlet-temp-avg", - "surface-massavg", - "field", - "temperature", - "surface-names", - "outlet", - "()", - "quit", -) - -############################################################################### -# Create expression report definition -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create a report definition of single value expression type computing the difference -# of area-averaged static pressure over cold-inlet and oulet. The name of the -# report definition is ``"ave-pressure-diff"``. - -solver.tui.solve.report_definitions.add( - "ave-pressure-diff", - "single-val-expression", - "define", - "\"AreaAve(StaticPressure, ['cold-inlet'])-AreaAve(StaticPressure, ['outlet'])\"", - "quit", -) - -############################################################################### -# Create convergence condition -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create a convergence condition for ``outlet-temp-avg``. - -# - Set ``"add"`` to ``"con-outlet-temp-avg"``. -# - Set ``"report-defs"`` to ``"outlet-temp-avg"``. -# - Set ``"stop-criterion"`` to ``"1e-04"``. -# - Set ``"initial-values-to-ignore"`` to ``"20"``. -# - Set ``"previous-values-to-consider"`` to ``"15"``. -# - Set ``"print?"``to ``"yes"``. -# - Set ``"frequency"`` to ``"3"``. -# -# These settings cause Fluent to consider the solution converged when the -# surface report definition value for each of the previous 15 iterations is -# within 0.001% of the current value. Convergence of the values is checked -# every 3 iterations. The first 20 iterations are ignored, allowing for any -# initial solution dynamics to settle out. Note that the value printed to the -# console is the deviation between the current and previous iteration values -# only. - -solver.tui.solve.convergence_conditions( - "conv-reports", - "add", - "con-outlet-temp-avg", - "initial-values-to-ignore", - "20", - "previous-values-to-consider", - "15", - "print?", - "yes", - "report-defs", - "outlet-temp-avg", - "stop-criterion", - "1e-04", - "quit", - "quit", - "condition", - "1", - "frequency", - "3", - "quit", -) -solver.tui.solve.convergence_conditions("frequency", "3", "quit") - -############################################################################### -# Initialize flow field -# ~~~~~~~~~~~~~~~~~~~~~ -# Initialize the flow field using hybrid initialization. - -solver.tui.solve.initialize.hyb_initialization() - -############################################################################### -# Save case file -# ~~~~~~~~~~~~~~ -# Solve the case file (``mixing_elbow1.cas.h5``). - -solver.tui.file.write_case("mixing_elbow1.cas.h5") - -############################################################################### -# Solve for 100 iterations -# ~~~~~~~~~~~~~~~~~~~~~~~~ -# Solve for 100 iterations. - -solver.tui.solve.iterate(100) - -############################################################################### -# .. image:: /_static/mixing_elbow_012.png -# :width: 500pt -# :align: center - -############################################################################### -# .. image:: /_static/mixing_elbow_013.png -# :width: 500pt -# :align: center - -############################################################################### -# Save data file -# ~~~~~~~~~~~~~~ -# Save the data file (``mixing_elbow1.dat.h5``). - -solver.tui.file.write_data("mixing_elbow1.dat.h5") - -############################################################################### -# Configure graphics picture export -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Since Fluent is being run without the GUI, we will need to export plots as -# picture files. Edit the picture settings to use a custom resolution so that -# the images are large enough. - -picture = solver.tui.display.set.picture -# use-window-container TUI option not available inside containers or Ansys Lab environment -if "use_window_resolution" in dir(picture): - picture.use_window_resolution("no") -picture.x_resolution("1920") -picture.y_resolution("1440") - -############################################################################### -# Create definition for velocity magnitude contours -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create and display a definition for the velocity magnitude contours on the -# symmetry plane. Then display it and export the image for inspection. -# -# - Set ``"contour"`` to ``"contour-vel"``. -# - Set ``"field"`` to ``"velocity-magnitude"``. -# - Set ``"surfaces-list"`` to ``"symmetry-xyplane"``. -# - Set ``"display"`` to ``"contour-vel contour"``. - -solver.tui.display.objects.create( - "contour", - "contour-vel", - "filled?", - "yes", - "node-values?", - "yes", - "field", - "velocity-magnitude", - "surfaces-list", - "symmetry-xyplane", - "()", - "coloring", - "banded", - "quit", -) - -solver.tui.display.objects.display("contour-vel") - -views = solver.tui.display.views -views.restore_view("front") -views.auto_scale() -solver.tui.display.save_picture("contour-vel.png") - -############################################################################### -# .. image:: /_static/mixing_elbow_014.png -# :width: 500pt -# :align: center - -############################################################################### -# Create definition for temperature contours -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create and display a definition for temperature contours on the symmetry -# plane. Then display it and export the image for inspection. -# -# - Set ``"contour"`` to ``"contour-temp"``. -# - Set ``"field"`` to ``"temperature"``. -# - Set ``"surfaces-list"`` to ``"symmetry-xyplane"``. -# - Set ``"display"`` to ``"contour-temp contour"``. - -solver.tui.display.objects.create( - "contour", - "contour-temp", - "filled?", - "yes", - "node-values?", - "yes", - "field", - "temperature", - "surfaces-list", - "symmetry-xyplane", - "()", - "coloring", - "smooth", - "quit", -) - -solver.tui.display.objects.display("contour-temp") - -views = solver.tui.display.views -views.restore_view("front") -views.auto_scale() -solver.tui.display.save_picture("contour-temp.png") - -############################################################################### -# .. image:: /_static/mixing_elbow_015.png -# :width: 500pt -# :align: center - -############################################################################### -# Create velocity vectors -# ~~~~~~~~~~~~~~~~~~~~~~~ -# Create and display velocity vectors on the symmetry-xyplane plane. Then -# display it and export the image for inspection. -# -# - Set ``"vector"`` to ``"vector-vel"``. -# - Set ``"style"`` to ``"arrow"``. -# - Set ``"surface-list"`` to ``"symmetry-xyplane"``. -# - Set ``"scale"`` to ``"4"``. -# - Set ``"skip"`` to ``"2"``. - -solver.tui.display.objects.create( - "vector", - "vector-vel", - "style", - "arrow", - "surface-list", - "symmetry-xyplane", - "()", - "scale", - "scale-f", - "4", - "quit", - "skip", - "2", - "quit", -) - -solver.tui.display.objects.display("vector-vel") - -views = solver.tui.display.views -views.restore_view("front") -views.auto_scale() -solver.tui.display.save_picture("vector-vel.png") - -############################################################################### -# .. image:: /_static/mixing_elbow_tui_016.png -# :width: 500pt -# :align: center - -############################################################################### -# Create iso-surface -# ~~~~~~~~~~~~~~~~~~ -# Create an iso-surface representing the intersection of the plane z=0 and the -# surface outlet. Name it ``"z=0_outlet"``. - -solver.tui.surface.iso_surface( - "z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()" -) - -############################################################################### -# Display and save XY plot -# ~~~~~~~~~~~~~~~~~~~~~~~~~ -# Display and save an XY plot of the temperature profile across the centerline -# of the outlet for the initial solution. - -solver.tui.display.objects.create( - "xy", - "xy-outlet-temp", - "y-axis-function", - "temperature", - "surfaces-list", - "z=0_outlet", - "()", - "quit", -) - -############################################################################### -# .. image:: /_static/mixing_elbow_017.png -# :width: 500pt -# :align: center - -############################################################################### -# Write final case file and data -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Write the final case file and the data. - -solver.tui.file.write_case_data("mixing_elbow2_tui.cas.h5") - -######################################################################### -# Close Fluent -# ~~~~~~~~~~~~ -# Close Fluent. - -solver.exit() - -############################################################################### diff --git a/examples/00-fluent/modeling_cavitation.py b/examples/00-fluent/modeling_cavitation.py index 78a73400676c..2e32a2085cb6 100644 --- a/examples/00-fluent/modeling_cavitation.py +++ b/examples/00-fluent/modeling_cavitation.py @@ -41,10 +41,7 @@ # the geometry file. # sphinx_gallery_thumbnail_path = '_static/cavitation_model_thumb.png' -import os -os.environ["PYFLUENT_FLUENT_ROOT"] = r"C:\ANSYSDev\ANSYSDev\vNNN\fluent" -os.environ["AWP_ROOT251"] = r"C:\Program Files\ANSYS Inc\v241" import ansys.fluent.core as pyfluent from ansys.fluent.core import examples @@ -306,7 +303,7 @@ ############################################################################### # Mirror the display around the symmetry plane to show the full model. -solver.tui.display.set.mirror_zones(["symm_2", "symm_1"]) +solver.results.graphics.views.mirror_zones = ["symm_2", "symm_1"] graphics.contour["contour_static_pressure"].display() @@ -359,6 +356,6 @@ # Save case to 'cav.cas.h5' and exit -solver.file.write_case(file_name="cav") +solver.file.write_case(file_name="cav.cas.h5") solver.exit() From 4fe08f40d81133e45d4a5b3cfe161ebb8d62a2eb Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 10 Jul 2024 13:56:50 +0530 Subject: [PATCH 2/2] restore meshing tui calls --- examples/00-fluent/exhaust_system_settings_api.py | 7 +++++++ examples/00-fluent/external_compressible_flow.py | 7 +++++++ examples/00-fluent/modeling_cavitation.py | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/00-fluent/exhaust_system_settings_api.py b/examples/00-fluent/exhaust_system_settings_api.py index b158d6bd3fcf..ed015072ea99 100644 --- a/examples/00-fluent/exhaust_system_settings_api.py +++ b/examples/00-fluent/exhaust_system_settings_api.py @@ -535,6 +535,13 @@ ) volume_mesh_gen.Execute() +############################################################################### +# Check mesh +# ~~~~~~~~~~ +# Check the mesh. + +meshing.tui.mesh.check_mesh() + ############################################################################### # Solve and postprocess # --------------------- diff --git a/examples/00-fluent/external_compressible_flow.py b/examples/00-fluent/external_compressible_flow.py index f3c95c3d7613..119524a85750 100644 --- a/examples/00-fluent/external_compressible_flow.py +++ b/examples/00-fluent/external_compressible_flow.py @@ -199,6 +199,13 @@ volume_mesh_gen.Execute() +############################################################################### +# Check mesh in meshing mode +# ~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Check the mesh in meshing mode. + +meshing.tui.mesh.check_mesh() + ############################################################################### # Save mesh file # ~~~~~~~~~~~~~~ diff --git a/examples/00-fluent/modeling_cavitation.py b/examples/00-fluent/modeling_cavitation.py index 2e32a2085cb6..07c9fce56424 100644 --- a/examples/00-fluent/modeling_cavitation.py +++ b/examples/00-fluent/modeling_cavitation.py @@ -303,7 +303,7 @@ ############################################################################### # Mirror the display around the symmetry plane to show the full model. -solver.results.graphics.views.mirror_zones = ["symm_2", "symm_1"] +solver.settings.results.graphics.views.mirror_zones = ["symm_2", "symm_1"] graphics.contour["contour_static_pressure"].display() @@ -356,6 +356,6 @@ # Save case to 'cav.cas.h5' and exit -solver.file.write_case(file_name="cav.cas.h5") +solver.settings.file.write_case(file_name="cav.cas.h5") solver.exit()