@galihru/mnp-mie 0.1.0
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/README.md +31 -0
- package/package.json +27 -0
- package/src/complex.js +35 -0
- package/src/index.js +2 -0
- package/src/rayleigh.js +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @galihru/mnp-mie
|
|
2
|
+
|
|
3
|
+
Rayleigh-limit scattering formulas for small spherical particles.
|
|
4
|
+
|
|
5
|
+
Implemented formulations:
|
|
6
|
+
|
|
7
|
+
$$
|
|
8
|
+
\alpha = 4\pi a^3\frac{\varepsilon_p-\varepsilon_m}{\varepsilon_p+2\varepsilon_m}
|
|
9
|
+
$$
|
|
10
|
+
|
|
11
|
+
$$
|
|
12
|
+
C_{\mathrm{ext}} = k\,\mathrm{Im}(\alpha),\quad
|
|
13
|
+
C_{\mathrm{sca}} = \frac{|k|^4}{6\pi}|\alpha|^2,\quad
|
|
14
|
+
C_{\mathrm{abs}} = C_{\mathrm{ext}}-C_{\mathrm{sca}}
|
|
15
|
+
$$
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @galihru/mnp-mie
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { complex, rayleighCrossSections } from "@galihru/mnp-mie";
|
|
27
|
+
|
|
28
|
+
const epsParticle = complex(-5.2, 2.1);
|
|
29
|
+
const epsMedium = complex(1.77, 0.0);
|
|
30
|
+
console.log(rayleighCrossSections(548.1, 50, epsParticle, epsMedium));
|
|
31
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galihru/mnp-mie",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rayleigh-limit scattering formulations for spherical particles.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"author": "GALIH RIDHO UTOMO <g4lihru@students.unnes.ac.id>",
|
|
15
|
+
"license": "GPL-2.0-only",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/galihru/mnpbem.git"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"registry": "https://registry.npmjs.org/",
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --test"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/complex.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function complex(re = 0, im = 0) {
|
|
2
|
+
return { re: Number(re), im: Number(im) };
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function add(a, b) {
|
|
6
|
+
return complex(a.re + b.re, a.im + b.im);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function sub(a, b) {
|
|
10
|
+
return complex(a.re - b.re, a.im - b.im);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function mul(a, b) {
|
|
14
|
+
return complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function div(a, b) {
|
|
18
|
+
const denom = b.re * b.re + b.im * b.im;
|
|
19
|
+
if (denom === 0) {
|
|
20
|
+
throw new Error("Division by zero complex number");
|
|
21
|
+
}
|
|
22
|
+
return complex((a.re * b.re + a.im * b.im) / denom, (a.im * b.re - a.re * b.im) / denom);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function abs(z) {
|
|
26
|
+
return Math.hypot(z.re, z.im);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function imag(z) {
|
|
30
|
+
return z.im;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function fromReal(x) {
|
|
34
|
+
return complex(x, 0);
|
|
35
|
+
}
|
package/src/index.js
ADDED
package/src/rayleigh.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { abs, add, complex, div, fromReal, imag, mul, sub } from "./complex.js";
|
|
2
|
+
|
|
3
|
+
function mapInput(values, fn) {
|
|
4
|
+
if (Array.isArray(values)) {
|
|
5
|
+
return values.map(fn);
|
|
6
|
+
}
|
|
7
|
+
return fn(values);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function rayleighPolarizability(radiusNm, epsParticle, epsMedium) {
|
|
11
|
+
const a = Number(radiusNm);
|
|
12
|
+
const top = sub(epsParticle, epsMedium);
|
|
13
|
+
const bottom = add(epsParticle, mul(fromReal(2), epsMedium));
|
|
14
|
+
return mul(fromReal(4 * Math.PI * a ** 3), div(top, bottom));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function rayleighCrossSections(wavelengthNm, radiusNm, epsParticle, epsMedium) {
|
|
18
|
+
const solveOne = (wl, ep, em) => {
|
|
19
|
+
const kFactor = (2 * Math.PI * Math.sqrt(em.re)) / Number(wl);
|
|
20
|
+
const k = fromReal(kFactor);
|
|
21
|
+
const alpha = rayleighPolarizability(radiusNm, ep, em);
|
|
22
|
+
const cExt = k.re * imag(alpha);
|
|
23
|
+
const cSca = (Math.abs(k.re) ** 4 * abs(alpha) ** 2) / (6 * Math.PI);
|
|
24
|
+
const cAbs = cExt - cSca;
|
|
25
|
+
return { cExt, cSca, cAbs };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (Array.isArray(wavelengthNm)) {
|
|
29
|
+
return wavelengthNm.map((wl, i) => solveOne(wl, epsParticle[i], epsMedium[i]));
|
|
30
|
+
}
|
|
31
|
+
return solveOne(wavelengthNm, epsParticle, epsMedium);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { complex };
|