This FEniCSx script simulates fluid flow and heat transfer around a 2D circuit board with heat-generating electronic components.It first solves the transient, incompressible Navier-Stokes equations using a Discontinuous Galerkin (DG) method to find the velocity and pressure fields. Then, it uses this computed velocity field to solve the steady-state convection-diffusion heat transfer equation (with SUPG stabilization) to determine the temperature distribution.
This project uses conda for environment management.
Environment Setup
Create a file named environment.yml with the following contents. This specifies all necessary dependencies.
name: circuit_board_ht
channels:
- conda-forge
dependencies:
- python=3.10
- fenics-dolfinx
- mpi4py
- petsc4py
- numpy
- gmsh
- adios2
Create and activate the conda environment by running the following commands in your terminal:
conda env create -f environment.yml
First, make sure you have activated the conda environment first
conda activate circuit_board_ht
Then run the simulation
python src/data_generation/main.py
The script will:
- Generate the mesh file using gmsh.
- Solve the initial Stokes problem.
- Time-step through the transient Navier-Stokes problem.
- Solve the steady-state heat transfer problem.
- Save the results (velocity u.bp, pressure p.bp, and temperature T.bp) in the output/ folder in VTX format, viewable with tools like ParaView.
This simulation solves two main physical problems sequentially.
The fluid flow is modeled by the transient, incompressible Navier-Stokes equations, which enforce conservation of momentum and mass.
Strong Form:
The equations for the velocity vector
- Momentum Equation:
$$\frac{\partial \mathbf{u}}{\partial t} + (\mathbf{u} \cdot \nabla) \mathbf{u} = -\frac{1}{\rho} \nabla p + \nu \nabla^2 \mathbf{u} + \mathbf{f}$$ - Continuity Equation (Incompressibility):
$$\nabla \cdot \mathbf{u} = 0$$ Where:-
$\rho$ is the fluid density. -
$\nu$ is the kinematic viscosity. -
$\mathbf{f}$ is an external body force (assumed zero).
-
Weak Form (Discontinuous Galerkin): The script uses a DG method, which is solved on a mixed function space
- Initial Stokes Problem (t=0):
The initial Stokes problem bilinear form
$a((\mathbf{u}, p), (\mathbf{v}, q))$ combines the standard continuous Galerkin terms with specific DG flux terms. The standard part is:$$a_{std} = \int_{\Omega} \nu \nabla \mathbf{u} : \nabla \mathbf{v} , dx - \int_{\Omega} p (\nabla \cdot \mathbf{v}) , dx - \int_{\Omega} (\nabla \cdot \mathbf{u}) q , dx$$ Boundary Condition Terms: Similar terms are added on the boundary facets$\mathcal{F}_{ext}$ (ufl.ds) to weakly impose the Dirichlet boundary conditions. The crucial DG Terms enforce continuity and penalize jumps with Symmetry Terms (enforce consistency) and Penalty Term (enforce stability for the discontinuous solution - This term penalizes large jumps in velocity across interior facets.$\alpha$ is a penalty parameter and$h$ is the cell diameter):
-
Transient Navier-Stokes Problem:
The formulation is modified with three additional terms to account for time and advection:
(1) Time Derivative (Backward-Euler): This term is split between the LHS and RHS for the implicit time-stepping scheme.
(
(The Upwind Flux Terms use the operator
After solving for the flow, the steady-state temperature
The governing equation is the steady-state convection-diffusion equation:
Where:
-
$\rho c_p$ is volumetric heat capacity (only relevant in the fluid domain). -
$k$ is the thermal conductivity, which is piecewise constant (fluid, PCB, components). -
$Q$ is the volumetric heat source (non-zero only in components).
Weak Form (SUPG Stabilized)
The total weak form
Standard Weak Form (
(Where
SUPG Stabilization Term (
Where
(