Solve the Heat Equation with a PINN
Use a neural network to simulate how heat flows through a spacecraft wall.
Last reviewed: March 2026Overview
When a spacecraft re-enters Earth's atmosphere, its surface heats to thousands of degrees. Engineers must know exactly how that heat moves through the thermal protection system to keep the vehicle—and its occupants—safe. Traditionally this required specialist finite-element codes and weeks of setup. Physics-Informed Neural Networks (PINNs) offer a radical alternative: embed the governing physics equation directly into a neural network's loss function and let it solve the problem automatically.
In this project you will use DeepXDE, an open-source Python library developed at Brown University and MIT, to solve the 1D heat equation with Dirichlet boundary conditions. The heat equation describes how temperature evolves over space and time: it appears in everything from thermal insulation design to electronics cooling. You will set up the problem, train the network, and compare its output to the exact analytical solution.
PINNs represent a genuine frontier in computational physics—research groups at NASA, MIT, and Caltech are actively applying them to problems that stumped traditional methods. This project gives you an authentic taste of that frontier while building Python and machine-learning skills that transfer directly to future coursework and careers.
What You'll Learn
- ✓ State the 1D heat equation and explain what each term represents physically.
- ✓ Explain how a PINN embeds a differential equation into its loss function.
- ✓ Use DeepXDE to define geometry, boundary conditions, and a PDE in Python.
- ✓ Train a PINN and evaluate convergence by plotting the loss history.
- ✓ Compare PINN predictions to an exact analytical solution and quantify error.
Step-by-Step Guide
Install DeepXDE and dependencies
Create a Python virtual environment and install DeepXDE with pip install deepxde matplotlib numpy. DeepXDE supports TensorFlow and PyTorch backends—set TensorFlow as your backend by running import os; os.environ["DDE_BACKEND"] = "tensorflow" at the top of your script (or set the environment variable permanently). Verify the install with import deepxde as dde; print(dde.__version__).
Understand the heat equation you will solve
The 1D heat equation is ∂u/∂t = α · ∂²u/∂x², where u is temperature, x is position (0 to 1 m), t is time (0 to 1 s), and α = 0.01 m²/s is thermal diffusivity. Boundary conditions: u(0,t) = 0, u(1,t) = 0 (both ends held at 0°C). Initial condition: u(x,0) = sin(πx) (a sine-shaped initial temperature profile). Write the exact analytical solution: u(x,t) = e^(−α π² t) · sin(πx) and verify it satisfies the PDE by substituting it back in by hand.
Define the geometry and time domain in DeepXDE
Import DeepXDE and define the spatial domain with geom = dde.geometry.Interval(0, 1) and the time domain with timedomain = dde.geometry.TimeDomain(0, 1). Combine them: geomtime = dde.geometry.GeometryXTime(geom, timedomain). This object tells DeepXDE where to sample collocation points—the random locations where the PDE residual will be penalized during training.
Define the PDE, boundary conditions, and initial condition
Write a function pde(x, y) that computes the PDE residual: use dde.grad.jacobian(y, x, i=0, j=1) for ∂u/∂t and dde.grad.hessian(y, x, i=0, j=0) for ∂²u/∂x². Define boundary conditions with dde.DirichletBC and the initial condition with dde.IC using a lambda that returns np.sin(np.pi * x[:,0:1]). Combine into a TimePDE data object.
Build and train the network
Define a 4-layer neural network with 32 neurons per layer using net = dde.nn.FNN([2] + [32]*3 + [1], "tanh", "Glorot normal"). Assemble the model with model = dde.Model(data, net), compile with Adam optimizer and learning rate 1e-3, and train for 10,000 iterations: model.compile("adam", lr=1e-3); losshistory, _ = model.train(iterations=10000). Plot the loss history to confirm convergence.
Compare predictions to the analytical solution
Generate a grid of (x, t) test points and predict temperature with model.predict(X_test). Compute the exact solution at the same points using your analytical formula. Plot both as 2D heatmaps side by side using Matplotlib, and plot the absolute error as a third map. Compute the maximum absolute error—well-trained PINNs typically achieve errors below 0.001 on this benchmark. Discuss where error is largest and why (hint: look at early times and the interior).
Career Connection
See how this project connects to real aerospace careers.
Aerospace Engineer →
Thermal protection system engineers are among the first adopters of PINNs for rapid iteration on re-entry vehicle designs where traditional FEM is too slow.
Space Operations →
Spacecraft operators must understand thermal constraints to plan attitude maneuvers—PINN-based thermal models can provide faster onboard predictions.
Astronaut →
Astronauts with computational science backgrounds are better equipped to support and communicate about the research experiments they conduct in orbit.
Avionics Technician →
Electronics thermal management is critical in avionics bays; understanding heat flow helps technicians identify cooling failures before they become safety issues.
Go Further
- Solve the 2D heat equation on a square domain using
dde.geometry.Rectangleand visualize the full temperature field over time. - Change the boundary condition to a time-varying Dirichlet condition (e.g., a sinusoidal heat source) and observe how the PINN adapts.
- Compare PINN solution time and accuracy to a finite-difference solver you write yourself in NumPy.
- Read a published paper applying PINNs to hypersonic re-entry thermal analysis and summarize how the method scales to 3D problems.