Application Library / Flow & Heat

Temperature field in a cooling flange

A fused-silica flange with three cooling fins: hot process fluid inside, air cooling outside that depends on the angle around the pipe.

To reproduce the case, put its notebook and accompanying inputs in the same folder. Use the Python environment set up in the installation tutorial. Start with the original parameters and compare the result with the check reported below.

STEP importConductionNatural convectionMesh convergence

Run this example yourself. The OneSimulation Runtime brings the full Python library and an MCP server for Codex and Claude Code. It starts with a seven-day trial, then from €19 per month before any applicable tax.

Start the 7-day trial Compare the plans

Temperature field in a cooling flange
Temperature field in a cooling flange. Run the notebook to produce its own figures.

What it computes

OneSimulation solves steady 3D heat conduction with quadratic elements on a graded mesh of the finned flange, with forced convection in the bore and an angle- and temperature-dependent natural-convection coefficient on the outside, iterated to the nonlinear boundary condition. The geometry is read from a STEP file with named faces; the script that builds it comes with the notebook.

What it checks

The heat entering through the bore equals the heat leaving to the air to 0.01 %, and the cooling power and the extreme temperatures converge at second order over three meshes, changing by 0.2 % and 0.05 K between the last two.

Geometry

The notebook starts at the import of the CAD file cooling_flange_temperature.step: STEP (AP242), readable by any CAD program, with the names of the faces that the boundary conditions use. Put it next to the notebook.

Geometry of the example: Temperature field in a cooling flange
The geometry as the notebook reads it from the STEP file and draws it.

The geometry script

The script cooling_flange_temperature_geometry.py builds the geometry with the CAD objects of OneSimulation and writes the file. Change a dimension there, run it, and run the notebook again.

"""Geometry of the OneSimulation example "Temperature field in a cooling flange".

Builds one half (z >= 0) of the glass flange with the CAD objects of OneSimulation and writes
cooling_flange_temperature.step: a pipe of 16 mm bore and 4 mm wall with three fins, 4 mm wide and
10 mm tall, with rounded shoulders and tips, joined to a 12 mm connecting pipe with a 3 mm wall.
Both pieces are solids of revolution about the pipe axis x. The file names the face groups bore,
outer, pipe_end, flange_end and symmetry.
"""

import numpy as np
from onesim.cad.d2 import Path, Profile, Segment
from onesim.cad.d3 import Revolution, UnionFromObjects

mm = 1e-3
bore, pipe_length, pipe_wall, wall, fin_height, fin_width = (
    8 * mm,
    12 * mm,
    3 * mm,
    4 * mm,
    10 * mm,
    4 * mm,
)
root, shoulder, top = (
    bore + wall,
    bore + wall + fin_width / 2,
    bore + wall + fin_height - fin_width / 2,
)

connecting_pipe = Path(
    (bore, -pipe_length),
    (
        Segment((bore + pipe_wall, -pipe_length)),
        Segment((bore + pipe_wall, -2 * pipe_length / 3)),
        Segment(
            (root, 0.0), control=((root, -pipe_length / 3), (root, -pipe_length / 3))
        ),
        Segment((bore, 0.0)),
        Segment((bore, -pipe_length)),
    ),
)
fins = [Segment((root, 0.0))]
for fin in range(3):
    start, rise, fall, end = (
        2 * fin_width * fin + offset
        for offset in (0, fin_width / 2, 3 * fin_width / 2, 2 * fin_width)
    )
    fins += [
        Segment((shoulder, rise), control=((root, rise),)),
        Segment((top, rise)),
        Segment((top, fall), center=(top, start + fin_width)),
        Segment((shoulder, fall)),
        Segment((root, end), control=((root, fall),)),
    ]
fins += [Segment((bore, 6 * fin_width)), Segment((bore, 0.0))]

half_turn = dict(angle=np.pi, axis=(1.0, 0.0, 0.0))
flange = UnionFromObjects(
    objects=[
        Revolution(profile=Profile(connecting_pipe), **half_turn),
        Revolution(profile=Profile(Path((bore, 0.0), tuple(fins))), **half_turn),
    ]
)

