diff --git a/README.md b/README.md index c370e9f..314155f 100644 Binary files a/README.md and b/README.md differ diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..a8a79f2 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,2 @@ +declare const addon: any; +export default addon; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..a16a68c --- /dev/null +++ b/dist/index.js @@ -0,0 +1,9 @@ +"use strict"; +// var addon = require("./build/Release/napi-addon-fdtd.node"); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var bindings_1 = __importDefault(require("bindings")); +var addon = (0, bindings_1.default)('napi-addon-fdtd'); +exports.default = addon; diff --git a/dist/test-addon.d.ts b/dist/test-addon.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/test-addon.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/test-addon.js b/dist/test-addon.js new file mode 100644 index 0000000..f23e1ed --- /dev/null +++ b/dist/test-addon.js @@ -0,0 +1,56 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var fs_1 = __importDefault(require("fs")); +var path_1 = __importDefault(require("path")); +var index_1 = __importDefault(require("./index")); +var test1D = function () { + var condition = [1, 10, 1]; + var eps = [1, 1.2]; + var sigma = [0, 0.04]; + var srcPosition = [0.4, 0.8]; + var data = index_1.default.getData2D(condition, true, eps, 2, srcPosition, sigma); + for (var j = 0; j < 50; ++j) { + data = index_1.default.getData2D(condition, false, eps, 2, srcPosition, sigma); + } + fs_1.default.writeFileSync(path_1.default.resolve(__dirname, "tmp.txt"), JSON.stringify(data.dataHy), + // @ts-ignore + function (err) { + if (err) { + return console.log(err); + } + console.log("The file was saved!"); + }); // Orfs.writeFileSync('/tmp/test-sync', 'Hey there!'); +}; +var test2D = function () { + var epsSize = 40; + var eps = Array(epsSize * 2).fill(0).map(function (_) { return Math.random() * 10; }); + var condition = [1, 10]; + var reload = true; + var data = index_1.default.getData3D(condition, reload, [4, 5, 6, 7], 2, 0); + reload = false; + for (var j = 0; j < 150; ++j) { + //eps, epsSize + data = index_1.default.getData3D(condition, reload, [4, 5, 6, 7], 2, 0); + } + fs_1.default.writeFileSync(path_1.default.resolve(__dirname, "tmp.txt"), JSON.stringify(data.dataY), + // @ts-ignore + function (err) { + if (err) { + return console.log(err); + } + console.log("The file was saved!"); + }); // Orfs.writeFileSync('/tmp/test-sync', 'Hey there!'); +}; +function testMemoryUsage() { + // const arr = [1, 2, 3, 4, 5, 6, 9, 7, 8, 9, 10]; + // const arr = Array(1e7).fill(1e3); + // arr.reverse(); + var used = process.memoryUsage().heapUsed / 1024 / 1024; + console.log("The script uses approximately ".concat(Math.round(used * 100) / 100, " MB")); +} +test1D(); +// test2D(); +// testMemoryUsage(); diff --git a/dist/tmp.txt b/dist/tmp.txt new file mode 100644 index 0000000..fcf0495 --- /dev/null +++ b/dist/tmp.txt @@ -0,0 +1 @@ +[2.220446047393039e-23,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,4.440892098500626e-24,1e-8,0.0012325076431646516,0.0010463784384080524,0.0007875661891052479,0.0004943708066556822,0.0001997006066360833,-0.00006542641099382795,-0.00028108790805666476,-0.00043372038148587594,-0.0005172913891631924,-0.0005386023777307399,-0.0005007158868566528,-0.00042218337821043944,-0.00031618521306208953,-0.00019388368414890262,-0.0000776739820877198,0.000026567614627989825,0.00011465436537071313,0.00017161922112388453,0.00019884538936437853,0.0002083153189791913,0.00019812992491725537,0.0001626161040688944,0.00011133681664271628,0.00006307097936149048,0.00002971649308812137,0.000011758862189057855,0.0000039498943360206454,0.0000011402179875649962,2.894257963007429e-7,6.990045671293881e-8,2.1187446672595064e-8,1.1827040811397835e-8,1.0261583274571132e-8,1.0032887217679263e-8,1.0003633401962912e-8,1.0000352687780532e-8,1.000003004532032e-8,1.000000224161425e-8,1.0000000145999337e-8,1.000000000826416e-8,1.0000000000404098e-8,1.0000000000016933e-8,1.00000000000006e-8,1.0000000000000018e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8,1e-8] \ No newline at end of file diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..6209141 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,33 @@ + +type GetData3D = ( + condition: number[], + reload: boolean, + eps: number[], + epsSize: number, + dataReturnType: number, +) => any + +type GetData2D = ( + condition: number[], + reload: boolean, + eps: number[], + epsSize: number, + sourcePositionRelative: number[], + sigma: number[] + // dataReturnType: number, +) => any + +// interface Module { +// sayHi: (id: number) => void; +// getData3D: GetData3D; +// getData2D: GetData2D; +// } + + // declare module 'bindings' { + // export default function(string: 'hello'): Module; + // } + + declare module 'napi-addon-fdtd' { + export const getData3D: GetData3D; + export const getData2D: GetData2D; + } \ No newline at end of file diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..ca7d5be --- /dev/null +++ b/index.ts @@ -0,0 +1,9 @@ +// var addon = require("./build/Release/napi-addon-fdtd.node"); + +import bindings from 'bindings'; +const addon = bindings('napi-addon-fdtd') + + +export default addon; + + diff --git a/package-lock.json b/package-lock.json index c8a47f7..4069f8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,40 @@ { "name": "napi-addon-fdtd", - "version": "3.1.15", + "version": "3.1.21", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "napi-addon-fdtd", - "version": "3.1.15", + "version": "3.1.21", "hasInstallScript": true, "license": "ISC", "dependencies": { + "bindings": "^1.5.0", "cmake-js": "^6.2.1", - "napi-addon-fdtd": "^3.1.5", "node-addon-api": "^3.1.0" + }, + "devDependencies": { + "@types/bindings": "^1.5.1", + "@types/node": "^17.0.24", + "typescript": "^4.6.3" } }, + "node_modules/@types/bindings": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@types/bindings/-/bindings-1.5.1.tgz", + "integrity": "sha512-8HzueDeoxGXdsJ0Ep7TOXHGN+woRTWa1bAds30r5we7PCC3P5zrSTRknePLn/KYAubgQv5t/1zkonnStHLCWOg==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "17.0.24", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.24.tgz", + "integrity": "sha512-aveCYRQbgTH9Pssp1voEP7HiuWlD2jW2BO56w+bVrJn04i61yh6mRfoKO6hEYQD9vF+W8Chkwc6j1M36uPkx4g==", + "dev": true + }, "node_modules/ansi": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/ansi/-/ansi-0.3.1.tgz", @@ -92,6 +112,14 @@ "node": "*" } }, + "node_modules/bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dependencies": { + "file-uri-to-path": "1.0.0" + } + }, "node_modules/bluebird": { "version": "3.4.7", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz", @@ -279,6 +307,11 @@ "safe-buffer": "~5.1.0" } }, + "node_modules/file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, "node_modules/follow-redirects": { "version": "1.14.6", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz", @@ -525,16 +558,6 @@ "mkdirp": "bin/cmd.js" } }, - "node_modules/napi-addon-fdtd": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/napi-addon-fdtd/-/napi-addon-fdtd-3.1.5.tgz", - "integrity": "sha512-l0PU1otM+Q7dvsFPGEa+DCaNJxgDAkexTfCdsDjrhpEjoVOk3hL5m4DcyKBdTMz6RP/KaYIlocI+qfA29QpKRw==", - "hasInstallScript": true, - "dependencies": { - "cmake-js": "^6.2.1", - "node-addon-api": "^3.1.0" - } - }, "node_modules/node-addon-api": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", @@ -735,6 +758,19 @@ "node": "*" } }, + "node_modules/typescript": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", + "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -853,6 +889,21 @@ } }, "dependencies": { + "@types/bindings": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@types/bindings/-/bindings-1.5.1.tgz", + "integrity": "sha512-8HzueDeoxGXdsJ0Ep7TOXHGN+woRTWa1bAds30r5we7PCC3P5zrSTRknePLn/KYAubgQv5t/1zkonnStHLCWOg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/node": { + "version": "17.0.24", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.24.tgz", + "integrity": "sha512-aveCYRQbgTH9Pssp1voEP7HiuWlD2jW2BO56w+bVrJn04i61yh6mRfoKO6hEYQD9vF+W8Chkwc6j1M36uPkx4g==", + "dev": true + }, "ansi": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/ansi/-/ansi-0.3.1.tgz", @@ -923,6 +974,14 @@ "chainsaw": "~0.1.0" } }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bluebird": { "version": "3.4.7", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz", @@ -1079,6 +1138,11 @@ } } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, "follow-redirects": { "version": "1.14.6", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz", @@ -1287,15 +1351,6 @@ "minimist": "^1.2.5" } }, - "napi-addon-fdtd": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/napi-addon-fdtd/-/napi-addon-fdtd-3.1.5.tgz", - "integrity": "sha512-l0PU1otM+Q7dvsFPGEa+DCaNJxgDAkexTfCdsDjrhpEjoVOk3hL5m4DcyKBdTMz6RP/KaYIlocI+qfA29QpKRw==", - "requires": { - "cmake-js": "^6.2.1", - "node-addon-api": "^3.1.0" - } - }, "node-addon-api": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", @@ -1453,6 +1508,12 @@ "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", "integrity": "sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk=" }, + "typescript": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", + "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "dev": true + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", diff --git a/package.json b/package.json index 5c0a3fb..b10028c 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,24 @@ { "name": "napi-addon-fdtd", - "version": "3.1.15", + "version": "3.1.22", "description": "Build N-API native addon with CMake and node-addon-api C++ wrapper. FDTD physics simulation", - "main": "index.js", + "main": "dist/index.js", + "types": "index.d.ts", "scripts": { "install": "cmake-js compile", - "test": "node index.js" + "test": "npm install && tsc && node dist/test-addon.js" }, "keywords": [], "author": "maxmaxkklosd99", "license": "ISC", "dependencies": { + "bindings": "^1.5.0", "cmake-js": "^6.2.1", - "napi-addon-fdtd": "^3.1.5", "node-addon-api": "^3.1.0" + }, + "devDependencies": { + "@types/bindings": "^1.5.1", + "@types/node": "^17.0.24", + "typescript": "^4.6.3" } } diff --git a/src/FDTD/2D/FDTD_2D.cpp b/src/FDTD/2D/FDTD_2D.cpp index 17c93f2..dc31f51 100644 --- a/src/FDTD/2D/FDTD_2D.cpp +++ b/src/FDTD/2D/FDTD_2D.cpp @@ -35,13 +35,14 @@ void FDTD_2D::setParams() ticks = 0; // Grid steps. + // dx = 1 / 20 dx = 0.05; - dt = 0.025; + dt = dx / 2; // Physics params. - aa1 = lambda * lambda / (0.09 * tau * tau); - tMax = 4 * tau / (lambda / 0.3); + aa1 = lambda * lambda / (c0 * c0 * tau * tau); + tMax = 3 * tau / (lambda / c0); for (int i = 0; i < Nx; i++) { diff --git a/src/FDTD/2D/FDTD_2D.h b/src/FDTD/2D/FDTD_2D.h index 2c6dcbe..ae8ca1f 100644 --- a/src/FDTD/2D/FDTD_2D.h +++ b/src/FDTD/2D/FDTD_2D.h @@ -13,9 +13,11 @@ class FDTD_2D double Ti; //?? double tMax; //?? - // Grid size + // Grid size. static const size_t Nx = 800; - static const size_t Ny = 501; + + // Source position. + static const size_t Ny = 200; // Grid steps. double dx; @@ -33,6 +35,9 @@ class FDTD_2D double Ex[Nx]; double Ex_prev[Nx]; + // Normalized light speed in Gaussian system. + double c0 = 0.3; + // lambda - wave length double lambda; diff --git a/index.js b/test-addon.ts similarity index 54% rename from index.js rename to test-addon.ts index 812ae63..371f41c 100644 --- a/index.js +++ b/test-addon.ts @@ -1,11 +1,12 @@ -var addon = require("./build/Release/napi-addon-fdtd.node"); +import fs from 'fs'; +import path from 'path'; + +import addon from './index'; -module.exports = addon; -const fs = require("fs"); -const path = require("path"); const test1D = () => { + const condition = [1, 10, 1]; const eps = [1, 1.2]; const sigma = [0, 0.04]; @@ -13,13 +14,14 @@ const test1D = () => { let data = addon.getData2D(condition, true, eps, 2, srcPosition, sigma); - for (let j = 0; j < 150; ++j) { + for (let j = 0; j < 50; ++j) { data = addon.getData2D(condition, false, eps, 2, srcPosition, sigma); } fs.writeFileSync( path.resolve(__dirname, "tmp.txt"), JSON.stringify(data.dataHy), + // @ts-ignore function (err) { if (err) { return console.log(err); @@ -30,14 +32,25 @@ const test1D = () => { }; const test2D = () => { - let data = addon.getData3D([1, 10], true, [1, 2, 1, 1], 2, 0); + const epsSize = 40; + const eps = Array(epsSize*2).fill(0).map(_ => Math.random()*10) + + const condition = [1, 10] + + let reload = true; + let data = addon.getData3D(condition, reload, [4,5,6,7], 2, 0); + + reload = false; for (let j = 0; j < 150; ++j) { - data = addon.getData3D([1, 10], false, [1, 2, 1, 1], 2, 0); + //eps, epsSize + data = addon.getData3D(condition, reload, [4,5,6,7], 2, 0); } + fs.writeFileSync( path.resolve(__dirname, "tmp.txt"), JSON.stringify(data.dataY), + // @ts-ignore function (err) { if (err) { return console.log(err); @@ -47,6 +60,15 @@ const test2D = () => { ); // Orfs.writeFileSync('/tmp/test-sync', 'Hey there!'); }; +function testMemoryUsage() { + // const arr = [1, 2, 3, 4, 5, 6, 9, 7, 8, 9, 10]; + // const arr = Array(1e7).fill(1e3); + // arr.reverse(); + const used = process.memoryUsage().heapUsed / 1024 / 1024; + console.log(`The script uses approximately ${Math.round(used * 100) / 100} MB`); +} + test1D(); -test2D(); \ No newline at end of file +// test2D(); +// testMemoryUsage(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ece7461 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,101 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "CommonJS", /* Specify what module code is generated. */ + "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + "typeRoots": ["./"], /* Specify multiple folders that act like `./node_modules/@types`. */ + "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +}