|
| 1 | +# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +""".. _One_Way_FSI_Simulation: |
| 24 | +
|
| 25 | +Modeling One-Way Fluid-Structure Interaction |
| 26 | +------------------------------------------------------------- |
| 27 | +""" |
| 28 | + |
| 29 | +# %% |
| 30 | +# Objective |
| 31 | +# --------- |
| 32 | +# |
| 33 | +# This example models turbulent airflow through a cylindrical test chamber |
| 34 | +# that contains a steel probe. The airflow generates aerodynamic forces on |
| 35 | +# the probe, causing it to deform. In this case, the deformation is expected |
| 36 | +# to be small compared with the overall flow field. Because the probe’s motion |
| 37 | +# does not significantly alter the airflow, we can treat the problem using |
| 38 | +# a one-way fluid–structure interaction (FSI) approach. |
| 39 | +# |
| 40 | +# In a one-way FSI analysis, the fluid flow is solved first and the |
| 41 | +# resulting forces are transferred to the structural model. The |
| 42 | +# structural response is then computed independently, without feeding |
| 43 | +# back into the fluid solution. This contrasts with a two-way FSI |
| 44 | +# analysis, where structural deformation and fluid flow are solved |
| 45 | +# in a fully coupled manner. The one-way approach is computationally |
| 46 | +# more efficient and appropriate when structural feedback on the flow |
| 47 | +# can be neglected. |
| 48 | + |
| 49 | +# %% |
| 50 | +# Problem Description |
| 51 | +# ------------------- |
| 52 | +# |
| 53 | +# The cylindrical test chamber is 20 cm long, with a diameter of 10 cm. |
| 54 | +# Turbulent air enters the chamber at 100 m/s, flows around and through |
| 55 | +# the steel probe, and exits through a pressure outlet. |
| 56 | +# |
| 57 | +# |
| 58 | +# .. image:: ../../_static/fsi_1way_1.png |
| 59 | +# :align: center |
| 60 | +# :alt: One-Way Fluid-Structure Interaction Model |
| 61 | + |
| 62 | +# %% |
| 63 | +# Import modules |
| 64 | +# -------------- |
| 65 | +# |
| 66 | +# .. note:: |
| 67 | +# Importing the following classes offer streamlined access to key solver settings, |
| 68 | +# eliminating the need to manually browse through the full settings structure. |
| 69 | + |
| 70 | +import os |
| 71 | + |
| 72 | +import ansys.fluent.core as pyfluent |
| 73 | +from ansys.fluent.core import FluentMode, Precision, examples |
| 74 | +from ansys.fluent.core.solver import ( |
| 75 | + BoundaryConditions, |
| 76 | + Contour, |
| 77 | + Graphics, |
| 78 | + Initialization, |
| 79 | + RunCalculation, |
| 80 | + Setup, |
| 81 | + Solution, |
| 82 | + VelocityInlet, |
| 83 | +) |
| 84 | + |
| 85 | +# %% |
| 86 | +# Launch Fluent session in solver mode |
| 87 | +# ------------------------------------ |
| 88 | + |
| 89 | +solver = pyfluent.launch_fluent( |
| 90 | + precision=Precision.DOUBLE, |
| 91 | + mode=FluentMode.SOLVER, |
| 92 | +) |
| 93 | + |
| 94 | +# %% |
| 95 | +# Download and read the mesh file |
| 96 | +# ------------------------------- |
| 97 | + |
| 98 | +mesh_file = examples.download_file( |
| 99 | + "fsi_1way.msh.h5", |
| 100 | + "pyfluent/fsi_1way", |
| 101 | + save_path=os.getcwd(), |
| 102 | +) |
| 103 | +solver.settings.file.read_case(file_name=mesh_file) |
| 104 | + |
| 105 | +# %% |
| 106 | +# Configure solver settings for fluid flow |
| 107 | +# ---------------------------------------- |
| 108 | + |
| 109 | +velocity_inlet = VelocityInlet(solver, name="velocity_inlet") |
| 110 | +velocity_inlet.momentum.velocity_magnitude = 100.0 # High-speed inlet flow (m/s) |
| 111 | +velocity_inlet.turbulence.turbulent_viscosity_ratio = ( |
| 112 | + 5 # Dimensionless, typically 1-10 for moderate turbulence |
| 113 | +) |
| 114 | + |
| 115 | +# %% |
| 116 | +# Initialize and run fluid flow simulation |
| 117 | +# ---------------------------------------- |
| 118 | + |
| 119 | +initialize = Initialization(solver) |
| 120 | +initialize.hybrid_initialize() |
| 121 | + |
| 122 | +calculation = RunCalculation(solver) |
| 123 | +calculation.iterate(iter_count=100) |
| 124 | + |
| 125 | +# %% |
| 126 | +# Post-processing |
| 127 | +# --------------- |
| 128 | + |
| 129 | +graphics = Graphics(solver) |
| 130 | +graphics.picture.x_resolution = 650 # Horizontal resolution for clear visualization |
| 131 | +graphics.picture.y_resolution = 450 # Vertical resolution matching typical aspect ratio |
| 132 | + |
| 133 | +graphics.contour["contour-vel"] = { |
| 134 | + "field": "velocity-magnitude", |
| 135 | + "surfaces_list": ["fluid-symmetry"], |
| 136 | + "coloring": {"option": "banded"}, |
| 137 | +} |
| 138 | + |
| 139 | +graphics.contour["contour-vel"].display() |
| 140 | +graphics.views.restore_view(view_name="front") |
| 141 | + |
| 142 | +graphics.picture.save_picture(file_name="fsi_1way_2.png") |
| 143 | + |
| 144 | + |
| 145 | +# %% |
| 146 | +# .. image:: ../../_static/fsi_1way_2.png |
| 147 | +# :align: center |
| 148 | +# :alt: Velocity Contour |
| 149 | + |
| 150 | +# %% |
| 151 | +# Structural model and material setup |
| 152 | +# ----------------------------------- |
| 153 | +# To analyze the deformation of a steel probe under fluid flow, |
| 154 | +# Linear Elasticity Structural model is chosen |
| 155 | + |
| 156 | +setup = Setup(solver) |
| 157 | +setup.models.structure.model = "linear-elasticity" |
| 158 | + |
| 159 | +# Copy materials from the database and assign to solid zone |
| 160 | + |
| 161 | +setup.materials.database.copy_by_name(type="solid", name="steel") |
| 162 | +setup.cell_zone_conditions.solid["solid"] = {"general": {"material": "steel"}} |
| 163 | + |
| 164 | +# %% |
| 165 | +# Structural boundary conditions |
| 166 | +# ------------------------------ |
| 167 | +# configure Fluent to define the steel probe's support and movement using |
| 168 | +# structural boundary conditions |
| 169 | + |
| 170 | +wall_boundary = BoundaryConditions(solver) |
| 171 | + |
| 172 | +# Configure solid-symmetry boundary |
| 173 | +wall_boundary.wall["solid-symmetry"] = { |
| 174 | + "structure": { |
| 175 | + "z_disp_boundary_value": 0, |
| 176 | + "z_disp_boundary_condition": "Node Z-Displacement", |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +# Set solid-top boundary (fully fixed) |
| 181 | +wall_boundary.wall["solid-top"] = { |
| 182 | + "structure": { |
| 183 | + "z_disp_boundary_value": 0, |
| 184 | + "z_disp_boundary_condition": "Node Z-Displacement", |
| 185 | + "y_disp_boundary_value": 0, |
| 186 | + "y_disp_boundary_condition": "Node Y-Displacement", |
| 187 | + "x_disp_boundary_value": 0, |
| 188 | + "x_disp_boundary_condition": "Node X-Displacement", |
| 189 | + } |
| 190 | +} |
| 191 | + |
| 192 | +# Copy boundary conditions from solid-symmetry to solid-symmetry:011 |
| 193 | +wall_boundary.copy(from_="solid-symmetry", to=["solid-symmetry:011"]) |
| 194 | + |
| 195 | +# Configure FSI surface |
| 196 | +wall_boundary.wall["fsisurface-solid"] = { |
| 197 | + "structure": { |
| 198 | + "x_disp_boundary_condition": "Intrinsic FSI", |
| 199 | + "y_disp_boundary_condition": "Intrinsic FSI", |
| 200 | + "z_disp_boundary_condition": "Intrinsic FSI", |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +# %% |
| 205 | +# Inclusion of Operating Pressure in Fluid-Structure Interaction Forces |
| 206 | +# --------------------------------------------------------------------- |
| 207 | +# Fluent uses gauge pressure for fluid-structure interaction force calculations. |
| 208 | +# By setting ``include_pop_in_fsi_force`` to ``True``, Fluent uses absolute pressure. |
| 209 | + |
| 210 | +setup.models.structure.expert.include_pop_in_fsi_force = True |
| 211 | + |
| 212 | +# %% |
| 213 | +# Configure flow settings |
| 214 | +# ----------------------- |
| 215 | +# Disable flow equations for structural simulation |
| 216 | + |
| 217 | +solution = Solution(solver) |
| 218 | +solution.controls.equations["flow"] = False |
| 219 | +solution.controls.equations["kw"] = False |
| 220 | + |
| 221 | +# %% |
| 222 | +# Run FSI simulation |
| 223 | +# ------------------ |
| 224 | + |
| 225 | +solver.settings.file.write_case(file_name="probe_fsi_1way.cas.h5") |
| 226 | + |
| 227 | +calculation.iterate(iter_count=2) |
| 228 | + |
| 229 | +# %% |
| 230 | +# Structural Postprocessing |
| 231 | +# ------------------------- |
| 232 | + |
| 233 | +displacement_contour = Contour(solver, new_instance_name="displacement_contour") |
| 234 | + |
| 235 | +displacement_contour.field = "total-displacement" |
| 236 | +displacement_contour.surfaces_list = ["fsisurface-solid"] |
| 237 | + |
| 238 | +displacement_contour.display() |
| 239 | +graphics.views.restore_view(view_name="isometric") |
| 240 | +graphics.picture.save_picture(file_name="fsi_1way_3.png") |
| 241 | + |
| 242 | +# save the case and data file |
| 243 | +solver.settings.file.write_case_data(file_name="probe_fsi_1way") |
| 244 | + |
| 245 | +# %% |
| 246 | +# .. image:: ../../_static/fsi_1way_3.png |
| 247 | +# :align: center |
| 248 | +# :alt: Structural Displacement Contour |
| 249 | + |
| 250 | +# %% |
| 251 | +# Close Fluent |
| 252 | +# ------------ |
| 253 | +solver.exit() |
| 254 | + |
| 255 | +####################################################################################### |
| 256 | +# References: |
| 257 | +# ===================================================================================== |
| 258 | +# .. _Reference: |
| 259 | +# [1] Modeling One-Way Fluid-Structure Interaction (FSI) Within Fluent, `Ansys Fluent documentation <https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/corp/v252/en/flu_tg/flu_tg_fsi_1way.html>`_. |
| 260 | + |
| 261 | +# sphinx_gallery_thumbnail_path = '_static/fsi_1way_2.png' |
0 commit comments