Skip to content

Commit 104b23e

Browse files
committed
Refactor solver configuration in FEAScript; remove coefficient functions handling and update boundary conditions application
1 parent b20b50d commit 104b23e

File tree

3 files changed

+12
-101
lines changed

3 files changed

+12
-101
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!-- [![liberapay](https://img.shields.io/liberapay/receives/FEAScript.svg?logo=liberapay)](https://liberapay.com/FEAScript/) -->
88

9-
[FEAScript](https://feascript.com/) is a lightweight finite element simulation library written in JavaScript. It empowers users to create and execute simulations for physics and engineering applications in both browser-based and server-side environments. This is the core library of the FEAScript project.
9+
[FEAScript](https://feascript.com/) is a lightweight finite element simulation library written in JavaScript. It empowers users to perform simulations for physics and engineering applications in both browser-based and server-side environments. This is the core library of the FEAScript project.
1010

1111
> 🚧 **FEAScript is currently under heavy development.** Its functionality and interfaces may change rapidly as new features and enhancements are introduced.
1212

src/FEAScript.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,12 @@ export class FEAScriptModel {
3434
}
3535

3636
/**
37-
* Sets the solver configuration and optionally PDE coefficient functions
37+
* Sets the solver configuration
3838
* @param {string} solverConfig - Parameter specifying the type of solver
39-
* @param {object} [options] - Additional solver options
40-
* @param {object} [options.coefficientFunctions] - Functions A(x), B(x), C(x), D(x) for general form PDE
4139
*/
42-
setSolverConfig(solverConfig, options = {}) {
40+
setSolverConfig(solverConfig = {}) {
4341
this.solverConfig = solverConfig;
4442

45-
// Store coefficient functions if provided
46-
if (options.coefficientFunctions) {
47-
this.coefficientFunctions = options.coefficientFunctions;
48-
debugLog(`Coefficient functions set for ${solverConfig}`);
49-
}
50-
5143
debugLog(`Solver config set to: ${solverConfig}`);
5244
}
5345

@@ -158,29 +150,16 @@ export class FEAScriptModel {
158150
} else if (this.solverConfig === "generalFormPDEScript") {
159151
basicLog(`Using solver: ${this.solverConfig}`);
160152

161-
// Check if coefficient functions are provided
162-
if (!this.coefficientFunctions) {
163-
const error = "Coefficient functions must be provided for general form PDE solver";
164-
errorLog(error);
165-
throw new Error(error);
166-
}
167-
168153
if (this.solverMethod === "frontal") {
169154
// For frontal solver
170-
const frontalResult = runFrontalSolver(
171-
assembleGeneralFormPDEFront,
172-
meshData,
173-
this.boundaryConditions,
174-
{ coefficientFunctions: this.coefficientFunctions }
175-
);
176-
solutionVector = frontalResult.solutionVector;
177155
} else {
178156
// For other solver methods
179-
({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(
180-
meshData,
181-
this.boundaryConditions,
182-
this.coefficientFunctions
183-
));
157+
({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(meshData, this.boundaryConditions, {
158+
A: () => 1, // Diffusion coefficient
159+
B: () => 1, // Advection coefficient
160+
C: () => 0, // Reaction coefficient
161+
D: () => 0, // Source term
162+
}));
184163
const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector);
185164
solutionVector = linearSystemResult.solutionVector;
186165
}

src/solvers/generalFormPDEScript.js

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,73 +13,6 @@ import { initializeFEA, performIsoparametricMapping1D } from "../mesh/meshUtilsS
1313
import { GenericBoundaryConditions } from "./genericBoundaryConditionsScript.js";
1414
import { basicLog, debugLog, errorLog } from "../utilities/loggingScript.js";
1515

16-
/**
17-
* Class to handle general form PDE boundary conditions application
18-
* Extends GenericBoundaryConditions for PDE-specific conditions
19-
*/
20-
export class GeneralFormPDEBoundaryConditions extends GenericBoundaryConditions {
21-
/**
22-
* Constructor to initialize the GeneralFormPDEBoundaryConditions class
23-
* @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis
24-
* @param {array} boundaryElements - Array containing elements that belong to each boundary
25-
* @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes
26-
* @param {string} meshDimension - The dimension of the mesh (e.g., "1D")
27-
* @param {string} elementOrder - The order of elements (e.g., "linear")
28-
* @param {object} coefficients - Coefficient functions for the PDE
29-
*/
30-
constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder, coefficients) {
31-
super(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder);
32-
this.coefficients = coefficients;
33-
}
34-
35-
/**
36-
* Function to impose Dirichlet boundary conditions for the general form PDE
37-
* @param {array} residualVector - The residual vector to be modified
38-
* @param {array} jacobianMatrix - The Jacobian matrix to be modified
39-
*/
40-
imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {
41-
for (const [boundaryKey, condition] of Object.entries(this.boundaryConditions)) {
42-
if (condition[0] === "constantValue") {
43-
const value = condition[1];
44-
const boundaryNodes = this.getBoundaryNodes(boundaryKey);
45-
46-
for (const nodeIndex of boundaryNodes) {
47-
// Standard Dirichlet implementation
48-
for (let i = 0; i < jacobianMatrix.length; i++) {
49-
jacobianMatrix[nodeIndex][i] = 0;
50-
}
51-
jacobianMatrix[nodeIndex][nodeIndex] = 1;
52-
residualVector[nodeIndex] = value;
53-
}
54-
}
55-
}
56-
debugLog("Dirichlet boundary conditions applied for general form PDE");
57-
}
58-
59-
/**
60-
* Get all nodes associated with a boundary
61-
* @param {string} boundaryKey - The key identifying the boundary
62-
* @returns {array} Array of node indices
63-
*/
64-
getBoundaryNodes(boundaryKey) {
65-
const boundaryNodes = new Set();
66-
const elements = this.boundaryElements[boundaryKey];
67-
68-
if (!elements) {
69-
errorLog(`Boundary ${boundaryKey} not found`);
70-
return [];
71-
}
72-
73-
for (const element of elements) {
74-
for (const node of this.nop[element]) {
75-
boundaryNodes.add(Math.abs(node) - 1); // Convert to 0-based indexing
76-
}
77-
}
78-
79-
return Array.from(boundaryNodes);
80-
}
81-
}
82-
8316
/**
8417
* Function to assemble the Jacobian matrix and residuals vector for the general form PDE model
8518
* @param {object} meshData - Object containing prepared mesh data
@@ -200,17 +133,16 @@ export function assembleGeneralFormPDEMat(meshData, boundaryConditions, coeffici
200133
}
201134

202135
// Apply boundary conditions
203-
const pdeBoundaryConditions = new GeneralFormPDEBoundaryConditions(
136+
const genericBoundaryConditions = new GenericBoundaryConditions(
204137
boundaryConditions,
205138
boundaryElements,
206139
nop,
207140
meshDimension,
208-
elementOrder,
209-
coefficientFunctions
141+
elementOrder
210142
);
211143

212144
// Apply Dirichlet boundary conditions only
213-
pdeBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);
145+
genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);
214146

215147
basicLog("General form PDE matrix assembly completed");
216148

0 commit comments

Comments
 (0)