From 522e1729a05e9cb208a4a45cdf1bd28769836a8c Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 18 Nov 2019 18:20:07 -0800 Subject: Adding constant init type for parsing constant values for E_ and B_external_grid --- Source/Initialization/WarpXInitData.cpp | 50 ++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 609399ece..69c17acd4 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -303,20 +303,56 @@ WarpX::InitOpenbc () void WarpX::InitLevelData (int lev, Real time) { + + ParmParse pp("warpx"); + + std::string B_ext_grid_s; + // default is constant so that the default values of + // E_external_grid[i] and B_external_grid[i] can + // be used for setting the value of the E & B fields. + B_ext_grid_s = "constant"; + pp.query("B_ext_grid_init_style", B_ext_grid_s); + std::transform(B_ext_grid_s.begin(), + B_ext_grid_s.end(), + B_ext_grid_s.begin(), + ::tolower); + + std::string E_ext_grid_s; + pp.query("E_ext_grid_init_style", E_ext_grid_s); + std::transform(E_ext_grid_s.begin(), + E_ext_grid_s.end(), + E_ext_grid_s.begin(), + ::tolower); + + if (B_ext_grid_s == "constant") { + pp.getarr("B_external_grid", B_external_particle); + } + + if (E_ext_grid_s == "constant") { + pp.getarr("E_external_grid", E_external_particle); + } + for (int i = 0; i < 3; ++i) { current_fp[lev][i]->setVal(0.0); - Efield_fp[lev][i]->setVal(E_external_grid[i]); - Bfield_fp[lev][i]->setVal(B_external_grid[i]); + if (B_ext_grid_s == "constant") { + Bfield_fp[lev][i]->setVal(B_external_grid[i]); + } + if (E_ext_grid_s == "constant") { + Efield_fp[lev][i]->setVal(E_external_grid[i]); + } } if (lev > 0) { for (int i = 0; i < 3; ++i) { - Efield_aux[lev][i]->setVal(E_external_grid[i]); - Bfield_aux[lev][i]->setVal(B_external_grid[i]); - current_cp[lev][i]->setVal(0.0); - Efield_cp[lev][i]->setVal(E_external_grid[i]); - Bfield_cp[lev][i]->setVal(B_external_grid[i]); + if (B_ext_grid_s == "constant") { + Bfield_aux[lev][i]->setVal(B_external_grid[i]); + Bfield_cp[lev][i]->setVal(B_external_grid[i]); + } + if (E_ext_grid_s == "constant") { + Efield_aux[lev][i]->setVal(E_external_grid[i]); + Efield_cp[lev][i]->setVal(E_external_grid[i]); + } } } -- cgit v1.2.3 From 1701c17ce57ebc7048ecbe254a6247a4b06dfbe9 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Thu, 21 Nov 2019 15:03:47 -0800 Subject: adding GPU parser --- Source/Initialization/WarpXInitData.cpp | 183 +++++++++++++++++++++++++++++++- Source/WarpX.H | 34 +++++- Source/WarpX.cpp | 9 ++ 3 files changed, 223 insertions(+), 3 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index d0e38af07..1a9ee3d00 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -10,6 +10,9 @@ #ifdef BL_USE_SENSEI_INSITU #include #endif +#include + +#include using namespace amrex; @@ -231,10 +234,44 @@ WarpX::PostRestart () mypc->PostRestart(); } + +namespace { +WarpXParser makeParser (std::string const& parse_function) +{ + std::cout << " in make parser " << parse_function << std::endl; + WarpXParser parser(parse_function); + parser.registerVariables({"x","y","z"}); + ParmParse pp("my_constants"); + std::set symbols = parser.symbols(); + symbols.erase("x"); + symbols.erase("y"); + symbols.erase("z"); + for (auto it = symbols.begin(); it != symbols.end(); ) { + Real v; + if (pp.query(it->c_str(), v)) { + parser.setConstant(*it, v); + it = symbols.erase(it); + } else { + ++it; + } + } + for (auto const& s : symbols) { + amrex::Abort(" ExternalEBFieldOnGrid::makeParser::Unknown symbol "+s); + } + return parser; +} +} + + + + + + void WarpX::InitLevelData (int lev, Real time) { + amrex::Print() << " at initlevel data " << lev << " time " << time << "\n"; ParmParse pp("warpx"); std::string B_ext_grid_s; @@ -242,11 +279,13 @@ WarpX::InitLevelData (int lev, Real time) // E_external_grid[i] and B_external_grid[i] can // be used for setting the value of the E & B fields. B_ext_grid_s = "constant"; + pp.query("B_ext_grid_init_style", B_ext_grid_s); std::transform(B_ext_grid_s.begin(), B_ext_grid_s.end(), B_ext_grid_s.begin(), ::tolower); + amrex::Print() << " init style " << B_ext_grid_s << "\n"; std::string E_ext_grid_s; pp.query("E_ext_grid_init_style", E_ext_grid_s); @@ -256,15 +295,28 @@ WarpX::InitLevelData (int lev, Real time) ::tolower); if (B_ext_grid_s == "constant") { - pp.getarr("B_external_grid", B_external_particle); + pp.getarr("B_external_grid", B_external_grid); + } + if (B_ext_grid_s == "parse_b_ext_grid_function") + { + amrex::Print() << " parse function " << "\n"; +// std::vector f; +// pp.getarr("Bx_external_grid_function(x,y,z)", f); +// for (auto const& s : f) { +// str_Bx_ext_grid_function += s; +// } +// f.clear(); +// } if (E_ext_grid_s == "constant") { - pp.getarr("E_external_grid", E_external_particle); + pp.getarr("E_external_grid", E_external_grid); } for (int i = 0; i < 3; ++i) { current_fp[lev][i]->setVal(0.0); + Bfield_fp[lev][i]->setVal(0.0); + Efield_fp[lev][i]->setVal(0.0); if (B_ext_grid_s == "constant") { Bfield_fp[lev][i]->setVal(B_external_grid[i]); } @@ -272,6 +324,126 @@ WarpX::InitLevelData (int lev, Real time) Efield_fp[lev][i]->setVal(E_external_grid[i]); } } + if (B_ext_grid_s == "parse_b_ext_grid_function") { + + MultiFab *Bx, *By, *Bz; + Bx = Bfield_fp[lev][0].get(); + By = Bfield_fp[lev][1].get(); + Bz = Bfield_fp[lev][2].get(); + const auto dx_lev = geom[lev].CellSizeArray(); + const RealBox& real_box = geom[lev].ProbDomain(); + amrex::Print() << " cell size " << dx_lev[0] << " " << dx_lev[1] << " \n"; + std::string str_Bx_function; + std::vector f; + pp.getarr("Bx_external_grid_function(x,y,z)", f); + str_Bx_function.clear(); + for (auto const& s : f) { + str_Bx_function += s; + } + f.clear(); + + std::unique_ptr Bx_parsewrap; + Bx_parsewrap.reset(new ParserWrapper(makeParser(str_Bx_function))); + ParserWrapper* Bx_wrap = (Bx_parsewrap.get()); + + for ( MFIter mfi(*Bx, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& tbx = mfi.tilebox(Bx_nodal_flag); + const Box& tby = mfi.tilebox(By_nodal_flag); + const Box& tbz = mfi.tilebox(Bz_nodal_flag); + // Bx + auto const& Bxfab = Bx->array(mfi); + auto const& lo = lbound(tbx); + auto const& hi = ubound(tbx); + amrex::Print() << " lo " << lo << " hi " << hi << "\n"; + auto const& Bx_IndexType = (*Bx).ixType(); + IntVect Bx_type(AMREX_D_DECL(0,0,0)); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + Bx_type[idim] = Bx_IndexType.nodeCentered(idim); + } + amrex::Print() << " ix type " << Bx_IndexType << "\n"; + amrex::Print() << " type : " << Bx_type << "\n"; + //ParserWrapper *Bx_parsewrap = new ParserWrapper(Bx_parser); +// amrex::Print() << " parsewrap " << Bx_parsewrap->m_parser << "\n"; +// amrex::Print() << " parse wrap " << Bx_wrap->m_parser << "\n"; + Real xx = 1.0; Real yy = 0.0; Real zz = 0.0; + Real g = Bx_wrap->m_parser(xx,yy,zz); + amrex::Print() << "g " << g << "\n"; + Real g2 = Bx_wrap->getField(xx,yy,zz); + amrex::Print() << "g2 " << g2 << "\n"; + amrex::ParallelFor (tbx, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + int xdim = 0; int ydim = 1; int zdim = 2; + + //Real fac_x = (1.0 - Bx_type[0]) * dx_lev[0]*0.5; + //Real x = i*dx_lev[xdim] + real_box.lo(xdim) + fac_x; + //Real fac_y = (1.0 - Bx_type[1]) * dx_lev[1]*0.5; + //Real y = j*dx_lev[ydim] + real_box.lo(ydim) + fac_y; + Real x = 0.0, y = 0.0, z = 0.0; + Bxfab(i,j,k) = Bx_wrap->getField(x,y,z); + // Bxfab(i,j,k) = 0.0; + + } + ); + + // for (int k = lo.z; k <= hi.z; ++k) { + // for (int j = lo.y; j <= hi.y; ++j) { + // for (int i = lo.x; i <= hi.x; ++i) { + // //std::vector f; + // //pp.getarr("Bx_external_grid_function(x,y,z)", f); + // //str_Bx_ext_grid_function.clear(); + // //for (auto const& s : f) { + // // str_Bx_ext_grid_function += s; + // //} + // //f.clear(); + // //WarpXParser const& Bx_parser = makeParser(str_Bx_ext_grid_function); + // // + // //GpuParser m_Bx_parser = Bx_parser; + + // //Real x,y,z; + // int xdim = 0; int ydim = 1; int zdim = 2; + // // + // Real fac_x = (1.0 - Bx_type[0]) * dx_lev[0]*0.5; + // Real x = i*dx_lev[xdim] + real_box.lo(xdim) + fac_x; + // Real fac_y = (1.0 - Bx_type[1]) * dx_lev[1]*0.5; + // Real y = j*dx_lev[ydim] + real_box.lo(ydim) + fac_y; + // Real z = 0.0; + // //Bxfab(i,j,k) = m_Bx_parser(x,y,z); + // //amrex::Print() << " facx " << fac_x << " facy " << fac_y << "\n"; + // //amrex::Print() << " Bx at " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << " x is " << x << " z is " << y << "\n"; + // amrex::Print() << " x " << x << " " << y << "\n"; + // //Real compare = 200*std::cosh(x/2.0) + 10*y; + // Real compare = 200*std::cos(x/2.0) + 10*y; + // amrex::Print() << " Bx at " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << " compare " << compare << "\n"; + // }}} + // // By + // auto const& By_IndexType = (*By).ixType(); + // auto const& Byfab = By->array(mfi); + // auto const& lo_y = lbound(tby); + // auto const& hi_y = ubound(tby); + // for (int k = lo_y.z; k <= hi_y.z; ++k) { + // for (int j = lo_y.y; j <= hi_y.y; ++j) { + // for (int i = lo_y.x; i <= hi_y.x; ++i) { +// // Byfab(i,j,k) = B_external_grid[1]; + // Byfab(i,j,k) = 0; + // amrex::Print() << " By at " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; + // }}} + // + // // Bz + // auto const& Bz_IndexType = (*Bz).ixType(); + // auto const& Bzfab = Bz->array(mfi); + // auto const& lo_z = lbound(tbz); + // auto const& hi_z = ubound(tbz); + // for (int k = lo_z.z; k <= hi_z.z; ++k) { + // for (int j = lo_z.y; j <= hi_z.y; ++j) { + // for (int i = lo_z.x; i <= hi_z.x; ++i) { + // //Bzfab(i,j,k) = B_external_grid[2]; + // Bzfab(i,j,k) = 0; + // amrex::Print() << " Bz at " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; + // }}} + // + } + } if (lev > 0) { for (int i = 0; i < 3; ++i) { @@ -280,9 +452,16 @@ WarpX::InitLevelData (int lev, Real time) Bfield_aux[lev][i]->setVal(B_external_grid[i]); Bfield_cp[lev][i]->setVal(B_external_grid[i]); } + else { + Bfield_aux[lev][i]->setVal(0.0); + Bfield_cp[lev][i]->setVal(0.0); + } if (E_ext_grid_s == "constant") { Efield_aux[lev][i]->setVal(E_external_grid[i]); Efield_cp[lev][i]->setVal(E_external_grid[i]); + } else { + Efield_aux[lev][i]->setVal(0.0); + Efield_cp[lev][i]->setVal(0.0); } } } diff --git a/Source/WarpX.H b/Source/WarpX.H index 0a36e46ed..9ded68f82 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -82,6 +82,15 @@ public: static amrex::Vector E_external_grid; static amrex::Vector B_external_grid; + // Parser for B_external on the grid + static std::string str_Bx_ext_grid_function; + static std::string str_By_ext_grid_function; + static std::string str_Bz_ext_grid_function; + // Parser for E_external on the grid + static std::string str_Ex_ext_grid_function; + static std::string str_Ey_ext_grid_function; + static std::string str_Ez_ext_grid_function; + // Algorithms static long current_deposition_algo; static long charge_deposition_algo; @@ -309,6 +318,9 @@ public: void computeE(amrex::Vector, 3> >& E, const amrex::Vector >& phi) const; + // Making this function public to allow the use of GPU launch + // to initialize E and B fields using parser. + void InitLevelData (int lev, amrex::Real time); protected: //! Tagging cells for refinement @@ -398,7 +410,6 @@ private: void AllocLevelData (int lev, const amrex::BoxArray& new_grids, const amrex::DistributionMapping& new_dmap); - void InitLevelData (int lev, amrex::Real time); void InitFromCheckpoint (); void PostRestart (); @@ -648,4 +659,25 @@ private: int insitu_pin_mesh; }; +struct ParserWrapper + : public amrex::Gpu::Managed +{ + ParserWrapper (WarpXParser const& a_parser) noexcept + : m_parser(a_parser) {} + + AMREX_GPU_HOST_DEVICE + amrex::Real + getField (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept + { + return m_parser(x,y,z); + } + + GpuParser m_parser; + + ~ParserWrapper() { + m_parser.clear(); + } + +}; + #endif diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index b07a48cde..bc23e0370 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -30,6 +30,15 @@ Vector WarpX::E_external_particle(3, 0.0); Vector WarpX::E_external_grid(3, 0.0); Vector WarpX::B_external_grid(3, 0.0); +// Parser for B_external on the grid +std::string WarpX::str_Bx_ext_grid_function; +std::string WarpX::str_By_ext_grid_function; +std::string WarpX::str_Bz_ext_grid_function; +// Parser for E_external on the grid +std::string WarpX::str_Ex_ext_grid_function; +std::string WarpX::str_Ey_ext_grid_function; +std::string WarpX::str_Ez_ext_grid_function; + int WarpX::do_moving_window = 0; int WarpX::moving_window_dir = -1; Real WarpX::moving_window_v = std::numeric_limits::max(); -- cgit v1.2.3 From 6c1e356fe07da0b7d570f8c336cf6504222bf89f Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Fri, 22 Nov 2019 17:50:09 -0800 Subject: adding shared memory for parser and cleaning --- Source/Initialization/WarpXInitData.cpp | 420 +++++++++++++++++++++----------- Source/WarpX.H | 47 ++-- Source/WarpX.cpp | 3 - 3 files changed, 305 insertions(+), 165 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 1a9ee3d00..69c8d8efd 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -12,7 +12,6 @@ #endif #include -#include using namespace amrex; @@ -271,192 +270,216 @@ void WarpX::InitLevelData (int lev, Real time) { - amrex::Print() << " at initlevel data " << lev << " time " << time << "\n"; ParmParse pp("warpx"); std::string B_ext_grid_s; - // default is constant so that the default values of - // E_external_grid[i] and B_external_grid[i] can - // be used for setting the value of the E & B fields. - B_ext_grid_s = "constant"; + std::string E_ext_grid_s; + // default values of E_external_grid and B_external_grid + // are used to set the E and B field when "constant" or + // "parser" is not explicitly used in the input. + B_ext_grid_s = "default"; + E_ext_grid_s = "default"; pp.query("B_ext_grid_init_style", B_ext_grid_s); std::transform(B_ext_grid_s.begin(), B_ext_grid_s.end(), B_ext_grid_s.begin(), ::tolower); - amrex::Print() << " init style " << B_ext_grid_s << "\n"; + amrex::Print() << " B_init style " << B_ext_grid_s << "\n"; - std::string E_ext_grid_s; pp.query("E_ext_grid_init_style", E_ext_grid_s); std::transform(E_ext_grid_s.begin(), E_ext_grid_s.end(), E_ext_grid_s.begin(), ::tolower); + amrex::Print() << " E_init style " << E_ext_grid_s << "\n"; - if (B_ext_grid_s == "constant") { + // if the input string is "constant", the values for the + // external grid must be provided in the input. + if (B_ext_grid_s == "constant") pp.getarr("B_external_grid", B_external_grid); - } - if (B_ext_grid_s == "parse_b_ext_grid_function") - { - amrex::Print() << " parse function " << "\n"; -// std::vector f; -// pp.getarr("Bx_external_grid_function(x,y,z)", f); -// for (auto const& s : f) { -// str_Bx_ext_grid_function += s; -// } -// f.clear(); -// - } - - if (E_ext_grid_s == "constant") { + + // if the input string is "constant", the values for the + // external grid must be provided in the input. + if (E_ext_grid_s == "constant") pp.getarr("E_external_grid", E_external_grid); - } - + for (int i = 0; i < 3; ++i) { current_fp[lev][i]->setVal(0.0); - Bfield_fp[lev][i]->setVal(0.0); - Efield_fp[lev][i]->setVal(0.0); - if (B_ext_grid_s == "constant") { - Bfield_fp[lev][i]->setVal(B_external_grid[i]); - } - if (E_ext_grid_s == "constant") { - Efield_fp[lev][i]->setVal(E_external_grid[i]); - } + if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") + Bfield_fp[lev][i]->setVal(B_external_grid[i]); + if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") + Efield_fp[lev][i]->setVal(E_external_grid[i]); } + if (B_ext_grid_s == "parse_b_ext_grid_function") { - + + std::vector f; + // Parse Bx_external_grid_function + pp.getarr("Bx_external_grid_function(x,y,z)", f); + str_Bx_ext_grid_function.clear(); + for (auto const& s : f) { + str_Bx_ext_grid_function += s; + } + f.clear(); + + // Parse By_external_grid_function + pp.getarr("By_external_grid_function(x,y,z)", f); + str_By_ext_grid_function.clear(); + for (auto const& s : f) { + str_By_ext_grid_function += s; + } + f.clear(); + + // Parse Bz_external_grid_function + pp.getarr("Bz_external_grid_function(x,y,z)", f); + str_Bz_ext_grid_function.clear(); + for (auto const& s : f) { + str_Bz_ext_grid_function += s; + } + f.clear(); + + // Initialize Bfield_fp with external function MultiFab *Bx, *By, *Bz; Bx = Bfield_fp[lev][0].get(); By = Bfield_fp[lev][1].get(); Bz = Bfield_fp[lev][2].get(); - const auto dx_lev = geom[lev].CellSizeArray(); - const RealBox& real_box = geom[lev].ProbDomain(); - amrex::Print() << " cell size " << dx_lev[0] << " " << dx_lev[1] << " \n"; - std::string str_Bx_function; - std::vector f; - pp.getarr("Bx_external_grid_function(x,y,z)", f); - str_Bx_function.clear(); - for (auto const& s : f) { - str_Bx_function += s; - } - f.clear(); - - std::unique_ptr Bx_parsewrap; - Bx_parsewrap.reset(new ParserWrapper(makeParser(str_Bx_function))); - ParserWrapper* Bx_wrap = (Bx_parsewrap.get()); + + bool B_flag = 1; + InitializeExternalFieldsOnGridUsingParser(Bx, By, Bz, lev, B_flag); for ( MFIter mfi(*Bx, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& tbx = mfi.tilebox(Bx_nodal_flag); const Box& tby = mfi.tilebox(By_nodal_flag); const Box& tbz = mfi.tilebox(Bz_nodal_flag); - // Bx + auto const& Bxfab = Bx->array(mfi); - auto const& lo = lbound(tbx); - auto const& hi = ubound(tbx); - amrex::Print() << " lo " << lo << " hi " << hi << "\n"; - auto const& Bx_IndexType = (*Bx).ixType(); - IntVect Bx_type(AMREX_D_DECL(0,0,0)); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - Bx_type[idim] = Bx_IndexType.nodeCentered(idim); - } - amrex::Print() << " ix type " << Bx_IndexType << "\n"; - amrex::Print() << " type : " << Bx_type << "\n"; - //ParserWrapper *Bx_parsewrap = new ParserWrapper(Bx_parser); -// amrex::Print() << " parsewrap " << Bx_parsewrap->m_parser << "\n"; -// amrex::Print() << " parse wrap " << Bx_wrap->m_parser << "\n"; - Real xx = 1.0; Real yy = 0.0; Real zz = 0.0; - Real g = Bx_wrap->m_parser(xx,yy,zz); - amrex::Print() << "g " << g << "\n"; - Real g2 = Bx_wrap->getField(xx,yy,zz); - amrex::Print() << "g2 " << g2 << "\n"; - amrex::ParallelFor (tbx, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - int xdim = 0; int ydim = 1; int zdim = 2; - - //Real fac_x = (1.0 - Bx_type[0]) * dx_lev[0]*0.5; - //Real x = i*dx_lev[xdim] + real_box.lo(xdim) + fac_x; - //Real fac_y = (1.0 - Bx_type[1]) * dx_lev[1]*0.5; - //Real y = j*dx_lev[ydim] + real_box.lo(ydim) + fac_y; - Real x = 0.0, y = 0.0, z = 0.0; - Bxfab(i,j,k) = Bx_wrap->getField(x,y,z); - // Bxfab(i,j,k) = 0.0; - - } - ); - - // for (int k = lo.z; k <= hi.z; ++k) { - // for (int j = lo.y; j <= hi.y; ++j) { - // for (int i = lo.x; i <= hi.x; ++i) { - // //std::vector f; - // //pp.getarr("Bx_external_grid_function(x,y,z)", f); - // //str_Bx_ext_grid_function.clear(); - // //for (auto const& s : f) { - // // str_Bx_ext_grid_function += s; - // //} - // //f.clear(); - // //WarpXParser const& Bx_parser = makeParser(str_Bx_ext_grid_function); - // // - // //GpuParser m_Bx_parser = Bx_parser; - - // //Real x,y,z; - // int xdim = 0; int ydim = 1; int zdim = 2; - // // - // Real fac_x = (1.0 - Bx_type[0]) * dx_lev[0]*0.5; - // Real x = i*dx_lev[xdim] + real_box.lo(xdim) + fac_x; - // Real fac_y = (1.0 - Bx_type[1]) * dx_lev[1]*0.5; - // Real y = j*dx_lev[ydim] + real_box.lo(ydim) + fac_y; - // Real z = 0.0; - // //Bxfab(i,j,k) = m_Bx_parser(x,y,z); - // //amrex::Print() << " facx " << fac_x << " facy " << fac_y << "\n"; - // //amrex::Print() << " Bx at " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << " x is " << x << " z is " << y << "\n"; - // amrex::Print() << " x " << x << " " << y << "\n"; - // //Real compare = 200*std::cosh(x/2.0) + 10*y; - // Real compare = 200*std::cos(x/2.0) + 10*y; - // amrex::Print() << " Bx at " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << " compare " << compare << "\n"; - // }}} + auto const& Byfab = By->array(mfi); + auto const& Bzfab = Bz->array(mfi); + + const auto lo = lbound(tbx); + const auto hi = ubound(tbx); + for (int k = lo.z; k <= hi.z; ++k) { + for (int j = lo.y; j <= hi.y; ++j) { + for (int i = lo.x; i <= hi.x; ++i) { + amrex::Print() << " Bx at " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << "\n"; + }}} // // By - // auto const& By_IndexType = (*By).ixType(); - // auto const& Byfab = By->array(mfi); - // auto const& lo_y = lbound(tby); - // auto const& hi_y = ubound(tby); - // for (int k = lo_y.z; k <= hi_y.z; ++k) { - // for (int j = lo_y.y; j <= hi_y.y; ++j) { - // for (int i = lo_y.x; i <= hi_y.x; ++i) { -// // Byfab(i,j,k) = B_external_grid[1]; - // Byfab(i,j,k) = 0; - // amrex::Print() << " By at " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; - // }}} - // + auto const& lo_y = lbound(tby); + auto const& hi_y = ubound(tby); + for (int k = lo_y.z; k <= hi_y.z; ++k) { + for (int j = lo_y.y; j <= hi_y.y; ++j) { + for (int i = lo_y.x; i <= hi_y.x; ++i) { + amrex::Print() << " By at " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; + }}} + // // Bz - // auto const& Bz_IndexType = (*Bz).ixType(); - // auto const& Bzfab = Bz->array(mfi); - // auto const& lo_z = lbound(tbz); - // auto const& hi_z = ubound(tbz); - // for (int k = lo_z.z; k <= hi_z.z; ++k) { - // for (int j = lo_z.y; j <= hi_z.y; ++j) { - // for (int i = lo_z.x; i <= hi_z.x; ++i) { - // //Bzfab(i,j,k) = B_external_grid[2]; - // Bzfab(i,j,k) = 0; - // amrex::Print() << " Bz at " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; - // }}} - // + auto const& lo_z = lbound(tbz); + auto const& hi_z = ubound(tbz); + for (int k = lo_z.z; k <= hi_z.z; ++k) { + for (int j = lo_z.y; j <= hi_z.y; ++j) { + for (int i = lo_z.x; i <= hi_z.x; ++i) { + amrex::Print() << " Bz at " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; + }}} + } } if (lev > 0) { for (int i = 0; i < 3; ++i) { current_cp[lev][i]->setVal(0.0); - if (B_ext_grid_s == "constant") { + if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") { Bfield_aux[lev][i]->setVal(B_external_grid[i]); Bfield_cp[lev][i]->setVal(B_external_grid[i]); } - else { - Bfield_aux[lev][i]->setVal(0.0); - Bfield_cp[lev][i]->setVal(0.0); + else if (B_ext_grid_s == "parse_b_ext_grid_function") { + + MultiFab *Bx_aux, *By_aux, *Bz_aux; + Bx_aux = Bfield_aux[lev][0].get(); + By_aux = Bfield_aux[lev][1].get(); + Bz_aux = Bfield_aux[lev][2].get(); + + bool B_flag = 1; + InitializeExternalFieldsOnGridUsingParser(Bx_aux, By_aux, + Bz_aux, lev, B_flag); + + MultiFab *Bx_cp, *By_cp, *Bz_cp; + Bx_cp = Bfield_cp[lev][0].get(); + By_cp = Bfield_cp[lev][1].get(); + Bz_cp = Bfield_cp[lev][2].get(); + + InitializeExternalFieldsOnGridUsingParser(Bx_cp, By_cp, + Bz_cp, lev, B_flag); + + for ( MFIter mfi(*Bx_aux, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& tbx = mfi.tilebox(Bx_nodal_flag); + const Box& tby = mfi.tilebox(By_nodal_flag); + const Box& tbz = mfi.tilebox(Bz_nodal_flag); + + auto const& Bxfab = Bx_aux->array(mfi); + auto const& Byfab = By_aux->array(mfi); + auto const& Bzfab = Bz_aux->array(mfi); + + const auto lo = lbound(tbx); + const auto hi = ubound(tbx); + for (int k = lo.z; k <= hi.z; ++k) { + for (int j = lo.y; j <= hi.y; ++j) { + for (int i = lo.x; i <= hi.x; ++i) { + amrex::Print() << " Bx at aux " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << "\n"; + }}} + const auto lo_y = lbound(tby); + const auto hi_y = ubound(tby); + for (int k = lo_y.z; k <= hi_y.z; ++k) { + for (int j = lo_y.y; j <= hi_y.y; ++j) { + for (int i = lo_y.x; i <= hi_y.x; ++i) { + amrex::Print() << " By at aux " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; + }}} + const auto lo_z = lbound(tbz); + const auto hi_z = ubound(tbz); + for (int k = lo_z.z; k <= hi_z.z; ++k) { + for (int j = lo_z.y; j <= hi_z.y; ++j) { + for (int i = lo_z.x; i <= hi_z.x; ++i) { + amrex::Print() << " Bz at aux " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; + }}} + } + + for ( MFIter mfi(*Bx_cp, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& tbx = mfi.tilebox(Bx_nodal_flag); + const Box& tby = mfi.tilebox(By_nodal_flag); + const Box& tbz = mfi.tilebox(Bz_nodal_flag); + + auto const& Bxfab = Bx_cp->array(mfi); + auto const& Byfab = By_cp->array(mfi); + auto const& Bzfab = Bz_cp->array(mfi); + + const auto lo = lbound(tbx); + const auto hi = ubound(tbx); + for (int k = lo.z; k <= hi.z; ++k) { + for (int j = lo.y; j <= hi.y; ++j) { + for (int i = lo.x; i <= hi.x; ++i) { + amrex::Print() << " Bx at cp " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << "\n"; + }}} + const auto lo_y = lbound(tby); + const auto hi_y = ubound(tby); + for (int k = lo_y.z; k <= hi_y.z; ++k) { + for (int j = lo_y.y; j <= hi_y.y; ++j) { + for (int i = lo_y.x; i <= hi_y.x; ++i) { + amrex::Print() << " By at cp " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; + }}} + const auto lo_z = lbound(tbz); + const auto hi_z = ubound(tbz); + for (int k = lo_z.z; k <= hi_z.z; ++k) { + for (int j = lo_z.y; j <= hi_z.y; ++j) { + for (int i = lo_z.x; i <= hi_z.x; ++i) { + amrex::Print() << " Bz at cp " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; + }}} + } + } - if (E_ext_grid_s == "constant") { + if (E_ext_grid_s == "constant" || E_ext_grid_s == " default") { Efield_aux[lev][i]->setVal(E_external_grid[i]); Efield_cp[lev][i]->setVal(E_external_grid[i]); } else { @@ -521,3 +544,116 @@ WarpX::InitLevelDataFFT (int lev, Real time) } #endif + + +void +WarpX::InitializeExternalFieldsOnGridUsingParser ( + MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, + const int lev, const bool B_flag) +{ + std::unique_ptr Bx_parsewrap; + std::unique_ptr By_parsewrap; + std::unique_ptr Bz_parsewrap; + + if (B_flag == 1) { + Bx_parsewrap.reset(new ParserWrapper + (makeParser(str_Bx_ext_grid_function))); + By_parsewrap.reset(new ParserWrapper + (makeParser(str_By_ext_grid_function))); + Bz_parsewrap.reset(new ParserWrapper + (makeParser(str_Bz_ext_grid_function))); + } else { + Bx_parsewrap.reset(new ParserWrapper + (makeParser(str_Bx_ext_grid_function))); + By_parsewrap.reset(new ParserWrapper + (makeParser(str_By_ext_grid_function))); + Bz_parsewrap.reset(new ParserWrapper + (makeParser(str_Bz_ext_grid_function))); + } + + ParserWrapper *xfield_wrap = Bx_parsewrap.get(); + ParserWrapper *yfield_wrap = By_parsewrap.get(); + ParserWrapper *zfield_wrap = Bz_parsewrap.get(); + + const auto dx_lev = geom[lev].CellSizeArray(); + const RealBox& real_box = geom[lev].ProbDomain(); + for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + IntVect x_nodal_flag, y_nodal_flag, z_nodal_flag; + if (B_flag == 1) { + x_nodal_flag = Bx_nodal_flag; + y_nodal_flag = By_nodal_flag; + z_nodal_flag = Bz_nodal_flag; + } else { + x_nodal_flag = Ex_nodal_flag; + y_nodal_flag = Ey_nodal_flag; + z_nodal_flag = Ez_nodal_flag; + } + const Box& tbx = mfi.tilebox(Bx_nodal_flag); + const Box& tby = mfi.tilebox(By_nodal_flag); + const Box& tbz = mfi.tilebox(Bz_nodal_flag); + + auto const& mfxfab = mfx->array(mfi); + auto const& mfyfab = mfy->array(mfi); + auto const& mfzfab = mfz->array(mfi); + + auto const& mfx_IndexType = (*mfx).ixType(); + auto const& mfy_IndexType = (*mfy).ixType(); + auto const& mfz_IndexType = (*mfz).ixType(); + + IntVect mfx_type(AMREX_D_DECL(0,0,0)); + IntVect mfy_type(AMREX_D_DECL(0,0,0)); + IntVect mfz_type(AMREX_D_DECL(0,0,0)); + + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + mfx_type[idim] = mfx_IndexType.nodeCentered(idim); + mfy_type[idim] = mfy_IndexType.nodeCentered(idim); + mfz_type[idim] = mfz_IndexType.nodeCentered(idim); + } + + amrex::ParallelFor (tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Real fac_x = (1.0 - mfx_type[0]) * dx_lev[0]*0.5; + Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; +#if (AMREX_SPACEDIM==2) + Real z = 0.0; +#elif (AMREX_SPACEDIM==3) + Real fac_z = (1.0 - mfx_type[2]) * dx_lev[2]*0.5; + Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; +#endif + mfxfab(i,j,k) = xfield_wrap->getField(x,y,z); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Real fac_x = (1.0 - mfy_type[0]) * dx_lev[0]*0.5; + Real fac_y = (1.0 - mfy_type[1]) * dx_lev[1]*0.5; + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; +#if (AMREX_SPACEDIM==2) + Real z = 0.0; +#elif (AMREX_SPACEDIM==3) + Real fac_z = (1.0 - mfy_type[2]) * dx_lev[2]*0.5; + Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; +#endif + mfyfab(i,j,k) = yfield_wrap->getField(x,y,z); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Real fac_x = (1.0 - mfz_type[0]) * dx_lev[0]*0.5; + Real fac_y = (1.0 - mfz_type[1]) * dx_lev[1]*0.5; + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; +#if (AMREX_SPACEDIM==2) + Real z = 0.0; +#elif (AMREX_SPACEDIM==3) + Real fac_z = (1.0 - mfz_type[2]) * dx_lev[2]*0.5; + Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; +#endif + mfzfab(i,j,k) = zfield_wrap->getField(x,y,z); + }, + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 + ); + + } + +} diff --git a/Source/WarpX.H b/Source/WarpX.H index 9ded68f82..9f4582092 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -45,6 +45,27 @@ enum struct PatchType : int coarse }; +struct ParserWrapper + : public amrex::Gpu::Managed +{ + ParserWrapper (WarpXParser const& a_parser) noexcept + : m_parser(a_parser) {} + + ~ParserWrapper() { + m_parser.clear(); + } + + AMREX_GPU_HOST_DEVICE + amrex::Real + getField (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept + { + return m_parser(x,y,z); + } + + GpuParser m_parser; +}; + + class WarpX : public amrex::AmrCore { @@ -321,6 +342,12 @@ public: // Making this function public to allow the use of GPU launch // to initialize E and B fields using parser. void InitLevelData (int lev, amrex::Real time); + + void InitializeExternalFieldsOnGridUsingParser ( + amrex::MultiFab* mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, +// ParserWrapper* xField_wrap, ParserWrapper* yField_wrap, +// ParserWrapper* zField_wrap, + const int lev, const bool B_flag); protected: //! Tagging cells for refinement @@ -659,25 +686,5 @@ private: int insitu_pin_mesh; }; -struct ParserWrapper - : public amrex::Gpu::Managed -{ - ParserWrapper (WarpXParser const& a_parser) noexcept - : m_parser(a_parser) {} - - AMREX_GPU_HOST_DEVICE - amrex::Real - getField (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept - { - return m_parser(x,y,z); - } - - GpuParser m_parser; - - ~ParserWrapper() { - m_parser.clear(); - } - -}; #endif diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index bc23e0370..c6cf03b05 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -310,9 +310,6 @@ WarpX::ReadParameters () pp.queryarr("B_external_particle", B_external_particle); pp.queryarr("E_external_particle", E_external_particle); - pp.queryarr("E_external_grid", E_external_grid); - pp.queryarr("B_external_grid", B_external_grid); - pp.query("do_moving_window", do_moving_window); if (do_moving_window) { -- cgit v1.2.3 From 1ef13c63a0b83b310c72221c8d9b09c29039ddaf Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 25 Nov 2019 16:53:09 -0800 Subject: Extend initialization using parser to _cp and _aux --- Source/Initialization/WarpXInitData.cpp | 164 ++++++++++++++++++++++++++++++-- 1 file changed, 158 insertions(+), 6 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 69c8d8efd..cb9f92a07 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -386,6 +386,77 @@ WarpX::InitLevelData (int lev, Real time) } } + if (E_ext_grid_s == "parse_e_ext_grid_function") { + + std::vector f; + // Parse Ex_external_grid_function + pp.getarr("Ex_external_grid_function(x,y,z)", f); + str_Ex_ext_grid_function.clear(); + for (auto const& s : f) { + str_Ex_ext_grid_function += s; + } + f.clear(); + + // Parse Ey_external_grid_function + pp.getarr("Ey_external_grid_function(x,y,z)", f); + str_Ey_ext_grid_function.clear(); + for (auto const& s : f) { + str_Ey_ext_grid_function += s; + } + f.clear(); + + // Parse Ez_external_grid_function + pp.getarr("Ez_external_grid_function(x,y,z)", f); + str_Ez_ext_grid_function.clear(); + for (auto const& s : f) { + str_Ez_ext_grid_function += s; + } + f.clear(); + + // Initialize Efield_fp with external function + MultiFab *Ex, *Ey, *Ez; + Ex = Efield_fp[lev][0].get(); + Ey = Efield_fp[lev][1].get(); + Ez = Efield_fp[lev][2].get(); + + bool B_flag = 0; + InitializeExternalFieldsOnGridUsingParser(Ex, Ey, Ez, lev, B_flag); + + for ( MFIter mfi(*Ex, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& tbx = mfi.tilebox(Ex_nodal_flag); + const Box& tby = mfi.tilebox(Ey_nodal_flag); + const Box& tbz = mfi.tilebox(Ez_nodal_flag); + + auto const& Exfab = Ex->array(mfi); + auto const& Eyfab = Ey->array(mfi); + auto const& Ezfab = Ez->array(mfi); + + const auto lo = lbound(tbx); + const auto hi = ubound(tbx); + for (int k = lo.z; k <= hi.z; ++k) { + for (int j = lo.y; j <= hi.y; ++j) { + for (int i = lo.x; i <= hi.x; ++i) { + amrex::Print() << " Ex at " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; + }}} + auto const& lo_y = lbound(tby); + auto const& hi_y = ubound(tby); + for (int k = lo_y.z; k <= hi_y.z; ++k) { + for (int j = lo_y.y; j <= hi_y.y; ++j) { + for (int i = lo_y.x; i <= hi_y.x; ++i) { + amrex::Print() << " Ey at " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; + }}} + auto const& lo_z = lbound(tbz); + auto const& hi_z = ubound(tbz); + for (int k = lo_z.z; k <= hi_z.z; ++k) { + for (int j = lo_z.y; j <= hi_z.y; ++j) { + for (int i = lo_z.x; i <= hi_z.x; ++i) { + amrex::Print() << " Ez at " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; + }}} + } + + } + if (lev > 0) { for (int i = 0; i < 3; ++i) { current_cp[lev][i]->setVal(0.0); @@ -482,9 +553,90 @@ WarpX::InitLevelData (int lev, Real time) if (E_ext_grid_s == "constant" || E_ext_grid_s == " default") { Efield_aux[lev][i]->setVal(E_external_grid[i]); Efield_cp[lev][i]->setVal(E_external_grid[i]); - } else { - Efield_aux[lev][i]->setVal(0.0); - Efield_cp[lev][i]->setVal(0.0); + } else if (E_ext_grid_s == "parse_e_ext_grid_function") { + + MultiFab *Ex_aux, *Ey_aux, *Ez_aux; + Ex_aux = Efield_aux[lev][0].get(); + Ey_aux = Efield_aux[lev][1].get(); + Ez_aux = Efield_aux[lev][2].get(); + + bool B_flag = 0; + InitializeExternalFieldsOnGridUsingParser(Ex_aux, Ey_aux, + Ez_aux, lev, B_flag); + + MultiFab *Ex_cp, *Ey_cp, *Ez_cp; + Ex_cp = Efield_cp[lev][0].get(); + Ey_cp = Efield_cp[lev][1].get(); + Ez_cp = Efield_cp[lev][2].get(); + + InitializeExternalFieldsOnGridUsingParser(Ex_cp, Ey_cp, + Ez_cp, lev, B_flag); + + for (MFIter mfi(*Ex_aux, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& tbx = mfi.tilebox(Ex_nodal_flag); + const Box& tby = mfi.tilebox(Ey_nodal_flag); + const Box& tbz = mfi.tilebox(Ez_nodal_flag); + + auto const& Exfab = Ex_aux->array(mfi); + auto const& Eyfab = Ey_aux->array(mfi); + auto const& Ezfab = Ez_aux->array(mfi); + + const auto lo = lbound(tbx); + const auto hi = ubound(tbx); + for (int k = lo.z; k <= hi.z; ++k) { + for (int j = lo.y; k <= hi.y; ++j) { + for (int i = lo.x; i <= hi.x; ++i) { + amrex::Print() << " Ex at aux " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; + }}} + const auto lo_y = lbound(tby); + const auto hi_y = ubound(tby); + for (int k = lo_y.z; k <= hi_y.z; ++k) { + for (int j = lo_y.y; k <= hi_y.y; ++j) { + for (int i = lo_y.x; i <= hi_y.x; ++i) { + amrex::Print() << " Ey at aux " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; + }}} + const auto lo_z = lbound(tbz); + const auto hi_z = ubound(tbz); + for (int k = lo_z.z; k <= hi_z.z; ++k) { + for (int j = lo_z.y; k <= hi_z.y; ++j) { + for (int i = lo_z.x; i <= hi_z.x; ++i) { + amrex::Print() << " Ez at aux " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; + }}} + } + + for (MFIter mfi(*Ex_cp, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& tbx = mfi.tilebox(Ex_nodal_flag); + const Box& tby = mfi.tilebox(Ey_nodal_flag); + const Box& tbz = mfi.tilebox(Ez_nodal_flag); + + auto const& Exfab = Ex_cp->array(mfi); + auto const& Eyfab = Ey_cp->array(mfi); + auto const& Ezfab = Ez_cp->array(mfi); + + const auto lo = lbound(tbx); + const auto hi = ubound(tbx); + for (int k = lo.z; k <= hi.z; ++k) { + for (int j = lo.y; k <= hi.y; ++j) { + for (int i = lo.x; i <= hi.x; ++i) { + amrex::Print() << " Ex at cp " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; + }}} + const auto lo_y = lbound(tby); + const auto hi_y = ubound(tby); + for (int k = lo_y.z; k <= hi_y.z; ++k) { + for (int j = lo_y.y; k <= hi_y.y; ++j) { + for (int i = lo_y.x; i <= hi_y.x; ++i) { + amrex::Print() << " Ey at cp " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; + }}} + const auto lo_z = lbound(tbz); + const auto hi_z = ubound(tbz); + for (int k = lo_z.z; k <= hi_z.z; ++k) { + for (int j = lo_z.y; k <= hi_z.y; ++j) { + for (int i = lo_z.x; i <= hi_z.x; ++i) { + amrex::Print() << " Ez at cp " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; + }}} + } } } } @@ -589,9 +741,9 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( y_nodal_flag = Ey_nodal_flag; z_nodal_flag = Ez_nodal_flag; } - const Box& tbx = mfi.tilebox(Bx_nodal_flag); - const Box& tby = mfi.tilebox(By_nodal_flag); - const Box& tbz = mfi.tilebox(Bz_nodal_flag); + const Box& tbx = mfi.tilebox(x_nodal_flag); + const Box& tby = mfi.tilebox(y_nodal_flag); + const Box& tbz = mfi.tilebox(z_nodal_flag); auto const& mfxfab = mfx->array(mfi); auto const& mfyfab = mfy->array(mfi); -- cgit v1.2.3 From 959540fb3839db32b3f117a511d989334d750f25 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 25 Nov 2019 17:39:08 -0800 Subject: Fixing bug in for loop wherein Ex Ey Ez are printed for debugging purposes. --- Source/Initialization/WarpXInitData.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index cb9f92a07..a4854586c 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -585,21 +585,21 @@ WarpX::InitLevelData (int lev, Real time) const auto lo = lbound(tbx); const auto hi = ubound(tbx); for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; k <= hi.y; ++j) { + for (int j = lo.y; j <= hi.y; ++j) { for (int i = lo.x; i <= hi.x; ++i) { amrex::Print() << " Ex at aux " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; }}} const auto lo_y = lbound(tby); const auto hi_y = ubound(tby); for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; k <= hi_y.y; ++j) { + for (int j = lo_y.y; j <= hi_y.y; ++j) { for (int i = lo_y.x; i <= hi_y.x; ++i) { amrex::Print() << " Ey at aux " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; }}} const auto lo_z = lbound(tbz); const auto hi_z = ubound(tbz); for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; k <= hi_z.y; ++j) { + for (int j = lo_z.y; j <= hi_z.y; ++j) { for (int i = lo_z.x; i <= hi_z.x; ++i) { amrex::Print() << " Ez at aux " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; }}} @@ -618,21 +618,21 @@ WarpX::InitLevelData (int lev, Real time) const auto lo = lbound(tbx); const auto hi = ubound(tbx); for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; k <= hi.y; ++j) { + for (int j = lo.y; j <= hi.y; ++j) { for (int i = lo.x; i <= hi.x; ++i) { amrex::Print() << " Ex at cp " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; }}} const auto lo_y = lbound(tby); const auto hi_y = ubound(tby); for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; k <= hi_y.y; ++j) { + for (int j = lo_y.y; j <= hi_y.y; ++j) { for (int i = lo_y.x; i <= hi_y.x; ++i) { amrex::Print() << " Ey at cp " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; }}} const auto lo_z = lbound(tbz); const auto hi_z = ubound(tbz); for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; k <= hi_z.y; ++j) { + for (int j = lo_z.y; j <= hi_z.y; ++j) { for (int i = lo_z.x; i <= hi_z.x; ++i) { amrex::Print() << " Ez at cp " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; }}} -- cgit v1.2.3 From aec2314d9880bd80c09231d978c076f7aab929f7 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 26 Nov 2019 15:54:48 -0800 Subject: cleaning and adding comments --- Source/Initialization/WarpXInitData.cpp | 306 ++++++++------------------------ 1 file changed, 73 insertions(+), 233 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index a4854586c..780b050a6 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -264,7 +264,30 @@ WarpXParser makeParser (std::string const& parse_function) - +/* \brief + * This function initializes E, B, rho, and F, at all the levels + * of the multifab. rho and F are initialized with 0. + * The E and B fields are initialized using user-defined inputs. + * The initialization type is set using "B_ext_grid_init_style" + * and "E_ext_grid_init_style". The initialization style is set to "default" + * if not explicitly defined by the user, and the E and B fields are + * initialized with E_external_grid and B_external_grid, respectively, each with + * a default value of 0. + * If the initialization type for the E and B field is "constant", + * then, the E and B fields at all the levels are initialized with + * user-defined values for E_external_grid and B_external_grid. + * If the initialization type for B-field is set to + * "parse_B_ext_grid_function", then, the parser is used to read + * Bx_external_grid_function(x,y,z), By_external_grid_function(x,y,z), + * and Bz_external_grid_function(x,y,z). + * Similarly, if the E-field initialization type is set to + * "parse_E_ext_grid_function", then, the parser is used to read + * Ex_external_grid_function(x,y,z), Ey_external_grid_function(x,y,z), + * and Ex_external_grid_function(x,y,z). The parser for the E and B + * initialization assumes that the function has three independent + * variables, at max, namely, x, y, z. However, any number of constants + * can be used in the function used to define the E and B fields on the grid. + */ void WarpX::InitLevelData (int lev, Real time) @@ -285,14 +308,12 @@ WarpX::InitLevelData (int lev, Real time) B_ext_grid_s.end(), B_ext_grid_s.begin(), ::tolower); - amrex::Print() << " B_init style " << B_ext_grid_s << "\n"; pp.query("E_ext_grid_init_style", E_ext_grid_s); std::transform(E_ext_grid_s.begin(), E_ext_grid_s.end(), E_ext_grid_s.begin(), ::tolower); - amrex::Print() << " E_init style " << E_ext_grid_s << "\n"; // if the input string is "constant", the values for the // external grid must be provided in the input. @@ -347,43 +368,6 @@ WarpX::InitLevelData (int lev, Real time) bool B_flag = 1; InitializeExternalFieldsOnGridUsingParser(Bx, By, Bz, lev, B_flag); - - for ( MFIter mfi(*Bx, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& tbx = mfi.tilebox(Bx_nodal_flag); - const Box& tby = mfi.tilebox(By_nodal_flag); - const Box& tbz = mfi.tilebox(Bz_nodal_flag); - - auto const& Bxfab = Bx->array(mfi); - auto const& Byfab = By->array(mfi); - auto const& Bzfab = Bz->array(mfi); - - const auto lo = lbound(tbx); - const auto hi = ubound(tbx); - for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; j <= hi.y; ++j) { - for (int i = lo.x; i <= hi.x; ++i) { - amrex::Print() << " Bx at " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << "\n"; - }}} - // // By - auto const& lo_y = lbound(tby); - auto const& hi_y = ubound(tby); - for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; j <= hi_y.y; ++j) { - for (int i = lo_y.x; i <= hi_y.x; ++i) { - amrex::Print() << " By at " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; - }}} - - // // Bz - auto const& lo_z = lbound(tbz); - auto const& hi_z = ubound(tbz); - for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; j <= hi_z.y; ++j) { - for (int i = lo_z.x; i <= hi_z.x; ++i) { - amrex::Print() << " Bz at " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; - }}} - - } } if (E_ext_grid_s == "parse_e_ext_grid_function") { @@ -422,39 +406,6 @@ WarpX::InitLevelData (int lev, Real time) bool B_flag = 0; InitializeExternalFieldsOnGridUsingParser(Ex, Ey, Ez, lev, B_flag); - for ( MFIter mfi(*Ex, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& tbx = mfi.tilebox(Ex_nodal_flag); - const Box& tby = mfi.tilebox(Ey_nodal_flag); - const Box& tbz = mfi.tilebox(Ez_nodal_flag); - - auto const& Exfab = Ex->array(mfi); - auto const& Eyfab = Ey->array(mfi); - auto const& Ezfab = Ez->array(mfi); - - const auto lo = lbound(tbx); - const auto hi = ubound(tbx); - for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; j <= hi.y; ++j) { - for (int i = lo.x; i <= hi.x; ++i) { - amrex::Print() << " Ex at " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; - }}} - auto const& lo_y = lbound(tby); - auto const& hi_y = ubound(tby); - for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; j <= hi_y.y; ++j) { - for (int i = lo_y.x; i <= hi_y.x; ++i) { - amrex::Print() << " Ey at " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; - }}} - auto const& lo_z = lbound(tbz); - auto const& hi_z = ubound(tbz); - for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; j <= hi_z.y; ++j) { - for (int i = lo_z.x; i <= hi_z.x; ++i) { - amrex::Print() << " Ez at " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; - }}} - } - } if (lev > 0) { @@ -471,6 +422,8 @@ WarpX::InitLevelData (int lev, Real time) By_aux = Bfield_aux[lev][1].get(); Bz_aux = Bfield_aux[lev][2].get(); + // Setting b_flag to 1 since we are initializing + // B_external on the grid. bool B_flag = 1; InitializeExternalFieldsOnGridUsingParser(Bx_aux, By_aux, Bz_aux, lev, B_flag); @@ -483,72 +436,6 @@ WarpX::InitLevelData (int lev, Real time) InitializeExternalFieldsOnGridUsingParser(Bx_cp, By_cp, Bz_cp, lev, B_flag); - for ( MFIter mfi(*Bx_aux, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& tbx = mfi.tilebox(Bx_nodal_flag); - const Box& tby = mfi.tilebox(By_nodal_flag); - const Box& tbz = mfi.tilebox(Bz_nodal_flag); - - auto const& Bxfab = Bx_aux->array(mfi); - auto const& Byfab = By_aux->array(mfi); - auto const& Bzfab = Bz_aux->array(mfi); - - const auto lo = lbound(tbx); - const auto hi = ubound(tbx); - for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; j <= hi.y; ++j) { - for (int i = lo.x; i <= hi.x; ++i) { - amrex::Print() << " Bx at aux " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << "\n"; - }}} - const auto lo_y = lbound(tby); - const auto hi_y = ubound(tby); - for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; j <= hi_y.y; ++j) { - for (int i = lo_y.x; i <= hi_y.x; ++i) { - amrex::Print() << " By at aux " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; - }}} - const auto lo_z = lbound(tbz); - const auto hi_z = ubound(tbz); - for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; j <= hi_z.y; ++j) { - for (int i = lo_z.x; i <= hi_z.x; ++i) { - amrex::Print() << " Bz at aux " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; - }}} - } - - for ( MFIter mfi(*Bx_cp, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& tbx = mfi.tilebox(Bx_nodal_flag); - const Box& tby = mfi.tilebox(By_nodal_flag); - const Box& tbz = mfi.tilebox(Bz_nodal_flag); - - auto const& Bxfab = Bx_cp->array(mfi); - auto const& Byfab = By_cp->array(mfi); - auto const& Bzfab = Bz_cp->array(mfi); - - const auto lo = lbound(tbx); - const auto hi = ubound(tbx); - for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; j <= hi.y; ++j) { - for (int i = lo.x; i <= hi.x; ++i) { - amrex::Print() << " Bx at cp " << i << " " << j << " " << k << " is " << Bxfab(i,j,k) << "\n"; - }}} - const auto lo_y = lbound(tby); - const auto hi_y = ubound(tby); - for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; j <= hi_y.y; ++j) { - for (int i = lo_y.x; i <= hi_y.x; ++i) { - amrex::Print() << " By at cp " << i << " " << j << " " << k << " is " << Byfab(i,j,k) << "\n"; - }}} - const auto lo_z = lbound(tbz); - const auto hi_z = ubound(tbz); - for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; j <= hi_z.y; ++j) { - for (int i = lo_z.x; i <= hi_z.x; ++i) { - amrex::Print() << " Bz at cp " << i << " " << j << " " << k << " is " << Bzfab(i,j,k) << "\n"; - }}} - } - } if (E_ext_grid_s == "constant" || E_ext_grid_s == " default") { Efield_aux[lev][i]->setVal(E_external_grid[i]); @@ -559,7 +446,8 @@ WarpX::InitLevelData (int lev, Real time) Ex_aux = Efield_aux[lev][0].get(); Ey_aux = Efield_aux[lev][1].get(); Ez_aux = Efield_aux[lev][2].get(); - + // Setting b_flag to zero since we are initializing + // E_external on the grid here. bool B_flag = 0; InitializeExternalFieldsOnGridUsingParser(Ex_aux, Ey_aux, Ez_aux, lev, B_flag); @@ -572,71 +460,6 @@ WarpX::InitLevelData (int lev, Real time) InitializeExternalFieldsOnGridUsingParser(Ex_cp, Ey_cp, Ez_cp, lev, B_flag); - for (MFIter mfi(*Ex_aux, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& tbx = mfi.tilebox(Ex_nodal_flag); - const Box& tby = mfi.tilebox(Ey_nodal_flag); - const Box& tbz = mfi.tilebox(Ez_nodal_flag); - - auto const& Exfab = Ex_aux->array(mfi); - auto const& Eyfab = Ey_aux->array(mfi); - auto const& Ezfab = Ez_aux->array(mfi); - - const auto lo = lbound(tbx); - const auto hi = ubound(tbx); - for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; j <= hi.y; ++j) { - for (int i = lo.x; i <= hi.x; ++i) { - amrex::Print() << " Ex at aux " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; - }}} - const auto lo_y = lbound(tby); - const auto hi_y = ubound(tby); - for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; j <= hi_y.y; ++j) { - for (int i = lo_y.x; i <= hi_y.x; ++i) { - amrex::Print() << " Ey at aux " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; - }}} - const auto lo_z = lbound(tbz); - const auto hi_z = ubound(tbz); - for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; j <= hi_z.y; ++j) { - for (int i = lo_z.x; i <= hi_z.x; ++i) { - amrex::Print() << " Ez at aux " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; - }}} - } - - for (MFIter mfi(*Ex_cp, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& tbx = mfi.tilebox(Ex_nodal_flag); - const Box& tby = mfi.tilebox(Ey_nodal_flag); - const Box& tbz = mfi.tilebox(Ez_nodal_flag); - - auto const& Exfab = Ex_cp->array(mfi); - auto const& Eyfab = Ey_cp->array(mfi); - auto const& Ezfab = Ez_cp->array(mfi); - - const auto lo = lbound(tbx); - const auto hi = ubound(tbx); - for (int k = lo.z; k <= hi.z; ++k) { - for (int j = lo.y; j <= hi.y; ++j) { - for (int i = lo.x; i <= hi.x; ++i) { - amrex::Print() << " Ex at cp " << i << " " << j << " " << k << " is " << Exfab(i,j,k) << "\n"; - }}} - const auto lo_y = lbound(tby); - const auto hi_y = ubound(tby); - for (int k = lo_y.z; k <= hi_y.z; ++k) { - for (int j = lo_y.y; j <= hi_y.y; ++j) { - for (int i = lo_y.x; i <= hi_y.x; ++i) { - amrex::Print() << " Ey at cp " << i << " " << j << " " << k << " is " << Eyfab(i,j,k) << "\n"; - }}} - const auto lo_z = lbound(tbz); - const auto hi_z = ubound(tbz); - for (int k = lo_z.z; k <= hi_z.z; ++k) { - for (int j = lo_z.y; j <= hi_z.y; ++j) { - for (int i = lo_z.x; i <= hi_z.x; ++i) { - amrex::Print() << " Ez at cp " << i << " " << j << " " << k << " is " << Ezfab(i,j,k) << "\n"; - }}} - } } } } @@ -697,35 +520,44 @@ WarpX::InitLevelDataFFT (int lev, Real time) #endif +/* \brief + * This function initializes the E and B fields on each level + * using the parser and the user-defined function for the external fields. + * Depending on the bool value of the B_flag, the subroutine will parse + * the Bx_/By_/Bz_external_grid_function (if B_flag==1) + * or parse the Ex_/Ey_/Ez_external_grid_function (if B_flag==0). + * Then, the B or E multifab is initialized based on the (x,y,z) position + * on the staggered yee-grid or cell-centered grid. + */ void WarpX::InitializeExternalFieldsOnGridUsingParser ( MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, const int lev, const bool B_flag) { - std::unique_ptr Bx_parsewrap; - std::unique_ptr By_parsewrap; - std::unique_ptr Bz_parsewrap; + std::unique_ptr xfield_parsewrap; + std::unique_ptr yfield_parsewrap; + std::unique_ptr zfield_parsewrap; if (B_flag == 1) { - Bx_parsewrap.reset(new ParserWrapper - (makeParser(str_Bx_ext_grid_function))); - By_parsewrap.reset(new ParserWrapper - (makeParser(str_By_ext_grid_function))); - Bz_parsewrap.reset(new ParserWrapper - (makeParser(str_Bz_ext_grid_function))); + xfield_parsewrap.reset(new ParserWrapper + (makeParser(str_Bx_ext_grid_function))); + yfield_parsewrap.reset(new ParserWrapper + (makeParser(str_By_ext_grid_function))); + zfield_parsewrap.reset(new ParserWrapper + (makeParser(str_Bz_ext_grid_function))); } else { - Bx_parsewrap.reset(new ParserWrapper - (makeParser(str_Bx_ext_grid_function))); - By_parsewrap.reset(new ParserWrapper - (makeParser(str_By_ext_grid_function))); - Bz_parsewrap.reset(new ParserWrapper - (makeParser(str_Bz_ext_grid_function))); + xfield_parsewrap.reset(new ParserWrapper + (makeParser(str_Ex_ext_grid_function))); + yfield_parsewrap.reset(new ParserWrapper + (makeParser(str_Ey_ext_grid_function))); + zfield_parsewrap.reset(new ParserWrapper + (makeParser(str_Ez_ext_grid_function))); } - ParserWrapper *xfield_wrap = Bx_parsewrap.get(); - ParserWrapper *yfield_wrap = By_parsewrap.get(); - ParserWrapper *zfield_wrap = Bz_parsewrap.get(); + ParserWrapper *xfield_wrap = xfield_parsewrap.get(); + ParserWrapper *yfield_wrap = yfield_parsewrap.get(); + ParserWrapper *zfield_wrap = zfield_parsewrap.get(); const auto dx_lev = geom[lev].CellSizeArray(); const RealBox& real_box = geom[lev].ProbDomain(); @@ -753,6 +585,8 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( auto const& mfy_IndexType = (*mfy).ixType(); auto const& mfz_IndexType = (*mfz).ixType(); + // Initialize IntVect based on the index type of multiFab + // 0 if cell-centered, 1 if node-centered. IntVect mfx_type(AMREX_D_DECL(0,0,0)); IntVect mfy_type(AMREX_D_DECL(0,0,0)); IntVect mfz_type(AMREX_D_DECL(0,0,0)); @@ -764,18 +598,22 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( } amrex::ParallelFor (tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Real fac_x = (1.0 - mfx_type[0]) * dx_lev[0]*0.5; - Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; - Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; - Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + // Shift required in the x-, y-, or z- position + // depending on the index type of the multifab + Real fac_x = (1.0 - mfx_type[0]) * dx_lev[0]*0.5; + Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) - Real z = 0.0; -#elif (AMREX_SPACEDIM==3) - Real fac_z = (1.0 - mfx_type[2]) * dx_lev[2]*0.5; - Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; + Real z = 0.0; +#else + Real fac_z = (1.0 - mfx_type[2]) * dx_lev[2]*0.5; + Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif - mfxfab(i,j,k) = xfield_wrap->getField(x,y,z); + // Initialize the x-component of the field. + mfxfab(i,j,k) = xfield_wrap->getField(x,y,z); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { Real fac_x = (1.0 - mfy_type[0]) * dx_lev[0]*0.5; @@ -788,6 +626,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( Real fac_z = (1.0 - mfy_type[2]) * dx_lev[2]*0.5; Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif + // Initialize the y-component of the field. mfyfab(i,j,k) = yfield_wrap->getField(x,y,z); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { @@ -801,6 +640,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( Real fac_z = (1.0 - mfz_type[2]) * dx_lev[2]*0.5; Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif + // Initialize the z-component of the field. mfzfab(i,j,k) = zfield_wrap->getField(x,y,z); }, amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 -- cgit v1.2.3 From dca3cf61c578630078e3a07097f7660a2a1cd696 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 26 Nov 2019 17:03:56 -0800 Subject: addressing EOL whitespace error --- Docs/source/running_cpp/parameters.rst | 28 ++++---- Source/Initialization/WarpXInitData.cpp | 110 ++++++++++++++++---------------- Source/WarpX.H | 6 +- 3 files changed, 72 insertions(+), 72 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 51df27ea2..a445f7156 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -632,44 +632,44 @@ Laser initialization so that it contains at least ``mirror_z_npoints``. * ``warpx.B_ext_grid_init_style`` (string) optional (default is "default") - This parameter determines the type of initialization for the external + This parameter determines the type of initialization for the external magnetic field. The "default" style initializes the external magnetic field (Bx,By,Bz) to (0.0, 0.0, 0.0). - The string can be set to "constant" if a constant magnetic field is - required to be set at initialization. If set to "constant", then an - array for ``warpx.B_external_grid`` must be specified. + The string can be set to "constant" if a constant magnetic field is + required to be set at initialization. If set to "constant", then an + array for ``warpx.B_external_grid`` must be specified. If set to ``parse_B_ext_grid_function``, then a mathematical expression can - be used to initialize the external magnetic field on the grid. It + be used to initialize the external magnetic field on the grid. It required additional parameters in the input file, namely, ``warpx.Bx_external_grid_function(x,y,z)``, ``warpx.By_external_grid_function(x,y,z)``, ``warpx.Bz_external_grid_function(x,y,z)`` can be used to initialize the external magnetic field for each of the three components on the grid. Constants required in the expression can be set using ``my_constants``. - For example, if ``warpx.Bx_external_grid_function(x,y,z)=Bo*x + delta*(y + z)`` + For example, if ``warpx.Bx_external_grid_function(x,y,z)=Bo*x + delta*(y + z)`` then the constants `Bo` and `delta` required in the above equation can be set using ``my_constants.Bo=`` and ``my_constants.delta=`` in the - input file. + input file. * ``warpx.E_Ext_grid_init_style`` (string) optional (default is "default") - This parameter determines the type of initialization for the external + This parameter determines the type of initialization for the external electric field. The "default" style initializes the external electric field (Ex,Ey,Ez) to (0.0, 0.0, 0.0). - The string can be set to "constant" if a constant electric field is - required to be set at initialization. If set to "constant", then an - array for ``warpx.E_external_grid`` must be specified. + The string can be set to "constant" if a constant electric field is + required to be set at initialization. If set to "constant", then an + array for ``warpx.E_external_grid`` must be specified. If set to ``parse_E_ext_grid_function``, then a mathematical expression can - be used to initialize the external magnetic field on the grid. It + be used to initialize the external magnetic field on the grid. It required additional parameters in the input file, namely, ``warpx.Ex_external_grid_function(x,y,z)``, ``warpx.Ey_external_grid_function(x,y,z)``, ``warpx.Ez_external_grid_function(x,y,z)`` can be used to initialize the external magnetic field for each of the three components on the grid. Constants required in the expression can be set using ``my_constants``. - For example, if ``warpx.Ex_external_grid_function(x,y,z)=Eo*x + delta*(y + z)`` + For example, if ``warpx.Ex_external_grid_function(x,y,z)=Eo*x + delta*(y + z)`` then the constants `Bo` and `delta` required in the above equation can be set using ``my_constants.Eo=`` and ``my_constants.delta=`` in the - input file. + input file. * ``warpx.E_external_grid`` & ``warpx.B_external_grid`` (list of `int`) required when ``warpx.B_ext_grid_init_style="parse_B_ext_grid_function"`` diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 780b050a6..c70b7263e 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -265,18 +265,18 @@ WarpXParser makeParser (std::string const& parse_function) /* \brief - * This function initializes E, B, rho, and F, at all the levels + * This function initializes E, B, rho, and F, at all the levels * of the multifab. rho and F are initialized with 0. * The E and B fields are initialized using user-defined inputs. - * The initialization type is set using "B_ext_grid_init_style" + * The initialization type is set using "B_ext_grid_init_style" * and "E_ext_grid_init_style". The initialization style is set to "default" - * if not explicitly defined by the user, and the E and B fields are - * initialized with E_external_grid and B_external_grid, respectively, each with - * a default value of 0. + * if not explicitly defined by the user, and the E and B fields are + * initialized with E_external_grid and B_external_grid, respectively, each with + * a default value of 0. * If the initialization type for the E and B field is "constant", - * then, the E and B fields at all the levels are initialized with - * user-defined values for E_external_grid and B_external_grid. - * If the initialization type for B-field is set to + * then, the E and B fields at all the levels are initialized with + * user-defined values for E_external_grid and B_external_grid. + * If the initialization type for B-field is set to * "parse_B_ext_grid_function", then, the parser is used to read * Bx_external_grid_function(x,y,z), By_external_grid_function(x,y,z), * and Bz_external_grid_function(x,y,z). @@ -286,8 +286,8 @@ WarpXParser makeParser (std::string const& parse_function) * and Ex_external_grid_function(x,y,z). The parser for the E and B * initialization assumes that the function has three independent * variables, at max, namely, x, y, z. However, any number of constants - * can be used in the function used to define the E and B fields on the grid. - */ + * can be used in the function used to define the E and B fields on the grid. + */ void WarpX::InitLevelData (int lev, Real time) @@ -298,11 +298,11 @@ WarpX::InitLevelData (int lev, Real time) std::string B_ext_grid_s; std::string E_ext_grid_s; // default values of E_external_grid and B_external_grid - // are used to set the E and B field when "constant" or - // "parser" is not explicitly used in the input. + // are used to set the E and B field when "constant" or + // "parser" is not explicitly used in the input. B_ext_grid_s = "default"; E_ext_grid_s = "default"; - + pp.query("B_ext_grid_init_style", B_ext_grid_s); std::transform(B_ext_grid_s.begin(), B_ext_grid_s.end(), @@ -315,28 +315,28 @@ WarpX::InitLevelData (int lev, Real time) E_ext_grid_s.begin(), ::tolower); - // if the input string is "constant", the values for the - // external grid must be provided in the input. + // if the input string is "constant", the values for the + // external grid must be provided in the input. if (B_ext_grid_s == "constant") - pp.getarr("B_external_grid", B_external_grid); - - // if the input string is "constant", the values for the - // external grid must be provided in the input. - if (E_ext_grid_s == "constant") - pp.getarr("E_external_grid", E_external_grid); - + pp.getarr("B_external_grid", B_external_grid); + + // if the input string is "constant", the values for the + // external grid must be provided in the input. + if (E_ext_grid_s == "constant") + pp.getarr("E_external_grid", E_external_grid); + for (int i = 0; i < 3; ++i) { current_fp[lev][i]->setVal(0.0); - if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") - Bfield_fp[lev][i]->setVal(B_external_grid[i]); - if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") - Efield_fp[lev][i]->setVal(E_external_grid[i]); + if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") + Bfield_fp[lev][i]->setVal(B_external_grid[i]); + if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") + Efield_fp[lev][i]->setVal(E_external_grid[i]); } if (B_ext_grid_s == "parse_b_ext_grid_function") { std::vector f; - // Parse Bx_external_grid_function + // Parse Bx_external_grid_function pp.getarr("Bx_external_grid_function(x,y,z)", f); str_Bx_ext_grid_function.clear(); for (auto const& s : f) { @@ -351,7 +351,7 @@ WarpX::InitLevelData (int lev, Real time) str_By_ext_grid_function += s; } f.clear(); - + // Parse Bz_external_grid_function pp.getarr("Bz_external_grid_function(x,y,z)", f); str_Bz_ext_grid_function.clear(); @@ -360,7 +360,7 @@ WarpX::InitLevelData (int lev, Real time) } f.clear(); - // Initialize Bfield_fp with external function + // Initialize Bfield_fp with external function MultiFab *Bx, *By, *Bz; Bx = Bfield_fp[lev][0].get(); By = Bfield_fp[lev][1].get(); @@ -373,7 +373,7 @@ WarpX::InitLevelData (int lev, Real time) if (E_ext_grid_s == "parse_e_ext_grid_function") { std::vector f; - // Parse Ex_external_grid_function + // Parse Ex_external_grid_function pp.getarr("Ex_external_grid_function(x,y,z)", f); str_Ex_ext_grid_function.clear(); for (auto const& s : f) { @@ -381,15 +381,15 @@ WarpX::InitLevelData (int lev, Real time) } f.clear(); - // Parse Ey_external_grid_function + // Parse Ey_external_grid_function pp.getarr("Ey_external_grid_function(x,y,z)", f); str_Ey_ext_grid_function.clear(); for (auto const& s : f) { str_Ey_ext_grid_function += s; } f.clear(); - - // Parse Ez_external_grid_function + + // Parse Ez_external_grid_function pp.getarr("Ez_external_grid_function(x,y,z)", f); str_Ez_ext_grid_function.clear(); for (auto const& s : f) { @@ -397,7 +397,7 @@ WarpX::InitLevelData (int lev, Real time) } f.clear(); - // Initialize Efield_fp with external function + // Initialize Efield_fp with external function MultiFab *Ex, *Ey, *Ez; Ex = Efield_fp[lev][0].get(); Ey = Efield_fp[lev][1].get(); @@ -422,7 +422,7 @@ WarpX::InitLevelData (int lev, Real time) By_aux = Bfield_aux[lev][1].get(); Bz_aux = Bfield_aux[lev][2].get(); - // Setting b_flag to 1 since we are initializing + // Setting b_flag to 1 since we are initializing // B_external on the grid. bool B_flag = 1; InitializeExternalFieldsOnGridUsingParser(Bx_aux, By_aux, @@ -441,12 +441,12 @@ WarpX::InitLevelData (int lev, Real time) Efield_aux[lev][i]->setVal(E_external_grid[i]); Efield_cp[lev][i]->setVal(E_external_grid[i]); } else if (E_ext_grid_s == "parse_e_ext_grid_function") { - + MultiFab *Ex_aux, *Ey_aux, *Ez_aux; - Ex_aux = Efield_aux[lev][0].get(); - Ey_aux = Efield_aux[lev][1].get(); - Ez_aux = Efield_aux[lev][2].get(); - // Setting b_flag to zero since we are initializing + Ex_aux = Efield_aux[lev][0].get(); + Ey_aux = Efield_aux[lev][1].get(); + Ez_aux = Efield_aux[lev][2].get(); + // Setting b_flag to zero since we are initializing // E_external on the grid here. bool B_flag = 0; InitializeExternalFieldsOnGridUsingParser(Ex_aux, Ey_aux, @@ -523,16 +523,16 @@ WarpX::InitLevelDataFFT (int lev, Real time) /* \brief * This function initializes the E and B fields on each level * using the parser and the user-defined function for the external fields. - * Depending on the bool value of the B_flag, the subroutine will parse + * Depending on the bool value of the B_flag, the subroutine will parse * the Bx_/By_/Bz_external_grid_function (if B_flag==1) - * or parse the Ex_/Ey_/Ez_external_grid_function (if B_flag==0). + * or parse the Ex_/Ey_/Ez_external_grid_function (if B_flag==0). * Then, the B or E multifab is initialized based on the (x,y,z) position * on the staggered yee-grid or cell-centered grid. */ -void +void WarpX::InitializeExternalFieldsOnGridUsingParser ( - MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, + MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, const int lev, const bool B_flag) { std::unique_ptr xfield_parsewrap; @@ -554,14 +554,14 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( zfield_parsewrap.reset(new ParserWrapper (makeParser(str_Ez_ext_grid_function))); } - - ParserWrapper *xfield_wrap = xfield_parsewrap.get(); - ParserWrapper *yfield_wrap = yfield_parsewrap.get(); - ParserWrapper *zfield_wrap = zfield_parsewrap.get(); + + ParserWrapper *xfield_wrap = xfield_parsewrap.get(); + ParserWrapper *yfield_wrap = yfield_parsewrap.get(); + ParserWrapper *zfield_wrap = zfield_parsewrap.get(); const auto dx_lev = geom[lev].CellSizeArray(); const RealBox& real_box = geom[lev].ProbDomain(); - for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) + for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) { IntVect x_nodal_flag, y_nodal_flag, z_nodal_flag; if (B_flag == 1) { @@ -576,15 +576,15 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( const Box& tbx = mfi.tilebox(x_nodal_flag); const Box& tby = mfi.tilebox(y_nodal_flag); const Box& tbz = mfi.tilebox(z_nodal_flag); - + auto const& mfxfab = mfx->array(mfi); auto const& mfyfab = mfy->array(mfi); auto const& mfzfab = mfz->array(mfi); - + auto const& mfx_IndexType = (*mfx).ixType(); auto const& mfy_IndexType = (*mfy).ixType(); auto const& mfz_IndexType = (*mfz).ixType(); - + // Initialize IntVect based on the index type of multiFab // 0 if cell-centered, 1 if node-centered. IntVect mfx_type(AMREX_D_DECL(0,0,0)); @@ -599,11 +599,11 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( amrex::ParallelFor (tbx, tby, tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) { - // Shift required in the x-, y-, or z- position - // depending on the index type of the multifab + // Shift required in the x-, y-, or z- position + // depending on the index type of the multifab Real fac_x = (1.0 - mfx_type[0]) * dx_lev[0]*0.5; Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; - + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) diff --git a/Source/WarpX.H b/Source/WarpX.H index d4cf89235..41d77668b 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -49,7 +49,7 @@ struct ParserWrapper : public amrex::Gpu::Managed { ParserWrapper (WarpXParser const& a_parser) noexcept - : m_parser(a_parser) {} + : m_parser(a_parser) {} ~ParserWrapper() { m_parser.clear(); @@ -346,11 +346,11 @@ public: std::array const beta = {{0,0,0}} ) const; // Making this function public to allow the use of GPU launch - // to initialize E and B fields using parser. + // to initialize E and B fields using parser. void InitLevelData (int lev, amrex::Real time); void InitializeExternalFieldsOnGridUsingParser ( - amrex::MultiFab* mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, + amrex::MultiFab* mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, // ParserWrapper* xField_wrap, ParserWrapper* yField_wrap, // ParserWrapper* zField_wrap, const int lev, const bool B_flag); -- cgit v1.2.3 From fb09f1c8afcb0673d1dd4973ec2bc5e939d0c2ad Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 26 Nov 2019 20:27:06 -0800 Subject: fixing bug for MR --- Source/Initialization/WarpXInitData.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index c70b7263e..a3e05e92a 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -415,7 +415,12 @@ WarpX::InitLevelData (int lev, Real time) Bfield_aux[lev][i]->setVal(B_external_grid[i]); Bfield_cp[lev][i]->setVal(B_external_grid[i]); } - else if (B_ext_grid_s == "parse_b_ext_grid_function") { + if (E_ext_grid_s == "constant" || E_ext_grid_s == " default") { + Efield_aux[lev][i]->setVal(E_external_grid[i]); + Efield_cp[lev][i]->setVal(E_external_grid[i]); + } + } + if (B_ext_grid_s == "parse_b_ext_grid_function") { MultiFab *Bx_aux, *By_aux, *Bz_aux; Bx_aux = Bfield_aux[lev][0].get(); @@ -436,11 +441,8 @@ WarpX::InitLevelData (int lev, Real time) InitializeExternalFieldsOnGridUsingParser(Bx_cp, By_cp, Bz_cp, lev, B_flag); - } - if (E_ext_grid_s == "constant" || E_ext_grid_s == " default") { - Efield_aux[lev][i]->setVal(E_external_grid[i]); - Efield_cp[lev][i]->setVal(E_external_grid[i]); - } else if (E_ext_grid_s == "parse_e_ext_grid_function") { + } + if (E_ext_grid_s == "parse_e_ext_grid_function") { MultiFab *Ex_aux, *Ey_aux, *Ez_aux; Ex_aux = Efield_aux[lev][0].get(); @@ -460,7 +462,6 @@ WarpX::InitLevelData (int lev, Real time) InitializeExternalFieldsOnGridUsingParser(Ex_cp, Ey_cp, Ez_cp, lev, B_flag); - } } } -- cgit v1.2.3 From 41a3ec074762fc02f39968cb4fc569f9bb0fec3c Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 26 Nov 2019 20:39:20 -0800 Subject: cleaning --- Source/Initialization/WarpXInitData.cpp | 64 ++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index a3e05e92a..0133d1604 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -422,45 +422,45 @@ WarpX::InitLevelData (int lev, Real time) } if (B_ext_grid_s == "parse_b_ext_grid_function") { - MultiFab *Bx_aux, *By_aux, *Bz_aux; - Bx_aux = Bfield_aux[lev][0].get(); - By_aux = Bfield_aux[lev][1].get(); - Bz_aux = Bfield_aux[lev][2].get(); + MultiFab *Bx_aux, *By_aux, *Bz_aux; + Bx_aux = Bfield_aux[lev][0].get(); + By_aux = Bfield_aux[lev][1].get(); + Bz_aux = Bfield_aux[lev][2].get(); - // Setting b_flag to 1 since we are initializing - // B_external on the grid. - bool B_flag = 1; - InitializeExternalFieldsOnGridUsingParser(Bx_aux, By_aux, - Bz_aux, lev, B_flag); + // Setting b_flag to 1 since we are initializing + // B_external on the grid. + bool B_flag = 1; + InitializeExternalFieldsOnGridUsingParser(Bx_aux, By_aux, + Bz_aux, lev, B_flag); - MultiFab *Bx_cp, *By_cp, *Bz_cp; - Bx_cp = Bfield_cp[lev][0].get(); - By_cp = Bfield_cp[lev][1].get(); - Bz_cp = Bfield_cp[lev][2].get(); + MultiFab *Bx_cp, *By_cp, *Bz_cp; + Bx_cp = Bfield_cp[lev][0].get(); + By_cp = Bfield_cp[lev][1].get(); + Bz_cp = Bfield_cp[lev][2].get(); - InitializeExternalFieldsOnGridUsingParser(Bx_cp, By_cp, - Bz_cp, lev, B_flag); + InitializeExternalFieldsOnGridUsingParser(Bx_cp, By_cp, + Bz_cp, lev, B_flag); } if (E_ext_grid_s == "parse_e_ext_grid_function") { - MultiFab *Ex_aux, *Ey_aux, *Ez_aux; - Ex_aux = Efield_aux[lev][0].get(); - Ey_aux = Efield_aux[lev][1].get(); - Ez_aux = Efield_aux[lev][2].get(); - // Setting b_flag to zero since we are initializing - // E_external on the grid here. - bool B_flag = 0; - InitializeExternalFieldsOnGridUsingParser(Ex_aux, Ey_aux, - Ez_aux, lev, B_flag); - - MultiFab *Ex_cp, *Ey_cp, *Ez_cp; - Ex_cp = Efield_cp[lev][0].get(); - Ey_cp = Efield_cp[lev][1].get(); - Ez_cp = Efield_cp[lev][2].get(); - - InitializeExternalFieldsOnGridUsingParser(Ex_cp, Ey_cp, - Ez_cp, lev, B_flag); + MultiFab *Ex_aux, *Ey_aux, *Ez_aux; + Ex_aux = Efield_aux[lev][0].get(); + Ey_aux = Efield_aux[lev][1].get(); + Ez_aux = Efield_aux[lev][2].get(); + // Setting b_flag to zero since we are initializing + // E_external on the grid here. + bool B_flag = 0; + InitializeExternalFieldsOnGridUsingParser(Ex_aux, Ey_aux, + Ez_aux, lev, B_flag); + + MultiFab *Ex_cp, *Ey_cp, *Ez_cp; + Ex_cp = Efield_cp[lev][0].get(); + Ey_cp = Efield_cp[lev][1].get(); + Ez_cp = Efield_cp[lev][2].get(); + + InitializeExternalFieldsOnGridUsingParser(Ex_cp, Ey_cp, + Ez_cp, lev, B_flag); } } -- cgit v1.2.3 From 91e190da0e45bdfe67b19b843ce9fe60f4406316 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Sat, 30 Nov 2019 11:57:49 -0800 Subject: removing space in string default which causes a bug! --- Source/Initialization/WarpXInitData.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 0133d1604..c9592ed5c 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -415,13 +415,12 @@ WarpX::InitLevelData (int lev, Real time) Bfield_aux[lev][i]->setVal(B_external_grid[i]); Bfield_cp[lev][i]->setVal(B_external_grid[i]); } - if (E_ext_grid_s == "constant" || E_ext_grid_s == " default") { + if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") { Efield_aux[lev][i]->setVal(E_external_grid[i]); Efield_cp[lev][i]->setVal(E_external_grid[i]); } } if (B_ext_grid_s == "parse_b_ext_grid_function") { - MultiFab *Bx_aux, *By_aux, *Bz_aux; Bx_aux = Bfield_aux[lev][0].get(); By_aux = Bfield_aux[lev][1].get(); -- cgit v1.2.3 From e18c5113c396655c2a78fb27899d893e21fa8236 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Sat, 30 Nov 2019 16:30:38 -0800 Subject: cleaning --- Source/Initialization/WarpXInitData.cpp | 6 ------ Source/WarpX.H | 4 ++++ Source/WarpX.cpp | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index c9592ed5c..ce11fa0fd 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -237,7 +237,6 @@ WarpX::PostRestart () namespace { WarpXParser makeParser (std::string const& parse_function) { - std::cout << " in make parser " << parse_function << std::endl; WarpXParser parser(parse_function); parser.registerVariables({"x","y","z"}); ParmParse pp("my_constants"); @@ -295,14 +294,9 @@ WarpX::InitLevelData (int lev, Real time) ParmParse pp("warpx"); - std::string B_ext_grid_s; - std::string E_ext_grid_s; // default values of E_external_grid and B_external_grid // are used to set the E and B field when "constant" or // "parser" is not explicitly used in the input. - B_ext_grid_s = "default"; - E_ext_grid_s = "default"; - pp.query("B_ext_grid_init_style", B_ext_grid_s); std::transform(B_ext_grid_s.begin(), B_ext_grid_s.end(), diff --git a/Source/WarpX.H b/Source/WarpX.H index 41d77668b..b34f0cc67 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -103,6 +103,10 @@ public: static amrex::Vector E_external_grid; static amrex::Vector B_external_grid; + // Initialization Type for External E and B + static std::string B_ext_grid_s; + static std::string E_ext_grid_s; + // Parser for B_external on the grid static std::string str_Bx_ext_grid_function; static std::string str_By_ext_grid_function; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index c6cf03b05..03ed5e1e5 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -30,6 +30,9 @@ Vector WarpX::E_external_particle(3, 0.0); Vector WarpX::E_external_grid(3, 0.0); Vector WarpX::B_external_grid(3, 0.0); +std::string WarpX::B_ext_grid_s = "default"; +std::string WarpX::E_ext_grid_s = "default"; + // Parser for B_external on the grid std::string WarpX::str_Bx_ext_grid_function; std::string WarpX::str_By_ext_grid_function; -- cgit v1.2.3 From db6a476daa9d8547b96436d5cc9b5ef5ab212a43 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Fri, 13 Dec 2019 13:42:00 -0800 Subject: for 2D, the function is (x,y=0.0,z) --- Docs/source/running_cpp/parameters.rst | 8 +++++--- Source/Initialization/WarpXInitData.cpp | 25 ++++++++++++++++--------- Source/Utils/WarpXMovingWindow.cpp | 8 +++++--- 3 files changed, 26 insertions(+), 15 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 756b17c19..768ea7160 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -653,9 +653,9 @@ Laser initialization For example, if ``warpx.Bx_external_grid_function(x,y,z)=Bo*x + delta*(y + z)`` then the constants `Bo` and `delta` required in the above equation can be set using ``my_constants.Bo=`` and ``my_constants.delta=`` in the - input file. + input file. For a two-dimensional simulation, it is assumed that the first dimension is `x` and the second dimension in `z`, and the value of `y` is set to zero. -* ``warpx.E_Ext_grid_init_style`` (string) optional (default is "default") +* ``warpx.E_ext_grid_init_style`` (string) optional (default is "default") This parameter determines the type of initialization for the external electric field. The "default" style initializes the external electric field (Ex,Ey,Ez) to (0.0, 0.0, 0.0). @@ -674,7 +674,9 @@ Laser initialization For example, if ``warpx.Ex_external_grid_function(x,y,z)=Eo*x + delta*(y + z)`` then the constants `Bo` and `delta` required in the above equation can be set using ``my_constants.Eo=`` and ``my_constants.delta=`` in the - input file. + input file. For a two-dimensional simulation, it is assumed that the first + dimension is `x` and the second dimension in `z`, + and the value of `y` is set to zero. * ``warpx.E_external_grid`` & ``warpx.B_external_grid`` (list of `int`) required when ``warpx.B_ext_grid_init_style="parse_B_ext_grid_function"`` diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index ce11fa0fd..488c351dc 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -596,13 +596,14 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( // Shift required in the x-, y-, or z- position // depending on the index type of the multifab Real fac_x = (1.0 - mfx_type[0]) * dx_lev[0]*0.5; - Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; - Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; - Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) - Real z = 0.0; + Real y = 0.0; + Real fac_z = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real z = j*dx_lev[1] + real_box.lo(1) + fac_z; #else + Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; Real fac_z = (1.0 - mfx_type[2]) * dx_lev[2]*0.5; Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif @@ -611,13 +612,15 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { Real fac_x = (1.0 - mfy_type[0]) * dx_lev[0]*0.5; - Real fac_y = (1.0 - mfy_type[1]) * dx_lev[1]*0.5; Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; - Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) - Real z = 0.0; + Real y = 0.0; + Real fac_z = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real z = j*dx_lev[1] + real_box.lo(1) + fac_z; #elif (AMREX_SPACEDIM==3) - Real fac_z = (1.0 - mfy_type[2]) * dx_lev[2]*0.5; + Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; + Real fac_z = (1.0 - mfx_type[2]) * dx_lev[2]*0.5; Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif // Initialize the y-component of the field. @@ -629,8 +632,12 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) - Real z = 0.0; + Real y = 0.0; + Real fac_z = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real z = j*dx_lev[1] + real_box.lo(1) + fac_z; #elif (AMREX_SPACEDIM==3) + Real fac_y = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; + Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; Real fac_z = (1.0 - mfz_type[2]) * dx_lev[2]*0.5; Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index 2f4203da5..a3ec07f65 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -359,12 +359,14 @@ WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, { // Compute x,y,z co-ordinates based on index type of mf Real fac_x = (1.0 - mf_type[0]) * dx[0]*0.5; - Real fac_y = (1.0 - mf_type[1]) * dx[1]*0.5; Real x = i*dx[0] + real_box.lo(0) + fac_x; - Real y = j*dx[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) - Real z = 0.0; + Real y = 0.0; + Real fac_z = (1.0 - mf_type[1]) * dx[1]*0.5; + Real z = j*dx[1] + real_box.lo(1) + fac_z; #else + Real fac_y = (1.0 - mf_type[1]) * dx[1]*0.5; + Real y = j*dx[1] + real_box.lo(1) + fac_y; Real fac_z = (1.0 - mf_type[2]) * dx[2]*0.5; Real z = k*dx[2] + real_box.lo(2) + fac_z; #endif -- cgit v1.2.3 From fd55d1061efbaf88bbf7b17a49da92ce57de364a Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Fri, 13 Dec 2019 14:39:21 -0800 Subject: fixing compilation error - redundant variable declaration --- Source/Initialization/WarpXInitData.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 488c351dc..2166adbe2 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -628,9 +628,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { Real fac_x = (1.0 - mfz_type[0]) * dx_lev[0]*0.5; - Real fac_y = (1.0 - mfz_type[1]) * dx_lev[1]*0.5; Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; - Real y = j*dx_lev[1] + real_box.lo(1) + fac_y; #if (AMREX_SPACEDIM==2) Real y = 0.0; Real fac_z = (1.0 - mfx_type[1]) * dx_lev[1]*0.5; -- cgit v1.2.3 From 5df218e2678fb8f6f6a8efa0391a04e592ee7b60 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Thu, 19 Dec 2019 11:38:04 -0800 Subject: adding function to store parser string to reduce duplication --- Source/Initialization/WarpXInitData.cpp | 130 ++++++++++---------------------- Source/Utils/WarpXUtil.H | 3 + Source/Utils/WarpXUtil.cpp | 17 +++++ 3 files changed, 58 insertions(+), 92 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 2166adbe2..3392b5ef3 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -11,6 +10,7 @@ #include #endif #include +#include using namespace amrex; @@ -261,8 +261,6 @@ WarpXParser makeParser (std::string const& parse_function) } - - /* \brief * This function initializes E, B, rho, and F, at all the levels * of the multifab. rho and F are initialized with 0. @@ -329,76 +327,35 @@ WarpX::InitLevelData (int lev, Real time) if (B_ext_grid_s == "parse_b_ext_grid_function") { - std::vector f; - // Parse Bx_external_grid_function - pp.getarr("Bx_external_grid_function(x,y,z)", f); - str_Bx_ext_grid_function.clear(); - for (auto const& s : f) { - str_Bx_ext_grid_function += s; - } - f.clear(); - - // Parse By_external_grid_function - pp.getarr("By_external_grid_function(x,y,z)", f); - str_By_ext_grid_function.clear(); - for (auto const& s : f) { - str_By_ext_grid_function += s; - } - f.clear(); - - // Parse Bz_external_grid_function - pp.getarr("Bz_external_grid_function(x,y,z)", f); - str_Bz_ext_grid_function.clear(); - for (auto const& s : f) { - str_Bz_ext_grid_function += s; - } - f.clear(); - + Store_parserString("Bx_external_grid_function(x,y,z)", + str_Bx_ext_grid_function); + Store_parserString("By_external_grid_function(x,y,z)", + str_By_ext_grid_function); + Store_parserString("Bz_external_grid_function(x,y,z)", + str_Bz_ext_grid_function); // Initialize Bfield_fp with external function - MultiFab *Bx, *By, *Bz; - Bx = Bfield_fp[lev][0].get(); - By = Bfield_fp[lev][1].get(); - Bz = Bfield_fp[lev][2].get(); - bool B_flag = 1; - InitializeExternalFieldsOnGridUsingParser(Bx, By, Bz, lev, B_flag); + InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), + Bfield_fp[lev][1].get(), + Bfield_fp[lev][2].get(), + lev, B_flag); } if (E_ext_grid_s == "parse_e_ext_grid_function") { - std::vector f; - // Parse Ex_external_grid_function - pp.getarr("Ex_external_grid_function(x,y,z)", f); - str_Ex_ext_grid_function.clear(); - for (auto const& s : f) { - str_Ex_ext_grid_function += s; - } - f.clear(); - - // Parse Ey_external_grid_function - pp.getarr("Ey_external_grid_function(x,y,z)", f); - str_Ey_ext_grid_function.clear(); - for (auto const& s : f) { - str_Ey_ext_grid_function += s; - } - f.clear(); - - // Parse Ez_external_grid_function - pp.getarr("Ez_external_grid_function(x,y,z)", f); - str_Ez_ext_grid_function.clear(); - for (auto const& s : f) { - str_Ez_ext_grid_function += s; - } - f.clear(); + Store_parserString("Ex_external_grid_function(x,y,z)", + str_Ex_ext_grid_function); + Store_parserString("Ey_external_grid_function(x,y,z)", + str_Ey_ext_grid_function); + Store_parserString("Ez_external_grid_function(x,y,z)", + str_Ez_ext_grid_function); // Initialize Efield_fp with external function - MultiFab *Ex, *Ey, *Ez; - Ex = Efield_fp[lev][0].get(); - Ey = Efield_fp[lev][1].get(); - Ez = Efield_fp[lev][2].get(); - bool B_flag = 0; - InitializeExternalFieldsOnGridUsingParser(Ex, Ey, Ez, lev, B_flag); + InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), + Efield_fp[lev][1].get(), + Efield_fp[lev][2].get(), + lev, B_flag); } @@ -415,46 +372,35 @@ WarpX::InitLevelData (int lev, Real time) } } if (B_ext_grid_s == "parse_b_ext_grid_function") { - MultiFab *Bx_aux, *By_aux, *Bz_aux; - Bx_aux = Bfield_aux[lev][0].get(); - By_aux = Bfield_aux[lev][1].get(); - Bz_aux = Bfield_aux[lev][2].get(); // Setting b_flag to 1 since we are initializing // B_external on the grid. bool B_flag = 1; - InitializeExternalFieldsOnGridUsingParser(Bx_aux, By_aux, - Bz_aux, lev, B_flag); - - MultiFab *Bx_cp, *By_cp, *Bz_cp; - Bx_cp = Bfield_cp[lev][0].get(); - By_cp = Bfield_cp[lev][1].get(); - Bz_cp = Bfield_cp[lev][2].get(); + InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), + Bfield_aux[lev][1].get(), + Bfield_aux[lev][2].get(), + lev, B_flag); - InitializeExternalFieldsOnGridUsingParser(Bx_cp, By_cp, - Bz_cp, lev, B_flag); + InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), + Bfield_cp[lev][1].get(), + Bfield_cp[lev][2].get(), + lev, B_flag); } if (E_ext_grid_s == "parse_e_ext_grid_function") { - MultiFab *Ex_aux, *Ey_aux, *Ez_aux; - Ex_aux = Efield_aux[lev][0].get(); - Ey_aux = Efield_aux[lev][1].get(); - Ez_aux = Efield_aux[lev][2].get(); // Setting b_flag to zero since we are initializing // E_external on the grid here. bool B_flag = 0; - InitializeExternalFieldsOnGridUsingParser(Ex_aux, Ey_aux, - Ez_aux, lev, B_flag); - - MultiFab *Ex_cp, *Ey_cp, *Ez_cp; - Ex_cp = Efield_cp[lev][0].get(); - Ey_cp = Efield_cp[lev][1].get(); - Ez_cp = Efield_cp[lev][2].get(); - - InitializeExternalFieldsOnGridUsingParser(Ex_cp, Ey_cp, - Ez_cp, lev, B_flag); - + InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), + Efield_aux[lev][1].get(), + Efield_aux[lev][2].get(), + lev, B_flag); + + InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), + Efield_cp[lev][1].get(), + Efield_cp[lev][2].get(), + lev, B_flag); } } diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H index 195e309cf..ce24d1233 100644 --- a/Source/Utils/WarpXUtil.H +++ b/Source/Utils/WarpXUtil.H @@ -15,6 +15,9 @@ void ConvertLabParamsToBoost(); void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, amrex::Real zmax); +void Store_parserString(std::string query_string, + std::string& stored_string); + namespace WarpXUtilIO{ /** * A helper function to write binary data on disk. diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 8764a09c6..029e03dc2 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -164,3 +164,20 @@ namespace WarpXUtilIO{ } } +void Store_parserString(std::string query_string, + std::string& stored_string) +{ + + ParmParse pp("warpx"); + char cstr[query_string.size()+1]; + strcpy(cstr, query_string.c_str()); + + std::vector f; + pp.getarr(cstr, f); + stored_string.clear(); + for (auto const& s : f) { + stored_string += s; + } + f.clear(); + +} -- cgit v1.2.3 From 23153e9385db5b6f4b730190eb111730e7bb7667 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Thu, 19 Dec 2019 11:44:51 -0800 Subject: fixing EOL whitespace --- Source/Initialization/WarpXInitData.cpp | 34 ++++++++++++++++----------------- Source/Utils/WarpXUtil.H | 2 +- Source/Utils/WarpXUtil.cpp | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 3392b5ef3..a6bf60840 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -327,34 +327,34 @@ WarpX::InitLevelData (int lev, Real time) if (B_ext_grid_s == "parse_b_ext_grid_function") { - Store_parserString("Bx_external_grid_function(x,y,z)", + Store_parserString("Bx_external_grid_function(x,y,z)", str_Bx_ext_grid_function); - Store_parserString("By_external_grid_function(x,y,z)", + Store_parserString("By_external_grid_function(x,y,z)", str_By_ext_grid_function); Store_parserString("Bz_external_grid_function(x,y,z)", str_Bz_ext_grid_function); // Initialize Bfield_fp with external function bool B_flag = 1; - InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), - Bfield_fp[lev][1].get(), - Bfield_fp[lev][2].get(), + InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), + Bfield_fp[lev][1].get(), + Bfield_fp[lev][2].get(), lev, B_flag); } if (E_ext_grid_s == "parse_e_ext_grid_function") { - Store_parserString("Ex_external_grid_function(x,y,z)", + Store_parserString("Ex_external_grid_function(x,y,z)", str_Ex_ext_grid_function); - Store_parserString("Ey_external_grid_function(x,y,z)", + Store_parserString("Ey_external_grid_function(x,y,z)", str_Ey_ext_grid_function); Store_parserString("Ez_external_grid_function(x,y,z)", str_Ez_ext_grid_function); // Initialize Efield_fp with external function bool B_flag = 0; - InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), - Efield_fp[lev][1].get(), - Efield_fp[lev][2].get(), + InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), + Efield_fp[lev][1].get(), + Efield_fp[lev][2].get(), lev, B_flag); } @@ -376,14 +376,14 @@ WarpX::InitLevelData (int lev, Real time) // Setting b_flag to 1 since we are initializing // B_external on the grid. bool B_flag = 1; - InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), + InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), Bfield_aux[lev][1].get(), - Bfield_aux[lev][2].get(), + Bfield_aux[lev][2].get(), lev, B_flag); - InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), + InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get(), + Bfield_cp[lev][2].get(), lev, B_flag); } @@ -392,12 +392,12 @@ WarpX::InitLevelData (int lev, Real time) // Setting b_flag to zero since we are initializing // E_external on the grid here. bool B_flag = 0; - InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), + InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), Efield_aux[lev][1].get(), - Efield_aux[lev][2].get(), + Efield_aux[lev][2].get(), lev, B_flag); - InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), + InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get(), lev, B_flag); diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H index ce24d1233..7ea6e5508 100644 --- a/Source/Utils/WarpXUtil.H +++ b/Source/Utils/WarpXUtil.H @@ -15,7 +15,7 @@ void ConvertLabParamsToBoost(); void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, amrex::Real zmax); -void Store_parserString(std::string query_string, +void Store_parserString(std::string query_string, std::string& stored_string); namespace WarpXUtilIO{ diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 029e03dc2..db5a646f9 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -164,7 +164,7 @@ namespace WarpXUtilIO{ } } -void Store_parserString(std::string query_string, +void Store_parserString(std::string query_string, std::string& stored_string) { -- cgit v1.2.3 From 468f2442c661023d4fd91c34f2bace339a34d754 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Thu, 19 Dec 2019 12:24:39 -0800 Subject: Remove B_flag and instead pass IntVect of nodalflag and parser_functions --- Source/Initialization/WarpXInitData.cpp | 85 +++++++++++++++------------------ Source/WarpX.H | 9 ++-- 2 files changed, 44 insertions(+), 50 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index a6bf60840..b949c5373 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -334,11 +334,14 @@ WarpX::InitLevelData (int lev, Real time) Store_parserString("Bz_external_grid_function(x,y,z)", str_Bz_ext_grid_function); // Initialize Bfield_fp with external function - bool B_flag = 1; InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), Bfield_fp[lev][2].get(), - lev, B_flag); + str_Bx_ext_grid_function, + str_By_ext_grid_function, + str_Bz_ext_grid_function, + Bx_nodal_flag, By_nodal_flag, + Bz_nodal_flag, lev); } if (E_ext_grid_s == "parse_e_ext_grid_function") { @@ -351,12 +354,14 @@ WarpX::InitLevelData (int lev, Real time) str_Ez_ext_grid_function); // Initialize Efield_fp with external function - bool B_flag = 0; InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), Efield_fp[lev][2].get(), - lev, B_flag); - + str_Ex_ext_grid_function, + str_Ey_ext_grid_function, + str_Ez_ext_grid_function, + Ex_nodal_flag, Ey_nodal_flag, + Ez_nodal_flag, lev); } if (lev > 0) { @@ -373,34 +378,44 @@ WarpX::InitLevelData (int lev, Real time) } if (B_ext_grid_s == "parse_b_ext_grid_function") { - // Setting b_flag to 1 since we are initializing - // B_external on the grid. - bool B_flag = 1; InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), Bfield_aux[lev][1].get(), Bfield_aux[lev][2].get(), - lev, B_flag); + str_Bx_ext_grid_function, + str_By_ext_grid_function, + str_Bz_ext_grid_function, + Bx_nodal_flag, By_nodal_flag, + Bz_nodal_flag, lev); InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), Bfield_cp[lev][2].get(), - lev, B_flag); + str_Bx_ext_grid_function, + str_By_ext_grid_function, + str_Bz_ext_grid_function, + Bx_nodal_flag, By_nodal_flag, + Bz_nodal_flag, lev); } if (E_ext_grid_s == "parse_e_ext_grid_function") { - // Setting b_flag to zero since we are initializing - // E_external on the grid here. - bool B_flag = 0; InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), Efield_aux[lev][1].get(), Efield_aux[lev][2].get(), - lev, B_flag); + str_Ex_ext_grid_function, + str_Ey_ext_grid_function, + str_Ez_ext_grid_function, + Ex_nodal_flag, Ey_nodal_flag, + Ez_nodal_flag, lev); InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get(), - lev, B_flag); + str_Ex_ext_grid_function, + str_Ey_ext_grid_function, + str_Ez_ext_grid_function, + Ex_nodal_flag, Ey_nodal_flag, + Ez_nodal_flag, lev); } } @@ -463,37 +478,25 @@ WarpX::InitLevelDataFFT (int lev, Real time) /* \brief * This function initializes the E and B fields on each level * using the parser and the user-defined function for the external fields. - * Depending on the bool value of the B_flag, the subroutine will parse - * the Bx_/By_/Bz_external_grid_function (if B_flag==1) - * or parse the Ex_/Ey_/Ez_external_grid_function (if B_flag==0). - * Then, the B or E multifab is initialized based on the (x,y,z) position + * The subroutine will parse the x_/y_z_external_grid_function and + * then, the B or E multifab is initialized based on the (x,y,z) position * on the staggered yee-grid or cell-centered grid. */ - void WarpX::InitializeExternalFieldsOnGridUsingParser ( MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, - const int lev, const bool B_flag) + const std::string x_function, const std::string y_function, + const std::string z_function, IntVect x_nodal_flag, + IntVect y_nodal_flag, IntVect z_nodal_flag, + const int lev) { std::unique_ptr xfield_parsewrap; std::unique_ptr yfield_parsewrap; std::unique_ptr zfield_parsewrap; - if (B_flag == 1) { - xfield_parsewrap.reset(new ParserWrapper - (makeParser(str_Bx_ext_grid_function))); - yfield_parsewrap.reset(new ParserWrapper - (makeParser(str_By_ext_grid_function))); - zfield_parsewrap.reset(new ParserWrapper - (makeParser(str_Bz_ext_grid_function))); - } else { - xfield_parsewrap.reset(new ParserWrapper - (makeParser(str_Ex_ext_grid_function))); - yfield_parsewrap.reset(new ParserWrapper - (makeParser(str_Ey_ext_grid_function))); - zfield_parsewrap.reset(new ParserWrapper - (makeParser(str_Ez_ext_grid_function))); - } + xfield_parsewrap.reset(new ParserWrapper(makeParser(x_function))); + yfield_parsewrap.reset(new ParserWrapper(makeParser(y_function))); + zfield_parsewrap.reset(new ParserWrapper(makeParser(z_function))); ParserWrapper *xfield_wrap = xfield_parsewrap.get(); ParserWrapper *yfield_wrap = yfield_parsewrap.get(); @@ -503,16 +506,6 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( const RealBox& real_box = geom[lev].ProbDomain(); for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - IntVect x_nodal_flag, y_nodal_flag, z_nodal_flag; - if (B_flag == 1) { - x_nodal_flag = Bx_nodal_flag; - y_nodal_flag = By_nodal_flag; - z_nodal_flag = Bz_nodal_flag; - } else { - x_nodal_flag = Ex_nodal_flag; - y_nodal_flag = Ey_nodal_flag; - z_nodal_flag = Ez_nodal_flag; - } const Box& tbx = mfi.tilebox(x_nodal_flag); const Box& tby = mfi.tilebox(y_nodal_flag); const Box& tbz = mfi.tilebox(z_nodal_flag); diff --git a/Source/WarpX.H b/Source/WarpX.H index 5d6ec1f63..683e7c269 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -358,10 +358,11 @@ public: void InitLevelData (int lev, amrex::Real time); void InitializeExternalFieldsOnGridUsingParser ( - amrex::MultiFab* mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, -// ParserWrapper* xField_wrap, ParserWrapper* yField_wrap, -// ParserWrapper* zField_wrap, - const int lev, const bool B_flag); + amrex::MultiFab *mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, + const std::string x_function, const std::string y_function, + const std::string z_function, amrex::IntVect x_nodal_flag, + amrex::IntVect y_nodal_flag, amrex::IntVect z_nodal_flag, + const int lev); protected: //! Tagging cells for refinement -- cgit v1.2.3 From 8213a3e88e679fd5b073eaf003d68f722dadf641 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 10:44:56 -0800 Subject: adding comments from .cpp to .H for documentation as suggested in review --- Source/Initialization/WarpXInitData.cpp | 31 ---------------------------- Source/WarpX.H | 36 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 34 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index b949c5373..6ac8195f8 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -261,30 +261,6 @@ WarpXParser makeParser (std::string const& parse_function) } -/* \brief - * This function initializes E, B, rho, and F, at all the levels - * of the multifab. rho and F are initialized with 0. - * The E and B fields are initialized using user-defined inputs. - * The initialization type is set using "B_ext_grid_init_style" - * and "E_ext_grid_init_style". The initialization style is set to "default" - * if not explicitly defined by the user, and the E and B fields are - * initialized with E_external_grid and B_external_grid, respectively, each with - * a default value of 0. - * If the initialization type for the E and B field is "constant", - * then, the E and B fields at all the levels are initialized with - * user-defined values for E_external_grid and B_external_grid. - * If the initialization type for B-field is set to - * "parse_B_ext_grid_function", then, the parser is used to read - * Bx_external_grid_function(x,y,z), By_external_grid_function(x,y,z), - * and Bz_external_grid_function(x,y,z). - * Similarly, if the E-field initialization type is set to - * "parse_E_ext_grid_function", then, the parser is used to read - * Ex_external_grid_function(x,y,z), Ey_external_grid_function(x,y,z), - * and Ex_external_grid_function(x,y,z). The parser for the E and B - * initialization assumes that the function has three independent - * variables, at max, namely, x, y, z. However, any number of constants - * can be used in the function used to define the E and B fields on the grid. - */ void WarpX::InitLevelData (int lev, Real time) @@ -475,13 +451,6 @@ WarpX::InitLevelDataFFT (int lev, Real time) #endif -/* \brief - * This function initializes the E and B fields on each level - * using the parser and the user-defined function for the external fields. - * The subroutine will parse the x_/y_z_external_grid_function and - * then, the B or E multifab is initialized based on the (x,y,z) position - * on the staggered yee-grid or cell-centered grid. - */ void WarpX::InitializeExternalFieldsOnGridUsingParser ( MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, diff --git a/Source/WarpX.H b/Source/WarpX.H index 683e7c269..8f8979d34 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -352,11 +352,41 @@ public: void computeB (amrex::Vector, 3> >& B, const amrex::Vector >& phi, std::array const beta = {{0,0,0}} ) const; - - // Making this function public to allow the use of GPU launch - // to initialize E and B fields using parser. +/** + * \brief + * This function initializes E, B, rho, and F, at all the levels + * of the multifab. rho and F are initialized with 0. + * The E and B fields are initialized using user-defined inputs. + * The initialization type is set using "B_ext_grid_init_style" + * and "E_ext_grid_init_style". The initialization style is set to "default" + * if not explicitly defined by the user, and the E and B fields are + * initialized with E_external_grid and B_external_grid, respectively, each with + * a default value of 0. + * If the initialization type for the E and B field is "constant", + * then, the E and B fields at all the levels are initialized with + * user-defined values for E_external_grid and B_external_grid. + * If the initialization type for B-field is set to + * "parse_B_ext_grid_function", then, the parser is used to read + * Bx_external_grid_function(x,y,z), By_external_grid_function(x,y,z), + * and Bz_external_grid_function(x,y,z). + * Similarly, if the E-field initialization type is set to + * "parse_E_ext_grid_function", then, the parser is used to read + * Ex_external_grid_function(x,y,z), Ey_external_grid_function(x,y,z), + * and Ex_external_grid_function(x,y,z). The parser for the E and B + * initialization assumes that the function has three independent + * variables, at max, namely, x, y, z. However, any number of constants + * can be used in the function used to define the E and B fields on the grid. + */ void InitLevelData (int lev, amrex::Real time); +/** + * \brief + * This function initializes the E and B fields on each level + * using the parser and the user-defined function for the external fields. + * The subroutine will parse the x_/y_z_external_grid_function and + * then, the B or E multifab is initialized based on the (x,y,z) position + * on the staggered yee-grid or cell-centered grid. + */ void InitializeExternalFieldsOnGridUsingParser ( amrex::MultiFab *mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, const std::string x_function, const std::string y_function, -- cgit v1.2.3 From c23edfd29a92a4744ff3fb6e89f0e799ee550c84 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 11:28:50 -0800 Subject: merging all makeParser () functions in WarpXUtil.H --- Source/Initialization/PlasmaInjector.cpp | 29 +---------------------------- Source/Initialization/WarpXInitData.cpp | 28 ---------------------------- Source/Utils/WarpXMovingWindow.cpp | 28 +--------------------------- Source/Utils/WarpXUtil.cpp | 27 +++++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 83 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index f7c7e498f..6e7880ca5 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -168,34 +169,6 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) } } -namespace { -WarpXParser makeParser (std::string const& parse_function) -{ - WarpXParser parser(parse_function); - parser.registerVariables({"x","y","z"}); - - ParmParse pp("my_constants"); - std::set symbols = parser.symbols(); - symbols.erase("x"); - symbols.erase("y"); - symbols.erase("z"); // after removing variables, we are left with constants - for (auto it = symbols.begin(); it != symbols.end(); ) { - Real v; - if (pp.query(it->c_str(), v)) { - parser.setConstant(*it, v); - it = symbols.erase(it); - } else { - ++it; - } - } - for (auto const& s : symbols) { // make sure there no unknown symbols - amrex::Abort("PlasmaInjector::makeParser: Unknown symbol "+s); - } - - return parser; -} -} - // Depending on injection type at runtime, initialize inj_rho // so that inj_rho->getDensity calls // InjectorPosition[Constant or Custom or etc.].getDensity. diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 6ac8195f8..cd548f73e 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -234,34 +234,6 @@ WarpX::PostRestart () } -namespace { -WarpXParser makeParser (std::string const& parse_function) -{ - WarpXParser parser(parse_function); - parser.registerVariables({"x","y","z"}); - ParmParse pp("my_constants"); - std::set symbols = parser.symbols(); - symbols.erase("x"); - symbols.erase("y"); - symbols.erase("z"); - for (auto it = symbols.begin(); it != symbols.end(); ) { - Real v; - if (pp.query(it->c_str(), v)) { - parser.setConstant(*it, v); - it = symbols.erase(it); - } else { - ++it; - } - } - for (auto const& s : symbols) { - amrex::Abort(" ExternalEBFieldOnGrid::makeParser::Unknown symbol "+s); - } - return parser; -} -} - - - void WarpX::InitLevelData (int lev, Real time) { diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index a3ec07f65..247c89869 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -1,35 +1,9 @@ #include +#include #include using namespace amrex; -namespace { -WarpXParser makeParser (std::string const& parse_function) -{ - WarpXParser parser(parse_function); - parser.registerVariables({"x","y","z"}); - ParmParse pp("my_constants"); - std::set symbols = parser.symbols(); - symbols.erase("x"); - symbols.erase("y"); - symbols.erase("z"); - for (auto it = symbols.begin(); it != symbols.end(); ) { - Real v; - if (pp.query(it->c_str(), v)) { - parser.setConstant(*it, v); - it = symbols.erase(it); - } else { - ++it; - } - } - for (auto const& s : symbols) { - amrex::Abort(" ExternalEBFieldOnGrid::makeParser::Unknown symbol "+s); - } - return parser; -} -} - - void WarpX::UpdatePlasmaInjectionPosition (Real a_dt) { diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index db5a646f9..152eaba07 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -181,3 +181,30 @@ void Store_parserString(std::string query_string, f.clear(); } + + +//namespace { +WarpXParser makeParser (std::string const& parse_function) +{ + WarpXParser parser(parse_function); + parser.registerVariables({"x","y","z"}); + ParmParse pp("my_constants"); + std::set symbols = parser.symbols(); + symbols.erase("x"); + symbols.erase("y"); + symbols.erase("z"); + for (auto it = symbols.begin(); it != symbols.end(); ) { + Real v; + if (pp.query(it->c_str(), v)) { + parser.setConstant(*it, v); + it = symbols.erase(it); + } else { + ++it; + } + } + for (auto const& s : symbols) { + amrex::Abort("makeParser::Unknown symbol "+s); + } + return parser; +} +//} -- cgit v1.2.3 From 02c4656ddc2c90d58ce260eba02d0b51ed8ba56a Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 12:02:14 -0800 Subject: cleaning --- Source/Initialization/WarpXInitData.cpp | 110 +++++++++++++++----------------- 1 file changed, 53 insertions(+), 57 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index cd548f73e..6ed0dbed2 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -267,10 +267,23 @@ WarpX::InitLevelData (int lev, Real time) for (int i = 0; i < 3; ++i) { current_fp[lev][i]->setVal(0.0); - if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") + if (lev > 0) + current_cp[lev][i]->setVal(0.0); + + if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") { Bfield_fp[lev][i]->setVal(B_external_grid[i]); - if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") + if (lev > 0) { + Bfield_aux[lev][i]->setVal(B_external_grid[i]); + Bfield_cp[lev][i]->setVal(B_external_grid[i]); + } + } + if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") { Efield_fp[lev][i]->setVal(E_external_grid[i]); + if (lev > 0) { + Efield_aux[lev][i]->setVal(E_external_grid[i]); + Efield_cp[lev][i]->setVal(E_external_grid[i]); + } + } } if (B_ext_grid_s == "parse_b_ext_grid_function") { @@ -290,6 +303,25 @@ WarpX::InitLevelData (int lev, Real time) str_Bz_ext_grid_function, Bx_nodal_flag, By_nodal_flag, Bz_nodal_flag, lev); + if (lev > 0) { + InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), + Bfield_aux[lev][1].get(), + Bfield_aux[lev][2].get(), + str_Bx_ext_grid_function, + str_By_ext_grid_function, + str_Bz_ext_grid_function, + Bx_nodal_flag, By_nodal_flag, + Bz_nodal_flag, lev); + + InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), + Bfield_cp[lev][1].get(), + Bfield_cp[lev][2].get(), + str_Bx_ext_grid_function, + str_By_ext_grid_function, + str_Bz_ext_grid_function, + Bx_nodal_flag, By_nodal_flag, + Bz_nodal_flag, lev); + } } if (E_ext_grid_s == "parse_e_ext_grid_function") { @@ -310,61 +342,25 @@ WarpX::InitLevelData (int lev, Real time) str_Ez_ext_grid_function, Ex_nodal_flag, Ey_nodal_flag, Ez_nodal_flag, lev); - } - - if (lev > 0) { - for (int i = 0; i < 3; ++i) { - current_cp[lev][i]->setVal(0.0); - if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") { - Bfield_aux[lev][i]->setVal(B_external_grid[i]); - Bfield_cp[lev][i]->setVal(B_external_grid[i]); - } - if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") { - Efield_aux[lev][i]->setVal(E_external_grid[i]); - Efield_cp[lev][i]->setVal(E_external_grid[i]); - } - } - if (B_ext_grid_s == "parse_b_ext_grid_function") { - - InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), - Bfield_aux[lev][1].get(), - Bfield_aux[lev][2].get(), - str_Bx_ext_grid_function, - str_By_ext_grid_function, - str_Bz_ext_grid_function, - Bx_nodal_flag, By_nodal_flag, - Bz_nodal_flag, lev); - - InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), - Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get(), - str_Bx_ext_grid_function, - str_By_ext_grid_function, - str_Bz_ext_grid_function, - Bx_nodal_flag, By_nodal_flag, - Bz_nodal_flag, lev); - - } - if (E_ext_grid_s == "parse_e_ext_grid_function") { - - InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), - Efield_aux[lev][1].get(), - Efield_aux[lev][2].get(), - str_Ex_ext_grid_function, - str_Ey_ext_grid_function, - str_Ez_ext_grid_function, - Ex_nodal_flag, Ey_nodal_flag, - Ez_nodal_flag, lev); - - InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), - Efield_cp[lev][1].get(), - Efield_cp[lev][2].get(), - str_Ex_ext_grid_function, - str_Ey_ext_grid_function, - str_Ez_ext_grid_function, - Ex_nodal_flag, Ey_nodal_flag, - Ez_nodal_flag, lev); - } + if (lev > 0) { + InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), + Efield_aux[lev][1].get(), + Efield_aux[lev][2].get(), + str_Ex_ext_grid_function, + str_Ey_ext_grid_function, + str_Ez_ext_grid_function, + Ex_nodal_flag, Ey_nodal_flag, + Ez_nodal_flag, lev); + + InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), + Efield_cp[lev][1].get(), + Efield_cp[lev][2].get(), + str_Ex_ext_grid_function, + str_Ey_ext_grid_function, + str_Ez_ext_grid_function, + Ex_nodal_flag, Ey_nodal_flag, + Ez_nodal_flag, lev); + } } if (F_fp[lev]) { -- cgit v1.2.3 From a8b92c298b3c74d61b3dc3b1b3ddfa3f85b534f7 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 16:42:49 -0800 Subject: adding comment regarding external EB values that are constant --- Source/Initialization/WarpXInitData.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 6ed0dbed2..7a31267c1 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -286,6 +286,9 @@ WarpX::InitLevelData (int lev, Real time) } } + // if the input string is "constant", the values for the + // external field on the grid must be provided in the input file. + if (B_ext_grid_s == "parse_b_ext_grid_function") { Store_parserString("Bx_external_grid_function(x,y,z)", -- cgit v1.2.3 From 1ef0e65b956b8c6cf789c3a9ef9b565a221cce49 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 17:33:04 -0800 Subject: fixing style --- Source/Initialization/WarpXInitData.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 7a31267c1..2390ee4ec 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -286,8 +286,8 @@ WarpX::InitLevelData (int lev, Real time) } } - // if the input string is "constant", the values for the - // external field on the grid must be provided in the input file. + // if the input string is "constant", the values for the + // external field on the grid must be provided in the input file. if (B_ext_grid_s == "parse_b_ext_grid_function") { -- cgit v1.2.3 From 14b8a62600b323b42f264237fe3b4562ab345600 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 17:42:07 -0800 Subject: correcting comment --- Source/Initialization/WarpXInitData.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 2390ee4ec..ea7437183 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -286,9 +286,9 @@ WarpX::InitLevelData (int lev, Real time) } } - // if the input string is "constant", the values for the - // external field on the grid must be provided in the input file. - + // if the input string for the B-field is "parse_b_ext_grid_function", + // then the analytical expression or function must be + // provided in the input file. if (B_ext_grid_s == "parse_b_ext_grid_function") { Store_parserString("Bx_external_grid_function(x,y,z)", @@ -327,6 +327,9 @@ WarpX::InitLevelData (int lev, Real time) } } + // if the input string for the E-field is "parse_e_ext_grid_function", + // then the analytical expression or function must be + // provided in the input file. if (E_ext_grid_s == "parse_e_ext_grid_function") { Store_parserString("Ex_external_grid_function(x,y,z)", -- cgit v1.2.3 From 049f99ef7841b2760d92424c7b460ff608e5e2c3 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 6 Jan 2020 17:47:20 -0800 Subject: fixing EOL whitespace --- Source/Initialization/WarpXInitData.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index ea7437183..2c9c83676 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -286,9 +286,9 @@ WarpX::InitLevelData (int lev, Real time) } } - // if the input string for the B-field is "parse_b_ext_grid_function", - // then the analytical expression or function must be - // provided in the input file. + // if the input string for the B-field is "parse_b_ext_grid_function", + // then the analytical expression or function must be + // provided in the input file. if (B_ext_grid_s == "parse_b_ext_grid_function") { Store_parserString("Bx_external_grid_function(x,y,z)", @@ -327,9 +327,9 @@ WarpX::InitLevelData (int lev, Real time) } } - // if the input string for the E-field is "parse_e_ext_grid_function", - // then the analytical expression or function must be - // provided in the input file. + // if the input string for the E-field is "parse_e_ext_grid_function", + // then the analytical expression or function must be + // provided in the input file. if (E_ext_grid_s == "parse_e_ext_grid_function") { Store_parserString("Ex_external_grid_function(x,y,z)", -- cgit v1.2.3 From 2915558864672dbd32a3bfbd56096ac0e378056b Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 7 Jan 2020 13:20:29 -0800 Subject: mmodifying shiftMF to read in stored field_parser instead of parsing the function --- Source/Initialization/WarpXInitData.cpp | 72 ++++++++++++++++-------------- Source/Utils/WarpXMovingWindow.cpp | 78 ++++++++++----------------------- Source/Utils/WarpXUtil.cpp | 2 - Source/WarpX.H | 19 ++++++-- 4 files changed, 76 insertions(+), 95 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 2c9c83676..534ffb0a8 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -297,31 +297,39 @@ WarpX::InitLevelData (int lev, Real time) str_By_ext_grid_function); Store_parserString("Bz_external_grid_function(x,y,z)", str_Bz_ext_grid_function); + + Bxfield_parser.reset(new ParserWrapper( + makeParser(str_Bx_ext_grid_function))); + Byfield_parser.reset(new ParserWrapper( + makeParser(str_By_ext_grid_function))); + Bzfield_parser.reset(new ParserWrapper( + makeParser(str_Bz_ext_grid_function))); + // Initialize Bfield_fp with external function InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), Bfield_fp[lev][2].get(), - str_Bx_ext_grid_function, - str_By_ext_grid_function, - str_Bz_ext_grid_function, + Bxfield_parser.get(), + Byfield_parser.get(), + Bzfield_parser.get(), Bx_nodal_flag, By_nodal_flag, Bz_nodal_flag, lev); if (lev > 0) { InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), Bfield_aux[lev][1].get(), Bfield_aux[lev][2].get(), - str_Bx_ext_grid_function, - str_By_ext_grid_function, - str_Bz_ext_grid_function, + Bxfield_parser.get(), + Byfield_parser.get(), + Bzfield_parser.get(), Bx_nodal_flag, By_nodal_flag, Bz_nodal_flag, lev); InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), Bfield_cp[lev][2].get(), - str_Bx_ext_grid_function, - str_By_ext_grid_function, - str_Bz_ext_grid_function, + Bxfield_parser.get(), + Byfield_parser.get(), + Bzfield_parser.get(), Bx_nodal_flag, By_nodal_flag, Bz_nodal_flag, lev); } @@ -339,31 +347,38 @@ WarpX::InitLevelData (int lev, Real time) Store_parserString("Ez_external_grid_function(x,y,z)", str_Ez_ext_grid_function); + Exfield_parser.reset(new ParserWrapper( + makeParser(str_Ex_ext_grid_function))); + Eyfield_parser.reset(new ParserWrapper( + makeParser(str_Ey_ext_grid_function))); + Ezfield_parser.reset(new ParserWrapper( + makeParser(str_Ez_ext_grid_function))); + // Initialize Efield_fp with external function InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), Efield_fp[lev][2].get(), - str_Ex_ext_grid_function, - str_Ey_ext_grid_function, - str_Ez_ext_grid_function, + Exfield_parser.get(), + Eyfield_parser.get(), + Ezfield_parser.get(), Ex_nodal_flag, Ey_nodal_flag, Ez_nodal_flag, lev); if (lev > 0) { InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), Efield_aux[lev][1].get(), Efield_aux[lev][2].get(), - str_Ex_ext_grid_function, - str_Ey_ext_grid_function, - str_Ez_ext_grid_function, + Exfield_parser.get(), + Eyfield_parser.get(), + Ezfield_parser.get(), Ex_nodal_flag, Ey_nodal_flag, Ez_nodal_flag, lev); InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get(), - str_Ex_ext_grid_function, - str_Ey_ext_grid_function, - str_Ez_ext_grid_function, + Exfield_parser.get(), + Eyfield_parser.get(), + Ezfield_parser.get(), Ex_nodal_flag, Ey_nodal_flag, Ez_nodal_flag, lev); } @@ -428,22 +443,11 @@ WarpX::InitLevelDataFFT (int lev, Real time) void WarpX::InitializeExternalFieldsOnGridUsingParser ( MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, - const std::string x_function, const std::string y_function, - const std::string z_function, IntVect x_nodal_flag, + ParserWrapper *xfield_parser, ParserWrapper *yfield_parser, + ParserWrapper *zfield_parser, IntVect x_nodal_flag, IntVect y_nodal_flag, IntVect z_nodal_flag, const int lev) { - std::unique_ptr xfield_parsewrap; - std::unique_ptr yfield_parsewrap; - std::unique_ptr zfield_parsewrap; - - xfield_parsewrap.reset(new ParserWrapper(makeParser(x_function))); - yfield_parsewrap.reset(new ParserWrapper(makeParser(y_function))); - zfield_parsewrap.reset(new ParserWrapper(makeParser(z_function))); - - ParserWrapper *xfield_wrap = xfield_parsewrap.get(); - ParserWrapper *yfield_wrap = yfield_parsewrap.get(); - ParserWrapper *zfield_wrap = zfield_parsewrap.get(); const auto dx_lev = geom[lev].CellSizeArray(); const RealBox& real_box = geom[lev].ProbDomain(); @@ -490,7 +494,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif // Initialize the x-component of the field. - mfxfab(i,j,k) = xfield_wrap->getField(x,y,z); + mfxfab(i,j,k) = xfield_parser->getField(x,y,z); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { Real fac_x = (1.0 - mfy_type[0]) * dx_lev[0]*0.5; @@ -506,7 +510,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif // Initialize the y-component of the field. - mfyfab(i,j,k) = yfield_wrap->getField(x,y,z); + mfyfab(i,j,k) = yfield_parser->getField(x,y,z); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { Real fac_x = (1.0 - mfz_type[0]) * dx_lev[0]*0.5; @@ -522,7 +526,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( Real z = k*dx_lev[2] + real_box.lo(2) + fac_z; #endif // Initialize the z-component of the field. - mfzfab(i,j,k) = zfield_wrap->getField(x,y,z); + mfzfab(i,j,k) = zfield_parser->getField(x,y,z); }, amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 ); diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index 247c89869..c1c83d847 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -101,9 +101,25 @@ WarpX::MoveWindow (bool move_j) // Fine grid // initialize with external field = true and B_flag = true; - shiftMF(*Bfield_fp[lev][dim], geom[lev], num_shift, dir, true, true); + ParserWrapper *Bfield_parser; + ParserWrapper *Efield_parser; + bool use_Bparser = false; + bool use_Eparser = false; + if (B_ext_grid_s == "parse_b_ext_grid_function") { + use_Bparser = true; + if (dim == 0) Bfield_parser = Bxfield_parser.get(); + if (dim == 1) Bfield_parser = Byfield_parser.get(); + if (dim == 2) Bfield_parser = Bzfield_parser.get(); + } + shiftMF(*Bfield_fp[lev][dim], geom[lev], num_shift, dir, B_external_grid[dim], use_Bparser, Bfield_parser); // initialize with external field = true and B_flag = false; - shiftMF(*Efield_fp[lev][dim], geom[lev], num_shift, dir, true, false); + if (E_ext_grid_s == "parse_e_ext_grid_function") { + use_Eparser = true; + if (dim == 0) Efield_parser = Exfield_parser.get(); + if (dim == 1) Efield_parser = Eyfield_parser.get(); + if (dim == 2) Efield_parser = Ezfield_parser.get(); + } + shiftMF(*Efield_fp[lev][dim], geom[lev], num_shift, dir, E_external_grid[dim], use_Eparser, Efield_parser); if (move_j) { shiftMF(*current_fp[lev][dim], geom[lev], num_shift, dir); } @@ -117,9 +133,9 @@ WarpX::MoveWindow (bool move_j) if (lev > 0) { // Coarse grid // initialize with external field = true and B_flag = true; - shiftMF(*Bfield_cp[lev][dim], geom[lev-1], num_shift_crse, dir, true, true); + shiftMF(*Bfield_cp[lev][dim], geom[lev-1], num_shift_crse, dir, B_external_grid[dim], use_Bparser, Bfield_parser); // initialize with external field = true and B_flag = false; - shiftMF(*Efield_cp[lev][dim], geom[lev-1], num_shift_crse, dir, true, false); + shiftMF(*Efield_cp[lev][dim], geom[lev-1], num_shift_crse, dir, E_external_grid[dim], use_Eparser, Efield_parser); shiftMF(*Bfield_aux[lev][dim], geom[lev], num_shift, dir); shiftMF(*Efield_aux[lev][dim], geom[lev], num_shift, dir); if (move_j) { @@ -137,7 +153,7 @@ WarpX::MoveWindow (bool move_j) // Shift scalar component F for dive cleaning if (do_dive_cleaning) { // Fine grid - shiftMF(*F_fp[lev], geom[lev], num_shift, dir); + shiftMF(*F_fp[lev], geom[lev], num_shift, dir); if (do_pml && pml[lev]->ok()) { MultiFab* pml_F = pml[lev]->GetF_fp(); shiftMF(*pml_F, geom[lev], num_shift, dir); @@ -209,15 +225,13 @@ WarpX::MoveWindow (bool move_j) void WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, - bool ext_init, bool B_flag) + amrex::Real external_field, bool useparser, ParserWrapper *field_parser) { BL_PROFILE("WarpX::shiftMF()"); const BoxArray& ba = mf.boxArray(); const DistributionMapping& dm = mf.DistributionMap(); const int nc = mf.nComp(); const IntVect& ng = mf.nGrowVect(); - // default value of external_field = 0.0 for initialization of mf - amrex::Real external_field = 0.0; AMREX_ALWAYS_ASSERT(ng.min() >= num_shift); @@ -255,51 +269,6 @@ WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, const RealBox& real_box = geom.ProbDomain(); const auto dx = geom.CellSizeArray(); - std::unique_ptr field_parsewrap; - bool useparser = false; - - if (ext_init == true && B_flag == true) { - if (B_ext_grid_s == "constant" || B_ext_grid_s == "default") - external_field = B_external_grid[dir]; - if (B_ext_grid_s == "parse_b_ext_grid_function") { - useparser = true; - if (dir==0) - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Bx_ext_grid_function))); - if (dir==1) -#if (AMREX_SPACEDIM==2) - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Bz_ext_grid_function))); -#else - field_parsewrap.reset(new ParserWrapper( - makeParser(str_By_ext_grid_function))); -#endif - if (dir==2) - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Bz_ext_grid_function))); - } - } - if (ext_init == true && B_flag == false) { - if (E_ext_grid_s == "constant" || E_ext_grid_s == "default") - external_field = E_external_grid[dir]; - if (E_ext_grid_s == "parse_e_ext_grid_function") { - if (dir==0) - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Ex_ext_grid_function))); - if (dir==1) -#if (AMREX_SPACEDIM==2) - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Ez_ext_grid_function))); -#else - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Ey_ext_grid_function))); -#endif - if (dir==2) - field_parsewrap.reset(new ParserWrapper( - makeParser(str_Ez_ext_grid_function))); - useparser = true; - } - } #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -326,7 +295,6 @@ WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { mf_type[idim] = mf_IndexType.nodeCentered(idim); } - ParserWrapper *field_wrap = field_parsewrap.get(); amrex::ParallelFor (outbox, nc, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept @@ -344,7 +312,7 @@ WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, Real fac_z = (1.0 - mf_type[2]) * dx[2]*0.5; Real z = k*dx[2] + real_box.lo(2) + fac_z; #endif - srcfab(i,j,k,n) = field_wrap->getField(x,y,z); + srcfab(i,j,k,n) = field_parser->getField(x,y,z); } , amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double)*3 ); diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 152eaba07..4dabee8b6 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -183,7 +183,6 @@ void Store_parserString(std::string query_string, } -//namespace { WarpXParser makeParser (std::string const& parse_function) { WarpXParser parser(parse_function); @@ -207,4 +206,3 @@ WarpXParser makeParser (std::string const& parse_function) } return parser; } -//} diff --git a/Source/WarpX.H b/Source/WarpX.H index 68e84c611..f4b892e45 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -94,8 +94,10 @@ public: MultiParticleContainer& GetPartContainer () { return *mypc; } - static void shiftMF (amrex::MultiFab& mf, const amrex::Geometry& geom, int num_shift, int dir, - bool ext_init=false, bool B_flag=false); + static void shiftMF (amrex::MultiFab& mf, const amrex::Geometry& geom, + int num_shift, int dir, amrex::Real external_field=0.0, + bool useparser = false, + ParserWrapper *field_parser=nullptr); static void GotoNextLine (std::istream& is); @@ -120,6 +122,15 @@ public: static std::string str_Ey_ext_grid_function; static std::string str_Ez_ext_grid_function; + // ParserWrapper for B_external on the grid + std::unique_ptr Bxfield_parser; + std::unique_ptr Byfield_parser; + std::unique_ptr Bzfield_parser; + // ParserWrapper for E_external on the grid + std::unique_ptr Exfield_parser; + std::unique_ptr Eyfield_parser; + std::unique_ptr Ezfield_parser; + // Algorithms static long current_deposition_algo; static long charge_deposition_algo; @@ -391,8 +402,8 @@ public: */ void InitializeExternalFieldsOnGridUsingParser ( amrex::MultiFab *mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, - const std::string x_function, const std::string y_function, - const std::string z_function, amrex::IntVect x_nodal_flag, + ParserWrapper *xfield_parser, ParserWrapper *yfield_parser, + ParserWrapper *zfield_parser, amrex::IntVect x_nodal_flag, amrex::IntVect y_nodal_flag, amrex::IntVect z_nodal_flag, const int lev); protected: -- cgit v1.2.3 From 11f2f2e55d0e940f2262cb97ab5d03633c863fad Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 7 Jan 2020 17:53:50 -0800 Subject: added ParmParse object in Store_parserString --- Source/Initialization/WarpXInitData.cpp | 12 ++++++------ Source/Utils/WarpXUtil.H | 4 +++- Source/Utils/WarpXUtil.cpp | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 534ffb0a8..6d59ce34d 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -291,11 +291,11 @@ WarpX::InitLevelData (int lev, Real time) // provided in the input file. if (B_ext_grid_s == "parse_b_ext_grid_function") { - Store_parserString("Bx_external_grid_function(x,y,z)", + Store_parserString(pp, "Bx_external_grid_function(x,y,z)", str_Bx_ext_grid_function); - Store_parserString("By_external_grid_function(x,y,z)", + Store_parserString(pp, "By_external_grid_function(x,y,z)", str_By_ext_grid_function); - Store_parserString("Bz_external_grid_function(x,y,z)", + Store_parserString(pp, "Bz_external_grid_function(x,y,z)", str_Bz_ext_grid_function); Bxfield_parser.reset(new ParserWrapper( @@ -340,11 +340,11 @@ WarpX::InitLevelData (int lev, Real time) // provided in the input file. if (E_ext_grid_s == "parse_e_ext_grid_function") { - Store_parserString("Ex_external_grid_function(x,y,z)", + Store_parserString(pp, "Ex_external_grid_function(x,y,z)", str_Ex_ext_grid_function); - Store_parserString("Ey_external_grid_function(x,y,z)", + Store_parserString(pp, "Ey_external_grid_function(x,y,z)", str_Ey_ext_grid_function); - Store_parserString("Ez_external_grid_function(x,y,z)", + Store_parserString(pp, "Ez_external_grid_function(x,y,z)", str_Ez_ext_grid_function); Exfield_parser.reset(new ParserWrapper( diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H index cdba7cd6d..fa4930ba6 100644 --- a/Source/Utils/WarpXUtil.H +++ b/Source/Utils/WarpXUtil.H @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -20,11 +21,12 @@ void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, * \brief Parse a string (typically a mathematical expression) from the * input file and store it into a variable. * + * \param ParmParse pp used to read the query_string pp.=string * \param parmparse_string String used to initialize ParmParse * \param query_string ParmParse.query will look for this string * \param stored_string variable in which the string to parse is stored */ -void Store_parserString(std::string query_string, +void Store_parserString(amrex::ParmParse &pp, std::string query_string, std::string& stored_string); namespace WarpXUtilIO{ diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 4dabee8b6..e9fb958fd 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -164,11 +164,10 @@ namespace WarpXUtilIO{ } } -void Store_parserString(std::string query_string, +void Store_parserString(amrex::ParmParse& pp, std::string query_string, std::string& stored_string) { - ParmParse pp("warpx"); char cstr[query_string.size()+1]; strcpy(cstr, query_string.c_str()); -- cgit v1.2.3 From 3a2d78c64e4af140d376df126755e94f87261e32 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Wed, 8 Jan 2020 11:00:54 -0800 Subject: RZ abor message --- Docs/source/running_cpp/parameters.rst | 4 ++++ Source/Initialization/WarpXInitData.cpp | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 22580cd56..f49edc106 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -656,6 +656,8 @@ Laser initialization then the constants `Bo` and `delta` required in the above equation can be set using ``my_constants.Bo=`` and ``my_constants.delta=`` in the input file. For a two-dimensional simulation, it is assumed that the first dimension is `x` and the second dimension in `z`, and the value of `y` is set to zero. + Note that the current implementation of the parser for external B-field + does not work with RZ and the code will abort with an error message. * ``warpx.E_ext_grid_init_style`` (string) optional (default is "default") This parameter determines the type of initialization for the external @@ -679,6 +681,8 @@ Laser initialization input file. For a two-dimensional simulation, it is assumed that the first dimension is `x` and the second dimension in `z`, and the value of `y` is set to zero. + Note that the current implementation of the parser for external E-field + does not work with RZ and the code will abort with an error message. * ``warpx.E_external_grid`` & ``warpx.B_external_grid`` (list of `int`) required when ``warpx.B_ext_grid_init_style="parse_B_ext_grid_function"`` diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 6d59ce34d..f4c2afd57 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -291,6 +291,9 @@ WarpX::InitLevelData (int lev, Real time) // provided in the input file. if (B_ext_grid_s == "parse_b_ext_grid_function") { +#ifdef WARPX_DIM_RZ + amrex::Abort("E and B parser for external fields does not work with RZ -- TO DO"); +#endif Store_parserString(pp, "Bx_external_grid_function(x,y,z)", str_Bx_ext_grid_function); Store_parserString(pp, "By_external_grid_function(x,y,z)", @@ -340,6 +343,9 @@ WarpX::InitLevelData (int lev, Real time) // provided in the input file. if (E_ext_grid_s == "parse_e_ext_grid_function") { +#ifdef WARPX_DIM_RZ + amrex::Abort("E and B parser for external fields does not work with RZ -- TO DO"); +#endif Store_parserString(pp, "Ex_external_grid_function(x,y,z)", str_Ex_ext_grid_function); Store_parserString(pp, "Ey_external_grid_function(x,y,z)", -- cgit v1.2.3 From de900bcb42c5c255133832a978f9cd73e22e246c Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Wed, 8 Jan 2020 16:50:18 -0800 Subject: changes to docs, additional comments, and ParserWrapper file from PR suggestion --- Docs/source/running_cpp/parameters.rst | 2 +- Examples/Physics_applications/plasma_acceleration/inputs.3d.boost | 2 +- Source/Initialization/WarpXInitData.cpp | 2 ++ Source/Parser/Make.package | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) (limited to 'Source/Initialization/WarpXInitData.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index f49edc106..c5d1600d3 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -673,7 +673,7 @@ Laser initialization ``warpx.Ex_external_grid_function(x,y,z)``, ``warpx.Ey_external_grid_function(x,y,z)``, ``warpx.Ez_externail_grid_function(x,y,z)`` to initialize the external - magnetic field for each of the three components on the grid. + electric field for each of the three components on the grid. Constants required in the expression can be set using ``my_constants``. For example, if ``warpx.Ex_external_grid_function(x,y,z)=Eo*x + delta*(y + z)`` then the constants `Bo` and `delta` required in the above equation diff --git a/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost b/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost index f65c9aa0a..84ab18cf9 100644 --- a/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost +++ b/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost @@ -2,7 +2,7 @@ ####### GENERAL PARAMETERS ###### ################################# stop_time = 3.93151387287e-11 -amr.n_cell = 32 32 256 +amr.n_cell = 64 64 256 amr.max_grid_size = 64 amr.blocking_factor = 32 amr.max_level = 0 diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index f4c2afd57..be29a1cbc 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -534,6 +534,8 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( // Initialize the z-component of the field. mfzfab(i,j,k) = zfield_parser->getField(x,y,z); }, + /* To allocate shared memory for the GPU threads. */ + /* But, for now only 3 doubles (x,y,z) are allocated. */ amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 ); diff --git a/Source/Parser/Make.package b/Source/Parser/Make.package index 5ce02cbda..15115c138 100644 --- a/Source/Parser/Make.package +++ b/Source/Parser/Make.package @@ -5,6 +5,7 @@ CEXE_sources += WarpXParser.cpp CEXE_headers += WarpXParser.H CEXE_headers += GpuParser.H CEXE_sources += GpuParser.cpp +CEXE_headers += WarpXParserWrapper.H INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Parser VPATH_LOCATIONS += $(WARPX_HOME)/Source/Parser -- cgit v1.2.3