-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathheatConduction2DFinGmsh.js
More file actions
70 lines (55 loc) · 2.32 KB
/
heatConduction2DFinGmsh.js
File metadata and controls
70 lines (55 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* ════════════════════════════════════════════════════════════════
* FEAScript Core Library
* Lightweight Finite Element Simulation in JavaScript
* Version: 0.3.0 (RC) | https://feascript.com
* MIT License © 2023–2026 FEAScript
* ════════════════════════════════════════════════════════════════
*/
// Import required Node.js modules
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
// Import Math.js
import * as math from "mathjs";
global.math = math;
// Import FEAScript library
import { FEAScriptModel, importGmshMesh, printVersion } from "feascript";
console.log("FEAScript Version:", printVersion);
// Get directory name for the current file
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Read the mesh file
const meshFilePath = path.join(__dirname, "rect_quad.msh");
const meshContent = fs.readFileSync(meshFilePath, "utf8");
async function main() {
// Create a new FEAScript model
const model = new FEAScriptModel();
// Select physics/PDE
model.setModelConfig("heatConductionScript");
// Create a mock File object for Node.js environment
const mockFile = {
text: async () => meshContent,
name: "rect_quad.msh",
};
// Parse the mesh data
const result = await importGmshMesh(mockFile);
// Define mesh configuration with the parsed result
model.setMeshConfig({
parsedMesh: result,
meshDimension: "2D",
elementOrder: "quadratic",
});
// Define boundary conditions
model.addBoundaryCondition("0", ["constantTemp", 200]); // Bottom boundary
model.addBoundaryCondition("1", ["constantTemp", 200]); // Right boundary
model.addBoundaryCondition("2", ["convection", 1, 20]); // Top boundary
model.addBoundaryCondition("3", ["symmetry"]); // Left boundary
// Solve the problem
const { solutionVector, nodesCoordinates } = model.solve();
// Print results
console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`);
console.log("Node coordinates:", nodesCoordinates);
console.log("Solution vector:", solutionVector);
}
// Run the main function
main();