From 2cdea2b8b54d59237edbb2072955f3bcbcf8c092 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 6 Jun 2019 22:25:15 +0200 Subject: Started implementing PML inside domain --- Source/BoundaryConditions/PML.cpp | 90 ++++++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 10 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index f780f335c..d9f771fa3 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -407,13 +407,76 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } +// BoxArray +// PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) +// { +// Box domain = geom.Domain(); +// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { +// if ( ! geom.isPeriodic(idim) ) { +// domain.grow(idim, ncell); +// } +// } +// +// BoxList bl; +// for (int i = 0, N = grid_ba.size(); i < N; ++i) +// { +// const Box& grid_bx = grid_ba[i]; +// const IntVect& grid_bx_sz = grid_bx.size(); +// AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, +// "Consider using larger amr.blocking_factor"); +// +// Box bx = grid_bx; +// bx.grow(ncell); +// bx &= domain; +// +// Vector bndryboxes; +// #if (AMREX_SPACEDIM == 3) +// int kbegin = -1, kend = 1; +// #else +// int kbegin = 0, kend = 0; +// #endif +// for (int kk = kbegin; kk <= kend; ++kk) { +// for (int jj = -1; jj <= 1; ++jj) { +// for (int ii = -1; ii <= 1; ++ii) { +// if (ii != 0 || jj != 0 || kk != 0) { +// Box b = grid_bx; +// b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); +// b &= bx; +// if (b.ok()) { +// bndryboxes.push_back(b); +// } +// } +// } +// } +// } +// +// const BoxList& noncovered = grid_ba.complementIn(bx); +// for (const Box& b : noncovered) { +// for (const auto& bb : bndryboxes) { +// Box ib = b & bb; +// if (ib.ok()) { +// bl.push_back(ib); +// } +// } +// } +// } +// +// BoxArray ba(bl); +// ba.removeOverlap(false); +// +// return ba; +// } + BoxArray PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) { Box domain = geom.Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom.isPeriodic(idim) ) { - domain.grow(idim, ncell); + // Create the simulation area (inside the whole domain) (only if non-periodical boundary conditions) + domain.grow(idim, -ncell); // I don't know if that works + // domain.growHi(idim, -ncell); + // domain.growLo(idim, -ncell); } } @@ -421,13 +484,16 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, for (int i = 0, N = grid_ba.size(); i < N; ++i) { const Box& grid_bx = grid_ba[i]; - const IntVect& grid_bx_sz = grid_bx.size(); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, - "Consider using larger amr.blocking_factor"); + // const IntVect& grid_bx_sz = grid_bx.size(); + // AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, + // "Consider using larger amr.blocking_factor"); Box bx = grid_bx; - bx.grow(ncell); - bx &= domain; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + bx.grow(idim, -ncell); + } + bx &= domain; // is this step necessary? We're always inside the domain by doing so, even if there are some periodical boundary conditions... + const IntVect& bx_sz = bx.size(); Vector bndryboxes; #if (AMREX_SPACEDIM == 3) @@ -439,9 +505,10 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, for (int jj = -1; jj <= 1; ++jj) { for (int ii = -1; ii <= 1; ++ii) { if (ii != 0 || jj != 0 || kk != 0) { - Box b = grid_bx; - b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); - b &= bx; + Box b = bx; //grid_bx; + // b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b.shift(bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b &= grid_bx;// bx; if (b.ok()) { bndryboxes.push_back(b); } @@ -450,7 +517,10 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, } } - const BoxList& noncovered = grid_ba.complementIn(bx); + // const BoxList& grid_ba_reduced = grid_ba.complementIn(bx); + BoxArray domain_ba = BoxArray(domain); + + const BoxList& noncovered = domain_ba.complementIn(grid_bx); //grid_ba.complementIn(bx); for (const Box& b : noncovered) { for (const auto& bb : bndryboxes) { Box ib = b & bb; -- cgit v1.2.3 From 2a7dc97bceb17d3f96e9d9f00792938d7f65346e Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 7 Jun 2019 01:27:20 +0200 Subject: Added printing boxes --- Source/BoundaryConditions/PML.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index d9f771fa3..40b9cba78 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -534,6 +534,15 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, BoxArray ba(bl); ba.removeOverlap(false); + BoxList bl_2 = BoxList(ba); + + amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; + amrex::Print() << "[" << std::endl; + for (const Box& b: bl_2) { + amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< Date: Fri, 7 Jun 2019 17:54:29 +0200 Subject: Improved the PML repartition. 2D geometry for now. Problem with Bottom left corner. --- Examples/Tests/PML/inputs2d | 2 +- Source/BoundaryConditions/PML.cpp | 134 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 130 insertions(+), 6 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Examples/Tests/PML/inputs2d b/Examples/Tests/PML/inputs2d index 5b936a333..dc1f136ef 100644 --- a/Examples/Tests/PML/inputs2d +++ b/Examples/Tests/PML/inputs2d @@ -2,7 +2,7 @@ max_step = 300 # number of grid points -amr.n_cell = 128 512 +amr.n_cell = 128 256 # Maximum allowable size of each subdomain in the problem domain; # this is used to decompose the domain for parallel calculations. diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 40b9cba78..0a47c5d84 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -471,6 +471,10 @@ BoxArray PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) { Box domain = geom.Domain(); + + IntVect limInfDomain = domain.smallEnd(); + IntVect limSupDomain = domain.bigEnd(); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom.isPeriodic(idim) ) { // Create the simulation area (inside the whole domain) (only if non-periodical boundary conditions) @@ -505,14 +509,128 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, for (int jj = -1; jj <= 1; ++jj) { for (int ii = -1; ii <= 1; ++ii) { if (ii != 0 || jj != 0 || kk != 0) { - Box b = bx; //grid_bx; + // if ((ii != 0 && jj == 0 && kk == 0)||(ii == 0 && jj != 0 && kk == 0)||(ii == 0 && jj == 0 && kk != 0)) { + if(ii!=0 && jj!=0){ + int xlimg, xlimd, ylimg, ylimd; + if (ii == -1){ + xlimg = grid_bx.smallEnd()[0]; + xlimd = limInfDomain[0]; + } + else if (ii = 1) { + xlimg = grid_bx.bigEnd()[0]; + xlimd = limSupDomain[0]; + } + + if (jj == -1){ + ylimg = grid_bx.smallEnd()[1]; + ylimd = limInfDomain[1]; + } + else if (jj = 1){ + ylimg = grid_bx.bigEnd()[1]; + ylimd = limSupDomain[1]; + } + + if (xlimd==xlimg && ylimd==ylimg){ + amrex::Print() << "INDICES : i = " << ii << " j = " << jj << std::endl; + Box b = grid_bx; //grid_bx; + b.shift(bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b.shift(ncell * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b &= grid_bx;// grid_bx; + amrex::Print() << "BOITE = [" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< Date: Fri, 7 Jun 2019 19:23:57 +0200 Subject: PML.cpp : most basic function that does PML in domain - works for 3D PML_Cplx.cpp : more complex function to get rid of the small squares. Works for 2D only for the moment. Problem with Bottom right corner (from AMReX removeOverlap function) --- Source/BoundaryConditions/PML.cpp | 230 ++++---- Source/BoundaryConditions/PML_Cplx.cpp | 958 +++++++++++++++++++++++++++++++++ 2 files changed, 1073 insertions(+), 115 deletions(-) create mode 100644 Source/BoundaryConditions/PML_Cplx.cpp (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 0a47c5d84..7f1b23910 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -510,125 +510,125 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, for (int ii = -1; ii <= 1; ++ii) { if (ii != 0 || jj != 0 || kk != 0) { // if ((ii != 0 && jj == 0 && kk == 0)||(ii == 0 && jj != 0 && kk == 0)||(ii == 0 && jj == 0 && kk != 0)) { - if(ii!=0 && jj!=0){ - int xlimg, xlimd, ylimg, ylimd; - if (ii == -1){ - xlimg = grid_bx.smallEnd()[0]; - xlimd = limInfDomain[0]; - } - else if (ii = 1) { - xlimg = grid_bx.bigEnd()[0]; - xlimd = limSupDomain[0]; - } - - if (jj == -1){ - ylimg = grid_bx.smallEnd()[1]; - ylimd = limInfDomain[1]; - } - else if (jj = 1){ - ylimg = grid_bx.bigEnd()[1]; - ylimd = limSupDomain[1]; - } - - if (xlimd==xlimg && ylimd==ylimg){ - amrex::Print() << "INDICES : i = " << ii << " j = " << jj << std::endl; - Box b = grid_bx; //grid_bx; - b.shift(bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); - b.shift(ncell * IntVect{AMREX_D_DECL(ii,jj,kk)}); - b &= grid_bx;// grid_bx; - amrex::Print() << "BOITE = [" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< +#include +#include + +#include +#include + +#include + +#ifdef _OPENMP +#include +#endif + +using namespace amrex; + +namespace +{ + static void FillLo (int idim, Sigma& sigma, Sigma& sigma_star, + const Box& overlap, const Box& grid, Real fac) + { + int glo = grid.smallEnd(idim); + int olo = overlap.smallEnd(idim); + int ohi = overlap.bigEnd(idim); + int slo = sigma.m_lo; + int sslo = sigma_star.m_lo; + for (int i = olo; i <= ohi+1; ++i) + { + Real offset = static_cast(glo-i); + sigma[i-slo] = fac*(offset*offset); + } + for (int i = olo; i <= ohi; ++i) + { + Real offset = static_cast(glo-i) - 0.5; + sigma_star[i-sslo] = fac*(offset*offset); + } + } + + static void FillHi (int idim, Sigma& sigma, Sigma& sigma_star, + const Box& overlap, const Box& grid, Real fac) + { + int ghi = grid.bigEnd(idim); + int olo = overlap.smallEnd(idim); + int ohi = overlap.bigEnd(idim); + int slo = sigma.m_lo; + int sslo = sigma_star.m_lo; + for (int i = olo; i <= ohi+1; ++i) + { + Real offset = static_cast(i-ghi-1); + sigma[i-slo] = fac*(offset*offset); + } + for (int i = olo; i <= ohi; ++i) + { + Real offset = static_cast(i-ghi) - 0.5; + sigma_star[i-sslo] = fac*(offset*offset); + } + } + + static void FillZero (int idim, Sigma& sigma, Sigma& sigma_star, const Box& overlap) + { + int olo = overlap.smallEnd(idim); + int ohi = overlap.bigEnd(idim); + int slo = sigma.m_lo; + int sslo = sigma_star.m_lo; + std::fill(sigma.begin()+(olo-slo), sigma.begin()+(ohi+2-slo), 0.0); + std::fill(sigma_star.begin()+(olo-sslo), sigma_star.begin()+(ohi+1-sslo), 0.0); + } +} + +SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) +{ + BL_ASSERT(box.cellCentered()); + + const IntVect& sz = box.size(); + const int* lo = box.loVect(); + const int* hi = box.hiVect(); + + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + sigma [idim].resize(sz[idim]+1); + sigma_star [idim].resize(sz[idim] ); + sigma_fac [idim].resize(sz[idim]+1); + sigma_star_fac[idim].resize(sz[idim] ); + + sigma [idim].m_lo = lo[idim]; + sigma [idim].m_hi = hi[idim]+1; + sigma_star [idim].m_lo = lo[idim]; + sigma_star [idim].m_hi = hi[idim]; + sigma_fac [idim].m_lo = lo[idim]; + sigma_fac [idim].m_hi = hi[idim]+1; + sigma_star_fac[idim].m_lo = lo[idim]; + sigma_star_fac[idim].m_hi = hi[idim]; + } + + Array fac; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); + } + + const std::vector >& isects = grids.intersections(box, false, ncell); + + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + int jdim = (idim+1) % AMREX_SPACEDIM; +#if (AMREX_SPACEDIM == 3) + int kdim = (idim+2) % AMREX_SPACEDIM; +#endif + + Vector direct_faces, side_faces, direct_side_edges, side_side_edges, corners; + for (const auto& kv : isects) + { + const Box& grid_box = grids[kv.first]; + + if (amrex::grow(grid_box, idim, ncell).intersects(box)) + { + direct_faces.push_back(kv.first); + } + else if (amrex::grow(grid_box, jdim, ncell).intersects(box)) + { + side_faces.push_back(kv.first); + } +#if (AMREX_SPACEDIM == 3) + else if (amrex::grow(grid_box, kdim, ncell).intersects(box)) + { + side_faces.push_back(kv.first); + } + else if (amrex::grow(amrex::grow(grid_box,idim,ncell), + jdim,ncell).intersects(box)) + { + direct_side_edges.push_back(kv.first); + } + else if (amrex::grow(amrex::grow(grid_box,idim,ncell), + kdim,ncell).intersects(box)) + { + direct_side_edges.push_back(kv.first); + } + else if (amrex::grow(amrex::grow(grid_box,jdim,ncell), + kdim,ncell).intersects(box)) + { + side_side_edges.push_back(kv.first); + } +#endif + else + { + corners.push_back(kv.first); + } + } + + for (auto gid : corners) + { + const Box& grid_box = grids[gid]; + + Box lobox = amrex::adjCellLo(grid_box, idim, ncell); + lobox.grow(jdim,ncell); +#if (AMREX_SPACEDIM == 3) + lobox.grow(kdim,ncell); +#endif + Box looverlap = lobox & box; + if (looverlap.ok()) { + FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + } + + Box hibox = amrex::adjCellHi(grid_box, idim, ncell); + hibox.grow(jdim,ncell); +#if (AMREX_SPACEDIM == 3) + hibox.grow(kdim,ncell); +#endif + Box hioverlap = hibox & box; + if (hioverlap.ok()) { + FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + } + + if (!looverlap.ok() && !hioverlap.ok()) { + amrex::Abort("SigmaBox::SigmaBox(): corners, how did this happen?\n"); + } + } + +#if (AMREX_SPACEDIM == 3) + for (auto gid : side_side_edges) + { + const Box& grid_box = grids[gid]; + const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; + if (overlap.ok()) { + FillZero(idim, sigma[idim], sigma_star[idim], overlap); + } else { + amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); + } + } + + for (auto gid : direct_side_edges) + { + const Box& grid_box = grids[gid]; + + Box lobox = amrex::adjCellLo(grid_box, idim, ncell); + Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; + if (looverlap.ok()) { + FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + } + + Box hibox = amrex::adjCellHi(grid_box, idim, ncell); + Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; + if (hioverlap.ok()) { + FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + } + + if (!looverlap.ok() && !hioverlap.ok()) { + amrex::Abort("SigmaBox::SigmaBox(): direct_side_edges, how did this happen?\n"); + } + } +#endif + + for (auto gid : side_faces) + { + const Box& grid_box = grids[gid]; +#if (AMREX_SPACEDIM == 2) + const Box& overlap = amrex::grow(grid_box,jdim,ncell) & box; +#else + const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; +#endif + if (overlap.ok()) { + FillZero(idim, sigma[idim], sigma_star[idim], overlap); + } else { + amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); + } + } + + for (auto gid : direct_faces) + { + const Box& grid_box = grids[gid]; + + const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); + Box looverlap = lobox & box; + if (looverlap.ok()) { + FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + } + + const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); + Box hioverlap = hibox & box; + if (hioverlap.ok()) { + FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + } + + if (!looverlap.ok() && !hioverlap.ok()) { + amrex::Abort("SigmaBox::SigmaBox(): direct faces, how did this happen?\n"); + } + } + + if (direct_faces.size() > 1) { + amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); + } + } +} + +void +SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) +{ + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + for (int i = 0, N = sigma_star[idim].size(); i < N; ++i) + { + if (sigma_star[idim][i] == 0.0) + { + sigma_star_fac[idim][i] = 1.0; + } + else + { + sigma_star_fac[idim][i] = std::exp(-sigma_star[idim][i]*dt); + } + } + } +} + +void +SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) +{ + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + for (int i = 0, N = sigma[idim].size(); i < N; ++i) + { + if (sigma[idim][i] == 0.0) + { + sigma_fac[idim][i] = 1.0; + } + else + { + sigma_fac[idim][i] = std::exp(-sigma[idim][i]*dt); + } + } + } +} + +MultiSigmaBox::MultiSigmaBox (const BoxArray& ba, const DistributionMapping& dm, + const BoxArray& grid_ba, const Real* dx, int ncell, int delta) + : FabArray(ba,dm,1,0,MFInfo(), + FabFactory(grid_ba,dx,ncell,delta)) +{} + +void +MultiSigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) +{ + if (dt == dt_B) return; + + dt_B = dt; + +#ifdef _OPENMP +#pragma omp parallel +#endif + for (MFIter mfi(*this); mfi.isValid(); ++mfi) + { + (*this)[mfi].ComputePMLFactorsB(dx, dt); + } +} + +void +MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) +{ + if (dt == dt_E) return; + + dt_E = dt; + +#ifdef _OPENMP +#pragma omp parallel +#endif + for (MFIter mfi(*this); mfi.isValid(); ++mfi) + { + (*this)[mfi].ComputePMLFactorsE(dx, dt); + } +} + +PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, + const Geometry* geom, const Geometry* cgeom, + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window) + : m_geom(geom), + m_cgeom(cgeom) +{ + const BoxArray& ba = MakeBoxArray(*geom, grid_ba, ncell); + if (ba.size() == 0) { + m_ok = false; + return; + } else { + m_ok = true; + } + + DistributionMapping dm{ba}; + + int nge = 2; + int ngb = 2; + int ngf = (do_moving_window) ? 2 : 0; + if (WarpX::maxwell_fdtd_solver_id == 1) ngf = std::max( ngf, 1 ); + + pml_E_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::Ex_nodal_flag), dm, 3, nge)); + pml_E_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::Ey_nodal_flag), dm, 3, nge)); + pml_E_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Ez_nodal_flag), dm, 3, nge)); + pml_B_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::Bx_nodal_flag), dm, 2, ngb)); + pml_B_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::By_nodal_flag), dm, 2, ngb)); + pml_B_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Bz_nodal_flag), dm, 2, ngb)); + + pml_E_fp[0]->setVal(0.0); + pml_E_fp[1]->setVal(0.0); + pml_E_fp[2]->setVal(0.0); + pml_B_fp[0]->setVal(0.0); + pml_B_fp[1]->setVal(0.0); + pml_B_fp[2]->setVal(0.0); + + if (do_dive_cleaning) + { + pml_F_fp.reset(new MultiFab(amrex::convert(ba,IntVect::TheUnitVector()), dm, 3, ngf)); + pml_F_fp->setVal(0.0); + } + + sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba, geom->CellSize(), ncell, delta)); + + if (cgeom) + { + + nge = 1; + ngb = 1; + + BoxArray grid_cba = grid_ba; + grid_cba.coarsen(ref_ratio); + const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba, ncell); + + DistributionMapping cdm{cba}; + + pml_E_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::Ex_nodal_flag), cdm, 3, nge)); + pml_E_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::Ey_nodal_flag), cdm, 3, nge)); + pml_E_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::Ez_nodal_flag), cdm, 3, nge)); + pml_B_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::Bx_nodal_flag), cdm, 2, ngb)); + pml_B_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::By_nodal_flag), cdm, 2, ngb)); + pml_B_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::Bz_nodal_flag), cdm, 2, ngb)); + + pml_E_cp[0]->setVal(0.0); + pml_E_cp[1]->setVal(0.0); + pml_E_cp[2]->setVal(0.0); + pml_B_cp[0]->setVal(0.0); + pml_B_cp[1]->setVal(0.0); + pml_B_cp[2]->setVal(0.0); + + if (do_dive_cleaning) + { + pml_F_cp.reset(new MultiFab(amrex::convert(cba,IntVect::TheUnitVector()), cdm, 3, ngf)); + pml_F_cp->setVal(0.0); + } + + sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); + } + +} + +// BoxArray +// PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) +// { +// Box domain = geom.Domain(); +// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { +// if ( ! geom.isPeriodic(idim) ) { +// domain.grow(idim, ncell); +// } +// } +// +// BoxList bl; +// for (int i = 0, N = grid_ba.size(); i < N; ++i) +// { +// const Box& grid_bx = grid_ba[i]; +// const IntVect& grid_bx_sz = grid_bx.size(); +// AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, +// "Consider using larger amr.blocking_factor"); +// +// Box bx = grid_bx; +// bx.grow(ncell); +// bx &= domain; +// +// Vector bndryboxes; +// #if (AMREX_SPACEDIM == 3) +// int kbegin = -1, kend = 1; +// #else +// int kbegin = 0, kend = 0; +// #endif +// for (int kk = kbegin; kk <= kend; ++kk) { +// for (int jj = -1; jj <= 1; ++jj) { +// for (int ii = -1; ii <= 1; ++ii) { +// if (ii != 0 || jj != 0 || kk != 0) { +// Box b = grid_bx; +// b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); +// b &= bx; +// if (b.ok()) { +// bndryboxes.push_back(b); +// } +// } +// } +// } +// } +// +// const BoxList& noncovered = grid_ba.complementIn(bx); +// for (const Box& b : noncovered) { +// for (const auto& bb : bndryboxes) { +// Box ib = b & bb; +// if (ib.ok()) { +// bl.push_back(ib); +// } +// } +// } +// } +// +// BoxArray ba(bl); +// ba.removeOverlap(false); +// +// return ba; +// } + +BoxArray +PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) +{ + Box domain = geom.Domain(); + + IntVect limInfDomain = domain.smallEnd(); + IntVect limSupDomain = domain.bigEnd(); + + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + if ( ! geom.isPeriodic(idim) ) { + // Create the simulation area (inside the whole domain) (only if non-periodical boundary conditions) + domain.grow(idim, -ncell); // I don't know if that works + // domain.growHi(idim, -ncell); + // domain.growLo(idim, -ncell); + } + } + + BoxList bl; + for (int i = 0, N = grid_ba.size(); i < N; ++i) + { + const Box& grid_bx = grid_ba[i]; + // const IntVect& grid_bx_sz = grid_bx.size(); + // AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, + // "Consider using larger amr.blocking_factor"); + + Box bx = grid_bx; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + bx.grow(idim, -ncell); + } + bx &= domain; // is this step necessary? We're always inside the domain by doing so, even if there are some periodical boundary conditions... + const IntVect& bx_sz = bx.size(); + + Vector bndryboxes; +#if (AMREX_SPACEDIM == 3) + int kbegin = -1, kend = 1; +#else + int kbegin = 0, kend = 0; +#endif + for (int kk = kbegin; kk <= kend; ++kk) { + for (int jj = -1; jj <= 1; ++jj) { + for (int ii = -1; ii <= 1; ++ii) { + if (ii != 0 || jj != 0 || kk != 0) { + // if ((ii != 0 && jj == 0 && kk == 0)||(ii == 0 && jj != 0 && kk == 0)||(ii == 0 && jj == 0 && kk != 0)) { + if(ii!=0 && jj!=0){ + int xlimg, xlimd, ylimg, ylimd; + if (ii == -1){ + xlimg = grid_bx.smallEnd()[0]; + xlimd = limInfDomain[0]; + } + else if (ii = 1) { + xlimg = grid_bx.bigEnd()[0]; + xlimd = limSupDomain[0]; + } + + if (jj == -1){ + ylimg = grid_bx.smallEnd()[1]; + ylimd = limInfDomain[1]; + } + else if (jj = 1){ + ylimg = grid_bx.bigEnd()[1]; + ylimd = limSupDomain[1]; + } + + if (xlimd==xlimg && ylimd==ylimg){ + amrex::Print() << "INDICES : i = " << ii << " j = " << jj << std::endl; + Box b = grid_bx; //grid_bx; + b.shift(bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b.shift(ncell * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b &= grid_bx;// grid_bx; + amrex::Print() << "BOITE = [" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "<ComputePMLFactorsB(m_geom->CellSize(), dt); + sigba_fp->ComputePMLFactorsE(m_geom->CellSize(), dt); + } + if (sigba_cp) { + sigba_cp->ComputePMLFactorsB(m_cgeom->CellSize(), dt); + sigba_cp->ComputePMLFactorsE(m_cgeom->CellSize(), dt); + } +} + +std::array +PML::GetE_fp () +{ + return {pml_E_fp[0].get(), pml_E_fp[1].get(), pml_E_fp[2].get()}; +} + +std::array +PML::GetB_fp () +{ + return {pml_B_fp[0].get(), pml_B_fp[1].get(), pml_B_fp[2].get()}; +} + +std::array +PML::GetE_cp () +{ + return {pml_E_cp[0].get(), pml_E_cp[1].get(), pml_E_cp[2].get()}; +} + +std::array +PML::GetB_cp () +{ + return {pml_B_cp[0].get(), pml_B_cp[1].get(), pml_B_cp[2].get()}; +} + +MultiFab* +PML::GetF_fp () +{ + return pml_F_fp.get(); +} + +MultiFab* +PML::GetF_cp () +{ + return pml_F_cp.get(); +} + +void +PML::ExchangeB (const std::array& B_fp, + const std::array& B_cp) +{ + ExchangeB(PatchType::fine, B_fp); + ExchangeB(PatchType::coarse, B_cp); +} + +void +PML::ExchangeB (PatchType patch_type, + const std::array& Bp) +{ + if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) + { + Exchange(*pml_B_fp[0], *Bp[0], *m_geom); + Exchange(*pml_B_fp[1], *Bp[1], *m_geom); + Exchange(*pml_B_fp[2], *Bp[2], *m_geom); + } + else if (patch_type == PatchType::coarse && pml_B_cp[0] && Bp[0]) + { + Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom); + Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom); + Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom); + } +} + +void +PML::ExchangeE (const std::array& E_fp, + const std::array& E_cp) +{ + ExchangeE(PatchType::fine, E_fp); + ExchangeE(PatchType::coarse, E_cp); +} + +void +PML::ExchangeE (PatchType patch_type, + const std::array& Ep) +{ + if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) + { + Exchange(*pml_E_fp[0], *Ep[0], *m_geom); + Exchange(*pml_E_fp[1], *Ep[1], *m_geom); + Exchange(*pml_E_fp[2], *Ep[2], *m_geom); + } + else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) + { + Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom); + Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom); + Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom); + } +} + +void +PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) +{ + ExchangeF(PatchType::fine, F_fp); + ExchangeF(PatchType::coarse, F_cp); +} + +void +PML::ExchangeF (PatchType patch_type, MultiFab* Fp) +{ + if (patch_type == PatchType::fine && pml_F_fp && Fp) { + Exchange(*pml_F_fp, *Fp, *m_geom); + } else if (patch_type == PatchType::coarse && pml_F_cp && Fp) { + Exchange(*pml_F_cp, *Fp, *m_cgeom); + } +} + +void +PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) +{ + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + const int ncp = pml.nComp(); + const auto& period = geom.periodicity(); + + MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); + + if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data + { + MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); + MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); + if (ncp == 3) { + MultiFab::Add(totpmlmf,pml,2,0,1,0); + } + + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); + +#ifdef _OPENMP +#pragma omp parallel +#endif + for (MFIter mfi(reg); mfi.isValid(); ++mfi) + { + const FArrayBox& src = tmpregmf[mfi]; + FArrayBox& dst = reg[mfi]; + const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); + for (const Box& bx : bl) + { + dst.copy(src, bx, 0, bx, 0, 1); + } + } + } + + // Copy from regular data to PML's first component + // Zero out the second (and third) component + MultiFab::Copy(tmpregmf,reg,0,0,1,0); + tmpregmf.setVal(0.0, 1, ncp-1, 0); + pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); +} + +void +PML::FillBoundary () +{ + FillBoundaryE(); + FillBoundaryB(); + FillBoundaryF(); +} + +void +PML::FillBoundaryE () +{ + FillBoundaryE(PatchType::fine); + FillBoundaryE(PatchType::coarse); +} + +void +PML::FillBoundaryE (PatchType patch_type) +{ + if (patch_type == PatchType::fine && pml_E_fp[0] && pml_E_fp[0]->nGrowVect().max() > 0) + { + const auto& period = m_geom->periodicity(); + Vector mf{pml_E_fp[0].get(),pml_E_fp[1].get(),pml_E_fp[2].get()}; + amrex::FillBoundary(mf, period); + } + else if (patch_type == PatchType::coarse && pml_E_cp[0] && pml_E_cp[0]->nGrowVect().max() > 0) + { + const auto& period = m_cgeom->periodicity(); + Vector mf{pml_E_cp[0].get(),pml_E_cp[1].get(),pml_E_cp[2].get()}; + amrex::FillBoundary(mf, period); + } +} + +void +PML::FillBoundaryB () +{ + FillBoundaryB(PatchType::fine); + FillBoundaryB(PatchType::coarse); +} + +void +PML::FillBoundaryB (PatchType patch_type) +{ + if (patch_type == PatchType::fine && pml_B_fp[0]) + { + const auto& period = m_geom->periodicity(); + Vector mf{pml_B_fp[0].get(),pml_B_fp[1].get(),pml_B_fp[2].get()}; + amrex::FillBoundary(mf, period); + } + else if (patch_type == PatchType::coarse && pml_B_cp[0]) + { + const auto& period = m_cgeom->periodicity(); + Vector mf{pml_B_cp[0].get(),pml_B_cp[1].get(),pml_B_cp[2].get()}; + amrex::FillBoundary(mf, period); + } +} + +void +PML::FillBoundaryF () +{ + FillBoundaryF(PatchType::fine); + FillBoundaryF(PatchType::coarse); +} + +void +PML::FillBoundaryF (PatchType patch_type) +{ + if (patch_type == PatchType::fine && pml_F_fp && pml_F_fp->nGrowVect().max() > 0) + { + const auto& period = m_geom->periodicity(); + pml_F_fp->FillBoundary(period); + } + else if (patch_type == PatchType::coarse && pml_F_cp && pml_F_cp->nGrowVect().max() > 0) + { + const auto& period = m_cgeom->periodicity(); + pml_F_cp->FillBoundary(period); + } +} + +void +PML::CheckPoint (const std::string& dir) const +{ + if (pml_E_fp[0]) + { + VisMF::Write(*pml_E_fp[0], dir+"_Ex_fp"); + VisMF::Write(*pml_E_fp[1], dir+"_Ey_fp"); + VisMF::Write(*pml_E_fp[2], dir+"_Ez_fp"); + VisMF::Write(*pml_B_fp[0], dir+"_Bx_fp"); + VisMF::Write(*pml_B_fp[1], dir+"_By_fp"); + VisMF::Write(*pml_B_fp[2], dir+"_Bz_fp"); + } + + if (pml_E_cp[0]) + { + VisMF::Write(*pml_E_cp[0], dir+"_Ex_cp"); + VisMF::Write(*pml_E_cp[1], dir+"_Ey_cp"); + VisMF::Write(*pml_E_cp[2], dir+"_Ez_cp"); + VisMF::Write(*pml_B_cp[0], dir+"_Bx_cp"); + VisMF::Write(*pml_B_cp[1], dir+"_By_cp"); + VisMF::Write(*pml_B_cp[2], dir+"_Bz_cp"); + } +} + +void +PML::Restart (const std::string& dir) +{ + if (pml_E_fp[0]) + { + VisMF::Read(*pml_E_fp[0], dir+"_Ex_fp"); + VisMF::Read(*pml_E_fp[1], dir+"_Ey_fp"); + VisMF::Read(*pml_E_fp[2], dir+"_Ez_fp"); + VisMF::Read(*pml_B_fp[0], dir+"_Bx_fp"); + VisMF::Read(*pml_B_fp[1], dir+"_By_fp"); + VisMF::Read(*pml_B_fp[2], dir+"_Bz_fp"); + } + + if (pml_E_cp[0]) + { + VisMF::Read(*pml_E_cp[0], dir+"_Ex_cp"); + VisMF::Read(*pml_E_cp[1], dir+"_Ey_cp"); + VisMF::Read(*pml_E_cp[2], dir+"_Ez_cp"); + VisMF::Read(*pml_B_cp[0], dir+"_Bx_cp"); + VisMF::Read(*pml_B_cp[1], dir+"_By_cp"); + VisMF::Read(*pml_B_cp[2], dir+"_Bz_cp"); + } +} -- cgit v1.2.3 From dfeb025881fcaaf1ccbea68d0413949e1606c866 Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 7 Jun 2019 19:51:19 +0200 Subject: Added a partial flag for particles in PML (we still have to implement the fact that the flag has to be read in the input file) --- Source/BoundaryConditions/PML.H | 2 +- Source/BoundaryConditions/PML.cpp | 27 ++++++++++++++++++++------- Source/Initialization/WarpXInitData.cpp | 16 ++++++++-------- 3 files changed, 29 insertions(+), 16 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 25dfc7996..e74924a24 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -100,7 +100,7 @@ class PML public: PML (const amrex::BoxArray& ba, const amrex::DistributionMapping& dm, const amrex::Geometry* geom, const amrex::Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window); + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles); void ComputePMLFactors (amrex::Real dt); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7f1b23910..d3b98054c 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -329,7 +329,7 @@ MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const Geometry* geom, const Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window) + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles) : m_geom(geom), m_cgeom(cgeom) { @@ -355,6 +355,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_B_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::By_nodal_flag), dm, 2, ngb)); pml_B_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Bz_nodal_flag), dm, 2, ngb)); + pml_E_fp[0]->setVal(0.0); pml_E_fp[1]->setVal(0.0); pml_E_fp[2]->setVal(0.0); @@ -362,6 +363,17 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_B_fp[1]->setVal(0.0); pml_B_fp[2]->setVal(0.0); + + if (pml_has_particles){ + // pml_J_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::Jx_nodal_flag), dm, 2, ngb)); + // pml_J_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::Jy_nodal_flag), dm, 2, ngb)); + // pml_J_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Jz_nodal_flag), dm, 2, ngb)); + // pml_J_fp[0]->setVal(0.0); + // pml_J_fp[1]->setVal(0.0); + // pml_J_fp[2]->setVal(0.0); + + } + if (do_dive_cleaning) { pml_F_fp.reset(new MultiFab(amrex::convert(ba,IntVect::TheUnitVector()), dm, 3, ngf)); @@ -400,6 +412,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, { pml_F_cp.reset(new MultiFab(amrex::convert(cba,IntVect::TheUnitVector()), cdm, 3, ngf)); pml_F_cp->setVal(0.0); + amrex::Print() << "PML HAS PARTICLES "<< std::endl; } sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); @@ -648,12 +661,12 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, } } } - amrex::Print() << "Printing PML boxes BEFORE cleaning" << std::endl; - amrex::Print() << "[" << std::endl; - for (const Box& b: bl) { - amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< alllohi(6*nprocs,100000); MPI_Allgather(lohi, 6, MPI_INT, alllohi.data(), 6, MPI_INT, ParallelDescriptor::Communicator()); - + BoxList bl{IndexType::TheNodeType()}; for (int i = 0; i < nprocs; ++i) { @@ -252,7 +252,7 @@ WarpX::InitOpenbc () rho_openbc.copy(*rho, 0, 0, 1, rho->nGrow(), 0, gm.periodicity(), FabArrayBase::ADD); const Real* dx = gm.CellSize(); - + warpx_openbc_potential(rho_openbc[myproc].dataPtr(), phi_openbc[myproc].dataPtr(), dx); BoxArray nba = boxArray(lev); -- cgit v1.2.3 From 6dfb11f5875a8d172ba11b4b4bb612f45c6d1f75 Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 7 Jun 2019 20:42:12 +0200 Subject: Added a flag for particles in PMLs --- Source/BoundaryConditions/PML.H | 2 ++ Source/BoundaryConditions/PML.cpp | 15 ++++++++------- Source/Initialization/WarpXInitData.cpp | 4 ++-- Source/WarpX.H | 7 ++++--- Source/WarpX.cpp | 1 + 5 files changed, 17 insertions(+), 12 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index e74924a24..2dfbe7a14 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -151,9 +151,11 @@ private: std::array,3> pml_E_fp; std::array,3> pml_B_fp; + std::array,3> pml_J_fp; std::array,3> pml_E_cp; std::array,3> pml_B_cp; + std::array,3> pml_J_cp; std::unique_ptr pml_F_fp; std::unique_ptr pml_F_cp; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index d3b98054c..bbfc4118b 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -365,12 +365,13 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, if (pml_has_particles){ - // pml_J_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::Jx_nodal_flag), dm, 2, ngb)); - // pml_J_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::Jy_nodal_flag), dm, 2, ngb)); - // pml_J_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Jz_nodal_flag), dm, 2, ngb)); - // pml_J_fp[0]->setVal(0.0); - // pml_J_fp[1]->setVal(0.0); - // pml_J_fp[2]->setVal(0.0); + pml_J_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jx_nodal_flag) + pml_J_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jy_nodal_flag) + pml_J_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jz_nodal_flag) + pml_J_fp[0]->setVal(0.0); + pml_J_fp[1]->setVal(0.0); + pml_J_fp[2]->setVal(0.0); + amrex::Print() << "PML HAS PARTICLES "<< std::endl; } @@ -412,7 +413,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, { pml_F_cp.reset(new MultiFab(amrex::convert(cba,IntVect::TheUnitVector()), cdm, 3, ngf)); pml_F_cp->setVal(0.0); - amrex::Print() << "PML HAS PARTICLES "<< std::endl; + } sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 4e0a6c20e..bc7c2219a 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -134,13 +134,13 @@ WarpX::InitPML () if (do_pml) { pml[0].reset(new PML(boxArray(0), DistributionMap(0), &Geom(0), nullptr, - pml_ncell, pml_delta, 0, do_dive_cleaning, do_moving_window, 1)); //pml_has_particles)); + pml_ncell, pml_delta, 0, do_dive_cleaning, do_moving_window, pml_has_particles)); //pml_has_particles)); for (int lev = 1; lev <= finest_level; ++lev) { pml[lev].reset(new PML(boxArray(lev), DistributionMap(lev), &Geom(lev), &Geom(lev-1), pml_ncell, pml_delta, refRatio(lev-1)[0], do_dive_cleaning, - do_moving_window, 1)); //pml_has_particles)); + do_moving_window, pml_has_particles)); //pml_has_particles)); } } } diff --git a/Source/WarpX.H b/Source/WarpX.H index 2580c5320..f14420c74 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -149,12 +149,12 @@ public: BilinearFilter bilinear_filter; amrex::Vector< std::unique_ptr > nci_godfrey_filter_exeybz; amrex::Vector< std::unique_ptr > nci_godfrey_filter_bxbyez; - + static int num_mirrors; amrex::Vector mirror_z; amrex::Vector mirror_z_width; amrex::Vector mirror_z_npoints; - + void applyMirrors(amrex::Real time); void ComputeDt (); @@ -485,6 +485,7 @@ private: int do_pml = 1; int pml_ncell = 10; int pml_delta = 10; + int pml_has_particles = 0; amrex::Vector > pml; amrex::Real moving_window_x = std::numeric_limits::max(); @@ -495,7 +496,7 @@ private: int warpx_do_continuous_injection = 0; int num_injected_species = -1; amrex::Vector injected_plasma_species; - + int do_electrostatic = 0; int n_buffer = 4; amrex::Real const_dt = 0.5e-11; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index c2cf97f30..829f151b0 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -379,6 +379,7 @@ WarpX::ReadParameters () pp.query("do_pml", do_pml); pp.query("pml_ncell", pml_ncell); pp.query("pml_delta", pml_delta); + pp.query("pml_has_particles", pml_has_particles); pp.query("dump_openpmd", dump_openpmd); pp.query("dump_plotfiles", dump_plotfiles); -- cgit v1.2.3 From 0289e350a802436fd06b5ee6dfd1e49dc62dc38e Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 7 Jun 2019 23:21:27 +0200 Subject: Started implementing modifications for Sigma --- .gitignore | 2 +- Source/BoundaryConditions/PML.H | 4 +- Source/BoundaryConditions/PML.cpp | 223 +++++++++++++++++++++++++++++++++++--- 3 files changed, 212 insertions(+), 17 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/.gitignore b/.gitignore index 02bd9eafa..0a57eb54c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ AMReX_buildInfo.cpp Backtrace.* *.vth *.sw[opqrs] - +Bin/ diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 2dfbe7a14..a05b4b291 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -151,11 +151,11 @@ private: std::array,3> pml_E_fp; std::array,3> pml_B_fp; - std::array,3> pml_J_fp; + std::array,3> pml_j_fp; std::array,3> pml_E_cp; std::array,3> pml_B_cp; - std::array,3> pml_J_cp; + std::array,3> pml_j_cp; std::unique_ptr pml_F_fp; std::unique_ptr pml_F_cp; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index bbfc4118b..5e7db342f 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -67,6 +67,190 @@ namespace } } +// SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) +// { +// BL_ASSERT(box.cellCentered()); +// +// const IntVect& sz = box.size(); +// const int* lo = box.loVect(); +// const int* hi = box.hiVect(); +// +// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) +// { +// sigma [idim].resize(sz[idim]+1); +// sigma_star [idim].resize(sz[idim] ); +// sigma_fac [idim].resize(sz[idim]+1); +// sigma_star_fac[idim].resize(sz[idim] ); +// +// sigma [idim].m_lo = lo[idim]; +// sigma [idim].m_hi = hi[idim]+1; +// sigma_star [idim].m_lo = lo[idim]; +// sigma_star [idim].m_hi = hi[idim]; +// sigma_fac [idim].m_lo = lo[idim]; +// sigma_fac [idim].m_hi = hi[idim]+1; +// sigma_star_fac[idim].m_lo = lo[idim]; +// sigma_star_fac[idim].m_hi = hi[idim]; +// } +// +// Array fac; +// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { +// fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); +// } +// +// const std::vector >& isects = grids.intersections(box, false, ncell); +// +// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) +// { +// int jdim = (idim+1) % AMREX_SPACEDIM; +// #if (AMREX_SPACEDIM == 3) +// int kdim = (idim+2) % AMREX_SPACEDIM; +// #endif +// +// Vector direct_faces, side_faces, direct_side_edges, side_side_edges, corners; +// for (const auto& kv : isects) +// { +// const Box& grid_box = grids[kv.first]; +// +// if (amrex::grow(grid_box, idim, ncell).intersects(box)) +// { +// direct_faces.push_back(kv.first); +// } +// else if (amrex::grow(grid_box, jdim, ncell).intersects(box)) +// { +// side_faces.push_back(kv.first); +// } +// #if (AMREX_SPACEDIM == 3) +// else if (amrex::grow(grid_box, kdim, ncell).intersects(box)) +// { +// side_faces.push_back(kv.first); +// } +// else if (amrex::grow(amrex::grow(grid_box,idim,ncell), +// jdim,ncell).intersects(box)) +// { +// direct_side_edges.push_back(kv.first); +// } +// else if (amrex::grow(amrex::grow(grid_box,idim,ncell), +// kdim,ncell).intersects(box)) +// { +// direct_side_edges.push_back(kv.first); +// } +// else if (amrex::grow(amrex::grow(grid_box,jdim,ncell), +// kdim,ncell).intersects(box)) +// { +// side_side_edges.push_back(kv.first); +// } +// #endif +// else +// { +// corners.push_back(kv.first); +// } +// } +// +// for (auto gid : corners) +// { +// const Box& grid_box = grids[gid]; +// +// Box lobox = amrex::adjCellLo(grid_box, idim, ncell); +// lobox.grow(jdim,ncell); +// #if (AMREX_SPACEDIM == 3) +// lobox.grow(kdim,ncell); +// #endif +// Box looverlap = lobox & box; +// if (looverlap.ok()) { +// FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); +// } +// +// Box hibox = amrex::adjCellHi(grid_box, idim, ncell); +// hibox.grow(jdim,ncell); +// #if (AMREX_SPACEDIM == 3) +// hibox.grow(kdim,ncell); +// #endif +// Box hioverlap = hibox & box; +// if (hioverlap.ok()) { +// FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); +// } +// +// if (!looverlap.ok() && !hioverlap.ok()) { +// amrex::Abort("SigmaBox::SigmaBox(): corners, how did this happen?\n"); +// } +// } +// +// #if (AMREX_SPACEDIM == 3) +// for (auto gid : side_side_edges) +// { +// const Box& grid_box = grids[gid]; +// const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; +// if (overlap.ok()) { +// FillZero(idim, sigma[idim], sigma_star[idim], overlap); +// } else { +// amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); +// } +// } +// +// for (auto gid : direct_side_edges) +// { +// const Box& grid_box = grids[gid]; +// +// Box lobox = amrex::adjCellLo(grid_box, idim, ncell); +// Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; +// if (looverlap.ok()) { +// FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); +// } +// +// Box hibox = amrex::adjCellHi(grid_box, idim, ncell); +// Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; +// if (hioverlap.ok()) { +// FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); +// } +// +// if (!looverlap.ok() && !hioverlap.ok()) { +// amrex::Abort("SigmaBox::SigmaBox(): direct_side_edges, how did this happen?\n"); +// } +// } +// #endif +// +// for (auto gid : side_faces) +// { +// const Box& grid_box = grids[gid]; +// #if (AMREX_SPACEDIM == 2) +// const Box& overlap = amrex::grow(grid_box,jdim,ncell) & box; +// #else +// const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; +// #endif +// if (overlap.ok()) { +// FillZero(idim, sigma[idim], sigma_star[idim], overlap); +// } else { +// amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); +// } +// } +// +// for (auto gid : direct_faces) +// { +// const Box& grid_box = grids[gid]; +// +// const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); +// Box looverlap = lobox & box; +// if (looverlap.ok()) { +// FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); +// } +// +// const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); +// Box hioverlap = hibox & box; +// if (hioverlap.ok()) { +// FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); +// } +// +// if (!looverlap.ok() && !hioverlap.ok()) { +// amrex::Abort("SigmaBox::SigmaBox(): direct faces, how did this happen?\n"); +// } +// } +// +// if (direct_faces.size() > 1) { +// amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); +// } +// } +// } + SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) { BL_ASSERT(box.cellCentered()); @@ -97,7 +281,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); } - const std::vector >& isects = grids.intersections(box, false, ncell); + const std::vector >& isects = grids.intersections(box); //, false, ncell); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { @@ -109,7 +293,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Vector direct_faces, side_faces, direct_side_edges, side_side_edges, corners; for (const auto& kv : isects) { - const Box& grid_box = grids[kv.first]; + const Box& grid_box = grids[kv.first].grow(-ncell); //grids[kv.first] if (amrex::grow(grid_box, idim, ncell).intersects(box)) { @@ -148,7 +332,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (auto gid : corners) { - const Box& grid_box = grids[gid]; + const Box& grid_box = grids[gid].grow(-ncell); //grids[gid] Box lobox = amrex::adjCellLo(grid_box, idim, ncell); lobox.grow(jdim,ncell); @@ -178,7 +362,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #if (AMREX_SPACEDIM == 3) for (auto gid : side_side_edges) { - const Box& grid_box = grids[gid]; + const Box& grid_box = grids[gid].grow(-ncell); const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; if (overlap.ok()) { FillZero(idim, sigma[idim], sigma_star[idim], overlap); @@ -189,7 +373,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (auto gid : direct_side_edges) { - const Box& grid_box = grids[gid]; + const Box& grid_box = grids[gid].grow(-ncell); Box lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; @@ -211,7 +395,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (auto gid : side_faces) { - const Box& grid_box = grids[gid]; + const Box& grid_box = grids[gid].grow(-ncell); #if (AMREX_SPACEDIM == 2) const Box& overlap = amrex::grow(grid_box,jdim,ncell) & box; #else @@ -226,7 +410,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (auto gid : direct_faces) { - const Box& grid_box = grids[gid]; + const Box& grid_box = grids[gid].grow(-ncell); const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox & box; @@ -365,13 +549,13 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, if (pml_has_particles){ - pml_J_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jx_nodal_flag) - pml_J_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jy_nodal_flag) - pml_J_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jz_nodal_flag) - pml_J_fp[0]->setVal(0.0); - pml_J_fp[1]->setVal(0.0); - pml_J_fp[2]->setVal(0.0); - amrex::Print() << "PML HAS PARTICLES "<< std::endl; + pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jx_nodal_flag) + pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jy_nodal_flag) + pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jz_nodal_flag) + pml_j_fp[0]->setVal(0.0); + pml_j_fp[1]->setVal(0.0); + pml_j_fp[2]->setVal(0.0); + amrex::Print() << "PML HAS PARTICLES - fine"<< std::endl; } @@ -416,6 +600,17 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } + if (pml_has_particles) + { + pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 2, ngb)); + pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 2, ngb)); + pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 2, ngb)); + pml_j_cp[0]->setVal(0.0); + pml_j_cp[1]->setVal(0.0); + pml_j_cp[2]->setVal(0.0); + amrex::Print() << "PML HAS PARTICLES - coarse"<< std::endl; + } + sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); } -- cgit v1.2.3 From 31da133d61ff5d0b3e69f2f6e2ffac5f01cc1ca1 Mon Sep 17 00:00:00 2001 From: ablelly Date: Sat, 8 Jun 2019 00:27:27 +0200 Subject: Finish implementing MultiSigmaBox for PML in domain. Running. --- Source/BoundaryConditions/PML.cpp | 62 ++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 5e7db342f..7dde89814 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -289,19 +289,29 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #if (AMREX_SPACEDIM == 3) int kdim = (idim+2) % AMREX_SPACEDIM; #endif - + amrex::Print() << " #### SIGMA BOX - START ####" << std::endl; + amrex::Print() << "pml_box = ["<< box.smallEnd()[0]<<", "< direct_faces, side_faces, direct_side_edges, side_side_edges, corners; for (const auto& kv : isects) { - const Box& grid_box = grids[kv.first].grow(-ncell); //grids[kv.first] + const Box& grid_box0 = grids[kv.first]; //.grow(-ncell); //grids[kv.first] + const Box& grid_box = amrex::grow(grid_box0, -ncell); + + // for (int idim_loc = 0; idim_loc < AMREX_SPACEDIM; ++idim_loc) { + // grid_box.grow(idim_loc, -ncell); + // } + amrex::Print() << "grid_box0 = ["<< grid_box0.smallEnd()[0]<<", "< Date: Sat, 8 Jun 2019 01:28:17 +0200 Subject: Improved the computation of PML domains (more similar to what was done previously) --- Source/BoundaryConditions/PML.cpp | 97 +++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 20 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7dde89814..6508d571b 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -297,9 +297,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& grid_box0 = grids[kv.first]; //.grow(-ncell); //grids[kv.first] const Box& grid_box = amrex::grow(grid_box0, -ncell); - // for (int idim_loc = 0; idim_loc < AMREX_SPACEDIM; ++idim_loc) { - // grid_box.grow(idim_loc, -ncell); - // } amrex::Print() << "grid_box0 = ["<< grid_box0.smallEnd()[0]<<", "< ncell, + "Consider using larger amr.blocking_factor"); + + Box bx = grid_bx; + bx.grow(ncell); + bx &= domain; + + Vector bndryboxes; +#if (AMREX_SPACEDIM == 3) + int kbegin = -1, kend = 1; +#else + int kbegin = 0, kend = 0; +#endif + for (int kk = kbegin; kk <= kend; ++kk) { + for (int jj = -1; jj <= 1; ++jj) { + for (int ii = -1; ii <= 1; ++ii) { + if (ii != 0 || jj != 0 || kk != 0) { + Box b = grid_bx; + b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); + b &= bx; + if (b.ok()) { + bndryboxes.push_back(b); + } + } + } + } + } + + const BoxList& noncovered = grid_ba_reduced.complementIn(bx); + for (const Box& b : noncovered) { + for (const auto& bb : bndryboxes) { + Box ib = b & bb; + if (ib.ok()) { + bl.push_back(ib); + } + } + } + } + + BoxArray ba(bl); + ba.removeOverlap(false); + + BoxList bl_2 = BoxList(ba); + + amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; + amrex::Print() << "[" << std::endl; + for (const Box& b: bl_2) { + amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< Date: Sat, 8 Jun 2019 01:45:58 +0200 Subject: Simplified version for computation of SigmaBox::SigmaBox. Works in 3D. Runs. --- Source/BoundaryConditions/PML.cpp | 378 +++++++++++++++++++------------------- 1 file changed, 193 insertions(+), 185 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 6508d571b..ddf0489c3 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -67,190 +67,191 @@ namespace } } -// SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) -// { -// BL_ASSERT(box.cellCentered()); -// -// const IntVect& sz = box.size(); -// const int* lo = box.loVect(); -// const int* hi = box.hiVect(); -// -// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) -// { -// sigma [idim].resize(sz[idim]+1); -// sigma_star [idim].resize(sz[idim] ); -// sigma_fac [idim].resize(sz[idim]+1); -// sigma_star_fac[idim].resize(sz[idim] ); -// -// sigma [idim].m_lo = lo[idim]; -// sigma [idim].m_hi = hi[idim]+1; -// sigma_star [idim].m_lo = lo[idim]; -// sigma_star [idim].m_hi = hi[idim]; -// sigma_fac [idim].m_lo = lo[idim]; -// sigma_fac [idim].m_hi = hi[idim]+1; -// sigma_star_fac[idim].m_lo = lo[idim]; -// sigma_star_fac[idim].m_hi = hi[idim]; -// } -// -// Array fac; -// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -// fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); -// } -// -// const std::vector >& isects = grids.intersections(box, false, ncell); -// -// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) -// { -// int jdim = (idim+1) % AMREX_SPACEDIM; -// #if (AMREX_SPACEDIM == 3) -// int kdim = (idim+2) % AMREX_SPACEDIM; -// #endif -// -// Vector direct_faces, side_faces, direct_side_edges, side_side_edges, corners; -// for (const auto& kv : isects) -// { -// const Box& grid_box = grids[kv.first]; -// -// if (amrex::grow(grid_box, idim, ncell).intersects(box)) -// { -// direct_faces.push_back(kv.first); -// } -// else if (amrex::grow(grid_box, jdim, ncell).intersects(box)) -// { -// side_faces.push_back(kv.first); -// } -// #if (AMREX_SPACEDIM == 3) -// else if (amrex::grow(grid_box, kdim, ncell).intersects(box)) -// { -// side_faces.push_back(kv.first); -// } -// else if (amrex::grow(amrex::grow(grid_box,idim,ncell), -// jdim,ncell).intersects(box)) -// { -// direct_side_edges.push_back(kv.first); -// } -// else if (amrex::grow(amrex::grow(grid_box,idim,ncell), -// kdim,ncell).intersects(box)) -// { -// direct_side_edges.push_back(kv.first); -// } -// else if (amrex::grow(amrex::grow(grid_box,jdim,ncell), -// kdim,ncell).intersects(box)) -// { -// side_side_edges.push_back(kv.first); -// } -// #endif -// else -// { -// corners.push_back(kv.first); -// } -// } -// -// for (auto gid : corners) -// { -// const Box& grid_box = grids[gid]; -// -// Box lobox = amrex::adjCellLo(grid_box, idim, ncell); -// lobox.grow(jdim,ncell); -// #if (AMREX_SPACEDIM == 3) -// lobox.grow(kdim,ncell); -// #endif -// Box looverlap = lobox & box; -// if (looverlap.ok()) { -// FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); -// } -// -// Box hibox = amrex::adjCellHi(grid_box, idim, ncell); -// hibox.grow(jdim,ncell); -// #if (AMREX_SPACEDIM == 3) -// hibox.grow(kdim,ncell); -// #endif -// Box hioverlap = hibox & box; -// if (hioverlap.ok()) { -// FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); -// } -// -// if (!looverlap.ok() && !hioverlap.ok()) { -// amrex::Abort("SigmaBox::SigmaBox(): corners, how did this happen?\n"); -// } -// } -// -// #if (AMREX_SPACEDIM == 3) -// for (auto gid : side_side_edges) -// { -// const Box& grid_box = grids[gid]; -// const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; -// if (overlap.ok()) { -// FillZero(idim, sigma[idim], sigma_star[idim], overlap); -// } else { -// amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); -// } -// } -// -// for (auto gid : direct_side_edges) -// { -// const Box& grid_box = grids[gid]; -// -// Box lobox = amrex::adjCellLo(grid_box, idim, ncell); -// Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; -// if (looverlap.ok()) { -// FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); -// } -// -// Box hibox = amrex::adjCellHi(grid_box, idim, ncell); -// Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; -// if (hioverlap.ok()) { -// FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); -// } -// -// if (!looverlap.ok() && !hioverlap.ok()) { -// amrex::Abort("SigmaBox::SigmaBox(): direct_side_edges, how did this happen?\n"); -// } -// } -// #endif -// -// for (auto gid : side_faces) -// { -// const Box& grid_box = grids[gid]; -// #if (AMREX_SPACEDIM == 2) -// const Box& overlap = amrex::grow(grid_box,jdim,ncell) & box; -// #else -// const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; -// #endif -// if (overlap.ok()) { -// FillZero(idim, sigma[idim], sigma_star[idim], overlap); -// } else { -// amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); -// } -// } -// -// for (auto gid : direct_faces) -// { -// const Box& grid_box = grids[gid]; -// -// const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); -// Box looverlap = lobox & box; -// if (looverlap.ok()) { -// FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); -// } -// -// const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); -// Box hioverlap = hibox & box; -// if (hioverlap.ok()) { -// FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); -// } -// -// if (!looverlap.ok() && !hioverlap.ok()) { -// amrex::Abort("SigmaBox::SigmaBox(): direct faces, how did this happen?\n"); -// } -// } -// -// if (direct_faces.size() > 1) { -// amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); -// } -// } -// } +SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) +{ + BL_ASSERT(box.cellCentered()); + + const IntVect& sz = box.size(); + const int* lo = box.loVect(); + const int* hi = box.hiVect(); + + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + sigma [idim].resize(sz[idim]+1); + sigma_star [idim].resize(sz[idim] ); + sigma_fac [idim].resize(sz[idim]+1); + sigma_star_fac[idim].resize(sz[idim] ); + + sigma [idim].m_lo = lo[idim]; + sigma [idim].m_hi = hi[idim]+1; + sigma_star [idim].m_lo = lo[idim]; + sigma_star [idim].m_hi = hi[idim]; + sigma_fac [idim].m_lo = lo[idim]; + sigma_fac [idim].m_hi = hi[idim]+1; + sigma_star_fac[idim].m_lo = lo[idim]; + sigma_star_fac[idim].m_hi = hi[idim]; + } + + Array fac; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); + } + + const std::vector >& isects = grids.intersections(box, false, ncell); + + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + int jdim = (idim+1) % AMREX_SPACEDIM; +#if (AMREX_SPACEDIM == 3) + int kdim = (idim+2) % AMREX_SPACEDIM; +#endif + + Vector direct_faces, side_faces, direct_side_edges, side_side_edges, corners; + for (const auto& kv : isects) + { + const Box& grid_box = grids[kv.first]; + + if (amrex::grow(grid_box, idim, ncell).intersects(box)) + { + direct_faces.push_back(kv.first); + } + else if (amrex::grow(grid_box, jdim, ncell).intersects(box)) + { + side_faces.push_back(kv.first); + } +#if (AMREX_SPACEDIM == 3) + else if (amrex::grow(grid_box, kdim, ncell).intersects(box)) + { + side_faces.push_back(kv.first); + } + else if (amrex::grow(amrex::grow(grid_box,idim,ncell), + jdim,ncell).intersects(box)) + { + direct_side_edges.push_back(kv.first); + } + else if (amrex::grow(amrex::grow(grid_box,idim,ncell), + kdim,ncell).intersects(box)) + { + direct_side_edges.push_back(kv.first); + } + else if (amrex::grow(amrex::grow(grid_box,jdim,ncell), + kdim,ncell).intersects(box)) + { + side_side_edges.push_back(kv.first); + } +#endif + else + { + corners.push_back(kv.first); + } + } + + for (auto gid : corners) + { + const Box& grid_box = grids[gid]; + + Box lobox = amrex::adjCellLo(grid_box, idim, ncell); + lobox.grow(jdim,ncell); +#if (AMREX_SPACEDIM == 3) + lobox.grow(kdim,ncell); +#endif + Box looverlap = lobox & box; + if (looverlap.ok()) { + FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + } + + Box hibox = amrex::adjCellHi(grid_box, idim, ncell); + hibox.grow(jdim,ncell); +#if (AMREX_SPACEDIM == 3) + hibox.grow(kdim,ncell); +#endif + Box hioverlap = hibox & box; + if (hioverlap.ok()) { + FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + } + + if (!looverlap.ok() && !hioverlap.ok()) { + amrex::Abort("SigmaBox::SigmaBox(): corners, how did this happen?\n"); + } + } + +#if (AMREX_SPACEDIM == 3) + for (auto gid : side_side_edges) + { + const Box& grid_box = grids[gid]; + const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; + if (overlap.ok()) { + FillZero(idim, sigma[idim], sigma_star[idim], overlap); + } else { + amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); + } + } + + for (auto gid : direct_side_edges) + { + const Box& grid_box = grids[gid]; + Box lobox = amrex::adjCellLo(grid_box, idim, ncell); + Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; + if (looverlap.ok()) { + FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + } + + Box hibox = amrex::adjCellHi(grid_box, idim, ncell); + Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; + if (hioverlap.ok()) { + FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + } + + if (!looverlap.ok() && !hioverlap.ok()) { + amrex::Abort("SigmaBox::SigmaBox(): direct_side_edges, how did this happen?\n"); + } + } +#endif + + for (auto gid : side_faces) + { + const Box& grid_box = grids[gid]; +#if (AMREX_SPACEDIM == 2) + const Box& overlap = amrex::grow(grid_box,jdim,ncell) & box; +#else + const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; +#endif + if (overlap.ok()) { + FillZero(idim, sigma[idim], sigma_star[idim], overlap); + } else { + amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); + } + } + + for (auto gid : direct_faces) + { + const Box& grid_box = grids[gid]; + + const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); + Box looverlap = lobox & box; + if (looverlap.ok()) { + FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + } + + const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); + Box hioverlap = hibox & box; + if (hioverlap.ok()) { + FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + } + + if (!looverlap.ok() && !hioverlap.ok()) { + amrex::Abort("SigmaBox::SigmaBox(): direct faces, how did this happen?\n"); + } + } + + if (direct_faces.size() > 1) { + amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); + } + } +} + +#if 0 SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) { BL_ASSERT(box.cellCentered()); @@ -460,7 +461,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n } } } - +#endif void SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) { @@ -590,8 +591,15 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_F_fp.reset(new MultiFab(amrex::convert(ba,IntVect::TheUnitVector()), dm, 3, ngf)); pml_F_fp->setVal(0.0); } + Box domain0 = amrex::grow(geom->Domain(), -ncell); + // for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + // if ( ! geom->isPeriodic(idim) ) { + // domain0.grow(idim, -ncell); + // } + // } + const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); - sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba, geom->CellSize(), ncell, delta)); + sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba_reduced, geom->CellSize(), ncell, delta)); if (cgeom) { -- cgit v1.2.3 From 305427d0ed0ebf94bc1fd3343b441ccd2e51f086 Mon Sep 17 00:00:00 2001 From: ablelly Date: Mon, 10 Jun 2019 17:37:23 +0200 Subject: Simplified even more the call to MakeBoxArray() for PML creation (now unmodified, all modifications are in PML::PML) --- Source/BoundaryConditions/PML.cpp | 161 ++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 78 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index ddf0489c3..76ae2a239 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -544,7 +543,10 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, : m_geom(geom), m_cgeom(cgeom) { - const BoxArray& ba = MakeBoxArray(*geom, grid_ba, ncell); + Box domain0 = amrex::grow(geom->Domain(), -ncell); + const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); + + const BoxArray& ba = MakeBoxArray(*geom, grid_ba_reduced, ncell); //MakeBoxArray(*geom, grid_ba, ncell); if (ba.size() == 0) { m_ok = false; return; @@ -591,13 +593,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_F_fp.reset(new MultiFab(amrex::convert(ba,IntVect::TheUnitVector()), dm, 3, ngf)); pml_F_fp->setVal(0.0); } - Box domain0 = amrex::grow(geom->Domain(), -ncell); - // for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - // if ( ! geom->isPeriodic(idim) ) { - // domain0.grow(idim, -ncell); - // } - // } - const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); + sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba_reduced, geom->CellSize(), ncell, delta)); @@ -650,83 +646,20 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } -// BoxArray -// PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) -// { -// Box domain = geom.Domain(); -// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -// if ( ! geom.isPeriodic(idim) ) { -// domain.grow(idim, ncell); -// } -// } -// -// BoxList bl; -// for (int i = 0, N = grid_ba.size(); i < N; ++i) -// { -// const Box& grid_bx = grid_ba[i]; -// const IntVect& grid_bx_sz = grid_bx.size(); -// AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, -// "Consider using larger amr.blocking_factor"); -// -// Box bx = grid_bx; -// bx.grow(ncell); -// bx &= domain; -// -// Vector bndryboxes; -// #if (AMREX_SPACEDIM == 3) -// int kbegin = -1, kend = 1; -// #else -// int kbegin = 0, kend = 0; -// #endif -// for (int kk = kbegin; kk <= kend; ++kk) { -// for (int jj = -1; jj <= 1; ++jj) { -// for (int ii = -1; ii <= 1; ++ii) { -// if (ii != 0 || jj != 0 || kk != 0) { -// Box b = grid_bx; -// b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); -// b &= bx; -// if (b.ok()) { -// bndryboxes.push_back(b); -// } -// } -// } -// } -// } -// -// const BoxList& noncovered = grid_ba.complementIn(bx); -// for (const Box& b : noncovered) { -// for (const auto& bb : bndryboxes) { -// Box ib = b & bb; -// if (ib.ok()) { -// bl.push_back(ib); -// } -// } -// } -// } -// -// BoxArray ba(bl); -// ba.removeOverlap(false); -// -// return ba; -// } - BoxArray PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) { - amrex::Print() << "========= CREATE PML INSIDE DOMAIN ============" < ncell, "Consider using larger amr.blocking_factor"); @@ -756,7 +689,7 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, } } - const BoxList& noncovered = grid_ba_reduced.complementIn(bx); + const BoxList& noncovered = grid_ba.complementIn(bx); for (const Box& b : noncovered) { for (const auto& bb : bndryboxes) { Box ib = b & bb; @@ -769,7 +702,7 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, BoxArray ba(bl); ba.removeOverlap(false); - + BoxList bl_2 = BoxList(ba); amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; @@ -781,6 +714,78 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, return ba; } +// VERSION 2 +// BoxArray +// PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) +// { +// amrex::Print() << "========= CREATE PML INSIDE DOMAIN ============" < ncell, +// "Consider using larger amr.blocking_factor"); +// +// Box bx = grid_bx; +// bx.grow(ncell); +// bx &= domain; +// +// Vector bndryboxes; +// #if (AMREX_SPACEDIM == 3) +// int kbegin = -1, kend = 1; +// #else +// int kbegin = 0, kend = 0; +// #endif +// for (int kk = kbegin; kk <= kend; ++kk) { +// for (int jj = -1; jj <= 1; ++jj) { +// for (int ii = -1; ii <= 1; ++ii) { +// if (ii != 0 || jj != 0 || kk != 0) { +// Box b = grid_bx; +// b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); +// b &= bx; +// if (b.ok()) { +// bndryboxes.push_back(b); +// } +// } +// } +// } +// } +// +// const BoxList& noncovered = grid_ba_reduced.complementIn(bx); +// for (const Box& b : noncovered) { +// for (const auto& bb : bndryboxes) { +// Box ib = b & bb; +// if (ib.ok()) { +// bl.push_back(ib); +// } +// } +// } +// } +// +// BoxArray ba(bl); +// ba.removeOverlap(false); +// +// BoxList bl_2 = BoxList(ba); +// +// amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; +// amrex::Print() << "[" << std::endl; +// for (const Box& b: bl_2) { +// amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< Date: Mon, 10 Jun 2019 17:41:31 +0200 Subject: PML.cpp cleaned version --- Source/BoundaryConditions/PML.cpp | 488 +------------------------------------- 1 file changed, 1 insertion(+), 487 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 76ae2a239..900295771 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -250,217 +250,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n } } -#if 0 -SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) -{ - BL_ASSERT(box.cellCentered()); - - const IntVect& sz = box.size(); - const int* lo = box.loVect(); - const int* hi = box.hiVect(); - - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - sigma [idim].resize(sz[idim]+1); - sigma_star [idim].resize(sz[idim] ); - sigma_fac [idim].resize(sz[idim]+1); - sigma_star_fac[idim].resize(sz[idim] ); - - sigma [idim].m_lo = lo[idim]; - sigma [idim].m_hi = hi[idim]+1; - sigma_star [idim].m_lo = lo[idim]; - sigma_star [idim].m_hi = hi[idim]; - sigma_fac [idim].m_lo = lo[idim]; - sigma_fac [idim].m_hi = hi[idim]+1; - sigma_star_fac[idim].m_lo = lo[idim]; - sigma_star_fac[idim].m_hi = hi[idim]; - } - - Array fac; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); - } - - const std::vector >& isects = grids.intersections(box); //, false, ncell); - - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - int jdim = (idim+1) % AMREX_SPACEDIM; -#if (AMREX_SPACEDIM == 3) - int kdim = (idim+2) % AMREX_SPACEDIM; -#endif - amrex::Print() << " #### SIGMA BOX - START ####" << std::endl; - amrex::Print() << "pml_box = ["<< box.smallEnd()[0]<<", "< direct_faces, side_faces, direct_side_edges, side_side_edges, corners; - for (const auto& kv : isects) - { - const Box& grid_box0 = grids[kv.first]; //.grow(-ncell); //grids[kv.first] - const Box& grid_box = amrex::grow(grid_box0, -ncell); - - amrex::Print() << "grid_box0 = ["<< grid_box0.smallEnd()[0]<<", "< 1) { - amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); - } - } -} -#endif void SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) { @@ -700,282 +490,6 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, } } - BoxArray ba(bl); - ba.removeOverlap(false); - - BoxList bl_2 = BoxList(ba); - - amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; - amrex::Print() << "[" << std::endl; - for (const Box& b: bl_2) { - amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< ncell, -// "Consider using larger amr.blocking_factor"); -// -// Box bx = grid_bx; -// bx.grow(ncell); -// bx &= domain; -// -// Vector bndryboxes; -// #if (AMREX_SPACEDIM == 3) -// int kbegin = -1, kend = 1; -// #else -// int kbegin = 0, kend = 0; -// #endif -// for (int kk = kbegin; kk <= kend; ++kk) { -// for (int jj = -1; jj <= 1; ++jj) { -// for (int ii = -1; ii <= 1; ++ii) { -// if (ii != 0 || jj != 0 || kk != 0) { -// Box b = grid_bx; -// b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); -// b &= bx; -// if (b.ok()) { -// bndryboxes.push_back(b); -// } -// } -// } -// } -// } -// -// const BoxList& noncovered = grid_ba_reduced.complementIn(bx); -// for (const Box& b : noncovered) { -// for (const auto& bb : bndryboxes) { -// Box ib = b & bb; -// if (ib.ok()) { -// bl.push_back(ib); -// } -// } -// } -// } -// -// BoxArray ba(bl); -// ba.removeOverlap(false); -// -// BoxList bl_2 = BoxList(ba); -// -// amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; -// amrex::Print() << "[" << std::endl; -// for (const Box& b: bl_2) { -// amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< ncell, - // "Consider using larger amr.blocking_factor"); - - Box bx = grid_bx; - for (int idim_loc = 0; idim_loc < AMREX_SPACEDIM; ++idim_loc) { - bx.grow(idim_loc, -ncell); - } - bx &= domain; // is this step necessary? We're always inside the domain by doing so, even if there are some periodical boundary conditions... - const IntVect& bx_sz = bx.size(); - - Vector bndryboxes; -#if (AMREX_SPACEDIM == 3) - int kbegin = -1, kend = 1; -#else - int kbegin = 0, kend = 0; -#endif - for (int kk = kbegin; kk <= kend; ++kk) { - for (int jj = -1; jj <= 1; ++jj) { - for (int ii = -1; ii <= 1; ++ii) { - if (ii != 0 || jj != 0 || kk != 0) { - // if ((ii != 0 && jj == 0 && kk == 0)||(ii == 0 && jj != 0 && kk == 0)||(ii == 0 && jj == 0 && kk != 0)) { - // if(ii!=0 && jj!=0){ - // int xlimg, xlimd, ylimg, ylimd; - // if (ii == -1){ - // xlimg = grid_bx.smallEnd()[0]; - // xlimd = limInfDomain[0]; - // } - // else if (ii = 1) { - // xlimg = grid_bx.bigEnd()[0]; - // xlimd = limSupDomain[0]; - // } - // - // if (jj == -1){ - // ylimg = grid_bx.smallEnd()[1]; - // ylimd = limInfDomain[1]; - // } - // else if (jj = 1){ - // ylimg = grid_bx.bigEnd()[1]; - // ylimd = limSupDomain[1]; - // } - // - // if (xlimd==xlimg && ylimd==ylimg){ - // amrex::Print() << "INDICES : i = " << ii << " j = " << jj << std::endl; - // Box b = grid_bx; //grid_bx; - // b.shift(bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); - // b.shift(ncell * IntVect{AMREX_D_DECL(ii,jj,kk)}); - // b &= grid_bx;// grid_bx; - // amrex::Print() << "BOITE = [" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< Date: Mon, 10 Jun 2019 18:05:35 +0200 Subject: Added the possibility to have PML in simulation area for coarse patch --- Source/BoundaryConditions/PML.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 900295771..4e7654401 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -395,7 +395,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, BoxArray grid_cba = grid_ba; grid_cba.coarsen(ref_ratio); - const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba, ncell); + const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); + const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba_reduced, ncell); DistributionMapping cdm{cba}; -- cgit v1.2.3 From 347607274d02b970b2f4381685b88b96b58788e5 Mon Sep 17 00:00:00 2001 From: ablelly Date: Mon, 10 Jun 2019 18:07:29 +0200 Subject: Added the computation of sigma_coarse for the coarse patch --- Source/BoundaryConditions/PML.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 4e7654401..e9b2b07a7 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -432,7 +432,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, amrex::Print() << "PML HAS PARTICLES - coarse"<< std::endl; } - sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); + // sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); + sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba_reduced, cgeom->CellSize(), ncell, delta)); } } -- cgit v1.2.3 From 92c4e93cdb0fb34423218d20b47fd265a7a614b8 Mon Sep 17 00:00:00 2001 From: ablelly Date: Mon, 10 Jun 2019 20:23:10 +0200 Subject: First modifications for current in PMLs (modification of Maxwell's equations in PMLs) --- Source/BoundaryConditions/PML.H | 2 ++ Source/BoundaryConditions/PML.cpp | 24 ++++++++++++++++++------ Source/BoundaryConditions/PML_routines.F90 | 23 +++++++++++++++++------ Source/Evolve/WarpXEvolveEM.cpp | 29 +++++++++++++++++------------ Source/FieldSolver/WarpXPushFieldsEM.cpp | 8 +++++++- Source/FortranInterface/WarpX_f.H | 12 +++++++++--- 6 files changed, 70 insertions(+), 28 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index a05b4b291..5b71ae3b0 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -106,8 +106,10 @@ public: std::array GetE_fp (); std::array GetB_fp (); + std::array Getj_fp (); std::array GetE_cp (); std::array GetB_cp (); + std::array Getj_cp (); amrex::MultiFab* GetF_fp (); amrex::MultiFab* GetF_cp (); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index e9b2b07a7..12c9b7cbb 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -368,9 +368,9 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, if (pml_has_particles){ - pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jx_nodal_flag) - pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jy_nodal_flag) - pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 2, ngb)); //convert(ba,WarpX::Jz_nodal_flag) + pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jx_nodal_flag) + pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jy_nodal_flag) + pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jz_nodal_flag) pml_j_fp[0]->setVal(0.0); pml_j_fp[1]->setVal(0.0); pml_j_fp[2]->setVal(0.0); @@ -423,9 +423,9 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, if (pml_has_particles) { - pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 2, ngb)); - pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 2, ngb)); - pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 2, ngb)); + pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 1, ngb)); + pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 1, ngb)); + pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 1, ngb)); pml_j_cp[0]->setVal(0.0); pml_j_cp[1]->setVal(0.0); pml_j_cp[2]->setVal(0.0); @@ -532,6 +532,12 @@ PML::GetB_fp () return {pml_B_fp[0].get(), pml_B_fp[1].get(), pml_B_fp[2].get()}; } +std::array +PML::Getj_fp () +{ + return {pml_j_fp[0].get(), pml_j_fp[1].get(), pml_j_fp[2].get()}; +} + std::array PML::GetE_cp () { @@ -544,6 +550,12 @@ PML::GetB_cp () return {pml_B_cp[0].get(), pml_B_cp[1].get(), pml_B_cp[2].get()}; } +std::array +PML::Getj_cp () +{ + return {pml_j_cp[0].get(), pml_j_cp[1].get(), pml_j_cp[2].get()}; +} + MultiFab* PML::GetF_fp () { diff --git a/Source/BoundaryConditions/PML_routines.F90 b/Source/BoundaryConditions/PML_routines.F90 index 380e52934..9d28c491a 100644 --- a/Source/BoundaryConditions/PML_routines.F90 +++ b/Source/BoundaryConditions/PML_routines.F90 @@ -431,11 +431,15 @@ contains & Bx, Bxlo, Bxhi, & & By, Bylo, Byhi, & & Bz, Bzlo, Bzhi, & - & dtsdx, dtsdy, dtsdz) & + & jx, jxlo, jxhi, & + & jy, jylo, jyhi, & + & jz, jzlo, jzhi, & + & mudt, dtsdx, dtsdy, dtsdz) & bind(c,name='warpx_push_pml_evec_2d') integer, intent(in) :: xlo(2), xhi(2), ylo(2), yhi(2), zlo(2), zhi(2), & Exlo(2), Exhi(2), Eylo(2), Eyhi(2), Ezlo(2), Ezhi(2), & - Bxlo(2), Bxhi(2), Bylo(2), Byhi(2), Bzlo(2), Bzhi(2) + Bxlo(2), Bxhi(2), Bylo(2), Byhi(2), Bzlo(2), Bzhi(2), & + jxlo(2), jxhi(2), jylo(2), jyhi(2), jzlo(2), jzhi(2) real(amrex_real), intent(in) :: dtsdx, dtsdy, dtsdz real(amrex_real), intent(inout) :: Ex (Exlo(1):Exhi(1),Exlo(2):Exhi(2),2) real(amrex_real), intent(inout) :: Ey (Eylo(1):Eyhi(1),Eylo(2):Eyhi(2),2) @@ -443,29 +447,36 @@ contains real(amrex_real), intent(in ) :: Bx (Bxlo(1):Bxhi(1),Bxlo(2):Bxhi(2),2) real(amrex_real), intent(in ) :: By (Bylo(1):Byhi(1),Bylo(2):Byhi(2),2) real(amrex_real), intent(in ) :: Bz (Bzlo(1):Bzhi(1),Bzlo(2):Bzhi(2),2) + real(amrex_real), intent(in ) :: jx (jxlo(1):jxhi(1),jxlo(2):jxhi(2),1) + real(amrex_real), intent(in ) :: jy (jylo(1):jyhi(1),jylo(2):jyhi(2),1) + real(amrex_real), intent(in ) :: jz (jzlo(1):jzhi(1),jzlo(2):jzhi(2),1) integer :: i, k do k = xlo(2), xhi(2) do i = xlo(1), xhi(1) Ex(i,k,2) = Ex(i,k,2) - dtsdz*(By(i,k ,1)+By(i,k ,2) & - & -By(i,k-1,1)-By(i,k-1,2)) + & -By(i,k-1,1)-By(i,k-1,2))& + & - mudt * jx(j,k) end do end do do k = ylo(2), yhi(2) do i = ylo(1), yhi(1) Ey(i,k,1) = Ey(i,k,1) + dtsdz*(Bx(i ,k ,1)+Bx(i ,k ,2) & - & -Bx(i ,k-1,1)-Bx(i ,k-1,2)) + & -Bx(i ,k-1,1)-Bx(i ,k-1,2))& + & - mudt * 0.5 * jy(j,k) Ey(i,k,2) = Ey(i,k,2) - dtsdx*(Bz(i ,k ,1)+Bz(i ,k ,2) & - & -Bz(i-1,k ,1)-Bz(i-1,k ,2)) + & -Bz(i-1,k ,1)-Bz(i-1,k ,2))& + & - mudt * 0.5 * jy(j,k) end do end do do k = zlo(2), zhi(2) do i = zlo(1), zhi(1) Ez(i,k,1) = Ez(i,k,1) + dtsdx*(By(i ,k,1)+By(i ,k,2) & - & -By(i-1,k,1)-By(i-1,k,2)) + & -By(i-1,k,1)-By(i-1,k,2))& + & - mudt * jz(j,k) end do end do diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index a5d68e4f9..4a12ee807 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -133,7 +133,7 @@ WarpX::EvolveEM (int numsteps) bool to_make_plot = (plot_int > 0) && ((step+1) % plot_int == 0); // slice generation // - bool to_make_slice_plot = (slice_plot_int > 0) && ( (step+1)% slice_plot_int == 0); + bool to_make_slice_plot = (slice_plot_int > 0) && ( (step+1)% slice_plot_int == 0); bool do_insitu = ((step+1) >= insitu_start) && (insitu_int > 0) && ((step+1) % insitu_int == 0); @@ -142,7 +142,7 @@ WarpX::EvolveEM (int numsteps) // We might need to move j because we are going to make a plotfile. int num_moved = MoveWindow(move_j); - + if (max_level == 0) { int num_redistribute_ghost = num_moved + 1; mypc->RedistributeLocal(num_redistribute_ghost); @@ -225,7 +225,7 @@ WarpX::EvolveEM (int numsteps) // End loop on time steps } - bool write_plot_file = plot_int > 0 && istep[0] > last_plot_file_step + bool write_plot_file = plot_int > 0 && istep[0] > last_plot_file_step && (max_time_reached || istep[0] >= max_step); bool do_insitu = (insitu_start >= istep[0]) && (insitu_int > 0) && @@ -252,7 +252,7 @@ WarpX::EvolveEM (int numsteps) UpdateInSitu(); } - if (check_int > 0 && istep[0] > last_check_file_step && + if (check_int > 0 && istep[0] > last_check_file_step && (max_time_reached || istep[0] >= max_step)) { WriteCheckPointFile(); } @@ -302,8 +302,11 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryF(); EvolveB(0.5*dt[0]); // We now have B^{n+1/2} FillBoundaryB(); + // if do particles in pmls: + // copy J (créer une fonction qui peut le faire ô EvolveB) de grille physique vers grille de pml EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); + // if DO_PML : copy E de pmls dans domaine physique EvolveF(0.5*dt[0], DtType::SecondHalf); EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { @@ -311,6 +314,8 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryE(); } FillBoundaryB(); + // if do_pml : copy B de pmls dans domaine physique + #endif } @@ -520,13 +525,13 @@ WarpX::ComputeDt () /* \brief computes max_step for wakefield simulation in boosted frame. * \param geom: Geometry object that contains simulation domain. - * - * max_step is set so that the simulation stop when the lower corner of the + * + * max_step is set so that the simulation stop when the lower corner of the * simulation box passes input parameter zmax_plasma_to_compute_max_step. */ void WarpX::computeMaxStepBoostAccelerator(amrex::Geometry a_geom){ - // Sanity checks: can use zmax_plasma_to_compute_max_step only if + // Sanity checks: can use zmax_plasma_to_compute_max_step only if // the moving window and the boost are all in z direction. AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::moving_window_dir == AMREX_SPACEDIM-1, @@ -543,7 +548,7 @@ WarpX::computeMaxStepBoostAccelerator(amrex::Geometry a_geom){ "Can use zmax_plasma_to_compute_max_step only if " + "warpx.boost_direction = z. TODO: all directions."); - // Lower end of the simulation domain. All quantities are given in boosted + // Lower end of the simulation domain. All quantities are given in boosted // frame except zmax_plasma_to_compute_max_step. const Real zmin_domain_boost = a_geom.ProbLo(AMREX_SPACEDIM-1); // End of the plasma: Transform input argument @@ -551,7 +556,7 @@ WarpX::computeMaxStepBoostAccelerator(amrex::Geometry a_geom){ const Real len_plasma_boost = zmax_plasma_to_compute_max_step/gamma_boost; // Plasma velocity const Real v_plasma_boost = -beta_boost * PhysConst::c; - // Get time at which the lower end of the simulation domain passes the + // Get time at which the lower end of the simulation domain passes the // upper end of the plasma (in the z direction). const Real interaction_time_boost = (len_plasma_boost-zmin_domain_boost)/ (moving_window_v-v_plasma_boost); @@ -564,7 +569,7 @@ WarpX::computeMaxStepBoostAccelerator(amrex::Geometry a_geom){ /* \brief Apply perfect mirror condition inside the box (not at a boundary). * In practice, set all fields to 0 on a section of the simulation domain - * (as for a perfect conductor with a given thickness). + * (as for a perfect conductor with a given thickness). * The mirror normal direction has to be parallel to the z axis. */ void @@ -581,10 +586,10 @@ WarpX::applyMirrors(Real time){ } // Loop over levels for(int lev=0; lev<=finest_level; lev++){ - // Make sure that the mirror contains at least + // Make sure that the mirror contains at least // mirror_z_npoints[i_mirror] cells Real dz = WarpX::CellSize(lev)[2]; - Real z_max = std::max(z_max_tmp, + Real z_max = std::max(z_max_tmp, z_min+mirror_z_npoints[i_mirror]*dz); // Get fine patch field MultiFabs MultiFab& Ex = *Efield_fp[lev][0].get(); diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index c53e13f8f..c84a23e51 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -137,6 +137,7 @@ WarpX::EvolveB (int lev, PatchType patch_type, amrex::Real a_dt) { const auto& pml_B = (patch_type == PatchType::fine) ? pml[lev]->GetB_fp() : pml[lev]->GetB_cp(); const auto& pml_E = (patch_type == PatchType::fine) ? pml[lev]->GetE_fp() : pml[lev]->GetE_cp(); + const auto& pml_j = (patch_type == PatchType::fine) ? pml[lev]->Getj_fp() : pml[lev]->Getj_cp(); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -338,6 +339,12 @@ WarpX::EvolveE (int lev, PatchType patch_type, amrex::Real a_dt) BL_TO_FORTRAN_3D((*pml_B[0])[mfi]), BL_TO_FORTRAN_3D((*pml_B[1])[mfi]), BL_TO_FORTRAN_3D((*pml_B[2])[mfi]), +#if (AMREX_SPACEDIM==2) + BL_TO_FORTRAN_3D((*pml_j[0])[mfi]), + BL_TO_FORTRAN_3D((*pml_j[1])[mfi]), + BL_TO_FORTRAN_3D((*pml_j[2])[mfi]), + &mu_c2_dt, +#endif &dtsdx_c2, &dtsdy_c2, &dtsdz_c2); if (pml_F) @@ -435,4 +442,3 @@ WarpX::EvolveF (int lev, PatchType patch_type, Real a_dt, DtType a_dt_type) } } } - diff --git a/Source/FortranInterface/WarpX_f.H b/Source/FortranInterface/WarpX_f.H index 1053ace89..ed3edf1a7 100644 --- a/Source/FortranInterface/WarpX_f.H +++ b/Source/FortranInterface/WarpX_f.H @@ -80,7 +80,7 @@ extern "C" const amrex_real* uxp, const amrex_real* uyp, const amrex_real* uzp, amrex_real* xpold, amrex_real* ypold, amrex_real* zpold, amrex_real* uxpold, amrex_real* uypold, amrex_real* uzpold); - + // Charge deposition void warpx_charge_deposition(amrex::Real* rho, const long* np, const amrex::Real* xp, const amrex::Real* yp, const amrex::Real* zp, const amrex::Real* w, @@ -178,7 +178,7 @@ extern "C" amrex::Real* u_Xx, amrex::Real* u_Xy, amrex::Real* u_Xz, amrex::Real* u_Yx, amrex::Real* u_Yy, amrex::Real* u_Yz, amrex::Real* positionx, amrex::Real* positiony, amrex::Real* positionz ); - + void update_laser_particle( const long* np, amrex::Real* xp, amrex::Real* yp, amrex::Real* zp, amrex::Real* uxp, amrex::Real* uyp, amrex::Real* uzp, @@ -187,7 +187,7 @@ extern "C" amrex::Real* nvecx, amrex::Real* nvecy, amrex::Real* nvecz, amrex::Real* mobility, amrex::Real* dt, const amrex::Real* c, const amrex::Real* beta_boost, const amrex::Real* gamma_boost ); - + // Maxwell solver void warpx_push_evec( @@ -377,6 +377,12 @@ extern "C" const BL_FORT_FAB_ARG_3D(bx), const BL_FORT_FAB_ARG_3D(by), const BL_FORT_FAB_ARG_3D(bz), +#if (AMREX_SPACEDIM == 2) + BL_FORT_FAB_ARG_3D(jx), + BL_FORT_FAB_ARG_3D(jy), + BL_FORT_FAB_ARG_3D(jz), + const amrex::Real* mudt, +#endif const amrex::Real* dtsdx, const amrex::Real* dtsdy, const amrex::Real* dtsdz); -- cgit v1.2.3 From 67baa94f638d03d2b25044beab01c65c25fc91dd Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 11 Jun 2019 00:57:58 +0200 Subject: Added : - function to copy J from simulation area to pmls - function to copy a field (E or B) from the pmls to the simulation area --- Source/BoundaryConditions/PML.H | 2 + Source/BoundaryConditions/PML.cpp | 104 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 5b71ae3b0..663232c85 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -169,6 +169,8 @@ private: const amrex::BoxArray& grid_ba, int ncell); static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void CopyJinPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void CopyField_fromPML_toReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; #endif diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 12c9b7cbb..aaddc7509 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -333,9 +333,27 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, : m_geom(geom), m_cgeom(cgeom) { + // BoxList bl_init = BoxList(grid_ba); + // + // amrex::Print() << "========== Printing grid_ba boxes" << std::endl; + // amrex::Print() << "[" << std::endl; + // for (const Box& b: bl_init) { + // amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "<Domain(), -ncell); const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); + // BoxList bl_reduced = BoxList(grid_ba_reduced); + // + // amrex::Print() << "========== Printing grid_ba_reduced boxes" << std::endl; + // amrex::Print() << "[" << std::endl; + // for (const Box& b: bl_reduced) { + // amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< 0) // Copy from pml to the ghost cells of regular data +// { +// MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); +// MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); +// if (ncp == 3) { +// MultiFab::Add(totpmlmf,pml,2,0,1,0); +// } +// +// MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); +// tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); +// +// #ifdef _OPENMP +// #pragma omp parallel +// #endif +// for (MFIter mfi(reg); mfi.isValid(); ++mfi) +// { +// const FArrayBox& src = tmpregmf[mfi]; +// FArrayBox& dst = reg[mfi]; +// const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); +// for (const Box& bx : bl) +// { +// dst.copy(src, bx, 0, bx, 0, 1); +// } +// } +// } + + // Copy from regular data to PML's first component + // Zero out the second (and third) component + // MultiFab::Copy(tmpregmf,reg,0,0,1,0); + // tmpregmf.setVal(0.0, 1, ncp-1, 0); + // pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); + pml.ParallelCopy(reg, ncp, 0, 0, IntVect(0), ngp, period); // pour J il n'y a qu'une seule composante!!! Et pour B il n'y en a que 2!!! Comment est-ce que ca marche? +} + +PML::CopyField_fromPML_toReg (MultiFab& pml, MultiFab& reg, const Geometry& geom) +{ + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + const int ncp = pml.nComp(); + const auto& period = geom.periodicity(); + + MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); + + if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data + { + MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); + MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); + if (ncp == 3) { + MultiFab::Add(totpmlmf,pml,2,0,1,0); + } + + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); + +#ifdef _OPENMP +#pragma omp parallel +#endif + for (MFIter mfi(reg); mfi.isValid(); ++mfi) + { + const FArrayBox& src = tmpregmf[mfi]; + FArrayBox& dst = reg[mfi]; + const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); + for (const Box& bx : bl) + { + dst.copy(src, bx, 0, bx, 0, 1); + } + } + } + + // // Copy from regular data to PML's first component + // // Zero out the second (and third) component + // MultiFab::Copy(tmpregmf,reg,0,0,1,0); + // tmpregmf.setVal(0.0, 1, ncp-1, 0); + // pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); +} + void PML::FillBoundary () { -- cgit v1.2.3 From f661fc2ebef927feb3c4f248a1872ff4b4725a8f Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 11 Jun 2019 01:11:07 +0200 Subject: Corrected PML.H so that the code can compile --- Source/BoundaryConditions/PML.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index aaddc7509..7947de399 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -742,6 +742,7 @@ PML::CopyJinPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) pml.ParallelCopy(reg, ncp, 0, 0, IntVect(0), ngp, period); // pour J il n'y a qu'une seule composante!!! Et pour B il n'y en a que 2!!! Comment est-ce que ca marche? } +void PML::CopyField_fromPML_toReg (MultiFab& pml, MultiFab& reg, const Geometry& geom) { const IntVect& ngr = reg.nGrowVect(); -- cgit v1.2.3 From 525f08a4a2c86d60b23bc8e89bbec4c2cda11cde Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 11 Jun 2019 01:43:35 +0200 Subject: Added for the copy of J in PML a function that can be called from WarpXEvolveEM.cpp and that will copy both cp an fp fields. Compiles. --- Source/BoundaryConditions/PML.H | 7 ++++++- Source/BoundaryConditions/PML.cpp | 28 +++++++++++++++++++++++++++- Source/Evolve/WarpXEvolveEM.cpp | 3 +++ 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 663232c85..44304a782 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -124,10 +124,15 @@ public: const std::array& B_cp); void ExchangeE (const std::array& E_fp, const std::array& E_cp); + void CopyJinPMLs (const std::array& j_fp, + const std::array& j_cp); + void ExchangeB (PatchType patch_type, const std::array& Bp); void ExchangeE (PatchType patch_type, const std::array& Ep); + void CopyJinPMLs (PatchType patch_type, + const std::array& jp); void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp); void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp); @@ -169,7 +174,7 @@ private: const amrex::BoxArray& grid_ba, int ncell); static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); - static void CopyJinPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyField_fromPML_toReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7947de399..7d70e9e40 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -638,6 +638,32 @@ PML::ExchangeE (PatchType patch_type, } } +void +PML::CopyJinPMLs (PatchType patch_type, + const std::array& jp) +{ + if (patch_type == PatchType::fine && pml_j_fp[0] && jp[0]) + { + CopyRegInPMLs(*pml_j_fp[0], *jp[0], *m_geom); + CopyRegInPMLs(*pml_j_fp[1], *jp[1], *m_geom); + CopyRegInPMLs(*pml_j_fp[2], *jp[2], *m_geom); + } + else if (patch_type == PatchType::coarse && pml_j_cp[0] && jp[0]) + { + CopyRegInPMLs(*pml_j_cp[0], *jp[0], *m_cgeom); + CopyRegInPMLs(*pml_j_cp[1], *jp[1], *m_cgeom); + CopyRegInPMLs(*pml_j_cp[2], *jp[2], *m_cgeom); + } +} + +void +PML::CopyJinPMLs (const std::array& j_fp, + const std::array& j_cp) +{ + CopyJinPMLs(PatchType::fine, j_fp); + CopyJinPMLs(PatchType::coarse, j_cp); +} + void PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) { @@ -699,7 +725,7 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) } void -PML::CopyJinPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) +PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) { // const IntVect& ngr = reg.nGrowVect(); const IntVect& ngp = pml.nGrowVect(); diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 4a12ee807..abd787505 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -304,6 +304,9 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryB(); // if do particles in pmls: // copy J (créer une fonction qui peut le faire ô EvolveB) de grille physique vers grille de pml + // if (pml_has_particles){ + // // CopyJinPMLs(MultiFab& pml, MultiFab& reg, const Geometry& geom); + // } EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); // if DO_PML : copy E de pmls dans domaine physique -- cgit v1.2.3 From 7fa091877d000d068d0923303f3bd59ecc041e5f Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 11 Jun 2019 17:52:05 +0200 Subject: Functions to copy the fields from PMLs to mother grid --- Source/BoundaryConditions/PML.H | 8 ++++++-- Source/BoundaryConditions/PML.cpp | 28 +++++++++++++++++++++++++++- Source/Evolve/WarpXEvolveEM.cpp | 14 +++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 44304a782..5ab088af3 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -126,13 +126,17 @@ public: const std::array& E_cp); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); - + void CopyFieldInReg (const std::array& j_fp, + const std::array& j_cp); + void ExchangeB (PatchType patch_type, const std::array& Bp); void ExchangeE (PatchType patch_type, const std::array& Ep); void CopyJinPMLs (PatchType patch_type, const std::array& jp); + void CopyFieldInReg (PatchType patch_type, + const std::array& jp); void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp); void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp); @@ -175,7 +179,7 @@ private: static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); - static void CopyField_fromPML_toReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void CopyPMLinReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; #endif diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7d70e9e40..6b65dd5e4 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -664,6 +664,32 @@ PML::CopyJinPMLs (const std::array& j_fp, CopyJinPMLs(PatchType::coarse, j_cp); } +void +PML::CopyFieldInReg (PatchType patch_type, + const std::array& Ep) +{ + if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) + { + CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_geom); + CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_geom); + CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_geom); + } + else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) + { + CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_cgeom); + CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_cgeom); + CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_cgeom); + } +} + +void +PML::CopyFieldInReg (const std::array& j_fp, + const std::array& j_cp) +{ + CopyFieldInReg(PatchType::fine, j_fp); + CopyFieldInReg(PatchType::coarse, j_cp); +} + void PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) { @@ -769,7 +795,7 @@ PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) } void -PML::CopyField_fromPML_toReg (MultiFab& pml, MultiFab& reg, const Geometry& geom) +PML::CopyPMLinReg(MultiFab& pml, MultiFab& reg, const Geometry& geom) { const IntVect& ngr = reg.nGrowVect(); const IntVect& ngp = pml.nGrowVect(); diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index abd787505..74ca4d8ab 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -304,12 +304,17 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryB(); // if do particles in pmls: // copy J (créer une fonction qui peut le faire ô EvolveB) de grille physique vers grille de pml - // if (pml_has_particles){ - // // CopyJinPMLs(MultiFab& pml, MultiFab& reg, const Geometry& geom); - // } + if (do_pml && pml_has_particles){ + // CopyJinPMLs(MultiFab& pml, MultiFab& reg, const Geometry& geom); + // pml[0].CopyJinPMLs(const std::array& j_fp, + // const std::array& j_cp) + } EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); // if DO_PML : copy E de pmls dans domaine physique + if (do_pml) { + // copy field B from PMLs to domain + } EvolveF(0.5*dt[0], DtType::SecondHalf); EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { @@ -318,6 +323,9 @@ WarpX::OneStep_nosub (Real cur_time) } FillBoundaryB(); // if do_pml : copy B de pmls dans domaine physique + if (do_pml){ + // copy field B from PMLs to domain + } #endif } -- cgit v1.2.3 From 133f711ca56a1acc77d2f31b9c5b7c096765afe0 Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 11 Jun 2019 18:39:24 +0200 Subject: Added copy of B and E fields from PMLs to domain in WarpXEvolveEM.cpp. Compiling. --- Source/BoundaryConditions/PML.H | 6 +++--- Source/BoundaryConditions/PML.cpp | 8 ++++---- Source/Evolve/WarpXEvolveEM.cpp | 31 ++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 12 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 5ab088af3..b8c2c3dd6 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -126,8 +126,8 @@ public: const std::array& E_cp); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); - void CopyFieldInReg (const std::array& j_fp, - const std::array& j_cp); + void CopyFieldInReg (const std::array& E_fp, + const std::array& E_cp); void ExchangeB (PatchType patch_type, const std::array& Bp); @@ -136,7 +136,7 @@ public: void CopyJinPMLs (PatchType patch_type, const std::array& jp); void CopyFieldInReg (PatchType patch_type, - const std::array& jp); + const std::array& Ep); void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp); void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 6b65dd5e4..25ff66e8e 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -683,11 +683,11 @@ PML::CopyFieldInReg (PatchType patch_type, } void -PML::CopyFieldInReg (const std::array& j_fp, - const std::array& j_cp) +PML::CopyFieldInReg (const std::array& E_fp, + const std::array& E_cp) { - CopyFieldInReg(PatchType::fine, j_fp); - CopyFieldInReg(PatchType::coarse, j_cp); + CopyFieldInReg(PatchType::fine, E_fp); + CopyFieldInReg(PatchType::coarse, E_cp); } void diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index a7ddc414f..8a48956cd 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -320,9 +320,20 @@ WarpX::OneStep_nosub (Real cur_time) } EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); - // if DO_PML : copy E de pmls dans domaine physique + if (do_pml) { - // copy field B from PMLs to domain + // copy E from pmls to mothergrid + for (int lev = 0; lev <= finest_level; ++lev) + { + if (pml[lev]->ok()){ + pml[lev]->CopyFieldInReg({ Efield_fp[lev][0].get(), + Efield_fp[lev][1].get(), + Efield_fp[lev][2].get() }, + { Efield_cp[lev][0].get(), + Efield_cp[lev][1].get(), + Efield_cp[lev][2].get() }); + } + } } EvolveF(0.5*dt[0], DtType::SecondHalf); EvolveB(0.5*dt[0]); // We now have B^{n+1} @@ -331,9 +342,19 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryE(); } FillBoundaryB(); - // if do_pml : copy B de pmls dans domaine physique - if (do_pml){ - // copy field B from PMLs to domain + if (do_pml) { + // copy B from pmls to mothergrid + for (int lev = 0; lev <= finest_level; ++lev) + { + if (pml[lev]->ok()){ + pml[lev]->CopyFieldInReg({ Bfield_fp[lev][0].get(), + Bfield_fp[lev][1].get(), + Bfield_fp[lev][2].get() }, + { Bfield_cp[lev][0].get(), + Bfield_cp[lev][1].get(), + Bfield_cp[lev][2].get() }); + } + } } #endif -- cgit v1.2.3 From 967ef322d47c11bc2b34149212342bf2e4ced1de Mon Sep 17 00:00:00 2001 From: ablelly Date: Wed, 12 Jun 2019 00:37:16 +0200 Subject: First intent to take ghost cells + communications into account. Compiling, but does not give the expected result. --- Source/BoundaryConditions/PML.cpp | 76 +++++++++++++++++++----------- Source/BoundaryConditions/PML_routines.F90 | 11 ++--- Source/Evolve/WarpXEvolveEM.cpp | 57 +++++++++++----------- Source/FieldSolver/WarpXPushFieldsEM.cpp | 2 +- 4 files changed, 82 insertions(+), 64 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 25ff66e8e..33ba3c44d 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -384,17 +384,23 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_B_fp[1]->setVal(0.0); pml_B_fp[2]->setVal(0.0); - - if (pml_has_particles){ - pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jx_nodal_flag) - pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jy_nodal_flag) - pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jz_nodal_flag) - pml_j_fp[0]->setVal(0.0); - pml_j_fp[1]->setVal(0.0); - pml_j_fp[2]->setVal(0.0); - amrex::Print() << "PML HAS PARTICLES - fine"<< std::endl; - - } + pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jx_nodal_flag) + pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jy_nodal_flag) + pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jz_nodal_flag) + pml_j_fp[0]->setVal(0.0); + pml_j_fp[1]->setVal(0.0); + pml_j_fp[2]->setVal(0.0); + + // if (pml_has_particles){ + // pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jx_nodal_flag) + // pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jy_nodal_flag) + // pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jz_nodal_flag) + // pml_j_fp[0]->setVal(0.0); + // pml_j_fp[1]->setVal(0.0); + // pml_j_fp[2]->setVal(0.0); + // amrex::Print() << "PML HAS PARTICLES - fine"<< std::endl; + // + // } if (do_dive_cleaning) { @@ -438,17 +444,22 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_F_cp->setVal(0.0); } - - if (pml_has_particles) - { - pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 1, ngb)); - pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 1, ngb)); - pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 1, ngb)); - pml_j_cp[0]->setVal(0.0); - pml_j_cp[1]->setVal(0.0); - pml_j_cp[2]->setVal(0.0); - amrex::Print() << "PML HAS PARTICLES - coarse"<< std::endl; - } + pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 1, ngb)); + pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 1, ngb)); + pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 1, ngb)); + pml_j_cp[0]->setVal(0.0); + pml_j_cp[1]->setVal(0.0); + pml_j_cp[2]->setVal(0.0); + // if (pml_has_particles) + // { + // pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 1, ngb)); + // pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 1, ngb)); + // pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 1, ngb)); + // pml_j_cp[0]->setVal(0.0); + // pml_j_cp[1]->setVal(0.0); + // pml_j_cp[2]->setVal(0.0); + // amrex::Print() << "PML HAS PARTICLES - coarse"<< std::endl; + // } // sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba_reduced, cgeom->CellSize(), ncell, delta)); @@ -714,6 +725,7 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) const IntVect& ngp = pml.nGrowVect(); const int ncp = pml.nComp(); const auto& period = geom.periodicity(); + int ncells = 10; MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); @@ -735,11 +747,19 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) { const FArrayBox& src = tmpregmf[mfi]; FArrayBox& dst = reg[mfi]; - const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); - for (const Box& bx : bl) - { - dst.copy(src, bx, 0, bx, 0, 1); - } + // BoxList + // Box box1 = dst.box(); + // amrex::grow(box1, -ncells); + // Box box2 = mfi.validbox(); + // amrex::Print() << "dst.box() = ["<< box1.smallEnd()[0] << ", "<ok()){ - pml[lev]->CopyFieldInReg({ Efield_fp[lev][0].get(), - Efield_fp[lev][1].get(), - Efield_fp[lev][2].get() }, - { Efield_cp[lev][0].get(), - Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }); - } - } - } + // if (do_pml) { + // // copy E from pmls to mothergrid + // for (int lev = 0; lev <= finest_level; ++lev) + // { + // if (pml[lev]->ok()){ + // pml[lev]->CopyFieldInReg({ Efield_fp[lev][0].get(), + // Efield_fp[lev][1].get(), + // Efield_fp[lev][2].get() }, + // { Efield_cp[lev][0].get(), + // Efield_cp[lev][1].get(), + // Efield_cp[lev][2].get() }); + // } + // } + // } EvolveF(0.5*dt[0], DtType::SecondHalf); EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { @@ -342,20 +341,20 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryE(); } FillBoundaryB(); - if (do_pml) { - // copy B from pmls to mothergrid - for (int lev = 0; lev <= finest_level; ++lev) - { - if (pml[lev]->ok()){ - pml[lev]->CopyFieldInReg({ Bfield_fp[lev][0].get(), - Bfield_fp[lev][1].get(), - Bfield_fp[lev][2].get() }, - { Bfield_cp[lev][0].get(), - Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }); - } - } - } + // if (do_pml) { + // // copy B from pmls to mothergrid + // for (int lev = 0; lev <= finest_level; ++lev) + // { + // if (pml[lev]->ok()){ + // pml[lev]->CopyFieldInReg({ Bfield_fp[lev][0].get(), + // Bfield_fp[lev][1].get(), + // Bfield_fp[lev][2].get() }, + // { Bfield_cp[lev][0].get(), + // Bfield_cp[lev][1].get(), + // Bfield_cp[lev][2].get() }); + // } + // } + // } #endif } diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index 4b3be0a43..b3d7b8469 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -348,7 +348,7 @@ WarpX::EvolveE (int lev, PatchType patch_type, amrex::Real a_dt) &mu_c2_dt, #endif &dtsdx_c2, &dtsdy_c2, &dtsdz_c2); - + if (pml_F) { WRPX_PUSH_PML_EVEC_F( -- cgit v1.2.3 From 75b9e7241e31a7469040fcc486a58e10123697ea Mon Sep 17 00:00:00 2001 From: ablelly Date: Wed, 12 Jun 2019 18:18:05 +0200 Subject: Fixed all problems for PMLs in domain. Compiling AND working. --- Source/BoundaryConditions/PML.cpp | 119 +++++++++++++++++++++++++++----------- 1 file changed, 86 insertions(+), 33 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 33ba3c44d..f644d4239 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -718,6 +718,49 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp) } } +// void +// PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) +// { +// const IntVect& ngr = reg.nGrowVect(); +// const IntVect& ngp = pml.nGrowVect(); +// const int ncp = pml.nComp(); +// const auto& period = geom.periodicity(); +// +// MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); +// +// if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data +// { +// MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); +// MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); +// if (ncp == 3) { +// MultiFab::Add(totpmlmf,pml,2,0,1,0); +// } +// +// MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); +// tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); +// +// #ifdef _OPENMP +// #pragma omp parallel +// #endif +// for (MFIter mfi(reg); mfi.isValid(); ++mfi) +// { +// const FArrayBox& src = tmpregmf[mfi]; +// FArrayBox& dst = reg[mfi]; +// const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); //amrex::boxDiff(dst.box(), mfi.validbox()); +// for (const Box& bx : bl) +// { +// dst.copy(src, bx, 0, bx, 0, 1); +// } +// } +// } +// +// // Copy from regular data to PML's first component +// // Zero out the second (and third) component +// MultiFab::Copy(tmpregmf,reg,0,0,1,0); +// tmpregmf.setVal(0.0, 1, ncp-1, 0); +// pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); +// } + void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) { @@ -725,51 +768,61 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) const IntVect& ngp = pml.nGrowVect(); const int ncp = pml.nComp(); const auto& period = geom.periodicity(); - int ncells = 10; MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data - { - MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); - MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); - if (ncp == 3) { - MultiFab::Add(totpmlmf,pml,2,0,1,0); - } - - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); - tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); + // MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); + tmpregmf.setVal(0.0, 0, ncp, ngr); + tmpregmf.setVal(0.0, 0, ncp, ngr); + tmpregmf.setVal(0.0, 0, ncp, ngr); + MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), ncp, ngp); + totpmlmf.setVal(0.0, 0, ncp, ngp); + totpmlmf.setVal(0.0, 0, ncp, ngp); + totpmlmf.setVal(0.0, 0, ncp, ngp); + // realise sum of splitted fields inside pml + MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); + if (ncp == 3) { + MultiFab::Add(totpmlmf,pml,2,0,1,0); + } + totpmlmf.setVal(0.0, 1, ncp-1, 0); + // MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + // tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); + reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); #ifdef _OPENMP #pragma omp parallel #endif - for (MFIter mfi(reg); mfi.isValid(); ++mfi) + + if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data + { + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + tmpregmf.setVal(0.0, 1, ncp-1, 0); + // MultiFab::Copy(totpmlmf, pml, 0, 0, ncp, ngp); + // amrex::Print() << "======= BEFORE ParallelCopy " << std::endl; + totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); //totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, IntVect(0), ngp, period); + // totpmlmf.setVal(0.0, 1, ncp-1, 0); + // amrex::Print() << "======= AFTER ParallelCopy " << std::endl; + for (MFIter mfi(pml); mfi.isValid(); ++mfi) { - const FArrayBox& src = tmpregmf[mfi]; - FArrayBox& dst = reg[mfi]; - // BoxList - // Box box1 = dst.box(); - // amrex::grow(box1, -ncells); - // Box box2 = mfi.validbox(); - // amrex::Print() << "dst.box() = ["<< box1.smallEnd()[0] << ", "< Date: Wed, 12 Jun 2019 18:30:07 +0200 Subject: Cleaned files --- Source/BoundaryConditions/PML.H | 5 -- Source/BoundaryConditions/PML.cpp | 129 +------------------------------------- 2 files changed, 1 insertion(+), 133 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index b8c2c3dd6..4b3df958c 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -126,8 +126,6 @@ public: const std::array& E_cp); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); - void CopyFieldInReg (const std::array& E_fp, - const std::array& E_cp); void ExchangeB (PatchType patch_type, const std::array& Bp); @@ -135,8 +133,6 @@ public: const std::array& Ep); void CopyJinPMLs (PatchType patch_type, const std::array& jp); - void CopyFieldInReg (PatchType patch_type, - const std::array& Ep); void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp); void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp); @@ -179,7 +175,6 @@ private: static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); - static void CopyPMLinReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; #endif diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index f644d4239..d8b6c9e20 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -675,32 +675,6 @@ PML::CopyJinPMLs (const std::array& j_fp, CopyJinPMLs(PatchType::coarse, j_cp); } -void -PML::CopyFieldInReg (PatchType patch_type, - const std::array& Ep) -{ - if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) - { - CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_geom); - CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_geom); - CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_geom); - } - else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) - { - CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_cgeom); - CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_cgeom); - CopyPMLinReg(*pml_E_fp[0], *Ep[0], *m_cgeom); - } -} - -void -PML::CopyFieldInReg (const std::array& E_fp, - const std::array& E_cp) -{ - CopyFieldInReg(PatchType::fine, E_fp); - CopyFieldInReg(PatchType::coarse, E_cp); -} - void PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) { @@ -718,49 +692,6 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp) } } -// void -// PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) -// { -// const IntVect& ngr = reg.nGrowVect(); -// const IntVect& ngp = pml.nGrowVect(); -// const int ncp = pml.nComp(); -// const auto& period = geom.periodicity(); -// -// MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); -// -// if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data -// { -// MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); -// MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); -// if (ncp == 3) { -// MultiFab::Add(totpmlmf,pml,2,0,1,0); -// } -// -// MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); -// tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); -// -// #ifdef _OPENMP -// #pragma omp parallel -// #endif -// for (MFIter mfi(reg); mfi.isValid(); ++mfi) -// { -// const FArrayBox& src = tmpregmf[mfi]; -// FArrayBox& dst = reg[mfi]; -// const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); //amrex::boxDiff(dst.box(), mfi.validbox()); -// for (const Box& bx : bl) -// { -// dst.copy(src, bx, 0, bx, 0, 1); -// } -// } -// } -// -// // Copy from regular data to PML's first component -// // Zero out the second (and third) component -// MultiFab::Copy(tmpregmf,reg,0,0,1,0); -// tmpregmf.setVal(0.0, 1, ncp-1, 0); -// pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); -// } - void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) { @@ -770,7 +701,6 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) const auto& period = geom.periodicity(); MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - // MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); tmpregmf.setVal(0.0, 0, ncp, ngr); tmpregmf.setVal(0.0, 0, ncp, ngr); tmpregmf.setVal(0.0, 0, ncp, ngr); @@ -784,8 +714,6 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) MultiFab::Add(totpmlmf,pml,2,0,1,0); } totpmlmf.setVal(0.0, 1, ncp-1, 0); - // MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); - // tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); #ifdef _OPENMP @@ -796,11 +724,7 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) { MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); tmpregmf.setVal(0.0, 1, ncp-1, 0); - // MultiFab::Copy(totpmlmf, pml, 0, 0, ncp, ngp); - // amrex::Print() << "======= BEFORE ParallelCopy " << std::endl; - totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); //totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, IntVect(0), ngp, period); - // totpmlmf.setVal(0.0, 1, ncp-1, 0); - // amrex::Print() << "======= AFTER ParallelCopy " << std::endl; + totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); for (MFIter mfi(pml); mfi.isValid(); ++mfi) { const FArrayBox& src = totpmlmf[mfi]; @@ -812,14 +736,6 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) } } } - - // // Copy from regular data to PML's first component - // // Zero out the second (and third) component - // MultiFab::Copy(tmpregmf,reg,0,0,1,0); - // tmpregmf.setVal(0.0, 1, ncp-1, 0); - // pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); - - } @@ -867,49 +783,6 @@ PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) pml.ParallelCopy(reg, 0, 0, ncp, IntVect(0), ngp, period); // pour J il n'y a qu'une seule composante!!! Et pour B il n'y en a que 2!!! Comment est-ce que ca marche? } -void -PML::CopyPMLinReg(MultiFab& pml, MultiFab& reg, const Geometry& geom) -{ - const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const int ncp = pml.nComp(); - const auto& period = geom.periodicity(); - - MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data - { - MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); - MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); - if (ncp == 3) { - MultiFab::Add(totpmlmf,pml,2,0,1,0); - } - - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); - tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); - -#ifdef _OPENMP -#pragma omp parallel -#endif - for (MFIter mfi(reg); mfi.isValid(); ++mfi) - { - const FArrayBox& src = tmpregmf[mfi]; - FArrayBox& dst = reg[mfi]; - const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); - for (const Box& bx : bl) - { - dst.copy(src, bx, 0, bx, 0, 1); - } - } - } - - // // Copy from regular data to PML's first component - // // Zero out the second (and third) component - // MultiFab::Copy(tmpregmf,reg,0,0,1,0); - // tmpregmf.setVal(0.0, 1, ncp-1, 0); - // pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); -} - void PML::FillBoundary () { -- cgit v1.2.3 From b042c077cf3f791127d4b8ba694670a6698cb62f Mon Sep 17 00:00:00 2001 From: ablelly Date: Wed, 12 Jun 2019 19:54:03 +0200 Subject: Added copy of J from domain to PMLs for the case `pml_has_particles = 1` --- Source/BoundaryConditions/PML.cpp | 62 ++++++++++++--------------------------- Source/Evolve/WarpXEvolveEM.cpp | 41 +++++--------------------- 2 files changed, 25 insertions(+), 78 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index d8b6c9e20..12eec1382 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -695,6 +695,7 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp) void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) { + const IntVect& ngr = reg.nGrowVect(); const IntVect& ngp = pml.nGrowVect(); const int ncp = pml.nComp(); @@ -702,12 +703,8 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); tmpregmf.setVal(0.0, 0, ncp, ngr); - tmpregmf.setVal(0.0, 0, ncp, ngr); - tmpregmf.setVal(0.0, 0, ncp, ngr); MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), ncp, ngp); totpmlmf.setVal(0.0, 0, ncp, ngp); - totpmlmf.setVal(0.0, 0, ncp, ngp); - totpmlmf.setVal(0.0, 0, ncp, ngp); // realise sum of splitted fields inside pml MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); if (ncp == 3) { @@ -716,15 +713,14 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) totpmlmf.setVal(0.0, 1, ncp-1, 0); reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); -#ifdef _OPENMP -#pragma omp parallel -#endif - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data { MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); tmpregmf.setVal(0.0, 1, ncp-1, 0); totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); +// #ifdef _OPENMP +// #pragma omp parallel +// #endif for (MFIter mfi(pml); mfi.isValid(); ++mfi) { const FArrayBox& src = totpmlmf[mfi]; @@ -742,45 +738,23 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) void PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) { - // const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const int ncp = pml.nComp(); - const auto& period = geom.periodicity(); - - // MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - -// if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data -// { -// MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); -// MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); -// if (ncp == 3) { -// MultiFab::Add(totpmlmf,pml,2,0,1,0); -// } -// -// MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); -// tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); -// // #ifdef _OPENMP // #pragma omp parallel // #endif -// for (MFIter mfi(reg); mfi.isValid(); ++mfi) -// { -// const FArrayBox& src = tmpregmf[mfi]; -// FArrayBox& dst = reg[mfi]; -// const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); -// for (const Box& bx : bl) -// { -// dst.copy(src, bx, 0, bx, 0, 1); -// } -// } -// } - - // Copy from regular data to PML's first component - // Zero out the second (and third) component - // MultiFab::Copy(tmpregmf,reg,0,0,1,0); - // tmpregmf.setVal(0.0, 1, ncp-1, 0); - // pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); - pml.ParallelCopy(reg, 0, 0, ncp, IntVect(0), ngp, period); // pour J il n'y a qu'une seule composante!!! Et pour B il n'y en a que 2!!! Comment est-ce que ca marche? + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + // const int ncp = pml.nComp(); + const auto& period = geom.periodicity(); + + // MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), 1, ngr); + // tmpregmf.setVal(0.0, 0, 1, ngr); + // MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, ngp); + // totpmlmf.setVal(0.0, 0, 1, ngp); + // realise sum of splitted fields inside pml + + + pml.ParallelCopy(reg, 0, 0, 1, ngr, ngp, period); + } void diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 433a61145..9b7ef4ddb 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -298,13 +298,9 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryE(); FillBoundaryB(); #else - EvolveF(0.5*dt[0], DtType::FirstHalf); - FillBoundaryF(); - EvolveB(0.5*dt[0]); // We now have B^{n+1/2} - FillBoundaryB(); - // if do particles in pmls: - // copy J (créer une fonction qui peut le faire ô EvolveB) de grille physique vers grille de pml + if (do_pml && pml_has_particles){ + // do current deposition in PMLs // copy current computed on mother grid to PMLs for (int lev = 0; lev <= finest_level; ++lev) { @@ -318,22 +314,13 @@ WarpX::OneStep_nosub (Real cur_time) } } } + EvolveF(0.5*dt[0], DtType::FirstHalf); + FillBoundaryF(); + EvolveB(0.5*dt[0]); // We now have B^{n+1/2} + FillBoundaryB(); + EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); - // if (do_pml) { - // // copy E from pmls to mothergrid - // for (int lev = 0; lev <= finest_level; ++lev) - // { - // if (pml[lev]->ok()){ - // pml[lev]->CopyFieldInReg({ Efield_fp[lev][0].get(), - // Efield_fp[lev][1].get(), - // Efield_fp[lev][2].get() }, - // { Efield_cp[lev][0].get(), - // Efield_cp[lev][1].get(), - // Efield_cp[lev][2].get() }); - // } - // } - // } EvolveF(0.5*dt[0], DtType::SecondHalf); EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { @@ -341,20 +328,6 @@ WarpX::OneStep_nosub (Real cur_time) FillBoundaryE(); } FillBoundaryB(); - // if (do_pml) { - // // copy B from pmls to mothergrid - // for (int lev = 0; lev <= finest_level; ++lev) - // { - // if (pml[lev]->ok()){ - // pml[lev]->CopyFieldInReg({ Bfield_fp[lev][0].get(), - // Bfield_fp[lev][1].get(), - // Bfield_fp[lev][2].get() }, - // { Bfield_cp[lev][0].get(), - // Bfield_cp[lev][1].get(), - // Bfield_cp[lev][2].get() }); - // } - // } - // } #endif } -- cgit v1.2.3 From 4fd74ed939169af37cb63e908fc76c5f8fa50228 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 13 Jun 2019 00:15:25 +0200 Subject: First modifications to damp J. Compiling. --- Source/BoundaryConditions/PML.H | 2 ++ Source/BoundaryConditions/PML.cpp | 22 ++++++++++++++-------- Source/Evolve/WarpXEvolveEM.cpp | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 4b3df958c..318698c79 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -44,8 +44,10 @@ struct SigmaBox using SigmaVect = std::array; SigmaVect sigma; // sigma/epsilon + SigmaVect sigma_cum; // cumsum(sigma)/(c*epsilon) SigmaVect sigma_star; // sigma_star/mu SigmaVect sigma_fac; + SigmaVect sigma_cum_fac; SigmaVect sigma_star_fac; }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 12eec1382..0fb0fc9c2 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -15,7 +15,7 @@ using namespace amrex; namespace { - static void FillLo (int idim, Sigma& sigma, Sigma& sigma_star, + static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, const Box& overlap, const Box& grid, Real fac) { int glo = grid.smallEnd(idim); @@ -35,7 +35,7 @@ namespace } } - static void FillHi (int idim, Sigma& sigma, Sigma& sigma_star, + static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, const Box& overlap, const Box& grid, Real fac) { int ghi = grid.bigEnd(idim); @@ -77,16 +77,22 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { sigma [idim].resize(sz[idim]+1); + sigma_cum [idim].resize(sz[idim]+1); sigma_star [idim].resize(sz[idim] ); sigma_fac [idim].resize(sz[idim]+1); + sigma_cum_fac [idim].resize(sz[idim]+1); sigma_star_fac[idim].resize(sz[idim] ); sigma [idim].m_lo = lo[idim]; sigma [idim].m_hi = hi[idim]+1; + sigma_cum [idim].m_lo = lo[idim]; + sigma_cum [idim].m_hi = hi[idim]+1; sigma_star [idim].m_lo = lo[idim]; sigma_star [idim].m_hi = hi[idim]; sigma_fac [idim].m_lo = lo[idim]; sigma_fac [idim].m_hi = hi[idim]+1; + sigma_cum_fac [idim].m_lo = lo[idim]; + sigma_cum_fac [idim].m_hi = hi[idim]+1; sigma_star_fac[idim].m_lo = lo[idim]; sigma_star_fac[idim].m_hi = hi[idim]; } @@ -156,7 +162,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); @@ -166,7 +172,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -193,13 +199,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -230,13 +236,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 9b7ef4ddb..30768f31f 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -314,6 +314,7 @@ WarpX::OneStep_nosub (Real cur_time) } } } + // DAMP J!!!!!! EvolveF(0.5*dt[0], DtType::FirstHalf); FillBoundaryF(); EvolveB(0.5*dt[0]); // We now have B^{n+1/2} -- cgit v1.2.3 From 0b3629dcfd3ac71acae646c74515a524e104d479 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 13 Jun 2019 00:47:23 +0200 Subject: Added the computation of sigma_cum --- Source/BoundaryConditions/PML.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 0fb0fc9c2..11c402ff8 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -23,10 +23,19 @@ namespace int ohi = overlap.bigEnd(idim); int slo = sigma.m_lo; int sslo = sigma_star.m_lo; + Real cumsum = 0.; for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(glo-i); sigma[i-slo] = fac*(offset*offset); + + } + for (int j = olo; j <= ohi+1; ++j) + { + int i = -j + (ohi+olo+1); + cumsum = cumsum + sigma[i-slo]; + sigma_cum[i-slo] = cumsum; + } for (int i = olo; i <= ohi; ++i) { @@ -43,10 +52,13 @@ namespace int ohi = overlap.bigEnd(idim); int slo = sigma.m_lo; int sslo = sigma_star.m_lo; + Real cumsum = 0.; for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); + cumsum = cumsum+sigma[i-slo]; + sigma_cum[i-slo] = cumsum; } for (int i = olo; i <= ohi; ++i) { -- cgit v1.2.3 From 34eb16e0fb7a6f63504c27d9c71a0eb7ae4e60b2 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 13 Jun 2019 00:55:43 +0200 Subject: Added computation of sigma_cum_fac --- Source/BoundaryConditions/PML.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 11c402ff8..8cbbe969a 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -33,7 +33,7 @@ namespace for (int j = olo; j <= ohi+1; ++j) { int i = -j + (ohi+olo+1); - cumsum = cumsum + sigma[i-slo]; + cumsum = cumsum + sigma[i-slo]/(PhysConst::ep0*PhysConst::c); sigma_cum[i-slo] = cumsum; } @@ -57,7 +57,7 @@ namespace { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - cumsum = cumsum+sigma[i-slo]; + cumsum = cumsum+sigma[i-slo]/(PhysConst::ep0*PhysConst::c); sigma_cum[i-slo] = cumsum; } for (int i = olo; i <= ohi; ++i) @@ -298,10 +298,12 @@ SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) if (sigma[idim][i] == 0.0) { sigma_fac[idim][i] = 1.0; + sigma_cum_fac[idim][i] = 1.0; } else { sigma_fac[idim][i] = std::exp(-sigma[idim][i]*dt); + sigma_cum_fac[idim][i] = std::exp(-sigma_cum[idim][i] * *dx); } } } -- cgit v1.2.3 From e88dad4aab893531956998e7a26e7da8d0cdf388 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 13 Jun 2019 18:45:01 +0200 Subject: Correction on the damping term for J + cleaning --- Source/BoundaryConditions/PML.cpp | 2 +- Source/Evolve/WarpXEvolveEM.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 8cbbe969a..0a6f7808d 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -303,7 +303,7 @@ SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) else { sigma_fac[idim][i] = std::exp(-sigma[idim][i]*dt); - sigma_cum_fac[idim][i] = std::exp(-sigma_cum[idim][i] * *dx); + sigma_cum_fac[idim][i] = std::exp(-sigma_cum[idim][i]*dx[idim]); } } } diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 190d4df65..4f38e673e 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -317,7 +317,7 @@ WarpX::OneStep_nosub (Real cur_time) if (do_pml && do_pml_j_damping){ // damp current in pmls - amrex::Print() << "===== DAMPING IN PMLs =====" << std::endl; + // amrex::Print() << "===== DAMPING IN PMLs =====" << std::endl; DampJPML(); } -- cgit v1.2.3 From b250efa5487b333d814d8a7c8d470ad28a2e4c3a Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 14 Jun 2019 00:33:01 +0200 Subject: Added a function to copy current from pml to mother grid --- Source/BoundaryConditions/PML.H | 5 +++++ Source/BoundaryConditions/PML.cpp | 40 +++++++++++++++++++++++++++++++++++++++ Source/Evolve/WarpXEvolveEM.cpp | 17 +++++++++++++++++ 3 files changed, 62 insertions(+) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 0099dd419..9832e0bf4 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -132,6 +132,8 @@ public: const std::array& E_cp); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); + void CopyJinReg (const std::array& j_fp, + const std::array& j_cp); void ExchangeB (PatchType patch_type, const std::array& Bp); @@ -139,6 +141,8 @@ public: const std::array& Ep); void CopyJinPMLs (PatchType patch_type, const std::array& jp); + void CopyJinReg (PatchType patch_type, + const std::array& jp); void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp); void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp); @@ -181,6 +185,7 @@ private: static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void CopyPMLsInReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; #endif diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 0a6f7808d..7e6294252 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -695,6 +695,32 @@ PML::CopyJinPMLs (const std::array& j_fp, CopyJinPMLs(PatchType::coarse, j_cp); } +void +PML::CopyJinReg (PatchType patch_type, + const std::array& jp) +{ + if (patch_type == PatchType::fine && pml_j_fp[0] && jp[0]) + { + CopyPMLsInReg(*pml_j_fp[0], *jp[0], *m_geom); + CopyPMLsInReg(*pml_j_fp[1], *jp[1], *m_geom); + CopyPMLsInReg(*pml_j_fp[2], *jp[2], *m_geom); + } + else if (patch_type == PatchType::coarse && pml_j_cp[0] && jp[0]) + { + CopyPMLsInReg(*pml_j_cp[0], *jp[0], *m_cgeom); + CopyPMLsInReg(*pml_j_cp[1], *jp[1], *m_cgeom); + CopyPMLsInReg(*pml_j_cp[2], *jp[2], *m_cgeom); + } +} + +void +PML::CopyJinReg (const std::array& j_fp, + const std::array& j_cp) +{ + CopyJinReg(PatchType::fine, j_fp); + CopyJinReg(PatchType::coarse, j_cp); +} + void PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) { @@ -777,6 +803,20 @@ PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) } +void +PML::CopyPMLsInReg (MultiFab& pml, MultiFab& reg, const Geometry& geom) +{ +// #ifdef _OPENMP +// #pragma omp parallel +// #endif + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + const auto& period = geom.periodicity(); + + reg.ParallelCopy(pml, 0, 0, 1, IntVect(0), ngr, period); + +} + void PML::FillBoundary () { diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 4f38e673e..00f7b0eb6 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -329,6 +329,23 @@ WarpX::OneStep_nosub (Real cur_time) EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); EvolveF(0.5*dt[0], DtType::SecondHalf); + + if (do_pml && pml_has_particles){ + // do current deposition in PMLs + // copy current computed on mother grid to PMLs + for (int lev = 0; lev <= finest_level; ++lev) + { + if (pml[lev]->ok()){ + pml[lev]->CopyJinReg({ current_fp[lev][0].get(), + current_fp[lev][1].get(), + current_fp[lev][2].get() }, + { current_cp[lev][0].get(), + current_cp[lev][1].get(), + current_cp[lev][2].get() }); + } + } + } + EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { DampPML(); -- cgit v1.2.3 From 4cbda10c0fe7aedb5fa94409755e1bb96952c9c1 Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 14 Jun 2019 23:19:09 +0200 Subject: Corrected current damping. Compiling AND working! --- Source/BoundaryConditions/PML.cpp | 36 +++++++++++++++++----------- Source/BoundaryConditions/PML_routines.F90 | 6 ++--- Source/BoundaryConditions/WarpXEvolvePML.cpp | 6 ++++- Source/Evolve/WarpXEvolveEM.cpp | 9 +++++++ 4 files changed, 39 insertions(+), 18 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7e6294252..7eeb29c58 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -33,7 +33,7 @@ namespace for (int j = olo; j <= ohi+1; ++j) { int i = -j + (ohi+olo+1); - cumsum = cumsum + sigma[i-slo]/(PhysConst::ep0*PhysConst::c); + cumsum = cumsum + sigma[i-slo]/PhysConst::c; sigma_cum[i-slo] = cumsum; } @@ -57,7 +57,7 @@ namespace { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - cumsum = cumsum+sigma[i-slo]/(PhysConst::ep0*PhysConst::c); + cumsum = cumsum+sigma[i-slo]/PhysConst::c; sigma_cum[i-slo] = cumsum; } for (int i = olo; i <= ohi; ++i) @@ -67,13 +67,14 @@ namespace } } - static void FillZero (int idim, Sigma& sigma, Sigma& sigma_star, const Box& overlap) + static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, const Box& overlap) { int olo = overlap.smallEnd(idim); int ohi = overlap.bigEnd(idim); int slo = sigma.m_lo; int sslo = sigma_star.m_lo; std::fill(sigma.begin()+(olo-slo), sigma.begin()+(ohi+2-slo), 0.0); + std::fill(sigma_cum.begin()+(olo-slo), sigma_cum.begin()+(ohi+2-slo), 0.0); std::fill(sigma_star.begin()+(olo-sslo), sigma_star.begin()+(ohi+1-sslo), 0.0); } } @@ -198,7 +199,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& grid_box = grids[gid]; const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_star[idim], overlap); + FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); } @@ -235,7 +236,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; #endif if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_star[idim], overlap); + FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); } @@ -291,6 +292,7 @@ SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) void SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) { + // amrex::Print()<< "===== computing PML-E factors ====="<< std::endl; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { for (int i = 0, N = sigma[idim].size(); i < N; ++i) @@ -304,6 +306,11 @@ SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) { sigma_fac[idim][i] = std::exp(-sigma[idim][i]*dt); sigma_cum_fac[idim][i] = std::exp(-sigma_cum[idim][i]*dx[idim]); + // amrex::Print()<< "sigma["<ok()) { + // amrex::Print() << "===== ENTERING WarpX::DampJPML =====" << std::endl; const auto& pml_j = (patch_type == PatchType::fine) ? pml[lev]->Getj_fp() : pml[lev]->Getj_cp(); const auto& sigba = (patch_type == PatchType::fine) ? pml[lev]->GetMultiSigmaBox_fp() : pml[lev]->GetMultiSigmaBox_cp(); @@ -114,10 +115,10 @@ WarpX::DampJPML (int lev, PatchType patch_type) #endif for ( MFIter mfi(*pml_j[0], TilingIfNotGPU()); mfi.isValid(); ++mfi ) { + // amrex::Print() << "+++++ ENTERING LOOP +++++"<< std::endl; const Box& tjx = mfi.tilebox(jx_nodal_flag); const Box& tjy = mfi.tilebox(jy_nodal_flag); const Box& tjz = mfi.tilebox(jz_nodal_flag); - WRPX_DAMPJ_PML(tjx.loVect(), tjx.hiVect(), tjy.loVect(), tjy.hiVect(), tjz.loVect(), tjz.hiVect(), @@ -126,5 +127,8 @@ WarpX::DampJPML (int lev, PatchType patch_type) BL_TO_FORTRAN_3D((*pml_j[2])[mfi]), WRPX_PML_SIGMAJ_TO_FORTRAN(sigba[mfi])); } + // amrex::Print() << "+++++ EXITING LOOP +++++"<< std::endl; + } + // amrex::Print() << "===== LEAVING WarpX::DampJPML ====="<< std::endl; } diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 00f7b0eb6..7a4973c81 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -318,7 +318,11 @@ WarpX::OneStep_nosub (Real cur_time) if (do_pml && do_pml_j_damping){ // damp current in pmls // amrex::Print() << "===== DAMPING IN PMLs =====" << std::endl; + + // amrex::Print()<< "===== DAMPING J ====="<< std::endl; + // amrex::Print()<< "[AV DAMP] max_Jx_pml = "<< pml[0]->Getj_fp()[0]->min(0) << std::endl; DampJPML(); + // amrex::Print()<< "[AP DAMP] max_Jx_pml = "<< pml[0]->Getj_fp()[0]->min(0) << std::endl; } EvolveF(0.5*dt[0], DtType::FirstHalf); @@ -336,12 +340,17 @@ WarpX::OneStep_nosub (Real cur_time) for (int lev = 0; lev <= finest_level; ++lev) { if (pml[lev]->ok()){ + // amrex::Print()<< "[AV COPY] max_Jx = "<< current_fp[lev][0].get()->min(0) << std::endl; + // amrex::Print()<< "[AV COPY] max_Jx_pml = "<< pml[lev]->Getj_fp()[0]->min(0) << std::endl; + // amrex::Print()<< "===== Copy J from PML to Reg ====="<< std::endl; pml[lev]->CopyJinReg({ current_fp[lev][0].get(), current_fp[lev][1].get(), current_fp[lev][2].get() }, { current_cp[lev][0].get(), current_cp[lev][1].get(), current_cp[lev][2].get() }); + // amrex::Print()<< "[AP COPY] max_Jx = "<< current_fp[lev][0].get()->min(0) << std::endl; + } } } -- cgit v1.2.3 From 65496de255eb142e78d7ade02506a024eeb7d7a6 Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 18 Jun 2019 02:03:48 +0200 Subject: Corrected so that Lo PML could work. compiling and running. --- Source/BoundaryConditions/PML.cpp | 45 +++++++++++++++------------- Source/BoundaryConditions/WarpXEvolvePML.cpp | 5 ---- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7eeb29c58..668e262db 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -22,21 +22,23 @@ namespace int olo = overlap.smallEnd(idim); int ohi = overlap.bigEnd(idim); int slo = sigma.m_lo; + int shi = sigma.m_hi; int sslo = sigma_star.m_lo; Real cumsum = 0.; + Real x = 10.0; for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(glo-i); sigma[i-slo] = fac*(offset*offset); - } - for (int j = olo; j <= ohi+1; ++j) + + for (int j = olo; j <= ohi; ++j) { - int i = -j + (ohi+olo+1); - cumsum = cumsum + sigma[i-slo]/PhysConst::c; + int i = -j + (ohi+olo); + cumsum = cumsum + sigma[i+1-slo]/(PhysConst::c*x/std::sqrt(1+x*x)); sigma_cum[i-slo] = cumsum; - } + for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(glo-i) - 0.5; @@ -51,14 +53,19 @@ namespace int olo = overlap.smallEnd(idim); int ohi = overlap.bigEnd(idim); int slo = sigma.m_lo; + int shi = sigma.m_hi; int sslo = sigma_star.m_lo; Real cumsum = 0.; + Real x = 10.0; for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - cumsum = cumsum+sigma[i-slo]/PhysConst::c; - sigma_cum[i-slo] = cumsum; + cumsum = cumsum+sigma[i-slo]/(PhysConst::c*x/std::sqrt(1+x*x)); + if (i<=ohi){ + sigma_cum[i-slo] = cumsum; + } + } for (int i = olo; i <= ohi; ++i) { @@ -74,7 +81,7 @@ namespace int slo = sigma.m_lo; int sslo = sigma_star.m_lo; std::fill(sigma.begin()+(olo-slo), sigma.begin()+(ohi+2-slo), 0.0); - std::fill(sigma_cum.begin()+(olo-slo), sigma_cum.begin()+(ohi+2-slo), 0.0); + std::fill(sigma_cum.begin()+(olo-slo), sigma_cum.begin()+(ohi+1-slo), 0.0); std::fill(sigma_star.begin()+(olo-sslo), sigma_star.begin()+(ohi+1-sslo), 0.0); } } @@ -90,22 +97,22 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { sigma [idim].resize(sz[idim]+1); - sigma_cum [idim].resize(sz[idim]+1); + sigma_cum [idim].resize(sz[idim]); sigma_star [idim].resize(sz[idim] ); sigma_fac [idim].resize(sz[idim]+1); - sigma_cum_fac [idim].resize(sz[idim]+1); + sigma_cum_fac [idim].resize(sz[idim]); sigma_star_fac[idim].resize(sz[idim] ); sigma [idim].m_lo = lo[idim]; sigma [idim].m_hi = hi[idim]+1; sigma_cum [idim].m_lo = lo[idim]; - sigma_cum [idim].m_hi = hi[idim]+1; + sigma_cum [idim].m_hi = hi[idim]; sigma_star [idim].m_lo = lo[idim]; sigma_star [idim].m_hi = hi[idim]; sigma_fac [idim].m_lo = lo[idim]; sigma_fac [idim].m_hi = hi[idim]+1; sigma_cum_fac [idim].m_lo = lo[idim]; - sigma_cum_fac [idim].m_hi = hi[idim]+1; + sigma_cum_fac [idim].m_hi = hi[idim]; sigma_star_fac[idim].m_lo = lo[idim]; sigma_star_fac[idim].m_hi = hi[idim]; } @@ -292,7 +299,6 @@ SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) void SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) { - // amrex::Print()<< "===== computing PML-E factors ====="<< std::endl; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { for (int i = 0, N = sigma[idim].size(); i < N; ++i) @@ -300,17 +306,16 @@ SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) if (sigma[idim][i] == 0.0) { sigma_fac[idim][i] = 1.0; - sigma_cum_fac[idim][i] = 1.0; + if (iGetj_fp() : pml[lev]->Getj_cp(); const auto& sigba = (patch_type == PatchType::fine) ? pml[lev]->GetMultiSigmaBox_fp() : pml[lev]->GetMultiSigmaBox_cp(); @@ -115,7 +113,6 @@ WarpX::DampJPML (int lev, PatchType patch_type) #endif for ( MFIter mfi(*pml_j[0], TilingIfNotGPU()); mfi.isValid(); ++mfi ) { - // amrex::Print() << "+++++ ENTERING LOOP +++++"<< std::endl; const Box& tjx = mfi.tilebox(jx_nodal_flag); const Box& tjy = mfi.tilebox(jy_nodal_flag); const Box& tjz = mfi.tilebox(jz_nodal_flag); @@ -127,8 +124,6 @@ WarpX::DampJPML (int lev, PatchType patch_type) BL_TO_FORTRAN_3D((*pml_j[2])[mfi]), WRPX_PML_SIGMAJ_TO_FORTRAN(sigba[mfi])); } - // amrex::Print() << "+++++ EXITING LOOP +++++"<< std::endl; } - // amrex::Print() << "===== LEAVING WarpX::DampJPML ====="<< std::endl; } -- cgit v1.2.3 From 5f246bbd99250d0c27679f599d9a0ebb66739338 Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 25 Jun 2019 00:21:31 +0200 Subject: Added: - damping on all components of J - Splitting of E=Exy+Exz Compiling+running. --- Source/BoundaryConditions/PML.cpp | 10 ++++++++-- Source/BoundaryConditions/PML_routines.F90 | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 668e262db..cbba9cf4c 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -26,6 +26,9 @@ namespace int sslo = sigma_star.m_lo; Real cumsum = 0.; Real x = 10.0; + Real theta = 90.0; + Real coeff_v = std::sin(theta*MathConst::pi/180.); + for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(glo-i); @@ -35,7 +38,7 @@ namespace for (int j = olo; j <= ohi; ++j) { int i = -j + (ohi+olo); - cumsum = cumsum + sigma[i+1-slo]/(PhysConst::c*x/std::sqrt(1+x*x)); + cumsum = cumsum + sigma[i+1-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); sigma_cum[i-slo] = cumsum; } @@ -57,11 +60,14 @@ namespace int sslo = sigma_star.m_lo; Real cumsum = 0.; Real x = 10.0; + Real theta = 90.0; + Real coeff_v = std::sin(theta*MathConst::pi/180.); + for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - cumsum = cumsum+sigma[i-slo]/(PhysConst::c*x/std::sqrt(1+x*x)); + cumsum = cumsum+sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); if (i<=ohi){ sigma_cum[i-slo] = cumsum; } diff --git a/Source/BoundaryConditions/PML_routines.F90 b/Source/BoundaryConditions/PML_routines.F90 index 84fc6e435..9eae5cd3b 100644 --- a/Source/BoundaryConditions/PML_routines.F90 +++ b/Source/BoundaryConditions/PML_routines.F90 @@ -457,9 +457,19 @@ contains do k = xlo(2), xhi(2) do i = xlo(1), xhi(1) if (flag==1) then + ! Ex(i,k,2) = Ex(i,k,2) - dtsdz*(By(i,k ,1)+By(i,k ,2) & + ! & -By(i,k-1,1)-By(i,k-1,2))& + ! & - mudt * jx(i,k) + ! Ex(i,k,1) = Ex(i,k,1) - dtsdz*(By(i,k ,1)+By(i,k ,2) & + ! & -By(i,k-1,1)-By(i,k-1,2)) + ! + ! Ex(i,k,2) = Ex(i,k,2) - mudt * jx(i,k) + Ex(i,k,2) = Ex(i,k,2) - dtsdz*(By(i,k ,1)+By(i,k ,2) & - & -By(i,k-1,1)-By(i,k-1,2))& - & - mudt * jx(i,k) + & -By(i,k-1,1)-By(i,k-1,2)) ! Exz + + Ex(i,k,1) = Ex(i,k,1) - mudt * jx(i,k) ! Exy + else Ex(i,k,2) = Ex(i,k,2) - dtsdz*(By(i,k ,1)+By(i,k ,2) & & -By(i,k-1,1)-By(i,k-1,2)) @@ -856,6 +866,7 @@ contains do k = texlo(2), texhi(2) do i = texlo(1), texhi(1) + ! ex(i,k,1) = ex(i,k,1) * sigez(k) !No damping for Exy ex(i,k,2) = ex(i,k,2) * sigez(k) ex(i,k,3) = ex(i,k,3) * sigcx(i) end do @@ -913,7 +924,7 @@ contains do k = tjxlo(2), tjxhi(2) do i = tjxlo(1), tjxhi(1) - jx(i,k) = jx(i,k) * sigjx(i) !sigjz(k) + jx(i,k) = jx(i,k) * minval((/sigjx(i),sigjz(k)/)) !sigjx(k) end do end do @@ -925,7 +936,7 @@ contains do k = tjzlo(2), tjzhi(2) do i = tjzlo(1), tjzhi(1) - jz(i,k) = jz(i,k) * sigjz(k) !sigjx(k) + jz(i,k) = jz(i,k) * minval((/sigjx(i),sigjz(k)/)) !sigjz(k) end do end do -- cgit v1.2.3 From 38d381fed1e7da90c06c42ae11fe80c8f1764b96 Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 25 Jun 2019 23:45:03 +0200 Subject: Added damping with sigmaStar_cum (different damping for Jx, Jz depending on the number of components) (for the moment, only valid for PML along x-axis) --- Source/BoundaryConditions/PML.H | 6 +- Source/BoundaryConditions/PML.cpp | 90 ++++++++++++++++++---------- Source/BoundaryConditions/PML_routines.F90 | 32 +++++----- Source/BoundaryConditions/WarpXEvolvePML.cpp | 3 + Source/FortranInterface/WarpX_f.H | 4 +- 5 files changed, 88 insertions(+), 47 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 9832e0bf4..726a1c7be 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -26,7 +26,9 @@ #define WRPX_PML_SIGMAJ_TO_FORTRAN(x) \ (x).sigma_cum_fac[0].data(), (x).sigma_cum_fac[0].m_lo, (x).sigma_cum_fac[0].m_hi, \ - (x).sigma_cum_fac[1].data(), (x).sigma_cum_fac[1].m_lo, (x).sigma_cum_fac[1].m_hi + (x).sigma_cum_fac[1].data(), (x).sigma_cum_fac[1].m_lo, (x).sigma_cum_fac[1].m_hi, \ + (x).sigma_star_cum_fac[0].data(), (x).sigma_star_cum_fac[0].m_lo, (x).sigma_star_cum_fac[0].m_hi, \ + (x).sigma_star_cum_fac[1].data(), (x).sigma_star_cum_fac[1].m_lo, (x).sigma_star_cum_fac[1].m_hi #endif @@ -50,9 +52,11 @@ struct SigmaBox SigmaVect sigma; // sigma/epsilon SigmaVect sigma_cum; // cumsum(sigma)/(c*epsilon) SigmaVect sigma_star; // sigma_star/mu + SigmaVect sigma_star_cum; SigmaVect sigma_fac; SigmaVect sigma_cum_fac; SigmaVect sigma_star_fac; + SigmaVect sigma_star_cum_fac; }; namespace amrex { diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index cbba9cf4c..681f2489f 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -15,7 +15,7 @@ using namespace amrex; namespace { - static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, + static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, Sigma& sigma_star_cum, const Box& overlap, const Box& grid, Real fac) { int glo = grid.smallEnd(idim); @@ -26,7 +26,7 @@ namespace int sslo = sigma_star.m_lo; Real cumsum = 0.; Real x = 10.0; - Real theta = 90.0; + Real theta = 10.0; Real coeff_v = std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) @@ -35,10 +35,10 @@ namespace sigma[i-slo] = fac*(offset*offset); } - for (int j = olo; j <= ohi; ++j) + for (int j = olo; j <= ohi+1; ++j) { - int i = -j + (ohi+olo); - cumsum = cumsum + sigma[i+1-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + int i = -j + (ohi+olo+1); + cumsum = cumsum + sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); sigma_cum[i-slo] = cumsum; } @@ -47,9 +47,16 @@ namespace Real offset = static_cast(glo-i) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); } + cumsum = 0.; + for (int j = olo; j <= ohi; ++j) + { + int i = -j + (ohi+olo); + cumsum = cumsum + sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + sigma_star_cum[i-sslo] = cumsum; + } } - static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, + static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, Sigma& sigma_star_cum, const Box& overlap, const Box& grid, Real fac) { int ghi = grid.bigEnd(idim); @@ -60,7 +67,7 @@ namespace int sslo = sigma_star.m_lo; Real cumsum = 0.; Real x = 10.0; - Real theta = 90.0; + Real theta = 10.0; Real coeff_v = std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) @@ -68,19 +75,23 @@ namespace Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); cumsum = cumsum+sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - if (i<=ohi){ - sigma_cum[i-slo] = cumsum; - } + sigma_cum[i-slo] = cumsum; + // if (i<=ohi){ + // sigma_cum[i-slo] = cumsum; + // } } + cumsum = 0.; for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(i-ghi) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); + cumsum = cumsum+sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + sigma_cum[i-slo] = cumsum; } } - static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, const Box& overlap) + static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, Sigma& sigma_star_cum, const Box& overlap) { int olo = overlap.smallEnd(idim); int ohi = overlap.bigEnd(idim); @@ -89,6 +100,7 @@ namespace std::fill(sigma.begin()+(olo-slo), sigma.begin()+(ohi+2-slo), 0.0); std::fill(sigma_cum.begin()+(olo-slo), sigma_cum.begin()+(ohi+1-slo), 0.0); std::fill(sigma_star.begin()+(olo-sslo), sigma_star.begin()+(ohi+1-sslo), 0.0); + std::fill(sigma_star_cum.begin()+(olo-sslo), sigma_star_cum.begin()+(ohi+1-sslo), 0.0); } } @@ -103,24 +115,30 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { sigma [idim].resize(sz[idim]+1); - sigma_cum [idim].resize(sz[idim]); - sigma_star [idim].resize(sz[idim] ); + sigma_cum [idim].resize(sz[idim]+1); + sigma_star [idim].resize(sz[idim]); + sigma_star_cum[idim].resize(sz[idim]); sigma_fac [idim].resize(sz[idim]+1); - sigma_cum_fac [idim].resize(sz[idim]); - sigma_star_fac[idim].resize(sz[idim] ); + sigma_cum_fac [idim].resize(sz[idim]+1); + sigma_star_fac[idim].resize(sz[idim]); + sigma_star_cum_fac[idim].resize(sz[idim]); sigma [idim].m_lo = lo[idim]; sigma [idim].m_hi = hi[idim]+1; sigma_cum [idim].m_lo = lo[idim]; - sigma_cum [idim].m_hi = hi[idim]; + sigma_cum [idim].m_hi = hi[idim]+1; sigma_star [idim].m_lo = lo[idim]; sigma_star [idim].m_hi = hi[idim]; + sigma_star_cum[idim].m_lo = lo[idim]; + sigma_star_cum[idim].m_hi = hi[idim]; sigma_fac [idim].m_lo = lo[idim]; sigma_fac [idim].m_hi = hi[idim]+1; sigma_cum_fac [idim].m_lo = lo[idim]; - sigma_cum_fac [idim].m_hi = hi[idim]; + sigma_cum_fac [idim].m_hi = hi[idim]+1; sigma_star_fac[idim].m_lo = lo[idim]; sigma_star_fac[idim].m_hi = hi[idim]; + sigma_star_cum_fac[idim].m_lo = lo[idim]; + sigma_star_cum_fac[idim].m_hi = hi[idim]; } Array fac; @@ -188,7 +206,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); @@ -198,7 +216,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -212,7 +230,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& grid_box = grids[gid]; const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], overlap); + FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); } @@ -225,13 +243,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -249,7 +267,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; #endif if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], overlap); + FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); } @@ -262,13 +280,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -298,6 +316,15 @@ SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) { sigma_star_fac[idim][i] = std::exp(-sigma_star[idim][i]*dt); } + + if (sigma_star_cum[idim][i] == 0.0) + { + sigma_star_cum_fac[idim][i] = 1.0; + } + else + { + sigma_star_cum_fac[idim][i] = std::exp(-sigma_star_cum[idim][i]*dx[idim]); + } } } } @@ -312,16 +339,17 @@ SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) if (sigma[idim][i] == 0.0) { sigma_fac[idim][i] = 1.0; - if (i Date: Wed, 26 Jun 2019 19:53:44 +0200 Subject: Modified the way sigma_cum, sigma_star_cum are computed (are supposed to be integrals of the function giving sigma, sigma_star) --- Source/BoundaryConditions/PML.cpp | 96 ++++++++++++++++++++++------ Source/BoundaryConditions/PML_routines.F90 | 6 +- Source/BoundaryConditions/WarpXEvolvePML.cpp | 4 +- 3 files changed, 81 insertions(+), 25 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 681f2489f..480fd31fa 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -24,10 +24,10 @@ namespace int slo = sigma.m_lo; int shi = sigma.m_hi; int sslo = sigma_star.m_lo; - Real cumsum = 0.; + Real cumsum=0.; Real x = 10.0; Real theta = 10.0; - Real coeff_v = std::sin(theta*MathConst::pi/180.); + Real coeff_v = 1.; //std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) { @@ -35,24 +35,57 @@ namespace sigma[i-slo] = fac*(offset*offset); } - for (int j = olo; j <= ohi+1; ++j) - { - int i = -j + (ohi+olo+1); - cumsum = cumsum + sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - sigma_cum[i-slo] = cumsum; - } + // for (int j = olo; j <= ohi+1; ++j) + // { + // int i = -j + (ohi+olo+1); + // cumsum = cumsum + sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // sigma_cum[i-slo] = cumsum; + // } + // for (int j = olo+1; j <= ohi+1; ++j) + // { + // int i = -j + (ohi+olo+1); + // cumsum = cumsum + sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // sigma_star_cum[i-sslo] = cumsum; + // } for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(glo-i) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); } - cumsum = 0.; - for (int j = olo; j <= ohi; ++j) + // cumsum = 0.; + // for (int j = olo; j <= ohi; ++j) + // { + // int i = -j + (ohi+olo); + // cumsum = cumsum + sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // // sigma_star_cum[i-sslo] = cumsum; + // sigma_cum[i+1-slo] = cumsum; + // } + // int i = olo; + // Real offset = static_cast(glo-(i-1)) - 0.5; + // cumsum = cumsum + fac*(offset*offset)/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // sigma_cum[i-slo] = cumsum; + + // approximated integrals + cumsum = sigma[ohi+1-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + sigma_cum[ohi+1-slo] = cumsum; + amrex::Print()<<"sigma_cum["<(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - cumsum = cumsum+sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - sigma_cum[i-slo] = cumsum; + // cumsum = cumsum+sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // // sigma_cum[i-slo] = cumsum; // if (i<=ohi){ - // sigma_cum[i-slo] = cumsum; + // sigma_star_cum[i-sslo] = cumsum; + // amrex::Print()<<"sigma_star_cum["<(i-ghi) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - cumsum = cumsum+sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // cumsum = cumsum+sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); + // // sigma_star_cum[i-sslo] = cumsum; + // sigma_cum[i-slo] = cumsum; + // amrex::Print()<<"sigma_cum["< Date: Thu, 4 Jul 2019 00:16:28 +0200 Subject: First modifications to go to 3d. Exact computation of integrale(sigma). Creation of a variable storing the pml type for 2d and 3d (works at least in 2d) --- Source/BoundaryConditions/PML.H | 3 + Source/BoundaryConditions/PML.cpp | 179 ++++++++++++++------------- Source/BoundaryConditions/PML_routines.F90 | 74 +++++------ Source/BoundaryConditions/WarpXEvolvePML.cpp | 4 +- 4 files changed, 138 insertions(+), 122 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 726a1c7be..2ff736bc0 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -57,6 +57,9 @@ struct SigmaBox SigmaVect sigma_cum_fac; SigmaVect sigma_star_fac; SigmaVect sigma_star_cum_fac; + + std::array alpha; //{alpha_xy, alpha_xz, alpha_xf, alpha_yx, alpha_yz, alpha_fy, alpha_zx, alpha_zy, alpha_fz} + std::string pml_type; // if pml normal to x : if pml Hi : pml_type={1,0,0}; if pml Lo: pml_type={-1,0,0} }; namespace amrex { diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 480fd31fa..a4e95d74b 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -27,65 +27,20 @@ namespace Real cumsum=0.; Real x = 10.0; Real theta = 10.0; - Real coeff_v = 1.; //std::sin(theta*MathConst::pi/180.); + Real coeff_damp = std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(glo-i); sigma[i-slo] = fac*(offset*offset); + sigma_cum[i-slo] = coeff_damp*(fac*(offset*offset*offset)/3.)/(PhysConst::c*x/std::sqrt(1+x*x)); } - // for (int j = olo; j <= ohi+1; ++j) - // { - // int i = -j + (ohi+olo+1); - // cumsum = cumsum + sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - // sigma_cum[i-slo] = cumsum; - // } - // for (int j = olo+1; j <= ohi+1; ++j) - // { - // int i = -j + (ohi+olo+1); - // cumsum = cumsum + sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - // sigma_star_cum[i-sslo] = cumsum; - // } - for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(glo-i) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - } - // cumsum = 0.; - // for (int j = olo; j <= ohi; ++j) - // { - // int i = -j + (ohi+olo); - // cumsum = cumsum + sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - // // sigma_star_cum[i-sslo] = cumsum; - // sigma_cum[i+1-slo] = cumsum; - // } - // int i = olo; - // Real offset = static_cast(glo-(i-1)) - 0.5; - // cumsum = cumsum + fac*(offset*offset)/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - // sigma_cum[i-slo] = cumsum; - - // approximated integrals - cumsum = sigma[ohi+1-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - sigma_cum[ohi+1-slo] = cumsum; - amrex::Print()<<"sigma_cum["<(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - // cumsum = cumsum+sigma[i-slo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - // // sigma_cum[i-slo] = cumsum; - // if (i<=ohi){ - // sigma_star_cum[i-sslo] = cumsum; - // amrex::Print()<<"sigma_star_cum["<(i-ghi) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - // cumsum = cumsum+sigma_star[i-sslo]/(coeff_v*PhysConst::c*x/std::sqrt(1+x*x)); - // // sigma_star_cum[i-sslo] = cumsum; - // sigma_cum[i-slo] = cumsum; - // amrex::Print()<<"sigma_cum["< fac; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { @@ -219,35 +148,42 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (amrex::grow(grid_box, idim, ncell).intersects(box)) { direct_faces.push_back(kv.first); + amrex::Print()<<"direct_faces"< 0){pml_type[2]=idim+'0';} //std::to_string(idim) } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); + pml_type = "df0+"; + if (idim>0){pml_type[2] = idim+'0';} } if (!looverlap.ok() && !hioverlap.ok()) { @@ -354,6 +344,29 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); } } + amrex::Print()<<"pml_type = "< Date: Thu, 4 Jul 2019 01:39:42 +0200 Subject: Modifications for particles in PMLs in 3d : added variables to push pmls and to damp current. Compiling in 3d. --- Source/BoundaryConditions/PML.H | 9 +++- Source/BoundaryConditions/PML.cpp | 26 +--------- Source/BoundaryConditions/PML_routines.F90 | 78 +++++++++++++++++++++++++++--- Source/FieldSolver/WarpXPushFieldsEM.cpp | 12 ++++- Source/FortranInterface/WarpX_f.H | 24 ++++++++- 5 files changed, 114 insertions(+), 35 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 2ff736bc0..97b0b6b6f 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -16,6 +16,14 @@ (x).sigma_star_fac[1].data(), (x).sigma_star_fac[1].m_lo, (x).sigma_star_fac[1].m_hi, \ (x).sigma_star_fac[2].data(), (x).sigma_star_fac[2].m_lo, (x).sigma_star_fac[2].m_hi +#define WRPX_PML_SIGMAJ_TO_FORTRAN(x) \ + (x).sigma_cum_fac[0].data(), (x).sigma_cum_fac[0].m_lo, (x).sigma_cum_fac[0].m_hi, \ + (x).sigma_cum_fac[1].data(), (x).sigma_cum_fac[1].m_lo, (x).sigma_cum_fac[1].m_hi, \ + (x).sigma_cum_fac[2].data(), (x).sigma_cum_fac[2].m_lo, (x).sigma_cum_fac[2].m_hi, \ + (x).sigma_star_cum_fac[0].data(), (x).sigma_star_cum_fac[0].m_lo, (x).sigma_star_cum_fac[0].m_hi, \ + (x).sigma_star_cum_fac[1].data(), (x).sigma_star_cum_fac[1].m_lo, (x).sigma_star_cum_fac[1].m_hi, \ + (x).sigma_star_cum_fac[2].data(), (x).sigma_star_cum_fac[2].m_lo, (x).sigma_star_cum_fac[2].m_hi + #else #define WRPX_PML_TO_FORTRAN(x) \ @@ -58,7 +66,6 @@ struct SigmaBox SigmaVect sigma_star_fac; SigmaVect sigma_star_cum_fac; - std::array alpha; //{alpha_xy, alpha_xz, alpha_xf, alpha_yx, alpha_yz, alpha_fy, alpha_zx, alpha_zy, alpha_fz} std::string pml_type; // if pml normal to x : if pml Hi : pml_type={1,0,0}; if pml Lo: pml_type={-1,0,0} }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index a4e95d74b..f9ef0b632 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -24,7 +24,6 @@ namespace int slo = sigma.m_lo; int shi = sigma.m_hi; int sslo = sigma_star.m_lo; - Real cumsum=0.; Real x = 10.0; Real theta = 10.0; Real coeff_damp = std::sin(theta*MathConst::pi/180.); @@ -53,11 +52,9 @@ namespace int slo = sigma.m_lo; int shi = sigma.m_hi; int sslo = sigma_star.m_lo; - Real cumsum = 0.; Real x = 10.0; Real theta = 10.0; Real coeff_damp = std::sin(theta*MathConst::pi/180.); - // amrex::Print()<<"===== FillHi =====" <(i-ghi-1); @@ -123,7 +120,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n sigma_star_cum_fac[idim].m_lo = lo[idim]; sigma_star_cum_fac[idim].m_hi = hi[idim]; } - alpha = {0.,0.,0.,0.,0.,0.,0.,0.,0.}; + pml_type = ""; Array fac; @@ -346,27 +343,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n } amrex::Print()<<"pml_type = "<GetE_fp() : pml[lev]->GetE_cp(); const auto& pml_j = (patch_type == PatchType::fine) ? pml[lev]->Getj_fp() : pml[lev]->Getj_cp(); const auto& pml_F = (patch_type == PatchType::fine) ? pml[lev]->GetF_fp() : pml[lev]->GetF_cp(); + const auto& sigba = (patch_type == PatchType::fine) ? pml[lev]->GetMultiSigmaBox_fp() + : pml[lev]->GetMultiSigmaBox_cp(); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -346,9 +348,17 @@ WarpX::EvolveE (int lev, PatchType patch_type, amrex::Real a_dt) BL_TO_FORTRAN_3D((*pml_j[2])[mfi]), &pml_has_particles, &mu_c2_dt, +#endif +#if (AMREX_SPACEDIM==3) + BL_TO_FORTRAN_3D((*pml_j[0])[mfi]), + BL_TO_FORTRAN_3D((*pml_j[1])[mfi]), + BL_TO_FORTRAN_3D((*pml_j[2])[mfi]), + &pml_has_particles, + WRPX_PML_SIGMAJ_TO_FORTRAN(sigba[mfi]), + &mu_c2_dt, #endif &dtsdx_c2, &dtsdy_c2, &dtsdz_c2); - + if (pml_F) { WRPX_PUSH_PML_EVEC_F( diff --git a/Source/FortranInterface/WarpX_f.H b/Source/FortranInterface/WarpX_f.H index c9ef7cc11..4ca44b92f 100644 --- a/Source/FortranInterface/WarpX_f.H +++ b/Source/FortranInterface/WarpX_f.H @@ -38,6 +38,7 @@ #define WRPX_INTERPOLATE_CIC_TWO_LEVELS warpx_interpolate_cic_two_levels_3d #define WRPX_PUSH_LEAPFROG warpx_push_leapfrog_3d #define WRPX_PUSH_LEAPFROG_POSITIONS warpx_push_leapfrog_positions_3d +#define WRPX_DAMPJ_PML warpx_dampJ_pml_3d #elif (AMREX_SPACEDIM == 2) @@ -384,6 +385,19 @@ extern "C" BL_FORT_FAB_ARG_3D(jz), const int* flag, const amrex::Real* mudt, +#endif +#if (AMREX_SPACEDIM == 3) + BL_FORT_FAB_ARG_3D(jx), + BL_FORT_FAB_ARG_3D(jy), + BL_FORT_FAB_ARG_3D(jz), + const int* flag, + const amrex::Real* sigjx, int sigjx_lo, int sigjx_hi, + const amrex::Real* sigjy, int sigjy_lo, int sigjy_hi, + const amrex::Real* sigjz, int sigjz_lo, int sigjz_hi, + const amrex::Real* sigsjx, int sigsjx_lo, int sigsjx_hi, + const amrex::Real* sigsjy, int sigsjy_lo, int sigsjy_hi, + const amrex::Real* sigjsz, int sigsjz_lo, int sigsjz_hi, + const amrex::Real* mudt, #endif const amrex::Real* dtsdx, const amrex::Real* dtsdy, @@ -446,7 +460,7 @@ extern "C" #endif const amrex::Real* sigbz, int sigbz_lo, int sigbz_hi); -#if (AMREX_SPACEDIM == 2) + void WRPX_DAMPJ_PML (const int* tjxlo, const int* tjxhi, const int* tjylo, const int* tjyhi, const int* tjzlo, const int* tjzhi, @@ -454,10 +468,16 @@ extern "C" amrex::Real* jy, const int* jylo, const int* jyhi, amrex::Real* jz, const int* jzlo, const int* jzhi, const amrex::Real* sigjx, int sigjx_lo, int sigjx_hi, +#if (AMREX_SPACEDIM == 3) + const amrex::Real* sigjy, int sigjy_lo, int sigjy_hi, +#endif const amrex::Real* sigjz, int sigjz_lo, int sigjz_hi, const amrex::Real* sigsjx, int sigsjx_lo, int sigsjx_hi, - const amrex::Real* sigjsz, int sigsjz_lo, int sigsjz_hi); +#if (AMREX_SPACEDIM == 3) + const amrex::Real* sigsjy, int sigsjy_lo, int sigsjy_hi, #endif + const amrex::Real* sigjsz, int sigsjz_lo, int sigsjz_hi); + void WRPX_SYNC_CURRENT (const int* lo, const int* hi, BL_FORT_FAB_ARG_ANYD(crse), -- cgit v1.2.3 From 916f8744b353930add6572f711ae9d7a08260d97 Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 9 Jul 2019 17:27:16 +0200 Subject: Damp PML modified (corrected the entries) --- Source/BoundaryConditions/PML.H | 13 +++---- Source/BoundaryConditions/PML.cpp | 54 +++++++++++++++++++++++++----- Source/BoundaryConditions/PML_routines.F90 | 15 +++++---- Source/Evolve/WarpXEvolveEM.cpp | 7 +++- Source/FieldSolver/WarpXPushFieldsEM.cpp | 14 ++++++-- Source/FortranInterface/WarpX_f.H | 14 ++++---- 6 files changed, 86 insertions(+), 31 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 20f7ee4d7..39f99dfef 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -25,12 +25,12 @@ (x).sigma_star_cum_fac[2].data(), (x).sigma_star_cum_fac[2].m_lo, (x).sigma_star_cum_fac[2].m_hi #define WRPX_PML_SIGMACOEFF_TO_FORTRAN(x) \ - (x).sigma[0].data(), (x).sigma[0].m_lo, (x).sigma[0].m_hi, \ - (x).sigma[1].data(), (x).sigma[1].m_lo, (x).sigma[1].m_hi, \ - (x).sigma[2].data(), (x).sigma[2].m_lo, (x).sigma[2].m_hi, \ - (x).sigma_star[0].data(), (x).sigma_star[0].m_lo, (x).sigma_star[0].m_hi, \ - (x).sigma_star[1].data(), (x).sigma_star[1].m_lo, (x).sigma_star[1].m_hi, \ - (x).sigma_star[2].data(), (x).sigma_star[2].m_lo, (x).sigma_star[2].m_hi + (x).sigma[0].dataPtr(), &((x).sigma[0].m_lo), &((x).sigma[0].m_hi), \ + (x).sigma[1].dataPtr(), &((x).sigma[1].m_lo), &((x).sigma[1].m_hi), \ + (x).sigma[2].dataPtr(), &((x).sigma[2].m_lo), &((x).sigma[2].m_hi), \ + (x).sigma_star[0].dataPtr(), &((x).sigma_star[0].m_lo), &((x).sigma_star[0].m_hi), \ + (x).sigma_star[1].dataPtr(), &((x).sigma_star[1].m_lo), &((x).sigma_star[1].m_hi), \ + (x).sigma_star[2].dataPtr(), &((x).sigma_star[2].m_lo), &((x).sigma_star[2].m_hi) #else @@ -81,6 +81,7 @@ struct SigmaBox SigmaVect sigma_star_cum_fac; std::string pml_type; // if pml normal to x : if pml Hi : pml_type={1,0,0}; if pml Lo: pml_type={-1,0,0} + std::array pml_type_array; }; namespace amrex { diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index f9ef0b632..ec77ca7cf 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -26,7 +26,7 @@ namespace int sslo = sigma_star.m_lo; Real x = 10.0; Real theta = 10.0; - Real coeff_damp = std::sin(theta*MathConst::pi/180.); + Real coeff_damp = 1.; //std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) { @@ -54,7 +54,7 @@ namespace int sslo = sigma_star.m_lo; Real x = 10.0; Real theta = 10.0; - Real coeff_damp = std::sin(theta*MathConst::pi/180.); + Real coeff_damp = 1.;//std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(i-ghi-1); @@ -85,7 +85,8 @@ namespace SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) { amrex::Print()<< "===== BUILD SigmaBox ====="< fac; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { @@ -198,10 +200,15 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); if (idim == 0){ pml_type = "crn-++"; // for 2d only use the two first components + pml_type_array[0] = 1; + pml_type_array[1] = 0; + pml_type_array[2] = 1; + pml_type_array[3] = 1; } else { if (pml_type[0] == 'c'){ pml_type[3+idim] = '-'; + pml_type_array[1+idim] = 0; } } } @@ -216,10 +223,15 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); if (idim == 0){ pml_type = "crn+++"; // for 2d only use the two first components + pml_type_array[0] = 1; + pml_type_array[1] = 1; + pml_type_array[2] = 1; + pml_type_array[3] = 1; } else { if (pml_type[0] == 'c'){ pml_type[3+idim] = '+'; + pml_type_array[1+idim] = 1; } } } @@ -238,6 +250,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); if (idim==0){ pml_type="sed33--"; + pml_type_array[0] = 2; } } else { @@ -255,16 +268,23 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); if (idim == 0){ pml_type = "sed03-+"; // for 2d only use the two first components + pml_type_array[0] = 2; + pml_type_array[1] = idim; + pml_type_array[3] = 0; } else { if (pml_type[0] == 's'){ - if (pml_type[3]==3){ + if (pml_type[3]=='3'){ pml_type[3]=idim+'0'; pml_type[5]='-'; + pml_type_array[1] = idim; + pml_type_array[3] = 0; } else{ pml_type[4] = idim+'0'; pml_type[6] = '-'; + pml_type_array[2] = idim; + pml_type_array[4] = 0; } } } @@ -276,16 +296,23 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); if (idim == 0){ pml_type = "sed03++"; // for 2d only use the two first components + pml_type_array[0] = 2; + pml_type_array[1] = idim; + pml_type_array[3] = 1; } else { if (pml_type[0] == 's'){ - if (pml_type[3]==3){ + if (pml_type[3]=='3'){ pml_type[3]=idim+'0'; pml_type[5]='+'; + pml_type_array[1] = idim; + pml_type_array[3] = 1; } else{ pml_type[4] = idim+'0'; pml_type[6] = '+'; + pml_type_array[2] = idim; + pml_type_array[4] = 1; } } } @@ -321,6 +348,9 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); pml_type = "df0-"; + pml_type_array[0] = 0; + pml_type_array[1] = idim; + pml_type_array[2] = 0; if (idim > 0){pml_type[2]=idim+'0';} //std::to_string(idim) } @@ -329,6 +359,9 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); pml_type = "df0+"; + pml_type_array[0] = 0; + pml_type_array[1] = idim; + pml_type_array[2] = 1; if (idim>0){pml_type[2] = idim+'0';} } @@ -342,7 +375,11 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n } } amrex::Print()<<"pml_type = "<Domain(), -ncell); + amrex::Print() << "[" << domain0.smallEnd()[0]<<", "<< domain0.smallEnd()[1]<<", "<< domain0.smallEnd()[2]<< ", "<ok()){ @@ -316,6 +317,7 @@ WarpX::OneStep_nosub (Real cur_time) } if (do_pml && do_pml_j_damping){ + amrex::Print()<< "WarpXEvolveEM.cpp : DampJ "<ok()){ @@ -357,6 +361,7 @@ WarpX::OneStep_nosub (Real cur_time) EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { + amrex::Print()<< "WarpXEvolveEM.cpp : DampPML "<Getj_fp() : pml[lev]->Getj_cp(); const auto& pml_F = (patch_type == PatchType::fine) ? pml[lev]->GetF_fp() : pml[lev]->GetF_cp(); const auto& sigba = (patch_type == PatchType::fine) ? pml[lev]->GetMultiSigmaBox_fp() - : pml[lev]->GetMultiSigmaBox_cp(); + : pml[lev]->GetMultiSigmaBox_cp(); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -332,6 +332,14 @@ WarpX::EvolveE (int lev, PatchType patch_type, amrex::Real a_dt) const Box& tey = mfi.tilebox(Ey_nodal_flag); const Box& tez = mfi.tilebox(Ez_nodal_flag); + amrex::Print()<< "== sigba.pml_type_array"<* pml_type,//const std::string pml_type, + const amrex::Real* sigjx, const int* sigjx_lo, const int* sigjx_hi, + const amrex::Real* sigjy, const int* sigjy_lo, const int* sigjy_hi, + const amrex::Real* sigjz, const int* sigjz_lo, const int* sigjz_hi, + const amrex::Real* sigsjx, const int* sigsjx_lo, const int* sigsjx_hi, + const amrex::Real* sigsjy, const int* sigsjy_lo, const int* sigsjy_hi, + const amrex::Real* sigjsz, const int* sigsjz_lo, const int* sigsjz_hi, const amrex::Real* mudt, #endif const amrex::Real* dtsdx, -- cgit v1.2.3 From 26107de17802307cb81dd28bba6047baebcaf86d Mon Sep 17 00:00:00 2001 From: ablelly Date: Wed, 10 Jul 2019 00:35:09 +0200 Subject: Corrections to take into account periodic boundary conditions (2d, 3d). Compiling and running. --- Source/BoundaryConditions/PML.cpp | 12 +++++++++--- Source/BoundaryConditions/PML_routines.F90 | 13 ++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index ec77ca7cf..b01a95f10 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -490,7 +490,13 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, // } // amrex::Print()<< "];" << std::endl; amrex::Print()<<"===== BUILDING PML ====="<Domain(), -ncell); + Box domain0 = geom->Domain(); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + if ( ! geom->isPeriodic(idim) ) { + domain0.grow(idim, -ncell); + } + } + // Box domain0 = amrex::grow(geom->Domain(), -ncell); amrex::Print() << "[" << domain0.smallEnd()[0]<<", "<< domain0.smallEnd()[1]<<", "<< domain0.smallEnd()[2]<< ", "< ncell, - "Consider using larger amr.blocking_factor"); + // AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, + // "Consider using larger amr.blocking_factor"); Box bx = grid_bx; bx.grow(ncell); diff --git a/Source/BoundaryConditions/PML_routines.F90 b/Source/BoundaryConditions/PML_routines.F90 index 23cd05e89..f880c20a9 100644 --- a/Source/BoundaryConditions/PML_routines.F90 +++ b/Source/BoundaryConditions/PML_routines.F90 @@ -1182,19 +1182,18 @@ contains real(amrex_real), intent(in) :: sigsjz(ssjzlo:ssjzhi) integer :: i,k - !!!! FOR A PML ALONG X-AXIS !!!!! + do k = tjxlo(2), tjxhi(2) do i = tjxlo(1), tjxhi(1) - ! jx(i,k) = jx(i,k) * sigjx(i) !minval((/sigjx(i),sigjz(k)/)) jx(i,k) = jx(i,k) * sigsjx(i) * sigjz(k) end do end do - do k = tjylo(2), tjyhi(2) - do i = tjylo(1), tjyhi(1) - jy(i,k) = jy(i,k) !* minval((/sigjx(i),sigjz(k)/)) !sigjz(k) !no current jy... - end do - end do + ! do k = tjylo(2), tjyhi(2) + ! do i = tjylo(1), tjyhi(1) + ! jy(i,k) = jy(i,k) + ! end do + ! end do do k = tjzlo(2), tjzhi(2) do i = tjzlo(1), tjzhi(1) -- cgit v1.2.3 From b6834f615a8085f91ce07dfa1413d0d9ea4cc24a Mon Sep 17 00:00:00 2001 From: ablelly Date: Mon, 15 Jul 2019 23:19:01 +0200 Subject: Work on the merge --- Source/BoundaryConditions/PML.H | 8 +- Source/BoundaryConditions/PML.cpp | 105 ++- Source/BoundaryConditions/PML_Cplx.cpp | 958 --------------------------- Source/BoundaryConditions/WarpXEvolvePML.cpp | 6 +- Source/Evolve/WarpXEvolveEM.cpp | 22 +- Source/WarpX.H | 1 + Source/WarpX.cpp | 5 + 7 files changed, 56 insertions(+), 1049 deletions(-) delete mode 100644 Source/BoundaryConditions/PML_Cplx.cpp (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index fd8fe12ec..62a378986 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -71,9 +71,9 @@ struct SigmaBox using SigmaVect = std::array; - SigmaVect sigma; // sigma/epsilon - SigmaVect sigma_cum; // cumsum(sigma)/(c*epsilon) - SigmaVect sigma_star; // sigma_star/mu + SigmaVect sigma; + SigmaVect sigma_cum; + SigmaVect sigma_star; SigmaVect sigma_star_cum; SigmaVect sigma_fac; SigmaVect sigma_cum_fac; @@ -81,7 +81,7 @@ struct SigmaBox SigmaVect sigma_star_cum_fac; std::string pml_type; // if pml normal to x : if pml Hi : pml_type={1,0,0}; if pml Lo: pml_type={-1,0,0} - std::array pml_type_array; + std::array pml_type_array; }; namespace amrex { diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index b01a95f10..1f1cc80c3 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -84,9 +84,6 @@ namespace SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) { - amrex::Print()<< "===== BUILD SigmaBox ====="<Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom->isPeriodic(idim) ) { domain0.grow(idim, -ncell); } } - // Box domain0 = amrex::grow(geom->Domain(), -ncell); - amrex::Print() << "[" << domain0.smallEnd()[0]<<", "<< domain0.smallEnd()[1]<<", "<< domain0.smallEnd()[2]<< ", "<setVal(0.0); pml_j_fp[2]->setVal(0.0); - // if (pml_has_particles){ - // pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jx_nodal_flag) - // pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jy_nodal_flag) - // pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jz_nodal_flag) - // pml_j_fp[0]->setVal(0.0); - // pml_j_fp[1]->setVal(0.0); - // pml_j_fp[2]->setVal(0.0); - // amrex::Print() << "PML HAS PARTICLES - fine"<< std::endl; - // - // } - if (do_dive_cleaning) { pml_F_fp.reset(new MultiFab(amrex::convert(ba,IntVect::TheUnitVector()), dm, 3, ngf)); @@ -605,16 +571,6 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_j_cp[0]->setVal(0.0); pml_j_cp[1]->setVal(0.0); pml_j_cp[2]->setVal(0.0); - // if (pml_has_particles) - // { - // pml_j_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::jx_nodal_flag), cdm, 1, ngb)); - // pml_j_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::jy_nodal_flag), cdm, 1, ngb)); - // pml_j_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::jz_nodal_flag), cdm, 1, ngb)); - // pml_j_cp[0]->setVal(0.0); - // pml_j_cp[1]->setVal(0.0); - // pml_j_cp[2]->setVal(0.0); - // amrex::Print() << "PML HAS PARTICLES - coarse"<< std::endl; - // } // sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba_reduced, cgeom->CellSize(), ncell, delta)); @@ -679,15 +635,6 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, BoxArray ba(bl); ba.removeOverlap(false); - // BoxList bl_2 = BoxList(ba); - // - // amrex::Print() << "Printing PML boxes AFTER cleaning" << std::endl; - // amrex::Print() << "[" << std::endl; - // for (const Box& b: bl_2) { - // amrex::Print() << "[" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "< 0) // Copy from pml to the ghost cells of regular data +// { +// MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); +// MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); +// if (ncp == 3) { +// MultiFab::Add(totpmlmf,pml,2,0,1,0); +// } +// +// MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); +// tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); +// +// #ifdef _OPENMP +// #pragma omp parallel +// #endif +// for (MFIter mfi(reg); mfi.isValid(); ++mfi) +// { +// const FArrayBox& src = tmpregmf[mfi]; +// FArrayBox& dst = reg[mfi]; +// const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); +// for (const Box& bx : bl) +// { +// dst.copy(src, bx, 0, bx, 0, 1); +// } +// } +// } +// +// // Copy from regular data to PML's first component +// // Zero out the second (and third) component +// MultiFab::Copy(tmpregmf,reg,0,0,1,0); +// tmpregmf.setVal(0.0, 1, ncp-1, 0); +// pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); +// } + void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) { @@ -924,16 +914,8 @@ PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) // #endif const IntVect& ngr = reg.nGrowVect(); const IntVect& ngp = pml.nGrowVect(); - // const int ncp = pml.nComp(); const auto& period = geom.periodicity(); - // MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), 1, ngr); - // tmpregmf.setVal(0.0, 0, 1, ngr); - // MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, ngp); - // totpmlmf.setVal(0.0, 0, 1, ngp); - // realise sum of splitted fields inside pml - - pml.ParallelCopy(reg, 0, 0, 1, ngr, ngp, period); } @@ -948,7 +930,6 @@ PML::CopyPMLsInReg (MultiFab& pml, MultiFab& reg, const Geometry& geom) const IntVect& ngp = pml.nGrowVect(); const auto& period = geom.periodicity(); - // reg.ParallelCopy(pml, 0, 0, 1, IntVect(0), ngr, period); reg.ParallelCopy(pml, 0, 0, 1, ngp, ngr, period); } diff --git a/Source/BoundaryConditions/PML_Cplx.cpp b/Source/BoundaryConditions/PML_Cplx.cpp deleted file mode 100644 index 0a47c5d84..000000000 --- a/Source/BoundaryConditions/PML_Cplx.cpp +++ /dev/null @@ -1,958 +0,0 @@ - -#include -#include -#include - -#include -#include - -#include - -#ifdef _OPENMP -#include -#endif - -using namespace amrex; - -namespace -{ - static void FillLo (int idim, Sigma& sigma, Sigma& sigma_star, - const Box& overlap, const Box& grid, Real fac) - { - int glo = grid.smallEnd(idim); - int olo = overlap.smallEnd(idim); - int ohi = overlap.bigEnd(idim); - int slo = sigma.m_lo; - int sslo = sigma_star.m_lo; - for (int i = olo; i <= ohi+1; ++i) - { - Real offset = static_cast(glo-i); - sigma[i-slo] = fac*(offset*offset); - } - for (int i = olo; i <= ohi; ++i) - { - Real offset = static_cast(glo-i) - 0.5; - sigma_star[i-sslo] = fac*(offset*offset); - } - } - - static void FillHi (int idim, Sigma& sigma, Sigma& sigma_star, - const Box& overlap, const Box& grid, Real fac) - { - int ghi = grid.bigEnd(idim); - int olo = overlap.smallEnd(idim); - int ohi = overlap.bigEnd(idim); - int slo = sigma.m_lo; - int sslo = sigma_star.m_lo; - for (int i = olo; i <= ohi+1; ++i) - { - Real offset = static_cast(i-ghi-1); - sigma[i-slo] = fac*(offset*offset); - } - for (int i = olo; i <= ohi; ++i) - { - Real offset = static_cast(i-ghi) - 0.5; - sigma_star[i-sslo] = fac*(offset*offset); - } - } - - static void FillZero (int idim, Sigma& sigma, Sigma& sigma_star, const Box& overlap) - { - int olo = overlap.smallEnd(idim); - int ohi = overlap.bigEnd(idim); - int slo = sigma.m_lo; - int sslo = sigma_star.m_lo; - std::fill(sigma.begin()+(olo-slo), sigma.begin()+(ohi+2-slo), 0.0); - std::fill(sigma_star.begin()+(olo-sslo), sigma_star.begin()+(ohi+1-sslo), 0.0); - } -} - -SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int ncell, int delta) -{ - BL_ASSERT(box.cellCentered()); - - const IntVect& sz = box.size(); - const int* lo = box.loVect(); - const int* hi = box.hiVect(); - - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - sigma [idim].resize(sz[idim]+1); - sigma_star [idim].resize(sz[idim] ); - sigma_fac [idim].resize(sz[idim]+1); - sigma_star_fac[idim].resize(sz[idim] ); - - sigma [idim].m_lo = lo[idim]; - sigma [idim].m_hi = hi[idim]+1; - sigma_star [idim].m_lo = lo[idim]; - sigma_star [idim].m_hi = hi[idim]; - sigma_fac [idim].m_lo = lo[idim]; - sigma_fac [idim].m_hi = hi[idim]+1; - sigma_star_fac[idim].m_lo = lo[idim]; - sigma_star_fac[idim].m_hi = hi[idim]; - } - - Array fac; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); - } - - const std::vector >& isects = grids.intersections(box, false, ncell); - - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - int jdim = (idim+1) % AMREX_SPACEDIM; -#if (AMREX_SPACEDIM == 3) - int kdim = (idim+2) % AMREX_SPACEDIM; -#endif - - Vector direct_faces, side_faces, direct_side_edges, side_side_edges, corners; - for (const auto& kv : isects) - { - const Box& grid_box = grids[kv.first]; - - if (amrex::grow(grid_box, idim, ncell).intersects(box)) - { - direct_faces.push_back(kv.first); - } - else if (amrex::grow(grid_box, jdim, ncell).intersects(box)) - { - side_faces.push_back(kv.first); - } -#if (AMREX_SPACEDIM == 3) - else if (amrex::grow(grid_box, kdim, ncell).intersects(box)) - { - side_faces.push_back(kv.first); - } - else if (amrex::grow(amrex::grow(grid_box,idim,ncell), - jdim,ncell).intersects(box)) - { - direct_side_edges.push_back(kv.first); - } - else if (amrex::grow(amrex::grow(grid_box,idim,ncell), - kdim,ncell).intersects(box)) - { - direct_side_edges.push_back(kv.first); - } - else if (amrex::grow(amrex::grow(grid_box,jdim,ncell), - kdim,ncell).intersects(box)) - { - side_side_edges.push_back(kv.first); - } -#endif - else - { - corners.push_back(kv.first); - } - } - - for (auto gid : corners) - { - const Box& grid_box = grids[gid]; - - Box lobox = amrex::adjCellLo(grid_box, idim, ncell); - lobox.grow(jdim,ncell); -#if (AMREX_SPACEDIM == 3) - lobox.grow(kdim,ncell); -#endif - Box looverlap = lobox & box; - if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); - } - - Box hibox = amrex::adjCellHi(grid_box, idim, ncell); - hibox.grow(jdim,ncell); -#if (AMREX_SPACEDIM == 3) - hibox.grow(kdim,ncell); -#endif - Box hioverlap = hibox & box; - if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); - } - - if (!looverlap.ok() && !hioverlap.ok()) { - amrex::Abort("SigmaBox::SigmaBox(): corners, how did this happen?\n"); - } - } - -#if (AMREX_SPACEDIM == 3) - for (auto gid : side_side_edges) - { - const Box& grid_box = grids[gid]; - const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; - if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_star[idim], overlap); - } else { - amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); - } - } - - for (auto gid : direct_side_edges) - { - const Box& grid_box = grids[gid]; - - Box lobox = amrex::adjCellLo(grid_box, idim, ncell); - Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; - if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); - } - - Box hibox = amrex::adjCellHi(grid_box, idim, ncell); - Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; - if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); - } - - if (!looverlap.ok() && !hioverlap.ok()) { - amrex::Abort("SigmaBox::SigmaBox(): direct_side_edges, how did this happen?\n"); - } - } -#endif - - for (auto gid : side_faces) - { - const Box& grid_box = grids[gid]; -#if (AMREX_SPACEDIM == 2) - const Box& overlap = amrex::grow(grid_box,jdim,ncell) & box; -#else - const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; -#endif - if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_star[idim], overlap); - } else { - amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); - } - } - - for (auto gid : direct_faces) - { - const Box& grid_box = grids[gid]; - - const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); - Box looverlap = lobox & box; - if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_star[idim], looverlap, grid_box, fac[idim]); - } - - const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); - Box hioverlap = hibox & box; - if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_star[idim], hioverlap, grid_box, fac[idim]); - } - - if (!looverlap.ok() && !hioverlap.ok()) { - amrex::Abort("SigmaBox::SigmaBox(): direct faces, how did this happen?\n"); - } - } - - if (direct_faces.size() > 1) { - amrex::Abort("SigmaBox::SigmaBox(): direct_faces.size() > 1, Box gaps not wide enough?\n"); - } - } -} - -void -SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) -{ - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - for (int i = 0, N = sigma_star[idim].size(); i < N; ++i) - { - if (sigma_star[idim][i] == 0.0) - { - sigma_star_fac[idim][i] = 1.0; - } - else - { - sigma_star_fac[idim][i] = std::exp(-sigma_star[idim][i]*dt); - } - } - } -} - -void -SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) -{ - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - for (int i = 0, N = sigma[idim].size(); i < N; ++i) - { - if (sigma[idim][i] == 0.0) - { - sigma_fac[idim][i] = 1.0; - } - else - { - sigma_fac[idim][i] = std::exp(-sigma[idim][i]*dt); - } - } - } -} - -MultiSigmaBox::MultiSigmaBox (const BoxArray& ba, const DistributionMapping& dm, - const BoxArray& grid_ba, const Real* dx, int ncell, int delta) - : FabArray(ba,dm,1,0,MFInfo(), - FabFactory(grid_ba,dx,ncell,delta)) -{} - -void -MultiSigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) -{ - if (dt == dt_B) return; - - dt_B = dt; - -#ifdef _OPENMP -#pragma omp parallel -#endif - for (MFIter mfi(*this); mfi.isValid(); ++mfi) - { - (*this)[mfi].ComputePMLFactorsB(dx, dt); - } -} - -void -MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) -{ - if (dt == dt_E) return; - - dt_E = dt; - -#ifdef _OPENMP -#pragma omp parallel -#endif - for (MFIter mfi(*this); mfi.isValid(); ++mfi) - { - (*this)[mfi].ComputePMLFactorsE(dx, dt); - } -} - -PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, - const Geometry* geom, const Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window) - : m_geom(geom), - m_cgeom(cgeom) -{ - const BoxArray& ba = MakeBoxArray(*geom, grid_ba, ncell); - if (ba.size() == 0) { - m_ok = false; - return; - } else { - m_ok = true; - } - - DistributionMapping dm{ba}; - - int nge = 2; - int ngb = 2; - int ngf = (do_moving_window) ? 2 : 0; - if (WarpX::maxwell_fdtd_solver_id == 1) ngf = std::max( ngf, 1 ); - - pml_E_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::Ex_nodal_flag), dm, 3, nge)); - pml_E_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::Ey_nodal_flag), dm, 3, nge)); - pml_E_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Ez_nodal_flag), dm, 3, nge)); - pml_B_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::Bx_nodal_flag), dm, 2, ngb)); - pml_B_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::By_nodal_flag), dm, 2, ngb)); - pml_B_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::Bz_nodal_flag), dm, 2, ngb)); - - pml_E_fp[0]->setVal(0.0); - pml_E_fp[1]->setVal(0.0); - pml_E_fp[2]->setVal(0.0); - pml_B_fp[0]->setVal(0.0); - pml_B_fp[1]->setVal(0.0); - pml_B_fp[2]->setVal(0.0); - - if (do_dive_cleaning) - { - pml_F_fp.reset(new MultiFab(amrex::convert(ba,IntVect::TheUnitVector()), dm, 3, ngf)); - pml_F_fp->setVal(0.0); - } - - sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba, geom->CellSize(), ncell, delta)); - - if (cgeom) - { - - nge = 1; - ngb = 1; - - BoxArray grid_cba = grid_ba; - grid_cba.coarsen(ref_ratio); - const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba, ncell); - - DistributionMapping cdm{cba}; - - pml_E_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::Ex_nodal_flag), cdm, 3, nge)); - pml_E_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::Ey_nodal_flag), cdm, 3, nge)); - pml_E_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::Ez_nodal_flag), cdm, 3, nge)); - pml_B_cp[0].reset(new MultiFab(amrex::convert(cba,WarpX::Bx_nodal_flag), cdm, 2, ngb)); - pml_B_cp[1].reset(new MultiFab(amrex::convert(cba,WarpX::By_nodal_flag), cdm, 2, ngb)); - pml_B_cp[2].reset(new MultiFab(amrex::convert(cba,WarpX::Bz_nodal_flag), cdm, 2, ngb)); - - pml_E_cp[0]->setVal(0.0); - pml_E_cp[1]->setVal(0.0); - pml_E_cp[2]->setVal(0.0); - pml_B_cp[0]->setVal(0.0); - pml_B_cp[1]->setVal(0.0); - pml_B_cp[2]->setVal(0.0); - - if (do_dive_cleaning) - { - pml_F_cp.reset(new MultiFab(amrex::convert(cba,IntVect::TheUnitVector()), cdm, 3, ngf)); - pml_F_cp->setVal(0.0); - } - - sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); - } - -} - -// BoxArray -// PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) -// { -// Box domain = geom.Domain(); -// for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -// if ( ! geom.isPeriodic(idim) ) { -// domain.grow(idim, ncell); -// } -// } -// -// BoxList bl; -// for (int i = 0, N = grid_ba.size(); i < N; ++i) -// { -// const Box& grid_bx = grid_ba[i]; -// const IntVect& grid_bx_sz = grid_bx.size(); -// AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, -// "Consider using larger amr.blocking_factor"); -// -// Box bx = grid_bx; -// bx.grow(ncell); -// bx &= domain; -// -// Vector bndryboxes; -// #if (AMREX_SPACEDIM == 3) -// int kbegin = -1, kend = 1; -// #else -// int kbegin = 0, kend = 0; -// #endif -// for (int kk = kbegin; kk <= kend; ++kk) { -// for (int jj = -1; jj <= 1; ++jj) { -// for (int ii = -1; ii <= 1; ++ii) { -// if (ii != 0 || jj != 0 || kk != 0) { -// Box b = grid_bx; -// b.shift(grid_bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); -// b &= bx; -// if (b.ok()) { -// bndryboxes.push_back(b); -// } -// } -// } -// } -// } -// -// const BoxList& noncovered = grid_ba.complementIn(bx); -// for (const Box& b : noncovered) { -// for (const auto& bb : bndryboxes) { -// Box ib = b & bb; -// if (ib.ok()) { -// bl.push_back(ib); -// } -// } -// } -// } -// -// BoxArray ba(bl); -// ba.removeOverlap(false); -// -// return ba; -// } - -BoxArray -PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) -{ - Box domain = geom.Domain(); - - IntVect limInfDomain = domain.smallEnd(); - IntVect limSupDomain = domain.bigEnd(); - - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if ( ! geom.isPeriodic(idim) ) { - // Create the simulation area (inside the whole domain) (only if non-periodical boundary conditions) - domain.grow(idim, -ncell); // I don't know if that works - // domain.growHi(idim, -ncell); - // domain.growLo(idim, -ncell); - } - } - - BoxList bl; - for (int i = 0, N = grid_ba.size(); i < N; ++i) - { - const Box& grid_bx = grid_ba[i]; - // const IntVect& grid_bx_sz = grid_bx.size(); - // AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, - // "Consider using larger amr.blocking_factor"); - - Box bx = grid_bx; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - bx.grow(idim, -ncell); - } - bx &= domain; // is this step necessary? We're always inside the domain by doing so, even if there are some periodical boundary conditions... - const IntVect& bx_sz = bx.size(); - - Vector bndryboxes; -#if (AMREX_SPACEDIM == 3) - int kbegin = -1, kend = 1; -#else - int kbegin = 0, kend = 0; -#endif - for (int kk = kbegin; kk <= kend; ++kk) { - for (int jj = -1; jj <= 1; ++jj) { - for (int ii = -1; ii <= 1; ++ii) { - if (ii != 0 || jj != 0 || kk != 0) { - // if ((ii != 0 && jj == 0 && kk == 0)||(ii == 0 && jj != 0 && kk == 0)||(ii == 0 && jj == 0 && kk != 0)) { - if(ii!=0 && jj!=0){ - int xlimg, xlimd, ylimg, ylimd; - if (ii == -1){ - xlimg = grid_bx.smallEnd()[0]; - xlimd = limInfDomain[0]; - } - else if (ii = 1) { - xlimg = grid_bx.bigEnd()[0]; - xlimd = limSupDomain[0]; - } - - if (jj == -1){ - ylimg = grid_bx.smallEnd()[1]; - ylimd = limInfDomain[1]; - } - else if (jj = 1){ - ylimg = grid_bx.bigEnd()[1]; - ylimd = limSupDomain[1]; - } - - if (xlimd==xlimg && ylimd==ylimg){ - amrex::Print() << "INDICES : i = " << ii << " j = " << jj << std::endl; - Box b = grid_bx; //grid_bx; - b.shift(bx_sz * IntVect{AMREX_D_DECL(ii,jj,kk)}); - b.shift(ncell * IntVect{AMREX_D_DECL(ii,jj,kk)}); - b &= grid_bx;// grid_bx; - amrex::Print() << "BOITE = [" << b.smallEnd()[0]<<", "<< b.smallEnd()[1]<< ", "<ComputePMLFactorsB(m_geom->CellSize(), dt); - sigba_fp->ComputePMLFactorsE(m_geom->CellSize(), dt); - } - if (sigba_cp) { - sigba_cp->ComputePMLFactorsB(m_cgeom->CellSize(), dt); - sigba_cp->ComputePMLFactorsE(m_cgeom->CellSize(), dt); - } -} - -std::array -PML::GetE_fp () -{ - return {pml_E_fp[0].get(), pml_E_fp[1].get(), pml_E_fp[2].get()}; -} - -std::array -PML::GetB_fp () -{ - return {pml_B_fp[0].get(), pml_B_fp[1].get(), pml_B_fp[2].get()}; -} - -std::array -PML::GetE_cp () -{ - return {pml_E_cp[0].get(), pml_E_cp[1].get(), pml_E_cp[2].get()}; -} - -std::array -PML::GetB_cp () -{ - return {pml_B_cp[0].get(), pml_B_cp[1].get(), pml_B_cp[2].get()}; -} - -MultiFab* -PML::GetF_fp () -{ - return pml_F_fp.get(); -} - -MultiFab* -PML::GetF_cp () -{ - return pml_F_cp.get(); -} - -void -PML::ExchangeB (const std::array& B_fp, - const std::array& B_cp) -{ - ExchangeB(PatchType::fine, B_fp); - ExchangeB(PatchType::coarse, B_cp); -} - -void -PML::ExchangeB (PatchType patch_type, - const std::array& Bp) -{ - if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) - { - Exchange(*pml_B_fp[0], *Bp[0], *m_geom); - Exchange(*pml_B_fp[1], *Bp[1], *m_geom); - Exchange(*pml_B_fp[2], *Bp[2], *m_geom); - } - else if (patch_type == PatchType::coarse && pml_B_cp[0] && Bp[0]) - { - Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom); - Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom); - Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom); - } -} - -void -PML::ExchangeE (const std::array& E_fp, - const std::array& E_cp) -{ - ExchangeE(PatchType::fine, E_fp); - ExchangeE(PatchType::coarse, E_cp); -} - -void -PML::ExchangeE (PatchType patch_type, - const std::array& Ep) -{ - if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) - { - Exchange(*pml_E_fp[0], *Ep[0], *m_geom); - Exchange(*pml_E_fp[1], *Ep[1], *m_geom); - Exchange(*pml_E_fp[2], *Ep[2], *m_geom); - } - else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) - { - Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom); - Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom); - Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom); - } -} - -void -PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) -{ - ExchangeF(PatchType::fine, F_fp); - ExchangeF(PatchType::coarse, F_cp); -} - -void -PML::ExchangeF (PatchType patch_type, MultiFab* Fp) -{ - if (patch_type == PatchType::fine && pml_F_fp && Fp) { - Exchange(*pml_F_fp, *Fp, *m_geom); - } else if (patch_type == PatchType::coarse && pml_F_cp && Fp) { - Exchange(*pml_F_cp, *Fp, *m_cgeom); - } -} - -void -PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) -{ - const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const int ncp = pml.nComp(); - const auto& period = geom.periodicity(); - - MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data - { - MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); - MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); - if (ncp == 3) { - MultiFab::Add(totpmlmf,pml,2,0,1,0); - } - - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); - tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); - -#ifdef _OPENMP -#pragma omp parallel -#endif - for (MFIter mfi(reg); mfi.isValid(); ++mfi) - { - const FArrayBox& src = tmpregmf[mfi]; - FArrayBox& dst = reg[mfi]; - const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); - for (const Box& bx : bl) - { - dst.copy(src, bx, 0, bx, 0, 1); - } - } - } - - // Copy from regular data to PML's first component - // Zero out the second (and third) component - MultiFab::Copy(tmpregmf,reg,0,0,1,0); - tmpregmf.setVal(0.0, 1, ncp-1, 0); - pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); -} - -void -PML::FillBoundary () -{ - FillBoundaryE(); - FillBoundaryB(); - FillBoundaryF(); -} - -void -PML::FillBoundaryE () -{ - FillBoundaryE(PatchType::fine); - FillBoundaryE(PatchType::coarse); -} - -void -PML::FillBoundaryE (PatchType patch_type) -{ - if (patch_type == PatchType::fine && pml_E_fp[0] && pml_E_fp[0]->nGrowVect().max() > 0) - { - const auto& period = m_geom->periodicity(); - Vector mf{pml_E_fp[0].get(),pml_E_fp[1].get(),pml_E_fp[2].get()}; - amrex::FillBoundary(mf, period); - } - else if (patch_type == PatchType::coarse && pml_E_cp[0] && pml_E_cp[0]->nGrowVect().max() > 0) - { - const auto& period = m_cgeom->periodicity(); - Vector mf{pml_E_cp[0].get(),pml_E_cp[1].get(),pml_E_cp[2].get()}; - amrex::FillBoundary(mf, period); - } -} - -void -PML::FillBoundaryB () -{ - FillBoundaryB(PatchType::fine); - FillBoundaryB(PatchType::coarse); -} - -void -PML::FillBoundaryB (PatchType patch_type) -{ - if (patch_type == PatchType::fine && pml_B_fp[0]) - { - const auto& period = m_geom->periodicity(); - Vector mf{pml_B_fp[0].get(),pml_B_fp[1].get(),pml_B_fp[2].get()}; - amrex::FillBoundary(mf, period); - } - else if (patch_type == PatchType::coarse && pml_B_cp[0]) - { - const auto& period = m_cgeom->periodicity(); - Vector mf{pml_B_cp[0].get(),pml_B_cp[1].get(),pml_B_cp[2].get()}; - amrex::FillBoundary(mf, period); - } -} - -void -PML::FillBoundaryF () -{ - FillBoundaryF(PatchType::fine); - FillBoundaryF(PatchType::coarse); -} - -void -PML::FillBoundaryF (PatchType patch_type) -{ - if (patch_type == PatchType::fine && pml_F_fp && pml_F_fp->nGrowVect().max() > 0) - { - const auto& period = m_geom->periodicity(); - pml_F_fp->FillBoundary(period); - } - else if (patch_type == PatchType::coarse && pml_F_cp && pml_F_cp->nGrowVect().max() > 0) - { - const auto& period = m_cgeom->periodicity(); - pml_F_cp->FillBoundary(period); - } -} - -void -PML::CheckPoint (const std::string& dir) const -{ - if (pml_E_fp[0]) - { - VisMF::Write(*pml_E_fp[0], dir+"_Ex_fp"); - VisMF::Write(*pml_E_fp[1], dir+"_Ey_fp"); - VisMF::Write(*pml_E_fp[2], dir+"_Ez_fp"); - VisMF::Write(*pml_B_fp[0], dir+"_Bx_fp"); - VisMF::Write(*pml_B_fp[1], dir+"_By_fp"); - VisMF::Write(*pml_B_fp[2], dir+"_Bz_fp"); - } - - if (pml_E_cp[0]) - { - VisMF::Write(*pml_E_cp[0], dir+"_Ex_cp"); - VisMF::Write(*pml_E_cp[1], dir+"_Ey_cp"); - VisMF::Write(*pml_E_cp[2], dir+"_Ez_cp"); - VisMF::Write(*pml_B_cp[0], dir+"_Bx_cp"); - VisMF::Write(*pml_B_cp[1], dir+"_By_cp"); - VisMF::Write(*pml_B_cp[2], dir+"_Bz_cp"); - } -} - -void -PML::Restart (const std::string& dir) -{ - if (pml_E_fp[0]) - { - VisMF::Read(*pml_E_fp[0], dir+"_Ex_fp"); - VisMF::Read(*pml_E_fp[1], dir+"_Ey_fp"); - VisMF::Read(*pml_E_fp[2], dir+"_Ez_fp"); - VisMF::Read(*pml_B_fp[0], dir+"_Bx_fp"); - VisMF::Read(*pml_B_fp[1], dir+"_By_fp"); - VisMF::Read(*pml_B_fp[2], dir+"_Bz_fp"); - } - - if (pml_E_cp[0]) - { - VisMF::Read(*pml_E_cp[0], dir+"_Ex_cp"); - VisMF::Read(*pml_E_cp[1], dir+"_Ey_cp"); - VisMF::Read(*pml_E_cp[2], dir+"_Ez_cp"); - VisMF::Read(*pml_B_cp[0], dir+"_Bx_cp"); - VisMF::Read(*pml_B_cp[1], dir+"_By_cp"); - VisMF::Read(*pml_B_cp[2], dir+"_Bz_cp"); - } -} diff --git a/Source/BoundaryConditions/WarpXEvolvePML.cpp b/Source/BoundaryConditions/WarpXEvolvePML.cpp index 08173e424..dd67bfee5 100644 --- a/Source/BoundaryConditions/WarpXEvolvePML.cpp +++ b/Source/BoundaryConditions/WarpXEvolvePML.cpp @@ -111,21 +111,19 @@ WarpX::DampJPML (int lev, PatchType patch_type) #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - // amrex::Print()<<"===== DAMP PML ====="<ok()){ @@ -321,14 +317,7 @@ WarpX::OneStep_nosub (Real cur_time) } if (do_pml && do_pml_j_damping){ - // amrex::Print()<< "WarpXEvolveEM.cpp : DampJ "<ok()){ - // amrex::Print()<< "[AV COPY] max_Jx = "<< current_fp[lev][0].get()->min(0) << std::endl; - // amrex::Print()<< "[AV COPY] max_Jx_pml = "<< pml[lev]->Getj_fp()[0]->min(0) << std::endl; - // amrex::Print()<< "===== Copy J from PML to Reg ====="<< std::endl; pml[lev]->CopyJinReg({ current_fp[lev][0].get(), current_fp[lev][1].get(), current_fp[lev][2].get() }, { current_cp[lev][0].get(), current_cp[lev][1].get(), current_cp[lev][2].get() }); - // amrex::Print()<< "[AP COPY] max_Jx = "<< current_fp[lev][0].get()->min(0) << std::endl; - } } } EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { - // amrex::Print()<< "WarpXEvolveEM.cpp : Damp "< > pml; amrex::Real moving_window_x = std::numeric_limits::max(); diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 77fd83f7a..08a8b7b88 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -382,6 +382,11 @@ WarpX::ReadParameters () pp.query("pml_delta", pml_delta); pp.query("pml_has_particles", pml_has_particles); pp.query("do_pml_j_damping", do_pml_j_damping); + pp.query("do_pml_in_domain", do_pml_in_domain); + + if ( (do_pml_j_damping==1)&&(do_pml_in_domain==0) ){ + amrex::Abort("J-damping can only be done when PML are inside simulation domain (do_pml_in_domain=1)"); + } pp.query("dump_openpmd", dump_openpmd); pp.query("dump_plotfiles", dump_plotfiles); -- cgit v1.2.3 From e53c2b72b6a44b2507377eae9f66fff3bc813f2c Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 16 Jul 2019 18:29:37 +0200 Subject: Started to add flag do_pml_in_domain for the merge request. --- Source/BoundaryConditions/PML.H | 18 +++---- Source/BoundaryConditions/PML.cpp | 82 +++++++++++++++++++------------- Source/FieldSolver/WarpXPushFieldsEM.cpp | 2 +- Source/Initialization/WarpXInitData.cpp | 6 +-- Source/Parallelization/WarpXComm.cpp | 18 +++---- 5 files changed, 71 insertions(+), 55 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 62a378986..c64eb8193 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -81,7 +81,7 @@ struct SigmaBox SigmaVect sigma_star_cum_fac; std::string pml_type; // if pml normal to x : if pml Hi : pml_type={1,0,0}; if pml Lo: pml_type={-1,0,0} - std::array pml_type_array; + std::array pml_type_array; }; namespace amrex { @@ -128,7 +128,7 @@ class PML public: PML (const amrex::BoxArray& ba, const amrex::DistributionMapping& dm, const amrex::Geometry* geom, const amrex::Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles); + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain); void ComputePMLFactors (amrex::Real dt); @@ -149,25 +149,25 @@ public: { return *sigba_cp; } void ExchangeB (const std::array& B_fp, - const std::array& B_cp); + const std::array& B_cp, int do_pml_in_domain); void ExchangeE (const std::array& E_fp, - const std::array& E_cp); + const std::array& E_cp, int do_pml_in_domain); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); void CopyJinReg (const std::array& j_fp, const std::array& j_cp); void ExchangeB (PatchType patch_type, - const std::array& Bp); + const std::array& Bp, int do_pml_in_domain); void ExchangeE (PatchType patch_type, - const std::array& Ep); + const std::array& Ep, int do_pml_in_domain); void CopyJinPMLs (PatchType patch_type, const std::array& jp); void CopyJinReg (PatchType patch_type, const std::array& jp); - void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp); - void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp); + void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain); + void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain); void FillBoundary (); void FillBoundaryE (); @@ -205,7 +205,7 @@ private: static amrex::BoxArray MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell); - static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyPMLsInReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 1f1cc80c3..c8d8585d8 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -474,10 +474,11 @@ MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const Geometry* geom, const Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles) + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain) : m_geom(geom), m_cgeom(cgeom) { + Box domain0 = geom->Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom->isPeriodic(idim) ) { @@ -486,7 +487,11 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); - const BoxArray& ba = MakeBoxArray(*geom, grid_ba_reduced, ncell); //MakeBoxArray(*geom, grid_ba, ncell); + // const BoxArray& ba = MakeBoxArray(*geom, grid_ba_reduced, ncell); + // + // const BoxArray& ba = MakeBoxArray(*geom, grid_ba, ncell); + const BoxArray& ba = (do_pml_in_domain)? MakeBoxArray(*geom, grid_ba_reduced, ncell) : MakeBoxArray(*geom, grid_ba, ncell); + if (ba.size() == 0) { m_ok = false; return; @@ -529,8 +534,13 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_F_fp->setVal(0.0); } + if (do_pml_in_domain){ + sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba_reduced, geom->CellSize(), ncell, delta)); + } + else { + sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba, geom->CellSize(), ncell, delta)); + } - sigba_fp.reset(new MultiSigmaBox(ba, dm, grid_ba_reduced, geom->CellSize(), ncell, delta)); if (cgeom) { @@ -541,7 +551,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, BoxArray grid_cba = grid_ba; grid_cba.coarsen(ref_ratio); const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); - const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba_reduced, ncell); + // const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba_reduced, ncell); + const BoxArray& cba = (do_pml_in_domain) ? MakeBoxArray(*cgeom, grid_cba_reduced, ncell) : MakeBoxArray(*cgeom, grid_cba, ncell); DistributionMapping cdm{cba}; @@ -572,8 +583,13 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_j_cp[1]->setVal(0.0); pml_j_cp[2]->setVal(0.0); - // sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); - sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba_reduced, cgeom->CellSize(), ncell, delta)); + if (do_pml_in_domain){ + sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba_reduced, cgeom->CellSize(), ncell, delta)); + } + else { + sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); + } + } } @@ -701,53 +717,53 @@ PML::GetF_cp () void PML::ExchangeB (const std::array& B_fp, - const std::array& B_cp) + const std::array& B_cp, int do_pml_in_domain) { - ExchangeB(PatchType::fine, B_fp); - ExchangeB(PatchType::coarse, B_cp); + ExchangeB(PatchType::fine, B_fp, do_pml_in_domain); + ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain); } void PML::ExchangeB (PatchType patch_type, - const std::array& Bp) + const std::array& Bp, int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) { - Exchange(*pml_B_fp[0], *Bp[0], *m_geom); - Exchange(*pml_B_fp[1], *Bp[1], *m_geom); - Exchange(*pml_B_fp[2], *Bp[2], *m_geom); + Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain); + Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain); + Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain); } else if (patch_type == PatchType::coarse && pml_B_cp[0] && Bp[0]) { - Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom); - Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom); - Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom); + Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain); + Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain); + Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain); } } void PML::ExchangeE (const std::array& E_fp, - const std::array& E_cp) + const std::array& E_cp, int do_pml_in_domain) { - ExchangeE(PatchType::fine, E_fp); - ExchangeE(PatchType::coarse, E_cp); + ExchangeE(PatchType::fine, E_fp, do_pml_in_domain); + ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain); } void PML::ExchangeE (PatchType patch_type, - const std::array& Ep) + const std::array& Ep, int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) { - Exchange(*pml_E_fp[0], *Ep[0], *m_geom); - Exchange(*pml_E_fp[1], *Ep[1], *m_geom); - Exchange(*pml_E_fp[2], *Ep[2], *m_geom); + Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain); + Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain); + Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain); } else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) { - Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom); - Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom); - Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom); + Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain); + Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain); + Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain); } } @@ -804,19 +820,19 @@ PML::CopyJinReg (const std::array& j_fp, } void -PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp) +PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain) { - ExchangeF(PatchType::fine, F_fp); - ExchangeF(PatchType::coarse, F_cp); + ExchangeF(PatchType::fine, F_fp, do_pml_in_domain); + ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain); } void -PML::ExchangeF (PatchType patch_type, MultiFab* Fp) +PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_F_fp && Fp) { - Exchange(*pml_F_fp, *Fp, *m_geom); + Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain); } else if (patch_type == PatchType::coarse && pml_F_cp && Fp) { - Exchange(*pml_F_cp, *Fp, *m_cgeom); + Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain); } } @@ -864,7 +880,7 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp) // } void -PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) +PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain) { const IntVect& ngr = reg.nGrowVect(); diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index 298b03dc6..8b749fc54 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -315,7 +315,7 @@ WarpX::EvolveE (int lev, PatchType patch_type, amrex::Real a_dt) if (do_pml && pml[lev]->ok()) { - if (F) pml[lev]->ExchangeF(patch_type, F); + if (F) pml[lev]->ExchangeF(patch_type, F, do_pml_in_domain); const auto& pml_B = (patch_type == PatchType::fine) ? pml[lev]->GetB_fp() : pml[lev]->GetB_cp(); const auto& pml_E = (patch_type == PatchType::fine) ? pml[lev]->GetE_fp() : pml[lev]->GetE_cp(); diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 76704bcfe..5598b29fd 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -134,13 +134,13 @@ WarpX::InitPML () if (do_pml) { pml[0].reset(new PML(boxArray(0), DistributionMap(0), &Geom(0), nullptr, - pml_ncell, pml_delta, 0, do_dive_cleaning, do_moving_window, pml_has_particles)); //pml_has_particles)); + pml_ncell, pml_delta, 0, do_dive_cleaning, do_moving_window, pml_has_particles, do_pml_in_domain)); //pml_has_particles)); for (int lev = 1; lev <= finest_level; ++lev) { pml[lev].reset(new PML(boxArray(lev), DistributionMap(lev), &Geom(lev), &Geom(lev-1), pml_ncell, pml_delta, refRatio(lev-1)[0], do_dive_cleaning, - do_moving_window, pml_has_particles)); //pml_has_particles)); + do_moving_window, pml_has_particles, do_pml_in_domain)); //pml_has_particles)); } } } @@ -322,7 +322,7 @@ WarpX::InitLevelData (int lev, Real time) void WarpX::InitLevelDataFFT (int lev, Real time) { - + Efield_fp_fft[lev][0]->setVal(0.0); Efield_fp_fft[lev][1]->setVal(0.0); Efield_fp_fft[lev][2]->setVal(0.0); diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index 9d85783b0..7c00a5297 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -18,7 +18,7 @@ WarpX::ExchangeWithPmlB (int lev) Bfield_fp[lev][2].get() }, { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }); + Bfield_cp[lev][2].get() }, do_pml_in_domain); } } @@ -31,7 +31,7 @@ WarpX::ExchangeWithPmlE (int lev) Efield_fp[lev][2].get() }, { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }); + Efield_cp[lev][2].get() }, do_pml_in_domain); } } @@ -40,7 +40,7 @@ WarpX::ExchangeWithPmlF (int lev) { if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeF(F_fp[lev].get(), - F_cp[lev].get()); + F_cp[lev].get(), do_pml_in_domain); } } @@ -252,7 +252,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) pml[lev]->ExchangeE(patch_type, { Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), - Efield_fp[lev][2].get() }); + Efield_fp[lev][2].get() }, do_pml_in_domain); pml[lev]->FillBoundaryE(patch_type); } @@ -267,7 +267,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) pml[lev]->ExchangeE(patch_type, { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }); + Efield_cp[lev][2].get() }, do_pml_in_domain); pml[lev]->FillBoundaryE(patch_type); } @@ -294,7 +294,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) pml[lev]->ExchangeB(patch_type, { Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), - Bfield_fp[lev][2].get() }); + Bfield_fp[lev][2].get() }, do_pml_in_domain); pml[lev]->FillBoundaryB(patch_type); } const auto& period = Geom(lev).periodicity(); @@ -308,7 +308,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) pml[lev]->ExchangeB(patch_type, { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }); + Bfield_cp[lev][2].get() }, do_pml_in_domain); pml[lev]->FillBoundaryB(patch_type); } const auto& cperiod = Geom(lev-1).periodicity(); @@ -331,7 +331,7 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) { if (do_pml && pml[lev]->ok()) { - pml[lev]->ExchangeF(patch_type, F_fp[lev].get()); + pml[lev]->ExchangeF(patch_type, F_fp[lev].get(), do_pml_in_domain); pml[lev]->FillBoundaryF(patch_type); } @@ -342,7 +342,7 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) { if (do_pml && pml[lev]->ok()) { - pml[lev]->ExchangeF(patch_type, F_cp[lev].get()); + pml[lev]->ExchangeF(patch_type, F_cp[lev].get(), do_pml_in_domain); pml[lev]->FillBoundaryF(patch_type); } -- cgit v1.2.3 From 6a94b70452c0f6accce49cf1d75074906267326e Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 16 Jul 2019 18:50:19 +0200 Subject: Added the changes for the flag do_pml)_in_domain. Compiling, but does not give the expected result when executed. --- Source/BoundaryConditions/PML.cpp | 142 +++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 70 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index c8d8585d8..e7c6e7bb2 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -836,89 +836,91 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain) } } -// void -// PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom) -// { -// const IntVect& ngr = reg.nGrowVect(); -// const IntVect& ngp = pml.nGrowVect(); -// const int ncp = pml.nComp(); -// const auto& period = geom.periodicity(); -// -// MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); -// -// if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data -// { -// MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); -// MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); -// if (ncp == 3) { -// MultiFab::Add(totpmlmf,pml,2,0,1,0); -// } -// -// MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); -// tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); -// -// #ifdef _OPENMP -// #pragma omp parallel -// #endif -// for (MFIter mfi(reg); mfi.isValid(); ++mfi) -// { -// const FArrayBox& src = tmpregmf[mfi]; -// FArrayBox& dst = reg[mfi]; -// const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); -// for (const Box& bx : bl) -// { -// dst.copy(src, bx, 0, bx, 0, 1); -// } -// } -// } -// -// // Copy from regular data to PML's first component -// // Zero out the second (and third) component -// MultiFab::Copy(tmpregmf,reg,0,0,1,0); -// tmpregmf.setVal(0.0, 1, ncp-1, 0); -// pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); -// } void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain) { + if (do_pml_in_domain){ + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + const int ncp = pml.nComp(); + const auto& period = geom.periodicity(); + + MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); + tmpregmf.setVal(0.0, 0, ncp, ngr); + MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), ncp, ngp); + totpmlmf.setVal(0.0, 0, ncp, ngp); + // realise sum of splitted fields inside pml + MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); + if (ncp == 3) { + MultiFab::Add(totpmlmf,pml,2,0,1,0); + } + totpmlmf.setVal(0.0, 1, ncp-1, 0); + reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); - const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const int ncp = pml.nComp(); - const auto& period = geom.periodicity(); - - MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - tmpregmf.setVal(0.0, 0, ncp, ngr); - MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), ncp, ngp); - totpmlmf.setVal(0.0, 0, ncp, ngp); - // realise sum of splitted fields inside pml - MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); - if (ncp == 3) { - MultiFab::Add(totpmlmf,pml,2,0,1,0); - } - totpmlmf.setVal(0.0, 1, ncp-1, 0); - reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); - - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data - { - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); - tmpregmf.setVal(0.0, 1, ncp-1, 0); - totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); + if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data + { + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + tmpregmf.setVal(0.0, 1, ncp-1, 0); + totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); // #ifdef _OPENMP // #pragma omp parallel // #endif - for (MFIter mfi(pml); mfi.isValid(); ++mfi) + for (MFIter mfi(pml); mfi.isValid(); ++mfi) + { + const FArrayBox& src = totpmlmf[mfi]; + FArrayBox& dst = pml[mfi]; + const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); + for (const Box& bx : bl) + { + dst.copy(src, bx, 0, bx, 0, 1); + } + } + } + } + + else { + + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + const int ncp = pml.nComp(); + const auto& period = geom.periodicity(); + + MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); + + if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data { - const FArrayBox& src = totpmlmf[mfi]; - FArrayBox& dst = pml[mfi]; - const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); //amrex::boxDiff(dst.box(), mfi.validbox()); - for (const Box& bx : bl) + MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); + MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); + if (ncp == 3) { + MultiFab::Add(totpmlmf,pml,2,0,1,0); + } + + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); + +#ifdef _OPENMP +#pragma omp parallel +#endif + for (MFIter mfi(reg); mfi.isValid(); ++mfi) { - dst.copy(src, bx, 0, bx, 0, 1); + const FArrayBox& src = tmpregmf[mfi]; + FArrayBox& dst = reg[mfi]; + const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); + for (const Box& bx : bl) + { + dst.copy(src, bx, 0, bx, 0, 1); + } } } + + // Copy from regular data to PML's first component + // Zero out the second (and third) component + MultiFab::Copy(tmpregmf,reg,0,0,1,0); + tmpregmf.setVal(0.0, 1, ncp-1, 0); + pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); } + } -- cgit v1.2.3 From afe646b66116f7d554b6c3874f818cb2249b2922 Mon Sep 17 00:00:00 2001 From: ablelly Date: Tue, 16 Jul 2019 19:10:56 +0200 Subject: Cleaned code. Flag `do_pml_in_domain` is working. --- Source/BoundaryConditions/PML.cpp | 18 +----------------- Source/FieldSolver/WarpXPushFieldsEM.cpp | 12 ++---------- Source/Initialization/WarpXInitData.cpp | 4 ++-- 3 files changed, 5 insertions(+), 29 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index e7c6e7bb2..3888a59d0 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -144,42 +144,35 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (amrex::grow(grid_box, idim, ncell).intersects(box)) { direct_faces.push_back(kv.first); - amrex::Print()<<"direct_faces"< 1, Box gaps not wide enough?\n"); } } - amrex::Print()<<"pml_type = "< Date: Tue, 23 Jul 2019 22:49:49 +0200 Subject: Moving Window working now for pml in domain. --- Source/BoundaryConditions/PML.cpp | 22 +++++- Source/Particles/PhysicalParticleContainer.cpp | 96 +++++++++++++++++--------- 2 files changed, 83 insertions(+), 35 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 3888a59d0..1df3e3ba8 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -635,6 +635,13 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, BoxArray ba(bl); ba.removeOverlap(false); + amrex::Print()<<">> PRINT PML BOXES <<"<< std::endl; + const BoxList& bl2 = BoxList(ba); + amrex::Print()<<"["< 0) // Copy from pml to the ghost cells of regular data { MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); tmpregmf.setVal(0.0, 1, ncp-1, 0); - totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); + // totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); + tmpregmf.ParallelCopy(totpmlmf,0, 0, ncp, IntVect(0), IntVect(0), period); + // totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, ngr, ngp, period); + totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, ngr, IntVect(0), period); // #ifdef _OPENMP // #pragma omp parallel // #endif + // amrex::Print()<<">> PML EXCHANGE <<"< r; @@ -62,7 +62,7 @@ NumParticlesToAdd(const Box& overlap_box, const RealBox& overlap_realbox, ++np; } } - + return np; } @@ -82,7 +82,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); pp.query("do_continuous_injection", do_continuous_injection); - // Whether to plot back-transformed (lab-frame) diagnostics + // Whether to plot back-transformed (lab-frame) diagnostics // for this species. pp.query("do_boosted_frame_diags", do_boosted_frame_diags); @@ -91,7 +91,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp do_user_plot_vars = pp.queryarr("plot_vars", plot_vars); if (not do_user_plot_vars){ // By default, all particle variables are dumped to plotfiles, - // including {x,y,z,ux,uy,uz}old variables when running in a + // including {x,y,z,ux,uy,uz}old variables when running in a // boosted frame if (WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags){ plot_flags.resize(PIdx::nattribs + 6, 1); @@ -108,9 +108,9 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp // If not none, set plot_flags values to 1 for elements in plot_vars. if (plot_vars[0] != "none"){ for (const auto& var : plot_vars){ - // Return error if var not in PIdx. - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - ParticleStringNames::to_index.count(var), + // Return error if var not in PIdx. + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + ParticleStringNames::to_index.count(var), "plot_vars argument not in ParticleStringNames"); plot_flags[ParticleStringNames::to_index.at(var)] = 1; } @@ -181,7 +181,7 @@ void PhysicalParticleContainer::MapParticletoBoostedFrame(Real& x, Real& y, Real void PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m, Real x_rms, Real y_rms, Real z_rms, - Real q_tot, long npart, + Real q_tot, long npart, int do_symmetrize) { const Geometry& geom = m_gdb->Geom(0); @@ -195,7 +195,7 @@ PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m, if (ParallelDescriptor::IOProcessor()) { std::array u; Real weight; - // If do_symmetrize, create 4x fewer particles, and + // If do_symmetrize, create 4x fewer particles, and // Replicate each particle 4 times (x,y) (-x,y) (x,-y) (-x,-y) if (do_symmetrize){ npart /= 4; @@ -226,7 +226,7 @@ PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m, u_tmp[0] *= std::pow(-1,ix); y_tmp = y*std::pow(-1,iy); u_tmp[1] *= std::pow(-1,iy); - CheckAndAddParticle(x_tmp, y_tmp, z, + CheckAndAddParticle(x_tmp, y_tmp, z, u_tmp, weight/4); } } @@ -263,7 +263,7 @@ PhysicalParticleContainer::CheckAndAddParticle(Real x, Real y, Real z, particle_tile.push_back_real(particle_comps["xold"], x); particle_tile.push_back_real(particle_comps["yold"], y); particle_tile.push_back_real(particle_comps["zold"], z); - + particle_tile.push_back_real(particle_comps["uxold"], u[0]); particle_tile.push_back_real(particle_comps["uyold"], u[1]); particle_tile.push_back_real(particle_comps["uzold"], u[2]); @@ -537,7 +537,7 @@ PhysicalParticleContainer::AddPlasmaCPU (int lev, RealBox part_realbox) attribs[PIdx::ux] = u[0]; attribs[PIdx::uy] = u[1]; attribs[PIdx::uz] = u[2]; - + if (WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags) { auto& particle_tile = DefineAndReturnParticleTile(lev, grid_id, tile_id); @@ -666,7 +666,7 @@ PhysicalParticleContainer::AddPlasmaGPU (int lev, RealBox part_realbox) Cuda::HostVector host_particles; std::array, PIdx::nattribs> host_attribs; - + // Loop through the cells of overlap_box and inject // the corresponding particles const auto& overlap_corner = overlap_realbox.lo(); @@ -828,7 +828,7 @@ PhysicalParticleContainer::AddPlasmaGPU (int lev, RealBox part_realbox) host_attribs[kk].end(), particle_tile.GetStructOfArrays().GetRealData(kk).begin() + old_size); } - + if (cost) { wt = (amrex::second() - wt) / tile_box.d_numPts(); Array4 const& costarr = cost->array(mfi); @@ -838,7 +838,7 @@ PhysicalParticleContainer::AddPlasmaGPU (int lev, RealBox part_realbox) costarr(i,j,k) += wt; }); } - } + } } } #endif @@ -1166,11 +1166,11 @@ PhysicalParticleContainer::Evolve (int lev, BL_PROFILE_VAR_NS("PICSAR::FieldGather", blp_pxr_fg); BL_PROFILE_VAR_NS("PICSAR::ParticlePush", blp_pxr_pp); BL_PROFILE_VAR_NS("PPC::Evolve::partition", blp_partition); - + const std::array& dx = WarpX::CellSize(lev); const std::array& cdx = WarpX::CellSize(std::max(lev-1,0)); - // Get instances of NCI Godfrey filters + // Get instances of NCI Godfrey filters const auto& nci_godfrey_filter_exeybz = WarpX::GetInstance().nci_godfrey_filter_exeybz; const auto& nci_godfrey_filter_bxbyez = WarpX::GetInstance().nci_godfrey_filter_bxbyez; @@ -1184,7 +1184,7 @@ PhysicalParticleContainer::Evolve (int lev, bool has_buffer = cEx || cjx; #ifdef _OPENMP -#pragma omp parallel +#pragma omp parallel #endif { #ifdef _OPENMP @@ -1383,7 +1383,7 @@ PhysicalParticleContainer::Evolve (int lev, } const long np_current = (cjx) ? nfine_current : np; - + // // copy data from particle container to temp arrays // @@ -1392,7 +1392,7 @@ PhysicalParticleContainer::Evolve (int lev, BL_PROFILE_VAR_STOP(blp_copy); if (rho) DepositCharge(pti, wp, rho, crho, 0, np_current, np, thread_num, lev); - + if (! do_not_push) { // @@ -1403,7 +1403,7 @@ PhysicalParticleContainer::Evolve (int lev, const std::array& xyzmin_grid = WarpX::LowerCorner(box, lev); const int* ixyzmin_grid = box.loVect(); - + const long np_gather = (cEx) ? nfine_gather : np; BL_PROFILE_VAR_START(blp_pxr_fg); @@ -1428,6 +1428,36 @@ PhysicalParticleContainer::Evolve (int lev, &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, &lvect_fieldgathe, &WarpX::field_gathering_algo); + // auto& attribs = pti.GetAttribs(); + // + // Real* AMREX_RESTRICT zzp = m_zp[thread_num].dataPtr(); + // Real* AMREX_RESTRICT exp = attribs[PIdx::Ex].dataPtr(); + // Real* AMREX_RESTRICT eyp = attribs[PIdx::Ey].dataPtr(); + // Real* AMREX_RESTRICT ezp = attribs[PIdx::Ez].dataPtr(); + // Real* AMREX_RESTRICT bxp = attribs[PIdx::Bx].dataPtr(); + // Real* AMREX_RESTRICT byp = attribs[PIdx::By].dataPtr(); + // Real* AMREX_RESTRICT bzp = attribs[PIdx::Bz].dataPtr(); + // + // const long np = pti.numParticles(); + // const std::array& xyzmax_grid = WarpX::UpperCorner(box, lev); + // + // // amrex::Print()<<"dx = "< xyzmax_grid[2] - 50 * dx[2]){ //zzp[i] > xyzmin_grid[2] - 10 * dx[2] + // exp[i] = 0.; + // eyp[i] = 0.; + // ezp[i] = 0.; + // bxp[i] = 0.; + // byp[i] = 0.; + // bzp[i] = 0.; + // } + // } + // ); + + if (np_gather < np) { const IntVect& ref_ratio = WarpX::RefRatio(lev-1); @@ -1479,13 +1509,13 @@ PhysicalParticleContainer::Evolve (int lev, eyeli = filtered_Ey.elixir(); nci_godfrey_filter_exeybz[lev-1]->ApplyStencil(filtered_Ey, (*cEy)[pti], filtered_Ey.box()); ceyfab = &filtered_Ey; - + // Filter Bx filtered_Bx.resize(amrex::convert(tbox,WarpX::Bx_nodal_flag)); bxeli = filtered_Bx.elixir(); nci_godfrey_filter_bxbyez[lev-1]->ApplyStencil(filtered_Bx, (*cBx)[pti], filtered_Bx.box()); cbxfab = &filtered_Bx; - + // Filter Bz filtered_Bz.resize(amrex::convert(tbox,WarpX::Bz_nodal_flag)); bzeli = filtered_Bz.elixir(); @@ -1493,7 +1523,7 @@ PhysicalParticleContainer::Evolve (int lev, cbzfab = &filtered_Bz; #endif } - + long ncrse = np - nfine_gather; warpx_geteb_energy_conserving( &ncrse, @@ -1522,7 +1552,7 @@ PhysicalParticleContainer::Evolve (int lev, // Particle Push // BL_PROFILE_VAR_START(blp_pxr_pp); - PushPX(pti, m_xp[thread_num], m_yp[thread_num], m_zp[thread_num], + PushPX(pti, m_xp[thread_num], m_yp[thread_num], m_zp[thread_num], m_giv[thread_num], dt); BL_PROFILE_VAR_STOP(blp_pxr_pp); @@ -1539,7 +1569,7 @@ PhysicalParticleContainer::Evolve (int lev, np_current, np-np_current, thread_num, lev, lev-1, dt); } - + // // copy particle data back // @@ -1547,7 +1577,7 @@ PhysicalParticleContainer::Evolve (int lev, pti.SetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); BL_PROFILE_VAR_STOP(blp_copy); } - + if (rho) DepositCharge(pti, wp, rho, crho, 1, np_current, np, thread_num, lev); if (cost) { @@ -1602,7 +1632,7 @@ PhysicalParticleContainer::SplitParticles(int lev) for(int i=0; i Date: Wed, 24 Jul 2019 00:00:05 +0200 Subject: moving window working for pml in domain --- Source/BoundaryConditions/PML.cpp | 12 ----------- Source/Particles/PhysicalParticleContainer.cpp | 30 -------------------------- 2 files changed, 42 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 1df3e3ba8..4b982adb0 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -635,13 +635,6 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, BoxArray ba(bl); ba.removeOverlap(false); - amrex::Print()<<">> PRINT PML BOXES <<"<< std::endl; - const BoxList& bl2 = BoxList(ba); - amrex::Print()<<"["<> PML EXCHANGE <<"<& xyzmax_grid = WarpX::UpperCorner(box, lev); - // - // // amrex::Print()<<"dx = "< xyzmax_grid[2] - 50 * dx[2]){ //zzp[i] > xyzmin_grid[2] - 10 * dx[2] - // exp[i] = 0.; - // eyp[i] = 0.; - // ezp[i] = 0.; - // bxp[i] = 0.; - // byp[i] = 0.; - // bzp[i] = 0.; - // } - // } - // ); - - if (np_gather < np) { const IntVect& ref_ratio = WarpX::RefRatio(lev-1); -- cgit v1.2.3 From 51d5f19d9747b30f29dd4c78523b1d3df8e688ac Mon Sep 17 00:00:00 2001 From: ablelly Date: Wed, 24 Jul 2019 23:21:03 +0200 Subject: Exchange of ghost cells modified for PML in domain. --- Source/BoundaryConditions/PML.cpp | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 4b982adb0..51107b498 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -634,6 +634,13 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, BoxArray ba(bl); ba.removeOverlap(false); + // amrex::Print()<< "####### PML BOXES #######" < 0) // Copy from pml to the ghost cells of regular data { - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, IntVect(0)); //ngr); + MultiFab::Copy(totpmlmf, pml, 0, 0, ncp, ngp); + tmpregmf.setVal(0.0, 1, ncp-1, 0); // totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); tmpregmf.ParallelCopy(totpmlmf,0, 0, ncp, IntVect(0), IntVect(0), period); // totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, ngr, ngp, period); - totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, ngr, IntVect(0), period); + totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, IntVect(0), ngp, period); // #ifdef _OPENMP // #pragma omp parallel // #endif + // amrex::Print()<<"####### EXCHANGE INFORMATIONS GHOST CELLS PML #######"<>> EXCHANGE BOXES <<<<<" <>> EXCHANGE BOXES <<<<<" < Date: Thu, 25 Jul 2019 01:45:29 +0200 Subject: [WIP] Adding flags do_pml_Lo, do_pml_hi --- Source/BoundaryConditions/PML.H | 14 +++---- Source/BoundaryConditions/PML.cpp | 59 ++++++++++++++++-------------- Source/BoundaryConditions/PML_routines.F90 | 2 +- Source/FieldSolver/WarpXPushFieldsEM.cpp | 2 +- Source/Parallelization/WarpXComm.cpp | 18 ++++----- Source/WarpX.H | 4 +- Source/WarpX.cpp | 15 ++++++++ 7 files changed, 67 insertions(+), 47 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index c64eb8193..3f64db558 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -149,25 +149,25 @@ public: { return *sigba_cp; } void ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain); + const std::array& B_cp, int do_pml_in_domain, int ncell); void ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain); + const std::array& E_cp, int do_pml_in_domain, int ncell); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); void CopyJinReg (const std::array& j_fp, const std::array& j_cp); void ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain); + const std::array& Bp, int do_pml_in_domain, int ncell); void ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain); + const std::array& Ep, int do_pml_in_domain, int ncell); void CopyJinPMLs (PatchType patch_type, const std::array& jp); void CopyJinReg (PatchType patch_type, const std::array& jp); - void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain); - void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain); + void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain, int ncell); + void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain, int ncell); void FillBoundary (); void FillBoundaryE (); @@ -205,7 +205,7 @@ private: static amrex::BoxArray MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell); - static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain); + static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain, int ncell); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyPMLsInReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 51107b498..0e6c24131 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -708,53 +708,53 @@ PML::GetF_cp () void PML::ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain) + const std::array& B_cp, int do_pml_in_domain, int ncell) { - ExchangeB(PatchType::fine, B_fp, do_pml_in_domain); - ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain); + ExchangeB(PatchType::fine, B_fp, do_pml_in_domain, ncell); + ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain, ncell); } void PML::ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain) + const std::array& Bp, int do_pml_in_domain, int ncell) { if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) { - Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain); - Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain); - Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain); + Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain, ncell); } else if (patch_type == PatchType::coarse && pml_B_cp[0] && Bp[0]) { - Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain); - Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain); - Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain); + Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain, ncell); } } void PML::ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain) + const std::array& E_cp, int do_pml_in_domain, int ncell) { - ExchangeE(PatchType::fine, E_fp, do_pml_in_domain); - ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain); + ExchangeE(PatchType::fine, E_fp, do_pml_in_domain, ncell); + ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain, ncell); } void PML::ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain) + const std::array& Ep, int do_pml_in_domain, int ncell) { if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) { - Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain); - Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain); - Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain); + Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain, ncell); } else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) { - Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain); - Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain); - Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain); + Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain, ncell); } } @@ -811,29 +811,32 @@ PML::CopyJinReg (const std::array& j_fp, } void -PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain) +PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain, int ncell) { - ExchangeF(PatchType::fine, F_fp, do_pml_in_domain); - ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain); + ExchangeF(PatchType::fine, F_fp, do_pml_in_domain, ncell); + ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain, ncell); } void -PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain) +PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain, int ncell) { if (patch_type == PatchType::fine && pml_F_fp && Fp) { - Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain); + Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain, ncell); } else if (patch_type == PatchType::coarse && pml_F_cp && Fp) { - Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain); + Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain, ncell); } } void -PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain) +PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain, int ncell) { if (do_pml_in_domain){ const IntVect& ngr = reg.nGrowVect(); const IntVect& ngp = pml.nGrowVect(); + // amrex::Print()<< "##### PML EXCHANGE #####"<ok()) { - if (F) pml[lev]->ExchangeF(patch_type, F, do_pml_in_domain); + if (F) pml[lev]->ExchangeF(patch_type, F, do_pml_in_domain, pml_ncell); const auto& pml_B = (patch_type == PatchType::fine) ? pml[lev]->GetB_fp() : pml[lev]->GetB_cp(); const auto& pml_E = (patch_type == PatchType::fine) ? pml[lev]->GetE_fp() : pml[lev]->GetE_cp(); diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index 7c00a5297..17d87c73f 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -18,7 +18,7 @@ WarpX::ExchangeWithPmlB (int lev) Bfield_fp[lev][2].get() }, { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }, do_pml_in_domain); + Bfield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); } } @@ -31,7 +31,7 @@ WarpX::ExchangeWithPmlE (int lev) Efield_fp[lev][2].get() }, { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }, do_pml_in_domain); + Efield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); } } @@ -40,7 +40,7 @@ WarpX::ExchangeWithPmlF (int lev) { if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeF(F_fp[lev].get(), - F_cp[lev].get(), do_pml_in_domain); + F_cp[lev].get(), do_pml_in_domain, pml_ncell); } } @@ -252,7 +252,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) pml[lev]->ExchangeE(patch_type, { Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), - Efield_fp[lev][2].get() }, do_pml_in_domain); + Efield_fp[lev][2].get() }, do_pml_in_domain, pml_ncell); pml[lev]->FillBoundaryE(patch_type); } @@ -267,7 +267,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) pml[lev]->ExchangeE(patch_type, { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }, do_pml_in_domain); + Efield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); pml[lev]->FillBoundaryE(patch_type); } @@ -294,7 +294,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) pml[lev]->ExchangeB(patch_type, { Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), - Bfield_fp[lev][2].get() }, do_pml_in_domain); + Bfield_fp[lev][2].get() }, do_pml_in_domain, pml_ncell); pml[lev]->FillBoundaryB(patch_type); } const auto& period = Geom(lev).periodicity(); @@ -308,7 +308,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) pml[lev]->ExchangeB(patch_type, { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }, do_pml_in_domain); + Bfield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); pml[lev]->FillBoundaryB(patch_type); } const auto& cperiod = Geom(lev-1).periodicity(); @@ -331,7 +331,7 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) { if (do_pml && pml[lev]->ok()) { - pml[lev]->ExchangeF(patch_type, F_fp[lev].get(), do_pml_in_domain); + pml[lev]->ExchangeF(patch_type, F_fp[lev].get(), do_pml_in_domain, pml_ncell); pml[lev]->FillBoundaryF(patch_type); } @@ -342,7 +342,7 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) { if (do_pml && pml[lev]->ok()) { - pml[lev]->ExchangeF(patch_type, F_cp[lev].get(), do_pml_in_domain); + pml[lev]->ExchangeF(patch_type, F_cp[lev].get(), do_pml_in_domain, pml_ncell); pml[lev]->FillBoundaryF(patch_type); } diff --git a/Source/WarpX.H b/Source/WarpX.H index 54cad9ae0..20db5c75d 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -489,10 +489,12 @@ private: // PML int do_pml = 1; int pml_ncell = 10; - int pml_delta = 10; + int pml_delta = 5; int pml_has_particles = 0; int do_pml_j_damping = 0; int do_pml_in_domain = 0; + amrex::IntVect do_pml_Lo; + amrex::IntVect do_pml_Hi; amrex::Vector > pml; amrex::Real moving_window_x = std::numeric_limits::max(); diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 08a8b7b88..46b1926a0 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -384,6 +384,21 @@ WarpX::ReadParameters () pp.query("do_pml_j_damping", do_pml_j_damping); pp.query("do_pml_in_domain", do_pml_in_domain); + Vector parse_do_pml_Lo(AMREX_SPACEDIM,1); + pp.queryarr("do_pml_Lo", parse_do_pml_Lo); + do_pml_Lo[0] = parse_do_pml_Lo[0]; + do_pml_Lo[1] = parse_do_pml_Lo[1]; +#if (AMREX_SPACEDIM == 3) + do_pml_Lo[2] = parse_do_pml_Lo[2]; +#endif + Vector parse_do_pml_Hi(AMREX_SPACEDIM,1); + pp.queryarr("do_pml_Hi", parse_do_pml_Hi); + do_pml_Hi[0] = parse_do_pml_Hi[0]; + do_pml_Hi[1] = parse_do_pml_Hi[1]; +#if (AMREX_SPACEDIM == 3) + do_pml_Hi[2] = parse_do_pml_Hi[2]; +#endif + if ( (do_pml_j_damping==1)&&(do_pml_in_domain==0) ){ amrex::Abort("J-damping can only be done when PML are inside simulation domain (do_pml_in_domain=1)"); } -- cgit v1.2.3 From 0ca6e6fc94f22df5bd9a436b4701d7d564a70ed7 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 25 Jul 2019 18:28:40 +0200 Subject: [WIP] First function modifications to include flags do_pml_Lo,do_pml_Hi --- Source/BoundaryConditions/PML.H | 13 ++++++++++--- Source/BoundaryConditions/PML.cpp | 39 +++++++++++++++++++++++++++++++-------- Source/WarpX.H | 4 ++-- 3 files changed, 43 insertions(+), 13 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 3f64db558..ca200d6e5 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -128,7 +128,10 @@ class PML public: PML (const amrex::BoxArray& ba, const amrex::DistributionMapping& dm, const amrex::Geometry* geom, const amrex::Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain); + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, + int pml_has_particles, int do_pml_in_domain, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void ComputePMLFactors (amrex::Real dt); @@ -203,9 +206,13 @@ private: std::unique_ptr sigba_cp; static amrex::BoxArray MakeBoxArray (const amrex::Geometry& geom, - const amrex::BoxArray& grid_ba, int ncell); + const amrex::BoxArray& grid_ba, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); - static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain, int ncell); + static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); static void CopyPMLsInReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 0e6c24131..316a2bd2b 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -461,15 +461,24 @@ MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const Geometry* geom, const Geometry* cgeom, - int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain) + int ncell, int delta, int ref_ratio, int do_dive_cleaning, int do_moving_window, + int pml_has_particles, int do_pml_in_domain, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) // = amrex::IntVect::TheUnitVector() : m_geom(geom), m_cgeom(cgeom) { Box domain0 = geom->Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if ( ! geom->isPeriodic(idim) ) { - domain0.grow(idim, -ncell); + if ( ! geom->isPeriodic(idim)) { + // domain0.grow(idim, -ncell); + if (do_pml_Lo[idim]){ + domain0.growLo(idim, -ncell); + } + if (do_pml_Hi[idim]){ + domain0.growHi(idim, -ncell); + } + } } const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); @@ -534,7 +543,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, BoxArray grid_cba = grid_ba; grid_cba.coarsen(ref_ratio); - const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); + const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); // domain to change ? This domain was built for a fine grid: the reduced domain is only valid for the fine level... // const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba_reduced, ncell); const BoxArray& cba = (do_pml_in_domain) ? MakeBoxArray(*cgeom, grid_cba_reduced, ncell) : MakeBoxArray(*cgeom, grid_cba, ncell); @@ -579,12 +588,19 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } BoxArray -PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell) +PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { Box domain = geom.Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom.isPeriodic(idim) ) { - domain.grow(idim, ncell); + // domain.grow(idim, ncell); + if (do_pml_Lo[idim]){ + domain.growLo(idim, ncell); + } + if (do_pml_Hi[idim]){ + domain.growHi(idim, ncell); + } } } @@ -829,7 +845,8 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain, int nc void -PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain, int ncell) +PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { if (do_pml_in_domain){ const IntVect& ngr = reg.nGrowVect(); @@ -870,7 +887,13 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in Box domain0 = geom.Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom.isPeriodic(idim) ) { - domain0.grow(idim, -ncell); //-ncell + // domain0.grow(idim, -ncell); + if (do_pml_Lo[idim]){ + domain0.growLo(idim, -ncell); + } + if (do_pml_Hi[idim]){ + domain0.growHi(idim, -ncell); + } } } // amrex::Print()<<"domain0 = ["< > pml; amrex::Real moving_window_x = std::numeric_limits::max(); -- cgit v1.2.3 From fb755bd2518d924b138aaf6124f6b7c33d1c118e Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 25 Jul 2019 20:00:16 +0200 Subject: [WIP] First tests for flags on pml. Spurious charges appearing where there use to be corners - source is still to be identified. --- Source/BoundaryConditions/PML.cpp | 34 +++++++++++++++++++++++---------- Source/Initialization/WarpXInitData.cpp | 5 +++-- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 316a2bd2b..f880ebc56 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -119,6 +119,8 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n sigma_star_cum_fac[idim].m_hi = hi[idim]; } + amrex::Print()< 1, Box gaps not wide enough?\n"); } } + amrex::Print()< Date: Fri, 2 Aug 2019 20:15:56 +0200 Subject: Modifications for communications --- Source/BoundaryConditions/PML.H | 24 +++- Source/BoundaryConditions/PML.cpp | 154 ++++++++++++++----------- Source/Evolve/WarpXEvolveEM.cpp | 26 ++--- Source/Parallelization/WarpXComm.cpp | 36 ++++-- Source/Particles/PhysicalParticleContainer.cpp | 25 ++++ 5 files changed, 169 insertions(+), 96 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index ca200d6e5..9601dfec9 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -152,25 +152,37 @@ public: { return *sigba_cp; } void ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain, int ncell); + const std::array& B_cp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain, int ncell); + const std::array& E_cp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void CopyJinPMLs (const std::array& j_fp, const std::array& j_cp); void CopyJinReg (const std::array& j_fp, const std::array& j_cp); void ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain, int ncell); + const std::array& Bp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain, int ncell); + const std::array& Ep, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void CopyJinPMLs (PatchType patch_type, const std::array& jp); void CopyJinReg (PatchType patch_type, const std::array& jp); - void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain, int ncell); - void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain, int ncell); + void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void FillBoundary (); void FillBoundaryE (); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index f880ebc56..3c75d358f 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -738,53 +738,57 @@ PML::GetF_cp () void PML::ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain, int ncell) + const std::array& B_cp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { - ExchangeB(PatchType::fine, B_fp, do_pml_in_domain, ncell); - ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain, ncell); + ExchangeB(PatchType::fine, B_fp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } void PML::ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain, int ncell) + const std::array& Bp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) { - Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain, ncell); - Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain, ncell); - Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } else if (patch_type == PatchType::coarse && pml_B_cp[0] && Bp[0]) { - Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain, ncell); - Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain, ncell); - Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } } void PML::ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain, int ncell) + const std::array& E_cp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { - ExchangeE(PatchType::fine, E_fp, do_pml_in_domain, ncell); - ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain, ncell); + ExchangeE(PatchType::fine, E_fp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } void PML::ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain, int ncell) + const std::array& Ep, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) { - Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain, ncell); - Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain, ncell); - Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) { - Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain, ncell); - Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain, ncell); - Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } } @@ -841,19 +845,21 @@ PML::CopyJinReg (const std::array& j_fp, } void -PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain, int ncell) +PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { - ExchangeF(PatchType::fine, F_fp, do_pml_in_domain, ncell); - ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain, ncell); + ExchangeF(PatchType::fine, F_fp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } void -PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain, int ncell) +PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { if (patch_type == PatchType::fine && pml_F_fp && Fp) { - Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain, ncell); + Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } else if (patch_type == PatchType::coarse && pml_F_cp && Fp) { - Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain, ncell); + Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); } } @@ -881,8 +887,18 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in MultiFab::Add(totpmlmf,pml,2,0,1,0); } totpmlmf.setVal(0.0, 1, ncp-1, 0); - // reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); //old - reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), IntVect(0), period); //new + // reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); //old - not really working + reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), IntVect(0), period); //new - works better + + // amrex::Print()<<"##### BOXES EXCHANGE PML #####"< 0) // Copy from pml to the ghost cells of regular data { @@ -890,50 +906,53 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in MultiFab::Copy(totpmlmf, pml, 0, 0, ncp, ngp); tmpregmf.setVal(0.0, 1, ncp-1, 0); - // totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, IntVect(0), ngp, period); + // ce qui foncitonne a peu pres pour le moment tmpregmf.ParallelCopy(totpmlmf,0, 0, ncp, IntVect(0), IntVect(0), period); - // totpmlmf.ParallelCopy(tmpregmf,0, 0, 1, ngr, ngp, period); totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, IntVect(0), ngp, period); + + MultiFab::Copy(pml, totpmlmf, 0, 0, ncp, ngp); //test // #ifdef _OPENMP // #pragma omp parallel // #endif - // amrex::Print()<<"####### EXCHANGE INFORMATIONS GHOST CELLS PML #######"<>> EXCHANGE BOXES <<<<<" <>> EXCHANGE BOXES <<<<<" <ok()){ - pml[lev]->CopyJinReg({ current_fp[lev][0].get(), - current_fp[lev][1].get(), - current_fp[lev][2].get() }, - { current_cp[lev][0].get(), - current_cp[lev][1].get(), - current_cp[lev][2].get() }); - } - } - } + // if (do_pml && pml_has_particles){ + // for (int lev = 0; lev <= finest_level; ++lev) + // { + // if (pml[lev]->ok()){ + // pml[lev]->CopyJinReg({ current_fp[lev][0].get(), + // current_fp[lev][1].get(), + // current_fp[lev][2].get() }, + // { current_cp[lev][0].get(), + // current_cp[lev][1].get(), + // current_cp[lev][2].get() }); + // } + // } + // } EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index 17d87c73f..06cbf157a 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -18,7 +18,9 @@ WarpX::ExchangeWithPmlB (int lev) Bfield_fp[lev][2].get() }, { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); + Bfield_cp[lev][2].get() }, + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); } } @@ -31,7 +33,9 @@ WarpX::ExchangeWithPmlE (int lev) Efield_fp[lev][2].get() }, { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); + Efield_cp[lev][2].get() }, + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); } } @@ -40,7 +44,9 @@ WarpX::ExchangeWithPmlF (int lev) { if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeF(F_fp[lev].get(), - F_cp[lev].get(), do_pml_in_domain, pml_ncell); + F_cp[lev].get(), + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); } } @@ -252,7 +258,9 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) pml[lev]->ExchangeE(patch_type, { Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), - Efield_fp[lev][2].get() }, do_pml_in_domain, pml_ncell); + Efield_fp[lev][2].get() }, + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryE(patch_type); } @@ -267,7 +275,9 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) pml[lev]->ExchangeE(patch_type, { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), - Efield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); + Efield_cp[lev][2].get() }, + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryE(patch_type); } @@ -294,7 +304,9 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) pml[lev]->ExchangeB(patch_type, { Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), - Bfield_fp[lev][2].get() }, do_pml_in_domain, pml_ncell); + Bfield_fp[lev][2].get() }, + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryB(patch_type); } const auto& period = Geom(lev).periodicity(); @@ -308,7 +320,9 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) pml[lev]->ExchangeB(patch_type, { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell); + Bfield_cp[lev][2].get() }, + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryB(patch_type); } const auto& cperiod = Geom(lev-1).periodicity(); @@ -331,7 +345,9 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) { if (do_pml && pml[lev]->ok()) { - pml[lev]->ExchangeF(patch_type, F_fp[lev].get(), do_pml_in_domain, pml_ncell); + pml[lev]->ExchangeF(patch_type, F_fp[lev].get(), + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryF(patch_type); } @@ -342,7 +358,9 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) { if (do_pml && pml[lev]->ok()) { - pml[lev]->ExchangeF(patch_type, F_cp[lev].get(), do_pml_in_domain, pml_ncell); + pml[lev]->ExchangeF(patch_type, F_cp[lev].get(), + do_pml_in_domain, pml_ncell, + do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryF(patch_type); } diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index ae4d80552..f4b218947 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1518,6 +1518,31 @@ PhysicalParticleContainer::Evolve (int lev, BL_PROFILE_VAR_STOP(blp_pxr_fg); + // auto& attribs = pti.GetAttribs(); + // + // Real* AMREX_RESTRICT zzp = m_zp[thread_num].dataPtr(); + // Real* AMREX_RESTRICT exp = attribs[PIdx::Ex].dataPtr(); + // Real* AMREX_RESTRICT eyp = attribs[PIdx::Ey].dataPtr(); + // Real* AMREX_RESTRICT ezp = attribs[PIdx::Ez].dataPtr(); + // Real* AMREX_RESTRICT bxp = attribs[PIdx::Bx].dataPtr(); + // Real* AMREX_RESTRICT byp = attribs[PIdx::By].dataPtr(); + // Real* AMREX_RESTRICT bzp = attribs[PIdx::Bz].dataPtr(); + // // const std::array& xyzmax_grid = WarpX::UpperCorner(box, lev); + // + // const long np = pti.numParticles(); + // + // ParallelFor( np_gather, + // [=] AMREX_GPU_DEVICE (long i) { + // if (zzp[i] < xyzmin_grid[1] + 20 * dx[1]){ //xyzmin_grid[2] + 10 * dx[2] + // exp[i] = 0.; + // eyp[i] = 0.; + // ezp[i] = 0.; + // bxp[i] = 0.; + // byp[i] = 0.; + // bzp[i] = 0.; + // } + // } + // ); // // Particle Push // -- cgit v1.2.3 From 7a5adaa22b1e1830b2046aba6ba38de90c96138c Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 21 Aug 2019 13:13:23 -0700 Subject: Code cleanup + add test --- Examples/Tests/particles_in_PML/analysis_2d.py | 26 ++++++ Examples/Tests/particles_in_PML/inputs2d | 56 ++++++++++++ Source/BoundaryConditions/PML.cpp | 115 ++----------------------- Source/Evolve/WarpXEvolveEM.cpp | 18 +--- Source/FieldSolver/WarpXPushFieldsEM.cpp | 1 - Source/Parallelization/WarpXComm.cpp | 12 +-- Source/Particles/PhysicalParticleContainer.cpp | 32 +++---- Source/WarpX.H | 1 - Source/WarpX.cpp | 1 - 9 files changed, 113 insertions(+), 149 deletions(-) create mode 100755 Examples/Tests/particles_in_PML/analysis_2d.py create mode 100644 Examples/Tests/particles_in_PML/inputs2d (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Examples/Tests/particles_in_PML/analysis_2d.py b/Examples/Tests/particles_in_PML/analysis_2d.py new file mode 100755 index 000000000..5b0279a9b --- /dev/null +++ b/Examples/Tests/particles_in_PML/analysis_2d.py @@ -0,0 +1,26 @@ +""" +This script tests the absorption of particles in the PML. + +The input file inputs_2d is used: it features a positive and a +negative particle, going in opposite direction and eventually +leaving the box. This script tests that the field in the box +is close to 0 once the particles have left. With regular +PML, this test fails, since the particles leave a spurious +charge, with associated fields, behind them. +""" +import sys +import yt +import numpy as np +yt.funcs.mylog.setLevel(0) + +# Open plotfile specified in command line +filename = sys.argv[1] +ds = yt.load( filename ) + +# Check that the field is low enough +ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +Ex_array = ad0['Ex'].to_ndarray() +Ey_array = ad0['Ey'].to_ndarray() +Ez_array = ad0['Ez'].to_ndarray() +max_Efield = max(Ex_array.max(), Ey_array.max(), Ez_array.max()) +assert max_Efield < 0.0003 \ No newline at end of file diff --git a/Examples/Tests/particles_in_PML/inputs2d b/Examples/Tests/particles_in_PML/inputs2d new file mode 100644 index 000000000..733032c53 --- /dev/null +++ b/Examples/Tests/particles_in_PML/inputs2d @@ -0,0 +1,56 @@ +max_step = 200 +amr.plot_int = 30 +amr.n_cell = 224 224 + +amr.blocking_factor = 8 +amr.max_grid_size = 1024 +amr.max_level = 0 + +warpx.dump_plotfiles = 1 + +# Geometry +geometry.coord_sys = 0 # 0: Cartesian +geometry.is_periodic = 0 0 # Is periodic? +geometry.prob_lo = -32.e-6 -32.e-6 # physical domain +geometry.prob_hi = 32.e-6 32.e-6 + +# PML +warpx.do_pml = 1 +warpx.pml_ncell = 12 +warpx.pml_delta = 6 +warpx.pml_has_particles = 0 +warpx.do_pml_in_domain = 0 +warpx.do_pml_j_damping = 0 + + +# Algorithms +algo.current_deposition = esirkepov +algo.charge_deposition = standard +algo.field_gathering = vectorized +algo.particle_pusher = vay +algo.maxwell_fdtd_solver = ckc +warpx.cfl = 1.0 +warpx.use_filter = 1 + +# Particle species +particles.nspecies = 2 +particles.species_names = electron proton + +electron.charge = -q_e +electron.mass = m_e +electron.injection_style = "singleparticle" +electron.single_particle_pos = 0. 0. 0. +electron.single_particle_vel = 2. 0. 0. +electron.single_particle_weight = 1. + +proton.charge = q_e +proton.mass = m_p # Very heavy ; should not move +proton.injection_style = "singleparticle" +proton.single_particle_pos = 0. 0. 0. +proton.single_particle_vel = -2. 0. 0. +proton.single_particle_weight = 1. + +# Particle shape factor in each direction +interpolation.nox = 3 +interpolation.noy = 3 +interpolation.noz = 3 diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 0b73859b4..15f18201b 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -24,22 +24,19 @@ namespace int slo = sigma.m_lo; int shi = sigma.m_hi; int sslo = sigma_star.m_lo; - Real x = 10.0; - Real theta = 10.0; - Real coeff_damp = 1.; //std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(glo-i); sigma[i-slo] = fac*(offset*offset); - sigma_cum[i-slo] = coeff_damp*(fac*(offset*offset*offset)/3.)/(PhysConst::c*x/std::sqrt(1+x*x)); + sigma_cum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(glo-i) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - sigma_star_cum[i-sslo] = coeff_damp*(fac*(offset*offset*offset)/3.)/(PhysConst::c*x/std::sqrt(1+x*x)); + sigma_star_cum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } } @@ -52,20 +49,17 @@ namespace int slo = sigma.m_lo; int shi = sigma.m_hi; int sslo = sigma_star.m_lo; - Real x = 10.0; - Real theta = 10.0; - Real coeff_damp = 1.;//std::sin(theta*MathConst::pi/180.); for (int i = olo; i <= ohi+1; ++i) { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - sigma_cum[i-slo] = coeff_damp*(fac*(offset*offset*offset)/3.)/(PhysConst::c*x/std::sqrt(1+x*x)); + sigma_cum[i-slo] = coeff_damp*(fac*(offset*offset*offset)/3.)/PhysConst::c; } for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(i-ghi) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - sigma_star_cum[i-sslo] = coeff_damp*(fac*(offset*offset*offset)/3.)/(PhysConst::c*x/std::sqrt(1+x*x)); + sigma_star_cum[i-sslo] = coeff_damp*(fac*(offset*offset*offset)/3.)/PhysConst::c; } } @@ -119,8 +113,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n sigma_star_cum_fac[idim].m_hi = hi[idim]; } - amrex::Print()< 0){pml_type[2]=idim+'0';} //std::to_string(idim) + if (idim > 0){pml_type[2]=idim+'0';} } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { - amrex::Print()<<"["< 1, Box gaps not wide enough?\n"); } } - amrex::Print()< 0) // Copy from pml to the ghost cells of regular data { - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, IntVect(0)); //ngr); + MultiFab::Copy(tmpregmf, reg, 0, 0, 1, IntVect(0)); MultiFab::Copy(totpmlmf, pml, 0, 0, ncp, ngp); tmpregmf.setVal(0.0, 1, ncp-1, 0); - // ce qui foncitonne a peu pres pour le moment tmpregmf.ParallelCopy(totpmlmf,0, 0, ncp, IntVect(0), IntVect(0), period); totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, IntVect(0), ngp, period); - MultiFab::Copy(pml, totpmlmf, 0, 0, ncp, ngp); //test -// #ifdef _OPENMP -// #pragma omp parallel -// #endif - // // amrex::Print()<<"####### EXCHANGE INFORMATIONS GHOST CELLS PML #######"<>> EXCHANGE BOXES <<<<<" <>> EXCHANGE BOXES <<<<<" < 0 && step < load_balance_max_step && (step+1) % load_balance_int == 0) + if (step > 0 && (step+1) % load_balance_int == 0) { LoadBalance(); // Reset the costs to 0 @@ -329,22 +329,6 @@ WarpX::OneStep_nosub (Real cur_time) EvolveE(dt[0]); // We now have E^{n+1} FillBoundaryE(); EvolveF(0.5*dt[0], DtType::SecondHalf); - - - // if (do_pml && pml_has_particles){ - // for (int lev = 0; lev <= finest_level; ++lev) - // { - // if (pml[lev]->ok()){ - // pml[lev]->CopyJinReg({ current_fp[lev][0].get(), - // current_fp[lev][1].get(), - // current_fp[lev][2].get() }, - // { current_cp[lev][0].get(), - // current_cp[lev][1].get(), - // current_cp[lev][2].get() }); - // } - // } - // } - EvolveB(0.5*dt[0]); // We now have B^{n+1} if (do_pml) { DampPML(); diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index 18c98b8f8..011d9cfcc 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -241,7 +241,6 @@ WarpX::EvolveB (int lev, PatchType patch_type, amrex::Real a_dt) { const auto& pml_B = (patch_type == PatchType::fine) ? pml[lev]->GetB_fp() : pml[lev]->GetB_cp(); const auto& pml_E = (patch_type == PatchType::fine) ? pml[lev]->GetE_fp() : pml[lev]->GetE_cp(); - // const auto& pml_j = (patch_type == PatchType::fine) ? pml[lev]->Getj_fp() : pml[lev]->Getj_cp(); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index 06cbf157a..c539cd89a 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -256,7 +256,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeE(patch_type, - { Efield_fp[lev][0].get(), + { Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), Efield_fp[lev][2].get() }, do_pml_in_domain, pml_ncell, @@ -273,7 +273,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeE(patch_type, - { Efield_cp[lev][0].get(), + { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell, @@ -302,7 +302,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeB(patch_type, - { Bfield_fp[lev][0].get(), + { Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), Bfield_fp[lev][2].get() }, do_pml_in_domain, pml_ncell, @@ -318,9 +318,9 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeB(patch_type, - { Bfield_cp[lev][0].get(), - Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get() }, + { Bfield_cp[lev][0].get(), + Bfield_cp[lev][1].get(), + Bfield_cp[lev][2].get() }, do_pml_in_domain, pml_ncell, do_pml_Lo, do_pml_Hi); pml[lev]->FillBoundaryB(patch_type); diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 20819a78c..d10390204 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -33,7 +33,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); pp.query("do_continuous_injection", do_continuous_injection); - // Whether to plot back-transformed (lab-frame) diagnostics + // Whether to plot back-transformed (lab-frame) diagnostics // for this species. pp.query("do_boosted_frame_diags", do_boosted_frame_diags); @@ -42,7 +42,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp do_user_plot_vars = pp.queryarr("plot_vars", plot_vars); if (not do_user_plot_vars){ // By default, all particle variables are dumped to plotfiles, - // including {x,y,z,ux,uy,uz}old variables when running in a + // including {x,y,z,ux,uy,uz}old variables when running in a // boosted frame if (WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags){ plot_flags.resize(PIdx::nattribs + 6, 1); @@ -59,9 +59,9 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp // If not none, set plot_flags values to 1 for elements in plot_vars. if (plot_vars[0] != "none"){ for (const auto& var : plot_vars){ - // Return error if var not in PIdx. - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - ParticleStringNames::to_index.count(var), + // Return error if var not in PIdx. + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + ParticleStringNames::to_index.count(var), "plot_vars argument not in ParticleStringNames"); plot_flags[ParticleStringNames::to_index.at(var)] = 1; } @@ -130,7 +130,7 @@ void PhysicalParticleContainer::MapParticletoBoostedFrame(Real& x, Real& y, Real void PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m, Real x_rms, Real y_rms, Real z_rms, - Real q_tot, long npart, + Real q_tot, long npart, int do_symmetrize) { const Geometry& geom = m_gdb->Geom(0); @@ -203,7 +203,7 @@ PhysicalParticleContainer::CheckAndAddParticle(Real x, Real y, Real z, particle_tile.push_back_real(particle_comps["xold"], x); particle_tile.push_back_real(particle_comps["yold"], y); particle_tile.push_back_real(particle_comps["zold"], z); - + particle_tile.push_back_real(particle_comps["uxold"], u[0]); particle_tile.push_back_real(particle_comps["uyold"], u[1]); particle_tile.push_back_real(particle_comps["uzold"], u[2]); @@ -931,11 +931,11 @@ PhysicalParticleContainer::Evolve (int lev, BL_PROFILE_VAR_NS("PICSAR::FieldGather", blp_pxr_fg); BL_PROFILE_VAR_NS("PPC::ParticlePush", blp_ppc_pp); BL_PROFILE_VAR_NS("PPC::Evolve::partition", blp_partition); - + const std::array& dx = WarpX::CellSize(lev); const std::array& cdx = WarpX::CellSize(std::max(lev-1,0)); - // Get instances of NCI Godfrey filters + // Get instances of NCI Godfrey filters const auto& nci_godfrey_filter_exeybz = WarpX::GetInstance().nci_godfrey_filter_exeybz; const auto& nci_godfrey_filter_bxbyez = WarpX::GetInstance().nci_godfrey_filter_bxbyez; @@ -949,7 +949,7 @@ PhysicalParticleContainer::Evolve (int lev, bool has_buffer = cEx || cjx; #ifdef _OPENMP -#pragma omp parallel +#pragma omp parallel #endif { #ifdef _OPENMP @@ -1227,13 +1227,13 @@ PhysicalParticleContainer::Evolve (int lev, eyeli = filtered_Ey.elixir(); nci_godfrey_filter_exeybz[lev-1]->ApplyStencil(filtered_Ey, (*cEy)[pti], filtered_Ey.box()); ceyfab = &filtered_Ey; - + // Filter Bx filtered_Bx.resize(amrex::convert(tbox,WarpX::Bx_nodal_flag)); bxeli = filtered_Bx.elixir(); nci_godfrey_filter_bxbyez[lev-1]->ApplyStencil(filtered_Bx, (*cBx)[pti], filtered_Bx.box()); cbxfab = &filtered_Bx; - + // Filter Bz filtered_Bz.resize(amrex::convert(tbox,WarpX::Bz_nodal_flag)); bzeli = filtered_Bz.elixir(); @@ -1453,7 +1453,7 @@ PhysicalParticleContainer::SplitParticles(int lev) } // Add local arrays psplit_x etc. to the temporary // particle container pctmp_split. Split particles - // are tagged with p.id()=NoSplitParticleID so that + // are tagged with p.id()=NoSplitParticleID so that // they are not re-split when entering a higher level // AddNParticles calls Redistribute, so that particles // in pctmp_split are in the proper grids and tiles @@ -1550,7 +1550,7 @@ PhysicalParticleContainer::PushP (int lev, Real dt, int thread_num = omp_get_thread_num(); #else int thread_num = 0; -#endif +#endif for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { const Box& box = pti.validbox(); @@ -1694,7 +1694,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real slice_box.setHi(direction, z_max); diagnostic_particles.resize(finestLevel()+1); - + for (int lev = 0; lev < nlevs; ++lev) { const Real* dx = Geom(lev).CellSize(); @@ -1776,7 +1776,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real Real uzp = uz_old_p *weight_old + uz_new_p *weight_new; diagnostic_particles[lev][index].GetRealData(DiagIdx::w).push_back(wp[i]); - + diagnostic_particles[lev][index].GetRealData(DiagIdx::x).push_back(xp); diagnostic_particles[lev][index].GetRealData(DiagIdx::y).push_back(yp); diagnostic_particles[lev][index].GetRealData(DiagIdx::z).push_back(zp); diff --git a/Source/WarpX.H b/Source/WarpX.H index b4dfe9ae4..3e8d45f49 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -524,7 +524,6 @@ private: amrex::Real const_dt = 0.5e-11; int load_balance_int = -1; - int load_balance_max_step = std::numeric_limits::max(); amrex::Vector > costs; int load_balance_with_sfc = 0; amrex::Real load_balance_knapsack_factor = 1.24; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 6abf27216..305fedbb4 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -498,7 +498,6 @@ WarpX::ReadParameters () } pp.query("load_balance_int", load_balance_int); - pp.query("load_balance_max_step", load_balance_max_step); pp.query("load_balance_with_sfc", load_balance_with_sfc); pp.query("load_balance_knapsack_factor", load_balance_knapsack_factor); -- cgit v1.2.3 From 8ba3af2987f28c0c6b75ee9ce6366ef6c3026e1f Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 21 Aug 2019 15:04:27 -0700 Subject: Fix typo --- Source/BoundaryConditions/PML.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 15f18201b..45be44dd3 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -53,13 +53,13 @@ namespace { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - sigma_cum[i-slo] = coeff_damp*(fac*(offset*offset*offset)/3.)/PhysConst::c; + sigma_cum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(i-ghi) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - sigma_star_cum[i-sslo] = coeff_damp*(fac*(offset*offset*offset)/3.)/PhysConst::c; + sigma_star_cum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } } -- cgit v1.2.3 From 4fc478e57695b399f36c7e4e19299614cd6bc6c7 Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 23 Aug 2019 20:39:11 +0200 Subject: - correction on the current term for pushing fields in PML - deleted variable pml_type (string) --- Source/BoundaryConditions/PML.H | 17 ++++++++-- Source/BoundaryConditions/PML.cpp | 50 +++++++++--------------------- Source/BoundaryConditions/PML_routines.F90 | 18 +++++------ 3 files changed, 39 insertions(+), 46 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 724bdc579..4a73d095c 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -84,8 +84,21 @@ struct SigmaBox SigmaVect sigma_star_fac; SigmaVect sigma_star_cum_fac; - std::string pml_type; // if pml normal to x : if pml Hi : pml_type={1,0,0}; if pml Lo: pml_type={-1,0,0} std::array pml_type_array; + /* + pml_type_array is an array containing the PML type. + pml_type_array[0] = 0 : direct face: need to store: + - direction: 0/1/2 (x/y/z) + - sign: 0/1 (-/+) + => 3 comp + pml_type_array[0] = 1 : corner: need to store: + - sign (x3): 0/1 (-/+) + => 4 comp + pml_type_array[0] = 2 : side edge: need to store: + - direction (x2): 0/1/2 (x/y/z) + - sign (x2): 0/1 (-/+) + => 5 comp + */ }; namespace amrex { @@ -138,7 +151,7 @@ public: #endif int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), + const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void ComputePMLFactors (amrex::Real dt); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 45be44dd3..48412b72a 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -113,7 +113,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n sigma_star_cum_fac[idim].m_hi = hi[idim]; } - pml_type = ""; + // pml_type = ""; pml_type_array = {3, 3, 3, 3, 3}; Array fac; @@ -183,15 +183,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); if (idim == 0){ - pml_type = "crn-++"; // for 2d only use the two first components pml_type_array[0] = 1; pml_type_array[1] = 0; pml_type_array[2] = 1; pml_type_array[3] = 1; } else { - if (pml_type[0] == 'c'){ - pml_type[3+idim] = '-'; + if (pml_type_array[0] == 1){ pml_type_array[1+idim] = 0; } } @@ -206,15 +204,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); if (idim == 0){ - pml_type = "crn+++"; // for 2d only use the two first components pml_type_array[0] = 1; pml_type_array[1] = 1; pml_type_array[2] = 1; pml_type_array[3] = 1; } else { - if (pml_type[0] == 'c'){ - pml_type[3+idim] = '+'; + if (pml_type_array[0] == 1){ pml_type_array[1+idim] = 1; } } @@ -233,7 +229,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (overlap.ok()) { FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); if (idim==0){ - pml_type="sed33--"; pml_type_array[0] = 2; } } @@ -251,22 +246,17 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); if (idim == 0){ - pml_type = "sed03-+"; // for 2d only use the two first components pml_type_array[0] = 2; pml_type_array[1] = idim; pml_type_array[3] = 0; } else { - if (pml_type[0] == 's'){ - if (pml_type[3]=='3'){ - pml_type[3]=idim+'0'; - pml_type[5]='-'; + if (pml_type_array[0] == 2){ + if (pml_type_array[1]==3){ pml_type_array[1] = idim; pml_type_array[3] = 0; } else{ - pml_type[4] = idim+'0'; - pml_type[6] = '-'; pml_type_array[2] = idim; pml_type_array[4] = 0; } @@ -279,22 +269,17 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); if (idim == 0){ - pml_type = "sed03++"; // for 2d only use the two first components pml_type_array[0] = 2; pml_type_array[1] = idim; pml_type_array[3] = 1; } else { - if (pml_type[0] == 's'){ - if (pml_type[3]=='3'){ - pml_type[3]=idim+'0'; - pml_type[5]='+'; + if (pml_type_array[0] == 2){ + if (pml_type_array[1]==3){ pml_type_array[1] = idim; pml_type_array[3] = 1; } else{ - pml_type[4] = idim+'0'; - pml_type[6] = '+'; pml_type_array[2] = idim; pml_type_array[4] = 1; } @@ -331,22 +316,18 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box looverlap = lobox & box; if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); - pml_type = "df0-"; pml_type_array[0] = 0; pml_type_array[1] = idim; pml_type_array[2] = 0; - if (idim > 0){pml_type[2]=idim+'0';} } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); - pml_type = "df0+"; pml_type_array[0] = 0; pml_type_array[1] = idim; pml_type_array[2] = 1; - if (idim>0){pml_type[2] = idim+'0';} } if (!looverlap.ok() && !hioverlap.ok()) { @@ -427,13 +408,13 @@ MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const Geometry* geom, const Geometry* cgeom, - int ncell, int delta, int ref_ratio, + int ncell, int delta, int ref_ratio, #ifdef WARPX_USE_PSATD Real dt, int nox_fft, int noy_fft, int noz_fft, bool do_nodal, #endif int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) // = amrex::IntVect::TheUnitVector() + const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) : m_geom(geom), m_cgeom(cgeom) { @@ -441,7 +422,6 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, Box domain0 = geom->Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom->isPeriodic(idim)) { - // domain0.grow(idim, -ncell); if (do_pml_Lo[idim]){ domain0.growLo(idim, -ncell); } @@ -504,9 +484,9 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, pml_B_fp[1]->setVal(0.0); pml_B_fp[2]->setVal(0.0); - pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jx_nodal_flag) - pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jy_nodal_flag) - pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); //convert(ba,WarpX::Jz_nodal_flag) + pml_j_fp[0].reset(new MultiFab(amrex::convert(ba,WarpX::jx_nodal_flag), dm, 1, ngb)); + pml_j_fp[1].reset(new MultiFab(amrex::convert(ba,WarpX::jy_nodal_flag), dm, 1, ngb)); + pml_j_fp[2].reset(new MultiFab(amrex::convert(ba,WarpX::jz_nodal_flag), dm, 1, ngb)); pml_j_fp[0]->setVal(0.0); pml_j_fp[1]->setVal(0.0); pml_j_fp[2]->setVal(0.0); @@ -526,7 +506,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, #ifdef WARPX_USE_PSATD - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( do_pml_in_domain==false, + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( do_pml_in_domain==false, "PSATD solver cannot be used with `do_pml_in_domain`."); const bool in_pml = true; // Tells spectral solver to use split-PML equations const RealVect dx{AMREX_D_DECL(geom->CellSize(0), geom->CellSize(1), geom->CellSize(2))}; @@ -546,8 +526,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, BoxArray grid_cba = grid_ba; grid_cba.coarsen(ref_ratio); - const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); // domain to change ? This domain was built for a fine grid: the reduced domain is only valid for the fine level... - // const BoxArray& cba = MakeBoxArray(*cgeom, grid_cba_reduced, ncell); + const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); + const BoxArray& cba = (do_pml_in_domain) ? MakeBoxArray(*cgeom, grid_cba_reduced, ncell, do_pml_Lo, do_pml_Hi) : MakeBoxArray(*cgeom, grid_cba, ncell, do_pml_Lo, do_pml_Hi); DistributionMapping cdm{cba}; diff --git a/Source/BoundaryConditions/PML_routines.F90 b/Source/BoundaryConditions/PML_routines.F90 index df1ab0fd5..8f617d86e 100644 --- a/Source/BoundaryConditions/PML_routines.F90 +++ b/Source/BoundaryConditions/PML_routines.F90 @@ -357,10 +357,10 @@ contains alpha_yz = 0. Ey(i,j,k,1) = Ey(i,j,k,1) + dtsdz*(Bx(i ,j,k ,1)+Bx(i ,j,k ,2) & & -Bx(i ,j,k-1,1)-Bx(i ,j,k-1,2))& - & -mudt*alpha_yx*jy(i,j,k) + & -mudt*alpha_yz*jy(i,j,k) Ey(i,j,k,2) = Ey(i,j,k,2) - dtsdx*(Bz(i ,j,k ,1)+Bz(i ,j,k ,2) & & -Bz(i-1,j,k ,1)-Bz(i-1,j,k ,2))& - & -mudt*alpha_yz*jy(i,j,k) + & -mudt*alpha_yx*jy(i,j,k) end do end do end do @@ -404,10 +404,10 @@ contains alpha_yz = 0.5 Ey(i,j,k,1) = Ey(i,j,k,1) + dtsdz*(Bx(i ,j,k ,1)+Bx(i ,j,k ,2) & & -Bx(i ,j,k-1,1)-Bx(i ,j,k-1,2))& - & -mudt*alpha_yx*jy(i,j,k) + & -mudt*alpha_yz*jy(i,j,k) Ey(i,j,k,2) = Ey(i,j,k,2) - dtsdx*(Bz(i ,j,k ,1)+Bz(i ,j,k ,2) & & -Bz(i-1,j,k ,1)-Bz(i-1,j,k ,2))& - & -mudt*alpha_yz*jy(i,j,k) + & -mudt*alpha_yx*jy(i,j,k) end do end do end do @@ -451,10 +451,10 @@ contains alpha_yz = 1. Ey(i,j,k,1) = Ey(i,j,k,1) + dtsdz*(Bx(i ,j,k ,1)+Bx(i ,j,k ,2) & & -Bx(i ,j,k-1,1)-Bx(i ,j,k-1,2))& - & -mudt*alpha_yx*jy(i,j,k) + & -mudt*alpha_yz*jy(i,j,k) Ey(i,j,k,2) = Ey(i,j,k,2) - dtsdx*(Bz(i ,j,k ,1)+Bz(i ,j,k ,2) & & -Bz(i-1,j,k ,1)-Bz(i-1,j,k ,2))& - & -mudt*alpha_yz*jy(i,j,k) + & -mudt*alpha_yx*jy(i,j,k) end do end do end do @@ -512,10 +512,10 @@ contains Ey(i,j,k,1) = Ey(i,j,k,1) + dtsdz*(Bx(i ,j,k ,1)+Bx(i ,j,k ,2) & & -Bx(i ,j,k-1,1)-Bx(i ,j,k-1,2))& - & -mudt*alpha_yx*jy(i,j,k) + & -mudt*alpha_yz*jy(i,j,k) Ey(i,j,k,2) = Ey(i,j,k,2) - dtsdx*(Bz(i ,j,k ,1)+Bz(i ,j,k ,2) & & -Bz(i-1,j,k ,1)-Bz(i-1,j,k ,2))& - & -mudt*alpha_yz*jy(i,j,k) + & -mudt*alpha_yx*jy(i,j,k) end do end do end do @@ -1170,7 +1170,7 @@ contains do k = tjxlo(2), tjxhi(2) do i = tjxlo(1), tjxhi(1) - jx(i,k) = jx(i,k) * sigsjx(i) * sigjz(k) + jx(i,k) = jx(i,k) * sigsjx(i) * sigjz(k) end do end do -- cgit v1.2.3 From b41479e0ddb100e50c40b4d6566e98a9a2d469ea Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 29 Aug 2019 17:29:36 +0200 Subject: Cleaned code from useless Fortran and from pml_type --- Source/BoundaryConditions/PML.H | 15 ------ Source/BoundaryConditions/PML.cpp | 68 ----------------------- Source/BoundaryConditions/PML_routines.F90 | 86 +----------------------------- 3 files changed, 1 insertion(+), 168 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 1ba10834a..2a428279c 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -56,21 +56,6 @@ struct SigmaBox SigmaVect sigma_star_fac; SigmaVect sigma_star_cum_fac; - std::array pml_type_array; - /* - pml_type_array is an array containing the PML type. - pml_type_array[0] = 0 : direct face: need to store: - - direction: 0/1/2 (x/y/z) - - sign: 0/1 (-/+) - => 3 comp - pml_type_array[0] = 1 : corner: need to store: - - sign (x3): 0/1 (-/+) - => 4 comp - pml_type_array[0] = 2 : side edge: need to store: - - direction (x2): 0/1/2 (x/y/z) - - sign (x2): 0/1 (-/+) - => 5 comp - */ }; namespace amrex { diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 48412b72a..c871dabee 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -113,9 +113,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n sigma_star_cum_fac[idim].m_hi = hi[idim]; } - // pml_type = ""; - pml_type_array = {3, 3, 3, 3, 3}; - Array fac; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fac[idim] = 4.0*PhysConst::c/(dx[idim]*static_cast(delta*delta)); @@ -182,17 +179,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box looverlap = lobox & box; if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); - if (idim == 0){ - pml_type_array[0] = 1; - pml_type_array[1] = 0; - pml_type_array[2] = 1; - pml_type_array[3] = 1; - } - else { - if (pml_type_array[0] == 1){ - pml_type_array[1+idim] = 0; - } - } } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); @@ -203,17 +189,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box hioverlap = hibox & box; if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); - if (idim == 0){ - pml_type_array[0] = 1; - pml_type_array[1] = 1; - pml_type_array[2] = 1; - pml_type_array[3] = 1; - } - else { - if (pml_type_array[0] == 1){ - pml_type_array[1+idim] = 1; - } - } } if (!looverlap.ok() && !hioverlap.ok()) { @@ -228,9 +203,6 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; if (overlap.ok()) { FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); - if (idim==0){ - pml_type_array[0] = 2; - } } else { amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); @@ -245,46 +217,12 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); - if (idim == 0){ - pml_type_array[0] = 2; - pml_type_array[1] = idim; - pml_type_array[3] = 0; - } - else { - if (pml_type_array[0] == 2){ - if (pml_type_array[1]==3){ - pml_type_array[1] = idim; - pml_type_array[3] = 0; - } - else{ - pml_type_array[2] = idim; - pml_type_array[4] = 0; - } - } - } } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); - if (idim == 0){ - pml_type_array[0] = 2; - pml_type_array[1] = idim; - pml_type_array[3] = 1; - } - else { - if (pml_type_array[0] == 2){ - if (pml_type_array[1]==3){ - pml_type_array[1] = idim; - pml_type_array[3] = 1; - } - else{ - pml_type_array[2] = idim; - pml_type_array[4] = 1; - } - } - } } if (!looverlap.ok() && !hioverlap.ok()) { @@ -316,18 +254,12 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box looverlap = lobox & box; if (looverlap.ok()) { FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); - pml_type_array[0] = 0; - pml_type_array[1] = idim; - pml_type_array[2] = 0; } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); - pml_type_array[0] = 0; - pml_type_array[1] = idim; - pml_type_array[2] = 1; } if (!looverlap.ok() && !hioverlap.ok()) { diff --git a/Source/BoundaryConditions/PML_routines.F90 b/Source/BoundaryConditions/PML_routines.F90 index 69c762dd1..e2540350e 100644 --- a/Source/BoundaryConditions/PML_routines.F90 +++ b/Source/BoundaryConditions/PML_routines.F90 @@ -1006,89 +1006,5 @@ contains end do end subroutine warpx_damp_pml_f_3d - subroutine warpx_dampJ_pml_2d (tjxlo, tjxhi, tjylo, tjyhi, tjzlo, tjzhi, & - & jx, jxlo, jxhi, jy, jylo, jyhi, jz, jzlo, jzhi, & - & sigjx, sjxlo, sjxhi, sigjz, sjzlo, sjzhi, & - & sigsjx, ssjxlo, ssjxhi, sigsjz, ssjzlo, ssjzhi) & - bind(c,name='warpx_dampJ_pml_2d') - integer, dimension(2), intent(in) :: tjxlo, tjxhi, tjylo, tjyhi, tjzlo, tjzhi, & - jxlo, jxhi, jylo, jyhi, jzlo, jzhi - integer, intent(in), value :: sjxlo, sjxhi, sjzlo, sjzhi, ssjxlo, ssjxhi, ssjzlo, ssjzhi - real(amrex_real), intent(inout) :: jx(jxlo(1):jxhi(1),jxlo(2):jxhi(2)) - real(amrex_real), intent(inout) :: jy(jylo(1):jyhi(1),jylo(2):jyhi(2)) - real(amrex_real), intent(inout) :: jz(jzlo(1):jzhi(1),jzlo(2):jzhi(2)) - real(amrex_real), intent(in) :: sigjx(sjxlo:sjxhi) - real(amrex_real), intent(in) :: sigjz(sjzlo:sjzhi) - real(amrex_real), intent(in) :: sigsjx(ssjxlo:ssjxhi) - real(amrex_real), intent(in) :: sigsjz(ssjzlo:ssjzhi) - - integer :: i,k - - do k = tjxlo(2), tjxhi(2) - do i = tjxlo(1), tjxhi(1) - jx(i,k) = jx(i,k) * sigsjx(i) * sigjz(k) - end do - end do - - ! do k = tjylo(2), tjyhi(2) - ! do i = tjylo(1), tjyhi(1) - ! jy(i,k) = jy(i,k) - ! end do - ! end do - - do k = tjzlo(2), tjzhi(2) - do i = tjzlo(1), tjzhi(1) - jz(i,k) = jz(i,k) * sigjx(i) * sigsjz(k) - end do - end do - - - end subroutine warpx_dampJ_pml_2d - - subroutine warpx_dampJ_pml_3d (tjxlo, tjxhi, tjylo, tjyhi, tjzlo, tjzhi, & - & jx, jxlo, jxhi, jy, jylo, jyhi, jz, jzlo, jzhi, & - & sigjx, sjxlo, sjxhi, sigjy, sjylo, sjyhi, sigjz, sjzlo, sjzhi, & - & sigsjx, ssjxlo, ssjxhi, sigsjy, ssjylo, ssjyhi, sigsjz, ssjzlo, ssjzhi) & - bind(c,name='warpx_dampJ_pml_3d') - integer, dimension(3), intent(in) :: tjxlo, tjxhi, tjylo, tjyhi, tjzlo, tjzhi, & - jxlo, jxhi, jylo, jyhi, jzlo, jzhi - integer, intent(in), value :: sjxlo, sjxhi, sjylo, sjyhi, sjzlo, sjzhi, ssjxlo, ssjxhi, ssjylo, ssjyhi, ssjzlo, ssjzhi - real(amrex_real), intent(inout) :: jx(jxlo(1):jxhi(1),jxlo(2):jxhi(2),jxlo(3):jxhi(3)) - real(amrex_real), intent(inout) :: jy(jylo(1):jyhi(1),jylo(2):jyhi(2),jylo(3):jyhi(3)) - real(amrex_real), intent(inout) :: jz(jzlo(1):jzhi(1),jzlo(2):jzhi(2),jzlo(3):jzhi(3)) - real(amrex_real), intent(in) :: sigjx(sjxlo:sjxhi) - real(amrex_real), intent(in) :: sigjy(sjylo:sjyhi) - real(amrex_real), intent(in) :: sigjz(sjzlo:sjzhi) - real(amrex_real), intent(in) :: sigsjx(ssjxlo:ssjxhi) - real(amrex_real), intent(in) :: sigsjy(ssjylo:ssjyhi) - real(amrex_real), intent(in) :: sigsjz(ssjzlo:ssjzhi) - - integer :: i,j,k - - do k = tjxlo(3), tjxhi(3) - do j = tjylo(2), tjyhi(2) - do i = tjxlo(1), tjxhi(1) - jx(i,j,k) = jx(i,j,k) * sigsjx(i) * sigjy(j) * sigjz(k) - end do - end do - end do - - do k = tjxlo(3), tjxhi(3) - do j = tjylo(2), tjyhi(2) - do i = tjxlo(1), tjxhi(1) - jy(i,j,k) = jy(i,j,k) * sigjx(i) * sigsjy(j) * sigjz(k) - end do - end do - end do - - do k = tjxlo(3), tjxhi(3) - do j = tjylo(2), tjyhi(2) - do i = tjxlo(1), tjxhi(1) - jz(i,j,k) = jz(i,j,k) * sigjx(i) * sigjy(j) * sigsjz(k) - end do - end do - end do - - end subroutine warpx_dampJ_pml_3d - + end module warpx_pml_module -- cgit v1.2.3 From 6a07ece4aa207f6675d06c26b642bcecaa41631e Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 29 Aug 2019 17:38:29 +0200 Subject: sigma_cum, sigma_cum_fac renamed into sigma_cumsum, sigma_cumsum_fac sigma_star_cum, sigma_star_cum_fac renamed into sigma_star_cumsum, sigma_star_cumsum_fac --- Source/BoundaryConditions/PML.H | 8 ++-- Source/BoundaryConditions/PML.cpp | 62 ++++++++++++++-------------- Source/BoundaryConditions/WarpXEvolvePML.cpp | 48 ++++++++++----------- 3 files changed, 59 insertions(+), 59 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 2a428279c..37c8ba961 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -48,13 +48,13 @@ struct SigmaBox using SigmaVect = std::array; SigmaVect sigma; - SigmaVect sigma_cum; + SigmaVect sigma_cumsum; SigmaVect sigma_star; - SigmaVect sigma_star_cum; + SigmaVect sigma_star_cumsum; SigmaVect sigma_fac; - SigmaVect sigma_cum_fac; + SigmaVect sigma_cumsum_fac; SigmaVect sigma_star_fac; - SigmaVect sigma_star_cum_fac; + SigmaVect sigma_star_cumsum_fac; }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index c871dabee..fd5a2de1c 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -15,7 +15,7 @@ using namespace amrex; namespace { - static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, Sigma& sigma_star_cum, + static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const Box& overlap, const Box& grid, Real fac) { int glo = grid.smallEnd(idim); @@ -29,18 +29,18 @@ namespace { Real offset = static_cast(glo-i); sigma[i-slo] = fac*(offset*offset); - sigma_cum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; + sigma_cumsum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(glo-i) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - sigma_star_cum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; + sigma_star_cumsum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } } - static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, Sigma& sigma_star_cum, + static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const Box& overlap, const Box& grid, Real fac) { int ghi = grid.bigEnd(idim); @@ -53,26 +53,26 @@ namespace { Real offset = static_cast(i-ghi-1); sigma[i-slo] = fac*(offset*offset); - sigma_cum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; + sigma_cumsum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } for (int i = olo; i <= ohi; ++i) { Real offset = static_cast(i-ghi) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); - sigma_star_cum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; + sigma_star_cumsum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } } - static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cum, Sigma& sigma_star, Sigma& sigma_star_cum, const Box& overlap) + static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const Box& overlap) { int olo = overlap.smallEnd(idim); int ohi = overlap.bigEnd(idim); int slo = sigma.m_lo; int sslo = sigma_star.m_lo; std::fill(sigma.begin()+(olo-slo), sigma.begin()+(ohi+2-slo), 0.0); - std::fill(sigma_cum.begin()+(olo-slo), sigma_cum.begin()+(ohi+2-slo), 0.0); + std::fill(sigma_cumsum.begin()+(olo-slo), sigma_cumsum.begin()+(ohi+2-slo), 0.0); std::fill(sigma_star.begin()+(olo-sslo), sigma_star.begin()+(ohi+1-sslo), 0.0); - std::fill(sigma_star_cum.begin()+(olo-sslo), sigma_star_cum.begin()+(ohi+1-sslo), 0.0); + std::fill(sigma_star_cumsum.begin()+(olo-sslo), sigma_star_cumsum.begin()+(ohi+1-sslo), 0.0); } } @@ -87,30 +87,30 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { sigma [idim].resize(sz[idim]+1); - sigma_cum [idim].resize(sz[idim]+1); + sigma_cumsum [idim].resize(sz[idim]+1); sigma_star [idim].resize(sz[idim]); - sigma_star_cum[idim].resize(sz[idim]); + sigma_star_cumsum[idim].resize(sz[idim]); sigma_fac [idim].resize(sz[idim]+1); - sigma_cum_fac [idim].resize(sz[idim]+1); + sigma_cumsum_fac [idim].resize(sz[idim]+1); sigma_star_fac[idim].resize(sz[idim]); - sigma_star_cum_fac[idim].resize(sz[idim]); + sigma_star_cumsum_fac[idim].resize(sz[idim]); sigma [idim].m_lo = lo[idim]; sigma [idim].m_hi = hi[idim]+1; - sigma_cum [idim].m_lo = lo[idim]; - sigma_cum [idim].m_hi = hi[idim]+1; + sigma_cumsum [idim].m_lo = lo[idim]; + sigma_cumsum [idim].m_hi = hi[idim]+1; sigma_star [idim].m_lo = lo[idim]; sigma_star [idim].m_hi = hi[idim]; - sigma_star_cum[idim].m_lo = lo[idim]; - sigma_star_cum[idim].m_hi = hi[idim]; + sigma_star_cumsum[idim].m_lo = lo[idim]; + sigma_star_cumsum[idim].m_hi = hi[idim]; sigma_fac [idim].m_lo = lo[idim]; sigma_fac [idim].m_hi = hi[idim]+1; - sigma_cum_fac [idim].m_lo = lo[idim]; - sigma_cum_fac [idim].m_hi = hi[idim]+1; + sigma_cumsum_fac [idim].m_lo = lo[idim]; + sigma_cumsum_fac [idim].m_hi = hi[idim]+1; sigma_star_fac[idim].m_lo = lo[idim]; sigma_star_fac[idim].m_hi = hi[idim]; - sigma_star_cum_fac[idim].m_lo = lo[idim]; - sigma_star_cum_fac[idim].m_hi = hi[idim]; + sigma_star_cumsum_fac[idim].m_lo = lo[idim]; + sigma_star_cumsum_fac[idim].m_hi = hi[idim]; } Array fac; @@ -178,7 +178,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); @@ -188,7 +188,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -202,7 +202,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& grid_box = grids[gid]; const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); + FillZero(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); @@ -216,13 +216,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -240,7 +240,7 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; #endif if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], overlap); + FillZero(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); } @@ -253,13 +253,13 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], looverlap, grid_box, fac[idim]); } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cum[idim], sigma_star[idim], sigma_star_cum[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -282,7 +282,7 @@ SigmaBox::ComputePMLFactorsB (const Real* dx, Real dt) for (int i = 0, N = sigma_star[idim].size(); i < N; ++i) { sigma_star_fac[idim][i] = std::exp(-sigma_star[idim][i]*dt); - sigma_star_cum_fac[idim][i] = std::exp(-sigma_star_cum[idim][i]*dx[idim]); + sigma_star_cumsum_fac[idim][i] = std::exp(-sigma_star_cumsum[idim][i]*dx[idim]); } } } @@ -295,7 +295,7 @@ SigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) for (int i = 0, N = sigma[idim].size(); i < N; ++i) { sigma_fac[idim][i] = std::exp(-sigma[idim][i]*dt); - sigma_cum_fac[idim][i] = std::exp(-sigma_cum[idim][i]*dx[idim]); + sigma_cumsum_fac[idim][i] = std::exp(-sigma_cumsum[idim][i]*dx[idim]); } } } diff --git a/Source/BoundaryConditions/WarpXEvolvePML.cpp b/Source/BoundaryConditions/WarpXEvolvePML.cpp index a801aabe4..505fa83d2 100644 --- a/Source/BoundaryConditions/WarpXEvolvePML.cpp +++ b/Source/BoundaryConditions/WarpXEvolvePML.cpp @@ -121,55 +121,55 @@ WarpX::DampJPML (int lev, PatchType patch_type) auto const& pml_jxfab = pml_j[0]->array(mfi); auto const& pml_jyfab = pml_j[1]->array(mfi); auto const& pml_jzfab = pml_j[2]->array(mfi); - const Real* sigma_cum_fac_j_x = sigba[mfi].sigma_cum_fac[0].data(); - const Real* sigma_star_cum_fac_j_x = sigba[mfi].sigma_star_cum_fac[0].data(); + const Real* sigma_cumsum_fac_j_x = sigba[mfi].sigma_cumsum_fac[0].data(); + const Real* sigma_star_cumsum_fac_j_x = sigba[mfi].sigma_star_cumsum_fac[0].data(); #if (AMREX_SPACEDIM == 3) - const Real* sigma_cum_fac_j_y = sigba[mfi].sigma_cum_fac[1].data(); - const Real* sigma_star_cum_fac_j_y = sigba[mfi].sigma_star_cum_fac[1].data(); - const Real* sigma_cum_fac_j_z = sigba[mfi].sigma_cum_fac[2].data(); - const Real* sigma_star_cum_fac_j_z = sigba[mfi].sigma_star_cum_fac[2].data(); + const Real* sigma_cumsum_fac_j_y = sigba[mfi].sigma_cumsum_fac[1].data(); + const Real* sigma_star_cumsum_fac_j_y = sigba[mfi].sigma_star_cumsum_fac[1].data(); + const Real* sigma_cumsum_fac_j_z = sigba[mfi].sigma_cumsum_fac[2].data(); + const Real* sigma_star_cumsum_fac_j_z = sigba[mfi].sigma_star_cumsum_fac[2].data(); #else - const Real* sigma_cum_fac_j_y = nullptr; - const Real* sigma_star_cum_fac_j_y = nullptr; - const Real* sigma_cum_fac_j_z = sigba[mfi].sigma_cum_fac[1].data(); - const Real* sigma_star_cum_fac_j_z = sigba[mfi].sigma_star_cum_fac[1].data(); + const Real* sigma_cumsum_fac_j_y = nullptr; + const Real* sigma_star_cumsum_fac_j_y = nullptr; + const Real* sigma_cumsum_fac_j_z = sigba[mfi].sigma_cumsum_fac[1].data(); + const Real* sigma_star_cumsum_fac_j_z = sigba[mfi].sigma_star_cumsum_fac[1].data(); #endif const Box& tjx = mfi.tilebox(jx_nodal_flag); const Box& tjy = mfi.tilebox(jy_nodal_flag); const Box& tjz = mfi.tilebox(jz_nodal_flag); - auto const& AMREX_RESTRICT x_lo = sigba[mfi].sigma_cum_fac[0].lo(); + auto const& AMREX_RESTRICT x_lo = sigba[mfi].sigma_cumsum_fac[0].lo(); #if (AMREX_SPACEDIM == 3) - auto const& AMREX_RESTRICT y_lo = sigba[mfi].sigma_cum_fac[1].lo(); - auto const& AMREX_RESTRICT z_lo = sigba[mfi].sigma_cum_fac[2].lo(); + auto const& AMREX_RESTRICT y_lo = sigba[mfi].sigma_cumsum_fac[1].lo(); + auto const& AMREX_RESTRICT z_lo = sigba[mfi].sigma_cumsum_fac[2].lo(); #else int y_lo = 0; - auto const& AMREX_RESTRICT z_lo = sigba[mfi].sigma_cum_fac[1].lo(); + auto const& AMREX_RESTRICT z_lo = sigba[mfi].sigma_cumsum_fac[1].lo(); #endif - auto const& AMREX_RESTRICT xs_lo = sigba[mfi].sigma_star_cum_fac[0].lo(); + auto const& AMREX_RESTRICT xs_lo = sigba[mfi].sigma_star_cumsum_fac[0].lo(); #if (AMREX_SPACEDIM == 3) - auto const& AMREX_RESTRICT ys_lo = sigba[mfi].sigma_star_cum_fac[1].lo(); - auto const& AMREX_RESTRICT zs_lo = sigba[mfi].sigma_star_cum_fac[2].lo(); + auto const& AMREX_RESTRICT ys_lo = sigba[mfi].sigma_star_cumsum_fac[1].lo(); + auto const& AMREX_RESTRICT zs_lo = sigba[mfi].sigma_star_cumsum_fac[2].lo(); #else int ys_lo = 0; - auto const& AMREX_RESTRICT zs_lo = sigba[mfi].sigma_star_cum_fac[1].lo(); + auto const& AMREX_RESTRICT zs_lo = sigba[mfi].sigma_star_cumsum_fac[1].lo(); #endif amrex::ParallelFor( tjx, tjy, tjz, [=] AMREX_GPU_DEVICE (int i, int j, int k) { - damp_jx_pml(i, j, k, pml_jxfab, sigma_star_cum_fac_j_x, - sigma_cum_fac_j_y, sigma_cum_fac_j_z, + damp_jx_pml(i, j, k, pml_jxfab, sigma_star_cumsum_fac_j_x, + sigma_cumsum_fac_j_y, sigma_cumsum_fac_j_z, xs_lo,y_lo, z_lo); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { - damp_jy_pml(i, j, k, pml_jyfab, sigma_cum_fac_j_x, - sigma_star_cum_fac_j_y, sigma_cum_fac_j_z, + damp_jy_pml(i, j, k, pml_jyfab, sigma_cumsum_fac_j_x, + sigma_star_cumsum_fac_j_y, sigma_cumsum_fac_j_z, x_lo,ys_lo, z_lo); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { - damp_jz_pml(i, j, k, pml_jzfab, sigma_cum_fac_j_x, - sigma_cum_fac_j_y, sigma_star_cum_fac_j_z, + damp_jz_pml(i, j, k, pml_jzfab, sigma_cumsum_fac_j_x, + sigma_cumsum_fac_j_y, sigma_star_cumsum_fac_j_z, x_lo,y_lo, zs_lo); } ); -- cgit v1.2.3 From 1e864e4431c673c2b8097900de461003e19f6365 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 29 Aug 2019 20:25:29 +0200 Subject: Changed function name `CopyJinPML` to `CopyJtoPML` --- Source/BoundaryConditions/PML.H | 4 ++-- Source/BoundaryConditions/PML.cpp | 8 ++++---- Source/Evolve/WarpXEvolveEM.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 37c8ba961..95c55d29a 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -141,7 +141,7 @@ public: const std::array& E_cp, int do_pml_in_domain, int ncell, const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); - void CopyJinPMLs (const std::array& j_fp, + void CopyJtoPMLs (const std::array& j_fp, const std::array& j_cp); void CopyJinReg (const std::array& j_fp, const std::array& j_cp); @@ -154,7 +154,7 @@ public: const std::array& Ep, int do_pml_in_domain, int ncell, const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); - void CopyJinPMLs (PatchType patch_type, + void CopyJtoPMLs (PatchType patch_type, const std::array& jp); void CopyJinReg (PatchType patch_type, const std::array& jp); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index fd5a2de1c..7cddc1308 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -693,7 +693,7 @@ PML::ExchangeE (PatchType patch_type, } void -PML::CopyJinPMLs (PatchType patch_type, +PML::CopyJtoPMLs (PatchType patch_type, const std::array& jp) { if (patch_type == PatchType::fine && pml_j_fp[0] && jp[0]) @@ -711,11 +711,11 @@ PML::CopyJinPMLs (PatchType patch_type, } void -PML::CopyJinPMLs (const std::array& j_fp, +PML::CopyJtoPMLs (const std::array& j_fp, const std::array& j_cp) { - CopyJinPMLs(PatchType::fine, j_fp); - CopyJinPMLs(PatchType::coarse, j_cp); + CopyJtoPMLs(PatchType::fine, j_fp); + CopyJtoPMLs(PatchType::coarse, j_cp); } void diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index ffb079a7e..638b81acf 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -308,7 +308,7 @@ WarpX::OneStep_nosub (Real cur_time) for (int lev = 0; lev <= finest_level; ++lev) { if (pml[lev]->ok()){ - pml[lev]->CopyJinPMLs({ current_fp[lev][0].get(), + pml[lev]->CopyJtoPMLs({ current_fp[lev][0].get(), current_fp[lev][1].get(), current_fp[lev][2].get() }, { current_cp[lev][0].get(), -- cgit v1.2.3 From f182d0b6edd3fccb83ec2cb9e8c999f6a6c0aa75 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 29 Aug 2019 20:34:44 +0200 Subject: Deleted functions `CopyJinReg` and `CopyPMLsInReg` (unused) --- Source/BoundaryConditions/PML.H | 5 ----- Source/BoundaryConditions/PML.cpp | 36 ------------------------------------ 2 files changed, 41 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 95c55d29a..282424e05 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -143,8 +143,6 @@ public: const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void CopyJtoPMLs (const std::array& j_fp, const std::array& j_cp); - void CopyJinReg (const std::array& j_fp, - const std::array& j_cp); void ExchangeB (PatchType patch_type, const std::array& Bp, int do_pml_in_domain, int ncell, @@ -156,8 +154,6 @@ public: const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); void CopyJtoPMLs (PatchType patch_type, const std::array& jp); - void CopyJinReg (PatchType patch_type, - const std::array& jp); void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain, int ncell, const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), @@ -213,7 +209,6 @@ private: const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); - static void CopyPMLsInReg (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; #ifdef WARPX_USE_PSATD diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7cddc1308..c95933872 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -718,31 +718,6 @@ PML::CopyJtoPMLs (const std::array& j_fp, CopyJtoPMLs(PatchType::coarse, j_cp); } -void -PML::CopyJinReg (PatchType patch_type, - const std::array& jp) -{ - if (patch_type == PatchType::fine && pml_j_fp[0] && jp[0]) - { - CopyPMLsInReg(*pml_j_fp[0], *jp[0], *m_geom); - CopyPMLsInReg(*pml_j_fp[1], *jp[1], *m_geom); - CopyPMLsInReg(*pml_j_fp[2], *jp[2], *m_geom); - } - else if (patch_type == PatchType::coarse && pml_j_cp[0] && jp[0]) - { - CopyPMLsInReg(*pml_j_cp[0], *jp[0], *m_cgeom); - CopyPMLsInReg(*pml_j_cp[1], *jp[1], *m_cgeom); - CopyPMLsInReg(*pml_j_cp[2], *jp[2], *m_cgeom); - } -} - -void -PML::CopyJinReg (const std::array& j_fp, - const std::array& j_cp) -{ - CopyJinReg(PatchType::fine, j_fp); - CopyJinReg(PatchType::coarse, j_cp); -} void PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain, int ncell, @@ -855,17 +830,6 @@ PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) pml.ParallelCopy(reg, 0, 0, 1, ngr, ngp, period); } -void -PML::CopyPMLsInReg (MultiFab& pml, MultiFab& reg, const Geometry& geom) -{ - const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const auto& period = geom.periodicity(); - - reg.ParallelCopy(pml, 0, 0, 1, ngp, ngr, period); - -} - void PML::FillBoundary () { -- cgit v1.2.3 From 2f836ac19bb13cbdb42234347d0f037573f97aa6 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 29 Aug 2019 21:56:15 +0200 Subject: Changed function name "CopyRegInPMLs" to "CopyToPML" Tabulations changes --- Source/BoundaryConditions/PML.H | 2 +- Source/BoundaryConditions/PML.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 282424e05..ad7326dbb 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -208,7 +208,7 @@ private: static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain, int ncell, const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); - static void CopyRegInPMLs (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); + static void CopyToPML (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; #ifdef WARPX_USE_PSATD diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index c95933872..8c35e34e2 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -698,15 +698,15 @@ PML::CopyJtoPMLs (PatchType patch_type, { if (patch_type == PatchType::fine && pml_j_fp[0] && jp[0]) { - CopyRegInPMLs(*pml_j_fp[0], *jp[0], *m_geom); - CopyRegInPMLs(*pml_j_fp[1], *jp[1], *m_geom); - CopyRegInPMLs(*pml_j_fp[2], *jp[2], *m_geom); + CopyToPML(*pml_j_fp[0], *jp[0], *m_geom); + CopyToPML(*pml_j_fp[1], *jp[1], *m_geom); + CopyToPML(*pml_j_fp[2], *jp[2], *m_geom); } else if (patch_type == PatchType::coarse && pml_j_cp[0] && jp[0]) { - CopyRegInPMLs(*pml_j_cp[0], *jp[0], *m_cgeom); - CopyRegInPMLs(*pml_j_cp[1], *jp[1], *m_cgeom); - CopyRegInPMLs(*pml_j_cp[2], *jp[2], *m_cgeom); + CopyToPML(*pml_j_cp[0], *jp[0], *m_cgeom); + CopyToPML(*pml_j_cp[1], *jp[1], *m_cgeom); + CopyToPML(*pml_j_cp[2], *jp[2], *m_cgeom); } } @@ -740,8 +740,10 @@ PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain, int nc void -PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) +PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, + int do_pml_in_domain, int ncell, + const amrex::IntVect do_pml_Lo, + const amrex::IntVect do_pml_Hi) { if (do_pml_in_domain){ const IntVect& ngr = reg.nGrowVect(); @@ -821,7 +823,7 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in void -PML::CopyRegInPMLs (MultiFab& pml, MultiFab& reg, const Geometry& geom) +PML::CopyToPML (MultiFab& pml, MultiFab& reg, const Geometry& geom) { const IntVect& ngr = reg.nGrowVect(); const IntVect& ngp = pml.nGrowVect(); -- cgit v1.2.3 From a025c00a7436299a754879edae0d70abe5fec1d3 Mon Sep 17 00:00:00 2001 From: ablelly Date: Thu, 29 Aug 2019 22:32:01 +0200 Subject: Removed useless variables in PML Exchange functions --- Source/BoundaryConditions/PML.H | 28 ++++----------- Source/BoundaryConditions/PML.cpp | 62 ++++++++++++++------------------ Source/FieldSolver/WarpXPushFieldsEM.cpp | 2 +- Source/Parallelization/WarpXComm.cpp | 27 +++++--------- 4 files changed, 44 insertions(+), 75 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index ad7326dbb..0a9b23b7f 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -134,33 +134,21 @@ public: #endif void ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + const std::array& B_cp, int do_pml_in_domain); void ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + const std::array& E_cp, int do_pml_in_domain); void CopyJtoPMLs (const std::array& j_fp, const std::array& j_cp); void ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + const std::array& Bp, int do_pml_in_domain); void ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + const std::array& Ep, int do_pml_in_domain); void CopyJtoPMLs (PatchType patch_type, const std::array& jp); - void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); - void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + void ExchangeF (amrex::MultiFab* F_fp, amrex::MultiFab* F_cp, int do_pml_in_domain); + void ExchangeF (PatchType patch_type, amrex::MultiFab* Fp, int do_pml_in_domain); void FillBoundary (); void FillBoundaryE (); @@ -205,9 +193,7 @@ private: const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); - static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), - const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); + static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain); static void CopyToPML (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom); }; diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 8c35e34e2..7d1906525 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -638,57 +638,53 @@ PML::GetF_cp () void PML::ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) + const std::array& B_cp, int do_pml_in_domain) { - ExchangeB(PatchType::fine, B_fp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + ExchangeB(PatchType::fine, B_fp, do_pml_in_domain); + ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain); } void PML::ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) + const std::array& Bp, int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) { - Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_B_fp[0], *Bp[0], *m_geom, do_pml_in_domain); + Exchange(*pml_B_fp[1], *Bp[1], *m_geom, do_pml_in_domain); + Exchange(*pml_B_fp[2], *Bp[2], *m_geom, do_pml_in_domain); } else if (patch_type == PatchType::coarse && pml_B_cp[0] && Bp[0]) { - Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_B_cp[0], *Bp[0], *m_cgeom, do_pml_in_domain); + Exchange(*pml_B_cp[1], *Bp[1], *m_cgeom, do_pml_in_domain); + Exchange(*pml_B_cp[2], *Bp[2], *m_cgeom, do_pml_in_domain); } } void PML::ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) + const std::array& E_cp, int do_pml_in_domain) { - ExchangeE(PatchType::fine, E_fp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + ExchangeE(PatchType::fine, E_fp, do_pml_in_domain); + ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain); } void PML::ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) + const std::array& Ep, int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) { - Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_E_fp[0], *Ep[0], *m_geom, do_pml_in_domain); + Exchange(*pml_E_fp[1], *Ep[1], *m_geom, do_pml_in_domain); + Exchange(*pml_E_fp[2], *Ep[2], *m_geom, do_pml_in_domain); } else if (patch_type == PatchType::coarse && pml_E_cp[0] && Ep[0]) { - Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_E_cp[0], *Ep[0], *m_cgeom, do_pml_in_domain); + Exchange(*pml_E_cp[1], *Ep[1], *m_cgeom, do_pml_in_domain); + Exchange(*pml_E_cp[2], *Ep[2], *m_cgeom, do_pml_in_domain); } } @@ -720,30 +716,26 @@ PML::CopyJtoPMLs (const std::array& j_fp, void -PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) +PML::ExchangeF (MultiFab* F_fp, MultiFab* F_cp, int do_pml_in_domain) { - ExchangeF(PatchType::fine, F_fp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); - ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + ExchangeF(PatchType::fine, F_fp, do_pml_in_domain); + ExchangeF(PatchType::coarse, F_cp, do_pml_in_domain); } void -PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) +PML::ExchangeF (PatchType patch_type, MultiFab* Fp, int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_F_fp && Fp) { - Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_F_fp, *Fp, *m_geom, do_pml_in_domain); } else if (patch_type == PatchType::coarse && pml_F_cp && Fp) { - Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain, ncell, do_pml_Lo, do_pml_Hi); + Exchange(*pml_F_cp, *Fp, *m_cgeom, do_pml_in_domain); } } void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, - int do_pml_in_domain, int ncell, - const amrex::IntVect do_pml_Lo, - const amrex::IntVect do_pml_Hi) + int do_pml_in_domain) { if (do_pml_in_domain){ const IntVect& ngr = reg.nGrowVect(); diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index 94e49f0bc..dae18002d 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -461,7 +461,7 @@ WarpX::EvolveE (int lev, PatchType patch_type, amrex::Real a_dt) if (do_pml && pml[lev]->ok()) { - if (F) pml[lev]->ExchangeF(patch_type, F, do_pml_in_domain, pml_ncell); + if (F) pml[lev]->ExchangeF(patch_type, F, do_pml_in_domain); const auto& pml_B = (patch_type == PatchType::fine) ? pml[lev]->GetB_fp() : pml[lev]->GetB_cp(); const auto& pml_E = (patch_type == PatchType::fine) ? pml[lev]->GetE_fp() : pml[lev]->GetE_cp(); diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index c539cd89a..feb9d3564 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -19,8 +19,7 @@ WarpX::ExchangeWithPmlB (int lev) { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), Bfield_cp[lev][2].get() }, - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); } } @@ -34,8 +33,7 @@ WarpX::ExchangeWithPmlE (int lev) { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get() }, - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); } } @@ -45,8 +43,7 @@ WarpX::ExchangeWithPmlF (int lev) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeF(F_fp[lev].get(), F_cp[lev].get(), - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); } } @@ -259,8 +256,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) { Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), Efield_fp[lev][2].get() }, - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); pml[lev]->FillBoundaryE(patch_type); } @@ -276,8 +272,7 @@ WarpX::FillBoundaryE (int lev, PatchType patch_type) { Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get() }, - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); pml[lev]->FillBoundaryE(patch_type); } @@ -305,8 +300,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) { Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), Bfield_fp[lev][2].get() }, - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); pml[lev]->FillBoundaryB(patch_type); } const auto& period = Geom(lev).periodicity(); @@ -321,8 +315,7 @@ WarpX::FillBoundaryB (int lev, PatchType patch_type) { Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), Bfield_cp[lev][2].get() }, - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); pml[lev]->FillBoundaryB(patch_type); } const auto& cperiod = Geom(lev-1).periodicity(); @@ -346,8 +339,7 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeF(patch_type, F_fp[lev].get(), - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); pml[lev]->FillBoundaryF(patch_type); } @@ -359,8 +351,7 @@ WarpX::FillBoundaryF (int lev, PatchType patch_type) if (do_pml && pml[lev]->ok()) { pml[lev]->ExchangeF(patch_type, F_cp[lev].get(), - do_pml_in_domain, pml_ncell, - do_pml_Lo, do_pml_Hi); + do_pml_in_domain); pml[lev]->FillBoundaryF(patch_type); } -- cgit v1.2.3 From 7e501a2b3d9ecf58ae5650c6f66cc234462980f1 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Thu, 29 Aug 2019 15:54:55 -0700 Subject: Refactor communications in PML --- Source/BoundaryConditions/PML.cpp | 91 ++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 53 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7d1906525..53101bf72 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -737,57 +737,36 @@ void PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, int do_pml_in_domain) { - if (do_pml_in_domain){ - const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const int ncp = pml.nComp(); - const auto& period = geom.periodicity(); - - MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - tmpregmf.setVal(0.0, 0, ncp, ngr); - MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), ncp, ngp); - totpmlmf.setVal(0.0, 0, ncp, ngp); - // realise sum of splitted fields inside pml - MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); - if (ncp == 3) { - MultiFab::Add(totpmlmf,pml,2,0,1,0); - } - totpmlmf.setVal(0.0, 1, ncp-1, 0); - reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), IntVect(0), period); + BL_PROFILE("PML::Exchange"); - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data - { - MultiFab::Copy(tmpregmf, reg, 0, 0, 1, IntVect(0)); - MultiFab::Copy(totpmlmf, pml, 0, 0, ncp, ngp); + const IntVect& ngr = reg.nGrowVect(); + const IntVect& ngp = pml.nGrowVect(); + const int ncp = pml.nComp(); + const auto& period = geom.periodicity(); - tmpregmf.setVal(0.0, 1, ncp-1, 0); - tmpregmf.ParallelCopy(totpmlmf,0, 0, ncp, IntVect(0), IntVect(0), period); - totpmlmf.ParallelCopy(tmpregmf,0, 0, ncp, IntVect(0), ngp, period); + // Create temporary MultiFab to copy to and from the PML + MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - MultiFab::Copy(pml, totpmlmf, 0, 0, ncp, ngp); - } + // Create the sum of the split fields, in the PML + MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); // Allocate + MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); // Sum + if (ncp == 3) { + MultiFab::Add(totpmlmf,pml,2,0,1,0); // Sum the third split component } - else { - - const IntVect& ngr = reg.nGrowVect(); - const IntVect& ngp = pml.nGrowVect(); - const int ncp = pml.nComp(); - const auto& period = geom.periodicity(); - - MultiFab tmpregmf(reg.boxArray(), reg.DistributionMap(), ncp, ngr); - - if (ngp.max() > 0) // Copy from pml to the ghost cells of regular data - { - MultiFab totpmlmf(pml.boxArray(), pml.DistributionMap(), 1, 0); - MultiFab::LinComb(totpmlmf, 1.0, pml, 0, 1.0, pml, 1, 0, 1, 0); - if (ncp == 3) { - MultiFab::Add(totpmlmf,pml,2,0,1,0); - } - + // Copy from the sum of PML split field to valid cells of regular grid + if (do_pml_in_domain){ + // Valid cells of the PML and of the regular grid overlap + // Copy from valid cells of the PML to valid cells of the regular grid + reg.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), IntVect(0), period); + } else { + // Valid cells of the PML only overlap with guard cells of regular grid + // (and outermost valid cell of the regular grid, for nodal direction) + // Copy from valid cells of PML to ghost cells of regular grid + // but avoid updating the outermost valid cell + if (ngr.max() > 0) { MultiFab::Copy(tmpregmf, reg, 0, 0, 1, ngr); tmpregmf.ParallelCopy(totpmlmf, 0, 0, 1, IntVect(0), ngr, period); - #ifdef _OPENMP #pragma omp parallel #endif @@ -795,22 +774,28 @@ PML::Exchange (MultiFab& pml, MultiFab& reg, const Geometry& geom, { const FArrayBox& src = tmpregmf[mfi]; FArrayBox& dst = reg[mfi]; - Box test = mfi.validbox(); const BoxList& bl = amrex::boxDiff(dst.box(), mfi.validbox()); - for (const Box& bx : bl) - { + // boxDiff avoids the outermost valid cell + for (const Box& bx : bl) { dst.copy(src, bx, 0, bx, 0, 1); } } } - - // Copy from regular data to PML's first component - // Zero out the second (and third) component - MultiFab::Copy(tmpregmf,reg,0,0,1,0); - tmpregmf.setVal(0.0, 1, ncp-1, 0); - pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); } + // Copy from valid cells of the regular grid to guard cells of the PML + // (and outermost valid cell in the nodal direction) + // More specifically, copy from regular data to PML's first component + // Zero out the second (and third) component + MultiFab::Copy(tmpregmf,reg,0,0,1,0); // Fill first component of tmpregmf + tmpregmf.setVal(0.0, 1, ncp-1, 0); // Zero out the second (and third) component + if (do_pml_in_domain){ + // Where valid cells of tmpregmf overlap with PML valid cells, + // copy the PML (this is order to avoid overwriting PML valid cells, + // in the next `ParallelCopy`) + tmpregmf.ParallelCopy(pml,0, 0, ncp, IntVect(0), IntVect(0), period); + } + pml.ParallelCopy(tmpregmf, 0, 0, ncp, IntVect(0), ngp, period); } -- cgit v1.2.3 From a34cb0f8d42b86593b319ab531e5ed66a98b1bc6 Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 30 Aug 2019 01:26:57 +0200 Subject: Layout changes for the file PML.cpp --- Source/BoundaryConditions/PML.cpp | 127 ++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 45 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 7d1906525..03d9dd9d8 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -15,7 +15,8 @@ using namespace amrex; namespace { - static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, + static void FillLo (int idim, Sigma& sigma, Sigma& sigma_cumsum, + Sigma& sigma_star, Sigma& sigma_star_cumsum, const Box& overlap, const Box& grid, Real fac) { int glo = grid.smallEnd(idim); @@ -29,6 +30,7 @@ namespace { Real offset = static_cast(glo-i); sigma[i-slo] = fac*(offset*offset); + // sigma_cumsum is the analytical integral of sigma function at same points than sigma sigma_cumsum[i-slo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } @@ -36,11 +38,13 @@ namespace { Real offset = static_cast(glo-i) - 0.5; sigma_star[i-sslo] = fac*(offset*offset); + // sigma_star_cumsum is the analytical integral of sigma function at same points than sigma_star sigma_star_cumsum[i-sslo] = (fac*(offset*offset*offset)/3.)/PhysConst::c; } } - static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, + static void FillHi (int idim, Sigma& sigma, Sigma& sigma_cumsum, + Sigma& sigma_star, Sigma& sigma_star_cumsum, const Box& overlap, const Box& grid, Real fac) { int ghi = grid.bigEnd(idim); @@ -63,7 +67,9 @@ namespace } } - static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const Box& overlap) + static void FillZero (int idim, Sigma& sigma, Sigma& sigma_cumsum, + Sigma& sigma_star, Sigma& sigma_star_cumsum, + const Box& overlap) { int olo = overlap.smallEnd(idim); int ohi = overlap.bigEnd(idim); @@ -86,29 +92,29 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - sigma [idim].resize(sz[idim]+1); - sigma_cumsum [idim].resize(sz[idim]+1); - sigma_star [idim].resize(sz[idim]); - sigma_star_cumsum[idim].resize(sz[idim]); - sigma_fac [idim].resize(sz[idim]+1); - sigma_cumsum_fac [idim].resize(sz[idim]+1); - sigma_star_fac[idim].resize(sz[idim]); + sigma [idim].resize(sz[idim]+1); + sigma_cumsum [idim].resize(sz[idim]+1); + sigma_star [idim].resize(sz[idim]); + sigma_star_cumsum [idim].resize(sz[idim]); + sigma_fac [idim].resize(sz[idim]+1); + sigma_cumsum_fac [idim].resize(sz[idim]+1); + sigma_star_fac [idim].resize(sz[idim]); sigma_star_cumsum_fac[idim].resize(sz[idim]); - sigma [idim].m_lo = lo[idim]; - sigma [idim].m_hi = hi[idim]+1; - sigma_cumsum [idim].m_lo = lo[idim]; - sigma_cumsum [idim].m_hi = hi[idim]+1; - sigma_star [idim].m_lo = lo[idim]; - sigma_star [idim].m_hi = hi[idim]; - sigma_star_cumsum[idim].m_lo = lo[idim]; - sigma_star_cumsum[idim].m_hi = hi[idim]; - sigma_fac [idim].m_lo = lo[idim]; - sigma_fac [idim].m_hi = hi[idim]+1; - sigma_cumsum_fac [idim].m_lo = lo[idim]; - sigma_cumsum_fac [idim].m_hi = hi[idim]+1; - sigma_star_fac[idim].m_lo = lo[idim]; - sigma_star_fac[idim].m_hi = hi[idim]; + sigma [idim].m_lo = lo[idim]; + sigma [idim].m_hi = hi[idim]+1; + sigma_cumsum [idim].m_lo = lo[idim]; + sigma_cumsum [idim].m_hi = hi[idim]+1; + sigma_star [idim].m_lo = lo[idim]; + sigma_star [idim].m_hi = hi[idim]; + sigma_star_cumsum [idim].m_lo = lo[idim]; + sigma_star_cumsum [idim].m_hi = hi[idim]; + sigma_fac [idim].m_lo = lo[idim]; + sigma_fac [idim].m_hi = hi[idim]+1; + sigma_cumsum_fac [idim].m_lo = lo[idim]; + sigma_cumsum_fac [idim].m_hi = hi[idim]+1; + sigma_star_fac [idim].m_lo = lo[idim]; + sigma_star_fac [idim].m_hi = hi[idim]; sigma_star_cumsum_fac[idim].m_lo = lo[idim]; sigma_star_cumsum_fac[idim].m_hi = hi[idim]; } @@ -178,7 +184,9 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], + looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); @@ -188,7 +196,9 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n #endif Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], + hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -202,7 +212,8 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& grid_box = grids[gid]; const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], overlap); + FillZero(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_side_edges, how did this happen?\n"); @@ -216,13 +227,17 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n Box lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox.grow(jdim,ncell).grow(kdim,ncell) & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], + looverlap, grid_box, fac[idim]); } Box hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox.grow(jdim,ncell).grow(kdim,ncell) & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], + hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -240,7 +255,8 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& overlap = amrex::grow(amrex::grow(grid_box,jdim,ncell),kdim,ncell) & box; #endif if (overlap.ok()) { - FillZero(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], overlap); + FillZero(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], overlap); } else { amrex::Abort("SigmaBox::SigmaBox(): side_faces, how did this happen?\n"); } @@ -253,13 +269,17 @@ SigmaBox::SigmaBox (const Box& box, const BoxArray& grids, const Real* dx, int n const Box& lobox = amrex::adjCellLo(grid_box, idim, ncell); Box looverlap = lobox & box; if (looverlap.ok()) { - FillLo(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], looverlap, grid_box, fac[idim]); + FillLo(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], + looverlap, grid_box, fac[idim]); } const Box& hibox = amrex::adjCellHi(grid_box, idim, ncell); Box hioverlap = hibox & box; if (hioverlap.ok()) { - FillHi(idim, sigma[idim], sigma_cumsum[idim], sigma_star[idim], sigma_star_cumsum[idim], hioverlap, grid_box, fac[idim]); + FillHi(idim, sigma[idim], sigma_cumsum[idim], + sigma_star[idim], sigma_star_cumsum[idim], + hioverlap, grid_box, fac[idim]); } if (!looverlap.ok() && !hioverlap.ok()) { @@ -341,9 +361,9 @@ MultiSigmaBox::ComputePMLFactorsE (const Real* dx, Real dt) PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const Geometry* geom, const Geometry* cgeom, int ncell, int delta, int ref_ratio, - #ifdef WARPX_USE_PSATD - Real dt, int nox_fft, int noy_fft, int noz_fft, bool do_nodal, - #endif +#ifdef WARPX_USE_PSATD + Real dt, int nox_fft, int noy_fft, int noz_fft, bool do_nodal, +#endif int do_dive_cleaning, int do_moving_window, int pml_has_particles, int do_pml_in_domain, const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) @@ -351,6 +371,11 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, m_cgeom(cgeom) { + // When `do_pml_in_domain` is true, the PML overlap with the last `ncell` of the physical domain + // (instead of extending `ncell` outside of the physical domain) + // In order to implement this, a reduced domain is created here (decreased by ncells in all direction) + // and passed to `MakeBoxArray`, which surrounds it by PML boxes + // (thus creating the PML boxes at the right position, where they overlap with the original domain) Box domain0 = geom->Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ( ! geom->isPeriodic(idim)) { @@ -365,7 +390,9 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); - const BoxArray& ba = (do_pml_in_domain)? MakeBoxArray(*geom, grid_ba_reduced, ncell, do_pml_Lo, do_pml_Hi) : MakeBoxArray(*geom, grid_ba, ncell, do_pml_Lo, do_pml_Hi); + const BoxArray& ba = (do_pml_in_domain)? + MakeBoxArray(*geom, grid_ba_reduced, ncell, do_pml_Lo, do_pml_Hi) : + MakeBoxArray(*geom, grid_ba, ncell, do_pml_Lo, do_pml_Hi); if (ba.size() == 0) { m_ok = false; @@ -460,7 +487,9 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, grid_cba.coarsen(ref_ratio); const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); - const BoxArray& cba = (do_pml_in_domain) ? MakeBoxArray(*cgeom, grid_cba_reduced, ncell, do_pml_Lo, do_pml_Hi) : MakeBoxArray(*cgeom, grid_cba, ncell, do_pml_Lo, do_pml_Hi); + const BoxArray& cba = (do_pml_in_domain) ? + MakeBoxArray(*cgeom, grid_cba_reduced, ncell, do_pml_Lo, do_pml_Hi) : + MakeBoxArray(*cgeom, grid_cba, ncell, do_pml_Lo, do_pml_Hi); DistributionMapping cdm{cba}; @@ -493,8 +522,7 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, if (do_pml_in_domain){ sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba_reduced, cgeom->CellSize(), ncell, delta)); - } - else { + } else { sigba_cp.reset(new MultiSigmaBox(cba, cdm, grid_cba, cgeom->CellSize(), ncell, delta)); } @@ -530,8 +558,13 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, { const Box& grid_bx = grid_ba[i]; const IntVect& grid_bx_sz = grid_bx.size(); - // AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, - // "Consider using larger amr.blocking_factor"); + + if (do_pml_in_domain == 0) { + // Make sure that, in the case of several distinct refinement patches, + // the PML cells surrounding these patches cannot overlap + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(grid_bx.shortside() > ncell, + "Consider using larger amr.blocking_factor"); + } Box bx = grid_bx; bx.grow(ncell); @@ -638,7 +671,8 @@ PML::GetF_cp () void PML::ExchangeB (const std::array& B_fp, - const std::array& B_cp, int do_pml_in_domain) + const std::array& B_cp, + int do_pml_in_domain) { ExchangeB(PatchType::fine, B_fp, do_pml_in_domain); ExchangeB(PatchType::coarse, B_cp, do_pml_in_domain); @@ -646,7 +680,8 @@ PML::ExchangeB (const std::array& B_fp, void PML::ExchangeB (PatchType patch_type, - const std::array& Bp, int do_pml_in_domain) + const std::array& Bp, + int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_B_fp[0] && Bp[0]) { @@ -664,7 +699,8 @@ PML::ExchangeB (PatchType patch_type, void PML::ExchangeE (const std::array& E_fp, - const std::array& E_cp, int do_pml_in_domain) + const std::array& E_cp, + int do_pml_in_domain) { ExchangeE(PatchType::fine, E_fp, do_pml_in_domain); ExchangeE(PatchType::coarse, E_cp, do_pml_in_domain); @@ -672,7 +708,8 @@ PML::ExchangeE (const std::array& E_fp, void PML::ExchangeE (PatchType patch_type, - const std::array& Ep, int do_pml_in_domain) + const std::array& Ep, + int do_pml_in_domain) { if (patch_type == PatchType::fine && pml_E_fp[0] && Ep[0]) { -- cgit v1.2.3 From e0fff837554473383fe0a7d3a39fda46344825a6 Mon Sep 17 00:00:00 2001 From: ablelly Date: Fri, 30 Aug 2019 17:01:19 +0200 Subject: Compilation bug fixed --- Source/BoundaryConditions/PML.H | 3 ++- Source/BoundaryConditions/PML.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'Source/BoundaryConditions/PML.cpp') diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 0a9b23b7f..9e04322f5 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -189,7 +189,8 @@ private: #endif static amrex::BoxArray MakeBoxArray (const amrex::Geometry& geom, - const amrex::BoxArray& grid_ba, int ncell, + const amrex::BoxArray& grid_ba, + int ncell, int do_pml_in_domain, const amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), const amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 3ee864b62..8f8a2608e 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -391,8 +391,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const BoxArray grid_ba_reduced = BoxArray(grid_ba.boxList().intersect(domain0)); const BoxArray& ba = (do_pml_in_domain)? - MakeBoxArray(*geom, grid_ba_reduced, ncell, do_pml_Lo, do_pml_Hi) : - MakeBoxArray(*geom, grid_ba, ncell, do_pml_Lo, do_pml_Hi); + MakeBoxArray(*geom, grid_ba_reduced, ncell, do_pml_in_domain, do_pml_Lo, do_pml_Hi) : + MakeBoxArray(*geom, grid_ba, ncell, do_pml_in_domain, do_pml_Lo, do_pml_Hi); if (ba.size() == 0) { m_ok = false; @@ -488,8 +488,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, const BoxArray grid_cba_reduced = BoxArray(grid_cba.boxList().intersect(domain0)); const BoxArray& cba = (do_pml_in_domain) ? - MakeBoxArray(*cgeom, grid_cba_reduced, ncell, do_pml_Lo, do_pml_Hi) : - MakeBoxArray(*cgeom, grid_cba, ncell, do_pml_Lo, do_pml_Hi); + MakeBoxArray(*cgeom, grid_cba_reduced, ncell, do_pml_in_domain, do_pml_Lo, do_pml_Hi) : + MakeBoxArray(*cgeom, grid_cba, ncell, do_pml_in_domain, do_pml_Lo, do_pml_Hi); DistributionMapping cdm{cba}; @@ -539,7 +539,8 @@ PML::PML (const BoxArray& grid_ba, const DistributionMapping& grid_dm, } BoxArray -PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, int ncell, +PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, + int ncell, int do_pml_in_domain, const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) { Box domain = geom.Domain(); @@ -558,7 +559,7 @@ PML::MakeBoxArray (const amrex::Geometry& geom, const amrex::BoxArray& grid_ba, { const Box& grid_bx = grid_ba[i]; const IntVect& grid_bx_sz = grid_bx.size(); - + if (do_pml_in_domain == 0) { // Make sure that, in the case of several distinct refinement patches, // the PML cells surrounding these patches cannot overlap -- cgit v1.2.3