Generative AI for Computational Science by Example
Score-Based Generative Models for Uncertain PDE Solutions
I’ve published a more detailed version of this post on my website, with all the equations, numerical results, and figures. Substack doesn’t handle inline LaTeX very well, so this version focuses more on the big picture.
Generative AI has exploded into public consciousness via image tools like DALLE and Stable Diffusion. These systems rely on Score-based Generative Models (SGMs) under the hood: they turn random noise into pictures through diffusion - a mathematical framework that corrupts data with noise and learns to reverse the process. Although you will almost never find how these models were trained, I would argue that SGMs are the principled way of doing GenAI. In this post I explore how generative AI can become a numerical tool for computational science, focusing on an example from battery modeling.
Recapping the journey. I have been writing about generative AI in computational science for a while - mostly from trying to understand where GenAI can fit in scientific computing. In the first part of my GenAI‑in‑CompSci series, I explained that generative models essentially sample a probability distribution (they are ‘generative’ after all). Bringing GenAI into scientific computing therefore has to happen in areas that deal with uncertainty . You can read that previous article here. In a follow up article, I argued that the immediate sweet spot for generative AI is uncertainty quantification and generative design, not replacing PDE solvers. The present article puts that philosophy into practice with a working example.
The physical problem: transport in a porous electrode
Modern lithium‑ion batteries are built from porous electrodes. Each electrode is built from a porous material in which electrically charged ions move, react and transfer charge. The function ε(x) measures the local porosity. Figure 1 demonstrates that the porosity is high when there are many large holes, and that it is small when the material is near continuum.
The macroscopic fields of interest are:
The electrolyte potential 𝜙(x), which determines ionic current flow.
The electrolyte concentration c(x), which tracks how many ions are available to carry charge.
These fields satisfy coupled conservation laws. The potential obeys a quasi‑static balance between conduction and reaction:
where k_eff(x) is an effective ionic conductivity, a_s(x) is the local surface area density, k_rn is a linearized reaction rate, 𝜙_s(x) is the solid‑phase potential, and U_0 is the applied voltage. The concentration is time-dependent and evolves according to
with D_eff(x) the effective diffusivity, t+ the transference number and j(x,t) a volumetric reaction current. In steady state the time derivative vanishes, leaving a balance between diffusion and reaction. We are mainly interested in this steady-state profile c(x).
Crucially, the porosity field ε(x) itself is unknown in practice. It depends on the microstructure of the electrode and varies randomly in space, and is different from one physical electrode to another. Even when macroscopic operating conditions (U_0, the applied current flux F_right, etc.) are fixed, different porosity realizations induce different profiles of 𝜙(x) and c(x). The problem is deterministic given ε(x), but ε must be treated as a latent random field. Our goal is to learn the distribution of steady‑state solution fields (c,𝜙) conditioned on the operating parameters, without ever observing ε directly.
A generative‑modeling perspective
In traditional uncertainty quantification, we would sample hundreds of porosity fields, solve the battery equations for each field, and compute the global statistics of the combined solutions. This approach is a mathematically correct but becomes costly when each PDE solver takes minutes to run. A score-based generative model learns potential solutions starting from a given simulation dataset.
Across many applications in computational science, thousands to millions of simulation results quietly accumulate on hard drives and are rarely reused. SGMs offer a way to turn this dormant goldmine of compute data into fast, probabilistic predictors. Here are the main steps:
Data generation. We sample many realistic porosity functions ε(x) from a Gaussian process, compute the corresponding steady‑state solutions for a range of (U_0,F_right), and discretize the resulting (c,𝜙) fields onto a 1‑D grid. These numerical fields are then stored on a hard drive (the goldmine).
Conditioned score learning. From this simulation data, we learn the conditional distribution p(c,𝜙 | U_0,F_right) for many operating conditions U_0 and F_right. Crucially, there should be more than one simulation result for given operating U_0 and F_right. Instead of learning the full density directly, the SGM learns its score, i.e., the gradient of the log probability with respect (c,𝜙). Although the score and density contain the exact same information, learning the score is more robust and regularizes the learning problem tremendously. In our setup here, the score network is a 1‑D convolutional neural network with Feature‑wise Linear Modulation (FiLM) layers that inject the operating parameters. This allows a single model to handle an entire family of conditions.
Fast sampling. Once trained, the model can turn random noise into physical solution fields via a reverse diffusion process. This step is much faster than solving the PDE over and over. Because it has learned the conditional distribution, we can generate thousands of samples to compute means, variances and confidence intervals nearly instantaneously.
What this buys us
Learning conditional distributions rather than individual solutions has several invaluable benefits:
UQ becomes very efficient. Sampling from the trained SGM is orders of magnitude faster than repeatedly solving the PDEs, enabling thorough Monte Carlo analysis.
Design and inference. Because the model is conditioned on operating parameters, we can explore how the distribution of states changes as we vary the applied voltage, current or porosity correlation length. This makes research orders of magnitude faster!
Hybrid workflows. The generative model is not a pure replacement for physics solvers. Indeed, PDE solvers are unbeatable in accuracy, but they are slow. Instead, SGMs create realistic candidates which can then be refined with high‑fidelity simulation or optimization. Generative models will never, ever, replace high-fidelity numerical routines (how could they), but they can seriously augment them.
Figure 2 shows the average solution fields of c(x) and 𝜙(x) computed over 1000 realizations of for both the PDE (blue) and SGM (red) for fixed operating conditions. We also plot the 95% confidence interval around this mean. Clearly, the SGM is unbiased and captures the uncertainty of the distribution very well! Even more, we can see the confidence bounds agree very well with the real uncertainty around the mean. Again, the porosity field is never passed to the SGM - it learns the solution distribution. In fact, the collection of porosity fields used to induce the distribution of solutions is fundamentally different for the PDE solver and for the SGM: the solver samples explicit realizations of ε(x), whereas the SGM uses unknowable porosity fields.

This result serves as a demonstration of the power of SGMs.
Closing thoughts
Generative AI has clear potential in scientific computing: learn distributions of physically admissible solutions induced by uncertain inputs. By embracing the randomness inherent to diffusion models, we can capture the variability inherent in real materials and processes. In this project I applied these ideas to batteries, but the same framework could be adapted to fluid and heat flow, chemical simulations, inverse problems, material science - anywhere uncertainty is part of the picture.
If you’d like to see the mathematical and algorithmic details, including the mathematics underpinning SGMs, a discussion on the PDE solver and data generation, the specific FiLM network architecture and more results, check out the full article on my blog. For the bigger picture behind this work, including why I believe generative models are best used for uncertainty quantification and generative design, revisit Part 1 and Part 2 of my GenAI series.


