-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfeascript.esm.js
More file actions
552 lines (552 loc) · 110 KB
/
Copy pathfeascript.esm.js
File metadata and controls
552 lines (552 loc) · 110 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}
/**
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var t,n,o,i,r,s,a,l,c,d,u,m,f,h,p,g,b,y,v,E,C,D,w,M,F,$,A,x,N,k,P,O,V,S,I,X,T,R,B,j,Y,q,W,G,_,L,K,J,H,U,z,Z,Q,ee,te,ne,oe,ie,re,se,ae,le,ce,de;function ue(){if(i)return o;i=1;var e=function(){if(n)return t;n=1;var e="function"==typeof Object.defineProperty?Object.defineProperty:null;return t=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return o=function(){try{return e({},"x",{}),!0}catch(e){return!1}}}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function me(){if(s)return r;s=1;var e=Object.defineProperty;return r=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function fe(){if(l)return a;return l=1,a=function(e){return"number"==typeof e}}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function he(){if(d)return c;function e(e){var t,n="";for(t=0;t<e;t++)n+="0";return n}return d=1,c=function(t,n,o){var i=!1,r=n-t.length;return r<0||(function(e){return"-"===e[0]}(t)&&(i=!0,t=t.substr(1)),t=o?t+e(r):e(r)+t,i&&(t="-"+t)),t}}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function pe(){if(E)return v;E=1;var e=function(){if(m)return u;m=1;var e=fe(),t=he(),n=String.prototype.toLowerCase,o=String.prototype.toUpperCase;return u=function(i){var r,s,a;switch(i.specifier){case"b":r=2;break;case"o":r=8;break;case"x":case"X":r=16;break;default:r=10}if(s=i.arg,a=parseInt(s,10),!isFinite(a)){if(!e(s))throw new Error("invalid integer. Value: "+s);a=0}return a<0&&("u"===i.specifier||10!==r)&&(a=4294967295+a+1),a<0?(s=(-a).toString(r),i.precision&&(s=t(s,i.precision,i.padRight)),s="-"+s):(s=a.toString(r),a||i.precision?i.precision&&(s=t(s,i.precision,i.padRight)):s="",i.sign&&(s=i.sign+s)),16===r&&(i.alternate&&(s="0x"+s),s=i.specifier===o.call(i.specifier)?o.call(s):n.call(s)),8===r&&i.alternate&&"0"!==s.charAt(0)&&(s="0"+s),s}}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/(),t=h?f:(h=1,f=function(e){return"string"==typeof e}),n=fe(),o=function(){if(g)return p;g=1;var e=Math.abs,t=String.prototype.toLowerCase,n=String.prototype.toUpperCase,o=String.prototype.replace,i=/e\+(\d)$/,r=/e-(\d)$/,s=/^(\d+)$/,a=/^(\d+)e/,l=/\.0$/,c=/\.0*e/,d=/(\..*[^0])0*e/;return p=function(u,m){var f,h;switch(m.specifier){case"e":case"E":h=u.toExponential(m.precision);break;case"f":case"F":h=u.toFixed(m.precision);break;case"g":case"G":e(u)<1e-4?((f=m.precision)>0&&(f-=1),h=u.toExponential(f)):h=u.toPrecision(m.precision),m.alternate||(h=o.call(h,d,"$1e"),h=o.call(h,c,"e"),h=o.call(h,l,""));break;default:throw new Error("invalid double notation. Value: "+m.specifier)}return h=o.call(h,i,"e+0$1"),h=o.call(h,r,"e-0$1"),m.alternate&&(h=o.call(h,s,"$1."),h=o.call(h,a,"$1.e")),u>=0&&m.sign&&(h=m.sign+h),m.specifier===n.call(m.specifier)?n.call(h):t.call(h)}}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/(),i=function(){if(y)return b;function e(e){var t,n="";for(t=0;t<e;t++)n+=" ";return n}return y=1,b=function(t,n,o){var i=n-t.length;return i<0?t:t=o?t+e(i):e(i)+t}}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/(),r=he(),s=String.fromCharCode,a=Array.isArray;function l(e){return e!=e}function c(e){var t={};return t.specifier=e.specifier,t.precision=void 0===e.precision?1:e.precision,t.width=e.width,t.flags=e.flags||"",t.mapping=e.mapping,t}return v=function(d){var u,m,f,h,p,g,b,y,v,E;if(!a(d))throw new TypeError("invalid argument. First argument must be an array. Value: `"+d+"`.");for(g="",b=1,v=0;v<d.length;v++)if(f=d[v],t(f))g+=f;else{if(u=void 0!==f.precision,!(f=c(f)).specifier)throw new TypeError("invalid argument. Token is missing `specifier` property. Index: `"+v+"`. Value: `"+f+"`.");for(f.mapping&&(b=f.mapping),m=f.flags,E=0;E<m.length;E++)switch(h=m.charAt(E)){case" ":f.sign=" ";break;case"+":f.sign="+";break;case"-":f.padRight=!0,f.padZeros=!1;break;case"0":f.padZeros=m.indexOf("-")<0;break;case"#":f.alternate=!0;break;default:throw new Error("invalid flag: "+h)}if("*"===f.width){if(f.width=parseInt(arguments[b],10),b+=1,l(f.width))throw new TypeError("the argument for * width at position "+b+" is not a number. Value: `"+f.width+"`.");f.width<0&&(f.padRight=!0,f.width=-f.width)}if(u&&"*"===f.precision){if(f.precision=parseInt(arguments[b],10),b+=1,l(f.precision))throw new TypeError("the argument for * precision at position "+b+" is not a number. Value: `"+f.precision+"`.");f.precision<0&&(f.precision=1,u=!1)}switch(f.arg=arguments[b],f.specifier){case"b":case"o":case"x":case"X":case"d":case"i":case"u":u&&(f.padZeros=!1),f.arg=e(f);break;case"s":f.maxWidth=u?f.precision:-1,f.arg=String(f.arg);break;case"c":if(!l(f.arg)){if((p=parseInt(f.arg,10))<0||p>127)throw new Error("invalid character code. Value: "+f.arg);f.arg=l(p)?String(f.arg):s(p)}break;case"e":case"E":case"f":case"F":case"g":case"G":if(u||(f.precision=6),y=parseFloat(f.arg),!isFinite(y)){if(!n(f.arg))throw new Error("invalid floating-point number. Value: "+g);y=f.arg,f.padZeros=!1}f.arg=o(y,f);break;default:throw new Error("invalid specifier: "+f.specifier)}f.maxWidth>=0&&f.arg.length>f.maxWidth&&(f.arg=f.arg.substring(0,f.maxWidth)),f.padZeros?f.arg=r(f.arg,f.width||f.precision,f.padRight):f.width&&(f.arg=i(f.arg,f.width,f.padRight)),g+=f.arg||"",b+=1}return g},v}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function ge(){if($)return F;$=1;var e=function(){if(M)return w;M=1;var e=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function t(e){var t={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(t.precision="1"),t}return w=function(n){var o,i,r,s;for(i=[],s=0,r=e.exec(n);r;)(o=n.slice(s,e.lastIndex-r[0].length)).length&&i.push(o),"%"===r[6]?i.push("%"):i.push(t(r)),s=e.lastIndex,r=e.exec(n);return(o=n.slice(s)).length&&i.push(o),i}}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return F=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function be(){if(k)return N;k=1;var e=function(){if(D)return C;D=1;var e=pe();return C=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/(),t=ge(),n=x?A:(x=1,A=function(e){return"string"==typeof e});return N=function o(i){var r,s;if(!n(i))throw new TypeError(o("invalid argument. First argument must be a string. Value: `%s`.",i));for(r=[t(i)],s=1;s<arguments.length;s++)r.push(arguments[s]);return e.apply(null,r)},N}
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function ye(){if(S)return V;S=1;var e=function(){if(O)return P;O=1;var e=be();return P=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/(),t=Object.prototype,n=t.toString,o=t.__defineGetter__,i=t.__defineSetter__,r=t.__lookupGetter__,s=t.__lookupSetter__;return V=function(a,l,c){var d,u,m,f;if("object"!=typeof a||null===a||"[object Array]"===n.call(a))throw new TypeError(e("invalid argument. First argument must be an object. Value: `%s`.",a));if("object"!=typeof c||null===c||"[object Array]"===n.call(c))throw new TypeError(e("invalid argument. Property descriptor must be an object. Value: `%s`.",c));if((u="value"in c)&&(r.call(a,l)||s.call(a,l)?(d=a.__proto__,a.__proto__=t,delete a[l],a[l]=c.value,a.__proto__=d):a[l]=c.value),m="get"in c,f="set"in c,u&&(m||f))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return m&&o&&o.call(a,l,c.get),f&&i&&i.call(a,l,c.set),a}}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function ve(){if(R)return T;R=1;var e=function(){if(X)return I;X=1;var e,t=ue(),n=me(),o=ye();return e=t()?n:o,I=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return T=function(t,n,o){e(t,n,{configurable:!1,enumerable:!1,writable:!1,value:o})}}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function Ee(){if(j)return B;j=1;var e=ve();return B=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function Ce(){if(G)return W;G=1;var e=q?Y:(q=1,Y=function(e,t){return t>0?0:(1-e)*t});return W=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function De(){if(U)return H;U=1;var e=J?K:(J=1,K=function(e){return Math.abs(e)});return H=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function we(){if(ee)return Q;ee=1;var e=Z?z:(Z=1,z=function(e){return e*e});return Q=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function Me(){if(ie)return oe;ie=1;var e=function(){if(ne)return te;ne=1;var e=Math.sqrt;return te=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return oe=e}
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function Fe(){if(se)return re;se=1;var e=L?_:(L=1,_=17976931348623157e292),t=De(),n=we(),o=Me(),i=44989137945431964e145,r=11113793747425387e-178;return re=function(s,a,l,c){var d,u,m,f,h,p,g,b,y,v,E;if(s<=0)return 0;for(v=c,d=!0,u=0,m=0,f=0,h=0,b=1,E=0;E<s;E++)(y=t(a[v]))>1997919072202235e131?(m+=n(y*r),d=!1):y<14916681462400413e-170?d&&(h+=n(y*i)):f+=y*y,v+=l;return m>0?((f>0||f>e||f!=f)&&(m+=f*r*r),b=1/r,u=m):h>0?f>0||f>e||f!=f?(f=o(f),(h=o(h)/i)>f?(g=f,p=h):(g=h,p=f),b=1,u=p*p*(1+n(g/p))):(b=1/i,u=h):(b=1,u=f),o(u)*b}}
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var $e,Ae,xe,Ne,ke,Pe,Oe=function(){if(de)return ce;de=1;var e=Ee(),t=function(){if(le)return ae;le=1;var e=Ce(),t=Fe();return ae=function(n,o,i){var r=e(n,i);return t(n,o,i,r)}}
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return e(t,"ndarray",Fe()),ce=t}(),Ve=e(Oe);function Se(){if(Ae)return $e;Ae=1;return $e=function(e,t,n,o,i,r,s){var a,l,c,d,u;if(a=0,e<=0)return a;if(l=o,c=s,1===n&&1===r){if((d=e%5)>0)for(u=0;u<d;u++)a+=t[l]*i[c],l+=1,c+=1;if(e<5)return a;for(u=d;u<e;u+=5)a+=t[l]*i[c]+t[l+1]*i[c+1]+t[l+2]*i[c+2]+t[l+3]*i[c+3]+t[l+4]*i[c+4],l+=5,c+=5;return a}for(u=0;u<e;u++)a+=t[l]*i[c],l+=n,c+=r;return a}}
/**
* @license Apache-2.0
*
* Copyright (c) 2019 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Ie,Xe,Te,Re,Be,je,Ye=function(){if(Pe)return ke;Pe=1;var e=Ee(),t=function(){if(Ne)return xe;Ne=1;var e=Ce(),t=Se();return xe=function(n,o,i,r,s){var a,l;return n<=0?0:(a=e(n,i),l=e(n,s),t(n,o,i,a,r,s,l))}}
/**
* @license Apache-2.0
*
* Copyright (c) 2019 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return e(t,"ndarray",Se()),ke=t}(),qe=e(Ye);function We(){if(Xe)return Ie;Xe=1;return Ie=function(e,t,n,o,i,r,s){var a,l,c,d;if(e<=0)return i;if(a=o,l=s,1===n&&1===r){if((c=e%8)>0)for(d=0;d<c;d++)i[l]=t[a],a+=n,l+=r;if(e<8)return i;for(d=c;d<e;d+=8)i[l]=t[a],i[l+1]=t[a+1],i[l+2]=t[a+2],i[l+3]=t[a+3],i[l+4]=t[a+4],i[l+5]=t[a+5],i[l+6]=t[a+6],i[l+7]=t[a+7],a+=8,l+=8;return i}for(d=0;d<e;d++)i[l]=t[a],a+=n,l+=r;return i}}
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Ge,_e,Le,Ke,Je,He,Ue=function(){if(je)return Be;je=1;var e=Ee(),t=function(){if(Re)return Te;Re=1;var e=Ce(),t=We();return Te=function(n,o,i,r,s){var a,l;return n<=0?r:(a=e(n,i),l=e(n,s),t(n,o,i,a,r,s,l))}}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return e(t,"ndarray",We()),Be=t}(),ze=e(Ue);function Ze(){if(_e)return Ge;_e=1;return Ge=function(e,t,n,o,i,r,s,a){var l,c,d,u;if(e<=0||0===t)return r;if(l=i,c=a,1===o&&1===s){if((d=e%4)>0)for(u=0;u<d;u++)r[c]+=t*n[l],l+=o,c+=s;if(e<4)return r;for(u=d;u<e;u+=4)r[c]+=t*n[l],r[c+1]+=t*n[l+1],r[c+2]+=t*n[l+2],r[c+3]+=t*n[l+3],l+=4,c+=4;return r}for(u=0;u<e;u++)r[c]+=t*n[l],l+=o,c+=s;return r}}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Qe=function(){if(He)return Je;He=1;var e=Ee(),t=function(){if(Ke)return Le;Ke=1;var e=Ce(),t=Ze();return Le=function(n,o,i,r,s,a){var l,c;return n<=0||0===o?s:(l=e(n,r),c=e(n,a),t(n,o,i,r,l,s,a,c))}}
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/();return e(t,"ndarray",Ze()),Je=t}(),et=e(Qe);function tt(e){const t=e instanceof Float64Array?e:new Float64Array(e);return Ve(t.length,t,1)}function nt(e,t){const n=e instanceof Float64Array?e:new Float64Array(e),o=t instanceof Float64Array?t:new Float64Array(t);return qe(n.length,n,1,o,1)}function ot(e,t,n){const o=t instanceof Float64Array?t:new Float64Array(t);et(o.length,e,o,1,n,1)}let it="basic";function rt(e){"none"!==e&&"basic"!==e&&"debug"!==e?(console.log("%c[WARN] Invalid log level: "+e+". Using basic instead. Allowed levels: none, basic, debug.","color: #FFC107; font-weight: bold;"),it="basic"):(it=e,at(`Log level set to: ${e}`))}function st(e){"debug"===it&&console.log("%c[DEBUG] "+e,"color: #2196F3; font-weight: bold;")}function at(e){"basic"!==it&&"debug"!==it||console.log("%c[INFO] "+e,"color: #4CAF50; font-weight: bold;")}function lt(e){console.log("%c[ERROR] "+e,"color: #F44336; font-weight: bold;")}
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const ct=Symbol("Comlink.proxy"),dt=Symbol("Comlink.endpoint"),ut=Symbol("Comlink.releaseProxy"),mt=Symbol("Comlink.finalizer"),ft=Symbol("Comlink.thrown"),ht=e=>"object"==typeof e&&null!==e||"function"==typeof e,pt=new Map([["proxy",{canHandle:e=>ht(e)&&e[ct],serialize(e){const{port1:t,port2:n}=new MessageChannel;return gt(e,t),[n,[n]]},deserialize:e=>(e.start(),yt(e))}],["throw",{canHandle:e=>ht(e)&&ft 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 gt(e,t=globalThis,n=["*"]){t.addEventListener("message",(function o(i){if(!i||!i.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,i.origin))return void console.warn(`Invalid origin '${i.origin}' for comlink proxy`);const{id:r,type:s,path:a}=Object.assign({path:[]},i.data),l=(i.data.argumentList||[]).map(At);let c;try{const t=a.slice(0,-1).reduce(((e,t)=>e[t]),e),n=a.reduce(((e,t)=>e[t]),e);switch(s){case"GET":c=n;break;case"SET":t[a.slice(-1)[0]]=At(i.data.value),c=!0;break;case"APPLY":c=n.apply(t,l);break;case"CONSTRUCT":c=function(e){return Object.assign(e,{[ct]:!0})}(new n(...l));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;gt(e,n),c=function(e,t){return Ft.set(e,t),e}(t,[t])}break;case"RELEASE":c=void 0;break;default:return}}catch(e){c={value:e,[ft]:0}}Promise.resolve(c).catch((e=>({value:e,[ft]:0}))).then((n=>{const[i,a]=$t(n);t.postMessage(Object.assign(Object.assign({},i),{id:r}),a),"RELEASE"===s&&(t.removeEventListener("message",o),bt(t),mt in e&&"function"==typeof e[mt]&&e[mt]())})).catch((e=>{const[n,o]=$t({value:new TypeError("Unserializable return value"),[ft]:0});t.postMessage(Object.assign(Object.assign({},n),{id:r}),o)}))})),t.start&&t.start()}function bt(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function yt(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)}})),wt(e,n,[],t)}function vt(e){if(e)throw new Error("Proxy has been released and is not useable")}function Et(e){return xt(e,new Map,{type:"RELEASE"}).then((()=>{bt(e)}))}const Ct=new WeakMap,Dt="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(Ct.get(e)||0)-1;Ct.set(e,t),0===t&&Et(e)}));function wt(e,t,n=[],o=function(){}){let i=!1;const r=new Proxy(o,{get(o,s){if(vt(i),s===ut)return()=>{!function(e){Dt&&Dt.unregister(e)}(r),Et(e),t.clear(),i=!0};if("then"===s){if(0===n.length)return{then:()=>r};const o=xt(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then(At);return o.then.bind(o)}return wt(e,t,[...n,s])},set(o,r,s){vt(i);const[a,l]=$t(s);return xt(e,t,{type:"SET",path:[...n,r].map((e=>e.toString())),value:a},l).then(At)},apply(o,r,s){vt(i);const a=n[n.length-1];if(a===dt)return xt(e,t,{type:"ENDPOINT"}).then(At);if("bind"===a)return wt(e,t,n.slice(0,-1));const[l,c]=Mt(s);return xt(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:l},c).then(At)},construct(o,r){vt(i);const[s,a]=Mt(r);return xt(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:s},a).then(At)}});return function(e,t){const n=(Ct.get(t)||0)+1;Ct.set(t,n),Dt&&Dt.register(e,t,e)}(r,e),r}function Mt(e){const t=e.map($t);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const Ft=new WeakMap;function $t(e){for(const[t,n]of pt)if(n.canHandle(e)){const[o,i]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},i]}return[{type:"RAW",value:e},Ft.get(e)||[]]}function At(e){switch(e.type){case"HANDLER":return pt.get(e.name).deserialize(e.value);case"RAW":return e.value}}function xt(e,t,n,o){return new Promise((i=>{const r=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(r,i),e.start&&e.start(),e.postMessage(Object.assign({id:r},n),o)}))}function Nt(e,t,n,o={}){const{maxIterations:i=1e4,tolerance:r=1e-4}=o;let s=[],a=!0,l=0;if(at(`Solving system using ${e}...`),console.time("systemSolving"),"lusolve"===e){const e=math.sparse(t),o=math.slu(e,1,1);let i=math.lusolve(o,n);s=math.squeeze(i).valueOf()}else if("jacobi"===e){const e=function(e,t,n,o={}){const{maxIterations:i,tolerance:r}=o,s=e.length,a=e.map((e=>new Float64Array(e))),l=new Float64Array(t);let c=new Float64Array(n),d=new Float64Array(s);const u=new Float64Array(s);for(let e=0;e<i;e++){for(let e=0;e<s;e++){const t=nt(a[e],c);d[e]=(l[e]-t+a[e][e]*c[e])/a[e][e]}for(let e=0;e<s;e++)u[e]=d[e]-c[e];const t=tt(u);if(f=c,ze((m=d).length,m,1,f,1),t<r)return{solutionVector:c,iterations:e+1,converged:!0}}var m,f;return{solutionVector:c,iterations:i,converged:!1}}(t,n,new Array(n.length).fill(0),{maxIterations:i,tolerance:r});e.converged?st(`Jacobi method converged in ${e.iterations} iterations`):lt(`Jacobi method did not converge after ${e.iterations} iterations`),s=e.solutionVector,a=e.converged,l=e.iterations}else lt(`Unknown solver method: ${e}`);return console.timeEnd("systemSolving"),at("System solved successfully"),{solutionVector:s,converged:a,iterations:l}}async function kt(e,t,n,o={}){const{maxIterations:i=1e4,tolerance:r=1e-4}=o;at(`Solving system using ${e}...`),console.time("systemSolving");const s=Array.isArray(t)?t:t?.toArray?.()??t,a=Array.isArray(n)?n:n?.toArray?.()??n;let l,c=null,d=null,u=[],m=!0;if("jacobi-gpu"===e){c=await async function(){const e=new URL("../workers/webgpuWorker.js",import.meta.url).href,t=new Blob([`import "${e}";`],{type:"application/javascript"}),n=new Worker(URL.createObjectURL(t),{type:"module"}),o=yt(n);return await o.initialize(),{computeEngine:o,worker:n}}(),d=c.computeEngine;const e=new Array(a.length).fill(0);let t;t=await d.webgpuJacobiSolver(s,a,e,{maxIterations:i,tolerance:r}),u=t.solutionVector,m=t.converged,l=t.iterations,m?st(`Jacobi method converged in ${l} iterations`):lt(`Jacobi method did not converge after ${l} iterations`)}else lt(`Unknown solver method: ${e}`);return console.timeEnd("systemSolving"),at(`System solved successfully (${e})`),c&&(await(d?.destroy?.().catch((()=>{}))),c.worker.terminate()),{solutionVector:u,converged:m,iterations:l}}class Pt{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getBasisFunctions(e,t=null,n=null){let o=[],i=[],r=[],s=[];if("1D"===this.meshDimension){if("linear"===this.elementOrder)o[0]=1-e,o[1]=e,i[0]=-1,i[1]=1;else if("quadratic"===this.elementOrder)o[0]=1-3*e+2*e**2,o[1]=4*e-4*e**2,o[2]=2*e**2-e,i[0]=4*e-3,i[1]=4-8*e,i[2]=4*e-1;else if("hermiteCubic"===this.elementOrder){if(null===n)return void lt("elementLength is required to evaluate 'hermiteCubic' basis functions");const a=n;o[0]=2*e**3-3*e**2+1,o[1]=a*(e**3-2*e**2+e),o[2]=-2*e**3+3*e**2,o[3]=a*(e**3-e**2),i[0]=6*e**2-6*e,i[1]=a*(3*e**2-4*e+1),i[2]=-6*e**2+6*e,i[3]=a*(3*e**2-2*e),s[0]=12*e-6,s[1]=a*(6*e-4),s[2]=-12*e+6,s[3]=a*(6*e-2)}}else if("2D"===this.meshDimension){if(null===t)return void lt("Eta coordinate is required for 2D elements");if("linear"===this.elementOrder){function l(e){return 1-e}o[0]=l(e)*l(t),o[1]=l(e)*t,o[2]=e*l(t),o[3]=e*t,i[0]=-1*l(t),i[1]=-1*t,i[2]=1*l(t),i[3]=1*t,r[0]=-1*l(e),r[1]=1*l(e),r[2]=-1*e,r[3]=1*e}else if("quadratic"===this.elementOrder){function c(e){return 2*e**2-3*e+1}function d(e){return-4*e**2+4*e}function u(e){return 2*e**2-e}function m(e){return 4*e-3}function f(e){return-8*e+4}function h(e){return 4*e-1}o[0]=c(e)*c(t),o[1]=c(e)*d(t),o[2]=c(e)*u(t),o[3]=d(e)*c(t),o[4]=d(e)*d(t),o[5]=d(e)*u(t),o[6]=u(e)*c(t),o[7]=u(e)*d(t),o[8]=u(e)*u(t),i[0]=m(e)*c(t),i[1]=m(e)*d(t),i[2]=m(e)*u(t),i[3]=f(e)*c(t),i[4]=f(e)*d(t),i[5]=f(e)*u(t),i[6]=h(e)*c(t),i[7]=h(e)*d(t),i[8]=h(e)*u(t),r[0]=c(e)*m(t),r[1]=c(e)*f(t),r[2]=c(e)*h(t),r[3]=d(e)*m(t),r[4]=d(e)*f(t),r[5]=d(e)*h(t),r[6]=u(e)*m(t),r[7]=u(e)*f(t),r[8]=u(e)*h(t)}}return{basisFunction:o,basisFunctionDerivKsi:i,basisFunctionDerivEta:r,basisFunctionDerivKsi2:s}}}class Ot{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:o=null,meshDimension:i=null,elementOrder:r="linear",parsedMesh:s=null}){this.numElementsX=e,this.numElementsY=n,this.maxX=t,this.maxY=o,this.meshDimension=i,this.elementOrder=r,this.parsedMesh=s,this.boundaryElementsProcessed=!1,this.parsedMesh&&(at("Using pre-parsed mesh from gmshReader data for mesh generation."),this.parseMeshFromGmsh())}parseMeshFromGmsh(){if(this.parsedMesh.nodalNumbering||lt("No valid nodal numbering found in the parsed mesh."),Array.isArray(this.parsedMesh.nodalNumbering))return this.boundaryElementsProcessed=!0,this.parsedMesh.boundaryElementsProcessed=!0,this.parsedMesh;if("object"==typeof this.parsedMesh.nodalNumbering&&!Array.isArray(this.parsedMesh.nodalNumbering)){const e=this.parsedMesh.nodalNumbering.quadElements||[];if(this.parsedMesh.nodalNumbering.triangleElements,st("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;n<e.length;n++){const o=e[n],i=new Array(o.length);4===o.length?(i[0]=o[0],i[1]=o[3],i[2]=o[1],i[3]=o[2]):9===o.length&&(i[0]=o[0],i[1]=o[7],i[2]=o[3],i[3]=o[4],i[4]=o[8],i[5]=o[6],i[6]=o[1],i[7]=o[5],i[8]=o[2]),t.push(i)}this.parsedMesh.nodalNumbering=t}else this.parsedMesh.elementTypes[2]&<("Element type is neither triangle nor quad; mapping for this type is not implemented yet.");if(st("Nodal numbering after mapping from Gmsh to FEAScript format: "+JSON.stringify(this.parsedMesh.nodalNumbering)),this.parsedMesh.physicalPropMap&&this.parsedMesh.boundaryElements){if(Array.isArray(this.parsedMesh.boundaryElements)&&this.parsedMesh.boundaryElements.length>0&&void 0===this.parsedMesh.boundaryElements[0]){const e=[];for(let t=1;t<this.parsedMesh.boundaryElements.length;t++)this.parsedMesh.boundaryElements[t]&&e.push(this.parsedMesh.boundaryElements[t]);this.parsedMesh.boundaryElements=e}if(this.parsedMesh.boundaryNodePairs&&!this.parsedMesh.boundaryElementsProcessed&&(this.parsedMesh.boundaryElements=[],this.parsedMesh.physicalPropMap.forEach((e=>{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],o=t[1];st(`Processing boundary node pair: [${n}, ${o}] for boundary ${e.tag} (${e.name||"unnamed"})`);let i=!1;for(let t=0;t<this.parsedMesh.nodalNumbering.length;t++){const r=this.parsedMesh.nodalNumbering[t];if(4===r.length){if(r.includes(n)&&r.includes(o)){let s;const a=r.indexOf(n),l=r.indexOf(o);st(` Found element ${t} containing boundary nodes. Element nodes: [${r.join(", ")}]`),st(` Node ${n} is at index ${a}, Node ${o} is at index ${l} in the element`),0===a&&2===l||2===a&&0===l?(s=0,st(` These nodes form the BOTTOM side (${s}) of element ${t}`)):0===a&&1===l||1===a&&0===l?(s=1,st(` These nodes form the LEFT side (${s}) of element ${t}`)):1===a&&3===l||3===a&&1===l?(s=2,st(` These nodes form the TOP side (${s}) of element ${t}`)):(2===a&&3===l||3===a&&2===l)&&(s=3,st(` These nodes form the RIGHT side (${s}) of element ${t}`)),this.parsedMesh.boundaryElements[e.tag].push([t,s]),st(` Added element-side pair [${t}, ${s}] to boundary tag ${e.tag}`),i=!0;break}}else if(9===r.length&&r.includes(n)&&r.includes(o)){let s;const a=r.indexOf(n),l=r.indexOf(o);st(` Found element ${t} containing boundary nodes. Element nodes: [${r.join(", ")}]`),st(` Node ${n} is at index ${a}, Node ${o} is at index ${l} in the element`),0===a&&6===l||6===a&&0===l||0===a&&3===l||3===a&&0===l||3===a&&6===l||6===a&&3===l?(s=0,st(` These nodes form the BOTTOM side (${s}) of element ${t}`)):0===a&&2===l||2===a&&0===l||0===a&&1===l||1===a&&0===l||1===a&&2===l||2===a&&1===l?(s=1,st(` These nodes form the LEFT side (${s}) of element ${t}`)):2===a&&8===l||8===a&&2===l||2===a&&5===l||5===a&&2===l||5===a&&8===l||8===a&&5===l?(s=2,st(` These nodes form the TOP side (${s}) of element ${t}`)):(6===a&&8===l||8===a&&6===l||6===a&&7===l||7===a&&6===l||7===a&&8===l||8===a&&7===l)&&(s=3,st(` These nodes form the RIGHT side (${s}) of element ${t}`)),this.parsedMesh.boundaryElements[e.tag].push([t,s]),st(` Added element-side pair [${t}, ${s}] to boundary tag ${e.tag}`),i=!0;break}}i||lt(`Could not find element containing boundary nodes ${n} and ${o}. Boundary may be incomplete.`)})))}})),this.boundaryElementsProcessed=!0,this.parsedMesh.boundaryElements.length>0&&void 0===this.parsedMesh.boundaryElements[0])){const e=[];for(let t=1;t<this.parsedMesh.boundaryElements.length;t++)this.parsedMesh.boundaryElements[t]&&e.push(this.parsedMesh.boundaryElements[t]);this.parsedMesh.boundaryElements=e}}}return this.parsedMesh}}class Vt extends Ot{constructor({numElementsX:e=null,maxX:t=null,elementOrder:n="linear",parsedMesh:o=null}){super({numElementsX:e,maxX:t,numElementsY:1,maxY:0,meshDimension:"1D",elementOrder:n,parsedMesh:o}),null!==this.numElementsX&&null!==this.maxX||lt("numElementsX and maxX are required parameters when generating a 1D mesh from geometry")}generateMesh(){let e=[];let t,n;if("linear"===this.elementOrder){t=this.numElementsX+1,n=(this.maxX-0)/this.numElementsX,e[0]=0;for(let o=1;o<t;o++)e[o]=e[o-1]+n}else if("quadratic"===this.elementOrder){t=2*this.numElementsX+1,n=(this.maxX-0)/this.numElementsX,e[0]=0;for(let o=1;o<t;o++)e[o]=e[o-1]+n/2}const o=this.generateNodalNumbering1D(this.numElementsX,t,this.elementOrder),i=this.findBoundaryElements();return st("Generated node X coordinates: "+JSON.stringify(e)),{nodesXCoordinates:e,totalNodesX:t,nodalNumbering:o,boundaryElements:i}}generateNodalNumbering1D(e,t,n){let o=[];if("linear"===n)for(let t=0;t<e;t++){o[t]=[];for(let e=1;e<=2;e++)o[t][e-1]=t+e}else if("quadratic"===n){let t=0;for(let n=0;n<e;n++){o[n]=[];for(let e=1;e<=3;e++)o[n][e-1]=n+e+t;t+=1}}return o}findBoundaryElements(){const e=[];for(let t=0;t<2;t++)e.push([]);return e[0].push([0,0]),e[1].push([this.numElementsX-1,1]),st("Identified boundary elements by side: "+JSON.stringify(e)),this.boundaryElementsProcessed=!0,e}}class St extends Ot{constructor({numElementsX:e=null,maxX:t=null,numElementsY:n=null,maxY:o=null,elementOrder:i="linear",parsedMesh:r=null,angleLeft:s=90,angleRight:a=90}){super({numElementsX:e,maxX:t,numElementsY:n,maxY:o,meshDimension:"2D",elementOrder:i,parsedMesh:r}),this.angleLeft=s,this.angleRight=a,r||null!==this.numElementsX&&null!==this.maxX&&null!==this.numElementsY&&null!==this.maxY||lt("numElementsX, maxX, numElementsY, and maxY are required parameters when generating a 2D mesh from geometry")}generateMesh(){let e=[],t=[];let n,o,i,r;if("linear"===this.elementOrder){n=this.numElementsX+1,o=this.numElementsY+1,i=(this.maxX-0)/this.numElementsX,r=(this.maxY-0)/this.numElementsY,e[0]=0,t[0]=0;for(let n=1;n<o;n++)e[n]=e[0],t[n]=t[0]+n*r;for(let s=1;s<n;s++){const n=s*o;e[n]=e[0]+s*i,t[n]=t[0];for(let i=1;i<o;i++)e[n+i]=e[n],t[n+i]=t[n]+i*r}}else if("quadratic"===this.elementOrder){n=2*this.numElementsX+1,o=2*this.numElementsY+1,i=(this.maxX-0)/this.numElementsX,r=(this.maxY-0)/this.numElementsY,e[0]=0,t[0]=0;for(let n=1;n<o;n++)e[n]=e[0],t[n]=t[0]+n*r/2;for(let s=1;s<n;s++){const n=s*o;e[n]=e[0]+s*i/2,t[n]=t[0];for(let i=1;i<o;i++)e[n+i]=e[n],t[n+i]=t[n]+i*r/2}}if(90!==this.angleLeft||90!==this.angleRight){const i=Math.PI/180,r=Math.tan(this.angleLeft*i),s=Math.tan(this.angleRight*i),a=1e-12;for(let i=0;i<o;i++){const l=t[i],c=Math.abs(r)<a?0:l/r,d=Math.abs(s)<a?this.maxX:this.maxX-l/s;for(let t=0;t<n;t++){const r=1===n?0:t/(n-1);e[t*o+i]=c+(d-c)*r}}}const s=this.generateNodalNumbering2D(this.numElementsX,this.numElementsY,o,this.elementOrder),a=this.findBoundaryElements();return st("Generated node X coordinates: "+JSON.stringify(e)),st("Generated node Y coordinates: "+JSON.stringify(t)),{nodesXCoordinates:e,nodesYCoordinates:t,totalNodesX:n,totalNodesY:o,nodalNumbering:s,boundaryElements:a}}generateNodalNumbering2D(e,t,n,o){let i=0,r=[];if("linear"===o){let n=0,o=2;for(let i=0;i<e*t;i++)n+=1,r[i]=[],r[i][0]=i+o-1,r[i][1]=i+o,r[i][2]=i+o+t,r[i][3]=i+o+t+1,n===t&&(o+=1,n=0)}else if("quadratic"===o)for(let o=1;o<=e;o++)for(let e=1;e<=t;e++){r[i]=[];for(let t=1;t<=3;t++){let s=3*t-2;r[i][s-1]=n*(2*o+t-3)+2*e-1,r[i][s]=r[i][s-1]+1,r[i][s+1]=r[i][s-1]+2}i+=1}return r}findBoundaryElements(){const e=[];for(let t=0;t<4;t++)e.push([]);for(let t=0;t<this.numElementsX;t++)for(let n=0;n<this.numElementsY;n++){const o=t*this.numElementsY+n;0===n&&e[0].push([o,0]),0===t&&e[1].push([o,1]),n===this.numElementsY-1&&e[2].push([o,2]),t===this.numElementsX-1&&e[3].push([o,3])}return st("Identified boundary elements by side: "+JSON.stringify(e)),this.boundaryElementsProcessed=!0,e}}class It{constructor({meshDimension:e,elementOrder:t}){this.meshDimension=e,this.elementOrder=t}getGaussPointsAndWeights(){let e=[],t=[];return"linear"===this.elementOrder?(e[0]=.5,t[0]=1):"quadratic"===this.elementOrder?(e[0]=(1-Math.sqrt(.6))/2,e[1]=.5,e[2]=(1+Math.sqrt(.6))/2,t[0]=5/18,t[1]=8/18,t[2]=5/18):"hermiteCubic"===this.elementOrder&&(e[0]=.03376524289842399,e[1]=.16939530676686776,e[2]=.38069040695840156,e[3]=.6193095930415985,e[4]=.8306046932331322,e[5]=.966234757101576,t[0]=.08566224618958516,t[1]=.1803807865240693,t[2]=.23395696728634552,t[3]=.23395696728634552,t[4]=.1803807865240693,t[5]=.08566224618958516),{gaussPoints:e,gaussWeights:t}}}function Xt(e){const{meshDimension:t,numElementsX:n,numElementsY:o,maxX:i,maxY:r,elementOrder:s,parsedMesh:a,angleLeft:l,angleRight:c}=e;let d;"1D"===t?d=new Vt({numElementsX:n,maxX:i,elementOrder:s,parsedMesh:a}):"2D"===t?d=new St({numElementsX:n,maxX:i,numElementsY:o,maxY:r,elementOrder:s,parsedMesh:a,angleLeft:l,angleRight:c}):lt("Mesh dimension must be either '1D' or '2D'");const u=d.boundaryElementsProcessed?d.parsedMesh:d.generateMesh();let m=u.nodesXCoordinates,f=u.nodesYCoordinates,h=u.totalNodesX,p=u.totalNodesY,g=u.nodalNumbering,b=u.boundaryElements;let y,v;return null!=a?(y=g.length,v=m.length,st(`Using parsed mesh with ${y} elements and ${v} nodes`)):(y=n*("2D"===t?o:1),v=h*("2D"===t?p:1),st(`Using mesh generated from geometry with ${y} elements and ${v} nodes`)),{nodesXCoordinates:m,nodesYCoordinates:f,totalNodesX:h,totalNodesY:p,nop:g,boundaryElements:b,totalElements:y,totalNodes:v,meshDimension:t,elementOrder:s}}function Tt(e){const{totalNodes:t,nop:n,meshDimension:o,elementOrder:i}=e;let r=[],s=[];for(let e=0;e<t;e++){r[e]=0,s.push([]);for(let n=0;n<t;n++)s[e][n]=0}const a=new Pt({meshDimension:o,elementOrder:i});let l=new It({meshDimension:o,elementOrder:i}).getGaussPointsAndWeights();return{residualVector:r,jacobianMatrix:s,localToGlobalMap:[],basisFunctions:a,gaussPoints:l.gaussPoints,gaussWeights:l.gaussWeights,nodesPerElement:n[0].length}}function Rt(e){const{basisFunction:t,basisFunctionDerivKsi:n,nodesXCoordinates:o,localToGlobalMap:i,nodesPerElement:r}=e;let s=0,a=0;for(let e=0;e<r;e++)s+=o[i[e]]*t[e],a+=o[i[e]]*n[e];let l=a,c=[];for(let e=0;e<r;e++)c[e]=n[e]/l;return{xCoordinates:s,detJacobian:l,basisFunctionDerivX:c}}function Bt(e){const{basisFunction:t,basisFunctionDerivKsi:n,basisFunctionDerivEta:o,nodesXCoordinates:i,nodesYCoordinates:r,localToGlobalMap:s,nodesPerElement:a}=e;let l=0,c=0,d=0,u=0,m=0,f=0;for(let e=0;e<a;e++)l+=i[s[e]]*t[e],c+=r[s[e]]*t[e],d+=i[s[e]]*n[e],u+=i[s[e]]*o[e],m+=r[s[e]]*n[e],f+=r[s[e]]*o[e];let h=d*f-u*m,p=[],g=[];for(let e=0;e<a;e++)p[e]=(f*n[e]-m*o[e])/h,g[e]=(d*o[e]-u*n[e])/h;return{xCoordinates:l,yCoordinates:c,detJacobian:h,basisFunctionDerivX:p,basisFunctionDerivY:g}}function jt(e,t,n){const[o,i,r]=n,s=(i[1]-r[1])*(o[0]-r[0])+(r[0]-i[0])*(o[1]-r[1]),a=((i[1]-r[1])*(e-r[0])+(r[0]-i[0])*(t-r[1]))/s,l=((r[1]-o[1])*(e-r[0])+(o[0]-r[0])*(t-r[1]))/s;return{inside:a>=-1e-12&&l>=-1e-12&&1-a-l>=-1e-12,ksi:a,eta:l}}function Yt(e,t,n){const[o,i]=function(e){const[t,n,o,i]=e;return[[t,n,i],[t,o,i]]}(n),r=jt(e,t,o),s=jt(e,t,i),a=r.inside||s.inside;let l=0,c=0;if(a){const[o,i,r,s]=n,a=(n,o)=>Math.abs((o[0]-n[0])*(n[1]-t)-(n[0]-e)*(o[1]-n[1]))/Math.sqrt((o[0]-n[0])**2+(o[1]-n[1])**2),d=a(o,i),u=a(r,s),m=a(o,r);l=d/(d+u),c=m/(m+a(i,s))}return{inside:a,ksi:l,eta:c}}function qt(e){const{nop:t,nodesXCoordinates:n}=e,o=n.length,i=t[0].length,r=Array.from({length:o},(()=>[])),s=Array(o).fill(0);for(let e=0;e<t.length;e++)for(let n=0;n<i;n++){const o=t[e][n]-1;s[o]=s[o]+1,r[o].push(e)}return{nodeNeighbors:r,neighborCount:s}}function Wt(e){let t,n=[],o=[],i=0;const{nodesXCoordinates:r,nodesYCoordinates:s,nop:a,boundaryElements:l,meshDimension:c,elementOrder:d}=e;"1D"===c?("linear"===d||"quadratic"===d)&&(t={0:[0],1:[1]}):"2D"===c&&("linear"===d?t={0:[0,2],1:[0,1],2:[1,3],3:[2,3]}:"quadratic"===d&&(t={0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]}));for(let e=0;e<l.length;e++)for(let c=0;c<l[e].length;c++){n[i]=l[e][c],i++;const[d,u]=l[e][c];let m=t[u],f=[],h=[];for(let e=0;e<m.length;e++){const t=a[d][m[e]]-1;f.push(r[t]),h.push(s[t])}for(let e=0;e<f.length-1;e++)o.push([[f[e],h[e]],[f[e+1],h[e+1]]])}return o}class Gt{constructor(e,t,n,o,i){this.boundaryConditions=e,this.boundaryElements=t,this.nop=n,this.meshDimension=o,this.elementOrder=i}imposeConstantTempBoundaryConditions(e,t){"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const o=this.boundaryConditions[n][1];st(`Boundary ${n}: Applying constant temperature of ${o} 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;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=o;for(let n=0;n<e.length;n++)t[r][n]=0;t[r][r]=1}))}else if("quadratic"===this.elementOrder){({0:[0],1:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=o;for(let n=0;n<e.length;n++)t[r][n]=0;t[r][r]=1}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const o=this.boundaryConditions[n][1];st(`Boundary ${n}: Applying constant temperature of ${o} 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;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=o;for(let n=0;n<e.length;n++)t[r][n]=0;t[r][r]=1}))}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;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=o;for(let n=0;n<e.length;n++)t[r][n]=0;t[r][r]=1}))}}))}}))}imposeConstantTempBoundaryConditionsFront(e,t){"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const o=this.boundaryConditions[n][1];st(`Boundary ${n}: Applying constant temperature of ${o} 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;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantTemp"===this.boundaryConditions[n][0]){const o=this.boundaryConditions[n][1];st(`Boundary ${n}: Applying constant temperature of ${o} 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;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}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;st(` - Applied constant temperature to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}}))}}))}imposeConvectionBoundaryConditions(e,t,n,o,i,r,s){let a=[],l=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(a[e]=t[1],l[e]=t[2])})),"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("convection"===this.boundaryConditions[n][0]){const o=a[n],i=l[n];st(`Boundary ${n}: Applying convection with heat transfer coefficient h=${o} W/(m²·K) and external temperature T∞=${i} K`),this.boundaryElements[n].forEach((([n,r])=>{let s;"linear"===this.elementOrder?s=0===r?0:1:"quadratic"===this.elementOrder&&(s=0===r?0:2);const a=this.nop[n][s]-1;st(` - Applied convection boundary condition to node ${a+1} (element ${n+1}, local node ${s+1})`),e[a]+=-o*i,t[a][a]+=o}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((c=>{if("convection"===this.boundaryConditions[c][0]){const d=a[c],u=l[c];st(`Boundary ${c}: Applying convection with heat transfer coefficient h=${d} W/(m²·K) and external temperature T∞=${u} K`),this.boundaryElements[c].forEach((([a,l])=>{if("linear"===this.elementOrder){let c,m,f,h,p;0===l?(c=n[0],m=0,f=0,h=3,p=2):1===l?(c=0,m=n[0],f=0,h=2,p=1):2===l?(c=n[0],m=1,f=1,h=4,p=2):3===l&&(c=1,m=n[0],f=2,h=4,p=1);let g=s.getBasisFunctions(c,m),b=g.basisFunction,y=g.basisFunctionDerivKsi,v=g.basisFunctionDerivEta,E=0,C=0,D=0,w=0;const M=this.nop[a].length;for(let e=0;e<M;e++){const t=this.nop[a][e]-1;0===l||2===l?(E+=i[t]*y[e],C+=r[t]*y[e]):1!==l&&3!==l||(D+=i[t]*v[e],w+=r[t]*v[e])}let F;F=0===l||2===l?Math.sqrt(E**2+C**2):Math.sqrt(D**2+w**2);for(let n=f;n<h;n+=p){let i=this.nop[a][n]-1;st(` - Applied convection boundary condition to node ${i+1} (element ${a+1}, local node ${n+1})`),e[i]+=-o[0]*F*b[n]*d*u;for(let e=f;e<h;e+=p){let r=this.nop[a][e]-1;t[i][r]+=-o[0]*F*b[n]*b[e]*d}}}else if("quadratic"===this.elementOrder)for(let c=0;c<3;c++){let m,f,h,p,g;0===l?(m=n[c],f=0,h=0,p=7,g=3):1===l?(m=0,f=n[c],h=0,p=3,g=1):2===l?(m=n[c],f=1,h=2,p=9,g=3):3===l&&(m=1,f=n[c],h=6,p=9,g=1);let b=s.getBasisFunctions(m,f),y=b.basisFunction,v=b.basisFunctionDerivKsi,E=b.basisFunctionDerivEta,C=0,D=0,w=0,M=0;const F=this.nop[a].length;for(let e=0;e<F;e++){const t=this.nop[a][e]-1;0===l||2===l?(C+=i[t]*v[e],D+=r[t]*v[e]):1!==l&&3!==l||(w+=i[t]*E[e],M+=r[t]*E[e])}let $;$=0===l||2===l?Math.sqrt(C**2+D**2):Math.sqrt(w**2+M**2);for(let n=h;n<p;n+=g){let i=this.nop[a][n]-1;st(` - Applied convection boundary condition to node ${i+1} (element ${a+1}, local node ${n+1})`),e[i]+=-o[c]*$*y[n]*d*u;for(let e=h;e<p;e+=g){let r=this.nop[a][e]-1;t[i][r]+=-o[c]*$*y[n]*y[e]*d}}}}))}}))}imposeConvectionBoundaryConditionsFront(e,t,n,o,i,r){let s=[],a=[];Object.keys(this.boundaryConditions).forEach((e=>{const t=this.boundaryConditions[e];"convection"===t[0]&&(s[e]=t[1],a[e]=t[2])}));const l=this.nop[e].length,c=Array(l).fill().map((()=>Array(l).fill(0))),d=Array(l).fill(0);for(const u in this.boundaryElements)if("convection"===this.boundaryConditions[u]?.[0]){const m=s[u],f=a[u];st(`Boundary ${u}: Applying convection with heat transfer coefficient h=${m} W/(m²·K) and external temperature T∞=${f} K`);const h=this.boundaryElements[u].find((([t,n])=>t===e));if(h){const s=h[1];if("1D"===this.meshDimension){let t;"linear"===this.elementOrder?t=0===s?0:1:"quadratic"===this.elementOrder&&(t=0===s?0:2),st(` - Applied convection boundary condition to node ${t+1} (element ${e+1}, local node ${t+1})`),d[t]+=-m*f,c[t][t]+=m}else if("2D"===this.meshDimension)if("linear"===this.elementOrder){let a,u,h,p,g;0===s?(a=o[0],u=0,h=0,p=3,g=2):1===s?(a=0,u=o[0],h=0,p=2,g=1):2===s?(a=o[0],u=1,h=1,p=4,g=2):3===s&&(a=1,u=o[0],h=2,p=4,g=1);const b=r.getBasisFunctions(a,u),y=b.basisFunction,v=b.basisFunctionDerivKsi,E=b.basisFunctionDerivEta;let C,D=0,w=0,M=0,F=0;for(let o=0;o<l;o++){const i=this.nop[e][o]-1;0===s||2===s?(D+=t[i]*v[o],w+=n[i]*v[o]):1!==s&&3!==s||(M+=t[i]*E[o],F+=n[i]*E[o])}C=0===s||2===s?Math.sqrt(D**2+w**2):Math.sqrt(M**2+F**2);for(let e=h;e<p;e+=g){d[e]+=-i[0]*C*y[e]*m*f;for(let t=h;t<p;t+=g)c[e][t]+=-i[0]*C*y[e]*y[t]*m}}else if("quadratic"===this.elementOrder)for(let a=0;a<3;a++){let l,u,h,p,g;0===s?(l=o[a],u=0,h=0,p=7,g=3):1===s?(l=0,u=o[a],h=0,p=3,g=1):2===s?(l=o[a],u=1,h=2,p=9,g=3):3===s&&(l=1,u=o[a],h=6,p=9,g=1);let b=r.getBasisFunctions(l,u),y=b.basisFunction,v=b.basisFunctionDerivKsi,E=b.basisFunctionDerivEta,C=0,D=0,w=0,M=0;const F=this.nop[e].length;for(let o=0;o<F;o++){const i=this.nop[e][o]-1;0===s||2===s?(C+=t[i]*v[o],D+=n[i]*v[o]):1!==s&&3!==s||(w+=t[i]*E[o],M+=n[i]*E[o])}let $;$=0===s||2===s?Math.sqrt(C**2+D**2):Math.sqrt(w**2+M**2);for(let e=h;e<p;e+=g){d[e]+=-i[a]*$*y[e]*m*f;for(let t=h;t<p;t+=g)c[e][t]+=-i[a]*$*y[e]*y[t]*m}}}}return{localJacobianMatrix:c,localResidualVector:d}}}function _t(e,t){at("Starting solid heat transfer matrix assembly...");const{nodesXCoordinates:n,nodesYCoordinates:o,nop:i,boundaryElements:r,totalElements:s,meshDimension:a,elementOrder:l}=e,c=Tt(e),{residualVector:d,jacobianMatrix:u,localToGlobalMap:m,basisFunctions:f,gaussPoints:h,gaussWeights:p,nodesPerElement:g}=c;for(let e=0;e<s;e++){for(let t=0;t<g;t++)m[t]=i[e][t]-1;for(let e=0;e<h.length;e++)if("1D"===a){const t=f.getBasisFunctions(h[e]),o=Rt({basisFunction:t.basisFunction,basisFunctionDerivKsi:t.basisFunctionDerivKsi,nodesXCoordinates:n,localToGlobalMap:m,nodesPerElement:g}),{detJacobian:i,basisFunctionDerivX:r}=o;for(let t=0;t<g;t++){let n=m[t];for(let o=0;o<g;o++){let s=m[o];u[n][s]+=-p[e]*i*(r[t]*r[o])}}}else if("2D"===a)for(let t=0;t<h.length;t++){const i=f.getBasisFunctions(h[e],h[t]),r=Bt({basisFunction:i.basisFunction,basisFunctionDerivKsi:i.basisFunctionDerivKsi,basisFunctionDerivEta:i.basisFunctionDerivEta,nodesXCoordinates:n,nodesYCoordinates:o,localToGlobalMap:m,nodesPerElement:g}),{detJacobian:s,basisFunctionDerivX:a,basisFunctionDerivY:l}=r;for(let n=0;n<g;n++){let o=m[n];for(let i=0;i<g;i++){let r=m[i];u[o][r]+=-p[e]*p[t]*s*(a[n]*a[i]+l[n]*l[i])}}}}const b=new Gt(t,r,i,a,l);return b.imposeConvectionBoundaryConditions(d,u,h,p,n,o,f),b.imposeConstantTempBoundaryConditions(d,u),at("Solid heat transfer matrix assembly completed"),{jacobianMatrix:u,residualVector:d}}function Lt({elementIndex:e,nop:t,meshData:n,basisFunctions:o,FEAData:i}){const{gaussPoints:r,gaussWeights:s,nodesPerElement:a}=i,{nodesXCoordinates:l,nodesYCoordinates:c,meshDimension:d}=n,u=Array(a).fill().map((()=>Array(a).fill(0))),m=Array(a).fill(0),f=Array(a),h=Array(a);for(let n=0;n<a;n++)f[n]=Math.abs(t[e][n]),h[n]=Math.abs(t[e][n])-1;if("1D"===d)for(let e=0;e<r.length;e++){const{basisFunction:t,basisFunctionDerivKsi:n}=o.getBasisFunctions(r[e]),{detJacobian:i,basisFunctionDerivX:c}=Rt({basisFunction:t,basisFunctionDerivKsi:n,nodesXCoordinates:l,localToGlobalMap:h,nodesPerElement:a});for(let t=0;t<a;t++)for(let n=0;n<a;n++)u[t][n]-=s[e]*i*(c[t]*c[n])}else if("2D"===d)for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){const{basisFunction:n,basisFunctionDerivKsi:i,basisFunctionDerivEta:d}=o.getBasisFunctions(r[e],r[t]),m=f.map((e=>e-1)),{detJacobian:h,basisFunctionDerivX:p,basisFunctionDerivY:g}=Bt({basisFunction:n,basisFunctionDerivKsi:i,basisFunctionDerivEta:d,nodesXCoordinates:l,nodesYCoordinates:c,localToGlobalMap:m,nodesPerElement:a});for(let n=0;n<a;n++)for(let o=0;o<a;o++)u[n][o]-=s[e]*s[t]*h*(p[n]*p[o]+g[n]*g[o])}return{localJacobianMatrix:u,localResidualVector:m,ngl:f}}class Kt{constructor(e,t,n,o,i){this.boundaryConditions=e,this.boundaryElements=t,this.nop=n,this.meshDimension=o,this.elementOrder=i}imposeDirichletBoundaryConditions(e,t,n){"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((o=>{if("constantValue"===this.boundaryConditions[o][0]){const i=this.boundaryConditions[o][1];st(`Boundary ${o}: Applying constant value of ${i} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,r])=>{if("linear"===this.elementOrder){({0:[0],1:[1]})[r].forEach((r=>{const s=this.nop[o][r]-1;st(` - Applied constant value to node ${s+1} (element ${o+1}, local node ${r+1})`),e[s]=n?i-n[s]:i;for(let n=0;n<e.length;n++)t[s][n]=0;t[s][s]=1}))}else if("quadratic"===this.elementOrder){({0:[0],1:[2]})[r].forEach((r=>{const s=this.nop[o][r]-1;st(` - Applied constant value to node ${s+1} (element ${o+1}, local node ${r+1})`),e[s]=n?i-n[s]:i;for(let n=0;n<e.length;n++)t[s][n]=0;t[s][s]=1}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((o=>{if("constantValue"===this.boundaryConditions[o][0]){const i=this.boundaryConditions[o][1];st(`Boundary ${o}: Applying constant value of ${i} (Dirichlet condition)`),this.boundaryElements[o].forEach((([o,r])=>{if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[r].forEach((r=>{const s=this.nop[o][r]-1;st(` - Applied constant value to node ${s+1} (element ${o+1}, local node ${r+1})`),e[s]=n?i-n[s]:i;for(let n=0;n<e.length;n++)t[s][n]=0;t[s][s]=1}))}else if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[r].forEach((r=>{const s=this.nop[o][r]-1;st(` - Applied constant value to node ${s+1} (element ${o+1}, local node ${r+1})`),e[s]=n?i-n[s]:i;for(let n=0;n<e.length;n++)t[s][n]=0;t[s][s]=1}))}}))}}))}imposeConstantValueBoundaryConditionsFront(e,t){"1D"===this.meshDimension?Object.keys(this.boundaryConditions).forEach((n=>{if("constantValue"===this.boundaryConditions[n][0]){const o=this.boundaryConditions[n][1];st(`Boundary ${n}: Applying constant value of ${o} (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;st(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}else if("quadratic"===this.elementOrder){({0:[0],2:[2]})[i].forEach((i=>{const r=this.nop[n][i]-1;st(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}}))}})):"2D"===this.meshDimension&&Object.keys(this.boundaryConditions).forEach((n=>{if("constantValue"===this.boundaryConditions[n][0]){const o=this.boundaryConditions[n][1];st(`Boundary ${n}: Applying constant value of ${o} (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;st(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}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;st(` - Applied constant value to node ${r+1} (element ${n+1}, local node ${i+1})`),e[r]=1,t[r]=o}))}}))}}))}}function Jt(e,t,n,o){at("Starting front propagation matrix assembly...");let i=1-o+.01;st(`eikonalViscousTerm: ${i}`),st(`eikonalActivationFlag: ${o}`);const{nodesXCoordinates:r,nodesYCoordinates:s,nop:a,boundaryElements:l,totalElements:c,meshDimension:d,elementOrder:u}=e,m=Tt(e),{residualVector:f,jacobianMatrix:h,localToGlobalMap:p,basisFunctions:g,gaussPoints:b,gaussWeights:y,nodesPerElement:v}=m;for(let e=0;e<c;e++){for(let t=0;t<v;t++)p[t]=a[e][t]-1;for(let e=0;e<b.length;e++)if("1D"===d){errorLog("1D front propagation is not yet supported");let t=g.getBasisFunctions(b[e]);const o=Rt({basisFunction:t.basisFunction,basisFunctionDerivKsi:t.basisFunctionDerivKsi,nodesXCoordinates:r,localToGlobalMap:p,nodesPerElement:v}),{detJacobian:i,basisFunctionDerivX:s}=o;t.basisFunction;let a=0;for(let e=0;e<v;e++)a+=n[p[e]]*s[e];for(let e=0;e<v;e++){p[e];for(let e=0;e<v;e++)p[e]}}else if("2D"===d)for(let t=0;t<b.length;t++){let a=g.getBasisFunctions(b[e],b[t]);const l=Bt({basisFunction:a.basisFunction,basisFunctionDerivKsi:a.basisFunctionDerivKsi,basisFunctionDerivEta:a.basisFunctionDerivEta,nodesXCoordinates:r,nodesYCoordinates:s,localToGlobalMap:p,nodesPerElement:v}),{detJacobian:c,basisFunctionDerivX:d,basisFunctionDerivY:u}=l,m=a.basisFunction;let E=0,C=0;for(let e=0;e<v;e++)E+=n[p[e]]*d[e],C+=n[p[e]]*u[e];for(let n=0;n<v;n++){let r=p[n];f[r]+=i*y[e]*y[t]*c*d[n]*E+i*y[e]*y[t]*c*u[n]*C,0!==o&&(f[r]+=o*(y[e]*y[t]*c*m[n]*Math.sqrt(E**2+C**2)-y[e]*y[t]*c*m[n]));for(let s=0;s<v;s++){let a=p[s];h[r][a]+=-i*y[e]*y[t]*c*(d[n]*d[s]+u[n]*u[s]),0!==o&&(h[r][a]+=o*(-c*E*m[n]*y[e]*y[t]/Math.sqrt(E**2+C**2+1e-8))*d[s]-o*(c*C*m[n]*y[e]*y[t]/Math.sqrt(E**2+C**2+1e-8))*u[s])}}}}return new Kt(t,l,a,d,u).imposeDirichletBoundaryConditions(f,h),at("Front propagation matrix assembly completed"),{jacobianMatrix:h,residualVector:f}}function Ht({elementIndex:e,nop:t,meshData:n,basisFunctions:o,FEAData:i,solutionVector:r,eikonalActivationFlag:s}){const{gaussPoints:a,gaussWeights:l,nodesPerElement:c}=i,{nodesXCoordinates:d,nodesYCoordinates:u,meshDimension:m}=n;let f=1-s+.01;const h=Array(c).fill().map((()=>Array(c).fill(0))),p=Array(c).fill(0),g=Array(c),b=Array(c);for(let n=0;n<c;n++)g[n]=Math.abs(t[e][n]),b[n]=Math.abs(t[e][n])-1;for(let e=0;e<a.length;e++)if("1D"===m){errorLog("1D front propagation is not yet supported");let t=o.getBasisFunctions(a[e]);const n=Rt({basisFunction:t.basisFunction,basisFunctionDerivKsi:t.basisFunctionDerivKsi,nodesXCoordinates:d,localToGlobalMap:b,nodesPerElement:c}),{detJacobian:i,basisFunctionDerivX:s}=n;t.basisFunction;let l=0;for(let e=0;e<c;e++)l+=r[b[e]]*s[e];for(let e=0;e<c;e++){b[e];for(let e=0;e<c;e++)b[e]}}else if("2D"===m)for(let t=0;t<a.length;t++){const{basisFunction:n,basisFunctionDerivKsi:i,basisFunctionDerivEta:m}=o.getBasisFunctions(a[e],a[t]),{detJacobian:g,basisFunctionDerivX:y,basisFunctionDerivY:v}=Bt({basisFunction:n,basisFunctionDerivKsi:i,basisFunctionDerivEta:m,nodesXCoordinates:d,nodesYCoordinates:u,localToGlobalMap:b,nodesPerElement:c});let E=0,C=0;for(let e=0;e<c;e++)E+=r[b[e]]*y[e],C+=r[b[e]]*v[e];for(let o=0;o<c;o++){b[o],p[o]+=f*l[e]*l[t]*g*y[o]*E+f*l[e]*l[t]*g*v[o]*C,0!==s&&(p[o]+=s*(l[e]*l[t]*g*n[o]*Math.sqrt(E**2+C**2)-l[e]*l[t]*g*n[o]));for(let i=0;i<c;i++)h[o][i]-=f*l[e]*l[t]*g*(y[o]*y[i]+v[o]*v[i]),0!==s&&(h[o][i]+=s*(-g*E*n[o]*l[e]*l[t]/Math.sqrt(E**2+C**2+1e-8))*y[i]-s*(g*C*n[o]*l[e]*l[t]/Math.sqrt(E**2+C**2+1e-8))*v[i])}}return{localJacobianMatrix:h,localResidualVector:p,ngl:g}}const Ut={},zt={},Zt={currentElementIndex:0},Qt={};let en;function tn(e,t,n,o={}){const i=Tt(t),r=t.nodesXCoordinates.length,s=t.totalElements;!function(e,t){Ut.nodalNumbering=Array(t).fill().map((()=>Array(e).fill(0))),Ut.nodeConstraintCode=Array(e).fill(0),Ut.boundaryValues=Array(e).fill(0),Ut.globalResidualVector=Array(e).fill(0),Ut.solutionVector=Array(e).fill(0),Ut.topologyData=Array(t).fill(0),Ut.lateralData=Array(t).fill(0),zt.writeFlag=0,zt.totalNodes=e,zt.transformationFlag=0,zt.nodesPerElement=Array(t).fill(0),zt.determinant=1;const n=Math.max(e,2e3);zt.globalSolutionVector=Array(n).fill(0),zt.frontDataIndex=0,Zt.localJacobianMatrix=Array(e).fill().map((()=>Array(e).fill(0))),Zt.currentElementIndex=0;const o=function(e,t){const n=Math.max(Math.ceil(Math.sqrt(t))*e,2*e);return n*t}(e,t);Qt.frontValues=Array(o).fill(0),Qt.columnHeaders=Array(n).fill(0),Qt.pivotRow=Array(n).fill(0),Qt.pivotData=Array(o).fill(0)}(i.nodesPerElement,s),at("Solving system using frontal..."),console.time("systemSolving"),en=new Pt({meshDimension:t.meshDimension,elementOrder:t.elementOrder});for(let e=0;e<t.totalElements;e++)for(let n=0;n<i.nodesPerElement;n++)Ut.nodalNumbering[e][n]=t.nop[e][n];for(let e=0;e<t.nodesXCoordinates.length;e++)Ut.nodeConstraintCode[e]=0,Ut.boundaryValues[e]=0;let a;e===Lt?(a=new Gt(n,t.boundaryElements,t.nop,t.meshDimension,t.elementOrder),a.imposeConstantTempBoundaryConditionsFront(Ut.nodeConstraintCode,Ut.boundaryValues)):e===Ht&&(a=new Kt(n,t.boundaryElements,t.nop,t.meshDimension,t.elementOrder),a.imposeConstantValueBoundaryConditionsFront(Ut.nodeConstraintCode,Ut.boundaryValues));for(let e=0;e<t.nodesXCoordinates.length;e++)Ut.globalResidualVector[e]=0;zt.totalNodes=t.nodesXCoordinates.length,zt.writeFlag=0,zt.transformationFlag=1,zt.determinant=1;for(let e=0;e<t.totalElements;e++)zt.nodesPerElement[e]=i.nodesPerElement;zt.currentSolutionVector=o.solutionVector,zt.eikonalActivationFlag=o.eikonalActivationFlag,function(e,t,n,o){const i=e.totalElements,r=e.nodesXCoordinates.length,s=Math.max(r,zt.globalSolutionVector.length);let a,l=Array(t.nodesPerElement).fill(0),c=Array(t.nodesPerElement).fill(0),d=Array(s).fill(0),u=Array(s).fill(0),m=Array(s).fill(0),f=Array(s).fill(0),h=Array(s).fill(0),p=Array(s).fill().map((()=>Array(s).fill(0))),g=Array(r).fill(0),b=Array(r).fill(0),y=Array(r).fill(0),v=1;zt.writeFlag++;let E=1,C=1;Zt.currentElementIndex=0;for(let e=0;e<zt.totalNodes;e++)g[e]=0,b[e]=0;if(0!==zt.transformationFlag){for(let e=0;e<zt.totalNodes;e++)y[e]=0;for(let e=0;e<i;e++){let t=i-e-1;for(let e=0;e<zt.nodesPerElement[t];e++){let n=Ut.nodalNumbering[t][e];0===y[n-1]&&(y[n-1]=1,Ut.nodalNumbering[t][e]=-Ut.nodalNumbering[t][e])}}}zt.transformationFlag=0;let D=0,w=0;for(let e=0;e<s;e++)for(let t=0;t<s;t++)p[t][e]=0;for(;;){let r=!1,y=0,M=0;if(Zt.currentElementIndex<i&&(Zt.currentElementIndex++,r=nn(e,t,n,o)),r){const e=Zt.currentElementIndex;y=zt.nodesPerElement[e-1],M=zt.nodesPerElement[e-1];for(let t=0;t<M;t++){let n,o,i=Ut.nodalNumbering[e-1][t];if(0===D)D++,l[t]=D,Qt.columnHeaders[D-1]=i;else{for(n=0;n<D&&Math.abs(i)!==Math.abs(Qt.columnHeaders[n]);n++);n===D?(D++,l[t]=D,Qt.columnHeaders[D-1]=i):(l[t]=n+1,Qt.columnHeaders[n]=i)}if(0===w)w++,c[t]=w,d[w-1]=i;else{for(o=0;o<w&&Math.abs(i)!==Math.abs(d[o]);o++);o===w?(w++,c[t]=w,d[w-1]=i):(c[t]=o+1,d[o]=i)}}if(w>s||D>s)return void lt("Error: systemSize not large enough");for(let e=0;e<M;e++){let t=l[e];for(let n=0;n<y;n++){p[c[n]-1][t-1]+=Zt.localJacobianMatrix[n][e]}}}let F=0;for(let e=0;e<D;e++)Qt.columnHeaders[e]<0&&(m[F]=e+1,F++);let $=0,A=0;for(let e=0;e<w;e++){let t=d[e];if(t<0){u[A]=e+1,A++;let n=Math.abs(t);1===Ut.nodeConstraintCode[n-1]&&(f[$]=e+1,$++,Ut.nodeConstraintCode[n-1]=2,Ut.globalResidualVector[n-1]=Ut.boundaryValues[n-1])}}if($>0)for(let e=0;e<$;e++){let t=f[e]-1,n=Math.abs(d[t]);for(let e=0;e<D;e++){p[t][e]=0,Math.abs(Qt.columnHeaders[e])===n&&(p[t][e]=1)}}if(F>C||Zt.currentElementIndex<i){if(0===F)return void lt("Error: no more rows fully summed");let e=u[0],t=m[0],n=p[e-1][t-1];if(Math.abs(n)<1e-4){n=0;for(let o=0;o<F;o++){let i=m[o];for(let o=0;o<A;o++){let r=u[o],s=p[r-1][i-1];Math.abs(s)>Math.abs(n)&&(n=s,t=i,e=r)}}}let o=Math.abs(d[e-1]);a=Math.abs(Qt.columnHeaders[t-1]);let r=o+a+g[o-1]+b[a-1];zt.determinant=zt.determinant*n*(-1)**r/Math.abs(n);for(let e=0;e<zt.totalNodes;e++)e>=o&&g[e]--,e>=a&&b[e]--;if(Math.abs(n)<1e-10&<(`Matrix singular or ill-conditioned, currentElementIndex=${Zt.currentElementIndex}, pivotGlobalRowIndex=${o}, pivotColumnGlobalIndex=${a}, pivotValue=${n}`),0===n)return;for(let t=0;t<D;t++)Qt.pivotRow[t]=p[e-1][t]/n;let s=Ut.globalResidualVector[o-1]/n;if(Ut.globalResidualVector[o-1]=s,h[e-1]=n,e>1)for(let n=0;n<e-1;n++){let e=Math.abs(d[n]),o=p[n][t-1];if(h[n]=o,t>1&&0!==o)for(let e=0;e<t-1;e++)p[n][e]-=o*Qt.pivotRow[e];if(t<D)for(let e=t;e<D;e++)p[n][e-1]=p[n][e]-o*Qt.pivotRow[e];Ut.globalResidualVector[e-1]-=o*s}if(e<w)for(let n=e;n<w;n++){let e=Math.abs(d[n]),o=p[n][t-1];if(h[n]=o,t>1)for(let e=0;e<t-1;e++)p[n-1][e]=p[n][e]-o*Qt.pivotRow[e];if(t<D)for(let e=t;e<D;e++)p[n-1][e-1]=p[n][e]-o*Qt.pivotRow[e];Ut.globalResidualVector[e-1]-=o*s}for(let e=0;e<w;e++)Qt.pivotData[E+e-1]=h[e];E+=w;for(let e=0;e<w;e++)Qt.pivotData[E+e-1]=d[e];E+=w,Qt.pivotData[E-1]=e,E++;for(let e=0;e<D;e++)Qt.frontValues[v-1+e]=Qt.pivotRow[e];v+=D;for(let e=0;e<D;e++)Qt.frontValues[v-1+e]=Qt.columnHeaders[e];v+=D,Qt.frontValues[v-1]=o,Qt.frontValues[v]=D,Qt.frontValues[v+1]=t,Qt.frontValues[v+2]=n,v+=4;for(let e=0;e<w;e++)p[e][D-1]=0;for(let e=0;e<D;e++)p[w-1][e]=0;if(D--,t<D+1)for(let e=t-1;e<D;e++)Qt.columnHeaders[e]=Qt.columnHeaders[e+1];if(w--,e<w+1)for(let t=e-1;t<w;t++)d[t]=d[t+1];if(w>1||Zt.currentElementIndex<i)continue;if(a=Math.abs(Qt.columnHeaders[0]),e=1,n=p[0][0],o=Math.abs(d[0]),t=1,r=o+a+g[o-1]+b[a-1],zt.determinant=zt.determinant*n*(-1)**r/Math.abs(n),Qt.pivotRow[0]=1,Math.abs(n)<1e-10&<(`Matrix singular or ill-conditioned, currentElementIndex=${Zt.currentElementIndex}, pivotGlobalRowIndex=${o}, pivotColumnGlobalIndex=${a}, pivotValue=${n}`),0===n)return;Ut.globalResidualVector[o-1]=Ut.globalResidualVector[o-1]/n,Qt.frontValues[v-1]=Qt.pivotRow[0],v++,Qt.frontValues[v-1]=Qt.columnHeaders[0],v++,Qt.frontValues[v-1]=o,Qt.frontValues[v]=D,Qt.frontValues[v+1]=t,Qt.frontValues[v+2]=n,v+=4,Qt.pivotData[E-1]=h[0],E++,Qt.pivotData[E-1]=d[0],E++,Qt.pivotData[E-1]=e,E++,zt.frontDataIndex=v,1===zt.writeFlag&&st(`total ecs transfer in matrix reduction=${v}`),on(v);break}}}(t,i,a,e);for(let e=0;e<t.nodesXCoordinates.length;e++)Ut.solutionVector[e]=zt.globalSolutionVector[e];const{nodesXCoordinates:l,nodesYCoordinates:c}=t;for(let e=0;e<t.nodesXCoordinates.length;e++)"1D"===t.meshDimension?st(`${l[e].toExponential(5)} ${Ut.solutionVector[e].toExponential(5)}`):st(`${l[e].toExponential(5)} ${c[e].toExponential(5)} ${Ut.solutionVector[e].toExponential(5)}`);console.timeEnd("systemSolving"),at("System solved successfully");const{nodesXCoordinates:d,nodesYCoordinates:u}=t;return{solutionVector:Ut.solutionVector.slice(0,r),nodesCoordinates:{nodesXCoordinates:d,nodesYCoordinates:u}}}function nn(e,t,n,o){const i=Zt.currentElementIndex-1;if(i<0||i>=e.totalElements)return lt(`Skipping out-of-range elementIndex=${i} (totalElements=${e.totalElements})`),!1;const{localJacobianMatrix:r,localResidualVector:s,ngl:a}=o({elementIndex:i,nop:Ut.nodalNumbering,meshData:e,basisFunctions:en,FEAData:t,solutionVector:zt.currentSolutionVector,eikonalActivationFlag:zt.eikonalActivationFlag});let l=Array(t.nodesPerElement).fill().map((()=>Array(t.nodesPerElement).fill(0))),c=Array(t.nodesPerElement).fill(0);if(o===Lt){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:r}=t,s=n.imposeConvectionBoundaryConditionsFront(i,e.nodesXCoordinates,e.nodesYCoordinates,o,r,en);l=s.localJacobianMatrix,c=s.localResidualVector}}for(let e=0;e<t.nodesPerElement;e++)for(let n=0;n<t.nodesPerElement;n++)Zt.localJacobianMatrix[e][n]=r[e][n]+l[e][n];for(let e=0;e<t.nodesPerElement;e++){const t=a[e]-1;Ut.globalResidualVector[t]+=s[e]+c[e]}return!0}function on(e){for(let e=0;e<zt.totalNodes;e++)zt.globalSolutionVector[e]=Ut.boundaryValues[e];for(let t=1;t<=zt.totalNodes;t++){e-=4;let n=Qt.frontValues[e-1],o=Qt.frontValues[e],i=Qt.frontValues[e+1];if(Qt.frontValues[e+2],1===t)e--,Qt.columnHeaders[0]=Qt.frontValues[e-1],e--,Qt.pivotRow[0]=Qt.frontValues[e-1];else{e-=o;for(let t=0;t<o;t++)Qt.columnHeaders[t]=Qt.frontValues[e-1+t];e-=o;for(let t=0;t<o;t++)Qt.pivotRow[t]=Qt.frontValues[e-1+t]}let r=Math.abs(Qt.columnHeaders[i-1]);if(Ut.nodeConstraintCode[r-1]>0)continue;let s=0;Qt.pivotRow[i-1]=0;for(let e=0;e<o;e++)s-=Qt.pivotRow[e]*zt.globalSolutionVector[Math.abs(Qt.columnHeaders[e])-1];zt.globalSolutionVector[r-1]=s+Ut.globalResidualVector[n-1],Ut.nodeConstraintCode[r-1]=1}1===zt.writeFlag&&st(`value of frontDataCounter after backsubstitution=${e}`)}function rn(e,t={}){let n=0,o=!1,i=0,r=[],s=[];const{maxIterations:a=100,tolerance:l=1e-4}=t,c=t.meshData.nodesXCoordinates.length;let d=new Float64Array(c),u=new Float64Array(c);for(t.initialSolution&&t.initialSolution.length===c&&(d=new Float64Array(t.initialSolution));i<a&&!o;){if(ot(1,u,d),"frontal"===t.solverMethod){u=tn(Ht,t.meshData,t.boundaryConditions,{solutionVector:d,eikonalActivationFlag:t.eikonalActivationFlag}).solutionVector}else{({jacobianMatrix:r,residualVector:s}=e(t.meshData,t.boundaryConditions,d,t.eikonalActivationFlag));u=Nt(t.solverMethod,r,s).solutionVector}if(n=tt(u),at(`Newton-Raphson iteration ${i+1}: Error norm = ${n.toExponential(4)}`),n<=l)o=!0;else if(n>100){lt(`Solution not converged. Error norm: ${n}`);break}i++}return{solutionVector:d,converged:o,iterations:i,jacobianMatrix:r,residualVector:s}}class sn{constructor(e,t,n,o,i,r,s,a){this.boundaryConditions=e,this.boundaryElements=t,this.nop=n,this.meshDimension=o,this.elementOrder=i,this.totalNodesVelocity=r,this.totalNodesPressure=s,this.q2ToPressureMap=a}imposeDirichletBoundaryConditions(e,t){const n=e.length;let o=!1;if("2D"===this.meshDimension&&(Object.keys(this.boundaryConditions).forEach((i=>{const r=this.boundaryConditions[i][0];if("stressFree"===r)o=!0,st(`Boundary ${i}: Applying stress-free condition (natural BC)`);else if("constantVelocity"===r){const o=this.boundaryConditions[i][1],r=this.boundaryConditions[i][2];st(`Boundary ${i}: Applying constant velocity condition (u=${o}, v=${r})`),this.boundaryElements[i].forEach((([i,s])=>{if("quadratic"===this.elementOrder){({0:[0,3,6],1:[0,1,2],2:[2,5,8],3:[6,7,8]})[s].forEach((s=>{const a=this.nop[i][s]-1,l=a,c=this.totalNodesVelocity+a;st(` - Applied velocity Dirichlet to node ${a+1} (element ${i+1}, local node ${s+1})`),e[l]=o;for(let e=0;e<n;e++)t[l][e]=0;t[l][l]=1,e[c]=r;for(let e=0;e<n;e++)t[c][e]=0;t[c][c]=1}))}else if("linear"===this.elementOrder){({0:[0,2],1:[0,1],2:[1,3],3:[2,3]})[s].forEach((s=>{const a=this.nop[i][s]-1,l=a,c=this.totalNodesVelocity+a;st(` - Applied velocity Dirichlet to node ${a+1} (element ${i+1}, local node ${s+1})`),e[l]=o;for(let e=0;e<n;e++)t[l][e]=0;t[l][l]=1,e[c]=r;for(let e=0;e<n;e++)t[c][e]=0;t[c][c]=1}))}}))}})),!o)){const o=2*this.totalNodesVelocity;for(let e=0;e<n;e++)t[o][e]=0;t[o][o]=1,e[o]=0,st("Pinned pressure at first pressure node (p = 0) to remove null space")}}}class an{constructor(e,t,n){this.boundaryConditions=e,this.totalNodesX=t,this.dofsPerNode=n}imposeNaturalAndSpringBoundaryConditions(e,t){Object.keys(this.boundaryConditions).forEach((n=>{const o=Number(n)-1,i=this.dofsPerNode*o,r=i+1;this.boundaryConditions[n].forEach((o=>{const[s,a,l]=o;if("force"===s)e[i]+=a,st(`Node ${n}: Applied point force ${a} (natural BC)`);else if("moment"===s)e[r]+=a,st(`Node ${n}: Applied point moment ${a} (natural BC)`);else if("spring"===s){const o=a,r=l??0;t[i][i]+=o,e[i]+=o*r,st(`Node ${n}: Applied transverse elastic spring, k=${o} (mixed/Robin BC)`)}}))}))}imposeEssentialBoundaryConditions(e,t){const n=e.length,o=(o,i)=>{e[o]=i;for(let e=0;e<n;e++)t[o][e]=0;t[o][o]=1};Object.keys(this.boundaryConditions).forEach((e=>{const t=Number(e)-1,n=this.dofsPerNode*t,i=n+1;this.boundaryConditions[e].forEach((t=>{const[r,s]=t;"fixed"===r?(o(n,0),o(i,0),st(`Node ${e}: Applied fixed (clamped) support: w=0, theta=0 (essential BC)`)):"pinned"===r||"deflection"===r?(o(n,s??0),st(`Node ${e}: Applied deflection w=${s??0} (essential BC)`)):"rotationFixed"===r||"rotation"===r?(o(i,s??0),st(`Node ${e}: Applied rotation theta=${s??0} (essential BC)`)):"force"!==r&&"moment"!==r&&"spring"!==r&<(`Unknown beam boundary condition type: "${r}"`)}))}))}}class ln{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;"),at("FEAScriptModel instance created")}setModelConfig(e,t={}){this.solverConfig=e,void 0!==t?.coefficientFunctions&&(this.coefficientFunctions=t.coefficientFunctions,st("coefficientFunctions set")),void 0!==t?.nonlinear&&(this.nonlinear=t.nonlinear,st(`nonlinear set to ${this.nonlinear}`)),void 0!==t?.maxIterations&&(this.maxIterations=t.maxIterations,st(`maxIterations set to ${this.maxIterations}`)),void 0!==t?.tolerance&&(this.tolerance=t.tolerance,st(`tolerance set to ${this.tolerance}`)),st(`solverConfig set to ${e}`)}setMeshConfig(e){this.meshConfig=e,st(`meshConfig set with dimensions: ${e.meshDimension}`)}addBoundaryCondition(e,t){this.boundaryConditions[e]=t,st(`boundaryConditions added for boundary: ${e}, type: ${t[0]}`)}setSolverMethod(e){this.solverMethod=e,st(`solverMethod set to: ${e}`)}solve(e={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||lt("solverConfig, meshConfig and boundaryConditions must be set before solving");let t=[],n=[],o=[],i=[];at("Preparing mesh...");const r=Xt(this.meshConfig);at("Mesh preparation completed");const s={nodesXCoordinates:r.nodesXCoordinates,nodesYCoordinates:r.nodesYCoordinates};if(at("Beginning solving process..."),console.time("totalSolvingTime"),at(`Using solver ${this.solverConfig}`),"heatConductionScript"===this.solverConfig)if("frontal"===this.solverMethod){o=tn(Lt,r,this.boundaryConditions).solutionVector}else{({jacobianMatrix:t,residualVector:n}=_t(r,this.boundaryConditions));o=Nt(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("frontPropagationScript"===this.solverConfig){let s=0;const a=5,l={meshData:r,boundaryConditions:this.boundaryConditions,eikonalActivationFlag:s,solverMethod:this.solverMethod,initialSolution:i,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance};for(;s<=1;){l.eikonalActivationFlag=s,o.length>0&&(l.initialSolution=[...o]);const e=rn(Jt,l);t=e.jacobianMatrix,n=e.residualVector,o=e.solutionVector,s+=1/a}}else if("generalFormPDEScript"===this.solverConfig)if("frontal"===this.solverMethod)lt("Frontal solver is not yet supported for generalFormPDEScript. Please use 'lusolve' or 'jacobi'.");else if(this.nonlinear){const i=rn(((e,t,n)=>function(e,t,n,o){at("Starting nonlinear general form PDE matrix assembly...");const{nodesXCoordinates:i,nodesYCoordinates:r,nop:s,boundaryElements:a,totalElements:l,meshDimension:c,elementOrder:d}=e,{A:u,B:m,C:f,D:h,dDdu:p}=n,g=Tt(e),{residualVector:b,jacobianMatrix:y,localToGlobalMap:v,basisFunctions:E,gaussPoints:C,gaussWeights:D,nodesPerElement:w}=g;if("1D"===c)for(let e=0;e<l;e++){for(let t=0;t<w;t++)v[t]=Math.abs(s[e][t])-1;for(let e=0;e<C.length;e++){const{basisFunction:t,basisFunctionDerivKsi:n}=E.getBasisFunctions(C[e]),{detJacobian:r,basisFunctionDerivX:s}=Rt({basisFunction:t,basisFunctionDerivKsi:n,nodesXCoordinates:i,localToGlobalMap:v,nodesPerElement:w});let a=0,l=0,c=0;for(let e=0;e<w;e++)a+=i[v[e]]*t[e],l+=o[v[e]]*t[e],c+=o[v[e]]*s[e];const d=u(a),g=m(a),M=f(a),F=h(a,l),$=p(a,l);for(let n=0;n<w;n++){const o=v[n];b[o]+=D[e]*r*(d*c*s[n]-g*c*t[n]-M*l*t[n]+F*t[n]);for(let i=0;i<w;i++){const a=v[i];y[o][a]+=-D[e]*r*(d*s[n]*s[i]-g*s[i]*t[n]-M*t[n]*t[i]+$*t[n]*t[i])}}}}else"2D"===c&<("2D nonlinear general form PDE is not yet supported in assembleGeneralFormPDENonlinearMat.");return new Kt(t,a,s,c,d).imposeDirichletBoundaryConditions(b,y,o),at("Nonlinear general form PDE matrix assembly completed"),{jacobianMatrix:y,residualVector:b}}(e,t,this.coefficientFunctions,n)),{meshData:r,boundaryConditions:this.boundaryConditions,solverMethod:this.solverMethod,maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance});t=i.jacobianMatrix,n=i.residualVector,o=i.solutionVector}else{({jacobianMatrix:t,residualVector:n}=function(e,t,n){at("Starting general form PDE matrix assembly...");const{nodesXCoordinates:o,nodesYCoordinates:i,nop:r,boundaryElements:s,totalElements:a,meshDimension:l,elementOrder:c}=e,{A:d,B:u,C:m,D:f}=n,h=Tt(e),{residualVector:p,jacobianMatrix:g,localToGlobalMap:b,basisFunctions:y,gaussPoints:v,gaussWeights:E,nodesPerElement:C}=h;if("1D"===l)for(let e=0;e<a;e++){for(let t=0;t<C;t++)b[t]=Math.abs(r[e][t])-1;for(let e=0;e<v.length;e++){const{basisFunction:t,basisFunctionDerivKsi:n}=y.getBasisFunctions(v[e]),{detJacobian:i,basisFunctionDerivX:r}=Rt({basisFunction:t,basisFunctionDerivKsi:n,nodesXCoordinates:o,localToGlobalMap:b,nodesPerElement:C});let s=0;for(let e=0;e<C;e++)s+=o[b[e]]*t[e];const a=d(s),l=u(s),c=m(s),h=f(s);for(let n=0;n<C;n++){const o=b[n];p[o]-=E[e]*i*h*t[n];for(let s=0;s<C;s++){const d=b[s];g[o][d]+=E[e]*i*a*r[n]*r[s],g[o][d]-=E[e]*i*l*r[s]*t[n],g[o][d]-=E[e]*i*c*t[n]*t[s]}}}}else"2D"===l&<("2D general form PDE is not yet supported in assembleGeneralFormPDEMat.");return new Kt(t,s,r,l,c).imposeDirichletBoundaryConditions(p,g),at("General form PDE matrix assembly completed"),{jacobianMatrix:g,residualVector:p}}(r,this.boundaryConditions,this.coefficientFunctions));o=Nt(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector}else if("creepingFlowScript"===this.solverConfig){const i=function(e,t){at("Starting creeping flow matrix assembly...");const{nodesXCoordinates:n,nodesYCoordinates:o,nop:i,boundaryElements:r,totalElements:s,totalNodes:a,meshDimension:l,elementOrder:c}=e;"2D"!==l&<("Creeping flow solver requires a 2D mesh"),"quadratic"!==c&<("Creeping flow solver requires quadratic elements for Taylor-Hood (Q2-Q1) formulation");const d=a,u=[0,2,6,8],m=new Map,f=[];let h=0;for(let e=0;e<s;e++)for(let t=0;t<u.length;t++){const n=i[e][u[t]]-1;m.has(n)||(m.set(n,h),f.push(n),h++)}const p=h,g=2*d+p;st(`Creeping flow DOFs: ${d} velocity nodes (Q2), ${p} pressure nodes (Q1), ${g} total DOFs`);let b=[],y=[];for(let e=0;e<g;e++){b[e]=0,y.push([]);for(let t=0;t<g;t++)y[e][t]=0}const v=new Pt({meshDimension:"2D",elementOrder:"quadratic"}),E=new Pt({meshDimension:"2D",elementOrder:"linear"});let C=new It({meshDimension:"2D",elementOrder:"quadratic"}).getGaussPointsAndWeights(),D=C.gaussPoints,w=C.gaussWeights;for(let e=0;e<s;e++){let t=[];for(let n=0;n<9;n++)t[n]=i[e][n]-1;let r=[];for(let t=0;t<4;t++){const n=i[e][u[t]]-1;r[t]=m.get(n)}for(let e=0;e<D.length;e++)for(let i=0;i<D.length;i++){const s=v.getBasisFunctions(D[e],D[i]),a=E.getBasisFunctions(D[e],D[i]),l=Bt({basisFunction:s.basisFunction,basisFunctionDerivKsi:s.basisFunctionDerivKsi,basisFunctionDerivEta:s.basisFunctionDerivEta,nodesXCoordinates:n,nodesYCoordinates:o,localToGlobalMap:t,nodesPerElement:9}),{detJacobian:c,basisFunctionDerivX:u,basisFunctionDerivY:m}=l,f=w[e]*w[i]*c;for(let e=0;e<9;e++){let n=t[e],o=n,i=d+n;for(let n=0;n<9;n++){let r=t[n],s=r,a=d+r,l=1*-f*(u[e]*u[n]+m[e]*m[n]);y[o][s]+=l,y[i][a]+=l}for(let t=0;t<4;t++){let n=2*d+r[t],s=f*a.basisFunction[t]*u[e],l=f*a.basisFunction[t]*m[e];y[o][n]+=s,y[i][n]+=l,y[n][o]+=-s,y[n][i]+=-l}}}}return new sn(t,r,i,l,c,d,p,m).imposeDirichletBoundaryConditions(b,y),at("Creeping flow matrix assembly completed"),{jacobianMatrix:y,residualVector:b,totalNodesVelocity:d,totalNodesPressure:p,pressureNodeIndices:f}}(r,this.boundaryConditions);t=i.jacobianMatrix,n=i.residualVector;o=Nt(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector,this._creepingFlowMetadata={totalNodesVelocity:i.totalNodesVelocity,totalNodesPressure:i.totalNodesPressure,pressureNodeIndices:i.pressureNodeIndices}}else if("eulerBernoulliBeamScript"===this.solverConfig){const i=function(e,t,n){at("Starting Euler-Bernoulli beam matrix assembly...");const{nodesXCoordinates:o,nop:i,totalElements:r,totalNodesX:s,meshDimension:a,elementOrder:l}=e;"1D"!==a&<("Euler-Bernoulli beam solver requires a 1D mesh"),"linear"!==l&<("Euler-Bernoulli beam solver requires 'linear' (2-node) elements for the beam geometry; the cubic Hermite field interpolation for w(x) is applied internally regardless of this setting");const{EI:c,c0:d=()=>0,q:u=()=>0}=n,m=2*s;let f=new Array(m).fill(0),h=[];for(let e=0;e<m;e++)h.push(new Array(m).fill(0));const p=new Pt({meshDimension:"1D",elementOrder:"hermiteCubic"}),g=new It({meshDimension:"1D",elementOrder:"hermiteCubic"}),{gaussPoints:b,gaussWeights:y}=g.getGaussPointsAndWeights();for(let e=0;e<r;e++){const t=i[e][0]-1,n=i[e][1]-1,r=o[t],s=o[n]-r,a=[2*t,2*t+1,2*n,2*n+1];for(let e=0;e<b.length;e++){const t=b[e],{basisFunction:n,basisFunctionDerivKsi2:o}=p.getBasisFunctions(t,null,s),i=s,l=o.map((e=>e/i**2)),m=r+s*t,g=c(m),v=d(m),E=u(m),C=y[e]*i;for(let e=0;e<4;e++){const t=a[e];f[t]+=C*E*n[e];for(let o=0;o<4;o++){const i=a[o];h[t][i]+=C*(g*l[e]*l[o]+v*n[e]*n[o])}}}}const v=new an(t,s,2);return v.imposeNaturalAndSpringBoundaryConditions(f,h),v.imposeEssentialBoundaryConditions(f,h),at("Euler-Bernoulli beam matrix assembly completed"),{jacobianMatrix:h,residualVector:f,dofsPerNode:2,totalDOFs:m}}(r,this.boundaryConditions,this.coefficientFunctions);t=i.jacobianMatrix,n=i.residualVector;o=Nt(this.solverMethod,t,n,{maxIterations:e.maxIterations??this.maxIterations,tolerance:e.tolerance??this.tolerance}).solutionVector,this._eulerBernoulliBeamMetadata={dofsPerNode:i.dofsPerNode,totalNodesX:r.totalNodesX}}return console.timeEnd("totalSolvingTime"),at("Solving process completed"),{solutionVector:o,nodesCoordinates:s}}async solveAsync(e,t={}){this.solverConfig&&this.meshConfig&&this.boundaryConditions||lt("Solver config, mesh config, and boundary conditions must be set before solving.");let n=[],o=[],i=[];at("Preparing mesh...");const r=Xt(this.meshConfig);at("Mesh preparation completed");const s={nodesXCoordinates:r.nodesXCoordinates,nodesYCoordinates:r.nodesYCoordinates};if(at("Beginning solving process..."),console.time("totalSolvingTime"),at(`Using solver: ${this.solverConfig}`),"heatConductionScript"===this.solverConfig&&(({jacobianMatrix:n,residualVector:o}=_t(r,this.boundaryConditions)),"jacobi-gpu"===this.solverMethod)){const{solutionVector:r}=await kt("jacobi-gpu",n,o,{computeEngine:e,maxIterations:t.maxIterations??this.maxIterations,tolerance:t.tolerance??this.tolerance});i=r}return console.timeEnd("totalSolvingTime"),at("Solving process completed"),{solutionVector:i,nodesCoordinates:s}}}const cn=async e=>{let t={nodesXCoordinates:[],nodesYCoordinates:[],nodalNumbering:{quadElements:[],triangleElements:[]},boundaryElements:[],boundaryConditions:[],boundaryNodePairs:{},gmshV:0,ascii:!1,fltBytes:"8",totalNodesX:0,totalNodesY:0,physicalPropMap:[],elementTypes:{}};const n={curves:{}};let o=(await e.text()).split("\n").map((e=>e.trim())).filter((e=>""!==e)),i="",r=0,s=0,a=0,l=0,c={numNodes:0},d=[],u=0,m=0,f=0,h=0,p={numElements:0},g=0,b={},y=null,v=null,E=0,C=0,D=0;for(;r<o.length;){const e=o[r];if("$MeshFormat"===e){i="meshFormat",r++;continue}if("$EndMeshFormat"===e){i="",r++;continue}if("$PhysicalNames"===e){i="physicalNames",r++;continue}if("$EndPhysicalNames"===e){i="",r++;continue}if("$Entities"===e){i="entities",v="counts",r++;continue}if("$EndEntities"===e){i="",y=null,v=null,r++;continue}if("$Nodes"===e){i="nodes",r++;continue}if("$EndNodes"===e){i="",r++;continue}if("$Elements"===e){i="elements",r++;continue}if("$EndElements"===e){i="",r++;continue}const w=e.split(/\s+/);if("meshFormat"===i)t.gmshV=parseFloat(w[0]),t.ascii="0"===w[1],t.fltBytes=w[2];else if("physicalNames"===i){const e=parseInt(w[0],10),n=parseInt(w[1],10);let o=w.slice(2).join(" ").replace(/^"|"$/g,"");t.physicalPropMap.push({tag:n,dimension:e,name:o})}else if("entities"===i)if("counts"===v)y={points:parseInt(w[0],10),curves:parseInt(w[1],10),surfaces:parseInt(w[2],10),volumes:parseInt(w[3],10)},v="points";else if("points"===v)E++,E===y.points&&(v="curves");else if("curves"===v){const e=parseInt(w[0],10),t=parseInt(w[7],10),o=w.slice(8,8+t).map((e=>parseInt(e,10)));n.curves[e]=o,C++,C===y.curves&&(v="surfaces")}else"surfaces"===v&&(D++,D===y.surfaces&&(v="volumes"));else if("nodes"===i){if(0===s)s=parseInt(w[0],10),a=parseInt(w[1],10),t.nodesXCoordinates=new Array(a).fill(0),t.nodesYCoordinates=new Array(a).fill(0);else if(l<s&&0===c.numNodes)c={dim:parseInt(w[0],10),tag:parseInt(w[1],10),parametric:parseInt(w[2],10),numNodes:parseInt(w[3],10)},d=[],u=0,m=0;else if(u<c.numNodes){for(let e of w)if(d.push(parseInt(e,10)),u++,u===c.numNodes)break}else if(m<c.numNodes){const e=d[m]-1;t.nodesXCoordinates[e]=parseFloat(w[0]),t.nodesYCoordinates[e]=parseFloat(w[1]),t.totalNodesX++,t.totalNodesY++,m++,m===c.numNodes&&(l++,c={numNodes:0})}}else if("elements"===i)if(0===f)f=parseInt(w[0],10),parseInt(w[1],10);else if(h<f&&0===p.numElements)p={dim:parseInt(w[0],10),tag:parseInt(w[1],10),elementType:parseInt(w[2],10),numElements:parseInt(w[3],10)},t.elementTypes[p.elementType]=(t.elementTypes[p.elementType]||0)+p.numElements,g=0;else if(g<p.numElements){const e=w.slice(1).map((e=>parseInt(e,10)));let o=p.tag;if(1===p.dim){const e=n.curves[p.tag];e&&e.length>0&&(o=e[0])}1===p.elementType||8===p.elementType?(b[o]||(b[o]=[]),b[o].push(e),t.boundaryNodePairs[o]||(t.boundaryNodePairs[o]=[]),t.boundaryNodePairs[o].push(e)):2===p.elementType?t.nodalNumbering.triangleElements.push(e):3!==p.elementType&&10!==p.elementType||t.nodalNumbering.quadElements.push(e),g++,g===p.numElements&&(h++,p={numElements:0})}r++}return t.physicalPropMap.forEach((e=>{if(1===e.dimension){const n=b[e.tag]||[];n.length>0&&t.boundaryConditions.push({name:e.name,tag:e.tag,nodes:n})}})),st(`Parsed boundary node pairs by physical tag: ${JSON.stringify(t.boundaryNodePairs)}`),t};function dn(e,t,n,o){console.time("plottingTime");const{nodesXCoordinates:i,nodesYCoordinates:r}=t.nodesCoordinates,s=t.solutionVector,a=e.solverConfig,l=e.meshConfig.meshDimension;if(Xt(e.meshConfig),"1D"===l&&"line"===n){let e;e=s.length>0&&Array.isArray(s[0])?s.map((e=>e[0])):s,Array.from(i);let t={x:i,y:e,mode:"lines",type:"scatter",line:{color:"rgb(219, 64, 82)",width:2},name:"Solution"},n=Math.min(window.innerWidth,700),r={title:`line plot - ${a}`,width:Math.min(n,600),height:300,xaxis:{title:"x"},yaxis:{title:"Solution"},margin:{l:50,r:50,t:50,b:50}};Plotly.newPlot(o,[t],r,{responsive:!0}),console.timeEnd("plottingTime")}else if("2D"===l&&"contour"===n){let e;e=Array.isArray(s[0])?s.map((e=>e[0])):s;let t=Math.min(window.innerWidth,700),l=Math.min(...i),c=Math.max(...i),d=Math.min(...r),u=(Math.max(...r)-d)/(c-l),m=Math.min(t,600),f={title:`${n} plot - ${a}`,width:m,height:m*u,xaxis:{title:"x"},yaxis:{title:"y",scaleanchor:"x",scaleratio:1},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"},h={x:i,y:r,z:e,type:"contour",line:{smoothing:.85},contours:{coloring:"heatmap",showlabels:!1},colorbar:{title:"Solution"},name:"Solution Field"};Plotly.newPlot(o,[h],f,{responsive:!0}),console.timeEnd("plottingTime")}}function un(e,t,n,o){console.time("plottingTime");const{nodesXCoordinates:i,nodesYCoordinates:r}=t.nodesCoordinates,s=e.meshConfig.meshDimension,a=Xt(e.meshConfig),l=new Pt({meshDimension:e.meshConfig.meshDimension,elementOrder:e.meshConfig.elementOrder});if("1D"===s&&"line"===n);else if("2D"===s&&"contour"===n){const s=[],c=[],d=Math.max(...i)-Math.min(...i),u=Math.max(...r)-Math.min(...r),m=50,f=Math.round(d*m),h=Math.round(u*m),p=d/(f-1),g=u/(h-1);let b=[];s[0]=Math.min(...i),c[0]=Math.min(...r);for(let e=1;e<h;e++)s[e]=s[0],c[e]=c[0]+e*g;for(let e=1;e<f;e++){const t=e*h;s[t]=s[0]+e*p,c[t]=c[0];for(let e=1;e<h;e++)s[t+e]=s[t],c[t+e]=c[t]+e*g}b=new Array(f*h).fill(null);const y=Wt(a),{nodeNeighbors:v,neighborCount:E}=qt(a);let C=0;for(let n=0;n<f*h;n++){if(!hn(s[n],c[n],y))continue;let o=!1;for(let i=0;i<a.nop[C].length;i++){let r=a.nop[C][i]-1;for(let i=0;i<E[r];i++){let d=v[r][i];const u=mn(e,a,t,d,s[n],c[n],l);if(u.inside){C=d,b[n]=u.value,o=!0;break}}if(o)break}if(!o)for(let i=0;i<a.nop.length;i++){const r=mn(e,a,t,i,s[n],c[n],l);if(r.inside){C=i,b[n]=r.value,o=!0;break}}}let D=Math.min(window.innerWidth,700),w=u/d,M=Math.min(D,600),F=M*w,$={title:`${n} plot (interpolated) - ${e.solverConfig}`,width:M,height:F,xaxis:{title:"x"},yaxis:{title:"y",scaleanchor:"x",scaleratio:1},margin:{l:50,r:50,t:50,b:50},hovermode:"closest"},A={x:s,y:c,z:b,type:"contour",connectgaps:!1,hoverongaps:!1,line:{smoothing:.85},contours:{coloring:"heatmap",showlabels:!1},colorbar:{title:"Solution"},name:"Interpolated Solution Field"};Plotly.newPlot(o,[A],$,{responsive:!0}),console.timeEnd("plottingTime")}}function mn(e,t,n,o,i,r,s){const{nodesXCoordinates:a,nodesYCoordinates:l}=n.nodesCoordinates,c=t.nop[o].length;if(4===c){const c=Yt(i,r,[[a[t.nop[o][0]-1],l[t.nop[o][0]-1]],[a[t.nop[o][1]-1],l[t.nop[o][1]-1]],[a[t.nop[o][2]-1],l[t.nop[o][2]-1]],[a[t.nop[o][3]-1],l[t.nop[o][3]-1]]]);if(c.inside)return{inside:!0,value:fn(e,t,n,o,c.ksi,c.eta,s)}}else if(9===c){const c=Yt(i,r,[[a[t.nop[o][0]-1],l[t.nop[o][0]-1]],[a[t.nop[o][2]-1],l[t.nop[o][2]-1]],[a[t.nop[o][6]-1],l[t.nop[o][6]-1]],[a[t.nop[o][8]-1],l[t.nop[o][8]-1]]]);if(c.inside)return{inside:!0,value:fn(e,t,n,o,c.ksi,c.eta,s)}}return{inside:!1,value:null}}function fn(e,t,n,o,i,r,s){const a=n.solutionVector,l=t.nop[o].length;let c,d=s.getBasisFunctions(i,r).basisFunction;c=Array.isArray(a[0])?a.map((e=>e[0])):a;let u=0;for(let e=0;e<l;e++)u+=c[t.nop[o][e]-1]*d[e];return u}function hn(e,t,n){let o=!1;for(let i=0;i<n.length;i++){const[[r,s],[a,l]]=n[i];s>t!=l>t&&e<(a-r)*(t-s)/(l-s)+r&&(o=!o)}return o}let pn=null;async function gn(){if(pn)return pn;await import("@kitware/vtk.js/Rendering/Profiles/Geometry.js");const[{default:e},{default:t},{default:n},{default:o},{default:i},{default:r},{default:s},{default:a},{default:l},{default:c}]=await Promise.all([import("@kitware/vtk.js/Rendering/Core/Actor.js"),import("@kitware/vtk.js/Rendering/Core/ColorTransferFunction.js"),import("@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps.js"),import("@kitware/vtk.js/Common/Core/DataArray.js"),import("@kitware/vtk.js/Common/DataModel/ImageData.js"),import("@kitware/vtk.js/Filters/General/ImageMarchingSquares.js"),import("@kitware/vtk.js/Rendering/Misc/GenericRenderWindow.js"),import("@kitware/vtk.js/Rendering/Core/Mapper.js"),import("@kitware/vtk.js/Common/DataModel/PolyData.js"),import("@kitware/vtk.js/Rendering/Core/ScalarBarActor.js")]);return pn={vtkActor:e,vtkColorTransferFunction:t,vtkColorMaps:n,vtkDataArray:o,vtkImageData:i,vtkImageMarchingSquares:r,vtkGenericRenderWindow:s,vtkMapper:a,vtkPolyData:l,vtkScalarBarActor:c},pn}const bn=new Map;function yn(e={}){return{presetName:e.presetName??"Cool to Warm",reverse:e.reverse??!1,showScalarBar:e.showScalarBar??!0,scalarBarTitle:e.scalarBarTitle??"Solution"}}function vn(e={}){return{enabled:e.enabled??!0,numberOfContours:e.numberOfContours??12,color:e.color??[.15,.15,.15],lineWidth:e.lineWidth??1}}async function En(e,t,n,o,i={}){console.time("plottingTime");const r=e.meshConfig.meshDimension,s=Xt(e.meshConfig),a=await Dn(e,t,s,{mode:"1D"===r&&"line"===n?"line":"surface"});await Fn(a,o,e.solverConfig,n,i),console.timeEnd("plottingTime")}async function Cn(e,t,n,o,i={}){if(console.time("plottingTime"),"2D"!==e.meshConfig.meshDimension||"contour"!==n){const r=Xt(e.meshConfig),s=await Dn(e,t,r,{mode:"1D"===e.meshConfig.meshDimension&&"line"===n?"line":"surface"});return await Fn(s,o,e.solverConfig,n,i),void console.timeEnd("plottingTime")}const r=Xt(e.meshConfig),s=await async function(e,t,n){const o=await async function(e,t,n){const{nodesXCoordinates:o,nodesYCoordinates:i}=t.nodesCoordinates,r=new Pt({meshDimension:e.meshConfig.meshDimension,elementOrder:e.meshConfig.elementOrder});let s=o[0],a=o[0],l=i[0],c=i[0];for(let e=1;e<o.length;e++){const t=o[e],n=i[e];t<s&&(s=t),t>a&&(a=t),n<l&&(l=n),n>c&&(c=n)}const d=a-s,u=c-l,m=50,f=Math.max(2,Math.round(d*m)),h=Math.max(2,Math.round(u*m)),p=d/(f-1),g=u/(h-1),b=f*h,y=new Float32Array(b),v=new Float32Array(b),E=new Float32Array(b);E.fill(Number.NaN);const C=new Uint8Array(b),D=Wt(n),{nodeNeighbors:w,neighborCount:M}=qt(n);let F=0;for(let o=0;o<f;o++)for(let i=0;i<h;i++){const a=o*h+i,c=s+o*p,d=l+i*g;if(y[a]=c,v[a]=d,!Sn(c,d,D))continue;let u=!1;for(let o=0;o<n.nop[F].length;o++){const i=n.nop[F][o]-1;for(let o=0;o<M[i];o++){const s=w[i][o],l=On(e,n,t,s,c,d,r);if(l.inside){F=s,E[a]=l.value,C[a]=1,u=!0;break}}if(u)break}if(!u)for(let o=0;o<n.nop.length;o++){const i=On(e,n,t,o,c,d,r);if(i.inside){F=o,E[a]=i.value,C[a]=1;break}}}return{visNodesX:f,visNodesY:h,minX:s,minY:l,deltaX:p,deltaY:g,lengthX:d,lengthY:u,visNodeXCoordinates:y,visNodeYCoordinates:v,visSolution:E,insideMask:C}}(e,t,n),{visNodesX:i,visNodesY:r,minX:s,minY:a,deltaX:l,deltaY:c,visNodeXCoordinates:d,visNodeYCoordinates:u,visSolution:m,insideMask:f}=o,h=An(d,u),p=function(e,t,n){const o=[];for(let i=0;i<e-1;i++)for(let e=0;e<t-1;e++){const r=i*t+e,s=(i+1)*t+e,a=(i+1)*t+(e+1),l=i*t+(e+1);n[r]&&n[s]&&n[a]&&n[l]&&o.push(4,r,s,a,l)}return Uint32Array.from(o)}(i,r,f),g=await $n(h,m,p,"surface");return{points:h,scalars:m,cells:p,polyData:g,mode:"surface",metadata:{meshDimension:"2D",numberOfPoints:h.length/3,numberOfCells:kn(p),interpolationGrid:{nx:i,ny:r,origin:[s,a],spacing:[l,c],imageScalars:Pn(m,i,r)}}}}(e,t,r);await Fn(s,o,e.solverConfig,`${n}-interpolated`,i),console.timeEnd("plottingTime")}async function Dn(e,t,n=null,o={}){const i=n??Xt(e.meshConfig),{nodesXCoordinates:r,nodesYCoordinates:s}=t.nodesCoordinates,a=xn(t.solutionVector,r.length),l=An(r,s),c=o.mode??"surface",d="line"===c?function(e){if(e<2)return new Uint32Array(0);const t=new Uint32Array(3*(e-1));let n=0;for(let o=0;o<e-1;o++)t[n++]=2,t[n++]=o,t[n++]=o+1;return t}(r.length):function(e){const t=[];for(let n=0;n<e.length;n++){const o=Nn(e[n]);t.push(o.length,...o)}return Uint32Array.from(t)}(i.nop??[]);return{points:l,scalars:a,cells:d,polyData:await $n(l,a,d,c),mode:c,metadata:{solverConfig:e.solverConfig,meshDimension:e.meshConfig.meshDimension,numberOfPoints:l.length/3,numberOfCells:kn(d)}}}async function wn(e,t,n=null,o={}){return function(e){const{connectivity:t,offsets:n}=function(e){const t=[],n=[];let o=0,i=0;for(;o<e.length;){const r=e[o++];for(let n=0;n<r;n++)t.push(e[o++]);i+=r,n.push(i)}return{connectivity:t,offsets:n}}(e.cells),o=e.points.length/3,i="line"===e.mode,r=i?"Lines":"Polys";return['<?xml version="1.0"?>','<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian">'," <PolyData>",` <Piece NumberOfPoints="${o}" NumberOfVerts="0" NumberOfLines="${i?n.length:0}" NumberOfStrips="0" NumberOfPolys="${i?0:n.length}">`,' <PointData Scalars="solution">',` <DataArray type="Float32" Name="solution" NumberOfComponents="1" format="ascii">${Array.from(e.scalars).join(" ")}</DataArray>`," </PointData>"," <Points>",` <DataArray type="Float32" NumberOfComponents="3" format="ascii">${Array.from(e.points).join(" ")}</DataArray>`," </Points>",` <${r}>`,` <DataArray type="Int32" Name="connectivity" format="ascii">${t.join(" ")}</DataArray>`,` <DataArray type="Int32" Name="offsets" format="ascii">${n.join(" ")}</DataArray>`,` </${r}>`," </Piece>"," </PolyData>","</VTKFile>"].join("\n")}(await Dn(e,t,n,o))}function Mn(e){const{nodesXCoordinates:t,nodesYCoordinates:n}=e.nodesCoordinates,o=xn(e.solutionVector,t.length),i=new Float32Array(3*t.length);for(let e=0;e<t.length;e++){const r=3*e;i[r]=Number(t[e])||0,i[r+1]=Number(n[e])||0,i[r+2]=o[e]}return{features:i,featuresShape:[t.length,3],labels:o,points:An(t,n)}}async function Fn(e,t,n,o,i={}){if("undefined"==typeof document)return void lt("vtk.js visualization requires a browser environment");const{vtkActor:r,vtkColorTransferFunction:s,vtkColorMaps:a,vtkGenericRenderWindow:l,vtkMapper:c,vtkScalarBarActor:d}=await gn(),u=document.getElementById(t);if(!u)return void lt(`Could not find plot container with id: ${t}`);bn.has(t)&&(bn.get(t).delete(),bn.delete(t)),u.innerHTML="",u.style.position="relative",u.style.width=u.style.width||"100%",u.style.height=u.style.height||"420px";const m=l.newInstance({background:[1,1,1]});m.setContainer(u),m.resize();const f=m.getRenderer(),h=m.getRenderWindow(),p=c.newInstance();p.setInputData(e.polyData),p.setScalarModeToUsePointData(),p.setColorModeToMapScalars(),p.setScalarVisibility(!0);const g=function(e){if(!e?.length)return[0,1];let t=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(let o=0;o<e.length;o++){const i=e[o];Number.isFinite(i)&&(i<t&&(t=i),i>n&&(n=i))}return Number.isFinite(t)&&Number.isFinite(n)?t===n?[t-1,n+1]:[t,n]:[0,1]}(e.scalars);p.setScalarRange(g[0],g[1]);const b=i.colorScale??yn({}),y=s.newInstance(),v=function(e,t){if(!t||!e?.RGBPoints?.length)return e;const n=e.RGBPoints,o=n[0],i=n[n.length-4],r=[];for(let e=n.length-4;e>=0;e-=4)r.push(i-(n[e]-o),n[e+1],n[e+2],n[e+3]);return{...e,RGBPoints:r}}(a.getPresetByName(b.presetName)??a.getPresetByName("Cool to Warm"),b.reverse);y.applyColorMap(v),y.setMappingRange(g[0],g[1]),y.updateRange(),p.setLookupTable(y);const E=r.newInstance();if(E.setMapper(p),"line"===e.mode&&E.getProperty().setLineWidth(3),f.addActor(E),b.showScalarBar){const e=d.newInstance({drawNanAnnotation:!1,generateTicks:e=>{const t=e.getLastTickBounds();if(!t||t.length<2)return;const[n,o]=t,i=(o-n)/4,r=Array.from({length:5},((e,t)=>n+t*i));e.setTicks(r),e.setTickStrings(r.map((e=>{const t=Math.abs(e);return 0===t?"0":t>=.01&&t<1e4?parseFloat(e.toPrecision(4)).toString():e.toExponential(2)})))}});e.setTickTextStyle({fontColor:"black"}),e.setAxisTextStyle({fontColor:"black"}),e.setAxisLabel(b.scalarBarTitle),e.setScalarsToColors(y),f.addActor2D(e)}const C=vn(i.contourLines??{enabled:!1});C.enabled&&"line"!==e.mode&&await async function(e,t,n,o){const i=t.metadata?.interpolationGrid;if(!i)return;const{vtkActor:r,vtkDataArray:s,vtkImageData:a,vtkImageMarchingSquares:l,vtkMapper:c}=await gn(),d=a.newInstance();d.setDimensions(i.nx,i.ny,1),d.setOrigin(i.origin[0],i.origin[1],0),d.setSpacing(i.spacing[0],i.spacing[1],1);const u=s.newInstance({name:"solution",numberOfComponents:1,values:i.imageScalars});d.getPointData().setScalars(u);const m=l.newInstance({slicingMode:2,slice:0,mergePoints:!0});m.setInputData(d);const f=Math.max(2,o.numberOfContours),h=n[0],p=n[1],g=(p-h)/(f-1),b=[];for(let e=0;e<f;e++)b.push(h+e*g);m.setContourValues(b),m.update();const y=c.newInstance();y.setInputData(m.getOutputData()),y.setScalarVisibility(!1);const v=r.newInstance();v.setMapper(y),v.getProperty().setColor(...o.color),v.getProperty().setLineWidth(o.lineWidth),e.addActor(v)}(f,e,g,C),f.resetCamera(),h.render(),bn.set(t,m),u.title=`${o} plot - ${n}`}async function $n(e,t,n,o="surface"){const{vtkPolyData:i,vtkDataArray:r}=await gn(),s=i.newInstance();s.getPoints().setData(e,3),n.length>0&&("line"===o?s.getLines().setData(n):s.getPolys().setData(n));const a=r.newInstance({name:"solution",numberOfComponents:1,values:t});return s.getPointData().setScalars(a),s}function An(e,t){const n=new Float32Array(3*e.length);for(let o=0;o<e.length;o++){const i=3*o;n[i]=Number(e[o])||0,n[i+1]=Number(t?.[o])||0,n[i+2]=0}return n}function xn(e,t){const n=new Float32Array(t);for(let o=0;o<t;o++){const t=e?.[o];n[o]=Number(Array.isArray(t)?t[0]:t)||0}return n}function Nn(e){const t=e.map((e=>e-1)),n=t.length;return 2===n||3===n?t:4===n?[t[0],t[2],t[3],t[1]]:6===n?[t[0],t[2],t[5]]:8===n?[t[0],t[4],t[6],t[2]]:9===n?[t[0],t[6],t[8],t[2]]:t.slice(0,Math.min(4,t.length))}function kn(e){let t=0,n=0;for(;n<e.length;)n+=e[n]+1,t++;return t}function Pn(e,t,n){const o=new Float32Array(t*n);for(let i=0;i<n;i++)for(let r=0;r<t;r++)o[r+i*t]=e[r*n+i];return o}function On(e,t,n,o,i,r,s){const{nodesXCoordinates:a,nodesYCoordinates:l}=n.nodesCoordinates,c=t.nop[o].length;if(4===c){const c=Yt(i,r,[[a[t.nop[o][0]-1],l[t.nop[o][0]-1]],[a[t.nop[o][1]-1],l[t.nop[o][1]-1]],[a[t.nop[o][2]-1],l[t.nop[o][2]-1]],[a[t.nop[o][3]-1],l[t.nop[o][3]-1]]]);if(c.inside)return{inside:!0,value:Vn(e,t,n,o,c.ksi,c.eta,s)}}else if(9===c){const c=Yt(i,r,[[a[t.nop[o][0]-1],l[t.nop[o][0]-1]],[a[t.nop[o][2]-1],l[t.nop[o][2]-1]],[a[t.nop[o][6]-1],l[t.nop[o][6]-1]],[a[t.nop[o][8]-1],l[t.nop[o][8]-1]]]);if(c.inside)return{inside:!0,value:Vn(e,t,n,o,c.ksi,c.eta,s)}}return{inside:!1,value:null}}function Vn(e,t,n,o,i,r,s){const a=n.solutionVector,l=t.nop[o].length,c=s.getBasisFunctions(i,r).basisFunction,d=Array.isArray(a[0])?a.map((e=>e[0])):a;let u=0;for(let e=0;e<l;e++)u+=d[t.nop[o][e]-1]*c[e];return u}function Sn(e,t,n){let o=!1;for(let i=0;i<n.length;i++){const[[r,s],[a,l]]=n[i];s>t!=l>t&&e<(a-r)*(t-s)/(l-s)+r&&(o=!o)}return o}class In{constructor(){this.worker=null,this.feaWorker=null,this.isReady=!1,this._initWorker()}async _initWorker(){try{const e=import.meta.url,t=e.includes("/src/workers/")?"../../dist/feascript-worker.esm.js":"./feascript-worker.esm.js",n=`import "${new URL(t,e).href}";`,o=new Blob([n],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(o),{type:"module"}),this.worker.onerror=e=>{console.error("FEAScriptWorker: Worker error:",e)};const i=yt(this.worker);this.feaWorker=await new i,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 setModelConfig(e){return await this._ensureReady(),this.feaWorker.setModelConfig(e)}async setMeshConfig(e){return await this._ensureReady(),this.feaWorker.setMeshConfig(e)}async addBoundaryCondition(e,t){return await this._ensureReady(),this.feaWorker.addBoundaryCondition(e,t)}async setSolverMethod(e){return await this._ensureReady(),this.feaWorker.setSolverMethod(e)}async solve(){await this._ensureReady(),performance.now();const e=await this.feaWorker.solve();return performance.now(),e}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 Xn="0.3.0 (RC)";export{ln as FEAScriptModel,In as FEAScriptWorker,yn as createColorScale,vn as createContourLineOptions,cn as importGmshMesh,rt as logSystem,un as plotInterpolatedSolution,Cn as plotInterpolatedSolutionVtk,dn as plotSolution,En as plotSolutionVtk,Xn as printVersion,Mn as transformSolverOutputToMLBuffers,wn as transformSolverOutputToVTP,Dn as transformSolverOutputToVtkData};
//# sourceMappingURL=feascript.esm.js.map