From d3f77f4b25c113b742e951ea639100e5dc44a42c Mon Sep 17 00:00:00 2001 From: max99xam Date: Thu, 30 Jun 2022 16:29:08 +0300 Subject: [PATCH] seaparate declaration and implementation in fdtd2d --- dist/test-addon.js | 4 +- package-lock.json | 4 +- package.json | 2 +- src/fdtd/1d-pml/fdtd-pml-1d.cpp | 50 +++---- src/fdtd/1d-pml/fdtd-pml-1d.h | 13 +- src/fdtd/2d-pml/fdtd-pml-2d.cpp | 212 +++++++++++++++++++++++++++++ src/fdtd/2d-pml/fdtd-pml-2d.h | 229 +++----------------------------- test-addon.ts | 117 ++++++++-------- 8 files changed, 326 insertions(+), 305 deletions(-) create mode 100644 src/fdtd/2d-pml/fdtd-pml-2d.cpp diff --git a/dist/test-addon.js b/dist/test-addon.js index cea26d9..4db1770 100644 --- a/dist/test-addon.js +++ b/dist/test-addon.js @@ -65,8 +65,8 @@ function testMemoryUsage() { var used = process.memoryUsage().heapUsed / 1024 / 1024; console.log("The script uses approximately ".concat(Math.round(used * 100) / 100, " MB")); } -test1D(); -// test2D(); +// test1D(); +test2D(); // testMemoryUsage(); // void printArray(std::array &arr) // { diff --git a/package-lock.json b/package-lock.json index 4cf7fab..1f63b1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "napi-addon-fdtd", - "version": "3.4.7", + "version": "3.4.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "napi-addon-fdtd", - "version": "3.4.7", + "version": "3.4.8", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index f024707..331474c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "napi-addon-fdtd", - "version": "3.4.7", + "version": "3.4.9", "description": "Build N-API native addon with CMake and node-addon-api C++ wrapper. FDTD physics simulation", "main": "dist/index.js", "types": "index.d.ts", diff --git a/src/fdtd/1d-pml/fdtd-pml-1d.cpp b/src/fdtd/1d-pml/fdtd-pml-1d.cpp index 60ea3f6..db0cec0 100644 --- a/src/fdtd/1d-pml/fdtd-pml-1d.cpp +++ b/src/fdtd/1d-pml/fdtd-pml-1d.cpp @@ -1,12 +1,12 @@ #include "fdtd-pml-1d.h" -#include // header in standard library void FdtdPml1D::SetParams(double new_tau, double new_omega, std::vector &new_eps, std::vector &new_mu, std::vector &new_sigma, - size_t new_src_position) { + size_t new_src_position) +{ time_step = 0; @@ -14,8 +14,8 @@ void FdtdPml1D::SetParams(double new_tau, omega = new_omega; src_position = new_src_position; - - for (int i = 0; i < grid_size; ++i) { + for (int i = 0; i < grid_size; ++i) + { eps[i] = new_eps[i] * eps0; mu[i] = new_mu[i] * mu0; sigma[i] = new_sigma[i]; @@ -26,18 +26,20 @@ void FdtdPml1D::SetParams(double new_tau, } // Taflove, page 292, equation 7.60a. - for (int i = 0; i < pml_width; ++i) { + for (int i = 0; i < pml_width; ++i) + { - double sigma_in_pml = std::pow( (double)i / pml_width, m) * sigma_max; + double sigma_in_pml = std::pow((double)i / pml_width, m) * sigma_max; // Lossy electric conductivity profile. sigma[grid_size - pml_width + i] = sigma_in_pml; sigma[pml_width - i - 1] = sigma_in_pml; } - for (int i = 0; i < grid_size; ++i) { + for (int i = 0; i < grid_size; ++i) + { - // Taflove, page 275, equation 7.8. + // Taflove, page 275, equation 7.8. // Magnetic conductivity loss. sigma_star[i] = sigma[i] * mu0 / eps0; @@ -50,44 +52,45 @@ void FdtdPml1D::SetParams(double new_tau, D[i] = (dt / dx) / (eps[i] + 0.5 * dt * sigma[i]); } - } - -size_t FdtdPml1D::GetCurrentTimeStep() { +size_t FdtdPml1D::GetCurrentTimeStep() +{ return time_step; } - -double FdtdPml1D::GetTau() { +double FdtdPml1D::GetTau() +{ return tau; } - -size_t FdtdPml1D::GetSourcePosition() { +size_t FdtdPml1D::GetSourcePosition() +{ return src_position; } - void FdtdPml1D::Calculation(std::vector &vect_x, std::vector &vect_ex, - std::vector &vect_hy) { - + std::vector &vect_hy) +{ // Insert source in certain space grid. double t = (double)time_step * dt; double source = std::exp(-(std::pow((t0 - t) / tau, 2))) * std::cos(omega * t); ex[src_position] += source; - for (int i = 0; i < grid_size - 1; ++i) { + for (int i = 0; i < grid_size - 1; ++i) + { hy[i] = A[i] * hy[i] - B[i] * (ex[i + 1] - ex[i]); } - for (int i = 1; i < grid_size - 1; ++i) { + for (int i = 1; i < grid_size - 1; ++i) + { ex[i] = C[i] * ex[i] - D[i] * (hy[i] - hy[i - 1]); } - - for (int i = 0; i < grid_size; ++i) { + + for (int i = 0; i < grid_size; ++i) + { vect_x.push_back(i); vect_ex.push_back(ex[i]); vect_hy.push_back(hy[i]); @@ -101,7 +104,8 @@ FdtdPml1D::FdtdPml1D(double new_tau, std::vector &new_eps, std::vector &new_mu, std::vector &new_sigma, - size_t new_src_position) { + size_t new_src_position) +{ SetParams(new_tau, new_omega, new_eps, new_mu, new_sigma, new_src_position); diff --git a/src/fdtd/1d-pml/fdtd-pml-1d.h b/src/fdtd/1d-pml/fdtd-pml-1d.h index 93b1d61..80ffdb7 100644 --- a/src/fdtd/1d-pml/fdtd-pml-1d.h +++ b/src/fdtd/1d-pml/fdtd-pml-1d.h @@ -8,7 +8,8 @@ #include #include // std::fill -class FdtdPml1D { +class FdtdPml1D +{ // Speed of light in nm/fs. const double light_spd = 299.792458; @@ -88,7 +89,6 @@ class FdtdPml1D { size_t time_step = 0; public: - void SetParams(double new_tau, double new_omega, std::vector &new_eps, @@ -100,10 +100,11 @@ class FdtdPml1D { size_t GetCurrentTimeStep(); double GetTau(); size_t GetSourcePosition(); - static size_t GetGridSize() { - // return grid_size - pml_width * 2; - return grid_size; -} + static size_t GetGridSize() + { + // return grid_size - pml_width * 2; + return grid_size; + } void Calculation(std::vector &vect_x, std::vector &vect_ex, diff --git a/src/fdtd/2d-pml/fdtd-pml-2d.cpp b/src/fdtd/2d-pml/fdtd-pml-2d.cpp new file mode 100644 index 0000000..98eed5c --- /dev/null +++ b/src/fdtd/2d-pml/fdtd-pml-2d.cpp @@ -0,0 +1,212 @@ +#include "fdtd-pml-2d.h" + +void FdtdPml2D::SetParams(std::vector> &eps, + std::vector> &mu, + std::vector> &sigma, + size_t new_src_position_row, + size_t new_src_position_col) +{ + time_step = 0; + + src_row = new_src_position_row + pml_width; + src_col = new_src_position_col + pml_width; + + // Init field arrays. + std::fill_n(&dz[0][0], rows * cols, 0.0); + std::fill_n(&ez[0][0], rows * cols, 0.0); + std::fill_n(&hx[0][0], rows * cols, 0.0); + std::fill_n(&hy[0][0], rows * cols, 0.0); + std::fill_n(&gaz[0][0], rows * cols, 1.0); + + // Init pml arrays. + std::fill_n(&gi2[0], rows, 1.0); + std::fill_n(&gi3[0], rows, 1.0); + std::fill_n(&fi1[0], rows, 0.0); + std::fill_n(&fi2[0], rows, 1.0); + std::fill_n(&fi3[0], rows, 1.0); + + std::fill_n(&gj2[0], rows, 1.0); + std::fill_n(&gj3[0], rows, 1.0); + std::fill_n(&fj1[0], rows, 0.0); + std::fill_n(&fj2[0], rows, 1.0); + std::fill_n(&fj3[0], rows, 1.0); + + // Fill pml arrays. + for (size_t i = 0; i < pml_width; ++i) + { + int xnum = pml_width - i; + double xd = pml_width; + double xxn = xnum / xd; + double xn = 0.33 * std::pow(xxn, 3); + + gi2[i] = 1.0 / (1.0 + xn); + gi2[rows - 1 - i] = 1.0 / (1.0 + xn); + gi3[i] = (1.0 - xn) / (1.0 + xn); + gi3[rows - i - 1] = (1.0 - xn) / (1.0 + xn); + + gj2[i] = 1.0 / (1.0 + xn); + gj2[rows - 1 - i] = 1.0 / (1.0 + xn); + gj3[i] = (1.0 - xn) / (1.0 + xn); + gj3[rows - i - 1] = (1.0 - xn) / (1.0 + xn); + + xxn = (xnum - 0.5) / xd; + xn = 0.33 * std::pow(xxn, 3); + + fi1[i] = xn; + fi1[rows - 2 - i] = xn; + fi2[i] = 1.0 / (1.0 + xn); + fi2[rows - 2 - i] = 1.0 / (1.0 + xn); + fi3[i] = (1.0 - xn) / (1.0 - xn); + fi3[rows - 2 - i] = (1.0 - xn) / (1.0 + xn); + + fj1[i] = xn; + fj1[rows - 2 - i] = xn; + fj2[i] = 1.0 / (1.0 + xn); + fj2[rows - 2 - i] = 1.0 / (1.0 + xn); + fj3[i] = (1.0 - xn) / (1.0 - xn); + fj3[rows - 2 - i] = (1.0 - xn) / (1.0 + xn); + } + + // Fill medium array. + for (size_t i = 0; i < rows; ++i) + { + for (size_t j = 0; j < cols; ++j) + { + + if (i > pml_width && i < (rows - pml_width) && j > pml_width && j < (cols - pml_width)) + { + gaz[i][j] = 1.0 / (eps[i - pml_width][j - pml_width] + (sigma[i - pml_width][j - pml_width] * dt) / epsz); + } + else + { + gaz[i][j] = 1.0 / (epsilon1 + (sigma1 * dt) / epsz); + } + + // Medium 1. + // gaz[i][j] = 1.0 / (epsilon1 + (sigma1 * dt) / epsz); + + // Medium 2. + // if (i>=80 && i<=90 && j>=80 && j<=120) { + // gaz[i][j] = 1.0 / (epsilon2 + (sigma2 * dt) / epsz); + // } + + // if (i>=120 && i<=130 && j>=80 && j<=120) { + // gaz[i][j] = 1.0 / (epsilon2 + (sigma2 * dt) / epsz); + // } + + // // Dielectric border. Medium 0. + // if (i >= (src_row - 20) && i <= (src_row + 20) && (j == (src_col - 10) || j == (src_col + 10)) || j >= (src_col - 10) && j <= (src_col + 10) && (i == (src_row - 10))) + // { + // gaz[i][j] = 1.0 / (epsilon0 + (sigma0 * dt) / epsz); + // } + } + } +} + +// One time layer calculation. +void FdtdPml2D::Calculation() +{ + + // Dz field calculation. + for (int i = 1; i < rows; i++) + { + for (int j = 1; j < cols; j++) + { + dz[i][j] = gi3[i] * gj3[j] * dz[i][j] + gi2[i] * gj2[j] * 0.5 * (hy[i][j] - hy[i - 1][j] - hx[i][j] + hx[i][j - 1]); + } + } + + // Ez field calculation. + for (int i = 1; i < rows; i++) + { + for (int j = 1; j < cols; j++) + { + ez[i][j] = gaz[i][j] * dz[i][j]; + } + } + + // Put Gaussian beam source. + double source = -2.0 * ((time_step - t0) / tau) * std::exp(-1.0 * std::pow((time_step - t0) / tau, 2)); + ez[src_row][src_col] = source; + + for (int i = 0; i < rows - 1; i++) + { + for (int j = 0; j < cols - 1; j++) + { + + // Hx field calculation. + hx[i][j] = fj3[j] * hx[i][j] + fj2[j] * 0.5 * (ez[i][j] - ez[i][j + 1]); + // Hy field calculation. + hy[i][j] = fi3[i] * hy[i][j] + fi2[i] * 0.5 * (ez[i + 1][j] - ez[i][j]); + } + } +} + +size_t FdtdPml2D::GetStep() +{ + return 1; +} + +size_t FdtdPml2D::GetCurrentTimeStep() +{ + return time_step; +} + +FdtdPml2D::FdtdPml2D(std::vector> &eps, + std::vector> &mu, + std::vector> &sigma, + size_t new_src_position_row, + size_t new_src_position_col) +{ + SetParams(eps, mu, sigma, new_src_position_row, new_src_position_col); +} + +void FdtdPml2D::CalcNextLayer(std::vector &vectX, + std::vector &vectY, + std::vector &vectEz, + std::vector &vectHy, + std::vector &vectHx, + std::vector &vectEnergy, + double &max, double &min) +{ + + Calculation(); + + size_t step = GetStep(); + + // for (int xx = 1; xx < rows - 1; xx += step) + for (int xx = pml_width; xx < rows - pml_width; xx += step) + { + // vectX.push_back(xx); + // vectY.push_back(xx); + // for (int yy = 1; yy < cols - 1; yy += step) + for (int yy = pml_width; yy < cols - pml_width; yy += step) + { + // Energy + // double energy = yy1[xx][yy] * yy1[xx][yy] * Ez1[xx][yy] * Ez1[xx][yy] + + // Hy1[xx][yy] * Hy1[xx][yy] + Hx1[xx][yy] * Hx1[xx][yy]; + double energy = 1; + + vectX.push_back(xx - pml_width); + vectY.push_back(yy - pml_width); + vectEz.push_back(ez[yy][xx]); + vectHy.push_back(hy[yy][xx]); + vectHx.push_back(hx[yy][xx]); + vectEnergy.push_back(energy); + + if (xx > (pml_width + 10) && xx < (rows - pml_width - 10) && yy > (pml_width + 10) && yy < (rows - pml_width - 10)) + { + if (ez[yy][xx] > max) + { + max = ez[yy][xx]; + } + if (ez[yy][xx] < min) + { + min = ez[yy][xx]; + } + } + } + } + + time_step++; +} \ No newline at end of file diff --git a/src/fdtd/2d-pml/fdtd-pml-2d.h b/src/fdtd/2d-pml/fdtd-pml-2d.h index 5a56d7d..9e5f542 100644 --- a/src/fdtd/2d-pml/fdtd-pml-2d.h +++ b/src/fdtd/2d-pml/fdtd-pml-2d.h @@ -4,7 +4,8 @@ // Electromagnetic simulation using the fdtd method with python. // Chapter 3. -#pragma once +#ifndef FDTD_PML_2D +#define FDTD_PML_2D #include #include @@ -18,8 +19,8 @@ class FdtdPml2D // Grid sizes. static const size_t pml_width = 40; - static const size_t rows = 220 + pml_width*2; - static const size_t cols = 220 + pml_width*2; + static const size_t rows = 220 + pml_width * 2; + static const size_t cols = 220 + pml_width * 2; // Set source position. size_t src_row = rows / 2; @@ -86,185 +87,34 @@ class FdtdPml2D double fj2[rows]; double fj3[rows]; - - public: // Getters. - static size_t GetRows() { - return rows - pml_width * 2; - } - - static size_t GetCols() { - return cols - pml_width * 2; - } - - - void SetParams(std::vector>& eps, - std::vector>& mu, - std::vector>& sigma, - size_t new_src_position_row, - size_t new_src_position_col) + static size_t GetRows() { - time_step = 0; - - src_row = new_src_position_row + pml_width; - src_col = new_src_position_col + pml_width; - - // std::cout << "row: " << src_row << std::endl; - // std::cout << "col: " << src_col << std::endl; - - // Init field arrays. - std::fill_n(&dz[0][0], rows * cols, 0.0); - std::fill_n(&ez[0][0], rows * cols, 0.0); - std::fill_n(&hx[0][0], rows * cols, 0.0); - std::fill_n(&hy[0][0], rows * cols, 0.0); - std::fill_n(&gaz[0][0], rows * cols, 1.0); - - // Init pml arrays. - std::fill_n(&gi2[0], rows, 1.0); - std::fill_n(&gi3[0], rows, 1.0); - std::fill_n(&fi1[0], rows, 0.0); - std::fill_n(&fi2[0], rows, 1.0); - std::fill_n(&fi3[0], rows, 1.0); - - std::fill_n(&gj2[0], rows, 1.0); - std::fill_n(&gj3[0], rows, 1.0); - std::fill_n(&fj1[0], rows, 0.0); - std::fill_n(&fj2[0], rows, 1.0); - std::fill_n(&fj3[0], rows, 1.0); - - // Fill pml arrays. - for (size_t i = 0; i < pml_width; ++i) - { - int xnum = pml_width - i; - double xd = pml_width; - double xxn = xnum / xd; - double xn = 0.33 * std::pow(xxn, 3); - - gi2[i] = 1.0 / (1.0 + xn); - gi2[rows - 1 - i] = 1.0 / (1.0 + xn); - gi3[i] = (1.0 - xn) / (1.0 + xn); - gi3[rows - i - 1] = (1.0 - xn) / (1.0 + xn); - - gj2[i] = 1.0 / (1.0 + xn); - gj2[rows - 1 - i] = 1.0 / (1.0 + xn); - gj3[i] = (1.0 - xn) / (1.0 + xn); - gj3[rows - i - 1] = (1.0 - xn) / (1.0 + xn); - - xxn = (xnum - 0.5) / xd; - xn = 0.33 * std::pow(xxn, 3); - - fi1[i] = xn; - fi1[rows - 2 - i] = xn; - fi2[i] = 1.0 / (1.0 + xn); - fi2[rows - 2 - i] = 1.0 / (1.0 + xn); - fi3[i] = (1.0 - xn) / (1.0 - xn); - fi3[rows - 2 - i] = (1.0 - xn) / (1.0 + xn); - - fj1[i] = xn; - fj1[rows - 2 - i] = xn; - fj2[i] = 1.0 / (1.0 + xn); - fj2[rows - 2 - i] = 1.0 / (1.0 + xn); - fj3[i] = (1.0 - xn) / (1.0 - xn); - fj3[rows - 2 - i] = (1.0 - xn) / (1.0 + xn); - } - - // Fill medium array. - for (size_t i = 0; i < rows; ++i) - { - for (size_t j = 0; j < cols; ++j) - { - - if(i > pml_width && i < (rows - pml_width) && j > pml_width && j < (cols - pml_width)){ - gaz[i][j] = 1.0 / (eps[i-pml_width][j-pml_width] + (sigma[i-pml_width][j-pml_width] * dt) / epsz); - }else { - gaz[i][j] = 1.0 / (epsilon1 + (sigma1 * dt) / epsz); - } - - - - - // Medium 1. - // gaz[i][j] = 1.0 / (epsilon1 + (sigma1 * dt) / epsz); - - // Medium 2. - // if (i>=80 && i<=90 && j>=80 && j<=120) { - // gaz[i][j] = 1.0 / (epsilon2 + (sigma2 * dt) / epsz); - // } - - // if (i>=120 && i<=130 && j>=80 && j<=120) { - // gaz[i][j] = 1.0 / (epsilon2 + (sigma2 * dt) / epsz); - // } - - // // Dielectric border. Medium 0. - // if (i >= (src_row - 20) && i <= (src_row + 20) && (j == (src_col - 10) || j == (src_col + 10)) || j >= (src_col - 10) && j <= (src_col + 10) && (i == (src_row - 10))) - // { - // gaz[i][j] = 1.0 / (epsilon0 + (sigma0 * dt) / epsz); - // } - } - } + return rows - pml_width * 2; } - - - void Calculation() + static size_t GetCols() { - // One time layer calculation. - - // Dz field calculation. - for (int i = 1; i < rows; i++) - { - for (int j = 1; j < cols; j++) - { - dz[i][j] = gi3[i] * gj3[j] * dz[i][j] - + gi2[i] * gj2[j] * 0.5 - * (hy[i][j] - hy[i-1][j] - hx[i][j] + hx[i][j-1]); - } - } - - // Ez field calculation. - for (int i = 1; i < rows; i++) - { - for (int j = 1; j < cols; j++) - { - ez[i][j] = gaz[i][j] * dz[i][j]; - } - } - - // Put Gaussian beam source. - double source = -2.0 * ((time_step - t0) / tau) * std::exp(-1.0 * std::pow((time_step - t0) / tau, 2)); - ez[src_row][src_col] = source; - - for (int i = 0; i < rows - 1; i++) - { - for (int j = 0; j < cols - 1; j++) - { - - // Hx field calculation. - hx[i][j] = fj3[j] * hx[i][j] + fj2[j] * 0.5 * (ez[i][j] - ez[i][j + 1]); - // Hy field calculation. - hy[i][j] = fi3[i] * hy[i][j] + fi2[i] * 0.5 * (ez[i + 1][j] - ez[i][j]); - } - } + return cols - pml_width * 2; } + size_t GetStep(); + size_t GetCurrentTimeStep(); - size_t GetStep() { - return 1; - } + void SetParams(std::vector> &eps, + std::vector> &mu, + std::vector> &sigma, + size_t new_src_position_row, + size_t new_src_position_col); - size_t GetCurrentTimeStep() { - return time_step; - } + void Calculation(); FdtdPml2D(std::vector> &eps, std::vector> &mu, std::vector> &sigma, size_t new_src_position_row, - size_t new_src_position_col) { - SetParams(eps, mu, sigma, new_src_position_row, new_src_position_col); - - } + size_t new_src_position_col); void CalcNextLayer(std::vector &vectX, std::vector &vectY, @@ -272,46 +122,7 @@ class FdtdPml2D std::vector &vectHy, std::vector &vectHx, std::vector &vectEnergy, - double &max, double &min) - { + double &max, double &min); +}; - Calculation(); - - size_t step = GetStep(); - - // for (int xx = 1; xx < rows - 1; xx += step) - for (int xx = pml_width; xx < rows - pml_width; xx += step) - { - // vectX.push_back(xx); - // vectY.push_back(xx); - // for (int yy = 1; yy < cols - 1; yy += step) - for (int yy = pml_width; yy < cols - pml_width; yy += step) - { - // Wem - // double energy = yy1[xx][yy] * yy1[xx][yy] * Ez1[xx][yy] * Ez1[xx][yy] + - // Hy1[xx][yy] * Hy1[xx][yy] + Hx1[xx][yy] * Hx1[xx][yy]; - double energy = 1; - - vectX.push_back(xx-pml_width); - vectY.push_back(yy-pml_width); - vectEz.push_back(ez[yy][xx]); - vectHy.push_back(hy[yy][xx]); - vectHx.push_back(hx[yy][xx]); - vectEnergy.push_back(energy); - - - if(xx > (pml_width+10) && xx < (rows-pml_width-10) - && yy > (pml_width+10) && yy < (rows-pml_width-10)){ - if(ez[yy][xx] > max){ - max = ez[yy][xx]; - } - if(ez[yy][xx] < min){ - min = ez[yy][xx]; - } - } - } - } - - time_step++; - } -}; \ No newline at end of file +#endif \ No newline at end of file diff --git a/test-addon.ts b/test-addon.ts index e46f45a..256b1cb 100644 --- a/test-addon.ts +++ b/test-addon.ts @@ -1,96 +1,89 @@ -import fs from 'fs'; -import path from 'path'; - -import addon from './index'; - - +import addon from "./index"; const test1D = () => { - - const condition = [3.5, 8] - const materialVector = [1,0,2,0,1] + const condition = [3.5, 8]; + const materialVector = [1, 0, 2, 0, 1]; const eps = [1.0, 1.2, 1.1]; const mu = [0.51, 0.5, 0.57]; const sigma = [1.0, 0.001, 1.0]; const srcPosition = [0.5]; let reload = true; - let data = addon.getData1D(condition, reload, materialVector, materialVector.length, eps, mu, sigma, srcPosition); + let data = addon.getData1D( + condition, + reload, + materialVector, + materialVector.length, + eps, + mu, + sigma, + srcPosition + ); reload = false; for (let j = 0; j < 5; ++j) { - data = addon.getData1D(condition, reload, materialVector, materialVector.length, eps, mu, sigma, srcPosition); + data = addon.getData1D( + condition, + reload, + materialVector, + materialVector.length, + eps, + mu, + sigma, + srcPosition + ); } - - console.log(data) - - // fs.writeFileSync( - // path.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!'); + console.log(data); }; const test2D = () => { - - const condition = [1, 10] - const materialMatrix = [1,0,2,0] + const condition = [1, 10]; + const materialMatrix = [1, 0, 2, 0]; const matrixSize = 2; const eps = [1.0, 1.2, 1.1]; const mu = [0.51, 0.5, 0.57]; const sigma = [1.0, 0.001, 1.0]; const returnDataNumber = 0; - const srcPosition = [0.1,0.1]; + const srcPosition = [0.1, 0.1]; let reload = true; - let data = addon.getData2D(condition, reload, materialMatrix, matrixSize, eps, mu, sigma, returnDataNumber, srcPosition); + let data = addon.getData2D( + condition, + reload, + materialMatrix, + matrixSize, + eps, + mu, + sigma, + returnDataNumber, + srcPosition + ); reload = false; for (let j = 0; j < 50; ++j) { - data = addon.getData2D(condition, reload, materialMatrix, matrixSize, eps, mu, sigma, returnDataNumber, srcPosition); + data = addon.getData2D( + condition, + reload, + materialMatrix, + matrixSize, + eps, + mu, + sigma, + returnDataNumber, + srcPosition + ); } - console.log(data) - - // fs.writeFileSync( - // path.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!'); + console.log(data); }; 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`); + console.log( + `The script uses approximately ${Math.round(used * 100) / 100} MB` + ); } - -test1D(); -// test2D(); +// test1D(); +test2D(); // testMemoryUsage(); - - - -// void printArray(std::array &arr) -// { -// for(double& e : arr) -// { -// std::cout << e << " "; -// } -// std::cout << std::endl; -// }