-
Notifications
You must be signed in to change notification settings - Fork 56
Adding a settings api example, and other changes refactoring examples #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
""".. _ref_mixing_elbow_settings_api_beta: | ||
Fluent Setup and Solutoin using Settings API (Beta) | ||
ypatel-qa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-------------------------------------------------- | ||
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 | ||
ypatel-qa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. Exit. | ||
# session.solver.tui.file.write_case_data('mixing_elbow2_set.cas.h5') | ||
# session.exit() | ||
|
||
############################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from util.solver_workflow import new_solver_session # noqa: F401 | ||
|
||
|
||
def test_report_system_proc_stats_tui(new_solver_session, capsys) -> None: | ||
def test_report_summary_tui(new_solver_session, capsys) -> None: | ||
new_solver_session.start_transcript() | ||
# Issue: Transcript missing for the first TUI command | ||
new_solver_session.solver.tui.report.system.sys_stats() | ||
new_solver_session.solver.tui.report.system.sys_stats() | ||
new_solver_session.solver.tui.report.summary("no") | ||
new_solver_session.solver.tui.report.summary("no") | ||
captured = capsys.readouterr() | ||
assert "CPU/Memory Usage" in captured.out | ||
assert "Settings" in captured.out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.