handy-diffusion 1.0.7 → 1.0.9
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 +1 -1
- package/bessel.js +52 -0
- package/index.d.ts +0 -2
- package/package.json +5 -2
package/ADI.js
CHANGED
|
@@ -45,7 +45,7 @@ export const setADIProperties = (
|
|
|
45
45
|
|
|
46
46
|
export const updateSinksAndSources = (sinks, sources) => {
|
|
47
47
|
for (let i = 0; i < WIDTH * HEIGHT; i++) {
|
|
48
|
-
gamma[i] = (sinks[i] * halfDeltaT) /
|
|
48
|
+
gamma[i] = (sinks[i] * halfDeltaT) / 2;
|
|
49
49
|
scaledSources[i] = sources[i] * halfDeltaT;
|
|
50
50
|
}
|
|
51
51
|
}
|
package/bessel.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import BESSEL from 'bessel'
|
|
2
|
+
|
|
3
|
+
export const BesselSolution = (
|
|
4
|
+
concentrationData,
|
|
5
|
+
width,
|
|
6
|
+
height,
|
|
7
|
+
sources,
|
|
8
|
+
decayRate,
|
|
9
|
+
) => {
|
|
10
|
+
if (width*height !== concentrationData.length) {
|
|
11
|
+
throw new Error("Width and height do not match the size of concentration data");
|
|
12
|
+
}
|
|
13
|
+
if (width*height !== sources.length) {
|
|
14
|
+
throw new Error("Width and height do not match the size of sources data");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const result = new Float64Array(concentrationData.length);
|
|
18
|
+
const sourcePositions = [];
|
|
19
|
+
// first get source positions
|
|
20
|
+
for (let y = 0; y < height; y++) {
|
|
21
|
+
for (let x = 0; x < width; x++) {
|
|
22
|
+
const index = y * width + x;
|
|
23
|
+
if (sources[index] !== 0) {
|
|
24
|
+
sourcePositions.push({ x, y, strength: sources[index] });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// now calculate the contribution from each source using the Greens function for the screened Poisson equation, which involves the modified Bessel function of the second kind
|
|
30
|
+
for (let y = 0; y < height; y++) {
|
|
31
|
+
for (let x = 0; x < width; x++) {
|
|
32
|
+
const index = y * width + x;
|
|
33
|
+
let value = 0;
|
|
34
|
+
for (const source of sourcePositions) {
|
|
35
|
+
const dx = x - source.x;
|
|
36
|
+
const dy = y - source.y;
|
|
37
|
+
const r = Math.sqrt(dx * dx + dy * dy);
|
|
38
|
+
if (r === 0) {
|
|
39
|
+
value += source.strength; // handle singularity at r=0
|
|
40
|
+
} else {
|
|
41
|
+
value += source.strength * BESSEL.besselk( Math.sqrt(decayRate) * r, 0) / (2 * Math.PI);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
result[index] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
package/index.d.ts
CHANGED
|
@@ -21,13 +21,11 @@ export function setADIProperties(
|
|
|
21
21
|
/**
|
|
22
22
|
* Solve 2D diffusion equation using ADI method
|
|
23
23
|
* @param concentrationData - Concentration array (width * height)
|
|
24
|
-
* @param sources - Source terms array
|
|
25
24
|
* @param totalNumberOfIterations - Number of time steps
|
|
26
25
|
* @param allowNegativeValues - Whether to allow negative concentrations (default: false)
|
|
27
26
|
*/
|
|
28
27
|
export function ADI(
|
|
29
28
|
concentrationData: Float64Array | number[],
|
|
30
|
-
sources: Float64Array | number[],
|
|
31
29
|
totalNumberOfIterations: number,
|
|
32
30
|
allowNegativeValues?: boolean
|
|
33
31
|
): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handy-diffusion",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "algorithms to simulate diffusion",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -21,5 +21,8 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/CritalMediumBlue/diffusionForBacteria/issues"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://github.com/CritalMediumBlue/diffusionForBacteria#readme"
|
|
24
|
+
"homepage": "https://github.com/CritalMediumBlue/diffusionForBacteria#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"bessel": "^1.0.2"
|
|
27
|
+
}
|
|
25
28
|
}
|