Skip to main content
Version: 0.2.0

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

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", ["constantTemp", 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 propagation2D
"creepingFlowScript"Creeping flow2D
OptionTypeUsed byDescription
coefficientFunctionsobjectGeneral form PDECoefficients of the equation; see the model page
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 the front propagation model; see Solvers for their defaults.

model.setModelConfig("generalFormPDEScript", {
coefficientFunctions: {
A: (x) => 1,
B: (x) => -10,
C: (x) => 0,
D: (x) => 10 * Math.exp(-200 * Math.pow(x - 0.5, 2)),
},
});

setSolverConfig(solverConfig, options)​

Deprecated alias of setModelConfig, with the same parameters. It logs a deprecation warning; use setModelConfig. It was removed in version 0.3.0.

setMeshConfig(meshConfig)​

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

PropertyTypeDescription
meshDimensionstring"1D" or "2D" (required, also for parsedMesh)
elementOrderstring"linear" (default) or "quadratic" (must match the elements of a 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 importGmshQuadTri

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", ...)
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 ignored without a message.

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
solutionVectornumber[]The computed unknowns (see the model pages)
nodesCoordinates.nodesXCoordinatesnumber[]xx coordinates of the mesh nodes
nodesCoordinates.nodesYCoordinatesnumber[]yy coordinates of the mesh nodes (2D meshes)

For the heat conduction, general form PDE and front propagation models, solutionVector has one value per node, in the order of nodesCoordinates. For the creeping flow model, it holds the velocity components and the pressure in consecutive blocks.

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
computeEngineobjectNot used in version 0.2.0: FEAScript creates a WebGPU compute engine for every solve
optionsobjectOptional { maxIterations, tolerance }
caution

solveAsync supports only heatConductionScript with the "jacobi-gpu" solver method, in browsers with WebGPU support, with FEAScript imported from src/index.js (see Solvers). For other models or solver methods, it returns an empty solution vector.

Error handling​

FEAScript reports configuration problems (for example a creeping flow model on linear elements, or a solver that did not converge) as [ERROR] messages in the console, and in most cases continues instead of throwing an exception. Some invalid configurations, such as a missing meshDimension, end in a JavaScript error later in the solution. Check the console output when a result looks wrong.