1111// External imports
1212import * as ti from '../vendor/taichi.esm.js' ;
1313
14+ // Internal imports
15+ import { basicLog , debugLog , errorLog } from "../utilities/loggingScript.js" ;
16+
1417export 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