Mesh
The mesh is defined with model.setMeshConfig(meshConfig). FEAScript can either generate a structured mesh
from a few geometric parameters, or use an unstructured 2D quadrilateral mesh imported from
Gmsh.
Structured meshes
A structured mesh covers a line () in 1D, or a rectangle (, ) in 2D, which can optionally be skewed into a trapezoid. 2D structured meshes always consist of quadrilateral elements.
// 1D: 20 quadratic elements on 0 ≤ x ≤ 0.15
model.setMeshConfig({
meshDimension: "1D",
elementOrder: "quadratic",
numElementsX: 20,
maxX: 0.15,
});
// 2D: 8 × 4 quadratic quadrilaterals on 0 ≤ x ≤ 4, 0 ≤ y ≤ 2
model.setMeshConfig({
meshDimension: "2D",
elementOrder: "quadratic",
numElementsX: 8,
numElementsY: 4,
maxX: 4,
maxY: 2,
});
| Property | Type | Required | Description |
|---|---|---|---|
meshDimension | string | Yes | "1D" or "2D" |
elementOrder | string | No | "linear" (default) or "quadratic" |
numElementsX | number | Yes | Number of elements along |
maxX | number | Yes | Length of the domain along (the domain starts at ) |
numElementsY | number | 2D only | Number of elements along |
maxY | number | 2D only | Height of the domain along (the domain starts at ) |
angleLeft | number | No (2D only) | Interior angle of the left side in degrees (default 90) |
angleRight | number | No (2D only) | Interior angle of the right side in degrees (default 90) |
Boundaries of a structured mesh
The boundaries of a structured mesh are identified by the following keys, which are the first argument of
addBoundaryCondition:
| Mesh | Key | Boundary |
|---|---|---|
| 1D | "0" | Left end, |
| 1D | "1" | Right end, |
| 2D | "0" | Bottom side, |
| 2D | "1" | Left side |
| 2D | "2" | Top side, |
| 2D | "3" | Right side |
Skewed (trapezoidal) domains
angleLeft and angleRight turn the rectangle into a trapezoid. Both angles are measured inside the domain,
from the bottom side, so 90 keeps the side vertical, a smaller angle leans the side towards the inside of the
domain and a larger one leans it outwards. The bottom side always spans , and the nodes of
every row are spaced uniformly between the left and right sides.
model.setMeshConfig({
meshDimension: "2D",
elementOrder: "linear",
numElementsX: 6,
numElementsY: 4,
maxX: 4,
maxY: 2,
angleLeft: 60,
angleRight: 75,
});
Node numbering
The nodes of a structured mesh are numbered column by column: along first (bottom to top), then along (left to right). In 2D, the node in column and row (both starting from zero) has the index
where is the number of nodes along ( for linear elements and
for quadratic elements). In 1D, the nodes are numbered from left to right.
This is also the order of the entries of the solution vector returned by solve().
Gmsh meshes
Unstructured 2D meshes made with Gmsh are read with importGmshQuadTri and passed to the
model through the parsedMesh property, together with the mesh dimension and the element order:
const parsedMesh = await importGmshQuadTri(meshFile);
model.setMeshConfig({
parsedMesh,
meshDimension: "2D", // Required
elementOrder: "quadratic", // Must match the elements of the mesh
});
FEAScript 0.2.0 does not detect the mesh dimension or the element order from the file. meshDimension: "2D" is
required, and elementOrder must be "quadratic" for a mesh of 9-node quadrangles (it defaults to "linear").
Supported Gmsh meshes:
-
.mshfile format version 4.1, ASCII -
2D meshes only
-
Quadrilaterals, linear or quadratic:
Gmsh element Gmsh type FEAScript element 4-node quadrangle 3 Quadrilateral, linear 9-node quadrangle 10 Quadrilateral, quadratic -
All elements of a mesh must have the same order. Triangular elements are not supported in this version.
-
The node tags must be numbered contiguously from 1 (the default numbering of Gmsh).
Boundaries of a Gmsh mesh
Boundaries are taken from the named 1D physical groups (Physical Curve or Physical Line with a name in a
.geo file). The names are required: FEAScript 0.2.0 reads the boundaries from the $PhysicalNames section of the
file, which Gmsh writes only for named groups. The boundaries are numbered in increasing order of their physical
tag, starting from key "0". When the physical curves have the tags 1, 2, ..., the boundary key is the tag
minus one. 2D physical groups (for example a Physical Surface) do not define boundaries.
To get the same keys as a structured mesh, tag the sides in the order bottom, left, top, right. For a rectangle whose lines 1, 2, 3, 4 are the bottom, right, top and left sides:
Physical Line("bottom", 1) = {1}; // tag 1 → boundary key "0"
Physical Line("left", 2) = {4}; // tag 2 → boundary key "1"
Physical Line("top", 3) = {3}; // tag 3 → boundary key "2"
Physical Line("right", 4) = {2}; // tag 4 → boundary key "3"
Physical Surface("domain", 5) = {1};
The second argument of Physical Line sets the tag explicitly. Without it, Gmsh numbers the groups in the order they
are defined.
Generate the mesh in the supported format with:
gmsh rect.geo -2 -format msh41 -o rect.msh
Add Recombine Surface{1}; in the .geo file for quadrilaterals, and Mesh.ElementOrder = 2; for quadratic
elements.