Skip to main content
Version: 0.3.1

General form PDE

generalFormPDEScript solves a general second-order, one-dimensional PDE, defined by four coefficient functions. It covers diffusion, advection–diffusion and reaction–diffusion problems, in linear or nonlinear form.

caution

The general form PDE model currently supports 1D meshes only.

Governing equation​

Linear form​

ddx(A(x) dudx)+B(x) dudx+C(x) u=D(x),0≤x≤maxX,\frac{d}{dx}\left( A(x) \, \frac{du}{dx} \right) + B(x) \, \frac{du}{dx} + C(x) \, u = D(x), \qquad 0 \le x \le maxX,

where AA is the diffusion coefficient, BB the advection coefficient, CC the reaction coefficient and DD the source term.

Nonlinear form​

With nonlinear: true, the source term may depend on the solution:

ddx(A(x) dudx)+B(x) dudx+C(x) u=D(x,u),\frac{d}{dx}\left( A(x) \, \frac{du}{dx} \right) + B(x) \, \frac{du}{dx} + C(x) \, u = D(x, u),

and the system is solved with the Newton–Raphson method. The derivative ∂D/∂u\partial D / \partial u must be given as well, since it enters the Jacobian matrix.

Boundary conditions​

u=ubconstant value,A dudx=0zero gradient.\begin{aligned} u &= u_b && \text{constant value}, \\ A \, \frac{du}{dx} &= 0 && \text{zero gradient}. \end{aligned}

Weak form​

After integration by parts of the diffusion term, the Galerkin residuals are

Ri=∫D(A dϕidxdudx−B ϕidudx−C ϕiu+D ϕi)dx,i=1,2,…,N.R_i = \int_{D} \left( A \, \frac{d\phi^i}{dx} \frac{du}{dx} - B \, \phi^i \frac{du}{dx} - C \, \phi^i u + D \, \phi^i \right) dx, \qquad i = 1, 2, \dots, N.

The boundary term [A dudx ϕi]\left[ A \, \frac{du}{dx} \, \phi^i \right] vanishes on zero-gradient boundaries, and the residuals of the nodes with a constant value are replaced by the Dirichlet condition. In the nonlinear form the Jacobian matrix is

Jij=−∂Ri∂uj=−∫D(A dϕidxdϕjdx−B ϕidϕjdx−C ϕiϕj+∂D∂u ϕiϕj)dx.\mathcal{J}_{ij} = -\frac{\partial R_i}{\partial u_j} = -\int_{D} \left( A \, \frac{d\phi^i}{dx} \frac{d\phi^j}{dx} - B \, \phi^i \frac{d\phi^j}{dx} - C \, \phi^i \phi^j + \frac{\partial D}{\partial u} \, \phi^i \phi^j \right) dx.

Usage​

Linear: advection–diffusion​

The equation d2udx2−10dudx=10 e−200(x−0.5)2\frac{d^2u}{dx^2} - 10 \frac{du}{dx} = 10 \, e^{-200 (x - 0.5)^2} on 0≤x≤10 \le x \le 1:

import { FEAScriptModel } from "feascript";

// 1. Create the model and select the physics
const model = new FEAScriptModel();
model.setModelConfig("generalFormPDEScript", {
coefficientFunctions: {
A: (x) => 1, // Diffusion coefficient
B: (x) => -10, // Advection coefficient
C: (x) => 0, // Reaction coefficient
D: (x) => 10 * Math.exp(-200 * Math.pow(x - 0.5, 2)), // Source term
},
});

// 2. Define the mesh
model.setMeshConfig({
meshDimension: "1D",
elementOrder: "quadratic",
numElementsX: 20,
maxX: 1.0,
});

// 3. Apply the boundary conditions
model.addBoundaryCondition("0", ["constantValue", 1]); // Left, x = 0
model.addBoundaryCondition("1", ["zeroGradient"]); // Right, x = 1

// 4. Solve
model.setSolverMethod("lusolve");
const { solutionVector, nodesCoordinates } = model.solve();

Nonlinear: reaction–diffusion​

The equation d2udx2−Da u2=0\frac{d^2u}{dx^2} - Da \, u^2 = 0 on 0≤x≤100 \le x \le 10, written as d2udx2=D(x,u)\frac{d^2u}{dx^2} = D(x, u) with D=Da u2D = Da \, u^2:

const Da = 1;

model.setModelConfig("generalFormPDEScript", {
nonlinear: true, // Solve with the Newton-Raphson method
coefficientFunctions: {
A: (x) => 1,
B: (x) => 0,
C: (x) => 0,
D: (x, u) => Da * u ** 2, // Nonlinear source term
dDdu: (x, u) => 2 * Da * u, // ∂D/∂u, required for the Jacobian matrix
},
});

model.setMeshConfig({ meshDimension: "1D", elementOrder: "linear", numElementsX: 20, maxX: 10.0 });

model.addBoundaryCondition("0", ["constantValue", 1]);
model.addBoundaryCondition("1", ["zeroGradient"]);

model.setSolverMethod("lusolve");

const { solutionVector, nodesCoordinates } = model.solve({ maxIterations: 100, tolerance: 1e-5 });

Model options​

OptionTypeDefaultDescription
coefficientFunctionsobject–The coefficient functions below (required)
nonlinearbooleanfalseSolve the nonlinear form with the Newton–Raphson method
maxIterationsnumber100Maximum Newton–Raphson iterations (nonlinear form)
tolerancenumber1e-4Newton–Raphson tolerance on ∥Δuˉ∥2\lVert \Delta \bar{u} \rVert_2 (nonlinear form)

maxIterations and tolerance can also be passed to solve(), which takes precedence. In the linear form, they apply to the "jacobi" solver instead.

Coefficient functions​

PropertySymbolSignatureRequired
AA(x)A(x)(x) => numberYes
BB(x)B(x)(x) => numberYes
CC(x)C(x)(x) => numberYes
DD(x)D(x) or D(x,u)D(x, u)(x) => number or (x, u) => numberYes
dDdu∂D/∂u\partial D / \partial u(x, u) => numberNonlinear form

All coefficients must be functions, even when they are constant (write A: (x) => 1, not A: 1). They are evaluated at every integration point; in the nonlinear form, u is the value of the current Newton–Raphson iterate at that point.

Boundary conditions​

ConditionParametersKind
["constantValue", value]ubu_bDirichlet
["zeroGradient"]–Neumann (natural)

The boundary keys are "0" (left end, x=0x = 0) and "1" (right end, x=maxXx = maxX). A boundary without a condition behaves as "zeroGradient".

Solvers​

FormSupported methods
Linear"lusolve", "jacobi", "frontal"
Nonlinear"lusolve", "jacobi" (inside Newton–Raphson)

The frontal solver is not supported for the nonlinear form.

Results​

solutionVector holds the nodal values of uu, in the order of nodesCoordinates.nodesXCoordinates (left to right).

Examples​