end_face = (
    lambda face, x: face.kind == "plane"
    and abs(abs(face.normal[0]) - 1) < 1e-9
    and abs(face.center[0] - x) < 1e-9
)
pipe_end = flange.select(faces=lambda face: end_face(face, -pipe_length))
flange_end = flange.select(faces=lambda face: end_face(face, 6 * fin_width))
symmetry = flange.select(
    faces=lambda face: face.kind == "plane" and abs(abs(face.normal[2]) - 1) < 1e-9
)
inner = flange.select(
    faces=lambda face: face.kind == "cylinder" and abs(face.radius - bore) < 1e-9
)
flange = flange.grouped(
    pipe_end=pipe_end,
    flange_end=flange_end,
    symmetry=symmetry,
    bore=inner,
    outer=flange.boundaries.all - pipe_end - flange_end - symmetry - inner,
)
flange.save("cooling_flange_temperature.step")

The notebook

The complete notebook, cell by cell. Run it to produce the figures and the comparison printout.

Reaction fluids are cooled by passing them through a glass pipe with cooling flanges. The fluid heats the bore, the glass conducts the heat into the flanges, and room air removes it by natural convection. The pipe axis is horizontal (\(x\)), gravity points along \(-y\).

One half of the flange comes from the CAD file cooling_flange_temperature.step: a pipe of 16 mm bore and 4 mm wall with three fins, 4 mm wide and 10 mm tall, with rounded shoulders and tips, and a 12 mm connecting pipe with a 3 mm wall. The script cooling_flange_temperature_geometry.py builds it as a solid of revolution with the CAD objects of OneSimulation and names its faces.

The glass obeys the stationary heat equation \(\nabla\cdot(k\nabla T)=0\) with

facecondition
boreforced convection, \(h_i=15\) W/(m² K), fluid at 363 K
outernatural convection \(q=C(\theta)\,(T-T_a)^{5/4}\) to air at 298 K
pipe_end, flange_end, symmetryno heat flux

The air-side law is the laminar correlation for a horizontal cylinder (B. Sundén, Kompendium i värmeöverföring, 2003): \(h_a=(k_\mathrm{air}/D)\,f(\theta)\,Gr^{1/4}\) with the Grashof number \(Gr=g\,(T-T_a)\,D^3/(T_a\nu^2)\) and a tabulated factor \(f(\theta)\) of the angle from the lowest point. It makes the problem nonlinear and three-dimensional: the bottom of the flange cools better than the top.

Reference. No closed-form solution exists. The check is the energy balance (heat through the bore equals heat to the air) and a three-level mesh study.

import numpy as np
from onesim.cad.exchange import load
from onesim.materials import IsotropicSolid
from onesim.meshing import Block, Geometric, arc, bezier, line, merge_blocks, revolve
from onesim.numerics import Numerics
from onesim.numerics.fem import FiniteElement, Lagrange
from onesim.numerics.linear import SparseDirect
from onesim.numerics.nonlinear import Newton
from onesim.physics.heat_transfer import (
    ConvectiveHeatFlux,
    HeatConduction,
    HeatFlux,
    NonlinearHeatFlux,
)
from onesim.results.comparisons import convergence
from onesim.simulation import Problem, Simulation
from onesim.visualization import plots, theme

theme.set()

Geometry and mesh

load returns the half flange with its named faces. The mesh consists of hexahedra: curved blocks cover the meridian section (straight sides, Bezier fillets at the shoulders, circular arcs at the fin tips, written as (radius, axial position)), merge_blocks joins them and revolve sweeps the section by 180° about the pipe axis. Bound to the loaded part, the mesh takes its boundary names from the faces of the STEP file.

flange = load("cooling_flange_temperature.step")
faces = flange.boundaries
mm = 1e-3
bore, pipe_length, pipe_wall, wall, fin_height, fin_width = (
    8 * mm,
    12 * mm,
    3 * mm,
    4 * mm,
    10 * mm,
    4 * mm,
)


