diff --git a/dist/feascript.cjs.js b/dist/feascript.cjs.js index 3a2dc6f..361c947 100644 --- a/dist/feascript.cjs.js +++ b/dist/feascript.cjs.js @@ -4,5 +4,5 @@ function e(e){let t=0;for(let n=0;n"object"==typeof e&&null!==e||"function"==typeof e,u=new Map([["proxy",{canHandle:e=>c(e)&&e[i],serialize(e){const{port1:t,port2:n}=new MessageChannel;return m(e,t),[n,[n]]},deserialize:e=>(e.start(),f(e))}],["throw",{canHandle:e=>c(e)&&d in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function m(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(s){if(!s||!s.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,s.origin))return void console.warn(`Invalid origin '${s.origin}' for comlink proxy`);const{id:r,type:a,path:c}=Object.assign({path:[]},s.data),u=(s.data.argumentList||[]).map($);let f;try{const t=c.slice(0,-1).reduce(((e,t)=>e[t]),e),n=c.reduce(((e,t)=>e[t]),e);switch(a){case"GET":f=n;break;case"SET":t[c.slice(-1)[0]]=$(s.data.value),f=!0;break;case"APPLY":f=n.apply(t,u);break;case"CONSTRUCT":f=function(e){return Object.assign(e,{[i]:!0})}(new n(...u));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;m(e,n),f=function(e,t){return C.set(e,t),e}(t,[t])}break;case"RELEASE":f=void 0;break;default:return}}catch(e){f={value:e,[d]:0}}Promise.resolve(f).catch((e=>({value:e,[d]:0}))).then((n=>{const[s,i]=M(n);t.postMessage(Object.assign(Object.assign({},s),{id:r}),i),"RELEASE"===a&&(t.removeEventListener("message",o),h(t),l in e&&"function"==typeof e[l]&&e[l]())})).catch((e=>{const[n,o]=M({value:new TypeError("Unserializable return value"),[d]:0});t.postMessage(Object.assign(Object.assign({},n),{id:r}),o)}))})),t.start&&t.start()}function h(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function f(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),E(e,n,[],t)}function p(e){if(e)throw new Error("Proxy has been released and is not useable")}function b(e){return D(e,new Map,{type:"RELEASE"}).then((()=>{h(e)}))}const g=new WeakMap,y="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(g.get(e)||0)-1;g.set(e,t),0===t&&b(e)}));function E(e,t,n=[],o=function(){}){let s=!1;const i=new Proxy(o,{get(o,r){if(p(s),r===a)return()=>{!function(e){y&&y.unregister(e)}(i),b(e),t.clear(),s=!0};if("then"===r){if(0===n.length)return{then:()=>i};const o=D(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then($);return o.then.bind(o)}return E(e,t,[...n,r])},set(o,i,r){p(s);const[a,l]=M(r);return D(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:a},l).then($)},apply(o,i,a){p(s);const l=n[n.length-1];if(l===r)return D(e,t,{type:"ENDPOINT"}).then($);if("bind"===l)return E(e,t,n.slice(0,-1));const[d,c]=v(a);return D(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:d},c).then($)},construct(o,i){p(s);const[r,a]=v(i);return D(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},a).then($)}});return function(e,t){const n=(g.get(t)||0)+1;g.set(t,n),y&&y.register(e,t,e)}(i,e),i}function v(e){const t=e.map(M);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const C=new WeakMap;function M(e){for(const[t,n]of u)if(n.canHandle(e)){const[o,s]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},s]}return[{type:"RAW",value:e},C.get(e)||[]]}function $(e){switch(e.type){case"HANDLER":return u.get(e.name).deserialize(e.value);case"RAW":return e.value}}function D(e,t,n,o){return new Promise((s=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,s),e.start&&e.start(),e.postMessage(Object.assign({id:i},n),o)}))}function F(e,t,i,r={}){const{maxIterations:a=1e4,tolerance:l=1e-4}=r;let d=[],c=!0,u=0;if(o(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),n=math.slu(e,1,1);let o=math.lusolve(n,i);d=math.squeeze(o).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:s,tolerance:i}=o,r=e.length;let a=[...n],l=new Array(r);for(let n=0;n{}))),m.worker.terminate()),{solutionVector:p,converged:b,iterations:u}}class A{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null){let n=[],o=[],i=[];if("1D"===this.meshDimension)"linear"===this.elementOrder?(n[0]=1-e,n[1]=e,o[0]=-1,o[1]=1):"quadratic"===this.elementOrder&&(n[0]=1-3*e+2*e**2,n[1]=4*e-4*e**2,n[2]=2*e**2-e,o[0]=4*e-3,o[1]=4-8*e,o[2]=4*e-1);else if("2D"===this.meshDimension){if(null===t)return void s("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function r(e){return 1-e}n[0]=r(e)*r(t),n[1]=r(e)*t,n[2]=e*r(t),n[3]=e*t,o[0]=-1*r(t),o[1]=-1*t,o[2]=1*r(t),o[3]=1*t,i[0]=-1*r(e),i[1]=1*r(e),i[2]=-1*e,i[3]=1*e}else if("quadratic"===this.elementOrder){function a(e){return 2*e**2-3*e+1}function l(e){return-4*e**2+4*e}function d(e){return 2*e**2-e}function c(e){return 4*e-3}function u(e){return-8*e+4}function m(e){return 4*e-1}n[0]=a(e)*a(t),n[1]=a(e)*l(t),n[2]=a(e)*d(t),n[3]=l(e)*a(t),n[4]=l(e)*l(t),n[5]=l(e)*d(t),n[6]=d(e)*a(t),n[7]=d(e)*l(t),n[8]=d(e)*d(t),o[0]=c(e)*a(t),o[1]=c(e)*l(t),o[2]=c(e)*d(t),o[3]=u(e)*a(t),o[4]=u(e)*l(t),o[5]=u(e)*d(t),o[6]=m(e)*a(t),o[7]=m(e)*l(t),o[8]=m(e)*d(t),i[0]=a(e)*c(t),i[1]=a(e)*u(t),i[2]=a(e)*m(t),i[3]=l(e)*c(t),i[4]=l(e)*u(t),i[5]=l(e)*m(t),i[6]=d(e)*c(t),i[7]=d(e)*u(t),i[8]=d(e)*m(t)}}return{basisFunction:n,basisFunctionDerivKsi:o,basisFunctionDerivEta:i}}}class w{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:s=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:a=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=s,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=a,this.boundaryElementsProcessed=!1,this.parsedMesh&&(o("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||s("No valid nodal numbering found in the parsed mesh."),"object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,n("Initial parsed mesh nodal numbering from GMSH format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.elementTypes[3]||this.parsedMesh.elementTypes[10]){const t=[];for(let n=0;n0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t{if(1===e.dimension){const t=this.parsedMesh.boundaryNodePairs[e.tag]||[];t.length>0&&(this.parsedMesh.boundaryElements[e.tag]||(this.parsedMesh.boundaryElements[e.tag]=[]),t.forEach((t=>{const o=t[0],i=t[1];n(`Processing boundary node pair: [${o}, ${i}] for boundary ${e.tag} (${e.name||"unnamed"})`);let r=!1;for(let t=0;t0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((o=>{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}imposeConvectionBoundaryConditions(e,t,o,s,i,r,a){let l=[],d=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(l[e]=t[1],d[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((o=>{if("convection"===this.boundaryConditions[o][0]){const s=l[o],i=d[o];n(`Boundary ${o}: Applying convection with heat transfer coefficient h=${s} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[o].forEach((([o,r])=>{let a;"linear"===this.elementOrder?a=0===r?0:1:"quadratic"===this.elementOrder&&(a=0===r?0:2);const l=this.nop[o][a]-1;n(` - Applied convection boundary condition to node ${l+1} (element ${o+1}, local node ${a+1})`),e[l]+=-s*i,t[l][l]+=s}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const u=l[c],m=d[c];n(`Boundary ${c}: Applying convection with heat transfer coefficient h=${u} W/(m²·K) and external temperature T∞=${m} K`),this.boundaryElements[c].forEach((([l,d])=>{if("linear"===this.elementOrder){let c,h,f,p,b;0===d?(c=o[0],h=0,f=0,p=3,b=2):1===d?(c=0,h=o[0],f=0,p=2,b=1):2===d?(c=o[0],h=1,f=1,p=4,b=2):3===d&&(c=1,h=o[0],f=2,p=4,b=1);let g=a.getBasisFunctions(c,h),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta,C=0,M=0,$=0,D=0;const F=this.nop[l].length;for(let e=0;e{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])}));const d=this.nop[e].length,c=Array(d).fill().map((()=>Array(d).fill(0))),u=Array(d).fill(0);for(const m in this.boundaryElements)if("convection"===this.boundaryConditions[m]?.[0]){const h=a[m],f=l[m];n(`Boundary ${m}: Applying convection with heat transfer coefficient h=${h} W/(m²·K) and external temperature T∞=${f} K`);const p=this.boundaryElements[m].find((([t,n])=>t===e));if(p){const a=p[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===a?0:1:"quadratic"===this.elementOrder&&(t=0===a?0:2),n(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),u[t]+=-h*f,c[t][t]+=h}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let n,l,m,p,b;0===a?(n=s[0],l=0,m=0,p=3,b=2):1===a?(n=0,l=s[0],m=0,p=2,b=1):2===a?(n=s[0],l=1,m=1,p=4,b=2):3===a&&(n=1,l=s[0],m=2,p=4,b=1);const g=r.getBasisFunctions(n,l),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta;let C,M=0,$=0,D=0,F=0;for(let n=0;nArray(a).fill(0))),m=Array(a).fill(0),h=Array(a),f=Array(a);for(let n=0;ne-1)),{detJacobian:f,basisFunctionDerivX:p,basisFunctionDerivY:b}=T({basisFunction:n,basisFunctionDerivKsi:s,basisFunctionDerivEta:c,nodesXCoordinates:l,nodesYCoordinates:d,localToGlobalMap:m,numNodes:a});for(let n=0;n{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((o=>{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}}function B(e,t,s,i){o("Starting front propagation matrix assembly...");let r=1-i+.01;n(`eikonalViscousTerm: ${r}`),n(`eikonalActivationFlag: ${i}`);const{nodesXCoordinates:a,nodesYCoordinates:l,nop:d,boundaryElements:c,totalElements:u,meshDimension:m,elementOrder:h}=e,f=V(e),{residualVector:p,jacobianMatrix:b,localToGlobalMap:g,basisFunctions:y,gaussPoints:E,gaussWeights:v,numNodes:C}=f;for(let e=0;eArray(d).fill(0))),p=Array(d).fill(0),b=Array(d),g=Array(d);for(let n=0;nArray(e).fill(0))),q.nodeConstraintCode=Array(e).fill(0),q.boundaryValues=Array(e).fill(0),q.globalResidualVector=Array(e).fill(0),q.solutionVector=Array(e).fill(0),q.topologyData=Array(t).fill(0),q.lateralData=Array(t).fill(0),W.writeFlag=0,W.totalNodes=e,W.transformationFlag=0,W.nodesPerElement=Array(t).fill(0),W.determinant=1;const n=Math.max(e,2e3);W.globalSolutionVector=Array(n).fill(0),W.frontDataIndex=0,G.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),G.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);K.frontValues=Array(o).fill(0),K.columnHeaders=Array(n).fill(0),K.pivotRow=Array(n).fill(0),K.pivotData=Array(o).fill(0)}(a.numNodes,d),o("Solving system using frontal..."),console.time("systemSolving"),J=new A({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;eArray(l).fill(0))),y=Array(a).fill(0),E=Array(a).fill(0),v=Array(a).fill(0),C=1;W.writeFlag++;let M=1,$=1;G.currentElementIndex=0;for(let e=0;el||D>l)return void s("Error: systemSize not large enough");for(let e=0;e0)for(let e=0;e$||G.currentElementIndexMath.abs(o)&&(o=r,t=s,e=i)}}}let i=Math.abs(m[e-1]);d=Math.abs(K.columnHeaders[t-1]);let a=i+d+y[i-1]+E[d-1];W.determinant=W.determinant*o*(-1)**a/Math.abs(o);for(let e=0;e=i&&y[e]--,e>=d&&E[e]--;if(Math.abs(o)<1e-10&&s(`Matrix singular or ill-conditioned, currentElementIndex=${G.currentElementIndex}, pivotGlobalRowIndex=${i}, pivotColumnGlobalIndex=${d}, pivotValue=${o}`),0===o)return;for(let t=0;t1)for(let n=0;n1&&0!==o)for(let e=0;e1)for(let e=0;e1||G.currentElementIndex=e.totalElements)return s(`Skipping out-of-range elementIndex=${i} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:a,ngl:l}=o({elementIndex:i,nop:q.nodalNumbering,meshData:e,basisFunctions:J,FEAData:t,solutionVector:W.currentSolutionVector,eikonalActivationFlag:W.eikonalActivationFlag});let d=Array(t.numNodes).fill().map((()=>Array(t.numNodes).fill(0))),c=Array(t.numNodes).fill(0);if(o===P){let o=!1;for(const t in e.boundaryElements)if("convection"===n.boundaryConditions[t]?.[0]&&e.boundaryElements[t].some((([e,t])=>e===i))){o=!0;break}if(o){const{gaussPoints:o,gaussWeights:s}=t,r=n.imposeConvectionBoundaryConditionsFront(i,e.nodesXCoordinates,e.nodesYCoordinates,o,s,J);d=r.localJacobianMatrix,c=r.localResidualVector}}for(let e=0;e0)continue;let r=0;K.pivotRow[s-1]=0;for(let e=0;e100){s(`Solution not converged. Error norm: ${i}`);break}a++}return{solutionVector:d,converged:r,iterations:a,jacobianMatrix:c,residualVector:u}}exports.FEAScriptModel=class{constructor(){var e;this.solverConfig=null,this.meshConfig={},this.boundaryConditions={},this.solverMethod="lusolve",this.coefficientFunctions=null,e="FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE",console.log("%c[WARN] "+e,"color: #FF9800; font-weight: bold;"),o("FEAScriptModel instance created")}setSolverConfig(e,t={}){this.solverConfig=e,t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,n("Coefficient functions set")),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations),void 0!==t?.tolerance&&(this.tolerance=t.tolerance),n(`Solver config set to: ${e}`)}setMeshConfig(e){this.meshConfig=e,n(`Mesh config set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,n(`Boundary condition added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,n(`Solver method set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||s("Solver config, mesh config, and boundary conditions must be set before solving.");let t=[],n=[],i=[],r=[];o("Preparing mesh...");const a=X(this.meshConfig);o("Mesh preparation completed");const l={nodesXCoordinates:a.nodesXCoordinates,nodesYCoordinates:a.nodesYCoordinates};if(o("Beginning solving process..."),console.time("totalSolvingTime"),o(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){i=H(P,a,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=R(a,this.boundaryConditions));i=F(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let o=0;const s=5,l={meshData:a,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:o,solverMethod:this.solverMethod,initialSolution:r,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;o<=1;){l.eikonalActivationFlag=o,i.length>0&&(l.initialSolution=[...i]);const e=z(B,l);t=e.jacobianMatrix,n=e.residualVector,i=e.solutionVector,o+=1/s}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)s("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){o("Starting general form PDE matrix assembly...");const{nodesXCoordinates:i,nodesYCoordinates:r,nop:a,boundaryElements:l,totalElements:d,meshDimension:c,elementOrder:u}=e,{A:m,B:h,C:f,D:p}=n,b=V(e),{residualVector:g,jacobianMatrix:y,localToGlobalMap:E,basisFunctions:v,gaussPoints:C,gaussWeights:M,numNodes:$}=b;if("1D"===c)for(let e=0;e{console.error("FEAScriptWorker: Worker error:",e)};const e=f(this.worker);this.feaWorker=await new e,this.isReady=!0}catch(e){throw console.error("Failed to initialize worker",e),e}}async _ensureReady(){return this.isReady?Promise.resolve():new Promise(((e,t)=>{let n=0;const o=()=>{n++,this.isReady?e():n>=50?t(new Error("Timeout waiting for worker to be ready")):setTimeout(o,1e3)};o()}))}async setSolverConfig(e){return await this._ensureReady(),o(`FEAScriptWorker: Setting solver config to: ${e}`),this.feaWorker.setSolverConfig(e)}async setMeshConfig(e){return await this._ensureReady(),o("FEAScriptWorker: Setting mesh config"),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),o(`FEAScriptWorker: Adding boundary condition for boundary: ${e}`),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),o(`FEAScriptWorker: Setting solver method to: ${e}`),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),o("FEAScriptWorker: Requesting solution from worker...");const e=performance.now(),t=await this.feaWorker.solve();return o(`FEAScriptWorker: Solution completed in ${((performance.now()-e)/1e3).toFixed(2)}s`),t}async getModelInfo(){return await this._ensureReady(),this.feaWorker.getModelInfo()}async ping(){return await this._ensureReady(),this.feaWorker.ping()}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.feaWorker=null,this.isReady=!1)}},exports.importGmshQuadTri=async e=>{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}},o=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e&&" "!==e)),s="",i=0,r=0,a=0,l=0,d={numNodes:0},c=0,u=[],m=0,h=0,f=0,p={dim:0,tag:0,elementType:0,numElements:0},b=0,g={};for(;i""!==e));if("meshFormat"===s)t.gmshV=parseFloat(n[0]),t.ascii="0"===n[1],t.fltBytes=n[2];else if("physicalNames"===s){if(n.length>=3){if(!/^\d+$/.test(n[0])){i++;continue}const e=parseInt(n[0],10),o=parseInt(n[1],10);let s=n.slice(2).join(" ");s=s.replace(/^"|"$/g,""),t.physicalPropMap.push({tag:o,dimension:e,name:s})}}else if("nodes"===s){if(0===r){r=parseInt(n[0],10),a=parseInt(n[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0),i++;continue}if(lparseInt(e,10)));if(1===p.elementType||8===p.elementType){const n=p.tag;g[n]||(g[n]=[]),g[n].push(e),t.boundaryNodePairs[n]||(t.boundaryNodePairs[n]=[]),t.boundaryNodePairs[n].push(e)}else 2===p.elementType?t.nodalNumbering.triangleElements.push(e):(3===p.elementType||10===p.elementType)&&t.nodalNumbering.quadElements.push(e);b++,b===p.numElements&&(f++,p={numElements:0})}}i++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=g[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),n(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}. These pairs will be used to identify boundary elements in the mesh.`),t},exports.logSystem=function(e){"basic"!==e&&"debug"!==e?(console.log("%c[WARN] Invalid log level: "+e+". Using basic instead.","color: #FFC107; font-weight: bold;"),t="basic"):(t=e,o(`Log level set to: ${e}`))},exports.plotSolution=function(e,t,n,o,s,i,r="structured"){const{nodesXCoordinates:a,nodesYCoordinates:l}=t;if("1D"===o&&"line"===s){let t;t=e.length>0&&Array.isArray(e[0])?e.map((e=>e[0])):e;let o=Array.from(a),s={x:o,y:t,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},r=Math.min(window.innerWidth,700),l=Math.max(...o),d=r/l,c={title:`line plot - ${n}`,width:Math.max(d*l,400),height:350,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:70,r:40,t:50,b:50}};Plotly.newPlot(i,[s],c,{responsive:!0})}else if("2D"===o&&"contour"===s){const t="structured"===r,o=new Set(a).size,d=new Set(l).size;let c;c=Array.isArray(e[0])?e.map((e=>e[0])):e;let u=Math.min(window.innerWidth,700),m=Math.max(...a),h=Math.max(...l)/m,f=Math.min(u,600),p={title:`${s} plot - ${n}`,width:f,height:f*h*.8,xaxis:{title:"x"},yaxis:{title:"y"},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"};if(t){const t=o,n=d;math.reshape(Array.from(a),[t,n]);let s=math.reshape(Array.from(l),[t,n]),r=math.reshape(Array.from(e),[t,n]),c=math.transpose(r),u=[];for(let e=0;e"object"==typeof e&&null!==e||"function"==typeof e,u=new Map([["proxy",{canHandle:e=>c(e)&&e[i],serialize(e){const{port1:t,port2:n}=new MessageChannel;return m(e,t),[n,[n]]},deserialize:e=>(e.start(),f(e))}],["throw",{canHandle:e=>c(e)&&d in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function m(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(s){if(!s||!s.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,s.origin))return void console.warn(`Invalid origin '${s.origin}' for comlink proxy`);const{id:r,type:a,path:c}=Object.assign({path:[]},s.data),u=(s.data.argumentList||[]).map($);let f;try{const t=c.slice(0,-1).reduce(((e,t)=>e[t]),e),n=c.reduce(((e,t)=>e[t]),e);switch(a){case"GET":f=n;break;case"SET":t[c.slice(-1)[0]]=$(s.data.value),f=!0;break;case"APPLY":f=n.apply(t,u);break;case"CONSTRUCT":f=function(e){return Object.assign(e,{[i]:!0})}(new n(...u));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;m(e,n),f=function(e,t){return C.set(e,t),e}(t,[t])}break;case"RELEASE":f=void 0;break;default:return}}catch(e){f={value:e,[d]:0}}Promise.resolve(f).catch((e=>({value:e,[d]:0}))).then((n=>{const[s,i]=M(n);t.postMessage(Object.assign(Object.assign({},s),{id:r}),i),"RELEASE"===a&&(t.removeEventListener("message",o),h(t),l in e&&"function"==typeof e[l]&&e[l]())})).catch((e=>{const[n,o]=M({value:new TypeError("Unserializable return value"),[d]:0});t.postMessage(Object.assign(Object.assign({},n),{id:r}),o)}))})),t.start&&t.start()}function h(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function f(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),E(e,n,[],t)}function p(e){if(e)throw new Error("Proxy has been released and is not useable")}function b(e){return D(e,new Map,{type:"RELEASE"}).then((()=>{h(e)}))}const g=new WeakMap,y="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(g.get(e)||0)-1;g.set(e,t),0===t&&b(e)}));function E(e,t,n=[],o=function(){}){let s=!1;const i=new Proxy(o,{get(o,r){if(p(s),r===a)return()=>{!function(e){y&&y.unregister(e)}(i),b(e),t.clear(),s=!0};if("then"===r){if(0===n.length)return{then:()=>i};const o=D(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then($);return o.then.bind(o)}return E(e,t,[...n,r])},set(o,i,r){p(s);const[a,l]=M(r);return D(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:a},l).then($)},apply(o,i,a){p(s);const l=n[n.length-1];if(l===r)return D(e,t,{type:"ENDPOINT"}).then($);if("bind"===l)return E(e,t,n.slice(0,-1));const[d,c]=v(a);return D(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:d},c).then($)},construct(o,i){p(s);const[r,a]=v(i);return D(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},a).then($)}});return function(e,t){const n=(g.get(t)||0)+1;g.set(t,n),y&&y.register(e,t,e)}(i,e),i}function v(e){const t=e.map(M);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const C=new WeakMap;function M(e){for(const[t,n]of u)if(n.canHandle(e)){const[o,s]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},s]}return[{type:"RAW",value:e},C.get(e)||[]]}function $(e){switch(e.type){case"HANDLER":return u.get(e.name).deserialize(e.value);case"RAW":return e.value}}function D(e,t,n,o){return new Promise((s=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,s),e.start&&e.start(),e.postMessage(Object.assign({id:i},n),o)}))}function F(e,t,i,r={}){const{maxIterations:a=1e4,tolerance:l=1e-4}=r;let d=[],c=!0,u=0;if(o(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),n=math.slu(e,1,1);let o=math.lusolve(n,i);d=math.squeeze(o).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:s,tolerance:i}=o,r=e.length;let a=[...n],l=new Array(r);for(let n=0;n{}))),m.worker.terminate()),{solutionVector:p,converged:b,iterations:u}}class A{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null){let n=[],o=[],i=[];if("1D"===this.meshDimension)"linear"===this.elementOrder?(n[0]=1-e,n[1]=e,o[0]=-1,o[1]=1):"quadratic"===this.elementOrder&&(n[0]=1-3*e+2*e**2,n[1]=4*e-4*e**2,n[2]=2*e**2-e,o[0]=4*e-3,o[1]=4-8*e,o[2]=4*e-1);else if("2D"===this.meshDimension){if(null===t)return void s("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function r(e){return 1-e}n[0]=r(e)*r(t),n[1]=r(e)*t,n[2]=e*r(t),n[3]=e*t,o[0]=-1*r(t),o[1]=-1*t,o[2]=1*r(t),o[3]=1*t,i[0]=-1*r(e),i[1]=1*r(e),i[2]=-1*e,i[3]=1*e}else if("quadratic"===this.elementOrder){function a(e){return 2*e**2-3*e+1}function l(e){return-4*e**2+4*e}function d(e){return 2*e**2-e}function c(e){return 4*e-3}function u(e){return-8*e+4}function m(e){return 4*e-1}n[0]=a(e)*a(t),n[1]=a(e)*l(t),n[2]=a(e)*d(t),n[3]=l(e)*a(t),n[4]=l(e)*l(t),n[5]=l(e)*d(t),n[6]=d(e)*a(t),n[7]=d(e)*l(t),n[8]=d(e)*d(t),o[0]=c(e)*a(t),o[1]=c(e)*l(t),o[2]=c(e)*d(t),o[3]=u(e)*a(t),o[4]=u(e)*l(t),o[5]=u(e)*d(t),o[6]=m(e)*a(t),o[7]=m(e)*l(t),o[8]=m(e)*d(t),i[0]=a(e)*c(t),i[1]=a(e)*u(t),i[2]=a(e)*m(t),i[3]=l(e)*c(t),i[4]=l(e)*u(t),i[5]=l(e)*m(t),i[6]=d(e)*c(t),i[7]=d(e)*u(t),i[8]=d(e)*m(t)}}return{basisFunction:n,basisFunctionDerivKsi:o,basisFunctionDerivEta:i}}}class w{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:s=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:a=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=s,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=a,this.boundaryElementsProcessed=!1,this.parsedMesh&&(o("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||s("No valid nodal numbering found in the parsed mesh."),"object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,n("Initial parsed mesh nodal numbering from GMSH format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.elementTypes[3]||this.parsedMesh.elementTypes[10]){const t=[];for(let n=0;n0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t{if(1===e.dimension){const t=this.parsedMesh.boundaryNodePairs[e.tag]||[];t.length>0&&(this.parsedMesh.boundaryElements[e.tag]||(this.parsedMesh.boundaryElements[e.tag]=[]),t.forEach((t=>{const o=t[0],i=t[1];n(`Processing boundary node pair: [${o}, ${i}] for boundary ${e.tag} (${e.name||"unnamed"})`);let r=!1;for(let t=0;t0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((o=>{if("constantTemp"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant temperature to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}imposeConvectionBoundaryConditions(e,t,o,s,i,r,a){let l=[],d=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(l[e]=t[1],d[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((o=>{if("convection"===this.boundaryConditions[o][0]){const s=l[o],i=d[o];n(`Boundary ${o}: Applying convection with heat transfer coefficient h=${s} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[o].forEach((([o,r])=>{let a;"linear"===this.elementOrder?a=0===r?0:1:"quadratic"===this.elementOrder&&(a=0===r?0:2);const l=this.nop[o][a]-1;n(` - Applied convection boundary condition to node ${l+1} (element ${o+1}, local node ${a+1})`),e[l]+=-s*i,t[l][l]+=s}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const u=l[c],m=d[c];n(`Boundary ${c}: Applying convection with heat transfer coefficient h=${u} W/(m²·K) and external temperature T∞=${m} K`),this.boundaryElements[c].forEach((([l,d])=>{if("linear"===this.elementOrder){let c,h,f,p,b;0===d?(c=o[0],h=0,f=0,p=3,b=2):1===d?(c=0,h=o[0],f=0,p=2,b=1):2===d?(c=o[0],h=1,f=1,p=4,b=2):3===d&&(c=1,h=o[0],f=2,p=4,b=1);let g=a.getBasisFunctions(c,h),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta,C=0,M=0,$=0,D=0;const F=this.nop[l].length;for(let e=0;e{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])}));const d=this.nop[e].length,c=Array(d).fill().map((()=>Array(d).fill(0))),u=Array(d).fill(0);for(const m in this.boundaryElements)if("convection"===this.boundaryConditions[m]?.[0]){const h=a[m],f=l[m];n(`Boundary ${m}: Applying convection with heat transfer coefficient h=${h} W/(m²·K) and external temperature T∞=${f} K`);const p=this.boundaryElements[m].find((([t,n])=>t===e));if(p){const a=p[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===a?0:1:"quadratic"===this.elementOrder&&(t=0===a?0:2),n(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),u[t]+=-h*f,c[t][t]+=h}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let n,l,m,p,b;0===a?(n=s[0],l=0,m=0,p=3,b=2):1===a?(n=0,l=s[0],m=0,p=2,b=1):2===a?(n=s[0],l=1,m=1,p=4,b=2):3===a&&(n=1,l=s[0],m=2,p=4,b=1);const g=r.getBasisFunctions(n,l),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta;let C,M=0,$=0,D=0,F=0;for(let n=0;nArray(a).fill(0))),m=Array(a).fill(0),h=Array(a),f=Array(a);for(let n=0;ne-1)),{detJacobian:f,basisFunctionDerivX:p,basisFunctionDerivY:b}=T({basisFunction:n,basisFunctionDerivKsi:s,basisFunctionDerivEta:c,nodesXCoordinates:l,nodesYCoordinates:d,localToGlobalMap:m,numNodes:a});for(let n=0;n{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((o=>{if("constantValue"===this.boundaryConditions[o][0]){const s=this.boundaryConditions[o][1];n(`Boundary ${o}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[o][i]-1;n(` - Applied constant value to node ${r+1} (element ${o+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}}function B(e,t,s,i){o("Starting front propagation matrix assembly...");let r=1-i+.01;n(`eikonalViscousTerm: ${r}`),n(`eikonalActivationFlag: ${i}`);const{nodesXCoordinates:a,nodesYCoordinates:l,nop:d,boundaryElements:c,totalElements:u,meshDimension:m,elementOrder:h}=e,f=V(e),{residualVector:p,jacobianMatrix:b,localToGlobalMap:g,basisFunctions:y,gaussPoints:E,gaussWeights:v,numNodes:C}=f;for(let e=0;eArray(d).fill(0))),p=Array(d).fill(0),b=Array(d),g=Array(d);for(let n=0;nArray(e).fill(0))),q.nodeConstraintCode=Array(e).fill(0),q.boundaryValues=Array(e).fill(0),q.globalResidualVector=Array(e).fill(0),q.solutionVector=Array(e).fill(0),q.topologyData=Array(t).fill(0),q.lateralData=Array(t).fill(0),W.writeFlag=0,W.totalNodes=e,W.transformationFlag=0,W.nodesPerElement=Array(t).fill(0),W.determinant=1;const n=Math.max(e,2e3);W.globalSolutionVector=Array(n).fill(0),W.frontDataIndex=0,G.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),G.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);K.frontValues=Array(o).fill(0),K.columnHeaders=Array(n).fill(0),K.pivotRow=Array(n).fill(0),K.pivotData=Array(o).fill(0)}(a.numNodes,d),o("Solving system using frontal..."),console.time("systemSolving"),J=new A({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;eArray(l).fill(0))),y=Array(a).fill(0),E=Array(a).fill(0),v=Array(a).fill(0),C=1;W.writeFlag++;let M=1,$=1;G.currentElementIndex=0;for(let e=0;el||D>l)return void s("Error: systemSize not large enough");for(let e=0;e0)for(let e=0;e$||G.currentElementIndexMath.abs(o)&&(o=r,t=s,e=i)}}}let i=Math.abs(m[e-1]);d=Math.abs(K.columnHeaders[t-1]);let a=i+d+y[i-1]+E[d-1];W.determinant=W.determinant*o*(-1)**a/Math.abs(o);for(let e=0;e=i&&y[e]--,e>=d&&E[e]--;if(Math.abs(o)<1e-10&&s(`Matrix singular or ill-conditioned, currentElementIndex=${G.currentElementIndex}, pivotGlobalRowIndex=${i}, pivotColumnGlobalIndex=${d}, pivotValue=${o}`),0===o)return;for(let t=0;t1)for(let n=0;n1&&0!==o)for(let e=0;e1)for(let e=0;e1||G.currentElementIndex=e.totalElements)return s(`Skipping out-of-range elementIndex=${i} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:a,ngl:l}=o({elementIndex:i,nop:q.nodalNumbering,meshData:e,basisFunctions:J,FEAData:t,solutionVector:W.currentSolutionVector,eikonalActivationFlag:W.eikonalActivationFlag});let d=Array(t.numNodes).fill().map((()=>Array(t.numNodes).fill(0))),c=Array(t.numNodes).fill(0);if(o===P){let o=!1;for(const t in e.boundaryElements)if("convection"===n.boundaryConditions[t]?.[0]&&e.boundaryElements[t].some((([e,t])=>e===i))){o=!0;break}if(o){const{gaussPoints:o,gaussWeights:s}=t,r=n.imposeConvectionBoundaryConditionsFront(i,e.nodesXCoordinates,e.nodesYCoordinates,o,s,J);d=r.localJacobianMatrix,c=r.localResidualVector}}for(let e=0;e0)continue;let r=0;K.pivotRow[s-1]=0;for(let e=0;e100){s(`Solution not converged. Error norm: ${i}`);break}a++}return{solutionVector:d,converged:r,iterations:a,jacobianMatrix:c,residualVector:u}}exports.FEAScriptModel=class{constructor(){var e;this.solverConfig=null,this.meshConfig={},this.boundaryConditions={},this.solverMethod="lusolve",this.coefficientFunctions=null,e="FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE",console.log("%c[WARN] "+e,"color: #FF9800; font-weight: bold;"),o("FEAScriptModel instance created")}setSolverConfig(e,t={}){this.solverConfig=e,t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,n("Coefficient functions set")),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations),void 0!==t?.tolerance&&(this.tolerance=t.tolerance),n(`Solver config set to: ${e}`)}setMeshConfig(e){this.meshConfig=e,n(`Mesh config set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,n(`Boundary condition added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,n(`Solver method set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||s("Solver config, mesh config, and boundary conditions must be set before solving.");let t=[],n=[],i=[],r=[];o("Preparing mesh...");const a=X(this.meshConfig);o("Mesh preparation completed");const l={nodesXCoordinates:a.nodesXCoordinates,nodesYCoordinates:a.nodesYCoordinates};if(o("Beginning solving process..."),console.time("totalSolvingTime"),o(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){i=H(P,a,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=R(a,this.boundaryConditions));i=F(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let o=0;const s=5,l={meshData:a,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:o,solverMethod:this.solverMethod,initialSolution:r,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;o<=1;){l.eikonalActivationFlag=o,i.length>0&&(l.initialSolution=[...i]);const e=_(B,l);t=e.jacobianMatrix,n=e.residualVector,i=e.solutionVector,o+=1/s}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)s("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){o("Starting general form PDE matrix assembly...");const{nodesXCoordinates:i,nodesYCoordinates:r,nop:a,boundaryElements:l,totalElements:d,meshDimension:c,elementOrder:u}=e,{A:m,B:h,C:f,D:p}=n,b=V(e),{residualVector:g,jacobianMatrix:y,localToGlobalMap:E,basisFunctions:v,gaussPoints:C,gaussWeights:M,numNodes:$}=b;if("1D"===c)for(let e=0;e{console.error("FEAScriptWorker: Worker error:",e)};const e=f(this.worker);this.feaWorker=await new e,this.isReady=!0}catch(e){throw console.error("Failed to initialize worker",e),e}}async _ensureReady(){return this.isReady?Promise.resolve():new Promise(((e,t)=>{let n=0;const o=()=>{n++,this.isReady?e():n>=50?t(new Error("Timeout waiting for worker to be ready")):setTimeout(o,1e3)};o()}))}async setSolverConfig(e){return await this._ensureReady(),o(`FEAScriptWorker: Setting solver config to: ${e}`),this.feaWorker.setSolverConfig(e)}async setMeshConfig(e){return await this._ensureReady(),o("FEAScriptWorker: Setting mesh config"),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),o(`FEAScriptWorker: Adding boundary condition for boundary: ${e}`),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),o(`FEAScriptWorker: Setting solver method to: ${e}`),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),o("FEAScriptWorker: Requesting solution from worker...");const e=performance.now(),t=await this.feaWorker.solve();return o(`FEAScriptWorker: Solution completed in ${((performance.now()-e)/1e3).toFixed(2)}s`),t}async getModelInfo(){return await this._ensureReady(),this.feaWorker.getModelInfo()}async ping(){return await this._ensureReady(),this.feaWorker.ping()}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.feaWorker=null,this.isReady=!1)}},exports.importGmshQuadTri=async e=>{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}},o=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e&&" "!==e)),s="",i=0,r=0,a=0,l=0,d={numNodes:0},c=0,u=[],m=0,h=0,f=0,p={dim:0,tag:0,elementType:0,numElements:0},b=0,g={};for(;i""!==e));if("meshFormat"===s)t.gmshV=parseFloat(n[0]),t.ascii="0"===n[1],t.fltBytes=n[2];else if("physicalNames"===s){if(n.length>=3){if(!/^\d+$/.test(n[0])){i++;continue}const e=parseInt(n[0],10),o=parseInt(n[1],10);let s=n.slice(2).join(" ");s=s.replace(/^"|"$/g,""),t.physicalPropMap.push({tag:o,dimension:e,name:s})}}else if("nodes"===s){if(0===r){r=parseInt(n[0],10),a=parseInt(n[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0),i++;continue}if(lparseInt(e,10)));if(1===p.elementType||8===p.elementType){const n=p.tag;g[n]||(g[n]=[]),g[n].push(e),t.boundaryNodePairs[n]||(t.boundaryNodePairs[n]=[]),t.boundaryNodePairs[n].push(e)}else 2===p.elementType?t.nodalNumbering.triangleElements.push(e):(3===p.elementType||10===p.elementType)&&t.nodalNumbering.quadElements.push(e);b++,b===p.numElements&&(f++,p={numElements:0})}}i++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=g[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),n(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}. These pairs will be used to identify boundary elements in the mesh.`),t},exports.logSystem=function(e){"basic"!==e&&"debug"!==e?(console.log("%c[WARN] Invalid log level: "+e+". Using basic instead.","color: #FFC107; font-weight: bold;"),t="basic"):(t=e,o(`Log level set to: ${e}`))},exports.plotSolution=function(e,t,n,o,s,i){const{nodesXCoordinates:r,nodesYCoordinates:a}=t;if("1D"===o&&"line"===s){let t;t=e.length>0&&Array.isArray(e[0])?e.map((e=>e[0])):e,Array.from(r);let o={x:r,y:t,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},s=Math.min(window.innerWidth,700),a={title:`line plot - ${n}`,width:Math.min(s,600),height:350,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:50,r:50,t:50,b:50}};Plotly.newPlot(i,[o],a,{responsive:!0})}else if("2D"===o&&"contour"===s){let t;t=Array.isArray(e[0])?e.map((e=>e[0])):e;let o=Math.min(window.innerWidth,700),l=Math.max(...r),d=Math.max(...a)/l,c=Math.min(o,600),u={title:`${s} plot - ${n}`,width:c,height:c*d,xaxis:{title:"x"},yaxis:{title:"y"},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"},m={x:r,y:a,z:t,type:"contour",line:{smoothing:.85},contours:{coloring:"heatmap",showlabels:!1},colorbar:{title:"Solution"},name:"Solution Field"};Plotly.newPlot(i,[m],u,{responsive:!0})}},exports.printVersion="0.1.4"; //# sourceMappingURL=feascript.cjs.js.map diff --git a/dist/feascript.cjs.js.map b/dist/feascript.cjs.js.map index a42c554..43859eb 100644 --- a/dist/feascript.cjs.js.map +++ b/dist/feascript.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"feascript.cjs.js","sources":["../src/methods/euclideanNormScript.js","../src/utilities/loggingScript.js","../src/vendor/comlink.mjs","../src/methods/linearSystemSolverScript.js","../src/methods/jacobiSolverScript.js","../src/mesh/basisFunctionsScript.js","../src/mesh/meshGenerationScript.js","../src/methods/numericalIntegrationScript.js","../src/mesh/meshUtilsScript.js","../src/models/thermalBoundaryConditionsScript.js","../src/models/heatConductionScript.js","../src/models/genericBoundaryConditionsScript.js","../src/models/frontPropagationScript.js","../src/methods/frontalSolverScript.js","../src/methods/newtonRaphsonScript.js","../src/FEAScript.js","../src/models/generalFormPDEScript.js","../src/workers/workerScript.js","../src/readers/gmshReaderScript.js","../src/visualization/plotSolutionScript.js","../src/index.js"],"sourcesContent":["/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to calculate the Euclidean norm of a vector\n * @param {array} vector - The input vector\n * @returns {number} The Euclidean norm of the vector\n */\nexport function euclideanNorm(vector) {\n let norm = 0;\n for (let i = 0; i < vector.length; i++) {\n norm += vector[i] * vector[i];\n }\n norm = Math.sqrt(norm);\n return norm;\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Global logging level\nlet currentLogLevel = \"basic\";\n\n/**\n * Function to set the logging system level\n * @param {string} level - Logging level (basic, debug)\n */\nexport function logSystem(level) {\n if (level !== \"basic\" && level !== \"debug\") {\n console.log(\n \"%c[WARN] Invalid log level: \" + level + \". Using basic instead.\",\n \"color: #FFC107; font-weight: bold;\"\n ); // Yellow for warnings\n currentLogLevel = \"basic\";\n } else {\n currentLogLevel = level;\n basicLog(`Log level set to: ${level}`);\n }\n}\n\n/**\n * Function to log debug messages - only logs if level is 'debug'\n * @param {string} message - Message to log\n */\nexport function debugLog(message) {\n if (currentLogLevel === \"debug\") {\n console.log(\"%c[DEBUG] \" + message, \"color: #2196F3; font-weight: bold;\");\n }\n}\n\n/**\n * Function to log basic information - always logs\n * @param {string} message - Message to log\n */\nexport function basicLog(message) {\n console.log(\"%c[INFO] \" + message, \"color: #4CAF50; font-weight: bold;\");\n}\n\n/**\n * Function to log error messages\n * @param {string} message - Message to log\n */\nexport function errorLog(message) {\n console.log(\"%c[ERROR] \" + message, \"color: #F44336; font-weight: bold;\");\n}\n\n/**\n * Function to log warning messages\n * @param {string} message - Message to log\n */\nexport function warnLog(message) {\n console.log(\"%c[WARN] \" + message, \"color: #FF9800; font-weight: bold;\");\n}\n\n/**\n * Function to handle version information and fetch the latest update date and release from GitHub\n */\nexport async function printVersionInformation() {\n basicLog(\"Fetching latest FEAScript version information...\");\n try {\n const commitResponse = await fetch(\"https://api.github.com/repos/FEAScript/FEAScript/commits/main\");\n const commitData = await commitResponse.json();\n const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();\n basicLog(`Latest FEAScript update: ${latestCommitDate}`);\n return latestCommitDate;\n } catch (error) {\n errorLog(\"Failed to fetch version information: \" + error);\n return \"Version information unavailable\";\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\nconst proxyMarker = Symbol(\"Comlink.proxy\");\nconst createEndpoint = Symbol(\"Comlink.endpoint\");\nconst releaseProxy = Symbol(\"Comlink.releaseProxy\");\nconst finalizer = Symbol(\"Comlink.finalizer\");\nconst throwMarker = Symbol(\"Comlink.thrown\");\nconst isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n};\n/**\n * Allows customizing the serialization of certain values.\n */\nconst transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\nfunction isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\nfunction expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n}\nfunction isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n}\nfunction closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n}\nfunction wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n}\nfunction throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\nfunction releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\nconst proxyCounter = new WeakMap();\nconst proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\nfunction registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\nfunction unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\nfunction createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n}\nfunction myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n}\nfunction processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\nconst transferCache = new WeakMap();\nfunction transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n}\nfunction proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n}\nfunction windowEndpoint(w, context = globalThis, targetOrigin = \"*\") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\nfunction toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\nfunction fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n}\nfunction requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n}\nfunction generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n\nexport { createEndpoint, expose, finalizer, proxy, proxyMarker, releaseProxy, transfer, transferHandlers, windowEndpoint, wrap };\n//# sourceMappingURL=comlink.mjs.map\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { jacobiSolver } from \"./jacobiSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n/**\n * Function to solve a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (\"lusolve\" or \"jacobi\")\n * @param {Array} jacobianMatrix - The coefficient matrix\n * @param {Array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {\n\n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n let solutionVector = [];\n let converged = true;\n let iterations = 0;\n\n // Solve the linear system based on the specified solver method\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n if (solverMethod === \"lusolve\") {\n // Use LU decomposition method\n const jacobianMatrixSparse = math.sparse(jacobianMatrix);\n const luFactorization = math.slu(jacobianMatrixSparse, 1, 1); // order=1, threshold=1 for pivoting\n let solutionMatrix = math.lusolve(luFactorization, residualVector);\n solutionVector = math.squeeze(solutionMatrix).valueOf();\n //solutionVector = math.lusolve(jacobianMatrix, residualVector); // In the case of a dense matrix\n } else if (solverMethod === \"jacobi\") {\n // Use Jacobi method\n const initialGuess = new Array(residualVector.length).fill(0);\n const jacobiSolverResult = jacobiSolver(jacobianMatrix, residualVector, initialGuess, {\n maxIterations,\n tolerance,\n });\n\n // Log convergence information\n if (jacobiSolverResult.converged) {\n debugLog(`Jacobi method converged in ${jacobiSolverResult.iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${jacobiSolverResult.iterations} iterations`);\n }\n\n solutionVector = jacobiSolverResult.solutionVector;\n converged = jacobiSolverResult.converged;\n iterations = jacobiSolverResult.iterations;\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n return { solutionVector, converged, iterations };\n}\n\n// Helper to lazily create a default WebGPU compute engine (Comlink + worker)\nasync function createDefaultComputeEngine() {\n const worker = new Worker(new URL(\"../workers/webgpuWorkerScript.js\", import.meta.url), {\n type: \"module\",\n });\n const computeEngine = Comlink.wrap(worker);\n await computeEngine.initialize();\n return { computeEngine, worker };\n}\n\n/**\n * Function to solve asynchronously a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (e.g., \"jacobi-gpu\")\n * @param {array} jacobianMatrix - The coefficient matrix\n * @param {array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport async function solveLinearSystemAsync(solverMethod, jacobianMatrix, residualVector, options = {}) {\n \n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n // Normalize inputs\n const A = Array.isArray(jacobianMatrix) ? jacobianMatrix : jacobianMatrix?.toArray?.() ?? jacobianMatrix;\n const b = Array.isArray(residualVector) ? residualVector : residualVector?.toArray?.() ?? residualVector;\n\n let created = null;\n let computeEngine = null;\n\n let solutionVector = [];\n let converged = true;\n let iterations;\n\n if (solverMethod === \"jacobi-gpu\") {\n // Spin up a worker-backed compute engine\n created = await createDefaultComputeEngine();\n computeEngine = created.computeEngine;\n\n const x0 = new Array(b.length).fill(0);\n let result;\n\n result = await computeEngine.webgpuJacobiSolver(A, b, x0, { maxIterations, tolerance });\n solutionVector = result.solutionVector;\n converged = result.converged;\n iterations = result.iterations;\n\n // Log convergence information\n if (converged) {\n debugLog(`Jacobi method converged in ${iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${iterations} iterations`);\n }\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(`System solved successfully (${solverMethod})`);\n\n if (created) {\n await computeEngine?.destroy?.().catch(() => { });\n created.worker.terminate();\n }\n\n return { solutionVector, converged, iterations };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to solve a system of linear equations using the Jacobi iterative method (CPU synchronous version)\n * @param {array} A - The system matrix\n * @param {array} b - The right-hand side vector\n * @param {array} x0 - Initial guess for solution vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\nexport function jacobiSolver(A, b, x0, options = {}) {\n // Extract options\n const { maxIterations, tolerance } = options;\n\n const n = A.length;\n let x = [...x0];\n let xNew = new Array(n);\n\n // Jacobi update: xNew[i] = (b[i] - sum(A[i][j] * x[j] for j != i)) / A[i][i]\n for (let iter = 0; iter < maxIterations; iter++) {\n for (let i = 0; i < n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (i !== j) {\n sum += A[i][j] * x[j];\n }\n }\n xNew[i] = (b[i] - sum) / A[i][i];\n }\n\n // Check convergence based on maximum difference in solution vector\n let maxDiff = 0;\n for (let i = 0; i < n; i++) {\n maxDiff = Math.max(maxDiff, Math.abs(xNew[i] - x[i]));\n }\n\n // Copy new solution for the next iteration\n x = [...xNew];\n\n if (maxDiff < tolerance) {\n return { solutionVector: x, iterations: iter + 1, converged: true };\n }\n }\n\n return { solutionVector: x, iterations: maxIterations, converged: false };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle basis functions and their derivatives based on element configuration\n */\nexport class BasisFunctions {\n /**\n * Constructor to initialize the BasisFunctions class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to calculate basis functions and their derivatives based on the dimension and order\n * @param {number} ksi - Natural coordinate (for both 1D and 2D)\n * @param {number} [eta] - Second natural coordinate (only for 2D elements)\n * @returns {object} An object containing:\n * - basisFunction: Array of evaluated basis functions\n * - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi\n * - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)\n */\n getBasisFunctions(ksi, eta = null) {\n let basisFunction = [];\n let basisFunctionDerivKsi = [];\n let basisFunctionDerivEta = [];\n\n if (this.meshDimension === \"1D\") {\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 1D elements\n basisFunction[0] = 1 - ksi;\n basisFunction[1] = ksi;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -1;\n basisFunctionDerivKsi[1] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 1D elements\n basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;\n basisFunction[1] = 4 * ksi - 4 * ksi ** 2;\n basisFunction[2] = -ksi + 2 * ksi ** 2;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -3 + 4 * ksi;\n basisFunctionDerivKsi[1] = 4 - 8 * ksi;\n basisFunctionDerivKsi[2] = -1 + 4 * ksi;\n }\n } else if (this.meshDimension === \"2D\") {\n if (eta === null) {\n errorLog(\"Eta coordinate is required for 2D elements\");\n return;\n }\n\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 2D elements\n function l1(c) {\n return 1 - c;\n }\n function l2(c) {\n return c;\n }\n function dl1() {\n return -1;\n }\n function dl2() {\n return 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l2(ksi) * l1(eta);\n basisFunction[3] = l2(ksi) * l2(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1() * l1(eta);\n basisFunctionDerivKsi[1] = dl1() * l2(eta);\n basisFunctionDerivKsi[2] = dl2() * l1(eta);\n basisFunctionDerivKsi[3] = dl2() * l2(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1();\n basisFunctionDerivEta[1] = l1(ksi) * dl2();\n basisFunctionDerivEta[2] = l2(ksi) * dl1();\n basisFunctionDerivEta[3] = l2(ksi) * dl2();\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 2D elements\n function l1(c) {\n return 2 * c ** 2 - 3 * c + 1;\n }\n function l2(c) {\n return -4 * c ** 2 + 4 * c;\n }\n function l3(c) {\n return 2 * c ** 2 - c;\n }\n function dl1(c) {\n return 4 * c - 3;\n }\n function dl2(c) {\n return -8 * c + 4;\n }\n function dl3(c) {\n return 4 * c - 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l1(ksi) * l3(eta);\n basisFunction[3] = l2(ksi) * l1(eta);\n basisFunction[4] = l2(ksi) * l2(eta);\n basisFunction[5] = l2(ksi) * l3(eta);\n basisFunction[6] = l3(ksi) * l1(eta);\n basisFunction[7] = l3(ksi) * l2(eta);\n basisFunction[8] = l3(ksi) * l3(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);\n basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);\n basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);\n basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);\n basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);\n basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);\n basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);\n basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);\n basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);\n basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);\n basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);\n basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);\n basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);\n basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);\n basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);\n basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);\n basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);\n }\n }\n\n return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Basic structure for the mesh\n */\nexport class Mesh {\n /**\n * Constructor to initialize the Mesh class\n * @param {object} config - Configuration object for the mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)\n * @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)\n * @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n meshDimension = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n this.numElementsX = numElementsX;\n this.numElementsY = numElementsY;\n this.maxX = maxX;\n this.maxY = maxY;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n this.parsedMesh = parsedMesh;\n\n this.boundaryElementsProcessed = false;\n\n if (this.parsedMesh) {\n basicLog(\"Using pre-parsed mesh from gmshReader data for mesh generation.\");\n this.parseMeshFromGmsh();\n }\n }\n\n /**\n * Method to parse the mesh from the GMSH format to the FEAScript format\n */\n parseMeshFromGmsh() {\n if (!this.parsedMesh.nodalNumbering) {\n errorLog(\"No valid nodal numbering found in the parsed mesh.\");\n }\n\n if (\n typeof this.parsedMesh.nodalNumbering === \"object\" &&\n !Array.isArray(this.parsedMesh.nodalNumbering)\n ) {\n // Store the nodal numbering structure before converting\n const quadElements = this.parsedMesh.nodalNumbering.quadElements || [];\n const triangleElements = this.parsedMesh.nodalNumbering.triangleElements || [];\n\n debugLog(\n \"Initial parsed mesh nodal numbering from GMSH format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Check if it has quadElements or triangleElements structure from gmshReader\n if (this.parsedMesh.elementTypes[3] || this.parsedMesh.elementTypes[10]) {\n // Map nodal numbering from GMSH format to FEAScript format for quad elements\n const mappedNodalNumbering = [];\n\n for (let elemIdx = 0; elemIdx < quadElements.length; elemIdx++) {\n const gmshNodes = quadElements[elemIdx];\n const feaScriptNodes = new Array(gmshNodes.length);\n\n // Check for element type based on number of nodes\n if (gmshNodes.length === 4) {\n // Simple mapping for linear quad elements (4 nodes)\n // GMSH: FEAScript:\n // 3 --- 2 1 --- 3\n // | | --> | |\n // 0 --- 1 0 --- 2\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[3]; // 3 -> 1\n feaScriptNodes[2] = gmshNodes[1]; // 1 -> 2\n feaScriptNodes[3] = gmshNodes[2]; // 2 -> 3\n } else if (gmshNodes.length === 9) {\n // Mapping for quadratic quad elements (9 nodes)\n // GMSH: FEAScript:\n // 3--6--2 2--5--8\n // | | | |\n // 7 8 5 --> 1 4 7\n // | | | |\n // 0--4--1 0--3--6\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[7]; // 7 -> 1\n feaScriptNodes[2] = gmshNodes[3]; // 3 -> 2\n feaScriptNodes[3] = gmshNodes[4]; // 4 -> 3\n feaScriptNodes[4] = gmshNodes[8]; // 8 -> 4\n feaScriptNodes[5] = gmshNodes[6]; // 6 -> 5\n feaScriptNodes[6] = gmshNodes[1]; // 1 -> 6\n feaScriptNodes[7] = gmshNodes[5]; // 5 -> 7\n feaScriptNodes[8] = gmshNodes[2]; // 2 -> 8\n }\n\n mappedNodalNumbering.push(feaScriptNodes);\n }\n\n this.parsedMesh.nodalNumbering = mappedNodalNumbering;\n } else if (this.parsedMesh.elementTypes[2]) {\n errorLog(\"Element type is neither triangle nor quad; mapping for this type is not implemented yet.\");\n }\n\n debugLog(\n \"Nodal numbering after mapping from GMSH to FEAScript format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Process boundary elements if they exist and if physical property mapping exists\n if (this.parsedMesh.physicalPropMap && this.parsedMesh.boundaryElements) {\n // Check if boundary elements need to be processed\n if (\n Array.isArray(this.parsedMesh.boundaryElements) &&\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n // Create a new array without the empty first element\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n\n // If boundary node pairs exist but boundary elements haven't been processed\n if (this.parsedMesh.boundaryNodePairs && !this.parsedMesh.boundaryElementsProcessed) {\n // Reset boundary elements array\n this.parsedMesh.boundaryElements = [];\n\n // Process each physical property from the Gmsh file\n this.parsedMesh.physicalPropMap.forEach((prop) => {\n // Only process 1D physical entities (boundary lines)\n if (prop.dimension === 1) {\n // Get all node pairs for this boundary\n const boundaryNodePairs = this.parsedMesh.boundaryNodePairs[prop.tag] || [];\n\n if (boundaryNodePairs.length > 0) {\n // Initialize array for this boundary tag\n if (!this.parsedMesh.boundaryElements[prop.tag]) {\n this.parsedMesh.boundaryElements[prop.tag] = [];\n }\n\n // For each boundary line segment (defined by a pair of nodes)\n boundaryNodePairs.forEach((nodesPair) => {\n const node1 = nodesPair[0]; // First node in the pair\n const node2 = nodesPair[1]; // Second node in the pair\n\n debugLog(\n `Processing boundary node pair: [${node1}, ${node2}] for boundary ${prop.tag} (${\n prop.name || \"unnamed\"\n })`\n );\n\n // Search through all elements to find which one contains both nodes\n let foundElement = false;\n\n // Loop through all elements in the mesh\n for (let elemIdx = 0; elemIdx < this.parsedMesh.nodalNumbering.length; elemIdx++) {\n const elemNodes = this.parsedMesh.nodalNumbering[elemIdx];\n\n // For linear quadrilateral linear elements (4 nodes)\n if (elemNodes.length === 4) {\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript linear quadrilateral numbering:\n // 1 --- 3\n // | |\n // 0 --- 2\n\n if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0)\n ) {\n side = 0; // Bottom side\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0)\n ) {\n side = 1; // Left side\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 1 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 1)\n ) {\n side = 2; // Top side\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 2)\n ) {\n side = 3; // Right side\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n } else if (elemNodes.length === 9) {\n // For quadratic quadrilateral elements (9 nodes)\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript quadratic quadrilateral numbering:\n // 2--5--8\n // | |\n // 1 4 7\n // | |\n // 0--3--6\n\n // TODO: Transform into dictionaries for better readability\n if (\n (node1Index === 0 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 0) ||\n (node1Index === 3 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 3)\n ) {\n side = 0; // Bottom side (nodes 0, 3, 6)\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0) ||\n (node1Index === 1 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 1)\n ) {\n side = 1; // Left side (nodes 0, 1, 2)\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 5) ||\n (node1Index === 5 && node2Index === 2) ||\n (node1Index === 5 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 5)\n ) {\n side = 2; // Top side (nodes 2, 5, 8)\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 6 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 7) ||\n (node1Index === 7 && node2Index === 6) ||\n (node1Index === 7 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 7)\n ) {\n side = 3; // Right side (nodes 6, 7, 8)\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n }\n }\n\n if (!foundElement) {\n errorLog(\n `Could not find element containing boundary nodes ${node1} and ${node2}. Boundary may be incomplete.`\n );\n }\n });\n }\n }\n });\n\n // Mark as processed\n this.boundaryElementsProcessed = true;\n\n // Fix boundary elements array - remove undefined entries\n if (\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n }\n }\n }\n\n return this.parsedMesh;\n }\n}\n\nexport class Mesh1D extends Mesh {\n /**\n * Constructor to initialize the 1D mesh\n * @param {object} config - Configuration object for the 1D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({ numElementsX = null, maxX = null, elementOrder = \"linear\", parsedMesh = null }) {\n super({\n numElementsX,\n maxX,\n numElementsY: 1,\n maxY: 0,\n meshDimension: \"1D\",\n elementOrder,\n parsedMesh,\n });\n\n if (this.numElementsX === null || this.maxX === null) {\n errorLog(\"numElementsX and maxX are required parameters when generating a 1D mesh from geometry\");\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n const xStart = 0;\n let totalNodesX, deltaX;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX;\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX / 2;\n }\n }\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate1DNodalNumbering(this.numElementsX, totalNodesX, this.elementOrder);\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n\n // Return x coordinates of nodes, total nodes, NOP array, and boundary elements\n return {\n nodesXCoordinates,\n totalNodesX,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate1DNodalNumbering(numElementsX, totalNodesX, elementOrder) {\n // TODO: The totalNodesX is not used in the original function. Verify if\n // there is a multiple calculation on the totalNodes.\n\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear 1D elements with the following nodes representation:\n *\n * 1 --- 2\n *\n */\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic 1D elements with the following nodes representation:\n *\n * 1--2--3\n *\n */\n let columnCounter = 0;\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex + columnCounter;\n }\n columnCounter += 1;\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 1D domains (line segments):\n * 0 - Left node of reference element (maps to physical left endpoint)\n * 1 - Right node of reference element (maps to physical right endpoint)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 2; // For 1D, we only have two sides (left and right)\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // Left boundary (element 0, side 0)\n boundaryElements[0].push([0, 0]);\n\n // Right boundary (last element, side 1)\n boundaryElements[1].push([this.numElementsX - 1, 1]);\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n\nexport class Mesh2D extends Mesh {\n /**\n * Constructor to initialize the 2D mesh\n * @param {object} config - Configuration object for the 2D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY] - Number of elements along the y-axis (required for geometry-based mesh)\n * @param {number} [config.maxY] - Maximum y-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n super({\n numElementsX,\n maxX,\n numElementsY,\n maxY,\n meshDimension: \"2D\",\n elementOrder,\n parsedMesh,\n });\n\n // Validate geometry parameters (when not using a parsed mesh)\n if (\n !parsedMesh &&\n (this.numElementsX === null || this.maxX === null || this.numElementsY === null || this.maxY === null)\n ) {\n errorLog(\n \"numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry\"\n );\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n let nodesYCoordinates = [];\n const xStart = 0;\n const yStart = 0;\n let totalNodesX, totalNodesY, deltaX, deltaY;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n totalNodesY = this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + nodeIndexY * deltaY;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + nodeIndexX * deltaX;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + nodeIndexY * deltaY;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n totalNodesY = 2 * this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;\n }\n }\n }\n\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate2DNodalNumbering(\n this.numElementsX,\n this.numElementsY,\n totalNodesY,\n this.elementOrder\n );\n\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n debugLog(\"Generated node Y coordinates: \" + JSON.stringify(nodesYCoordinates));\n\n // Return statement\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate2DNodalNumbering(numElementsX, numElementsY, totalNodesY, elementOrder) {\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear rectangular elements with the following nodes representation:\n *\n * 1 --- 3\n * | |\n * 0 --- 2\n *\n */\n let rowCounter = 0;\n let columnCounter = 2;\n for (let elementIndex = 0; elementIndex < numElementsX * numElementsY; elementIndex++) {\n rowCounter += 1;\n nop[elementIndex] = [];\n nop[elementIndex][0] = elementIndex + columnCounter - 1;\n nop[elementIndex][1] = elementIndex + columnCounter;\n nop[elementIndex][2] = elementIndex + columnCounter + numElementsY;\n nop[elementIndex][3] = elementIndex + columnCounter + numElementsY + 1;\n if (rowCounter === numElementsY) {\n columnCounter += 1;\n rowCounter = 0;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic rectangular elements with the following nodes representation:\n *\n * 2--5--8\n * | |\n * 1 4 7\n * | |\n * 0--3--6\n *\n */\n for (let elementIndexX = 1; elementIndexX <= numElementsX; elementIndexX++) {\n for (let elementIndexY = 1; elementIndexY <= numElementsY; elementIndexY++) {\n nop[elementIndex] = [];\n for (let nodeIndex1 = 1; nodeIndex1 <= 3; nodeIndex1++) {\n let nodeIndex2 = 3 * nodeIndex1 - 2;\n nop[elementIndex][nodeIndex2 - 1] =\n totalNodesY * (2 * elementIndexX + nodeIndex1 - 3) + 2 * elementIndexY - 1;\n nop[elementIndex][nodeIndex2] = nop[elementIndex][nodeIndex2 - 1] + 1;\n nop[elementIndex][nodeIndex2 + 1] = nop[elementIndex][nodeIndex2 - 1] + 2;\n }\n elementIndex = elementIndex + 1;\n }\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 2D domains (rectangular):\n * 0 - Bottom side of reference element (maps to physical bottom boundary)\n * 1 - Left side of reference element (maps to physical left boundary)\n * 2 - Top side of reference element (maps to physical top boundary)\n * 3 - Right side of reference element (maps to physical right boundary)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 4; // For 2D, we have four sides (left, right, bottom, top)\n\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // TODO: Why to loop through all elements? Is it not better to loop over only the\n // elements that are on the boundary? eg: [0, this.numElementsX - 1] on x and\n // [0, this.numElementsY - 1] on y\n for (let elementIndexX = 0; elementIndexX < this.numElementsX; elementIndexX++) {\n for (let elementIndexY = 0; elementIndexY < this.numElementsY; elementIndexY++) {\n const elementIndex = elementIndexX * this.numElementsY + elementIndexY;\n\n // Bottom boundary\n if (elementIndexY === 0) {\n boundaryElements[0].push([elementIndex, 0]);\n }\n\n // Left boundary\n if (elementIndexX === 0) {\n boundaryElements[1].push([elementIndex, 1]);\n }\n\n // Top boundary\n if (elementIndexY === this.numElementsY - 1) {\n boundaryElements[2].push([elementIndex, 2]);\n }\n\n // Right boundary\n if (elementIndexX === this.numElementsX - 1) {\n boundaryElements[3].push([elementIndex, 3]);\n }\n }\n }\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Class to handle numerical integration using Gauss quadrature\n */\nexport class NumericalIntegration {\n /**\n * Constructor to initialize the NumericalIntegration class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to return Gauss points and weights based on element configuration\n * @returns {object} An object containing:\n * - gaussPoints: Array of Gauss points\n * - gaussWeights: Array of Gauss weights\n */\n getGaussPointsAndWeights() {\n let gaussPoints = []; // Gauss points\n let gaussWeights = []; // Gauss weights\n\n if (this.elementOrder === \"linear\") {\n // For linear elements, use 1-point Gauss quadrature\n gaussPoints[0] = 0.5;\n gaussWeights[0] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // For quadratic elements, use 3-point Gauss quadrature\n gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;\n gaussPoints[1] = 0.5;\n gaussPoints[2] = (1 + Math.sqrt(3 / 5)) / 2;\n gaussWeights[0] = 5 / 18;\n gaussWeights[1] = 8 / 18;\n gaussWeights[2] = 5 / 18;\n }\n\n return { gaussPoints, gaussWeights };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nimport { BasisFunctions } from \"./basisFunctionsScript.js\";\nimport { Mesh1D, Mesh2D } from \"./meshGenerationScript.js\";\nimport { NumericalIntegration } from \"../methods/numericalIntegrationScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to prepare the mesh for finite element analysis\n * @param {object} meshConfig - Object containing computational mesh details\n * @returns {object} An object containing all mesh-related data\n */\nexport function prepareMesh(meshConfig) {\n const { meshDimension, numElementsX, numElementsY, maxX, maxY, elementOrder, parsedMesh } = meshConfig;\n\n // Create a new instance of the Mesh class\n let mesh;\n if (meshDimension === \"1D\") {\n mesh = new Mesh1D({ numElementsX, maxX, elementOrder, parsedMesh });\n } else if (meshDimension === \"2D\") {\n mesh = new Mesh2D({ numElementsX, maxX, numElementsY, maxY, elementOrder, parsedMesh });\n } else {\n errorLog(\"Mesh dimension must be either '1D' or '2D'.\");\n }\n\n // Use the parsed mesh in case it was already passed with Gmsh format\n const nodesCoordinatesAndNumbering = mesh.boundaryElementsProcessed ? mesh.parsedMesh : mesh.generateMesh();\n\n // Extract nodes coordinates and nodal numbering (NOP) from the mesh data\n let nodesXCoordinates = nodesCoordinatesAndNumbering.nodesXCoordinates;\n let nodesYCoordinates = nodesCoordinatesAndNumbering.nodesYCoordinates;\n let totalNodesX = nodesCoordinatesAndNumbering.totalNodesX;\n let totalNodesY = nodesCoordinatesAndNumbering.totalNodesY;\n let nop = nodesCoordinatesAndNumbering.nodalNumbering;\n let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;\n\n // Check the mesh type\n const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;\n\n // Calculate totalElements and totalNodes based on mesh type\n let totalElements, totalNodes;\n\n if (isParsedMesh) {\n totalElements = nop.length; // Number of elements is the length of the nodal numbering array\n totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array\n debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);\n } else {\n // For structured mesh, calculate based on dimensions\n totalElements = numElementsX * (meshDimension === \"2D\" ? numElementsY : 1);\n totalNodes = totalNodesX * (meshDimension === \"2D\" ? totalNodesY : 1);\n debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);\n }\n\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nop,\n boundaryElements,\n totalElements,\n totalNodes,\n meshDimension,\n elementOrder,\n };\n}\n\n/**\n * Function to initialize the FEA matrices and numerical tools\n * @param {object} meshData - Object containing mesh data from prepareMesh()\n * @returns {object} An object containing initialized matrices and numerical tools\n */\nexport function initializeFEA(meshData) {\n const { totalNodes, nop, meshDimension, elementOrder } = meshData;\n\n // Initialize variables for matrix assembly\n let residualVector = [];\n let jacobianMatrix = [];\n let localToGlobalMap = [];\n\n // Initialize jacobianMatrix and residualVector arrays\n for (let nodeIndex = 0; nodeIndex < totalNodes; nodeIndex++) {\n residualVector[nodeIndex] = 0;\n jacobianMatrix.push([]);\n for (let colIndex = 0; colIndex < totalNodes; colIndex++) {\n jacobianMatrix[nodeIndex][colIndex] = 0;\n }\n }\n\n // Initialize the BasisFunctions class\n const basisFunctions = new BasisFunctions({\n meshDimension,\n elementOrder,\n });\n\n // Initialize the NumericalIntegration class\n const numericalIntegration = new NumericalIntegration({\n meshDimension,\n elementOrder,\n });\n\n // Calculate Gauss points and weights\n let gaussPointsAndWeights = numericalIntegration.getGaussPointsAndWeights();\n let gaussPoints = gaussPointsAndWeights.gaussPoints;\n let gaussWeights = gaussPointsAndWeights.gaussWeights;\n\n // Determine the number of nodes in the reference element based on the first element in the nop array\n const numNodes = nop[0].length;\n\n return {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 1D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping1D(params) {\n const { basisFunction, basisFunctionDerivKsi, nodesXCoordinates, localToGlobalMap, numNodes } = params;\n\n let xCoordinates = 0;\n let ksiDerivX = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n }\n let detJacobian = ksiDerivX;\n\n // Compute x-derivative of basis functions\n let basisFunctionDerivX = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n basisFunctionDerivX[localNodeIndex] = basisFunctionDerivKsi[localNodeIndex] / detJacobian;\n }\n\n return {\n xCoordinates,\n detJacobian,\n basisFunctionDerivX,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 2D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping2D(params) {\n const {\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n } = params;\n\n let xCoordinates = 0;\n let yCoordinates = 0;\n let ksiDerivX = 0;\n let etaDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivY = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n yCoordinates += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n ksiDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n }\n let detJacobian = ksiDerivX * etaDerivY - etaDerivX * ksiDerivY;\n\n // Compute x-derivative and y-derivative of basis functions\n let basisFunctionDerivX = [];\n let basisFunctionDerivY = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // The x-derivative of the n basis function\n basisFunctionDerivX[localNodeIndex] =\n (etaDerivY * basisFunctionDerivKsi[localNodeIndex] -\n ksiDerivY * basisFunctionDerivEta[localNodeIndex]) /\n detJacobian;\n // The y-derivative of the n basis function\n basisFunctionDerivY[localNodeIndex] =\n (ksiDerivX * basisFunctionDerivEta[localNodeIndex] -\n etaDerivX * basisFunctionDerivKsi[localNodeIndex]) /\n detJacobian;\n }\n\n return {\n xCoordinates,\n yCoordinates,\n detJacobian,\n basisFunctionDerivX,\n basisFunctionDerivY,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle thermal boundary conditions application\n */\nexport class ThermalBoundaryConditions {\n /**\n * Constructor to initialize the ThermalBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose constant temperature boundary conditions (Dirichlet type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant temperature boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantTempBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions (Robin type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n */\n imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 1;\n }\n } else if (this.elementOrder === \"quadratic\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 2;\n }\n }\n\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n residualVector[globalNodeIndex] += -convectionCoeff * extTemp;\n jacobianMatrix[globalNodeIndex][globalNodeIndex] += convectionCoeff;\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions for the frontal solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix with convection contributions\n * - localResidualVector: Residual vector with convection contributions\n */\n imposeConvectionBoundaryConditionsFront(\n elementIndex,\n nodesXCoordinates,\n nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n // Initialize local Jacobian matrix and local residual vector\n const numNodes = this.nop[elementIndex].length;\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Check if this element is on a convection boundary\n for (const boundaryKey in this.boundaryElements) {\n if (this.boundaryConditions[boundaryKey]?.[0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n\n // Find if this element is on this boundary and which side\n const boundaryElement = this.boundaryElements[boundaryKey].find(\n ([elemIdx, _]) => elemIdx === elementIndex\n );\n\n if (boundaryElement) {\n const side = boundaryElement[1];\n\n if (this.meshDimension === \"1D\") {\n // Handle 1D case\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n nodeIndex = side === 0 ? 0 : 1;\n } else if (this.elementOrder === \"quadratic\") {\n nodeIndex = side === 0 ? 0 : 2;\n }\n\n // Add contribution to local Jacobian matrix and local residual vector\n debugLog(\n ` - Applied convection boundary condition to node ${nodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n localResidualVector[nodeIndex] += -convectionCoeff * extTemp;\n localJacobianMatrix[nodeIndex][nodeIndex] += convectionCoeff;\n } else if (this.meshDimension === \"2D\") {\n // Handle 2D case\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n // Get basis functions\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n const basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n const basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n // Calculate tangent vector components\n let ksiDerivX = 0,\n ksiDerivY = 0,\n etaDerivX = 0,\n etaDerivY = 0;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n } else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute tangent vector length\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n // Handle quadratic elements (similar pattern but with more Gauss points)\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { ThermalBoundaryConditions } from \"./thermalBoundaryConditionsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the solid heat transfer model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\nexport function assembleHeatConductionMat(meshData, boundaryConditions) {\n basicLog(\"Starting solid heat transfer matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D solid heat transfer\n if (meshDimension === \"1D\") {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n // 2D solid heat transfer\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const thermalBoundaryConditions = new ThermalBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Convection boundary conditions\n thermalBoundaryConditions.imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n );\n\n // Impose ConstantTemp boundary conditions\n thermalBoundaryConditions.imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Solid heat transfer matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the solid heat transfer model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - localResidualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleHeatConductionFront({ elementIndex, nop, meshData, basisFunctions, FEAData }) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n if (meshDimension === \"1D\") {\n // 1D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n // 2D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Create mapping from local element space to global mesh (convert to 0-based indexing)\n const localToGlobalMap = ngl.map((globalIndex) => globalIndex - 1);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle generic boundary conditions application\n */\nexport class GenericBoundaryConditions {\n /**\n * Constructor to initialize the GenericBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose Dirichlet boundary conditions\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant value (Dirichlet) boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantValueBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n// Base viscous term that remains when eikonal equation is fully activated\nconst baseEikonalViscousTerm = 1e-2;\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the front propagation model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleFrontPropagationMat(\n meshData,\n boundaryConditions,\n solutionVector,\n eikonalActivationFlag\n) {\n basicLog(\"Starting front propagation matrix assembly...\");\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n debugLog(`eikonalViscousTerm: ${eikonalViscousTerm}`);\n debugLog(`eikonalActivationFlag: ${eikonalActivationFlag}`);\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // jacobianMatrix\n // TODO jacobianMatrix calculation here\n }\n }\n }\n // 2D front propagation (eikonal) equation\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n\n // residualVector: Viscous term contribution (to stabilize the solution)\n residualVector[localToGlobalMap1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // residualVector: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n residualVector[localToGlobalMap1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n\n // jacobianMatrix: Viscous term contribution\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // jacobianMatrix: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Dirichlet boundary conditions\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Front propagation matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the front propagation model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - residualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleFrontPropagationFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n solutionVector,\n eikonalActivationFlag,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // localJacobianMatrix\n // TODO localJacobianMatrix calculation here\n }\n }\n // 2D front propagation (eikonal) equation\n } else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // Viscous term contribution\n localResidualVector[localNodeIndex1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localResidualVector[localNodeIndex1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Viscous term contribution\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { BasisFunctions } from \"../mesh/basisFunctionsScript.js\";\nimport { initializeFEA } from \"../mesh/meshUtilsScript.js\";\nimport { assembleHeatConductionFront } from \"../models/heatConductionScript.js\";\nimport { ThermalBoundaryConditions } from \"../models/thermalBoundaryConditionsScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\nimport { GenericBoundaryConditions } from \"../models/genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n// Create object templates\nconst frontalData = {};\nconst frontalState = {};\nconst elementData = { currentElementIndex: 0 };\nconst frontStorage = {};\nlet basisFunctions;\n\n/**\n * Function to run the frontal solver and obtain results for plotting\n * @param {function} assembleFront - Matrix assembler based on the physical model\n * @param {object} meshData - Object containing mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} [options] - Additional options for the solver\n * @returns {object} An object containing the solution vector and node coordinates\n */\nexport function runFrontalSolver(assembleFront, meshData, boundaryConditions, options = {}) {\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const totalNodes = meshData.nodesXCoordinates.length;\n const numElements = meshData.totalElements;\n const numNodes = FEAData.numNodes;\n\n // Calculate required array sizes\n initializeFrontalArrays(numNodes, numElements);\n\n // Start timing for system solving (frontal algorithm)\n basicLog(\"Solving system using frontal...\");\n console.time(\"systemSolving\");\n\n // Initialize basis functions\n basisFunctions = new BasisFunctions({\n meshDimension: meshData.meshDimension,\n elementOrder: meshData.elementOrder,\n });\n\n // Copy node connectivity array into frontalData storage\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n for (let nodeIndex = 0; nodeIndex < FEAData.numNodes; nodeIndex++) {\n frontalData.nodalNumbering[elementIndex][nodeIndex] = meshData.nop[elementIndex][nodeIndex];\n }\n }\n\n // Apply Dirichlet-type boundary conditions\n // Initialize all nodes with no boundary condition\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.nodeConstraintCode[nodeIndex] = 0;\n frontalData.boundaryValues[nodeIndex] = 0;\n }\n\n // Handle Dirichlet-type boundary conditions differently based on which solver is being used\n let dirichletBoundaryConditionsHandler;\n // Solid heat transfer model (heatConductionScript solver)\n if (assembleFront === assembleHeatConductionFront) {\n dirichletBoundaryConditionsHandler = new ThermalBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantTempBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n // Front propagation model (frontPropagationScript solver)\n } else if (assembleFront === assembleFrontPropagationFront) {\n dirichletBoundaryConditionsHandler = new GenericBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantValueBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n }\n // Initialize global residual vector\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.globalResidualVector[nodeIndex] = 0;\n }\n\n frontalState.totalNodes = meshData.nodesXCoordinates.length;\n frontalState.writeFlag = 0;\n frontalState.transformationFlag = 1;\n frontalState.determinant = 1;\n\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n frontalState.nodesPerElement[elementIndex] = FEAData.numNodes;\n }\n\n // Parameters for non-linear assemblers\n frontalState.currentSolutionVector = options.solutionVector;\n frontalState.eikonalActivationFlag = options.eikonalActivationFlag;\n\n // Pass assembleFront and dirichletBoundaryConditionsHandler to runFrontalAlgorithm\n runFrontalAlgorithm(meshData, FEAData, dirichletBoundaryConditionsHandler, assembleFront);\n\n // Copy solution\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.solutionVector[nodeIndex] = frontalState.globalSolutionVector[nodeIndex];\n }\n\n // Output results to console for debugging\n const { nodesXCoordinates, nodesYCoordinates } = meshData;\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n if (meshData.meshDimension === \"1D\") {\n // 1D case - only output X coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${frontalData.solutionVector[\n nodeIndex\n ].toExponential(5)}`\n );\n } else {\n // 2D case - output X, Y coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${nodesYCoordinates[nodeIndex].toExponential(\n 5\n )} ${frontalData.solutionVector[nodeIndex].toExponential(5)}`\n );\n }\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n const { nodesXCoordinates: finalNodesX, nodesYCoordinates: finalNodesY } = meshData;\n return {\n solutionVector: frontalData.solutionVector.slice(0, totalNodes),\n nodesCoordinates: {\n nodesXCoordinates: finalNodesX,\n nodesYCoordinates: finalNodesY,\n },\n };\n}\n\n/**\n * Function to initialize arrays dynamically based on problem size\n * @param {number} numNodes - Number of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n */\nfunction initializeFrontalArrays(numNodes, numElements) {\n // Use the actual number of elements from the mesh\n frontalData.nodalNumbering = Array(numElements)\n .fill()\n .map(() => Array(numNodes).fill(0));\n frontalData.nodeConstraintCode = Array(numNodes).fill(0);\n frontalData.boundaryValues = Array(numNodes).fill(0);\n frontalData.globalResidualVector = Array(numNodes).fill(0);\n frontalData.solutionVector = Array(numNodes).fill(0);\n frontalData.topologyData = Array(numElements).fill(0);\n frontalData.lateralData = Array(numElements).fill(0);\n\n // Initialize frontalState arrays\n frontalState.writeFlag = 0;\n frontalState.totalNodes = numNodes;\n frontalState.transformationFlag = 0;\n frontalState.nodesPerElement = Array(numElements).fill(0);\n frontalState.determinant = 1;\n\n // For matrix operations, estimate required size based on problem complexity\n const systemSize = Math.max(numNodes, 2000);\n frontalState.globalSolutionVector = Array(systemSize).fill(0);\n frontalState.frontDataIndex = 0;\n\n // Initialize elementData arrays\n elementData.localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n elementData.currentElementIndex = 0;\n\n // Initialize frontStorage arrays\n const frontSize = estimateFrontSize(numNodes, numElements);\n frontStorage.frontValues = Array(frontSize).fill(0);\n frontStorage.columnHeaders = Array(systemSize).fill(0);\n frontStorage.pivotRow = Array(systemSize).fill(0);\n frontStorage.pivotData = Array(frontSize).fill(0);\n}\n\n/**\n * Function to estimate the required front size\n * @param {number} numNodes - Number of of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n * @returns {number} Estimated front size\n */\nfunction estimateFrontSize(numNodes, numElements) {\n const frontWidthEstimate = Math.max(Math.ceil(Math.sqrt(numElements)) * numNodes, numNodes * 2);\n return frontWidthEstimate * numElements;\n}\n// Old function to estimate the required front size\n// function estimateFrontSize(numNodes, numElements, numNodes) {\n// const frontWidthEstimate = Math.ceil(Math.sqrt(numElements) * numNodes * 2);\n// const frontSize = frontWidthEstimate * numNodes * 4;\n// return Math.max(frontSize, 10000);\n// }\n\n/**\n * Function to compute local Jacobian matrix and local residual vector\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n const elementIndex = elementData.currentElementIndex - 1;\n\n // Guard against out-of-range indices\n if (elementIndex < 0 || elementIndex >= meshData.totalElements) {\n errorLog(`Skipping out-of-range elementIndex=${elementIndex} (totalElements=${meshData.totalElements})`);\n return false;\n }\n\n // Domain terms\n const { localJacobianMatrix, localResidualVector, ngl } = assembleFront({\n elementIndex,\n nop: frontalData.nodalNumbering,\n meshData,\n basisFunctions: basisFunctions,\n FEAData,\n // These are ignored by linear assemblers\n solutionVector: frontalState.currentSolutionVector,\n eikonalActivationFlag: frontalState.eikonalActivationFlag,\n });\n\n // Handle Robin-type boundary conditions differently based on which solver is being used\n let boundaryLocalJacobianMatrix = Array(FEAData.numNodes)\n .fill()\n .map(() => Array(FEAData.numNodes).fill(0));\n let boundaryResidualVector = Array(FEAData.numNodes).fill(0);\n\n // heatConductionScript solver\n if (assembleFront === assembleHeatConductionFront) {\n // Check if this element is on a Robin-type boundary\n let isOnRobinTypeBoundary = false;\n for (const boundaryKey in meshData.boundaryElements) {\n if (\n thermalBoundaryConditions.boundaryConditions[boundaryKey]?.[0] === \"convection\" &&\n meshData.boundaryElements[boundaryKey].some(([elemIdx, _]) => elemIdx === elementIndex)\n ) {\n isOnRobinTypeBoundary = true;\n break;\n }\n }\n\n // Only calculate Robin-type for elements when required\n if (isOnRobinTypeBoundary) {\n const { gaussPoints, gaussWeights } = FEAData;\n const result = thermalBoundaryConditions.imposeConvectionBoundaryConditionsFront(\n elementIndex,\n meshData.nodesXCoordinates,\n meshData.nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n );\n boundaryLocalJacobianMatrix = result.localJacobianMatrix;\n boundaryResidualVector = result.localResidualVector;\n }\n } else if (assembleFront === assembleFrontPropagationFront) {\n // For now, no Robin-type boundary conditions exist for any other solver\n }\n\n // Combine domain and boundary contributions\n for (let localNodeI = 0; localNodeI < FEAData.numNodes; localNodeI++) {\n for (let localNodeJ = 0; localNodeJ < FEAData.numNodes; localNodeJ++) {\n elementData.localJacobianMatrix[localNodeI][localNodeJ] =\n localJacobianMatrix[localNodeI][localNodeJ] + boundaryLocalJacobianMatrix[localNodeI][localNodeJ];\n }\n }\n\n // Assemble local element residual\n for (let localNodeIndex = 0; localNodeIndex < FEAData.numNodes; localNodeIndex++) {\n const globalNodeIndex = ngl[localNodeIndex] - 1;\n frontalData.globalResidualVector[globalNodeIndex] +=\n localResidualVector[localNodeIndex] + boundaryResidualVector[localNodeIndex];\n }\n\n return true;\n}\n\n/**\n * Function to implement the frontal solver algorithm\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction runFrontalAlgorithm(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n // Allocate local arrays dynamically\n const totalElements = meshData.totalElements;\n const numNodes = meshData.nodesXCoordinates.length;\n const systemSize = Math.max(numNodes, frontalState.globalSolutionVector.length);\n let localDestination = Array(FEAData.numNodes).fill(0);\n let rowDestination = Array(FEAData.numNodes).fill(0);\n let rowHeaders = Array(systemSize).fill(0);\n let pivotRowIndices = Array(systemSize).fill(0);\n let pivotColumnIndices = Array(systemSize).fill(0);\n let modifiedRows = Array(systemSize).fill(0);\n let pivotColumn = Array(systemSize).fill(0);\n let frontMatrix = Array(systemSize)\n .fill()\n .map(() => Array(systemSize).fill(0));\n let rowSwapCount = Array(numNodes).fill(0);\n let columnSwapCount = Array(numNodes).fill(0);\n let lastAppearanceCheck = Array(numNodes).fill(0);\n let pivotColumnGlobalIndex; // Pivot column global index\n\n let frontDataCounter = 1;\n frontalState.writeFlag++;\n let pivotDataIndex = 1;\n let summedRows = 1;\n elementData.currentElementIndex = 0;\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n rowSwapCount[nodeIndex] = 0;\n columnSwapCount[nodeIndex] = 0;\n }\n\n if (frontalState.transformationFlag !== 0) {\n // Prefront: find last appearance of each node\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n lastAppearanceCheck[nodeIndex] = 0;\n }\n\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n let reverseElementIndex = totalElements - elementIndex - 1;\n for (\n let localNodeIndex = 0;\n localNodeIndex < frontalState.nodesPerElement[reverseElementIndex];\n localNodeIndex++\n ) {\n let globalNodeIndex = frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n if (lastAppearanceCheck[globalNodeIndex - 1] === 0) {\n lastAppearanceCheck[globalNodeIndex - 1] = 1;\n frontalData.nodalNumbering[reverseElementIndex][localNodeIndex] =\n -frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n }\n }\n }\n }\n\n frontalState.transformationFlag = 0;\n let columnCount = 0;\n let rowCount = 0;\n\n for (let i = 0; i < systemSize; i++) {\n for (let j = 0; j < systemSize; j++) {\n frontMatrix[j][i] = 0;\n }\n }\n\n while (true) {\n // Assemble a new element only while we still have elements\n let assembled = false;\n let numElementNodes = 0;\n let numElementColumns = 0;\n\n if (elementData.currentElementIndex < totalElements) {\n elementData.currentElementIndex++;\n assembled = assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront);\n }\n\n if (assembled) {\n const currentElement = elementData.currentElementIndex;\n numElementNodes = frontalState.nodesPerElement[currentElement - 1];\n numElementColumns = frontalState.nodesPerElement[currentElement - 1];\n\n for (let localNodeIndex = 0; localNodeIndex < numElementColumns; localNodeIndex++) {\n let globalNodeIndex = frontalData.nodalNumbering[currentElement - 1][localNodeIndex];\n let columnIndex;\n\n if (columnCount === 0) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(frontStorage.columnHeaders[columnIndex])) break;\n }\n\n if (columnIndex === columnCount) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n localDestination[localNodeIndex] = columnIndex + 1;\n frontStorage.columnHeaders[columnIndex] = globalNodeIndex;\n }\n }\n\n let rowIndex;\n if (rowCount === 0) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(rowHeaders[rowIndex])) break;\n }\n\n if (rowIndex === rowCount) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n rowDestination[localNodeIndex] = rowIndex + 1;\n rowHeaders[rowIndex] = globalNodeIndex;\n }\n }\n }\n\n if (rowCount > systemSize || columnCount > systemSize) {\n errorLog(\"Error: systemSize not large enough\");\n return;\n }\n\n for (let localColumnIndex = 0; localColumnIndex < numElementColumns; localColumnIndex++) {\n let frontColumnIndex = localDestination[localColumnIndex];\n for (let localRowIndex = 0; localRowIndex < numElementNodes; localRowIndex++) {\n let frontRowIndex = rowDestination[localRowIndex];\n frontMatrix[frontRowIndex - 1][frontColumnIndex - 1] +=\n elementData.localJacobianMatrix[localRowIndex][localColumnIndex];\n }\n }\n }\n\n // Pivoting/elimination continues whether or not a new element was assembled\n let availableColumnCount = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (frontStorage.columnHeaders[columnIndex] < 0) {\n pivotColumnIndices[availableColumnCount] = columnIndex + 1;\n availableColumnCount++;\n }\n }\n\n let constrainedRowCount = 0;\n let availableRowCount = 0;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n let globalNodeIndex = rowHeaders[rowIndex];\n if (globalNodeIndex < 0) {\n pivotRowIndices[availableRowCount] = rowIndex + 1;\n availableRowCount++;\n let absoluteNodeIndex = Math.abs(globalNodeIndex);\n if (frontalData.nodeConstraintCode[absoluteNodeIndex - 1] === 1) {\n modifiedRows[constrainedRowCount] = rowIndex + 1;\n constrainedRowCount++;\n frontalData.nodeConstraintCode[absoluteNodeIndex - 1] = 2;\n frontalData.globalResidualVector[absoluteNodeIndex - 1] =\n frontalData.boundaryValues[absoluteNodeIndex - 1];\n }\n }\n }\n\n if (constrainedRowCount > 0) {\n for (let constrainedIndex = 0; constrainedIndex < constrainedRowCount; constrainedIndex++) {\n let rowIndex = modifiedRows[constrainedIndex] - 1;\n let globalNodeIndex = Math.abs(rowHeaders[rowIndex]);\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] = 0;\n let columnGlobalIndex = Math.abs(frontStorage.columnHeaders[columnIndex]);\n if (columnGlobalIndex === globalNodeIndex) frontMatrix[rowIndex][columnIndex] = 1;\n }\n }\n }\n\n if (availableColumnCount > summedRows || elementData.currentElementIndex < totalElements) {\n if (availableColumnCount === 0) {\n errorLog(\"Error: no more rows fully summed\");\n return;\n }\n\n let pivotRowIndex = pivotRowIndices[0];\n let pivotColumnIndex = pivotColumnIndices[0];\n let pivotValue = frontMatrix[pivotRowIndex - 1][pivotColumnIndex - 1];\n\n if (Math.abs(pivotValue) < 1e-4) {\n pivotValue = 0;\n for (let columnIndex = 0; columnIndex < availableColumnCount; columnIndex++) {\n let testColumnIndex = pivotColumnIndices[columnIndex];\n for (let rowIndex = 0; rowIndex < availableRowCount; rowIndex++) {\n let testRowIndex = pivotRowIndices[rowIndex];\n let testValue = frontMatrix[testRowIndex - 1][testColumnIndex - 1];\n if (Math.abs(testValue) > Math.abs(pivotValue)) {\n pivotValue = testValue;\n pivotColumnIndex = testColumnIndex;\n pivotRowIndex = testRowIndex;\n }\n }\n }\n }\n\n let pivotGlobalRowIndex = Math.abs(rowHeaders[pivotRowIndex - 1]);\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]); // Assign, don't declare\n let permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n if (nodeIndex >= pivotGlobalRowIndex) rowSwapCount[nodeIndex]--;\n if (nodeIndex >= pivotColumnGlobalIndex) columnSwapCount[nodeIndex]--;\n }\n\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontMatrix[pivotRowIndex - 1][columnIndex] / pivotValue;\n }\n\n let rightHandSide = frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] = rightHandSide;\n pivotColumn[pivotRowIndex - 1] = pivotValue;\n\n if (pivotRowIndex > 1) {\n for (let rowIndex = 0; rowIndex < pivotRowIndex - 1; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1 && eliminationFactor !== 0) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] -= eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n if (pivotRowIndex < rowCount) {\n for (let rowIndex = pivotRowIndex; rowIndex < rowCount; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = pivotColumn[i];\n }\n pivotDataIndex += rowCount;\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = rowHeaders[i];\n }\n pivotDataIndex += rowCount;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.pivotRow[i];\n }\n frontDataCounter += columnCount;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.columnHeaders[i];\n }\n frontDataCounter += columnCount;\n\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n frontMatrix[rowIndex][columnCount - 1] = 0;\n }\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowCount - 1][columnIndex] = 0;\n }\n\n columnCount--;\n if (pivotColumnIndex < columnCount + 1) {\n for (let columnIndex = pivotColumnIndex - 1; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] = frontStorage.columnHeaders[columnIndex + 1];\n }\n }\n\n rowCount--;\n if (pivotRowIndex < rowCount + 1) {\n for (let rowIndex = pivotRowIndex - 1; rowIndex < rowCount; rowIndex++) {\n rowHeaders[rowIndex] = rowHeaders[rowIndex + 1];\n }\n }\n\n if (rowCount > 1 || elementData.currentElementIndex < totalElements) continue;\n\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[0]); // Assign, don't declare\n pivotRowIndex = 1;\n pivotValue = frontMatrix[0][0];\n pivotGlobalRowIndex = Math.abs(rowHeaders[0]);\n pivotColumnIndex = 1;\n permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n frontStorage.pivotRow[0] = 1;\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] =\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.pivotRow[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.columnHeaders[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotColumn[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = rowHeaders[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n frontalState.frontDataIndex = frontDataCounter;\n if (frontalState.writeFlag === 1)\n debugLog(`total ecs transfer in matrix reduction=${frontDataCounter}`);\n\n // Back substitution\n performBackSubstitution(frontDataCounter);\n break;\n }\n }\n}\n\n/**\n * Function to perform back substitution for the frontal solver\n * @param {number} frontDataCounter - Index counter for the element contributions\n */\nfunction performBackSubstitution(frontDataCounter) {\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n frontalState.globalSolutionVector[nodeIndex] = frontalData.boundaryValues[nodeIndex];\n }\n\n for (let iterationIndex = 1; iterationIndex <= frontalState.totalNodes; iterationIndex++) {\n frontDataCounter -= 4;\n let pivotGlobalRowIndex = frontStorage.frontValues[frontDataCounter - 1];\n let columnCount = frontStorage.frontValues[frontDataCounter];\n let pivotColumnIndex = frontStorage.frontValues[frontDataCounter + 1];\n let pivotValue = frontStorage.frontValues[frontDataCounter + 2];\n\n if (iterationIndex === 1) {\n frontDataCounter--;\n frontStorage.columnHeaders[0] = frontStorage.frontValues[frontDataCounter - 1];\n frontDataCounter--;\n frontStorage.pivotRow[0] = frontStorage.frontValues[frontDataCounter - 1];\n } else {\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] =\n frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n }\n\n let pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]);\n if (frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] > 0) continue;\n\n let accumulatedValue = 0;\n frontStorage.pivotRow[pivotColumnIndex - 1] = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n accumulatedValue -=\n frontStorage.pivotRow[columnIndex] *\n frontalState.globalSolutionVector[Math.abs(frontStorage.columnHeaders[columnIndex]) - 1];\n }\n\n frontalState.globalSolutionVector[pivotColumnGlobalIndex - 1] =\n accumulatedValue + frontalData.globalResidualVector[pivotGlobalRowIndex - 1];\n\n frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] = 1;\n }\n\n if (frontalState.writeFlag === 1)\n debugLog(`value of frontDataCounter after backsubstitution=${frontDataCounter}`);\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { euclideanNorm } from \"../methods/euclideanNormScript.js\";\nimport { solveLinearSystem } from \"./linearSystemSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport { runFrontalSolver } from \"./frontalSolverScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\n\n/**\n * Function to solve a system of non-linear equations using the Newton-Raphson method\n * @param {function} assembleMat - Matrix assembler based on the physical model\n * @param {object} context - Context object containing simulation data and options\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\n\nexport function newtonRaphson(assembleMat, context = {}) {\n let errorNorm = 0;\n let converged = false;\n let iterations = 0;\n let deltaX = [];\n let solutionVector = [];\n let jacobianMatrix = [];\n let residualVector = [];\n\n // Extract context\n const { maxIterations = 100, tolerance = 1e-4 } = context;\n\n // Calculate system size\n let totalNodes = context.meshData.nodesXCoordinates.length;\n\n // Initialize arrays with proper size\n for (let i = 0; i < totalNodes; i++) {\n deltaX[i] = 0;\n solutionVector[i] = 0;\n }\n\n // Initialize solution from context if available\n if (context.initialSolution && context.initialSolution.length === totalNodes) {\n solutionVector = [...context.initialSolution];\n }\n\n while (iterations < maxIterations && !converged) {\n // Update solution\n for (let i = 0; i < solutionVector.length; i++) {\n solutionVector[i] = Number(solutionVector[i]) + Number(deltaX[i]);\n }\n\n // Check if using frontal solver\n if (context.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleFrontPropagationFront,\n context.meshData,\n context.boundaryConditions,\n { solutionVector, eikonalActivationFlag: context.eikonalActivationFlag }\n );\n deltaX = frontalResult.solutionVector;\n } else {\n // Compute Jacobian and residual matrices\n ({ jacobianMatrix, residualVector } = assembleMat(\n context.meshData,\n context.boundaryConditions,\n solutionVector, // The solution vector is required in the case of a non-linear equation\n context.eikonalActivationFlag // Currently used only in the front propagation solver (TODO refactor in case of a solver not needing it)\n ));\n\n // Solve the linear system based on the specified solver method\n const linearSystemResult = solveLinearSystem(context.solverMethod, jacobianMatrix, residualVector);\n deltaX = linearSystemResult.solutionVector;\n }\n\n // Check convergence\n errorNorm = euclideanNorm(deltaX);\n\n // Norm for each iteration\n basicLog(`Newton-Raphson iteration ${iterations + 1}: Error norm = ${errorNorm.toExponential(4)}`);\n\n if (errorNorm <= tolerance) {\n converged = true;\n } else if (errorNorm > 1e2) {\n errorLog(`Solution not converged. Error norm: ${errorNorm}`);\n break;\n }\n\n iterations++;\n }\n\n return {\n solutionVector,\n converged,\n iterations,\n jacobianMatrix,\n residualVector,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { newtonRaphson } from \"./methods/newtonRaphsonScript.js\";\nimport { solveLinearSystem } from \"./methods/linearSystemSolverScript.js\";\nimport { solveLinearSystemAsync } from \"./methods/linearSystemSolverScript.js\";\nimport { prepareMesh } from \"./mesh/meshUtilsScript.js\";\nimport { assembleFrontPropagationMat } from \"./models/frontPropagationScript.js\";\nimport { assembleGeneralFormPDEMat, assembleGeneralFormPDEFront } from \"./models/generalFormPDEScript.js\";\nimport { assembleHeatConductionMat, assembleHeatConductionFront } from \"./models/heatConductionScript.js\";\nimport { runFrontalSolver } from \"./methods/frontalSolverScript.js\";\nimport { basicLog, debugLog, warnLog, errorLog } from \"./utilities/loggingScript.js\";\n\n/**\n * Class to implement finite element analysis in JavaScript\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} meshConfig - Object containing computational mesh details\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containifng the solution vector and additional mesh information\n */\nexport class FEAScriptModel {\n constructor() {\n this.solverConfig = null;\n this.meshConfig = {};\n this.boundaryConditions = {};\n this.solverMethod = \"lusolve\"; // Default solver method\n this.coefficientFunctions = null; // Add storage for coefficient functions\n warnLog(\n \"FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE\"\n );\n basicLog(\"FEAScriptModel instance created\");\n }\n\n /**\n * Sets the solver configuration\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} [options] - Optional additional configuration\n */\n setSolverConfig(solverConfig, options = {}) {\n this.solverConfig = solverConfig;\n\n // Store coefficient functions if provided\n if (options?.coefficientFunctions) {\n this.coefficientFunctions = options.coefficientFunctions;\n debugLog(\"Coefficient functions set\");\n }\n // Only update if a value is provided, otherwise keep the default\n if (options?.maxIterations !== undefined) {\n this.maxIterations = options.maxIterations;\n }\n if (options?.tolerance !== undefined) {\n this.tolerance = options.tolerance;\n }\n\n debugLog(`Solver config set to: ${solverConfig}`);\n }\n\n setMeshConfig(meshConfig) {\n this.meshConfig = meshConfig;\n debugLog(`Mesh config set with dimensions: ${meshConfig.meshDimension}`);\n }\n\n addBoundaryCondition(boundaryKey, condition) {\n this.boundaryConditions[boundaryKey] = condition;\n debugLog(`Boundary condition added for boundary: ${boundaryKey}, type: ${condition[0]}`);\n }\n\n setSolverMethod(solverMethod) {\n this.solverMethod = solverMethod;\n debugLog(`Solver method set to: ${solverMethod}`);\n }\n\n /**\n * Function to solve the finite element problem synchronously\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing the solution vector and the coordinates of the mesh nodes\n */\n solve(options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n /**\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n let initialSolution = [];\n\n // Prepare the mesh\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n\n // Extract node coordinates from meshData\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n // Select and execute the appropriate solver based on solverConfig\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleHeatConductionFront,\n meshData,\n this.boundaryConditions\n );\n solutionVector = frontalResult.solutionVector;\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n } else if (this.solverConfig === \"frontPropagationScript\") {\n // Initialize eikonalActivationFlag\n let eikonalActivationFlag = 0;\n const eikonalExteralIterations = 5; // Number of incremental steps for the eikonal equation\n\n // Create context object with all necessary properties\n const context = {\n meshData: meshData,\n boundaryConditions: this.boundaryConditions,\n eikonalActivationFlag: eikonalActivationFlag,\n solverMethod: this.solverMethod,\n initialSolution,\n // TODO: Consider using different maxIterations/tolerance for Newton-Raphson and linear solver\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n };\n\n while (eikonalActivationFlag <= 1) {\n // Update the context object with current eikonalActivationFlag\n context.eikonalActivationFlag = eikonalActivationFlag;\n\n // Pass the previous solution as initial guess\n if (solutionVector.length > 0) {\n context.initialSolution = [...solutionVector];\n }\n\n // Solve the assembled non-linear system\n const newtonRaphsonResult = newtonRaphson(assembleFrontPropagationMat, context);\n\n // Extract results\n jacobianMatrix = newtonRaphsonResult.jacobianMatrix;\n residualVector = newtonRaphsonResult.residualVector;\n solutionVector = newtonRaphsonResult.solutionVector;\n\n // Increment for next iteration\n eikonalActivationFlag += 1 / eikonalExteralIterations;\n }\n } else if (this.solverConfig === \"generalFormPDEScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n errorLog(\n \"Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.\"\n );\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(\n meshData,\n this.boundaryConditions,\n this.coefficientFunctions\n ));\n\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n /**\n * Function to solve the finite element problem asynchronously\n * @param {object} computeEngine - The compute engine to use for the asynchronous solver (e.g., a worker or a WebGPU context)\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing the solution vector and the coordinates of the mesh nodes\n */\n async solveAsync(computeEngine, options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n\n if (this.solverMethod === \"jacobi-gpu\") {\n const { solutionVector: x } = await solveLinearSystemAsync(\"jacobi-gpu\", jacobianMatrix, residualVector, {\n computeEngine,\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = x;\n } else {\n // Other async solver\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { initializeFEA, performIsoparametricMapping1D } from \"../mesh/meshUtilsScript.js\";\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the general form PDE model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} coefficientFunctions - Functions A(x), B(x), C(x), D(x) for the PDE\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleGeneralFormPDEMat(meshData, boundaryConditions, coefficientFunctions) {\n basicLog(\"Starting general form PDE matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Extract coefficient functions\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Convert to 0-based indexing\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];\n\n // Source term contribution to residual vector\n residualVector[globalNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n const globalNodeIndex2 = localToGlobalMap[localNodeIndex2];\n\n // Diffusion term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEMat.\");\n // 2D general form PDE - empty for now\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Apply Dirichlet boundary conditions only\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n\n basicLog(\"General form PDE matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the frontal solver matrix for the general form PDE model\n * @param {object} data - Object containing element data for the frontal solver\n * @returns {object} An object containing local Jacobian matrix and residual vector\n */\nexport function assembleGeneralFormPDEFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n coefficientFunctions,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of local Jacobian matrix and residual vector\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n // Source term contribution to local residual vector\n localResidualVector[localNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Diffusion term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEFront.\");\n // 2D general form PDE - empty for now\n }\n\n return {\n localJacobianMatrix,\n localResidualVector,\n ngl,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// External imports\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n// Internal imports\nimport { basicLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to facilitate communication with web workers for FEAScript operations\n */\nexport class FEAScriptWorker {\n /**\n * Constructor to initialize the FEAScriptWorker class\n * Sets up the worker and initializes the workerWrapper.\n */\n constructor() {\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n\n this._initWorker();\n }\n\n /**\n * Function to initialize the web worker and wrap it using Comlink.\n * @private\n * @throws Will throw an error if the worker fails to initialize.\n */\n async _initWorker() {\n try {\n this.worker = new Worker(new URL(\"./wrapperScript.js\", import.meta.url), {\n type: \"module\",\n });\n\n this.worker.onerror = (event) => {\n console.error(\"FEAScriptWorker: Worker error:\", event);\n };\n const workerWrapper = Comlink.wrap(this.worker);\n\n this.feaWorker = await new workerWrapper();\n\n this.isReady = true;\n } catch (error) {\n console.error(\"Failed to initialize worker\", error);\n throw error;\n }\n }\n\n /**\n * Function to ensure that the worker is ready before performing any operations.\n * @private\n * @returns {Promise} Resolves when the worker is ready.\n * @throws Will throw an error if the worker is not ready within the timeout period.\n */\n async _ensureReady() {\n if (this.isReady) return Promise.resolve();\n\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds max\n\n const checkReady = () => {\n attempts++;\n if (this.isReady) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(\"Timeout waiting for worker to be ready\"));\n } else {\n setTimeout(checkReady, 1000);\n }\n };\n checkReady();\n });\n }\n\n /**\n * Function to set the solver configuration in the worker.\n * @param {string} solverConfig - The solver configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setSolverConfig(solverConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver config to: ${solverConfig}`);\n return this.feaWorker.setSolverConfig(solverConfig);\n }\n\n /**\n * Sets the mesh configuration in the worker.\n * @param {object} meshConfig - The mesh configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setMeshConfig(meshConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting mesh config`);\n return this.feaWorker.setMeshConfig(meshConfig);\n }\n\n /**\n * Adds a boundary condition to the worker.\n * @param {string} boundaryKey - The key identifying the boundary.\n * @param {array} condition - The boundary condition to add.\n * @returns {Promise} Resolves when the boundary condition is added.\n */\n async addBoundaryCondition(boundaryKey, condition) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Adding boundary condition for boundary: ${boundaryKey}`);\n return this.feaWorker.addBoundaryCondition(boundaryKey, condition);\n }\n\n /**\n * Sets the solver method in the worker.\n * @param {string} solverMethod - The solver method to set.\n * @returns {Promise} Resolves when the solver method is set.\n */\n async setSolverMethod(solverMethod) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver method to: ${solverMethod}`);\n return this.feaWorker.setSolverMethod(solverMethod);\n }\n\n /**\n * Requests the worker to solve the problem.\n * @returns {Promise} Resolves with the solution result.\n */\n async solve() {\n await this._ensureReady();\n basicLog(\"FEAScriptWorker: Requesting solution from worker...\");\n\n const startTime = performance.now();\n const result = await this.feaWorker.solve();\n const endTime = performance.now();\n\n basicLog(`FEAScriptWorker: Solution completed in ${((endTime - startTime) / 1000).toFixed(2)}s`);\n return result;\n }\n\n /**\n * Retrieves model information from the worker.\n * @returns {Promise} Resolves with the model information.\n */\n async getModelInfo() {\n await this._ensureReady();\n return this.feaWorker.getModelInfo();\n }\n\n /**\n * Sends a ping request to the worker to check its availability.\n * @returns {Promise} Resolves if the worker responds.\n */\n async ping() {\n await this._ensureReady();\n return this.feaWorker.ping();\n }\n\n /**\n * Terminates the worker and cleans up resources.\n */\n terminate() {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements\n * @param {File} file - The Gmsh file to be parsed (.msh version 4.1)\n * @returns {object} The parsed mesh data including node coordinates, element connectivity, and boundary conditions\n */\nconst importGmshQuadTri = async (file) => {\n let result = {\n nodesXCoordinates: [],\n nodesYCoordinates: [],\n nodalNumbering: {\n quadElements: [],\n triangleElements: [],\n },\n boundaryElements: [],\n boundaryConditions: [],\n boundaryNodePairs: {}, // Store boundary node pairs for processing in meshGenerationScript\n gmshV: 0,\n ascii: false,\n fltBytes: \"8\",\n totalNodesX: 0,\n totalNodesY: 0,\n physicalPropMap: [],\n elementTypes: {},\n };\n\n let content = await file.text();\n let lines = content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line !== \"\" && line !== \" \");\n\n let section = \"\";\n let lineIndex = 0;\n\n let nodeEntityBlocks = 0;\n let totalNodes = 0;\n let nodeBlocksProcessed = 0;\n let currentNodeBlock = { numNodes: 0 };\n let nodeTagsCollected = 0;\n let nodeTags = [];\n let nodeCoordinatesCollected = 0;\n\n let elementEntityBlocks = 0;\n let totalElements = 0;\n let elementBlocksProcessed = 0;\n let currentElementBlock = {\n dim: 0,\n tag: 0,\n elementType: 0,\n numElements: 0,\n };\n let elementsProcessedInBlock = 0;\n\n let boundaryElementsByTag = {};\n\n while (lineIndex < lines.length) {\n const line = lines[lineIndex];\n\n if (line === \"$MeshFormat\") {\n section = \"meshFormat\";\n lineIndex++;\n continue;\n } else if (line === \"$EndMeshFormat\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$PhysicalNames\") {\n section = \"physicalNames\";\n lineIndex++;\n continue;\n } else if (line === \"$EndPhysicalNames\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Entities\") {\n section = \"entities\";\n lineIndex++;\n continue;\n } else if (line === \"$EndEntities\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Nodes\") {\n section = \"nodes\";\n lineIndex++;\n continue;\n } else if (line === \"$EndNodes\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Elements\") {\n section = \"elements\";\n lineIndex++;\n continue;\n } else if (line === \"$EndElements\") {\n section = \"\";\n lineIndex++;\n continue;\n }\n\n const parts = line.split(/\\s+/).filter((part) => part !== \"\");\n\n if (section === \"meshFormat\") {\n result.gmshV = parseFloat(parts[0]);\n result.ascii = parts[1] === \"0\";\n result.fltBytes = parts[2];\n } else if (section === \"physicalNames\") {\n if (parts.length >= 3) {\n if (!/^\\d+$/.test(parts[0])) {\n lineIndex++;\n continue;\n }\n\n const dimension = parseInt(parts[0], 10);\n const tag = parseInt(parts[1], 10);\n let name = parts.slice(2).join(\" \");\n name = name.replace(/^\"|\"$/g, \"\");\n\n result.physicalPropMap.push({\n tag,\n dimension,\n name,\n });\n }\n } else if (section === \"nodes\") {\n if (nodeEntityBlocks === 0) {\n nodeEntityBlocks = parseInt(parts[0], 10);\n totalNodes = parseInt(parts[1], 10);\n result.nodesXCoordinates = new Array(totalNodes).fill(0);\n result.nodesYCoordinates = new Array(totalNodes).fill(0);\n lineIndex++;\n continue;\n }\n\n if (nodeBlocksProcessed < nodeEntityBlocks && currentNodeBlock.numNodes === 0) {\n currentNodeBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n parametric: parseInt(parts[2], 10),\n numNodes: parseInt(parts[3], 10),\n };\n\n nodeTags = [];\n nodeTagsCollected = 0;\n nodeCoordinatesCollected = 0;\n\n lineIndex++;\n continue;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n for (let i = 0; i < parts.length && nodeTagsCollected < currentNodeBlock.numNodes; i++) {\n nodeTags.push(parseInt(parts[i], 10));\n nodeTagsCollected++;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n lineIndex++;\n continue;\n }\n\n lineIndex++;\n continue;\n }\n\n if (nodeCoordinatesCollected < currentNodeBlock.numNodes) {\n const nodeTag = nodeTags[nodeCoordinatesCollected] - 1;\n const x = parseFloat(parts[0]);\n const y = parseFloat(parts[1]);\n\n result.nodesXCoordinates[nodeTag] = x;\n result.nodesYCoordinates[nodeTag] = y;\n result.totalNodesX++;\n result.totalNodesY++;\n\n nodeCoordinatesCollected++;\n\n if (nodeCoordinatesCollected === currentNodeBlock.numNodes) {\n nodeBlocksProcessed++;\n currentNodeBlock = { numNodes: 0 };\n }\n }\n } else if (section === \"elements\") {\n if (elementEntityBlocks === 0) {\n elementEntityBlocks = parseInt(parts[0], 10);\n totalElements = parseInt(parts[1], 10);\n lineIndex++;\n continue;\n }\n\n if (elementBlocksProcessed < elementEntityBlocks && currentElementBlock.numElements === 0) {\n currentElementBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n elementType: parseInt(parts[2], 10),\n numElements: parseInt(parts[3], 10),\n };\n\n result.elementTypes[currentElementBlock.elementType] =\n (result.elementTypes[currentElementBlock.elementType] || 0) + currentElementBlock.numElements;\n\n elementsProcessedInBlock = 0;\n lineIndex++;\n continue;\n }\n\n if (elementsProcessedInBlock < currentElementBlock.numElements) {\n const elementTag = parseInt(parts[0], 10);\n const nodeIndices = parts.slice(1).map((idx) => parseInt(idx, 10));\n\n if (currentElementBlock.elementType === 1 || currentElementBlock.elementType === 8) {\n const physicalTag = currentElementBlock.tag;\n\n if (!boundaryElementsByTag[physicalTag]) {\n boundaryElementsByTag[physicalTag] = [];\n }\n\n boundaryElementsByTag[physicalTag].push(nodeIndices);\n\n // Store boundary node pairs for later processing in meshGenerationScript\n if (!result.boundaryNodePairs[physicalTag]) {\n result.boundaryNodePairs[physicalTag] = [];\n }\n result.boundaryNodePairs[physicalTag].push(nodeIndices);\n } else if (currentElementBlock.elementType === 2) {\n // Linear triangle elements (3 nodes)\n result.nodalNumbering.triangleElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 3) {\n // Linear quadrilateral elements (4 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 10) {\n // Quadratic quadrilateral elements (9 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n }\n\n elementsProcessedInBlock++;\n\n if (elementsProcessedInBlock === currentElementBlock.numElements) {\n elementBlocksProcessed++;\n currentElementBlock = { numElements: 0 };\n }\n }\n }\n\n lineIndex++;\n }\n\n // Store boundary conditions information\n result.physicalPropMap.forEach((prop) => {\n if (prop.dimension === 1) {\n const boundaryNodes = boundaryElementsByTag[prop.tag] || [];\n\n if (boundaryNodes.length > 0) {\n result.boundaryConditions.push({\n name: prop.name,\n tag: prop.tag,\n nodes: boundaryNodes,\n });\n }\n }\n });\n\n debugLog(\n `Parsed boundary node pairs by physical tag: ${JSON.stringify(\n result.boundaryNodePairs\n )}. These pairs will be used to identify boundary elements in the mesh.`\n );\n\n return result;\n};\n\nexport { importGmshQuadTri };\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to create plots of the solution vector\n * @param {*} solutionVector - The computed solution vector\n * @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {string} meshDimension - The dimension of the solution\n * @param {string} plotType - The type of plot\n * @param {string} plotDivId - The id of the div where the plot will be rendered\n * @param {string} [meshType=\"structured\"] - Type of mesh: \"structured\" or \"unstructured\"\n */\nexport function plotSolution(\n solutionVector,\n nodesCoordinates,\n solverConfig,\n meshDimension,\n plotType,\n plotDivId,\n meshType = \"structured\"\n) {\n const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;\n\n if (meshDimension === \"1D\" && plotType === \"line\") {\n // Check if solutionVector is a nested array\n let yData;\n if (solutionVector.length > 0 && Array.isArray(solutionVector[0])) {\n yData = solutionVector.map((arr) => arr[0]);\n } else {\n yData = solutionVector;\n }\n let xData = Array.from(nodesXCoordinates);\n\n let lineData = {\n x: xData,\n y: yData,\n mode: \"lines\",\n type: \"scatter\",\n line: { color: \"rgb(219, 64, 82)\", width: 2 },\n name: \"Solution\",\n };\n\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxPlotWidth = Math.max(...xData);\n let zoomFactor = maxWindowWidth / maxPlotWidth;\n let plotWidth = Math.max(zoomFactor * maxPlotWidth, 400);\n let plotHeight = 350;\n\n let layout = {\n title: `line plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"Solution\" },\n margin: { l: 70, r: 40, t: 50, b: 50 },\n };\n\n Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });\n } else if (meshDimension === \"2D\" && plotType === \"contour\") {\n // Use the user-provided mesh type\n const isStructured = meshType === \"structured\";\n\n // For auto-detection (if needed)\n const uniqueXCoords = new Set(nodesXCoordinates).size;\n const uniqueYCoords = new Set(nodesYCoordinates).size;\n\n // Extract scalar values from solution vector\n let zValues;\n if (Array.isArray(solutionVector[0])) {\n zValues = solutionVector.map((val) => val[0]);\n } else {\n zValues = solutionVector;\n }\n\n // Common sizing parameters for both plot types\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxX = Math.max(...nodesXCoordinates);\n let maxY = Math.max(...nodesYCoordinates);\n let aspectRatio = maxY / maxX;\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = plotWidth * aspectRatio * 0.8; // Slightly reduce height for better appearance\n\n // Common layout properties\n let layout = {\n title: `${plotType} plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"y\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n hovermode: \"closest\",\n };\n\n if (isStructured) {\n // Calculate the number of nodes along the x-axis and y-axis\n const numNodesX = uniqueXCoords;\n const numNodesY = uniqueYCoords;\n\n // Reshape the nodesXCoordinates and nodesYCoordinates arrays to match the grid dimensions\n let reshapedXCoordinates = math.reshape(Array.from(nodesXCoordinates), [numNodesX, numNodesY]);\n let reshapedYCoordinates = math.reshape(Array.from(nodesYCoordinates), [numNodesX, numNodesY]);\n\n // Reshape the solution array to match the grid dimensions\n let reshapedSolution = math.reshape(Array.from(solutionVector), [numNodesX, numNodesY]);\n\n // Transpose the reshapedSolution array to get column-wise data\n let transposedSolution = math.transpose(reshapedSolution);\n\n // Create an array for x-coordinates used in the contour plot\n let reshapedXForPlot = [];\n for (let i = 0; i < numNodesX * numNodesY; i += numNodesY) {\n let xValue = nodesXCoordinates[i];\n reshapedXForPlot.push(xValue);\n }\n\n // Create the data structure for the contour plot\n let contourData = {\n z: transposedSolution,\n type: \"contour\",\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n x: reshapedXForPlot,\n y: reshapedYCoordinates[0],\n name: \"Solution Field\",\n };\n\n // Create the plot using Plotly\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n } else {\n // Create an interpolated contour plot for the unstructured mesh\n let contourData = {\n x: nodesXCoordinates,\n y: nodesYCoordinates,\n z: zValues,\n type: \"contour\",\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n name: \"Solution Field\",\n };\n\n // Create the plot using only the contour fill\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nexport { FEAScriptModel } from \"./FEAScript.js\";\nexport { importGmshQuadTri } from \"./readers/gmshReaderScript.js\";\nexport { logSystem } from \"./utilities/loggingScript.js\";\nexport { plotSolution } from \"./visualization/plotSolutionScript.js\";\nexport { FEAScriptWorker } from \"./workers/workerScript.js\";\nexport const printVersion = \"0.1.4\";"],"names":["euclideanNorm","vector","norm","i","length","Math","sqrt","currentLogLevel","debugLog","message","console","log","basicLog","errorLog","proxyMarker","Symbol","createEndpoint","releaseProxy","finalizer","throwMarker","isObject","val","transferHandlers","Map","canHandle","serialize","obj","port1","port2","MessageChannel","expose","deserialize","port","start","wrap","value","serialized","Error","isError","name","stack","Object","assign","ep","globalThis","allowedOrigins","addEventListener","callback","ev","data","origin","allowedOrigin","RegExp","test","isAllowedOrigin","warn","id","type","path","argumentList","map","fromWireValue","returnValue","parent","slice","reduce","prop","rawValue","apply","proxy","transfers","transferCache","set","transfer","undefined","Promise","resolve","catch","then","wireValue","transferables","toWireValue","postMessage","removeEventListener","closeEndPoint","error","TypeError","endpoint","constructor","isMessagePort","close","target","pendingListeners","resolver","get","delete","createProxy","throwIfProxyReleased","isReleased","releaseEndpoint","requestResponseMessage","proxyCounter","WeakMap","proxyFinalizers","FinalizationRegistry","newCount","isProxyReleased","Proxy","_target","unregister","unregisterProxy","clear","r","p","toString","bind","_thisArg","rawArgumentList","last","processArguments","construct","register","registerProxy","processed","v","arr","Array","prototype","concat","handler","serializedValue","msg","fill","floor","random","Number","MAX_SAFE_INTEGER","join","solveLinearSystem","solverMethod","jacobianMatrix","residualVector","options","maxIterations","tolerance","solutionVector","converged","iterations","time","jacobianMatrixSparse","math","sparse","luFactorization","slu","solutionMatrix","lusolve","squeeze","valueOf","jacobiSolverResult","A","b","x0","n","x","xNew","iter","sum","j","maxDiff","max","abs","jacobiSolver","timeEnd","async","solveLinearSystemAsync","isArray","toArray","created","computeEngine","worker","Worker","URL","document","require","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","Comlink.wrap","initialize","createDefaultComputeEngine","result","webgpuJacobiSolver","destroy","terminate","BasisFunctions","meshDimension","elementOrder","this","getBasisFunctions","ksi","eta","basisFunction","basisFunctionDerivKsi","basisFunctionDerivEta","l1","c","l2","l3","dl1","dl2","dl3","Mesh","numElementsX","maxX","numElementsY","maxY","parsedMesh","boundaryElementsProcessed","parseMeshFromGmsh","nodalNumbering","quadElements","triangleElements","JSON","stringify","elementTypes","mappedNodalNumbering","elemIdx","gmshNodes","feaScriptNodes","push","physicalPropMap","boundaryElements","fixedBoundaryElements","boundaryNodePairs","forEach","dimension","tag","nodesPair","node1","node2","foundElement","elemNodes","includes","side","node1Index","indexOf","node2Index","Mesh1D","super","generateMesh","nodesXCoordinates","totalNodesX","deltaX","nodeIndex","generate1DNodalNumbering","findBoundaryElements","nop","elementIndex","columnCounter","sideIndex","Mesh2D","nodesYCoordinates","totalNodesY","deltaY","nodeIndexY","nodeIndexX","nnode","generate2DNodalNumbering","rowCounter","elementIndexX","elementIndexY","nodeIndex1","nodeIndex2","NumericalIntegration","getGaussPointsAndWeights","gaussPoints","gaussWeights","prepareMesh","meshConfig","mesh","nodesCoordinatesAndNumbering","totalElements","totalNodes","initializeFEA","meshData","colIndex","basisFunctions","gaussPointsAndWeights","localToGlobalMap","numNodes","performIsoparametricMapping1D","params","xCoordinates","ksiDerivX","localNodeIndex","detJacobian","basisFunctionDerivX","performIsoparametricMapping2D","yCoordinates","etaDerivX","ksiDerivY","etaDerivY","basisFunctionDerivY","ThermalBoundaryConditions","boundaryConditions","imposeConstantTempBoundaryConditions","keys","boundaryKey","tempValue","globalNodeIndex","imposeConstantTempBoundaryConditionsFront","nodeConstraintCode","boundaryValues","imposeConvectionBoundaryConditions","convectionHeatTranfCoeff","convectionExtTemp","key","boundaryCondition","convectionCoeff","extTemp","gaussPoint1","gaussPoint2","firstNodeIndex","lastNodeIndex","nodeIncrement","basisFunctionsAndDerivatives","tangentVectorLength","localNodeIndex2","globalNodeIndex2","gaussPointIndex","imposeConvectionBoundaryConditionsFront","localJacobianMatrix","localResidualVector","boundaryElement","find","_","assembleHeatConductionMat","FEAData","gaussPointIndex1","mappingResult","localNodeIndex1","localToGlobalMap1","localToGlobalMap2","gaussPointIndex2","thermalBoundaryConditions","assembleHeatConductionFront","ngl","globalIndex","GenericBoundaryConditions","imposeDirichletBoundaryConditions","imposeConstantValueBoundaryConditionsFront","assembleFrontPropagationMat","eikonalActivationFlag","eikonalViscousTerm","solutionDerivX","solutionDerivY","assembleFrontPropagationFront","frontalData","frontalState","elementData","currentElementIndex","frontStorage","runFrontalSolver","assembleFront","numElements","globalResidualVector","topologyData","lateralData","writeFlag","transformationFlag","nodesPerElement","determinant","systemSize","globalSolutionVector","frontDataIndex","frontSize","frontWidthEstimate","ceil","estimateFrontSize","frontValues","columnHeaders","pivotRow","pivotData","initializeFrontalArrays","dirichletBoundaryConditionsHandler","currentSolutionVector","pivotColumnGlobalIndex","localDestination","rowDestination","rowHeaders","pivotRowIndices","pivotColumnIndices","modifiedRows","pivotColumn","frontMatrix","rowSwapCount","columnSwapCount","lastAppearanceCheck","frontDataCounter","pivotDataIndex","summedRows","reverseElementIndex","columnCount","rowCount","assembled","numElementNodes","numElementColumns","assembleElementContribution","currentElement","columnIndex","rowIndex","localColumnIndex","frontColumnIndex","localRowIndex","availableColumnCount","constrainedRowCount","availableRowCount","absoluteNodeIndex","constrainedIndex","pivotRowIndex","pivotColumnIndex","pivotValue","testColumnIndex","testRowIndex","testValue","pivotGlobalRowIndex","permutationHelper","rightHandSide","globalRowIndex","eliminationFactor","performBackSubstitution","runFrontalAlgorithm","toExponential","finalNodesX","finalNodesY","nodesCoordinates","boundaryLocalJacobianMatrix","boundaryResidualVector","isOnRobinTypeBoundary","some","localNodeI","localNodeJ","iterationIndex","accumulatedValue","newtonRaphson","assembleMat","context","errorNorm","initialSolution","solverConfig","coefficientFunctions","setSolverConfig","setMeshConfig","addBoundaryCondition","condition","setSolverMethod","solve","eikonalExteralIterations","newtonRaphsonResult","B","C","D","xCoord","a","d","globalNodeIndex1","assembleGeneralFormPDEMat","solveAsync","feaWorker","isReady","_initWorker","onerror","event","workerWrapper","_ensureReady","reject","attempts","checkReady","setTimeout","startTime","performance","now","toFixed","getModelInfo","ping","file","gmshV","ascii","fltBytes","lines","text","split","line","trim","filter","section","lineIndex","nodeEntityBlocks","nodeBlocksProcessed","currentNodeBlock","nodeTagsCollected","nodeTags","nodeCoordinatesCollected","elementEntityBlocks","elementBlocksProcessed","currentElementBlock","dim","elementType","elementsProcessedInBlock","boundaryElementsByTag","parts","part","parseFloat","parseInt","replace","parametric","nodeTag","y","nodeIndices","idx","physicalTag","boundaryNodes","nodes","level","plotType","plotDivId","meshType","yData","xData","from","lineData","mode","color","width","maxWindowWidth","min","window","innerWidth","maxPlotWidth","zoomFactor","layout","title","height","xaxis","yaxis","margin","l","t","Plotly","newPlot","responsive","isStructured","uniqueXCoords","Set","size","uniqueYCoords","zValues","aspectRatio","plotWidth","hovermode","numNodesX","numNodesY","reshape","reshapedYCoordinates","reshapedSolution","transposedSolution","transpose","reshapedXForPlot","xValue","contourData","z","contours","coloring","showlabels","colorbar"],"mappings":"AAaO,SAASA,EAAcC,GAC5B,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,OAAQD,IACjCD,GAAQD,EAAOE,GAAKF,EAAOE,GAG7B,OADAD,EAAOG,KAAKC,KAAKJ,GACVA,CACT,wDCXA,IAAIK,EAAkB,QAuBf,SAASC,EAASC,GACC,UAApBF,GACFG,QAAQC,IAAI,aAAeF,EAAS,qCAExC,CAMO,SAASG,EAASH,GACvBC,QAAQC,IAAI,YAAcF,EAAS,qCACrC,CAMO,SAASI,EAASJ,GACvBC,QAAQC,IAAI,aAAeF,EAAS,qCACtC;;;;;;AC/CA,MAAMK,EAAcC,OAAO,iBACrBC,EAAiBD,OAAO,oBACxBE,EAAeF,OAAO,wBACtBG,EAAYH,OAAO,q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AG,GAAIub,EAAG,GAAIvY,EAAG,IAClCmZ,UAAW,WAGb,GAAIR,EAAc,CAEhB,MAAMS,EAAYR,EACZS,EAAYN,EAGSzZ,KAAKga,QAAQxb,MAAMuZ,KAAKvR,GAAoB,CAACsT,EAAWC,IACnF,IAAIE,EAAuBja,KAAKga,QAAQxb,MAAMuZ,KAAK5Q,GAAoB,CAAC2S,EAAWC,IAG/EG,EAAmBla,KAAKga,QAAQxb,MAAMuZ,KAAKpY,GAAiB,CAACma,EAAWC,IAGxEI,EAAqBna,KAAKoa,UAAUF,GAGpCG,EAAmB,GACvB,IAAK,IAAIxjB,EAAI,EAAGA,EAAIijB,EAAYC,EAAWljB,GAAKkjB,EAAW,CACzD,IAAIO,EAAS9T,EAAkB3P,GAC/BwjB,EAAiBlV,KAAKmV,EACvB,CAGD,IAAIC,EAAc,CAChBC,EAAGL,EACHhgB,KAAM,UACNsgB,SAAU,CACRC,SAAU,UACVC,YAAY,GAGdC,SAAU,CACRjC,MAAO,YAET9X,EAAGwZ,EACHlD,EAAG8C,EAAqB,GACxBhhB,KAAM,kBAIRigB,OAAOC,QAAQxB,EAAW,CAAC4C,GAAc7B,EAAQ,CAAEU,YAAY,GACrE,KAAW,CAEL,IAAImB,EAAc,CAChB1Z,EAAG2F,EACH2Q,EAAGhQ,EACHqT,EAAGd,EACHvf,KAAM,UACNsgB,SAAU,CACRC,SAAU,UACVC,YAAY,GAGdC,SAAU,CACRjC,MAAO,YAET1f,KAAM,kBAIRigB,OAAOC,QAAQxB,EAAW,CAAC4C,GAAc7B,EAAQ,CAAEU,YAAY,GAChE,CACF,CACH,uBCrJ4B"} \ No newline at end of file +{"version":3,"file":"feascript.cjs.js","sources":["../src/methods/euclideanNormScript.js","../src/utilities/loggingScript.js","../src/vendor/comlink.mjs","../src/methods/linearSystemSolverScript.js","../src/methods/jacobiSolverScript.js","../src/mesh/basisFunctionsScript.js","../src/mesh/meshGenerationScript.js","../src/methods/numericalIntegrationScript.js","../src/mesh/meshUtilsScript.js","../src/models/thermalBoundaryConditionsScript.js","../src/models/heatConductionScript.js","../src/models/genericBoundaryConditionsScript.js","../src/models/frontPropagationScript.js","../src/methods/frontalSolverScript.js","../src/methods/newtonRaphsonScript.js","../src/FEAScript.js","../src/models/generalFormPDEScript.js","../src/workers/workerScript.js","../src/readers/gmshReaderScript.js","../src/visualization/plotSolutionScript.js","../src/index.js"],"sourcesContent":["/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to calculate the Euclidean norm of a vector\n * @param {array} vector - The input vector\n * @returns {number} The Euclidean norm of the vector\n */\nexport function euclideanNorm(vector) {\n let norm = 0;\n for (let i = 0; i < vector.length; i++) {\n norm += vector[i] * vector[i];\n }\n norm = Math.sqrt(norm);\n return norm;\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Global logging level\nlet currentLogLevel = \"basic\";\n\n/**\n * Function to set the logging system level\n * @param {string} level - Logging level (basic, debug)\n */\nexport function logSystem(level) {\n if (level !== \"basic\" && level !== \"debug\") {\n console.log(\n \"%c[WARN] Invalid log level: \" + level + \". Using basic instead.\",\n \"color: #FFC107; font-weight: bold;\"\n ); // Yellow for warnings\n currentLogLevel = \"basic\";\n } else {\n currentLogLevel = level;\n basicLog(`Log level set to: ${level}`);\n }\n}\n\n/**\n * Function to log debug messages - only logs if level is 'debug'\n * @param {string} message - Message to log\n */\nexport function debugLog(message) {\n if (currentLogLevel === \"debug\") {\n console.log(\"%c[DEBUG] \" + message, \"color: #2196F3; font-weight: bold;\");\n }\n}\n\n/**\n * Function to log basic information - always logs\n * @param {string} message - Message to log\n */\nexport function basicLog(message) {\n console.log(\"%c[INFO] \" + message, \"color: #4CAF50; font-weight: bold;\");\n}\n\n/**\n * Function to log error messages\n * @param {string} message - Message to log\n */\nexport function errorLog(message) {\n console.log(\"%c[ERROR] \" + message, \"color: #F44336; font-weight: bold;\");\n}\n\n/**\n * Function to log warning messages\n * @param {string} message - Message to log\n */\nexport function warnLog(message) {\n console.log(\"%c[WARN] \" + message, \"color: #FF9800; font-weight: bold;\");\n}\n\n/**\n * Function to handle version information and fetch the latest update date and release from GitHub\n */\nexport async function printVersionInformation() {\n basicLog(\"Fetching latest FEAScript version information...\");\n try {\n const commitResponse = await fetch(\"https://api.github.com/repos/FEAScript/FEAScript/commits/main\");\n const commitData = await commitResponse.json();\n const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();\n basicLog(`Latest FEAScript update: ${latestCommitDate}`);\n return latestCommitDate;\n } catch (error) {\n errorLog(\"Failed to fetch version information: \" + error);\n return \"Version information unavailable\";\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\nconst proxyMarker = Symbol(\"Comlink.proxy\");\nconst createEndpoint = Symbol(\"Comlink.endpoint\");\nconst releaseProxy = Symbol(\"Comlink.releaseProxy\");\nconst finalizer = Symbol(\"Comlink.finalizer\");\nconst throwMarker = Symbol(\"Comlink.thrown\");\nconst isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n};\n/**\n * Allows customizing the serialization of certain values.\n */\nconst transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\nfunction isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\nfunction expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n}\nfunction isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n}\nfunction closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n}\nfunction wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n}\nfunction throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\nfunction releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\nconst proxyCounter = new WeakMap();\nconst proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\nfunction registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\nfunction unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\nfunction createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n}\nfunction myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n}\nfunction processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\nconst transferCache = new WeakMap();\nfunction transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n}\nfunction proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n}\nfunction windowEndpoint(w, context = globalThis, targetOrigin = \"*\") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\nfunction toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\nfunction fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n}\nfunction requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n}\nfunction generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n\nexport { createEndpoint, expose, finalizer, proxy, proxyMarker, releaseProxy, transfer, transferHandlers, windowEndpoint, wrap };\n//# sourceMappingURL=comlink.mjs.map\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { jacobiSolver } from \"./jacobiSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n/**\n * Function to solve a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (\"lusolve\" or \"jacobi\")\n * @param {Array} jacobianMatrix - The coefficient matrix\n * @param {Array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {\n\n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n let solutionVector = [];\n let converged = true;\n let iterations = 0;\n\n // Solve the linear system based on the specified solver method\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n if (solverMethod === \"lusolve\") {\n // Use LU decomposition method\n const jacobianMatrixSparse = math.sparse(jacobianMatrix);\n const luFactorization = math.slu(jacobianMatrixSparse, 1, 1); // order=1, threshold=1 for pivoting\n let solutionMatrix = math.lusolve(luFactorization, residualVector);\n solutionVector = math.squeeze(solutionMatrix).valueOf();\n //solutionVector = math.lusolve(jacobianMatrix, residualVector); // In the case of a dense matrix\n } else if (solverMethod === \"jacobi\") {\n // Use Jacobi method\n const initialGuess = new Array(residualVector.length).fill(0);\n const jacobiSolverResult = jacobiSolver(jacobianMatrix, residualVector, initialGuess, {\n maxIterations,\n tolerance,\n });\n\n // Log convergence information\n if (jacobiSolverResult.converged) {\n debugLog(`Jacobi method converged in ${jacobiSolverResult.iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${jacobiSolverResult.iterations} iterations`);\n }\n\n solutionVector = jacobiSolverResult.solutionVector;\n converged = jacobiSolverResult.converged;\n iterations = jacobiSolverResult.iterations;\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n return { solutionVector, converged, iterations };\n}\n\n// Helper to lazily create a default WebGPU compute engine (Comlink + worker)\nasync function createDefaultComputeEngine() {\n const worker = new Worker(new URL(\"../workers/webgpuWorkerScript.js\", import.meta.url), {\n type: \"module\",\n });\n const computeEngine = Comlink.wrap(worker);\n await computeEngine.initialize();\n return { computeEngine, worker };\n}\n\n/**\n * Function to solve asynchronously a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (e.g., \"jacobi-gpu\")\n * @param {array} jacobianMatrix - The coefficient matrix\n * @param {array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport async function solveLinearSystemAsync(solverMethod, jacobianMatrix, residualVector, options = {}) {\n \n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n // Normalize inputs\n const A = Array.isArray(jacobianMatrix) ? jacobianMatrix : jacobianMatrix?.toArray?.() ?? jacobianMatrix;\n const b = Array.isArray(residualVector) ? residualVector : residualVector?.toArray?.() ?? residualVector;\n\n let created = null;\n let computeEngine = null;\n\n let solutionVector = [];\n let converged = true;\n let iterations;\n\n if (solverMethod === \"jacobi-gpu\") {\n // Spin up a worker-backed compute engine\n created = await createDefaultComputeEngine();\n computeEngine = created.computeEngine;\n\n const x0 = new Array(b.length).fill(0);\n let result;\n\n result = await computeEngine.webgpuJacobiSolver(A, b, x0, { maxIterations, tolerance });\n solutionVector = result.solutionVector;\n converged = result.converged;\n iterations = result.iterations;\n\n // Log convergence information\n if (converged) {\n debugLog(`Jacobi method converged in ${iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${iterations} iterations`);\n }\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(`System solved successfully (${solverMethod})`);\n\n if (created) {\n await computeEngine?.destroy?.().catch(() => { });\n created.worker.terminate();\n }\n\n return { solutionVector, converged, iterations };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to solve a system of linear equations using the Jacobi iterative method (CPU synchronous version)\n * @param {array} A - The system matrix\n * @param {array} b - The right-hand side vector\n * @param {array} x0 - Initial guess for solution vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\nexport function jacobiSolver(A, b, x0, options = {}) {\n // Extract options\n const { maxIterations, tolerance } = options;\n\n const n = A.length;\n let x = [...x0];\n let xNew = new Array(n);\n\n // Jacobi update: xNew[i] = (b[i] - sum(A[i][j] * x[j] for j != i)) / A[i][i]\n for (let iter = 0; iter < maxIterations; iter++) {\n for (let i = 0; i < n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (i !== j) {\n sum += A[i][j] * x[j];\n }\n }\n xNew[i] = (b[i] - sum) / A[i][i];\n }\n\n // Check convergence based on maximum difference in solution vector\n let maxDiff = 0;\n for (let i = 0; i < n; i++) {\n maxDiff = Math.max(maxDiff, Math.abs(xNew[i] - x[i]));\n }\n\n // Copy new solution for the next iteration\n x = [...xNew];\n\n if (maxDiff < tolerance) {\n return { solutionVector: x, iterations: iter + 1, converged: true };\n }\n }\n\n return { solutionVector: x, iterations: maxIterations, converged: false };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle basis functions and their derivatives based on element configuration\n */\nexport class BasisFunctions {\n /**\n * Constructor to initialize the BasisFunctions class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to calculate basis functions and their derivatives based on the dimension and order\n * @param {number} ksi - Natural coordinate (for both 1D and 2D)\n * @param {number} [eta] - Second natural coordinate (only for 2D elements)\n * @returns {object} An object containing:\n * - basisFunction: Array of evaluated basis functions\n * - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi\n * - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)\n */\n getBasisFunctions(ksi, eta = null) {\n let basisFunction = [];\n let basisFunctionDerivKsi = [];\n let basisFunctionDerivEta = [];\n\n if (this.meshDimension === \"1D\") {\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 1D elements\n basisFunction[0] = 1 - ksi;\n basisFunction[1] = ksi;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -1;\n basisFunctionDerivKsi[1] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 1D elements\n basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;\n basisFunction[1] = 4 * ksi - 4 * ksi ** 2;\n basisFunction[2] = -ksi + 2 * ksi ** 2;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -3 + 4 * ksi;\n basisFunctionDerivKsi[1] = 4 - 8 * ksi;\n basisFunctionDerivKsi[2] = -1 + 4 * ksi;\n }\n } else if (this.meshDimension === \"2D\") {\n if (eta === null) {\n errorLog(\"Eta coordinate is required for 2D elements\");\n return;\n }\n\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 2D elements\n function l1(c) {\n return 1 - c;\n }\n function l2(c) {\n return c;\n }\n function dl1() {\n return -1;\n }\n function dl2() {\n return 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l2(ksi) * l1(eta);\n basisFunction[3] = l2(ksi) * l2(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1() * l1(eta);\n basisFunctionDerivKsi[1] = dl1() * l2(eta);\n basisFunctionDerivKsi[2] = dl2() * l1(eta);\n basisFunctionDerivKsi[3] = dl2() * l2(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1();\n basisFunctionDerivEta[1] = l1(ksi) * dl2();\n basisFunctionDerivEta[2] = l2(ksi) * dl1();\n basisFunctionDerivEta[3] = l2(ksi) * dl2();\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 2D elements\n function l1(c) {\n return 2 * c ** 2 - 3 * c + 1;\n }\n function l2(c) {\n return -4 * c ** 2 + 4 * c;\n }\n function l3(c) {\n return 2 * c ** 2 - c;\n }\n function dl1(c) {\n return 4 * c - 3;\n }\n function dl2(c) {\n return -8 * c + 4;\n }\n function dl3(c) {\n return 4 * c - 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l1(ksi) * l3(eta);\n basisFunction[3] = l2(ksi) * l1(eta);\n basisFunction[4] = l2(ksi) * l2(eta);\n basisFunction[5] = l2(ksi) * l3(eta);\n basisFunction[6] = l3(ksi) * l1(eta);\n basisFunction[7] = l3(ksi) * l2(eta);\n basisFunction[8] = l3(ksi) * l3(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);\n basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);\n basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);\n basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);\n basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);\n basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);\n basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);\n basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);\n basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);\n basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);\n basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);\n basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);\n basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);\n basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);\n basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);\n basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);\n basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);\n }\n }\n\n return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Basic structure for the mesh\n */\nexport class Mesh {\n /**\n * Constructor to initialize the Mesh class\n * @param {object} config - Configuration object for the mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)\n * @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)\n * @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n meshDimension = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n this.numElementsX = numElementsX;\n this.numElementsY = numElementsY;\n this.maxX = maxX;\n this.maxY = maxY;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n this.parsedMesh = parsedMesh;\n\n this.boundaryElementsProcessed = false;\n\n if (this.parsedMesh) {\n basicLog(\"Using pre-parsed mesh from gmshReader data for mesh generation.\");\n this.parseMeshFromGmsh();\n }\n }\n\n /**\n * Method to parse the mesh from the GMSH format to the FEAScript format\n */\n parseMeshFromGmsh() {\n if (!this.parsedMesh.nodalNumbering) {\n errorLog(\"No valid nodal numbering found in the parsed mesh.\");\n }\n\n if (\n typeof this.parsedMesh.nodalNumbering === \"object\" &&\n !Array.isArray(this.parsedMesh.nodalNumbering)\n ) {\n // Store the nodal numbering structure before converting\n const quadElements = this.parsedMesh.nodalNumbering.quadElements || [];\n const triangleElements = this.parsedMesh.nodalNumbering.triangleElements || [];\n\n debugLog(\n \"Initial parsed mesh nodal numbering from GMSH format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Check if it has quadElements or triangleElements structure from gmshReader\n if (this.parsedMesh.elementTypes[3] || this.parsedMesh.elementTypes[10]) {\n // Map nodal numbering from GMSH format to FEAScript format for quad elements\n const mappedNodalNumbering = [];\n\n for (let elemIdx = 0; elemIdx < quadElements.length; elemIdx++) {\n const gmshNodes = quadElements[elemIdx];\n const feaScriptNodes = new Array(gmshNodes.length);\n\n // Check for element type based on number of nodes\n if (gmshNodes.length === 4) {\n // Simple mapping for linear quad elements (4 nodes)\n // GMSH: FEAScript:\n // 3 --- 2 1 --- 3\n // | | --> | |\n // 0 --- 1 0 --- 2\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[3]; // 3 -> 1\n feaScriptNodes[2] = gmshNodes[1]; // 1 -> 2\n feaScriptNodes[3] = gmshNodes[2]; // 2 -> 3\n } else if (gmshNodes.length === 9) {\n // Mapping for quadratic quad elements (9 nodes)\n // GMSH: FEAScript:\n // 3--6--2 2--5--8\n // | | | |\n // 7 8 5 --> 1 4 7\n // | | | |\n // 0--4--1 0--3--6\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[7]; // 7 -> 1\n feaScriptNodes[2] = gmshNodes[3]; // 3 -> 2\n feaScriptNodes[3] = gmshNodes[4]; // 4 -> 3\n feaScriptNodes[4] = gmshNodes[8]; // 8 -> 4\n feaScriptNodes[5] = gmshNodes[6]; // 6 -> 5\n feaScriptNodes[6] = gmshNodes[1]; // 1 -> 6\n feaScriptNodes[7] = gmshNodes[5]; // 5 -> 7\n feaScriptNodes[8] = gmshNodes[2]; // 2 -> 8\n }\n\n mappedNodalNumbering.push(feaScriptNodes);\n }\n\n this.parsedMesh.nodalNumbering = mappedNodalNumbering;\n } else if (this.parsedMesh.elementTypes[2]) {\n errorLog(\"Element type is neither triangle nor quad; mapping for this type is not implemented yet.\");\n }\n\n debugLog(\n \"Nodal numbering after mapping from GMSH to FEAScript format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Process boundary elements if they exist and if physical property mapping exists\n if (this.parsedMesh.physicalPropMap && this.parsedMesh.boundaryElements) {\n // Check if boundary elements need to be processed\n if (\n Array.isArray(this.parsedMesh.boundaryElements) &&\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n // Create a new array without the empty first element\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n\n // If boundary node pairs exist but boundary elements haven't been processed\n if (this.parsedMesh.boundaryNodePairs && !this.parsedMesh.boundaryElementsProcessed) {\n // Reset boundary elements array\n this.parsedMesh.boundaryElements = [];\n\n // Process each physical property from the Gmsh file\n this.parsedMesh.physicalPropMap.forEach((prop) => {\n // Only process 1D physical entities (boundary lines)\n if (prop.dimension === 1) {\n // Get all node pairs for this boundary\n const boundaryNodePairs = this.parsedMesh.boundaryNodePairs[prop.tag] || [];\n\n if (boundaryNodePairs.length > 0) {\n // Initialize array for this boundary tag\n if (!this.parsedMesh.boundaryElements[prop.tag]) {\n this.parsedMesh.boundaryElements[prop.tag] = [];\n }\n\n // For each boundary line segment (defined by a pair of nodes)\n boundaryNodePairs.forEach((nodesPair) => {\n const node1 = nodesPair[0]; // First node in the pair\n const node2 = nodesPair[1]; // Second node in the pair\n\n debugLog(\n `Processing boundary node pair: [${node1}, ${node2}] for boundary ${prop.tag} (${\n prop.name || \"unnamed\"\n })`\n );\n\n // Search through all elements to find which one contains both nodes\n let foundElement = false;\n\n // Loop through all elements in the mesh\n for (let elemIdx = 0; elemIdx < this.parsedMesh.nodalNumbering.length; elemIdx++) {\n const elemNodes = this.parsedMesh.nodalNumbering[elemIdx];\n\n // For linear quadrilateral linear elements (4 nodes)\n if (elemNodes.length === 4) {\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript linear quadrilateral numbering:\n // 1 --- 3\n // | |\n // 0 --- 2\n\n if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0)\n ) {\n side = 0; // Bottom side\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0)\n ) {\n side = 1; // Left side\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 1 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 1)\n ) {\n side = 2; // Top side\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 2)\n ) {\n side = 3; // Right side\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n } else if (elemNodes.length === 9) {\n // For quadratic quadrilateral elements (9 nodes)\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript quadratic quadrilateral numbering:\n // 2--5--8\n // | |\n // 1 4 7\n // | |\n // 0--3--6\n\n // TODO: Transform into dictionaries for better readability\n if (\n (node1Index === 0 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 0) ||\n (node1Index === 3 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 3)\n ) {\n side = 0; // Bottom side (nodes 0, 3, 6)\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0) ||\n (node1Index === 1 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 1)\n ) {\n side = 1; // Left side (nodes 0, 1, 2)\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 5) ||\n (node1Index === 5 && node2Index === 2) ||\n (node1Index === 5 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 5)\n ) {\n side = 2; // Top side (nodes 2, 5, 8)\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 6 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 7) ||\n (node1Index === 7 && node2Index === 6) ||\n (node1Index === 7 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 7)\n ) {\n side = 3; // Right side (nodes 6, 7, 8)\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n }\n }\n\n if (!foundElement) {\n errorLog(\n `Could not find element containing boundary nodes ${node1} and ${node2}. Boundary may be incomplete.`\n );\n }\n });\n }\n }\n });\n\n // Mark as processed\n this.boundaryElementsProcessed = true;\n\n // Fix boundary elements array - remove undefined entries\n if (\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n }\n }\n }\n\n return this.parsedMesh;\n }\n}\n\nexport class Mesh1D extends Mesh {\n /**\n * Constructor to initialize the 1D mesh\n * @param {object} config - Configuration object for the 1D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({ numElementsX = null, maxX = null, elementOrder = \"linear\", parsedMesh = null }) {\n super({\n numElementsX,\n maxX,\n numElementsY: 1,\n maxY: 0,\n meshDimension: \"1D\",\n elementOrder,\n parsedMesh,\n });\n\n if (this.numElementsX === null || this.maxX === null) {\n errorLog(\"numElementsX and maxX are required parameters when generating a 1D mesh from geometry\");\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n const xStart = 0;\n let totalNodesX, deltaX;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX;\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX / 2;\n }\n }\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate1DNodalNumbering(this.numElementsX, totalNodesX, this.elementOrder);\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n\n // Return x coordinates of nodes, total nodes, NOP array, and boundary elements\n return {\n nodesXCoordinates,\n totalNodesX,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate1DNodalNumbering(numElementsX, totalNodesX, elementOrder) {\n // TODO: The totalNodesX is not used in the original function. Verify if\n // there is a multiple calculation on the totalNodes.\n\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear 1D elements with the following nodes representation:\n *\n * 1 --- 2\n *\n */\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic 1D elements with the following nodes representation:\n *\n * 1--2--3\n *\n */\n let columnCounter = 0;\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex + columnCounter;\n }\n columnCounter += 1;\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 1D domains (line segments):\n * 0 - Left node of reference element (maps to physical left endpoint)\n * 1 - Right node of reference element (maps to physical right endpoint)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 2; // For 1D, we only have two sides (left and right)\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // Left boundary (element 0, side 0)\n boundaryElements[0].push([0, 0]);\n\n // Right boundary (last element, side 1)\n boundaryElements[1].push([this.numElementsX - 1, 1]);\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n\nexport class Mesh2D extends Mesh {\n /**\n * Constructor to initialize the 2D mesh\n * @param {object} config - Configuration object for the 2D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY] - Number of elements along the y-axis (required for geometry-based mesh)\n * @param {number} [config.maxY] - Maximum y-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n super({\n numElementsX,\n maxX,\n numElementsY,\n maxY,\n meshDimension: \"2D\",\n elementOrder,\n parsedMesh,\n });\n\n // Validate geometry parameters (when not using a parsed mesh)\n if (\n !parsedMesh &&\n (this.numElementsX === null || this.maxX === null || this.numElementsY === null || this.maxY === null)\n ) {\n errorLog(\n \"numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry\"\n );\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n let nodesYCoordinates = [];\n const xStart = 0;\n const yStart = 0;\n let totalNodesX, totalNodesY, deltaX, deltaY;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n totalNodesY = this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + nodeIndexY * deltaY;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + nodeIndexX * deltaX;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + nodeIndexY * deltaY;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n totalNodesY = 2 * this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;\n }\n }\n }\n\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate2DNodalNumbering(\n this.numElementsX,\n this.numElementsY,\n totalNodesY,\n this.elementOrder\n );\n\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n debugLog(\"Generated node Y coordinates: \" + JSON.stringify(nodesYCoordinates));\n\n // Return statement\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate2DNodalNumbering(numElementsX, numElementsY, totalNodesY, elementOrder) {\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear rectangular elements with the following nodes representation:\n *\n * 1 --- 3\n * | |\n * 0 --- 2\n *\n */\n let rowCounter = 0;\n let columnCounter = 2;\n for (let elementIndex = 0; elementIndex < numElementsX * numElementsY; elementIndex++) {\n rowCounter += 1;\n nop[elementIndex] = [];\n nop[elementIndex][0] = elementIndex + columnCounter - 1;\n nop[elementIndex][1] = elementIndex + columnCounter;\n nop[elementIndex][2] = elementIndex + columnCounter + numElementsY;\n nop[elementIndex][3] = elementIndex + columnCounter + numElementsY + 1;\n if (rowCounter === numElementsY) {\n columnCounter += 1;\n rowCounter = 0;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic rectangular elements with the following nodes representation:\n *\n * 2--5--8\n * | |\n * 1 4 7\n * | |\n * 0--3--6\n *\n */\n for (let elementIndexX = 1; elementIndexX <= numElementsX; elementIndexX++) {\n for (let elementIndexY = 1; elementIndexY <= numElementsY; elementIndexY++) {\n nop[elementIndex] = [];\n for (let nodeIndex1 = 1; nodeIndex1 <= 3; nodeIndex1++) {\n let nodeIndex2 = 3 * nodeIndex1 - 2;\n nop[elementIndex][nodeIndex2 - 1] =\n totalNodesY * (2 * elementIndexX + nodeIndex1 - 3) + 2 * elementIndexY - 1;\n nop[elementIndex][nodeIndex2] = nop[elementIndex][nodeIndex2 - 1] + 1;\n nop[elementIndex][nodeIndex2 + 1] = nop[elementIndex][nodeIndex2 - 1] + 2;\n }\n elementIndex = elementIndex + 1;\n }\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 2D domains (rectangular):\n * 0 - Bottom side of reference element (maps to physical bottom boundary)\n * 1 - Left side of reference element (maps to physical left boundary)\n * 2 - Top side of reference element (maps to physical top boundary)\n * 3 - Right side of reference element (maps to physical right boundary)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 4; // For 2D, we have four sides (left, right, bottom, top)\n\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // TODO: Why to loop through all elements? Is it not better to loop over only the\n // elements that are on the boundary? eg: [0, this.numElementsX - 1] on x and\n // [0, this.numElementsY - 1] on y\n for (let elementIndexX = 0; elementIndexX < this.numElementsX; elementIndexX++) {\n for (let elementIndexY = 0; elementIndexY < this.numElementsY; elementIndexY++) {\n const elementIndex = elementIndexX * this.numElementsY + elementIndexY;\n\n // Bottom boundary\n if (elementIndexY === 0) {\n boundaryElements[0].push([elementIndex, 0]);\n }\n\n // Left boundary\n if (elementIndexX === 0) {\n boundaryElements[1].push([elementIndex, 1]);\n }\n\n // Top boundary\n if (elementIndexY === this.numElementsY - 1) {\n boundaryElements[2].push([elementIndex, 2]);\n }\n\n // Right boundary\n if (elementIndexX === this.numElementsX - 1) {\n boundaryElements[3].push([elementIndex, 3]);\n }\n }\n }\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Class to handle numerical integration using Gauss quadrature\n */\nexport class NumericalIntegration {\n /**\n * Constructor to initialize the NumericalIntegration class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to return Gauss points and weights based on element configuration\n * @returns {object} An object containing:\n * - gaussPoints: Array of Gauss points\n * - gaussWeights: Array of Gauss weights\n */\n getGaussPointsAndWeights() {\n let gaussPoints = []; // Gauss points\n let gaussWeights = []; // Gauss weights\n\n if (this.elementOrder === \"linear\") {\n // For linear elements, use 1-point Gauss quadrature\n gaussPoints[0] = 0.5;\n gaussWeights[0] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // For quadratic elements, use 3-point Gauss quadrature\n gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;\n gaussPoints[1] = 0.5;\n gaussPoints[2] = (1 + Math.sqrt(3 / 5)) / 2;\n gaussWeights[0] = 5 / 18;\n gaussWeights[1] = 8 / 18;\n gaussWeights[2] = 5 / 18;\n }\n\n return { gaussPoints, gaussWeights };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nimport { BasisFunctions } from \"./basisFunctionsScript.js\";\nimport { Mesh1D, Mesh2D } from \"./meshGenerationScript.js\";\nimport { NumericalIntegration } from \"../methods/numericalIntegrationScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to prepare the mesh for finite element analysis\n * @param {object} meshConfig - Object containing computational mesh details\n * @returns {object} An object containing all mesh-related data\n */\nexport function prepareMesh(meshConfig) {\n const { meshDimension, numElementsX, numElementsY, maxX, maxY, elementOrder, parsedMesh } = meshConfig;\n\n // Create a new instance of the Mesh class\n let mesh;\n if (meshDimension === \"1D\") {\n mesh = new Mesh1D({ numElementsX, maxX, elementOrder, parsedMesh });\n } else if (meshDimension === \"2D\") {\n mesh = new Mesh2D({ numElementsX, maxX, numElementsY, maxY, elementOrder, parsedMesh });\n } else {\n errorLog(\"Mesh dimension must be either '1D' or '2D'.\");\n }\n\n // Use the parsed mesh in case it was already passed with Gmsh format\n const nodesCoordinatesAndNumbering = mesh.boundaryElementsProcessed ? mesh.parsedMesh : mesh.generateMesh();\n\n // Extract nodes coordinates and nodal numbering (NOP) from the mesh data\n let nodesXCoordinates = nodesCoordinatesAndNumbering.nodesXCoordinates;\n let nodesYCoordinates = nodesCoordinatesAndNumbering.nodesYCoordinates;\n let totalNodesX = nodesCoordinatesAndNumbering.totalNodesX;\n let totalNodesY = nodesCoordinatesAndNumbering.totalNodesY;\n let nop = nodesCoordinatesAndNumbering.nodalNumbering;\n let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;\n\n // Check the mesh type\n const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;\n\n // Calculate totalElements and totalNodes based on mesh type\n let totalElements, totalNodes;\n\n if (isParsedMesh) {\n totalElements = nop.length; // Number of elements is the length of the nodal numbering array\n totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array\n debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);\n } else {\n // For structured mesh, calculate based on dimensions\n totalElements = numElementsX * (meshDimension === \"2D\" ? numElementsY : 1);\n totalNodes = totalNodesX * (meshDimension === \"2D\" ? totalNodesY : 1);\n debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);\n }\n\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nop,\n boundaryElements,\n totalElements,\n totalNodes,\n meshDimension,\n elementOrder,\n };\n}\n\n/**\n * Function to initialize the FEA matrices and numerical tools\n * @param {object} meshData - Object containing mesh data from prepareMesh()\n * @returns {object} An object containing initialized matrices and numerical tools\n */\nexport function initializeFEA(meshData) {\n const { totalNodes, nop, meshDimension, elementOrder } = meshData;\n\n // Initialize variables for matrix assembly\n let residualVector = [];\n let jacobianMatrix = [];\n let localToGlobalMap = [];\n\n // Initialize jacobianMatrix and residualVector arrays\n for (let nodeIndex = 0; nodeIndex < totalNodes; nodeIndex++) {\n residualVector[nodeIndex] = 0;\n jacobianMatrix.push([]);\n for (let colIndex = 0; colIndex < totalNodes; colIndex++) {\n jacobianMatrix[nodeIndex][colIndex] = 0;\n }\n }\n\n // Initialize the BasisFunctions class\n const basisFunctions = new BasisFunctions({\n meshDimension,\n elementOrder,\n });\n\n // Initialize the NumericalIntegration class\n const numericalIntegration = new NumericalIntegration({\n meshDimension,\n elementOrder,\n });\n\n // Calculate Gauss points and weights\n let gaussPointsAndWeights = numericalIntegration.getGaussPointsAndWeights();\n let gaussPoints = gaussPointsAndWeights.gaussPoints;\n let gaussWeights = gaussPointsAndWeights.gaussWeights;\n\n // Determine the number of nodes in the reference element based on the first element in the nop array\n const numNodes = nop[0].length;\n\n return {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 1D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping1D(params) {\n const { basisFunction, basisFunctionDerivKsi, nodesXCoordinates, localToGlobalMap, numNodes } = params;\n\n let xCoordinates = 0;\n let ksiDerivX = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n }\n let detJacobian = ksiDerivX;\n\n // Compute x-derivative of basis functions\n let basisFunctionDerivX = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n basisFunctionDerivX[localNodeIndex] = basisFunctionDerivKsi[localNodeIndex] / detJacobian;\n }\n\n return {\n xCoordinates,\n detJacobian,\n basisFunctionDerivX,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 2D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping2D(params) {\n const {\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n } = params;\n\n let xCoordinates = 0;\n let yCoordinates = 0;\n let ksiDerivX = 0;\n let etaDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivY = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n yCoordinates += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n ksiDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n }\n let detJacobian = ksiDerivX * etaDerivY - etaDerivX * ksiDerivY;\n\n // Compute x-derivative and y-derivative of basis functions\n let basisFunctionDerivX = [];\n let basisFunctionDerivY = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // The x-derivative of the n basis function\n basisFunctionDerivX[localNodeIndex] =\n (etaDerivY * basisFunctionDerivKsi[localNodeIndex] -\n ksiDerivY * basisFunctionDerivEta[localNodeIndex]) /\n detJacobian;\n // The y-derivative of the n basis function\n basisFunctionDerivY[localNodeIndex] =\n (ksiDerivX * basisFunctionDerivEta[localNodeIndex] -\n etaDerivX * basisFunctionDerivKsi[localNodeIndex]) /\n detJacobian;\n }\n\n return {\n xCoordinates,\n yCoordinates,\n detJacobian,\n basisFunctionDerivX,\n basisFunctionDerivY,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle thermal boundary conditions application\n */\nexport class ThermalBoundaryConditions {\n /**\n * Constructor to initialize the ThermalBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose constant temperature boundary conditions (Dirichlet type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant temperature boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantTempBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions (Robin type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n */\n imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 1;\n }\n } else if (this.elementOrder === \"quadratic\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 2;\n }\n }\n\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n residualVector[globalNodeIndex] += -convectionCoeff * extTemp;\n jacobianMatrix[globalNodeIndex][globalNodeIndex] += convectionCoeff;\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions for the frontal solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix with convection contributions\n * - localResidualVector: Residual vector with convection contributions\n */\n imposeConvectionBoundaryConditionsFront(\n elementIndex,\n nodesXCoordinates,\n nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n // Initialize local Jacobian matrix and local residual vector\n const numNodes = this.nop[elementIndex].length;\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Check if this element is on a convection boundary\n for (const boundaryKey in this.boundaryElements) {\n if (this.boundaryConditions[boundaryKey]?.[0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n\n // Find if this element is on this boundary and which side\n const boundaryElement = this.boundaryElements[boundaryKey].find(\n ([elemIdx, _]) => elemIdx === elementIndex\n );\n\n if (boundaryElement) {\n const side = boundaryElement[1];\n\n if (this.meshDimension === \"1D\") {\n // Handle 1D case\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n nodeIndex = side === 0 ? 0 : 1;\n } else if (this.elementOrder === \"quadratic\") {\n nodeIndex = side === 0 ? 0 : 2;\n }\n\n // Add contribution to local Jacobian matrix and local residual vector\n debugLog(\n ` - Applied convection boundary condition to node ${nodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n localResidualVector[nodeIndex] += -convectionCoeff * extTemp;\n localJacobianMatrix[nodeIndex][nodeIndex] += convectionCoeff;\n } else if (this.meshDimension === \"2D\") {\n // Handle 2D case\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n // Get basis functions\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n const basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n const basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n // Calculate tangent vector components\n let ksiDerivX = 0,\n ksiDerivY = 0,\n etaDerivX = 0,\n etaDerivY = 0;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n } else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute tangent vector length\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n // Handle quadratic elements (similar pattern but with more Gauss points)\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { ThermalBoundaryConditions } from \"./thermalBoundaryConditionsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the solid heat transfer model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\nexport function assembleHeatConductionMat(meshData, boundaryConditions) {\n basicLog(\"Starting solid heat transfer matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D solid heat transfer\n if (meshDimension === \"1D\") {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n // 2D solid heat transfer\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const thermalBoundaryConditions = new ThermalBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Convection boundary conditions\n thermalBoundaryConditions.imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n );\n\n // Impose ConstantTemp boundary conditions\n thermalBoundaryConditions.imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Solid heat transfer matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the solid heat transfer model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - localResidualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleHeatConductionFront({ elementIndex, nop, meshData, basisFunctions, FEAData }) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n if (meshDimension === \"1D\") {\n // 1D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n // 2D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Create mapping from local element space to global mesh (convert to 0-based indexing)\n const localToGlobalMap = ngl.map((globalIndex) => globalIndex - 1);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle generic boundary conditions application\n */\nexport class GenericBoundaryConditions {\n /**\n * Constructor to initialize the GenericBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose Dirichlet boundary conditions\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant value (Dirichlet) boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantValueBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n// Base viscous term that remains when eikonal equation is fully activated\nconst baseEikonalViscousTerm = 1e-2;\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the front propagation model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleFrontPropagationMat(\n meshData,\n boundaryConditions,\n solutionVector,\n eikonalActivationFlag\n) {\n basicLog(\"Starting front propagation matrix assembly...\");\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n debugLog(`eikonalViscousTerm: ${eikonalViscousTerm}`);\n debugLog(`eikonalActivationFlag: ${eikonalActivationFlag}`);\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // jacobianMatrix\n // TODO jacobianMatrix calculation here\n }\n }\n }\n // 2D front propagation (eikonal) equation\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n\n // residualVector: Viscous term contribution (to stabilize the solution)\n residualVector[localToGlobalMap1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // residualVector: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n residualVector[localToGlobalMap1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n\n // jacobianMatrix: Viscous term contribution\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // jacobianMatrix: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Dirichlet boundary conditions\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Front propagation matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the front propagation model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - residualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleFrontPropagationFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n solutionVector,\n eikonalActivationFlag,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // localJacobianMatrix\n // TODO localJacobianMatrix calculation here\n }\n }\n // 2D front propagation (eikonal) equation\n } else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // Viscous term contribution\n localResidualVector[localNodeIndex1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localResidualVector[localNodeIndex1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Viscous term contribution\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { BasisFunctions } from \"../mesh/basisFunctionsScript.js\";\nimport { initializeFEA } from \"../mesh/meshUtilsScript.js\";\nimport { assembleHeatConductionFront } from \"../models/heatConductionScript.js\";\nimport { ThermalBoundaryConditions } from \"../models/thermalBoundaryConditionsScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\nimport { GenericBoundaryConditions } from \"../models/genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n// Create object templates\nconst frontalData = {};\nconst frontalState = {};\nconst elementData = { currentElementIndex: 0 };\nconst frontStorage = {};\nlet basisFunctions;\n\n/**\n * Function to run the frontal solver and obtain results for plotting\n * @param {function} assembleFront - Matrix assembler based on the physical model\n * @param {object} meshData - Object containing mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} [options] - Additional options for the solver\n * @returns {object} An object containing the solution vector and node coordinates\n */\nexport function runFrontalSolver(assembleFront, meshData, boundaryConditions, options = {}) {\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const totalNodes = meshData.nodesXCoordinates.length;\n const numElements = meshData.totalElements;\n const numNodes = FEAData.numNodes;\n\n // Calculate required array sizes\n initializeFrontalArrays(numNodes, numElements);\n\n // Start timing for system solving (frontal algorithm)\n basicLog(\"Solving system using frontal...\");\n console.time(\"systemSolving\");\n\n // Initialize basis functions\n basisFunctions = new BasisFunctions({\n meshDimension: meshData.meshDimension,\n elementOrder: meshData.elementOrder,\n });\n\n // Copy node connectivity array into frontalData storage\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n for (let nodeIndex = 0; nodeIndex < FEAData.numNodes; nodeIndex++) {\n frontalData.nodalNumbering[elementIndex][nodeIndex] = meshData.nop[elementIndex][nodeIndex];\n }\n }\n\n // Apply Dirichlet-type boundary conditions\n // Initialize all nodes with no boundary condition\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.nodeConstraintCode[nodeIndex] = 0;\n frontalData.boundaryValues[nodeIndex] = 0;\n }\n\n // Handle Dirichlet-type boundary conditions differently based on which solver is being used\n let dirichletBoundaryConditionsHandler;\n // Solid heat transfer model (heatConductionScript solver)\n if (assembleFront === assembleHeatConductionFront) {\n dirichletBoundaryConditionsHandler = new ThermalBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantTempBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n // Front propagation model (frontPropagationScript solver)\n } else if (assembleFront === assembleFrontPropagationFront) {\n dirichletBoundaryConditionsHandler = new GenericBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantValueBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n }\n // Initialize global residual vector\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.globalResidualVector[nodeIndex] = 0;\n }\n\n frontalState.totalNodes = meshData.nodesXCoordinates.length;\n frontalState.writeFlag = 0;\n frontalState.transformationFlag = 1;\n frontalState.determinant = 1;\n\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n frontalState.nodesPerElement[elementIndex] = FEAData.numNodes;\n }\n\n // Parameters for non-linear assemblers\n frontalState.currentSolutionVector = options.solutionVector;\n frontalState.eikonalActivationFlag = options.eikonalActivationFlag;\n\n // Pass assembleFront and dirichletBoundaryConditionsHandler to runFrontalAlgorithm\n runFrontalAlgorithm(meshData, FEAData, dirichletBoundaryConditionsHandler, assembleFront);\n\n // Copy solution\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.solutionVector[nodeIndex] = frontalState.globalSolutionVector[nodeIndex];\n }\n\n // Output results to console for debugging\n const { nodesXCoordinates, nodesYCoordinates } = meshData;\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n if (meshData.meshDimension === \"1D\") {\n // 1D case - only output X coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${frontalData.solutionVector[\n nodeIndex\n ].toExponential(5)}`\n );\n } else {\n // 2D case - output X, Y coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${nodesYCoordinates[nodeIndex].toExponential(\n 5\n )} ${frontalData.solutionVector[nodeIndex].toExponential(5)}`\n );\n }\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n const { nodesXCoordinates: finalNodesX, nodesYCoordinates: finalNodesY } = meshData;\n return {\n solutionVector: frontalData.solutionVector.slice(0, totalNodes),\n nodesCoordinates: {\n nodesXCoordinates: finalNodesX,\n nodesYCoordinates: finalNodesY,\n },\n };\n}\n\n/**\n * Function to initialize arrays dynamically based on problem size\n * @param {number} numNodes - Number of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n */\nfunction initializeFrontalArrays(numNodes, numElements) {\n // Use the actual number of elements from the mesh\n frontalData.nodalNumbering = Array(numElements)\n .fill()\n .map(() => Array(numNodes).fill(0));\n frontalData.nodeConstraintCode = Array(numNodes).fill(0);\n frontalData.boundaryValues = Array(numNodes).fill(0);\n frontalData.globalResidualVector = Array(numNodes).fill(0);\n frontalData.solutionVector = Array(numNodes).fill(0);\n frontalData.topologyData = Array(numElements).fill(0);\n frontalData.lateralData = Array(numElements).fill(0);\n\n // Initialize frontalState arrays\n frontalState.writeFlag = 0;\n frontalState.totalNodes = numNodes;\n frontalState.transformationFlag = 0;\n frontalState.nodesPerElement = Array(numElements).fill(0);\n frontalState.determinant = 1;\n\n // For matrix operations, estimate required size based on problem complexity\n const systemSize = Math.max(numNodes, 2000);\n frontalState.globalSolutionVector = Array(systemSize).fill(0);\n frontalState.frontDataIndex = 0;\n\n // Initialize elementData arrays\n elementData.localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n elementData.currentElementIndex = 0;\n\n // Initialize frontStorage arrays\n const frontSize = estimateFrontSize(numNodes, numElements);\n frontStorage.frontValues = Array(frontSize).fill(0);\n frontStorage.columnHeaders = Array(systemSize).fill(0);\n frontStorage.pivotRow = Array(systemSize).fill(0);\n frontStorage.pivotData = Array(frontSize).fill(0);\n}\n\n/**\n * Function to estimate the required front size\n * @param {number} numNodes - Number of of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n * @returns {number} Estimated front size\n */\nfunction estimateFrontSize(numNodes, numElements) {\n const frontWidthEstimate = Math.max(Math.ceil(Math.sqrt(numElements)) * numNodes, numNodes * 2);\n return frontWidthEstimate * numElements;\n}\n// Old function to estimate the required front size\n// function estimateFrontSize(numNodes, numElements, numNodes) {\n// const frontWidthEstimate = Math.ceil(Math.sqrt(numElements) * numNodes * 2);\n// const frontSize = frontWidthEstimate * numNodes * 4;\n// return Math.max(frontSize, 10000);\n// }\n\n/**\n * Function to compute local Jacobian matrix and local residual vector\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n const elementIndex = elementData.currentElementIndex - 1;\n\n // Guard against out-of-range indices\n if (elementIndex < 0 || elementIndex >= meshData.totalElements) {\n errorLog(`Skipping out-of-range elementIndex=${elementIndex} (totalElements=${meshData.totalElements})`);\n return false;\n }\n\n // Domain terms\n const { localJacobianMatrix, localResidualVector, ngl } = assembleFront({\n elementIndex,\n nop: frontalData.nodalNumbering,\n meshData,\n basisFunctions: basisFunctions,\n FEAData,\n // These are ignored by linear assemblers\n solutionVector: frontalState.currentSolutionVector,\n eikonalActivationFlag: frontalState.eikonalActivationFlag,\n });\n\n // Handle Robin-type boundary conditions differently based on which solver is being used\n let boundaryLocalJacobianMatrix = Array(FEAData.numNodes)\n .fill()\n .map(() => Array(FEAData.numNodes).fill(0));\n let boundaryResidualVector = Array(FEAData.numNodes).fill(0);\n\n // heatConductionScript solver\n if (assembleFront === assembleHeatConductionFront) {\n // Check if this element is on a Robin-type boundary\n let isOnRobinTypeBoundary = false;\n for (const boundaryKey in meshData.boundaryElements) {\n if (\n thermalBoundaryConditions.boundaryConditions[boundaryKey]?.[0] === \"convection\" &&\n meshData.boundaryElements[boundaryKey].some(([elemIdx, _]) => elemIdx === elementIndex)\n ) {\n isOnRobinTypeBoundary = true;\n break;\n }\n }\n\n // Only calculate Robin-type for elements when required\n if (isOnRobinTypeBoundary) {\n const { gaussPoints, gaussWeights } = FEAData;\n const result = thermalBoundaryConditions.imposeConvectionBoundaryConditionsFront(\n elementIndex,\n meshData.nodesXCoordinates,\n meshData.nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n );\n boundaryLocalJacobianMatrix = result.localJacobianMatrix;\n boundaryResidualVector = result.localResidualVector;\n }\n } else if (assembleFront === assembleFrontPropagationFront) {\n // For now, no Robin-type boundary conditions exist for any other solver\n }\n\n // Combine domain and boundary contributions\n for (let localNodeI = 0; localNodeI < FEAData.numNodes; localNodeI++) {\n for (let localNodeJ = 0; localNodeJ < FEAData.numNodes; localNodeJ++) {\n elementData.localJacobianMatrix[localNodeI][localNodeJ] =\n localJacobianMatrix[localNodeI][localNodeJ] + boundaryLocalJacobianMatrix[localNodeI][localNodeJ];\n }\n }\n\n // Assemble local element residual\n for (let localNodeIndex = 0; localNodeIndex < FEAData.numNodes; localNodeIndex++) {\n const globalNodeIndex = ngl[localNodeIndex] - 1;\n frontalData.globalResidualVector[globalNodeIndex] +=\n localResidualVector[localNodeIndex] + boundaryResidualVector[localNodeIndex];\n }\n\n return true;\n}\n\n/**\n * Function to implement the frontal solver algorithm\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction runFrontalAlgorithm(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n // Allocate local arrays dynamically\n const totalElements = meshData.totalElements;\n const numNodes = meshData.nodesXCoordinates.length;\n const systemSize = Math.max(numNodes, frontalState.globalSolutionVector.length);\n let localDestination = Array(FEAData.numNodes).fill(0);\n let rowDestination = Array(FEAData.numNodes).fill(0);\n let rowHeaders = Array(systemSize).fill(0);\n let pivotRowIndices = Array(systemSize).fill(0);\n let pivotColumnIndices = Array(systemSize).fill(0);\n let modifiedRows = Array(systemSize).fill(0);\n let pivotColumn = Array(systemSize).fill(0);\n let frontMatrix = Array(systemSize)\n .fill()\n .map(() => Array(systemSize).fill(0));\n let rowSwapCount = Array(numNodes).fill(0);\n let columnSwapCount = Array(numNodes).fill(0);\n let lastAppearanceCheck = Array(numNodes).fill(0);\n let pivotColumnGlobalIndex; // Pivot column global index\n\n let frontDataCounter = 1;\n frontalState.writeFlag++;\n let pivotDataIndex = 1;\n let summedRows = 1;\n elementData.currentElementIndex = 0;\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n rowSwapCount[nodeIndex] = 0;\n columnSwapCount[nodeIndex] = 0;\n }\n\n if (frontalState.transformationFlag !== 0) {\n // Prefront: find last appearance of each node\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n lastAppearanceCheck[nodeIndex] = 0;\n }\n\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n let reverseElementIndex = totalElements - elementIndex - 1;\n for (\n let localNodeIndex = 0;\n localNodeIndex < frontalState.nodesPerElement[reverseElementIndex];\n localNodeIndex++\n ) {\n let globalNodeIndex = frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n if (lastAppearanceCheck[globalNodeIndex - 1] === 0) {\n lastAppearanceCheck[globalNodeIndex - 1] = 1;\n frontalData.nodalNumbering[reverseElementIndex][localNodeIndex] =\n -frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n }\n }\n }\n }\n\n frontalState.transformationFlag = 0;\n let columnCount = 0;\n let rowCount = 0;\n\n for (let i = 0; i < systemSize; i++) {\n for (let j = 0; j < systemSize; j++) {\n frontMatrix[j][i] = 0;\n }\n }\n\n while (true) {\n // Assemble a new element only while we still have elements\n let assembled = false;\n let numElementNodes = 0;\n let numElementColumns = 0;\n\n if (elementData.currentElementIndex < totalElements) {\n elementData.currentElementIndex++;\n assembled = assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront);\n }\n\n if (assembled) {\n const currentElement = elementData.currentElementIndex;\n numElementNodes = frontalState.nodesPerElement[currentElement - 1];\n numElementColumns = frontalState.nodesPerElement[currentElement - 1];\n\n for (let localNodeIndex = 0; localNodeIndex < numElementColumns; localNodeIndex++) {\n let globalNodeIndex = frontalData.nodalNumbering[currentElement - 1][localNodeIndex];\n let columnIndex;\n\n if (columnCount === 0) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(frontStorage.columnHeaders[columnIndex])) break;\n }\n\n if (columnIndex === columnCount) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n localDestination[localNodeIndex] = columnIndex + 1;\n frontStorage.columnHeaders[columnIndex] = globalNodeIndex;\n }\n }\n\n let rowIndex;\n if (rowCount === 0) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(rowHeaders[rowIndex])) break;\n }\n\n if (rowIndex === rowCount) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n rowDestination[localNodeIndex] = rowIndex + 1;\n rowHeaders[rowIndex] = globalNodeIndex;\n }\n }\n }\n\n if (rowCount > systemSize || columnCount > systemSize) {\n errorLog(\"Error: systemSize not large enough\");\n return;\n }\n\n for (let localColumnIndex = 0; localColumnIndex < numElementColumns; localColumnIndex++) {\n let frontColumnIndex = localDestination[localColumnIndex];\n for (let localRowIndex = 0; localRowIndex < numElementNodes; localRowIndex++) {\n let frontRowIndex = rowDestination[localRowIndex];\n frontMatrix[frontRowIndex - 1][frontColumnIndex - 1] +=\n elementData.localJacobianMatrix[localRowIndex][localColumnIndex];\n }\n }\n }\n\n // Pivoting/elimination continues whether or not a new element was assembled\n let availableColumnCount = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (frontStorage.columnHeaders[columnIndex] < 0) {\n pivotColumnIndices[availableColumnCount] = columnIndex + 1;\n availableColumnCount++;\n }\n }\n\n let constrainedRowCount = 0;\n let availableRowCount = 0;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n let globalNodeIndex = rowHeaders[rowIndex];\n if (globalNodeIndex < 0) {\n pivotRowIndices[availableRowCount] = rowIndex + 1;\n availableRowCount++;\n let absoluteNodeIndex = Math.abs(globalNodeIndex);\n if (frontalData.nodeConstraintCode[absoluteNodeIndex - 1] === 1) {\n modifiedRows[constrainedRowCount] = rowIndex + 1;\n constrainedRowCount++;\n frontalData.nodeConstraintCode[absoluteNodeIndex - 1] = 2;\n frontalData.globalResidualVector[absoluteNodeIndex - 1] =\n frontalData.boundaryValues[absoluteNodeIndex - 1];\n }\n }\n }\n\n if (constrainedRowCount > 0) {\n for (let constrainedIndex = 0; constrainedIndex < constrainedRowCount; constrainedIndex++) {\n let rowIndex = modifiedRows[constrainedIndex] - 1;\n let globalNodeIndex = Math.abs(rowHeaders[rowIndex]);\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] = 0;\n let columnGlobalIndex = Math.abs(frontStorage.columnHeaders[columnIndex]);\n if (columnGlobalIndex === globalNodeIndex) frontMatrix[rowIndex][columnIndex] = 1;\n }\n }\n }\n\n if (availableColumnCount > summedRows || elementData.currentElementIndex < totalElements) {\n if (availableColumnCount === 0) {\n errorLog(\"Error: no more rows fully summed\");\n return;\n }\n\n let pivotRowIndex = pivotRowIndices[0];\n let pivotColumnIndex = pivotColumnIndices[0];\n let pivotValue = frontMatrix[pivotRowIndex - 1][pivotColumnIndex - 1];\n\n if (Math.abs(pivotValue) < 1e-4) {\n pivotValue = 0;\n for (let columnIndex = 0; columnIndex < availableColumnCount; columnIndex++) {\n let testColumnIndex = pivotColumnIndices[columnIndex];\n for (let rowIndex = 0; rowIndex < availableRowCount; rowIndex++) {\n let testRowIndex = pivotRowIndices[rowIndex];\n let testValue = frontMatrix[testRowIndex - 1][testColumnIndex - 1];\n if (Math.abs(testValue) > Math.abs(pivotValue)) {\n pivotValue = testValue;\n pivotColumnIndex = testColumnIndex;\n pivotRowIndex = testRowIndex;\n }\n }\n }\n }\n\n let pivotGlobalRowIndex = Math.abs(rowHeaders[pivotRowIndex - 1]);\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]); // Assign, don't declare\n let permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n if (nodeIndex >= pivotGlobalRowIndex) rowSwapCount[nodeIndex]--;\n if (nodeIndex >= pivotColumnGlobalIndex) columnSwapCount[nodeIndex]--;\n }\n\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontMatrix[pivotRowIndex - 1][columnIndex] / pivotValue;\n }\n\n let rightHandSide = frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] = rightHandSide;\n pivotColumn[pivotRowIndex - 1] = pivotValue;\n\n if (pivotRowIndex > 1) {\n for (let rowIndex = 0; rowIndex < pivotRowIndex - 1; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1 && eliminationFactor !== 0) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] -= eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n if (pivotRowIndex < rowCount) {\n for (let rowIndex = pivotRowIndex; rowIndex < rowCount; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = pivotColumn[i];\n }\n pivotDataIndex += rowCount;\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = rowHeaders[i];\n }\n pivotDataIndex += rowCount;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.pivotRow[i];\n }\n frontDataCounter += columnCount;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.columnHeaders[i];\n }\n frontDataCounter += columnCount;\n\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n frontMatrix[rowIndex][columnCount - 1] = 0;\n }\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowCount - 1][columnIndex] = 0;\n }\n\n columnCount--;\n if (pivotColumnIndex < columnCount + 1) {\n for (let columnIndex = pivotColumnIndex - 1; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] = frontStorage.columnHeaders[columnIndex + 1];\n }\n }\n\n rowCount--;\n if (pivotRowIndex < rowCount + 1) {\n for (let rowIndex = pivotRowIndex - 1; rowIndex < rowCount; rowIndex++) {\n rowHeaders[rowIndex] = rowHeaders[rowIndex + 1];\n }\n }\n\n if (rowCount > 1 || elementData.currentElementIndex < totalElements) continue;\n\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[0]); // Assign, don't declare\n pivotRowIndex = 1;\n pivotValue = frontMatrix[0][0];\n pivotGlobalRowIndex = Math.abs(rowHeaders[0]);\n pivotColumnIndex = 1;\n permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n frontStorage.pivotRow[0] = 1;\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] =\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.pivotRow[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.columnHeaders[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotColumn[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = rowHeaders[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n frontalState.frontDataIndex = frontDataCounter;\n if (frontalState.writeFlag === 1)\n debugLog(`total ecs transfer in matrix reduction=${frontDataCounter}`);\n\n // Back substitution\n performBackSubstitution(frontDataCounter);\n break;\n }\n }\n}\n\n/**\n * Function to perform back substitution for the frontal solver\n * @param {number} frontDataCounter - Index counter for the element contributions\n */\nfunction performBackSubstitution(frontDataCounter) {\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n frontalState.globalSolutionVector[nodeIndex] = frontalData.boundaryValues[nodeIndex];\n }\n\n for (let iterationIndex = 1; iterationIndex <= frontalState.totalNodes; iterationIndex++) {\n frontDataCounter -= 4;\n let pivotGlobalRowIndex = frontStorage.frontValues[frontDataCounter - 1];\n let columnCount = frontStorage.frontValues[frontDataCounter];\n let pivotColumnIndex = frontStorage.frontValues[frontDataCounter + 1];\n let pivotValue = frontStorage.frontValues[frontDataCounter + 2];\n\n if (iterationIndex === 1) {\n frontDataCounter--;\n frontStorage.columnHeaders[0] = frontStorage.frontValues[frontDataCounter - 1];\n frontDataCounter--;\n frontStorage.pivotRow[0] = frontStorage.frontValues[frontDataCounter - 1];\n } else {\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] =\n frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n }\n\n let pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]);\n if (frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] > 0) continue;\n\n let accumulatedValue = 0;\n frontStorage.pivotRow[pivotColumnIndex - 1] = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n accumulatedValue -=\n frontStorage.pivotRow[columnIndex] *\n frontalState.globalSolutionVector[Math.abs(frontStorage.columnHeaders[columnIndex]) - 1];\n }\n\n frontalState.globalSolutionVector[pivotColumnGlobalIndex - 1] =\n accumulatedValue + frontalData.globalResidualVector[pivotGlobalRowIndex - 1];\n\n frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] = 1;\n }\n\n if (frontalState.writeFlag === 1)\n debugLog(`value of frontDataCounter after backsubstitution=${frontDataCounter}`);\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { euclideanNorm } from \"../methods/euclideanNormScript.js\";\nimport { solveLinearSystem } from \"./linearSystemSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport { runFrontalSolver } from \"./frontalSolverScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\n\n/**\n * Function to solve a system of non-linear equations using the Newton-Raphson method\n * @param {function} assembleMat - Matrix assembler based on the physical model\n * @param {object} context - Context object containing simulation data and options\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\n\nexport function newtonRaphson(assembleMat, context = {}) {\n let errorNorm = 0;\n let converged = false;\n let iterations = 0;\n let deltaX = [];\n let solutionVector = [];\n let jacobianMatrix = [];\n let residualVector = [];\n\n // Extract context\n const { maxIterations = 100, tolerance = 1e-4 } = context;\n\n // Calculate system size\n let totalNodes = context.meshData.nodesXCoordinates.length;\n\n // Initialize arrays with proper size\n for (let i = 0; i < totalNodes; i++) {\n deltaX[i] = 0;\n solutionVector[i] = 0;\n }\n\n // Initialize solution from context if available\n if (context.initialSolution && context.initialSolution.length === totalNodes) {\n solutionVector = [...context.initialSolution];\n }\n\n while (iterations < maxIterations && !converged) {\n // Update solution\n for (let i = 0; i < solutionVector.length; i++) {\n solutionVector[i] = Number(solutionVector[i]) + Number(deltaX[i]);\n }\n\n // Check if using frontal solver\n if (context.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleFrontPropagationFront,\n context.meshData,\n context.boundaryConditions,\n { solutionVector, eikonalActivationFlag: context.eikonalActivationFlag }\n );\n deltaX = frontalResult.solutionVector;\n } else {\n // Compute Jacobian and residual matrices\n ({ jacobianMatrix, residualVector } = assembleMat(\n context.meshData,\n context.boundaryConditions,\n solutionVector, // The solution vector is required in the case of a non-linear equation\n context.eikonalActivationFlag // Currently used only in the front propagation solver (TODO refactor in case of a solver not needing it)\n ));\n\n // Solve the linear system based on the specified solver method\n const linearSystemResult = solveLinearSystem(context.solverMethod, jacobianMatrix, residualVector);\n deltaX = linearSystemResult.solutionVector;\n }\n\n // Check convergence\n errorNorm = euclideanNorm(deltaX);\n\n // Norm for each iteration\n basicLog(`Newton-Raphson iteration ${iterations + 1}: Error norm = ${errorNorm.toExponential(4)}`);\n\n if (errorNorm <= tolerance) {\n converged = true;\n } else if (errorNorm > 1e2) {\n errorLog(`Solution not converged. Error norm: ${errorNorm}`);\n break;\n }\n\n iterations++;\n }\n\n return {\n solutionVector,\n converged,\n iterations,\n jacobianMatrix,\n residualVector,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { newtonRaphson } from \"./methods/newtonRaphsonScript.js\";\nimport { solveLinearSystem } from \"./methods/linearSystemSolverScript.js\";\nimport { solveLinearSystemAsync } from \"./methods/linearSystemSolverScript.js\";\nimport { prepareMesh } from \"./mesh/meshUtilsScript.js\";\nimport { assembleFrontPropagationMat } from \"./models/frontPropagationScript.js\";\nimport { assembleGeneralFormPDEMat, assembleGeneralFormPDEFront } from \"./models/generalFormPDEScript.js\";\nimport { assembleHeatConductionMat, assembleHeatConductionFront } from \"./models/heatConductionScript.js\";\nimport { runFrontalSolver } from \"./methods/frontalSolverScript.js\";\nimport { basicLog, debugLog, warnLog, errorLog } from \"./utilities/loggingScript.js\";\n\n/**\n * Class to implement finite element analysis in JavaScript\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} meshConfig - Object containing computational mesh details\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containifng the solution vector and additional mesh information\n */\nexport class FEAScriptModel {\n constructor() {\n this.solverConfig = null;\n this.meshConfig = {};\n this.boundaryConditions = {};\n this.solverMethod = \"lusolve\"; // Default solver method\n this.coefficientFunctions = null; // Add storage for coefficient functions\n warnLog(\n \"FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE\"\n );\n basicLog(\"FEAScriptModel instance created\");\n }\n\n /**\n * Sets the solver configuration\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} [options] - Optional additional configuration\n */\n setSolverConfig(solverConfig, options = {}) {\n this.solverConfig = solverConfig;\n\n // Store coefficient functions if provided\n if (options?.coefficientFunctions) {\n this.coefficientFunctions = options.coefficientFunctions;\n debugLog(\"Coefficient functions set\");\n }\n // Only update if a value is provided, otherwise keep the default\n if (options?.maxIterations !== undefined) {\n this.maxIterations = options.maxIterations;\n }\n if (options?.tolerance !== undefined) {\n this.tolerance = options.tolerance;\n }\n\n debugLog(`Solver config set to: ${solverConfig}`);\n }\n\n setMeshConfig(meshConfig) {\n this.meshConfig = meshConfig;\n debugLog(`Mesh config set with dimensions: ${meshConfig.meshDimension}`);\n }\n\n addBoundaryCondition(boundaryKey, condition) {\n this.boundaryConditions[boundaryKey] = condition;\n debugLog(`Boundary condition added for boundary: ${boundaryKey}, type: ${condition[0]}`);\n }\n\n setSolverMethod(solverMethod) {\n this.solverMethod = solverMethod;\n debugLog(`Solver method set to: ${solverMethod}`);\n }\n\n /**\n * Function to solve the finite element problem synchronously\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing the solution vector and the coordinates of the mesh nodes\n */\n solve(options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n /**\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n let initialSolution = [];\n\n // Prepare the mesh\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n\n // Extract node coordinates from meshData\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n // Select and execute the appropriate solver based on solverConfig\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleHeatConductionFront,\n meshData,\n this.boundaryConditions\n );\n solutionVector = frontalResult.solutionVector;\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n } else if (this.solverConfig === \"frontPropagationScript\") {\n // Initialize eikonalActivationFlag\n let eikonalActivationFlag = 0;\n const eikonalExteralIterations = 5; // Number of incremental steps for the eikonal equation\n\n // Create context object with all necessary properties\n const context = {\n meshData: meshData,\n boundaryConditions: this.boundaryConditions,\n eikonalActivationFlag: eikonalActivationFlag,\n solverMethod: this.solverMethod,\n initialSolution,\n // TODO: Consider using different maxIterations/tolerance for Newton-Raphson and linear solver\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n };\n\n while (eikonalActivationFlag <= 1) {\n // Update the context object with current eikonalActivationFlag\n context.eikonalActivationFlag = eikonalActivationFlag;\n\n // Pass the previous solution as initial guess\n if (solutionVector.length > 0) {\n context.initialSolution = [...solutionVector];\n }\n\n // Solve the assembled non-linear system\n const newtonRaphsonResult = newtonRaphson(assembleFrontPropagationMat, context);\n\n // Extract results\n jacobianMatrix = newtonRaphsonResult.jacobianMatrix;\n residualVector = newtonRaphsonResult.residualVector;\n solutionVector = newtonRaphsonResult.solutionVector;\n\n // Increment for next iteration\n eikonalActivationFlag += 1 / eikonalExteralIterations;\n }\n } else if (this.solverConfig === \"generalFormPDEScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n errorLog(\n \"Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.\"\n );\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(\n meshData,\n this.boundaryConditions,\n this.coefficientFunctions\n ));\n\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n /**\n * Function to solve the finite element problem asynchronously\n * @param {object} computeEngine - The compute engine to use for the asynchronous solver (e.g., a worker or a WebGPU context)\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing the solution vector and the coordinates of the mesh nodes\n */\n async solveAsync(computeEngine, options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n\n if (this.solverMethod === \"jacobi-gpu\") {\n const { solutionVector: x } = await solveLinearSystemAsync(\"jacobi-gpu\", jacobianMatrix, residualVector, {\n computeEngine,\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = x;\n } else {\n // Other async solver\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { initializeFEA, performIsoparametricMapping1D } from \"../mesh/meshUtilsScript.js\";\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the general form PDE model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} coefficientFunctions - Functions A(x), B(x), C(x), D(x) for the PDE\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleGeneralFormPDEMat(meshData, boundaryConditions, coefficientFunctions) {\n basicLog(\"Starting general form PDE matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Extract coefficient functions\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Convert to 0-based indexing\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];\n\n // Source term contribution to residual vector\n residualVector[globalNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n const globalNodeIndex2 = localToGlobalMap[localNodeIndex2];\n\n // Diffusion term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEMat.\");\n // 2D general form PDE - empty for now\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Apply Dirichlet boundary conditions only\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n\n basicLog(\"General form PDE matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the frontal solver matrix for the general form PDE model\n * @param {object} data - Object containing element data for the frontal solver\n * @returns {object} An object containing local Jacobian matrix and residual vector\n */\nexport function assembleGeneralFormPDEFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n coefficientFunctions,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of local Jacobian matrix and residual vector\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n // Source term contribution to local residual vector\n localResidualVector[localNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Diffusion term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEFront.\");\n // 2D general form PDE - empty for now\n }\n\n return {\n localJacobianMatrix,\n localResidualVector,\n ngl,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// External imports\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n// Internal imports\nimport { basicLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to facilitate communication with web workers for FEAScript operations\n */\nexport class FEAScriptWorker {\n /**\n * Constructor to initialize the FEAScriptWorker class\n * Sets up the worker and initializes the workerWrapper.\n */\n constructor() {\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n\n this._initWorker();\n }\n\n /**\n * Function to initialize the web worker and wrap it using Comlink.\n * @private\n * @throws Will throw an error if the worker fails to initialize.\n */\n async _initWorker() {\n try {\n this.worker = new Worker(new URL(\"./wrapperScript.js\", import.meta.url), {\n type: \"module\",\n });\n\n this.worker.onerror = (event) => {\n console.error(\"FEAScriptWorker: Worker error:\", event);\n };\n const workerWrapper = Comlink.wrap(this.worker);\n\n this.feaWorker = await new workerWrapper();\n\n this.isReady = true;\n } catch (error) {\n console.error(\"Failed to initialize worker\", error);\n throw error;\n }\n }\n\n /**\n * Function to ensure that the worker is ready before performing any operations.\n * @private\n * @returns {Promise} Resolves when the worker is ready.\n * @throws Will throw an error if the worker is not ready within the timeout period.\n */\n async _ensureReady() {\n if (this.isReady) return Promise.resolve();\n\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds max\n\n const checkReady = () => {\n attempts++;\n if (this.isReady) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(\"Timeout waiting for worker to be ready\"));\n } else {\n setTimeout(checkReady, 1000);\n }\n };\n checkReady();\n });\n }\n\n /**\n * Function to set the solver configuration in the worker.\n * @param {string} solverConfig - The solver configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setSolverConfig(solverConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver config to: ${solverConfig}`);\n return this.feaWorker.setSolverConfig(solverConfig);\n }\n\n /**\n * Sets the mesh configuration in the worker.\n * @param {object} meshConfig - The mesh configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setMeshConfig(meshConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting mesh config`);\n return this.feaWorker.setMeshConfig(meshConfig);\n }\n\n /**\n * Adds a boundary condition to the worker.\n * @param {string} boundaryKey - The key identifying the boundary.\n * @param {array} condition - The boundary condition to add.\n * @returns {Promise} Resolves when the boundary condition is added.\n */\n async addBoundaryCondition(boundaryKey, condition) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Adding boundary condition for boundary: ${boundaryKey}`);\n return this.feaWorker.addBoundaryCondition(boundaryKey, condition);\n }\n\n /**\n * Sets the solver method in the worker.\n * @param {string} solverMethod - The solver method to set.\n * @returns {Promise} Resolves when the solver method is set.\n */\n async setSolverMethod(solverMethod) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver method to: ${solverMethod}`);\n return this.feaWorker.setSolverMethod(solverMethod);\n }\n\n /**\n * Requests the worker to solve the problem.\n * @returns {Promise} Resolves with the solution result.\n */\n async solve() {\n await this._ensureReady();\n basicLog(\"FEAScriptWorker: Requesting solution from worker...\");\n\n const startTime = performance.now();\n const result = await this.feaWorker.solve();\n const endTime = performance.now();\n\n basicLog(`FEAScriptWorker: Solution completed in ${((endTime - startTime) / 1000).toFixed(2)}s`);\n return result;\n }\n\n /**\n * Retrieves model information from the worker.\n * @returns {Promise} Resolves with the model information.\n */\n async getModelInfo() {\n await this._ensureReady();\n return this.feaWorker.getModelInfo();\n }\n\n /**\n * Sends a ping request to the worker to check its availability.\n * @returns {Promise} Resolves if the worker responds.\n */\n async ping() {\n await this._ensureReady();\n return this.feaWorker.ping();\n }\n\n /**\n * Terminates the worker and cleans up resources.\n */\n terminate() {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements\n * @param {File} file - The Gmsh file to be parsed (.msh version 4.1)\n * @returns {object} The parsed mesh data including node coordinates, element connectivity, and boundary conditions\n */\nconst importGmshQuadTri = async (file) => {\n let result = {\n nodesXCoordinates: [],\n nodesYCoordinates: [],\n nodalNumbering: {\n quadElements: [],\n triangleElements: [],\n },\n boundaryElements: [],\n boundaryConditions: [],\n boundaryNodePairs: {}, // Store boundary node pairs for processing in meshGenerationScript\n gmshV: 0,\n ascii: false,\n fltBytes: \"8\",\n totalNodesX: 0,\n totalNodesY: 0,\n physicalPropMap: [],\n elementTypes: {},\n };\n\n let content = await file.text();\n let lines = content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line !== \"\" && line !== \" \");\n\n let section = \"\";\n let lineIndex = 0;\n\n let nodeEntityBlocks = 0;\n let totalNodes = 0;\n let nodeBlocksProcessed = 0;\n let currentNodeBlock = { numNodes: 0 };\n let nodeTagsCollected = 0;\n let nodeTags = [];\n let nodeCoordinatesCollected = 0;\n\n let elementEntityBlocks = 0;\n let totalElements = 0;\n let elementBlocksProcessed = 0;\n let currentElementBlock = {\n dim: 0,\n tag: 0,\n elementType: 0,\n numElements: 0,\n };\n let elementsProcessedInBlock = 0;\n\n let boundaryElementsByTag = {};\n\n while (lineIndex < lines.length) {\n const line = lines[lineIndex];\n\n if (line === \"$MeshFormat\") {\n section = \"meshFormat\";\n lineIndex++;\n continue;\n } else if (line === \"$EndMeshFormat\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$PhysicalNames\") {\n section = \"physicalNames\";\n lineIndex++;\n continue;\n } else if (line === \"$EndPhysicalNames\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Entities\") {\n section = \"entities\";\n lineIndex++;\n continue;\n } else if (line === \"$EndEntities\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Nodes\") {\n section = \"nodes\";\n lineIndex++;\n continue;\n } else if (line === \"$EndNodes\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Elements\") {\n section = \"elements\";\n lineIndex++;\n continue;\n } else if (line === \"$EndElements\") {\n section = \"\";\n lineIndex++;\n continue;\n }\n\n const parts = line.split(/\\s+/).filter((part) => part !== \"\");\n\n if (section === \"meshFormat\") {\n result.gmshV = parseFloat(parts[0]);\n result.ascii = parts[1] === \"0\";\n result.fltBytes = parts[2];\n } else if (section === \"physicalNames\") {\n if (parts.length >= 3) {\n if (!/^\\d+$/.test(parts[0])) {\n lineIndex++;\n continue;\n }\n\n const dimension = parseInt(parts[0], 10);\n const tag = parseInt(parts[1], 10);\n let name = parts.slice(2).join(\" \");\n name = name.replace(/^\"|\"$/g, \"\");\n\n result.physicalPropMap.push({\n tag,\n dimension,\n name,\n });\n }\n } else if (section === \"nodes\") {\n if (nodeEntityBlocks === 0) {\n nodeEntityBlocks = parseInt(parts[0], 10);\n totalNodes = parseInt(parts[1], 10);\n result.nodesXCoordinates = new Array(totalNodes).fill(0);\n result.nodesYCoordinates = new Array(totalNodes).fill(0);\n lineIndex++;\n continue;\n }\n\n if (nodeBlocksProcessed < nodeEntityBlocks && currentNodeBlock.numNodes === 0) {\n currentNodeBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n parametric: parseInt(parts[2], 10),\n numNodes: parseInt(parts[3], 10),\n };\n\n nodeTags = [];\n nodeTagsCollected = 0;\n nodeCoordinatesCollected = 0;\n\n lineIndex++;\n continue;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n for (let i = 0; i < parts.length && nodeTagsCollected < currentNodeBlock.numNodes; i++) {\n nodeTags.push(parseInt(parts[i], 10));\n nodeTagsCollected++;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n lineIndex++;\n continue;\n }\n\n lineIndex++;\n continue;\n }\n\n if (nodeCoordinatesCollected < currentNodeBlock.numNodes) {\n const nodeTag = nodeTags[nodeCoordinatesCollected] - 1;\n const x = parseFloat(parts[0]);\n const y = parseFloat(parts[1]);\n\n result.nodesXCoordinates[nodeTag] = x;\n result.nodesYCoordinates[nodeTag] = y;\n result.totalNodesX++;\n result.totalNodesY++;\n\n nodeCoordinatesCollected++;\n\n if (nodeCoordinatesCollected === currentNodeBlock.numNodes) {\n nodeBlocksProcessed++;\n currentNodeBlock = { numNodes: 0 };\n }\n }\n } else if (section === \"elements\") {\n if (elementEntityBlocks === 0) {\n elementEntityBlocks = parseInt(parts[0], 10);\n totalElements = parseInt(parts[1], 10);\n lineIndex++;\n continue;\n }\n\n if (elementBlocksProcessed < elementEntityBlocks && currentElementBlock.numElements === 0) {\n currentElementBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n elementType: parseInt(parts[2], 10),\n numElements: parseInt(parts[3], 10),\n };\n\n result.elementTypes[currentElementBlock.elementType] =\n (result.elementTypes[currentElementBlock.elementType] || 0) + currentElementBlock.numElements;\n\n elementsProcessedInBlock = 0;\n lineIndex++;\n continue;\n }\n\n if (elementsProcessedInBlock < currentElementBlock.numElements) {\n const elementTag = parseInt(parts[0], 10);\n const nodeIndices = parts.slice(1).map((idx) => parseInt(idx, 10));\n\n if (currentElementBlock.elementType === 1 || currentElementBlock.elementType === 8) {\n const physicalTag = currentElementBlock.tag;\n\n if (!boundaryElementsByTag[physicalTag]) {\n boundaryElementsByTag[physicalTag] = [];\n }\n\n boundaryElementsByTag[physicalTag].push(nodeIndices);\n\n // Store boundary node pairs for later processing in meshGenerationScript\n if (!result.boundaryNodePairs[physicalTag]) {\n result.boundaryNodePairs[physicalTag] = [];\n }\n result.boundaryNodePairs[physicalTag].push(nodeIndices);\n } else if (currentElementBlock.elementType === 2) {\n // Linear triangle elements (3 nodes)\n result.nodalNumbering.triangleElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 3) {\n // Linear quadrilateral elements (4 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 10) {\n // Quadratic quadrilateral elements (9 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n }\n\n elementsProcessedInBlock++;\n\n if (elementsProcessedInBlock === currentElementBlock.numElements) {\n elementBlocksProcessed++;\n currentElementBlock = { numElements: 0 };\n }\n }\n }\n\n lineIndex++;\n }\n\n // Store boundary conditions information\n result.physicalPropMap.forEach((prop) => {\n if (prop.dimension === 1) {\n const boundaryNodes = boundaryElementsByTag[prop.tag] || [];\n\n if (boundaryNodes.length > 0) {\n result.boundaryConditions.push({\n name: prop.name,\n tag: prop.tag,\n nodes: boundaryNodes,\n });\n }\n }\n });\n\n debugLog(\n `Parsed boundary node pairs by physical tag: ${JSON.stringify(\n result.boundaryNodePairs\n )}. These pairs will be used to identify boundary elements in the mesh.`\n );\n\n return result;\n};\n\nexport { importGmshQuadTri };\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to create plots of the solution vector\n * @param {*} solutionVector - The computed solution vector\n * @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {string} meshDimension - The dimension of the solution\n * @param {string} plotType - The type of plot\n * @param {string} plotDivId - The id of the div where the plot will be rendered\n */\nexport function plotSolution(\n solutionVector,\n nodesCoordinates,\n solverConfig,\n meshDimension,\n plotType,\n plotDivId\n) {\n const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;\n\n if (meshDimension === \"1D\" && plotType === \"line\") {\n // Check if solutionVector is a nested array\n let yData;\n if (solutionVector.length > 0 && Array.isArray(solutionVector[0])) {\n yData = solutionVector.map((arr) => arr[0]);\n } else {\n yData = solutionVector;\n }\n let xData = Array.from(nodesXCoordinates);\n\n let lineData = {\n x: nodesXCoordinates,\n y: yData,\n mode: \"lines\",\n type: \"scatter\",\n line: { color: \"rgb(219, 64, 82)\", width: 2 },\n name: \"Solution\",\n };\n\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = 350;\n\n let layout = {\n title: `line plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"Solution\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n };\n\n Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });\n } else if (meshDimension === \"2D\" && plotType === \"contour\") {\n // Check if solutionVector is a nested array\n let zData;\n if (Array.isArray(solutionVector[0])) {\n zData = solutionVector.map((val) => val[0]);\n } else {\n zData = solutionVector;\n }\n\n // Sizing parameters\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxX = Math.max(...nodesXCoordinates);\n let maxY = Math.max(...nodesYCoordinates);\n let aspectRatio = maxY / maxX;\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = plotWidth * aspectRatio;\n\n // Layout properties\n let layout = {\n title: `${plotType} plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"y\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n hovermode: \"closest\",\n };\n\n // Create the plot\n let contourData = {\n x: nodesXCoordinates,\n y: nodesYCoordinates,\n z: zData,\n type: \"contour\",\n line: {\n smoothing: 0.85,\n },\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n name: \"Solution Field\",\n };\n\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nexport { FEAScriptModel } from \"./FEAScript.js\";\nexport { importGmshQuadTri } from \"./readers/gmshReaderScript.js\";\nexport { logSystem } from \"./utilities/loggingScript.js\";\nexport { plotSolution } from \"./visualization/plotSolutionScript.js\";\nexport { FEAScriptWorker } from \"./workers/workerScript.js\";\nexport const printVersion = \"0.1.4\";"],"names":["euclideanNorm","vector","norm","i","length","Math","sqrt","currentLogLevel","debugLog","message","console","log","basicLog","errorLog","proxyMarker","Symbol","createEndpoint","releaseProxy","finalizer","throwMarker","isObject","val","transferHandlers","Map","canHandle","serialize","obj","port1","port2","MessageChannel","expose","deserialize","port","start","wrap","value","serialized","Error","isError","name","stack","Object","assign","ep","globalThis","allowedOrigins","addEventListener","callback","ev","data","origin","allowedOrigin","RegExp","test","isAllowedOrigin","warn","id","type","path","argumentList","map","fromWireValue","returnValue","parent","slice","reduce","prop","rawValue","apply","proxy","transfers","transferCache","set","transfer","undefined","Promise","resolve","catch","then","wireValue","transferables","toWireValue","postMessage","removeEventListener","closeEndPoint","error","TypeError","endpoint","constructor","isMessagePort","close","target","pendingListeners","resolver","get","delete","createProxy","throwIfProxyReleased","isReleased","releaseEndpoint","requestResponseMessage","proxyCounter","WeakMap","proxyFinalizers","FinalizationRegistry","newCount","isProxyReleased","Proxy","_target","unregister","unregisterProxy","clear","r","p","toString","bind","_thisArg","rawArgumentList","last","processArguments","construct","register","registerProxy","processed","v","arr","Array","prototype","concat","handler","serializedValue","msg","fill","floor","random","Number","MAX_SAFE_INTEGER","join","solveLinearSystem","solverMethod","jacobianMatrix","residualVector","options","maxIterations","tolerance","solutionVector","converged","iterations","time","jacobianMatrixSparse","math","sparse","luFactorization","slu","solutionMatrix","lusolve","squeeze","valueOf","jacobiSolverResult","A","b","x0","n","x","xNew","iter","sum","j","maxDiff","max","abs","jacobiSolver","timeEnd","async","solveLinearSystemAsync","isArray","toArray","created","computeEngine","worker","Worker","URL","document","require","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","Comlink.wrap","initialize","createDefaultComputeEngine","result","webgpuJacobiSolver","destroy","terminate","BasisFunctions","meshDimension","elementOrder","this","getBasisFunctions","ksi","eta","basisFunction","basisFunctionDerivKsi","basisFunctionDerivEta","l1","c","l2","l3","dl1","dl2","dl3","Mesh","numElementsX","maxX","numElementsY","maxY","parsedMesh","boundaryElementsProcessed","parseMeshFromGmsh","nodalNumbering","quadElements","triangleElements","JSON","stringify","elementTypes","mappedNodalNumbering","elemIdx","gmshNodes","feaScriptNodes","push","physicalPropMap","boundaryElements","fixedBoundaryElements","boundaryNodePairs","forEach","dimension","tag","nodesPair","node1","node2","foundElement","elemNodes","includes","side","node1Index","indexOf","node2Index","Mesh1D","super","generateMesh","nodesXCoordinates","totalNodesX","deltaX","nodeIndex","generate1DNodalNumbering","findBoundaryElements","nop","elementIndex","columnCounter","sideIndex","Mesh2D","nodesYCoordinates","totalNodesY","deltaY","nodeIndexY","nodeIndexX","nnode","generate2DNodalNumbering","rowCounter","elementIndexX","elementIndexY","nodeIndex1","nodeIndex2","NumericalIntegration","getGaussPointsAndWeights","gaussPoints","gaussWeights","prepareMesh","meshConfig","mesh","nodesCoordinatesAndNumbering","totalElements","totalNodes","initializeFEA","meshData","colIndex","basisFunctions","gaussPointsAndWeights","localToGlobalMap","numNodes","performIsoparametricMapping1D","params","xCoordinates","ksiDerivX","localNodeIndex","detJacobian","basisFunctionDerivX","performIsoparametricMapping2D","yCoordinates","etaDerivX","ksiDerivY","etaDerivY","basisFunctionDerivY","ThermalBoundaryConditions","boundaryConditions","imposeConstantTempBoundaryConditions","keys","boundaryKey","tempValue","globalNodeIndex","imposeConstantTempBoundaryConditionsFront","nodeConstraintCode","boundaryValues","imposeConvectionBoundaryConditions","convectionHeatTranfCoeff","convectionExtTemp","key","boundaryCondition","convectionCoeff","extTemp","gaussPoint1","gaussPoint2","firstNodeIndex","lastNodeIndex","nodeIncrement","basisFunctionsAndDerivatives","tangentVectorLength","localNodeIndex2","globalNodeIndex2","gaussPointIndex","imposeConvectionBoundaryConditionsFront","localJacobianMatrix","localResidualVector","boundaryElement","find","_","assembleHeatConductionMat","FEAData","gaussPointIndex1","mappingResult","localNodeIndex1","localToGlobalMap1","localToGlobalMap2","gaussPointIndex2","thermalBoundaryConditions","assembleHeatConductionFront","ngl","globalIndex","GenericBoundaryConditions","imposeDirichletBoundaryConditions","imposeConstantValueBoundaryConditionsFront","assembleFrontPropagationMat","eikonalActivationFlag","eikonalViscousTerm","solutionDerivX","solutionDerivY","assembleFrontPropagationFront","frontalData","frontalState","elementData","currentElementIndex","frontStorage","runFrontalSolver","assembleFront","numElements","globalResidualVector","topologyData","lateralData","writeFlag","transformationFlag","nodesPerElement","determinant","systemSize","globalSolutionVector","frontDataIndex","frontSize","frontWidthEstimate","ceil","estimateFrontSize","frontValues","columnHeaders","pivotRow","pivotData","initializeFrontalArrays","dirichletBoundaryConditionsHandler","currentSolutionVector","pivotColumnGlobalIndex","localDestination","rowDestination","rowHeaders","pivotRowIndices","pivotColumnIndices","modifiedRows","pivotColumn","frontMatrix","rowSwapCount","columnSwapCount","lastAppearanceCheck","frontDataCounter","pivotDataIndex","summedRows","reverseElementIndex","columnCount","rowCount","assembled","numElementNodes","numElementColumns","assembleElementContribution","currentElement","columnIndex","rowIndex","localColumnIndex","frontColumnIndex","localRowIndex","availableColumnCount","constrainedRowCount","availableRowCount","absoluteNodeIndex","constrainedIndex","pivotRowIndex","pivotColumnIndex","pivotValue","testColumnIndex","testRowIndex","testValue","pivotGlobalRowIndex","permutationHelper","rightHandSide","globalRowIndex","eliminationFactor","performBackSubstitution","runFrontalAlgorithm","toExponential","finalNodesX","finalNodesY","nodesCoordinates","boundaryLocalJacobianMatrix","boundaryResidualVector","isOnRobinTypeBoundary","some","localNodeI","localNodeJ","iterationIndex","accumulatedValue","newtonRaphson","assembleMat","context","errorNorm","initialSolution","solverConfig","coefficientFunctions","setSolverConfig","setMeshConfig","addBoundaryCondition","condition","setSolverMethod","solve","eikonalExteralIterations","newtonRaphsonResult","B","C","D","xCoord","a","d","globalNodeIndex1","assembleGeneralFormPDEMat","solveAsync","feaWorker","isReady","_initWorker","onerror","event","workerWrapper","_ensureReady","reject","attempts","checkReady","setTimeout","startTime","performance","now","toFixed","getModelInfo","ping","file","gmshV","ascii","fltBytes","lines","text","split","line","trim","filter","section","lineIndex","nodeEntityBlocks","nodeBlocksProcessed","currentNodeBlock","nodeTagsCollected","nodeTags","nodeCoordinatesCollected","elementEntityBlocks","elementBlocksProcessed","currentElementBlock","dim","elementType","elementsProcessedInBlock","boundaryElementsByTag","parts","part","parseFloat","parseInt","replace","parametric","nodeTag","y","nodeIndices","idx","physicalTag","boundaryNodes","nodes","level","plotType","plotDivId","yData","from","lineData","mode","color","width","maxWindowWidth","min","window","innerWidth","layout","title","height","xaxis","yaxis","margin","l","t","Plotly","newPlot","responsive","zData","aspectRatio","plotWidth","hovermode","contourData","z","smoothing","contours","coloring","showlabels","colorbar"],"mappings":"AAaO,SAASA,EAAcC,GAC5B,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,OAAQD,IACjCD,GAAQD,EAAOE,GAAKF,EAAOE,GAG7B,OADAD,EAAOG,KAAKC,KAAKJ,GACVA,CACT,wDCXA,IAAIK,EAAkB,QAuBf,SAASC,EAASC,GACC,UAApBF,GACFG,QAAQC,IAAI,aAAeF,EAAS,qCAExC,CAMO,SAASG,EAASH,GACvBC,QAAQC,IAAI,YAAcF,EAAS,qCACrC,CAMO,SAASI,EAASJ,GACvBC,QAAQC,IAAI,aAAeF,EAAS,qCACtC;;;;;;AC/CA,MAAMK,EAAcC,OA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ACJ6D,UAAW,KAEbC,SAAU,CACRC,SAAU,UACVC,YAAY,GAGdC,SAAU,CACRpB,MAAO,YAETtf,KAAM,kBAGR6f,OAAOC,QAAQpB,EAAW,CAAC0B,GAAcf,EAAQ,CAAEU,YAAY,GAChE,CACH,uBCjG4B"} \ No newline at end of file diff --git a/dist/feascript.esm.js b/dist/feascript.esm.js index cbda0d4..f36b4b0 100644 --- a/dist/feascript.esm.js +++ b/dist/feascript.esm.js @@ -4,5 +4,5 @@ function e(e){let t=0;for(let n=0;n"object"==typeof e&&null!==e||"function"==typeof e,m=new Map([["proxy",{canHandle:e=>u(e)&&e[r],serialize(e){const{port1:t,port2:n}=new MessageChannel;return h(e,t),[n,[n]]},deserialize:e=>(e.start(),p(e))}],["throw",{canHandle:e=>u(e)&&c in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function h(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(s){if(!s||!s.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,s.origin))return void console.warn(`Invalid origin '${s.origin}' for comlink proxy`);const{id:i,type:a,path:l}=Object.assign({path:[]},s.data),u=(s.data.argumentList||[]).map(D);let m;try{const t=l.slice(0,-1).reduce(((e,t)=>e[t]),e),n=l.reduce(((e,t)=>e[t]),e);switch(a){case"GET":m=n;break;case"SET":t[l.slice(-1)[0]]=D(s.data.value),m=!0;break;case"APPLY":m=n.apply(t,u);break;case"CONSTRUCT":m=function(e){return Object.assign(e,{[r]:!0})}(new n(...u));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;h(e,n),m=function(e,t){return M.set(e,t),e}(t,[t])}break;case"RELEASE":m=void 0;break;default:return}}catch(e){m={value:e,[c]:0}}Promise.resolve(m).catch((e=>({value:e,[c]:0}))).then((n=>{const[s,r]=$(n);t.postMessage(Object.assign(Object.assign({},s),{id:i}),r),"RELEASE"===a&&(t.removeEventListener("message",o),f(t),d in e&&"function"==typeof e[d]&&e[d]())})).catch((e=>{const[n,o]=$({value:new TypeError("Unserializable return value"),[c]:0});t.postMessage(Object.assign(Object.assign({},n),{id:i}),o)}))})),t.start&&t.start()}function f(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function p(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),v(e,n,[],t)}function b(e){if(e)throw new Error("Proxy has been released and is not useable")}function g(e){return F(e,new Map,{type:"RELEASE"}).then((()=>{f(e)}))}const y=new WeakMap,E="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(y.get(e)||0)-1;y.set(e,t),0===t&&g(e)}));function v(e,t,n=[],o=function(){}){let s=!1;const i=new Proxy(o,{get(o,r){if(b(s),r===l)return()=>{!function(e){E&&E.unregister(e)}(i),g(e),t.clear(),s=!0};if("then"===r){if(0===n.length)return{then:()=>i};const o=F(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then(D);return o.then.bind(o)}return v(e,t,[...n,r])},set(o,i,r){b(s);const[a,l]=$(r);return F(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:a},l).then(D)},apply(o,i,r){b(s);const l=n[n.length-1];if(l===a)return F(e,t,{type:"ENDPOINT"}).then(D);if("bind"===l)return v(e,t,n.slice(0,-1));const[d,c]=C(r);return F(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:d},c).then(D)},construct(o,i){b(s);const[r,a]=C(i);return F(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},a).then(D)}});return function(e,t){const n=(y.get(t)||0)+1;y.set(t,n),E&&E.register(e,t,e)}(i,e),i}function C(e){const t=e.map($);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const M=new WeakMap;function $(e){for(const[t,n]of m)if(n.canHandle(e)){const[o,s]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},s]}return[{type:"RAW",value:e},M.get(e)||[]]}function D(e){switch(e.type){case"HANDLER":return m.get(e.name).deserialize(e.value);case"RAW":return e.value}}function F(e,t,n,o){return new Promise((s=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,s),e.start&&e.start(),e.postMessage(Object.assign({id:i},n),o)}))}function x(e,t,n,r={}){const{maxIterations:a=1e4,tolerance:l=1e-4}=r;let d=[],c=!0,u=0;if(s(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),o=math.slu(e,1,1);let s=math.lusolve(o,n);d=math.squeeze(s).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:s,tolerance:i}=o,r=e.length;let a=[...n],l=new Array(r);for(let n=0;n{}))),m.worker.terminate()),{solutionVector:f,converged:b,iterations:u}}class w{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null){let n=[],o=[],s=[];if("1D"===this.meshDimension)"linear"===this.elementOrder?(n[0]=1-e,n[1]=e,o[0]=-1,o[1]=1):"quadratic"===this.elementOrder&&(n[0]=1-3*e+2*e**2,n[1]=4*e-4*e**2,n[2]=2*e**2-e,o[0]=4*e-3,o[1]=4-8*e,o[2]=4*e-1);else if("2D"===this.meshDimension){if(null===t)return void i("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function r(e){return 1-e}n[0]=r(e)*r(t),n[1]=r(e)*t,n[2]=e*r(t),n[3]=e*t,o[0]=-1*r(t),o[1]=-1*t,o[2]=1*r(t),o[3]=1*t,s[0]=-1*r(e),s[1]=1*r(e),s[2]=-1*e,s[3]=1*e}else if("quadratic"===this.elementOrder){function a(e){return 2*e**2-3*e+1}function l(e){return-4*e**2+4*e}function d(e){return 2*e**2-e}function c(e){return 4*e-3}function u(e){return-8*e+4}function m(e){return 4*e-1}n[0]=a(e)*a(t),n[1]=a(e)*l(t),n[2]=a(e)*d(t),n[3]=l(e)*a(t),n[4]=l(e)*l(t),n[5]=l(e)*d(t),n[6]=d(e)*a(t),n[7]=d(e)*l(t),n[8]=d(e)*d(t),o[0]=c(e)*a(t),o[1]=c(e)*l(t),o[2]=c(e)*d(t),o[3]=u(e)*a(t),o[4]=u(e)*l(t),o[5]=u(e)*d(t),o[6]=m(e)*a(t),o[7]=m(e)*l(t),o[8]=m(e)*d(t),s[0]=a(e)*c(t),s[1]=a(e)*u(t),s[2]=a(e)*m(t),s[3]=l(e)*c(t),s[4]=l(e)*u(t),s[5]=l(e)*m(t),s[6]=d(e)*c(t),s[7]=d(e)*u(t),s[8]=d(e)*m(t)}}return{basisFunction:n,basisFunctionDerivKsi:o,basisFunctionDerivEta:s}}}class N{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:o=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:a=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=o,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=a,this.boundaryElementsProcessed=!1,this.parsedMesh&&(s("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||i("No valid nodal numbering found in the parsed mesh."),"object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,o("Initial parsed mesh nodal numbering from GMSH format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.elementTypes[3]||this.parsedMesh.elementTypes[10]){const t=[];for(let n=0;n0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t{if(1===e.dimension){const t=this.parsedMesh.boundaryNodePairs[e.tag]||[];t.length>0&&(this.parsedMesh.boundaryElements[e.tag]||(this.parsedMesh.boundaryElements[e.tag]=[]),t.forEach((t=>{const n=t[0],s=t[1];o(`Processing boundary node pair: [${n}, ${s}] for boundary ${e.tag} (${e.name||"unnamed"})`);let r=!1;for(let t=0;t0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}imposeConvectionBoundaryConditions(e,t,n,s,i,r,a){let l=[],d=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(l[e]=t[1],d[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("convection"===this.boundaryConditions[n][0]){const s=l[n],i=d[n];o(`Boundary ${n}: Applying convection with heat transfer coefficient h=${s} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[n].forEach((([n,r])=>{let a;"linear"===this.elementOrder?a=0===r?0:1:"quadratic"===this.elementOrder&&(a=0===r?0:2);const l=this.nop[n][a]-1;o(` - Applied convection boundary condition to node ${l+1} (element ${n+1}, local node ${a+1})`),e[l]+=-s*i,t[l][l]+=s}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const u=l[c],m=d[c];o(`Boundary ${c}: Applying convection with heat transfer coefficient h=${u} W/(m²·K) and external temperature T∞=${m} K`),this.boundaryElements[c].forEach((([l,d])=>{if("linear"===this.elementOrder){let c,h,f,p,b;0===d?(c=n[0],h=0,f=0,p=3,b=2):1===d?(c=0,h=n[0],f=0,p=2,b=1):2===d?(c=n[0],h=1,f=1,p=4,b=2):3===d&&(c=1,h=n[0],f=2,p=4,b=1);let g=a.getBasisFunctions(c,h),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta,C=0,M=0,$=0,D=0;const F=this.nop[l].length;for(let e=0;e{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])}));const d=this.nop[e].length,c=Array(d).fill().map((()=>Array(d).fill(0))),u=Array(d).fill(0);for(const m in this.boundaryElements)if("convection"===this.boundaryConditions[m]?.[0]){const h=a[m],f=l[m];o(`Boundary ${m}: Applying convection with heat transfer coefficient h=${h} W/(m²·K) and external temperature T∞=${f} K`);const p=this.boundaryElements[m].find((([t,n])=>t===e));if(p){const a=p[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===a?0:1:"quadratic"===this.elementOrder&&(t=0===a?0:2),o(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),u[t]+=-h*f,c[t][t]+=h}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let o,l,m,p,b;0===a?(o=s[0],l=0,m=0,p=3,b=2):1===a?(o=0,l=s[0],m=0,p=2,b=1):2===a?(o=s[0],l=1,m=1,p=4,b=2):3===a&&(o=1,l=s[0],m=2,p=4,b=1);const g=r.getBasisFunctions(o,l),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta;let C,M=0,$=0,D=0,F=0;for(let o=0;oArray(a).fill(0))),m=Array(a).fill(0),h=Array(a),f=Array(a);for(let n=0;ne-1)),{detJacobian:f,basisFunctionDerivX:p,basisFunctionDerivY:b}=I({basisFunction:n,basisFunctionDerivKsi:s,basisFunctionDerivEta:c,nodesXCoordinates:l,nodesYCoordinates:d,localToGlobalMap:m,numNodes:a});for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}}function j(e,t,n,i){s("Starting front propagation matrix assembly...");let r=1-i+.01;o(`eikonalViscousTerm: ${r}`),o(`eikonalActivationFlag: ${i}`);const{nodesXCoordinates:a,nodesYCoordinates:l,nop:d,boundaryElements:c,totalElements:u,meshDimension:m,elementOrder:h}=e,f=k(e),{residualVector:p,jacobianMatrix:b,localToGlobalMap:g,basisFunctions:y,gaussPoints:E,gaussWeights:v,numNodes:C}=f;for(let e=0;eArray(d).fill(0))),p=Array(d).fill(0),b=Array(d),g=Array(d);for(let n=0;nArray(e).fill(0))),W.nodeConstraintCode=Array(e).fill(0),W.boundaryValues=Array(e).fill(0),W.globalResidualVector=Array(e).fill(0),W.solutionVector=Array(e).fill(0),W.topologyData=Array(t).fill(0),W.lateralData=Array(t).fill(0),G.writeFlag=0,G.totalNodes=e,G.transformationFlag=0,G.nodesPerElement=Array(t).fill(0),G.determinant=1;const n=Math.max(e,2e3);G.globalSolutionVector=Array(n).fill(0),G.frontDataIndex=0,K.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),K.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);J.frontValues=Array(o).fill(0),J.columnHeaders=Array(n).fill(0),J.pivotRow=Array(n).fill(0),J.pivotData=Array(o).fill(0)}(a.numNodes,d),s("Solving system using frontal..."),console.time("systemSolving"),H=new w({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;eArray(l).fill(0))),y=Array(a).fill(0),E=Array(a).fill(0),v=Array(a).fill(0),C=1;G.writeFlag++;let M=1,$=1;K.currentElementIndex=0;for(let e=0;el||D>l)return void i("Error: systemSize not large enough");for(let e=0;e0)for(let e=0;e$||K.currentElementIndexMath.abs(n)&&(n=r,t=s,e=i)}}}let s=Math.abs(m[e-1]);d=Math.abs(J.columnHeaders[t-1]);let a=s+d+y[s-1]+E[d-1];G.determinant=G.determinant*n*(-1)**a/Math.abs(n);for(let e=0;e=s&&y[e]--,e>=d&&E[e]--;if(Math.abs(n)<1e-10&&i(`Matrix singular or ill-conditioned, currentElementIndex=${K.currentElementIndex}, pivotGlobalRowIndex=${s}, pivotColumnGlobalIndex=${d}, pivotValue=${n}`),0===n)return;for(let t=0;t1)for(let n=0;n1&&0!==o)for(let e=0;e1)for(let e=0;e1||K.currentElementIndex=e.totalElements)return i(`Skipping out-of-range elementIndex=${s} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:a,ngl:l}=o({elementIndex:s,nop:W.nodalNumbering,meshData:e,basisFunctions:H,FEAData:t,solutionVector:G.currentSolutionVector,eikonalActivationFlag:G.eikonalActivationFlag});let d=Array(t.numNodes).fill().map((()=>Array(t.numNodes).fill(0))),c=Array(t.numNodes).fill(0);if(o===Y){let o=!1;for(const t in e.boundaryElements)if("convection"===n.boundaryConditions[t]?.[0]&&e.boundaryElements[t].some((([e,t])=>e===s))){o=!0;break}if(o){const{gaussPoints:o,gaussWeights:i}=t,r=n.imposeConvectionBoundaryConditionsFront(s,e.nodesXCoordinates,e.nodesYCoordinates,o,i,H);d=r.localJacobianMatrix,c=r.localResidualVector}}for(let e=0;e0)continue;let r=0;J.pivotRow[s-1]=0;for(let e=0;e100){i(`Solution not converged. Error norm: ${o}`);break}a++}return{solutionVector:d,converged:r,iterations:a,jacobianMatrix:c,residualVector:u}}class Q{constructor(){var e;this.solverConfig=null,this.meshConfig={},this.boundaryConditions={},this.solverMethod="lusolve",this.coefficientFunctions=null,e="FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE",console.log("%c[WARN] "+e,"color: #FF9800; font-weight: bold;"),s("FEAScriptModel instance created")}setSolverConfig(e,t={}){this.solverConfig=e,t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,o("Coefficient functions set")),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations),void 0!==t?.tolerance&&(this.tolerance=t.tolerance),o(`Solver config set to: ${e}`)}setMeshConfig(e){this.meshConfig=e,o(`Mesh config set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,o(`Boundary condition added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,o(`Solver method set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||i("Solver config, mesh config, and boundary conditions must be set before solving.");let t=[],n=[],o=[],r=[];s("Preparing mesh...");const a=V(this.meshConfig);s("Mesh preparation completed");const l={nodesXCoordinates:a.nodesXCoordinates,nodesYCoordinates:a.nodesYCoordinates};if(s("Beginning solving process..."),console.time("totalSolvingTime"),s(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){o=L(Y,a,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=R(a,this.boundaryConditions));o=x(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let s=0;const i=5,l={meshData:a,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:s,solverMethod:this.solverMethod,initialSolution:r,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;s<=1;){l.eikonalActivationFlag=s,o.length>0&&(l.initialSolution=[...o]);const e=_(j,l);t=e.jacobianMatrix,n=e.residualVector,o=e.solutionVector,s+=1/i}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)i("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){s("Starting general form PDE matrix assembly...");const{nodesXCoordinates:o,nodesYCoordinates:r,nop:a,boundaryElements:l,totalElements:d,meshDimension:c,elementOrder:u}=e,{A:m,B:h,C:f,D:p}=n,b=k(e),{residualVector:g,jacobianMatrix:y,localToGlobalMap:E,basisFunctions:v,gaussPoints:C,gaussWeights:M,numNodes:$}=b;if("1D"===c)for(let e=0;e{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}},n=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e&&" "!==e)),s="",i=0,r=0,a=0,l=0,d={numNodes:0},c=0,u=[],m=0,h=0,f=0,p={dim:0,tag:0,elementType:0,numElements:0},b=0,g={};for(;i""!==e));if("meshFormat"===s)t.gmshV=parseFloat(o[0]),t.ascii="0"===o[1],t.fltBytes=o[2];else if("physicalNames"===s){if(o.length>=3){if(!/^\d+$/.test(o[0])){i++;continue}const e=parseInt(o[0],10),n=parseInt(o[1],10);let s=o.slice(2).join(" ");s=s.replace(/^"|"$/g,""),t.physicalPropMap.push({tag:n,dimension:e,name:s})}}else if("nodes"===s){if(0===r){r=parseInt(o[0],10),a=parseInt(o[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0),i++;continue}if(lparseInt(e,10)));if(1===p.elementType||8===p.elementType){const n=p.tag;g[n]||(g[n]=[]),g[n].push(e),t.boundaryNodePairs[n]||(t.boundaryNodePairs[n]=[]),t.boundaryNodePairs[n].push(e)}else 2===p.elementType?t.nodalNumbering.triangleElements.push(e):(3===p.elementType||10===p.elementType)&&t.nodalNumbering.quadElements.push(e);b++,b===p.numElements&&(f++,p={numElements:0})}}i++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=g[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),o(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}. These pairs will be used to identify boundary elements in the mesh.`),t};function ee(e,t,n,o,s,i,r="structured"){const{nodesXCoordinates:a,nodesYCoordinates:l}=t;if("1D"===o&&"line"===s){let t;t=e.length>0&&Array.isArray(e[0])?e.map((e=>e[0])):e;let o=Array.from(a),s={x:o,y:t,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},r=Math.min(window.innerWidth,700),l=Math.max(...o),d=r/l,c={title:`line plot - ${n}`,width:Math.max(d*l,400),height:350,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:70,r:40,t:50,b:50}};Plotly.newPlot(i,[s],c,{responsive:!0})}else if("2D"===o&&"contour"===s){const t="structured"===r,o=new Set(a).size,d=new Set(l).size;let c;c=Array.isArray(e[0])?e.map((e=>e[0])):e;let u=Math.min(window.innerWidth,700),m=Math.max(...a),h=Math.max(...l)/m,f=Math.min(u,600),p={title:`${s} plot - ${n}`,width:f,height:f*h*.8,xaxis:{title:"x"},yaxis:{title:"y"},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"};if(t){const t=o,n=d;math.reshape(Array.from(a),[t,n]);let s=math.reshape(Array.from(l),[t,n]),r=math.reshape(Array.from(e),[t,n]),c=math.transpose(r),u=[];for(let e=0;e{console.error("FEAScriptWorker: Worker error:",e)};const e=p(this.worker);this.feaWorker=await new e,this.isReady=!0}catch(e){throw console.error("Failed to initialize worker",e),e}}async _ensureReady(){return this.isReady?Promise.resolve():new Promise(((e,t)=>{let n=0;const o=()=>{n++,this.isReady?e():n>=50?t(new Error("Timeout waiting for worker to be ready")):setTimeout(o,1e3)};o()}))}async setSolverConfig(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver config to: ${e}`),this.feaWorker.setSolverConfig(e)}async setMeshConfig(e){return await this._ensureReady(),s("FEAScriptWorker: Setting mesh config"),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),s(`FEAScriptWorker: Adding boundary condition for boundary: ${e}`),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver method to: ${e}`),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),s("FEAScriptWorker: Requesting solution from worker...");const e=performance.now(),t=await this.feaWorker.solve();return s(`FEAScriptWorker: Solution completed in ${((performance.now()-e)/1e3).toFixed(2)}s`),t}async getModelInfo(){return await this._ensureReady(),this.feaWorker.getModelInfo()}async ping(){return await this._ensureReady(),this.feaWorker.ping()}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.feaWorker=null,this.isReady=!1)}}const ne="0.1.4";export{Q as FEAScriptModel,te as FEAScriptWorker,Z as importGmshQuadTri,n as logSystem,ee as plotSolution,ne as printVersion}; +const r=Symbol("Comlink.proxy"),a=Symbol("Comlink.endpoint"),l=Symbol("Comlink.releaseProxy"),d=Symbol("Comlink.finalizer"),c=Symbol("Comlink.thrown"),u=e=>"object"==typeof e&&null!==e||"function"==typeof e,m=new Map([["proxy",{canHandle:e=>u(e)&&e[r],serialize(e){const{port1:t,port2:n}=new MessageChannel;return h(e,t),[n,[n]]},deserialize:e=>(e.start(),p(e))}],["throw",{canHandle:e=>u(e)&&c in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function h(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(s){if(!s||!s.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,s.origin))return void console.warn(`Invalid origin '${s.origin}' for comlink proxy`);const{id:i,type:a,path:l}=Object.assign({path:[]},s.data),u=(s.data.argumentList||[]).map(D);let m;try{const t=l.slice(0,-1).reduce(((e,t)=>e[t]),e),n=l.reduce(((e,t)=>e[t]),e);switch(a){case"GET":m=n;break;case"SET":t[l.slice(-1)[0]]=D(s.data.value),m=!0;break;case"APPLY":m=n.apply(t,u);break;case"CONSTRUCT":m=function(e){return Object.assign(e,{[r]:!0})}(new n(...u));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;h(e,n),m=function(e,t){return M.set(e,t),e}(t,[t])}break;case"RELEASE":m=void 0;break;default:return}}catch(e){m={value:e,[c]:0}}Promise.resolve(m).catch((e=>({value:e,[c]:0}))).then((n=>{const[s,r]=$(n);t.postMessage(Object.assign(Object.assign({},s),{id:i}),r),"RELEASE"===a&&(t.removeEventListener("message",o),f(t),d in e&&"function"==typeof e[d]&&e[d]())})).catch((e=>{const[n,o]=$({value:new TypeError("Unserializable return value"),[c]:0});t.postMessage(Object.assign(Object.assign({},n),{id:i}),o)}))})),t.start&&t.start()}function f(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function p(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),v(e,n,[],t)}function b(e){if(e)throw new Error("Proxy has been released and is not useable")}function g(e){return F(e,new Map,{type:"RELEASE"}).then((()=>{f(e)}))}const y=new WeakMap,E="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(y.get(e)||0)-1;y.set(e,t),0===t&&g(e)}));function v(e,t,n=[],o=function(){}){let s=!1;const i=new Proxy(o,{get(o,r){if(b(s),r===l)return()=>{!function(e){E&&E.unregister(e)}(i),g(e),t.clear(),s=!0};if("then"===r){if(0===n.length)return{then:()=>i};const o=F(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then(D);return o.then.bind(o)}return v(e,t,[...n,r])},set(o,i,r){b(s);const[a,l]=$(r);return F(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:a},l).then(D)},apply(o,i,r){b(s);const l=n[n.length-1];if(l===a)return F(e,t,{type:"ENDPOINT"}).then(D);if("bind"===l)return v(e,t,n.slice(0,-1));const[d,c]=C(r);return F(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:d},c).then(D)},construct(o,i){b(s);const[r,a]=C(i);return F(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},a).then(D)}});return function(e,t){const n=(y.get(t)||0)+1;y.set(t,n),E&&E.register(e,t,e)}(i,e),i}function C(e){const t=e.map($);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const M=new WeakMap;function $(e){for(const[t,n]of m)if(n.canHandle(e)){const[o,s]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},s]}return[{type:"RAW",value:e},M.get(e)||[]]}function D(e){switch(e.type){case"HANDLER":return m.get(e.name).deserialize(e.value);case"RAW":return e.value}}function F(e,t,n,o){return new Promise((s=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,s),e.start&&e.start(),e.postMessage(Object.assign({id:i},n),o)}))}function x(e,t,n,r={}){const{maxIterations:a=1e4,tolerance:l=1e-4}=r;let d=[],c=!0,u=0;if(s(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),o=math.slu(e,1,1);let s=math.lusolve(o,n);d=math.squeeze(s).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:s,tolerance:i}=o,r=e.length;let a=[...n],l=new Array(r);for(let n=0;n{}))),m.worker.terminate()),{solutionVector:f,converged:b,iterations:u}}class w{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null){let n=[],o=[],s=[];if("1D"===this.meshDimension)"linear"===this.elementOrder?(n[0]=1-e,n[1]=e,o[0]=-1,o[1]=1):"quadratic"===this.elementOrder&&(n[0]=1-3*e+2*e**2,n[1]=4*e-4*e**2,n[2]=2*e**2-e,o[0]=4*e-3,o[1]=4-8*e,o[2]=4*e-1);else if("2D"===this.meshDimension){if(null===t)return void i("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function r(e){return 1-e}n[0]=r(e)*r(t),n[1]=r(e)*t,n[2]=e*r(t),n[3]=e*t,o[0]=-1*r(t),o[1]=-1*t,o[2]=1*r(t),o[3]=1*t,s[0]=-1*r(e),s[1]=1*r(e),s[2]=-1*e,s[3]=1*e}else if("quadratic"===this.elementOrder){function a(e){return 2*e**2-3*e+1}function l(e){return-4*e**2+4*e}function d(e){return 2*e**2-e}function c(e){return 4*e-3}function u(e){return-8*e+4}function m(e){return 4*e-1}n[0]=a(e)*a(t),n[1]=a(e)*l(t),n[2]=a(e)*d(t),n[3]=l(e)*a(t),n[4]=l(e)*l(t),n[5]=l(e)*d(t),n[6]=d(e)*a(t),n[7]=d(e)*l(t),n[8]=d(e)*d(t),o[0]=c(e)*a(t),o[1]=c(e)*l(t),o[2]=c(e)*d(t),o[3]=u(e)*a(t),o[4]=u(e)*l(t),o[5]=u(e)*d(t),o[6]=m(e)*a(t),o[7]=m(e)*l(t),o[8]=m(e)*d(t),s[0]=a(e)*c(t),s[1]=a(e)*u(t),s[2]=a(e)*m(t),s[3]=l(e)*c(t),s[4]=l(e)*u(t),s[5]=l(e)*m(t),s[6]=d(e)*c(t),s[7]=d(e)*u(t),s[8]=d(e)*m(t)}}return{basisFunction:n,basisFunctionDerivKsi:o,basisFunctionDerivEta:s}}}class N{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:o=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:a=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=o,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=a,this.boundaryElementsProcessed=!1,this.parsedMesh&&(s("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||i("No valid nodal numbering found in the parsed mesh."),"object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,o("Initial parsed mesh nodal numbering from GMSH format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.elementTypes[3]||this.parsedMesh.elementTypes[10]){const t=[];for(let n=0;n0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t{if(1===e.dimension){const t=this.parsedMesh.boundaryNodePairs[e.tag]||[];t.length>0&&(this.parsedMesh.boundaryElements[e.tag]||(this.parsedMesh.boundaryElements[e.tag]=[]),t.forEach((t=>{const n=t[0],s=t[1];o(`Processing boundary node pair: [${n}, ${s}] for boundary ${e.tag} (${e.name||"unnamed"})`);let r=!1;for(let t=0;t0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}imposeConvectionBoundaryConditions(e,t,n,s,i,r,a){let l=[],d=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(l[e]=t[1],d[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("convection"===this.boundaryConditions[n][0]){const s=l[n],i=d[n];o(`Boundary ${n}: Applying convection with heat transfer coefficient h=${s} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[n].forEach((([n,r])=>{let a;"linear"===this.elementOrder?a=0===r?0:1:"quadratic"===this.elementOrder&&(a=0===r?0:2);const l=this.nop[n][a]-1;o(` - Applied convection boundary condition to node ${l+1} (element ${n+1}, local node ${a+1})`),e[l]+=-s*i,t[l][l]+=s}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const u=l[c],m=d[c];o(`Boundary ${c}: Applying convection with heat transfer coefficient h=${u} W/(m²·K) and external temperature T∞=${m} K`),this.boundaryElements[c].forEach((([l,d])=>{if("linear"===this.elementOrder){let c,h,f,p,b;0===d?(c=n[0],h=0,f=0,p=3,b=2):1===d?(c=0,h=n[0],f=0,p=2,b=1):2===d?(c=n[0],h=1,f=1,p=4,b=2):3===d&&(c=1,h=n[0],f=2,p=4,b=1);let g=a.getBasisFunctions(c,h),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta,C=0,M=0,$=0,D=0;const F=this.nop[l].length;for(let e=0;e{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])}));const d=this.nop[e].length,c=Array(d).fill().map((()=>Array(d).fill(0))),u=Array(d).fill(0);for(const m in this.boundaryElements)if("convection"===this.boundaryConditions[m]?.[0]){const h=a[m],f=l[m];o(`Boundary ${m}: Applying convection with heat transfer coefficient h=${h} W/(m²·K) and external temperature T∞=${f} K`);const p=this.boundaryElements[m].find((([t,n])=>t===e));if(p){const a=p[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===a?0:1:"quadratic"===this.elementOrder&&(t=0===a?0:2),o(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),u[t]+=-h*f,c[t][t]+=h}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let o,l,m,p,b;0===a?(o=s[0],l=0,m=0,p=3,b=2):1===a?(o=0,l=s[0],m=0,p=2,b=1):2===a?(o=s[0],l=1,m=1,p=4,b=2):3===a&&(o=1,l=s[0],m=2,p=4,b=1);const g=r.getBasisFunctions(o,l),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta;let C,M=0,$=0,D=0,F=0;for(let o=0;oArray(a).fill(0))),m=Array(a).fill(0),h=Array(a),f=Array(a);for(let n=0;ne-1)),{detJacobian:f,basisFunctionDerivX:p,basisFunctionDerivY:b}=I({basisFunction:n,basisFunctionDerivKsi:s,basisFunctionDerivEta:c,nodesXCoordinates:l,nodesYCoordinates:d,localToGlobalMap:m,numNodes:a});for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}}function j(e,t,n,i){s("Starting front propagation matrix assembly...");let r=1-i+.01;o(`eikonalViscousTerm: ${r}`),o(`eikonalActivationFlag: ${i}`);const{nodesXCoordinates:a,nodesYCoordinates:l,nop:d,boundaryElements:c,totalElements:u,meshDimension:m,elementOrder:h}=e,f=k(e),{residualVector:p,jacobianMatrix:b,localToGlobalMap:g,basisFunctions:y,gaussPoints:E,gaussWeights:v,numNodes:C}=f;for(let e=0;eArray(d).fill(0))),p=Array(d).fill(0),b=Array(d),g=Array(d);for(let n=0;nArray(e).fill(0))),W.nodeConstraintCode=Array(e).fill(0),W.boundaryValues=Array(e).fill(0),W.globalResidualVector=Array(e).fill(0),W.solutionVector=Array(e).fill(0),W.topologyData=Array(t).fill(0),W.lateralData=Array(t).fill(0),G.writeFlag=0,G.totalNodes=e,G.transformationFlag=0,G.nodesPerElement=Array(t).fill(0),G.determinant=1;const n=Math.max(e,2e3);G.globalSolutionVector=Array(n).fill(0),G.frontDataIndex=0,K.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),K.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);J.frontValues=Array(o).fill(0),J.columnHeaders=Array(n).fill(0),J.pivotRow=Array(n).fill(0),J.pivotData=Array(o).fill(0)}(a.numNodes,d),s("Solving system using frontal..."),console.time("systemSolving"),H=new w({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;eArray(l).fill(0))),y=Array(a).fill(0),E=Array(a).fill(0),v=Array(a).fill(0),C=1;G.writeFlag++;let M=1,$=1;K.currentElementIndex=0;for(let e=0;el||D>l)return void i("Error: systemSize not large enough");for(let e=0;e0)for(let e=0;e$||K.currentElementIndexMath.abs(n)&&(n=r,t=s,e=i)}}}let s=Math.abs(m[e-1]);d=Math.abs(J.columnHeaders[t-1]);let a=s+d+y[s-1]+E[d-1];G.determinant=G.determinant*n*(-1)**a/Math.abs(n);for(let e=0;e=s&&y[e]--,e>=d&&E[e]--;if(Math.abs(n)<1e-10&&i(`Matrix singular or ill-conditioned, currentElementIndex=${K.currentElementIndex}, pivotGlobalRowIndex=${s}, pivotColumnGlobalIndex=${d}, pivotValue=${n}`),0===n)return;for(let t=0;t1)for(let n=0;n1&&0!==o)for(let e=0;e1)for(let e=0;e1||K.currentElementIndex=e.totalElements)return i(`Skipping out-of-range elementIndex=${s} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:a,ngl:l}=o({elementIndex:s,nop:W.nodalNumbering,meshData:e,basisFunctions:H,FEAData:t,solutionVector:G.currentSolutionVector,eikonalActivationFlag:G.eikonalActivationFlag});let d=Array(t.numNodes).fill().map((()=>Array(t.numNodes).fill(0))),c=Array(t.numNodes).fill(0);if(o===Y){let o=!1;for(const t in e.boundaryElements)if("convection"===n.boundaryConditions[t]?.[0]&&e.boundaryElements[t].some((([e,t])=>e===s))){o=!0;break}if(o){const{gaussPoints:o,gaussWeights:i}=t,r=n.imposeConvectionBoundaryConditionsFront(s,e.nodesXCoordinates,e.nodesYCoordinates,o,i,H);d=r.localJacobianMatrix,c=r.localResidualVector}}for(let e=0;e0)continue;let r=0;J.pivotRow[s-1]=0;for(let e=0;e100){i(`Solution not converged. Error norm: ${o}`);break}a++}return{solutionVector:d,converged:r,iterations:a,jacobianMatrix:c,residualVector:u}}class Q{constructor(){var e;this.solverConfig=null,this.meshConfig={},this.boundaryConditions={},this.solverMethod="lusolve",this.coefficientFunctions=null,e="FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE",console.log("%c[WARN] "+e,"color: #FF9800; font-weight: bold;"),s("FEAScriptModel instance created")}setSolverConfig(e,t={}){this.solverConfig=e,t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,o("Coefficient functions set")),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations),void 0!==t?.tolerance&&(this.tolerance=t.tolerance),o(`Solver config set to: ${e}`)}setMeshConfig(e){this.meshConfig=e,o(`Mesh config set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,o(`Boundary condition added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,o(`Solver method set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||i("Solver config, mesh config, and boundary conditions must be set before solving.");let t=[],n=[],o=[],r=[];s("Preparing mesh...");const a=V(this.meshConfig);s("Mesh preparation completed");const l={nodesXCoordinates:a.nodesXCoordinates,nodesYCoordinates:a.nodesYCoordinates};if(s("Beginning solving process..."),console.time("totalSolvingTime"),s(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){o=L(Y,a,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=P(a,this.boundaryConditions));o=x(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let s=0;const i=5,l={meshData:a,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:s,solverMethod:this.solverMethod,initialSolution:r,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;s<=1;){l.eikonalActivationFlag=s,o.length>0&&(l.initialSolution=[...o]);const e=_(j,l);t=e.jacobianMatrix,n=e.residualVector,o=e.solutionVector,s+=1/i}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)i("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){s("Starting general form PDE matrix assembly...");const{nodesXCoordinates:o,nodesYCoordinates:r,nop:a,boundaryElements:l,totalElements:d,meshDimension:c,elementOrder:u}=e,{A:m,B:h,C:f,D:p}=n,b=k(e),{residualVector:g,jacobianMatrix:y,localToGlobalMap:E,basisFunctions:v,gaussPoints:C,gaussWeights:M,numNodes:$}=b;if("1D"===c)for(let e=0;e{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}},n=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e&&" "!==e)),s="",i=0,r=0,a=0,l=0,d={numNodes:0},c=0,u=[],m=0,h=0,f=0,p={dim:0,tag:0,elementType:0,numElements:0},b=0,g={};for(;i""!==e));if("meshFormat"===s)t.gmshV=parseFloat(o[0]),t.ascii="0"===o[1],t.fltBytes=o[2];else if("physicalNames"===s){if(o.length>=3){if(!/^\d+$/.test(o[0])){i++;continue}const e=parseInt(o[0],10),n=parseInt(o[1],10);let s=o.slice(2).join(" ");s=s.replace(/^"|"$/g,""),t.physicalPropMap.push({tag:n,dimension:e,name:s})}}else if("nodes"===s){if(0===r){r=parseInt(o[0],10),a=parseInt(o[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0),i++;continue}if(lparseInt(e,10)));if(1===p.elementType||8===p.elementType){const n=p.tag;g[n]||(g[n]=[]),g[n].push(e),t.boundaryNodePairs[n]||(t.boundaryNodePairs[n]=[]),t.boundaryNodePairs[n].push(e)}else 2===p.elementType?t.nodalNumbering.triangleElements.push(e):(3===p.elementType||10===p.elementType)&&t.nodalNumbering.quadElements.push(e);b++,b===p.numElements&&(f++,p={numElements:0})}}i++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=g[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),o(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}. These pairs will be used to identify boundary elements in the mesh.`),t};function ee(e,t,n,o,s,i){const{nodesXCoordinates:r,nodesYCoordinates:a}=t;if("1D"===o&&"line"===s){let t;t=e.length>0&&Array.isArray(e[0])?e.map((e=>e[0])):e,Array.from(r);let o={x:r,y:t,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},s=Math.min(window.innerWidth,700),a={title:`line plot - ${n}`,width:Math.min(s,600),height:350,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:50,r:50,t:50,b:50}};Plotly.newPlot(i,[o],a,{responsive:!0})}else if("2D"===o&&"contour"===s){let t;t=Array.isArray(e[0])?e.map((e=>e[0])):e;let o=Math.min(window.innerWidth,700),l=Math.max(...r),d=Math.max(...a)/l,c=Math.min(o,600),u={title:`${s} plot - ${n}`,width:c,height:c*d,xaxis:{title:"x"},yaxis:{title:"y"},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"},m={x:r,y:a,z:t,type:"contour",line:{smoothing:.85},contours:{coloring:"heatmap",showlabels:!1},colorbar:{title:"Solution"},name:"Solution Field"};Plotly.newPlot(i,[m],u,{responsive:!0})}}class te{constructor(){this.worker=null,this.feaWorker=null,this.isReady=!1,this._initWorker()}async _initWorker(){try{this.worker=new Worker(new URL("./wrapperScript.js",import.meta.url),{type:"module"}),this.worker.onerror=e=>{console.error("FEAScriptWorker: Worker error:",e)};const e=p(this.worker);this.feaWorker=await new e,this.isReady=!0}catch(e){throw console.error("Failed to initialize worker",e),e}}async _ensureReady(){return this.isReady?Promise.resolve():new Promise(((e,t)=>{let n=0;const o=()=>{n++,this.isReady?e():n>=50?t(new Error("Timeout waiting for worker to be ready")):setTimeout(o,1e3)};o()}))}async setSolverConfig(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver config to: ${e}`),this.feaWorker.setSolverConfig(e)}async setMeshConfig(e){return await this._ensureReady(),s("FEAScriptWorker: Setting mesh config"),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),s(`FEAScriptWorker: Adding boundary condition for boundary: ${e}`),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver method to: ${e}`),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),s("FEAScriptWorker: Requesting solution from worker...");const e=performance.now(),t=await this.feaWorker.solve();return s(`FEAScriptWorker: Solution completed in ${((performance.now()-e)/1e3).toFixed(2)}s`),t}async getModelInfo(){return await this._ensureReady(),this.feaWorker.getModelInfo()}async ping(){return await this._ensureReady(),this.feaWorker.ping()}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.feaWorker=null,this.isReady=!1)}}const ne="0.1.4";export{Q as FEAScriptModel,te as FEAScriptWorker,Z as importGmshQuadTri,n as logSystem,ee as plotSolution,ne as printVersion}; //# sourceMappingURL=feascript.esm.js.map diff --git a/dist/feascript.esm.js.map b/dist/feascript.esm.js.map index 4c725cc..1a7ece7 100644 --- a/dist/feascript.esm.js.map +++ b/dist/feascript.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"feascript.esm.js","sources":["../src/methods/euclideanNormScript.js","../src/utilities/loggingScript.js","../src/vendor/comlink.mjs","../src/methods/linearSystemSolverScript.js","../src/methods/jacobiSolverScript.js","../src/mesh/basisFunctionsScript.js","../src/mesh/meshGenerationScript.js","../src/methods/numericalIntegrationScript.js","../src/mesh/meshUtilsScript.js","../src/models/thermalBoundaryConditionsScript.js","../src/models/heatConductionScript.js","../src/models/genericBoundaryConditionsScript.js","../src/models/frontPropagationScript.js","../src/methods/frontalSolverScript.js","../src/methods/newtonRaphsonScript.js","../src/FEAScript.js","../src/models/generalFormPDEScript.js","../src/readers/gmshReaderScript.js","../src/visualization/plotSolutionScript.js","../src/workers/workerScript.js","../src/index.js"],"sourcesContent":["/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to calculate the Euclidean norm of a vector\n * @param {array} vector - The input vector\n * @returns {number} The Euclidean norm of the vector\n */\nexport function euclideanNorm(vector) {\n let norm = 0;\n for (let i = 0; i < vector.length; i++) {\n norm += vector[i] * vector[i];\n }\n norm = Math.sqrt(norm);\n return norm;\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Global logging level\nlet currentLogLevel = \"basic\";\n\n/**\n * Function to set the logging system level\n * @param {string} level - Logging level (basic, debug)\n */\nexport function logSystem(level) {\n if (level !== \"basic\" && level !== \"debug\") {\n console.log(\n \"%c[WARN] Invalid log level: \" + level + \". Using basic instead.\",\n \"color: #FFC107; font-weight: bold;\"\n ); // Yellow for warnings\n currentLogLevel = \"basic\";\n } else {\n currentLogLevel = level;\n basicLog(`Log level set to: ${level}`);\n }\n}\n\n/**\n * Function to log debug messages - only logs if level is 'debug'\n * @param {string} message - Message to log\n */\nexport function debugLog(message) {\n if (currentLogLevel === \"debug\") {\n console.log(\"%c[DEBUG] \" + message, \"color: #2196F3; font-weight: bold;\");\n }\n}\n\n/**\n * Function to log basic information - always logs\n * @param {string} message - Message to log\n */\nexport function basicLog(message) {\n console.log(\"%c[INFO] \" + message, \"color: #4CAF50; font-weight: bold;\");\n}\n\n/**\n * Function to log error messages\n * @param {string} message - Message to log\n */\nexport function errorLog(message) {\n console.log(\"%c[ERROR] \" + message, \"color: #F44336; font-weight: bold;\");\n}\n\n/**\n * Function to log warning messages\n * @param {string} message - Message to log\n */\nexport function warnLog(message) {\n console.log(\"%c[WARN] \" + message, \"color: #FF9800; font-weight: bold;\");\n}\n\n/**\n * Function to handle version information and fetch the latest update date and release from GitHub\n */\nexport async function printVersionInformation() {\n basicLog(\"Fetching latest FEAScript version information...\");\n try {\n const commitResponse = await fetch(\"https://api.github.com/repos/FEAScript/FEAScript/commits/main\");\n const commitData = await commitResponse.json();\n const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();\n basicLog(`Latest FEAScript update: ${latestCommitDate}`);\n return latestCommitDate;\n } catch (error) {\n errorLog(\"Failed to fetch version information: \" + error);\n return \"Version information unavailable\";\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\nconst proxyMarker = Symbol(\"Comlink.proxy\");\nconst createEndpoint = Symbol(\"Comlink.endpoint\");\nconst releaseProxy = Symbol(\"Comlink.releaseProxy\");\nconst finalizer = Symbol(\"Comlink.finalizer\");\nconst throwMarker = Symbol(\"Comlink.thrown\");\nconst isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n};\n/**\n * Allows customizing the serialization of certain values.\n */\nconst transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\nfunction isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\nfunction expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n}\nfunction isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n}\nfunction closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n}\nfunction wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n}\nfunction throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\nfunction releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\nconst proxyCounter = new WeakMap();\nconst proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\nfunction registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\nfunction unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\nfunction createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n}\nfunction myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n}\nfunction processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\nconst transferCache = new WeakMap();\nfunction transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n}\nfunction proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n}\nfunction windowEndpoint(w, context = globalThis, targetOrigin = \"*\") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\nfunction toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\nfunction fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n}\nfunction requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n}\nfunction generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n\nexport { createEndpoint, expose, finalizer, proxy, proxyMarker, releaseProxy, transfer, transferHandlers, windowEndpoint, wrap };\n//# sourceMappingURL=comlink.mjs.map\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { jacobiSolver } from \"./jacobiSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n/**\n * Function to solve a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (\"lusolve\" or \"jacobi\")\n * @param {Array} jacobianMatrix - The coefficient matrix\n * @param {Array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {\n\n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n let solutionVector = [];\n let converged = true;\n let iterations = 0;\n\n // Solve the linear system based on the specified solver method\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n if (solverMethod === \"lusolve\") {\n // Use LU decomposition method\n const jacobianMatrixSparse = math.sparse(jacobianMatrix);\n const luFactorization = math.slu(jacobianMatrixSparse, 1, 1); // order=1, threshold=1 for pivoting\n let solutionMatrix = math.lusolve(luFactorization, residualVector);\n solutionVector = math.squeeze(solutionMatrix).valueOf();\n //solutionVector = math.lusolve(jacobianMatrix, residualVector); // In the case of a dense matrix\n } else if (solverMethod === \"jacobi\") {\n // Use Jacobi method\n const initialGuess = new Array(residualVector.length).fill(0);\n const jacobiSolverResult = jacobiSolver(jacobianMatrix, residualVector, initialGuess, {\n maxIterations,\n tolerance,\n });\n\n // Log convergence information\n if (jacobiSolverResult.converged) {\n debugLog(`Jacobi method converged in ${jacobiSolverResult.iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${jacobiSolverResult.iterations} iterations`);\n }\n\n solutionVector = jacobiSolverResult.solutionVector;\n converged = jacobiSolverResult.converged;\n iterations = jacobiSolverResult.iterations;\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n return { solutionVector, converged, iterations };\n}\n\n// Helper to lazily create a default WebGPU compute engine (Comlink + worker)\nasync function createDefaultComputeEngine() {\n const worker = new Worker(new URL(\"../workers/webgpuWorkerScript.js\", import.meta.url), {\n type: \"module\",\n });\n const computeEngine = Comlink.wrap(worker);\n await computeEngine.initialize();\n return { computeEngine, worker };\n}\n\n/**\n * Function to solve asynchronously a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (e.g., \"jacobi-gpu\")\n * @param {array} jacobianMatrix - The coefficient matrix\n * @param {array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport async function solveLinearSystemAsync(solverMethod, jacobianMatrix, residualVector, options = {}) {\n \n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n // Normalize inputs\n const A = Array.isArray(jacobianMatrix) ? jacobianMatrix : jacobianMatrix?.toArray?.() ?? jacobianMatrix;\n const b = Array.isArray(residualVector) ? residualVector : residualVector?.toArray?.() ?? residualVector;\n\n let created = null;\n let computeEngine = null;\n\n let solutionVector = [];\n let converged = true;\n let iterations;\n\n if (solverMethod === \"jacobi-gpu\") {\n // Spin up a worker-backed compute engine\n created = await createDefaultComputeEngine();\n computeEngine = created.computeEngine;\n\n const x0 = new Array(b.length).fill(0);\n let result;\n\n result = await computeEngine.webgpuJacobiSolver(A, b, x0, { maxIterations, tolerance });\n solutionVector = result.solutionVector;\n converged = result.converged;\n iterations = result.iterations;\n\n // Log convergence information\n if (converged) {\n debugLog(`Jacobi method converged in ${iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${iterations} iterations`);\n }\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(`System solved successfully (${solverMethod})`);\n\n if (created) {\n await computeEngine?.destroy?.().catch(() => { });\n created.worker.terminate();\n }\n\n return { solutionVector, converged, iterations };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to solve a system of linear equations using the Jacobi iterative method (CPU synchronous version)\n * @param {array} A - The system matrix\n * @param {array} b - The right-hand side vector\n * @param {array} x0 - Initial guess for solution vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\nexport function jacobiSolver(A, b, x0, options = {}) {\n // Extract options\n const { maxIterations, tolerance } = options;\n\n const n = A.length;\n let x = [...x0];\n let xNew = new Array(n);\n\n // Jacobi update: xNew[i] = (b[i] - sum(A[i][j] * x[j] for j != i)) / A[i][i]\n for (let iter = 0; iter < maxIterations; iter++) {\n for (let i = 0; i < n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (i !== j) {\n sum += A[i][j] * x[j];\n }\n }\n xNew[i] = (b[i] - sum) / A[i][i];\n }\n\n // Check convergence based on maximum difference in solution vector\n let maxDiff = 0;\n for (let i = 0; i < n; i++) {\n maxDiff = Math.max(maxDiff, Math.abs(xNew[i] - x[i]));\n }\n\n // Copy new solution for the next iteration\n x = [...xNew];\n\n if (maxDiff < tolerance) {\n return { solutionVector: x, iterations: iter + 1, converged: true };\n }\n }\n\n return { solutionVector: x, iterations: maxIterations, converged: false };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle basis functions and their derivatives based on element configuration\n */\nexport class BasisFunctions {\n /**\n * Constructor to initialize the BasisFunctions class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to calculate basis functions and their derivatives based on the dimension and order\n * @param {number} ksi - Natural coordinate (for both 1D and 2D)\n * @param {number} [eta] - Second natural coordinate (only for 2D elements)\n * @returns {object} An object containing:\n * - basisFunction: Array of evaluated basis functions\n * - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi\n * - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)\n */\n getBasisFunctions(ksi, eta = null) {\n let basisFunction = [];\n let basisFunctionDerivKsi = [];\n let basisFunctionDerivEta = [];\n\n if (this.meshDimension === \"1D\") {\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 1D elements\n basisFunction[0] = 1 - ksi;\n basisFunction[1] = ksi;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -1;\n basisFunctionDerivKsi[1] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 1D elements\n basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;\n basisFunction[1] = 4 * ksi - 4 * ksi ** 2;\n basisFunction[2] = -ksi + 2 * ksi ** 2;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -3 + 4 * ksi;\n basisFunctionDerivKsi[1] = 4 - 8 * ksi;\n basisFunctionDerivKsi[2] = -1 + 4 * ksi;\n }\n } else if (this.meshDimension === \"2D\") {\n if (eta === null) {\n errorLog(\"Eta coordinate is required for 2D elements\");\n return;\n }\n\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 2D elements\n function l1(c) {\n return 1 - c;\n }\n function l2(c) {\n return c;\n }\n function dl1() {\n return -1;\n }\n function dl2() {\n return 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l2(ksi) * l1(eta);\n basisFunction[3] = l2(ksi) * l2(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1() * l1(eta);\n basisFunctionDerivKsi[1] = dl1() * l2(eta);\n basisFunctionDerivKsi[2] = dl2() * l1(eta);\n basisFunctionDerivKsi[3] = dl2() * l2(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1();\n basisFunctionDerivEta[1] = l1(ksi) * dl2();\n basisFunctionDerivEta[2] = l2(ksi) * dl1();\n basisFunctionDerivEta[3] = l2(ksi) * dl2();\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 2D elements\n function l1(c) {\n return 2 * c ** 2 - 3 * c + 1;\n }\n function l2(c) {\n return -4 * c ** 2 + 4 * c;\n }\n function l3(c) {\n return 2 * c ** 2 - c;\n }\n function dl1(c) {\n return 4 * c - 3;\n }\n function dl2(c) {\n return -8 * c + 4;\n }\n function dl3(c) {\n return 4 * c - 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l1(ksi) * l3(eta);\n basisFunction[3] = l2(ksi) * l1(eta);\n basisFunction[4] = l2(ksi) * l2(eta);\n basisFunction[5] = l2(ksi) * l3(eta);\n basisFunction[6] = l3(ksi) * l1(eta);\n basisFunction[7] = l3(ksi) * l2(eta);\n basisFunction[8] = l3(ksi) * l3(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);\n basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);\n basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);\n basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);\n basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);\n basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);\n basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);\n basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);\n basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);\n basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);\n basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);\n basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);\n basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);\n basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);\n basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);\n basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);\n basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);\n }\n }\n\n return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Basic structure for the mesh\n */\nexport class Mesh {\n /**\n * Constructor to initialize the Mesh class\n * @param {object} config - Configuration object for the mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)\n * @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)\n * @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n meshDimension = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n this.numElementsX = numElementsX;\n this.numElementsY = numElementsY;\n this.maxX = maxX;\n this.maxY = maxY;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n this.parsedMesh = parsedMesh;\n\n this.boundaryElementsProcessed = false;\n\n if (this.parsedMesh) {\n basicLog(\"Using pre-parsed mesh from gmshReader data for mesh generation.\");\n this.parseMeshFromGmsh();\n }\n }\n\n /**\n * Method to parse the mesh from the GMSH format to the FEAScript format\n */\n parseMeshFromGmsh() {\n if (!this.parsedMesh.nodalNumbering) {\n errorLog(\"No valid nodal numbering found in the parsed mesh.\");\n }\n\n if (\n typeof this.parsedMesh.nodalNumbering === \"object\" &&\n !Array.isArray(this.parsedMesh.nodalNumbering)\n ) {\n // Store the nodal numbering structure before converting\n const quadElements = this.parsedMesh.nodalNumbering.quadElements || [];\n const triangleElements = this.parsedMesh.nodalNumbering.triangleElements || [];\n\n debugLog(\n \"Initial parsed mesh nodal numbering from GMSH format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Check if it has quadElements or triangleElements structure from gmshReader\n if (this.parsedMesh.elementTypes[3] || this.parsedMesh.elementTypes[10]) {\n // Map nodal numbering from GMSH format to FEAScript format for quad elements\n const mappedNodalNumbering = [];\n\n for (let elemIdx = 0; elemIdx < quadElements.length; elemIdx++) {\n const gmshNodes = quadElements[elemIdx];\n const feaScriptNodes = new Array(gmshNodes.length);\n\n // Check for element type based on number of nodes\n if (gmshNodes.length === 4) {\n // Simple mapping for linear quad elements (4 nodes)\n // GMSH: FEAScript:\n // 3 --- 2 1 --- 3\n // | | --> | |\n // 0 --- 1 0 --- 2\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[3]; // 3 -> 1\n feaScriptNodes[2] = gmshNodes[1]; // 1 -> 2\n feaScriptNodes[3] = gmshNodes[2]; // 2 -> 3\n } else if (gmshNodes.length === 9) {\n // Mapping for quadratic quad elements (9 nodes)\n // GMSH: FEAScript:\n // 3--6--2 2--5--8\n // | | | |\n // 7 8 5 --> 1 4 7\n // | | | |\n // 0--4--1 0--3--6\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[7]; // 7 -> 1\n feaScriptNodes[2] = gmshNodes[3]; // 3 -> 2\n feaScriptNodes[3] = gmshNodes[4]; // 4 -> 3\n feaScriptNodes[4] = gmshNodes[8]; // 8 -> 4\n feaScriptNodes[5] = gmshNodes[6]; // 6 -> 5\n feaScriptNodes[6] = gmshNodes[1]; // 1 -> 6\n feaScriptNodes[7] = gmshNodes[5]; // 5 -> 7\n feaScriptNodes[8] = gmshNodes[2]; // 2 -> 8\n }\n\n mappedNodalNumbering.push(feaScriptNodes);\n }\n\n this.parsedMesh.nodalNumbering = mappedNodalNumbering;\n } else if (this.parsedMesh.elementTypes[2]) {\n errorLog(\"Element type is neither triangle nor quad; mapping for this type is not implemented yet.\");\n }\n\n debugLog(\n \"Nodal numbering after mapping from GMSH to FEAScript format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Process boundary elements if they exist and if physical property mapping exists\n if (this.parsedMesh.physicalPropMap && this.parsedMesh.boundaryElements) {\n // Check if boundary elements need to be processed\n if (\n Array.isArray(this.parsedMesh.boundaryElements) &&\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n // Create a new array without the empty first element\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n\n // If boundary node pairs exist but boundary elements haven't been processed\n if (this.parsedMesh.boundaryNodePairs && !this.parsedMesh.boundaryElementsProcessed) {\n // Reset boundary elements array\n this.parsedMesh.boundaryElements = [];\n\n // Process each physical property from the Gmsh file\n this.parsedMesh.physicalPropMap.forEach((prop) => {\n // Only process 1D physical entities (boundary lines)\n if (prop.dimension === 1) {\n // Get all node pairs for this boundary\n const boundaryNodePairs = this.parsedMesh.boundaryNodePairs[prop.tag] || [];\n\n if (boundaryNodePairs.length > 0) {\n // Initialize array for this boundary tag\n if (!this.parsedMesh.boundaryElements[prop.tag]) {\n this.parsedMesh.boundaryElements[prop.tag] = [];\n }\n\n // For each boundary line segment (defined by a pair of nodes)\n boundaryNodePairs.forEach((nodesPair) => {\n const node1 = nodesPair[0]; // First node in the pair\n const node2 = nodesPair[1]; // Second node in the pair\n\n debugLog(\n `Processing boundary node pair: [${node1}, ${node2}] for boundary ${prop.tag} (${\n prop.name || \"unnamed\"\n })`\n );\n\n // Search through all elements to find which one contains both nodes\n let foundElement = false;\n\n // Loop through all elements in the mesh\n for (let elemIdx = 0; elemIdx < this.parsedMesh.nodalNumbering.length; elemIdx++) {\n const elemNodes = this.parsedMesh.nodalNumbering[elemIdx];\n\n // For linear quadrilateral linear elements (4 nodes)\n if (elemNodes.length === 4) {\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript linear quadrilateral numbering:\n // 1 --- 3\n // | |\n // 0 --- 2\n\n if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0)\n ) {\n side = 0; // Bottom side\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0)\n ) {\n side = 1; // Left side\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 1 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 1)\n ) {\n side = 2; // Top side\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 2)\n ) {\n side = 3; // Right side\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n } else if (elemNodes.length === 9) {\n // For quadratic quadrilateral elements (9 nodes)\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript quadratic quadrilateral numbering:\n // 2--5--8\n // | |\n // 1 4 7\n // | |\n // 0--3--6\n\n // TODO: Transform into dictionaries for better readability\n if (\n (node1Index === 0 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 0) ||\n (node1Index === 3 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 3)\n ) {\n side = 0; // Bottom side (nodes 0, 3, 6)\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0) ||\n (node1Index === 1 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 1)\n ) {\n side = 1; // Left side (nodes 0, 1, 2)\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 5) ||\n (node1Index === 5 && node2Index === 2) ||\n (node1Index === 5 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 5)\n ) {\n side = 2; // Top side (nodes 2, 5, 8)\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 6 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 7) ||\n (node1Index === 7 && node2Index === 6) ||\n (node1Index === 7 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 7)\n ) {\n side = 3; // Right side (nodes 6, 7, 8)\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n }\n }\n\n if (!foundElement) {\n errorLog(\n `Could not find element containing boundary nodes ${node1} and ${node2}. Boundary may be incomplete.`\n );\n }\n });\n }\n }\n });\n\n // Mark as processed\n this.boundaryElementsProcessed = true;\n\n // Fix boundary elements array - remove undefined entries\n if (\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n }\n }\n }\n\n return this.parsedMesh;\n }\n}\n\nexport class Mesh1D extends Mesh {\n /**\n * Constructor to initialize the 1D mesh\n * @param {object} config - Configuration object for the 1D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({ numElementsX = null, maxX = null, elementOrder = \"linear\", parsedMesh = null }) {\n super({\n numElementsX,\n maxX,\n numElementsY: 1,\n maxY: 0,\n meshDimension: \"1D\",\n elementOrder,\n parsedMesh,\n });\n\n if (this.numElementsX === null || this.maxX === null) {\n errorLog(\"numElementsX and maxX are required parameters when generating a 1D mesh from geometry\");\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n const xStart = 0;\n let totalNodesX, deltaX;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX;\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX / 2;\n }\n }\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate1DNodalNumbering(this.numElementsX, totalNodesX, this.elementOrder);\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n\n // Return x coordinates of nodes, total nodes, NOP array, and boundary elements\n return {\n nodesXCoordinates,\n totalNodesX,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate1DNodalNumbering(numElementsX, totalNodesX, elementOrder) {\n // TODO: The totalNodesX is not used in the original function. Verify if\n // there is a multiple calculation on the totalNodes.\n\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear 1D elements with the following nodes representation:\n *\n * 1 --- 2\n *\n */\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic 1D elements with the following nodes representation:\n *\n * 1--2--3\n *\n */\n let columnCounter = 0;\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex + columnCounter;\n }\n columnCounter += 1;\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 1D domains (line segments):\n * 0 - Left node of reference element (maps to physical left endpoint)\n * 1 - Right node of reference element (maps to physical right endpoint)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 2; // For 1D, we only have two sides (left and right)\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // Left boundary (element 0, side 0)\n boundaryElements[0].push([0, 0]);\n\n // Right boundary (last element, side 1)\n boundaryElements[1].push([this.numElementsX - 1, 1]);\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n\nexport class Mesh2D extends Mesh {\n /**\n * Constructor to initialize the 2D mesh\n * @param {object} config - Configuration object for the 2D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY] - Number of elements along the y-axis (required for geometry-based mesh)\n * @param {number} [config.maxY] - Maximum y-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n super({\n numElementsX,\n maxX,\n numElementsY,\n maxY,\n meshDimension: \"2D\",\n elementOrder,\n parsedMesh,\n });\n\n // Validate geometry parameters (when not using a parsed mesh)\n if (\n !parsedMesh &&\n (this.numElementsX === null || this.maxX === null || this.numElementsY === null || this.maxY === null)\n ) {\n errorLog(\n \"numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry\"\n );\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n let nodesYCoordinates = [];\n const xStart = 0;\n const yStart = 0;\n let totalNodesX, totalNodesY, deltaX, deltaY;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n totalNodesY = this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + nodeIndexY * deltaY;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + nodeIndexX * deltaX;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + nodeIndexY * deltaY;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n totalNodesY = 2 * this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;\n }\n }\n }\n\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate2DNodalNumbering(\n this.numElementsX,\n this.numElementsY,\n totalNodesY,\n this.elementOrder\n );\n\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n debugLog(\"Generated node Y coordinates: \" + JSON.stringify(nodesYCoordinates));\n\n // Return statement\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate2DNodalNumbering(numElementsX, numElementsY, totalNodesY, elementOrder) {\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear rectangular elements with the following nodes representation:\n *\n * 1 --- 3\n * | |\n * 0 --- 2\n *\n */\n let rowCounter = 0;\n let columnCounter = 2;\n for (let elementIndex = 0; elementIndex < numElementsX * numElementsY; elementIndex++) {\n rowCounter += 1;\n nop[elementIndex] = [];\n nop[elementIndex][0] = elementIndex + columnCounter - 1;\n nop[elementIndex][1] = elementIndex + columnCounter;\n nop[elementIndex][2] = elementIndex + columnCounter + numElementsY;\n nop[elementIndex][3] = elementIndex + columnCounter + numElementsY + 1;\n if (rowCounter === numElementsY) {\n columnCounter += 1;\n rowCounter = 0;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic rectangular elements with the following nodes representation:\n *\n * 2--5--8\n * | |\n * 1 4 7\n * | |\n * 0--3--6\n *\n */\n for (let elementIndexX = 1; elementIndexX <= numElementsX; elementIndexX++) {\n for (let elementIndexY = 1; elementIndexY <= numElementsY; elementIndexY++) {\n nop[elementIndex] = [];\n for (let nodeIndex1 = 1; nodeIndex1 <= 3; nodeIndex1++) {\n let nodeIndex2 = 3 * nodeIndex1 - 2;\n nop[elementIndex][nodeIndex2 - 1] =\n totalNodesY * (2 * elementIndexX + nodeIndex1 - 3) + 2 * elementIndexY - 1;\n nop[elementIndex][nodeIndex2] = nop[elementIndex][nodeIndex2 - 1] + 1;\n nop[elementIndex][nodeIndex2 + 1] = nop[elementIndex][nodeIndex2 - 1] + 2;\n }\n elementIndex = elementIndex + 1;\n }\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 2D domains (rectangular):\n * 0 - Bottom side of reference element (maps to physical bottom boundary)\n * 1 - Left side of reference element (maps to physical left boundary)\n * 2 - Top side of reference element (maps to physical top boundary)\n * 3 - Right side of reference element (maps to physical right boundary)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 4; // For 2D, we have four sides (left, right, bottom, top)\n\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // TODO: Why to loop through all elements? Is it not better to loop over only the\n // elements that are on the boundary? eg: [0, this.numElementsX - 1] on x and\n // [0, this.numElementsY - 1] on y\n for (let elementIndexX = 0; elementIndexX < this.numElementsX; elementIndexX++) {\n for (let elementIndexY = 0; elementIndexY < this.numElementsY; elementIndexY++) {\n const elementIndex = elementIndexX * this.numElementsY + elementIndexY;\n\n // Bottom boundary\n if (elementIndexY === 0) {\n boundaryElements[0].push([elementIndex, 0]);\n }\n\n // Left boundary\n if (elementIndexX === 0) {\n boundaryElements[1].push([elementIndex, 1]);\n }\n\n // Top boundary\n if (elementIndexY === this.numElementsY - 1) {\n boundaryElements[2].push([elementIndex, 2]);\n }\n\n // Right boundary\n if (elementIndexX === this.numElementsX - 1) {\n boundaryElements[3].push([elementIndex, 3]);\n }\n }\n }\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Class to handle numerical integration using Gauss quadrature\n */\nexport class NumericalIntegration {\n /**\n * Constructor to initialize the NumericalIntegration class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to return Gauss points and weights based on element configuration\n * @returns {object} An object containing:\n * - gaussPoints: Array of Gauss points\n * - gaussWeights: Array of Gauss weights\n */\n getGaussPointsAndWeights() {\n let gaussPoints = []; // Gauss points\n let gaussWeights = []; // Gauss weights\n\n if (this.elementOrder === \"linear\") {\n // For linear elements, use 1-point Gauss quadrature\n gaussPoints[0] = 0.5;\n gaussWeights[0] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // For quadratic elements, use 3-point Gauss quadrature\n gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;\n gaussPoints[1] = 0.5;\n gaussPoints[2] = (1 + Math.sqrt(3 / 5)) / 2;\n gaussWeights[0] = 5 / 18;\n gaussWeights[1] = 8 / 18;\n gaussWeights[2] = 5 / 18;\n }\n\n return { gaussPoints, gaussWeights };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nimport { BasisFunctions } from \"./basisFunctionsScript.js\";\nimport { Mesh1D, Mesh2D } from \"./meshGenerationScript.js\";\nimport { NumericalIntegration } from \"../methods/numericalIntegrationScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to prepare the mesh for finite element analysis\n * @param {object} meshConfig - Object containing computational mesh details\n * @returns {object} An object containing all mesh-related data\n */\nexport function prepareMesh(meshConfig) {\n const { meshDimension, numElementsX, numElementsY, maxX, maxY, elementOrder, parsedMesh } = meshConfig;\n\n // Create a new instance of the Mesh class\n let mesh;\n if (meshDimension === \"1D\") {\n mesh = new Mesh1D({ numElementsX, maxX, elementOrder, parsedMesh });\n } else if (meshDimension === \"2D\") {\n mesh = new Mesh2D({ numElementsX, maxX, numElementsY, maxY, elementOrder, parsedMesh });\n } else {\n errorLog(\"Mesh dimension must be either '1D' or '2D'.\");\n }\n\n // Use the parsed mesh in case it was already passed with Gmsh format\n const nodesCoordinatesAndNumbering = mesh.boundaryElementsProcessed ? mesh.parsedMesh : mesh.generateMesh();\n\n // Extract nodes coordinates and nodal numbering (NOP) from the mesh data\n let nodesXCoordinates = nodesCoordinatesAndNumbering.nodesXCoordinates;\n let nodesYCoordinates = nodesCoordinatesAndNumbering.nodesYCoordinates;\n let totalNodesX = nodesCoordinatesAndNumbering.totalNodesX;\n let totalNodesY = nodesCoordinatesAndNumbering.totalNodesY;\n let nop = nodesCoordinatesAndNumbering.nodalNumbering;\n let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;\n\n // Check the mesh type\n const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;\n\n // Calculate totalElements and totalNodes based on mesh type\n let totalElements, totalNodes;\n\n if (isParsedMesh) {\n totalElements = nop.length; // Number of elements is the length of the nodal numbering array\n totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array\n debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);\n } else {\n // For structured mesh, calculate based on dimensions\n totalElements = numElementsX * (meshDimension === \"2D\" ? numElementsY : 1);\n totalNodes = totalNodesX * (meshDimension === \"2D\" ? totalNodesY : 1);\n debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);\n }\n\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nop,\n boundaryElements,\n totalElements,\n totalNodes,\n meshDimension,\n elementOrder,\n };\n}\n\n/**\n * Function to initialize the FEA matrices and numerical tools\n * @param {object} meshData - Object containing mesh data from prepareMesh()\n * @returns {object} An object containing initialized matrices and numerical tools\n */\nexport function initializeFEA(meshData) {\n const { totalNodes, nop, meshDimension, elementOrder } = meshData;\n\n // Initialize variables for matrix assembly\n let residualVector = [];\n let jacobianMatrix = [];\n let localToGlobalMap = [];\n\n // Initialize jacobianMatrix and residualVector arrays\n for (let nodeIndex = 0; nodeIndex < totalNodes; nodeIndex++) {\n residualVector[nodeIndex] = 0;\n jacobianMatrix.push([]);\n for (let colIndex = 0; colIndex < totalNodes; colIndex++) {\n jacobianMatrix[nodeIndex][colIndex] = 0;\n }\n }\n\n // Initialize the BasisFunctions class\n const basisFunctions = new BasisFunctions({\n meshDimension,\n elementOrder,\n });\n\n // Initialize the NumericalIntegration class\n const numericalIntegration = new NumericalIntegration({\n meshDimension,\n elementOrder,\n });\n\n // Calculate Gauss points and weights\n let gaussPointsAndWeights = numericalIntegration.getGaussPointsAndWeights();\n let gaussPoints = gaussPointsAndWeights.gaussPoints;\n let gaussWeights = gaussPointsAndWeights.gaussWeights;\n\n // Determine the number of nodes in the reference element based on the first element in the nop array\n const numNodes = nop[0].length;\n\n return {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 1D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping1D(params) {\n const { basisFunction, basisFunctionDerivKsi, nodesXCoordinates, localToGlobalMap, numNodes } = params;\n\n let xCoordinates = 0;\n let ksiDerivX = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n }\n let detJacobian = ksiDerivX;\n\n // Compute x-derivative of basis functions\n let basisFunctionDerivX = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n basisFunctionDerivX[localNodeIndex] = basisFunctionDerivKsi[localNodeIndex] / detJacobian;\n }\n\n return {\n xCoordinates,\n detJacobian,\n basisFunctionDerivX,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 2D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping2D(params) {\n const {\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n } = params;\n\n let xCoordinates = 0;\n let yCoordinates = 0;\n let ksiDerivX = 0;\n let etaDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivY = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n yCoordinates += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n ksiDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n }\n let detJacobian = ksiDerivX * etaDerivY - etaDerivX * ksiDerivY;\n\n // Compute x-derivative and y-derivative of basis functions\n let basisFunctionDerivX = [];\n let basisFunctionDerivY = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // The x-derivative of the n basis function\n basisFunctionDerivX[localNodeIndex] =\n (etaDerivY * basisFunctionDerivKsi[localNodeIndex] -\n ksiDerivY * basisFunctionDerivEta[localNodeIndex]) /\n detJacobian;\n // The y-derivative of the n basis function\n basisFunctionDerivY[localNodeIndex] =\n (ksiDerivX * basisFunctionDerivEta[localNodeIndex] -\n etaDerivX * basisFunctionDerivKsi[localNodeIndex]) /\n detJacobian;\n }\n\n return {\n xCoordinates,\n yCoordinates,\n detJacobian,\n basisFunctionDerivX,\n basisFunctionDerivY,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle thermal boundary conditions application\n */\nexport class ThermalBoundaryConditions {\n /**\n * Constructor to initialize the ThermalBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose constant temperature boundary conditions (Dirichlet type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant temperature boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantTempBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions (Robin type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n */\n imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 1;\n }\n } else if (this.elementOrder === \"quadratic\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 2;\n }\n }\n\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n residualVector[globalNodeIndex] += -convectionCoeff * extTemp;\n jacobianMatrix[globalNodeIndex][globalNodeIndex] += convectionCoeff;\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions for the frontal solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix with convection contributions\n * - localResidualVector: Residual vector with convection contributions\n */\n imposeConvectionBoundaryConditionsFront(\n elementIndex,\n nodesXCoordinates,\n nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n // Initialize local Jacobian matrix and local residual vector\n const numNodes = this.nop[elementIndex].length;\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Check if this element is on a convection boundary\n for (const boundaryKey in this.boundaryElements) {\n if (this.boundaryConditions[boundaryKey]?.[0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n\n // Find if this element is on this boundary and which side\n const boundaryElement = this.boundaryElements[boundaryKey].find(\n ([elemIdx, _]) => elemIdx === elementIndex\n );\n\n if (boundaryElement) {\n const side = boundaryElement[1];\n\n if (this.meshDimension === \"1D\") {\n // Handle 1D case\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n nodeIndex = side === 0 ? 0 : 1;\n } else if (this.elementOrder === \"quadratic\") {\n nodeIndex = side === 0 ? 0 : 2;\n }\n\n // Add contribution to local Jacobian matrix and local residual vector\n debugLog(\n ` - Applied convection boundary condition to node ${nodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n localResidualVector[nodeIndex] += -convectionCoeff * extTemp;\n localJacobianMatrix[nodeIndex][nodeIndex] += convectionCoeff;\n } else if (this.meshDimension === \"2D\") {\n // Handle 2D case\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n // Get basis functions\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n const basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n const basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n // Calculate tangent vector components\n let ksiDerivX = 0,\n ksiDerivY = 0,\n etaDerivX = 0,\n etaDerivY = 0;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n } else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute tangent vector length\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n // Handle quadratic elements (similar pattern but with more Gauss points)\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { ThermalBoundaryConditions } from \"./thermalBoundaryConditionsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the solid heat transfer model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\nexport function assembleHeatConductionMat(meshData, boundaryConditions) {\n basicLog(\"Starting solid heat transfer matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D solid heat transfer\n if (meshDimension === \"1D\") {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n // 2D solid heat transfer\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const thermalBoundaryConditions = new ThermalBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Convection boundary conditions\n thermalBoundaryConditions.imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n );\n\n // Impose ConstantTemp boundary conditions\n thermalBoundaryConditions.imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Solid heat transfer matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the solid heat transfer model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - localResidualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleHeatConductionFront({ elementIndex, nop, meshData, basisFunctions, FEAData }) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n if (meshDimension === \"1D\") {\n // 1D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n // 2D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Create mapping from local element space to global mesh (convert to 0-based indexing)\n const localToGlobalMap = ngl.map((globalIndex) => globalIndex - 1);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle generic boundary conditions application\n */\nexport class GenericBoundaryConditions {\n /**\n * Constructor to initialize the GenericBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose Dirichlet boundary conditions\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant value (Dirichlet) boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantValueBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n// Base viscous term that remains when eikonal equation is fully activated\nconst baseEikonalViscousTerm = 1e-2;\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the front propagation model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleFrontPropagationMat(\n meshData,\n boundaryConditions,\n solutionVector,\n eikonalActivationFlag\n) {\n basicLog(\"Starting front propagation matrix assembly...\");\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n debugLog(`eikonalViscousTerm: ${eikonalViscousTerm}`);\n debugLog(`eikonalActivationFlag: ${eikonalActivationFlag}`);\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // jacobianMatrix\n // TODO jacobianMatrix calculation here\n }\n }\n }\n // 2D front propagation (eikonal) equation\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n\n // residualVector: Viscous term contribution (to stabilize the solution)\n residualVector[localToGlobalMap1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // residualVector: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n residualVector[localToGlobalMap1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n\n // jacobianMatrix: Viscous term contribution\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // jacobianMatrix: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Dirichlet boundary conditions\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Front propagation matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the front propagation model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - residualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleFrontPropagationFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n solutionVector,\n eikonalActivationFlag,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // localJacobianMatrix\n // TODO localJacobianMatrix calculation here\n }\n }\n // 2D front propagation (eikonal) equation\n } else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // Viscous term contribution\n localResidualVector[localNodeIndex1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localResidualVector[localNodeIndex1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Viscous term contribution\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { BasisFunctions } from \"../mesh/basisFunctionsScript.js\";\nimport { initializeFEA } from \"../mesh/meshUtilsScript.js\";\nimport { assembleHeatConductionFront } from \"../models/heatConductionScript.js\";\nimport { ThermalBoundaryConditions } from \"../models/thermalBoundaryConditionsScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\nimport { GenericBoundaryConditions } from \"../models/genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n// Create object templates\nconst frontalData = {};\nconst frontalState = {};\nconst elementData = { currentElementIndex: 0 };\nconst frontStorage = {};\nlet basisFunctions;\n\n/**\n * Function to run the frontal solver and obtain results for plotting\n * @param {function} assembleFront - Matrix assembler based on the physical model\n * @param {object} meshData - Object containing mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} [options] - Additional options for the solver\n * @returns {object} An object containing the solution vector and node coordinates\n */\nexport function runFrontalSolver(assembleFront, meshData, boundaryConditions, options = {}) {\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const totalNodes = meshData.nodesXCoordinates.length;\n const numElements = meshData.totalElements;\n const numNodes = FEAData.numNodes;\n\n // Calculate required array sizes\n initializeFrontalArrays(numNodes, numElements);\n\n // Start timing for system solving (frontal algorithm)\n basicLog(\"Solving system using frontal...\");\n console.time(\"systemSolving\");\n\n // Initialize basis functions\n basisFunctions = new BasisFunctions({\n meshDimension: meshData.meshDimension,\n elementOrder: meshData.elementOrder,\n });\n\n // Copy node connectivity array into frontalData storage\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n for (let nodeIndex = 0; nodeIndex < FEAData.numNodes; nodeIndex++) {\n frontalData.nodalNumbering[elementIndex][nodeIndex] = meshData.nop[elementIndex][nodeIndex];\n }\n }\n\n // Apply Dirichlet-type boundary conditions\n // Initialize all nodes with no boundary condition\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.nodeConstraintCode[nodeIndex] = 0;\n frontalData.boundaryValues[nodeIndex] = 0;\n }\n\n // Handle Dirichlet-type boundary conditions differently based on which solver is being used\n let dirichletBoundaryConditionsHandler;\n // Solid heat transfer model (heatConductionScript solver)\n if (assembleFront === assembleHeatConductionFront) {\n dirichletBoundaryConditionsHandler = new ThermalBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantTempBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n // Front propagation model (frontPropagationScript solver)\n } else if (assembleFront === assembleFrontPropagationFront) {\n dirichletBoundaryConditionsHandler = new GenericBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantValueBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n }\n // Initialize global residual vector\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.globalResidualVector[nodeIndex] = 0;\n }\n\n frontalState.totalNodes = meshData.nodesXCoordinates.length;\n frontalState.writeFlag = 0;\n frontalState.transformationFlag = 1;\n frontalState.determinant = 1;\n\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n frontalState.nodesPerElement[elementIndex] = FEAData.numNodes;\n }\n\n // Parameters for non-linear assemblers\n frontalState.currentSolutionVector = options.solutionVector;\n frontalState.eikonalActivationFlag = options.eikonalActivationFlag;\n\n // Pass assembleFront and dirichletBoundaryConditionsHandler to runFrontalAlgorithm\n runFrontalAlgorithm(meshData, FEAData, dirichletBoundaryConditionsHandler, assembleFront);\n\n // Copy solution\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.solutionVector[nodeIndex] = frontalState.globalSolutionVector[nodeIndex];\n }\n\n // Output results to console for debugging\n const { nodesXCoordinates, nodesYCoordinates } = meshData;\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n if (meshData.meshDimension === \"1D\") {\n // 1D case - only output X coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${frontalData.solutionVector[\n nodeIndex\n ].toExponential(5)}`\n );\n } else {\n // 2D case - output X, Y coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${nodesYCoordinates[nodeIndex].toExponential(\n 5\n )} ${frontalData.solutionVector[nodeIndex].toExponential(5)}`\n );\n }\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n const { nodesXCoordinates: finalNodesX, nodesYCoordinates: finalNodesY } = meshData;\n return {\n solutionVector: frontalData.solutionVector.slice(0, totalNodes),\n nodesCoordinates: {\n nodesXCoordinates: finalNodesX,\n nodesYCoordinates: finalNodesY,\n },\n };\n}\n\n/**\n * Function to initialize arrays dynamically based on problem size\n * @param {number} numNodes - Number of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n */\nfunction initializeFrontalArrays(numNodes, numElements) {\n // Use the actual number of elements from the mesh\n frontalData.nodalNumbering = Array(numElements)\n .fill()\n .map(() => Array(numNodes).fill(0));\n frontalData.nodeConstraintCode = Array(numNodes).fill(0);\n frontalData.boundaryValues = Array(numNodes).fill(0);\n frontalData.globalResidualVector = Array(numNodes).fill(0);\n frontalData.solutionVector = Array(numNodes).fill(0);\n frontalData.topologyData = Array(numElements).fill(0);\n frontalData.lateralData = Array(numElements).fill(0);\n\n // Initialize frontalState arrays\n frontalState.writeFlag = 0;\n frontalState.totalNodes = numNodes;\n frontalState.transformationFlag = 0;\n frontalState.nodesPerElement = Array(numElements).fill(0);\n frontalState.determinant = 1;\n\n // For matrix operations, estimate required size based on problem complexity\n const systemSize = Math.max(numNodes, 2000);\n frontalState.globalSolutionVector = Array(systemSize).fill(0);\n frontalState.frontDataIndex = 0;\n\n // Initialize elementData arrays\n elementData.localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n elementData.currentElementIndex = 0;\n\n // Initialize frontStorage arrays\n const frontSize = estimateFrontSize(numNodes, numElements);\n frontStorage.frontValues = Array(frontSize).fill(0);\n frontStorage.columnHeaders = Array(systemSize).fill(0);\n frontStorage.pivotRow = Array(systemSize).fill(0);\n frontStorage.pivotData = Array(frontSize).fill(0);\n}\n\n/**\n * Function to estimate the required front size\n * @param {number} numNodes - Number of of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n * @returns {number} Estimated front size\n */\nfunction estimateFrontSize(numNodes, numElements) {\n const frontWidthEstimate = Math.max(Math.ceil(Math.sqrt(numElements)) * numNodes, numNodes * 2);\n return frontWidthEstimate * numElements;\n}\n// Old function to estimate the required front size\n// function estimateFrontSize(numNodes, numElements, numNodes) {\n// const frontWidthEstimate = Math.ceil(Math.sqrt(numElements) * numNodes * 2);\n// const frontSize = frontWidthEstimate * numNodes * 4;\n// return Math.max(frontSize, 10000);\n// }\n\n/**\n * Function to compute local Jacobian matrix and local residual vector\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n const elementIndex = elementData.currentElementIndex - 1;\n\n // Guard against out-of-range indices\n if (elementIndex < 0 || elementIndex >= meshData.totalElements) {\n errorLog(`Skipping out-of-range elementIndex=${elementIndex} (totalElements=${meshData.totalElements})`);\n return false;\n }\n\n // Domain terms\n const { localJacobianMatrix, localResidualVector, ngl } = assembleFront({\n elementIndex,\n nop: frontalData.nodalNumbering,\n meshData,\n basisFunctions: basisFunctions,\n FEAData,\n // These are ignored by linear assemblers\n solutionVector: frontalState.currentSolutionVector,\n eikonalActivationFlag: frontalState.eikonalActivationFlag,\n });\n\n // Handle Robin-type boundary conditions differently based on which solver is being used\n let boundaryLocalJacobianMatrix = Array(FEAData.numNodes)\n .fill()\n .map(() => Array(FEAData.numNodes).fill(0));\n let boundaryResidualVector = Array(FEAData.numNodes).fill(0);\n\n // heatConductionScript solver\n if (assembleFront === assembleHeatConductionFront) {\n // Check if this element is on a Robin-type boundary\n let isOnRobinTypeBoundary = false;\n for (const boundaryKey in meshData.boundaryElements) {\n if (\n thermalBoundaryConditions.boundaryConditions[boundaryKey]?.[0] === \"convection\" &&\n meshData.boundaryElements[boundaryKey].some(([elemIdx, _]) => elemIdx === elementIndex)\n ) {\n isOnRobinTypeBoundary = true;\n break;\n }\n }\n\n // Only calculate Robin-type for elements when required\n if (isOnRobinTypeBoundary) {\n const { gaussPoints, gaussWeights } = FEAData;\n const result = thermalBoundaryConditions.imposeConvectionBoundaryConditionsFront(\n elementIndex,\n meshData.nodesXCoordinates,\n meshData.nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n );\n boundaryLocalJacobianMatrix = result.localJacobianMatrix;\n boundaryResidualVector = result.localResidualVector;\n }\n } else if (assembleFront === assembleFrontPropagationFront) {\n // For now, no Robin-type boundary conditions exist for any other solver\n }\n\n // Combine domain and boundary contributions\n for (let localNodeI = 0; localNodeI < FEAData.numNodes; localNodeI++) {\n for (let localNodeJ = 0; localNodeJ < FEAData.numNodes; localNodeJ++) {\n elementData.localJacobianMatrix[localNodeI][localNodeJ] =\n localJacobianMatrix[localNodeI][localNodeJ] + boundaryLocalJacobianMatrix[localNodeI][localNodeJ];\n }\n }\n\n // Assemble local element residual\n for (let localNodeIndex = 0; localNodeIndex < FEAData.numNodes; localNodeIndex++) {\n const globalNodeIndex = ngl[localNodeIndex] - 1;\n frontalData.globalResidualVector[globalNodeIndex] +=\n localResidualVector[localNodeIndex] + boundaryResidualVector[localNodeIndex];\n }\n\n return true;\n}\n\n/**\n * Function to implement the frontal solver algorithm\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction runFrontalAlgorithm(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n // Allocate local arrays dynamically\n const totalElements = meshData.totalElements;\n const numNodes = meshData.nodesXCoordinates.length;\n const systemSize = Math.max(numNodes, frontalState.globalSolutionVector.length);\n let localDestination = Array(FEAData.numNodes).fill(0);\n let rowDestination = Array(FEAData.numNodes).fill(0);\n let rowHeaders = Array(systemSize).fill(0);\n let pivotRowIndices = Array(systemSize).fill(0);\n let pivotColumnIndices = Array(systemSize).fill(0);\n let modifiedRows = Array(systemSize).fill(0);\n let pivotColumn = Array(systemSize).fill(0);\n let frontMatrix = Array(systemSize)\n .fill()\n .map(() => Array(systemSize).fill(0));\n let rowSwapCount = Array(numNodes).fill(0);\n let columnSwapCount = Array(numNodes).fill(0);\n let lastAppearanceCheck = Array(numNodes).fill(0);\n let pivotColumnGlobalIndex; // Pivot column global index\n\n let frontDataCounter = 1;\n frontalState.writeFlag++;\n let pivotDataIndex = 1;\n let summedRows = 1;\n elementData.currentElementIndex = 0;\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n rowSwapCount[nodeIndex] = 0;\n columnSwapCount[nodeIndex] = 0;\n }\n\n if (frontalState.transformationFlag !== 0) {\n // Prefront: find last appearance of each node\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n lastAppearanceCheck[nodeIndex] = 0;\n }\n\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n let reverseElementIndex = totalElements - elementIndex - 1;\n for (\n let localNodeIndex = 0;\n localNodeIndex < frontalState.nodesPerElement[reverseElementIndex];\n localNodeIndex++\n ) {\n let globalNodeIndex = frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n if (lastAppearanceCheck[globalNodeIndex - 1] === 0) {\n lastAppearanceCheck[globalNodeIndex - 1] = 1;\n frontalData.nodalNumbering[reverseElementIndex][localNodeIndex] =\n -frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n }\n }\n }\n }\n\n frontalState.transformationFlag = 0;\n let columnCount = 0;\n let rowCount = 0;\n\n for (let i = 0; i < systemSize; i++) {\n for (let j = 0; j < systemSize; j++) {\n frontMatrix[j][i] = 0;\n }\n }\n\n while (true) {\n // Assemble a new element only while we still have elements\n let assembled = false;\n let numElementNodes = 0;\n let numElementColumns = 0;\n\n if (elementData.currentElementIndex < totalElements) {\n elementData.currentElementIndex++;\n assembled = assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront);\n }\n\n if (assembled) {\n const currentElement = elementData.currentElementIndex;\n numElementNodes = frontalState.nodesPerElement[currentElement - 1];\n numElementColumns = frontalState.nodesPerElement[currentElement - 1];\n\n for (let localNodeIndex = 0; localNodeIndex < numElementColumns; localNodeIndex++) {\n let globalNodeIndex = frontalData.nodalNumbering[currentElement - 1][localNodeIndex];\n let columnIndex;\n\n if (columnCount === 0) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(frontStorage.columnHeaders[columnIndex])) break;\n }\n\n if (columnIndex === columnCount) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n localDestination[localNodeIndex] = columnIndex + 1;\n frontStorage.columnHeaders[columnIndex] = globalNodeIndex;\n }\n }\n\n let rowIndex;\n if (rowCount === 0) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(rowHeaders[rowIndex])) break;\n }\n\n if (rowIndex === rowCount) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n rowDestination[localNodeIndex] = rowIndex + 1;\n rowHeaders[rowIndex] = globalNodeIndex;\n }\n }\n }\n\n if (rowCount > systemSize || columnCount > systemSize) {\n errorLog(\"Error: systemSize not large enough\");\n return;\n }\n\n for (let localColumnIndex = 0; localColumnIndex < numElementColumns; localColumnIndex++) {\n let frontColumnIndex = localDestination[localColumnIndex];\n for (let localRowIndex = 0; localRowIndex < numElementNodes; localRowIndex++) {\n let frontRowIndex = rowDestination[localRowIndex];\n frontMatrix[frontRowIndex - 1][frontColumnIndex - 1] +=\n elementData.localJacobianMatrix[localRowIndex][localColumnIndex];\n }\n }\n }\n\n // Pivoting/elimination continues whether or not a new element was assembled\n let availableColumnCount = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (frontStorage.columnHeaders[columnIndex] < 0) {\n pivotColumnIndices[availableColumnCount] = columnIndex + 1;\n availableColumnCount++;\n }\n }\n\n let constrainedRowCount = 0;\n let availableRowCount = 0;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n let globalNodeIndex = rowHeaders[rowIndex];\n if (globalNodeIndex < 0) {\n pivotRowIndices[availableRowCount] = rowIndex + 1;\n availableRowCount++;\n let absoluteNodeIndex = Math.abs(globalNodeIndex);\n if (frontalData.nodeConstraintCode[absoluteNodeIndex - 1] === 1) {\n modifiedRows[constrainedRowCount] = rowIndex + 1;\n constrainedRowCount++;\n frontalData.nodeConstraintCode[absoluteNodeIndex - 1] = 2;\n frontalData.globalResidualVector[absoluteNodeIndex - 1] =\n frontalData.boundaryValues[absoluteNodeIndex - 1];\n }\n }\n }\n\n if (constrainedRowCount > 0) {\n for (let constrainedIndex = 0; constrainedIndex < constrainedRowCount; constrainedIndex++) {\n let rowIndex = modifiedRows[constrainedIndex] - 1;\n let globalNodeIndex = Math.abs(rowHeaders[rowIndex]);\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] = 0;\n let columnGlobalIndex = Math.abs(frontStorage.columnHeaders[columnIndex]);\n if (columnGlobalIndex === globalNodeIndex) frontMatrix[rowIndex][columnIndex] = 1;\n }\n }\n }\n\n if (availableColumnCount > summedRows || elementData.currentElementIndex < totalElements) {\n if (availableColumnCount === 0) {\n errorLog(\"Error: no more rows fully summed\");\n return;\n }\n\n let pivotRowIndex = pivotRowIndices[0];\n let pivotColumnIndex = pivotColumnIndices[0];\n let pivotValue = frontMatrix[pivotRowIndex - 1][pivotColumnIndex - 1];\n\n if (Math.abs(pivotValue) < 1e-4) {\n pivotValue = 0;\n for (let columnIndex = 0; columnIndex < availableColumnCount; columnIndex++) {\n let testColumnIndex = pivotColumnIndices[columnIndex];\n for (let rowIndex = 0; rowIndex < availableRowCount; rowIndex++) {\n let testRowIndex = pivotRowIndices[rowIndex];\n let testValue = frontMatrix[testRowIndex - 1][testColumnIndex - 1];\n if (Math.abs(testValue) > Math.abs(pivotValue)) {\n pivotValue = testValue;\n pivotColumnIndex = testColumnIndex;\n pivotRowIndex = testRowIndex;\n }\n }\n }\n }\n\n let pivotGlobalRowIndex = Math.abs(rowHeaders[pivotRowIndex - 1]);\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]); // Assign, don't declare\n let permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n if (nodeIndex >= pivotGlobalRowIndex) rowSwapCount[nodeIndex]--;\n if (nodeIndex >= pivotColumnGlobalIndex) columnSwapCount[nodeIndex]--;\n }\n\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontMatrix[pivotRowIndex - 1][columnIndex] / pivotValue;\n }\n\n let rightHandSide = frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] = rightHandSide;\n pivotColumn[pivotRowIndex - 1] = pivotValue;\n\n if (pivotRowIndex > 1) {\n for (let rowIndex = 0; rowIndex < pivotRowIndex - 1; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1 && eliminationFactor !== 0) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] -= eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n if (pivotRowIndex < rowCount) {\n for (let rowIndex = pivotRowIndex; rowIndex < rowCount; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = pivotColumn[i];\n }\n pivotDataIndex += rowCount;\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = rowHeaders[i];\n }\n pivotDataIndex += rowCount;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.pivotRow[i];\n }\n frontDataCounter += columnCount;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.columnHeaders[i];\n }\n frontDataCounter += columnCount;\n\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n frontMatrix[rowIndex][columnCount - 1] = 0;\n }\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowCount - 1][columnIndex] = 0;\n }\n\n columnCount--;\n if (pivotColumnIndex < columnCount + 1) {\n for (let columnIndex = pivotColumnIndex - 1; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] = frontStorage.columnHeaders[columnIndex + 1];\n }\n }\n\n rowCount--;\n if (pivotRowIndex < rowCount + 1) {\n for (let rowIndex = pivotRowIndex - 1; rowIndex < rowCount; rowIndex++) {\n rowHeaders[rowIndex] = rowHeaders[rowIndex + 1];\n }\n }\n\n if (rowCount > 1 || elementData.currentElementIndex < totalElements) continue;\n\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[0]); // Assign, don't declare\n pivotRowIndex = 1;\n pivotValue = frontMatrix[0][0];\n pivotGlobalRowIndex = Math.abs(rowHeaders[0]);\n pivotColumnIndex = 1;\n permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n frontStorage.pivotRow[0] = 1;\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] =\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.pivotRow[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.columnHeaders[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotColumn[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = rowHeaders[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n frontalState.frontDataIndex = frontDataCounter;\n if (frontalState.writeFlag === 1)\n debugLog(`total ecs transfer in matrix reduction=${frontDataCounter}`);\n\n // Back substitution\n performBackSubstitution(frontDataCounter);\n break;\n }\n }\n}\n\n/**\n * Function to perform back substitution for the frontal solver\n * @param {number} frontDataCounter - Index counter for the element contributions\n */\nfunction performBackSubstitution(frontDataCounter) {\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n frontalState.globalSolutionVector[nodeIndex] = frontalData.boundaryValues[nodeIndex];\n }\n\n for (let iterationIndex = 1; iterationIndex <= frontalState.totalNodes; iterationIndex++) {\n frontDataCounter -= 4;\n let pivotGlobalRowIndex = frontStorage.frontValues[frontDataCounter - 1];\n let columnCount = frontStorage.frontValues[frontDataCounter];\n let pivotColumnIndex = frontStorage.frontValues[frontDataCounter + 1];\n let pivotValue = frontStorage.frontValues[frontDataCounter + 2];\n\n if (iterationIndex === 1) {\n frontDataCounter--;\n frontStorage.columnHeaders[0] = frontStorage.frontValues[frontDataCounter - 1];\n frontDataCounter--;\n frontStorage.pivotRow[0] = frontStorage.frontValues[frontDataCounter - 1];\n } else {\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] =\n frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n }\n\n let pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]);\n if (frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] > 0) continue;\n\n let accumulatedValue = 0;\n frontStorage.pivotRow[pivotColumnIndex - 1] = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n accumulatedValue -=\n frontStorage.pivotRow[columnIndex] *\n frontalState.globalSolutionVector[Math.abs(frontStorage.columnHeaders[columnIndex]) - 1];\n }\n\n frontalState.globalSolutionVector[pivotColumnGlobalIndex - 1] =\n accumulatedValue + frontalData.globalResidualVector[pivotGlobalRowIndex - 1];\n\n frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] = 1;\n }\n\n if (frontalState.writeFlag === 1)\n debugLog(`value of frontDataCounter after backsubstitution=${frontDataCounter}`);\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { euclideanNorm } from \"../methods/euclideanNormScript.js\";\nimport { solveLinearSystem } from \"./linearSystemSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport { runFrontalSolver } from \"./frontalSolverScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\n\n/**\n * Function to solve a system of non-linear equations using the Newton-Raphson method\n * @param {function} assembleMat - Matrix assembler based on the physical model\n * @param {object} context - Context object containing simulation data and options\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\n\nexport function newtonRaphson(assembleMat, context = {}) {\n let errorNorm = 0;\n let converged = false;\n let iterations = 0;\n let deltaX = [];\n let solutionVector = [];\n let jacobianMatrix = [];\n let residualVector = [];\n\n // Extract context\n const { maxIterations = 100, tolerance = 1e-4 } = context;\n\n // Calculate system size\n let totalNodes = context.meshData.nodesXCoordinates.length;\n\n // Initialize arrays with proper size\n for (let i = 0; i < totalNodes; i++) {\n deltaX[i] = 0;\n solutionVector[i] = 0;\n }\n\n // Initialize solution from context if available\n if (context.initialSolution && context.initialSolution.length === totalNodes) {\n solutionVector = [...context.initialSolution];\n }\n\n while (iterations < maxIterations && !converged) {\n // Update solution\n for (let i = 0; i < solutionVector.length; i++) {\n solutionVector[i] = Number(solutionVector[i]) + Number(deltaX[i]);\n }\n\n // Check if using frontal solver\n if (context.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleFrontPropagationFront,\n context.meshData,\n context.boundaryConditions,\n { solutionVector, eikonalActivationFlag: context.eikonalActivationFlag }\n );\n deltaX = frontalResult.solutionVector;\n } else {\n // Compute Jacobian and residual matrices\n ({ jacobianMatrix, residualVector } = assembleMat(\n context.meshData,\n context.boundaryConditions,\n solutionVector, // The solution vector is required in the case of a non-linear equation\n context.eikonalActivationFlag // Currently used only in the front propagation solver (TODO refactor in case of a solver not needing it)\n ));\n\n // Solve the linear system based on the specified solver method\n const linearSystemResult = solveLinearSystem(context.solverMethod, jacobianMatrix, residualVector);\n deltaX = linearSystemResult.solutionVector;\n }\n\n // Check convergence\n errorNorm = euclideanNorm(deltaX);\n\n // Norm for each iteration\n basicLog(`Newton-Raphson iteration ${iterations + 1}: Error norm = ${errorNorm.toExponential(4)}`);\n\n if (errorNorm <= tolerance) {\n converged = true;\n } else if (errorNorm > 1e2) {\n errorLog(`Solution not converged. Error norm: ${errorNorm}`);\n break;\n }\n\n iterations++;\n }\n\n return {\n solutionVector,\n converged,\n iterations,\n jacobianMatrix,\n residualVector,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { newtonRaphson } from \"./methods/newtonRaphsonScript.js\";\nimport { solveLinearSystem } from \"./methods/linearSystemSolverScript.js\";\nimport { solveLinearSystemAsync } from \"./methods/linearSystemSolverScript.js\";\nimport { prepareMesh } from \"./mesh/meshUtilsScript.js\";\nimport { assembleFrontPropagationMat } from \"./models/frontPropagationScript.js\";\nimport { assembleGeneralFormPDEMat, assembleGeneralFormPDEFront } from \"./models/generalFormPDEScript.js\";\nimport { assembleHeatConductionMat, assembleHeatConductionFront } from \"./models/heatConductionScript.js\";\nimport { runFrontalSolver } from \"./methods/frontalSolverScript.js\";\nimport { basicLog, debugLog, warnLog, errorLog } from \"./utilities/loggingScript.js\";\n\n/**\n * Class to implement finite element analysis in JavaScript\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} meshConfig - Object containing computational mesh details\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containifng the solution vector and additional mesh information\n */\nexport class FEAScriptModel {\n constructor() {\n this.solverConfig = null;\n this.meshConfig = {};\n this.boundaryConditions = {};\n this.solverMethod = \"lusolve\"; // Default solver method\n this.coefficientFunctions = null; // Add storage for coefficient functions\n warnLog(\n \"FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE\"\n );\n basicLog(\"FEAScriptModel instance created\");\n }\n\n /**\n * Sets the solver configuration\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} [options] - Optional additional configuration\n */\n setSolverConfig(solverConfig, options = {}) {\n this.solverConfig = solverConfig;\n\n // Store coefficient functions if provided\n if (options?.coefficientFunctions) {\n this.coefficientFunctions = options.coefficientFunctions;\n debugLog(\"Coefficient functions set\");\n }\n // Only update if a value is provided, otherwise keep the default\n if (options?.maxIterations !== undefined) {\n this.maxIterations = options.maxIterations;\n }\n if (options?.tolerance !== undefined) {\n this.tolerance = options.tolerance;\n }\n\n debugLog(`Solver config set to: ${solverConfig}`);\n }\n\n setMeshConfig(meshConfig) {\n this.meshConfig = meshConfig;\n debugLog(`Mesh config set with dimensions: ${meshConfig.meshDimension}`);\n }\n\n addBoundaryCondition(boundaryKey, condition) {\n this.boundaryConditions[boundaryKey] = condition;\n debugLog(`Boundary condition added for boundary: ${boundaryKey}, type: ${condition[0]}`);\n }\n\n setSolverMethod(solverMethod) {\n this.solverMethod = solverMethod;\n debugLog(`Solver method set to: ${solverMethod}`);\n }\n\n /**\n * Function to solve the finite element problem synchronously\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing the solution vector and the coordinates of the mesh nodes\n */\n solve(options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n /**\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n let initialSolution = [];\n\n // Prepare the mesh\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n\n // Extract node coordinates from meshData\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n // Select and execute the appropriate solver based on solverConfig\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleHeatConductionFront,\n meshData,\n this.boundaryConditions\n );\n solutionVector = frontalResult.solutionVector;\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n } else if (this.solverConfig === \"frontPropagationScript\") {\n // Initialize eikonalActivationFlag\n let eikonalActivationFlag = 0;\n const eikonalExteralIterations = 5; // Number of incremental steps for the eikonal equation\n\n // Create context object with all necessary properties\n const context = {\n meshData: meshData,\n boundaryConditions: this.boundaryConditions,\n eikonalActivationFlag: eikonalActivationFlag,\n solverMethod: this.solverMethod,\n initialSolution,\n // TODO: Consider using different maxIterations/tolerance for Newton-Raphson and linear solver\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n };\n\n while (eikonalActivationFlag <= 1) {\n // Update the context object with current eikonalActivationFlag\n context.eikonalActivationFlag = eikonalActivationFlag;\n\n // Pass the previous solution as initial guess\n if (solutionVector.length > 0) {\n context.initialSolution = [...solutionVector];\n }\n\n // Solve the assembled non-linear system\n const newtonRaphsonResult = newtonRaphson(assembleFrontPropagationMat, context);\n\n // Extract results\n jacobianMatrix = newtonRaphsonResult.jacobianMatrix;\n residualVector = newtonRaphsonResult.residualVector;\n solutionVector = newtonRaphsonResult.solutionVector;\n\n // Increment for next iteration\n eikonalActivationFlag += 1 / eikonalExteralIterations;\n }\n } else if (this.solverConfig === \"generalFormPDEScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n errorLog(\n \"Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.\"\n );\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(\n meshData,\n this.boundaryConditions,\n this.coefficientFunctions\n ));\n\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n /**\n * Function to solve the finite element problem asynchronously\n * @param {object} computeEngine - The compute engine to use for the asynchronous solver (e.g., a worker or a WebGPU context)\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing the solution vector and the coordinates of the mesh nodes\n */\n async solveAsync(computeEngine, options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n\n if (this.solverMethod === \"jacobi-gpu\") {\n const { solutionVector: x } = await solveLinearSystemAsync(\"jacobi-gpu\", jacobianMatrix, residualVector, {\n computeEngine,\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = x;\n } else {\n // Other async solver\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { initializeFEA, performIsoparametricMapping1D } from \"../mesh/meshUtilsScript.js\";\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the general form PDE model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} coefficientFunctions - Functions A(x), B(x), C(x), D(x) for the PDE\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleGeneralFormPDEMat(meshData, boundaryConditions, coefficientFunctions) {\n basicLog(\"Starting general form PDE matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Extract coefficient functions\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Convert to 0-based indexing\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];\n\n // Source term contribution to residual vector\n residualVector[globalNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n const globalNodeIndex2 = localToGlobalMap[localNodeIndex2];\n\n // Diffusion term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEMat.\");\n // 2D general form PDE - empty for now\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Apply Dirichlet boundary conditions only\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n\n basicLog(\"General form PDE matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the frontal solver matrix for the general form PDE model\n * @param {object} data - Object containing element data for the frontal solver\n * @returns {object} An object containing local Jacobian matrix and residual vector\n */\nexport function assembleGeneralFormPDEFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n coefficientFunctions,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of local Jacobian matrix and residual vector\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n // Source term contribution to local residual vector\n localResidualVector[localNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Diffusion term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEFront.\");\n // 2D general form PDE - empty for now\n }\n\n return {\n localJacobianMatrix,\n localResidualVector,\n ngl,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements\n * @param {File} file - The Gmsh file to be parsed (.msh version 4.1)\n * @returns {object} The parsed mesh data including node coordinates, element connectivity, and boundary conditions\n */\nconst importGmshQuadTri = async (file) => {\n let result = {\n nodesXCoordinates: [],\n nodesYCoordinates: [],\n nodalNumbering: {\n quadElements: [],\n triangleElements: [],\n },\n boundaryElements: [],\n boundaryConditions: [],\n boundaryNodePairs: {}, // Store boundary node pairs for processing in meshGenerationScript\n gmshV: 0,\n ascii: false,\n fltBytes: \"8\",\n totalNodesX: 0,\n totalNodesY: 0,\n physicalPropMap: [],\n elementTypes: {},\n };\n\n let content = await file.text();\n let lines = content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line !== \"\" && line !== \" \");\n\n let section = \"\";\n let lineIndex = 0;\n\n let nodeEntityBlocks = 0;\n let totalNodes = 0;\n let nodeBlocksProcessed = 0;\n let currentNodeBlock = { numNodes: 0 };\n let nodeTagsCollected = 0;\n let nodeTags = [];\n let nodeCoordinatesCollected = 0;\n\n let elementEntityBlocks = 0;\n let totalElements = 0;\n let elementBlocksProcessed = 0;\n let currentElementBlock = {\n dim: 0,\n tag: 0,\n elementType: 0,\n numElements: 0,\n };\n let elementsProcessedInBlock = 0;\n\n let boundaryElementsByTag = {};\n\n while (lineIndex < lines.length) {\n const line = lines[lineIndex];\n\n if (line === \"$MeshFormat\") {\n section = \"meshFormat\";\n lineIndex++;\n continue;\n } else if (line === \"$EndMeshFormat\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$PhysicalNames\") {\n section = \"physicalNames\";\n lineIndex++;\n continue;\n } else if (line === \"$EndPhysicalNames\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Entities\") {\n section = \"entities\";\n lineIndex++;\n continue;\n } else if (line === \"$EndEntities\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Nodes\") {\n section = \"nodes\";\n lineIndex++;\n continue;\n } else if (line === \"$EndNodes\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Elements\") {\n section = \"elements\";\n lineIndex++;\n continue;\n } else if (line === \"$EndElements\") {\n section = \"\";\n lineIndex++;\n continue;\n }\n\n const parts = line.split(/\\s+/).filter((part) => part !== \"\");\n\n if (section === \"meshFormat\") {\n result.gmshV = parseFloat(parts[0]);\n result.ascii = parts[1] === \"0\";\n result.fltBytes = parts[2];\n } else if (section === \"physicalNames\") {\n if (parts.length >= 3) {\n if (!/^\\d+$/.test(parts[0])) {\n lineIndex++;\n continue;\n }\n\n const dimension = parseInt(parts[0], 10);\n const tag = parseInt(parts[1], 10);\n let name = parts.slice(2).join(\" \");\n name = name.replace(/^\"|\"$/g, \"\");\n\n result.physicalPropMap.push({\n tag,\n dimension,\n name,\n });\n }\n } else if (section === \"nodes\") {\n if (nodeEntityBlocks === 0) {\n nodeEntityBlocks = parseInt(parts[0], 10);\n totalNodes = parseInt(parts[1], 10);\n result.nodesXCoordinates = new Array(totalNodes).fill(0);\n result.nodesYCoordinates = new Array(totalNodes).fill(0);\n lineIndex++;\n continue;\n }\n\n if (nodeBlocksProcessed < nodeEntityBlocks && currentNodeBlock.numNodes === 0) {\n currentNodeBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n parametric: parseInt(parts[2], 10),\n numNodes: parseInt(parts[3], 10),\n };\n\n nodeTags = [];\n nodeTagsCollected = 0;\n nodeCoordinatesCollected = 0;\n\n lineIndex++;\n continue;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n for (let i = 0; i < parts.length && nodeTagsCollected < currentNodeBlock.numNodes; i++) {\n nodeTags.push(parseInt(parts[i], 10));\n nodeTagsCollected++;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n lineIndex++;\n continue;\n }\n\n lineIndex++;\n continue;\n }\n\n if (nodeCoordinatesCollected < currentNodeBlock.numNodes) {\n const nodeTag = nodeTags[nodeCoordinatesCollected] - 1;\n const x = parseFloat(parts[0]);\n const y = parseFloat(parts[1]);\n\n result.nodesXCoordinates[nodeTag] = x;\n result.nodesYCoordinates[nodeTag] = y;\n result.totalNodesX++;\n result.totalNodesY++;\n\n nodeCoordinatesCollected++;\n\n if (nodeCoordinatesCollected === currentNodeBlock.numNodes) {\n nodeBlocksProcessed++;\n currentNodeBlock = { numNodes: 0 };\n }\n }\n } else if (section === \"elements\") {\n if (elementEntityBlocks === 0) {\n elementEntityBlocks = parseInt(parts[0], 10);\n totalElements = parseInt(parts[1], 10);\n lineIndex++;\n continue;\n }\n\n if (elementBlocksProcessed < elementEntityBlocks && currentElementBlock.numElements === 0) {\n currentElementBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n elementType: parseInt(parts[2], 10),\n numElements: parseInt(parts[3], 10),\n };\n\n result.elementTypes[currentElementBlock.elementType] =\n (result.elementTypes[currentElementBlock.elementType] || 0) + currentElementBlock.numElements;\n\n elementsProcessedInBlock = 0;\n lineIndex++;\n continue;\n }\n\n if (elementsProcessedInBlock < currentElementBlock.numElements) {\n const elementTag = parseInt(parts[0], 10);\n const nodeIndices = parts.slice(1).map((idx) => parseInt(idx, 10));\n\n if (currentElementBlock.elementType === 1 || currentElementBlock.elementType === 8) {\n const physicalTag = currentElementBlock.tag;\n\n if (!boundaryElementsByTag[physicalTag]) {\n boundaryElementsByTag[physicalTag] = [];\n }\n\n boundaryElementsByTag[physicalTag].push(nodeIndices);\n\n // Store boundary node pairs for later processing in meshGenerationScript\n if (!result.boundaryNodePairs[physicalTag]) {\n result.boundaryNodePairs[physicalTag] = [];\n }\n result.boundaryNodePairs[physicalTag].push(nodeIndices);\n } else if (currentElementBlock.elementType === 2) {\n // Linear triangle elements (3 nodes)\n result.nodalNumbering.triangleElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 3) {\n // Linear quadrilateral elements (4 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 10) {\n // Quadratic quadrilateral elements (9 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n }\n\n elementsProcessedInBlock++;\n\n if (elementsProcessedInBlock === currentElementBlock.numElements) {\n elementBlocksProcessed++;\n currentElementBlock = { numElements: 0 };\n }\n }\n }\n\n lineIndex++;\n }\n\n // Store boundary conditions information\n result.physicalPropMap.forEach((prop) => {\n if (prop.dimension === 1) {\n const boundaryNodes = boundaryElementsByTag[prop.tag] || [];\n\n if (boundaryNodes.length > 0) {\n result.boundaryConditions.push({\n name: prop.name,\n tag: prop.tag,\n nodes: boundaryNodes,\n });\n }\n }\n });\n\n debugLog(\n `Parsed boundary node pairs by physical tag: ${JSON.stringify(\n result.boundaryNodePairs\n )}. These pairs will be used to identify boundary elements in the mesh.`\n );\n\n return result;\n};\n\nexport { importGmshQuadTri };\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to create plots of the solution vector\n * @param {*} solutionVector - The computed solution vector\n * @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {string} meshDimension - The dimension of the solution\n * @param {string} plotType - The type of plot\n * @param {string} plotDivId - The id of the div where the plot will be rendered\n * @param {string} [meshType=\"structured\"] - Type of mesh: \"structured\" or \"unstructured\"\n */\nexport function plotSolution(\n solutionVector,\n nodesCoordinates,\n solverConfig,\n meshDimension,\n plotType,\n plotDivId,\n meshType = \"structured\"\n) {\n const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;\n\n if (meshDimension === \"1D\" && plotType === \"line\") {\n // Check if solutionVector is a nested array\n let yData;\n if (solutionVector.length > 0 && Array.isArray(solutionVector[0])) {\n yData = solutionVector.map((arr) => arr[0]);\n } else {\n yData = solutionVector;\n }\n let xData = Array.from(nodesXCoordinates);\n\n let lineData = {\n x: xData,\n y: yData,\n mode: \"lines\",\n type: \"scatter\",\n line: { color: \"rgb(219, 64, 82)\", width: 2 },\n name: \"Solution\",\n };\n\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxPlotWidth = Math.max(...xData);\n let zoomFactor = maxWindowWidth / maxPlotWidth;\n let plotWidth = Math.max(zoomFactor * maxPlotWidth, 400);\n let plotHeight = 350;\n\n let layout = {\n title: `line plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"Solution\" },\n margin: { l: 70, r: 40, t: 50, b: 50 },\n };\n\n Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });\n } else if (meshDimension === \"2D\" && plotType === \"contour\") {\n // Use the user-provided mesh type\n const isStructured = meshType === \"structured\";\n\n // For auto-detection (if needed)\n const uniqueXCoords = new Set(nodesXCoordinates).size;\n const uniqueYCoords = new Set(nodesYCoordinates).size;\n\n // Extract scalar values from solution vector\n let zValues;\n if (Array.isArray(solutionVector[0])) {\n zValues = solutionVector.map((val) => val[0]);\n } else {\n zValues = solutionVector;\n }\n\n // Common sizing parameters for both plot types\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxX = Math.max(...nodesXCoordinates);\n let maxY = Math.max(...nodesYCoordinates);\n let aspectRatio = maxY / maxX;\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = plotWidth * aspectRatio * 0.8; // Slightly reduce height for better appearance\n\n // Common layout properties\n let layout = {\n title: `${plotType} plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"y\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n hovermode: \"closest\",\n };\n\n if (isStructured) {\n // Calculate the number of nodes along the x-axis and y-axis\n const numNodesX = uniqueXCoords;\n const numNodesY = uniqueYCoords;\n\n // Reshape the nodesXCoordinates and nodesYCoordinates arrays to match the grid dimensions\n let reshapedXCoordinates = math.reshape(Array.from(nodesXCoordinates), [numNodesX, numNodesY]);\n let reshapedYCoordinates = math.reshape(Array.from(nodesYCoordinates), [numNodesX, numNodesY]);\n\n // Reshape the solution array to match the grid dimensions\n let reshapedSolution = math.reshape(Array.from(solutionVector), [numNodesX, numNodesY]);\n\n // Transpose the reshapedSolution array to get column-wise data\n let transposedSolution = math.transpose(reshapedSolution);\n\n // Create an array for x-coordinates used in the contour plot\n let reshapedXForPlot = [];\n for (let i = 0; i < numNodesX * numNodesY; i += numNodesY) {\n let xValue = nodesXCoordinates[i];\n reshapedXForPlot.push(xValue);\n }\n\n // Create the data structure for the contour plot\n let contourData = {\n z: transposedSolution,\n type: \"contour\",\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n x: reshapedXForPlot,\n y: reshapedYCoordinates[0],\n name: \"Solution Field\",\n };\n\n // Create the plot using Plotly\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n } else {\n // Create an interpolated contour plot for the unstructured mesh\n let contourData = {\n x: nodesXCoordinates,\n y: nodesYCoordinates,\n z: zValues,\n type: \"contour\",\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n name: \"Solution Field\",\n };\n\n // Create the plot using only the contour fill\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// External imports\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n// Internal imports\nimport { basicLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to facilitate communication with web workers for FEAScript operations\n */\nexport class FEAScriptWorker {\n /**\n * Constructor to initialize the FEAScriptWorker class\n * Sets up the worker and initializes the workerWrapper.\n */\n constructor() {\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n\n this._initWorker();\n }\n\n /**\n * Function to initialize the web worker and wrap it using Comlink.\n * @private\n * @throws Will throw an error if the worker fails to initialize.\n */\n async _initWorker() {\n try {\n this.worker = new Worker(new URL(\"./wrapperScript.js\", import.meta.url), {\n type: \"module\",\n });\n\n this.worker.onerror = (event) => {\n console.error(\"FEAScriptWorker: Worker error:\", event);\n };\n const workerWrapper = Comlink.wrap(this.worker);\n\n this.feaWorker = await new workerWrapper();\n\n this.isReady = true;\n } catch (error) {\n console.error(\"Failed to initialize worker\", error);\n throw error;\n }\n }\n\n /**\n * Function to ensure that the worker is ready before performing any operations.\n * @private\n * @returns {Promise} Resolves when the worker is ready.\n * @throws Will throw an error if the worker is not ready within the timeout period.\n */\n async _ensureReady() {\n if (this.isReady) return Promise.resolve();\n\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds max\n\n const checkReady = () => {\n attempts++;\n if (this.isReady) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(\"Timeout waiting for worker to be ready\"));\n } else {\n setTimeout(checkReady, 1000);\n }\n };\n checkReady();\n });\n }\n\n /**\n * Function to set the solver configuration in the worker.\n * @param {string} solverConfig - The solver configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setSolverConfig(solverConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver config to: ${solverConfig}`);\n return this.feaWorker.setSolverConfig(solverConfig);\n }\n\n /**\n * Sets the mesh configuration in the worker.\n * @param {object} meshConfig - The mesh configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setMeshConfig(meshConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting mesh config`);\n return this.feaWorker.setMeshConfig(meshConfig);\n }\n\n /**\n * Adds a boundary condition to the worker.\n * @param {string} boundaryKey - The key identifying the boundary.\n * @param {array} condition - The boundary condition to add.\n * @returns {Promise} Resolves when the boundary condition is added.\n */\n async addBoundaryCondition(boundaryKey, condition) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Adding boundary condition for boundary: ${boundaryKey}`);\n return this.feaWorker.addBoundaryCondition(boundaryKey, condition);\n }\n\n /**\n * Sets the solver method in the worker.\n * @param {string} solverMethod - The solver method to set.\n * @returns {Promise} Resolves when the solver method is set.\n */\n async setSolverMethod(solverMethod) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver method to: ${solverMethod}`);\n return this.feaWorker.setSolverMethod(solverMethod);\n }\n\n /**\n * Requests the worker to solve the problem.\n * @returns {Promise} Resolves with the solution result.\n */\n async solve() {\n await this._ensureReady();\n basicLog(\"FEAScriptWorker: Requesting solution from worker...\");\n\n const startTime = performance.now();\n const result = await this.feaWorker.solve();\n const endTime = performance.now();\n\n basicLog(`FEAScriptWorker: Solution completed in ${((endTime - startTime) / 1000).toFixed(2)}s`);\n return result;\n }\n\n /**\n * Retrieves model information from the worker.\n * @returns {Promise} Resolves with the model information.\n */\n async getModelInfo() {\n await this._ensureReady();\n return this.feaWorker.getModelInfo();\n }\n\n /**\n * Sends a ping request to the worker to check its availability.\n * @returns {Promise} Resolves if the worker responds.\n */\n async ping() {\n await this._ensureReady();\n return this.feaWorker.ping();\n }\n\n /**\n * Terminates the worker and cleans up resources.\n */\n terminate() {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nexport { FEAScriptModel } from \"./FEAScript.js\";\nexport { importGmshQuadTri } from \"./readers/gmshReaderScript.js\";\nexport { logSystem } from \"./utilities/loggingScript.js\";\nexport { plotSolution } from \"./visualization/plotSolutionScript.js\";\nexport { FEAScriptWorker } from \"./workers/workerScript.js\";\nexport const printVersion = \"0.1.4\";"],"names":["euclideanNorm","vector","norm","i","length","Math","sqrt","currentLogLevel","logSystem","level","console","log","basicLog","debugLog","message","errorLog","proxyMarker","Symbol","createEndpoint","releaseProxy","finalizer","throwMarker","isObject","val","transferHandlers","Map","canHandle","serialize","obj","port1","port2","MessageChannel","expose","deserialize","port","start","wrap","value","serialized","Error","isError","name","stack","Object","assign","ep","globalThis","allowedOrigins","addEventListener","callback","ev","data","origin","allowedOrigin","RegExp","test","isAllowedOrigin","warn","id","type","path","argumentList","map","fromWireValue","returnValue","parent","slice","reduce","prop","rawValue","apply","proxy","transfers","transferCache","set","transfer","undefined","Promise","resolve","catch","then","wireValue","transferables","toWireValue","postMessage","removeEventListener","closeEndPoint","error","TypeError","endpoint","constructor","isMessagePort","close","target","pendingListeners","resolver","get","delete","createProxy","throwIfProxyReleased","isReleased","releaseEndpoint","requestResponseMessage","proxyCounter","WeakMap","proxyFinalizers","FinalizationRegistry","newCount","isProxyReleased","Proxy","_target","unregister","unregisterProxy","clear","r","p","toString","bind","_thisArg","rawArgumentList","last","processArguments","construct","register","registerProxy","processed","v","arr","Array","prototype","concat","handler","serializedValue","msg","fill","floor","random","Number","MAX_SAFE_INTEGER","join","solveLinearSystem","solverMethod","jacobianMatrix","residualVector","options","maxIterations","tolerance","solutionVector","converged","iterations","time","jacobianMatrixSparse","math","sparse","luFactorization","slu","solutionMatrix","lusolve","squeeze","valueOf","jacobiSolverResult","A","b","x0","n","x","xNew","iter","sum","j","maxDiff","max","abs","jacobiSolver","timeEnd","async","solveLinearSystemAsync","isArray","toArray","created","computeEngine","worker","Worker","URL","url","Comlink.wrap","initialize","createDefaultComputeEngine","result","webgpuJacobiSolver","destroy","terminate","BasisFunctions","meshDimension","elementOrder","this","getBasisFunctions","ksi","eta","basisFunction","basisFunctionDerivKsi","basisFunctionDerivEta","l1","c","l2","l3","dl1","dl2","dl3","Mesh","numElementsX","maxX","numElementsY","maxY","parsedMesh","boundaryElementsProcessed","parseMeshFromGmsh","nodalNumbering","quadElements","triangleElements","JSON","stringify","elementTypes","mappedNodalNumbering","elemIdx","gmshNodes","feaScriptNodes","push","physicalPropMap","boundaryElements","fixedBoundaryElements","boundaryNodePairs","forEach","dimension","tag","nodesPair","node1","node2","foundElement","elemNodes","includes","side","node1Index","indexOf","node2Index","Mesh1D","super","generateMesh","nodesXCoordinates","totalNodesX","deltaX","nodeIndex","generate1DNodalNumbering","findBoundaryElements","nop","elementIndex","columnCounter","sideIndex","Mesh2D","nodesYCoordinates","totalNodesY","deltaY","nodeIndexY","nodeIndexX","nnode","generate2DNodalNumbering","rowCounter","elementIndexX","elementIndexY","nodeIndex1","nodeIndex2","NumericalIntegration","getGaussPointsAndWeights","gaussPoints","gaussWeights","prepareMesh","meshConfig","mesh","nodesCoordinatesAndNumbering","totalElements","totalNodes","initializeFEA","meshData","colIndex","basisFunctions","gaussPointsAndWeights","localToGlobalMap","numNodes","performIsoparametricMapping1D","params","xCoordinates","ksiDerivX","localNodeIndex","detJacobian","basisFunctionDerivX","performIsoparametricMapping2D","yCoordinates","etaDerivX","ksiDerivY","etaDerivY","basisFunctionDerivY","ThermalBoundaryConditions","boundaryConditions","imposeConstantTempBoundaryConditions","keys","boundaryKey","tempValue","globalNodeIndex","imposeConstantTempBoundaryConditionsFront","nodeConstraintCode","boundaryValues","imposeConvectionBoundaryConditions","convectionHeatTranfCoeff","convectionExtTemp","key","boundaryCondition","convectionCoeff","extTemp","gaussPoint1","gaussPoint2","firstNodeIndex","lastNodeIndex","nodeIncrement","basisFunctionsAndDerivatives","tangentVectorLength","localNodeIndex2","globalNodeIndex2","gaussPointIndex","imposeConvectionBoundaryConditionsFront","localJacobianMatrix","localResidualVector","boundaryElement","find","_","assembleHeatConductionMat","FEAData","gaussPointIndex1","mappingResult","localNodeIndex1","localToGlobalMap1","localToGlobalMap2","gaussPointIndex2","thermalBoundaryConditions","assembleHeatConductionFront","ngl","globalIndex","GenericBoundaryConditions","imposeDirichletBoundaryConditions","imposeConstantValueBoundaryConditionsFront","assembleFrontPropagationMat","eikonalActivationFlag","eikonalViscousTerm","solutionDerivX","solutionDerivY","assembleFrontPropagationFront","frontalData","frontalState","elementData","currentElementIndex","frontStorage","runFrontalSolver","assembleFront","numElements","globalResidualVector","topologyData","lateralData","writeFlag","transformationFlag","nodesPerElement","determinant","systemSize","globalSolutionVector","frontDataIndex","frontSize","frontWidthEstimate","ceil","estimateFrontSize","frontValues","columnHeaders","pivotRow","pivotData","initializeFrontalArrays","dirichletBoundaryConditionsHandler","currentSolutionVector","pivotColumnGlobalIndex","localDestination","rowDestination","rowHeaders","pivotRowIndices","pivotColumnIndices","modifiedRows","pivotColumn","frontMatrix","rowSwapCount","columnSwapCount","lastAppearanceCheck","frontDataCounter","pivotDataIndex","summedRows","reverseElementIndex","columnCount","rowCount","assembled","numElementNodes","numElementColumns","assembleElementContribution","currentElement","columnIndex","rowIndex","localColumnIndex","frontColumnIndex","localRowIndex","availableColumnCount","constrainedRowCount","availableRowCount","absoluteNodeIndex","constrainedIndex","pivotRowIndex","pivotColumnIndex","pivotValue","testColumnIndex","testRowIndex","testValue","pivotGlobalRowIndex","permutationHelper","rightHandSide","globalRowIndex","eliminationFactor","performBackSubstitution","runFrontalAlgorithm","toExponential","finalNodesX","finalNodesY","nodesCoordinates","boundaryLocalJacobianMatrix","boundaryResidualVector","isOnRobinTypeBoundary","some","localNodeI","localNodeJ","iterationIndex","accumulatedValue","newtonRaphson","assembleMat","context","errorNorm","initialSolution","FEAScriptModel","solverConfig","coefficientFunctions","setSolverConfig","setMeshConfig","addBoundaryCondition","condition","setSolverMethod","solve","eikonalExteralIterations","newtonRaphsonResult","B","C","D","xCoord","a","d","globalNodeIndex1","assembleGeneralFormPDEMat","solveAsync","importGmshQuadTri","file","gmshV","ascii","fltBytes","lines","text","split","line","trim","filter","section","lineIndex","nodeEntityBlocks","nodeBlocksProcessed","currentNodeBlock","nodeTagsCollected","nodeTags","nodeCoordinatesCollected","elementEntityBlocks","elementBlocksProcessed","currentElementBlock","dim","elementType","elementsProcessedInBlock","boundaryElementsByTag","parts","part","parseFloat","parseInt","replace","parametric","nodeTag","y","nodeIndices","idx","physicalTag","boundaryNodes","nodes","plotSolution","plotType","plotDivId","meshType","yData","xData","from","lineData","mode","color","width","maxWindowWidth","min","window","innerWidth","maxPlotWidth","zoomFactor","layout","title","height","xaxis","yaxis","margin","l","t","Plotly","newPlot","responsive","isStructured","uniqueXCoords","Set","size","uniqueYCoords","zValues","aspectRatio","plotWidth","hovermode","numNodesX","numNodesY","reshape","reshapedYCoordinates","reshapedSolution","transposedSolution","transpose","reshapedXForPlot","xValue","contourData","z","contours","coloring","showlabels","colorbar","FEAScriptWorker","feaWorker","isReady","_initWorker","onerror","event","workerWrapper","_ensureReady","reject","attempts","checkReady","setTimeout","startTime","performance","now","toFixed","getModelInfo","ping","printVersion"],"mappings":"AAaO,SAASA,EAAcC,GAC5B,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,OAAQD,IACjCD,GAAQD,EAAOE,GAAKF,EAAOE,GAG7B,OADAD,EAAOG,KAAKC,KAAKJ,GACVA,CACT,CCXA,IAAIK,EAAkB,QAMf,SAASC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X,KAAK6W,QACPle,IACSye,GANO,GAOhBD,EAAO,IAAI/gB,MAAM,2CAEjBkhB,WAAWD,EAAY,IACxB,EAEHA,GAAY,GAEf,CAOD,qBAAMtH,CAAgBF,GAGpB,aAFM7P,KAAKkX,eACXziB,EAAS,8CAA8Cob,KAChD7P,KAAK4W,UAAU7G,gBAAgBF,EACvC,CAOD,mBAAMG,CAAc/K,GAGlB,aAFMjF,KAAKkX,eACXziB,EAAS,wCACFuL,KAAK4W,UAAU5G,cAAc/K,EACrC,CAQD,0BAAMgL,CAAqBnJ,EAAaoJ,GAGtC,aAFMlQ,KAAKkX,eACXziB,EAAS,4DAA4DqS,KAC9D9G,KAAK4W,UAAU3G,qBAAqBnJ,EAAaoJ,EACzD,CAOD,qBAAMC,CAAgBzT,GAGpB,aAFMsD,KAAKkX,eACXziB,EAAS,8CAA8CiI,KAChDsD,KAAK4W,UAAUzG,gBAAgBzT,EACvC,CAMD,WAAM0T,SACEpQ,KAAKkX,eACXziB,EAAS,uDAET,MAAM8iB,EAAYC,YAAYC,MACxBhY,QAAeO,KAAK4W,UAAUxG,QAIpC,OADA3b,EAAS,4CAFO+iB,YAAYC,MAEmCF,GAAa,KAAMG,QAAQ,OACnFjY,CACR,CAMD,kBAAMkY,GAEJ,aADM3X,KAAKkX,eACJlX,KAAK4W,UAAUe,cACvB,CAMD,UAAMC,GAEJ,aADM5X,KAAKkX,eACJlX,KAAK4W,UAAUgB,MACvB,CAKD,SAAAhY,GACMI,KAAKd,SACPc,KAAKd,OAAOU,YACZI,KAAKd,OAAS,KACdc,KAAK4W,UAAY,KACjB5W,KAAK6W,SAAU,EAElB,EC9JS,MAACgB,GAAe"} \ No newline at end of file +{"version":3,"file":"feascript.esm.js","sources":["../src/methods/euclideanNormScript.js","../src/utilities/loggingScript.js","../src/vendor/comlink.mjs","../src/methods/linearSystemSolverScript.js","../src/methods/jacobiSolverScript.js","../src/mesh/basisFunctionsScript.js","../src/mesh/meshGenerationScript.js","../src/methods/numericalIntegrationScript.js","../src/mesh/meshUtilsScript.js","../src/models/thermalBoundaryConditionsScript.js","../src/models/heatConductionScript.js","../src/models/genericBoundaryConditionsScript.js","../src/models/frontPropagationScript.js","../src/methods/frontalSolverScript.js","../src/methods/newtonRaphsonScript.js","../src/FEAScript.js","../src/models/generalFormPDEScript.js","../src/readers/gmshReaderScript.js","../src/visualization/plotSolutionScript.js","../src/workers/workerScript.js","../src/index.js"],"sourcesContent":["/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to calculate the Euclidean norm of a vector\n * @param {array} vector - The input vector\n * @returns {number} The Euclidean norm of the vector\n */\nexport function euclideanNorm(vector) {\n let norm = 0;\n for (let i = 0; i < vector.length; i++) {\n norm += vector[i] * vector[i];\n }\n norm = Math.sqrt(norm);\n return norm;\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Global logging level\nlet currentLogLevel = \"basic\";\n\n/**\n * Function to set the logging system level\n * @param {string} level - Logging level (basic, debug)\n */\nexport function logSystem(level) {\n if (level !== \"basic\" && level !== \"debug\") {\n console.log(\n \"%c[WARN] Invalid log level: \" + level + \". Using basic instead.\",\n \"color: #FFC107; font-weight: bold;\"\n ); // Yellow for warnings\n currentLogLevel = \"basic\";\n } else {\n currentLogLevel = level;\n basicLog(`Log level set to: ${level}`);\n }\n}\n\n/**\n * Function to log debug messages - only logs if level is 'debug'\n * @param {string} message - Message to log\n */\nexport function debugLog(message) {\n if (currentLogLevel === \"debug\") {\n console.log(\"%c[DEBUG] \" + message, \"color: #2196F3; font-weight: bold;\");\n }\n}\n\n/**\n * Function to log basic information - always logs\n * @param {string} message - Message to log\n */\nexport function basicLog(message) {\n console.log(\"%c[INFO] \" + message, \"color: #4CAF50; font-weight: bold;\");\n}\n\n/**\n * Function to log error messages\n * @param {string} message - Message to log\n */\nexport function errorLog(message) {\n console.log(\"%c[ERROR] \" + message, \"color: #F44336; font-weight: bold;\");\n}\n\n/**\n * Function to log warning messages\n * @param {string} message - Message to log\n */\nexport function warnLog(message) {\n console.log(\"%c[WARN] \" + message, \"color: #FF9800; font-weight: bold;\");\n}\n\n/**\n * Function to handle version information and fetch the latest update date and release from GitHub\n */\nexport async function printVersionInformation() {\n basicLog(\"Fetching latest FEAScript version information...\");\n try {\n const commitResponse = await fetch(\"https://api.github.com/repos/FEAScript/FEAScript/commits/main\");\n const commitData = await commitResponse.json();\n const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();\n basicLog(`Latest FEAScript update: ${latestCommitDate}`);\n return latestCommitDate;\n } catch (error) {\n errorLog(\"Failed to fetch version information: \" + error);\n return \"Version information unavailable\";\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\nconst proxyMarker = Symbol(\"Comlink.proxy\");\nconst createEndpoint = Symbol(\"Comlink.endpoint\");\nconst releaseProxy = Symbol(\"Comlink.releaseProxy\");\nconst finalizer = Symbol(\"Comlink.finalizer\");\nconst throwMarker = Symbol(\"Comlink.thrown\");\nconst isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n};\n/**\n * Allows customizing the serialization of certain values.\n */\nconst transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\nfunction isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\nfunction expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n}\nfunction isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n}\nfunction closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n}\nfunction wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n}\nfunction throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\nfunction releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\nconst proxyCounter = new WeakMap();\nconst proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\nfunction registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\nfunction unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\nfunction createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n}\nfunction myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n}\nfunction processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\nconst transferCache = new WeakMap();\nfunction transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n}\nfunction proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n}\nfunction windowEndpoint(w, context = globalThis, targetOrigin = \"*\") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\nfunction toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\nfunction fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n}\nfunction requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n}\nfunction generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n\nexport { createEndpoint, expose, finalizer, proxy, proxyMarker, releaseProxy, transfer, transferHandlers, windowEndpoint, wrap };\n//# sourceMappingURL=comlink.mjs.map\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { jacobiSolver } from \"./jacobiSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n/**\n * Function to solve a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (\"lusolve\" or \"jacobi\")\n * @param {Array} jacobianMatrix - The coefficient matrix\n * @param {Array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {\n\n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n let solutionVector = [];\n let converged = true;\n let iterations = 0;\n\n // Solve the linear system based on the specified solver method\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n if (solverMethod === \"lusolve\") {\n // Use LU decomposition method\n const jacobianMatrixSparse = math.sparse(jacobianMatrix);\n const luFactorization = math.slu(jacobianMatrixSparse, 1, 1); // order=1, threshold=1 for pivoting\n let solutionMatrix = math.lusolve(luFactorization, residualVector);\n solutionVector = math.squeeze(solutionMatrix).valueOf();\n //solutionVector = math.lusolve(jacobianMatrix, residualVector); // In the case of a dense matrix\n } else if (solverMethod === \"jacobi\") {\n // Use Jacobi method\n const initialGuess = new Array(residualVector.length).fill(0);\n const jacobiSolverResult = jacobiSolver(jacobianMatrix, residualVector, initialGuess, {\n maxIterations,\n tolerance,\n });\n\n // Log convergence information\n if (jacobiSolverResult.converged) {\n debugLog(`Jacobi method converged in ${jacobiSolverResult.iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${jacobiSolverResult.iterations} iterations`);\n }\n\n solutionVector = jacobiSolverResult.solutionVector;\n converged = jacobiSolverResult.converged;\n iterations = jacobiSolverResult.iterations;\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n return { solutionVector, converged, iterations };\n}\n\n// Helper to lazily create a default WebGPU compute engine (Comlink + worker)\nasync function createDefaultComputeEngine() {\n const worker = new Worker(new URL(\"../workers/webgpuWorkerScript.js\", import.meta.url), {\n type: \"module\",\n });\n const computeEngine = Comlink.wrap(worker);\n await computeEngine.initialize();\n return { computeEngine, worker };\n}\n\n/**\n * Function to solve asynchronously a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (e.g., \"jacobi-gpu\")\n * @param {array} jacobianMatrix - The coefficient matrix\n * @param {array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport async function solveLinearSystemAsync(solverMethod, jacobianMatrix, residualVector, options = {}) {\n \n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n // Normalize inputs\n const A = Array.isArray(jacobianMatrix) ? jacobianMatrix : jacobianMatrix?.toArray?.() ?? jacobianMatrix;\n const b = Array.isArray(residualVector) ? residualVector : residualVector?.toArray?.() ?? residualVector;\n\n let created = null;\n let computeEngine = null;\n\n let solutionVector = [];\n let converged = true;\n let iterations;\n\n if (solverMethod === \"jacobi-gpu\") {\n // Spin up a worker-backed compute engine\n created = await createDefaultComputeEngine();\n computeEngine = created.computeEngine;\n\n const x0 = new Array(b.length).fill(0);\n let result;\n\n result = await computeEngine.webgpuJacobiSolver(A, b, x0, { maxIterations, tolerance });\n solutionVector = result.solutionVector;\n converged = result.converged;\n iterations = result.iterations;\n\n // Log convergence information\n if (converged) {\n debugLog(`Jacobi method converged in ${iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${iterations} iterations`);\n }\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(`System solved successfully (${solverMethod})`);\n\n if (created) {\n await computeEngine?.destroy?.().catch(() => { });\n created.worker.terminate();\n }\n\n return { solutionVector, converged, iterations };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to solve a system of linear equations using the Jacobi iterative method (CPU synchronous version)\n * @param {array} A - The system matrix\n * @param {array} b - The right-hand side vector\n * @param {array} x0 - Initial guess for solution vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\nexport function jacobiSolver(A, b, x0, options = {}) {\n // Extract options\n const { maxIterations, tolerance } = options;\n\n const n = A.length;\n let x = [...x0];\n let xNew = new Array(n);\n\n // Jacobi update: xNew[i] = (b[i] - sum(A[i][j] * x[j] for j != i)) / A[i][i]\n for (let iter = 0; iter < maxIterations; iter++) {\n for (let i = 0; i < n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (i !== j) {\n sum += A[i][j] * x[j];\n }\n }\n xNew[i] = (b[i] - sum) / A[i][i];\n }\n\n // Check convergence based on maximum difference in solution vector\n let maxDiff = 0;\n for (let i = 0; i < n; i++) {\n maxDiff = Math.max(maxDiff, Math.abs(xNew[i] - x[i]));\n }\n\n // Copy new solution for the next iteration\n x = [...xNew];\n\n if (maxDiff < tolerance) {\n return { solutionVector: x, iterations: iter + 1, converged: true };\n }\n }\n\n return { solutionVector: x, iterations: maxIterations, converged: false };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle basis functions and their derivatives based on element configuration\n */\nexport class BasisFunctions {\n /**\n * Constructor to initialize the BasisFunctions class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to calculate basis functions and their derivatives based on the dimension and order\n * @param {number} ksi - Natural coordinate (for both 1D and 2D)\n * @param {number} [eta] - Second natural coordinate (only for 2D elements)\n * @returns {object} An object containing:\n * - basisFunction: Array of evaluated basis functions\n * - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi\n * - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)\n */\n getBasisFunctions(ksi, eta = null) {\n let basisFunction = [];\n let basisFunctionDerivKsi = [];\n let basisFunctionDerivEta = [];\n\n if (this.meshDimension === \"1D\") {\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 1D elements\n basisFunction[0] = 1 - ksi;\n basisFunction[1] = ksi;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -1;\n basisFunctionDerivKsi[1] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 1D elements\n basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;\n basisFunction[1] = 4 * ksi - 4 * ksi ** 2;\n basisFunction[2] = -ksi + 2 * ksi ** 2;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -3 + 4 * ksi;\n basisFunctionDerivKsi[1] = 4 - 8 * ksi;\n basisFunctionDerivKsi[2] = -1 + 4 * ksi;\n }\n } else if (this.meshDimension === \"2D\") {\n if (eta === null) {\n errorLog(\"Eta coordinate is required for 2D elements\");\n return;\n }\n\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 2D elements\n function l1(c) {\n return 1 - c;\n }\n function l2(c) {\n return c;\n }\n function dl1() {\n return -1;\n }\n function dl2() {\n return 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l2(ksi) * l1(eta);\n basisFunction[3] = l2(ksi) * l2(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1() * l1(eta);\n basisFunctionDerivKsi[1] = dl1() * l2(eta);\n basisFunctionDerivKsi[2] = dl2() * l1(eta);\n basisFunctionDerivKsi[3] = dl2() * l2(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1();\n basisFunctionDerivEta[1] = l1(ksi) * dl2();\n basisFunctionDerivEta[2] = l2(ksi) * dl1();\n basisFunctionDerivEta[3] = l2(ksi) * dl2();\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 2D elements\n function l1(c) {\n return 2 * c ** 2 - 3 * c + 1;\n }\n function l2(c) {\n return -4 * c ** 2 + 4 * c;\n }\n function l3(c) {\n return 2 * c ** 2 - c;\n }\n function dl1(c) {\n return 4 * c - 3;\n }\n function dl2(c) {\n return -8 * c + 4;\n }\n function dl3(c) {\n return 4 * c - 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l1(ksi) * l3(eta);\n basisFunction[3] = l2(ksi) * l1(eta);\n basisFunction[4] = l2(ksi) * l2(eta);\n basisFunction[5] = l2(ksi) * l3(eta);\n basisFunction[6] = l3(ksi) * l1(eta);\n basisFunction[7] = l3(ksi) * l2(eta);\n basisFunction[8] = l3(ksi) * l3(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);\n basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);\n basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);\n basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);\n basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);\n basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);\n basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);\n basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);\n basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);\n basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);\n basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);\n basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);\n basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);\n basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);\n basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);\n basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);\n basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);\n }\n }\n\n return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Basic structure for the mesh\n */\nexport class Mesh {\n /**\n * Constructor to initialize the Mesh class\n * @param {object} config - Configuration object for the mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)\n * @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)\n * @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n meshDimension = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n this.numElementsX = numElementsX;\n this.numElementsY = numElementsY;\n this.maxX = maxX;\n this.maxY = maxY;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n this.parsedMesh = parsedMesh;\n\n this.boundaryElementsProcessed = false;\n\n if (this.parsedMesh) {\n basicLog(\"Using pre-parsed mesh from gmshReader data for mesh generation.\");\n this.parseMeshFromGmsh();\n }\n }\n\n /**\n * Method to parse the mesh from the GMSH format to the FEAScript format\n */\n parseMeshFromGmsh() {\n if (!this.parsedMesh.nodalNumbering) {\n errorLog(\"No valid nodal numbering found in the parsed mesh.\");\n }\n\n if (\n typeof this.parsedMesh.nodalNumbering === \"object\" &&\n !Array.isArray(this.parsedMesh.nodalNumbering)\n ) {\n // Store the nodal numbering structure before converting\n const quadElements = this.parsedMesh.nodalNumbering.quadElements || [];\n const triangleElements = this.parsedMesh.nodalNumbering.triangleElements || [];\n\n debugLog(\n \"Initial parsed mesh nodal numbering from GMSH format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Check if it has quadElements or triangleElements structure from gmshReader\n if (this.parsedMesh.elementTypes[3] || this.parsedMesh.elementTypes[10]) {\n // Map nodal numbering from GMSH format to FEAScript format for quad elements\n const mappedNodalNumbering = [];\n\n for (let elemIdx = 0; elemIdx < quadElements.length; elemIdx++) {\n const gmshNodes = quadElements[elemIdx];\n const feaScriptNodes = new Array(gmshNodes.length);\n\n // Check for element type based on number of nodes\n if (gmshNodes.length === 4) {\n // Simple mapping for linear quad elements (4 nodes)\n // GMSH: FEAScript:\n // 3 --- 2 1 --- 3\n // | | --> | |\n // 0 --- 1 0 --- 2\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[3]; // 3 -> 1\n feaScriptNodes[2] = gmshNodes[1]; // 1 -> 2\n feaScriptNodes[3] = gmshNodes[2]; // 2 -> 3\n } else if (gmshNodes.length === 9) {\n // Mapping for quadratic quad elements (9 nodes)\n // GMSH: FEAScript:\n // 3--6--2 2--5--8\n // | | | |\n // 7 8 5 --> 1 4 7\n // | | | |\n // 0--4--1 0--3--6\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[7]; // 7 -> 1\n feaScriptNodes[2] = gmshNodes[3]; // 3 -> 2\n feaScriptNodes[3] = gmshNodes[4]; // 4 -> 3\n feaScriptNodes[4] = gmshNodes[8]; // 8 -> 4\n feaScriptNodes[5] = gmshNodes[6]; // 6 -> 5\n feaScriptNodes[6] = gmshNodes[1]; // 1 -> 6\n feaScriptNodes[7] = gmshNodes[5]; // 5 -> 7\n feaScriptNodes[8] = gmshNodes[2]; // 2 -> 8\n }\n\n mappedNodalNumbering.push(feaScriptNodes);\n }\n\n this.parsedMesh.nodalNumbering = mappedNodalNumbering;\n } else if (this.parsedMesh.elementTypes[2]) {\n errorLog(\"Element type is neither triangle nor quad; mapping for this type is not implemented yet.\");\n }\n\n debugLog(\n \"Nodal numbering after mapping from GMSH to FEAScript format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Process boundary elements if they exist and if physical property mapping exists\n if (this.parsedMesh.physicalPropMap && this.parsedMesh.boundaryElements) {\n // Check if boundary elements need to be processed\n if (\n Array.isArray(this.parsedMesh.boundaryElements) &&\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n // Create a new array without the empty first element\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n\n // If boundary node pairs exist but boundary elements haven't been processed\n if (this.parsedMesh.boundaryNodePairs && !this.parsedMesh.boundaryElementsProcessed) {\n // Reset boundary elements array\n this.parsedMesh.boundaryElements = [];\n\n // Process each physical property from the Gmsh file\n this.parsedMesh.physicalPropMap.forEach((prop) => {\n // Only process 1D physical entities (boundary lines)\n if (prop.dimension === 1) {\n // Get all node pairs for this boundary\n const boundaryNodePairs = this.parsedMesh.boundaryNodePairs[prop.tag] || [];\n\n if (boundaryNodePairs.length > 0) {\n // Initialize array for this boundary tag\n if (!this.parsedMesh.boundaryElements[prop.tag]) {\n this.parsedMesh.boundaryElements[prop.tag] = [];\n }\n\n // For each boundary line segment (defined by a pair of nodes)\n boundaryNodePairs.forEach((nodesPair) => {\n const node1 = nodesPair[0]; // First node in the pair\n const node2 = nodesPair[1]; // Second node in the pair\n\n debugLog(\n `Processing boundary node pair: [${node1}, ${node2}] for boundary ${prop.tag} (${\n prop.name || \"unnamed\"\n })`\n );\n\n // Search through all elements to find which one contains both nodes\n let foundElement = false;\n\n // Loop through all elements in the mesh\n for (let elemIdx = 0; elemIdx < this.parsedMesh.nodalNumbering.length; elemIdx++) {\n const elemNodes = this.parsedMesh.nodalNumbering[elemIdx];\n\n // For linear quadrilateral linear elements (4 nodes)\n if (elemNodes.length === 4) {\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript linear quadrilateral numbering:\n // 1 --- 3\n // | |\n // 0 --- 2\n\n if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0)\n ) {\n side = 0; // Bottom side\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0)\n ) {\n side = 1; // Left side\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 1 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 1)\n ) {\n side = 2; // Top side\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 2)\n ) {\n side = 3; // Right side\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n } else if (elemNodes.length === 9) {\n // For quadratic quadrilateral elements (9 nodes)\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript quadratic quadrilateral numbering:\n // 2--5--8\n // | |\n // 1 4 7\n // | |\n // 0--3--6\n\n // TODO: Transform into dictionaries for better readability\n if (\n (node1Index === 0 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 0) ||\n (node1Index === 3 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 3)\n ) {\n side = 0; // Bottom side (nodes 0, 3, 6)\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0) ||\n (node1Index === 1 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 1)\n ) {\n side = 1; // Left side (nodes 0, 1, 2)\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 5) ||\n (node1Index === 5 && node2Index === 2) ||\n (node1Index === 5 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 5)\n ) {\n side = 2; // Top side (nodes 2, 5, 8)\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 6 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 7) ||\n (node1Index === 7 && node2Index === 6) ||\n (node1Index === 7 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 7)\n ) {\n side = 3; // Right side (nodes 6, 7, 8)\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n }\n }\n\n if (!foundElement) {\n errorLog(\n `Could not find element containing boundary nodes ${node1} and ${node2}. Boundary may be incomplete.`\n );\n }\n });\n }\n }\n });\n\n // Mark as processed\n this.boundaryElementsProcessed = true;\n\n // Fix boundary elements array - remove undefined entries\n if (\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n }\n }\n }\n\n return this.parsedMesh;\n }\n}\n\nexport class Mesh1D extends Mesh {\n /**\n * Constructor to initialize the 1D mesh\n * @param {object} config - Configuration object for the 1D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({ numElementsX = null, maxX = null, elementOrder = \"linear\", parsedMesh = null }) {\n super({\n numElementsX,\n maxX,\n numElementsY: 1,\n maxY: 0,\n meshDimension: \"1D\",\n elementOrder,\n parsedMesh,\n });\n\n if (this.numElementsX === null || this.maxX === null) {\n errorLog(\"numElementsX and maxX are required parameters when generating a 1D mesh from geometry\");\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n const xStart = 0;\n let totalNodesX, deltaX;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX;\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX / 2;\n }\n }\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate1DNodalNumbering(this.numElementsX, totalNodesX, this.elementOrder);\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n\n // Return x coordinates of nodes, total nodes, NOP array, and boundary elements\n return {\n nodesXCoordinates,\n totalNodesX,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate1DNodalNumbering(numElementsX, totalNodesX, elementOrder) {\n // TODO: The totalNodesX is not used in the original function. Verify if\n // there is a multiple calculation on the totalNodes.\n\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear 1D elements with the following nodes representation:\n *\n * 1 --- 2\n *\n */\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic 1D elements with the following nodes representation:\n *\n * 1--2--3\n *\n */\n let columnCounter = 0;\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex + columnCounter;\n }\n columnCounter += 1;\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 1D domains (line segments):\n * 0 - Left node of reference element (maps to physical left endpoint)\n * 1 - Right node of reference element (maps to physical right endpoint)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 2; // For 1D, we only have two sides (left and right)\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // Left boundary (element 0, side 0)\n boundaryElements[0].push([0, 0]);\n\n // Right boundary (last element, side 1)\n boundaryElements[1].push([this.numElementsX - 1, 1]);\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n\nexport class Mesh2D extends Mesh {\n /**\n * Constructor to initialize the 2D mesh\n * @param {object} config - Configuration object for the 2D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY] - Number of elements along the y-axis (required for geometry-based mesh)\n * @param {number} [config.maxY] - Maximum y-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n super({\n numElementsX,\n maxX,\n numElementsY,\n maxY,\n meshDimension: \"2D\",\n elementOrder,\n parsedMesh,\n });\n\n // Validate geometry parameters (when not using a parsed mesh)\n if (\n !parsedMesh &&\n (this.numElementsX === null || this.maxX === null || this.numElementsY === null || this.maxY === null)\n ) {\n errorLog(\n \"numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry\"\n );\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n let nodesYCoordinates = [];\n const xStart = 0;\n const yStart = 0;\n let totalNodesX, totalNodesY, deltaX, deltaY;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n totalNodesY = this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + nodeIndexY * deltaY;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + nodeIndexX * deltaX;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + nodeIndexY * deltaY;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n totalNodesY = 2 * this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;\n }\n }\n }\n\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate2DNodalNumbering(\n this.numElementsX,\n this.numElementsY,\n totalNodesY,\n this.elementOrder\n );\n\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n debugLog(\"Generated node Y coordinates: \" + JSON.stringify(nodesYCoordinates));\n\n // Return statement\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate2DNodalNumbering(numElementsX, numElementsY, totalNodesY, elementOrder) {\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear rectangular elements with the following nodes representation:\n *\n * 1 --- 3\n * | |\n * 0 --- 2\n *\n */\n let rowCounter = 0;\n let columnCounter = 2;\n for (let elementIndex = 0; elementIndex < numElementsX * numElementsY; elementIndex++) {\n rowCounter += 1;\n nop[elementIndex] = [];\n nop[elementIndex][0] = elementIndex + columnCounter - 1;\n nop[elementIndex][1] = elementIndex + columnCounter;\n nop[elementIndex][2] = elementIndex + columnCounter + numElementsY;\n nop[elementIndex][3] = elementIndex + columnCounter + numElementsY + 1;\n if (rowCounter === numElementsY) {\n columnCounter += 1;\n rowCounter = 0;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic rectangular elements with the following nodes representation:\n *\n * 2--5--8\n * | |\n * 1 4 7\n * | |\n * 0--3--6\n *\n */\n for (let elementIndexX = 1; elementIndexX <= numElementsX; elementIndexX++) {\n for (let elementIndexY = 1; elementIndexY <= numElementsY; elementIndexY++) {\n nop[elementIndex] = [];\n for (let nodeIndex1 = 1; nodeIndex1 <= 3; nodeIndex1++) {\n let nodeIndex2 = 3 * nodeIndex1 - 2;\n nop[elementIndex][nodeIndex2 - 1] =\n totalNodesY * (2 * elementIndexX + nodeIndex1 - 3) + 2 * elementIndexY - 1;\n nop[elementIndex][nodeIndex2] = nop[elementIndex][nodeIndex2 - 1] + 1;\n nop[elementIndex][nodeIndex2 + 1] = nop[elementIndex][nodeIndex2 - 1] + 2;\n }\n elementIndex = elementIndex + 1;\n }\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 2D domains (rectangular):\n * 0 - Bottom side of reference element (maps to physical bottom boundary)\n * 1 - Left side of reference element (maps to physical left boundary)\n * 2 - Top side of reference element (maps to physical top boundary)\n * 3 - Right side of reference element (maps to physical right boundary)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 4; // For 2D, we have four sides (left, right, bottom, top)\n\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // TODO: Why to loop through all elements? Is it not better to loop over only the\n // elements that are on the boundary? eg: [0, this.numElementsX - 1] on x and\n // [0, this.numElementsY - 1] on y\n for (let elementIndexX = 0; elementIndexX < this.numElementsX; elementIndexX++) {\n for (let elementIndexY = 0; elementIndexY < this.numElementsY; elementIndexY++) {\n const elementIndex = elementIndexX * this.numElementsY + elementIndexY;\n\n // Bottom boundary\n if (elementIndexY === 0) {\n boundaryElements[0].push([elementIndex, 0]);\n }\n\n // Left boundary\n if (elementIndexX === 0) {\n boundaryElements[1].push([elementIndex, 1]);\n }\n\n // Top boundary\n if (elementIndexY === this.numElementsY - 1) {\n boundaryElements[2].push([elementIndex, 2]);\n }\n\n // Right boundary\n if (elementIndexX === this.numElementsX - 1) {\n boundaryElements[3].push([elementIndex, 3]);\n }\n }\n }\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Class to handle numerical integration using Gauss quadrature\n */\nexport class NumericalIntegration {\n /**\n * Constructor to initialize the NumericalIntegration class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to return Gauss points and weights based on element configuration\n * @returns {object} An object containing:\n * - gaussPoints: Array of Gauss points\n * - gaussWeights: Array of Gauss weights\n */\n getGaussPointsAndWeights() {\n let gaussPoints = []; // Gauss points\n let gaussWeights = []; // Gauss weights\n\n if (this.elementOrder === \"linear\") {\n // For linear elements, use 1-point Gauss quadrature\n gaussPoints[0] = 0.5;\n gaussWeights[0] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // For quadratic elements, use 3-point Gauss quadrature\n gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;\n gaussPoints[1] = 0.5;\n gaussPoints[2] = (1 + Math.sqrt(3 / 5)) / 2;\n gaussWeights[0] = 5 / 18;\n gaussWeights[1] = 8 / 18;\n gaussWeights[2] = 5 / 18;\n }\n\n return { gaussPoints, gaussWeights };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nimport { BasisFunctions } from \"./basisFunctionsScript.js\";\nimport { Mesh1D, Mesh2D } from \"./meshGenerationScript.js\";\nimport { NumericalIntegration } from \"../methods/numericalIntegrationScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to prepare the mesh for finite element analysis\n * @param {object} meshConfig - Object containing computational mesh details\n * @returns {object} An object containing all mesh-related data\n */\nexport function prepareMesh(meshConfig) {\n const { meshDimension, numElementsX, numElementsY, maxX, maxY, elementOrder, parsedMesh } = meshConfig;\n\n // Create a new instance of the Mesh class\n let mesh;\n if (meshDimension === \"1D\") {\n mesh = new Mesh1D({ numElementsX, maxX, elementOrder, parsedMesh });\n } else if (meshDimension === \"2D\") {\n mesh = new Mesh2D({ numElementsX, maxX, numElementsY, maxY, elementOrder, parsedMesh });\n } else {\n errorLog(\"Mesh dimension must be either '1D' or '2D'.\");\n }\n\n // Use the parsed mesh in case it was already passed with Gmsh format\n const nodesCoordinatesAndNumbering = mesh.boundaryElementsProcessed ? mesh.parsedMesh : mesh.generateMesh();\n\n // Extract nodes coordinates and nodal numbering (NOP) from the mesh data\n let nodesXCoordinates = nodesCoordinatesAndNumbering.nodesXCoordinates;\n let nodesYCoordinates = nodesCoordinatesAndNumbering.nodesYCoordinates;\n let totalNodesX = nodesCoordinatesAndNumbering.totalNodesX;\n let totalNodesY = nodesCoordinatesAndNumbering.totalNodesY;\n let nop = nodesCoordinatesAndNumbering.nodalNumbering;\n let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;\n\n // Check the mesh type\n const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;\n\n // Calculate totalElements and totalNodes based on mesh type\n let totalElements, totalNodes;\n\n if (isParsedMesh) {\n totalElements = nop.length; // Number of elements is the length of the nodal numbering array\n totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array\n debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);\n } else {\n // For structured mesh, calculate based on dimensions\n totalElements = numElementsX * (meshDimension === \"2D\" ? numElementsY : 1);\n totalNodes = totalNodesX * (meshDimension === \"2D\" ? totalNodesY : 1);\n debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);\n }\n\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nop,\n boundaryElements,\n totalElements,\n totalNodes,\n meshDimension,\n elementOrder,\n };\n}\n\n/**\n * Function to initialize the FEA matrices and numerical tools\n * @param {object} meshData - Object containing mesh data from prepareMesh()\n * @returns {object} An object containing initialized matrices and numerical tools\n */\nexport function initializeFEA(meshData) {\n const { totalNodes, nop, meshDimension, elementOrder } = meshData;\n\n // Initialize variables for matrix assembly\n let residualVector = [];\n let jacobianMatrix = [];\n let localToGlobalMap = [];\n\n // Initialize jacobianMatrix and residualVector arrays\n for (let nodeIndex = 0; nodeIndex < totalNodes; nodeIndex++) {\n residualVector[nodeIndex] = 0;\n jacobianMatrix.push([]);\n for (let colIndex = 0; colIndex < totalNodes; colIndex++) {\n jacobianMatrix[nodeIndex][colIndex] = 0;\n }\n }\n\n // Initialize the BasisFunctions class\n const basisFunctions = new BasisFunctions({\n meshDimension,\n elementOrder,\n });\n\n // Initialize the NumericalIntegration class\n const numericalIntegration = new NumericalIntegration({\n meshDimension,\n elementOrder,\n });\n\n // Calculate Gauss points and weights\n let gaussPointsAndWeights = numericalIntegration.getGaussPointsAndWeights();\n let gaussPoints = gaussPointsAndWeights.gaussPoints;\n let gaussWeights = gaussPointsAndWeights.gaussWeights;\n\n // Determine the number of nodes in the reference element based on the first element in the nop array\n const numNodes = nop[0].length;\n\n return {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 1D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping1D(params) {\n const { basisFunction, basisFunctionDerivKsi, nodesXCoordinates, localToGlobalMap, numNodes } = params;\n\n let xCoordinates = 0;\n let ksiDerivX = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n }\n let detJacobian = ksiDerivX;\n\n // Compute x-derivative of basis functions\n let basisFunctionDerivX = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n basisFunctionDerivX[localNodeIndex] = basisFunctionDerivKsi[localNodeIndex] / detJacobian;\n }\n\n return {\n xCoordinates,\n detJacobian,\n basisFunctionDerivX,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 2D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping2D(params) {\n const {\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n } = params;\n\n let xCoordinates = 0;\n let yCoordinates = 0;\n let ksiDerivX = 0;\n let etaDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivY = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n yCoordinates += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n ksiDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n }\n let detJacobian = ksiDerivX * etaDerivY - etaDerivX * ksiDerivY;\n\n // Compute x-derivative and y-derivative of basis functions\n let basisFunctionDerivX = [];\n let basisFunctionDerivY = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // The x-derivative of the n basis function\n basisFunctionDerivX[localNodeIndex] =\n (etaDerivY * basisFunctionDerivKsi[localNodeIndex] -\n ksiDerivY * basisFunctionDerivEta[localNodeIndex]) /\n detJacobian;\n // The y-derivative of the n basis function\n basisFunctionDerivY[localNodeIndex] =\n (ksiDerivX * basisFunctionDerivEta[localNodeIndex] -\n etaDerivX * basisFunctionDerivKsi[localNodeIndex]) /\n detJacobian;\n }\n\n return {\n xCoordinates,\n yCoordinates,\n detJacobian,\n basisFunctionDerivX,\n basisFunctionDerivY,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle thermal boundary conditions application\n */\nexport class ThermalBoundaryConditions {\n /**\n * Constructor to initialize the ThermalBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose constant temperature boundary conditions (Dirichlet type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant temperature boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantTempBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions (Robin type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n */\n imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 1;\n }\n } else if (this.elementOrder === \"quadratic\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 2;\n }\n }\n\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n residualVector[globalNodeIndex] += -convectionCoeff * extTemp;\n jacobianMatrix[globalNodeIndex][globalNodeIndex] += convectionCoeff;\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions for the frontal solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix with convection contributions\n * - localResidualVector: Residual vector with convection contributions\n */\n imposeConvectionBoundaryConditionsFront(\n elementIndex,\n nodesXCoordinates,\n nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n // Initialize local Jacobian matrix and local residual vector\n const numNodes = this.nop[elementIndex].length;\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Check if this element is on a convection boundary\n for (const boundaryKey in this.boundaryElements) {\n if (this.boundaryConditions[boundaryKey]?.[0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n\n // Find if this element is on this boundary and which side\n const boundaryElement = this.boundaryElements[boundaryKey].find(\n ([elemIdx, _]) => elemIdx === elementIndex\n );\n\n if (boundaryElement) {\n const side = boundaryElement[1];\n\n if (this.meshDimension === \"1D\") {\n // Handle 1D case\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n nodeIndex = side === 0 ? 0 : 1;\n } else if (this.elementOrder === \"quadratic\") {\n nodeIndex = side === 0 ? 0 : 2;\n }\n\n // Add contribution to local Jacobian matrix and local residual vector\n debugLog(\n ` - Applied convection boundary condition to node ${nodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n localResidualVector[nodeIndex] += -convectionCoeff * extTemp;\n localJacobianMatrix[nodeIndex][nodeIndex] += convectionCoeff;\n } else if (this.meshDimension === \"2D\") {\n // Handle 2D case\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n // Get basis functions\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n const basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n const basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n // Calculate tangent vector components\n let ksiDerivX = 0,\n ksiDerivY = 0,\n etaDerivX = 0,\n etaDerivY = 0;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n } else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute tangent vector length\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n // Handle quadratic elements (similar pattern but with more Gauss points)\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { ThermalBoundaryConditions } from \"./thermalBoundaryConditionsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the solid heat transfer model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\nexport function assembleHeatConductionMat(meshData, boundaryConditions) {\n basicLog(\"Starting solid heat transfer matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D solid heat transfer\n if (meshDimension === \"1D\") {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n // 2D solid heat transfer\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const thermalBoundaryConditions = new ThermalBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Convection boundary conditions\n thermalBoundaryConditions.imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n );\n\n // Impose ConstantTemp boundary conditions\n thermalBoundaryConditions.imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Solid heat transfer matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the solid heat transfer model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - localResidualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleHeatConductionFront({ elementIndex, nop, meshData, basisFunctions, FEAData }) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n if (meshDimension === \"1D\") {\n // 1D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n // 2D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Create mapping from local element space to global mesh (convert to 0-based indexing)\n const localToGlobalMap = ngl.map((globalIndex) => globalIndex - 1);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle generic boundary conditions application\n */\nexport class GenericBoundaryConditions {\n /**\n * Constructor to initialize the GenericBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose Dirichlet boundary conditions\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant value (Dirichlet) boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantValueBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n// Base viscous term that remains when eikonal equation is fully activated\nconst baseEikonalViscousTerm = 1e-2;\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the front propagation model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleFrontPropagationMat(\n meshData,\n boundaryConditions,\n solutionVector,\n eikonalActivationFlag\n) {\n basicLog(\"Starting front propagation matrix assembly...\");\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n debugLog(`eikonalViscousTerm: ${eikonalViscousTerm}`);\n debugLog(`eikonalActivationFlag: ${eikonalActivationFlag}`);\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // jacobianMatrix\n // TODO jacobianMatrix calculation here\n }\n }\n }\n // 2D front propagation (eikonal) equation\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n\n // residualVector: Viscous term contribution (to stabilize the solution)\n residualVector[localToGlobalMap1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // residualVector: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n residualVector[localToGlobalMap1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n\n // jacobianMatrix: Viscous term contribution\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // jacobianMatrix: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Dirichlet boundary conditions\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Front propagation matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the front propagation model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - residualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleFrontPropagationFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n solutionVector,\n eikonalActivationFlag,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // localJacobianMatrix\n // TODO localJacobianMatrix calculation here\n }\n }\n // 2D front propagation (eikonal) equation\n } else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // Viscous term contribution\n localResidualVector[localNodeIndex1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localResidualVector[localNodeIndex1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Viscous term contribution\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { BasisFunctions } from \"../mesh/basisFunctionsScript.js\";\nimport { initializeFEA } from \"../mesh/meshUtilsScript.js\";\nimport { assembleHeatConductionFront } from \"../models/heatConductionScript.js\";\nimport { ThermalBoundaryConditions } from \"../models/thermalBoundaryConditionsScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\nimport { GenericBoundaryConditions } from \"../models/genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n// Create object templates\nconst frontalData = {};\nconst frontalState = {};\nconst elementData = { currentElementIndex: 0 };\nconst frontStorage = {};\nlet basisFunctions;\n\n/**\n * Function to run the frontal solver and obtain results for plotting\n * @param {function} assembleFront - Matrix assembler based on the physical model\n * @param {object} meshData - Object containing mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} [options] - Additional options for the solver\n * @returns {object} An object containing the solution vector and node coordinates\n */\nexport function runFrontalSolver(assembleFront, meshData, boundaryConditions, options = {}) {\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const totalNodes = meshData.nodesXCoordinates.length;\n const numElements = meshData.totalElements;\n const numNodes = FEAData.numNodes;\n\n // Calculate required array sizes\n initializeFrontalArrays(numNodes, numElements);\n\n // Start timing for system solving (frontal algorithm)\n basicLog(\"Solving system using frontal...\");\n console.time(\"systemSolving\");\n\n // Initialize basis functions\n basisFunctions = new BasisFunctions({\n meshDimension: meshData.meshDimension,\n elementOrder: meshData.elementOrder,\n });\n\n // Copy node connectivity array into frontalData storage\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n for (let nodeIndex = 0; nodeIndex < FEAData.numNodes; nodeIndex++) {\n frontalData.nodalNumbering[elementIndex][nodeIndex] = meshData.nop[elementIndex][nodeIndex];\n }\n }\n\n // Apply Dirichlet-type boundary conditions\n // Initialize all nodes with no boundary condition\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.nodeConstraintCode[nodeIndex] = 0;\n frontalData.boundaryValues[nodeIndex] = 0;\n }\n\n // Handle Dirichlet-type boundary conditions differently based on which solver is being used\n let dirichletBoundaryConditionsHandler;\n // Solid heat transfer model (heatConductionScript solver)\n if (assembleFront === assembleHeatConductionFront) {\n dirichletBoundaryConditionsHandler = new ThermalBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantTempBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n // Front propagation model (frontPropagationScript solver)\n } else if (assembleFront === assembleFrontPropagationFront) {\n dirichletBoundaryConditionsHandler = new GenericBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantValueBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n }\n // Initialize global residual vector\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.globalResidualVector[nodeIndex] = 0;\n }\n\n frontalState.totalNodes = meshData.nodesXCoordinates.length;\n frontalState.writeFlag = 0;\n frontalState.transformationFlag = 1;\n frontalState.determinant = 1;\n\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n frontalState.nodesPerElement[elementIndex] = FEAData.numNodes;\n }\n\n // Parameters for non-linear assemblers\n frontalState.currentSolutionVector = options.solutionVector;\n frontalState.eikonalActivationFlag = options.eikonalActivationFlag;\n\n // Pass assembleFront and dirichletBoundaryConditionsHandler to runFrontalAlgorithm\n runFrontalAlgorithm(meshData, FEAData, dirichletBoundaryConditionsHandler, assembleFront);\n\n // Copy solution\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.solutionVector[nodeIndex] = frontalState.globalSolutionVector[nodeIndex];\n }\n\n // Output results to console for debugging\n const { nodesXCoordinates, nodesYCoordinates } = meshData;\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n if (meshData.meshDimension === \"1D\") {\n // 1D case - only output X coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${frontalData.solutionVector[\n nodeIndex\n ].toExponential(5)}`\n );\n } else {\n // 2D case - output X, Y coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${nodesYCoordinates[nodeIndex].toExponential(\n 5\n )} ${frontalData.solutionVector[nodeIndex].toExponential(5)}`\n );\n }\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n const { nodesXCoordinates: finalNodesX, nodesYCoordinates: finalNodesY } = meshData;\n return {\n solutionVector: frontalData.solutionVector.slice(0, totalNodes),\n nodesCoordinates: {\n nodesXCoordinates: finalNodesX,\n nodesYCoordinates: finalNodesY,\n },\n };\n}\n\n/**\n * Function to initialize arrays dynamically based on problem size\n * @param {number} numNodes - Number of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n */\nfunction initializeFrontalArrays(numNodes, numElements) {\n // Use the actual number of elements from the mesh\n frontalData.nodalNumbering = Array(numElements)\n .fill()\n .map(() => Array(numNodes).fill(0));\n frontalData.nodeConstraintCode = Array(numNodes).fill(0);\n frontalData.boundaryValues = Array(numNodes).fill(0);\n frontalData.globalResidualVector = Array(numNodes).fill(0);\n frontalData.solutionVector = Array(numNodes).fill(0);\n frontalData.topologyData = Array(numElements).fill(0);\n frontalData.lateralData = Array(numElements).fill(0);\n\n // Initialize frontalState arrays\n frontalState.writeFlag = 0;\n frontalState.totalNodes = numNodes;\n frontalState.transformationFlag = 0;\n frontalState.nodesPerElement = Array(numElements).fill(0);\n frontalState.determinant = 1;\n\n // For matrix operations, estimate required size based on problem complexity\n const systemSize = Math.max(numNodes, 2000);\n frontalState.globalSolutionVector = Array(systemSize).fill(0);\n frontalState.frontDataIndex = 0;\n\n // Initialize elementData arrays\n elementData.localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n elementData.currentElementIndex = 0;\n\n // Initialize frontStorage arrays\n const frontSize = estimateFrontSize(numNodes, numElements);\n frontStorage.frontValues = Array(frontSize).fill(0);\n frontStorage.columnHeaders = Array(systemSize).fill(0);\n frontStorage.pivotRow = Array(systemSize).fill(0);\n frontStorage.pivotData = Array(frontSize).fill(0);\n}\n\n/**\n * Function to estimate the required front size\n * @param {number} numNodes - Number of of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n * @returns {number} Estimated front size\n */\nfunction estimateFrontSize(numNodes, numElements) {\n const frontWidthEstimate = Math.max(Math.ceil(Math.sqrt(numElements)) * numNodes, numNodes * 2);\n return frontWidthEstimate * numElements;\n}\n// Old function to estimate the required front size\n// function estimateFrontSize(numNodes, numElements, numNodes) {\n// const frontWidthEstimate = Math.ceil(Math.sqrt(numElements) * numNodes * 2);\n// const frontSize = frontWidthEstimate * numNodes * 4;\n// return Math.max(frontSize, 10000);\n// }\n\n/**\n * Function to compute local Jacobian matrix and local residual vector\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n const elementIndex = elementData.currentElementIndex - 1;\n\n // Guard against out-of-range indices\n if (elementIndex < 0 || elementIndex >= meshData.totalElements) {\n errorLog(`Skipping out-of-range elementIndex=${elementIndex} (totalElements=${meshData.totalElements})`);\n return false;\n }\n\n // Domain terms\n const { localJacobianMatrix, localResidualVector, ngl } = assembleFront({\n elementIndex,\n nop: frontalData.nodalNumbering,\n meshData,\n basisFunctions: basisFunctions,\n FEAData,\n // These are ignored by linear assemblers\n solutionVector: frontalState.currentSolutionVector,\n eikonalActivationFlag: frontalState.eikonalActivationFlag,\n });\n\n // Handle Robin-type boundary conditions differently based on which solver is being used\n let boundaryLocalJacobianMatrix = Array(FEAData.numNodes)\n .fill()\n .map(() => Array(FEAData.numNodes).fill(0));\n let boundaryResidualVector = Array(FEAData.numNodes).fill(0);\n\n // heatConductionScript solver\n if (assembleFront === assembleHeatConductionFront) {\n // Check if this element is on a Robin-type boundary\n let isOnRobinTypeBoundary = false;\n for (const boundaryKey in meshData.boundaryElements) {\n if (\n thermalBoundaryConditions.boundaryConditions[boundaryKey]?.[0] === \"convection\" &&\n meshData.boundaryElements[boundaryKey].some(([elemIdx, _]) => elemIdx === elementIndex)\n ) {\n isOnRobinTypeBoundary = true;\n break;\n }\n }\n\n // Only calculate Robin-type for elements when required\n if (isOnRobinTypeBoundary) {\n const { gaussPoints, gaussWeights } = FEAData;\n const result = thermalBoundaryConditions.imposeConvectionBoundaryConditionsFront(\n elementIndex,\n meshData.nodesXCoordinates,\n meshData.nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n );\n boundaryLocalJacobianMatrix = result.localJacobianMatrix;\n boundaryResidualVector = result.localResidualVector;\n }\n } else if (assembleFront === assembleFrontPropagationFront) {\n // For now, no Robin-type boundary conditions exist for any other solver\n }\n\n // Combine domain and boundary contributions\n for (let localNodeI = 0; localNodeI < FEAData.numNodes; localNodeI++) {\n for (let localNodeJ = 0; localNodeJ < FEAData.numNodes; localNodeJ++) {\n elementData.localJacobianMatrix[localNodeI][localNodeJ] =\n localJacobianMatrix[localNodeI][localNodeJ] + boundaryLocalJacobianMatrix[localNodeI][localNodeJ];\n }\n }\n\n // Assemble local element residual\n for (let localNodeIndex = 0; localNodeIndex < FEAData.numNodes; localNodeIndex++) {\n const globalNodeIndex = ngl[localNodeIndex] - 1;\n frontalData.globalResidualVector[globalNodeIndex] +=\n localResidualVector[localNodeIndex] + boundaryResidualVector[localNodeIndex];\n }\n\n return true;\n}\n\n/**\n * Function to implement the frontal solver algorithm\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction runFrontalAlgorithm(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n // Allocate local arrays dynamically\n const totalElements = meshData.totalElements;\n const numNodes = meshData.nodesXCoordinates.length;\n const systemSize = Math.max(numNodes, frontalState.globalSolutionVector.length);\n let localDestination = Array(FEAData.numNodes).fill(0);\n let rowDestination = Array(FEAData.numNodes).fill(0);\n let rowHeaders = Array(systemSize).fill(0);\n let pivotRowIndices = Array(systemSize).fill(0);\n let pivotColumnIndices = Array(systemSize).fill(0);\n let modifiedRows = Array(systemSize).fill(0);\n let pivotColumn = Array(systemSize).fill(0);\n let frontMatrix = Array(systemSize)\n .fill()\n .map(() => Array(systemSize).fill(0));\n let rowSwapCount = Array(numNodes).fill(0);\n let columnSwapCount = Array(numNodes).fill(0);\n let lastAppearanceCheck = Array(numNodes).fill(0);\n let pivotColumnGlobalIndex; // Pivot column global index\n\n let frontDataCounter = 1;\n frontalState.writeFlag++;\n let pivotDataIndex = 1;\n let summedRows = 1;\n elementData.currentElementIndex = 0;\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n rowSwapCount[nodeIndex] = 0;\n columnSwapCount[nodeIndex] = 0;\n }\n\n if (frontalState.transformationFlag !== 0) {\n // Prefront: find last appearance of each node\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n lastAppearanceCheck[nodeIndex] = 0;\n }\n\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n let reverseElementIndex = totalElements - elementIndex - 1;\n for (\n let localNodeIndex = 0;\n localNodeIndex < frontalState.nodesPerElement[reverseElementIndex];\n localNodeIndex++\n ) {\n let globalNodeIndex = frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n if (lastAppearanceCheck[globalNodeIndex - 1] === 0) {\n lastAppearanceCheck[globalNodeIndex - 1] = 1;\n frontalData.nodalNumbering[reverseElementIndex][localNodeIndex] =\n -frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n }\n }\n }\n }\n\n frontalState.transformationFlag = 0;\n let columnCount = 0;\n let rowCount = 0;\n\n for (let i = 0; i < systemSize; i++) {\n for (let j = 0; j < systemSize; j++) {\n frontMatrix[j][i] = 0;\n }\n }\n\n while (true) {\n // Assemble a new element only while we still have elements\n let assembled = false;\n let numElementNodes = 0;\n let numElementColumns = 0;\n\n if (elementData.currentElementIndex < totalElements) {\n elementData.currentElementIndex++;\n assembled = assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront);\n }\n\n if (assembled) {\n const currentElement = elementData.currentElementIndex;\n numElementNodes = frontalState.nodesPerElement[currentElement - 1];\n numElementColumns = frontalState.nodesPerElement[currentElement - 1];\n\n for (let localNodeIndex = 0; localNodeIndex < numElementColumns; localNodeIndex++) {\n let globalNodeIndex = frontalData.nodalNumbering[currentElement - 1][localNodeIndex];\n let columnIndex;\n\n if (columnCount === 0) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(frontStorage.columnHeaders[columnIndex])) break;\n }\n\n if (columnIndex === columnCount) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n localDestination[localNodeIndex] = columnIndex + 1;\n frontStorage.columnHeaders[columnIndex] = globalNodeIndex;\n }\n }\n\n let rowIndex;\n if (rowCount === 0) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(rowHeaders[rowIndex])) break;\n }\n\n if (rowIndex === rowCount) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n rowDestination[localNodeIndex] = rowIndex + 1;\n rowHeaders[rowIndex] = globalNodeIndex;\n }\n }\n }\n\n if (rowCount > systemSize || columnCount > systemSize) {\n errorLog(\"Error: systemSize not large enough\");\n return;\n }\n\n for (let localColumnIndex = 0; localColumnIndex < numElementColumns; localColumnIndex++) {\n let frontColumnIndex = localDestination[localColumnIndex];\n for (let localRowIndex = 0; localRowIndex < numElementNodes; localRowIndex++) {\n let frontRowIndex = rowDestination[localRowIndex];\n frontMatrix[frontRowIndex - 1][frontColumnIndex - 1] +=\n elementData.localJacobianMatrix[localRowIndex][localColumnIndex];\n }\n }\n }\n\n // Pivoting/elimination continues whether or not a new element was assembled\n let availableColumnCount = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (frontStorage.columnHeaders[columnIndex] < 0) {\n pivotColumnIndices[availableColumnCount] = columnIndex + 1;\n availableColumnCount++;\n }\n }\n\n let constrainedRowCount = 0;\n let availableRowCount = 0;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n let globalNodeIndex = rowHeaders[rowIndex];\n if (globalNodeIndex < 0) {\n pivotRowIndices[availableRowCount] = rowIndex + 1;\n availableRowCount++;\n let absoluteNodeIndex = Math.abs(globalNodeIndex);\n if (frontalData.nodeConstraintCode[absoluteNodeIndex - 1] === 1) {\n modifiedRows[constrainedRowCount] = rowIndex + 1;\n constrainedRowCount++;\n frontalData.nodeConstraintCode[absoluteNodeIndex - 1] = 2;\n frontalData.globalResidualVector[absoluteNodeIndex - 1] =\n frontalData.boundaryValues[absoluteNodeIndex - 1];\n }\n }\n }\n\n if (constrainedRowCount > 0) {\n for (let constrainedIndex = 0; constrainedIndex < constrainedRowCount; constrainedIndex++) {\n let rowIndex = modifiedRows[constrainedIndex] - 1;\n let globalNodeIndex = Math.abs(rowHeaders[rowIndex]);\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] = 0;\n let columnGlobalIndex = Math.abs(frontStorage.columnHeaders[columnIndex]);\n if (columnGlobalIndex === globalNodeIndex) frontMatrix[rowIndex][columnIndex] = 1;\n }\n }\n }\n\n if (availableColumnCount > summedRows || elementData.currentElementIndex < totalElements) {\n if (availableColumnCount === 0) {\n errorLog(\"Error: no more rows fully summed\");\n return;\n }\n\n let pivotRowIndex = pivotRowIndices[0];\n let pivotColumnIndex = pivotColumnIndices[0];\n let pivotValue = frontMatrix[pivotRowIndex - 1][pivotColumnIndex - 1];\n\n if (Math.abs(pivotValue) < 1e-4) {\n pivotValue = 0;\n for (let columnIndex = 0; columnIndex < availableColumnCount; columnIndex++) {\n let testColumnIndex = pivotColumnIndices[columnIndex];\n for (let rowIndex = 0; rowIndex < availableRowCount; rowIndex++) {\n let testRowIndex = pivotRowIndices[rowIndex];\n let testValue = frontMatrix[testRowIndex - 1][testColumnIndex - 1];\n if (Math.abs(testValue) > Math.abs(pivotValue)) {\n pivotValue = testValue;\n pivotColumnIndex = testColumnIndex;\n pivotRowIndex = testRowIndex;\n }\n }\n }\n }\n\n let pivotGlobalRowIndex = Math.abs(rowHeaders[pivotRowIndex - 1]);\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]); // Assign, don't declare\n let permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n if (nodeIndex >= pivotGlobalRowIndex) rowSwapCount[nodeIndex]--;\n if (nodeIndex >= pivotColumnGlobalIndex) columnSwapCount[nodeIndex]--;\n }\n\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontMatrix[pivotRowIndex - 1][columnIndex] / pivotValue;\n }\n\n let rightHandSide = frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] = rightHandSide;\n pivotColumn[pivotRowIndex - 1] = pivotValue;\n\n if (pivotRowIndex > 1) {\n for (let rowIndex = 0; rowIndex < pivotRowIndex - 1; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1 && eliminationFactor !== 0) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] -= eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n if (pivotRowIndex < rowCount) {\n for (let rowIndex = pivotRowIndex; rowIndex < rowCount; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = pivotColumn[i];\n }\n pivotDataIndex += rowCount;\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = rowHeaders[i];\n }\n pivotDataIndex += rowCount;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.pivotRow[i];\n }\n frontDataCounter += columnCount;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.columnHeaders[i];\n }\n frontDataCounter += columnCount;\n\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n frontMatrix[rowIndex][columnCount - 1] = 0;\n }\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowCount - 1][columnIndex] = 0;\n }\n\n columnCount--;\n if (pivotColumnIndex < columnCount + 1) {\n for (let columnIndex = pivotColumnIndex - 1; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] = frontStorage.columnHeaders[columnIndex + 1];\n }\n }\n\n rowCount--;\n if (pivotRowIndex < rowCount + 1) {\n for (let rowIndex = pivotRowIndex - 1; rowIndex < rowCount; rowIndex++) {\n rowHeaders[rowIndex] = rowHeaders[rowIndex + 1];\n }\n }\n\n if (rowCount > 1 || elementData.currentElementIndex < totalElements) continue;\n\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[0]); // Assign, don't declare\n pivotRowIndex = 1;\n pivotValue = frontMatrix[0][0];\n pivotGlobalRowIndex = Math.abs(rowHeaders[0]);\n pivotColumnIndex = 1;\n permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n frontStorage.pivotRow[0] = 1;\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] =\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.pivotRow[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.columnHeaders[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotColumn[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = rowHeaders[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n frontalState.frontDataIndex = frontDataCounter;\n if (frontalState.writeFlag === 1)\n debugLog(`total ecs transfer in matrix reduction=${frontDataCounter}`);\n\n // Back substitution\n performBackSubstitution(frontDataCounter);\n break;\n }\n }\n}\n\n/**\n * Function to perform back substitution for the frontal solver\n * @param {number} frontDataCounter - Index counter for the element contributions\n */\nfunction performBackSubstitution(frontDataCounter) {\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n frontalState.globalSolutionVector[nodeIndex] = frontalData.boundaryValues[nodeIndex];\n }\n\n for (let iterationIndex = 1; iterationIndex <= frontalState.totalNodes; iterationIndex++) {\n frontDataCounter -= 4;\n let pivotGlobalRowIndex = frontStorage.frontValues[frontDataCounter - 1];\n let columnCount = frontStorage.frontValues[frontDataCounter];\n let pivotColumnIndex = frontStorage.frontValues[frontDataCounter + 1];\n let pivotValue = frontStorage.frontValues[frontDataCounter + 2];\n\n if (iterationIndex === 1) {\n frontDataCounter--;\n frontStorage.columnHeaders[0] = frontStorage.frontValues[frontDataCounter - 1];\n frontDataCounter--;\n frontStorage.pivotRow[0] = frontStorage.frontValues[frontDataCounter - 1];\n } else {\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] =\n frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n }\n\n let pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]);\n if (frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] > 0) continue;\n\n let accumulatedValue = 0;\n frontStorage.pivotRow[pivotColumnIndex - 1] = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n accumulatedValue -=\n frontStorage.pivotRow[columnIndex] *\n frontalState.globalSolutionVector[Math.abs(frontStorage.columnHeaders[columnIndex]) - 1];\n }\n\n frontalState.globalSolutionVector[pivotColumnGlobalIndex - 1] =\n accumulatedValue + frontalData.globalResidualVector[pivotGlobalRowIndex - 1];\n\n frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] = 1;\n }\n\n if (frontalState.writeFlag === 1)\n debugLog(`value of frontDataCounter after backsubstitution=${frontDataCounter}`);\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { euclideanNorm } from \"../methods/euclideanNormScript.js\";\nimport { solveLinearSystem } from \"./linearSystemSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport { runFrontalSolver } from \"./frontalSolverScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\n\n/**\n * Function to solve a system of non-linear equations using the Newton-Raphson method\n * @param {function} assembleMat - Matrix assembler based on the physical model\n * @param {object} context - Context object containing simulation data and options\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\n\nexport function newtonRaphson(assembleMat, context = {}) {\n let errorNorm = 0;\n let converged = false;\n let iterations = 0;\n let deltaX = [];\n let solutionVector = [];\n let jacobianMatrix = [];\n let residualVector = [];\n\n // Extract context\n const { maxIterations = 100, tolerance = 1e-4 } = context;\n\n // Calculate system size\n let totalNodes = context.meshData.nodesXCoordinates.length;\n\n // Initialize arrays with proper size\n for (let i = 0; i < totalNodes; i++) {\n deltaX[i] = 0;\n solutionVector[i] = 0;\n }\n\n // Initialize solution from context if available\n if (context.initialSolution && context.initialSolution.length === totalNodes) {\n solutionVector = [...context.initialSolution];\n }\n\n while (iterations < maxIterations && !converged) {\n // Update solution\n for (let i = 0; i < solutionVector.length; i++) {\n solutionVector[i] = Number(solutionVector[i]) + Number(deltaX[i]);\n }\n\n // Check if using frontal solver\n if (context.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleFrontPropagationFront,\n context.meshData,\n context.boundaryConditions,\n { solutionVector, eikonalActivationFlag: context.eikonalActivationFlag }\n );\n deltaX = frontalResult.solutionVector;\n } else {\n // Compute Jacobian and residual matrices\n ({ jacobianMatrix, residualVector } = assembleMat(\n context.meshData,\n context.boundaryConditions,\n solutionVector, // The solution vector is required in the case of a non-linear equation\n context.eikonalActivationFlag // Currently used only in the front propagation solver (TODO refactor in case of a solver not needing it)\n ));\n\n // Solve the linear system based on the specified solver method\n const linearSystemResult = solveLinearSystem(context.solverMethod, jacobianMatrix, residualVector);\n deltaX = linearSystemResult.solutionVector;\n }\n\n // Check convergence\n errorNorm = euclideanNorm(deltaX);\n\n // Norm for each iteration\n basicLog(`Newton-Raphson iteration ${iterations + 1}: Error norm = ${errorNorm.toExponential(4)}`);\n\n if (errorNorm <= tolerance) {\n converged = true;\n } else if (errorNorm > 1e2) {\n errorLog(`Solution not converged. Error norm: ${errorNorm}`);\n break;\n }\n\n iterations++;\n }\n\n return {\n solutionVector,\n converged,\n iterations,\n jacobianMatrix,\n residualVector,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { newtonRaphson } from \"./methods/newtonRaphsonScript.js\";\nimport { solveLinearSystem } from \"./methods/linearSystemSolverScript.js\";\nimport { solveLinearSystemAsync } from \"./methods/linearSystemSolverScript.js\";\nimport { prepareMesh } from \"./mesh/meshUtilsScript.js\";\nimport { assembleFrontPropagationMat } from \"./models/frontPropagationScript.js\";\nimport { assembleGeneralFormPDEMat, assembleGeneralFormPDEFront } from \"./models/generalFormPDEScript.js\";\nimport { assembleHeatConductionMat, assembleHeatConductionFront } from \"./models/heatConductionScript.js\";\nimport { runFrontalSolver } from \"./methods/frontalSolverScript.js\";\nimport { basicLog, debugLog, warnLog, errorLog } from \"./utilities/loggingScript.js\";\n\n/**\n * Class to implement finite element analysis in JavaScript\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} meshConfig - Object containing computational mesh details\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containifng the solution vector and additional mesh information\n */\nexport class FEAScriptModel {\n constructor() {\n this.solverConfig = null;\n this.meshConfig = {};\n this.boundaryConditions = {};\n this.solverMethod = \"lusolve\"; // Default solver method\n this.coefficientFunctions = null; // Add storage for coefficient functions\n warnLog(\n \"FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE\"\n );\n basicLog(\"FEAScriptModel instance created\");\n }\n\n /**\n * Sets the solver configuration\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} [options] - Optional additional configuration\n */\n setSolverConfig(solverConfig, options = {}) {\n this.solverConfig = solverConfig;\n\n // Store coefficient functions if provided\n if (options?.coefficientFunctions) {\n this.coefficientFunctions = options.coefficientFunctions;\n debugLog(\"Coefficient functions set\");\n }\n // Only update if a value is provided, otherwise keep the default\n if (options?.maxIterations !== undefined) {\n this.maxIterations = options.maxIterations;\n }\n if (options?.tolerance !== undefined) {\n this.tolerance = options.tolerance;\n }\n\n debugLog(`Solver config set to: ${solverConfig}`);\n }\n\n setMeshConfig(meshConfig) {\n this.meshConfig = meshConfig;\n debugLog(`Mesh config set with dimensions: ${meshConfig.meshDimension}`);\n }\n\n addBoundaryCondition(boundaryKey, condition) {\n this.boundaryConditions[boundaryKey] = condition;\n debugLog(`Boundary condition added for boundary: ${boundaryKey}, type: ${condition[0]}`);\n }\n\n setSolverMethod(solverMethod) {\n this.solverMethod = solverMethod;\n debugLog(`Solver method set to: ${solverMethod}`);\n }\n\n /**\n * Function to solve the finite element problem synchronously\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing the solution vector and the coordinates of the mesh nodes\n */\n solve(options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n /**\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n let initialSolution = [];\n\n // Prepare the mesh\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n\n // Extract node coordinates from meshData\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n // Select and execute the appropriate solver based on solverConfig\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleHeatConductionFront,\n meshData,\n this.boundaryConditions\n );\n solutionVector = frontalResult.solutionVector;\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n } else if (this.solverConfig === \"frontPropagationScript\") {\n // Initialize eikonalActivationFlag\n let eikonalActivationFlag = 0;\n const eikonalExteralIterations = 5; // Number of incremental steps for the eikonal equation\n\n // Create context object with all necessary properties\n const context = {\n meshData: meshData,\n boundaryConditions: this.boundaryConditions,\n eikonalActivationFlag: eikonalActivationFlag,\n solverMethod: this.solverMethod,\n initialSolution,\n // TODO: Consider using different maxIterations/tolerance for Newton-Raphson and linear solver\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n };\n\n while (eikonalActivationFlag <= 1) {\n // Update the context object with current eikonalActivationFlag\n context.eikonalActivationFlag = eikonalActivationFlag;\n\n // Pass the previous solution as initial guess\n if (solutionVector.length > 0) {\n context.initialSolution = [...solutionVector];\n }\n\n // Solve the assembled non-linear system\n const newtonRaphsonResult = newtonRaphson(assembleFrontPropagationMat, context);\n\n // Extract results\n jacobianMatrix = newtonRaphsonResult.jacobianMatrix;\n residualVector = newtonRaphsonResult.residualVector;\n solutionVector = newtonRaphsonResult.solutionVector;\n\n // Increment for next iteration\n eikonalActivationFlag += 1 / eikonalExteralIterations;\n }\n } else if (this.solverConfig === \"generalFormPDEScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n errorLog(\n \"Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.\"\n );\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(\n meshData,\n this.boundaryConditions,\n this.coefficientFunctions\n ));\n\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n /**\n * Function to solve the finite element problem asynchronously\n * @param {object} computeEngine - The compute engine to use for the asynchronous solver (e.g., a worker or a WebGPU context)\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing the solution vector and the coordinates of the mesh nodes\n */\n async solveAsync(computeEngine, options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n\n if (this.solverMethod === \"jacobi-gpu\") {\n const { solutionVector: x } = await solveLinearSystemAsync(\"jacobi-gpu\", jacobianMatrix, residualVector, {\n computeEngine,\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = x;\n } else {\n // Other async solver\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { initializeFEA, performIsoparametricMapping1D } from \"../mesh/meshUtilsScript.js\";\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the general form PDE model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} coefficientFunctions - Functions A(x), B(x), C(x), D(x) for the PDE\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleGeneralFormPDEMat(meshData, boundaryConditions, coefficientFunctions) {\n basicLog(\"Starting general form PDE matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Extract coefficient functions\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Convert to 0-based indexing\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];\n\n // Source term contribution to residual vector\n residualVector[globalNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n const globalNodeIndex2 = localToGlobalMap[localNodeIndex2];\n\n // Diffusion term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEMat.\");\n // 2D general form PDE - empty for now\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Apply Dirichlet boundary conditions only\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n\n basicLog(\"General form PDE matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the frontal solver matrix for the general form PDE model\n * @param {object} data - Object containing element data for the frontal solver\n * @returns {object} An object containing local Jacobian matrix and residual vector\n */\nexport function assembleGeneralFormPDEFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n coefficientFunctions,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of local Jacobian matrix and residual vector\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n // Source term contribution to local residual vector\n localResidualVector[localNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Diffusion term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEFront.\");\n // 2D general form PDE - empty for now\n }\n\n return {\n localJacobianMatrix,\n localResidualVector,\n ngl,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements\n * @param {File} file - The Gmsh file to be parsed (.msh version 4.1)\n * @returns {object} The parsed mesh data including node coordinates, element connectivity, and boundary conditions\n */\nconst importGmshQuadTri = async (file) => {\n let result = {\n nodesXCoordinates: [],\n nodesYCoordinates: [],\n nodalNumbering: {\n quadElements: [],\n triangleElements: [],\n },\n boundaryElements: [],\n boundaryConditions: [],\n boundaryNodePairs: {}, // Store boundary node pairs for processing in meshGenerationScript\n gmshV: 0,\n ascii: false,\n fltBytes: \"8\",\n totalNodesX: 0,\n totalNodesY: 0,\n physicalPropMap: [],\n elementTypes: {},\n };\n\n let content = await file.text();\n let lines = content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line !== \"\" && line !== \" \");\n\n let section = \"\";\n let lineIndex = 0;\n\n let nodeEntityBlocks = 0;\n let totalNodes = 0;\n let nodeBlocksProcessed = 0;\n let currentNodeBlock = { numNodes: 0 };\n let nodeTagsCollected = 0;\n let nodeTags = [];\n let nodeCoordinatesCollected = 0;\n\n let elementEntityBlocks = 0;\n let totalElements = 0;\n let elementBlocksProcessed = 0;\n let currentElementBlock = {\n dim: 0,\n tag: 0,\n elementType: 0,\n numElements: 0,\n };\n let elementsProcessedInBlock = 0;\n\n let boundaryElementsByTag = {};\n\n while (lineIndex < lines.length) {\n const line = lines[lineIndex];\n\n if (line === \"$MeshFormat\") {\n section = \"meshFormat\";\n lineIndex++;\n continue;\n } else if (line === \"$EndMeshFormat\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$PhysicalNames\") {\n section = \"physicalNames\";\n lineIndex++;\n continue;\n } else if (line === \"$EndPhysicalNames\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Entities\") {\n section = \"entities\";\n lineIndex++;\n continue;\n } else if (line === \"$EndEntities\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Nodes\") {\n section = \"nodes\";\n lineIndex++;\n continue;\n } else if (line === \"$EndNodes\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Elements\") {\n section = \"elements\";\n lineIndex++;\n continue;\n } else if (line === \"$EndElements\") {\n section = \"\";\n lineIndex++;\n continue;\n }\n\n const parts = line.split(/\\s+/).filter((part) => part !== \"\");\n\n if (section === \"meshFormat\") {\n result.gmshV = parseFloat(parts[0]);\n result.ascii = parts[1] === \"0\";\n result.fltBytes = parts[2];\n } else if (section === \"physicalNames\") {\n if (parts.length >= 3) {\n if (!/^\\d+$/.test(parts[0])) {\n lineIndex++;\n continue;\n }\n\n const dimension = parseInt(parts[0], 10);\n const tag = parseInt(parts[1], 10);\n let name = parts.slice(2).join(\" \");\n name = name.replace(/^\"|\"$/g, \"\");\n\n result.physicalPropMap.push({\n tag,\n dimension,\n name,\n });\n }\n } else if (section === \"nodes\") {\n if (nodeEntityBlocks === 0) {\n nodeEntityBlocks = parseInt(parts[0], 10);\n totalNodes = parseInt(parts[1], 10);\n result.nodesXCoordinates = new Array(totalNodes).fill(0);\n result.nodesYCoordinates = new Array(totalNodes).fill(0);\n lineIndex++;\n continue;\n }\n\n if (nodeBlocksProcessed < nodeEntityBlocks && currentNodeBlock.numNodes === 0) {\n currentNodeBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n parametric: parseInt(parts[2], 10),\n numNodes: parseInt(parts[3], 10),\n };\n\n nodeTags = [];\n nodeTagsCollected = 0;\n nodeCoordinatesCollected = 0;\n\n lineIndex++;\n continue;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n for (let i = 0; i < parts.length && nodeTagsCollected < currentNodeBlock.numNodes; i++) {\n nodeTags.push(parseInt(parts[i], 10));\n nodeTagsCollected++;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n lineIndex++;\n continue;\n }\n\n lineIndex++;\n continue;\n }\n\n if (nodeCoordinatesCollected < currentNodeBlock.numNodes) {\n const nodeTag = nodeTags[nodeCoordinatesCollected] - 1;\n const x = parseFloat(parts[0]);\n const y = parseFloat(parts[1]);\n\n result.nodesXCoordinates[nodeTag] = x;\n result.nodesYCoordinates[nodeTag] = y;\n result.totalNodesX++;\n result.totalNodesY++;\n\n nodeCoordinatesCollected++;\n\n if (nodeCoordinatesCollected === currentNodeBlock.numNodes) {\n nodeBlocksProcessed++;\n currentNodeBlock = { numNodes: 0 };\n }\n }\n } else if (section === \"elements\") {\n if (elementEntityBlocks === 0) {\n elementEntityBlocks = parseInt(parts[0], 10);\n totalElements = parseInt(parts[1], 10);\n lineIndex++;\n continue;\n }\n\n if (elementBlocksProcessed < elementEntityBlocks && currentElementBlock.numElements === 0) {\n currentElementBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n elementType: parseInt(parts[2], 10),\n numElements: parseInt(parts[3], 10),\n };\n\n result.elementTypes[currentElementBlock.elementType] =\n (result.elementTypes[currentElementBlock.elementType] || 0) + currentElementBlock.numElements;\n\n elementsProcessedInBlock = 0;\n lineIndex++;\n continue;\n }\n\n if (elementsProcessedInBlock < currentElementBlock.numElements) {\n const elementTag = parseInt(parts[0], 10);\n const nodeIndices = parts.slice(1).map((idx) => parseInt(idx, 10));\n\n if (currentElementBlock.elementType === 1 || currentElementBlock.elementType === 8) {\n const physicalTag = currentElementBlock.tag;\n\n if (!boundaryElementsByTag[physicalTag]) {\n boundaryElementsByTag[physicalTag] = [];\n }\n\n boundaryElementsByTag[physicalTag].push(nodeIndices);\n\n // Store boundary node pairs for later processing in meshGenerationScript\n if (!result.boundaryNodePairs[physicalTag]) {\n result.boundaryNodePairs[physicalTag] = [];\n }\n result.boundaryNodePairs[physicalTag].push(nodeIndices);\n } else if (currentElementBlock.elementType === 2) {\n // Linear triangle elements (3 nodes)\n result.nodalNumbering.triangleElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 3) {\n // Linear quadrilateral elements (4 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 10) {\n // Quadratic quadrilateral elements (9 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n }\n\n elementsProcessedInBlock++;\n\n if (elementsProcessedInBlock === currentElementBlock.numElements) {\n elementBlocksProcessed++;\n currentElementBlock = { numElements: 0 };\n }\n }\n }\n\n lineIndex++;\n }\n\n // Store boundary conditions information\n result.physicalPropMap.forEach((prop) => {\n if (prop.dimension === 1) {\n const boundaryNodes = boundaryElementsByTag[prop.tag] || [];\n\n if (boundaryNodes.length > 0) {\n result.boundaryConditions.push({\n name: prop.name,\n tag: prop.tag,\n nodes: boundaryNodes,\n });\n }\n }\n });\n\n debugLog(\n `Parsed boundary node pairs by physical tag: ${JSON.stringify(\n result.boundaryNodePairs\n )}. These pairs will be used to identify boundary elements in the mesh.`\n );\n\n return result;\n};\n\nexport { importGmshQuadTri };\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to create plots of the solution vector\n * @param {*} solutionVector - The computed solution vector\n * @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {string} meshDimension - The dimension of the solution\n * @param {string} plotType - The type of plot\n * @param {string} plotDivId - The id of the div where the plot will be rendered\n */\nexport function plotSolution(\n solutionVector,\n nodesCoordinates,\n solverConfig,\n meshDimension,\n plotType,\n plotDivId\n) {\n const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;\n\n if (meshDimension === \"1D\" && plotType === \"line\") {\n // Check if solutionVector is a nested array\n let yData;\n if (solutionVector.length > 0 && Array.isArray(solutionVector[0])) {\n yData = solutionVector.map((arr) => arr[0]);\n } else {\n yData = solutionVector;\n }\n let xData = Array.from(nodesXCoordinates);\n\n let lineData = {\n x: nodesXCoordinates,\n y: yData,\n mode: \"lines\",\n type: \"scatter\",\n line: { color: \"rgb(219, 64, 82)\", width: 2 },\n name: \"Solution\",\n };\n\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = 350;\n\n let layout = {\n title: `line plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"Solution\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n };\n\n Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });\n } else if (meshDimension === \"2D\" && plotType === \"contour\") {\n // Check if solutionVector is a nested array\n let zData;\n if (Array.isArray(solutionVector[0])) {\n zData = solutionVector.map((val) => val[0]);\n } else {\n zData = solutionVector;\n }\n\n // Sizing parameters\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxX = Math.max(...nodesXCoordinates);\n let maxY = Math.max(...nodesYCoordinates);\n let aspectRatio = maxY / maxX;\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = plotWidth * aspectRatio;\n\n // Layout properties\n let layout = {\n title: `${plotType} plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"y\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n hovermode: \"closest\",\n };\n\n // Create the plot\n let contourData = {\n x: nodesXCoordinates,\n y: nodesYCoordinates,\n z: zData,\n type: \"contour\",\n line: {\n smoothing: 0.85,\n },\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n name: \"Solution Field\",\n };\n\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// External imports\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n// Internal imports\nimport { basicLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to facilitate communication with web workers for FEAScript operations\n */\nexport class FEAScriptWorker {\n /**\n * Constructor to initialize the FEAScriptWorker class\n * Sets up the worker and initializes the workerWrapper.\n */\n constructor() {\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n\n this._initWorker();\n }\n\n /**\n * Function to initialize the web worker and wrap it using Comlink.\n * @private\n * @throws Will throw an error if the worker fails to initialize.\n */\n async _initWorker() {\n try {\n this.worker = new Worker(new URL(\"./wrapperScript.js\", import.meta.url), {\n type: \"module\",\n });\n\n this.worker.onerror = (event) => {\n console.error(\"FEAScriptWorker: Worker error:\", event);\n };\n const workerWrapper = Comlink.wrap(this.worker);\n\n this.feaWorker = await new workerWrapper();\n\n this.isReady = true;\n } catch (error) {\n console.error(\"Failed to initialize worker\", error);\n throw error;\n }\n }\n\n /**\n * Function to ensure that the worker is ready before performing any operations.\n * @private\n * @returns {Promise} Resolves when the worker is ready.\n * @throws Will throw an error if the worker is not ready within the timeout period.\n */\n async _ensureReady() {\n if (this.isReady) return Promise.resolve();\n\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds max\n\n const checkReady = () => {\n attempts++;\n if (this.isReady) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(\"Timeout waiting for worker to be ready\"));\n } else {\n setTimeout(checkReady, 1000);\n }\n };\n checkReady();\n });\n }\n\n /**\n * Function to set the solver configuration in the worker.\n * @param {string} solverConfig - The solver configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setSolverConfig(solverConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver config to: ${solverConfig}`);\n return this.feaWorker.setSolverConfig(solverConfig);\n }\n\n /**\n * Sets the mesh configuration in the worker.\n * @param {object} meshConfig - The mesh configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setMeshConfig(meshConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting mesh config`);\n return this.feaWorker.setMeshConfig(meshConfig);\n }\n\n /**\n * Adds a boundary condition to the worker.\n * @param {string} boundaryKey - The key identifying the boundary.\n * @param {array} condition - The boundary condition to add.\n * @returns {Promise} Resolves when the boundary condition is added.\n */\n async addBoundaryCondition(boundaryKey, condition) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Adding boundary condition for boundary: ${boundaryKey}`);\n return this.feaWorker.addBoundaryCondition(boundaryKey, condition);\n }\n\n /**\n * Sets the solver method in the worker.\n * @param {string} solverMethod - The solver method to set.\n * @returns {Promise} Resolves when the solver method is set.\n */\n async setSolverMethod(solverMethod) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver method to: ${solverMethod}`);\n return this.feaWorker.setSolverMethod(solverMethod);\n }\n\n /**\n * Requests the worker to solve the problem.\n * @returns {Promise} Resolves with the solution result.\n */\n async solve() {\n await this._ensureReady();\n basicLog(\"FEAScriptWorker: Requesting solution from worker...\");\n\n const startTime = performance.now();\n const result = await this.feaWorker.solve();\n const endTime = performance.now();\n\n basicLog(`FEAScriptWorker: Solution completed in ${((endTime - startTime) / 1000).toFixed(2)}s`);\n return result;\n }\n\n /**\n * Retrieves model information from the worker.\n * @returns {Promise} Resolves with the model information.\n */\n async getModelInfo() {\n await this._ensureReady();\n return this.feaWorker.getModelInfo();\n }\n\n /**\n * Sends a ping request to the worker to check its availability.\n * @returns {Promise} Resolves if the worker responds.\n */\n async ping() {\n await this._ensureReady();\n return this.feaWorker.ping();\n }\n\n /**\n * Terminates the worker and cleans up resources.\n */\n terminate() {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nexport { FEAScriptModel } from \"./FEAScript.js\";\nexport { importGmshQuadTri } from \"./readers/gmshReaderScript.js\";\nexport { logSystem } from \"./utilities/loggingScript.js\";\nexport { plotSolution } from \"./visualization/plotSolutionScript.js\";\nexport { FEAScriptWorker } from \"./workers/workerScript.js\";\nexport const printVersion = \"0.1.4\";"],"names":["euclideanNorm","vector","norm","i","length","Math","sqrt","currentLogLevel","logSystem","level","console","log","basicLog","debugLog","message","errorLog","proxyMarker","Symbol","createEndpoint","releaseProxy","finalizer","throwMarker","isObject","val","transferHandlers","Map","canHandle","serialize","obj","port1","port2","MessageChannel","expose","deserialize","port","start","wrap","value","serialized","Error","isError","name","stack","Object","assign","ep","globalThis","allowedOrigins","addEventListener","callback","ev","data","origin","allowedOrigin","RegExp","test","isAllowedOrigin","warn","id","type","path","argumentList","map","fromWireValue","returnValue","parent","slice","reduce","prop","rawValue","apply","proxy","transfers","transferCache","set","transfer","undefined","Promise","resolve","catch","then","wireValue","transferables","toWireValue","postMessage","removeEventListener","closeEndPoint","error","TypeError","endpoint","constructor","isMessagePort","close","target","pendingListeners","resolver","get","delete","createProxy","throwIfProxyReleased","isReleased","releaseEndpoint","requestResponseMessage","proxyCounter","WeakMap","proxyFinalizers","FinalizationRegistry","newCount","isProxyReleased","Proxy","_target","unregister","unregisterProxy","clear","r","p","toString","bind","_thisArg","rawArgumentList","last","processArguments","construct","register","registerProxy","processed","v","arr","Array","prototype","concat","handler","serializedValue","msg","fill","floor","random","Number","MAX_SAFE_INTEGER","join","solveLinearSystem","solverMethod","jacobianMatrix","residualVector","options","maxIterations","tolerance","solutionVector","converged","iterations","time","jacobianMatrixSparse","math","sparse","luFactorization","slu","solutionMatrix","lusolve","squeeze","valueOf","jacobiSolverResult","A","b","x0","n","x","xNew","iter","sum","j","maxDiff","max","abs","jacobiSolver","timeEnd","async","solveLinearSystemAsync","isArray","toArray","created","computeEngine","worker","Worker","URL","url","Comlink.wrap","initialize","createDefaultComputeEngine","result","webgpuJacobiSolver","destroy","terminate","BasisFunctions","meshDimension","elementOrder","this","getBasisFunctions","ksi","eta","basisFunction","basisFunctionDerivKsi","basisFunctionDerivEta","l1","c","l2","l3","dl1","dl2","dl3","Mesh","numElementsX","maxX","numElementsY","maxY","parsedMesh","boundaryElementsProcessed","parseMeshFromGmsh","nodalNumbering","quadElements","triangleElements","JSON","stringify","elementTypes","mappedNodalNumbering","elemIdx","gmshNodes","feaScriptNodes","push","physicalPropMap","boundaryElements","fixedBoundaryElements","boundaryNodePairs","forEach","dimension","tag","nodesPair","node1","node2","foundElement","elemNodes","includes","side","node1Index","indexOf","node2Index","Mesh1D","super","generateMesh","nodesXCoordinates","totalNodesX","deltaX","nodeIndex","generate1DNodalNumbering","findBoundaryElements","nop","elementIndex","columnCounter","sideIndex","Mesh2D","nodesYCoordinates","totalNodesY","deltaY","nodeIndexY","nodeIndexX","nnode","generate2DNodalNumbering","rowCounter","elementIndexX","elementIndexY","nodeIndex1","nodeIndex2","NumericalIntegration","getGaussPointsAndWeights","gaussPoints","gaussWeights","prepareMesh","meshConfig","mesh","nodesCoordinatesAndNumbering","totalElements","totalNodes","initializeFEA","meshData","colIndex","basisFunctions","gaussPointsAndWeights","localToGlobalMap","numNodes","performIsoparametricMapping1D","params","xCoordinates","ksiDerivX","localNodeIndex","detJacobian","basisFunctionDerivX","performIsoparametricMapping2D","yCoordinates","etaDerivX","ksiDerivY","etaDerivY","basisFunctionDerivY","ThermalBoundaryConditions","boundaryConditions","imposeConstantTempBoundaryConditions","keys","boundaryKey","tempValue","globalNodeIndex","imposeConstantTempBoundaryConditionsFront","nodeConstraintCode","boundaryValues","imposeConvectionBoundaryConditions","convectionHeatTranfCoeff","convectionExtTemp","key","boundaryCondition","convectionCoeff","extTemp","gaussPoint1","gaussPoint2","firstNodeIndex","lastNodeIndex","nodeIncrement","basisFunctionsAndDerivatives","tangentVectorLength","localNodeIndex2","globalNodeIndex2","gaussPointIndex","imposeConvectionBoundaryConditionsFront","localJacobianMatrix","localResidualVector","boundaryElement","find","_","assembleHeatConductionMat","FEAData","gaussPointIndex1","mappingResult","localNodeIndex1","localToGlobalMap1","localToGlobalMap2","gaussPointIndex2","thermalBoundaryConditions","assembleHeatConductionFront","ngl","globalIndex","GenericBoundaryConditions","imposeDirichletBoundaryConditions","imposeConstantValueBoundaryConditionsFront","assembleFrontPropagationMat","eikonalActivationFlag","eikonalViscousTerm","solutionDerivX","solutionDerivY","assembleFrontPropagationFront","frontalData","frontalState","elementData","currentElementIndex","frontStorage","runFrontalSolver","assembleFront","numElements","globalResidualVector","topologyData","lateralData","writeFlag","transformationFlag","nodesPerElement","determinant","systemSize","globalSolutionVector","frontDataIndex","frontSize","frontWidthEstimate","ceil","estimateFrontSize","frontValues","columnHeaders","pivotRow","pivotData","initializeFrontalArrays","dirichletBoundaryConditionsHandler","currentSolutionVector","pivotColumnGlobalIndex","localDestination","rowDestination","rowHeaders","pivotRowIndices","pivotColumnIndices","modifiedRows","pivotColumn","frontMatrix","rowSwapCount","columnSwapCount","lastAppearanceCheck","frontDataCounter","pivotDataIndex","summedRows","reverseElementIndex","columnCount","rowCount","assembled","numElementNodes","numElementColumns","assembleElementContribution","currentElement","columnIndex","rowIndex","localColumnIndex","frontColumnIndex","localRowIndex","availableColumnCount","constrainedRowCount","availableRowCount","absoluteNodeIndex","constrainedIndex","pivotRowIndex","pivotColumnIndex","pivotValue","testColumnIndex","testRowIndex","testValue","pivotGlobalRowIndex","permutationHelper","rightHandSide","globalRowIndex","eliminationFactor","performBackSubstitution","runFrontalAlgorithm","toExponential","finalNodesX","finalNodesY","nodesCoordinates","boundaryLocalJacobianMatrix","boundaryResidualVector","isOnRobinTypeBoundary","some","localNodeI","localNodeJ","iterationIndex","accumulatedValue","newtonRaphson","assembleMat","context","errorNorm","initialSolution","FEAScriptModel","solverConfig","coefficientFunctions","setSolverConfig","setMeshConfig","addBoundaryCondition","condition","setSolverMethod","solve","eikonalExteralIterations","newtonRaphsonResult","B","C","D","xCoord","a","d","globalNodeIndex1","assembleGeneralFormPDEMat","solveAsync","importGmshQuadTri","file","gmshV","ascii","fltBytes","lines","text","split","line","trim","filter","section","lineIndex","nodeEntityBlocks","nodeBlocksProcessed","currentNodeBlock","nodeTagsCollected","nodeTags","nodeCoordinatesCollected","elementEntityBlocks","elementBlocksProcessed","currentElementBlock","dim","elementType","elementsProcessedInBlock","boundaryElementsByTag","parts","part","parseFloat","parseInt","replace","parametric","nodeTag","y","nodeIndices","idx","physicalTag","boundaryNodes","nodes","plotSolution","plotType","plotDivId","yData","from","lineData","mode","color","width","maxWindowWidth","min","window","innerWidth","layout","title","height","xaxis","yaxis","margin","l","t","Plotly","newPlot","responsive","zData","aspectRatio","plotWidth","hovermode","contourData","z","smoothing","contours","coloring","showlabels","colorbar","FEAScriptWorker","feaWorker","isReady","_initWorker","onerror","event","workerWrapper","_ensureReady","reject","attempts","checkReady","setTimeout","startTime","performance","now","toFixed","getModelInfo","ping","printVersion"],"mappings":"AAaO,SAASA,EAAcC,GAC5B,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,OAAQD,IACjCD,GAAQD,EAAOE,GAAKF,EAAOE,GAG7B,OADAD,EAAOG,KAAKC,KAAKJ,GACVA,CACT,CCXA,IAAIK,EAAkB,QAMf,SAASC,EAAUC,GACV,UAAVA,GAA+B,UAAVA,GACvBC,QAAQC,IACN,+BAAiCF,EAAQ,yBACzC,sCAEFF,EAAkB,UAElBA,EAAkBE,EAClBG,EAAS,qBAAqBH,KAElC,CAMO,SAASI,EAASC,GACC,UAApBP,GACF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ist/feascript.umd.js index f9281d1..8edc4f6 100644 --- a/dist/feascript.umd.js +++ b/dist/feascript.umd.js @@ -4,5 +4,5 @@ function _loadWasmModule(e,t,n){for(var o=t.length,s="="==t[o-2]?2:"="==t[o-1]?1 * Copyright 2019 Google LLC * SPDX-License-Identifier: Apache-2.0 */ -const r=Symbol("Comlink.proxy"),a=Symbol("Comlink.endpoint"),l=Symbol("Comlink.releaseProxy"),d=Symbol("Comlink.finalizer"),c=Symbol("Comlink.thrown"),u=e=>"object"==typeof e&&null!==e||"function"==typeof e,m=new Map([["proxy",{canHandle:e=>u(e)&&e[r],serialize(e){const{port1:t,port2:n}=new MessageChannel;return h(e,t),[n,[n]]},deserialize:e=>(e.start(),p(e))}],["throw",{canHandle:e=>u(e)&&c in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function h(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(s){if(!s||!s.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,s.origin))return void console.warn(`Invalid origin '${s.origin}' for comlink proxy`);const{id:i,type:a,path:l}=Object.assign({path:[]},s.data),u=(s.data.argumentList||[]).map(F);let m;try{const t=l.slice(0,-1).reduce(((e,t)=>e[t]),e),n=l.reduce(((e,t)=>e[t]),e);switch(a){case"GET":m=n;break;case"SET":t[l.slice(-1)[0]]=F(s.data.value),m=!0;break;case"APPLY":m=n.apply(t,u);break;case"CONSTRUCT":m=function(e){return Object.assign(e,{[r]:!0})}(new n(...u));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;h(e,n),m=function(e,t){return M.set(e,t),e}(t,[t])}break;case"RELEASE":m=void 0;break;default:return}}catch(e){m={value:e,[c]:0}}Promise.resolve(m).catch((e=>({value:e,[c]:0}))).then((n=>{const[s,r]=$(n);t.postMessage(Object.assign(Object.assign({},s),{id:i}),r),"RELEASE"===a&&(t.removeEventListener("message",o),f(t),d in e&&"function"==typeof e[d]&&e[d]())})).catch((e=>{const[n,o]=$({value:new TypeError("Unserializable return value"),[c]:0});t.postMessage(Object.assign(Object.assign({},n),{id:i}),o)}))})),t.start&&t.start()}function f(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function p(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),v(e,n,[],t)}function b(e){if(e)throw new Error("Proxy has been released and is not useable")}function y(e){return D(e,new Map,{type:"RELEASE"}).then((()=>{f(e)}))}const g=new WeakMap,E="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(g.get(e)||0)-1;g.set(e,t),0===t&&y(e)}));function v(e,t,n=[],o=function(){}){let s=!1;const i=new Proxy(o,{get(o,r){if(b(s),r===l)return()=>{!function(e){E&&E.unregister(e)}(i),y(e),t.clear(),s=!0};if("then"===r){if(0===n.length)return{then:()=>i};const o=D(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then(F);return o.then.bind(o)}return v(e,t,[...n,r])},set(o,i,r){b(s);const[a,l]=$(r);return D(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:a},l).then(F)},apply(o,i,r){b(s);const l=n[n.length-1];if(l===a)return D(e,t,{type:"ENDPOINT"}).then(F);if("bind"===l)return v(e,t,n.slice(0,-1));const[d,c]=C(r);return D(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:d},c).then(F)},construct(o,i){b(s);const[r,a]=C(i);return D(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},a).then(F)}});return function(e,t){const n=(g.get(t)||0)+1;g.set(t,n),E&&E.register(e,t,e)}(i,e),i}function C(e){const t=e.map($);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const M=new WeakMap;function $(e){for(const[t,n]of m)if(n.canHandle(e)){const[o,s]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},s]}return[{type:"RAW",value:e},M.get(e)||[]]}function F(e){switch(e.type){case"HANDLER":return m.get(e.name).deserialize(e.value);case"RAW":return e.value}}function D(e,t,n,o){return new Promise((s=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,s),e.start&&e.start(),e.postMessage(Object.assign({id:i},n),o)}))}function A(e,t,n,r={}){const{maxIterations:a=1e4,tolerance:l=1e-4}=r;let d=[],c=!0,u=0;if(s(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),o=math.slu(e,1,1);let s=math.lusolve(o,n);d=math.squeeze(s).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:s,tolerance:i}=o,r=e.length;let a=[...n],l=new Array(r);for(let n=0;n{}))),m.worker.terminate()),{solutionVector:f,converged:b,iterations:u}}class w{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null){let n=[],o=[],s=[];if("1D"===this.meshDimension)"linear"===this.elementOrder?(n[0]=1-e,n[1]=e,o[0]=-1,o[1]=1):"quadratic"===this.elementOrder&&(n[0]=1-3*e+2*e**2,n[1]=4*e-4*e**2,n[2]=2*e**2-e,o[0]=4*e-3,o[1]=4-8*e,o[2]=4*e-1);else if("2D"===this.meshDimension){if(null===t)return void i("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function r(e){return 1-e}n[0]=r(e)*r(t),n[1]=r(e)*t,n[2]=e*r(t),n[3]=e*t,o[0]=-1*r(t),o[1]=-1*t,o[2]=1*r(t),o[3]=1*t,s[0]=-1*r(e),s[1]=1*r(e),s[2]=-1*e,s[3]=1*e}else if("quadratic"===this.elementOrder){function a(e){return 2*e**2-3*e+1}function l(e){return-4*e**2+4*e}function d(e){return 2*e**2-e}function c(e){return 4*e-3}function u(e){return-8*e+4}function m(e){return 4*e-1}n[0]=a(e)*a(t),n[1]=a(e)*l(t),n[2]=a(e)*d(t),n[3]=l(e)*a(t),n[4]=l(e)*l(t),n[5]=l(e)*d(t),n[6]=d(e)*a(t),n[7]=d(e)*l(t),n[8]=d(e)*d(t),o[0]=c(e)*a(t),o[1]=c(e)*l(t),o[2]=c(e)*d(t),o[3]=u(e)*a(t),o[4]=u(e)*l(t),o[5]=u(e)*d(t),o[6]=m(e)*a(t),o[7]=m(e)*l(t),o[8]=m(e)*d(t),s[0]=a(e)*c(t),s[1]=a(e)*u(t),s[2]=a(e)*m(t),s[3]=l(e)*c(t),s[4]=l(e)*u(t),s[5]=l(e)*m(t),s[6]=d(e)*c(t),s[7]=d(e)*u(t),s[8]=d(e)*m(t)}}return{basisFunction:n,basisFunctionDerivKsi:o,basisFunctionDerivEta:s}}}class N{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:o=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:a=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=o,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=a,this.boundaryElementsProcessed=!1,this.parsedMesh&&(s("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||i("No valid nodal numbering found in the parsed mesh."),"object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,o("Initial parsed mesh nodal numbering from GMSH format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.elementTypes[3]||this.parsedMesh.elementTypes[10]){const t=[];for(let n=0;n0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t{if(1===e.dimension){const t=this.parsedMesh.boundaryNodePairs[e.tag]||[];t.length>0&&(this.parsedMesh.boundaryElements[e.tag]||(this.parsedMesh.boundaryElements[e.tag]=[]),t.forEach((t=>{const n=t[0],s=t[1];o(`Processing boundary node pair: [${n}, ${s}] for boundary ${e.tag} (${e.name||"unnamed"})`);let r=!1;for(let t=0;t0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}imposeConvectionBoundaryConditions(e,t,n,s,i,r,a){let l=[],d=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(l[e]=t[1],d[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("convection"===this.boundaryConditions[n][0]){const s=l[n],i=d[n];o(`Boundary ${n}: Applying convection with heat transfer coefficient h=${s} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[n].forEach((([n,r])=>{let a;"linear"===this.elementOrder?a=0===r?0:1:"quadratic"===this.elementOrder&&(a=0===r?0:2);const l=this.nop[n][a]-1;o(` - Applied convection boundary condition to node ${l+1} (element ${n+1}, local node ${a+1})`),e[l]+=-s*i,t[l][l]+=s}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const u=l[c],m=d[c];o(`Boundary ${c}: Applying convection with heat transfer coefficient h=${u} W/(m²·K) and external temperature T∞=${m} K`),this.boundaryElements[c].forEach((([l,d])=>{if("linear"===this.elementOrder){let c,h,f,p,b;0===d?(c=n[0],h=0,f=0,p=3,b=2):1===d?(c=0,h=n[0],f=0,p=2,b=1):2===d?(c=n[0],h=1,f=1,p=4,b=2):3===d&&(c=1,h=n[0],f=2,p=4,b=1);let y=a.getBasisFunctions(c,h),g=y.basisFunction,E=y.basisFunctionDerivKsi,v=y.basisFunctionDerivEta,C=0,M=0,$=0,F=0;const D=this.nop[l].length;for(let e=0;e{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])}));const d=this.nop[e].length,c=Array(d).fill().map((()=>Array(d).fill(0))),u=Array(d).fill(0);for(const m in this.boundaryElements)if("convection"===this.boundaryConditions[m]?.[0]){const h=a[m],f=l[m];o(`Boundary ${m}: Applying convection with heat transfer coefficient h=${h} W/(m²·K) and external temperature T∞=${f} K`);const p=this.boundaryElements[m].find((([t,n])=>t===e));if(p){const a=p[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===a?0:1:"quadratic"===this.elementOrder&&(t=0===a?0:2),o(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),u[t]+=-h*f,c[t][t]+=h}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let o,l,m,p,b;0===a?(o=s[0],l=0,m=0,p=3,b=2):1===a?(o=0,l=s[0],m=0,p=2,b=1):2===a?(o=s[0],l=1,m=1,p=4,b=2):3===a&&(o=1,l=s[0],m=2,p=4,b=1);const y=r.getBasisFunctions(o,l),g=y.basisFunction,E=y.basisFunctionDerivKsi,v=y.basisFunctionDerivEta;let C,M=0,$=0,F=0,D=0;for(let o=0;oArray(a).fill(0))),m=Array(a).fill(0),h=Array(a),f=Array(a);for(let n=0;ne-1)),{detJacobian:f,basisFunctionDerivX:p,basisFunctionDerivY:b}=I({basisFunction:n,basisFunctionDerivKsi:s,basisFunctionDerivEta:c,nodesXCoordinates:l,nodesYCoordinates:d,localToGlobalMap:m,numNodes:a});for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}}function W(e,t,n,i){s("Starting front propagation matrix assembly...");let r=1-i+.01;o(`eikonalViscousTerm: ${r}`),o(`eikonalActivationFlag: ${i}`);const{nodesXCoordinates:a,nodesYCoordinates:l,nop:d,boundaryElements:c,totalElements:u,meshDimension:m,elementOrder:h}=e,f=T(e),{residualVector:p,jacobianMatrix:b,localToGlobalMap:y,basisFunctions:g,gaussPoints:E,gaussWeights:v,numNodes:C}=f;for(let e=0;eArray(d).fill(0))),p=Array(d).fill(0),b=Array(d),y=Array(d);for(let n=0;nArray(e).fill(0))),q.nodeConstraintCode=Array(e).fill(0),q.boundaryValues=Array(e).fill(0),q.globalResidualVector=Array(e).fill(0),q.solutionVector=Array(e).fill(0),q.topologyData=Array(t).fill(0),q.lateralData=Array(t).fill(0),G.writeFlag=0,G.totalNodes=e,G.transformationFlag=0,G.nodesPerElement=Array(t).fill(0),G.determinant=1;const n=Math.max(e,2e3);G.globalSolutionVector=Array(n).fill(0),G.frontDataIndex=0,K.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),K.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);J.frontValues=Array(o).fill(0),J.columnHeaders=Array(n).fill(0),J.pivotRow=Array(n).fill(0),J.pivotData=Array(o).fill(0)}(a.numNodes,d),s("Solving system using frontal..."),console.time("systemSolving"),H=new w({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;eArray(l).fill(0))),g=Array(a).fill(0),E=Array(a).fill(0),v=Array(a).fill(0),C=1;G.writeFlag++;let M=1,$=1;K.currentElementIndex=0;for(let e=0;el||F>l)return void i("Error: systemSize not large enough");for(let e=0;e0)for(let e=0;e$||K.currentElementIndexMath.abs(n)&&(n=r,t=s,e=i)}}}let s=Math.abs(m[e-1]);d=Math.abs(J.columnHeaders[t-1]);let a=s+d+g[s-1]+E[d-1];G.determinant=G.determinant*n*(-1)**a/Math.abs(n);for(let e=0;e=s&&g[e]--,e>=d&&E[e]--;if(Math.abs(n)<1e-10&&i(`Matrix singular or ill-conditioned, currentElementIndex=${K.currentElementIndex}, pivotGlobalRowIndex=${s}, pivotColumnGlobalIndex=${d}, pivotValue=${n}`),0===n)return;for(let t=0;t1)for(let n=0;n1&&0!==o)for(let e=0;e1)for(let e=0;e1||K.currentElementIndex=e.totalElements)return i(`Skipping out-of-range elementIndex=${s} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:a,ngl:l}=o({elementIndex:s,nop:q.nodalNumbering,meshData:e,basisFunctions:H,FEAData:t,solutionVector:G.currentSolutionVector,eikonalActivationFlag:G.eikonalActivationFlag});let d=Array(t.numNodes).fill().map((()=>Array(t.numNodes).fill(0))),c=Array(t.numNodes).fill(0);if(o===Y){let o=!1;for(const t in e.boundaryElements)if("convection"===n.boundaryConditions[t]?.[0]&&e.boundaryElements[t].some((([e,t])=>e===s))){o=!0;break}if(o){const{gaussPoints:o,gaussWeights:i}=t,r=n.imposeConvectionBoundaryConditionsFront(s,e.nodesXCoordinates,e.nodesYCoordinates,o,i,H);d=r.localJacobianMatrix,c=r.localResidualVector}}for(let e=0;e0)continue;let r=0;J.pivotRow[s-1]=0;for(let e=0;e100){i(`Solution not converged. Error norm: ${o}`);break}a++}return{solutionVector:d,converged:r,iterations:a,jacobianMatrix:c,residualVector:u}}e.FEAScriptModel=class{constructor(){var e;this.solverConfig=null,this.meshConfig={},this.boundaryConditions={},this.solverMethod="lusolve",this.coefficientFunctions=null,e="FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE",console.log("%c[WARN] "+e,"color: #FF9800; font-weight: bold;"),s("FEAScriptModel instance created")}setSolverConfig(e,t={}){this.solverConfig=e,t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,o("Coefficient functions set")),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations),void 0!==t?.tolerance&&(this.tolerance=t.tolerance),o(`Solver config set to: ${e}`)}setMeshConfig(e){this.meshConfig=e,o(`Mesh config set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,o(`Boundary condition added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,o(`Solver method set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||i("Solver config, mesh config, and boundary conditions must be set before solving.");let t=[],n=[],o=[],r=[];s("Preparing mesh...");const a=V(this.meshConfig);s("Mesh preparation completed");const l={nodesXCoordinates:a.nodesXCoordinates,nodesYCoordinates:a.nodesYCoordinates};if(s("Beginning solving process..."),console.time("totalSolvingTime"),s(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){o=L(Y,a,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=P(a,this.boundaryConditions));o=A(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let s=0;const i=5,l={meshData:a,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:s,solverMethod:this.solverMethod,initialSolution:r,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;s<=1;){l.eikonalActivationFlag=s,o.length>0&&(l.initialSolution=[...o]);const e=_(W,l);t=e.jacobianMatrix,n=e.residualVector,o=e.solutionVector,s+=1/i}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)i("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){s("Starting general form PDE matrix assembly...");const{nodesXCoordinates:o,nodesYCoordinates:r,nop:a,boundaryElements:l,totalElements:d,meshDimension:c,elementOrder:u}=e,{A:m,B:h,C:f,D:p}=n,b=T(e),{residualVector:y,jacobianMatrix:g,localToGlobalMap:E,basisFunctions:v,gaussPoints:C,gaussWeights:M,numNodes:$}=b;if("1D"===c)for(let e=0;e{console.error("FEAScriptWorker: Worker error:",e)};const e=p(this.worker);this.feaWorker=await new e,this.isReady=!0}catch(e){throw console.error("Failed to initialize worker",e),e}}async _ensureReady(){return this.isReady?Promise.resolve():new Promise(((e,t)=>{let n=0;const o=()=>{n++,this.isReady?e():n>=50?t(new Error("Timeout waiting for worker to be ready")):setTimeout(o,1e3)};o()}))}async setSolverConfig(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver config to: ${e}`),this.feaWorker.setSolverConfig(e)}async setMeshConfig(e){return await this._ensureReady(),s("FEAScriptWorker: Setting mesh config"),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),s(`FEAScriptWorker: Adding boundary condition for boundary: ${e}`),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver method to: ${e}`),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),s("FEAScriptWorker: Requesting solution from worker...");const e=performance.now(),t=await this.feaWorker.solve();return s(`FEAScriptWorker: Solution completed in ${((performance.now()-e)/1e3).toFixed(2)}s`),t}async getModelInfo(){return await this._ensureReady(),this.feaWorker.getModelInfo()}async ping(){return await this._ensureReady(),this.feaWorker.ping()}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.feaWorker=null,this.isReady=!1)}},e.importGmshQuadTri=async e=>{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}},n=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e&&" "!==e)),s="",i=0,r=0,a=0,l=0,d={numNodes:0},c=0,u=[],m=0,h=0,f=0,p={dim:0,tag:0,elementType:0,numElements:0},b=0,y={};for(;i""!==e));if("meshFormat"===s)t.gmshV=parseFloat(o[0]),t.ascii="0"===o[1],t.fltBytes=o[2];else if("physicalNames"===s){if(o.length>=3){if(!/^\d+$/.test(o[0])){i++;continue}const e=parseInt(o[0],10),n=parseInt(o[1],10);let s=o.slice(2).join(" ");s=s.replace(/^"|"$/g,""),t.physicalPropMap.push({tag:n,dimension:e,name:s})}}else if("nodes"===s){if(0===r){r=parseInt(o[0],10),a=parseInt(o[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0),i++;continue}if(lparseInt(e,10)));if(1===p.elementType||8===p.elementType){const n=p.tag;y[n]||(y[n]=[]),y[n].push(e),t.boundaryNodePairs[n]||(t.boundaryNodePairs[n]=[]),t.boundaryNodePairs[n].push(e)}else 2===p.elementType?t.nodalNumbering.triangleElements.push(e):(3===p.elementType||10===p.elementType)&&t.nodalNumbering.quadElements.push(e);b++,b===p.numElements&&(f++,p={numElements:0})}}i++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=y[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),o(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}. These pairs will be used to identify boundary elements in the mesh.`),t},e.logSystem=function(e){"basic"!==e&&"debug"!==e?(console.log("%c[WARN] Invalid log level: "+e+". Using basic instead.","color: #FFC107; font-weight: bold;"),n="basic"):(n=e,s(`Log level set to: ${e}`))},e.plotSolution=function(e,t,n,o,s,i,r="structured"){const{nodesXCoordinates:a,nodesYCoordinates:l}=t;if("1D"===o&&"line"===s){let t;t=e.length>0&&Array.isArray(e[0])?e.map((e=>e[0])):e;let o=Array.from(a),s={x:o,y:t,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},r=Math.min(window.innerWidth,700),l=Math.max(...o),d=r/l,c={title:`line plot - ${n}`,width:Math.max(d*l,400),height:350,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:70,r:40,t:50,b:50}};Plotly.newPlot(i,[s],c,{responsive:!0})}else if("2D"===o&&"contour"===s){const t="structured"===r,o=new Set(a).size,d=new Set(l).size;let c;c=Array.isArray(e[0])?e.map((e=>e[0])):e;let u=Math.min(window.innerWidth,700),m=Math.max(...a),h=Math.max(...l)/m,f=Math.min(u,600),p={title:`${s} plot - ${n}`,width:f,height:f*h*.8,xaxis:{title:"x"},yaxis:{title:"y"},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"};if(t){const t=o,n=d;math.reshape(Array.from(a),[t,n]);let s=math.reshape(Array.from(l),[t,n]),r=math.reshape(Array.from(e),[t,n]),c=math.transpose(r),u=[];for(let e=0;e"object"==typeof e&&null!==e||"function"==typeof e,m=new Map([["proxy",{canHandle:e=>u(e)&&e[r],serialize(e){const{port1:t,port2:n}=new MessageChannel;return h(e,t),[n,[n]]},deserialize:e=>(e.start(),p(e))}],["throw",{canHandle:e=>u(e)&&c in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function h(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(s){if(!s||!s.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,s.origin))return void console.warn(`Invalid origin '${s.origin}' for comlink proxy`);const{id:i,type:a,path:l}=Object.assign({path:[]},s.data),u=(s.data.argumentList||[]).map(D);let m;try{const t=l.slice(0,-1).reduce(((e,t)=>e[t]),e),n=l.reduce(((e,t)=>e[t]),e);switch(a){case"GET":m=n;break;case"SET":t[l.slice(-1)[0]]=D(s.data.value),m=!0;break;case"APPLY":m=n.apply(t,u);break;case"CONSTRUCT":m=function(e){return Object.assign(e,{[r]:!0})}(new n(...u));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;h(e,n),m=function(e,t){return M.set(e,t),e}(t,[t])}break;case"RELEASE":m=void 0;break;default:return}}catch(e){m={value:e,[c]:0}}Promise.resolve(m).catch((e=>({value:e,[c]:0}))).then((n=>{const[s,r]=$(n);t.postMessage(Object.assign(Object.assign({},s),{id:i}),r),"RELEASE"===a&&(t.removeEventListener("message",o),f(t),d in e&&"function"==typeof e[d]&&e[d]())})).catch((e=>{const[n,o]=$({value:new TypeError("Unserializable return value"),[c]:0});t.postMessage(Object.assign(Object.assign({},n),{id:i}),o)}))})),t.start&&t.start()}function f(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function p(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),v(e,n,[],t)}function b(e){if(e)throw new Error("Proxy has been released and is not useable")}function g(e){return F(e,new Map,{type:"RELEASE"}).then((()=>{f(e)}))}const y=new WeakMap,E="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(y.get(e)||0)-1;y.set(e,t),0===t&&g(e)}));function v(e,t,n=[],o=function(){}){let s=!1;const i=new Proxy(o,{get(o,r){if(b(s),r===l)return()=>{!function(e){E&&E.unregister(e)}(i),g(e),t.clear(),s=!0};if("then"===r){if(0===n.length)return{then:()=>i};const o=F(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then(D);return o.then.bind(o)}return v(e,t,[...n,r])},set(o,i,r){b(s);const[a,l]=$(r);return F(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:a},l).then(D)},apply(o,i,r){b(s);const l=n[n.length-1];if(l===a)return F(e,t,{type:"ENDPOINT"}).then(D);if("bind"===l)return v(e,t,n.slice(0,-1));const[d,c]=C(r);return F(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:d},c).then(D)},construct(o,i){b(s);const[r,a]=C(i);return F(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},a).then(D)}});return function(e,t){const n=(y.get(t)||0)+1;y.set(t,n),E&&E.register(e,t,e)}(i,e),i}function C(e){const t=e.map($);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const M=new WeakMap;function $(e){for(const[t,n]of m)if(n.canHandle(e)){const[o,s]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},s]}return[{type:"RAW",value:e},M.get(e)||[]]}function D(e){switch(e.type){case"HANDLER":return m.get(e.name).deserialize(e.value);case"RAW":return e.value}}function F(e,t,n,o){return new Promise((s=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,s),e.start&&e.start(),e.postMessage(Object.assign({id:i},n),o)}))}function A(e,t,n,r={}){const{maxIterations:a=1e4,tolerance:l=1e-4}=r;let d=[],c=!0,u=0;if(s(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),o=math.slu(e,1,1);let s=math.lusolve(o,n);d=math.squeeze(s).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:s,tolerance:i}=o,r=e.length;let a=[...n],l=new Array(r);for(let n=0;n{}))),m.worker.terminate()),{solutionVector:f,converged:b,iterations:u}}class w{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null){let n=[],o=[],s=[];if("1D"===this.meshDimension)"linear"===this.elementOrder?(n[0]=1-e,n[1]=e,o[0]=-1,o[1]=1):"quadratic"===this.elementOrder&&(n[0]=1-3*e+2*e**2,n[1]=4*e-4*e**2,n[2]=2*e**2-e,o[0]=4*e-3,o[1]=4-8*e,o[2]=4*e-1);else if("2D"===this.meshDimension){if(null===t)return void i("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function r(e){return 1-e}n[0]=r(e)*r(t),n[1]=r(e)*t,n[2]=e*r(t),n[3]=e*t,o[0]=-1*r(t),o[1]=-1*t,o[2]=1*r(t),o[3]=1*t,s[0]=-1*r(e),s[1]=1*r(e),s[2]=-1*e,s[3]=1*e}else if("quadratic"===this.elementOrder){function a(e){return 2*e**2-3*e+1}function l(e){return-4*e**2+4*e}function d(e){return 2*e**2-e}function c(e){return 4*e-3}function u(e){return-8*e+4}function m(e){return 4*e-1}n[0]=a(e)*a(t),n[1]=a(e)*l(t),n[2]=a(e)*d(t),n[3]=l(e)*a(t),n[4]=l(e)*l(t),n[5]=l(e)*d(t),n[6]=d(e)*a(t),n[7]=d(e)*l(t),n[8]=d(e)*d(t),o[0]=c(e)*a(t),o[1]=c(e)*l(t),o[2]=c(e)*d(t),o[3]=u(e)*a(t),o[4]=u(e)*l(t),o[5]=u(e)*d(t),o[6]=m(e)*a(t),o[7]=m(e)*l(t),o[8]=m(e)*d(t),s[0]=a(e)*c(t),s[1]=a(e)*u(t),s[2]=a(e)*m(t),s[3]=l(e)*c(t),s[4]=l(e)*u(t),s[5]=l(e)*m(t),s[6]=d(e)*c(t),s[7]=d(e)*u(t),s[8]=d(e)*m(t)}}return{basisFunction:n,basisFunctionDerivKsi:o,basisFunctionDerivEta:s}}}class N{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:o=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:a=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=o,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=a,this.boundaryElementsProcessed=!1,this.parsedMesh&&(s("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||i("No valid nodal numbering found in the parsed mesh."),"object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,o("Initial parsed mesh nodal numbering from GMSH format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.elementTypes[3]||this.parsedMesh.elementTypes[10]){const t=[];for(let n=0;n0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t{if(1===e.dimension){const t=this.parsedMesh.boundaryNodePairs[e.tag]||[];t.length>0&&(this.parsedMesh.boundaryElements[e.tag]||(this.parsedMesh.boundaryElements[e.tag]=[]),t.forEach((t=>{const n=t[0],s=t[1];o(`Processing boundary node pair: [${n}, ${s}] for boundary ${e.tag} (${e.name||"unnamed"})`);let r=!1;for(let t=0;t0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant temperature of ${s} K (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}imposeConvectionBoundaryConditions(e,t,n,s,i,r,a){let l=[],d=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(l[e]=t[1],d[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("convection"===this.boundaryConditions[n][0]){const s=l[n],i=d[n];o(`Boundary ${n}: Applying convection with heat transfer coefficient h=${s} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[n].forEach((([n,r])=>{let a;"linear"===this.elementOrder?a=0===r?0:1:"quadratic"===this.elementOrder&&(a=0===r?0:2);const l=this.nop[n][a]-1;o(` - Applied convection boundary condition to node ${l+1} (element ${n+1}, local node ${a+1})`),e[l]+=-s*i,t[l][l]+=s}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const u=l[c],m=d[c];o(`Boundary ${c}: Applying convection with heat transfer coefficient h=${u} W/(m²·K) and external temperature T∞=${m} K`),this.boundaryElements[c].forEach((([l,d])=>{if("linear"===this.elementOrder){let c,h,f,p,b;0===d?(c=n[0],h=0,f=0,p=3,b=2):1===d?(c=0,h=n[0],f=0,p=2,b=1):2===d?(c=n[0],h=1,f=1,p=4,b=2):3===d&&(c=1,h=n[0],f=2,p=4,b=1);let g=a.getBasisFunctions(c,h),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta,C=0,M=0,$=0,D=0;const F=this.nop[l].length;for(let e=0;e{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])}));const d=this.nop[e].length,c=Array(d).fill().map((()=>Array(d).fill(0))),u=Array(d).fill(0);for(const m in this.boundaryElements)if("convection"===this.boundaryConditions[m]?.[0]){const h=a[m],f=l[m];o(`Boundary ${m}: Applying convection with heat transfer coefficient h=${h} W/(m²·K) and external temperature T∞=${f} K`);const p=this.boundaryElements[m].find((([t,n])=>t===e));if(p){const a=p[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===a?0:1:"quadratic"===this.elementOrder&&(t=0===a?0:2),o(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),u[t]+=-h*f,c[t][t]+=h}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let o,l,m,p,b;0===a?(o=s[0],l=0,m=0,p=3,b=2):1===a?(o=0,l=s[0],m=0,p=2,b=1):2===a?(o=s[0],l=1,m=1,p=4,b=2):3===a&&(o=1,l=s[0],m=2,p=4,b=1);const g=r.getBasisFunctions(o,l),y=g.basisFunction,E=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta;let C,M=0,$=0,D=0,F=0;for(let o=0;oArray(a).fill(0))),m=Array(a).fill(0),h=Array(a),f=Array(a);for(let n=0;ne-1)),{detJacobian:f,basisFunctionDerivX:p,basisFunctionDerivY:b}=I({basisFunction:n,basisFunctionDerivKsi:s,basisFunctionDerivEta:c,nodesXCoordinates:l,nodesYCoordinates:d,localToGlobalMap:m,numNodes:a});for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=s;for(let n=0;n{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantValue"===this.boundaryConditions[n][0]){const s=this.boundaryConditions[n][1];o(`Boundary ${n}: Applying constant value of ${s} (Dirichlet condition)`),this.boundaryElements[n].forEach((([n,i])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[i].forEach((i=>{const r=this.nop[n][i]-1;o(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=s}))}}))}}))}}function W(e,t,n,i){s("Starting front propagation matrix assembly...");let r=1-i+.01;o(`eikonalViscousTerm: ${r}`),o(`eikonalActivationFlag: ${i}`);const{nodesXCoordinates:a,nodesYCoordinates:l,nop:d,boundaryElements:c,totalElements:u,meshDimension:m,elementOrder:h}=e,f=T(e),{residualVector:p,jacobianMatrix:b,localToGlobalMap:g,basisFunctions:y,gaussPoints:E,gaussWeights:v,numNodes:C}=f;for(let e=0;eArray(d).fill(0))),p=Array(d).fill(0),b=Array(d),g=Array(d);for(let n=0;nArray(e).fill(0))),q.nodeConstraintCode=Array(e).fill(0),q.boundaryValues=Array(e).fill(0),q.globalResidualVector=Array(e).fill(0),q.solutionVector=Array(e).fill(0),q.topologyData=Array(t).fill(0),q.lateralData=Array(t).fill(0),G.writeFlag=0,G.totalNodes=e,G.transformationFlag=0,G.nodesPerElement=Array(t).fill(0),G.determinant=1;const n=Math.max(e,2e3);G.globalSolutionVector=Array(n).fill(0),G.frontDataIndex=0,K.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),K.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);J.frontValues=Array(o).fill(0),J.columnHeaders=Array(n).fill(0),J.pivotRow=Array(n).fill(0),J.pivotData=Array(o).fill(0)}(a.numNodes,d),s("Solving system using frontal..."),console.time("systemSolving"),H=new w({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;eArray(l).fill(0))),y=Array(a).fill(0),E=Array(a).fill(0),v=Array(a).fill(0),C=1;G.writeFlag++;let M=1,$=1;K.currentElementIndex=0;for(let e=0;el||D>l)return void i("Error: systemSize not large enough");for(let e=0;e0)for(let e=0;e$||K.currentElementIndexMath.abs(n)&&(n=r,t=s,e=i)}}}let s=Math.abs(m[e-1]);d=Math.abs(J.columnHeaders[t-1]);let a=s+d+y[s-1]+E[d-1];G.determinant=G.determinant*n*(-1)**a/Math.abs(n);for(let e=0;e=s&&y[e]--,e>=d&&E[e]--;if(Math.abs(n)<1e-10&&i(`Matrix singular or ill-conditioned, currentElementIndex=${K.currentElementIndex}, pivotGlobalRowIndex=${s}, pivotColumnGlobalIndex=${d}, pivotValue=${n}`),0===n)return;for(let t=0;t1)for(let n=0;n1&&0!==o)for(let e=0;e1)for(let e=0;e1||K.currentElementIndex=e.totalElements)return i(`Skipping out-of-range elementIndex=${s} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:a,ngl:l}=o({elementIndex:s,nop:q.nodalNumbering,meshData:e,basisFunctions:H,FEAData:t,solutionVector:G.currentSolutionVector,eikonalActivationFlag:G.eikonalActivationFlag});let d=Array(t.numNodes).fill().map((()=>Array(t.numNodes).fill(0))),c=Array(t.numNodes).fill(0);if(o===Y){let o=!1;for(const t in e.boundaryElements)if("convection"===n.boundaryConditions[t]?.[0]&&e.boundaryElements[t].some((([e,t])=>e===s))){o=!0;break}if(o){const{gaussPoints:o,gaussWeights:i}=t,r=n.imposeConvectionBoundaryConditionsFront(s,e.nodesXCoordinates,e.nodesYCoordinates,o,i,H);d=r.localJacobianMatrix,c=r.localResidualVector}}for(let e=0;e0)continue;let r=0;J.pivotRow[s-1]=0;for(let e=0;e100){i(`Solution not converged. Error norm: ${o}`);break}a++}return{solutionVector:d,converged:r,iterations:a,jacobianMatrix:c,residualVector:u}}e.FEAScriptModel=class{constructor(){var e;this.solverConfig=null,this.meshConfig={},this.boundaryConditions={},this.solverMethod="lusolve",this.coefficientFunctions=null,e="FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE",console.log("%c[WARN] "+e,"color: #FF9800; font-weight: bold;"),s("FEAScriptModel instance created")}setSolverConfig(e,t={}){this.solverConfig=e,t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,o("Coefficient functions set")),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations),void 0!==t?.tolerance&&(this.tolerance=t.tolerance),o(`Solver config set to: ${e}`)}setMeshConfig(e){this.meshConfig=e,o(`Mesh config set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,o(`Boundary condition added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,o(`Solver method set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||i("Solver config, mesh config, and boundary conditions must be set before solving.");let t=[],n=[],o=[],r=[];s("Preparing mesh...");const a=V(this.meshConfig);s("Mesh preparation completed");const l={nodesXCoordinates:a.nodesXCoordinates,nodesYCoordinates:a.nodesYCoordinates};if(s("Beginning solving process..."),console.time("totalSolvingTime"),s(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){o=L(Y,a,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=P(a,this.boundaryConditions));o=A(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let s=0;const i=5,l={meshData:a,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:s,solverMethod:this.solverMethod,initialSolution:r,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;s<=1;){l.eikonalActivationFlag=s,o.length>0&&(l.initialSolution=[...o]);const e=z(W,l);t=e.jacobianMatrix,n=e.residualVector,o=e.solutionVector,s+=1/i}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)i("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){s("Starting general form PDE matrix assembly...");const{nodesXCoordinates:o,nodesYCoordinates:r,nop:a,boundaryElements:l,totalElements:d,meshDimension:c,elementOrder:u}=e,{A:m,B:h,C:f,D:p}=n,b=T(e),{residualVector:g,jacobianMatrix:y,localToGlobalMap:E,basisFunctions:v,gaussPoints:C,gaussWeights:M,numNodes:$}=b;if("1D"===c)for(let e=0;e{console.error("FEAScriptWorker: Worker error:",e)};const e=p(this.worker);this.feaWorker=await new e,this.isReady=!0}catch(e){throw console.error("Failed to initialize worker",e),e}}async _ensureReady(){return this.isReady?Promise.resolve():new Promise(((e,t)=>{let n=0;const o=()=>{n++,this.isReady?e():n>=50?t(new Error("Timeout waiting for worker to be ready")):setTimeout(o,1e3)};o()}))}async setSolverConfig(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver config to: ${e}`),this.feaWorker.setSolverConfig(e)}async setMeshConfig(e){return await this._ensureReady(),s("FEAScriptWorker: Setting mesh config"),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),s(`FEAScriptWorker: Adding boundary condition for boundary: ${e}`),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),s(`FEAScriptWorker: Setting solver method to: ${e}`),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),s("FEAScriptWorker: Requesting solution from worker...");const e=performance.now(),t=await this.feaWorker.solve();return s(`FEAScriptWorker: Solution completed in ${((performance.now()-e)/1e3).toFixed(2)}s`),t}async getModelInfo(){return await this._ensureReady(),this.feaWorker.getModelInfo()}async ping(){return await this._ensureReady(),this.feaWorker.ping()}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.feaWorker=null,this.isReady=!1)}},e.importGmshQuadTri=async e=>{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}},n=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e&&" "!==e)),s="",i=0,r=0,a=0,l=0,d={numNodes:0},c=0,u=[],m=0,h=0,f=0,p={dim:0,tag:0,elementType:0,numElements:0},b=0,g={};for(;i""!==e));if("meshFormat"===s)t.gmshV=parseFloat(o[0]),t.ascii="0"===o[1],t.fltBytes=o[2];else if("physicalNames"===s){if(o.length>=3){if(!/^\d+$/.test(o[0])){i++;continue}const e=parseInt(o[0],10),n=parseInt(o[1],10);let s=o.slice(2).join(" ");s=s.replace(/^"|"$/g,""),t.physicalPropMap.push({tag:n,dimension:e,name:s})}}else if("nodes"===s){if(0===r){r=parseInt(o[0],10),a=parseInt(o[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0),i++;continue}if(lparseInt(e,10)));if(1===p.elementType||8===p.elementType){const n=p.tag;g[n]||(g[n]=[]),g[n].push(e),t.boundaryNodePairs[n]||(t.boundaryNodePairs[n]=[]),t.boundaryNodePairs[n].push(e)}else 2===p.elementType?t.nodalNumbering.triangleElements.push(e):(3===p.elementType||10===p.elementType)&&t.nodalNumbering.quadElements.push(e);b++,b===p.numElements&&(f++,p={numElements:0})}}i++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=g[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),o(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}. These pairs will be used to identify boundary elements in the mesh.`),t},e.logSystem=function(e){"basic"!==e&&"debug"!==e?(console.log("%c[WARN] Invalid log level: "+e+". Using basic instead.","color: #FFC107; font-weight: bold;"),n="basic"):(n=e,s(`Log level set to: ${e}`))},e.plotSolution=function(e,t,n,o,s,i){const{nodesXCoordinates:r,nodesYCoordinates:a}=t;if("1D"===o&&"line"===s){let t;t=e.length>0&&Array.isArray(e[0])?e.map((e=>e[0])):e,Array.from(r);let o={x:r,y:t,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},s=Math.min(window.innerWidth,700),a={title:`line plot - ${n}`,width:Math.min(s,600),height:350,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:50,r:50,t:50,b:50}};Plotly.newPlot(i,[o],a,{responsive:!0})}else if("2D"===o&&"contour"===s){let t;t=Array.isArray(e[0])?e.map((e=>e[0])):e;let o=Math.min(window.innerWidth,700),l=Math.max(...r),d=Math.max(...a)/l,c=Math.min(o,600),u={title:`${s} plot - ${n}`,width:c,height:c*d,xaxis:{title:"x"},yaxis:{title:"y"},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"},m={x:r,y:a,z:t,type:"contour",line:{smoothing:.85},contours:{coloring:"heatmap",showlabels:!1},colorbar:{title:"Solution"},name:"Solution Field"};Plotly.newPlot(i,[m],u,{responsive:!0})}},e.printVersion="0.1.4",Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=feascript.umd.js.map diff --git a/dist/feascript.umd.js.map b/dist/feascript.umd.js.map index 254446d..57328ff 100644 --- a/dist/feascript.umd.js.map +++ b/dist/feascript.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"feascript.umd.js","sources":["../src/methods/euclideanNormScript.js","../src/utilities/loggingScript.js","../src/vendor/comlink.mjs","../src/methods/linearSystemSolverScript.js","../src/methods/jacobiSolverScript.js","../src/mesh/basisFunctionsScript.js","../src/mesh/meshGenerationScript.js","../src/methods/numericalIntegrationScript.js","../src/mesh/meshUtilsScript.js","../src/models/thermalBoundaryConditionsScript.js","../src/models/heatConductionScript.js","../src/models/genericBoundaryConditionsScript.js","../src/models/frontPropagationScript.js","../src/methods/frontalSolverScript.js","../src/methods/newtonRaphsonScript.js","../src/FEAScript.js","../src/models/generalFormPDEScript.js","../src/workers/workerScript.js","../src/readers/gmshReaderScript.js","../src/visualization/plotSolutionScript.js","../src/index.js"],"sourcesContent":["/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to calculate the Euclidean norm of a vector\n * @param {array} vector - The input vector\n * @returns {number} The Euclidean norm of the vector\n */\nexport function euclideanNorm(vector) {\n let norm = 0;\n for (let i = 0; i < vector.length; i++) {\n norm += vector[i] * vector[i];\n }\n norm = Math.sqrt(norm);\n return norm;\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Global logging level\nlet currentLogLevel = \"basic\";\n\n/**\n * Function to set the logging system level\n * @param {string} level - Logging level (basic, debug)\n */\nexport function logSystem(level) {\n if (level !== \"basic\" && level !== \"debug\") {\n console.log(\n \"%c[WARN] Invalid log level: \" + level + \". Using basic instead.\",\n \"color: #FFC107; font-weight: bold;\"\n ); // Yellow for warnings\n currentLogLevel = \"basic\";\n } else {\n currentLogLevel = level;\n basicLog(`Log level set to: ${level}`);\n }\n}\n\n/**\n * Function to log debug messages - only logs if level is 'debug'\n * @param {string} message - Message to log\n */\nexport function debugLog(message) {\n if (currentLogLevel === \"debug\") {\n console.log(\"%c[DEBUG] \" + message, \"color: #2196F3; font-weight: bold;\");\n }\n}\n\n/**\n * Function to log basic information - always logs\n * @param {string} message - Message to log\n */\nexport function basicLog(message) {\n console.log(\"%c[INFO] \" + message, \"color: #4CAF50; font-weight: bold;\");\n}\n\n/**\n * Function to log error messages\n * @param {string} message - Message to log\n */\nexport function errorLog(message) {\n console.log(\"%c[ERROR] \" + message, \"color: #F44336; font-weight: bold;\");\n}\n\n/**\n * Function to log warning messages\n * @param {string} message - Message to log\n */\nexport function warnLog(message) {\n console.log(\"%c[WARN] \" + message, \"color: #FF9800; font-weight: bold;\");\n}\n\n/**\n * Function to handle version information and fetch the latest update date and release from GitHub\n */\nexport async function printVersionInformation() {\n basicLog(\"Fetching latest FEAScript version information...\");\n try {\n const commitResponse = await fetch(\"https://api.github.com/repos/FEAScript/FEAScript/commits/main\");\n const commitData = await commitResponse.json();\n const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();\n basicLog(`Latest FEAScript update: ${latestCommitDate}`);\n return latestCommitDate;\n } catch (error) {\n errorLog(\"Failed to fetch version information: \" + error);\n return \"Version information unavailable\";\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\nconst proxyMarker = Symbol(\"Comlink.proxy\");\nconst createEndpoint = Symbol(\"Comlink.endpoint\");\nconst releaseProxy = Symbol(\"Comlink.releaseProxy\");\nconst finalizer = Symbol(\"Comlink.finalizer\");\nconst throwMarker = Symbol(\"Comlink.thrown\");\nconst isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n};\n/**\n * Allows customizing the serialization of certain values.\n */\nconst transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\nfunction isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\nfunction expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n}\nfunction isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n}\nfunction closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n}\nfunction wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n}\nfunction throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\nfunction releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\nconst proxyCounter = new WeakMap();\nconst proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\nfunction registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\nfunction unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\nfunction createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n}\nfunction myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n}\nfunction processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\nconst transferCache = new WeakMap();\nfunction transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n}\nfunction proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n}\nfunction windowEndpoint(w, context = globalThis, targetOrigin = \"*\") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\nfunction toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\nfunction fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n}\nfunction requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n}\nfunction generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n\nexport { createEndpoint, expose, finalizer, proxy, proxyMarker, releaseProxy, transfer, transferHandlers, windowEndpoint, wrap };\n//# sourceMappingURL=comlink.mjs.map\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { jacobiSolver } from \"./jacobiSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n/**\n * Function to solve a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (\"lusolve\" or \"jacobi\")\n * @param {Array} jacobianMatrix - The coefficient matrix\n * @param {Array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {\n\n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n let solutionVector = [];\n let converged = true;\n let iterations = 0;\n\n // Solve the linear system based on the specified solver method\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n if (solverMethod === \"lusolve\") {\n // Use LU decomposition method\n const jacobianMatrixSparse = math.sparse(jacobianMatrix);\n const luFactorization = math.slu(jacobianMatrixSparse, 1, 1); // order=1, threshold=1 for pivoting\n let solutionMatrix = math.lusolve(luFactorization, residualVector);\n solutionVector = math.squeeze(solutionMatrix).valueOf();\n //solutionVector = math.lusolve(jacobianMatrix, residualVector); // In the case of a dense matrix\n } else if (solverMethod === \"jacobi\") {\n // Use Jacobi method\n const initialGuess = new Array(residualVector.length).fill(0);\n const jacobiSolverResult = jacobiSolver(jacobianMatrix, residualVector, initialGuess, {\n maxIterations,\n tolerance,\n });\n\n // Log convergence information\n if (jacobiSolverResult.converged) {\n debugLog(`Jacobi method converged in ${jacobiSolverResult.iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${jacobiSolverResult.iterations} iterations`);\n }\n\n solutionVector = jacobiSolverResult.solutionVector;\n converged = jacobiSolverResult.converged;\n iterations = jacobiSolverResult.iterations;\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n return { solutionVector, converged, iterations };\n}\n\n// Helper to lazily create a default WebGPU compute engine (Comlink + worker)\nasync function createDefaultComputeEngine() {\n const worker = new Worker(new URL(\"../workers/webgpuWorkerScript.js\", import.meta.url), {\n type: \"module\",\n });\n const computeEngine = Comlink.wrap(worker);\n await computeEngine.initialize();\n return { computeEngine, worker };\n}\n\n/**\n * Function to solve asynchronously a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (e.g., \"jacobi-gpu\")\n * @param {array} jacobianMatrix - The coefficient matrix\n * @param {array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport async function solveLinearSystemAsync(solverMethod, jacobianMatrix, residualVector, options = {}) {\n \n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n // Normalize inputs\n const A = Array.isArray(jacobianMatrix) ? jacobianMatrix : jacobianMatrix?.toArray?.() ?? jacobianMatrix;\n const b = Array.isArray(residualVector) ? residualVector : residualVector?.toArray?.() ?? residualVector;\n\n let created = null;\n let computeEngine = null;\n\n let solutionVector = [];\n let converged = true;\n let iterations;\n\n if (solverMethod === \"jacobi-gpu\") {\n // Spin up a worker-backed compute engine\n created = await createDefaultComputeEngine();\n computeEngine = created.computeEngine;\n\n const x0 = new Array(b.length).fill(0);\n let result;\n\n result = await computeEngine.webgpuJacobiSolver(A, b, x0, { maxIterations, tolerance });\n solutionVector = result.solutionVector;\n converged = result.converged;\n iterations = result.iterations;\n\n // Log convergence information\n if (converged) {\n debugLog(`Jacobi method converged in ${iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${iterations} iterations`);\n }\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(`System solved successfully (${solverMethod})`);\n\n if (created) {\n await computeEngine?.destroy?.().catch(() => { });\n created.worker.terminate();\n }\n\n return { solutionVector, converged, iterations };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to solve a system of linear equations using the Jacobi iterative method (CPU synchronous version)\n * @param {array} A - The system matrix\n * @param {array} b - The right-hand side vector\n * @param {array} x0 - Initial guess for solution vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\nexport function jacobiSolver(A, b, x0, options = {}) {\n // Extract options\n const { maxIterations, tolerance } = options;\n\n const n = A.length;\n let x = [...x0];\n let xNew = new Array(n);\n\n // Jacobi update: xNew[i] = (b[i] - sum(A[i][j] * x[j] for j != i)) / A[i][i]\n for (let iter = 0; iter < maxIterations; iter++) {\n for (let i = 0; i < n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (i !== j) {\n sum += A[i][j] * x[j];\n }\n }\n xNew[i] = (b[i] - sum) / A[i][i];\n }\n\n // Check convergence based on maximum difference in solution vector\n let maxDiff = 0;\n for (let i = 0; i < n; i++) {\n maxDiff = Math.max(maxDiff, Math.abs(xNew[i] - x[i]));\n }\n\n // Copy new solution for the next iteration\n x = [...xNew];\n\n if (maxDiff < tolerance) {\n return { solutionVector: x, iterations: iter + 1, converged: true };\n }\n }\n\n return { solutionVector: x, iterations: maxIterations, converged: false };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle basis functions and their derivatives based on element configuration\n */\nexport class BasisFunctions {\n /**\n * Constructor to initialize the BasisFunctions class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to calculate basis functions and their derivatives based on the dimension and order\n * @param {number} ksi - Natural coordinate (for both 1D and 2D)\n * @param {number} [eta] - Second natural coordinate (only for 2D elements)\n * @returns {object} An object containing:\n * - basisFunction: Array of evaluated basis functions\n * - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi\n * - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)\n */\n getBasisFunctions(ksi, eta = null) {\n let basisFunction = [];\n let basisFunctionDerivKsi = [];\n let basisFunctionDerivEta = [];\n\n if (this.meshDimension === \"1D\") {\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 1D elements\n basisFunction[0] = 1 - ksi;\n basisFunction[1] = ksi;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -1;\n basisFunctionDerivKsi[1] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 1D elements\n basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;\n basisFunction[1] = 4 * ksi - 4 * ksi ** 2;\n basisFunction[2] = -ksi + 2 * ksi ** 2;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -3 + 4 * ksi;\n basisFunctionDerivKsi[1] = 4 - 8 * ksi;\n basisFunctionDerivKsi[2] = -1 + 4 * ksi;\n }\n } else if (this.meshDimension === \"2D\") {\n if (eta === null) {\n errorLog(\"Eta coordinate is required for 2D elements\");\n return;\n }\n\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 2D elements\n function l1(c) {\n return 1 - c;\n }\n function l2(c) {\n return c;\n }\n function dl1() {\n return -1;\n }\n function dl2() {\n return 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l2(ksi) * l1(eta);\n basisFunction[3] = l2(ksi) * l2(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1() * l1(eta);\n basisFunctionDerivKsi[1] = dl1() * l2(eta);\n basisFunctionDerivKsi[2] = dl2() * l1(eta);\n basisFunctionDerivKsi[3] = dl2() * l2(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1();\n basisFunctionDerivEta[1] = l1(ksi) * dl2();\n basisFunctionDerivEta[2] = l2(ksi) * dl1();\n basisFunctionDerivEta[3] = l2(ksi) * dl2();\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 2D elements\n function l1(c) {\n return 2 * c ** 2 - 3 * c + 1;\n }\n function l2(c) {\n return -4 * c ** 2 + 4 * c;\n }\n function l3(c) {\n return 2 * c ** 2 - c;\n }\n function dl1(c) {\n return 4 * c - 3;\n }\n function dl2(c) {\n return -8 * c + 4;\n }\n function dl3(c) {\n return 4 * c - 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l1(ksi) * l3(eta);\n basisFunction[3] = l2(ksi) * l1(eta);\n basisFunction[4] = l2(ksi) * l2(eta);\n basisFunction[5] = l2(ksi) * l3(eta);\n basisFunction[6] = l3(ksi) * l1(eta);\n basisFunction[7] = l3(ksi) * l2(eta);\n basisFunction[8] = l3(ksi) * l3(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);\n basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);\n basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);\n basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);\n basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);\n basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);\n basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);\n basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);\n basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);\n basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);\n basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);\n basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);\n basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);\n basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);\n basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);\n basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);\n basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);\n }\n }\n\n return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Basic structure for the mesh\n */\nexport class Mesh {\n /**\n * Constructor to initialize the Mesh class\n * @param {object} config - Configuration object for the mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)\n * @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)\n * @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n meshDimension = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n this.numElementsX = numElementsX;\n this.numElementsY = numElementsY;\n this.maxX = maxX;\n this.maxY = maxY;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n this.parsedMesh = parsedMesh;\n\n this.boundaryElementsProcessed = false;\n\n if (this.parsedMesh) {\n basicLog(\"Using pre-parsed mesh from gmshReader data for mesh generation.\");\n this.parseMeshFromGmsh();\n }\n }\n\n /**\n * Method to parse the mesh from the GMSH format to the FEAScript format\n */\n parseMeshFromGmsh() {\n if (!this.parsedMesh.nodalNumbering) {\n errorLog(\"No valid nodal numbering found in the parsed mesh.\");\n }\n\n if (\n typeof this.parsedMesh.nodalNumbering === \"object\" &&\n !Array.isArray(this.parsedMesh.nodalNumbering)\n ) {\n // Store the nodal numbering structure before converting\n const quadElements = this.parsedMesh.nodalNumbering.quadElements || [];\n const triangleElements = this.parsedMesh.nodalNumbering.triangleElements || [];\n\n debugLog(\n \"Initial parsed mesh nodal numbering from GMSH format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Check if it has quadElements or triangleElements structure from gmshReader\n if (this.parsedMesh.elementTypes[3] || this.parsedMesh.elementTypes[10]) {\n // Map nodal numbering from GMSH format to FEAScript format for quad elements\n const mappedNodalNumbering = [];\n\n for (let elemIdx = 0; elemIdx < quadElements.length; elemIdx++) {\n const gmshNodes = quadElements[elemIdx];\n const feaScriptNodes = new Array(gmshNodes.length);\n\n // Check for element type based on number of nodes\n if (gmshNodes.length === 4) {\n // Simple mapping for linear quad elements (4 nodes)\n // GMSH: FEAScript:\n // 3 --- 2 1 --- 3\n // | | --> | |\n // 0 --- 1 0 --- 2\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[3]; // 3 -> 1\n feaScriptNodes[2] = gmshNodes[1]; // 1 -> 2\n feaScriptNodes[3] = gmshNodes[2]; // 2 -> 3\n } else if (gmshNodes.length === 9) {\n // Mapping for quadratic quad elements (9 nodes)\n // GMSH: FEAScript:\n // 3--6--2 2--5--8\n // | | | |\n // 7 8 5 --> 1 4 7\n // | | | |\n // 0--4--1 0--3--6\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[7]; // 7 -> 1\n feaScriptNodes[2] = gmshNodes[3]; // 3 -> 2\n feaScriptNodes[3] = gmshNodes[4]; // 4 -> 3\n feaScriptNodes[4] = gmshNodes[8]; // 8 -> 4\n feaScriptNodes[5] = gmshNodes[6]; // 6 -> 5\n feaScriptNodes[6] = gmshNodes[1]; // 1 -> 6\n feaScriptNodes[7] = gmshNodes[5]; // 5 -> 7\n feaScriptNodes[8] = gmshNodes[2]; // 2 -> 8\n }\n\n mappedNodalNumbering.push(feaScriptNodes);\n }\n\n this.parsedMesh.nodalNumbering = mappedNodalNumbering;\n } else if (this.parsedMesh.elementTypes[2]) {\n errorLog(\"Element type is neither triangle nor quad; mapping for this type is not implemented yet.\");\n }\n\n debugLog(\n \"Nodal numbering after mapping from GMSH to FEAScript format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Process boundary elements if they exist and if physical property mapping exists\n if (this.parsedMesh.physicalPropMap && this.parsedMesh.boundaryElements) {\n // Check if boundary elements need to be processed\n if (\n Array.isArray(this.parsedMesh.boundaryElements) &&\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n // Create a new array without the empty first element\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n\n // If boundary node pairs exist but boundary elements haven't been processed\n if (this.parsedMesh.boundaryNodePairs && !this.parsedMesh.boundaryElementsProcessed) {\n // Reset boundary elements array\n this.parsedMesh.boundaryElements = [];\n\n // Process each physical property from the Gmsh file\n this.parsedMesh.physicalPropMap.forEach((prop) => {\n // Only process 1D physical entities (boundary lines)\n if (prop.dimension === 1) {\n // Get all node pairs for this boundary\n const boundaryNodePairs = this.parsedMesh.boundaryNodePairs[prop.tag] || [];\n\n if (boundaryNodePairs.length > 0) {\n // Initialize array for this boundary tag\n if (!this.parsedMesh.boundaryElements[prop.tag]) {\n this.parsedMesh.boundaryElements[prop.tag] = [];\n }\n\n // For each boundary line segment (defined by a pair of nodes)\n boundaryNodePairs.forEach((nodesPair) => {\n const node1 = nodesPair[0]; // First node in the pair\n const node2 = nodesPair[1]; // Second node in the pair\n\n debugLog(\n `Processing boundary node pair: [${node1}, ${node2}] for boundary ${prop.tag} (${\n prop.name || \"unnamed\"\n })`\n );\n\n // Search through all elements to find which one contains both nodes\n let foundElement = false;\n\n // Loop through all elements in the mesh\n for (let elemIdx = 0; elemIdx < this.parsedMesh.nodalNumbering.length; elemIdx++) {\n const elemNodes = this.parsedMesh.nodalNumbering[elemIdx];\n\n // For linear quadrilateral linear elements (4 nodes)\n if (elemNodes.length === 4) {\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript linear quadrilateral numbering:\n // 1 --- 3\n // | |\n // 0 --- 2\n\n if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0)\n ) {\n side = 0; // Bottom side\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0)\n ) {\n side = 1; // Left side\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 1 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 1)\n ) {\n side = 2; // Top side\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 2)\n ) {\n side = 3; // Right side\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n } else if (elemNodes.length === 9) {\n // For quadratic quadrilateral elements (9 nodes)\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript quadratic quadrilateral numbering:\n // 2--5--8\n // | |\n // 1 4 7\n // | |\n // 0--3--6\n\n // TODO: Transform into dictionaries for better readability\n if (\n (node1Index === 0 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 0) ||\n (node1Index === 3 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 3)\n ) {\n side = 0; // Bottom side (nodes 0, 3, 6)\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0) ||\n (node1Index === 1 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 1)\n ) {\n side = 1; // Left side (nodes 0, 1, 2)\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 5) ||\n (node1Index === 5 && node2Index === 2) ||\n (node1Index === 5 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 5)\n ) {\n side = 2; // Top side (nodes 2, 5, 8)\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 6 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 7) ||\n (node1Index === 7 && node2Index === 6) ||\n (node1Index === 7 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 7)\n ) {\n side = 3; // Right side (nodes 6, 7, 8)\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n }\n }\n\n if (!foundElement) {\n errorLog(\n `Could not find element containing boundary nodes ${node1} and ${node2}. Boundary may be incomplete.`\n );\n }\n });\n }\n }\n });\n\n // Mark as processed\n this.boundaryElementsProcessed = true;\n\n // Fix boundary elements array - remove undefined entries\n if (\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n }\n }\n }\n\n return this.parsedMesh;\n }\n}\n\nexport class Mesh1D extends Mesh {\n /**\n * Constructor to initialize the 1D mesh\n * @param {object} config - Configuration object for the 1D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({ numElementsX = null, maxX = null, elementOrder = \"linear\", parsedMesh = null }) {\n super({\n numElementsX,\n maxX,\n numElementsY: 1,\n maxY: 0,\n meshDimension: \"1D\",\n elementOrder,\n parsedMesh,\n });\n\n if (this.numElementsX === null || this.maxX === null) {\n errorLog(\"numElementsX and maxX are required parameters when generating a 1D mesh from geometry\");\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n const xStart = 0;\n let totalNodesX, deltaX;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX;\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX / 2;\n }\n }\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate1DNodalNumbering(this.numElementsX, totalNodesX, this.elementOrder);\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n\n // Return x coordinates of nodes, total nodes, NOP array, and boundary elements\n return {\n nodesXCoordinates,\n totalNodesX,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate1DNodalNumbering(numElementsX, totalNodesX, elementOrder) {\n // TODO: The totalNodesX is not used in the original function. Verify if\n // there is a multiple calculation on the totalNodes.\n\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear 1D elements with the following nodes representation:\n *\n * 1 --- 2\n *\n */\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic 1D elements with the following nodes representation:\n *\n * 1--2--3\n *\n */\n let columnCounter = 0;\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex + columnCounter;\n }\n columnCounter += 1;\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 1D domains (line segments):\n * 0 - Left node of reference element (maps to physical left endpoint)\n * 1 - Right node of reference element (maps to physical right endpoint)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 2; // For 1D, we only have two sides (left and right)\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // Left boundary (element 0, side 0)\n boundaryElements[0].push([0, 0]);\n\n // Right boundary (last element, side 1)\n boundaryElements[1].push([this.numElementsX - 1, 1]);\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n\nexport class Mesh2D extends Mesh {\n /**\n * Constructor to initialize the 2D mesh\n * @param {object} config - Configuration object for the 2D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY] - Number of elements along the y-axis (required for geometry-based mesh)\n * @param {number} [config.maxY] - Maximum y-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n super({\n numElementsX,\n maxX,\n numElementsY,\n maxY,\n meshDimension: \"2D\",\n elementOrder,\n parsedMesh,\n });\n\n // Validate geometry parameters (when not using a parsed mesh)\n if (\n !parsedMesh &&\n (this.numElementsX === null || this.maxX === null || this.numElementsY === null || this.maxY === null)\n ) {\n errorLog(\n \"numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry\"\n );\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n let nodesYCoordinates = [];\n const xStart = 0;\n const yStart = 0;\n let totalNodesX, totalNodesY, deltaX, deltaY;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n totalNodesY = this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + nodeIndexY * deltaY;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + nodeIndexX * deltaX;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + nodeIndexY * deltaY;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n totalNodesY = 2 * this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;\n }\n }\n }\n\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate2DNodalNumbering(\n this.numElementsX,\n this.numElementsY,\n totalNodesY,\n this.elementOrder\n );\n\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n debugLog(\"Generated node Y coordinates: \" + JSON.stringify(nodesYCoordinates));\n\n // Return statement\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate2DNodalNumbering(numElementsX, numElementsY, totalNodesY, elementOrder) {\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear rectangular elements with the following nodes representation:\n *\n * 1 --- 3\n * | |\n * 0 --- 2\n *\n */\n let rowCounter = 0;\n let columnCounter = 2;\n for (let elementIndex = 0; elementIndex < numElementsX * numElementsY; elementIndex++) {\n rowCounter += 1;\n nop[elementIndex] = [];\n nop[elementIndex][0] = elementIndex + columnCounter - 1;\n nop[elementIndex][1] = elementIndex + columnCounter;\n nop[elementIndex][2] = elementIndex + columnCounter + numElementsY;\n nop[elementIndex][3] = elementIndex + columnCounter + numElementsY + 1;\n if (rowCounter === numElementsY) {\n columnCounter += 1;\n rowCounter = 0;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic rectangular elements with the following nodes representation:\n *\n * 2--5--8\n * | |\n * 1 4 7\n * | |\n * 0--3--6\n *\n */\n for (let elementIndexX = 1; elementIndexX <= numElementsX; elementIndexX++) {\n for (let elementIndexY = 1; elementIndexY <= numElementsY; elementIndexY++) {\n nop[elementIndex] = [];\n for (let nodeIndex1 = 1; nodeIndex1 <= 3; nodeIndex1++) {\n let nodeIndex2 = 3 * nodeIndex1 - 2;\n nop[elementIndex][nodeIndex2 - 1] =\n totalNodesY * (2 * elementIndexX + nodeIndex1 - 3) + 2 * elementIndexY - 1;\n nop[elementIndex][nodeIndex2] = nop[elementIndex][nodeIndex2 - 1] + 1;\n nop[elementIndex][nodeIndex2 + 1] = nop[elementIndex][nodeIndex2 - 1] + 2;\n }\n elementIndex = elementIndex + 1;\n }\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 2D domains (rectangular):\n * 0 - Bottom side of reference element (maps to physical bottom boundary)\n * 1 - Left side of reference element (maps to physical left boundary)\n * 2 - Top side of reference element (maps to physical top boundary)\n * 3 - Right side of reference element (maps to physical right boundary)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 4; // For 2D, we have four sides (left, right, bottom, top)\n\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // TODO: Why to loop through all elements? Is it not better to loop over only the\n // elements that are on the boundary? eg: [0, this.numElementsX - 1] on x and\n // [0, this.numElementsY - 1] on y\n for (let elementIndexX = 0; elementIndexX < this.numElementsX; elementIndexX++) {\n for (let elementIndexY = 0; elementIndexY < this.numElementsY; elementIndexY++) {\n const elementIndex = elementIndexX * this.numElementsY + elementIndexY;\n\n // Bottom boundary\n if (elementIndexY === 0) {\n boundaryElements[0].push([elementIndex, 0]);\n }\n\n // Left boundary\n if (elementIndexX === 0) {\n boundaryElements[1].push([elementIndex, 1]);\n }\n\n // Top boundary\n if (elementIndexY === this.numElementsY - 1) {\n boundaryElements[2].push([elementIndex, 2]);\n }\n\n // Right boundary\n if (elementIndexX === this.numElementsX - 1) {\n boundaryElements[3].push([elementIndex, 3]);\n }\n }\n }\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Class to handle numerical integration using Gauss quadrature\n */\nexport class NumericalIntegration {\n /**\n * Constructor to initialize the NumericalIntegration class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to return Gauss points and weights based on element configuration\n * @returns {object} An object containing:\n * - gaussPoints: Array of Gauss points\n * - gaussWeights: Array of Gauss weights\n */\n getGaussPointsAndWeights() {\n let gaussPoints = []; // Gauss points\n let gaussWeights = []; // Gauss weights\n\n if (this.elementOrder === \"linear\") {\n // For linear elements, use 1-point Gauss quadrature\n gaussPoints[0] = 0.5;\n gaussWeights[0] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // For quadratic elements, use 3-point Gauss quadrature\n gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;\n gaussPoints[1] = 0.5;\n gaussPoints[2] = (1 + Math.sqrt(3 / 5)) / 2;\n gaussWeights[0] = 5 / 18;\n gaussWeights[1] = 8 / 18;\n gaussWeights[2] = 5 / 18;\n }\n\n return { gaussPoints, gaussWeights };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nimport { BasisFunctions } from \"./basisFunctionsScript.js\";\nimport { Mesh1D, Mesh2D } from \"./meshGenerationScript.js\";\nimport { NumericalIntegration } from \"../methods/numericalIntegrationScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to prepare the mesh for finite element analysis\n * @param {object} meshConfig - Object containing computational mesh details\n * @returns {object} An object containing all mesh-related data\n */\nexport function prepareMesh(meshConfig) {\n const { meshDimension, numElementsX, numElementsY, maxX, maxY, elementOrder, parsedMesh } = meshConfig;\n\n // Create a new instance of the Mesh class\n let mesh;\n if (meshDimension === \"1D\") {\n mesh = new Mesh1D({ numElementsX, maxX, elementOrder, parsedMesh });\n } else if (meshDimension === \"2D\") {\n mesh = new Mesh2D({ numElementsX, maxX, numElementsY, maxY, elementOrder, parsedMesh });\n } else {\n errorLog(\"Mesh dimension must be either '1D' or '2D'.\");\n }\n\n // Use the parsed mesh in case it was already passed with Gmsh format\n const nodesCoordinatesAndNumbering = mesh.boundaryElementsProcessed ? mesh.parsedMesh : mesh.generateMesh();\n\n // Extract nodes coordinates and nodal numbering (NOP) from the mesh data\n let nodesXCoordinates = nodesCoordinatesAndNumbering.nodesXCoordinates;\n let nodesYCoordinates = nodesCoordinatesAndNumbering.nodesYCoordinates;\n let totalNodesX = nodesCoordinatesAndNumbering.totalNodesX;\n let totalNodesY = nodesCoordinatesAndNumbering.totalNodesY;\n let nop = nodesCoordinatesAndNumbering.nodalNumbering;\n let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;\n\n // Check the mesh type\n const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;\n\n // Calculate totalElements and totalNodes based on mesh type\n let totalElements, totalNodes;\n\n if (isParsedMesh) {\n totalElements = nop.length; // Number of elements is the length of the nodal numbering array\n totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array\n debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);\n } else {\n // For structured mesh, calculate based on dimensions\n totalElements = numElementsX * (meshDimension === \"2D\" ? numElementsY : 1);\n totalNodes = totalNodesX * (meshDimension === \"2D\" ? totalNodesY : 1);\n debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);\n }\n\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nop,\n boundaryElements,\n totalElements,\n totalNodes,\n meshDimension,\n elementOrder,\n };\n}\n\n/**\n * Function to initialize the FEA matrices and numerical tools\n * @param {object} meshData - Object containing mesh data from prepareMesh()\n * @returns {object} An object containing initialized matrices and numerical tools\n */\nexport function initializeFEA(meshData) {\n const { totalNodes, nop, meshDimension, elementOrder } = meshData;\n\n // Initialize variables for matrix assembly\n let residualVector = [];\n let jacobianMatrix = [];\n let localToGlobalMap = [];\n\n // Initialize jacobianMatrix and residualVector arrays\n for (let nodeIndex = 0; nodeIndex < totalNodes; nodeIndex++) {\n residualVector[nodeIndex] = 0;\n jacobianMatrix.push([]);\n for (let colIndex = 0; colIndex < totalNodes; colIndex++) {\n jacobianMatrix[nodeIndex][colIndex] = 0;\n }\n }\n\n // Initialize the BasisFunctions class\n const basisFunctions = new BasisFunctions({\n meshDimension,\n elementOrder,\n });\n\n // Initialize the NumericalIntegration class\n const numericalIntegration = new NumericalIntegration({\n meshDimension,\n elementOrder,\n });\n\n // Calculate Gauss points and weights\n let gaussPointsAndWeights = numericalIntegration.getGaussPointsAndWeights();\n let gaussPoints = gaussPointsAndWeights.gaussPoints;\n let gaussWeights = gaussPointsAndWeights.gaussWeights;\n\n // Determine the number of nodes in the reference element based on the first element in the nop array\n const numNodes = nop[0].length;\n\n return {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 1D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping1D(params) {\n const { basisFunction, basisFunctionDerivKsi, nodesXCoordinates, localToGlobalMap, numNodes } = params;\n\n let xCoordinates = 0;\n let ksiDerivX = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n }\n let detJacobian = ksiDerivX;\n\n // Compute x-derivative of basis functions\n let basisFunctionDerivX = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n basisFunctionDerivX[localNodeIndex] = basisFunctionDerivKsi[localNodeIndex] / detJacobian;\n }\n\n return {\n xCoordinates,\n detJacobian,\n basisFunctionDerivX,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 2D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping2D(params) {\n const {\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n } = params;\n\n let xCoordinates = 0;\n let yCoordinates = 0;\n let ksiDerivX = 0;\n let etaDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivY = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n yCoordinates += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n ksiDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n }\n let detJacobian = ksiDerivX * etaDerivY - etaDerivX * ksiDerivY;\n\n // Compute x-derivative and y-derivative of basis functions\n let basisFunctionDerivX = [];\n let basisFunctionDerivY = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // The x-derivative of the n basis function\n basisFunctionDerivX[localNodeIndex] =\n (etaDerivY * basisFunctionDerivKsi[localNodeIndex] -\n ksiDerivY * basisFunctionDerivEta[localNodeIndex]) /\n detJacobian;\n // The y-derivative of the n basis function\n basisFunctionDerivY[localNodeIndex] =\n (ksiDerivX * basisFunctionDerivEta[localNodeIndex] -\n etaDerivX * basisFunctionDerivKsi[localNodeIndex]) /\n detJacobian;\n }\n\n return {\n xCoordinates,\n yCoordinates,\n detJacobian,\n basisFunctionDerivX,\n basisFunctionDerivY,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle thermal boundary conditions application\n */\nexport class ThermalBoundaryConditions {\n /**\n * Constructor to initialize the ThermalBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose constant temperature boundary conditions (Dirichlet type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant temperature boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantTempBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions (Robin type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n */\n imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 1;\n }\n } else if (this.elementOrder === \"quadratic\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 2;\n }\n }\n\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n residualVector[globalNodeIndex] += -convectionCoeff * extTemp;\n jacobianMatrix[globalNodeIndex][globalNodeIndex] += convectionCoeff;\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions for the frontal solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix with convection contributions\n * - localResidualVector: Residual vector with convection contributions\n */\n imposeConvectionBoundaryConditionsFront(\n elementIndex,\n nodesXCoordinates,\n nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n // Initialize local Jacobian matrix and local residual vector\n const numNodes = this.nop[elementIndex].length;\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Check if this element is on a convection boundary\n for (const boundaryKey in this.boundaryElements) {\n if (this.boundaryConditions[boundaryKey]?.[0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n\n // Find if this element is on this boundary and which side\n const boundaryElement = this.boundaryElements[boundaryKey].find(\n ([elemIdx, _]) => elemIdx === elementIndex\n );\n\n if (boundaryElement) {\n const side = boundaryElement[1];\n\n if (this.meshDimension === \"1D\") {\n // Handle 1D case\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n nodeIndex = side === 0 ? 0 : 1;\n } else if (this.elementOrder === \"quadratic\") {\n nodeIndex = side === 0 ? 0 : 2;\n }\n\n // Add contribution to local Jacobian matrix and local residual vector\n debugLog(\n ` - Applied convection boundary condition to node ${nodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n localResidualVector[nodeIndex] += -convectionCoeff * extTemp;\n localJacobianMatrix[nodeIndex][nodeIndex] += convectionCoeff;\n } else if (this.meshDimension === \"2D\") {\n // Handle 2D case\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n // Get basis functions\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n const basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n const basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n // Calculate tangent vector components\n let ksiDerivX = 0,\n ksiDerivY = 0,\n etaDerivX = 0,\n etaDerivY = 0;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n } else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute tangent vector length\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n // Handle quadratic elements (similar pattern but with more Gauss points)\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { ThermalBoundaryConditions } from \"./thermalBoundaryConditionsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the solid heat transfer model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\nexport function assembleHeatConductionMat(meshData, boundaryConditions) {\n basicLog(\"Starting solid heat transfer matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D solid heat transfer\n if (meshDimension === \"1D\") {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n // 2D solid heat transfer\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const thermalBoundaryConditions = new ThermalBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Convection boundary conditions\n thermalBoundaryConditions.imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n );\n\n // Impose ConstantTemp boundary conditions\n thermalBoundaryConditions.imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Solid heat transfer matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the solid heat transfer model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - localResidualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleHeatConductionFront({ elementIndex, nop, meshData, basisFunctions, FEAData }) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n if (meshDimension === \"1D\") {\n // 1D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n // 2D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Create mapping from local element space to global mesh (convert to 0-based indexing)\n const localToGlobalMap = ngl.map((globalIndex) => globalIndex - 1);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle generic boundary conditions application\n */\nexport class GenericBoundaryConditions {\n /**\n * Constructor to initialize the GenericBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose Dirichlet boundary conditions\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant value (Dirichlet) boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantValueBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n// Base viscous term that remains when eikonal equation is fully activated\nconst baseEikonalViscousTerm = 1e-2;\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the front propagation model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleFrontPropagationMat(\n meshData,\n boundaryConditions,\n solutionVector,\n eikonalActivationFlag\n) {\n basicLog(\"Starting front propagation matrix assembly...\");\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n debugLog(`eikonalViscousTerm: ${eikonalViscousTerm}`);\n debugLog(`eikonalActivationFlag: ${eikonalActivationFlag}`);\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // jacobianMatrix\n // TODO jacobianMatrix calculation here\n }\n }\n }\n // 2D front propagation (eikonal) equation\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n\n // residualVector: Viscous term contribution (to stabilize the solution)\n residualVector[localToGlobalMap1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // residualVector: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n residualVector[localToGlobalMap1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n\n // jacobianMatrix: Viscous term contribution\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // jacobianMatrix: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Dirichlet boundary conditions\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Front propagation matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the front propagation model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - residualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleFrontPropagationFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n solutionVector,\n eikonalActivationFlag,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // localJacobianMatrix\n // TODO localJacobianMatrix calculation here\n }\n }\n // 2D front propagation (eikonal) equation\n } else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // Viscous term contribution\n localResidualVector[localNodeIndex1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localResidualVector[localNodeIndex1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Viscous term contribution\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { BasisFunctions } from \"../mesh/basisFunctionsScript.js\";\nimport { initializeFEA } from \"../mesh/meshUtilsScript.js\";\nimport { assembleHeatConductionFront } from \"../models/heatConductionScript.js\";\nimport { ThermalBoundaryConditions } from \"../models/thermalBoundaryConditionsScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\nimport { GenericBoundaryConditions } from \"../models/genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n// Create object templates\nconst frontalData = {};\nconst frontalState = {};\nconst elementData = { currentElementIndex: 0 };\nconst frontStorage = {};\nlet basisFunctions;\n\n/**\n * Function to run the frontal solver and obtain results for plotting\n * @param {function} assembleFront - Matrix assembler based on the physical model\n * @param {object} meshData - Object containing mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} [options] - Additional options for the solver\n * @returns {object} An object containing the solution vector and node coordinates\n */\nexport function runFrontalSolver(assembleFront, meshData, boundaryConditions, options = {}) {\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const totalNodes = meshData.nodesXCoordinates.length;\n const numElements = meshData.totalElements;\n const numNodes = FEAData.numNodes;\n\n // Calculate required array sizes\n initializeFrontalArrays(numNodes, numElements);\n\n // Start timing for system solving (frontal algorithm)\n basicLog(\"Solving system using frontal...\");\n console.time(\"systemSolving\");\n\n // Initialize basis functions\n basisFunctions = new BasisFunctions({\n meshDimension: meshData.meshDimension,\n elementOrder: meshData.elementOrder,\n });\n\n // Copy node connectivity array into frontalData storage\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n for (let nodeIndex = 0; nodeIndex < FEAData.numNodes; nodeIndex++) {\n frontalData.nodalNumbering[elementIndex][nodeIndex] = meshData.nop[elementIndex][nodeIndex];\n }\n }\n\n // Apply Dirichlet-type boundary conditions\n // Initialize all nodes with no boundary condition\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.nodeConstraintCode[nodeIndex] = 0;\n frontalData.boundaryValues[nodeIndex] = 0;\n }\n\n // Handle Dirichlet-type boundary conditions differently based on which solver is being used\n let dirichletBoundaryConditionsHandler;\n // Solid heat transfer model (heatConductionScript solver)\n if (assembleFront === assembleHeatConductionFront) {\n dirichletBoundaryConditionsHandler = new ThermalBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantTempBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n // Front propagation model (frontPropagationScript solver)\n } else if (assembleFront === assembleFrontPropagationFront) {\n dirichletBoundaryConditionsHandler = new GenericBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantValueBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n }\n // Initialize global residual vector\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.globalResidualVector[nodeIndex] = 0;\n }\n\n frontalState.totalNodes = meshData.nodesXCoordinates.length;\n frontalState.writeFlag = 0;\n frontalState.transformationFlag = 1;\n frontalState.determinant = 1;\n\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n frontalState.nodesPerElement[elementIndex] = FEAData.numNodes;\n }\n\n // Parameters for non-linear assemblers\n frontalState.currentSolutionVector = options.solutionVector;\n frontalState.eikonalActivationFlag = options.eikonalActivationFlag;\n\n // Pass assembleFront and dirichletBoundaryConditionsHandler to runFrontalAlgorithm\n runFrontalAlgorithm(meshData, FEAData, dirichletBoundaryConditionsHandler, assembleFront);\n\n // Copy solution\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.solutionVector[nodeIndex] = frontalState.globalSolutionVector[nodeIndex];\n }\n\n // Output results to console for debugging\n const { nodesXCoordinates, nodesYCoordinates } = meshData;\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n if (meshData.meshDimension === \"1D\") {\n // 1D case - only output X coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${frontalData.solutionVector[\n nodeIndex\n ].toExponential(5)}`\n );\n } else {\n // 2D case - output X, Y coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${nodesYCoordinates[nodeIndex].toExponential(\n 5\n )} ${frontalData.solutionVector[nodeIndex].toExponential(5)}`\n );\n }\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n const { nodesXCoordinates: finalNodesX, nodesYCoordinates: finalNodesY } = meshData;\n return {\n solutionVector: frontalData.solutionVector.slice(0, totalNodes),\n nodesCoordinates: {\n nodesXCoordinates: finalNodesX,\n nodesYCoordinates: finalNodesY,\n },\n };\n}\n\n/**\n * Function to initialize arrays dynamically based on problem size\n * @param {number} numNodes - Number of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n */\nfunction initializeFrontalArrays(numNodes, numElements) {\n // Use the actual number of elements from the mesh\n frontalData.nodalNumbering = Array(numElements)\n .fill()\n .map(() => Array(numNodes).fill(0));\n frontalData.nodeConstraintCode = Array(numNodes).fill(0);\n frontalData.boundaryValues = Array(numNodes).fill(0);\n frontalData.globalResidualVector = Array(numNodes).fill(0);\n frontalData.solutionVector = Array(numNodes).fill(0);\n frontalData.topologyData = Array(numElements).fill(0);\n frontalData.lateralData = Array(numElements).fill(0);\n\n // Initialize frontalState arrays\n frontalState.writeFlag = 0;\n frontalState.totalNodes = numNodes;\n frontalState.transformationFlag = 0;\n frontalState.nodesPerElement = Array(numElements).fill(0);\n frontalState.determinant = 1;\n\n // For matrix operations, estimate required size based on problem complexity\n const systemSize = Math.max(numNodes, 2000);\n frontalState.globalSolutionVector = Array(systemSize).fill(0);\n frontalState.frontDataIndex = 0;\n\n // Initialize elementData arrays\n elementData.localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n elementData.currentElementIndex = 0;\n\n // Initialize frontStorage arrays\n const frontSize = estimateFrontSize(numNodes, numElements);\n frontStorage.frontValues = Array(frontSize).fill(0);\n frontStorage.columnHeaders = Array(systemSize).fill(0);\n frontStorage.pivotRow = Array(systemSize).fill(0);\n frontStorage.pivotData = Array(frontSize).fill(0);\n}\n\n/**\n * Function to estimate the required front size\n * @param {number} numNodes - Number of of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n * @returns {number} Estimated front size\n */\nfunction estimateFrontSize(numNodes, numElements) {\n const frontWidthEstimate = Math.max(Math.ceil(Math.sqrt(numElements)) * numNodes, numNodes * 2);\n return frontWidthEstimate * numElements;\n}\n// Old function to estimate the required front size\n// function estimateFrontSize(numNodes, numElements, numNodes) {\n// const frontWidthEstimate = Math.ceil(Math.sqrt(numElements) * numNodes * 2);\n// const frontSize = frontWidthEstimate * numNodes * 4;\n// return Math.max(frontSize, 10000);\n// }\n\n/**\n * Function to compute local Jacobian matrix and local residual vector\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n const elementIndex = elementData.currentElementIndex - 1;\n\n // Guard against out-of-range indices\n if (elementIndex < 0 || elementIndex >= meshData.totalElements) {\n errorLog(`Skipping out-of-range elementIndex=${elementIndex} (totalElements=${meshData.totalElements})`);\n return false;\n }\n\n // Domain terms\n const { localJacobianMatrix, localResidualVector, ngl } = assembleFront({\n elementIndex,\n nop: frontalData.nodalNumbering,\n meshData,\n basisFunctions: basisFunctions,\n FEAData,\n // These are ignored by linear assemblers\n solutionVector: frontalState.currentSolutionVector,\n eikonalActivationFlag: frontalState.eikonalActivationFlag,\n });\n\n // Handle Robin-type boundary conditions differently based on which solver is being used\n let boundaryLocalJacobianMatrix = Array(FEAData.numNodes)\n .fill()\n .map(() => Array(FEAData.numNodes).fill(0));\n let boundaryResidualVector = Array(FEAData.numNodes).fill(0);\n\n // heatConductionScript solver\n if (assembleFront === assembleHeatConductionFront) {\n // Check if this element is on a Robin-type boundary\n let isOnRobinTypeBoundary = false;\n for (const boundaryKey in meshData.boundaryElements) {\n if (\n thermalBoundaryConditions.boundaryConditions[boundaryKey]?.[0] === \"convection\" &&\n meshData.boundaryElements[boundaryKey].some(([elemIdx, _]) => elemIdx === elementIndex)\n ) {\n isOnRobinTypeBoundary = true;\n break;\n }\n }\n\n // Only calculate Robin-type for elements when required\n if (isOnRobinTypeBoundary) {\n const { gaussPoints, gaussWeights } = FEAData;\n const result = thermalBoundaryConditions.imposeConvectionBoundaryConditionsFront(\n elementIndex,\n meshData.nodesXCoordinates,\n meshData.nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n );\n boundaryLocalJacobianMatrix = result.localJacobianMatrix;\n boundaryResidualVector = result.localResidualVector;\n }\n } else if (assembleFront === assembleFrontPropagationFront) {\n // For now, no Robin-type boundary conditions exist for any other solver\n }\n\n // Combine domain and boundary contributions\n for (let localNodeI = 0; localNodeI < FEAData.numNodes; localNodeI++) {\n for (let localNodeJ = 0; localNodeJ < FEAData.numNodes; localNodeJ++) {\n elementData.localJacobianMatrix[localNodeI][localNodeJ] =\n localJacobianMatrix[localNodeI][localNodeJ] + boundaryLocalJacobianMatrix[localNodeI][localNodeJ];\n }\n }\n\n // Assemble local element residual\n for (let localNodeIndex = 0; localNodeIndex < FEAData.numNodes; localNodeIndex++) {\n const globalNodeIndex = ngl[localNodeIndex] - 1;\n frontalData.globalResidualVector[globalNodeIndex] +=\n localResidualVector[localNodeIndex] + boundaryResidualVector[localNodeIndex];\n }\n\n return true;\n}\n\n/**\n * Function to implement the frontal solver algorithm\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction runFrontalAlgorithm(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n // Allocate local arrays dynamically\n const totalElements = meshData.totalElements;\n const numNodes = meshData.nodesXCoordinates.length;\n const systemSize = Math.max(numNodes, frontalState.globalSolutionVector.length);\n let localDestination = Array(FEAData.numNodes).fill(0);\n let rowDestination = Array(FEAData.numNodes).fill(0);\n let rowHeaders = Array(systemSize).fill(0);\n let pivotRowIndices = Array(systemSize).fill(0);\n let pivotColumnIndices = Array(systemSize).fill(0);\n let modifiedRows = Array(systemSize).fill(0);\n let pivotColumn = Array(systemSize).fill(0);\n let frontMatrix = Array(systemSize)\n .fill()\n .map(() => Array(systemSize).fill(0));\n let rowSwapCount = Array(numNodes).fill(0);\n let columnSwapCount = Array(numNodes).fill(0);\n let lastAppearanceCheck = Array(numNodes).fill(0);\n let pivotColumnGlobalIndex; // Pivot column global index\n\n let frontDataCounter = 1;\n frontalState.writeFlag++;\n let pivotDataIndex = 1;\n let summedRows = 1;\n elementData.currentElementIndex = 0;\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n rowSwapCount[nodeIndex] = 0;\n columnSwapCount[nodeIndex] = 0;\n }\n\n if (frontalState.transformationFlag !== 0) {\n // Prefront: find last appearance of each node\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n lastAppearanceCheck[nodeIndex] = 0;\n }\n\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n let reverseElementIndex = totalElements - elementIndex - 1;\n for (\n let localNodeIndex = 0;\n localNodeIndex < frontalState.nodesPerElement[reverseElementIndex];\n localNodeIndex++\n ) {\n let globalNodeIndex = frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n if (lastAppearanceCheck[globalNodeIndex - 1] === 0) {\n lastAppearanceCheck[globalNodeIndex - 1] = 1;\n frontalData.nodalNumbering[reverseElementIndex][localNodeIndex] =\n -frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n }\n }\n }\n }\n\n frontalState.transformationFlag = 0;\n let columnCount = 0;\n let rowCount = 0;\n\n for (let i = 0; i < systemSize; i++) {\n for (let j = 0; j < systemSize; j++) {\n frontMatrix[j][i] = 0;\n }\n }\n\n while (true) {\n // Assemble a new element only while we still have elements\n let assembled = false;\n let numElementNodes = 0;\n let numElementColumns = 0;\n\n if (elementData.currentElementIndex < totalElements) {\n elementData.currentElementIndex++;\n assembled = assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront);\n }\n\n if (assembled) {\n const currentElement = elementData.currentElementIndex;\n numElementNodes = frontalState.nodesPerElement[currentElement - 1];\n numElementColumns = frontalState.nodesPerElement[currentElement - 1];\n\n for (let localNodeIndex = 0; localNodeIndex < numElementColumns; localNodeIndex++) {\n let globalNodeIndex = frontalData.nodalNumbering[currentElement - 1][localNodeIndex];\n let columnIndex;\n\n if (columnCount === 0) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(frontStorage.columnHeaders[columnIndex])) break;\n }\n\n if (columnIndex === columnCount) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n localDestination[localNodeIndex] = columnIndex + 1;\n frontStorage.columnHeaders[columnIndex] = globalNodeIndex;\n }\n }\n\n let rowIndex;\n if (rowCount === 0) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(rowHeaders[rowIndex])) break;\n }\n\n if (rowIndex === rowCount) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n rowDestination[localNodeIndex] = rowIndex + 1;\n rowHeaders[rowIndex] = globalNodeIndex;\n }\n }\n }\n\n if (rowCount > systemSize || columnCount > systemSize) {\n errorLog(\"Error: systemSize not large enough\");\n return;\n }\n\n for (let localColumnIndex = 0; localColumnIndex < numElementColumns; localColumnIndex++) {\n let frontColumnIndex = localDestination[localColumnIndex];\n for (let localRowIndex = 0; localRowIndex < numElementNodes; localRowIndex++) {\n let frontRowIndex = rowDestination[localRowIndex];\n frontMatrix[frontRowIndex - 1][frontColumnIndex - 1] +=\n elementData.localJacobianMatrix[localRowIndex][localColumnIndex];\n }\n }\n }\n\n // Pivoting/elimination continues whether or not a new element was assembled\n let availableColumnCount = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (frontStorage.columnHeaders[columnIndex] < 0) {\n pivotColumnIndices[availableColumnCount] = columnIndex + 1;\n availableColumnCount++;\n }\n }\n\n let constrainedRowCount = 0;\n let availableRowCount = 0;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n let globalNodeIndex = rowHeaders[rowIndex];\n if (globalNodeIndex < 0) {\n pivotRowIndices[availableRowCount] = rowIndex + 1;\n availableRowCount++;\n let absoluteNodeIndex = Math.abs(globalNodeIndex);\n if (frontalData.nodeConstraintCode[absoluteNodeIndex - 1] === 1) {\n modifiedRows[constrainedRowCount] = rowIndex + 1;\n constrainedRowCount++;\n frontalData.nodeConstraintCode[absoluteNodeIndex - 1] = 2;\n frontalData.globalResidualVector[absoluteNodeIndex - 1] =\n frontalData.boundaryValues[absoluteNodeIndex - 1];\n }\n }\n }\n\n if (constrainedRowCount > 0) {\n for (let constrainedIndex = 0; constrainedIndex < constrainedRowCount; constrainedIndex++) {\n let rowIndex = modifiedRows[constrainedIndex] - 1;\n let globalNodeIndex = Math.abs(rowHeaders[rowIndex]);\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] = 0;\n let columnGlobalIndex = Math.abs(frontStorage.columnHeaders[columnIndex]);\n if (columnGlobalIndex === globalNodeIndex) frontMatrix[rowIndex][columnIndex] = 1;\n }\n }\n }\n\n if (availableColumnCount > summedRows || elementData.currentElementIndex < totalElements) {\n if (availableColumnCount === 0) {\n errorLog(\"Error: no more rows fully summed\");\n return;\n }\n\n let pivotRowIndex = pivotRowIndices[0];\n let pivotColumnIndex = pivotColumnIndices[0];\n let pivotValue = frontMatrix[pivotRowIndex - 1][pivotColumnIndex - 1];\n\n if (Math.abs(pivotValue) < 1e-4) {\n pivotValue = 0;\n for (let columnIndex = 0; columnIndex < availableColumnCount; columnIndex++) {\n let testColumnIndex = pivotColumnIndices[columnIndex];\n for (let rowIndex = 0; rowIndex < availableRowCount; rowIndex++) {\n let testRowIndex = pivotRowIndices[rowIndex];\n let testValue = frontMatrix[testRowIndex - 1][testColumnIndex - 1];\n if (Math.abs(testValue) > Math.abs(pivotValue)) {\n pivotValue = testValue;\n pivotColumnIndex = testColumnIndex;\n pivotRowIndex = testRowIndex;\n }\n }\n }\n }\n\n let pivotGlobalRowIndex = Math.abs(rowHeaders[pivotRowIndex - 1]);\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]); // Assign, don't declare\n let permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n if (nodeIndex >= pivotGlobalRowIndex) rowSwapCount[nodeIndex]--;\n if (nodeIndex >= pivotColumnGlobalIndex) columnSwapCount[nodeIndex]--;\n }\n\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontMatrix[pivotRowIndex - 1][columnIndex] / pivotValue;\n }\n\n let rightHandSide = frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] = rightHandSide;\n pivotColumn[pivotRowIndex - 1] = pivotValue;\n\n if (pivotRowIndex > 1) {\n for (let rowIndex = 0; rowIndex < pivotRowIndex - 1; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1 && eliminationFactor !== 0) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] -= eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n if (pivotRowIndex < rowCount) {\n for (let rowIndex = pivotRowIndex; rowIndex < rowCount; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = pivotColumn[i];\n }\n pivotDataIndex += rowCount;\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = rowHeaders[i];\n }\n pivotDataIndex += rowCount;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.pivotRow[i];\n }\n frontDataCounter += columnCount;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.columnHeaders[i];\n }\n frontDataCounter += columnCount;\n\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n frontMatrix[rowIndex][columnCount - 1] = 0;\n }\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowCount - 1][columnIndex] = 0;\n }\n\n columnCount--;\n if (pivotColumnIndex < columnCount + 1) {\n for (let columnIndex = pivotColumnIndex - 1; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] = frontStorage.columnHeaders[columnIndex + 1];\n }\n }\n\n rowCount--;\n if (pivotRowIndex < rowCount + 1) {\n for (let rowIndex = pivotRowIndex - 1; rowIndex < rowCount; rowIndex++) {\n rowHeaders[rowIndex] = rowHeaders[rowIndex + 1];\n }\n }\n\n if (rowCount > 1 || elementData.currentElementIndex < totalElements) continue;\n\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[0]); // Assign, don't declare\n pivotRowIndex = 1;\n pivotValue = frontMatrix[0][0];\n pivotGlobalRowIndex = Math.abs(rowHeaders[0]);\n pivotColumnIndex = 1;\n permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n frontStorage.pivotRow[0] = 1;\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] =\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.pivotRow[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.columnHeaders[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotColumn[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = rowHeaders[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n frontalState.frontDataIndex = frontDataCounter;\n if (frontalState.writeFlag === 1)\n debugLog(`total ecs transfer in matrix reduction=${frontDataCounter}`);\n\n // Back substitution\n performBackSubstitution(frontDataCounter);\n break;\n }\n }\n}\n\n/**\n * Function to perform back substitution for the frontal solver\n * @param {number} frontDataCounter - Index counter for the element contributions\n */\nfunction performBackSubstitution(frontDataCounter) {\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n frontalState.globalSolutionVector[nodeIndex] = frontalData.boundaryValues[nodeIndex];\n }\n\n for (let iterationIndex = 1; iterationIndex <= frontalState.totalNodes; iterationIndex++) {\n frontDataCounter -= 4;\n let pivotGlobalRowIndex = frontStorage.frontValues[frontDataCounter - 1];\n let columnCount = frontStorage.frontValues[frontDataCounter];\n let pivotColumnIndex = frontStorage.frontValues[frontDataCounter + 1];\n let pivotValue = frontStorage.frontValues[frontDataCounter + 2];\n\n if (iterationIndex === 1) {\n frontDataCounter--;\n frontStorage.columnHeaders[0] = frontStorage.frontValues[frontDataCounter - 1];\n frontDataCounter--;\n frontStorage.pivotRow[0] = frontStorage.frontValues[frontDataCounter - 1];\n } else {\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] =\n frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n }\n\n let pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]);\n if (frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] > 0) continue;\n\n let accumulatedValue = 0;\n frontStorage.pivotRow[pivotColumnIndex - 1] = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n accumulatedValue -=\n frontStorage.pivotRow[columnIndex] *\n frontalState.globalSolutionVector[Math.abs(frontStorage.columnHeaders[columnIndex]) - 1];\n }\n\n frontalState.globalSolutionVector[pivotColumnGlobalIndex - 1] =\n accumulatedValue + frontalData.globalResidualVector[pivotGlobalRowIndex - 1];\n\n frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] = 1;\n }\n\n if (frontalState.writeFlag === 1)\n debugLog(`value of frontDataCounter after backsubstitution=${frontDataCounter}`);\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { euclideanNorm } from \"../methods/euclideanNormScript.js\";\nimport { solveLinearSystem } from \"./linearSystemSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport { runFrontalSolver } from \"./frontalSolverScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\n\n/**\n * Function to solve a system of non-linear equations using the Newton-Raphson method\n * @param {function} assembleMat - Matrix assembler based on the physical model\n * @param {object} context - Context object containing simulation data and options\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\n\nexport function newtonRaphson(assembleMat, context = {}) {\n let errorNorm = 0;\n let converged = false;\n let iterations = 0;\n let deltaX = [];\n let solutionVector = [];\n let jacobianMatrix = [];\n let residualVector = [];\n\n // Extract context\n const { maxIterations = 100, tolerance = 1e-4 } = context;\n\n // Calculate system size\n let totalNodes = context.meshData.nodesXCoordinates.length;\n\n // Initialize arrays with proper size\n for (let i = 0; i < totalNodes; i++) {\n deltaX[i] = 0;\n solutionVector[i] = 0;\n }\n\n // Initialize solution from context if available\n if (context.initialSolution && context.initialSolution.length === totalNodes) {\n solutionVector = [...context.initialSolution];\n }\n\n while (iterations < maxIterations && !converged) {\n // Update solution\n for (let i = 0; i < solutionVector.length; i++) {\n solutionVector[i] = Number(solutionVector[i]) + Number(deltaX[i]);\n }\n\n // Check if using frontal solver\n if (context.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleFrontPropagationFront,\n context.meshData,\n context.boundaryConditions,\n { solutionVector, eikonalActivationFlag: context.eikonalActivationFlag }\n );\n deltaX = frontalResult.solutionVector;\n } else {\n // Compute Jacobian and residual matrices\n ({ jacobianMatrix, residualVector } = assembleMat(\n context.meshData,\n context.boundaryConditions,\n solutionVector, // The solution vector is required in the case of a non-linear equation\n context.eikonalActivationFlag // Currently used only in the front propagation solver (TODO refactor in case of a solver not needing it)\n ));\n\n // Solve the linear system based on the specified solver method\n const linearSystemResult = solveLinearSystem(context.solverMethod, jacobianMatrix, residualVector);\n deltaX = linearSystemResult.solutionVector;\n }\n\n // Check convergence\n errorNorm = euclideanNorm(deltaX);\n\n // Norm for each iteration\n basicLog(`Newton-Raphson iteration ${iterations + 1}: Error norm = ${errorNorm.toExponential(4)}`);\n\n if (errorNorm <= tolerance) {\n converged = true;\n } else if (errorNorm > 1e2) {\n errorLog(`Solution not converged. Error norm: ${errorNorm}`);\n break;\n }\n\n iterations++;\n }\n\n return {\n solutionVector,\n converged,\n iterations,\n jacobianMatrix,\n residualVector,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { newtonRaphson } from \"./methods/newtonRaphsonScript.js\";\nimport { solveLinearSystem } from \"./methods/linearSystemSolverScript.js\";\nimport { solveLinearSystemAsync } from \"./methods/linearSystemSolverScript.js\";\nimport { prepareMesh } from \"./mesh/meshUtilsScript.js\";\nimport { assembleFrontPropagationMat } from \"./models/frontPropagationScript.js\";\nimport { assembleGeneralFormPDEMat, assembleGeneralFormPDEFront } from \"./models/generalFormPDEScript.js\";\nimport { assembleHeatConductionMat, assembleHeatConductionFront } from \"./models/heatConductionScript.js\";\nimport { runFrontalSolver } from \"./methods/frontalSolverScript.js\";\nimport { basicLog, debugLog, warnLog, errorLog } from \"./utilities/loggingScript.js\";\n\n/**\n * Class to implement finite element analysis in JavaScript\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} meshConfig - Object containing computational mesh details\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containifng the solution vector and additional mesh information\n */\nexport class FEAScriptModel {\n constructor() {\n this.solverConfig = null;\n this.meshConfig = {};\n this.boundaryConditions = {};\n this.solverMethod = \"lusolve\"; // Default solver method\n this.coefficientFunctions = null; // Add storage for coefficient functions\n warnLog(\n \"FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE\"\n );\n basicLog(\"FEAScriptModel instance created\");\n }\n\n /**\n * Sets the solver configuration\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} [options] - Optional additional configuration\n */\n setSolverConfig(solverConfig, options = {}) {\n this.solverConfig = solverConfig;\n\n // Store coefficient functions if provided\n if (options?.coefficientFunctions) {\n this.coefficientFunctions = options.coefficientFunctions;\n debugLog(\"Coefficient functions set\");\n }\n // Only update if a value is provided, otherwise keep the default\n if (options?.maxIterations !== undefined) {\n this.maxIterations = options.maxIterations;\n }\n if (options?.tolerance !== undefined) {\n this.tolerance = options.tolerance;\n }\n\n debugLog(`Solver config set to: ${solverConfig}`);\n }\n\n setMeshConfig(meshConfig) {\n this.meshConfig = meshConfig;\n debugLog(`Mesh config set with dimensions: ${meshConfig.meshDimension}`);\n }\n\n addBoundaryCondition(boundaryKey, condition) {\n this.boundaryConditions[boundaryKey] = condition;\n debugLog(`Boundary condition added for boundary: ${boundaryKey}, type: ${condition[0]}`);\n }\n\n setSolverMethod(solverMethod) {\n this.solverMethod = solverMethod;\n debugLog(`Solver method set to: ${solverMethod}`);\n }\n\n /**\n * Function to solve the finite element problem synchronously\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing the solution vector and the coordinates of the mesh nodes\n */\n solve(options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n /**\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n let initialSolution = [];\n\n // Prepare the mesh\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n\n // Extract node coordinates from meshData\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n // Select and execute the appropriate solver based on solverConfig\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleHeatConductionFront,\n meshData,\n this.boundaryConditions\n );\n solutionVector = frontalResult.solutionVector;\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n } else if (this.solverConfig === \"frontPropagationScript\") {\n // Initialize eikonalActivationFlag\n let eikonalActivationFlag = 0;\n const eikonalExteralIterations = 5; // Number of incremental steps for the eikonal equation\n\n // Create context object with all necessary properties\n const context = {\n meshData: meshData,\n boundaryConditions: this.boundaryConditions,\n eikonalActivationFlag: eikonalActivationFlag,\n solverMethod: this.solverMethod,\n initialSolution,\n // TODO: Consider using different maxIterations/tolerance for Newton-Raphson and linear solver\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n };\n\n while (eikonalActivationFlag <= 1) {\n // Update the context object with current eikonalActivationFlag\n context.eikonalActivationFlag = eikonalActivationFlag;\n\n // Pass the previous solution as initial guess\n if (solutionVector.length > 0) {\n context.initialSolution = [...solutionVector];\n }\n\n // Solve the assembled non-linear system\n const newtonRaphsonResult = newtonRaphson(assembleFrontPropagationMat, context);\n\n // Extract results\n jacobianMatrix = newtonRaphsonResult.jacobianMatrix;\n residualVector = newtonRaphsonResult.residualVector;\n solutionVector = newtonRaphsonResult.solutionVector;\n\n // Increment for next iteration\n eikonalActivationFlag += 1 / eikonalExteralIterations;\n }\n } else if (this.solverConfig === \"generalFormPDEScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n errorLog(\n \"Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.\"\n );\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(\n meshData,\n this.boundaryConditions,\n this.coefficientFunctions\n ));\n\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n /**\n * Function to solve the finite element problem asynchronously\n * @param {object} computeEngine - The compute engine to use for the asynchronous solver (e.g., a worker or a WebGPU context)\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing the solution vector and the coordinates of the mesh nodes\n */\n async solveAsync(computeEngine, options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n\n if (this.solverMethod === \"jacobi-gpu\") {\n const { solutionVector: x } = await solveLinearSystemAsync(\"jacobi-gpu\", jacobianMatrix, residualVector, {\n computeEngine,\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = x;\n } else {\n // Other async solver\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { initializeFEA, performIsoparametricMapping1D } from \"../mesh/meshUtilsScript.js\";\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the general form PDE model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} coefficientFunctions - Functions A(x), B(x), C(x), D(x) for the PDE\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleGeneralFormPDEMat(meshData, boundaryConditions, coefficientFunctions) {\n basicLog(\"Starting general form PDE matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Extract coefficient functions\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Convert to 0-based indexing\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];\n\n // Source term contribution to residual vector\n residualVector[globalNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n const globalNodeIndex2 = localToGlobalMap[localNodeIndex2];\n\n // Diffusion term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEMat.\");\n // 2D general form PDE - empty for now\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Apply Dirichlet boundary conditions only\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n\n basicLog(\"General form PDE matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the frontal solver matrix for the general form PDE model\n * @param {object} data - Object containing element data for the frontal solver\n * @returns {object} An object containing local Jacobian matrix and residual vector\n */\nexport function assembleGeneralFormPDEFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n coefficientFunctions,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of local Jacobian matrix and residual vector\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n // Source term contribution to local residual vector\n localResidualVector[localNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Diffusion term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEFront.\");\n // 2D general form PDE - empty for now\n }\n\n return {\n localJacobianMatrix,\n localResidualVector,\n ngl,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// External imports\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n// Internal imports\nimport { basicLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to facilitate communication with web workers for FEAScript operations\n */\nexport class FEAScriptWorker {\n /**\n * Constructor to initialize the FEAScriptWorker class\n * Sets up the worker and initializes the workerWrapper.\n */\n constructor() {\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n\n this._initWorker();\n }\n\n /**\n * Function to initialize the web worker and wrap it using Comlink.\n * @private\n * @throws Will throw an error if the worker fails to initialize.\n */\n async _initWorker() {\n try {\n this.worker = new Worker(new URL(\"./wrapperScript.js\", import.meta.url), {\n type: \"module\",\n });\n\n this.worker.onerror = (event) => {\n console.error(\"FEAScriptWorker: Worker error:\", event);\n };\n const workerWrapper = Comlink.wrap(this.worker);\n\n this.feaWorker = await new workerWrapper();\n\n this.isReady = true;\n } catch (error) {\n console.error(\"Failed to initialize worker\", error);\n throw error;\n }\n }\n\n /**\n * Function to ensure that the worker is ready before performing any operations.\n * @private\n * @returns {Promise} Resolves when the worker is ready.\n * @throws Will throw an error if the worker is not ready within the timeout period.\n */\n async _ensureReady() {\n if (this.isReady) return Promise.resolve();\n\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds max\n\n const checkReady = () => {\n attempts++;\n if (this.isReady) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(\"Timeout waiting for worker to be ready\"));\n } else {\n setTimeout(checkReady, 1000);\n }\n };\n checkReady();\n });\n }\n\n /**\n * Function to set the solver configuration in the worker.\n * @param {string} solverConfig - The solver configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setSolverConfig(solverConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver config to: ${solverConfig}`);\n return this.feaWorker.setSolverConfig(solverConfig);\n }\n\n /**\n * Sets the mesh configuration in the worker.\n * @param {object} meshConfig - The mesh configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setMeshConfig(meshConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting mesh config`);\n return this.feaWorker.setMeshConfig(meshConfig);\n }\n\n /**\n * Adds a boundary condition to the worker.\n * @param {string} boundaryKey - The key identifying the boundary.\n * @param {array} condition - The boundary condition to add.\n * @returns {Promise} Resolves when the boundary condition is added.\n */\n async addBoundaryCondition(boundaryKey, condition) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Adding boundary condition for boundary: ${boundaryKey}`);\n return this.feaWorker.addBoundaryCondition(boundaryKey, condition);\n }\n\n /**\n * Sets the solver method in the worker.\n * @param {string} solverMethod - The solver method to set.\n * @returns {Promise} Resolves when the solver method is set.\n */\n async setSolverMethod(solverMethod) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver method to: ${solverMethod}`);\n return this.feaWorker.setSolverMethod(solverMethod);\n }\n\n /**\n * Requests the worker to solve the problem.\n * @returns {Promise} Resolves with the solution result.\n */\n async solve() {\n await this._ensureReady();\n basicLog(\"FEAScriptWorker: Requesting solution from worker...\");\n\n const startTime = performance.now();\n const result = await this.feaWorker.solve();\n const endTime = performance.now();\n\n basicLog(`FEAScriptWorker: Solution completed in ${((endTime - startTime) / 1000).toFixed(2)}s`);\n return result;\n }\n\n /**\n * Retrieves model information from the worker.\n * @returns {Promise} Resolves with the model information.\n */\n async getModelInfo() {\n await this._ensureReady();\n return this.feaWorker.getModelInfo();\n }\n\n /**\n * Sends a ping request to the worker to check its availability.\n * @returns {Promise} Resolves if the worker responds.\n */\n async ping() {\n await this._ensureReady();\n return this.feaWorker.ping();\n }\n\n /**\n * Terminates the worker and cleans up resources.\n */\n terminate() {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements\n * @param {File} file - The Gmsh file to be parsed (.msh version 4.1)\n * @returns {object} The parsed mesh data including node coordinates, element connectivity, and boundary conditions\n */\nconst importGmshQuadTri = async (file) => {\n let result = {\n nodesXCoordinates: [],\n nodesYCoordinates: [],\n nodalNumbering: {\n quadElements: [],\n triangleElements: [],\n },\n boundaryElements: [],\n boundaryConditions: [],\n boundaryNodePairs: {}, // Store boundary node pairs for processing in meshGenerationScript\n gmshV: 0,\n ascii: false,\n fltBytes: \"8\",\n totalNodesX: 0,\n totalNodesY: 0,\n physicalPropMap: [],\n elementTypes: {},\n };\n\n let content = await file.text();\n let lines = content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line !== \"\" && line !== \" \");\n\n let section = \"\";\n let lineIndex = 0;\n\n let nodeEntityBlocks = 0;\n let totalNodes = 0;\n let nodeBlocksProcessed = 0;\n let currentNodeBlock = { numNodes: 0 };\n let nodeTagsCollected = 0;\n let nodeTags = [];\n let nodeCoordinatesCollected = 0;\n\n let elementEntityBlocks = 0;\n let totalElements = 0;\n let elementBlocksProcessed = 0;\n let currentElementBlock = {\n dim: 0,\n tag: 0,\n elementType: 0,\n numElements: 0,\n };\n let elementsProcessedInBlock = 0;\n\n let boundaryElementsByTag = {};\n\n while (lineIndex < lines.length) {\n const line = lines[lineIndex];\n\n if (line === \"$MeshFormat\") {\n section = \"meshFormat\";\n lineIndex++;\n continue;\n } else if (line === \"$EndMeshFormat\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$PhysicalNames\") {\n section = \"physicalNames\";\n lineIndex++;\n continue;\n } else if (line === \"$EndPhysicalNames\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Entities\") {\n section = \"entities\";\n lineIndex++;\n continue;\n } else if (line === \"$EndEntities\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Nodes\") {\n section = \"nodes\";\n lineIndex++;\n continue;\n } else if (line === \"$EndNodes\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Elements\") {\n section = \"elements\";\n lineIndex++;\n continue;\n } else if (line === \"$EndElements\") {\n section = \"\";\n lineIndex++;\n continue;\n }\n\n const parts = line.split(/\\s+/).filter((part) => part !== \"\");\n\n if (section === \"meshFormat\") {\n result.gmshV = parseFloat(parts[0]);\n result.ascii = parts[1] === \"0\";\n result.fltBytes = parts[2];\n } else if (section === \"physicalNames\") {\n if (parts.length >= 3) {\n if (!/^\\d+$/.test(parts[0])) {\n lineIndex++;\n continue;\n }\n\n const dimension = parseInt(parts[0], 10);\n const tag = parseInt(parts[1], 10);\n let name = parts.slice(2).join(\" \");\n name = name.replace(/^\"|\"$/g, \"\");\n\n result.physicalPropMap.push({\n tag,\n dimension,\n name,\n });\n }\n } else if (section === \"nodes\") {\n if (nodeEntityBlocks === 0) {\n nodeEntityBlocks = parseInt(parts[0], 10);\n totalNodes = parseInt(parts[1], 10);\n result.nodesXCoordinates = new Array(totalNodes).fill(0);\n result.nodesYCoordinates = new Array(totalNodes).fill(0);\n lineIndex++;\n continue;\n }\n\n if (nodeBlocksProcessed < nodeEntityBlocks && currentNodeBlock.numNodes === 0) {\n currentNodeBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n parametric: parseInt(parts[2], 10),\n numNodes: parseInt(parts[3], 10),\n };\n\n nodeTags = [];\n nodeTagsCollected = 0;\n nodeCoordinatesCollected = 0;\n\n lineIndex++;\n continue;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n for (let i = 0; i < parts.length && nodeTagsCollected < currentNodeBlock.numNodes; i++) {\n nodeTags.push(parseInt(parts[i], 10));\n nodeTagsCollected++;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n lineIndex++;\n continue;\n }\n\n lineIndex++;\n continue;\n }\n\n if (nodeCoordinatesCollected < currentNodeBlock.numNodes) {\n const nodeTag = nodeTags[nodeCoordinatesCollected] - 1;\n const x = parseFloat(parts[0]);\n const y = parseFloat(parts[1]);\n\n result.nodesXCoordinates[nodeTag] = x;\n result.nodesYCoordinates[nodeTag] = y;\n result.totalNodesX++;\n result.totalNodesY++;\n\n nodeCoordinatesCollected++;\n\n if (nodeCoordinatesCollected === currentNodeBlock.numNodes) {\n nodeBlocksProcessed++;\n currentNodeBlock = { numNodes: 0 };\n }\n }\n } else if (section === \"elements\") {\n if (elementEntityBlocks === 0) {\n elementEntityBlocks = parseInt(parts[0], 10);\n totalElements = parseInt(parts[1], 10);\n lineIndex++;\n continue;\n }\n\n if (elementBlocksProcessed < elementEntityBlocks && currentElementBlock.numElements === 0) {\n currentElementBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n elementType: parseInt(parts[2], 10),\n numElements: parseInt(parts[3], 10),\n };\n\n result.elementTypes[currentElementBlock.elementType] =\n (result.elementTypes[currentElementBlock.elementType] || 0) + currentElementBlock.numElements;\n\n elementsProcessedInBlock = 0;\n lineIndex++;\n continue;\n }\n\n if (elementsProcessedInBlock < currentElementBlock.numElements) {\n const elementTag = parseInt(parts[0], 10);\n const nodeIndices = parts.slice(1).map((idx) => parseInt(idx, 10));\n\n if (currentElementBlock.elementType === 1 || currentElementBlock.elementType === 8) {\n const physicalTag = currentElementBlock.tag;\n\n if (!boundaryElementsByTag[physicalTag]) {\n boundaryElementsByTag[physicalTag] = [];\n }\n\n boundaryElementsByTag[physicalTag].push(nodeIndices);\n\n // Store boundary node pairs for later processing in meshGenerationScript\n if (!result.boundaryNodePairs[physicalTag]) {\n result.boundaryNodePairs[physicalTag] = [];\n }\n result.boundaryNodePairs[physicalTag].push(nodeIndices);\n } else if (currentElementBlock.elementType === 2) {\n // Linear triangle elements (3 nodes)\n result.nodalNumbering.triangleElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 3) {\n // Linear quadrilateral elements (4 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 10) {\n // Quadratic quadrilateral elements (9 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n }\n\n elementsProcessedInBlock++;\n\n if (elementsProcessedInBlock === currentElementBlock.numElements) {\n elementBlocksProcessed++;\n currentElementBlock = { numElements: 0 };\n }\n }\n }\n\n lineIndex++;\n }\n\n // Store boundary conditions information\n result.physicalPropMap.forEach((prop) => {\n if (prop.dimension === 1) {\n const boundaryNodes = boundaryElementsByTag[prop.tag] || [];\n\n if (boundaryNodes.length > 0) {\n result.boundaryConditions.push({\n name: prop.name,\n tag: prop.tag,\n nodes: boundaryNodes,\n });\n }\n }\n });\n\n debugLog(\n `Parsed boundary node pairs by physical tag: ${JSON.stringify(\n result.boundaryNodePairs\n )}. These pairs will be used to identify boundary elements in the mesh.`\n );\n\n return result;\n};\n\nexport { importGmshQuadTri };\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to create plots of the solution vector\n * @param {*} solutionVector - The computed solution vector\n * @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {string} meshDimension - The dimension of the solution\n * @param {string} plotType - The type of plot\n * @param {string} plotDivId - The id of the div where the plot will be rendered\n * @param {string} [meshType=\"structured\"] - Type of mesh: \"structured\" or \"unstructured\"\n */\nexport function plotSolution(\n solutionVector,\n nodesCoordinates,\n solverConfig,\n meshDimension,\n plotType,\n plotDivId,\n meshType = \"structured\"\n) {\n const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;\n\n if (meshDimension === \"1D\" && plotType === \"line\") {\n // Check if solutionVector is a nested array\n let yData;\n if (solutionVector.length > 0 && Array.isArray(solutionVector[0])) {\n yData = solutionVector.map((arr) => arr[0]);\n } else {\n yData = solutionVector;\n }\n let xData = Array.from(nodesXCoordinates);\n\n let lineData = {\n x: xData,\n y: yData,\n mode: \"lines\",\n type: \"scatter\",\n line: { color: \"rgb(219, 64, 82)\", width: 2 },\n name: \"Solution\",\n };\n\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxPlotWidth = Math.max(...xData);\n let zoomFactor = maxWindowWidth / maxPlotWidth;\n let plotWidth = Math.max(zoomFactor * maxPlotWidth, 400);\n let plotHeight = 350;\n\n let layout = {\n title: `line plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"Solution\" },\n margin: { l: 70, r: 40, t: 50, b: 50 },\n };\n\n Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });\n } else if (meshDimension === \"2D\" && plotType === \"contour\") {\n // Use the user-provided mesh type\n const isStructured = meshType === \"structured\";\n\n // For auto-detection (if needed)\n const uniqueXCoords = new Set(nodesXCoordinates).size;\n const uniqueYCoords = new Set(nodesYCoordinates).size;\n\n // Extract scalar values from solution vector\n let zValues;\n if (Array.isArray(solutionVector[0])) {\n zValues = solutionVector.map((val) => val[0]);\n } else {\n zValues = solutionVector;\n }\n\n // Common sizing parameters for both plot types\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxX = Math.max(...nodesXCoordinates);\n let maxY = Math.max(...nodesYCoordinates);\n let aspectRatio = maxY / maxX;\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = plotWidth * aspectRatio * 0.8; // Slightly reduce height for better appearance\n\n // Common layout properties\n let layout = {\n title: `${plotType} plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"y\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n hovermode: \"closest\",\n };\n\n if (isStructured) {\n // Calculate the number of nodes along the x-axis and y-axis\n const numNodesX = uniqueXCoords;\n const numNodesY = uniqueYCoords;\n\n // Reshape the nodesXCoordinates and nodesYCoordinates arrays to match the grid dimensions\n let reshapedXCoordinates = math.reshape(Array.from(nodesXCoordinates), [numNodesX, numNodesY]);\n let reshapedYCoordinates = math.reshape(Array.from(nodesYCoordinates), [numNodesX, numNodesY]);\n\n // Reshape the solution array to match the grid dimensions\n let reshapedSolution = math.reshape(Array.from(solutionVector), [numNodesX, numNodesY]);\n\n // Transpose the reshapedSolution array to get column-wise data\n let transposedSolution = math.transpose(reshapedSolution);\n\n // Create an array for x-coordinates used in the contour plot\n let reshapedXForPlot = [];\n for (let i = 0; i < numNodesX * numNodesY; i += numNodesY) {\n let xValue = nodesXCoordinates[i];\n reshapedXForPlot.push(xValue);\n }\n\n // Create the data structure for the contour plot\n let contourData = {\n z: transposedSolution,\n type: \"contour\",\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n x: reshapedXForPlot,\n y: reshapedYCoordinates[0],\n name: \"Solution Field\",\n };\n\n // Create the plot using Plotly\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n } else {\n // Create an interpolated contour plot for the unstructured mesh\n let contourData = {\n x: nodesXCoordinates,\n y: nodesYCoordinates,\n z: zValues,\n type: \"contour\",\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n name: \"Solution Field\",\n };\n\n // Create the plot using only the contour fill\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nexport { FEAScriptModel } from \"./FEAScript.js\";\nexport { importGmshQuadTri } from \"./readers/gmshReaderScript.js\";\nexport { logSystem } from \"./utilities/loggingScript.js\";\nexport { plotSolution } from \"./visualization/plotSolutionScript.js\";\nexport { FEAScriptWorker } from \"./workers/workerScript.js\";\nexport const printVersion = \"0.1.4\";"],"names":["euclideanNorm","vector","norm","i","length","Math","sqrt","currentLogLevel","debugLog","message","console","log","basicLog","errorLog","proxyMarker","Symbol","createEndpoint","releaseProxy","finalizer","throwMarker","isObject","val","transferHandlers","Map","canHandle","serialize","obj","port1","port2","MessageChannel","expose","deserialize","port","start","wrap","value","serialized","Error","isError","name","stack","Object","assign","ep","globalThis","allowedOrigins","addEventListener","callback","ev","data","origin","allowedOrigin","RegExp","test","isAllowedOrigin","warn","id","type","path","argumentList","map","fromWireValue","returnValue","parent","slice","reduce","prop","rawValue","apply","proxy","transfers","transferCache","set","transfer","undefined","Promise","resolve","catch","then","wireValue","transferables","toWireValue","postMessage","removeEventListener","closeEndPoint","error","TypeError","endpoint","constructor","isMessagePort","close","target","pendingListeners","resolver","get","delete","createProxy","throwIfProxyReleased","isReleased","releaseEndpoint","requestResponseMessage","proxyCounter","WeakMap","proxyFinalizers","FinalizationRegistry","newCount","isProxyReleased","Proxy","_target","unregister","unregisterProxy","clear","r","p","toString","bind","_thisArg","rawArgumentList","last","processArguments","construct","register","registerProxy","processed","v","arr","Array","prototype","concat","handler","serializedValue","msg","fill","floor","random","Number","MAX_SAFE_INTEGER","join","solveLinearSystem","solverMethod","jacobianMatrix","residualVector","options","maxIterations","tolerance","solutionVector","converged","iterations","time","jacobianMatrixSparse","math","sparse","luFactorization","slu","solutionMatrix","lusolve","squeeze","valueOf","jacobiSolverResult","A","b","x0","n","x","xNew","iter","sum","j","maxDiff","max","abs","jacobiSolver","timeEnd","async","solveLinearSystemAsync","isArray","toArray","created","computeEngine","worker","Worker","URL","document","location","require","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","Comlink.wrap","initialize","createDefaultComputeEngine","result","webgpuJacobiSolver","destroy","terminate","BasisFunctions","meshDimension","elementOrder","this","getBasisFunctions","ksi","eta","basisFunction","basisFunctionDerivKsi","basisFunctionDerivEta","l1","c","l2","l3","dl1","dl2","dl3","Mesh","numElementsX","maxX","numElementsY","maxY","parsedMesh","boundaryElementsProcessed","parseMeshFromGmsh","nodalNumbering","quadElements","triangleElements","JSON","stringify","elementTypes","mappedNodalNumbering","elemIdx","gmshNodes","feaScriptNodes","push","physicalPropMap","boundaryElements","fixedBoundaryElements","boundaryNodePairs","forEach","dimension","tag","nodesPair","node1","node2","foundElement","elemNodes","includes","side","node1Index","indexOf","node2Index","Mesh1D","super","generateMesh","nodesXCoordinates","totalNodesX","deltaX","nodeIndex","generate1DNodalNumbering","findBoundaryElements","nop","elementIndex","columnCounter","sideIndex","Mesh2D","nodesYCoordinates","totalNodesY","deltaY","nodeIndexY","nodeIndexX","nnode","generate2DNodalNumbering","rowCounter","elementIndexX","elementIndexY","nodeIndex1","nodeIndex2","NumericalIntegration","getGaussPointsAndWeights","gaussPoints","gaussWeights","prepareMesh","meshConfig","mesh","nodesCoordinatesAndNumbering","totalElements","totalNodes","initializeFEA","meshData","colIndex","basisFunctions","gaussPointsAndWeights","localToGlobalMap","numNodes","performIsoparametricMapping1D","params","xCoordinates","ksiDerivX","localNodeIndex","detJacobian","basisFunctionDerivX","performIsoparametricMapping2D","yCoordinates","etaDerivX","ksiDerivY","etaDerivY","basisFunctionDerivY","ThermalBoundaryConditions","boundaryConditions","imposeConstantTempBoundaryConditions","keys","boundaryKey","tempValue","globalNodeIndex","imposeConstantTempBoundaryConditionsFront","nodeConstraintCode","boundaryValues","imposeConvectionBoundaryConditions","convectionHeatTranfCoeff","convectionExtTemp","key","boundaryCondition","convectionCoeff","extTemp","gaussPoint1","gaussPoint2","firstNodeIndex","lastNodeIndex","nodeIncrement","basisFunctionsAndDerivatives","tangentVectorLength","localNodeIndex2","globalNodeIndex2","gaussPointIndex","imposeConvectionBoundaryConditionsFront","localJacobianMatrix","localResidualVector","boundaryElement","find","_","assembleHeatConductionMat","FEAData","gaussPointIndex1","mappingResult","localNodeIndex1","localToGlobalMap1","localToGlobalMap2","gaussPointIndex2","thermalBoundaryConditions","assembleHeatConductionFront","ngl","globalIndex","GenericBoundaryConditions","imposeDirichletBoundaryConditions","imposeConstantValueBoundaryConditionsFront","assembleFrontPropagationMat","eikonalActivationFlag","eikonalViscousTerm","solutionDerivX","solutionDerivY","assembleFrontPropagationFront","frontalData","frontalState","elementData","currentElementIndex","frontStorage","runFrontalSolver","assembleFront","numElements","globalResidualVector","topologyData","lateralData","writeFlag","transformationFlag","nodesPerElement","determinant","systemSize","globalSolutionVector","frontDataIndex","frontSize","frontWidthEstimate","ceil","estimateFrontSize","frontValues","columnHeaders","pivotRow","pivotData","initializeFrontalArrays","dirichletBoundaryConditionsHandler","currentSolutionVector","pivotColumnGlobalIndex","localDestination","rowDestination","rowHeaders","pivotRowIndices","pivotColumnIndices","modifiedRows","pivotColumn","frontMatrix","rowSwapCount","columnSwapCount","lastAppearanceCheck","frontDataCounter","pivotDataIndex","summedRows","reverseElementIndex","columnCount","rowCount","assembled","numElementNodes","numElementColumns","assembleElementContribution","currentElement","columnIndex","rowIndex","localColumnIndex","frontColumnIndex","localRowIndex","availableColumnCount","constrainedRowCount","availableRowCount","absoluteNodeIndex","constrainedIndex","pivotRowIndex","pivotColumnIndex","pivotValue","testColumnIndex","testRowIndex","testValue","pivotGlobalRowIndex","permutationHelper","rightHandSide","globalRowIndex","eliminationFactor","performBackSubstitution","runFrontalAlgorithm","toExponential","finalNodesX","finalNodesY","nodesCoordinates","boundaryLocalJacobianMatrix","boundaryResidualVector","isOnRobinTypeBoundary","some","localNodeI","localNodeJ","iterationIndex","accumulatedValue","newtonRaphson","assembleMat","context","errorNorm","initialSolution","solverConfig","coefficientFunctions","setSolverConfig","setMeshConfig","addBoundaryCondition","condition","setSolverMethod","solve","eikonalExteralIterations","newtonRaphsonResult","B","C","D","xCoord","a","d","globalNodeIndex1","assembleGeneralFormPDEMat","solveAsync","feaWorker","isReady","_initWorker","onerror","event","workerWrapper","_ensureReady","reject","attempts","checkReady","setTimeout","startTime","performance","now","toFixed","getModelInfo","ping","file","gmshV","ascii","fltBytes","lines","text","split","line","trim","filter","section","lineIndex","nodeEntityBlocks","nodeBlocksProcessed","currentNodeBlock","nodeTagsCollected","nodeTags","nodeCoordinatesCollected","elementEntityBlocks","elementBlocksProcessed","currentElementBlock","dim","elementType","elementsProcessedInBlock","boundaryElementsByTag","parts","part","parseFloat","parseInt","replace","parametric","nodeTag","y","nodeIndices","idx","physicalTag","boundaryNodes","nodes","level","plotType","plotDivId","meshType","yData","xData","from","lineData","mode","color","width","maxWindowWidth","min","window","innerWidth","maxPlotWidth","zoomFactor","layout","title","height","xaxis","yaxis","margin","l","t","Plotly","newPlot","responsive","isStructured","uniqueXCoords","Set","size","uniqueYCoords","zValues","aspectRatio","plotWidth","hovermode","numNodesX","numNodesY","reshape","reshapedYCoordinates","reshapedSolution","transposedSolution","transpose","reshapedXForPlot","xValue","contourData","z","contours","coloring","showlabels","colorbar"],"mappings":"oyBAaO,SAASA,EAAcC,GAC5B,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,OAAQD,IACjCD,GAAQD,EAAOE,GAAKF,EAAOE,GAG7B,OADAD,EAAOG,KAAKC,KAAKJ,GACVA,CACT,CCXA,IAAIK,EAAkB,QAuBf,SAASC,EAASC,GACC,UAApBF,GACFG,QAAQC,IAAI,aAAeF,EAAS,qCAExC,CAMO,SAASG,EAASH,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AAO,YAET3f,KAAM,kBAIRkgB,OAAOC,QAAQxB,EAAW,CAAC4C,GAAc7B,EAAQ,CAAEU,YAAY,GAChE,CACF,CACH,iBCrJ4B"} \ No newline at end of file +{"version":3,"file":"feascript.umd.js","sources":["../src/methods/euclideanNormScript.js","../src/utilities/loggingScript.js","../src/vendor/comlink.mjs","../src/methods/linearSystemSolverScript.js","../src/methods/jacobiSolverScript.js","../src/mesh/basisFunctionsScript.js","../src/mesh/meshGenerationScript.js","../src/methods/numericalIntegrationScript.js","../src/mesh/meshUtilsScript.js","../src/models/thermalBoundaryConditionsScript.js","../src/models/heatConductionScript.js","../src/models/genericBoundaryConditionsScript.js","../src/models/frontPropagationScript.js","../src/methods/frontalSolverScript.js","../src/methods/newtonRaphsonScript.js","../src/FEAScript.js","../src/models/generalFormPDEScript.js","../src/workers/workerScript.js","../src/readers/gmshReaderScript.js","../src/visualization/plotSolutionScript.js","../src/index.js"],"sourcesContent":["/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to calculate the Euclidean norm of a vector\n * @param {array} vector - The input vector\n * @returns {number} The Euclidean norm of the vector\n */\nexport function euclideanNorm(vector) {\n let norm = 0;\n for (let i = 0; i < vector.length; i++) {\n norm += vector[i] * vector[i];\n }\n norm = Math.sqrt(norm);\n return norm;\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Global logging level\nlet currentLogLevel = \"basic\";\n\n/**\n * Function to set the logging system level\n * @param {string} level - Logging level (basic, debug)\n */\nexport function logSystem(level) {\n if (level !== \"basic\" && level !== \"debug\") {\n console.log(\n \"%c[WARN] Invalid log level: \" + level + \". Using basic instead.\",\n \"color: #FFC107; font-weight: bold;\"\n ); // Yellow for warnings\n currentLogLevel = \"basic\";\n } else {\n currentLogLevel = level;\n basicLog(`Log level set to: ${level}`);\n }\n}\n\n/**\n * Function to log debug messages - only logs if level is 'debug'\n * @param {string} message - Message to log\n */\nexport function debugLog(message) {\n if (currentLogLevel === \"debug\") {\n console.log(\"%c[DEBUG] \" + message, \"color: #2196F3; font-weight: bold;\");\n }\n}\n\n/**\n * Function to log basic information - always logs\n * @param {string} message - Message to log\n */\nexport function basicLog(message) {\n console.log(\"%c[INFO] \" + message, \"color: #4CAF50; font-weight: bold;\");\n}\n\n/**\n * Function to log error messages\n * @param {string} message - Message to log\n */\nexport function errorLog(message) {\n console.log(\"%c[ERROR] \" + message, \"color: #F44336; font-weight: bold;\");\n}\n\n/**\n * Function to log warning messages\n * @param {string} message - Message to log\n */\nexport function warnLog(message) {\n console.log(\"%c[WARN] \" + message, \"color: #FF9800; font-weight: bold;\");\n}\n\n/**\n * Function to handle version information and fetch the latest update date and release from GitHub\n */\nexport async function printVersionInformation() {\n basicLog(\"Fetching latest FEAScript version information...\");\n try {\n const commitResponse = await fetch(\"https://api.github.com/repos/FEAScript/FEAScript/commits/main\");\n const commitData = await commitResponse.json();\n const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();\n basicLog(`Latest FEAScript update: ${latestCommitDate}`);\n return latestCommitDate;\n } catch (error) {\n errorLog(\"Failed to fetch version information: \" + error);\n return \"Version information unavailable\";\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\nconst proxyMarker = Symbol(\"Comlink.proxy\");\nconst createEndpoint = Symbol(\"Comlink.endpoint\");\nconst releaseProxy = Symbol(\"Comlink.releaseProxy\");\nconst finalizer = Symbol(\"Comlink.finalizer\");\nconst throwMarker = Symbol(\"Comlink.thrown\");\nconst isObject = (val) => (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n }\n else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n },\n};\n/**\n * Allows customizing the serialization of certain values.\n */\nconst transferHandlers = new Map([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\nfunction isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\nfunction expose(obj, ep = globalThis, allowedOrigins = [\"*\"]) {\n ep.addEventListener(\"message\", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case \"GET\" /* MessageType.GET */:\n {\n returnValue = rawValue;\n }\n break;\n case \"SET\" /* MessageType.SET */:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case \"APPLY\" /* MessageType.APPLY */:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case \"CONSTRUCT\" /* MessageType.CONSTRUCT */:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case \"ENDPOINT\" /* MessageType.ENDPOINT */:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case \"RELEASE\" /* MessageType.RELEASE */:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n }\n catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === \"RELEASE\" /* MessageType.RELEASE */) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n}\nfunction isMessagePort(endpoint) {\n return endpoint.constructor.name === \"MessagePort\";\n}\nfunction closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n}\nfunction wrap(ep, target) {\n const pendingListeners = new Map();\n ep.addEventListener(\"message\", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n }\n finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n}\nfunction throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\nfunction releaseEndpoint(ep) {\n return requestResponseMessage(ep, new Map(), {\n type: \"RELEASE\" /* MessageType.RELEASE */,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\nconst proxyCounter = new WeakMap();\nconst proxyFinalizers = \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\nfunction registerProxy(proxy, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\nfunction unregisterProxy(proxy) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\nfunction createProxy(ep, pendingListeners, path = [], target = function () { }) {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: \"GET\" /* MessageType.GET */,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"SET\" /* MessageType.SET */,\n path: [...path, prop].map((p) => p.toString()),\n value,\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: \"ENDPOINT\" /* MessageType.ENDPOINT */,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"APPLY\" /* MessageType.APPLY */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: \"CONSTRUCT\" /* MessageType.CONSTRUCT */,\n path: path.map((p) => p.toString()),\n argumentList,\n }, transferables).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy;\n}\nfunction myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n}\nfunction processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\nconst transferCache = new WeakMap();\nfunction transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n}\nfunction proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n}\nfunction windowEndpoint(w, context = globalThis, targetOrigin = \"*\") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\nfunction toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: \"HANDLER\" /* WireValueType.HANDLER */,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: \"RAW\" /* WireValueType.RAW */,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\nfunction fromWireValue(value) {\n switch (value.type) {\n case \"HANDLER\" /* WireValueType.HANDLER */:\n return transferHandlers.get(value.name).deserialize(value.value);\n case \"RAW\" /* WireValueType.RAW */:\n return value.value;\n }\n}\nfunction requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n}\nfunction generateUUID() {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n\nexport { createEndpoint, expose, finalizer, proxy, proxyMarker, releaseProxy, transfer, transferHandlers, windowEndpoint, wrap };\n//# sourceMappingURL=comlink.mjs.map\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { jacobiSolver } from \"./jacobiSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n/**\n * Function to solve a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (\"lusolve\" or \"jacobi\")\n * @param {Array} jacobianMatrix - The coefficient matrix\n * @param {Array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport function solveLinearSystem(solverMethod, jacobianMatrix, residualVector, options = {}) {\n\n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n let solutionVector = [];\n let converged = true;\n let iterations = 0;\n\n // Solve the linear system based on the specified solver method\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n if (solverMethod === \"lusolve\") {\n // Use LU decomposition method\n const jacobianMatrixSparse = math.sparse(jacobianMatrix);\n const luFactorization = math.slu(jacobianMatrixSparse, 1, 1); // order=1, threshold=1 for pivoting\n let solutionMatrix = math.lusolve(luFactorization, residualVector);\n solutionVector = math.squeeze(solutionMatrix).valueOf();\n //solutionVector = math.lusolve(jacobianMatrix, residualVector); // In the case of a dense matrix\n } else if (solverMethod === \"jacobi\") {\n // Use Jacobi method\n const initialGuess = new Array(residualVector.length).fill(0);\n const jacobiSolverResult = jacobiSolver(jacobianMatrix, residualVector, initialGuess, {\n maxIterations,\n tolerance,\n });\n\n // Log convergence information\n if (jacobiSolverResult.converged) {\n debugLog(`Jacobi method converged in ${jacobiSolverResult.iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${jacobiSolverResult.iterations} iterations`);\n }\n\n solutionVector = jacobiSolverResult.solutionVector;\n converged = jacobiSolverResult.converged;\n iterations = jacobiSolverResult.iterations;\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n return { solutionVector, converged, iterations };\n}\n\n// Helper to lazily create a default WebGPU compute engine (Comlink + worker)\nasync function createDefaultComputeEngine() {\n const worker = new Worker(new URL(\"../workers/webgpuWorkerScript.js\", import.meta.url), {\n type: \"module\",\n });\n const computeEngine = Comlink.wrap(worker);\n await computeEngine.initialize();\n return { computeEngine, worker };\n}\n\n/**\n * Function to solve asynchronously a system of linear equations using different solver methods\n * @param {string} solverMethod - The solver method to use (e.g., \"jacobi-gpu\")\n * @param {array} jacobianMatrix - The coefficient matrix\n * @param {array} residualVector - The right-hand side vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing:\n * - solutionVector: The solution vector\n * - converged: Boolean indicating whether the method converged (for iterative methods)\n * - iterations: Number of iterations performed (for iterative methods)\n */\nexport async function solveLinearSystemAsync(solverMethod, jacobianMatrix, residualVector, options = {}) {\n \n // Extract options\n const { maxIterations = 10000, tolerance = 1e-4 } = options;\n\n basicLog(`Solving system using ${solverMethod}...`);\n console.time(\"systemSolving\");\n\n // Normalize inputs\n const A = Array.isArray(jacobianMatrix) ? jacobianMatrix : jacobianMatrix?.toArray?.() ?? jacobianMatrix;\n const b = Array.isArray(residualVector) ? residualVector : residualVector?.toArray?.() ?? residualVector;\n\n let created = null;\n let computeEngine = null;\n\n let solutionVector = [];\n let converged = true;\n let iterations;\n\n if (solverMethod === \"jacobi-gpu\") {\n // Spin up a worker-backed compute engine\n created = await createDefaultComputeEngine();\n computeEngine = created.computeEngine;\n\n const x0 = new Array(b.length).fill(0);\n let result;\n\n result = await computeEngine.webgpuJacobiSolver(A, b, x0, { maxIterations, tolerance });\n solutionVector = result.solutionVector;\n converged = result.converged;\n iterations = result.iterations;\n\n // Log convergence information\n if (converged) {\n debugLog(`Jacobi method converged in ${iterations} iterations`);\n } else {\n errorLog(`Jacobi method did not converge after ${iterations} iterations`);\n }\n } else {\n errorLog(`Unknown solver method: ${solverMethod}`);\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(`System solved successfully (${solverMethod})`);\n\n if (created) {\n await computeEngine?.destroy?.().catch(() => { });\n created.worker.terminate();\n }\n\n return { solutionVector, converged, iterations };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to solve a system of linear equations using the Jacobi iterative method (CPU synchronous version)\n * @param {array} A - The system matrix\n * @param {array} b - The right-hand side vector\n * @param {array} x0 - Initial guess for solution vector\n * @param {object} [options] - Optional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\nexport function jacobiSolver(A, b, x0, options = {}) {\n // Extract options\n const { maxIterations, tolerance } = options;\n\n const n = A.length;\n let x = [...x0];\n let xNew = new Array(n);\n\n // Jacobi update: xNew[i] = (b[i] - sum(A[i][j] * x[j] for j != i)) / A[i][i]\n for (let iter = 0; iter < maxIterations; iter++) {\n for (let i = 0; i < n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (i !== j) {\n sum += A[i][j] * x[j];\n }\n }\n xNew[i] = (b[i] - sum) / A[i][i];\n }\n\n // Check convergence based on maximum difference in solution vector\n let maxDiff = 0;\n for (let i = 0; i < n; i++) {\n maxDiff = Math.max(maxDiff, Math.abs(xNew[i] - x[i]));\n }\n\n // Copy new solution for the next iteration\n x = [...xNew];\n\n if (maxDiff < tolerance) {\n return { solutionVector: x, iterations: iter + 1, converged: true };\n }\n }\n\n return { solutionVector: x, iterations: maxIterations, converged: false };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle basis functions and their derivatives based on element configuration\n */\nexport class BasisFunctions {\n /**\n * Constructor to initialize the BasisFunctions class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to calculate basis functions and their derivatives based on the dimension and order\n * @param {number} ksi - Natural coordinate (for both 1D and 2D)\n * @param {number} [eta] - Second natural coordinate (only for 2D elements)\n * @returns {object} An object containing:\n * - basisFunction: Array of evaluated basis functions\n * - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi\n * - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)\n */\n getBasisFunctions(ksi, eta = null) {\n let basisFunction = [];\n let basisFunctionDerivKsi = [];\n let basisFunctionDerivEta = [];\n\n if (this.meshDimension === \"1D\") {\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 1D elements\n basisFunction[0] = 1 - ksi;\n basisFunction[1] = ksi;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -1;\n basisFunctionDerivKsi[1] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 1D elements\n basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;\n basisFunction[1] = 4 * ksi - 4 * ksi ** 2;\n basisFunction[2] = -ksi + 2 * ksi ** 2;\n\n // Derivatives of basis functions with respect to ksi\n basisFunctionDerivKsi[0] = -3 + 4 * ksi;\n basisFunctionDerivKsi[1] = 4 - 8 * ksi;\n basisFunctionDerivKsi[2] = -1 + 4 * ksi;\n }\n } else if (this.meshDimension === \"2D\") {\n if (eta === null) {\n errorLog(\"Eta coordinate is required for 2D elements\");\n return;\n }\n\n if (this.elementOrder === \"linear\") {\n // Linear basis functions for 2D elements\n function l1(c) {\n return 1 - c;\n }\n function l2(c) {\n return c;\n }\n function dl1() {\n return -1;\n }\n function dl2() {\n return 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l2(ksi) * l1(eta);\n basisFunction[3] = l2(ksi) * l2(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1() * l1(eta);\n basisFunctionDerivKsi[1] = dl1() * l2(eta);\n basisFunctionDerivKsi[2] = dl2() * l1(eta);\n basisFunctionDerivKsi[3] = dl2() * l2(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1();\n basisFunctionDerivEta[1] = l1(ksi) * dl2();\n basisFunctionDerivEta[2] = l2(ksi) * dl1();\n basisFunctionDerivEta[3] = l2(ksi) * dl2();\n } else if (this.elementOrder === \"quadratic\") {\n // Quadratic basis functions for 2D elements\n function l1(c) {\n return 2 * c ** 2 - 3 * c + 1;\n }\n function l2(c) {\n return -4 * c ** 2 + 4 * c;\n }\n function l3(c) {\n return 2 * c ** 2 - c;\n }\n function dl1(c) {\n return 4 * c - 3;\n }\n function dl2(c) {\n return -8 * c + 4;\n }\n function dl3(c) {\n return 4 * c - 1;\n }\n\n // Evaluate basis functions at (ksi, eta)\n basisFunction[0] = l1(ksi) * l1(eta);\n basisFunction[1] = l1(ksi) * l2(eta);\n basisFunction[2] = l1(ksi) * l3(eta);\n basisFunction[3] = l2(ksi) * l1(eta);\n basisFunction[4] = l2(ksi) * l2(eta);\n basisFunction[5] = l2(ksi) * l3(eta);\n basisFunction[6] = l3(ksi) * l1(eta);\n basisFunction[7] = l3(ksi) * l2(eta);\n basisFunction[8] = l3(ksi) * l3(eta);\n\n // Derivatives with respect to ksi\n basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);\n basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);\n basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);\n basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);\n basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);\n basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);\n basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);\n basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);\n basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);\n\n // Derivatives with respect to eta\n basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);\n basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);\n basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);\n basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);\n basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);\n basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);\n basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);\n basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);\n basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);\n }\n }\n\n return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Basic structure for the mesh\n */\nexport class Mesh {\n /**\n * Constructor to initialize the Mesh class\n * @param {object} config - Configuration object for the mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY=1] - Number of elements along the y-axis (for 1D meshes)\n * @param {number} [config.maxY=0] - Maximum y-coordinate of the mesh (for 1D meshes)\n * @param {string} [config.meshDimension='2D'] - The dimension of the mesh, either 1D or 2D\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n meshDimension = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n this.numElementsX = numElementsX;\n this.numElementsY = numElementsY;\n this.maxX = maxX;\n this.maxY = maxY;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n this.parsedMesh = parsedMesh;\n\n this.boundaryElementsProcessed = false;\n\n if (this.parsedMesh) {\n basicLog(\"Using pre-parsed mesh from gmshReader data for mesh generation.\");\n this.parseMeshFromGmsh();\n }\n }\n\n /**\n * Method to parse the mesh from the GMSH format to the FEAScript format\n */\n parseMeshFromGmsh() {\n if (!this.parsedMesh.nodalNumbering) {\n errorLog(\"No valid nodal numbering found in the parsed mesh.\");\n }\n\n if (\n typeof this.parsedMesh.nodalNumbering === \"object\" &&\n !Array.isArray(this.parsedMesh.nodalNumbering)\n ) {\n // Store the nodal numbering structure before converting\n const quadElements = this.parsedMesh.nodalNumbering.quadElements || [];\n const triangleElements = this.parsedMesh.nodalNumbering.triangleElements || [];\n\n debugLog(\n \"Initial parsed mesh nodal numbering from GMSH format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Check if it has quadElements or triangleElements structure from gmshReader\n if (this.parsedMesh.elementTypes[3] || this.parsedMesh.elementTypes[10]) {\n // Map nodal numbering from GMSH format to FEAScript format for quad elements\n const mappedNodalNumbering = [];\n\n for (let elemIdx = 0; elemIdx < quadElements.length; elemIdx++) {\n const gmshNodes = quadElements[elemIdx];\n const feaScriptNodes = new Array(gmshNodes.length);\n\n // Check for element type based on number of nodes\n if (gmshNodes.length === 4) {\n // Simple mapping for linear quad elements (4 nodes)\n // GMSH: FEAScript:\n // 3 --- 2 1 --- 3\n // | | --> | |\n // 0 --- 1 0 --- 2\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[3]; // 3 -> 1\n feaScriptNodes[2] = gmshNodes[1]; // 1 -> 2\n feaScriptNodes[3] = gmshNodes[2]; // 2 -> 3\n } else if (gmshNodes.length === 9) {\n // Mapping for quadratic quad elements (9 nodes)\n // GMSH: FEAScript:\n // 3--6--2 2--5--8\n // | | | |\n // 7 8 5 --> 1 4 7\n // | | | |\n // 0--4--1 0--3--6\n\n feaScriptNodes[0] = gmshNodes[0]; // 0 -> 0\n feaScriptNodes[1] = gmshNodes[7]; // 7 -> 1\n feaScriptNodes[2] = gmshNodes[3]; // 3 -> 2\n feaScriptNodes[3] = gmshNodes[4]; // 4 -> 3\n feaScriptNodes[4] = gmshNodes[8]; // 8 -> 4\n feaScriptNodes[5] = gmshNodes[6]; // 6 -> 5\n feaScriptNodes[6] = gmshNodes[1]; // 1 -> 6\n feaScriptNodes[7] = gmshNodes[5]; // 5 -> 7\n feaScriptNodes[8] = gmshNodes[2]; // 2 -> 8\n }\n\n mappedNodalNumbering.push(feaScriptNodes);\n }\n\n this.parsedMesh.nodalNumbering = mappedNodalNumbering;\n } else if (this.parsedMesh.elementTypes[2]) {\n errorLog(\"Element type is neither triangle nor quad; mapping for this type is not implemented yet.\");\n }\n\n debugLog(\n \"Nodal numbering after mapping from GMSH to FEAScript format: \" +\n JSON.stringify(this.parsedMesh.nodalNumbering)\n );\n\n // Process boundary elements if they exist and if physical property mapping exists\n if (this.parsedMesh.physicalPropMap && this.parsedMesh.boundaryElements) {\n // Check if boundary elements need to be processed\n if (\n Array.isArray(this.parsedMesh.boundaryElements) &&\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n // Create a new array without the empty first element\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n\n // If boundary node pairs exist but boundary elements haven't been processed\n if (this.parsedMesh.boundaryNodePairs && !this.parsedMesh.boundaryElementsProcessed) {\n // Reset boundary elements array\n this.parsedMesh.boundaryElements = [];\n\n // Process each physical property from the Gmsh file\n this.parsedMesh.physicalPropMap.forEach((prop) => {\n // Only process 1D physical entities (boundary lines)\n if (prop.dimension === 1) {\n // Get all node pairs for this boundary\n const boundaryNodePairs = this.parsedMesh.boundaryNodePairs[prop.tag] || [];\n\n if (boundaryNodePairs.length > 0) {\n // Initialize array for this boundary tag\n if (!this.parsedMesh.boundaryElements[prop.tag]) {\n this.parsedMesh.boundaryElements[prop.tag] = [];\n }\n\n // For each boundary line segment (defined by a pair of nodes)\n boundaryNodePairs.forEach((nodesPair) => {\n const node1 = nodesPair[0]; // First node in the pair\n const node2 = nodesPair[1]; // Second node in the pair\n\n debugLog(\n `Processing boundary node pair: [${node1}, ${node2}] for boundary ${prop.tag} (${\n prop.name || \"unnamed\"\n })`\n );\n\n // Search through all elements to find which one contains both nodes\n let foundElement = false;\n\n // Loop through all elements in the mesh\n for (let elemIdx = 0; elemIdx < this.parsedMesh.nodalNumbering.length; elemIdx++) {\n const elemNodes = this.parsedMesh.nodalNumbering[elemIdx];\n\n // For linear quadrilateral linear elements (4 nodes)\n if (elemNodes.length === 4) {\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript linear quadrilateral numbering:\n // 1 --- 3\n // | |\n // 0 --- 2\n\n if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0)\n ) {\n side = 0; // Bottom side\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0)\n ) {\n side = 1; // Left side\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 1 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 1)\n ) {\n side = 2; // Top side\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 2)\n ) {\n side = 3; // Right side\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n } else if (elemNodes.length === 9) {\n // For quadratic quadrilateral elements (9 nodes)\n // Check if both boundary nodes are in this element\n if (elemNodes.includes(node1) && elemNodes.includes(node2)) {\n // Find which side of the element these nodes form\n let side;\n\n const node1Index = elemNodes.indexOf(node1);\n const node2Index = elemNodes.indexOf(node2);\n\n debugLog(\n ` Found element ${elemIdx} containing boundary nodes. Element nodes: [${elemNodes.join(\n \", \"\n )}]`\n );\n debugLog(\n ` Node ${node1} is at index ${node1Index}, Node ${node2} is at index ${node2Index} in the element`\n );\n\n // Based on FEAScript quadratic quadrilateral numbering:\n // 2--5--8\n // | |\n // 1 4 7\n // | |\n // 0--3--6\n\n // TODO: Transform into dictionaries for better readability\n if (\n (node1Index === 0 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 3) ||\n (node1Index === 3 && node2Index === 0) ||\n (node1Index === 3 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 3)\n ) {\n side = 0; // Bottom side (nodes 0, 3, 6)\n debugLog(` These nodes form the BOTTOM side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 0 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 0) ||\n (node1Index === 0 && node2Index === 1) ||\n (node1Index === 1 && node2Index === 0) ||\n (node1Index === 1 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 1)\n ) {\n side = 1; // Left side (nodes 0, 1, 2)\n debugLog(` These nodes form the LEFT side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 2 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 2) ||\n (node1Index === 2 && node2Index === 5) ||\n (node1Index === 5 && node2Index === 2) ||\n (node1Index === 5 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 5)\n ) {\n side = 2; // Top side (nodes 2, 5, 8)\n debugLog(` These nodes form the TOP side (${side}) of element ${elemIdx}`);\n } else if (\n (node1Index === 6 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 6) ||\n (node1Index === 6 && node2Index === 7) ||\n (node1Index === 7 && node2Index === 6) ||\n (node1Index === 7 && node2Index === 8) ||\n (node1Index === 8 && node2Index === 7)\n ) {\n side = 3; // Right side (nodes 6, 7, 8)\n debugLog(` These nodes form the RIGHT side (${side}) of element ${elemIdx}`);\n }\n\n // Add the element and side to the boundary elements array\n this.parsedMesh.boundaryElements[prop.tag].push([elemIdx, side]);\n debugLog(\n ` Added element-side pair [${elemIdx}, ${side}] to boundary tag ${prop.tag}`\n );\n foundElement = true;\n break;\n }\n }\n }\n\n if (!foundElement) {\n errorLog(\n `Could not find element containing boundary nodes ${node1} and ${node2}. Boundary may be incomplete.`\n );\n }\n });\n }\n }\n });\n\n // Mark as processed\n this.boundaryElementsProcessed = true;\n\n // Fix boundary elements array - remove undefined entries\n if (\n this.parsedMesh.boundaryElements.length > 0 &&\n this.parsedMesh.boundaryElements[0] === undefined\n ) {\n const fixedBoundaryElements = [];\n for (let i = 1; i < this.parsedMesh.boundaryElements.length; i++) {\n if (this.parsedMesh.boundaryElements[i]) {\n fixedBoundaryElements.push(this.parsedMesh.boundaryElements[i]);\n }\n }\n this.parsedMesh.boundaryElements = fixedBoundaryElements;\n }\n }\n }\n }\n\n return this.parsedMesh;\n }\n}\n\nexport class Mesh1D extends Mesh {\n /**\n * Constructor to initialize the 1D mesh\n * @param {object} config - Configuration object for the 1D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({ numElementsX = null, maxX = null, elementOrder = \"linear\", parsedMesh = null }) {\n super({\n numElementsX,\n maxX,\n numElementsY: 1,\n maxY: 0,\n meshDimension: \"1D\",\n elementOrder,\n parsedMesh,\n });\n\n if (this.numElementsX === null || this.maxX === null) {\n errorLog(\"numElementsX and maxX are required parameters when generating a 1D mesh from geometry\");\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n const xStart = 0;\n let totalNodesX, deltaX;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX;\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n\n nodesXCoordinates[0] = xStart;\n for (let nodeIndex = 1; nodeIndex < totalNodesX; nodeIndex++) {\n nodesXCoordinates[nodeIndex] = nodesXCoordinates[nodeIndex - 1] + deltaX / 2;\n }\n }\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate1DNodalNumbering(this.numElementsX, totalNodesX, this.elementOrder);\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n\n // Return x coordinates of nodes, total nodes, NOP array, and boundary elements\n return {\n nodesXCoordinates,\n totalNodesX,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate1DNodalNumbering(numElementsX, totalNodesX, elementOrder) {\n // TODO: The totalNodesX is not used in the original function. Verify if\n // there is a multiple calculation on the totalNodes.\n\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear 1D elements with the following nodes representation:\n *\n * 1 --- 2\n *\n */\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic 1D elements with the following nodes representation:\n *\n * 1--2--3\n *\n */\n let columnCounter = 0;\n for (let elementIndex = 0; elementIndex < numElementsX; elementIndex++) {\n nop[elementIndex] = [];\n for (let nodeIndex = 1; nodeIndex <= 3; nodeIndex++) {\n nop[elementIndex][nodeIndex - 1] = elementIndex + nodeIndex + columnCounter;\n }\n columnCounter += 1;\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 1D domains (line segments):\n * 0 - Left node of reference element (maps to physical left endpoint)\n * 1 - Right node of reference element (maps to physical right endpoint)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 2; // For 1D, we only have two sides (left and right)\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // Left boundary (element 0, side 0)\n boundaryElements[0].push([0, 0]);\n\n // Right boundary (last element, side 1)\n boundaryElements[1].push([this.numElementsX - 1, 1]);\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n\nexport class Mesh2D extends Mesh {\n /**\n * Constructor to initialize the 2D mesh\n * @param {object} config - Configuration object for the 2D mesh\n * @param {number} [config.numElementsX] - Number of elements along the x-axis (required for geometry-based mesh)\n * @param {number} [config.maxX] - Maximum x-coordinate of the mesh (required for geometry-based mesh)\n * @param {number} [config.numElementsY] - Number of elements along the y-axis (required for geometry-based mesh)\n * @param {number} [config.maxY] - Maximum y-coordinate of the mesh (required for geometry-based mesh)\n * @param {string} [config.elementOrder='linear'] - The order of elements, either 'linear' or 'quadratic'\n * @param {object} [config.parsedMesh=null] - Optional pre-parsed mesh data\n */\n constructor({\n numElementsX = null,\n maxX = null,\n numElementsY = null,\n maxY = null,\n elementOrder = \"linear\",\n parsedMesh = null,\n }) {\n super({\n numElementsX,\n maxX,\n numElementsY,\n maxY,\n meshDimension: \"2D\",\n elementOrder,\n parsedMesh,\n });\n\n // Validate geometry parameters (when not using a parsed mesh)\n if (\n !parsedMesh &&\n (this.numElementsX === null || this.maxX === null || this.numElementsY === null || this.maxY === null)\n ) {\n errorLog(\n \"numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry\"\n );\n }\n }\n\n generateMesh() {\n let nodesXCoordinates = [];\n let nodesYCoordinates = [];\n const xStart = 0;\n const yStart = 0;\n let totalNodesX, totalNodesY, deltaX, deltaY;\n\n if (this.elementOrder === \"linear\") {\n totalNodesX = this.numElementsX + 1;\n totalNodesY = this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + nodeIndexY * deltaY;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + nodeIndexX * deltaX;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + nodeIndexY * deltaY;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n totalNodesX = 2 * this.numElementsX + 1;\n totalNodesY = 2 * this.numElementsY + 1;\n deltaX = (this.maxX - xStart) / this.numElementsX;\n deltaY = (this.maxY - yStart) / this.numElementsY;\n\n nodesXCoordinates[0] = xStart;\n nodesYCoordinates[0] = yStart;\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nodeIndexY] = nodesXCoordinates[0];\n nodesYCoordinates[nodeIndexY] = nodesYCoordinates[0] + (nodeIndexY * deltaY) / 2;\n }\n for (let nodeIndexX = 1; nodeIndexX < totalNodesX; nodeIndexX++) {\n const nnode = nodeIndexX * totalNodesY;\n nodesXCoordinates[nnode] = nodesXCoordinates[0] + (nodeIndexX * deltaX) / 2;\n nodesYCoordinates[nnode] = nodesYCoordinates[0];\n for (let nodeIndexY = 1; nodeIndexY < totalNodesY; nodeIndexY++) {\n nodesXCoordinates[nnode + nodeIndexY] = nodesXCoordinates[nnode];\n nodesYCoordinates[nnode + nodeIndexY] = nodesYCoordinates[nnode] + (nodeIndexY * deltaY) / 2;\n }\n }\n }\n\n // Generate nodal numbering (NOP) array\n const nodalNumbering = this.generate2DNodalNumbering(\n this.numElementsX,\n this.numElementsY,\n totalNodesY,\n this.elementOrder\n );\n\n // Find boundary elements\n const boundaryElements = this.findBoundaryElements();\n\n debugLog(\"Generated node X coordinates: \" + JSON.stringify(nodesXCoordinates));\n debugLog(\"Generated node Y coordinates: \" + JSON.stringify(nodesYCoordinates));\n\n // Return statement\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nodalNumbering,\n boundaryElements,\n };\n }\n\n /**\n * Function to generate the nodal numbering (NOP) array for a structured mesh\n * This array represents the connectivity between elements and their corresponding nodes\n * @param {number} numElementsX - Number of elements along the x-axis\n * @param {number} [numElementsY] - Number of elements along the y-axis (optional for 1D)\n * @param {number} totalNodesX - Total number of nodes along the x-axis\n * @param {number} [totalNodesY] - Total number of nodes along the y-axis (optional for 1D)\n * @param {string} elementOrder - The order of elements, either 'linear' or 'quadratic'\n * @returns {array} NOP - A two-dimensional array which represents the element-to-node connectivity for the entire mesh\n */\n generate2DNodalNumbering(numElementsX, numElementsY, totalNodesY, elementOrder) {\n let elementIndex = 0;\n let nop = [];\n\n if (elementOrder === \"linear\") {\n /**\n * Linear rectangular elements with the following nodes representation:\n *\n * 1 --- 3\n * | |\n * 0 --- 2\n *\n */\n let rowCounter = 0;\n let columnCounter = 2;\n for (let elementIndex = 0; elementIndex < numElementsX * numElementsY; elementIndex++) {\n rowCounter += 1;\n nop[elementIndex] = [];\n nop[elementIndex][0] = elementIndex + columnCounter - 1;\n nop[elementIndex][1] = elementIndex + columnCounter;\n nop[elementIndex][2] = elementIndex + columnCounter + numElementsY;\n nop[elementIndex][3] = elementIndex + columnCounter + numElementsY + 1;\n if (rowCounter === numElementsY) {\n columnCounter += 1;\n rowCounter = 0;\n }\n }\n } else if (elementOrder === \"quadratic\") {\n /**\n * Quadratic rectangular elements with the following nodes representation:\n *\n * 2--5--8\n * | |\n * 1 4 7\n * | |\n * 0--3--6\n *\n */\n for (let elementIndexX = 1; elementIndexX <= numElementsX; elementIndexX++) {\n for (let elementIndexY = 1; elementIndexY <= numElementsY; elementIndexY++) {\n nop[elementIndex] = [];\n for (let nodeIndex1 = 1; nodeIndex1 <= 3; nodeIndex1++) {\n let nodeIndex2 = 3 * nodeIndex1 - 2;\n nop[elementIndex][nodeIndex2 - 1] =\n totalNodesY * (2 * elementIndexX + nodeIndex1 - 3) + 2 * elementIndexY - 1;\n nop[elementIndex][nodeIndex2] = nop[elementIndex][nodeIndex2 - 1] + 1;\n nop[elementIndex][nodeIndex2 + 1] = nop[elementIndex][nodeIndex2 - 1] + 2;\n }\n elementIndex = elementIndex + 1;\n }\n }\n }\n\n return nop;\n }\n\n /**\n * Function to find the elements that belong to each boundary of a domain\n * @returns {array} An array containing arrays of elements and their adjacent boundary side for each boundary\n * Each element in the array is of the form [elementIndex, side], where 'side' indicates which side\n * of the reference element is in contact with the physical boundary:\n *\n * For 2D domains (rectangular):\n * 0 - Bottom side of reference element (maps to physical bottom boundary)\n * 1 - Left side of reference element (maps to physical left boundary)\n * 2 - Top side of reference element (maps to physical top boundary)\n * 3 - Right side of reference element (maps to physical right boundary)\n */\n findBoundaryElements() {\n const boundaryElements = [];\n const maxSides = 4; // For 2D, we have four sides (left, right, bottom, top)\n\n for (let sideIndex = 0; sideIndex < maxSides; sideIndex++) {\n boundaryElements.push([]);\n }\n\n // TODO: Why to loop through all elements? Is it not better to loop over only the\n // elements that are on the boundary? eg: [0, this.numElementsX - 1] on x and\n // [0, this.numElementsY - 1] on y\n for (let elementIndexX = 0; elementIndexX < this.numElementsX; elementIndexX++) {\n for (let elementIndexY = 0; elementIndexY < this.numElementsY; elementIndexY++) {\n const elementIndex = elementIndexX * this.numElementsY + elementIndexY;\n\n // Bottom boundary\n if (elementIndexY === 0) {\n boundaryElements[0].push([elementIndex, 0]);\n }\n\n // Left boundary\n if (elementIndexX === 0) {\n boundaryElements[1].push([elementIndex, 1]);\n }\n\n // Top boundary\n if (elementIndexY === this.numElementsY - 1) {\n boundaryElements[2].push([elementIndex, 2]);\n }\n\n // Right boundary\n if (elementIndexX === this.numElementsX - 1) {\n boundaryElements[3].push([elementIndex, 3]);\n }\n }\n }\n\n debugLog(\"Identified boundary elements by side: \" + JSON.stringify(boundaryElements));\n this.boundaryElementsProcessed = true;\n return boundaryElements;\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Class to handle numerical integration using Gauss quadrature\n */\nexport class NumericalIntegration {\n /**\n * Constructor to initialize the NumericalIntegration class\n * @param {string} meshDimension - The dimension of the mesh\n * @param {string} elementOrder - The order of elements\n */\n constructor({ meshDimension, elementOrder }) {\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to return Gauss points and weights based on element configuration\n * @returns {object} An object containing:\n * - gaussPoints: Array of Gauss points\n * - gaussWeights: Array of Gauss weights\n */\n getGaussPointsAndWeights() {\n let gaussPoints = []; // Gauss points\n let gaussWeights = []; // Gauss weights\n\n if (this.elementOrder === \"linear\") {\n // For linear elements, use 1-point Gauss quadrature\n gaussPoints[0] = 0.5;\n gaussWeights[0] = 1;\n } else if (this.elementOrder === \"quadratic\") {\n // For quadratic elements, use 3-point Gauss quadrature\n gaussPoints[0] = (1 - Math.sqrt(3 / 5)) / 2;\n gaussPoints[1] = 0.5;\n gaussPoints[2] = (1 + Math.sqrt(3 / 5)) / 2;\n gaussWeights[0] = 5 / 18;\n gaussWeights[1] = 8 / 18;\n gaussWeights[2] = 5 / 18;\n }\n\n return { gaussPoints, gaussWeights };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nimport { BasisFunctions } from \"./basisFunctionsScript.js\";\nimport { Mesh1D, Mesh2D } from \"./meshGenerationScript.js\";\nimport { NumericalIntegration } from \"../methods/numericalIntegrationScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to prepare the mesh for finite element analysis\n * @param {object} meshConfig - Object containing computational mesh details\n * @returns {object} An object containing all mesh-related data\n */\nexport function prepareMesh(meshConfig) {\n const { meshDimension, numElementsX, numElementsY, maxX, maxY, elementOrder, parsedMesh } = meshConfig;\n\n // Create a new instance of the Mesh class\n let mesh;\n if (meshDimension === \"1D\") {\n mesh = new Mesh1D({ numElementsX, maxX, elementOrder, parsedMesh });\n } else if (meshDimension === \"2D\") {\n mesh = new Mesh2D({ numElementsX, maxX, numElementsY, maxY, elementOrder, parsedMesh });\n } else {\n errorLog(\"Mesh dimension must be either '1D' or '2D'.\");\n }\n\n // Use the parsed mesh in case it was already passed with Gmsh format\n const nodesCoordinatesAndNumbering = mesh.boundaryElementsProcessed ? mesh.parsedMesh : mesh.generateMesh();\n\n // Extract nodes coordinates and nodal numbering (NOP) from the mesh data\n let nodesXCoordinates = nodesCoordinatesAndNumbering.nodesXCoordinates;\n let nodesYCoordinates = nodesCoordinatesAndNumbering.nodesYCoordinates;\n let totalNodesX = nodesCoordinatesAndNumbering.totalNodesX;\n let totalNodesY = nodesCoordinatesAndNumbering.totalNodesY;\n let nop = nodesCoordinatesAndNumbering.nodalNumbering;\n let boundaryElements = nodesCoordinatesAndNumbering.boundaryElements;\n\n // Check the mesh type\n const isParsedMesh = parsedMesh !== undefined && parsedMesh !== null;\n\n // Calculate totalElements and totalNodes based on mesh type\n let totalElements, totalNodes;\n\n if (isParsedMesh) {\n totalElements = nop.length; // Number of elements is the length of the nodal numbering array\n totalNodes = nodesXCoordinates.length; // Number of nodes is the length of the coordinates array\n debugLog(`Using parsed mesh with ${totalElements} elements and ${totalNodes} nodes`);\n } else {\n // For structured mesh, calculate based on dimensions\n totalElements = numElementsX * (meshDimension === \"2D\" ? numElementsY : 1);\n totalNodes = totalNodesX * (meshDimension === \"2D\" ? totalNodesY : 1);\n debugLog(`Using mesh generated from geometry with ${totalElements} elements and ${totalNodes} nodes`);\n }\n\n return {\n nodesXCoordinates,\n nodesYCoordinates,\n totalNodesX,\n totalNodesY,\n nop,\n boundaryElements,\n totalElements,\n totalNodes,\n meshDimension,\n elementOrder,\n };\n}\n\n/**\n * Function to initialize the FEA matrices and numerical tools\n * @param {object} meshData - Object containing mesh data from prepareMesh()\n * @returns {object} An object containing initialized matrices and numerical tools\n */\nexport function initializeFEA(meshData) {\n const { totalNodes, nop, meshDimension, elementOrder } = meshData;\n\n // Initialize variables for matrix assembly\n let residualVector = [];\n let jacobianMatrix = [];\n let localToGlobalMap = [];\n\n // Initialize jacobianMatrix and residualVector arrays\n for (let nodeIndex = 0; nodeIndex < totalNodes; nodeIndex++) {\n residualVector[nodeIndex] = 0;\n jacobianMatrix.push([]);\n for (let colIndex = 0; colIndex < totalNodes; colIndex++) {\n jacobianMatrix[nodeIndex][colIndex] = 0;\n }\n }\n\n // Initialize the BasisFunctions class\n const basisFunctions = new BasisFunctions({\n meshDimension,\n elementOrder,\n });\n\n // Initialize the NumericalIntegration class\n const numericalIntegration = new NumericalIntegration({\n meshDimension,\n elementOrder,\n });\n\n // Calculate Gauss points and weights\n let gaussPointsAndWeights = numericalIntegration.getGaussPointsAndWeights();\n let gaussPoints = gaussPointsAndWeights.gaussPoints;\n let gaussWeights = gaussPointsAndWeights.gaussWeights;\n\n // Determine the number of nodes in the reference element based on the first element in the nop array\n const numNodes = nop[0].length;\n\n return {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 1D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping1D(params) {\n const { basisFunction, basisFunctionDerivKsi, nodesXCoordinates, localToGlobalMap, numNodes } = params;\n\n let xCoordinates = 0;\n let ksiDerivX = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n }\n let detJacobian = ksiDerivX;\n\n // Compute x-derivative of basis functions\n let basisFunctionDerivX = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n basisFunctionDerivX[localNodeIndex] = basisFunctionDerivKsi[localNodeIndex] / detJacobian;\n }\n\n return {\n xCoordinates,\n detJacobian,\n basisFunctionDerivX,\n };\n}\n\n/**\n * Function to perform isoparametric mapping for 2D elements\n * @param {object} params - Parameters for the mapping\n * @returns {object} An object containing the mapped data\n */\nexport function performIsoparametricMapping2D(params) {\n const {\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n } = params;\n\n let xCoordinates = 0;\n let yCoordinates = 0;\n let ksiDerivX = 0;\n let etaDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivY = 0;\n\n // Isoparametric mapping\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n xCoordinates += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n yCoordinates += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunction[localNodeIndex];\n ksiDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivX += nodesXCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n ksiDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivKsi[localNodeIndex];\n etaDerivY += nodesYCoordinates[localToGlobalMap[localNodeIndex]] * basisFunctionDerivEta[localNodeIndex];\n }\n let detJacobian = ksiDerivX * etaDerivY - etaDerivX * ksiDerivY;\n\n // Compute x-derivative and y-derivative of basis functions\n let basisFunctionDerivX = [];\n let basisFunctionDerivY = [];\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // The x-derivative of the n basis function\n basisFunctionDerivX[localNodeIndex] =\n (etaDerivY * basisFunctionDerivKsi[localNodeIndex] -\n ksiDerivY * basisFunctionDerivEta[localNodeIndex]) /\n detJacobian;\n // The y-derivative of the n basis function\n basisFunctionDerivY[localNodeIndex] =\n (ksiDerivX * basisFunctionDerivEta[localNodeIndex] -\n etaDerivX * basisFunctionDerivKsi[localNodeIndex]) /\n detJacobian;\n }\n\n return {\n xCoordinates,\n yCoordinates,\n detJacobian,\n basisFunctionDerivX,\n basisFunctionDerivY,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle thermal boundary conditions application\n */\nexport class ThermalBoundaryConditions {\n /**\n * Constructor to initialize the ThermalBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose constant temperature boundary conditions (Dirichlet type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the ConstantTemp value\n residualVector[globalNodeIndex] = tempValue;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant temperature boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantTempBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantTemp\") {\n const tempValue = this.boundaryConditions[boundaryKey][1];\n debugLog(\n `Boundary ${boundaryKey}: Applying constant temperature of ${tempValue} K (Dirichlet condition)`\n );\n\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant temperature to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n\n // Set boundary condition code and value\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = tempValue;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions (Robin type)\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n */\n imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 1;\n }\n } else if (this.elementOrder === \"quadratic\") {\n if (side === 0) {\n // Node at the left side of the reference element\n nodeIndex = 0;\n } else {\n // Node at the right side of the reference element\n nodeIndex = 2;\n }\n }\n\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n residualVector[globalNodeIndex] += -convectionCoeff * extTemp;\n jacobianMatrix[globalNodeIndex][globalNodeIndex] += convectionCoeff;\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n let globalNodeIndex = this.nop[elementIndex][localNodeIndex] - 1;\n debugLog(\n ` - Applied convection boundary condition to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${localNodeIndex + 1})`\n );\n\n // Apply boundary condition with proper Jacobian for all sides\n residualVector[globalNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n let globalNodeIndex2 = this.nop[elementIndex][localNodeIndex2] - 1;\n jacobianMatrix[globalNodeIndex][globalNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose convection boundary conditions for the frontal solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nodesXCoordinates - Array of x-coordinates of nodes\n * @param {array} nodesYCoordinates - Array of y-coordinates of nodes\n * @param {array} gaussPoints - Array of Gauss points for numerical integration\n * @param {array} gaussWeights - Array of Gauss weights for numerical integration\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix with convection contributions\n * - localResidualVector: Residual vector with convection contributions\n */\n imposeConvectionBoundaryConditionsFront(\n elementIndex,\n nodesXCoordinates,\n nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n ) {\n // Extract convection parameters from boundary conditions\n let convectionHeatTranfCoeff = [];\n let convectionExtTemp = [];\n Object.keys(this.boundaryConditions).forEach((key) => {\n const boundaryCondition = this.boundaryConditions[key];\n if (boundaryCondition[0] === \"convection\") {\n convectionHeatTranfCoeff[key] = boundaryCondition[1];\n convectionExtTemp[key] = boundaryCondition[2];\n }\n });\n\n // Initialize local Jacobian matrix and local residual vector\n const numNodes = this.nop[elementIndex].length;\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Check if this element is on a convection boundary\n for (const boundaryKey in this.boundaryElements) {\n if (this.boundaryConditions[boundaryKey]?.[0] === \"convection\") {\n const convectionCoeff = convectionHeatTranfCoeff[boundaryKey];\n const extTemp = convectionExtTemp[boundaryKey];\n debugLog(\n `Boundary ${boundaryKey}: Applying convection with heat transfer coefficient h=${convectionCoeff} W/(m²·K) and external temperature T∞=${extTemp} K`\n );\n\n // Find if this element is on this boundary and which side\n const boundaryElement = this.boundaryElements[boundaryKey].find(\n ([elemIdx, _]) => elemIdx === elementIndex\n );\n\n if (boundaryElement) {\n const side = boundaryElement[1];\n\n if (this.meshDimension === \"1D\") {\n // Handle 1D case\n let nodeIndex;\n if (this.elementOrder === \"linear\") {\n nodeIndex = side === 0 ? 0 : 1;\n } else if (this.elementOrder === \"quadratic\") {\n nodeIndex = side === 0 ? 0 : 2;\n }\n\n // Add contribution to local Jacobian matrix and local residual vector\n debugLog(\n ` - Applied convection boundary condition to node ${nodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n localResidualVector[nodeIndex] += -convectionCoeff * extTemp;\n localJacobianMatrix[nodeIndex][nodeIndex] += convectionCoeff;\n } else if (this.meshDimension === \"2D\") {\n // Handle 2D case\n if (this.elementOrder === \"linear\") {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 2;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 0;\n lastNodeIndex = 2;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[0];\n gaussPoint2 = 1;\n firstNodeIndex = 1;\n lastNodeIndex = 4;\n nodeIncrement = 2;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[0];\n firstNodeIndex = 2;\n lastNodeIndex = 4;\n nodeIncrement = 1;\n }\n\n // Get basis functions\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n const basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n const basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n // Calculate tangent vector components\n let ksiDerivX = 0,\n ksiDerivY = 0,\n etaDerivX = 0,\n etaDerivY = 0;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n } else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute tangent vector length\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[0] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n } else if (this.elementOrder === \"quadratic\") {\n // Handle quadratic elements (similar pattern but with more Gauss points)\n for (let gaussPointIndex = 0; gaussPointIndex < 3; gaussPointIndex++) {\n let gaussPoint1, gaussPoint2, firstNodeIndex, lastNodeIndex, nodeIncrement;\n\n if (side === 0) {\n // Nodes at the bottom side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 0;\n firstNodeIndex = 0;\n lastNodeIndex = 7;\n nodeIncrement = 3;\n } else if (side === 1) {\n // Nodes at the left side of the reference element\n gaussPoint1 = 0;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 0;\n lastNodeIndex = 3;\n nodeIncrement = 1;\n } else if (side === 2) {\n // Nodes at the top side of the reference element\n gaussPoint1 = gaussPoints[gaussPointIndex];\n gaussPoint2 = 1;\n firstNodeIndex = 2;\n lastNodeIndex = 9;\n nodeIncrement = 3;\n } else if (side === 3) {\n // Nodes at the right side of the reference element\n gaussPoint1 = 1;\n gaussPoint2 = gaussPoints[gaussPointIndex];\n firstNodeIndex = 6;\n lastNodeIndex = 9;\n nodeIncrement = 1;\n }\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoint1, gaussPoint2);\n let basisFunction = basisFunctionsAndDerivatives.basisFunction;\n let basisFunctionDerivKsi = basisFunctionsAndDerivatives.basisFunctionDerivKsi;\n let basisFunctionDerivEta = basisFunctionsAndDerivatives.basisFunctionDerivEta;\n\n let ksiDerivX = 0;\n let ksiDerivY = 0;\n let etaDerivX = 0;\n let etaDerivY = 0;\n const numNodes = this.nop[elementIndex].length;\n for (let nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n\n // For boundaries along Ksi (horizontal), use Ksi derivatives\n if (side === 0 || side === 2) {\n ksiDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n ksiDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivKsi[nodeIndex];\n }\n // For boundaries along Eta (vertical), use Eta derivatives\n else if (side === 1 || side === 3) {\n etaDerivX += nodesXCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n etaDerivY += nodesYCoordinates[globalNodeIndex] * basisFunctionDerivEta[nodeIndex];\n }\n }\n\n // Compute the length of tangent vector\n let tangentVectorLength;\n if (side === 0 || side === 2) {\n tangentVectorLength = Math.sqrt(ksiDerivX ** 2 + ksiDerivY ** 2);\n } else {\n tangentVectorLength = Math.sqrt(etaDerivX ** 2 + etaDerivY ** 2);\n }\n\n // Apply boundary conditions to local matrices\n for (\n let localNodeIndex = firstNodeIndex;\n localNodeIndex < lastNodeIndex;\n localNodeIndex += nodeIncrement\n ) {\n localResidualVector[localNodeIndex] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n convectionCoeff *\n extTemp;\n\n for (\n let localNodeIndex2 = firstNodeIndex;\n localNodeIndex2 < lastNodeIndex;\n localNodeIndex2 += nodeIncrement\n ) {\n localJacobianMatrix[localNodeIndex][localNodeIndex2] +=\n -gaussWeights[gaussPointIndex] *\n tangentVectorLength *\n basisFunction[localNodeIndex] *\n basisFunction[localNodeIndex2] *\n convectionCoeff;\n }\n }\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector };\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { ThermalBoundaryConditions } from \"./thermalBoundaryConditionsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the solid heat transfer model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\nexport function assembleHeatConductionMat(meshData, boundaryConditions) {\n basicLog(\"Starting solid heat transfer matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D solid heat transfer\n if (meshDimension === \"1D\") {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n // 2D solid heat transfer\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector is zero for this case\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const thermalBoundaryConditions = new ThermalBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Convection boundary conditions\n thermalBoundaryConditions.imposeConvectionBoundaryConditions(\n residualVector,\n jacobianMatrix,\n gaussPoints,\n gaussWeights,\n nodesXCoordinates,\n nodesYCoordinates,\n basisFunctions\n );\n\n // Impose ConstantTemp boundary conditions\n thermalBoundaryConditions.imposeConstantTempBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Solid heat transfer matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the solid heat transfer model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - localResidualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleHeatConductionFront({ elementIndex, nop, meshData, basisFunctions, FEAData }) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n if (meshDimension === \"1D\") {\n // 1D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2]);\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n // 2D solid heat transfer\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Create mapping from local element space to global mesh (convert to 0-based indexing)\n const localToGlobalMap = ngl.map((globalIndex) => globalIndex - 1);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to handle generic boundary conditions application\n */\nexport class GenericBoundaryConditions {\n /**\n * Constructor to initialize the GenericBoundaryConditions class\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} boundaryElements - Array containing elements that belong to each boundary\n * @param {array} nop - Nodal numbering (NOP) array representing the connectivity between elements and nodes\n * @param {string} meshDimension - The dimension of the mesh (e.g., \"2D\")\n * @param {string} elementOrder - The order of elements (e.g., \"linear\", \"quadratic\")\n */\n constructor(boundaryConditions, boundaryElements, nop, meshDimension, elementOrder) {\n this.boundaryConditions = boundaryConditions;\n this.boundaryElements = boundaryElements;\n this.nop = nop;\n this.meshDimension = meshDimension;\n this.elementOrder = elementOrder;\n }\n\n /**\n * Function to impose Dirichlet boundary conditions\n * @param {array} residualVector - The residual vector to be modified\n * @param {array} jacobianMatrix - The Jacobian matrix to be modified\n *\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n imposeDirichletBoundaryConditions(residualVector, jacobianMatrix) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n // Set the residual vector to the value\n residualVector[globalNodeIndex] = value;\n // Set the Jacobian matrix row to zero\n for (let colIndex = 0; colIndex < residualVector.length; colIndex++) {\n jacobianMatrix[globalNodeIndex][colIndex] = 0;\n }\n // Set the diagonal entry of the Jacobian matrix to one\n jacobianMatrix[globalNodeIndex][globalNodeIndex] = 1;\n });\n }\n });\n }\n });\n }\n }\n\n /**\n * Function to impose constant value (Dirichlet) boundary conditions for the frontal solver\n * @param {array} nodeConstraintCode - Array indicating boundary condition code for each node\n * @param {array} boundaryValues - Array containing boundary condition values\n */\n imposeConstantValueBoundaryConditionsFront(nodeConstraintCode, boundaryValues) {\n if (this.meshDimension === \"1D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 1: [1], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0], // Node at the left side of the reference element\n 2: [2], // Node at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n } else if (this.meshDimension === \"2D\") {\n Object.keys(this.boundaryConditions).forEach((boundaryKey) => {\n if (this.boundaryConditions[boundaryKey][0] === \"constantValue\") {\n const value = this.boundaryConditions[boundaryKey][1];\n debugLog(`Boundary ${boundaryKey}: Applying constant value of ${value} (Dirichlet condition)`);\n this.boundaryElements[boundaryKey].forEach(([elementIndex, side]) => {\n if (this.elementOrder === \"linear\") {\n const boundarySides = {\n 0: [0, 2], // Nodes at the bottom side of the reference element\n 1: [0, 1], // Nodes at the left side of the reference element\n 2: [1, 3], // Nodes at the top side of the reference element\n 3: [2, 3], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n } else if (this.elementOrder === \"quadratic\") {\n const boundarySides = {\n 0: [0, 3, 6], // Nodes at the bottom side of the reference element\n 1: [0, 1, 2], // Nodes at the left side of the reference element\n 2: [2, 5, 8], // Nodes at the top side of the reference element\n 3: [6, 7, 8], // Nodes at the right side of the reference element\n };\n boundarySides[side].forEach((nodeIndex) => {\n const globalNodeIndex = this.nop[elementIndex][nodeIndex] - 1;\n debugLog(\n ` - Applied constant value to node ${globalNodeIndex + 1} (element ${\n elementIndex + 1\n }, local node ${nodeIndex + 1})`\n );\n nodeConstraintCode[globalNodeIndex] = 1;\n boundaryValues[globalNodeIndex] = value;\n });\n }\n });\n }\n });\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport {\n initializeFEA,\n performIsoparametricMapping1D,\n performIsoparametricMapping2D,\n} from \"../mesh/meshUtilsScript.js\";\nimport { basicLog, debugLog } from \"../utilities/loggingScript.js\";\n\n// Base viscous term that remains when eikonal equation is fully activated\nconst baseEikonalViscousTerm = 1e-2;\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the front propagation model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleFrontPropagationMat(\n meshData,\n boundaryConditions,\n solutionVector,\n eikonalActivationFlag\n) {\n basicLog(\"Starting front propagation matrix assembly...\");\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n debugLog(`eikonalViscousTerm: ${eikonalViscousTerm}`);\n debugLog(`eikonalActivationFlag: ${eikonalActivationFlag}`);\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Subtract 1 from nop in order to start numbering from 0\n localToGlobalMap[localNodeIndex] = nop[elementIndex][localNodeIndex] - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // jacobianMatrix\n // TODO jacobianMatrix calculation here\n }\n }\n }\n // 2D front propagation (eikonal) equation\n else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex1],\n gaussPoints[gaussPointIndex2]\n );\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping2D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n basisFunctionDerivEta: basisFunctionsAndDerivatives.basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n\n // residualVector: Viscous term contribution (to stabilize the solution)\n residualVector[localToGlobalMap1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // residualVector: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n residualVector[localToGlobalMap1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n\n // jacobianMatrix: Viscous term contribution\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n -eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // jacobianMatrix: Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n jacobianMatrix[localToGlobalMap1][localToGlobalMap2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Impose Dirichlet boundary conditions\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n basicLog(\"Front propagation matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the local Jacobian matrix and residual vector for the front propagation model when using the frontal system solver\n * @param {number} elementIndex - Index of the element being processed\n * @param {array} nop - Nodal connectivity array (element-to-node mapping)\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} basisFunctions - Object containing basis functions and their derivatives\n * @param {object} FEAData - Object containing FEA-related data\n * @param {array} solutionVector - The solution vector for non-linear equations\n * @param {number} eikonalActivationFlag - Activation parameter for the eikonal equation\n * @returns {object} An object containing:\n * - localJacobianMatrix: Local Jacobian matrix\n * - residualVector: Residual vector contributions\n * - ngl: Array mapping local node indices to global node indices\n */\nexport function assembleFrontPropagationFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n solutionVector,\n eikonalActivationFlag,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n\n // Calculate eikonal viscous term\n let eikonalViscousTerm = 1 - eikonalActivationFlag + baseEikonalViscousTerm; // Viscous term for the front propagation (eikonal) equation\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex1 = 0; gaussPointIndex1 < gaussPoints.length; gaussPointIndex1++) {\n // 1D front propagation (eikonal) equation\n if (meshDimension === \"1D\") {\n // Unsupported 1D front propagation\n errorLog(\"1D front propagation is not yet supported\");\n\n // Get basis functions for the current Gauss point\n let basisFunctionsAndDerivatives = basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1]);\n\n // Perform isoparametric mapping\n const mappingResult = performIsoparametricMapping1D({\n basisFunction: basisFunctionsAndDerivatives.basisFunction,\n basisFunctionDerivKsi: basisFunctionsAndDerivatives.basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Extract mapping results\n const { detJacobian, basisFunctionDerivX } = mappingResult;\n const basisFunction = basisFunctionsAndDerivatives.basisFunction;\n\n // Calculate solution derivative\n let solutionDerivX = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // residualVector\n // TODO residualVector calculation here\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n let localToGlobalMap2 = localToGlobalMap[localNodeIndex2];\n // localJacobianMatrix\n // TODO localJacobianMatrix calculation here\n }\n }\n // 2D front propagation (eikonal) equation\n } else if (meshDimension === \"2D\") {\n for (let gaussPointIndex2 = 0; gaussPointIndex2 < gaussPoints.length; gaussPointIndex2++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta } =\n basisFunctions.getBasisFunctions(gaussPoints[gaussPointIndex1], gaussPoints[gaussPointIndex2]);\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX, basisFunctionDerivY } = performIsoparametricMapping2D({\n basisFunction,\n basisFunctionDerivKsi,\n basisFunctionDerivEta,\n nodesXCoordinates,\n nodesYCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate solution derivatives\n let solutionDerivX = 0;\n let solutionDerivY = 0;\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n solutionDerivX +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivX[localNodeIndex];\n solutionDerivY +=\n solutionVector[localToGlobalMap[localNodeIndex]] * basisFunctionDerivY[localNodeIndex];\n }\n\n // Computation of Galerkin's residuals and Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n let localToGlobalMap1 = localToGlobalMap[localNodeIndex1];\n // Viscous term contribution\n localResidualVector[localNodeIndex1] +=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivX[localNodeIndex1] *\n solutionDerivX +\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunctionDerivY[localNodeIndex1] *\n solutionDerivY;\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localResidualVector[localNodeIndex1] +=\n eikonalActivationFlag *\n (gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1] *\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2) -\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n basisFunction[localNodeIndex1]);\n }\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Viscous term contribution\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n eikonalViscousTerm *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2] *\n detJacobian *\n (basisFunctionDerivX[localNodeIndex1] * basisFunctionDerivX[localNodeIndex2] +\n basisFunctionDerivY[localNodeIndex1] * basisFunctionDerivY[localNodeIndex2]);\n\n // Eikonal equation contribution\n if (eikonalActivationFlag !== 0) {\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n eikonalActivationFlag *\n (-(\n detJacobian *\n solutionDerivX *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]\n ) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivX[localNodeIndex2] -\n eikonalActivationFlag *\n ((detJacobian *\n solutionDerivY *\n basisFunction[localNodeIndex1] *\n gaussWeights[gaussPointIndex1] *\n gaussWeights[gaussPointIndex2]) /\n Math.sqrt(solutionDerivX ** 2 + solutionDerivY ** 2 + 1e-8)) *\n basisFunctionDerivY[localNodeIndex2];\n }\n }\n }\n }\n }\n }\n\n return { localJacobianMatrix, localResidualVector, ngl };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { BasisFunctions } from \"../mesh/basisFunctionsScript.js\";\nimport { initializeFEA } from \"../mesh/meshUtilsScript.js\";\nimport { assembleHeatConductionFront } from \"../models/heatConductionScript.js\";\nimport { ThermalBoundaryConditions } from \"../models/thermalBoundaryConditionsScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\nimport { GenericBoundaryConditions } from \"../models/genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n// Create object templates\nconst frontalData = {};\nconst frontalState = {};\nconst elementData = { currentElementIndex: 0 };\nconst frontStorage = {};\nlet basisFunctions;\n\n/**\n * Function to run the frontal solver and obtain results for plotting\n * @param {function} assembleFront - Matrix assembler based on the physical model\n * @param {object} meshData - Object containing mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} [options] - Additional options for the solver\n * @returns {object} An object containing the solution vector and node coordinates\n */\nexport function runFrontalSolver(assembleFront, meshData, boundaryConditions, options = {}) {\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const totalNodes = meshData.nodesXCoordinates.length;\n const numElements = meshData.totalElements;\n const numNodes = FEAData.numNodes;\n\n // Calculate required array sizes\n initializeFrontalArrays(numNodes, numElements);\n\n // Start timing for system solving (frontal algorithm)\n basicLog(\"Solving system using frontal...\");\n console.time(\"systemSolving\");\n\n // Initialize basis functions\n basisFunctions = new BasisFunctions({\n meshDimension: meshData.meshDimension,\n elementOrder: meshData.elementOrder,\n });\n\n // Copy node connectivity array into frontalData storage\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n for (let nodeIndex = 0; nodeIndex < FEAData.numNodes; nodeIndex++) {\n frontalData.nodalNumbering[elementIndex][nodeIndex] = meshData.nop[elementIndex][nodeIndex];\n }\n }\n\n // Apply Dirichlet-type boundary conditions\n // Initialize all nodes with no boundary condition\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.nodeConstraintCode[nodeIndex] = 0;\n frontalData.boundaryValues[nodeIndex] = 0;\n }\n\n // Handle Dirichlet-type boundary conditions differently based on which solver is being used\n let dirichletBoundaryConditionsHandler;\n // Solid heat transfer model (heatConductionScript solver)\n if (assembleFront === assembleHeatConductionFront) {\n dirichletBoundaryConditionsHandler = new ThermalBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantTempBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n // Front propagation model (frontPropagationScript solver)\n } else if (assembleFront === assembleFrontPropagationFront) {\n dirichletBoundaryConditionsHandler = new GenericBoundaryConditions(\n boundaryConditions,\n meshData.boundaryElements,\n meshData.nop,\n meshData.meshDimension,\n meshData.elementOrder\n );\n\n dirichletBoundaryConditionsHandler.imposeConstantValueBoundaryConditionsFront(\n frontalData.nodeConstraintCode,\n frontalData.boundaryValues\n );\n }\n // Initialize global residual vector\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.globalResidualVector[nodeIndex] = 0;\n }\n\n frontalState.totalNodes = meshData.nodesXCoordinates.length;\n frontalState.writeFlag = 0;\n frontalState.transformationFlag = 1;\n frontalState.determinant = 1;\n\n for (let elementIndex = 0; elementIndex < meshData.totalElements; elementIndex++) {\n frontalState.nodesPerElement[elementIndex] = FEAData.numNodes;\n }\n\n // Parameters for non-linear assemblers\n frontalState.currentSolutionVector = options.solutionVector;\n frontalState.eikonalActivationFlag = options.eikonalActivationFlag;\n\n // Pass assembleFront and dirichletBoundaryConditionsHandler to runFrontalAlgorithm\n runFrontalAlgorithm(meshData, FEAData, dirichletBoundaryConditionsHandler, assembleFront);\n\n // Copy solution\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n frontalData.solutionVector[nodeIndex] = frontalState.globalSolutionVector[nodeIndex];\n }\n\n // Output results to console for debugging\n const { nodesXCoordinates, nodesYCoordinates } = meshData;\n for (let nodeIndex = 0; nodeIndex < meshData.nodesXCoordinates.length; nodeIndex++) {\n if (meshData.meshDimension === \"1D\") {\n // 1D case - only output X coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${frontalData.solutionVector[\n nodeIndex\n ].toExponential(5)}`\n );\n } else {\n // 2D case - output X, Y coordinates and temperature\n debugLog(\n `${nodesXCoordinates[nodeIndex].toExponential(5)} ${nodesYCoordinates[nodeIndex].toExponential(\n 5\n )} ${frontalData.solutionVector[nodeIndex].toExponential(5)}`\n );\n }\n }\n\n console.timeEnd(\"systemSolving\");\n basicLog(\"System solved successfully\");\n\n const { nodesXCoordinates: finalNodesX, nodesYCoordinates: finalNodesY } = meshData;\n return {\n solutionVector: frontalData.solutionVector.slice(0, totalNodes),\n nodesCoordinates: {\n nodesXCoordinates: finalNodesX,\n nodesYCoordinates: finalNodesY,\n },\n };\n}\n\n/**\n * Function to initialize arrays dynamically based on problem size\n * @param {number} numNodes - Number of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n */\nfunction initializeFrontalArrays(numNodes, numElements) {\n // Use the actual number of elements from the mesh\n frontalData.nodalNumbering = Array(numElements)\n .fill()\n .map(() => Array(numNodes).fill(0));\n frontalData.nodeConstraintCode = Array(numNodes).fill(0);\n frontalData.boundaryValues = Array(numNodes).fill(0);\n frontalData.globalResidualVector = Array(numNodes).fill(0);\n frontalData.solutionVector = Array(numNodes).fill(0);\n frontalData.topologyData = Array(numElements).fill(0);\n frontalData.lateralData = Array(numElements).fill(0);\n\n // Initialize frontalState arrays\n frontalState.writeFlag = 0;\n frontalState.totalNodes = numNodes;\n frontalState.transformationFlag = 0;\n frontalState.nodesPerElement = Array(numElements).fill(0);\n frontalState.determinant = 1;\n\n // For matrix operations, estimate required size based on problem complexity\n const systemSize = Math.max(numNodes, 2000);\n frontalState.globalSolutionVector = Array(systemSize).fill(0);\n frontalState.frontDataIndex = 0;\n\n // Initialize elementData arrays\n elementData.localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n elementData.currentElementIndex = 0;\n\n // Initialize frontStorage arrays\n const frontSize = estimateFrontSize(numNodes, numElements);\n frontStorage.frontValues = Array(frontSize).fill(0);\n frontStorage.columnHeaders = Array(systemSize).fill(0);\n frontStorage.pivotRow = Array(systemSize).fill(0);\n frontStorage.pivotData = Array(frontSize).fill(0);\n}\n\n/**\n * Function to estimate the required front size\n * @param {number} numNodes - Number of of nodes per element\n * @param {number} numElements - Number of elements in the mesh\n * @returns {number} Estimated front size\n */\nfunction estimateFrontSize(numNodes, numElements) {\n const frontWidthEstimate = Math.max(Math.ceil(Math.sqrt(numElements)) * numNodes, numNodes * 2);\n return frontWidthEstimate * numElements;\n}\n// Old function to estimate the required front size\n// function estimateFrontSize(numNodes, numElements, numNodes) {\n// const frontWidthEstimate = Math.ceil(Math.sqrt(numElements) * numNodes * 2);\n// const frontSize = frontWidthEstimate * numNodes * 4;\n// return Math.max(frontSize, 10000);\n// }\n\n/**\n * Function to compute local Jacobian matrix and local residual vector\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n const elementIndex = elementData.currentElementIndex - 1;\n\n // Guard against out-of-range indices\n if (elementIndex < 0 || elementIndex >= meshData.totalElements) {\n errorLog(`Skipping out-of-range elementIndex=${elementIndex} (totalElements=${meshData.totalElements})`);\n return false;\n }\n\n // Domain terms\n const { localJacobianMatrix, localResidualVector, ngl } = assembleFront({\n elementIndex,\n nop: frontalData.nodalNumbering,\n meshData,\n basisFunctions: basisFunctions,\n FEAData,\n // These are ignored by linear assemblers\n solutionVector: frontalState.currentSolutionVector,\n eikonalActivationFlag: frontalState.eikonalActivationFlag,\n });\n\n // Handle Robin-type boundary conditions differently based on which solver is being used\n let boundaryLocalJacobianMatrix = Array(FEAData.numNodes)\n .fill()\n .map(() => Array(FEAData.numNodes).fill(0));\n let boundaryResidualVector = Array(FEAData.numNodes).fill(0);\n\n // heatConductionScript solver\n if (assembleFront === assembleHeatConductionFront) {\n // Check if this element is on a Robin-type boundary\n let isOnRobinTypeBoundary = false;\n for (const boundaryKey in meshData.boundaryElements) {\n if (\n thermalBoundaryConditions.boundaryConditions[boundaryKey]?.[0] === \"convection\" &&\n meshData.boundaryElements[boundaryKey].some(([elemIdx, _]) => elemIdx === elementIndex)\n ) {\n isOnRobinTypeBoundary = true;\n break;\n }\n }\n\n // Only calculate Robin-type for elements when required\n if (isOnRobinTypeBoundary) {\n const { gaussPoints, gaussWeights } = FEAData;\n const result = thermalBoundaryConditions.imposeConvectionBoundaryConditionsFront(\n elementIndex,\n meshData.nodesXCoordinates,\n meshData.nodesYCoordinates,\n gaussPoints,\n gaussWeights,\n basisFunctions\n );\n boundaryLocalJacobianMatrix = result.localJacobianMatrix;\n boundaryResidualVector = result.localResidualVector;\n }\n } else if (assembleFront === assembleFrontPropagationFront) {\n // For now, no Robin-type boundary conditions exist for any other solver\n }\n\n // Combine domain and boundary contributions\n for (let localNodeI = 0; localNodeI < FEAData.numNodes; localNodeI++) {\n for (let localNodeJ = 0; localNodeJ < FEAData.numNodes; localNodeJ++) {\n elementData.localJacobianMatrix[localNodeI][localNodeJ] =\n localJacobianMatrix[localNodeI][localNodeJ] + boundaryLocalJacobianMatrix[localNodeI][localNodeJ];\n }\n }\n\n // Assemble local element residual\n for (let localNodeIndex = 0; localNodeIndex < FEAData.numNodes; localNodeIndex++) {\n const globalNodeIndex = ngl[localNodeIndex] - 1;\n frontalData.globalResidualVector[globalNodeIndex] +=\n localResidualVector[localNodeIndex] + boundaryResidualVector[localNodeIndex];\n }\n\n return true;\n}\n\n/**\n * Function to implement the frontal solver algorithm\n * @param {object} meshData - Object containing mesh data\n * @param {object} FEAData - Object containing FEA-related data\n * @param {object} thermalBoundaryConditions - Object containing thermal boundary conditions\n * @param {function} assembleFront - Matrix assembler based on the physical model\n */\nfunction runFrontalAlgorithm(meshData, FEAData, thermalBoundaryConditions, assembleFront) {\n // Allocate local arrays dynamically\n const totalElements = meshData.totalElements;\n const numNodes = meshData.nodesXCoordinates.length;\n const systemSize = Math.max(numNodes, frontalState.globalSolutionVector.length);\n let localDestination = Array(FEAData.numNodes).fill(0);\n let rowDestination = Array(FEAData.numNodes).fill(0);\n let rowHeaders = Array(systemSize).fill(0);\n let pivotRowIndices = Array(systemSize).fill(0);\n let pivotColumnIndices = Array(systemSize).fill(0);\n let modifiedRows = Array(systemSize).fill(0);\n let pivotColumn = Array(systemSize).fill(0);\n let frontMatrix = Array(systemSize)\n .fill()\n .map(() => Array(systemSize).fill(0));\n let rowSwapCount = Array(numNodes).fill(0);\n let columnSwapCount = Array(numNodes).fill(0);\n let lastAppearanceCheck = Array(numNodes).fill(0);\n let pivotColumnGlobalIndex; // Pivot column global index\n\n let frontDataCounter = 1;\n frontalState.writeFlag++;\n let pivotDataIndex = 1;\n let summedRows = 1;\n elementData.currentElementIndex = 0;\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n rowSwapCount[nodeIndex] = 0;\n columnSwapCount[nodeIndex] = 0;\n }\n\n if (frontalState.transformationFlag !== 0) {\n // Prefront: find last appearance of each node\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n lastAppearanceCheck[nodeIndex] = 0;\n }\n\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n let reverseElementIndex = totalElements - elementIndex - 1;\n for (\n let localNodeIndex = 0;\n localNodeIndex < frontalState.nodesPerElement[reverseElementIndex];\n localNodeIndex++\n ) {\n let globalNodeIndex = frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n if (lastAppearanceCheck[globalNodeIndex - 1] === 0) {\n lastAppearanceCheck[globalNodeIndex - 1] = 1;\n frontalData.nodalNumbering[reverseElementIndex][localNodeIndex] =\n -frontalData.nodalNumbering[reverseElementIndex][localNodeIndex];\n }\n }\n }\n }\n\n frontalState.transformationFlag = 0;\n let columnCount = 0;\n let rowCount = 0;\n\n for (let i = 0; i < systemSize; i++) {\n for (let j = 0; j < systemSize; j++) {\n frontMatrix[j][i] = 0;\n }\n }\n\n while (true) {\n // Assemble a new element only while we still have elements\n let assembled = false;\n let numElementNodes = 0;\n let numElementColumns = 0;\n\n if (elementData.currentElementIndex < totalElements) {\n elementData.currentElementIndex++;\n assembled = assembleElementContribution(meshData, FEAData, thermalBoundaryConditions, assembleFront);\n }\n\n if (assembled) {\n const currentElement = elementData.currentElementIndex;\n numElementNodes = frontalState.nodesPerElement[currentElement - 1];\n numElementColumns = frontalState.nodesPerElement[currentElement - 1];\n\n for (let localNodeIndex = 0; localNodeIndex < numElementColumns; localNodeIndex++) {\n let globalNodeIndex = frontalData.nodalNumbering[currentElement - 1][localNodeIndex];\n let columnIndex;\n\n if (columnCount === 0) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(frontStorage.columnHeaders[columnIndex])) break;\n }\n\n if (columnIndex === columnCount) {\n columnCount++;\n localDestination[localNodeIndex] = columnCount;\n frontStorage.columnHeaders[columnCount - 1] = globalNodeIndex;\n } else {\n localDestination[localNodeIndex] = columnIndex + 1;\n frontStorage.columnHeaders[columnIndex] = globalNodeIndex;\n }\n }\n\n let rowIndex;\n if (rowCount === 0) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n if (Math.abs(globalNodeIndex) === Math.abs(rowHeaders[rowIndex])) break;\n }\n\n if (rowIndex === rowCount) {\n rowCount++;\n rowDestination[localNodeIndex] = rowCount;\n rowHeaders[rowCount - 1] = globalNodeIndex;\n } else {\n rowDestination[localNodeIndex] = rowIndex + 1;\n rowHeaders[rowIndex] = globalNodeIndex;\n }\n }\n }\n\n if (rowCount > systemSize || columnCount > systemSize) {\n errorLog(\"Error: systemSize not large enough\");\n return;\n }\n\n for (let localColumnIndex = 0; localColumnIndex < numElementColumns; localColumnIndex++) {\n let frontColumnIndex = localDestination[localColumnIndex];\n for (let localRowIndex = 0; localRowIndex < numElementNodes; localRowIndex++) {\n let frontRowIndex = rowDestination[localRowIndex];\n frontMatrix[frontRowIndex - 1][frontColumnIndex - 1] +=\n elementData.localJacobianMatrix[localRowIndex][localColumnIndex];\n }\n }\n }\n\n // Pivoting/elimination continues whether or not a new element was assembled\n let availableColumnCount = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n if (frontStorage.columnHeaders[columnIndex] < 0) {\n pivotColumnIndices[availableColumnCount] = columnIndex + 1;\n availableColumnCount++;\n }\n }\n\n let constrainedRowCount = 0;\n let availableRowCount = 0;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n let globalNodeIndex = rowHeaders[rowIndex];\n if (globalNodeIndex < 0) {\n pivotRowIndices[availableRowCount] = rowIndex + 1;\n availableRowCount++;\n let absoluteNodeIndex = Math.abs(globalNodeIndex);\n if (frontalData.nodeConstraintCode[absoluteNodeIndex - 1] === 1) {\n modifiedRows[constrainedRowCount] = rowIndex + 1;\n constrainedRowCount++;\n frontalData.nodeConstraintCode[absoluteNodeIndex - 1] = 2;\n frontalData.globalResidualVector[absoluteNodeIndex - 1] =\n frontalData.boundaryValues[absoluteNodeIndex - 1];\n }\n }\n }\n\n if (constrainedRowCount > 0) {\n for (let constrainedIndex = 0; constrainedIndex < constrainedRowCount; constrainedIndex++) {\n let rowIndex = modifiedRows[constrainedIndex] - 1;\n let globalNodeIndex = Math.abs(rowHeaders[rowIndex]);\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] = 0;\n let columnGlobalIndex = Math.abs(frontStorage.columnHeaders[columnIndex]);\n if (columnGlobalIndex === globalNodeIndex) frontMatrix[rowIndex][columnIndex] = 1;\n }\n }\n }\n\n if (availableColumnCount > summedRows || elementData.currentElementIndex < totalElements) {\n if (availableColumnCount === 0) {\n errorLog(\"Error: no more rows fully summed\");\n return;\n }\n\n let pivotRowIndex = pivotRowIndices[0];\n let pivotColumnIndex = pivotColumnIndices[0];\n let pivotValue = frontMatrix[pivotRowIndex - 1][pivotColumnIndex - 1];\n\n if (Math.abs(pivotValue) < 1e-4) {\n pivotValue = 0;\n for (let columnIndex = 0; columnIndex < availableColumnCount; columnIndex++) {\n let testColumnIndex = pivotColumnIndices[columnIndex];\n for (let rowIndex = 0; rowIndex < availableRowCount; rowIndex++) {\n let testRowIndex = pivotRowIndices[rowIndex];\n let testValue = frontMatrix[testRowIndex - 1][testColumnIndex - 1];\n if (Math.abs(testValue) > Math.abs(pivotValue)) {\n pivotValue = testValue;\n pivotColumnIndex = testColumnIndex;\n pivotRowIndex = testRowIndex;\n }\n }\n }\n }\n\n let pivotGlobalRowIndex = Math.abs(rowHeaders[pivotRowIndex - 1]);\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]); // Assign, don't declare\n let permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n if (nodeIndex >= pivotGlobalRowIndex) rowSwapCount[nodeIndex]--;\n if (nodeIndex >= pivotColumnGlobalIndex) columnSwapCount[nodeIndex]--;\n }\n\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontMatrix[pivotRowIndex - 1][columnIndex] / pivotValue;\n }\n\n let rightHandSide = frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] = rightHandSide;\n pivotColumn[pivotRowIndex - 1] = pivotValue;\n\n if (pivotRowIndex > 1) {\n for (let rowIndex = 0; rowIndex < pivotRowIndex - 1; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1 && eliminationFactor !== 0) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex][columnIndex] -= eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n if (pivotRowIndex < rowCount) {\n for (let rowIndex = pivotRowIndex; rowIndex < rowCount; rowIndex++) {\n let globalRowIndex = Math.abs(rowHeaders[rowIndex]);\n let eliminationFactor = frontMatrix[rowIndex][pivotColumnIndex - 1];\n pivotColumn[rowIndex] = eliminationFactor;\n if (pivotColumnIndex > 1) {\n for (let columnIndex = 0; columnIndex < pivotColumnIndex - 1; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n if (pivotColumnIndex < columnCount) {\n for (let columnIndex = pivotColumnIndex; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowIndex - 1][columnIndex - 1] =\n frontMatrix[rowIndex][columnIndex] - eliminationFactor * frontStorage.pivotRow[columnIndex];\n }\n }\n frontalData.globalResidualVector[globalRowIndex - 1] -= eliminationFactor * rightHandSide;\n }\n }\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = pivotColumn[i];\n }\n pivotDataIndex += rowCount;\n\n for (let i = 0; i < rowCount; i++) {\n frontStorage.pivotData[pivotDataIndex + i - 1] = rowHeaders[i];\n }\n pivotDataIndex += rowCount;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.pivotRow[i];\n }\n frontDataCounter += columnCount;\n\n for (let i = 0; i < columnCount; i++) {\n frontStorage.frontValues[frontDataCounter - 1 + i] = frontStorage.columnHeaders[i];\n }\n frontDataCounter += columnCount;\n\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n frontMatrix[rowIndex][columnCount - 1] = 0;\n }\n\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontMatrix[rowCount - 1][columnIndex] = 0;\n }\n\n columnCount--;\n if (pivotColumnIndex < columnCount + 1) {\n for (let columnIndex = pivotColumnIndex - 1; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] = frontStorage.columnHeaders[columnIndex + 1];\n }\n }\n\n rowCount--;\n if (pivotRowIndex < rowCount + 1) {\n for (let rowIndex = pivotRowIndex - 1; rowIndex < rowCount; rowIndex++) {\n rowHeaders[rowIndex] = rowHeaders[rowIndex + 1];\n }\n }\n\n if (rowCount > 1 || elementData.currentElementIndex < totalElements) continue;\n\n pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[0]); // Assign, don't declare\n pivotRowIndex = 1;\n pivotValue = frontMatrix[0][0];\n pivotGlobalRowIndex = Math.abs(rowHeaders[0]);\n pivotColumnIndex = 1;\n permutationHelper =\n pivotGlobalRowIndex +\n pivotColumnGlobalIndex +\n rowSwapCount[pivotGlobalRowIndex - 1] +\n columnSwapCount[pivotColumnGlobalIndex - 1];\n frontalState.determinant =\n (frontalState.determinant * pivotValue * (-1) ** permutationHelper) / Math.abs(pivotValue);\n\n frontStorage.pivotRow[0] = 1;\n if (Math.abs(pivotValue) < 1e-10) {\n errorLog(\n `Matrix singular or ill-conditioned, currentElementIndex=${elementData.currentElementIndex}, pivotGlobalRowIndex=${pivotGlobalRowIndex}, pivotColumnGlobalIndex=${pivotColumnGlobalIndex}, pivotValue=${pivotValue}`\n );\n }\n\n if (pivotValue === 0) return;\n\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] =\n frontalData.globalResidualVector[pivotGlobalRowIndex - 1] / pivotValue;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.pivotRow[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = frontStorage.columnHeaders[0];\n frontDataCounter++;\n frontStorage.frontValues[frontDataCounter - 1] = pivotGlobalRowIndex;\n frontStorage.frontValues[frontDataCounter] = columnCount;\n frontStorage.frontValues[frontDataCounter + 1] = pivotColumnIndex;\n frontStorage.frontValues[frontDataCounter + 2] = pivotValue;\n frontDataCounter += 4;\n\n frontStorage.pivotData[pivotDataIndex - 1] = pivotColumn[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = rowHeaders[0];\n pivotDataIndex++;\n frontStorage.pivotData[pivotDataIndex - 1] = pivotRowIndex;\n pivotDataIndex++;\n\n frontalState.frontDataIndex = frontDataCounter;\n if (frontalState.writeFlag === 1)\n debugLog(`total ecs transfer in matrix reduction=${frontDataCounter}`);\n\n // Back substitution\n performBackSubstitution(frontDataCounter);\n break;\n }\n }\n}\n\n/**\n * Function to perform back substitution for the frontal solver\n * @param {number} frontDataCounter - Index counter for the element contributions\n */\nfunction performBackSubstitution(frontDataCounter) {\n for (let nodeIndex = 0; nodeIndex < frontalState.totalNodes; nodeIndex++) {\n frontalState.globalSolutionVector[nodeIndex] = frontalData.boundaryValues[nodeIndex];\n }\n\n for (let iterationIndex = 1; iterationIndex <= frontalState.totalNodes; iterationIndex++) {\n frontDataCounter -= 4;\n let pivotGlobalRowIndex = frontStorage.frontValues[frontDataCounter - 1];\n let columnCount = frontStorage.frontValues[frontDataCounter];\n let pivotColumnIndex = frontStorage.frontValues[frontDataCounter + 1];\n let pivotValue = frontStorage.frontValues[frontDataCounter + 2];\n\n if (iterationIndex === 1) {\n frontDataCounter--;\n frontStorage.columnHeaders[0] = frontStorage.frontValues[frontDataCounter - 1];\n frontDataCounter--;\n frontStorage.pivotRow[0] = frontStorage.frontValues[frontDataCounter - 1];\n } else {\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.columnHeaders[columnIndex] =\n frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n frontDataCounter -= columnCount;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n frontStorage.pivotRow[columnIndex] = frontStorage.frontValues[frontDataCounter - 1 + columnIndex];\n }\n }\n\n let pivotColumnGlobalIndex = Math.abs(frontStorage.columnHeaders[pivotColumnIndex - 1]);\n if (frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] > 0) continue;\n\n let accumulatedValue = 0;\n frontStorage.pivotRow[pivotColumnIndex - 1] = 0;\n for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {\n accumulatedValue -=\n frontStorage.pivotRow[columnIndex] *\n frontalState.globalSolutionVector[Math.abs(frontStorage.columnHeaders[columnIndex]) - 1];\n }\n\n frontalState.globalSolutionVector[pivotColumnGlobalIndex - 1] =\n accumulatedValue + frontalData.globalResidualVector[pivotGlobalRowIndex - 1];\n\n frontalData.nodeConstraintCode[pivotColumnGlobalIndex - 1] = 1;\n }\n\n if (frontalState.writeFlag === 1)\n debugLog(`value of frontDataCounter after backsubstitution=${frontDataCounter}`);\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { euclideanNorm } from \"../methods/euclideanNormScript.js\";\nimport { solveLinearSystem } from \"./linearSystemSolverScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\nimport { runFrontalSolver } from \"./frontalSolverScript.js\";\nimport { assembleFrontPropagationFront } from \"../models/frontPropagationScript.js\";\n\n/**\n * Function to solve a system of non-linear equations using the Newton-Raphson method\n * @param {function} assembleMat - Matrix assembler based on the physical model\n * @param {object} context - Context object containing simulation data and options\n * @returns {object} An object containing:\n * - solutionVector: The solution vector\n * - iterations: The number of iterations performed\n * - converged: Boolean indicating whether the method converged\n */\n\nexport function newtonRaphson(assembleMat, context = {}) {\n let errorNorm = 0;\n let converged = false;\n let iterations = 0;\n let deltaX = [];\n let solutionVector = [];\n let jacobianMatrix = [];\n let residualVector = [];\n\n // Extract context\n const { maxIterations = 100, tolerance = 1e-4 } = context;\n\n // Calculate system size\n let totalNodes = context.meshData.nodesXCoordinates.length;\n\n // Initialize arrays with proper size\n for (let i = 0; i < totalNodes; i++) {\n deltaX[i] = 0;\n solutionVector[i] = 0;\n }\n\n // Initialize solution from context if available\n if (context.initialSolution && context.initialSolution.length === totalNodes) {\n solutionVector = [...context.initialSolution];\n }\n\n while (iterations < maxIterations && !converged) {\n // Update solution\n for (let i = 0; i < solutionVector.length; i++) {\n solutionVector[i] = Number(solutionVector[i]) + Number(deltaX[i]);\n }\n\n // Check if using frontal solver\n if (context.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleFrontPropagationFront,\n context.meshData,\n context.boundaryConditions,\n { solutionVector, eikonalActivationFlag: context.eikonalActivationFlag }\n );\n deltaX = frontalResult.solutionVector;\n } else {\n // Compute Jacobian and residual matrices\n ({ jacobianMatrix, residualVector } = assembleMat(\n context.meshData,\n context.boundaryConditions,\n solutionVector, // The solution vector is required in the case of a non-linear equation\n context.eikonalActivationFlag // Currently used only in the front propagation solver (TODO refactor in case of a solver not needing it)\n ));\n\n // Solve the linear system based on the specified solver method\n const linearSystemResult = solveLinearSystem(context.solverMethod, jacobianMatrix, residualVector);\n deltaX = linearSystemResult.solutionVector;\n }\n\n // Check convergence\n errorNorm = euclideanNorm(deltaX);\n\n // Norm for each iteration\n basicLog(`Newton-Raphson iteration ${iterations + 1}: Error norm = ${errorNorm.toExponential(4)}`);\n\n if (errorNorm <= tolerance) {\n converged = true;\n } else if (errorNorm > 1e2) {\n errorLog(`Solution not converged. Error norm: ${errorNorm}`);\n break;\n }\n\n iterations++;\n }\n\n return {\n solutionVector,\n converged,\n iterations,\n jacobianMatrix,\n residualVector,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { newtonRaphson } from \"./methods/newtonRaphsonScript.js\";\nimport { solveLinearSystem } from \"./methods/linearSystemSolverScript.js\";\nimport { solveLinearSystemAsync } from \"./methods/linearSystemSolverScript.js\";\nimport { prepareMesh } from \"./mesh/meshUtilsScript.js\";\nimport { assembleFrontPropagationMat } from \"./models/frontPropagationScript.js\";\nimport { assembleGeneralFormPDEMat, assembleGeneralFormPDEFront } from \"./models/generalFormPDEScript.js\";\nimport { assembleHeatConductionMat, assembleHeatConductionFront } from \"./models/heatConductionScript.js\";\nimport { runFrontalSolver } from \"./methods/frontalSolverScript.js\";\nimport { basicLog, debugLog, warnLog, errorLog } from \"./utilities/loggingScript.js\";\n\n/**\n * Class to implement finite element analysis in JavaScript\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} meshConfig - Object containing computational mesh details\n * @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis\n * @returns {object} An object containifng the solution vector and additional mesh information\n */\nexport class FEAScriptModel {\n constructor() {\n this.solverConfig = null;\n this.meshConfig = {};\n this.boundaryConditions = {};\n this.solverMethod = \"lusolve\"; // Default solver method\n this.coefficientFunctions = null; // Add storage for coefficient functions\n warnLog(\n \"FEAScript is provided “as is” without any warranty. The authors are not responsible for any damages or losses that may result from using the software. See the license for more details: https://github.com/FEAScript/FEAScript-core/blob/main/LICENSE\"\n );\n basicLog(\"FEAScriptModel instance created\");\n }\n\n /**\n * Sets the solver configuration\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {object} [options] - Optional additional configuration\n */\n setSolverConfig(solverConfig, options = {}) {\n this.solverConfig = solverConfig;\n\n // Store coefficient functions if provided\n if (options?.coefficientFunctions) {\n this.coefficientFunctions = options.coefficientFunctions;\n debugLog(\"Coefficient functions set\");\n }\n // Only update if a value is provided, otherwise keep the default\n if (options?.maxIterations !== undefined) {\n this.maxIterations = options.maxIterations;\n }\n if (options?.tolerance !== undefined) {\n this.tolerance = options.tolerance;\n }\n\n debugLog(`Solver config set to: ${solverConfig}`);\n }\n\n setMeshConfig(meshConfig) {\n this.meshConfig = meshConfig;\n debugLog(`Mesh config set with dimensions: ${meshConfig.meshDimension}`);\n }\n\n addBoundaryCondition(boundaryKey, condition) {\n this.boundaryConditions[boundaryKey] = condition;\n debugLog(`Boundary condition added for boundary: ${boundaryKey}, type: ${condition[0]}`);\n }\n\n setSolverMethod(solverMethod) {\n this.solverMethod = solverMethod;\n debugLog(`Solver method set to: ${solverMethod}`);\n }\n\n /**\n * Function to solve the finite element problem synchronously\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {object} An object containing the solution vector and the coordinates of the mesh nodes\n */\n solve(options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n /**\n * For consistency across both linear and nonlinear formulations,\n * this project always refers to the assembled right-hand side vector\n * as `residualVector` and the assembled system matrix as `jacobianMatrix`.\n *\n * In linear problems `jacobianMatrix` is equivalent to the\n * classic stiffness/conductivity matrix and `residualVector`\n * corresponds to the traditional load (RHS) vector.\n */\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n let initialSolution = [];\n\n // Prepare the mesh\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n\n // Extract node coordinates from meshData\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n // Select and execute the appropriate solver based on solverConfig\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n const frontalResult = runFrontalSolver(\n assembleHeatConductionFront,\n meshData,\n this.boundaryConditions\n );\n solutionVector = frontalResult.solutionVector;\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n } else if (this.solverConfig === \"frontPropagationScript\") {\n // Initialize eikonalActivationFlag\n let eikonalActivationFlag = 0;\n const eikonalExteralIterations = 5; // Number of incremental steps for the eikonal equation\n\n // Create context object with all necessary properties\n const context = {\n meshData: meshData,\n boundaryConditions: this.boundaryConditions,\n eikonalActivationFlag: eikonalActivationFlag,\n solverMethod: this.solverMethod,\n initialSolution,\n // TODO: Consider using different maxIterations/tolerance for Newton-Raphson and linear solver\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n };\n\n while (eikonalActivationFlag <= 1) {\n // Update the context object with current eikonalActivationFlag\n context.eikonalActivationFlag = eikonalActivationFlag;\n\n // Pass the previous solution as initial guess\n if (solutionVector.length > 0) {\n context.initialSolution = [...solutionVector];\n }\n\n // Solve the assembled non-linear system\n const newtonRaphsonResult = newtonRaphson(assembleFrontPropagationMat, context);\n\n // Extract results\n jacobianMatrix = newtonRaphsonResult.jacobianMatrix;\n residualVector = newtonRaphsonResult.residualVector;\n solutionVector = newtonRaphsonResult.solutionVector;\n\n // Increment for next iteration\n eikonalActivationFlag += 1 / eikonalExteralIterations;\n }\n } else if (this.solverConfig === \"generalFormPDEScript\") {\n // Check if using frontal solver\n if (this.solverMethod === \"frontal\") {\n errorLog(\n \"Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.\"\n );\n } else {\n // Use regular linear solver methods\n ({ jacobianMatrix, residualVector } = assembleGeneralFormPDEMat(\n meshData,\n this.boundaryConditions,\n this.coefficientFunctions\n ));\n\n const linearSystemResult = solveLinearSystem(this.solverMethod, jacobianMatrix, residualVector, {\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = linearSystemResult.solutionVector;\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n /**\n * Function to solve the finite element problem asynchronously\n * @param {object} computeEngine - The compute engine to use for the asynchronous solver (e.g., a worker or a WebGPU context)\n * @param {object} [options] - Additional parameters for the solver, such as `maxIterations` and `tolerance`\n * @returns {Promise} A promise that resolves to an object containing the solution vector and the coordinates of the mesh nodes\n */\n async solveAsync(computeEngine, options = {}) {\n if (!this.solverConfig || !this.meshConfig || !this.boundaryConditions) {\n errorLog(\"Solver config, mesh config, and boundary conditions must be set before solving.\");\n }\n\n let jacobianMatrix = [];\n let residualVector = [];\n let solutionVector = [];\n\n basicLog(\"Preparing mesh...\");\n const meshData = prepareMesh(this.meshConfig);\n basicLog(\"Mesh preparation completed\");\n const nodesCoordinates = {\n nodesXCoordinates: meshData.nodesXCoordinates,\n nodesYCoordinates: meshData.nodesYCoordinates,\n };\n\n basicLog(\"Beginning solving process...\");\n console.time(\"totalSolvingTime\");\n\n basicLog(`Using solver: ${this.solverConfig}`);\n if (this.solverConfig === \"heatConductionScript\") {\n ({ jacobianMatrix, residualVector } = assembleHeatConductionMat(meshData, this.boundaryConditions));\n\n if (this.solverMethod === \"jacobi-gpu\") {\n const { solutionVector: x } = await solveLinearSystemAsync(\"jacobi-gpu\", jacobianMatrix, residualVector, {\n computeEngine,\n maxIterations: options.maxIterations ?? this.maxIterations,\n tolerance: options.tolerance ?? this.tolerance,\n });\n solutionVector = x;\n } else {\n // Other async solver\n }\n }\n console.timeEnd(\"totalSolvingTime\");\n basicLog(\"Solving process completed\");\n\n return { solutionVector, nodesCoordinates };\n }\n\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { initializeFEA, performIsoparametricMapping1D } from \"../mesh/meshUtilsScript.js\";\nimport { GenericBoundaryConditions } from \"./genericBoundaryConditionsScript.js\";\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to assemble the Jacobian matrix and residuals vector for the general form PDE model\n * @param {object} meshData - Object containing prepared mesh data\n * @param {object} boundaryConditions - Object containing boundary conditions\n * @param {object} coefficientFunctions - Functions A(x), B(x), C(x), D(x) for the PDE\n * @returns {object} An object containing:\n * - jacobianMatrix: The assembled Jacobian matrix\n * - residualVector: The assembled residual vector\n */\nexport function assembleGeneralFormPDEMat(meshData, boundaryConditions, coefficientFunctions) {\n basicLog(\"Starting general form PDE matrix assembly...\");\n\n // Extract mesh data\n const {\n nodesXCoordinates,\n nodesYCoordinates,\n nop,\n boundaryElements,\n totalElements,\n meshDimension,\n elementOrder,\n } = meshData;\n\n // Extract coefficient functions\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize FEA components\n const FEAData = initializeFEA(meshData);\n const {\n residualVector,\n jacobianMatrix,\n localToGlobalMap,\n basisFunctions,\n gaussPoints,\n gaussWeights,\n numNodes,\n } = FEAData;\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Matrix assembly\n for (let elementIndex = 0; elementIndex < totalElements; elementIndex++) {\n // Map local element nodes to global mesh nodes\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n // Convert to 0-based indexing\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of Galerkin's residuals and local Jacobian matrix\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];\n\n // Source term contribution to residual vector\n residualVector[globalNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n const globalNodeIndex2 = localToGlobalMap[localNodeIndex2];\n\n // Diffusion term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEMat.\");\n // 2D general form PDE - empty for now\n }\n\n // Apply boundary conditions\n const genericBoundaryConditions = new GenericBoundaryConditions(\n boundaryConditions,\n boundaryElements,\n nop,\n meshDimension,\n elementOrder\n );\n\n // Apply Dirichlet boundary conditions only\n genericBoundaryConditions.imposeDirichletBoundaryConditions(residualVector, jacobianMatrix);\n\n basicLog(\"General form PDE matrix assembly completed\");\n\n return {\n jacobianMatrix,\n residualVector,\n };\n}\n\n/**\n * Function to assemble the frontal solver matrix for the general form PDE model\n * @param {object} data - Object containing element data for the frontal solver\n * @returns {object} An object containing local Jacobian matrix and residual vector\n */\nexport function assembleGeneralFormPDEFront({\n elementIndex,\n nop,\n meshData,\n basisFunctions,\n FEAData,\n coefficientFunctions,\n}) {\n // Extract numerical integration parameters and mesh coordinates\n const { gaussPoints, gaussWeights, numNodes } = FEAData;\n const { nodesXCoordinates, nodesYCoordinates, meshDimension } = meshData;\n const { A, B, C, D } = coefficientFunctions;\n\n // Initialize local Jacobian matrix and local residual vector\n const localJacobianMatrix = Array(numNodes)\n .fill()\n .map(() => Array(numNodes).fill(0));\n const localResidualVector = Array(numNodes).fill(0);\n\n // Build the mapping from local node indices to global node indices\n const ngl = Array(numNodes);\n const localToGlobalMap = Array(numNodes);\n for (let localNodeIndex = 0; localNodeIndex < numNodes; localNodeIndex++) {\n ngl[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]);\n localToGlobalMap[localNodeIndex] = Math.abs(nop[elementIndex][localNodeIndex]) - 1;\n }\n\n if (meshDimension === \"1D\") {\n // 1D general form PDE\n\n // Loop over Gauss points\n for (let gaussPointIndex = 0; gaussPointIndex < gaussPoints.length; gaussPointIndex++) {\n // Get basis functions for the current Gauss point\n const { basisFunction, basisFunctionDerivKsi } = basisFunctions.getBasisFunctions(\n gaussPoints[gaussPointIndex]\n );\n\n // Perform isoparametric mapping\n const { detJacobian, basisFunctionDerivX } = performIsoparametricMapping1D({\n basisFunction,\n basisFunctionDerivKsi,\n nodesXCoordinates,\n localToGlobalMap,\n numNodes,\n });\n\n // Calculate the physical coordinate for this Gauss point\n let xCoord = 0;\n for (let i = 0; i < numNodes; i++) {\n xCoord += nodesXCoordinates[localToGlobalMap[i]] * basisFunction[i];\n }\n\n // Evaluate coefficient functions at this physical coordinate\n const a = A(xCoord);\n const b = B(xCoord);\n const c = C(xCoord);\n const d = D(xCoord);\n\n // Computation of local Jacobian matrix and residual vector\n for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {\n // Source term contribution to local residual vector\n localResidualVector[localNodeIndex1] -=\n gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];\n\n for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {\n // Diffusion term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n a *\n basisFunctionDerivX[localNodeIndex1] *\n basisFunctionDerivX[localNodeIndex2];\n\n // Advection term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n b *\n basisFunctionDerivX[localNodeIndex2] *\n basisFunction[localNodeIndex1];\n\n // Reaction term\n localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=\n gaussWeights[gaussPointIndex] *\n detJacobian *\n c *\n basisFunction[localNodeIndex1] *\n basisFunction[localNodeIndex2];\n }\n }\n }\n } else if (meshDimension === \"2D\") {\n errorLog(\"2D general form PDE is not yet supported in assembleGeneralFormPDEFront.\");\n // 2D general form PDE - empty for now\n }\n\n return {\n localJacobianMatrix,\n localResidualVector,\n ngl,\n };\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// External imports\nimport * as Comlink from \"../vendor/comlink.mjs\";\n\n// Internal imports\nimport { basicLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Class to facilitate communication with web workers for FEAScript operations\n */\nexport class FEAScriptWorker {\n /**\n * Constructor to initialize the FEAScriptWorker class\n * Sets up the worker and initializes the workerWrapper.\n */\n constructor() {\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n\n this._initWorker();\n }\n\n /**\n * Function to initialize the web worker and wrap it using Comlink.\n * @private\n * @throws Will throw an error if the worker fails to initialize.\n */\n async _initWorker() {\n try {\n this.worker = new Worker(new URL(\"./wrapperScript.js\", import.meta.url), {\n type: \"module\",\n });\n\n this.worker.onerror = (event) => {\n console.error(\"FEAScriptWorker: Worker error:\", event);\n };\n const workerWrapper = Comlink.wrap(this.worker);\n\n this.feaWorker = await new workerWrapper();\n\n this.isReady = true;\n } catch (error) {\n console.error(\"Failed to initialize worker\", error);\n throw error;\n }\n }\n\n /**\n * Function to ensure that the worker is ready before performing any operations.\n * @private\n * @returns {Promise} Resolves when the worker is ready.\n * @throws Will throw an error if the worker is not ready within the timeout period.\n */\n async _ensureReady() {\n if (this.isReady) return Promise.resolve();\n\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds max\n\n const checkReady = () => {\n attempts++;\n if (this.isReady) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(\"Timeout waiting for worker to be ready\"));\n } else {\n setTimeout(checkReady, 1000);\n }\n };\n checkReady();\n });\n }\n\n /**\n * Function to set the solver configuration in the worker.\n * @param {string} solverConfig - The solver configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setSolverConfig(solverConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver config to: ${solverConfig}`);\n return this.feaWorker.setSolverConfig(solverConfig);\n }\n\n /**\n * Sets the mesh configuration in the worker.\n * @param {object} meshConfig - The mesh configuration to set.\n * @returns {Promise} Resolves when the configuration is set.\n */\n async setMeshConfig(meshConfig) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting mesh config`);\n return this.feaWorker.setMeshConfig(meshConfig);\n }\n\n /**\n * Adds a boundary condition to the worker.\n * @param {string} boundaryKey - The key identifying the boundary.\n * @param {array} condition - The boundary condition to add.\n * @returns {Promise} Resolves when the boundary condition is added.\n */\n async addBoundaryCondition(boundaryKey, condition) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Adding boundary condition for boundary: ${boundaryKey}`);\n return this.feaWorker.addBoundaryCondition(boundaryKey, condition);\n }\n\n /**\n * Sets the solver method in the worker.\n * @param {string} solverMethod - The solver method to set.\n * @returns {Promise} Resolves when the solver method is set.\n */\n async setSolverMethod(solverMethod) {\n await this._ensureReady();\n basicLog(`FEAScriptWorker: Setting solver method to: ${solverMethod}`);\n return this.feaWorker.setSolverMethod(solverMethod);\n }\n\n /**\n * Requests the worker to solve the problem.\n * @returns {Promise} Resolves with the solution result.\n */\n async solve() {\n await this._ensureReady();\n basicLog(\"FEAScriptWorker: Requesting solution from worker...\");\n\n const startTime = performance.now();\n const result = await this.feaWorker.solve();\n const endTime = performance.now();\n\n basicLog(`FEAScriptWorker: Solution completed in ${((endTime - startTime) / 1000).toFixed(2)}s`);\n return result;\n }\n\n /**\n * Retrieves model information from the worker.\n * @returns {Promise} Resolves with the model information.\n */\n async getModelInfo() {\n await this._ensureReady();\n return this.feaWorker.getModelInfo();\n }\n\n /**\n * Sends a ping request to the worker to check its availability.\n * @returns {Promise} Resolves if the worker responds.\n */\n async ping() {\n await this._ensureReady();\n return this.feaWorker.ping();\n }\n\n /**\n * Terminates the worker and cleans up resources.\n */\n terminate() {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.feaWorker = null;\n this.isReady = false;\n }\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n// Internal imports\nimport { basicLog, debugLog, errorLog } from \"../utilities/loggingScript.js\";\n\n/**\n * Function to import mesh data from Gmsh format containing quadrilateral and triangular elements\n * @param {File} file - The Gmsh file to be parsed (.msh version 4.1)\n * @returns {object} The parsed mesh data including node coordinates, element connectivity, and boundary conditions\n */\nconst importGmshQuadTri = async (file) => {\n let result = {\n nodesXCoordinates: [],\n nodesYCoordinates: [],\n nodalNumbering: {\n quadElements: [],\n triangleElements: [],\n },\n boundaryElements: [],\n boundaryConditions: [],\n boundaryNodePairs: {}, // Store boundary node pairs for processing in meshGenerationScript\n gmshV: 0,\n ascii: false,\n fltBytes: \"8\",\n totalNodesX: 0,\n totalNodesY: 0,\n physicalPropMap: [],\n elementTypes: {},\n };\n\n let content = await file.text();\n let lines = content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line !== \"\" && line !== \" \");\n\n let section = \"\";\n let lineIndex = 0;\n\n let nodeEntityBlocks = 0;\n let totalNodes = 0;\n let nodeBlocksProcessed = 0;\n let currentNodeBlock = { numNodes: 0 };\n let nodeTagsCollected = 0;\n let nodeTags = [];\n let nodeCoordinatesCollected = 0;\n\n let elementEntityBlocks = 0;\n let totalElements = 0;\n let elementBlocksProcessed = 0;\n let currentElementBlock = {\n dim: 0,\n tag: 0,\n elementType: 0,\n numElements: 0,\n };\n let elementsProcessedInBlock = 0;\n\n let boundaryElementsByTag = {};\n\n while (lineIndex < lines.length) {\n const line = lines[lineIndex];\n\n if (line === \"$MeshFormat\") {\n section = \"meshFormat\";\n lineIndex++;\n continue;\n } else if (line === \"$EndMeshFormat\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$PhysicalNames\") {\n section = \"physicalNames\";\n lineIndex++;\n continue;\n } else if (line === \"$EndPhysicalNames\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Entities\") {\n section = \"entities\";\n lineIndex++;\n continue;\n } else if (line === \"$EndEntities\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Nodes\") {\n section = \"nodes\";\n lineIndex++;\n continue;\n } else if (line === \"$EndNodes\") {\n section = \"\";\n lineIndex++;\n continue;\n } else if (line === \"$Elements\") {\n section = \"elements\";\n lineIndex++;\n continue;\n } else if (line === \"$EndElements\") {\n section = \"\";\n lineIndex++;\n continue;\n }\n\n const parts = line.split(/\\s+/).filter((part) => part !== \"\");\n\n if (section === \"meshFormat\") {\n result.gmshV = parseFloat(parts[0]);\n result.ascii = parts[1] === \"0\";\n result.fltBytes = parts[2];\n } else if (section === \"physicalNames\") {\n if (parts.length >= 3) {\n if (!/^\\d+$/.test(parts[0])) {\n lineIndex++;\n continue;\n }\n\n const dimension = parseInt(parts[0], 10);\n const tag = parseInt(parts[1], 10);\n let name = parts.slice(2).join(\" \");\n name = name.replace(/^\"|\"$/g, \"\");\n\n result.physicalPropMap.push({\n tag,\n dimension,\n name,\n });\n }\n } else if (section === \"nodes\") {\n if (nodeEntityBlocks === 0) {\n nodeEntityBlocks = parseInt(parts[0], 10);\n totalNodes = parseInt(parts[1], 10);\n result.nodesXCoordinates = new Array(totalNodes).fill(0);\n result.nodesYCoordinates = new Array(totalNodes).fill(0);\n lineIndex++;\n continue;\n }\n\n if (nodeBlocksProcessed < nodeEntityBlocks && currentNodeBlock.numNodes === 0) {\n currentNodeBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n parametric: parseInt(parts[2], 10),\n numNodes: parseInt(parts[3], 10),\n };\n\n nodeTags = [];\n nodeTagsCollected = 0;\n nodeCoordinatesCollected = 0;\n\n lineIndex++;\n continue;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n for (let i = 0; i < parts.length && nodeTagsCollected < currentNodeBlock.numNodes; i++) {\n nodeTags.push(parseInt(parts[i], 10));\n nodeTagsCollected++;\n }\n\n if (nodeTagsCollected < currentNodeBlock.numNodes) {\n lineIndex++;\n continue;\n }\n\n lineIndex++;\n continue;\n }\n\n if (nodeCoordinatesCollected < currentNodeBlock.numNodes) {\n const nodeTag = nodeTags[nodeCoordinatesCollected] - 1;\n const x = parseFloat(parts[0]);\n const y = parseFloat(parts[1]);\n\n result.nodesXCoordinates[nodeTag] = x;\n result.nodesYCoordinates[nodeTag] = y;\n result.totalNodesX++;\n result.totalNodesY++;\n\n nodeCoordinatesCollected++;\n\n if (nodeCoordinatesCollected === currentNodeBlock.numNodes) {\n nodeBlocksProcessed++;\n currentNodeBlock = { numNodes: 0 };\n }\n }\n } else if (section === \"elements\") {\n if (elementEntityBlocks === 0) {\n elementEntityBlocks = parseInt(parts[0], 10);\n totalElements = parseInt(parts[1], 10);\n lineIndex++;\n continue;\n }\n\n if (elementBlocksProcessed < elementEntityBlocks && currentElementBlock.numElements === 0) {\n currentElementBlock = {\n dim: parseInt(parts[0], 10),\n tag: parseInt(parts[1], 10),\n elementType: parseInt(parts[2], 10),\n numElements: parseInt(parts[3], 10),\n };\n\n result.elementTypes[currentElementBlock.elementType] =\n (result.elementTypes[currentElementBlock.elementType] || 0) + currentElementBlock.numElements;\n\n elementsProcessedInBlock = 0;\n lineIndex++;\n continue;\n }\n\n if (elementsProcessedInBlock < currentElementBlock.numElements) {\n const elementTag = parseInt(parts[0], 10);\n const nodeIndices = parts.slice(1).map((idx) => parseInt(idx, 10));\n\n if (currentElementBlock.elementType === 1 || currentElementBlock.elementType === 8) {\n const physicalTag = currentElementBlock.tag;\n\n if (!boundaryElementsByTag[physicalTag]) {\n boundaryElementsByTag[physicalTag] = [];\n }\n\n boundaryElementsByTag[physicalTag].push(nodeIndices);\n\n // Store boundary node pairs for later processing in meshGenerationScript\n if (!result.boundaryNodePairs[physicalTag]) {\n result.boundaryNodePairs[physicalTag] = [];\n }\n result.boundaryNodePairs[physicalTag].push(nodeIndices);\n } else if (currentElementBlock.elementType === 2) {\n // Linear triangle elements (3 nodes)\n result.nodalNumbering.triangleElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 3) {\n // Linear quadrilateral elements (4 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n } else if (currentElementBlock.elementType === 10) {\n // Quadratic quadrilateral elements (9 nodes)\n result.nodalNumbering.quadElements.push(nodeIndices);\n }\n\n elementsProcessedInBlock++;\n\n if (elementsProcessedInBlock === currentElementBlock.numElements) {\n elementBlocksProcessed++;\n currentElementBlock = { numElements: 0 };\n }\n }\n }\n\n lineIndex++;\n }\n\n // Store boundary conditions information\n result.physicalPropMap.forEach((prop) => {\n if (prop.dimension === 1) {\n const boundaryNodes = boundaryElementsByTag[prop.tag] || [];\n\n if (boundaryNodes.length > 0) {\n result.boundaryConditions.push({\n name: prop.name,\n tag: prop.tag,\n nodes: boundaryNodes,\n });\n }\n }\n });\n\n debugLog(\n `Parsed boundary node pairs by physical tag: ${JSON.stringify(\n result.boundaryNodePairs\n )}. These pairs will be used to identify boundary elements in the mesh.`\n );\n\n return result;\n};\n\nexport { importGmshQuadTri };\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\n/**\n * Function to create plots of the solution vector\n * @param {*} solutionVector - The computed solution vector\n * @param {*} nodesCoordinates - Object containing x and y coordinates for the nodes\n * @param {string} solverConfig - Parameter specifying the type of solver\n * @param {string} meshDimension - The dimension of the solution\n * @param {string} plotType - The type of plot\n * @param {string} plotDivId - The id of the div where the plot will be rendered\n */\nexport function plotSolution(\n solutionVector,\n nodesCoordinates,\n solverConfig,\n meshDimension,\n plotType,\n plotDivId\n) {\n const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;\n\n if (meshDimension === \"1D\" && plotType === \"line\") {\n // Check if solutionVector is a nested array\n let yData;\n if (solutionVector.length > 0 && Array.isArray(solutionVector[0])) {\n yData = solutionVector.map((arr) => arr[0]);\n } else {\n yData = solutionVector;\n }\n let xData = Array.from(nodesXCoordinates);\n\n let lineData = {\n x: nodesXCoordinates,\n y: yData,\n mode: \"lines\",\n type: \"scatter\",\n line: { color: \"rgb(219, 64, 82)\", width: 2 },\n name: \"Solution\",\n };\n\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = 350;\n\n let layout = {\n title: `line plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"Solution\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n };\n\n Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });\n } else if (meshDimension === \"2D\" && plotType === \"contour\") {\n // Check if solutionVector is a nested array\n let zData;\n if (Array.isArray(solutionVector[0])) {\n zData = solutionVector.map((val) => val[0]);\n } else {\n zData = solutionVector;\n }\n\n // Sizing parameters\n let maxWindowWidth = Math.min(window.innerWidth, 700);\n let maxX = Math.max(...nodesXCoordinates);\n let maxY = Math.max(...nodesYCoordinates);\n let aspectRatio = maxY / maxX;\n let plotWidth = Math.min(maxWindowWidth, 600);\n let plotHeight = plotWidth * aspectRatio;\n\n // Layout properties\n let layout = {\n title: `${plotType} plot - ${solverConfig}`,\n width: plotWidth,\n height: plotHeight,\n xaxis: { title: \"x\" },\n yaxis: { title: \"y\" },\n margin: { l: 50, r: 50, t: 50, b: 50 },\n hovermode: \"closest\",\n };\n\n // Create the plot\n let contourData = {\n x: nodesXCoordinates,\n y: nodesYCoordinates,\n z: zData,\n type: \"contour\",\n line: {\n smoothing: 0.85,\n },\n contours: {\n coloring: \"heatmap\",\n showlabels: false,\n },\n //colorscale: 'Viridis',\n colorbar: {\n title: \"Solution\",\n },\n name: \"Solution Field\",\n };\n\n Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true });\n }\n}\n","/**\n * ════════════════════════════════════════════════════════════\n * FEAScript Library\n * Lightweight Finite Element Simulation in JavaScript\n * Version: 0.1.4 | https://feascript.com\n * ════════════════════════════════════════════════════════════\n */\n\nexport { FEAScriptModel } from \"./FEAScript.js\";\nexport { importGmshQuadTri } from \"./readers/gmshReaderScript.js\";\nexport { logSystem } from \"./utilities/loggingScript.js\";\nexport { plotSolution } from \"./visualization/plotSolutionScript.js\";\nexport { FEAScriptWorker } from \"./workers/workerScript.js\";\nexport const printVersion = \"0.1.4\";"],"names":["euclideanNorm","vector","norm","i","length","Math","sqrt","currentLogLevel","debugLog","message","console","log","basicLog","errorLog","proxyMarker","Symbol","createEndpoint","releaseProxy","finalizer","throwMarker","isObject","val","transferHandlers","Map","canHandle","serialize","obj","port1","port2","MessageChannel","expose","deserialize","port","start","wrap","value","serialized","Error","isError","name","stack","Object","assign","ep","globalThis","allowedOrigins","addEventListener","callback","ev","data","origin","allowedOrigin","RegExp","test","isAllowedOrigin","warn","id","type","path","argumentList","map","fromWireValue","returnValue","parent","slice","reduce","prop","rawValue","apply","proxy","transfers","transferCache","set","transfer","undefined","Promise","resolve","catch","then","wireValue","transferables","toWireValue","postMessage","removeEventListener","closeEndPoint","error","TypeError","endpoint","constructor","isMessagePort","close","target","pendingListeners","resolver","get","delete","createProxy","throwIfProxyReleased","isReleased","releaseEndpoint","requestResponseMessage","proxyCounter","WeakMap","proxyFinalizers","FinalizationRegistry","newCount","isProxyReleased","Proxy","_target","unregister","unregisterProxy","clear","r","p","toString","bind","_thisArg","rawArgumentList","last","processArguments","construct","register","registerProxy","processed","v","arr","Array","prototype","concat","handler","serializedValue","msg","fill","floor","random","Number","MAX_SAFE_INTEGER","join","solveLinearSystem","solverMethod","jacobianMatrix","residualVector","options","maxIterations","tolerance","solutionVector","converged","iterations","time","jacobianMatrixSparse","math","sparse","luFactorization","slu","solutionMatrix","lusolve","squeeze","valueOf","jacobiSolverResult","A","b","x0","n","x","xNew","iter","sum","j","maxDiff","max","abs","jacobiSolver","timeEnd","async","solveLinearSystemAsync","isArray","toArray","created","computeEngine","worker","Worker","URL","document","location","require","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","Comlink.wrap","initialize","createDefaultComputeEngine","result","webgpuJacobiSolver","destroy","terminate","BasisFunctions","meshDimension","elementOrder","this","getBasisFunctions","ksi","eta","basisFunction","basisFunctionDerivKsi","basisFunctionDerivEta","l1","c","l2","l3","dl1","dl2","dl3","Mesh","numElementsX","maxX","numElementsY","maxY","parsedMesh","boundaryElementsProcessed","parseMeshFromGmsh","nodalNumbering","quadElements","triangleElements","JSON","stringify","elementTypes","mappedNodalNumbering","elemIdx","gmshNodes","feaScriptNodes","push","physicalPropMap","boundaryElements","fixedBoundaryElements","boundaryNodePairs","forEach","dimension","tag","nodesPair","node1","node2","foundElement","elemNodes","includes","side","node1Index","indexOf","node2Index","Mesh1D","super","generateMesh","nodesXCoordinates","totalNodesX","deltaX","nodeIndex","generate1DNodalNumbering","findBoundaryElements","nop","elementIndex","columnCounter","sideIndex","Mesh2D","nodesYCoordinates","totalNodesY","deltaY","nodeIndexY","nodeIndexX","nnode","generate2DNodalNumbering","rowCounter","elementIndexX","elementIndexY","nodeIndex1","nodeIndex2","NumericalIntegration","getGaussPointsAndWeights","gaussPoints","gaussWeights","prepareMesh","meshConfig","mesh","nodesCoordinatesAndNumbering","totalElements","totalNodes","initializeFEA","meshData","colIndex","basisFunctions","gaussPointsAndWeights","localToGlobalMap","numNodes","performIsoparametricMapping1D","params","xCoordinates","ksiDerivX","localNodeIndex","detJacobian","basisFunctionDerivX","performIsoparametricMapping2D","yCoordinates","etaDerivX","ksiDerivY","etaDerivY","basisFunctionDerivY","ThermalBoundaryConditions","boundaryConditions","imposeConstantTempBoundaryConditions","keys","boundaryKey","tempValue","globalNodeIndex","imposeConstantTempBoundaryConditionsFront","nodeConstraintCode","boundaryValues","imposeConvectionBoundaryConditions","convectionHeatTranfCoeff","convectionExtTemp","key","boundaryCondition","convectionCoeff","extTemp","gaussPoint1","gaussPoint2","firstNodeIndex","lastNodeIndex","nodeIncrement","basisFunctionsAndDerivatives","tangentVectorLength","localNodeIndex2","globalNodeIndex2","gaussPointIndex","imposeConvectionBoundaryConditionsFront","localJacobianMatrix","localResidualVector","boundaryElement","find","_","assembleHeatConductionMat","FEAData","gaussPointIndex1","mappingResult","localNodeIndex1","localToGlobalMap1","localToGlobalMap2","gaussPointIndex2","thermalBoundaryConditions","assembleHeatConductionFront","ngl","globalIndex","GenericBoundaryConditions","imposeDirichletBoundaryConditions","imposeConstantValueBoundaryConditionsFront","assembleFrontPropagationMat","eikonalActivationFlag","eikonalViscousTerm","solutionDerivX","solutionDerivY","assembleFrontPropagationFront","frontalData","frontalState","elementData","currentElementIndex","frontStorage","runFrontalSolver","assembleFront","numElements","globalResidualVector","topologyData","lateralData","writeFlag","transformationFlag","nodesPerElement","determinant","systemSize","globalSolutionVector","frontDataIndex","frontSize","frontWidthEstimate","ceil","estimateFrontSize","frontValues","columnHeaders","pivotRow","pivotData","initializeFrontalArrays","dirichletBoundaryConditionsHandler","currentSolutionVector","pivotColumnGlobalIndex","localDestination","rowDestination","rowHeaders","pivotRowIndices","pivotColumnIndices","modifiedRows","pivotColumn","frontMatrix","rowSwapCount","columnSwapCount","lastAppearanceCheck","frontDataCounter","pivotDataIndex","summedRows","reverseElementIndex","columnCount","rowCount","assembled","numElementNodes","numElementColumns","assembleElementContribution","currentElement","columnIndex","rowIndex","localColumnIndex","frontColumnIndex","localRowIndex","availableColumnCount","constrainedRowCount","availableRowCount","absoluteNodeIndex","constrainedIndex","pivotRowIndex","pivotColumnIndex","pivotValue","testColumnIndex","testRowIndex","testValue","pivotGlobalRowIndex","permutationHelper","rightHandSide","globalRowIndex","eliminationFactor","performBackSubstitution","runFrontalAlgorithm","toExponential","finalNodesX","finalNodesY","nodesCoordinates","boundaryLocalJacobianMatrix","boundaryResidualVector","isOnRobinTypeBoundary","some","localNodeI","localNodeJ","iterationIndex","accumulatedValue","newtonRaphson","assembleMat","context","errorNorm","initialSolution","solverConfig","coefficientFunctions","setSolverConfig","setMeshConfig","addBoundaryCondition","condition","setSolverMethod","solve","eikonalExteralIterations","newtonRaphsonResult","B","C","D","xCoord","a","d","globalNodeIndex1","assembleGeneralFormPDEMat","solveAsync","feaWorker","isReady","_initWorker","onerror","event","workerWrapper","_ensureReady","reject","attempts","checkReady","setTimeout","startTime","performance","now","toFixed","getModelInfo","ping","file","gmshV","ascii","fltBytes","lines","text","split","line","trim","filter","section","lineIndex","nodeEntityBlocks","nodeBlocksProcessed","currentNodeBlock","nodeTagsCollected","nodeTags","nodeCoordinatesCollected","elementEntityBlocks","elementBlocksProcessed","currentElementBlock","dim","elementType","elementsProcessedInBlock","boundaryElementsByTag","parts","part","parseFloat","parseInt","replace","parametric","nodeTag","y","nodeIndices","idx","physicalTag","boundaryNodes","nodes","level","plotType","plotDivId","yData","from","lineData","mode","color","width","maxWindowWidth","min","window","innerWidth","layout","title","height","xaxis","yaxis","margin","l","t","Plotly","newPlot","responsive","zData","aspectRatio","plotWidth","hovermode","contourData","z","smoothing","contours","coloring","showlabels","colorbar"],"mappings":"oyBAaO,SAASA,EAAcC,GAC5B,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,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BphB,KAAKqhB,IAAIC,OAAOC,WAAY,KAC7ClU,EAAOrN,KAAKoK,OAAOsF,GAEnB0S,EADOpiB,KAAKoK,OAAOiG,GACEhD,EACrBgV,EAAYriB,KAAKqhB,IAAID,EAAgB,KAIrCI,EAAS,CACXC,MAAO,GAAGb,YAAmB3E,IAC7BkF,MAAOkB,EACPX,OANeW,EAAYD,EAO3BT,MAAO,CAAEF,MAAO,KAChBG,MAAO,CAAEH,MAAO,KAChBI,OAAQ,CAAEC,EAAG,GAAInb,EAAG,GAAIob,EAAG,GAAIpY,EAAG,IAClC2Y,UAAW,WAITC,EAAc,CAChBzY,EAAG4F,EACH2Q,EAAGhQ,EACHmS,EAAGL,EACH/e,KAAM,UACNwb,KAAM,CACJ6D,UAAW,KAEbC,SAAU,CACRC,SAAU,UACVC,YAAY,GAGdC,SAAU,CACRpB,MAAO,YAETvf,KAAM,kBAGR8f,OAAOC,QAAQpB,EAAW,CAAC0B,GAAcf,EAAQ,CAAEU,YAAY,GAChE,CACH,iBCjG4B"} \ No newline at end of file diff --git a/src/visualization/plotSolutionScript.js b/src/visualization/plotSolutionScript.js index 29c9915..c31b8c1 100644 --- a/src/visualization/plotSolutionScript.js +++ b/src/visualization/plotSolutionScript.js @@ -14,7 +14,6 @@ * @param {string} meshDimension - The dimension of the solution * @param {string} plotType - The type of plot * @param {string} plotDivId - The id of the div where the plot will be rendered - * @param {string} [meshType="structured"] - Type of mesh: "structured" or "unstructured" */ export function plotSolution( solutionVector, @@ -22,8 +21,7 @@ export function plotSolution( solverConfig, meshDimension, plotType, - plotDivId, - meshType = "structured" + plotDivId ) { const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates; @@ -38,7 +36,7 @@ export function plotSolution( let xData = Array.from(nodesXCoordinates); let lineData = { - x: xData, + x: nodesXCoordinates, y: yData, mode: "lines", type: "scatter", @@ -47,9 +45,7 @@ export function plotSolution( }; let maxWindowWidth = Math.min(window.innerWidth, 700); - let maxPlotWidth = Math.max(...xData); - let zoomFactor = maxWindowWidth / maxPlotWidth; - let plotWidth = Math.max(zoomFactor * maxPlotWidth, 400); + let plotWidth = Math.min(maxWindowWidth, 600); let plotHeight = 350; let layout = { @@ -58,35 +54,28 @@ export function plotSolution( height: plotHeight, xaxis: { title: "x" }, yaxis: { title: "Solution" }, - margin: { l: 70, r: 40, t: 50, b: 50 }, + margin: { l: 50, r: 50, t: 50, b: 50 }, }; Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true }); } else if (meshDimension === "2D" && plotType === "contour") { - // Use the user-provided mesh type - const isStructured = meshType === "structured"; - - // For auto-detection (if needed) - const uniqueXCoords = new Set(nodesXCoordinates).size; - const uniqueYCoords = new Set(nodesYCoordinates).size; - - // Extract scalar values from solution vector - let zValues; + // Check if solutionVector is a nested array + let zData; if (Array.isArray(solutionVector[0])) { - zValues = solutionVector.map((val) => val[0]); + zData = solutionVector.map((val) => val[0]); } else { - zValues = solutionVector; + zData = solutionVector; } - // Common sizing parameters for both plot types + // Sizing parameters let maxWindowWidth = Math.min(window.innerWidth, 700); let maxX = Math.max(...nodesXCoordinates); let maxY = Math.max(...nodesYCoordinates); let aspectRatio = maxY / maxX; let plotWidth = Math.min(maxWindowWidth, 600); - let plotHeight = plotWidth * aspectRatio * 0.8; // Slightly reduce height for better appearance + let plotHeight = plotWidth * aspectRatio; - // Common layout properties + // Layout properties let layout = { title: `${plotType} plot - ${solverConfig}`, width: plotWidth, @@ -97,67 +86,26 @@ export function plotSolution( hovermode: "closest", }; - if (isStructured) { - // Calculate the number of nodes along the x-axis and y-axis - const numNodesX = uniqueXCoords; - const numNodesY = uniqueYCoords; - - // Reshape the nodesXCoordinates and nodesYCoordinates arrays to match the grid dimensions - let reshapedXCoordinates = math.reshape(Array.from(nodesXCoordinates), [numNodesX, numNodesY]); - let reshapedYCoordinates = math.reshape(Array.from(nodesYCoordinates), [numNodesX, numNodesY]); - - // Reshape the solution array to match the grid dimensions - let reshapedSolution = math.reshape(Array.from(solutionVector), [numNodesX, numNodesY]); - - // Transpose the reshapedSolution array to get column-wise data - let transposedSolution = math.transpose(reshapedSolution); - - // Create an array for x-coordinates used in the contour plot - let reshapedXForPlot = []; - for (let i = 0; i < numNodesX * numNodesY; i += numNodesY) { - let xValue = nodesXCoordinates[i]; - reshapedXForPlot.push(xValue); - } - - // Create the data structure for the contour plot - let contourData = { - z: transposedSolution, - type: "contour", - contours: { - coloring: "heatmap", - showlabels: false, - }, - //colorscale: 'Viridis', - colorbar: { - title: "Solution", - }, - x: reshapedXForPlot, - y: reshapedYCoordinates[0], - name: "Solution Field", - }; - - // Create the plot using Plotly - Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true }); - } else { - // Create an interpolated contour plot for the unstructured mesh - let contourData = { - x: nodesXCoordinates, - y: nodesYCoordinates, - z: zValues, - type: "contour", - contours: { - coloring: "heatmap", - showlabels: false, - }, - //colorscale: 'Viridis', - colorbar: { - title: "Solution", - }, - name: "Solution Field", - }; + // Create the plot + let contourData = { + x: nodesXCoordinates, + y: nodesYCoordinates, + z: zData, + type: "contour", + line: { + smoothing: 0.85, + }, + contours: { + coloring: "heatmap", + showlabels: false, + }, + //colorscale: 'Viridis', + colorbar: { + title: "Solution", + }, + name: "Solution Field", + }; - // Create the plot using only the contour fill - Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true }); - } + Plotly.newPlot(plotDivId, [contourData], layout, { responsive: true }); } }