handy-diffusion 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ADI.js CHANGED
@@ -8,7 +8,8 @@ let modifiedUpperDiagonal2, modifiedRightHandSide2, solution2;
8
8
  let intermediateConcentration;
9
9
  let a1, b1, c1, d1;
10
10
  let a2, b2, c2, d2;
11
- let alpha, halfDeltaT, oneMinus2AlphaMinusGamma, scaledSources;
11
+ let alpha, halfDeltaT, scaledSources;
12
+ let gamma;
12
13
 
13
14
  export const setADIProperties = (
14
15
  width,
@@ -16,7 +17,7 @@ export const setADIProperties = (
16
17
  diffusionCoefficient,
17
18
  deltaX,
18
19
  deltaT,
19
- decayRate = 0
20
+ decayRates = 0
20
21
  ) => {
21
22
  WIDTH = width;
22
23
  HEIGHT = height;
@@ -38,11 +39,39 @@ export const setADIProperties = (
38
39
  d2,
39
40
  alpha,
40
41
  halfDeltaT,
41
- oneMinus2AlphaMinusGamma,
42
42
  scaledSources,
43
- } = initADIArrays(WIDTH, HEIGHT, diffusionCoefficient, deltaX, deltaT, decayRate));
43
+ gamma,
44
+ } = initADIArrays(WIDTH, HEIGHT, diffusionCoefficient, deltaX, deltaT));
44
45
  };
45
46
 