def flange_mesh(n):
    """Hexahedral mesh of the half flange with n cells across each block unit."""
    root, neck, shoulder, top = (
        bore + wall,
        -2 * pipe_length / 3,
        bore + wall + fin_width / 2,
        bore + wall + fin_height - fin_width / 2,
    )
    blocks = [
        Block(
            line((bore, -pipe_length), (bore, neck)),
            line((bore, neck), (bore + pipe_wall, neck)),
            line((bore + pipe_wall, -pipe_length), (bore + pipe_wall, neck)),
            line((bore, -pipe_length), (bore + pipe_wall, -pipe_length)),
            cells=(n, 2 * n),
        ),
        Block(
            line((bore, neck), (bore, 0)),
            line((bore, 0), (root, 0)),
            bezier(
                (bore + pipe_wall, neck),
                (root, -pipe_length / 3),
                (root, -pipe_length / 3),
                (root, 0),
            ),
            line((bore, neck), (bore + pipe_wall, neck)),
            cells=(2 * n, 2 * n),
        ),
    ]
    for fin in range(3):
        a, b, c, d = (
            2 * fin_width * fin + offset
            for offset in (0, fin_width / 2, 3 * fin_width / 2, 2 * fin_width)
        )
        tip = lambda start, end: arc((top, a + fin_width), fin_width / 2, start, end)
        blocks += [
            Block(
                line((bore, a), (bore, b)),
                line((bore, b), (shoulder, b)),
                bezier((root, a), (root, b), (shoulder, b)),
                line((bore, a), (root, a)),
                cells=(n, 2 * n),
            ),
            Block(
                line((bore, b), (bore, c)),
                line((bore, c), (shoulder, c)),
                line((shoulder, b), (shoulder, c)),
                line((bore, b), (shoulder, b)),
                cells=(2 * n, 2 * n),
            ),
            Block(
                line((bore, c), (bore, d)),
                line((bore, d), (root, d)),
                bezier((shoulder, c), (root, c), (root, d)),
                line((bore, c), (shoulder, c)),
                cells=(n, 2 * n),
            ),
            Block(
                line((shoulder, b), (shoulder, c)),
                line((shoulder, c), (top, c)),
                line((top, b), (top, c)),
                line((shoulder, b), (top, b)),
                cells=(2 * n, 3 * n),
                grading=(None, Geometric(3 * n, growth=1.15 ** (-2 / n))),
            ),
            Block(
                line((top, b), (top, c)),
                tip(np.pi / 2, np.pi / 4),
                tip(-np.pi / 4, np.pi / 4),
                tip(-np.pi / 2, -np.pi / 4),
                cells=(2 * n, n),
            ),
        ]
    return revolve(
        merge_blocks(blocks),
        4 * n,
        angle=np.pi,
        axis=(1.0, 0.0, 0.0),
        radial=(0.0, 1.0, 0.0),
        geometry=flange,
    )


levels = (2, 3, 4)
meshes = [flange_mesh(level) for level in levels]

view = plots.Camera(elevation=14, azimuth=-58, up="y")
fig = plots.figure(1, 2, size=(14, 6))
plots.geometry(
    flange,
    selection={"bore": faces.bore, "outer": faces.outer, "symmetry": faces.symmetry},
    labels=False,
    camera=view,
    title="Half flange with its named faces",
    ax=fig[0],
)
plots.mesh(
    meshes[0],
    groups=("all",),
    legend=False,
    camera=view,
    title=f"Coarsest mesh: {meshes[0].cell_count} hexahedra",
    ax=fig[1],
)
plots.show()

Model

Fused silica conducts with \(k=1.38\) W/(m K); air at 298 K has \(k=0.0262\) W/(m K) and \(\nu=18\times10^{-6}\) m²/s. Newton's method handles the nonlinear air-side flux, which enters as a NonlinearHeatFlux with its derivative \(\partial q/\partial T\).

diameter = 2 * (bore + wall + fin_height)
fluid_film, fluid_temperature, air_temperature = 15.0, 363.0, 298.0
glass = IsotropicSolid(
    density=2203.0,
    specific_heat_capacity=703.0,
    thermal_conductivity=1.38,
    youngs_modulus=73.1e9,
    poisson_ratio=0.17,
    thermal_expansion_coefficient=5.5e-7,
)
angles = np.radians([0, 90, 100, 110, 120, 130, 140, 150, 160, 180])
factors = np.array([0.48, 0.46, 0.45, 0.435, 0.42, 0.38, 0.35, 0.28, 0.22, 0.15])
grashof_per_kelvin = 9.81 * diameter**3 / (air_temperature * 18e-6**2)


def air_flux(temperature, y, z, power=1.25):
    """Natural-convection flux C(theta) (T - T_air)^(5/4) leaving the surface."""
    coefficient = (
        0.0262
        / diameter
        * np.interp(np.arctan2(np.abs(z), -y), angles, factors)
        * grashof_per_kelvin**0.25
    )
    return coefficient * np.maximum(temperature - air_temperature, 0.0) ** power


