Skip to main content
Version: 0.3.1

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 mesh imported from Gmsh.

Structured meshes​

A structured mesh covers a line (0≤x≤maxX0 \le x \le maxX) in 1D, or a rectangle (0≤x≤maxX0 \le x \le maxX, 0≤y≤maxY0 \le y \le maxY) 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,
});
PropertyTypeRequiredDescription
meshDimensionstringYes"1D" or "2D"
elementOrderstringNo"linear" (default) or "quadratic"
numElementsXnumberYesNumber of elements along xx
maxXnumberYesLength of the domain along xx (the domain starts at x=0x = 0)
numElementsYnumber2D onlyNumber of elements along yy
maxYnumber2D onlyHeight of the domain along yy (the domain starts at y=0y = 0)
angleLeftnumberNo (2D only)Interior angle of the left side in degrees (default 90)
angleRightnumberNo (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:

Boundary keys of the structured 1D and 2D meshes

MeshKeyBoundary
1D"0"Left end, x=0x = 0
1D"1"Right end, x=maxXx = maxX
2D"0"Bottom side, y=0y = 0
2D"1"Left side
2D"2"Top side, y=maxYy = maxY
2D"3"Right side
note

The Euler–Bernoulli beam model does not use these keys: its boundary conditions are keyed by node number, so that supports and loads can also be placed at interior nodes.

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 0≤x≤maxX0 \le x \le maxX, and the nodes of every row are spaced uniformly between the left and right sides.

Skewed 2D structured mesh defined by angleLeft and angleRight

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 yy first (bottom to top), then along xx (left to right). In 2D, the node in column ii and row jj (both starting from zero) has the index

index=i⋅ny+j,\text{index} = i \cdot n_y + j,

where nyn_y is the number of nodes along yy (ny=numElementsY+1n_y = numElementsY + 1 for linear elements and ny=2⋅numElementsY+1n_y = 2 \cdot numElementsY + 1 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 importGmshMesh and passed to the model through the parsedMesh property:

const parsedMesh = await importGmshMesh(meshFile);
model.setMeshConfig({ parsedMesh });

The mesh dimension and the element order are detected from the file, so meshDimension and elementOrder can be omitted. If they are given and differ from the mesh, FEAScript logs an error.

Supported Gmsh meshes:

  • .msh file format version 4.1, ASCII

  • 2D meshes only

  • Quadrilaterals or triangles, linear or quadratic:

    Gmsh elementGmsh typeFEAScript element
    3-node triangle2Triangle, linear
    4-node quadrangle3Quadrilateral, linear
    6-node triangle9Triangle, quadratic
    9-node quadrangle10Quadrilateral, quadratic
  • All elements of a mesh must have the same shape and the same order (mixed meshes are not supported).

Boundaries of a Gmsh mesh​

Boundaries are taken from the 1D physical groups (Physical Curve or Physical Line in a .geo file). They 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.