> SPECTRAL GALERKIN HEAT SOLVER

My thesis needs thousands of simulations of a laser melting metal, enough to train a model that predicts microstructure from process parameters. With finite elements, one part-scale laser scan took 189 hours. So, with Andreas Ntinos and Manas Upadhyay, I wrote a solver that does it in under an hour.

227×faster than the finite element reference
189 h → 50 minsame scan, one CPU core vs. one GPU
< 1%temperature error vs. finite elements
Opensource code (Apache 2.0) + docs

Why speed matters here

The plan of my Ph.D. is to learn the link between laser parameters and the microstructure they produce. A machine learning model can do that, but it needs data, a lot of it, and experiments alone are too slow and too expensive. High-fidelity simulations could fill the gap if they were cheap. They are not: a single scan can take days on a CPU.

Cuboid domain heated by a moving laser, with evaporation on top, convection at the bottom and insulated side walls
The problem: a moving laser on a block of metal, with evaporation and latent heat at the top and convection at the bottom.

How it works

The temperature is written as a sum of cosine modes of the block. In that basis, plain heat diffusion is exact: each mode just decays at its own rate, so there is no big linear system to solve at each time step. Everything that makes the problem hard (conductivity that changes with temperature, melting, evaporation, the laser itself) goes into a forcing term that is updated by fixed-point iterations.

Moving between the modes and the grid is a discrete cosine transform. cuFFT does not provide one, so on the GPU I built it from CuPy's real FFT and a few custom CUDA kernels. Laser paths are read straight from G-code.

The intuition we had to drop

Every cosine mode has zero heat flux at the boundary. Our first intuition was therefore that this basis could never represent the laser heating the top surface, and that we needed a different one. That intuition was wrong. In the Galerkin formulation the surface flux enters through the boundary term, and the series still converges to the right temperature; it just needs more modes near the surface. Accepting that, and understanding why, was the most interesting part of the project for me.

Results

On a single-pass laser scan, the solver stays within 0.67% of a fine finite element reference. On one core of a Ryzen 9 5900X, the finite element run took 189 hours; ours took 30.6 hours with ten times more degrees of freedom (25 million). On an NVIDIA Quadro RTX 5000 it took 50 minutes.

Same scan, same clock: spectral Galerkin (top) against finite elements (bottom).
Temperature profile along the scan line: finite element and spectral Galerkin curves overlap
Temperature along the scan line: the two curves overlap.
Runtime versus relative error: spectral Galerkin is one to two orders of magnitude faster at equal error
At equal error, 10 to 100 times faster.

Then we ran something finite elements could not reasonably do: a whole plate of 6 × 6 cm, 1 mm thick, scanned island by island with 2,500 laser tracks of 0.5 cm. That is 20.8 seconds of scanning, and it took 3.82 hours on a single GPU. Including evaporation and latent heat more than halved a temperature-uniformity metric from the literature, so these effects cannot be left out when choosing scan strategies.

The part-scale study, 100 islands, with the computation clock.

The code, the documentation and the examples are open source. These thermal histories are now the input for the microstructure models of my thesis.

< all projects next: X-Rocket >