-
Notifications
You must be signed in to change notification settings - Fork 60
docs: Example on ventilation flow simulation [skip tests] #4833
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
Open
MohammedAnsys
wants to merge
20
commits into
main
Choose a base branch
from
docs/example_on_ventilation_flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f1e7fe6
Add ventilation flow simulation workflow example
MohammedAnsys 26262af
chore: adding changelog file 4833.documentation.md [dependabot-skip]
pyansys-ci-bot 42fe70d
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys c058da6
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys 8673540
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys df82dc2
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys 80d3e38
chore: adding changelog file 4833.documentation.md [dependabot-skip]
pyansys-ci-bot b0b30e4
Merge branch 'main' into docs/example_on_ventilation_flow
MohammedAnsys 3611f31
Merge branch 'main' into docs/example_on_ventilation_flow
MohammedAnsys a5fc8a4
update ventilation workflow example with improvements
MohammedAnsys dd196c0
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys ccef1a7
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys b57ebac
Merge branch 'main' into docs/example_on_ventilation_flow
MohammedAnsys d77f99b
update ventilation workflow example
MohammedAnsys 9dd1a69
Update examples/00-fluent/ventilation_workflow.py
MohammedAnsys 5c93b0d
update image extension in the workflow
MohammedAnsys 38f2d4d
Merge branch 'docs/example_on_ventilation_flow' of https://github.com…
MohammedAnsys f54596c
update year in the license
MohammedAnsys efe1d58
Merge branch 'main' into docs/example_on_ventilation_flow
MohammedAnsys ea91e54
Merge branch 'main' into docs/example_on_ventilation_flow
MohammedAnsys 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Example on ventilation flow simulation [skip test] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,287 @@ | ||
| # Copyright (C) 2021 - 2025 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. | ||
|
|
||
| """.. _ventilation_flow_simulation: | ||
|
|
||
| Wind Flow Through A Mechanically Ventilated Poultry House | ||
| ------------------------------------------------------------- | ||
| """ | ||
| # %% | ||
| # Objective | ||
| # --------- | ||
| # | ||
| # The primary objective of this PyFluent study is to investigate airflow patterns, air distribution, | ||
| # and ventilation effectiveness inside a mechanically ventilated poultry house. | ||
| # The simulation represents a typical poultry housing configuration with | ||
| # 32 side inlet windows and six exhaust fans installed on one end wall, capturing the | ||
| # interaction between inlet air jets and exhaust driven flow. | ||
| # | ||
| # The study analyzes velocity fields, airflow distribution, and mixing characteristics | ||
| # to evaluate the uniformity of fresh air delivery, particularly within bird occupied zones, | ||
| # and to identify regions of stagnant airflow. | ||
| # | ||
| # Ventilation performance is assessed based on its ability to supply adequate fresh air. | ||
| # In addition, the influence of inlet and fan configuration on airflow direction is examined | ||
| # to provide insights for ventilation system optimization. | ||
| # | ||
| # | ||
| # Problem Description | ||
| # ------------------- | ||
| # | ||
| # This simulation models a mechanically ventilated broiler house with the following | ||
| # configuration: | ||
| # | ||
| # - **32 side inlet windows**: Located along the sidewalls to allow fresh air intake | ||
| # - **6 exhaust fans**: Installed on one end wall to remove stale air | ||
| # | ||
| # The analysis focuses on: | ||
| # | ||
| # - Velocity field distribution throughout the poultry house | ||
| # - Airflow pathlines from inlets to exhaust fans | ||
| # - Uniformity of exhaust velocities across the six fans | ||
| # | ||
| # .. image:: ../../_static/wind_flow_1.png | ||
| # :align: center | ||
| # :alt: Schematic of mechanically ventilated poultry house | ||
|
|
||
| # %% | ||
| # Import modules | ||
| # ^^^^^^^^^^^^^^ | ||
|
|
||
| import os | ||
|
|
||
| import ansys.fluent.core as pyfluent | ||
| from ansys.fluent.core import examples | ||
| from ansys.fluent.core.solver import ( | ||
| BoundaryConditions, | ||
| Contour, | ||
| Graphics, | ||
| Initialization, | ||
| Methods, | ||
| Pathlines, | ||
| PlaneSurfaces, | ||
| PressureOutlets, | ||
| Residual, | ||
| RunCalculation, | ||
| SurfaceIntegrals, | ||
| Viscous, | ||
| ) | ||
|
|
||
| # %% | ||
| # Launch Fluent in solver mode | ||
| # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| # | ||
| # .. note:: | ||
| # To enable the graphical user interface (GUI), import the ``UIMode`` class | ||
| # and set the UI mode before launching the solver:: | ||
| # | ||
| # from ansys.fluent.core import UIMode | ||
| # ui_mode = UIMode.GUI | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| solver = pyfluent.launch_fluent( | ||
| precision=pyfluent.Precision.DOUBLE, | ||
| mode=pyfluent.FluentMode.SOLVER, | ||
| ) | ||
|
|
||
| # %% | ||
| # Read mesh | ||
| # ^^^^^^^^^ | ||
| mesh_file = examples.download_file( | ||
| "poultry_farm_ventilation.msh", | ||
| "pyfluent/poultry_ventilation", | ||
| save_path=os.getcwd(), | ||
| ) | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| solver.file.read(file_type="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 = "k-epsilon" | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # %% | ||
| # Boundary conditions | ||
| # ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| boundary_conditions = BoundaryConditions(solver) | ||
| boundary_conditions.set_zone_type(new_type="inlet-vent", zone_list=["*inlet_vent_*"]) | ||
|
|
||
| pressure_outlets = PressureOutlets(solver) | ||
| # %% | ||
| # The target mass flow rate option is enabled to ensure that each exhaust outlet (fan) removes a specified and controlled amount of air | ||
|
||
|
|
||
| pressure_outlets["outlet_1"] = { | ||
| "momentum": { | ||
| "target_mass_flow_rate": True, | ||
| "target_mass_flow": { | ||
| "value": 12.25 # kg/s Represents the design airflow capacity of one exhaust fan | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| } | ||
| } | ||
|
|
||
| boundary_conditions.copy(from_="outlet_1", to=["*outlet_*"]) | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # %% | ||
| # Solution methods and controls | ||
| # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| solution_methods = Methods(solver) | ||
|
|
||
| solution_methods.p_v_coupling.flow_scheme = "SIMPLEC" | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # %% | ||
| # SIMPLEC: Faster convergence and better pressure–velocity coupling for steady, incompressible indoor airflow | ||
|
|
||
| # %% | ||
| solution_methods.spatial_discretization = { | ||
| "gradient_scheme": "green-gauss-cell-based", | ||
| "discretization_scheme": { | ||
| "epsilon": "second-order-upwind", | ||
| "k": "second-order-upwind", | ||
| "mom": "second-order-upwind", | ||
| "pressure": "second-order", | ||
| }, | ||
| } | ||
| # %% | ||
| # The cell-based Green–Gauss method calculates gradients using cell centered values and face fluxes, | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # making it less sensitive to mesh irregularities and more stable than node-based methods | ||
|
|
||
| # %% | ||
| monitor_residuals = Residual(solver) | ||
| monitor_residuals.equations["continuity"].absolute_criteria = 1e-06 | ||
| monitor_residuals.equations["x-velocity"].absolute_criteria = 1e-06 | ||
| monitor_residuals.equations["y-velocity"].absolute_criteria = 1e-06 | ||
| monitor_residuals.equations["z-velocity"].absolute_criteria = 1e-06 | ||
| monitor_residuals.equations["k"].absolute_criteria = 1e-06 | ||
| monitor_residuals.equations["epsilon"].absolute_criteria = 1e-06 | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # %% | ||
| # Residual convergence: to ensure a high level of numerical accuracy and solution stability in the simulation | ||
|
|
||
| # %% | ||
| # Initialize and run | ||
| # ^^^^^^^^^^^^^^^^^^ | ||
| solution_initialization = Initialization(solver) | ||
| solution_initialization.initialization_type = "hybrid" | ||
| solution_initialization.initialize() | ||
|
|
||
| calculation = RunCalculation(solver) | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| calculation.iterate(iter_count=1000) | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # %% | ||
| # Results | ||
| # ^^^^^^^ | ||
|
|
||
| graphics = Graphics(solver) | ||
| plane_surfaces = PlaneSurfaces(solver) | ||
|
|
||
| # Create ZX plane at the center of the domain | ||
| plane_surfaces.create() | ||
| plane_surfaces.rename(new="zx-plane", old="plane-1") | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| plane_surfaces["zx-plane"].method = "zx-plane" | ||
|
|
||
| # Create pathlines | ||
| velocity_pathline = Pathlines(solver) | ||
|
|
||
| velocity_pathline["pathlines-1"] = { | ||
| "field": "velocity-magnitude", | ||
| "release_from_surfaces": ["*inlet_vent_*"], | ||
| } | ||
| velocity_pathline["pathlines-1"].display() | ||
|
|
||
| graphics.picture.x_resolution = 650 # Horizontal resolution for clear visualization | ||
| graphics.picture.y_resolution = 450 # Vertical resolution matching typical aspect ratio | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| graphics.picture.save_picture(file_name="wind_flow_2.jpg") | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # %% | ||
| # .. image:: ../../_static/wind_flow_2.png | ||
| # :align: center | ||
| # :alt: Pathlines showing airflow from inlets to outlets | ||
|
|
||
|
|
||
| # Create velocity contour | ||
| velocity_contour = Contour(solver, new_instance_name="velocity_contour") | ||
|
|
||
| velocity_contour.field = "velocity-magnitude" | ||
| velocity_contour.surfaces_list = ["zx-plane"] | ||
| velocity_contour.display() | ||
|
|
||
| graphics.picture.save_picture(file_name="wind_flow_3.jpg") | ||
MohammedAnsys marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # %% | ||
| # .. image:: ../../_static/wind_flow_3.png | ||
| # :align: center | ||
| # :alt: Velocity contour showing airflow distribution | ||
|
|
||
|
|
||
| surface_integrals_reports = SurfaceIntegrals(solver) | ||
|
|
||
| surface_integrals_reports.area_weighted_avg( | ||
| file_name="velocity_area_avg_of_outlets", | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| report_of="velocity-magnitude", | ||
| surface_names=["*outlet_*"], | ||
| write_to_file=True, | ||
| ) | ||
| # %% | ||
| # Computes the area-weighted average of velocity magnitude over all outlet surfaces and writes the results to a | ||
| # "Surface Integral Report" file, listing the velocity values for each outlet. | ||
MohammedAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| solver.settings.file.write_case_data(file_name="poultry_ventilation") | ||
| # %% | ||
| # Save case and data | ||
|
|
||
| # %% | ||
| # Close session | ||
| # ^^^^^^^^^^^^^ | ||
| solver.exit() | ||
|
|
||
| # %% | ||
| # Discussion | ||
| # ^^^^^^^^^^ | ||
| # | ||
| # The airflow behavior inside the mechanically ventilated house was analyzed using | ||
| # velocity contour, pathlines, and surface integral reports obtained from the PyFluent simulation. | ||
| # | ||
| # Pathline visualizations illustrated the trajectories of air entering through the side inlets and | ||
| # exiting through the exhaust fans. These pathlines confirmed the effective transport of fresh air | ||
| # across the poultry house and demonstrated the interaction between inlet air jets and the exhaust-driven flow. | ||
| # | ||
| # Quantitative assessment of ventilation performance was conducted using area-weighted average velocity values | ||
| # at the exhaust outlets. The outlet velocities ranged from approximately 7.99 m/s to 8.94 m/s, with a | ||
| # net area-weighted average velocity of 8.36 m/s. The relatively small variation in velocity among the | ||
| # six outlets indicates a balanced and uniform exhaust performance, suggesting that the ventilation | ||
| # system effectively distributes airflow across the outlets without significant flow imbalance. | ||
| # | ||
| # Overall, the combined analysis of pathlines, velocity contours, and outlet velocity averages | ||
| # demonstrates that the simulated ventilation system provides effective airflow transport and | ||
| # reasonably uniform exhaust performance. These results validate the use of PyFluent for evaluating | ||
| # ventilation effectiveness and offer valuable insights for optimizing inlet and fan configurations | ||
| # to further improve airflow distribution and indoor air quality in mechanically ventilated poultry housing. | ||
|
|
||
| # sphinx_gallery_thumbnail_path = '_static/wind_flow_2.png' | ||
Oops, something went wrong.
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.