Skip to main content
Version: 0.2.0

General form PDE

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

caution

The general form PDE model of version 0.2.0 supports 1D meshes and the linear form only. The nonlinear form (solved with the Newton–Raphson method) was added in version 0.3.0.

Governing equation​

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.

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.

Usage​

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 * as math from "mathjs";
global.math = math;

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();

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)(x) => numberYes

All coefficients must be functions, even when they are constant (write A: (x) => 1, not A: 1). They are evaluated at every integration point.

The maxIterations and tolerance options of setModelConfig and solve() apply to the "jacobi" solver.

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​

"lusolve" (default) and "jacobi" are supported. The frontal solver is not supported for this model in version 0.2.0: it logs an error and returns an empty solution vector.

Results​

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

Examples​