importGmshMesh
const parsedMesh = await importGmshMesh(file);
Reads a 2D 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.
| Parameter | Type | Description |
|---|---|---|
file | object | A 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. Its meshDimension ("2D") and elementOrder
("linear" or "quadratic") are detected from the file and used by setMeshConfig.
In the browser
From a file input:
<input type="file" id="meshFile" accept=".msh" />
<script type="module">
import { FEAScriptModel, importGmshMesh } from "https://core.feascript.com/dist/feascript.esm.js";
document.getElementById("meshFile").addEventListener("change", async (event) => {
const parsedMesh = await importGmshMesh(event.target.files[0]);
const model = new FEAScriptModel();
model.setModelConfig("heatConductionScript");
model.setMeshConfig({ parsedMesh });
// ...boundary conditions and solve
});
</script>
From a file on the server:
const response = await fetch("./rhom_quad.msh");
const meshFile = new File([await response.text()], "rhom_quad.msh");
const parsedMesh = await importGmshMesh(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 { FEAScriptModel, importGmshMesh } 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 importGmshMesh({ text: async () => meshContent });
model.setMeshConfig({ parsedMesh });
// 3. Apply the boundary conditions
model.addBoundaryCondition("0", ["constantTemperature", 200]); // Physical curve "bottom", tag 1
model.addBoundaryCondition("1", ["symmetry"]); // Physical curve "left", tag 2
model.addBoundaryCondition("2", ["convection", 1, 20]); // Physical curve "top", tag 3
model.addBoundaryCondition("3", ["constantTemperature", 200]); // Physical curve "right", tag 4
// 4. Solve
const { solutionVector, nodesCoordinates } = model.solve();
Limitations
- Only 2D meshes are supported; a 1D or 3D mesh is reported as an error.
- All elements must be of the same shape (quadrilaterals or triangles) and order (linear or quadratic).
- 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.