Skip to main content
Version: 0.2.0

importGmshQuadTri

const parsedMesh = await importGmshQuadTri(file);

Reads a 2D quadrilateral mesh generated by Gmsh (.msh format version 4.1, ASCII) and returns it in the form that setMeshConfig expects through its parsedMesh property. See Mesh for the supported element types and for how boundaries are defined.

note

Despite its name, importGmshQuadTri supports quadrilateral elements only in version 0.2.0. Version 0.3.0 replaced it with importGmshMesh, which also reads triangles.

ParameterTypeDescription
fileobjectA File object, or any object with an asynchronous text() method that returns the content of the .msh file

Returns a Promise that resolves to the parsed mesh. Pass it to setMeshConfig together with meshDimension: "2D" and the elementOrder of the mesh, which are not detected from the file.

In the browser​

From a file input:

<input type="file" id="meshFile" accept=".msh" />

<script type="module">
import {
FEAScriptModel,
importGmshQuadTri,
} from "https://cdn.jsdelivr.net/npm/feascript@0.2.0/dist/feascript.esm.js";

document.getElementById("meshFile").addEventListener("change", async (event) => {
const parsedMesh = await importGmshQuadTri(event.target.files[0]);

const model = new FEAScriptModel();
model.setModelConfig("heatConductionScript");
model.setMeshConfig({ parsedMesh, meshDimension: "2D", elementOrder: "quadratic" });
// ...boundary conditions and solve
});
</script>

From a file on the server:

const response = await fetch("./rect_quad.msh");
const meshFile = new File([await response.text()], "rect_quad.msh");
const parsedMesh = await importGmshQuadTri(meshFile);

In Node.js​

Node.js has no File object for files on disk, so pass an object with a text() method:

import fs from "fs";
import * as math from "mathjs";
global.math = math;

import { FEAScriptModel, importGmshQuadTri } from "feascript";

// 1. Create the model and select the physics
const model = new FEAScriptModel();
model.setModelConfig("heatConductionScript");

// 2. Load the Gmsh mesh
const meshContent = fs.readFileSync("rect_quad.msh", "utf8");
const parsedMesh = await importGmshQuadTri({ text: async () => meshContent });
model.setMeshConfig({ parsedMesh, meshDimension: "2D", elementOrder: "quadratic" });

// 3. Apply the boundary conditions
model.addBoundaryCondition("0", ["constantTemp", 200]); // Physical curve "bottom", tag 1
model.addBoundaryCondition("1", ["constantTemp", 200]); // Physical curve "right", tag 2
model.addBoundaryCondition("2", ["convection", 1, 20]); // Physical curve "top", tag 3
model.addBoundaryCondition("3", ["symmetry"]); // Physical curve "left", tag 4

// 4. Solve
const { solutionVector, nodesCoordinates } = model.solve();

The mesh file of this example, rect_quad.msh, is in the examples of FEAScript-core 0.2.0. Its physical curves are tagged bottom, right, top, left, so the keys differ from those of a structured mesh.

Limitations​

  • Only 2D meshes of quadrilaterals are supported, all of the same order (linear or quadratic).
  • The boundaries must be named 1D physical groups (see Boundaries of a Gmsh mesh).
  • Only the ASCII variant of the version 4.1 format is read. Export with gmsh model.geo -2 -format msh41 -o model.msh, or with File → Export and the "Version 4 ASCII" format in the Gmsh interface.