Parameters
About
Solve the diffusion equation with Crank-Nicolson method. Choose initial and boundary conditions, then watch the solution evolve in real-time animation.
Solve the diffusion equation with Crank-Nicolson method. Choose initial and boundary conditions, then watch the solution evolve in real-time animation.
Solve the diffusion equation with Crank-Nicolson method. Choose initial and boundary conditions, then watch the solution evolve in real-time animation.
The core physics is governed by the 1D diffusion (or heat) equation. It states that the rate of change of the quantity (like temperature) at a point is proportional to its spatial curvature.
$$ \frac{\partial u}{\partial t}= D \frac{\partial^2 u}{\partial x^2}$$Here, $u(x,t)$ is the quantity (temperature, concentration), $t$ is time, $x$ is the spatial position, and $D$ is the diffusivity (Parameter A). A high $D$ means diffusion happens quickly.
The simulator solves this equation numerically using the Crank-Nicolson method. It's an implicit scheme that averages the spatial derivative at the current and next time step, making it stable and accurate.
$$ \frac{u_i^{n+1} - u_i^n}{\Delta t}= \frac{D}{2}\left( \frac{u_{i+1}^{n+1}- 2u_i^{n+1}+ u_{i-1}^{n+1}}{(\Delta x)^2}+ \frac{u_{i+1}^{n}- 2u_i^{n}+ u_{i-1}^{n}}{(\Delta x)^2}\right) $$Here, $u_i^n$ is the value at grid point $i$ and time step $n$. $\Delta t$ is the time step (Parameter B). This equation forms a linear system that is solved at each step to find $u^{n+1}$, which you see animated.
Heat Treatment of Metals: Engineers use diffusion models to predict how heat propagates through a steel beam during quenching or annealing. Getting this right is crucial for achieving the desired material hardness and preventing cracks.
Drug Delivery Patch Design: Transdermal patches rely on the diffusion of medication through the skin. Simulating the 1D concentration profile helps design patches that release the drug at a steady, controlled rate over hours or days.
Semiconductor Manufacturing (Doping): Creating computer chips involves diffusing impurity atoms (dopants) into silicon wafers. Precise control of the depth and concentration profile, governed by the diffusion equation, defines the transistor's electrical properties.
Groundwater Contaminant Transport: If a pollutant leaks into an aquifer, it spreads primarily through diffusion and advection. 1D models are a foundational tool for environmental engineers to predict the plume's movement and plan remediation strategies.
Let's go over a few points where people often stumble when starting to play with this tool. First, "the sense of scale for the diffusion coefficient D". Textbooks often use D=1.0 for calculations, but real-world values are orders of magnitude different. For example, the diffusion coefficient for water vapor in air is about 2.5e-5 m²/s, and the thermal diffusivity of steel is around 1e-5 m²/s. If you set D=1 in the simulator, it spreads out instantly because this "sense of scale" is ignored. When applying it to real problems, be mindful of the dimensionless Fourier number $F_o = D \Delta t / (\Delta x)^2$, aligning it with the domain length L and time scale. While the Crank-Nicolson method is unconditionally stable, the trick for accuracy is to keep $F_o$ from getting too large (e.g., below 10).
Next, "the true meaning of Neumann boundary condition = 0". It correctly represents insulation or no mass flux, but this is a "zero gradient" condition, meaning the curve of the distribution flattens at the boundary. Therefore, if the initial distribution has a value at the boundary, it won't move from there at all. For instance, if you heat only the center of a metal rod and insulate both ends, the heat cannot escape even when it reaches the ends, and the entire rod will eventually settle to a uniform temperature. Be careful not to confuse this with Dirichlet (fixed value) conditions.
Finally, the pitfall of "numerical diffusion and oscillation". This solver is robust, but if the initial condition has a sharp change (like a step function), you might see slight computational "smearing" or very subtle oscillations in the initial time steps. This is an unavoidable phenomenon due to discretization and can be mitigated by refining the mesh (making Δx smaller). In practice, if you think "are these results too smooth?", get into the habit of checking for mesh dependency.
The concept of this 1D diffusion is actually foundational to a huge number of fields. First, "battery engineering". During the charging/discharging of lithium-ion batteries, the diffusion of lithium ions within the electrodes is critical to performance. If you think of the concentration u in this simulator as lithium concentration and D as the solid-state diffusion coefficient, you can grasp the phenomenon of "plating" (degradation when the surface concentration saturates due to overly fast charging).
Next, "expansion into the world of structural mechanics". Mastering how to solve the diffusion equation actually serves as a bridge to numerical methods for the differential equation for beam deflection and the one-dimensional wave equation, because the governing equations are similar. For example, the fundamental equation for beam deflection is $EI \frac{d^4 w}{dx^4} = q(x)$, which is also solved using finite difference methods. The algorithm for solving the system of linear equations (the Thomas algorithm) is built on exactly the same foundation.
Furthermore, it's also applied in "image processing". "Gaussian filters" and "anisotropic diffusion" in images achieve noise reduction and edge-preserving smoothing by solving the diffusion equation on a 2D image. Watching a 1D Gaussian distribution smoothly spread over time with this tool connects directly to an essential understanding of the image blurring process.
Once you're comfortable with this tool, consider "extending to 2D" as your next step. The system of equations solved easily in 1D with the Thomas algorithm becomes a much larger sparse matrix in 2D. How to solve this efficiently is the next hurdle, where "iterative methods (e.g., SOR method, conjugate gradient method)" come into play. A good starting point is to imagine how the temperature distribution in a square metal plate, cooled at both ends, changes over time.
If you want to deepen the mathematical background, study "the classification of PDEs (parabolic, elliptic, hyperbolic)". The diffusion equation here is a classic example of a "parabolic" type. Understanding the differences compared to the Laplace equation (elliptic type), representing steady states, and the wave equation (hyperbolic type), representing oscillations, will help you see all the physical phenomena encountered in CAE in an organized framework. If you look closely at the Crank-Nicolson formula in this tool, you'll see that how the time term is handled is key.
Finally, if you use CAE tools in practice, the concept of "non-dimensionalization" is essential. The Fourier number mentioned earlier is one example. Non-dimensionalizing equations reduces the number of parameters and highlights the essence of the phenomenon. For instance, a problem with separate parameters for diffusion coefficient D, length L, and time t can be organized using dimensionless time $t^* = D t / L^2$, allowing the phenomenon to be represented by a single curve. This is a super important skill when comparing experimental data with simulation, so try to get a feel for it now.