Skip to main content
Version: 0.3.1

FEAScriptModel

FEAScriptModel is the main class of FEAScript. It holds the configuration of a simulation (model, mesh, boundary conditions and solver) and solves it.

import { FEAScriptModel } from "feascript";

const model = new FEAScriptModel();
model.setModelConfig("heatConductionScript");
model.setMeshConfig({ meshDimension: "1D", elementOrder: "linear", numElementsX: 10, maxX: 0.15 });
model.addBoundaryCondition("0", ["convection", 1, 25]);
model.addBoundaryCondition("1", ["constantTemperature", 5]);
model.setSolverMethod("lusolve");
const { solutionVector, nodesCoordinates } = model.solve();

Constructor​

new FEAScriptModel()​

Creates an empty model. The solver method defaults to "lusolve".

Methods​

setModelConfig(modelConfig, options)​

Selects the physical model and sets its options.

ParameterTypeDescription
modelConfigstringName of the model (see below)
optionsobjectOptional model options (see below)
modelConfigModelDimensions
"heatConductionScript"Heat conduction1D, 2D
"generalFormPDEScript"General form PDE1D
"frontPropagationScript"Front propagation1D, 2D
"creepingFlowScript"Creeping flow2D
"eulerBernoulliBeamScript"Euler–Bernoulli beam1D
OptionTypeUsed byDescription
coefficientFunctionsobjectHeat conduction, general form PDE, creeping flow, Euler–Bernoulli beamCoefficients of the equation; see each model page
nonlinearbooleanGeneral form PDESolve with the Newton–Raphson method (default false)
maxIterationsnumberAllMaximum iterations of the iterative method in use
tolerancenumberAllConvergence tolerance of the iterative method in use

maxIterations and tolerance apply to the Jacobi solvers in linear models and to the Newton–Raphson method in nonlinear models; see Solvers for their defaults.

model.setModelConfig("heatConductionScript", {
coefficientFunctions: {
thermalConductivity: (x, y) => (x < 2 ? 10 : 1),
heatSource: 0,
},
});

setMeshConfig(meshConfig)​

Sets the mesh: either the parameters of a structured mesh or a mesh imported from Gmsh.

PropertyTypeDescription
meshDimensionstring"1D" or "2D" (detected automatically for parsedMesh)
elementOrderstring"linear" (default) or "quadratic" (detected automatically for parsedMesh)
numElementsXnumberNumber of elements along xx (structured mesh)
numElementsYnumberNumber of elements along yy (structured 2D mesh)
maxXnumberLength of the domain along xx (structured mesh)
maxYnumberHeight of the domain along yy (structured 2D mesh)
angleLeftnumberInterior angle of the left side in degrees, default 90 (structured 2D mesh)
angleRightnumberInterior angle of the right side in degrees, default 90 (structured 2D mesh)
parsedMeshobjectMesh returned by importGmshMesh

See Mesh for the geometry, the boundary keys and the node numbering.

addBoundaryCondition(boundaryKey, condition)​

Adds a boundary condition, or replaces the condition of a boundary that already has one.

ParameterTypeDescription
boundaryKeystringBoundary key ("0", "1", ...), or node number for the Euler–Bernoulli beam
conditionarrayCondition type followed by its parameters, e.g. ["convection", 1, 20]

See Boundary conditions for the condition types of each model. Condition types that the selected model does not recognize are reported as errors when solve() runs (see Checks).

setSolverMethod(solverMethod)​

Selects the linear system solver: "lusolve" (default), "jacobi", "frontal" or "jacobi-gpu". See Solvers for the methods supported by each model.

solve(options)​

Prepares the mesh, assembles the system, applies the boundary conditions and solves it. This method is synchronous.

ParameterTypeDescription
optionsobjectOptional { maxIterations, tolerance }; they take precedence over setModelConfig options

Returns an object with:

PropertyTypeDescription
solutionVectorFloat64ArrayThe computed unknowns (see the model pages)
nodesCoordinates.nodesXCoordinatesnumber[]xx coordinates of the mesh nodes
nodesCoordinates.nodesYCoordinatesnumber[]yy coordinates of the mesh nodes (2D meshes)
fieldsobjectNamed fields, one value per node (models with several unknowns per node)

For scalar models (heat conduction, general form PDE, front propagation), solutionVector has one value per node, in the order of nodesCoordinates, and there is no fields property. The creeping flow (velocityMagnitude, u, v, p) and Euler–Bernoulli beam (w, theta) models have more unknowns per node: fields holds each of them as a Float64Array with one value per node, ready to plot or post-process.

solveAsync(computeEngine, options)​

Asynchronous version of solve, used with the "jacobi-gpu" solver method. It returns a Promise that resolves to the same object as solve().

model.setSolverMethod("jacobi-gpu");
const { solutionVector, nodesCoordinates } = await model.solveAsync();
ParameterTypeDescription
computeEngineobjectOptional. An initialized WebGPU compute engine to reuse across solves. When omitted or null, FEAScript creates one for the solve and terminates it afterwards; a provided engine is left running
optionsobjectOptional { maxIterations, tolerance }
caution

solveAsync currently supports only heatConductionScript with the "jacobi-gpu" solver method, in browsers with WebGPU support. For other models or solver methods, it returns an empty solution vector.

Error handling​

FEAScript reports configuration problems (for example an unsupported mesh for a model, or a solver that did not converge) as [ERROR] messages in the console, and in most cases continues instead of throwing an exception. Check the console output when a result looks wrong. See Logging to control the amount of output.