Skip to content

Commit ef7e37e

Browse files
committed
Cleanup WebGPU functions
1 parent 23a3445 commit ef7e37e

File tree

5 files changed

+20
-229
lines changed

5 files changed

+20
-229
lines changed

examples/heatConductionScript/heatConduction2DFin/HeatConduction2DFinWebgpu.html

Lines changed: 0 additions & 212 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "feascript",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Lightweight finite element simulation library built in JavaScript for browser-based physics and engineering simulations",
55
"main": "dist/feascript.cjs.js",
66
"module": "dist/feascript.esm.js",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export { importGmshQuadTri } from "./readers/gmshReaderScript.js";
1313
export { logSystem } from "./utilities/loggingScript.js";
1414
export { plotSolution } from "./visualization/plotSolutionScript.js";
1515
export { FEAScriptWorker } from "./workers/workerScript.js";
16-
export const printVersion = "0.1.3";
16+
export const printVersion = "0.1.4";

src/methods/linearSystemSolverScript.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import * as Comlink from "../vendor/comlink.mjs";
1919
* @param {Array} jacobianMatrix - The coefficient matrix
2020
* @param {Array} residualVector - The right-hand side vector
2121
* @param {object} [options] - Additional options for the solver
22-
* @param {number} [options.maxIterations=1000] - Maximum iterations for iterative methods
23-
* @param {number} [options.tolerance=1e-6] - Convergence tolerance for iterative methods
22+
* @param {number} [options.maxIterations=10000] - Maximum iterations for iterative methods
23+
* @param {number} [options.tolerance=1e-3] - Convergence tolerance for iterative methods
2424
* @returns {object} An object containing:
2525
* - solutionVector: The solution vector
2626
* - converged: Boolean indicating whether the method converged (for iterative methods)
2727
* - iterations: Number of iterations performed (for iterative methods)
2828
*/
2929
export function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {
30-
const { maxIterations = 1000, tolerance = 1e-6 } = options;
30+
const { maxIterations = 10000, tolerance = 1e-3 } = options;
3131

3232
let solutionVector = [];
3333
let converged = true;
@@ -128,7 +128,6 @@ export async function solveLinearSystemAsync(solverMethod, jacobianMatrix, resid
128128
errorLog(`Unknown solver method: ${solverMethod}`);
129129
}
130130

131-
// Success-only logging and cleanup
132131
console.timeEnd("systemSolving");
133132
basicLog(`System solved successfully (${solverMethod})`);
134133

src/methods/webgpuComputeEngineScript.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
// External imports
1212
import * as ti from '../vendor/taichi.esm.js';
1313

14+
// Internal imports
15+
import { basicLog, debugLog, errorLog } from "../utilities/loggingScript.js";
16+
1417
export class WebGPUComputeEngine {
1518
constructor() {
1619
this.initialized = false;
@@ -799,7 +802,8 @@ export class WebGPUComputeEngine {
799802
// Full SSOR would need iterative application or matrix splitting
800803
return this.vecMul(invDiag, r);
801804
} else {
802-
throw new Error(`Unsupported preconditioner type: ${type}`);
805+
errorLog(`Unsupported preconditioner type: ${type}`);
806+
return null;
803807
}
804808
}
805809

@@ -813,7 +817,7 @@ export class WebGPUComputeEngine {
813817
* @param {string} [preconditionerType=null] - The type of preconditioner to use
814818
* @returns {array} The solution vector
815819
*/
816-
async webgpuConjugateGradientSolver(A, b, x0 = null, tol = 1e-6, maxIter = 1000, preconditionerType = null) {
820+
async webgpuConjugateGradientSolver(A, b, x0 = null, tol, maxIter, preconditionerType = null) {
817821
const n = b.length;
818822
let x = x0 ? await this.copy(x0) : new Array(n).fill(0.0);
819823

@@ -822,10 +826,10 @@ export class WebGPUComputeEngine {
822826
let rr = await this.dotProduct(r, r);
823827
let rnorm0 = Math.sqrt(rr);
824828

825-
console.log(`CG: Initial residual norm: ${rnorm0}`);
829+
basicLog(`CG: Initial residual norm: ${rnorm0}`);
826830

827831
if (rnorm0 < tol) {
828-
console.log(`CG: Already converged`);
832+
basicLog(`CG: Already converged`);
829833
return x;
830834
}
831835

@@ -840,7 +844,7 @@ export class WebGPUComputeEngine {
840844
const pAp = await this.dotProduct(p, Ap);
841845

842846
if (Math.abs(pAp) < 1e-16) {
843-
console.log(`CG: p^T * A * p is too small (${pAp}), stopping`);
847+
errorLog(`CG: p^T * A * p is too small (${pAp}), stopping`);
844848
break;
845849
}
846850

@@ -859,11 +863,11 @@ export class WebGPUComputeEngine {
859863
const rr_new = await this.dotProduct(r, r);
860864
const rnorm = Math.sqrt(rr_new);
861865

862-
console.log(`CG: Iteration ${iter + 1}, residual norm: ${rnorm}`);
866+
basicLog(`CG: Iteration ${iter + 1}, residual norm: ${rnorm}`);
863867

864868
// Check convergence
865869
if (rnorm < tol * rnorm0) {
866-
console.log(`CG: Converged in ${iter + 1} iterations`);
870+
basicLog(`CG: Converged in ${iter + 1} iterations`);
867871
break;
868872
}
869873

@@ -897,7 +901,7 @@ export class WebGPUComputeEngine {
897901
* @param {number} [tol=1e-6] - Convergence tolerance
898902
* @returns {array} The solution vector
899903
*/
900-
async webgpuJacobiSolver(A, b, x0, maxIter = 1000, tol = 1e-6) {
904+
async webgpuJacobiSolver(A, b, x0, maxIter, tol) {
901905
const n = b.length;
902906
let x = await this.copy(x0);
903907
let x_new = await this.copy(x0);
@@ -911,10 +915,10 @@ export class WebGPUComputeEngine {
911915

912916
// Check convergence
913917
const rnorm = await this.norm(r);
914-
console.log(`Jacobi: Iteration ${iter + 1}, residual norm: ${rnorm}`);
918+
basicLog(`Jacobi: Iteration ${iter + 1}, residual norm: ${rnorm}`);
915919

916920
if (rnorm < tol) {
917-
console.log(`Jacobi: Converged in ${iter + 1} iterations`);
921+
basicLog(`Jacobi: Converged in ${iter + 1} iterations`);
918922
return x;
919923
}
920924

@@ -927,7 +931,7 @@ export class WebGPUComputeEngine {
927931
[x, x_new] = [x_new, x];
928932
}
929933

930-
console.log(`Jacobi: Did not converge in ${maxIter} iterations`);
934+
errorLog(`Jacobi: Did not converge in ${maxIter} iterations`);
931935
return x;
932936
}
933937

0 commit comments

Comments
 (0)