1+ // ______ ______ _____ _ _ //
2+ // | ____| ____| /\ / ____| (_) | | //
3+ // | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+ // | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+ // | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+ // |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+ // | | | | //
8+ // |_| | |_ //
9+ // Website: https://feascript.com/ \__| //
10+
111import * as Comlink from "https://unpkg.com/comlink/dist/esm/comlink.mjs" ;
212import { basicLog } from "./utilities/utilitiesScript.js" ;
313
414export class FEAWorkerScript {
15+ /**
16+ * Constructor to initialize the FEAWorkerScript class
17+ * Sets up the worker and initializes the FEAWorkerWrapper.
18+ */
519 constructor ( ) {
620 this . worker = null ;
721 this . feaWorker = null ;
@@ -10,6 +24,11 @@ export class FEAWorkerScript {
1024 this . _initWorker ( ) ;
1125 }
1226
27+ /**
28+ * Initializes the web worker and wraps it using Comlink.
29+ * @private
30+ * @throws Will throw an error if the worker fails to initialize.
31+ */
1332 async _initWorker ( ) {
1433 try {
1534 this . worker = new Worker (
@@ -33,6 +52,12 @@ export class FEAWorkerScript {
3352 }
3453 }
3554
55+ /**
56+ * Ensures that the worker is ready before performing any operations.
57+ * @private
58+ * @returns {Promise<void> } Resolves when the worker is ready.
59+ * @throws Will throw an error if the worker is not ready within the timeout period.
60+ */
3661 async _ensureReady ( ) {
3762 if ( this . isReady ) return Promise . resolve ( ) ;
3863
@@ -54,18 +79,34 @@ export class FEAWorkerScript {
5479 } ) ;
5580 }
5681
82+ /**
83+ * Sets the solver configuration in the worker.
84+ * @param {string } solverConfig - The solver configuration to set.
85+ * @returns {Promise<boolean> } Resolves when the configuration is set.
86+ */
5787 async setSolverConfig ( solverConfig ) {
5888 await this . _ensureReady ( ) ;
5989 basicLog ( `FEAWorkerScript: Setting solver config to: ${ solverConfig } ` ) ;
6090 return this . feaWorker . setSolverConfig ( solverConfig ) ;
6191 }
6292
93+ /**
94+ * Sets the mesh configuration in the worker.
95+ * @param {object } meshConfig - The mesh configuration to set.
96+ * @returns {Promise<boolean> } Resolves when the configuration is set.
97+ */
6398 async setMeshConfig ( meshConfig ) {
6499 await this . _ensureReady ( ) ;
65100 basicLog ( `FEAWorkerScript: Setting mesh config` ) ;
66101 return this . feaWorker . setMeshConfig ( meshConfig ) ;
67102 }
68103
104+ /**
105+ * Adds a boundary condition to the worker.
106+ * @param {string } boundaryKey - The key identifying the boundary.
107+ * @param {array } condition - The boundary condition to add.
108+ * @returns {Promise<boolean> } Resolves when the boundary condition is added.
109+ */
69110 async addBoundaryCondition ( boundaryKey , condition ) {
70111 await this . _ensureReady ( ) ;
71112 basicLog (
@@ -74,12 +115,21 @@ export class FEAWorkerScript {
74115 return this . feaWorker . addBoundaryCondition ( boundaryKey , condition ) ;
75116 }
76117
118+ /**
119+ * Sets the solver method in the worker.
120+ * @param {string } solverMethod - The solver method to set.
121+ * @returns {Promise<boolean> } Resolves when the solver method is set.
122+ */
77123 async setSolverMethod ( solverMethod ) {
78124 await this . _ensureReady ( ) ;
79125 basicLog ( `FEAWorkerScript: Setting solver method to: ${ solverMethod } ` ) ;
80126 return this . feaWorker . setSolverMethod ( solverMethod ) ;
81127 }
82128
129+ /**
130+ * Requests the worker to solve the problem.
131+ * @returns {Promise<object> } Resolves with the solution result.
132+ */
83133 async solve ( ) {
84134 await this . _ensureReady ( ) ;
85135 basicLog ( "FEAWorkerScript: Requesting solution from worker..." ) ;
@@ -97,16 +147,27 @@ export class FEAWorkerScript {
97147 return result ;
98148 }
99149
150+ /**
151+ * Retrieves model information from the worker.
152+ * @returns {Promise<object> } Resolves with the model information.
153+ */
100154 async getModelInfo ( ) {
101155 await this . _ensureReady ( ) ;
102156 return this . feaWorker . getModelInfo ( ) ;
103157 }
104158
159+ /**
160+ * Sends a ping request to the worker to check its availability.
161+ * @returns {Promise<boolean> } Resolves if the worker responds.
162+ */
105163 async ping ( ) {
106164 await this . _ensureReady ( ) ;
107165 return this . feaWorker . ping ( ) ;
108166 }
109167
168+ /**
169+ * Terminates the worker and cleans up resources.
170+ */
110171 terminate ( ) {
111172 if ( this . worker ) {
112173 this . worker . terminate ( ) ;
0 commit comments