1+ // ______ ______ _____ _ _ //
2+ // | ____| ____| /\ / ____| (_) | | //
3+ // | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+ // | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+ // | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+ // |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+ // | | | | //
8+ // |_| | |_ //
9+ // Website: https://feascript.com/ \__| //
10+
11+ import * as Comlink from "../vendor/comlink.mjs" ;
12+ import { WebGPUComputeEngine } from "../utilities/webgpuComputeEngine.js" ;
13+
14+ /**
15+ * Function to solve a system of linear equations using the Jacobi iterative method
16+ * This version uses the WebGPU compute engine for maximum performance and reusability
17+ * @param {array } A - The coefficient matrix (must be square)
18+ * @param {array } b - The right-hand side vector
19+ * @param {array } x0 - Initial guess for solution vector
20+ * @param {number } [maxIterations=100] - Maximum number of iterations
21+ * @param {number } [tolerance=1e-7] - Convergence tolerance
22+ * @param {boolean } [useFloat64=true] - Whether to use Float64Array for higher precision
23+ * @returns {object } An object containing:
24+ * - solution: The solution vector
25+ * - iterations: The number of iterations performed
26+ * - converged: Boolean indicating whether the method converged
27+ */
28+ export async function jacobiMethod ( A , b , x0 , maxIterations = 100 , tolerance = 1e-7 , useFloat64 = true ) {
29+ // Use the dedicated worker file
30+ const worker = new Worker ( './workers/webgpuJacobiWorker.js' , { type : 'module' } ) ;
31+ const jacobiWorker = Comlink . wrap ( worker ) ;
32+
33+ try {
34+ const result = await jacobiWorker . jacobiMethod ( A , b , x0 , maxIterations , tolerance , useFloat64 ) ;
35+ return result ;
36+ } catch ( error ) {
37+ console . error ( "Error in WebGPU Jacobi method:" , error ) ;
38+ throw error ;
39+ } finally {
40+ worker . terminate ( ) ;
41+ }
42+ }
0 commit comments