From e1c1f889a17750ac530cd6c1fc3d8ee86c613172 Mon Sep 17 00:00:00 2001 From: Krishna Kuntar Date: Wed, 5 Nov 2025 13:12:12 -0500 Subject: [PATCH 01/10] Added cht pipe example. --- examples/00-systemcoupling/cht_pipe.py | 116 +++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 examples/00-systemcoupling/cht_pipe.py diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py new file mode 100644 index 000000000..776e9b66e --- /dev/null +++ b/examples/00-systemcoupling/cht_pipe.py @@ -0,0 +1,116 @@ +# Copyright (C) 2023 - 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. + +""".. _ref_CHT_pipe_example: + +Conjugate Heat transfer- Pipe flow +----------------------------------- + +This example illustrates a two way conjugate heat transfer case for *flow in a pipe* that is used as +a tutorial for System Coupling. This Fluid-Structure interaction (FSI) is based on a steady case fluid flow +in a pipe with surface data transfers. + +- Ansys Mechanical APDL (MAPDL) is used to perform a structural analysis. +- Ansys Fluent is used to perform a steady fluid-flow analysis. +- System Coupling coordinates the coupled sloution involving the above prodcuts to + solve the multiphysics problem via co-simulation. + +**Problem description** + +A fluid at a certain temperature flows into a pipe of known diameter and length. As it flows, the heated wall +of the pipe conducts heat to the inner wall, which in turns heats the fluid and cools down the walls of the pipe. +#image + +The flow is smooth inside the pipe and the outer wall of the pipe is adiabatic. Fluid enters at an initial +temperature of 300K while the outside pipe of the wall is at some higher temperature. The setup is simulated for +a few iterations to allow the examination of the temperature field in the pipe. + + """ +# %% +# Import modules, download files, launch products +# ----------------------------------------------- +# Setting up this example consists of performing imports, downloading +# the input file, and launching the required products. +# +# Perform required imports +# ~~~~~~~~~~~~~~~~~~~~~~~~ +# Import ``ansys-systemcoupling-core``, ``ansys-fluent-core`` + +import ansys.fluent.core as pyfluent +import ansys.systemcoupling.core as pysyc + +# launch Fluent session and read in mesh file +pipe_fluid_session = pyfluent.launch_fluent(start_transcript=False) +pipe_fluid_mesh_file = "pipe_fluid.msh.h5" +pipe_fluid_session.file.read(file_type="mesh", file_name=pipe_fluid_mesh_file) + +# %% +# Setup +# ----- +# The setup consists of setting up the fluids analysis and the coupled analysis. + +# turn on energy model +pipe_fluid_session.setup.models.energy.enabled = True + +# add water material +pipe_fluid_session.setup.materials.database.copy_by_name(type="fluid", name="water-liquid") + +# set up cell zone conditions +pipe_fluid_session.setup.cell_zone_conditions.fluid["fluid"].material = "water-liquid" + +# set up boundary conditions +pipe_fluid_session.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 +pipe_fluid_session.setup.boundary_conditions.wall["wall"].thermal.thermal_bc = "via System Coupling" + +# set up solver settings - 1 fluent iteration per 1 coupling iteration +pipe_fluid_session.solution.run_calculation.iter_count = 1 + +#=== + +# launch another Fluent session and read in mesh file +pipe_solid_session = pyfluent.launch_fluent(start_transcript=False) +pipe_solid_mesh_file = "pipe_solid.msh.h5" +pipe_solid_session.file.read(file_type="mesh", file_name=pipe_solid_mesh_file) + +# turn on energy model +pipe_solid_session.setup.models.energy.enabled = True + +# add copper material +pipe_solid_session.setup.materials.database.copy_by_name(type="solid", name="copper") + +# set up cell zone conditions +pipe_solid_session.setup.cell_zone_conditions.solid["solid"].material = "copper" + +# set up boundary conditions +pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.thermal_bc = "Temperature" +pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.t.value = 350 + +pipe_solid_session.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = "via System Coupling" + +pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.thermal_bc = "Heat Flux" +pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.q.value = 0 + +pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.thermal_bc = "Heat Flux" +pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.q.value = 0 + +# set up solver settings - 1 fluent iteration per 1 coupling iteration +pipe_solid_session.solution.run_calculation.iter_count = 1 \ No newline at end of file From 0f41711e23839fb5ae4991fa2704a2b3a604ae6e Mon Sep 17 00:00:00 2001 From: Krishna Kuntar Date: Thu, 6 Nov 2025 15:27:03 -0500 Subject: [PATCH 02/10] Added the second fluent participant to the cht_pipe example. --- examples/00-systemcoupling/cht_pipe.py | 118 +++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 6 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index 776e9b66e..253bb5792 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -58,16 +58,13 @@ import ansys.fluent.core as pyfluent import ansys.systemcoupling.core as pysyc +#=== + # launch Fluent session and read in mesh file pipe_fluid_session = pyfluent.launch_fluent(start_transcript=False) pipe_fluid_mesh_file = "pipe_fluid.msh.h5" pipe_fluid_session.file.read(file_type="mesh", file_name=pipe_fluid_mesh_file) -# %% -# Setup -# ----- -# The setup consists of setting up the fluids analysis and the coupled analysis. - # turn on energy model pipe_fluid_session.setup.models.energy.enabled = True @@ -113,4 +110,113 @@ pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.q.value = 0 # set up solver settings - 1 fluent iteration per 1 coupling iteration -pipe_solid_session.solution.run_calculation.iter_count = 1 \ No newline at end of file +pipe_solid_session.solution.run_calculation.iter_count = 1 + +import numpy as np + + +rho_water = 998.2 +mu_water = 1.002e-3 +k_water = 0.6 +Pr_water = 7.0 + +rho_al = 2700 +k_al = 237 +cp_al = 900 + + +# Flow and Geometry + +u = 0.5 # velocity [m/s] +L = 0.5 # pipe length [m] +D = 0.1 # inner diameter [m] → characteristic length for fluid +t_wall = 0.12 # wall thickness [m] → characteristic length for solid conduction + + +# Functions + +def getReynoldsNumber(rho, u, D, mu): + return rho * u * D / mu + +def getPrandtlNumber(mu, cp, k): + return mu * cp / k + +def getNusseltNumber(Re, Pr, L_over_D): + + if Re < 2300: + Nu = 3.66 # laminar, fully developed + elif Re < 10000: + Nu = 0.023 * Re**0.8 * Pr**0.4 # transitional approximation + else: + Nu = 0.023 * Re**0.8 * Pr**0.4 # fully turbulent + return Nu + +def getConvectionCoefficient(Nu, k_fluid, D): + return Nu * k_fluid / D + +def getBiotNumber(h, k_solid, t_wall): + return h * t_wall / k_solid + + +Re = getReynoldsNumber(rho_water, u, D, mu_water) +Pr = Pr_water # directly used +L_over_D = L / D + +Nu = getNusseltNumber(Re, Pr, L_over_D) +h = getConvectionCoefficient(Nu, k_water, D) +Bi = getBiotNumber(h, k_al, t_wall) + + +print(f"{'Parameter':<25} {'Value':<15} {'Unit'}") +print("-" * 50) +print(f"{'Reynolds Number (Re)':<25} {Re:<15.2f}") +print(f"{'Prandtl Number (Pr)':<25} {Pr:<15.1f}") +print(f"{'Nusselt Number (Nu)':<25} {Nu:<15.2f}") +print(f"{'Convection coeff (h)':<25} {h:<15.1f} W/m²·K") +print(f"{'Biot Number (Bi)':<25} {Bi:<15.6f}") +print("-" * 50) +print(f"The Biot number is {Bi:.6f}") + + +if Bi < 0.1: + print("→ Bi < 0.1 → Lumped capacitance valid (uniform wall temperature)") +elif Bi > 10: + print("→ Bi > 10 → Significant temperature gradient in wall") +else: + print("→ 0.1 < Bi < 10 → Moderate internal resistance") +#=== + +# launch System Coupling session +syc = pysyc.launch() +syc.start_output() + +# add two Fluent sessions above as participants +fluid_name = syc.setup.add_participant(participant_session = pipe_fluid_session) +solid_name = syc.setup.add_participant(participant_session = pipe_solid_session) +syc.setup.coupling_participant[fluid_name].display_name = "Fluid" +syc.setup.coupling_participant[solid_name].display_name = "Solid" + +# add a coupling interface +interface = syc.setup.add_interface( + side_one_participant = fluid_name, side_one_regions = ["wall"], + side_two_participant = solid_name, side_two_regions = ["inner_wall"]) + +# set up 2-way coupling - add temperature and heat flow data transfers +syc.setup.add_thermal_data_transfers(interface = interface) + +# set up coupled analysis settings +# it should take about 80 iterations to converge +syc.setup.solution_control.maximum_iterations = 100 + +#=== + +# solve the coupled analysis +syc.solution.solve() + +#=== + +# clean up at the end +syc.end_output() +pipe_fluid_session.exit() +pipe_solid_session.exit() +syc.exit() \ No newline at end of file From ec7eb7c45b5d623482fc0c4b895dd58d6b61f7ce Mon Sep 17 00:00:00 2001 From: Krishna Kuntar Date: Mon, 10 Nov 2025 10:46:29 -0500 Subject: [PATCH 03/10] Apply black formatting and fix style issues --- examples/00-systemcoupling/cht_pipe.py | 114 +++++++++++++++---------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index 253bb5792..f1dcd0b64 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -25,26 +25,29 @@ Conjugate Heat transfer- Pipe flow ----------------------------------- -This example illustrates a two way conjugate heat transfer case for *flow in a pipe* that is used as -a tutorial for System Coupling. This Fluid-Structure interaction (FSI) is based on a steady case fluid flow -in a pipe with surface data transfers. +This example illustrates a two way conjugate heat transfer case for +*flow in a pipe* that is used as a tutorial for System Coupling. This Fluid-Structure +interaction (FSI) is based on a steady case fluid flow in a pipe with surface data transfers. - Ansys Mechanical APDL (MAPDL) is used to perform a structural analysis. - Ansys Fluent is used to perform a steady fluid-flow analysis. -- System Coupling coordinates the coupled sloution involving the above prodcuts to +- System Coupling coordinates the coupled sloution involving the above products to solve the multiphysics problem via co-simulation. - -**Problem description** -A fluid at a certain temperature flows into a pipe of known diameter and length. As it flows, the heated wall -of the pipe conducts heat to the inner wall, which in turns heats the fluid and cools down the walls of the pipe. +**Problem description** + +A fluid at a certain temperature flows into a pipe of known diameter and length. As it flows, +the heated wall of the pipe conducts heat to the inner wall, which in turns heats the fluid and +cools down the walls of the pipe. + #image -The flow is smooth inside the pipe and the outer wall of the pipe is adiabatic. Fluid enters at an initial -temperature of 300K while the outside pipe of the wall is at some higher temperature. The setup is simulated for -a few iterations to allow the examination of the temperature field in the pipe. +The flow is smooth inside the pipe and the outer wall of the pipe is adiabatic. Fluid enters +at an initial temperature of 300K while the outside pipe of the wall is at some higher +temperature. The setup is simulated for a few iterations to allow the examination +of the temperature field in the pipe. - """ +""" # %% # Import modules, download files, launch products # ----------------------------------------------- @@ -56,9 +59,10 @@ # Import ``ansys-systemcoupling-core``, ``ansys-fluent-core`` import ansys.fluent.core as pyfluent + import ansys.systemcoupling.core as pysyc -#=== +# === # launch Fluent session and read in mesh file pipe_fluid_session = pyfluent.launch_fluent(start_transcript=False) @@ -69,19 +73,25 @@ pipe_fluid_session.setup.models.energy.enabled = True # add water material -pipe_fluid_session.setup.materials.database.copy_by_name(type="fluid", name="water-liquid") +pipe_fluid_session.setup.materials.database.copy_by_name( + type="fluid", name="water-liquid" +) # set up cell zone conditions pipe_fluid_session.setup.cell_zone_conditions.fluid["fluid"].material = "water-liquid" # set up boundary conditions -pipe_fluid_session.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 -pipe_fluid_session.setup.boundary_conditions.wall["wall"].thermal.thermal_bc = "via System Coupling" +pipe_fluid_session.setup.boundary_conditions.velocity_inlet[ + "inlet" +].momentum.velocity = 0.1 +pipe_fluid_session.setup.boundary_conditions.wall["wall"].thermal.thermal_bc = ( + "via System Coupling" +) # set up solver settings - 1 fluent iteration per 1 coupling iteration pipe_fluid_session.solution.run_calculation.iter_count = 1 -#=== +# === # launch another Fluent session and read in mesh file pipe_solid_session = pyfluent.launch_fluent(start_transcript=False) @@ -98,51 +108,60 @@ pipe_solid_session.setup.cell_zone_conditions.solid["solid"].material = "copper" # set up boundary conditions -pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.thermal_bc = "Temperature" +pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.thermal_bc = ( + "Temperature" +) pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.t.value = 350 -pipe_solid_session.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = "via System Coupling" +pipe_solid_session.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = ( + "via System Coupling" +) -pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.thermal_bc = "Heat Flux" +pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.thermal_bc = ( + "Heat Flux" +) pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.q.value = 0 -pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.thermal_bc = "Heat Flux" +pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.thermal_bc = ( + "Heat Flux" +) pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.q.value = 0 # set up solver settings - 1 fluent iteration per 1 coupling iteration pipe_solid_session.solution.run_calculation.iter_count = 1 -import numpy as np +rho_water = 998.2 +mu_water = 1.002e-3 +k_water = 0.6 +Pr_water = 7.0 -rho_water = 998.2 -mu_water = 1.002e-3 -k_water = 0.6 -Pr_water = 7.0 - -rho_al = 2700 -k_al = 237 -cp_al = 900 +rho_al = 2700 +k_al = 237 +cp_al = 900 # Flow and Geometry -u = 0.5 # velocity [m/s] -L = 0.5 # pipe length [m] -D = 0.1 # inner diameter [m] → characteristic length for fluid -t_wall = 0.12 # wall thickness [m] → characteristic length for solid conduction +u = 0.5 # velocity [m/s] +L = 0.5 # pipe length [m] +D = 0.1 # inner diameter [m] → characteristic length for fluid +t_wall = 0.12 # wall thickness [m] → characteristic length for solid conduction # Functions + def getReynoldsNumber(rho, u, D, mu): return rho * u * D / mu + def getPrandtlNumber(mu, cp, k): return mu * cp / k + def getNusseltNumber(Re, Pr, L_over_D): - + if Re < 2300: Nu = 3.66 # laminar, fully developed elif Re < 10000: @@ -151,9 +170,11 @@ def getNusseltNumber(Re, Pr, L_over_D): Nu = 0.023 * Re**0.8 * Pr**0.4 # fully turbulent return Nu + def getConvectionCoefficient(Nu, k_fluid, D): return Nu * k_fluid / D + def getBiotNumber(h, k_solid, t_wall): return h * t_wall / k_solid @@ -163,7 +184,7 @@ def getBiotNumber(h, k_solid, t_wall): L_over_D = L / D Nu = getNusseltNumber(Re, Pr, L_over_D) -h = getConvectionCoefficient(Nu, k_water, D) +h = getConvectionCoefficient(Nu, k_water, D) Bi = getBiotNumber(h, k_al, t_wall) @@ -184,39 +205,42 @@ def getBiotNumber(h, k_solid, t_wall): print("→ Bi > 10 → Significant temperature gradient in wall") else: print("→ 0.1 < Bi < 10 → Moderate internal resistance") -#=== +# === # launch System Coupling session syc = pysyc.launch() syc.start_output() # add two Fluent sessions above as participants -fluid_name = syc.setup.add_participant(participant_session = pipe_fluid_session) -solid_name = syc.setup.add_participant(participant_session = pipe_solid_session) +fluid_name = syc.setup.add_participant(participant_session=pipe_fluid_session) +solid_name = syc.setup.add_participant(participant_session=pipe_solid_session) syc.setup.coupling_participant[fluid_name].display_name = "Fluid" syc.setup.coupling_participant[solid_name].display_name = "Solid" # add a coupling interface interface = syc.setup.add_interface( - side_one_participant = fluid_name, side_one_regions = ["wall"], - side_two_participant = solid_name, side_two_regions = ["inner_wall"]) + side_one_participant=fluid_name, + side_one_regions=["wall"], + side_two_participant=solid_name, + side_two_regions=["inner_wall"], +) # set up 2-way coupling - add temperature and heat flow data transfers -syc.setup.add_thermal_data_transfers(interface = interface) +syc.setup.add_thermal_data_transfers(interface=interface) # set up coupled analysis settings # it should take about 80 iterations to converge syc.setup.solution_control.maximum_iterations = 100 -#=== +# === # solve the coupled analysis syc.solution.solve() -#=== +# === # clean up at the end syc.end_output() pipe_fluid_session.exit() pipe_solid_session.exit() -syc.exit() \ No newline at end of file +syc.exit() From eca5c654ac9fa0d9f4a499b393da0914519cd74e Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Thu, 20 Nov 2025 16:51:12 -0500 Subject: [PATCH 04/10] updated code to use pymapdl to create geometry --- examples/00-systemcoupling/cht_pipe.py | 324 ++++++++++++------------- 1 file changed, 160 insertions(+), 164 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index f1dcd0b64..01cb41657 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -40,11 +40,11 @@ the heated wall of the pipe conducts heat to the inner wall, which in turns heats the fluid and cools down the walls of the pipe. -#image + The flow is smooth inside the pipe and the outer wall of the pipe is adiabatic. Fluid enters -at an initial temperature of 300K while the outside pipe of the wall is at some higher -temperature. The setup is simulated for a few iterations to allow the examination +at an initial temperature of 300K while the outside pipe of the wall is at 400K. +The setup is simulated for a few iterations to allow the examination of the temperature field in the pipe. """ @@ -58,189 +58,185 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~ # Import ``ansys-systemcoupling-core``, ``ansys-fluent-core`` +import ansys.mapdl.core as pymapdl import ansys.fluent.core as pyfluent - import ansys.systemcoupling.core as pysyc +from ansys.systemcoupling.core import examples -# === - -# launch Fluent session and read in mesh file -pipe_fluid_session = pyfluent.launch_fluent(start_transcript=False) -pipe_fluid_mesh_file = "pipe_fluid.msh.h5" -pipe_fluid_session.file.read(file_type="mesh", file_name=pipe_fluid_mesh_file) - -# turn on energy model -pipe_fluid_session.setup.models.energy.enabled = True - -# add water material -pipe_fluid_session.setup.materials.database.copy_by_name( - type="fluid", name="water-liquid" -) - -# set up cell zone conditions -pipe_fluid_session.setup.cell_zone_conditions.fluid["fluid"].material = "water-liquid" - -# set up boundary conditions -pipe_fluid_session.setup.boundary_conditions.velocity_inlet[ - "inlet" -].momentum.velocity = 0.1 -pipe_fluid_session.setup.boundary_conditions.wall["wall"].thermal.thermal_bc = ( - "via System Coupling" -) - -# set up solver settings - 1 fluent iteration per 1 coupling iteration -pipe_fluid_session.solution.run_calculation.iter_count = 1 - -# === - -# launch another Fluent session and read in mesh file -pipe_solid_session = pyfluent.launch_fluent(start_transcript=False) -pipe_solid_mesh_file = "pipe_solid.msh.h5" -pipe_solid_session.file.read(file_type="mesh", file_name=pipe_solid_mesh_file) - -# turn on energy model -pipe_solid_session.setup.models.energy.enabled = True - -# add copper material -pipe_solid_session.setup.materials.database.copy_by_name(type="solid", name="copper") - -# set up cell zone conditions -pipe_solid_session.setup.cell_zone_conditions.solid["solid"].material = "copper" - -# set up boundary conditions -pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.thermal_bc = ( - "Temperature" -) -pipe_solid_session.setup.boundary_conditions.wall["outer_wall"].thermal.t.value = 350 - -pipe_solid_session.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = ( - "via System Coupling" -) - -pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.thermal_bc = ( - "Heat Flux" -) -pipe_solid_session.setup.boundary_conditions.wall["insulated1"].thermal.q.value = 0 - -pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.thermal_bc = ( - "Heat Flux" +# %% +# Download the mesh file +fluent_msh_file = examples.download_file( + "fluid_domain.msh", "pysystem-coupling/cht_pipe" ) -pipe_solid_session.setup.boundary_conditions.wall["insulated2"].thermal.q.value = 0 - -# set up solver settings - 1 fluent iteration per 1 coupling iteration -pipe_solid_session.solution.run_calculation.iter_count = 1 - - -rho_water = 998.2 -mu_water = 1.002e-3 -k_water = 0.6 -Pr_water = 7.0 -rho_al = 2700 -k_al = 237 -cp_al = 900 +mapdl=pymapdl.launch_mapdl() +mapdl.clear() +mapdl.prep7() + +#%% +#Define material properties +mapdl.mp("EX", 1, 69e9) +mapdl.mp("NUXY", 1, 0.33) +mapdl.mp("DENS", 1, 2700) +mapdl.mp("ALPX", 1, 23.6e-6) +mapdl.mp("KXX", 1, 237) +mapdl.mp("C", 1 , 900) + +#%% +#Set element type to SOLID279 +mapdl.et(1, 279) +mapdl.keyopt(1, 2, 1) +print(mapdl) + +#%% +#Parameter of the pipe +r_in=0.025 +r_out=0.035 +l=0.2 + +#%% +#Create hollow pipe +mapdl.cyl4(0, 0, rad1=r_in, rad2=r_out, depth=l) +mapdl.esize(0.002) +mapdl.vsweep(1) +print(mapdl.geometry.anum) +# %% +# Biot number prediction +def biot_number( + rho=1000, + mu=1e-3, + cp=4180, + k_f=0.6, + k_s=237, + L_c=r_out-r_in, + U=0.1 +): + Re= (rho*U*L_c)/mu + Pr= (mu*cp)/ k_f + Nu= 0.023 * Re**0.8 * Pr**0.4 + h= Nu * k_f / L_c + Bi= h *L_c / k_s + return Bi +Bi=biot_number() +print("The Biot number is ", Bi) -# Flow and Geometry - -u = 0.5 # velocity [m/s] -L = 0.5 # pipe length [m] -D = 0.1 # inner diameter [m] → characteristic length for fluid -t_wall = 0.12 # wall thickness [m] → characteristic length for solid conduction - - -# Functions - - -def getReynoldsNumber(rho, u, D, mu): - return rho * u * D / mu - - -def getPrandtlNumber(mu, cp, k): - return mu * cp / k - - -def getNusseltNumber(Re, Pr, L_over_D): - - if Re < 2300: - Nu = 3.66 # laminar, fully developed - elif Re < 10000: - Nu = 0.023 * Re**0.8 * Pr**0.4 # transitional approximation - else: - Nu = 0.023 * Re**0.8 * Pr**0.4 # fully turbulent - return Nu - - -def getConvectionCoefficient(Nu, k_fluid, D): - return Nu * k_fluid / D - - -def getBiotNumber(h, k_solid, t_wall): - return h * t_wall / k_solid - +# %% +# Creating the regions from the geometry for named selections +#Inner wall NS +mapdl.asel('S', 'AREA', '', 5, 6) +mapdl.nsla('S', 1) +mapdl.cm("FSIN_1", "NODE") +mapdl.allsel() + +#Outer wall NS +mapdl.asel('S', 'AREA', '', 3, 4) +mapdl.cm("Outer_wall", "AREA") +mapdl.allsel() + +#Outlet NS +mapdl.asel('S', 'AREA', '', 2) +mapdl.cm("Outlet", "AREA") +mapdl.allsel() + +#Inlet NS +mapdl.asel('S', 'AREA', '', 1) +mapdl.cm("Inlet", "AREA") +mapdl.allsel() + +#%% +#Boundary conditions +mapdl.cmsel('S', 'Outer_wall') +mapdl.d('Outer_wall', 'TEMP', 77) +mapdl.allsel() + +mapdl.cmsel('S', 'Inlet') +mapdl.sf('ALL', 'HFLUX', 0) +mapdl.allsel() + +mapdl.cmsel('S', 'Outlet') +mapdl.sf('ALL', 'HFLUX', 0) +mapdl.allsel() + +mapdl.cmsel('S', 'FSIN_1') +mapdl.sf('FSIN_1', 'FSIN', 1) +mapdl.allsel() + +#%% +#Setup the rest of the analysis +mapdl.run("/SOLU") +mapdl.antype(0) -Re = getReynoldsNumber(rho_water, u, D, mu_water) -Pr = Pr_water # directly used -L_over_D = L / D +# %% +# Set up the fluid analysis +# ~~~~~~~~~~~~~~~~~~~~~~~~~ -Nu = getNusseltNumber(Re, Pr, L_over_D) -h = getConvectionCoefficient(Nu, k_water, D) -Bi = getBiotNumber(h, k_al, t_wall) +# %% +# Read the pre-created mesh file +fluent=pyfluent.launch_fluent(start_transcript=False) +fluent.file.read(file_type="mesh", file_name=fluent_msh_file) -print(f"{'Parameter':<25} {'Value':<15} {'Unit'}") -print("-" * 50) -print(f"{'Reynolds Number (Re)':<25} {Re:<15.2f}") -print(f"{'Prandtl Number (Pr)':<25} {Pr:<15.1f}") -print(f"{'Nusselt Number (Nu)':<25} {Nu:<15.2f}") -print(f"{'Convection coeff (h)':<25} {h:<15.1f} W/m²·K") -print(f"{'Biot Number (Bi)':<25} {Bi:<15.6f}") -print("-" * 50) -print(f"The Biot number is {Bi:.6f}") +#%% +#Define the fluid solver settings +fluent.setup.models.energy.enabled =True +#%% +#Add the material +fluent.setup.materials.database.copy_by_name(type="fluid", name="water-liquid") -if Bi < 0.1: - print("→ Bi < 0.1 → Lumped capacitance valid (uniform wall temperature)") -elif Bi > 10: - print("→ Bi > 10 → Significant temperature gradient in wall") -else: - print("→ 0.1 < Bi < 10 → Moderate internal resistance") -# === +fluent.setup.cell_zone_conditions.fluid["fff_fluiddomain"].material = "water-liquid" -# launch System Coupling session -syc = pysyc.launch() -syc.start_output() +#%% +#Define boundary conditions +fluent.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 +fluent.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = 300 +fluent.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = "via System Coupling" -# add two Fluent sessions above as participants -fluid_name = syc.setup.add_participant(participant_session=pipe_fluid_session) -solid_name = syc.setup.add_participant(participant_session=pipe_solid_session) -syc.setup.coupling_participant[fluid_name].display_name = "Fluid" -syc.setup.coupling_participant[solid_name].display_name = "Solid" +fluent.solution.run_calculation.iter_count = 20 -# add a coupling interface -interface = syc.setup.add_interface( - side_one_participant=fluid_name, - side_one_regions=["wall"], - side_two_participant=solid_name, - side_two_regions=["inner_wall"], +# %% +# Set up the coupled analysis +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# System Coupling setup involves adding the structural and fluid +# participants, adding coupled interfaces and data transfers, +# and setting other coupled analysis properties. +syc=pysyc.launch(start_output= True) + +#%% +# Add participants by passing session handles to System Coupling. +fluid_name=syc.setup.add_participant(participant_session= fluent) +solid_name=syc.setup.add_participant(participant_session= mapdl) + +syc.setup.coupling_participant[fluid_name].display_name= "Fluid" +syc.setup.coupling_participant[solid_name].display_name= "Solid" + +#%% +#Add coupling face and data transfers +interface_name=syc.setup.add_interface( + side_one_participant= fluid_name, side_one_regions= ["inner_wall"], + side_two_participant= solid_name, side_two_regions= ["FSIN_1"] ) -# set up 2-way coupling - add temperature and heat flow data transfers -syc.setup.add_thermal_data_transfers(interface=interface) +#%% +#Set up 2-way thermal FSI coupling +syc.setup.add_thermal_data_transfers(interface = interface_name) -# set up coupled analysis settings -# it should take about 80 iterations to converge -syc.setup.solution_control.maximum_iterations = 100 +# %% +# Time step size, end time, output controls +syc.setup.solution_control.time_step_size = "0.1 [s]" # time step is 0.1 [s] +syc.setup.solution_control.end_time = 10 # end time is 10.0 [s] -# === +syc.setup.solution_control.maximum_iterations=100 -# solve the coupled analysis +# %% +# Solution +# -------- syc.solution.solve() -# === - -# clean up at the end +# %% +# Exit +# ---- syc.end_output() -pipe_fluid_session.exit() -pipe_solid_session.exit() syc.exit() + From e6dd1798590a0f454a431b42c1f9f19184339e47 Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Fri, 21 Nov 2025 13:15:38 -0500 Subject: [PATCH 05/10] formatted the code --- examples/00-systemcoupling/cht_pipe.py | 153 ++++++++++++------------- 1 file changed, 76 insertions(+), 77 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index 01cb41657..3380f8f5a 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -43,7 +43,7 @@ The flow is smooth inside the pipe and the outer wall of the pipe is adiabatic. Fluid enters -at an initial temperature of 300K while the outside pipe of the wall is at 400K. +at an initial temperature of 300K while the outside pipe of the wall is at 400K. The setup is simulated for a few iterations to allow the examination of the temperature field in the pipe. @@ -58,8 +58,9 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~ # Import ``ansys-systemcoupling-core``, ``ansys-fluent-core`` -import ansys.mapdl.core as pymapdl import ansys.fluent.core as pyfluent +import ansys.mapdl.core as pymapdl + import ansys.systemcoupling.core as pysyc from ansys.systemcoupling.core import examples @@ -69,101 +70,96 @@ "fluid_domain.msh", "pysystem-coupling/cht_pipe" ) -mapdl=pymapdl.launch_mapdl() +mapdl = pymapdl.launch_mapdl() mapdl.clear() mapdl.prep7() -#%% -#Define material properties +# %% +# Define material properties mapdl.mp("EX", 1, 69e9) mapdl.mp("NUXY", 1, 0.33) mapdl.mp("DENS", 1, 2700) mapdl.mp("ALPX", 1, 23.6e-6) mapdl.mp("KXX", 1, 237) -mapdl.mp("C", 1 , 900) +mapdl.mp("C", 1, 900) -#%% -#Set element type to SOLID279 +# %% +# Set element type to SOLID279 mapdl.et(1, 279) mapdl.keyopt(1, 2, 1) print(mapdl) -#%% -#Parameter of the pipe -r_in=0.025 -r_out=0.035 -l=0.2 +# %% +# Parameter of the pipe +r_in = 0.025 +r_out = 0.035 +l = 0.2 -#%% -#Create hollow pipe -mapdl.cyl4(0, 0, rad1=r_in, rad2=r_out, depth=l) +# %% +# Create hollow pipe +mapdl.cyl4(0, 0, rad1=r_in, rad2=r_out, depth=l) mapdl.esize(0.002) mapdl.vsweep(1) print(mapdl.geometry.anum) + # %% # Biot number prediction -def biot_number( - rho=1000, - mu=1e-3, - cp=4180, - k_f=0.6, - k_s=237, - L_c=r_out-r_in, - U=0.1 -): - Re= (rho*U*L_c)/mu - Pr= (mu*cp)/ k_f - Nu= 0.023 * Re**0.8 * Pr**0.4 - h= Nu * k_f / L_c - Bi= h *L_c / k_s +def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, U=0.1): + Re = (rho * U * L_c) / mu + Pr = (mu * cp) / k_f + Nu = 0.023 * Re**0.8 * Pr**0.4 + h = Nu * k_f / L_c + Bi = h * L_c / k_s return Bi -Bi=biot_number() + + +Bi = biot_number() print("The Biot number is ", Bi) # %% # Creating the regions from the geometry for named selections -#Inner wall NS -mapdl.asel('S', 'AREA', '', 5, 6) -mapdl.nsla('S', 1) +# Inner wall NS +mapdl.asel("S", "AREA", "", 5, 6) +mapdl.nsla("S", 1) mapdl.cm("FSIN_1", "NODE") mapdl.allsel() -#Outer wall NS -mapdl.asel('S', 'AREA', '', 3, 4) +# Outer wall NS +mapdl.asel("S", "AREA", "", 3, 4) mapdl.cm("Outer_wall", "AREA") mapdl.allsel() -#Outlet NS -mapdl.asel('S', 'AREA', '', 2) +# Outlet NS +mapdl.asel("S", "AREA", "", 2) mapdl.cm("Outlet", "AREA") mapdl.allsel() -#Inlet NS -mapdl.asel('S', 'AREA', '', 1) +# Inlet NS +mapdl.asel("S", "AREA", "", 1) mapdl.cm("Inlet", "AREA") mapdl.allsel() -#%% -#Boundary conditions -mapdl.cmsel('S', 'Outer_wall') -mapdl.d('Outer_wall', 'TEMP', 77) +# %% +# Boundary conditions +mapdl.cmsel("S", "Outer_wall") +mapdl.d("Outer_wall", "TEMP", 77) mapdl.allsel() -mapdl.cmsel('S', 'Inlet') -mapdl.sf('ALL', 'HFLUX', 0) +mapdl.cmsel("S", "Inlet") +mapdl.sf("ALL", "HFLUX", 0) mapdl.allsel() -mapdl.cmsel('S', 'Outlet') -mapdl.sf('ALL', 'HFLUX', 0) +mapdl.cmsel("S", "Outlet") +mapdl.sf("ALL", "HFLUX", 0) mapdl.allsel() -mapdl.cmsel('S', 'FSIN_1') -mapdl.sf('FSIN_1', 'FSIN', 1) +mapdl.cmsel("S", "FSIN_1") +mapdl.sf("FSIN_1", "FSIN", 1) mapdl.allsel() -#%% -#Setup the rest of the analysis +# %% +# Setup the rest of the analysis mapdl.run("/SOLU") mapdl.antype(0) @@ -174,24 +170,26 @@ def biot_number( # %% # Read the pre-created mesh file -fluent=pyfluent.launch_fluent(start_transcript=False) +fluent = pyfluent.launch_fluent(start_transcript=False) fluent.file.read(file_type="mesh", file_name=fluent_msh_file) -#%% -#Define the fluid solver settings -fluent.setup.models.energy.enabled =True +# %% +# Define the fluid solver settings +fluent.setup.models.energy.enabled = True -#%% -#Add the material +# %% +# Add the material fluent.setup.materials.database.copy_by_name(type="fluid", name="water-liquid") fluent.setup.cell_zone_conditions.fluid["fff_fluiddomain"].material = "water-liquid" -#%% -#Define boundary conditions +# %% +# Define boundary conditions fluent.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 fluent.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = 300 -fluent.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = "via System Coupling" +fluent.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = ( + "via System Coupling" +) fluent.solution.run_calculation.iter_count = 20 @@ -201,33 +199,35 @@ def biot_number( # System Coupling setup involves adding the structural and fluid # participants, adding coupled interfaces and data transfers, # and setting other coupled analysis properties. -syc=pysyc.launch(start_output= True) +syc = pysyc.launch(start_output=True) -#%% +# %% # Add participants by passing session handles to System Coupling. -fluid_name=syc.setup.add_participant(participant_session= fluent) -solid_name=syc.setup.add_participant(participant_session= mapdl) +fluid_name = syc.setup.add_participant(participant_session=fluent) +solid_name = syc.setup.add_participant(participant_session=mapdl) -syc.setup.coupling_participant[fluid_name].display_name= "Fluid" -syc.setup.coupling_participant[solid_name].display_name= "Solid" +syc.setup.coupling_participant[fluid_name].display_name = "Fluid" +syc.setup.coupling_participant[solid_name].display_name = "Solid" -#%% -#Add coupling face and data transfers -interface_name=syc.setup.add_interface( - side_one_participant= fluid_name, side_one_regions= ["inner_wall"], - side_two_participant= solid_name, side_two_regions= ["FSIN_1"] +# %% +# Add coupling face and data transfers +interface_name = syc.setup.add_interface( + side_one_participant=fluid_name, + side_one_regions=["inner_wall"], + side_two_participant=solid_name, + side_two_regions=["FSIN_1"], ) -#%% -#Set up 2-way thermal FSI coupling -syc.setup.add_thermal_data_transfers(interface = interface_name) +# %% +# Set up 2-way thermal FSI coupling +syc.setup.add_thermal_data_transfers(interface=interface_name) # %% # Time step size, end time, output controls syc.setup.solution_control.time_step_size = "0.1 [s]" # time step is 0.1 [s] syc.setup.solution_control.end_time = 10 # end time is 10.0 [s] -syc.setup.solution_control.maximum_iterations=100 +syc.setup.solution_control.maximum_iterations = 100 # %% # Solution @@ -239,4 +239,3 @@ def biot_number( # ---- syc.end_output() syc.exit() - From c5e8ff9ab54c2a404555269bd470529e570354a1 Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Fri, 21 Nov 2025 16:12:55 -0500 Subject: [PATCH 06/10] fixed mapdl instance not opening --- doc/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index dbc081609..2b0d9a16d 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -210,7 +210,7 @@ def _reset_example(gallery_conf, fname: str, when: str): example_name = fname.replace(".py", "") # Add any examples that need MAPDL to this list - using_mapdl_examples = ["oscillating_plate", "turek_hron_fsi2"] + using_mapdl_examples = ["oscillating_plate", "turek_hron_fsi2", "cht_pipe"] # If the examples needs to run MAPDL in a container, launch it before # the example and remove it after. This is because it has been found From 9a35ec96966eb5c6b013da14b14129130066eb7f Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Wed, 26 Nov 2025 15:01:23 -0500 Subject: [PATCH 07/10] updated the example with latest modifications --- examples/00-systemcoupling/cht_pipe.py | 143 +++++++++++++++++-------- 1 file changed, 101 insertions(+), 42 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index 3380f8f5a..4d339ab84 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -25,27 +25,27 @@ Conjugate Heat transfer- Pipe flow ----------------------------------- -This example illustrates a two way conjugate heat transfer case for -*flow in a pipe* that is used as a tutorial for System Coupling. This Fluid-Structure -interaction (FSI) is based on a steady case fluid flow in a pipe with surface data transfers. +Conjugate heat transfer (CHT) simualtions often exhibit numerical sensitivity at the fluid-solid +interface. This example demonstrates how users can appropriately select interface conditiions +and stabilization schemes for a typical pipe-flow configuration. It highlights best practices +for setting up a robust CHT workflow in System Coupling, including managing temperature and +heat-flux exchange, controlling relaxation, ensuring consistent mesh-to-mesh interpolation. -- Ansys Mechanical APDL (MAPDL) is used to perform a structural analysis. -- Ansys Fluent is used to perform a steady fluid-flow analysis. -- System Coupling coordinates the coupled sloution involving the above products to - solve the multiphysics problem via co-simulation. +- Ansys Fluent is used to model the thermal fluid flow in the pipe. +- Ansys Mechanical APDL (MAPDL) is used to model thermal transfer in the pipe wall. +- System Coupling coordinates the coupled solution to the conjugate heat transfer problem, +including numerical stabilization if needed. **Problem description** A fluid at a certain temperature flows into a pipe of known diameter and length. As it flows, -the heated wall of the pipe conducts heat to the inner wall, which in turns heats the fluid and -cools down the walls of the pipe. - +the heated outer wall of the pipe conducts heat to the inner wall, which in turns heats the +fluid and cools down the walls of the pipe. The flow is smooth inside the pipe and the outer wall of the pipe is adiabatic. Fluid enters -at an initial temperature of 300K while the outside pipe of the wall is at 400K. -The setup is simulated for a few iterations to allow the examination -of the temperature field in the pipe. +at an initial temperature of 300K while the outside pipe of the wall is at 350K. + """ # %% @@ -56,7 +56,7 @@ # # Perform required imports # ~~~~~~~~~~~~~~~~~~~~~~~~ -# Import ``ansys-systemcoupling-core``, ``ansys-fluent-core`` +# Import ``ansys-systemcoupling-core``, ``ansys-fluent-core``, ``ansys-mapdl-core`` import ansys.fluent.core as pyfluent import ansys.mapdl.core as pymapdl @@ -70,6 +70,8 @@ "fluid_domain.msh", "pysystem-coupling/cht_pipe" ) +# %% +# Launch MAPDL mapdl = pymapdl.launch_mapdl() mapdl.clear() mapdl.prep7() @@ -89,6 +91,7 @@ mapdl.keyopt(1, 2, 1) print(mapdl) + # %% # Parameter of the pipe r_in = 0.025 @@ -96,52 +99,41 @@ l = 0.2 # %% -# Create hollow pipe +# Create a simple hollow pipe mapdl.cyl4(0, 0, rad1=r_in, rad2=r_out, depth=l) mapdl.esize(0.002) mapdl.vsweep(1) -print(mapdl.geometry.anum) - # %% -# Biot number prediction -def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, U=0.1): - Re = (rho * U * L_c) / mu - Pr = (mu * cp) / k_f - Nu = 0.023 * Re**0.8 * Pr**0.4 - h = Nu * k_f / L_c - Bi = h * L_c / k_s - return Bi - - -Bi = biot_number() -print("The Biot number is ", Bi) +# Visualizing the meshed gemoetry +mapdl.eplot() # %% # Creating the regions from the geometry for named selections -# Inner wall NS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Inner wall Named Selection mapdl.asel("S", "AREA", "", 5, 6) mapdl.nsla("S", 1) mapdl.cm("FSIN_1", "NODE") mapdl.allsel() -# Outer wall NS +# Outer wall Named Selection mapdl.asel("S", "AREA", "", 3, 4) mapdl.cm("Outer_wall", "AREA") mapdl.allsel() -# Outlet NS +# Outlet Named Selection mapdl.asel("S", "AREA", "", 2) mapdl.cm("Outlet", "AREA") mapdl.allsel() -# Inlet NS +# Inlet Named Selection mapdl.asel("S", "AREA", "", 1) mapdl.cm("Inlet", "AREA") mapdl.allsel() # %% -# Boundary conditions +# Boundary conditions in degrees Cesius mapdl.cmsel("S", "Outer_wall") mapdl.d("Outer_wall", "TEMP", 77) mapdl.allsel() @@ -163,12 +155,10 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, mapdl.run("/SOLU") mapdl.antype(0) -# %% -# Set up the fluid analysis -# ~~~~~~~~~~~~~~~~~~~~~~~~~ # %% -# Read the pre-created mesh file +# Set up the fluid analysis and read the pre-created mesh file +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fluent = pyfluent.launch_fluent(start_transcript=False) fluent.file.read(file_type="mesh", file_name=fluent_msh_file) @@ -185,8 +175,8 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, # %% # Define boundary conditions -fluent.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 -fluent.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = 300 +fluent.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 # units: m/s +fluent.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = 300 # Units: Kelvin fluent.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = ( "via System Coupling" ) @@ -220,10 +210,50 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, # %% # Set up 2-way thermal FSI coupling -syc.setup.add_thermal_data_transfers(interface=interface_name) +# ----Temp from solid to fluid---- +temp_transfer= syc.setup.add_data_transfer( + interface=interface_name, + target_side="One", + source_variable='TEMP', + target_variable='temperature' +) + +#----Heat flux from fluid to solid---- +hf_transfer= syc.setup.add_data_transfer( + interface=interface_name, + target_side="Two", + source_variable="heatflow", + target_variable="HFLW" +) + +# %% +# Biot number prediction +# ~~~~~~~~~~~~~~~~~~~~~~ +# rho: density +# mu: dynamic viscosity +# cp: specific heat capacity +# k_f: thermal conductivity of fluid +# k_s: thermal conductivity of solid +# L_c: characteristic length +# U: velocity of flow +def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, U=0.1): + Re = (rho * U * L_c) / mu # Reynolds number calculation from the flow properties + Pr = (mu * cp) / k_f # Prandtl number calculation from fluid properties + Nu = 0.023 * Re**0.8 * Pr**0.4 # Nusselt number calculation from Dittus-Boelter equation + h = Nu * k_f / L_c # Calculate heat transfer coefficient from Nu=(h*L_c)/k_f + Bi = h * L_c / k_s # Calculate Biot number from Bi=(h*L_c)/k_s + return Bi + + +Bi = biot_number() +print("The Biot number is ", Bi) # %% -# Time step size, end time, output controls +# Apply stabilization if Biot number exceeds 10 +if Bi>10: + syc.setup.analysis_control.global_stabilization.option = "Quasi-Newton" + + syc.setup.solution_control.time_step_size = "0.1 [s]" # time step is 0.1 [s] syc.setup.solution_control.end_time = 10 # end time is 10.0 [s] @@ -239,3 +269,32 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, # ---- syc.end_output() syc.exit() + +# %% +# Post processing +# ~~~~~~~~~~~~~~~ +# Post process the fluid results in fluent +if fluent.settings.results.graphics.picture.use_window_resolution.is_active(): + fluent.settings.results.graphics.picture.use_window_resolution = False + +fluent.settings.results.graphics.picture.x_resolution = 1920 +fluent.settings.results.graphics.picture.y_resolution = 1440 + +fluent.settings.results.surfaces.plane_surface.create(name="mid_plane") +fluent.settings.results.surfaces.plane_surface["mid_plane"].method= "zx-plane" + +fluent.settings.results.graphics.contour.create(name= "contour_temperature") +fluent.settings.results.graphics.contour["contour_temperature"]= { + "field": "temperature", + "surfaces_list": ["mid_plane"], +} +fluent.settings.results.graphics.contour.display(object_name="contour_temperature") + +fluent.settings.results.graphics.views.restore_view(view_name="top") +fluent.settings.results.graphics.views.auto_scale() +fluent.settings.results.graphics.picture.save_picture(file_name="cht_temp_contour.png") + +####################################################################################### +# .. image:: /_static/cht_temp_contour.png +# :width: 500pt +# :align: center \ No newline at end of file From 037c8bbc266e4198b21f85bdd8f3c7d259c8536d Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Wed, 26 Nov 2025 15:10:19 -0500 Subject: [PATCH 08/10] formattted the code --- examples/00-systemcoupling/cht_pipe.py | 57 +++++++++++++++----------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index 4d339ab84..e943b172f 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -25,21 +25,21 @@ Conjugate Heat transfer- Pipe flow ----------------------------------- -Conjugate heat transfer (CHT) simualtions often exhibit numerical sensitivity at the fluid-solid -interface. This example demonstrates how users can appropriately select interface conditiions -and stabilization schemes for a typical pipe-flow configuration. It highlights best practices -for setting up a robust CHT workflow in System Coupling, including managing temperature and +Conjugate heat transfer (CHT) simualtions often exhibit numerical sensitivity at the fluid-solid +interface. This example demonstrates how users can appropriately select interface conditiions +and stabilization schemes for a typical pipe-flow configuration. It highlights best practices +for setting up a robust CHT workflow in System Coupling, including managing temperature and heat-flux exchange, controlling relaxation, ensuring consistent mesh-to-mesh interpolation. - Ansys Fluent is used to model the thermal fluid flow in the pipe. - Ansys Mechanical APDL (MAPDL) is used to model thermal transfer in the pipe wall. -- System Coupling coordinates the coupled solution to the conjugate heat transfer problem, +- System Coupling coordinates the coupled solution to the conjugate heat transfer problem, including numerical stabilization if needed. **Problem description** A fluid at a certain temperature flows into a pipe of known diameter and length. As it flows, -the heated outer wall of the pipe conducts heat to the inner wall, which in turns heats the +the heated outer wall of the pipe conducts heat to the inner wall, which in turns heats the fluid and cools down the walls of the pipe. @@ -175,8 +175,12 @@ # %% # Define boundary conditions -fluent.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 0.1 # units: m/s -fluent.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = 300 # Units: Kelvin +fluent.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = ( + 0.1 # units: m/s +) +fluent.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = ( + 300 # Units: Kelvin +) fluent.setup.boundary_conditions.wall["inner_wall"].thermal.thermal_bc = ( "via System Coupling" ) @@ -211,21 +215,22 @@ # %% # Set up 2-way thermal FSI coupling # ----Temp from solid to fluid---- -temp_transfer= syc.setup.add_data_transfer( +temp_transfer = syc.setup.add_data_transfer( interface=interface_name, target_side="One", - source_variable='TEMP', - target_variable='temperature' + source_variable="TEMP", + target_variable="temperature", ) -#----Heat flux from fluid to solid---- -hf_transfer= syc.setup.add_data_transfer( +# ----Heat flux from fluid to solid---- +hf_transfer = syc.setup.add_data_transfer( interface=interface_name, target_side="Two", source_variable="heatflow", - target_variable="HFLW" + target_variable="HFLW", ) + # %% # Biot number prediction # ~~~~~~~~~~~~~~~~~~~~~~ @@ -237,11 +242,13 @@ # L_c: characteristic length # U: velocity of flow def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, U=0.1): - Re = (rho * U * L_c) / mu # Reynolds number calculation from the flow properties - Pr = (mu * cp) / k_f # Prandtl number calculation from fluid properties - Nu = 0.023 * Re**0.8 * Pr**0.4 # Nusselt number calculation from Dittus-Boelter equation - h = Nu * k_f / L_c # Calculate heat transfer coefficient from Nu=(h*L_c)/k_f - Bi = h * L_c / k_s # Calculate Biot number from Bi=(h*L_c)/k_s + Re = (rho * U * L_c) / mu # Reynolds number calculation from the flow properties + Pr = (mu * cp) / k_f # Prandtl number calculation from fluid properties + Nu = ( + 0.023 * Re**0.8 * Pr**0.4 + ) # Nusselt number calculation from Dittus-Boelter equation + h = Nu * k_f / L_c # Calculate heat transfer coefficient from Nu=(h*L_c)/k_f + Bi = h * L_c / k_s # Calculate Biot number from Bi=(h*L_c)/k_s return Bi @@ -250,9 +257,9 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, # %% # Apply stabilization if Biot number exceeds 10 -if Bi>10: +if Bi > 10: syc.setup.analysis_control.global_stabilization.option = "Quasi-Newton" - + syc.setup.solution_control.time_step_size = "0.1 [s]" # time step is 0.1 [s] syc.setup.solution_control.end_time = 10 # end time is 10.0 [s] @@ -281,10 +288,10 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, fluent.settings.results.graphics.picture.y_resolution = 1440 fluent.settings.results.surfaces.plane_surface.create(name="mid_plane") -fluent.settings.results.surfaces.plane_surface["mid_plane"].method= "zx-plane" +fluent.settings.results.surfaces.plane_surface["mid_plane"].method = "zx-plane" -fluent.settings.results.graphics.contour.create(name= "contour_temperature") -fluent.settings.results.graphics.contour["contour_temperature"]= { +fluent.settings.results.graphics.contour.create(name="contour_temperature") +fluent.settings.results.graphics.contour["contour_temperature"] = { "field": "temperature", "surfaces_list": ["mid_plane"], } @@ -297,4 +304,4 @@ def biot_number(rho=1000, mu=1e-3, cp=4180, k_f=0.6, k_s=237, L_c=r_out - r_in, ####################################################################################### # .. image:: /_static/cht_temp_contour.png # :width: 500pt -# :align: center \ No newline at end of file +# :align: center From db442f8c70c0dddcf1811e9c3b4d186ed83411be Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Wed, 26 Nov 2025 15:16:47 -0500 Subject: [PATCH 09/10] fixed typos --- examples/00-systemcoupling/cht_pipe.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index e943b172f..f02916bc0 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -25,8 +25,8 @@ Conjugate Heat transfer- Pipe flow ----------------------------------- -Conjugate heat transfer (CHT) simualtions often exhibit numerical sensitivity at the fluid-solid -interface. This example demonstrates how users can appropriately select interface conditiions +Conjugate heat transfer (CHT) simulations often exhibit numerical sensitivity at the fluid-solid +interface. This example demonstrates how users can appropriately select interface conditions and stabilization schemes for a typical pipe-flow configuration. It highlights best practices for setting up a robust CHT workflow in System Coupling, including managing temperature and heat-flux exchange, controlling relaxation, ensuring consistent mesh-to-mesh interpolation. @@ -105,7 +105,7 @@ mapdl.vsweep(1) # %% -# Visualizing the meshed gemoetry +# Visualizing the meshed geometry mapdl.eplot() # %% @@ -133,7 +133,7 @@ mapdl.allsel() # %% -# Boundary conditions in degrees Cesius +# Boundary conditions in degrees Celsius mapdl.cmsel("S", "Outer_wall") mapdl.d("Outer_wall", "TEMP", 77) mapdl.allsel() From fb256c33ed0870648a7701eb43c95592787f8b59 Mon Sep 17 00:00:00 2001 From: krishnatejas12 Date: Thu, 27 Nov 2025 10:06:27 -0500 Subject: [PATCH 10/10] removed meshing visualization --- examples/00-systemcoupling/cht_pipe.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/00-systemcoupling/cht_pipe.py b/examples/00-systemcoupling/cht_pipe.py index f02916bc0..3e67301e9 100644 --- a/examples/00-systemcoupling/cht_pipe.py +++ b/examples/00-systemcoupling/cht_pipe.py @@ -104,9 +104,6 @@ mapdl.esize(0.002) mapdl.vsweep(1) -# %% -# Visualizing the meshed geometry -mapdl.eplot() # %% # Creating the regions from the geometry for named selections