Skip to content

Commit

Permalink
update indexes in pml calcualting
Browse files Browse the repository at this point in the history
  • Loading branch information
abc0990cba committed May 12, 2022
1 parent 7b36062 commit 9a77bd5
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 84 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ include_directories(${CMAKE_JS_INC})

# Declare the location of the source files
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h"
"src/FDTD/2d-pml/*.cpp" "src/FDTD/2d-pml/*.h"
"src/FDTD/1d-pml/*.cpp" "src/FDTD/1d-pml/*.h"
"src/fdtd/2d-pml/*.cpp" "src/fdtd/2d-pml/*.h"
"src/fdtd/1d-pml/*.cpp" "src/fdtd/1d-pml/*.h"
)

# This line will tell CMake that we're building a shared library
Expand Down
4 changes: 2 additions & 2 deletions dist/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var test2D = function () {
var reload = true;
var data = index_1.default.getData2D(condition, reload, materialMatrix, matrixSize, eps, mu, sigma, returnDataNumber, srcPosition);
reload = false;
for (var j = 0; j < 200; ++j) {
for (var j = 0; j < 50; ++j) {
data = index_1.default.getData2D(condition, reload, materialMatrix, matrixSize, eps, mu, sigma, returnDataNumber, srcPosition);
}
console.log(data);
Expand All @@ -63,5 +63,5 @@ function testMemoryUsage() {
console.log("The script uses approximately ".concat(Math.round(used * 100) / 100, " MB"));
}
test1D();
test2D();
// test2D();
// testMemoryUsage();
2 changes: 1 addition & 1 deletion dist/tmp.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[-9.39396425566878e-74,3.1075656233251706e-57,4.498848239990849e-20,0.7421015235618883,1.4189518370070469,1.977043530626149,2.3593384653342016,2.5413770376992044,2.491565159736345,2.22429728711163,1.743080203180158,1.1001924609025715,0.3331211947405604,-0.48045963631556954,-1.281491695182893,-1.9884397470534967,-2.5415478317646474,-2.880324301186735,-2.9676997536129837,-2.7847111745070134,-2.3351390496496105,-1.6499160476906907,-0.7794766297807355,0.20386670568417442,1.2134024226122526,2.1601977577523526,2.9462951724156925,3.500186602615365,3.745150250985643,3.658631181081437,3.2140552850208555,2.454026202725322,1.4162892408044585,0.2007685361032705,-1.098106475911226,-2.355223509148887,-3.448665382092062,-4.27476805137157,-4.726529926917601,-4.765602627556546,-4.341171875797549,-3.5029474614161136,-2.2805893834837456,-0.8020975184173558,0.827004322410102,2.4409924324968113,3.8950656295147486,5.0417114756725665,5.756610613822861,5.9591025634755175,5.60754778541156,4.710903127851519,3.346713795777114,1.6055677549617273,-0.3295618791449513,-2.3163694450942973,-4.134707856162988,-5.631787535809645,-6.64303125935203,-7.057693382422351,-6.828153980042947,-5.949979867877014,-4.4869058773677395,-2.580820112983587,-0.3699114882457595,1.913421222957858,4.06854311185637,5.897645665244169,7.20991318446944,7.859070284233828,7.795672326575035,7.008126045110368,5.560890492089182,3.572098302491793,1.2277652292243761,-1.2622483147989967,-3.6598357843442897,-5.744397632081171,-7.312035543394781,-8.216560913072701,-8.363519582537188,-7.739387809753721,-6.3941700397610886,-4.455604659546936,-2.0989191400029306,2.0989191400029306,4.455604659546936,6.3941700397610886,7.739387809753721,8.363519582537188,8.216560913072701,7.312035543394781,5.744397632081171,3.6598357843442897,1.2622483147989967,-1.2277652292243761,-3.572098302491793,-5.560890492089182,-7.008126045110368,-7.794119538706236,-7.8495218640062365,-7.188827934318461,-5.878477729249168,-4.060240004434826,-1.9042059569098657,0.3741170949177821,2.5705883434069863,4.474359176395259,5.926851434020128,6.794834070087455,7.024800666970978,6.601717490277381,5.5953555589315025,4.103594095869217,2.291732054046535,0.32384638582820835,-1.6001244084977326,-3.3183264078776364,-4.6657370430243965,-5.546162777804934,-5.881526679911601,-5.676594058014988,-4.956810639557911,-3.8239315965726473,-2.384583367499495,-0.7985280947392004,0.79641837205699,2.2395669269039082,3.4188810588414222,4.225654004311862,4.615986295671221,4.5630333687957485,4.104424965064013,3.2933281934247436,2.2309436543520915,1.0206613578944126,-0.21266001656780875,-1.3594278194629672,-2.316413970234189,-3.008515662127692,-3.387890400586359,-3.436792477963944,-3.1740357819109826,-2.6379024221550607,-1.901066041445712,-1.0355561755238334,-0.13837005360103227,0.7173491462951687,1.4440432441503344,1.997244910823135,2.3243488015699056,2.4258809031020663,2.2935970026955883,1.9714028076793162,1.4877754982896167,0.9130370848732287,0.29310185706727154,-0.2998217334066292,-0.8244152553688672,-1.229205046578654,-1.4936336061684077,-1.6001599002343205,-1.554102544262964,-1.3724905523314423,-1.080279936667202,-0.7188506893290195,-0.31920789095358526,0.06882097245763397,0.42289363260830276,0.7001011476780283,0.8967635939589469,0.98684791300276,0.9872744934362394,0.8914052595020254,0.7306636809432207,0.5138751566015052,0.2757772055337032,0.033299461333931885,-0.18735777924829844,-0.36845461030966364,-0.5006642487638799,-0.5701450240853309,-0.5867272984911475,-0.5418188505109167,-0.4603623729371087,-0.33789413882647434,-0.20587280354035697,-0.06212748348556549,0.06549665208314027,0.1778462470884217,0.25913171630663884,0.3083927502606358,0.3261508207043803,0.30835777302169975,0.2707407804950766,0.20553962289316507,0.13761223249113266,0.056861421341490165,-0.011891480464539514,-0.07744511801681248,-0.1242798547967973,-0.15533718866731216,-0.17034308630755926,-0.1634965581218513,-0.14961633188532397,-0.11551787148568599,-0.08406640257469197,-0.04102245657983675,-0.005679146360368422,0.028476227670905022,0.05640906499731489,0.07113403294210274,0.08490083611465628,0.0800165558078738,0.07757588356391662,0.06138500760662793,0.0451660848271237,0.028387387899476667,0.005443346463993276,-0.005715493316742006,-0.024637391047762174,-0.03111376029377172,-0.03643197687814111,-0.04131376907465045,-0.0328927154513693,-0.03331990995549233,-0.023128433856885466,-0.012546700972476928,-0.01023176957660304,0.004205606672021854,0.009215266047994854,0.008303107421544198,0.019167935994999837,0.021085250150978074,0.00954842022758919,0.0015527878687986733,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0.26513420337100985,0.24756296069654327,0.21136554288739606,0.1610163350276805,0.09580362712589234,0.021036053019497625,-0.059242552477563264,-0.1417622574561465,-0.2176287882990065,-0.2831155064570815,-0.33212578810170446,-0.3535238578488235,-0.3545382086038569,-0.3138360967246292,-0.25341622298989686,-0.15320885604065942,-0.034382891789368625,0.0985594603637065,0.24718657261500743,0.3707868542778436,0.4936822828926011,0.5649472843678022,0.5992739994636243,0.5803767936619343,0.4964586420918576,0.35923934426166915,0.17905467182675405,-0.052467397328931714,-0.2968624556846812,-0.5234235768290945,-0.7322164688120193,-0.8914052595020254,-0.9872744934362394,-0.98684791300276,-0.8967635939589469,-0.7001011476780283,-0.42289363260830276,-0.06882097245763397,0.31920789095358526,0.7188506893290195,1.080279936667202,1.3724905523314423,1.554102544262964,1.6001599002343205,1.4936336061684077,1.229205046578654,0.8244152553688672,0.2998217334066292,-0.29310185706727154,-0.9130370848732287,-1.4877754982896167,-1.9714028076793162,-2.2935970026955883,-2.4258809031020663,-2.3243488015699056,-1.997244910823135,-1.4440432441503344,-0.7173491462951687,0.13837005360103227,1.0355561755238334,1.901066041445712,2.6379024221550607,3.1740357819109826,3.436792477963944,3.387890400586359,3.008515662127692,2.316413970234189,1.3594278194629672,0.21266001656780875,-1.0206613578944126,-2.2309436543520915,-3.2933281934247436,-4.104424965064013,-4.5630333687957485,-4.615986295671221,-4.225654004311862,-3.4188810588414222,-2.2395669269039082,-0.79641837205699,0.7985280947392004,2.384583367499495,3.8239315965726473,4.956810639557911,5.676594058014988,5.881526679911601,5.546162777804934,4.6657370430243965,3.3183264078776364,1.6001244084977326,-0.32384638582820835,-2.291732054046535,-4.103594095869217,-5.5953555589315025,-6.601717490277381,-7.024800666970978,-6.794834070087455,-5.926851434020128,-4.474359176395259,-2.5705883434069863,-0.3741170949177821,1.9042059569098657,4.060240004434826,5.878477729249168,7.188827934318461,7.8495218640062365,7.794119538706236,7.008126045110368,5.560890492089182,3.572098302491793,1.2277652292243761,-1.2622483147989967,-3.6598357843442897,-5.744397632081171,-7.312035543394781,-8.216560913072701,-8.363519582537188,-7.739387809753721,-6.3941700397610886,-4.455604659546936,-2.0989191400029306,2.0989191400029306,4.455604659546936,6.3941700397610886,7.739387809753721,8.363519582537188,8.216560913072701,7.312035543394781,5.744397632081171,3.6598357843442897,1.2622483147989967,-1.2277652292243761,-3.572098302491793,-5.560890492089182,-7.008126045110368,-7.794119538706236,-7.8495218640062365,-7.188827934318461,-5.878477729249168,-4.060240004434826,-1.9042059569098657,0.3741170949177821,2.5705883434069863,4.474359176395259,5.926851434020128,6.794834070087455,7.024800666970978,6.601717490277381,5.5953555589315025,4.103594095869217,2.291732054046535,0.32384638582820835,-1.6001244084977326,-3.3183264078776364,-4.6657370430243965,-5.546162777804934,-5.881526679911601,-5.676594058014988,-4.956810639557911,-3.8239315965726473,-2.384583367499495,-0.7985280947392004,0.79641837205699,2.2395669269039082,3.4188810588414222,4.225654004311862,4.615986295671221,4.5630333687957485,4.104424965064013,3.2933281934247436,2.2309436543520915,1.0206613578944126,-0.21266001656780875,-1.3594278194629672,-2.316413970234189,-3.008515662127692,-3.387890400586359,-3.436792477963944,-3.1740357819109826,-2.6379024221550607,-1.901066041445712,-1.0355561755238334,-0.13837005360103227,0.7173491462951687,1.4440432441503344,1.997244910823135,2.3243488015699056,2.4258809031020663,2.2935970026955883,1.9714028076793162,1.4877754982896167,0.9130370848732287,0.29310185706727154,-0.2998217334066292,-0.8244152553688672,-1.229205046578654,-1.4936336061684077,-1.6001599002343205,-1.554102544262964,-1.3724905523314423,-1.080279936667202,-0.7188506893290195,-0.31920789095358526,0.06882097245763397,0.42289363260830276,0.7001011476780283,0.8967635939589469,0.98684791300276,0.9872744934362394,0.8914052595020254,0.7306636809432207,0.5138751566015052,0.2757772055337032,0.033299461333931885,-0.18735777924829844,-0.36845461030966364,-0.5006642487638799,-0.5701450240853309,-0.5867272984911475,-0.5418188505109167,-0.4603623729371087,-0.33789413882647434,-0.20587280354035697,-0.06212748348556549,0.06549665208314027,0.1778462470884217,0.25913171630663884,0.3083927502606358,0.3261508207043803,0.30835777302169975,0.2707407804950766,0.20553962289316507,0.13761223249113266,0.056861421341490165,-0.011891480464539514,-0.07744511801681248,-0.1242798547967973,-0.15533718866731216,-0.17034308630755926,-0.1634965581218513,-0.14961633188532397,-0.11551787148568599,-0.08406640257469197,-0.04102245657983675,-0.005679146360368422,0.028476227670905022,0.05640906499731489,0.07113403294210274,0.08490083611465628,0.0800165558078738,0.07757588356391662,0.06138500760662793,0.0451660848271237,0.028387387899476667,0.005443346463993276,-0.005715493316742006,-0.024637391047762174,-0.03111376029377172,-0.03643197687814111,-0.04131376907465045,-0.0328927154513693,-0.03331990995549233,-0.023128433856885466,-0.012546700972476928,-0.01023176957660304,0.004205606672021854,0.009215266047994854,0.008303107421544198,0.019167935994999837,0.021085250150978074,0.00954842022758919,0.0015527878687986733,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
11 changes: 10 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ type GetData2D = (
sigma: number[],
dataToReturn: number,
srcPositionRelativeSet: number[]
) => any
) => {
dataX: number[],
dataY: number[],
dataEz: number[],
rows: number,
cols: number,
timeStep: number,
max: number,
min: number,
}

type GetData1D = (
condition: number[],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "napi-addon-fdtd",
"version": "3.2.16",
"version": "3.3.2",
"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",
Expand Down
11 changes: 6 additions & 5 deletions src/FDTD/1d-pml/fdtd-pml-1d.h → src/fdtd/1d-pml/fdtd-pml-1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FdtdPml1D {
const double tau = 8.0;

// Position index of source.
size_t src_position = 85;
size_t src_position = 120;

// 1D grid size.
static const size_t grid_size = 500;
Expand Down Expand Up @@ -114,12 +114,12 @@ class FdtdPml1D {


// Taflove, pp 292, Eq 7.60a.
for(int i = 0; i <= pml_width; ++i) {
double sigma_in_pml = std::pow((i+1) / pml_width, m) * sigma_max;
for(int i = 0; i < pml_width; ++i) {
double sigma_in_pml = std::pow((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;
sigma[pml_width-i-1] = sigma_in_pml;
}


Expand Down Expand Up @@ -154,7 +154,7 @@ class FdtdPml1D {
std::vector<double> &vect_hy)
{
// Insert source in certain space grid.
double t = time_step * dt;
double t = (double)time_step * dt;
double source = std::exp(-(std::pow((t0 - t) / tau, 2))) * std::cos(omega * t);
ex[src_position] += source;

Expand All @@ -166,6 +166,7 @@ class FdtdPml1D {
for(int i = 1; i < grid_size-1; ++i) {
ex[i] = C[i] * ex[i] - D[i] * (hy[i] - hy[i-1]);
}
ex[grid_size-1] = ex[grid_size-2];
// ex[grid_size-1] = ex[grid_size-2];

for(int i = 0; i < grid_size; ++i) {
Expand Down
25 changes: 14 additions & 11 deletions src/FDTD/2d-pml/fdtd-pml-2d.h → src/fdtd/2d-pml/fdtd-pml-2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ class FdtdPml2D
{

// Grid sizes.
static const size_t pml_width = 60;

static const size_t rows = 200 + pml_width*2;
static const size_t cols = 200 + pml_width*2;
// static const size_t pml_width = 2;

// static const size_t rows = 6 + pml_width*2;
// static const size_t cols = 6 + pml_width*2;
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;

// Set source position.
size_t src_row = rows / 2;
Expand Down Expand Up @@ -59,9 +54,6 @@ class FdtdPml2D

double gaz[rows][cols];

// Max simulation time.
const size_t max_time = 500;

// Space grid step.
const double ddx = 1.0e-3;
const double ddy = ddx;
Expand Down Expand Up @@ -97,10 +89,21 @@ class FdtdPml2D


public:
// Getters.
static size_t GetRows() {
return rows - pml_width * 2;
}

static size_t GetCols() {
return cols - pml_width * 2;
}


void SetParams(std::vector<std::vector<double>>& eps,
std::vector<std::vector<double>>& mu,
std::vector<std::vector<double>>& sigma)
{
time_step = 0;

// Init field arrays.
std::fill_n(&dz[0][0], rows * cols, 0.0);
Expand Down
5 changes: 0 additions & 5 deletions src/globals.h

This file was deleted.

Loading

0 comments on commit 9a77bd5

Please sign in to comment.