47
+ export const updateSinksAndSources = (sinks, sources) => {
48
+ for (let i = 0; i < WIDTH * HEIGHT; i++) {
49
+ gamma[i] = (sinks[i] * halfDeltaT) / 4;
50
+ scaledSources[i] = sources[i] * halfDeltaT;
51
+ }
52
+ }
53
+ const updateMainDiagonalXstep = (yCoord) => {
54
+ //update b1
55
+ for (let i = 0; i < WIDTH; i++) {
56
+ const idx = yCoord * WIDTH + i;
57
+ b1[i] = 1 + 2 * alpha + gamma[idx];
58
+ }
59
+ //boundary conditions
60
+ b1[0] = 1 + alpha + gamma[yCoord * WIDTH + 0];
61
+ b1[WIDTH - 1] = 1 + alpha + gamma[yCoord * WIDTH + (WIDTH - 1)];
62
+ }
63
+
64
+ const updateMainDiagonalYstep = (xCoord) => {
65
+ //update b2
66
+ for (let j = 0; j < HEIGHT; j++) {
67
+ const idx = j * WIDTH + xCoord;
68
+ b2[j] = 1 + 2 * alpha + gamma[idx];
69
+ }
70
+ //boundary conditions
71
+ b2[0] = 1 + alpha + gamma[0 * WIDTH + xCoord];
72
+ b2[HEIGHT - 1] = 1 + alpha + gamma[(HEIGHT - 1) * WIDTH + xCoord];
73
+ }
74
+
46
75
  export const ADI = (
47
76
  concentrationData,
48
77
  sources,
@@ -72,10 +101,11 @@ export const ADI = (
72
101
 
73
102
  d1[i] =
74
103
  alpha * bottom +
75
- oneMinus2AlphaMinusGamma * center +
104
+ (1 - 2 * alpha - gamma[idx]) * center +
76
105
  alpha * top +
77
106
  scaledSources[idx];
78
107
  }
108
+ updateMainDiagonalXstep(j);
79
109
 
80
110
  thomasAlgorithm(
81
111
  a1,
@@ -104,7 +134,7 @@ export const ADI = (
104
134
 
105
135
  d1[i] =
106
136
  alpha * bottom +
107
- oneMinus2AlphaMinusGamma * center +
137
+ (1 - 2 * alpha - gamma[idx]) * center +
108
138
  alpha * top +
109
139
  scaledSources[idx];
110
140
  }
@@ -133,7 +163,7 @@ export const ADI = (
133
163
 
134
164
  d1[i] =
135
165
  alpha * bottom +
136
- oneMinus2AlphaMinusGamma * center +
166
+ (1 - 2 * alpha - gamma[idx]) * center +
137
167
  alpha * top +
138
168
  scaledSources[idx];
139
169
  }
@@ -165,11 +195,11 @@ export const ADI = (
165
195
 
166
196
  d2[j] =
167
197
  alpha * left +
168
- oneMinus2AlphaMinusGamma * center +
198
+ (1 - 2 * alpha - gamma[idx]) * center +
169
199
  alpha * right +
170
200
  scaledSources[idx];
171
201
  }
172
-
202
+ updateMainDiagonalYstep(i);
173
203
  thomasAlgorithm(
174
204
  a2,
175
205
  b2,
@@ -201,7 +231,7 @@ export const ADI = (
201
231
 
202
232
  d2[j] =
203
233
  alpha * left +
204
- oneMinus2AlphaMinusGamma * center +
234
+ (1 - 2 * alpha - gamma[idx]) * center +
205
235
  alpha * right +
206
236
  scaledSources[idx];
207
237
  }
@@ -234,7 +264,7 @@ export const ADI = (
234
264
 
235
265
  d2[j] =
236
266
  alpha * left +
237
- oneMinus2AlphaMinusGamma * center +
267
+ (1 - 2 * alpha - gamma[idx]) * center +
238
268
  alpha * right +
239
269
  scaledSources[idx];
240
270
  }
package/index.d.ts CHANGED
@@ -100,4 +100,19 @@ export function efectiveInfluence(
100
100
  sources: Float64Array | number[],
101
101
  lambda: number,
102
102
  scale: number
103
- ): Float64Array;
103
+ ): Float64Array;
104
+
105
+ /**
106
+ * Solve tridiagonal system using Thomas algorithm
107
+ * @param a - Sub-diagonal coefficients
108
+ * @param b - Main diagonal coefficients
109
+ * @param c - Super-diagonal coefficients
110
+ * @param d - Right-hand side values
111
+ * @returns Solution array
112
+ */
113
+ export function thomasAlgorithm(
114
+ a: Float64Array | number[],
115
+ b: Float64Array | number[],
116
+ c: Float64Array | number[],
117
+ d: Float64Array | number[]
118
+ ): Float64Array;
package/index.js CHANGED
@@ -8,4 +8,7 @@ export { CrankNicolson, setCNProperties } from './CrankNicolson.js';
8
8
  export { analyticSteadyState } from './analyticSolution.js';
9
9
 
10
10
  // Import and re-export effective influence
11
- export { efectiveInfluence } from './effective.js';
11
+ export { efectiveInfluence } from './effective.js';
12
+
13
+ // Import and re-export thomas algorithm
14
+ export { thomasAlgorithm } from './thomasAlgorithm.js';
package/initArrays.js CHANGED
@@ -12,7 +12,7 @@ const generateDiagonals = (length, alpha, gamma) => {
12
12
  return { lowerDiagonal, mainDiagonal, upperDiagonal, rightHandSide };
13
13
  };
14
14
 
15
- export const initADIArrays = (WIDTH, HEIGHT, DIFFUSION_RATE, deltaX, deltaT, decayRate) => {
15
+ export const initADIArrays = (WIDTH, HEIGHT, DIFFUSION_RATE, deltaX, deltaT) => {
16
16
  const modifiedUpperDiagonal1 = new Float64Array(WIDTH);
17
17
  const modifiedRightHandSide1 = new Float64Array(WIDTH);
18
18
  const solution1 = new Float64Array(WIDTH);
@@ -21,23 +21,23 @@ export const initADIArrays = (WIDTH, HEIGHT, DIFFUSION_RATE, deltaX, deltaT, dec
21
21
  const solution2 = new Float64Array(HEIGHT);
22
22
  const intermediateConcentration = new Float64Array(WIDTH * HEIGHT);
23
23
  const scaledSources = new Float64Array(WIDTH * HEIGHT);
24
+ const gamma = new Float64Array(WIDTH * HEIGHT).fill(0);
24
25
 
25
26
  const alpha = (DIFFUSION_RATE * deltaT) / (2 * deltaX * deltaX);
26
- const gamma = (decayRate * deltaT) / 4;
27
+ const gammaPoint = 0;
27
28
  const {
28
29
  lowerDiagonal: a1,
29
30
  mainDiagonal: b1,
30
31
  upperDiagonal: c1,
31
32
  rightHandSide: d1,
32
- } = generateDiagonals(WIDTH, alpha, gamma);
33
+ } = generateDiagonals(WIDTH, alpha, gammaPoint);
33
34
  const {
34
35
  lowerDiagonal: a2,
35
36
  mainDiagonal: b2,
36
37
  upperDiagonal: c2,
37
38
  rightHandSide: d2,
38
- } = generateDiagonals(HEIGHT, alpha, gamma);
39
+ } = generateDiagonals(HEIGHT, alpha, gammaPoint);
39
40
  const halfDeltaT = deltaT / 2;
40
- const oneMinus2AlphaMinusGamma = 1 - 2 * alpha - gamma;
41
41
  return {
42
42
  modifiedUpperDiagonal1,
43
43
  modifiedRightHandSide1,
@@ -56,8 +56,8 @@ export const initADIArrays = (WIDTH, HEIGHT, DIFFUSION_RATE, deltaX, deltaT, dec
56
56
  d2,
57
57
  alpha,
58
58
  halfDeltaT,
59
- oneMinus2AlphaMinusGamma,
60
59
  scaledSources,
61
- deltaT,
60
+ gamma,
62
61
  };
63
62
  };
63
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handy-diffusion",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "algorithms to simulate diffusion",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",