Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/00-fluent/README.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Full Examples Using PyFluent
============================
These examples demonstrate how to use Fluent solver capabilities from Python.
These examples demonstrate how to use Fluent capabilities from Python.
41 changes: 33 additions & 8 deletions examples/00-fluent/exhaust_system.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
""".. _ref_exhaust_system_tui_api:

Exhaust System: Fault-tolerant Meshing
End-to-end Fault-tolerant Meshing Workflow
----------------------------------------------

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
Expand All @@ -11,8 +10,7 @@
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:

End-to-end Fault Tolerant Meshing Workflow example:

- Use the Fault-tolerant Meshing guided workflow to:
- Import a CAD geometry and manage individual parts
Expand All @@ -37,10 +35,15 @@
"""

###############################################################################
# First, connect with a Fluent server
# First, download the geometry file and start Fluent as a service with
# Meshing Mode, Double Precision, Number of Processors 2

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, set_view_on_display="isometric")

import_filename = examples.download_file(
"exhaust_system.fmd", "pyfluent/exhaust_system"
Expand All @@ -50,7 +53,7 @@
# Start Fluent in double precision running on 2 processors

session = pyfluent.launch_fluent(
meshing_mode=True, precision="double", processor_count=4
meshing_mode=True, precision="double", processor_count=2
)

###############################################################################
Expand Down Expand Up @@ -651,7 +654,29 @@
# session.solver.tui.display.objects.display("scene-1")

###############################################################################
# Save case, data and exit.
# Mesh display using PyVista

graphics_session = Graphics(session)
mesh_1 = graphics_session.Meshes["mesh-1"]
mesh_1.show_edges = True
mesh_1.surfaces_list = [
"inlet-1",
"inlet-2",
"inlet-3",
"outlet-1",
"flow-pipe",
"main.1",
"object1.1",
"object2.1",
"outpipe3.1",
]

mesh_1.display()
###############################################################################
# Save case, data.
# session.solver.tui.file.write_case_data("exhaust_system.cas.h5")

# session.exit()
#########################################################################
# Close Fluent

session.exit()
20 changes: 13 additions & 7 deletions examples/00-fluent/mixing_elbow.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
""".. _ref_mixing_elbow_tui_api:

Fluid Flow and Heat Transfer in a Mixing Elbow
----------------------------------------------
End-to-end Watertight Meshing Workflow
---------------------------------------
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
processindustries. It is often important to predict the flow field and
temperature field in the area of the mixing regionin order to properly design
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:
End-to-end Watertight Meshing Workflow example:

- Use the Watertight Geometry guided workflow to:
- Import a CAD geometry
Expand Down Expand Up @@ -43,12 +43,12 @@
from ansys.fluent.post import set_config
from ansys.fluent.post.pyvista import Graphics

set_config(blocking=True)
set_config(blocking=True, set_view_on_display="isometric")

import_filename = examples.download_file("mixing_elbow.pmdb", "pyfluent/mixing_elbow")

session = pyfluent.launch_fluent(
meshing_mode=True, precision="double", processor_count=4
meshing_mode=True, precision="double", processor_count=2
)

###############################################################################
Expand Down Expand Up @@ -516,4 +516,10 @@
# Write final case and data.
# session.solver.tui.file.write_case_data("mixing_elbow2_tui.cas.h5")

#########################################################################
# Close Fluent

session.exit()


###############################################################################
231 changes: 231 additions & 0 deletions examples/00-fluent/mixing_elbow_settings_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
""".. _ref_mixing_elbow_settings_api_beta:

Fluent Setup and Solutoin using Settings API (Beta)
-----------------------------------------------------
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 use of 'settings' modules (Beta):

- Launch Ansys Fluent
- Import Mesh
- Define Material
- Setup Cell Zone Conditions
- Setup Boundary Conditions
- Iniialize and Solve
- Compute Mass Flow Rate and Temperature
- Display Mesh and Contour using PyVista

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.
"""
# sphinx_gallery_thumbnail_number = 2

###############################################################################
# First, download the mesh file and start Fluent as a service with
# Solver Mode, Double Precision, Number of Processors 2

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, set_view_on_display="isometric")

import_filename = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow")

session = pyfluent.launch_fluent(precision="double", processor_count=2)
###############################################################################
# Import mesh and perform mesh check:
# 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.

session.solver.root.file.read(file_type="case", file_name=import_filename)
session.solver.tui.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.

session.solver.tui.define.units("length", "in")

###############################################################################
# Enable heat transfer by activating the energy equation.

session.solver.root.setup.models.energy.enabled = True

###############################################################################
# Create a new material called water-liquid.

session.solver.root.setup.materials.copy_database_material_by_name(
type="fluid", name="water-liquid"
)

###############################################################################
# Set up the cell zone conditions for the fluid zone (elbow-fluid). Select
# water-liquid from the Material list.

session.solver.root.setup.cell_zone_conditions.fluid[
"elbow-fluid"
].material = "water-liquid"

###############################################################################
# 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]

session.solver.root.setup.boundary_conditions.velocity_inlet["cold-inlet"].vmag = {
"option": "constant or expression",
"constant": 0.4,
}
session.solver.root.setup.boundary_conditions.velocity_inlet[
"cold-inlet"
].ke_spec = "Intensity and Hydraulic Diameter"
session.solver.root.setup.boundary_conditions.velocity_inlet[
"cold-inlet"
].turb_intensity = 5
session.solver.root.setup.boundary_conditions.velocity_inlet[
"cold-inlet"
].turb_hydraulic_diam = "4 [in]"
session.solver.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]

session.solver.root.setup.boundary_conditions.velocity_inlet["hot-inlet"].vmag = {
"option": "constant or expression",
"constant": 1.2,
}
session.solver.root.setup.boundary_conditions.velocity_inlet[
"hot-inlet"
].ke_spec = "Intensity and Hydraulic Diameter"
session.solver.root.setup.boundary_conditions.velocity_inlet[
"hot-inlet"
].turb_hydraulic_diam = "1 [in]"
session.solver.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

session.solver.root.setup.boundary_conditions.pressure_outlet[
"outlet"
].turb_viscosity_ratio = 4

###############################################################################
# Disable the plotting of residuals during the calculation.

session.solver.tui.solve.monitors.residual.plot("no")

###############################################################################
# Initialize the flow field using the Hybrid Initialization

session.solver.root.solution.initialization.hybrid_initialize()

###############################################################################
# Solve for 150 Iterations.

session.solver.root.solution.run_calculation.iterate.get_attr("arguments")
session.solver.root.solution.run_calculation.iterate(number_of_iterations=150)

###############################################################################
# Create and display velocity vectors on the symmetry-xyplane plane.

session.solver.root.results.graphics.vector["velocity_vector_symmetry"] = {}
session.solver.root.results.graphics.vector["velocity_vector_symmetry"].print_state()
session.solver.root.results.graphics.vector[
"velocity_vector_symmetry"
].field = "temperature"
session.solver.root.results.graphics.vector[
"velocity_vector_symmetry"
].surfaces_list = [
"symmetry-xyplane",
]
session.solver.root.results.graphics.vector[
"velocity_vector_symmetry"
].scale.scale_f = 4
session.solver.root.results.graphics.vector["velocity_vector_symmetry"].style = "arrow"
# session.solver.root.results.graphics.vector["velocity_vector_symmetry"].display()

###############################################################################
# Compute mass flow rate

session.solver.root.solution.report_definitions.flux["mass_flow_rate"] = {}
session.solver.root.solution.report_definitions.flux[
"mass_flow_rate"
].zone_names.get_attr("allowed-values")
session.solver.root.solution.report_definitions.flux["mass_flow_rate"].zone_names = [
"cold-inlet",
"hot-inlet",
"outlet",
]
session.solver.root.solution.report_definitions.flux["mass_flow_rate"].print_state()
session.solver.root.solution.report_definitions.compute(report_defs=["mass_flow_rate"])

###############################################################################
# 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()

###############################################################################
# Write final case and data.
# session.solver.tui.file.write_case_data('mixing_elbow2_set.cas.h5')

#########################################################################
# Close Fluent

session.exit()
Loading