model = HeatConduction(domain=flange.volume, material=glass, heating=0.0)
problem = Problem(
    name="Glass cooling flange",
    geometry=flange,
    physics=(model,),
    boundary_conditions=(
        ConvectiveHeatFlux(
            boundary=faces.bore,
            physics=model,
            heat_transfer_coefficient=fluid_film,
            ambient_temperature=fluid_temperature,
        ),
        NonlinearHeatFlux(
            boundary=faces.outer,
            physics=model,
            flux=air_flux,
            derivative=lambda T, y, z: 1.25 * air_flux(T, y, z, power=0.25),
        ),
        HeatFlux(
            boundary=faces.pipe_end | faces.flange_end | faces.symmetry,
            physics=model,
            value=0.0,
        ),
    ),
)
numerics = Numerics(
    spatial=FiniteElement(element=Lagrange(order=2)),
    linear_solver=SparseDirect(),
    nonlinear_solver=Newton(),
    initial_guess={model.temperature: 330.0},
)
fields = [
    Simulation(problem=problem, mesh=mesh, numerics=numerics)
    .solve_stationary()
    .field(model.temperature)
    for mesh in meshes
]
field = fields[-1]

Results

Heat rates of the full flange (twice the computed half). convergence returns the observed order and the Richardson estimate from the three meshes.

heat_in = [-2 * f.boundary_flux(faces.bore) for f in fields]
heat_out = [2 * f.boundary_flux(faces.outer) for f in fields]
study = convergence(heat_in, [1.0 / level for level in levels])
surface = field.sample(along=faces.outer, subdivisions=2)
print("level   hexahedra   heat through the bore [W]   heat to the air [W]")
for level, mesh, q_in, q_out in zip(levels, meshes, heat_in, heat_out):
    print(f"{level:5d} {mesh.cell_count:11d} {q_in:22.5f} {q_out:21.5f}")
print(f"energy imbalance on the finest mesh: {abs(heat_in[-1] / heat_out[-1] - 1):.1e}")
print(
    f"observed order {study.order:.2f}, Richardson estimate {study.extrapolated:.4f} W "
    f"(finest mesh {100 * (heat_in[-1] / study.extrapolated - 1):+.2f} %)"
)
print(
    f"surface temperature between {surface.values.min():.1f} K and {surface.values.max():.1f} K"
)

Figure

The surface temperature of the complete flange, the vertical section through the axis (top of the flange above, bottom below), the mesh study, and the local air-side film coefficient.

positions, surface_temperature = (
    np.asarray(surface.positions),
    np.asarray(surface.values).ravel(),
)
film = air_flux(surface_temperature, positions[:, 1], positions[:, 2]) / np.maximum(
    surface_temperature - air_temperature, 1e-9
)
limits = (
    surface_temperature.min(),
    float(np.asarray(field.sample(along=faces.bore).values).max()),
)
fig = plots.figure(
    layout=[["surface", "section", "study"], ["surface", "section", "film"]],
    size=(17, 6.2),
)
plots.surface(
    field,
    boundary=faces.outer | faces.pipe_end | faces.flange_end,
    symmetry={"planes": [((0, 0, 1), (0, 0, 0))]},
    limits=limits,
    subdivisions=3,
    camera=view,
    label="T [K]",
    title="Surface temperature (full flange)",
    ax=fig["surface"],
)
plots.surface(
    field,
    boundary=faces.symmetry,
    limits=limits,
    contours=10,
    subdivisions=3,
    label="T [K]",
    title="Vertical section through the axis",
    ax=fig["section"],
)
plots.line(
    levels,
    {"through the bore": heat_in, "to the air": heat_out},
    hlines={f"Richardson estimate {study.extrapolated:.4f} W": study.extrapolated},
    markers=True,
    xlabel="mesh level",
    ylabel="heat rate [W]",
    title="Mesh study of the cooling power",
    ax=fig["study"],
)
plots.line(
    points={
        "outer surface": (
            np.degrees(np.arctan2(np.abs(positions[:, 2]), -positions[:, 1])),
            film,
        )
    },
    xlabel="angle from the bottom [deg]",
    ylabel="film coefficient [W/(m² K)]",
    title="Local natural-convection coefficient",
    legend=False,
    ax=fig["film"],
)
plots.show()

Going further

Change the bore radius between 6 and 10 mm in cooling_flange_temperature_geometry.py and write the STEP file again: the bore-side film resistance dominates, so a wider bore raises the cooling power noticeably. Add a fourth fin, or replace glass by a metal, and compare how much of the temperature drop sits in the wall and in the two films.

Original OneSimulation Showcase entry