Change parameters · Explore this notebook model
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Python runs on this device. The first run loads the scientific libraries.
The optional OneSimulation calculation uses the local OneSimulation installation. Save this notebook to run that comparison in Jupyter.
Integrate the heat equation against a hat function
Take a uniform rod of length one with the two endpoint temperatures held at zero. With constant diffusivity \(\kappa>0\) the evolution is \(u_t=\kappa u_{xx}\). Approximate \(u(x,t)\) as a linear combination of continuous piecewise-linear hat functions. Multiply by an interior hat and integrate. Integration by parts transfers one spatial derivative onto each hat. The boundary term vanishes. The nodal temperature vector satisfies
On an element of length \(h\) the two hats are \(1-x/h\) and \(x/h\) in local coordinates. Integrating their products gives diagonal entries \(h/3\) and off-diagonal entries \(h/6\) in the element mass matrix. Their constant derivatives give diagonal stiffness \(\kappa/h\) and off-diagonal stiffness \(-\kappa/h\). After assembly and imposing Dirichlet values, the interior mass has diagonal \(4h/6\) and neighbouring entries \(h/6\). The stiffness has diagonal \(2\kappa/h\) and neighbours \(-\kappa/h\).
Forward Euler advances with \(G=I-\Delta t M^{-1}K\). On an eigenvector of \(K\phi=\lambda M\phi\) it multiplies the amplitude by \(1-\Delta t\lambda\). A bound \(\Delta t\lambda_{\max}\leq2\) therefore ensures no growth in the mass norm. Preserving nonnegative temperatures for every nonnegative initial vector requires every entry of \(G\) to be nonnegative. Each column is the response to a single positive nodal impulse, so the latter condition can be tested directly.
One alternative assigns half of each element's total heat capacity to each endpoint, before removing boundary degrees of freedom. Each interior mass then equals \(h\) and the explicit stencil has weights \(r,1-2r,r\), with \(r=\kappa\Delta t/h^2\). These coefficients are all nonnegative for \(0\leq r\leq 1/2\). The first and last interior equations also couple to the fixed zero boundary temperatures.
Compute the remote temperature after one update
With three interior nodes, \(h=1/4\), initially set the left interior node to 1 K above the boundary reference and both others to zero. Inverting the consistent mass in this three-by-three system gives the first column of \((h^2/\kappa)M^{-1}K\) as \((51,-36,9)/14\). At \(r=0.1\) the interior temperatures after one step become \((0.63571,0.25714,-0.06429)\) K. The cold node two edges away immediately drops below the lower reference.
The largest dimensionless eigenvalue is about 7.9223. The chosen step gives \(r\lambda_{\max}h^2/\kappa\approx0.7922\), comfortably inside the linear stability interval. Lumping instead gives \((0.8,0.1,0)\) K. The negative consistent-mass entry shrinks linearly when the step shrinks. For this impulse its sign persists for every positive first step. With OneSimulation installed locally, the notebook also constructs a physical line mesh and obtains the mass and stiffness by integrating its hat functions at mapped quadrature points. Compare the assembled result against the explicit tridiagonal entries. The experiment shows why reducing the time step can satisfy a stability test without restoring a discrete maximum principle.
Set the experimental inputs
Edit these values, then run the calculation and both figures again.
Line segments are the linear finite-element interpolants. Both ends have a fixed zero temperature and participate in the heat balance.
The orange trace is the one-step temperature at the third interior node. The vertical line is the exact stability threshold for this mesh. Crossing it eventually produces amplification greater than one.
Exercise · keep the lumped temperatures nonnegative
Suppose \(h=0.02\) m and \(\kappa=8\times10^{-5}\) m²/s. Find the greatest time step allowed by nonnegative weights. What stencil results at that step?
The condition gives \(\Delta t=h^2/(2\kappa)=2.5\) s. The central coefficient vanishes and each adjacent value receives weight one half. At the first interior node the fixed boundary value supplies one of these two terms. A step slightly above this threshold gives a negative central coefficient and can drive an isolated positive impulse below zero.
Exercise · derive the largest mode on successively finer meshes
An interior sine wave has neighbouring sum \(2\cos(\theta)\) times its own nodal value. Use this fact to find the limiting stability condition for forward Euler with consistent mass as the number of uniform elements grows.
The mass eigenvalue is \(h(2+\cos\theta)/3\) and the stiffness eigenvalue is \(2\kappa(1-\cos\theta)/h\). Their ratio, multiplied by \(h^2/\kappa\), is \(6(1-\cos\theta)/(2+\cos\theta)\). The largest allowed angle tends to \(\pi\), giving 12. The limiting stable step therefore has \(r\leq1/6\). A positivity test still inspects the entries of the update matrix separately.