|
| 1 | +/** |
| 2 | + * ════════════════════════════════════════════════════════════════ |
| 3 | + * FEAScript Core Library |
| 4 | + * Lightweight Finite Element Simulation in JavaScript |
| 5 | + * Version: 0.2.0 | https://feascript.com |
| 6 | + * MIT License © 2023–2026 FEAScript |
| 7 | + * ════════════════════════════════════════════════════════════════ |
| 8 | + */ |
| 9 | + |
| 10 | +// Import Math.js |
| 11 | +import * as math from "mathjs"; |
| 12 | +global.math = math; |
| 13 | + |
| 14 | +// Import FEAScript library |
| 15 | +import { FEAScriptModel, printVersion } from "feascript"; |
| 16 | + |
| 17 | +console.log("FEAScript Version:", printVersion); |
| 18 | + |
| 19 | +// Create a new FEAScript model |
| 20 | +const model = new FEAScriptModel(); |
| 21 | + |
| 22 | +// Select physics/PDE |
| 23 | +model.setModelConfig("creepingFlowScript"); |
| 24 | + |
| 25 | +// Define mesh configuration |
| 26 | +model.setMeshConfig({ |
| 27 | + meshDimension: "2D", |
| 28 | + elementOrder: "quadratic", |
| 29 | + numElementsX: 12, |
| 30 | + numElementsY: 6, |
| 31 | + maxX: 4, |
| 32 | + maxY: 2, |
| 33 | +}); |
| 34 | + |
| 35 | +// Define boundary conditions |
| 36 | +model.addBoundaryCondition("0", ["constantVelocity", 0, 0]); // Bottom boundary |
| 37 | +model.addBoundaryCondition("1", ["constantVelocity", 0, 0]); // Left boundary |
| 38 | +model.addBoundaryCondition("2", ["constantVelocity", 1, 0]); // Top boundary |
| 39 | +model.addBoundaryCondition("3", ["constantVelocity", 0, 0]); // Right boundary |
| 40 | + |
| 41 | +// Set solver method (optional) |
| 42 | +model.setSolverMethod("lusolve"); |
| 43 | + |
| 44 | +// Solve the problem |
| 45 | +const { solutionVector, nodesCoordinates } = model.solve(); |
| 46 | + |
| 47 | +// Print results |
| 48 | +console.log(`Number of nodes in mesh: ${nodesCoordinates.nodesXCoordinates.length}`); |
| 49 | +console.log("Node coordinates:", nodesCoordinates); |
| 50 | +console.log("Solution vector:", solutionVector); |
0 commit comments