-
Notifications
You must be signed in to change notification settings - Fork 65
docs: Example on pipe flow [skip tests] #4883
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
base: main
Are you sure you want to change the base?
Changes from all commits
6c960c8
1187c8e
be87774
f6d430a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Example on pipe flow [skip tests] |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,318 @@ | ||||||||||
| # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. | ||||||||||
| # SPDX-License-Identifier: MIT | ||||||||||
| # | ||||||||||
| # | ||||||||||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||
| # of this software and associated documentation files (the "Software"), to deal | ||||||||||
| # in the Software without restriction, including without limitation the rights | ||||||||||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||
| # copies of the Software, and to permit persons to whom the Software is | ||||||||||
| # furnished to do so, subject to the following conditions: | ||||||||||
| # | ||||||||||
| # The above copyright notice and this permission notice shall be included in all | ||||||||||
| # copies or substantial portions of the Software. | ||||||||||
| # | ||||||||||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||||
| # SOFTWARE. | ||||||||||
|
|
||||||||||
| """.. _flow_through_pipe: | ||||||||||
|
|
||||||||||
| Flow of oil in a pipe through a lake | ||||||||||
| ===================================== | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Objective | ||||||||||
| # --------- | ||||||||||
| # | ||||||||||
| # The primary objective of this study is to simulate **thermal energy transport** | ||||||||||
| # in a circular pipe subjected to a constant wall temperature boundary condition. | ||||||||||
| # The simulation represents oil flowing through a horizontal pipeline submerged in | ||||||||||
| # icy lake water, where the surrounding cold environment maintains the pipe wall | ||||||||||
| # at a uniform temperature. The analysis focuses on predicting the oil temperature | ||||||||||
| # at the pipe exit after heat loss to the cold surroundings over the submerged | ||||||||||
| # pipe length. | ||||||||||
| # | ||||||||||
| # The numerical results are validated against the analytical solution, demonstrating | ||||||||||
| # the use of PyFluent as a verification and validation tool for classical | ||||||||||
| # internal-flow heat-transfer problems. | ||||||||||
| # | ||||||||||
| # Problem Description | ||||||||||
| # ------------------- | ||||||||||
| # | ||||||||||
| # This simulation models the internal flow of oil through a horizontal circular | ||||||||||
| # pipeline exposed to icy lake conditions. A 200-m-long section of the pipe passes | ||||||||||
| # through lake water at 0°C. Due to the cold surroundings, measurements indicate | ||||||||||
| # that the outer and inner pipe wall temperatures are very nearly uniform at 0°C. | ||||||||||
| # The oil enters the lake section fully developed at a higher temperature and | ||||||||||
| # undergoes convective cooling as it flows downstream. | ||||||||||
| # | ||||||||||
| # **Configuration:** | ||||||||||
| # | ||||||||||
| # - **Pipe diameter:** 0.3 m | ||||||||||
| # - **Pipe length:** 200 m | ||||||||||
| # - **Inlet velocity:** 2 m/s | ||||||||||
| # - **Inlet temperature:** 20°C (293.15 K) | ||||||||||
| # - **Wall temperature:** 0°C (273.15 K) | ||||||||||
| # | ||||||||||
| # **Assumptions:** | ||||||||||
| # | ||||||||||
| # - Steady operating conditions | ||||||||||
| # - Thermal resistance of pipe material is negligible | ||||||||||
| # - Inner surfaces of pipeline are smooth | ||||||||||
| # - Flow is hydrodynamically developed when entering the lake section | ||||||||||
| # | ||||||||||
| # **Oil Properties at 20°C:** | ||||||||||
| # | ||||||||||
| # - Density (ρ): 888.1 kg/m³ | ||||||||||
| # - Kinematic viscosity (ν): 0.0009429 m²/s | ||||||||||
| # - Specific heat (cp): 1880 J/kg·K | ||||||||||
| # - Thermal conductivity (k): 0.145 W/m·K | ||||||||||
| # - Prandtl number (Pr): 10863 | ||||||||||
| # | ||||||||||
| # **Reynolds Number:** | ||||||||||
| # | ||||||||||
| # .. math:: | ||||||||||
| # | ||||||||||
| # Re = \frac{V D}{\nu} = \frac{(2 \text{ m/s})(0.3 \text{ m})}{9.429 \times 10^{-4} \text{ m}^2/\text{s}} = 636 | ||||||||||
| # | ||||||||||
| # Since Re < 2300, the flow is laminar. | ||||||||||
| # | ||||||||||
| # .. image:: ../../_static/pipe_flow_1.png | ||||||||||
| # :align: center | ||||||||||
| # :alt: Schematic of pipe flow through lake | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Import modules | ||||||||||
| # -------------- | ||||||||||
|
|
||||||||||
| import os | ||||||||||
|
|
||||||||||
| import ansys.fluent.core as pyfluent | ||||||||||
| from ansys.fluent.core import examples | ||||||||||
| from ansys.fluent.core.solver import ( | ||||||||||
| Energy, | ||||||||||
| FluidMaterials, | ||||||||||
| Initialization, | ||||||||||
| LineSurfaces, | ||||||||||
| RunCalculation, | ||||||||||
| VelocityInlets, | ||||||||||
| Viscous, | ||||||||||
| WallBoundaries, | ||||||||||
| ) | ||||||||||
| from ansys.fluent.visualization import GraphicsWindow, Monitor, XYPlot | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Launch Fluent in solver mode | ||||||||||
| # ----------------------------- | ||||||||||
|
|
||||||||||
| solver = pyfluent.launch_fluent( | ||||||||||
| precision=pyfluent.Precision.DOUBLE, | ||||||||||
| mode=pyfluent.FluentMode.SOLVER, | ||||||||||
| dimension=pyfluent.Dimension.TWO, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Read mesh | ||||||||||
| # --------- | ||||||||||
|
|
||||||||||
| mesh_file = examples.download_file( | ||||||||||
| "flow_through_pipe.msh", | ||||||||||
| "pyfluent/flow_through_pipe", | ||||||||||
| save_path=os.getcwd(), | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| solver.settings.file.read_mesh(file_name=mesh_file) | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Setup | ||||||||||
| # ----- | ||||||||||
| # | ||||||||||
| # Configure the simulation settings including turbulence model, boundary conditions, | ||||||||||
| # and solution methods. | ||||||||||
| # | ||||||||||
| # Viscous Model | ||||||||||
| # ^^^^^^^^^^^^^ | ||||||||||
|
|
||||||||||
| viscous = Viscous(solver) | ||||||||||
| viscous.model = viscous.model.LAMINAR | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Energy model | ||||||||||
| # ^^^^^^^^^^^^ | ||||||||||
|
|
||||||||||
| energy_model = Energy(solver) | ||||||||||
| energy_model.enabled = True | ||||||||||
|
|
||||||||||
| # %% | ||||||||||
| # Materials | ||||||||||
| # ^^^^^^^^^ | ||||||||||
|
|
||||||||||
| fluid_materials = FluidMaterials(solver) | ||||||||||
|
|
||||||||||
| fluid_materials.rename(new="oil", old="air") | ||||||||||
| fluid_materials["oil"] = { | ||||||||||
| "density": 888.1, | ||||||||||
| "viscosity": 0.0009429, | ||||||||||
|
Comment on lines
+160
to
+161
|
||||||||||
| "density": 888.1, | |
| "viscosity": 0.0009429, | |
| "density": 888.1, # kg/m^3 | |
| "viscosity": 0.8375, # Pa·s (dynamic viscosity μ = 888.1 kg/m^3 × 0.0009429 m^2/s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MohammedAnsys The resolved Copilot comments regarding viscosity here are justified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment should go before the iterate() call and it should not comment concretely on what has happened.
E.g.,
# Allow up to 300 iterations. The solver will terminate early if
# convergence criteria are met, so the actual iteration count may
# be lower and can vary between runs.
calculation.iterate(iter_count=300)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might refer to this as a typical result for PyFluent, given that the user is not guaranteed to get the same result in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have concerns about how this validation is being presented.
- Significance of the discrepancy
The discussion compares two absolute outlet temperatures and concludes that “both show only a small temperature drop.”
However, the relevant quantity for validation is not the absolute temperature but the temperature drop relative to the inlet:
- Inlet: 293.15 K
- Analytical outlet: 292.74 K → ΔT ≈ 0.41 K
- PyFluent outlet: 291.79 K → ΔT ≈ 1.36 K
The difference between the two predicted drops (~0.95 K) is more than twice the magnitude of the analytical drop itself.
That is not a minor deviation—it corresponds to substantially different thermal behaviour over the pipe length.
As written, the text risks giving the impression that the two approaches are in close agreement when, in terms of the physics being evaluated (heat transfer rate), they are not.
- Model vs. model vs. reality
The analytical solution is itself a model based on idealisations (fully developed laminar flow, constant properties, etc.).
The PyFluent result is another model with different assumptions and discretisation.
What we are doing here is:
model A ↔ model B
not
model ↔ physical reality.
The discussion should acknowledge that a discrepancy reflects a gap between two modelling approaches, and that either (or neither) may be closer to reality. Calling this a “validation of PyFluent’s capability” feels too strong without experimental reference data or a more rigorous error analysis.
- Viscosity specification
There is also the unresolved issue noted earlier: the example appears to supply kinematic viscosity where Fluent expects dynamic viscosity.
The material properties used in the simulation are inconsistent which would directly affect the Prandtl number and the predicted thermal entry behaviour.
Before drawing conclusions about agreement with the analytical solution, we should correct the viscosity definition.
Uh oh!
There was an error while loading. Please reload this page.