diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc80e9647859..8c25b33de6cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,8 +131,8 @@ jobs: - name: Build Documentation run: | - pip install -r requirements_docs.txt - make -C doc html + pip install -r requirements_docs.txt + xvfb-run make -C doc html SPHINXOPTS="-v" touch doc/_build/html/.nojekyll echo "fluentdocs.pyansys.com" >> doc/_build/html/CNAME env: diff --git a/doc/source/conf.py b/doc/source/conf.py index 54c2124d6c3e..135f8d40a187 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -4,11 +4,32 @@ import subprocess import sys +import numpy as np from pyansys_sphinx_theme import pyansys_logo_black +import pyvista from sphinx_gallery.sorting import FileNameSortKey from ansys.fluent.core import __version__ +# Manage errors +pyvista.set_error_output_file("errors.txt") + +# Ensure that offscreen rendering is used for docs generation +pyvista.OFF_SCREEN = True + +# must be less than or equal to the XVFB window size +pyvista.rcParams["window_size"] = np.array([1024, 768]) + +# Save figures in specified directory +pyvista.FIGURE_PATH = os.path.join( + os.path.abspath("./images/"), "auto-generated/" +) +if not os.path.exists(pyvista.FIGURE_PATH): + os.makedirs(pyvista.FIGURE_PATH) + +# necessary when building the sphinx gallery +pyvista.BUILDING_GALLERY = True + # -- Project information ----------------------------------------------------- project = "ansys.fluent.core" @@ -95,7 +116,6 @@ copybutton_prompt_text = r">>> ?|\.\.\. " copybutton_prompt_is_regexp = True -templates_path = ["_templates"] _THIS_DIR = os.path.dirname(__file__) _START_FLUENT_FILE = os.path.normpath( @@ -110,21 +130,15 @@ def _start_or_stop_fluent_container(gallery_conf, fname, when): start_instance = bool(int(os.getenv("PYFLUENT_START_INSTANCE", "1"))) if not start_instance: if when == "before": - if fname in [ - "mixing_elbow_settings_api.py", - "mixing_elbow_tui_api.py", - ]: - args = ["3ddp", "-t4", "-meshing"] - elif fname in [ - "exhaust_system_settings_api.py", - "exhaust_system_tui_api.py", - ]: + if fname in ["mixing_elbow.py", "exhaust_system.py"]: args = ["3ddp", "-t2", "-meshing"] elif fname in [ "parametric_static_mixer_1.py", "parametric_static_mixer_2.py", "parametric_static_mixer_3.py", ]: + args = ["3ddp", "-t2"] + elif fname in ["post_processing_exhaust_manifold.py"]: args = ["3ddp", "-t4"] subprocess.run([sys.executable, _START_FLUENT_FILE] + args) elif when == "after": diff --git a/examples/00-fluent/exhaust_system_tui_api.py b/examples/00-fluent/exhaust_system.py similarity index 99% rename from examples/00-fluent/exhaust_system_tui_api.py rename to examples/00-fluent/exhaust_system.py index d6709444c40e..ee0a6fb41d5e 100644 --- a/examples/00-fluent/exhaust_system_tui_api.py +++ b/examples/00-fluent/exhaust_system.py @@ -1,7 +1,7 @@ """.. _ref_exhaust_system_tui_api: -Exhaust System: Fault-tolerant Meshing (TUI API) ------------------------------------------------- +Exhaust System: Fault-tolerant Meshing +---------------------------------------------- This tutorial illustrates the setup and solution of a three-dimensional turbulent fluid flow in a manifold exhaust system. The manifold configuration @@ -47,7 +47,7 @@ ) ############################################################################### -# Start Fluent in double precision running on 4 processors +# Start Fluent in double precision running on 2 processors session = pyfluent.launch_fluent( meshing_mode=True, precision="double", processor_count=2 diff --git a/examples/00-fluent/exhaust_system_settings_api.py b/examples/00-fluent/exhaust_system_settings_api.py deleted file mode 100755 index 909188f225cc..000000000000 --- a/examples/00-fluent/exhaust_system_settings_api.py +++ /dev/null @@ -1,675 +0,0 @@ -""".. _ref_exhaust_system_settings_api: - -Exhaust System: Fault-tolerant Meshing (Settings API) ------------------------------------------------------ - -This tutorial illustrates the setup and solution of a three-dimensional -turbulent fluid flow in a manifold exhaust system. The manifold configuration -is encountered in the automotive industry. It is often important to predict -the flow field in the area of the mixing region in order to properly design -the junction. You will use the Fault-tolerant Meshing guided workflow, which -unlike the watertight workflow used in Fluid Flow in a Mixing Elbow, is -appropriate for geometries with imperfections, such as gaps and leakages. - -This tutorial demonstrates how to do the following in Ansys Fluent: - - -- Use the Fault-tolerant Meshing guided workflow to: - - 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 - - Setup size controls - - Generate a volume mesh -- Set up appropriate physics and boundary conditions. -- Calculate a solution. -- Review the results of the simulation. - -Problem Description: - -Air flows through the three inlets with a uniform velocity of 1 m/s, and then -exits through the outlet. A small pipe is placed in the main portion of the -manifold where edge extraction will be considered. There is also a known small -leakage included that will be addressed in the meshing portion of the tutorial -to demonstrate the automatic leakage detection aspects of the meshing workflow. -""" - -############################################################################### -# First, connect with a Fluent server - -import ansys.fluent.core as pyfluent -from ansys.fluent.core import examples - -import_filename = examples.download_file( - "exhaust_system.fmd", "pyfluent/exhaust_system" -) - -############################################################################### -# Start Fluent in double precision running on 4 processors - -session = pyfluent.launch_fluent( - meshing_mode=True, precision="double", processor_count=2 -) - -############################################################################### -# Select the Fault Tolerant Meshing Workflow - -session.workflow.InitializeWorkflow(WorkflowType="Fault-tolerant Meshing") - -############################################################################### -# Import the CAD geometry (exhaust_system.fmd). Perform some selective part -# management. - -session.part_management.InputFileChanged( - FilePath=import_filename, IgnoreSolidNames=False, PartPerBody=False -) -session.PMFileManagement.FileManager.LoadFiles() -session.part_management.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", - ] -) -session.part_management.ObjectSetting[ - "DefaultObjectSetting" -].OneZonePer.setState("part") -session.workflow.TaskObject[ - "Import CAD and Part Management" -].Arguments.setState( - { - "Context": 0, - "CreateObjectPer": "Custom", - "FMDFileName": "import_filenamed", - "FileLoaded": "yes", - "ObjectSetting": "DefaultObjectSetting", - "Options": { - "Line": False, - "Solid": False, - "Surface": False, - }, - } -) -session.workflow.TaskObject["Import CAD and Part Management"].Execute() - -############################################################################### -# Provide a description for the geometry and the flow characteristics. - -session.workflow.TaskObject["Describe Geometry and Flow"].Arguments.setState( - { - "AddEnclosure": "No", - "CloseCaps": "Yes", - "FlowType": "Internal flow through the object", - } -) -session.workflow.TaskObject["Describe Geometry and Flow"].UpdateChildTasks( - SetupTypeChanged=False -) -session.workflow.TaskObject["Describe Geometry and Flow"].Arguments.setState( - { - "AddEnclosure": "No", - "CloseCaps": "Yes", - "DescribeGeometryAndFlowOptions": { - "AdvancedOptions": True, - "ExtractEdgeFeatures": "Yes", - }, - "FlowType": "Internal flow through the object", - } -) -session.workflow.TaskObject["Describe Geometry and Flow"].UpdateChildTasks( - SetupTypeChanged=False -) -session.workflow.TaskObject["Describe Geometry and Flow"].Execute() - -############################################################################### -# Cover any openings in your geometry. - -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "CreatePatchPreferences": { - "ShowCreatePatchPreferences": False, - }, - "PatchName": "inlet-1", - "SelectionType": "zone", - "ZoneSelectionList": ["inlet.1"], - } -) -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "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"], - } -) -session.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask() - -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].InsertCompoundChildTask() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState({}) -session.workflow.TaskObject["inlet-1"].Execute() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "PatchName": "inlet-2", - "SelectionType": "zone", - "ZoneSelectionList": ["inlet.2"], - } -) -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "PatchName": "inlet-2", - "SelectionType": "zone", - "ZoneLocation": [ - "1", - "441.68205", - "-361.34322", - "-301.88668", - "486.96205", - "-332.84759", - "-266.69751", - "inlet.2", - ], - "ZoneSelectionList": ["inlet.2"], - } -) -session.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask() - -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].InsertCompoundChildTask() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState({}) -session.workflow.TaskObject["inlet-2"].Execute() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "PatchName": "inlet-3", - "SelectionType": "zone", - "ZoneSelectionList": ["inlet"], - } -) -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "PatchName": "inlet-3", - "SelectionType": "zone", - "ZoneLocation": [ - "1", - "261.68205", - "-361.34322", - "-301.88668", - "306.96205", - "-332.84759", - "-266.69751", - "inlet", - ], - "ZoneSelectionList": ["inlet"], - } -) -session.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask() - -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].InsertCompoundChildTask() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState({}) -session.workflow.TaskObject["inlet-3"].Execute() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "PatchName": "outlet-1", - "SelectionType": "zone", - "ZoneSelectionList": ["outlet"], - "ZoneType": "pressure-outlet", - } -) -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState( - { - "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", - } -) -session.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask() - -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].InsertCompoundChildTask() -session.workflow.TaskObject[ - "Enclose Fluid Regions (Capping)" -].Arguments.setState({}) -session.workflow.TaskObject["outlet-1"].Execute() - -############################################################################### -# Extract edge features. - -session.workflow.TaskObject["Extract Edge Features"].Arguments.setState( - { - "ExtractMethodType": "Intersection Loops", - "ObjectSelectionList": ["flow_pipe", "main"], - } -) -session.workflow.TaskObject["Extract Edge Features"].AddChildToTask() - -session.workflow.TaskObject["Extract Edge Features"].InsertCompoundChildTask() - -session.workflow.TaskObject["edge-group-1"].Arguments.setState( - { - "ExtractEdgesName": "edge-group-1", - "ExtractMethodType": "Intersection Loops", - "ObjectSelectionList": ["flow_pipe", "main"], - } -) -session.workflow.TaskObject["Extract Edge Features"].Arguments.setState({}) - -session.workflow.TaskObject["edge-group-1"].Execute() - -############################################################################### -# Identify regions. - -session.workflow.TaskObject["Identify Regions"].Arguments.setState( - { - "SelectionType": "zone", - "X": 377.322045740589, - "Y": -176.800676988458, - "Z": -37.0764628583475, - "ZoneSelectionList": ["main.1"], - } -) -session.workflow.TaskObject["Identify Regions"].Arguments.setState( - { - "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"], - } -) -session.workflow.TaskObject["Identify Regions"].AddChildToTask() - -session.workflow.TaskObject["Identify Regions"].InsertCompoundChildTask() - -session.workflow.TaskObject["fluid-region-1"].Arguments.setState( - { - "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"], - } -) -session.workflow.TaskObject["Identify Regions"].Arguments.setState({}) - -session.workflow.TaskObject["fluid-region-1"].Execute() -session.workflow.TaskObject["Identify Regions"].Arguments.setState( - { - "MaterialPointsName": "void-region-1", - "NewRegionType": "void", - "ObjectSelectionList": ["inlet-1", "inlet-2", "inlet-3", "main"], - "X": 374.722045740589, - "Y": -278.9775145640143, - "Z": -161.1700719416913, - } -) -session.workflow.TaskObject["Identify Regions"].AddChildToTask() - -session.workflow.TaskObject["Identify Regions"].InsertCompoundChildTask() - -session.workflow.TaskObject["Identify Regions"].Arguments.setState({}) - -session.workflow.TaskObject["void-region-1"].Execute() - -############################################################################### -# Define thresholds for any potential leakages. - -session.workflow.TaskObject["Define Leakage Threshold"].Arguments.setState( - { - "AddChild": "yes", - "FlipDirection": True, - "PlaneDirection": "X", - "RegionSelectionSingle": "void-region-1", - } -) -session.workflow.TaskObject["Define Leakage Threshold"].AddChildToTask() - -session.workflow.TaskObject[ - "Define Leakage Threshold" -].InsertCompoundChildTask() -session.workflow.TaskObject["leakage-1"].Arguments.setState( - { - "AddChild": "yes", - "FlipDirection": True, - "LeakageName": "leakage-1", - "PlaneDirection": "X", - "RegionSelectionSingle": "void-region-1", - } -) -session.workflow.TaskObject["Define Leakage Threshold"].Arguments.setState( - { - "AddChild": "yes", - } -) -session.workflow.TaskObject["leakage-1"].Execute() - -############################################################################### -# Review your region settings. - -session.workflow.TaskObject["Update Region Settings"].Arguments.setState( - { - "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"], - } -) -session.workflow.TaskObject["Update Region Settings"].Execute() - - -############################################################################### -# Select options for controlling the mesh. - -session.workflow.TaskObject["Choose Mesh Control Options"].Execute() - -############################################################################### -# Generate the surface mesh. - -session.workflow.TaskObject["Generate the Surface Mesh"].Execute() - -############################################################################### -# Confirm and update the boundaries. - -session.workflow.TaskObject["Update Boundaries"].Execute() - -############################################################################### -# Add boundary layers. - -session.workflow.TaskObject["Add Boundary Layers"].AddChildToTask() - -session.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask() - -session.workflow.TaskObject["aspect-ratio_1"].Arguments.setState( - { - "BLControlName": "aspect-ratio_1", - } -) -session.workflow.TaskObject["Add Boundary Layers"].Arguments.setState({}) - -session.workflow.TaskObject["aspect-ratio_1"].Execute() - -############################################################################### -# Generate the volume mesh. - -session.workflow.TaskObject["Generate the Volume Mesh"].Arguments.setState( - { - "AllRegionNameList": [ - "main", - "flow_pipe", - "outpipe3", - "object2", - "object1", - "void-region-1", - "fluid-region-1", - ], - "AllRegionSizeList": ["11.33375"] * 7, - "AllRegionVolumeFillList": ["none"] * 6 + ["tet"], - "EnableParallel": True, - } -) -session.workflow.TaskObject["Generate the Volume Mesh"].Execute() - -############################################################################### -# Check the mesh. - -session.tui.meshing.mesh.check_mesh() - -############################################################################### -# Switch to Solution mode. - -session.tui.meshing.switch_to_solution_mode("yes") - -session.tui.solver.mesh.check() - -############################################################################### -# Set the units for length - -session.tui.solver.define.units("length", "mm") - -############################################################################### -# The settings objects provide a natural way to access and modify settings. -# The top-level settings object for a session can be accessed with the -# get_settings_root() method of the session object. -# Enabling the settings objects (Beta) -root = session.get_settings_root() - -############################################################################### -# Select kw sst turbulence model - -root.setup.models.viscous.k_omega_model = "sst" - -############################################################################### -# Set the velocity and turbulence boundary conditions for the first inlet -# (inlet-1). - -root.setup.boundary_conditions.velocity_inlet["inlet-1"].vmag = { - "option": "constant or expression", - "constant": 1, -} -############################################################################### -# Apply the same conditions for the other velocity inlet boundaries (inlet_2, -# and inlet_3). - -session.tui.solver.define.boundary_conditions.copy_bc( - "inlet-1", "inlet-2", "inlet-3", () -) - -############################################################################### -# Set the boundary conditions at the outlet (outlet-1). - -root.setup.boundary_conditions.pressure_outlet[ - "outlet-1" -].turb_intensity = 0.05 - -############################################################################### -# Enable the plotting of residuals during the calculation. -session.tui.solver.solve.monitors.residual.plot("yes") - -############################################################################### -# Initialize the flow field using the Initialization - -session.tui.solver.solve.initialize.hyb_initialization() - -############################################################################### -# Start the calculation by requesting 100 iterations - -session.tui.solver.solve.set.number_of_iterations(100) -session.tui.solver.solve.iterate() - -############################################################################### -# Monitor the total mass flow rate through the entire domain - -root.solution.report_definitions.volume["report-volume-int"] = {} -root.solution.report_definitions.volume[ - "report-volume-int" -].report_type = "volume-integral" -root.solution.report_definitions.volume["report-volume-int"].zone_names = [ - "fluid-region-1" -] -root.solution.report_definitions.compute(report_defs=["report-volume-int"]) - -############################################################################### -# Display path lines highlighting the flow field - -root.results.graphics.pathlines["pathlines-1"] = {} -root.results.graphics.pathlines["pathlines-1"].print_state() -root.results.graphics.pathlines["pathlines-1"].field = "time" -root.results.graphics.pathlines["pathlines-1"].skip = 5 -root.results.graphics.pathlines["pathlines-1"].surfaces_list = [ - "inlet-1", - "inlet-2", - "inlet-3", -] - -# root.results.graphics.pathlines["pathlines-1"].display() - - -############################################################################### -# Create an iso-surface through the manifold geometry. -# Using TUI API due to Issue #288 - -session.tui.solver.surface.iso_surface( - "x-coordinate", - "surf-x-coordinate", - "()", - "fluid-region-1", - "()", - "380", - "()", -) - -############################################################################### -# Create and define contours of velocity magnitude throughout the manifold -# along with the mesh. - -root.results.graphics.contour["contour-velocity"] = {} -root.results.graphics.contour["contour-velocity"].print_state() -root.results.graphics.contour["contour-velocity"].field = "velocity-magnitude" -root.results.graphics.contour["contour-velocity"].surfaces_list = [ - "surf-x-coordinate" -] -root.results.graphics.contour["contour-velocity"].node_values = False -root.results.graphics.contour[ - "contour-velocity" -].range_option.auto_range_on.global_range = False -# root.results.graphics.contour["contour-velocity"].display() - -root.results.graphics.mesh["mesh-1"] = {} -surface_list = root.results.graphics.mesh["mesh-1"].surfaces_list.get_attr( - "allowed-values" -) -root.results.graphics.mesh["mesh-1"].surfaces_list = surface_list -# root.results.graphics.mesh["mesh-1"].display() - - -############################################################################### -# Create a scene containing the mesh and the contours. -# Using the TUI API due to Issue #289 - -session.tui.solver.display.objects.create( - "scene", - "scene-1", - "graphics-objects", - "add", - "mesh-1", - "transparency", - "90", - "quit", - "add", - "contour-velocity", - "quit", - "quit", - "quit", -) -# session.tui.solver.display.objects.display("scene-1") - -############################################################################### -# Save case, data and exit. -# session.tui.solver.file.write_case_data("exhaust_system.cas.h5") - -# session.exit() diff --git a/examples/00-fluent/mixing_elbow_tui_api.py b/examples/00-fluent/mixing_elbow.py similarity index 73% rename from examples/00-fluent/mixing_elbow_tui_api.py rename to examples/00-fluent/mixing_elbow.py index e45050ff6c78..a5ef0885206d 100644 --- a/examples/00-fluent/mixing_elbow_tui_api.py +++ b/examples/00-fluent/mixing_elbow.py @@ -1,8 +1,7 @@ """.. _ref_mixing_elbow_tui_api: -Fluid Flow and Heat Transfer in a Mixing Elbow (TUI API) --------------------------------------------------------- - +Fluid Flow and Heat Transfer in a Mixing Elbow +---------------------------------------------- This example illustrates the setup and solution of a three-dimensional turbulent fluid flow and heat transfer problem in a mixing elbow. The mixing elbow configuration is encountered in piping systems in power plants and @@ -36,63 +35,62 @@ """ ############################################################################### - # First, download the geometry file and start Fluent as a service with -# Meshing Mode, Double Precision, Number of Processors 4 +# Meshing Mode, Double Precision, Number of Processors 2 +# Importing the graphics module - pyvista import ansys.fluent.core as pyfluent from ansys.fluent.core import examples +from ansys.fluent.post import set_config +from ansys.fluent.post.pyvista import Graphics + +set_config(blocking=True) import_filename = examples.download_file( "mixing_elbow.pmdb", "pyfluent/mixing_elbow" ) -s = pyfluent.launch_fluent( - meshing_mode=True, precision="double", processor_count="4" +session = pyfluent.launch_fluent( + meshing_mode=True, precision="double", processor_count=2 ) ############################################################################### - # Select the Watertight Geometry Meshing Workflow -s.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") +session.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") ############################################################################### - # Import the CAD geometry. For Length Units, select "in". # Execute the Import Geometry task. -s.workflow.TaskObject["Import Geometry"].Arguments = dict( +session.workflow.TaskObject["Import Geometry"].Arguments = dict( FileName=import_filename, LengthUnit="in" ) -s.workflow.TaskObject["Import Geometry"].Execute() +session.workflow.TaskObject["Import Geometry"].Execute() ############################################################################### - # Add local sizing: # In the Add Local Sizing task, you are prompted as to whether or not you would # like to add local sizing controls to the faceted geometry. For the purposes # of this example, you can keep the default setting. Execute to complete this # task # and proceed to the next task in the workflow. -s.workflow.TaskObject["Add Local Sizing"].AddChildToTask() -s.workflow.TaskObject["Add Local Sizing"].Execute() +session.workflow.TaskObject["Add Local Sizing"].AddChildToTask() +session.workflow.TaskObject["Add Local Sizing"].Execute() ############################################################################### - # Generate the surface mesh: # In the Generate the Surface Mesh task, you can set various properties of the # surface mesh for the faceted geometry. Specify 0.3 for Maximum Size. Execute # the Surface Mesh to complete this task and proceed to the next task in the # workflow. -s.workflow.TaskObject["Generate the Surface Mesh"].Arguments = { +session.workflow.TaskObject["Generate the Surface Mesh"].Arguments = { "CFDSurfaceMeshControls": {"MaxSize": 0.3} } -s.workflow.TaskObject["Generate the Surface Mesh"].Execute() +session.workflow.TaskObject["Generate the Surface Mesh"].Execute() ############################################################################### - # Describe the geometry: # When you select the Describe Geometry task, you are prompted with questions # relating to the nature of the imported geometry. Since the geometry defined @@ -100,121 +98,109 @@ # voids for Geometry Type. Execute Describe Geometry to complete this task and # proceed # to the next task in the workflow. -s.workflow.TaskObject["Describe Geometry"].UpdateChildTasks( +session.workflow.TaskObject["Describe Geometry"].UpdateChildTasks( SetupTypeChanged=False ) -s.workflow.TaskObject["Describe Geometry"].Arguments = dict( +session.workflow.TaskObject["Describe Geometry"].Arguments = dict( SetupType="The geometry consists of only fluid regions with no voids" ) -s.workflow.TaskObject["Describe Geometry"].UpdateChildTasks( +session.workflow.TaskObject["Describe Geometry"].UpdateChildTasks( SetupTypeChanged=True ) -s.workflow.TaskObject["Describe Geometry"].Execute() +session.workflow.TaskObject["Describe Geometry"].Execute() ############################################################################### - # Update Boundaries Task: # For the wall-inlet boundary, change the Boundary Type field to wall. Execute # Update Boundaries to complete this task and proceed to the next task in the # workflow. -s.workflow.TaskObject["Update Boundaries"].Arguments = { +session.workflow.TaskObject["Update Boundaries"].Arguments = { "BoundaryLabelList": ["wall-inlet"], "BoundaryLabelTypeList": ["wall"], "OldBoundaryLabelList": ["wall-inlet"], "OldBoundaryLabelTypeList": ["velocity-inlet"], } -s.workflow.TaskObject["Update Boundaries"].Execute() +session.workflow.TaskObject["Update Boundaries"].Execute() ############################################################################### - # Update your regions: # Select the Update Regions task, where you can review the names and types of # the various regions that have been generated from your imported geometry, and # change them as needed. Keep the default settings, and execute Update Regions. -s.workflow.TaskObject["Update Regions"].Execute() +session.workflow.TaskObject["Update Regions"].Execute() ############################################################################### - # Add Boundary Layers: # Select the Add Boundary Layers task, where you can set properties of the # boundary layer mesh. Keep the default settings, and Add Boundary Layers. -s.workflow.TaskObject["Add Boundary Layers"].AddChildToTask() -s.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask() -s.workflow.TaskObject["smooth-transition_1"].Arguments = { +session.workflow.TaskObject["Add Boundary Layers"].AddChildToTask() +session.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask() +session.workflow.TaskObject["smooth-transition_1"].Arguments = { "BLControlName": "smooth-transition_1", } -s.workflow.TaskObject["Add Boundary Layers"].Arguments = {} -s.workflow.TaskObject["smooth-transition_1"].Execute() +session.workflow.TaskObject["Add Boundary Layers"].Arguments = {} +session.workflow.TaskObject["smooth-transition_1"].Execute() ############################################################################### - # Generate the volume mesh: # Select the Generate the Volume Mesh task, where you can set properties of the # volume mesh. Select the poly-hexcore for Fill With. Execute Generate the # Volume Mesh. -s.workflow.TaskObject["Generate the Volume Mesh"].Arguments = { +session.workflow.TaskObject["Generate the Volume Mesh"].Arguments = { "VolumeFill": "poly-hexcore", "VolumeFillControls": { "HexMaxCellLength": 0.3, }, } -s.workflow.TaskObject["Generate the Volume Mesh"].Execute() +session.workflow.TaskObject["Generate the Volume Mesh"].Execute() ############################################################################### - # Check the mesh in Meshing mode -s.tui.meshing.mesh.check_mesh() +session.tui.meshing.mesh.check_mesh() ############################################################################### - # Save the mesh file (mixing_elbow.msh.h5) -# s.tui.meshing.file.write_mesh('mixing_elbow.msh.h5') +# session.tui.meshing.file.write_mesh('mixing_elbow.msh.h5') ############################################################################### - # Switch to Solution mode: # Now that a high-quality mesh has been generated using Ansys Fluent in meshing # mode, you can now switch to solver mode to complete the setup of the # simulation. We have just checked the mesh, so select Yes to switch to # solution mode. -s.tui.meshing.switch_to_solution_mode("yes") +session.tui.meshing.switch_to_solution_mode("yes") ############################################################################### - # Check the mesh in Solver mode: # The mesh check will list the minimum and maximum x, y, and z values from the # mesh in the default SI unit of meters. It will also report a number of other # mesh features that are checked. Any errors in the mesh will be reported at # this time. Ensure that the minimum volume is not negative, since Ansys Fluent # cannot begin a calculation when this is the case. -s.tui.solver.mesh.check() +session.tui.solver.mesh.check() ############################################################################### - # Set the working units for the mesh: # select "in" to set inches as the working unit for length. Note: Because the # default SI units will be used for everything except length, there is no need # to change any other units in this problem. If you want a different working # unit for length, other than inches (for example, millimeters), make the # appropriate change. -s.tui.solver.define.units("length", "in") +session.tui.solver.define.units("length", "in") ############################################################################### - # Enable heat transfer by activating the energy equation. -s.tui.solver.define.models.energy("yes", ", ", ", ", ", ", ", ") +session.tui.solver.define.models.energy("yes", ", ", ", ", ", ", ", ") ############################################################################### - # Create a new material called water-liquid. -s.tui.solver.define.materials.copy("fluid", "water-liquid") +session.tui.solver.define.materials.copy("fluid", "water-liquid") ############################################################################### - # Set up the cell zone conditions for the fluid zone (elbow-fluid). Select # water-liquid from the Material list. -s.tui.solver.define.boundary_conditions.fluid( +session.tui.solver.define.boundary_conditions.fluid( "elbow-fluid", "yes", "water-liquid", @@ -241,74 +227,69 @@ ) ############################################################################### - # Set up the boundary conditions for the inlets, outlet, and walls for your CFD # analysis. # cold inlet (cold-inlet), Setting: Value: # Velocity Specification Method: Magnitude, Normal to Boundary -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "cold-inlet", [], "vmag", "no", 0.4, "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "cold-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "cold-inlet", [], "turb-intensity", 5, "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "cold-inlet", [], "turb-hydraulic-diam", 4, "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "cold-inlet", [], "temperature", "no", 293.15, "quit" ) ############################################################################### - # hot inlet (hot-inlet), Setting: Value: # Velocity Specification Method: Magnitude, Normal to Boundary -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "hot-inlet", [], "vmag", "no", 1.2, "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "hot-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "hot-inlet", [], "turb-intensity", 5, "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "hot-inlet", [], "turb-hydraulic-diam", 1, "quit" ) -s.tui.solver.define.boundary_conditions.set.velocity_inlet( +session.tui.solver.define.boundary_conditions.set.velocity_inlet( "hot-inlet", [], "temperature", "no", 313.15, "quit" ) ############################################################################### - # pressure outlet (outlet), Setting: Value: # Backflow Turbulent Intensity: 5 [%] # Backflow Turbulent Viscosity Ratio: 4 -s.tui.solver.define.boundary_conditions.set.pressure_outlet( +session.tui.solver.define.boundary_conditions.set.pressure_outlet( "outlet", [], "turb-intensity", 5, "quit" ) -s.tui.solver.define.boundary_conditions.set.pressure_outlet( +session.tui.solver.define.boundary_conditions.set.pressure_outlet( "outlet", [], "turb-viscosity-ratio", 4, "quit" ) ############################################################################### - # Enable the plotting of residuals during the calculation. -s.tui.solver.solve.monitors.residual.plot("yes") +session.tui.solver.solve.monitors.residual.plot("yes") ############################################################################### - # Create a surface report definition of average temperature at the outlet # (outlet) called "outlet-temp-avg -s.tui.solver.solve.report_definitions.add( +session.tui.solver.solve.report_definitions.add( "outlet-temp-avg", "surface-massavg", "field", @@ -320,33 +301,6 @@ ) ############################################################################### - -# Create a surface report file called outlet-temp-avg-rfile using -# report-definition outlet-temp-avg -# s.tui.solver.solve.report_files.add( -# "outlet-temp-avg-rfile", -# "report-defs", -# "outlet-temp-avg", -# "()", -# "file-name", -# "outlet-temp-avg-rfile.out", -# "print?", -# "yes", -# "file-name", -# "outlet-temp-avg-rfile.out", -# "frequency", -# "3", -# "frequency-of", -# "iteration", -# "itr-index", -# "1", -# "run-index", -# "0", -# "quit", -# ) - -############################################################################### - # Create a convergence condition for outlet-temp-avg: # Provide con-outlet-temp-avg for Conditions. Select outlet-temp-avg Report # Definition. Provide 1e-5 for Stop Criterion. Provide 20 for Ignore Iterations @@ -361,7 +315,7 @@ # 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. -s.tui.solver.solve.convergence_conditions( +session.tui.solver.solve.convergence_conditions( "conv-reports", "add", "con-outlet-temp-avg", @@ -374,7 +328,7 @@ "report-defs", "outlet-temp-avg", "stop-criterion", - "1e-05", + "1e-04", "quit", "quit", "condition", @@ -383,45 +337,39 @@ "3", "quit", ) -s.tui.solver.solve.convergence_conditions("frequency", "3", "quit") +session.tui.solver.solve.convergence_conditions("frequency", "3", "quit") ############################################################################### - # Initialize the flow field using the Hybrid Initialization -s.tui.solver.solve.initialize.hyb_initialization() +session.tui.solver.solve.initialize.hyb_initialization() ############################################################################### - # Save the case file (mixing_elbow1.cas.h5). -# s.tui.solver.file.write_case('mixing_elbow1.cas.h5') +# session.tui.solver.file.write_case('mixing_elbow1.cas.h5') ############################################################################### - -# Solve for 150 Iterations. -s.tui.solver.solve.iterate(150) +# Solve for 100 Iterations. +session.tui.solver.solve.iterate(100) ############################################################################### - # Examine the mass flux report for convergence: Select cold-inlet, hot-inlet, # and outlet from the Boundaries selection list. -# s.tui.solver.report.fluxes.mass_flow( +# session.tui.solver.report.fluxes.mass_flow( # "no", "cold-inlet", "hot-inlet", "outlet", "()", "yes", "mass-flux1.flp" # ) ############################################################################### - # Save the data file (mixing_elbow1.dat.h5). -# s.tui.solver.file.write_data('mixing_elbow1.dat.h5') +# session.tui.solver.file.write_data('mixing_elbow1.dat.h5') ############################################################################### - # Create and display a definition for velocity magnitude contours on the # symmetry plane: # Provide contour-vel for Contour Name. Select velocity magnitude. Select # symmetry-xyplane from the Surfaces list. Display contour-vel contour. -s.tui.solver.display.objects.create( +session.tui.solver.display.objects.create( "contour", "contour-vel", "filled?", @@ -437,16 +385,15 @@ "banded", "quit", ) -# s.tui.solver.display.objects.display("contour-vel") +# session.tui.solver.display.objects.display("contour-vel") ############################################################################### - # Create and display a definition for temperature contours on the symmetry # plane: # Provide contour-temp for Contour Name. Select temperature. Select # symmetry-xyplane from the Surfaces list. Display contour-temp contour. -s.tui.solver.display.objects.create( +session.tui.solver.display.objects.create( "contour", "contour-temp", "filled?", @@ -462,16 +409,15 @@ "smooth", "quit", ) -# s.tui.solver.display.objects.display("contour-temp") +# session.tui.solver.display.objects.display("contour-temp") ############################################################################### - # Create and display velocity vectors on the symmetry-xyplane plane: # Provide vector-vel for Vector Name. Select arrow for the Style. Select # symmetry-xyplane from the Surfaces selection list. Provide 4 for Scale. Set # Skip to 2. -s.tui.solver.display.objects.create( +session.tui.solver.display.objects.create( "vector", "vector-vel", "style", @@ -487,22 +433,19 @@ "2", "quit", ) -# s.tui.solver.display.objects.display("vector-vel") +# session.tui.solver.display.objects.display("vector-vel") ############################################################################### - # Create an iso-surface representing the intersection of the plane z=0 and the # surface outlet. Name: z=0_outlet -s.tui.solver.surface.iso_surface( +session.tui.solver.surface.iso_surface( "z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()" ) ############################################################################### -# s.tui.solver.file.write_case_data("mixing_elbow1_tui.cas.h5") - # Display and save an XY plot of the temperature profile across the centerline # of the outlet for the initial solution -s.tui.solver.display.objects.create( +session.tui.solver.display.objects.create( "xy", "xy-outlet-temp", "y-axis-function", @@ -512,8 +455,8 @@ "()", "quit", ) -# s.tui.solver.display.objects.display("xy-outlet-temp") -# s.tui.solver.plot.plot( +# session.tui.solver.display.objects.display("xy-outlet-temp") +# session.tui.solver.plot.plot( # "yes", # "temp-1.xy", # "no", @@ -529,8 +472,44 @@ # ) ############################################################################### +# Mesh display using PyVista +graphics_session = Graphics(session) +mesh_1 = graphics_session.Meshes["mesh-1"] +mesh_1.show_edges = True +mesh_1.surfaces_list = [ + "cold-inlet", + "hot-inlet", + "wall-elbow", + "wall-inlet", + "symmetry-xyplane", + "outlet", +] + +mesh_1.display() + +############################################################################### +# Temperature Contour display using PyVista + +# contour_1 = graphics_session.Contours["contour_1"] +# contour_1.field = "temperature" +# contour_1.surfaces_list = [ +# "symmetry-xyplane" +# ] +# contour_1.display() + +############################################################################### +# Velocity Magnitude Contour display using PyVista + +# contour_2 = graphics_session.Contours["contour_2"] +# contour_2.field = "velocity-magnitude" +# contour_2.surfaces_list = [ +# "symmetry-xyplane" +# ] +# contour_2.display() + +############################################################################### # Write final case and data. -# s.tui.solver.file.write_case_data("mixing_elbow2_tui.cas.h5") +# session.tui.solver.file.write_case_data("mixing_elbow2_tui.cas.h5") ############################################################################### diff --git a/examples/00-fluent/mixing_elbow_settings_api.py b/examples/00-fluent/mixing_elbow_settings_api.py deleted file mode 100644 index a1b5f97c3b1e..000000000000 --- a/examples/00-fluent/mixing_elbow_settings_api.py +++ /dev/null @@ -1,531 +0,0 @@ -""".. _ref_mixing_elbow_settings_api: - -Fluid Flow and Heat Transfer in a Mixing Elbow (Settings API) -------------------------------------------------------------- - -This example illustrates the setup and solution of a three-dimensional -turbulent fluid flow and heat transfer problem in a mixing elbow. The mixing -elbow configuration is encountered in piping systems in power plants and -process industries. It is often important to predict the flow field and -temperature field in the area of the mixing region in order to properly design -the junction. - -This example demonstrates how to do the following: - -- Use the Watertight Geometry guided workflow to: - - Import a CAD geometry - - Generate a surface mesh - - Describe the geometry - - Generate a volume mesh -- Launch Ansys Fluent. -- Read an existing mesh file into Ansys Fluent. -- Use mixed units to define the geometry and fluid properties. -- Set material properties and boundary conditions for a turbulent - forced-convection problem. -- Create a surface report definition and use it as a convergence criterion. -- Calculate a solution using the pressure-based solver. -- Visually examine the flow and temperature fields using the postprocessing - tools available in Ansys Fluent. - -Problem Description: -A cold fluid at 20 deg C flows into the pipe through a large inlet, and 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. The Reynolds number for the flow at -the larger inlet is 50, 800, so a turbulent flow model will be required. -""" - - -############################################################################### - -# First, download the geometry file and start Fluent as a service with -# Meshing Mode, Double Precision, Number of Processors 4 - -import ansys.fluent.core as pyfluent -from ansys.fluent.core import examples - -import_filename = examples.download_file( - "mixing_elbow.pmdb", "pyfluent/mixing_elbow" -) - -s = pyfluent.launch_fluent( - meshing_mode=True, precision="double", processor_count="4" -) - -############################################################################### - -# Import the CAD geometry (mixing_elbow.scdoc). For Length Units, select "in". -# Execute the Import Geometry task. -s.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") - -############################################################################### - -# Import the CAD geometry. For Length Units, select "in". -# Execute the Import Geometry task. - -s.workflow.TaskObject["Import Geometry"].Arguments = dict( - FileName=import_filename, LengthUnit="in" -) - -s.workflow.TaskObject["Import Geometry"].Execute() - -############################################################################### - -# Add local sizing: -# In the Add Local Sizing task, you are prompted as to whether or not you would -# like to add local sizing controls to the faceted geometry. For the purposes -# of this tutorial, you can keep the default setting. Execute to complete this -# task and proceed to the next task in the workflow. - -s.workflow.TaskObject["Add Local Sizing"].AddChildToTask() -s.workflow.TaskObject["Add Local Sizing"].Execute() - -############################################################################### - -# Generate the surface mesh: -# In the Generate the Surface Mesh task, you can set various properties of the -# surface mesh for the faceted geometry. Specify 0.3 for Maximum Size. Execute -# the Surface Mesh to complete this task and proceed to the next task in the -# workflow. - -s.workflow.TaskObject["Generate the Surface Mesh"].Arguments = { - "CFDSurfaceMeshControls": {"MaxSize": 0.3} -} -s.workflow.TaskObject["Generate the Surface Mesh"].Execute() - -############################################################################### - -# Describe the geometry: -# When you select the Describe Geometry task, you are prompted with questions -# relating to the nature of the imported geometry. Since the geometry defined -# the fluid region. Select The geometry consists of only fluid regions with no -# voids for Geometry Type. Execute Describe Geometry to complete this task and -# proceed -# to the next task in the workflow. -s.workflow.TaskObject["Describe Geometry"].UpdateChildTasks( - SetupTypeChanged=False -) -s.workflow.TaskObject["Describe Geometry"].Arguments = dict( - SetupType="The geometry consists of only fluid regions with no voids" -) -s.workflow.TaskObject["Describe Geometry"].UpdateChildTasks( - SetupTypeChanged=True -) -s.workflow.TaskObject["Describe Geometry"].Execute() - -############################################################################### - -# Update Boundaries Task: -# For the wall-inlet boundary, change the Boundary Type field to wall. Execute -# Update Boundaries to complete this task and proceed to the next task in the -# workflow. -s.workflow.TaskObject["Update Boundaries"].Arguments = { - "BoundaryLabelList": ["wall-inlet"], - "BoundaryLabelTypeList": ["wall"], - "OldBoundaryLabelList": ["wall-inlet"], - "OldBoundaryLabelTypeList": ["velocity-inlet"], -} -s.workflow.TaskObject["Update Boundaries"].Execute() - -############################################################################### - -# Update your regions: -# Select the Update Regions task, where you can review the names and types of -# the various regions that have been generated from your imported geometry, and -# change them as needed. Keep the default settings, and execute Update Regions. -s.workflow.TaskObject["Update Regions"].Execute() - -############################################################################### - -# Add Boundary Layers: -# Select the Add Boundary Layers task, where you can set properties of the -# boundary layer mesh. Keep the default settings, and Add Boundary Layers. -s.workflow.TaskObject["Add Boundary Layers"].AddChildToTask() -s.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask() -s.workflow.TaskObject["smooth-transition_1"].Arguments = { - "BLControlName": "smooth-transition_1", -} -s.workflow.TaskObject["Add Boundary Layers"].Arguments = {} -s.workflow.TaskObject["smooth-transition_1"].Execute() - -############################################################################### - -# Generate the volume mesh: -# Select the Generate the Volume Mesh task, where you can set properties of the -# volume mesh. Select the poly-hexcore for Fill With. Execute Generate the -# Volume Mesh. -s.workflow.TaskObject["Generate the Volume Mesh"].Arguments = { - "VolumeFill": "poly-hexcore", - "VolumeFillControls": { - "HexMaxCellLength": 0.3, - }, -} -s.workflow.TaskObject["Generate the Volume Mesh"].Execute() - -############################################################################### - -# Check the mesh in Meshing mode -s.tui.meshing.mesh.check_mesh() - -############################################################################### - -# Save the mesh file (mixing_elbow.msh.h5). -# s.tui.meshing.file.write_mesh('mixing_elbow.msh.h5') - -############################################################################### - -# Switch to Solution mode: -# Now that a high-quality mesh has been generated using Ansys Fluent in meshing -# mode, you can now switch to solver mode to complete the setup of the -# simulation. We have just checked the mesh, so select Yes to switch to -# solution mode. -s.tui.meshing.switch_to_solution_mode("yes") - -############################################################################### - -# Check the mesh in Solver mode: -# The mesh check will list the minimum and maximum x, y, and z values from the -# mesh in the default SI unit of meters. It will also report a number of other -# mesh features that are checked. Any errors in the mesh will be reported at -# this time. Ensure that the minimum volume is not negative, since Ansys Fluent -# cannot begin a calculation when this is the case. -s.tui.solver.mesh.check() - -############################################################################### - -# The settings objects provide a natural way to access and modify settings. -# The top-level settings object for a session can be accessed with the -# get_settings_root() method of the session object. -# Enabling the settings objects. -root = s.get_settings_root() - -############################################################################### - -# Set the working units for the mesh: -# select "in" to set inches as the working unit for length. Note: Because the -# default SI units will be used for everything except length, there is no need -# to change any other units in this problem. If you want a different working -# unit for length, other than inches (for example, millimeters), make the -# appropriate change. -s.tui.solver.define.units("length", "in") - -############################################################################### - -# Enable heat transfer by activating the energy equation. -root.setup.models.energy.enabled = True - -############################################################################### - -# Create a new material called water-liquid. -s.tui.solver.define.materials.copy("fluid", "water-liquid") - -############################################################################### - -# Set up the cell zone conditions for the fluid zone (elbow-fluid). Select -# water-liquid from the Material list. -s.tui.solver.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 the boundary conditions for the inlets, outlet, and walls for your CFD -# analysis. - -# cold inlet (cold-inlet), Setting: Value: -# Velocity Specification Method: Magnitude, Normal to Boundary - -# Velocity Magnitude: 0.4 [m/s] -# Specification Method: Intensity and Hydraulic Diameter -# Turbulent Intensity: 5 [%] -# Hydraulic Diameter: 4 [inch] -# Temperature: 293.15 [K] -root.setup.boundary_conditions.velocity_inlet["cold-inlet"].vmag = { - "option": "constant or expression", - "constant": 0.4, -} -root.setup.boundary_conditions.velocity_inlet[ - "cold-inlet" -].ke_spec = "Intensity and Hydraulic Diameter" -root.setup.boundary_conditions.velocity_inlet["cold-inlet"].turb_intensity = 5 -root.setup.boundary_conditions.velocity_inlet[ - "cold-inlet" -].turb_hydraulic_diam = "4 [in]" -root.setup.boundary_conditions.velocity_inlet["cold-inlet"].t = { - "option": "constant or expression", - "constant": 293.15, -} - -############################################################################### - -# hot inlet (hot-inlet), Setting: Value: -# Velocity Specification Method: Magnitude, Normal to Boundary -# Velocity Magnitude: 1.2 [m/s] -# Specification Method: Intensity and Hydraulic Diameter -# Turbulent Intensity: 5 [%] -# Hydraulic Diameter: 1 [inch] -# Temperature: 313.15 [K] - -root.setup.boundary_conditions.velocity_inlet["hot-inlet"].vmag = { - "option": "constant or expression", - "constant": 1.2, -} -root.setup.boundary_conditions.velocity_inlet[ - "hot-inlet" -].ke_spec = "Intensity and Hydraulic Diameter" -root.setup.boundary_conditions.velocity_inlet[ - "hot-inlet" -].turb_hydraulic_diam = "1 [in]" -root.setup.boundary_conditions.velocity_inlet["hot-inlet"].t = { - "option": "constant or expression", - "constant": 313.15, -} - -############################################################################### - -# pressure outlet (outlet), Setting: Value: -# Backflow Turbulent Intensity: 5 [%] -# Backflow Turbulent Viscosity Ratio: 4 -root.setup.boundary_conditions.pressure_outlet[ - "outlet" -].turb_viscosity_ratio = 4 - -############################################################################### - -# Enable the plotting of residuals during the calculation. -s.tui.solver.solve.monitors.residual.plot("yes") - -############################################################################### - -# Create a surface report definition of average temperature at the outlet -# (outlet) called outlet-temp-avg -root.solution.report_definitions.surface["outlet-temp-avg"] = {} -root.solution.report_definitions.surface[ - "outlet-temp-avg" -].report_type = "surface-massavg" -root.solution.report_definitions.surface[ - "outlet-temp-avg" -].field = "temperature" -root.solution.report_definitions.surface["outlet-temp-avg"].surface_names = [ - "outlet" -] -root.solution.report_definitions.compute(report_defs=["outlet-temp-avg"]) - -############################################################################### - -# Create a surface report file called outlet-temp-avg-rfile using -# report-definition outlet-temp-avg -# s.tui.solver.solve.report_files.add( -# "outlet-temp-avg-rfile", -# "report-defs", -# "outlet-temp-avg", -# "()", -# "file-name", -# "outlet-temp-avg-rfile.out", -# "print?", -# "yes", -# "file-name", -# "outlet-temp-avg-rfile.out", -# "frequency", -# "3", -# "frequency-of", -# "iteration", -# "itr-index", -# "1", -# "run-index", -# "0", -# "quit", -# ) - -############################################################################### - -# Create a convergence condition for outlet-temp-avg: -# Provide con-outlet-temp-avg for Conditions. Select outlet-temp-avg Report -# Definition. Provide 1e-5 for Stop Criterion. Provide 20 for Ignore Iterations -# Before. Provide 15 for Use Iterations. Enable Print. Set Every Iteration to -# 3. - - -# These settings will 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 will be checked -# every 3 iterations. The first 20 iterations will be 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. -# Change Convergence Conditions -s.tui.solver.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-05", - "quit", - "quit", - "condition", - "1", - "frequency", - "3", - "quit", -) -s.tui.solver.solve.convergence_conditions("frequency", "3", "quit") - -############################################################################### - -# Initialize the flow field using the Hybrid Initialization -s.tui.solver.solve.initialize.hyb_initialization() - -############################################################################### - -# Solve for 150 Iterations. -s.tui.solver.solve.iterate(150) - -############################################################################### - -# Save the case and data file (mixing_elbow1.cas.h5 and mixing_elbow1.dat.h5). -# s.tui.solver.file.write_case_data('mixing_elbow1.cas.h5') - -############################################################################### - -# Examine the mass flux report for convergence: Select cold-inlet, hot-inlet, -# and outlet from the Boundaries selection list. -# Compute a Mass Flux Report for convergence -root.solution.report_definitions.flux[ - "report_mfr" -] = {} # Create a default report flux report -root.solution.report_definitions.flux["report_mfr"].zone_names = [ - "cold-inlet", - "hot-inlet", - "outlet", -] -root.solution.report_definitions.compute(report_defs=["report_mfr"]) - -############################################################################### - -# Create and display a definition for velocity magnitude contours on the -# symmetry plane: -# Provide contour-vel for Contour Name. Select velocity magnitude. Select -# symmetry-xyplane from the Surfaces list. Display contour-vel contour. - -root.results.graphics.contour["contour-vel"] = {} -root.results.graphics.contour["contour-vel"].print_state() -root.results.graphics.contour["contour-vel"].field = "velocity-magnitude" -root.results.graphics.contour["contour-vel"].surfaces_list = [ - "symmetry-xyplane" -] -# root.results.graphics.contour["contour-vel"].display() - -############################################################################### - -# Create and display a definition for temperature contours on the symmetry -# plane: -# Provide contour-temp for Contour Name. Select temperature. Select -# symmetry-xyplane from the Surfaces list. Display contour-temp contour. - -root.results.graphics.contour["contour-temp"] = {} -root.results.graphics.contour["contour-temp"].print_state() -root.results.graphics.contour["contour-temp"].field = "temperature" -root.results.graphics.contour["contour-temp"].surfaces_list = [ - "symmetry-xyplane" -] -# root.results.graphics.contour["contour-temp"].display() - -############################################################################### - -# Create and display velocity vectors on the symmetry-xyplane plane: - -# Provide vector-vel for Vector Name. Select arrow for the Style. Select -# symmetry-xyplane from the Surfaces selection list. -root.results.graphics.vector["vector-vel"] = {} -root.results.graphics.vector["vector-vel"].print_state() -root.results.graphics.vector["vector-vel"].field = "temperature" -root.results.graphics.vector["vector-vel"].surfaces_list = ["symmetry-xyplane"] -root.results.graphics.vector["vector-vel"].scale.scale_f = 4 -root.results.graphics.vector["vector-vel"].style = "arrow" -# root.results.graphics.vector["vector-vel"].display() - -############################################################################### - -# Create an iso-surface representing the intersection of the plane z=0 and the -# surface outlet. Name: z=0_outlet -s.tui.solver.surface.iso_surface( - "z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()" -) - -# Create Contour on the iso-surface -root.results.graphics.contour["contour-z_0_outlet"] = {} -root.results.graphics.contour["contour-z_0_outlet"].print_state() -root.results.graphics.contour["contour-z_0_outlet"].field = "temperature" -root.results.graphics.contour["contour-z_0_outlet"].surfaces_list = [ - "z=0_outlet" -] -# root.results.graphics.contour["contour-z_0_outlet"].display() - -############################################################################### -# s.tui.solver.file.write_case_data("mixing_elbow1_set.cas.h5") - -# Display and save an XY plot of the temperature profile across the centerline -# of the outlet for the initial solution - -s.tui.solver.display.objects.create( - "xy", - "xy-outlet-temp", - "y-axis-function", - "temperature", - "surfaces-list", - "z=0_outlet", - "()", - "quit", -) -# s.tui.solver.display.objects.display("xy-outlet-temp") -# s.tui.solver.plot.plot( -# "yes", -# "temp-1.xy", -# "no", -# "no", -# "no", -# "temperature", -# "yes", -# "1", -# "0", -# "0", -# "z=0_outlet", -# "()", -# ) - -############################################################################### - -# Write final case and data. -# s.tui.solver.file.write_case_data('mixing_elbow2_set.cas.h5') - -############################################################################### diff --git a/examples/01-parametric/parametric_static_mixer_1.py b/examples/01-parametric/parametric_static_mixer_1.py index 779977fe211e..ad568bef1d9d 100755 --- a/examples/01-parametric/parametric_static_mixer_1.py +++ b/examples/01-parametric/parametric_static_mixer_1.py @@ -1,7 +1,7 @@ """.. _ref_parametric_static_mixer_1: Parametric Study Workflow -------------------------- +------------------------------ This example for executing a parametric study workflow performs these steps: @@ -17,17 +17,18 @@ """ ############################################################################ -# Import the path module from pathlib import Path -############################################################################ -# Import the pyfluent module +import pandas as pd + import ansys.fluent.core as pyfluent +from ansys.fluent.core import examples +from ansys.fluent.parametric import ParametricStudy ############################################################################ # Launch Fluent in 3D and double precision -session = pyfluent.launch_fluent(precision="double", processor_count=4) +session = pyfluent.launch_fluent(precision="double", processor_count=2) ############################################################################ # Enable the settings API (Beta) @@ -37,8 +38,6 @@ ############################################################################ # Read the hopper/mixer case -from ansys.fluent.core import examples - import_filename = examples.download_file( "Static_Mixer_main.cas.h5", "pyfluent/static_mixer" ) @@ -46,9 +45,9 @@ session.tui.solver.file.read_case(case_file_name=import_filename) ############################################################################ -# Set number of iterations to 1000 to ensure convergence +# Set number of iterations to 100 -session.tui.solver.solve.set.number_of_iterations("1000") +session.tui.solver.solve.set.number_of_iterations("100") ############################################################################ # Create input parameters after enabling parameter creation in the TUI: @@ -117,12 +116,6 @@ ) session.tui.solver.file.write_case(case_path) -########################################################################### -# Parametric study workflow -# Import the parametric study module - -from ansys.fluent.parametric import ParametricStudy - ########################################################################### # Instantiate a parametric study from a Fluent session @@ -181,8 +174,6 @@ ######################################################################### # Display CSV table as a pandas dataframe -import pandas as pd - data_frame = pd.read_csv(design_point_table) print(data_frame) diff --git a/examples/01-parametric/parametric_static_mixer_2.py b/examples/01-parametric/parametric_static_mixer_2.py index 887268af56fa..b129c0d41f47 100755 --- a/examples/01-parametric/parametric_static_mixer_2.py +++ b/examples/01-parametric/parametric_static_mixer_2.py @@ -1,7 +1,7 @@ """.. _ref_parametric_static_mixer_2: Parametric Project-Based Workflow ---------------------------------- +---------------------------------------------------- This example for executing a parametric project-based workflow performs these steps: @@ -15,24 +15,15 @@ """ ######################################################################### -# Parametric project-based workflow - -######################################################################### -# Import the parametric project module and the parametric study module - from pathlib import Path import ansys.fluent.core as pyfluent from ansys.fluent.parametric import ParametricProject -############################################################################ -# Import the pyfluent module and path - - ######################################################################### # Launch Fluent and enable the settings API (Beta) -session = pyfluent.launch_fluent(precision="double", processor_count=4) +session = pyfluent.launch_fluent(precision="double", processor_count=2) root = session.get_settings_root() ######################################################################### diff --git a/examples/01-parametric/parametric_static_mixer_3.py b/examples/01-parametric/parametric_static_mixer_3.py index e97c68963fdf..38789cb23cd8 100755 --- a/examples/01-parametric/parametric_static_mixer_3.py +++ b/examples/01-parametric/parametric_static_mixer_3.py @@ -1,7 +1,7 @@ """.. _ref_parametric_static_mixer_3: Parametric Session Workflow ---------------------------- +---------------------------------------------- This example for executing a parametric session workflow performs these steps: - Launches a parametric session using the hopper/mixer case file @@ -13,18 +13,13 @@ """ ######################################################################### -# Parametric session workflow -# Import the parametric session workflow - from pathlib import Path +import pandas as pd + import ansys.fluent.core as pyfluent from ansys.fluent.parametric import ParametricSession -############################################################################ -# Import the pyfluent module and path - - ######################################################################### # Launch parametric session using the hopper/mixer case File # This case file contains pre-created input and output parameters @@ -78,8 +73,6 @@ ######################################################################### # Display CSV table as a pandas dataframe -import pandas as pd - data_frame = pd.read_csv(design_point_table_study_2) print(data_frame) diff --git a/examples/02-postprocessing/post_processing_exhaust_manifold.py b/examples/02-postprocessing/post_processing_exhaust_manifold.py new file mode 100644 index 000000000000..28a292fa0cf0 --- /dev/null +++ b/examples/02-postprocessing/post_processing_exhaust_manifold.py @@ -0,0 +1,151 @@ +""".. _ref_post_processing_exhaust_manifold: + +Post Processing using PyVista and Matplotlib: Exhaust Manifold +---------------------------------------------------------------------- +This example demonstrates the postprocessing capabilities of PyFluent +(using PyVista and Matplotlib) using a 3D model +of an exhaust manifold with high temperature flows passing through. +The flow through the manifold is turbulent and +involves conjugate heat transfer. + +This example demonstrates how to do the following: + +- Create surfaces for the display of 3D data. +- Display filled contours of temperature on several surfaces. +- Display velocity vectors. +- Plot quantitative results using Matplotlib +""" +############################################################################### +import ansys.fluent.core as pyfluent +from ansys.fluent.core import examples +from ansys.fluent.post import set_config +from ansys.fluent.post.matplotlib import Plots +from ansys.fluent.post.pyvista import Graphics + +set_config(blocking=True) + +############################################################################### +# First, download the case and data file and start Fluent as a service with +# Meshing mode, double precision, number of processors: 4 + +import_case = examples.download_file( + filename="manifold_solution.cas.h5", directory="pyfluent/exhaust_manifold" +) + +import_data = examples.download_file( + filename="manifold_solution.dat.h5", directory="pyfluent/exhaust_manifold" +) + +session = pyfluent.launch_fluent(precision="double", processor_count=2) +root = session.get_settings_root() + +session.tui.solver.file.read_case(case_file_name=import_case) +session.tui.solver.file.read_data(case_file_name=import_data) + +############################################################################### +# Get the graphics object for mesh display + +graphics = Graphics(session=session) + +############################################################################### +# Create a graphics object for mesh display + +mesh1 = graphics.Meshes["mesh-1"] + +############################################################################### +# Show edges and faces + +mesh1.show_edges = True +mesh1.show_faces = True + +############################################################################### +# Get the surfaces list + +mesh1.surfaces_list = [ + "in1", + "in2", + "in3", + "out1", + "solid_up:1", + "solid_up:1:830", + "solid_up:1:830-shadow", +] +mesh1.display("window-1") + +############################################################################### +# Disable edges and display again + +mesh1.show_edges = False +mesh1.display("window-2") + +############################################################################### +# Create iso-surface on the outlet plane + +surf_outlet_plane = graphics.Surfaces["outlet-plane"] +surf_outlet_plane.surface.type = "iso-surface" +iso_surf1 = surf_outlet_plane.surface.iso_surface +iso_surf1.field = "y-coordinate" +iso_surf1.iso_value = -0.125017 +surf_outlet_plane.display("window-3") + +############################################################################### +# Create iso-surface on the mid-plane (Issue # 276) + +surf_mid_plane_x = graphics.Surfaces["mid-plane-x"] +surf_mid_plane_x.surface.type = "iso-surface" +iso_surf2 = surf_mid_plane_x.surface.iso_surface +iso_surf2.field = "x-coordinate" +iso_surf2.iso_value = -0.174 +surf_mid_plane_x.display("window-4") + +############################################################################### +# Temperature contour on the mid-plane and the outlet + +temperature_contour = graphics.Contours["contour-temperature"] +temperature_contour.field = "temperature" +temperature_contour.surfaces_list = ["mid-plane-x", "outlet-plane"] +temperature_contour.display("window-4") + +############################################################################### +# Contour plot of temperature on the manifold + +temperature_contour_manifold = graphics.Contours[ + "contour-temperature-manifold" +] +temperature_contour_manifold.field = "temperature" +temperature_contour_manifold.surfaces_list = [ + "in1", + "in2", + "in3", + "out1", + "solid_up:1", + "solid_up:1:830", +] +temperature_contour_manifold.display("window-5") + +############################################################################### +# Vector on the mid-plane +# Currently using outlet-plane since mid-plane is affected by Issue # 276 + +velocity_vector = graphics.Vectors["velocity-vector"] +velocity_vector.surfaces_list = ["outlet-plane"] +velocity_vector.scale = 1 +velocity_vector.display("window-6") + +############################################################################### +# Commenting out due to issue #290 +# Start the Plot Object for the session +plots_session_1 = Plots(session) + +############################################################################### +# Create a default XY-Plot +plot_1 = plots_session_1.XYPlots["plot-1"] + +############################################################################### +# Set the surface on which the plot is plotted and the Y-axis function +plot_1.surfaces_list = ["outlet"] +plot_1.y_axis_function = "temperature" + +############################################################################### +# Plot the created XY-Plot +plot_1.plot("window-7")