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.
The general form PDE model currently supports 1D meshes only.
Governing equation
Linear form
where is the diffusion coefficient, the advection coefficient, the reaction coefficient and the source term.
Nonlinear form
With nonlinear: true, the source term may depend on the solution:
and the system is solved with the Newton–Raphson method. The derivative must be given as well, since it enters the Jacobian matrix.
Boundary conditions
Weak form
After integration by parts of the diffusion term, the Galerkin residuals are
The boundary term 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
Usage
Linear: advection–diffusion
The equation on :
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 on , written as with :
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
| Option | Type | Default | Description |
|---|---|---|---|
coefficientFunctions | object | – | The coefficient functions below (required) |
nonlinear | boolean | false | Solve the nonlinear form with the Newton–Raphson method |
maxIterations | number | 100 | Maximum Newton–Raphson iterations (nonlinear form) |
tolerance | number | 1e-4 | Newton–Raphson tolerance on (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
| Property | Symbol | Signature | Required |
|---|---|---|---|
A | (x) => number | Yes | |
B | (x) => number | Yes | |
C | (x) => number | Yes | |
D | or | (x) => number or (x, u) => number | Yes |
dDdu | (x, u) => number | Nonlinear 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
| Condition | Parameters | Kind |
|---|---|---|
["constantValue", value] | Dirichlet | |
["zeroGradient"] | – | Neumann (natural) |
The boundary keys are "0" (left end, ) and "1" (right end, ). A boundary without a
condition behaves as "zeroGradient".
Solvers
| Form | Supported 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 , in the order of nodesCoordinates.nodesXCoordinates (left to
right).
Examples
- Advection–diffusion in 1D
- Node.js scripts in
examples/generalFormPDEScript(advection–diffusion and nonlinear reaction–diffusion)