diff options
Diffstat (limited to 'Source/Initialization')
-rw-r--r-- | Source/Initialization/CustomDensityProb.H | 6 | ||||
-rw-r--r-- | Source/Initialization/CustomMomentumProb.H | 6 | ||||
-rw-r--r-- | Source/Initialization/InitSpaceChargeField.cpp | 6 | ||||
-rw-r--r-- | Source/Initialization/InjectorDensity.H | 7 | ||||
-rw-r--r-- | Source/Initialization/InjectorDensity.cpp | 11 | ||||
-rw-r--r-- | Source/Initialization/InjectorMomentum.H | 7 | ||||
-rw-r--r-- | Source/Initialization/InjectorMomentum.cpp | 11 | ||||
-rw-r--r-- | Source/Initialization/InjectorPosition.H | 7 | ||||
-rw-r--r-- | Source/Initialization/PlasmaInjector.H | 8 | ||||
-rw-r--r-- | Source/Initialization/PlasmaInjector.cpp | 65 | ||||
-rw-r--r-- | Source/Initialization/WarpXInitData.cpp | 277 |
11 files changed, 348 insertions, 63 deletions
diff --git a/Source/Initialization/CustomDensityProb.H b/Source/Initialization/CustomDensityProb.H index c5c159ee8..804b56ce8 100644 --- a/Source/Initialization/CustomDensityProb.H +++ b/Source/Initialization/CustomDensityProb.H @@ -1,3 +1,9 @@ +/* Copyright 2019 Maxence Thevenet, Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef CUSTOM_DENSITY_PROB_H_ #define CUSTOM_DENSITY_PROB_H_ diff --git a/Source/Initialization/CustomMomentumProb.H b/Source/Initialization/CustomMomentumProb.H index f8bc29a05..0b4d531c7 100644 --- a/Source/Initialization/CustomMomentumProb.H +++ b/Source/Initialization/CustomMomentumProb.H @@ -1,3 +1,9 @@ +/* Copyright 2019 Maxence Thevenet, Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef CUSTOM_MOMENTUM_PROB_H #define CUSTOM_MOMENTUM_PROB_H diff --git a/Source/Initialization/InitSpaceChargeField.cpp b/Source/Initialization/InitSpaceChargeField.cpp index 0a873b742..36914d2c6 100644 --- a/Source/Initialization/InitSpaceChargeField.cpp +++ b/Source/Initialization/InitSpaceChargeField.cpp @@ -1,3 +1,9 @@ +/* Copyright 2019 Remi Lehe + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #include <AMReX_ParallelDescriptor.H> #include <AMReX_MLMG.H> diff --git a/Source/Initialization/InjectorDensity.H b/Source/Initialization/InjectorDensity.H index 7e61ae27d..4558eeb96 100644 --- a/Source/Initialization/InjectorDensity.H +++ b/Source/Initialization/InjectorDensity.H @@ -1,3 +1,10 @@ +/* Copyright 2019 Axel Huebl, Maxence Thevenet, Weiqun Zhang + * + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef INJECTOR_DENSITY_H_ #define INJECTOR_DENSITY_H_ diff --git a/Source/Initialization/InjectorDensity.cpp b/Source/Initialization/InjectorDensity.cpp index 9f711a7af..f59202db9 100644 --- a/Source/Initialization/InjectorDensity.cpp +++ b/Source/Initialization/InjectorDensity.cpp @@ -1,3 +1,10 @@ +/* Copyright 2019-2020 Axel Huebl, Ligia Diana Amorim, Maxence Thevenet + * Revathi Jambunathan, Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #include <InjectorDensity.H> #include <PlasmaInjector.H> @@ -36,8 +43,8 @@ InjectorDensity::sharedMemoryNeeded () const noexcept case Type::parser: { // For parser injector, the 3D position of each particle - // is stored in shared memory. - return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3; + // and time, t, is stored in shared memory. + return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4; } default: return 0; diff --git a/Source/Initialization/InjectorMomentum.H b/Source/Initialization/InjectorMomentum.H index 88c954df6..bb5a70784 100644 --- a/Source/Initialization/InjectorMomentum.H +++ b/Source/Initialization/InjectorMomentum.H @@ -1,3 +1,10 @@ +/* Copyright 2019 Axel Huebl, Cameron Yang, Maxence Thevenet + * Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef INJECTOR_MOMENTUM_H_ #define INJECTOR_MOMENTUM_H_ diff --git a/Source/Initialization/InjectorMomentum.cpp b/Source/Initialization/InjectorMomentum.cpp index 8fadf0c4b..edbba8ac5 100644 --- a/Source/Initialization/InjectorMomentum.cpp +++ b/Source/Initialization/InjectorMomentum.cpp @@ -1,3 +1,10 @@ +/* Copyright 2019-2020 Axel Huebl, Maxence Thevenet, Revathi Jambunathan + * Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #include <InjectorMomentum.H> #include <PlasmaInjector.H> @@ -30,9 +37,9 @@ InjectorMomentum::sharedMemoryNeeded () const noexcept { case Type::parser: { - // For parser injector, the 3D position of each particle + // For parser injector, the 3D position of each particle and time, t, // is stored in shared memory. - return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3; + return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4; } default: return 0; diff --git a/Source/Initialization/InjectorPosition.H b/Source/Initialization/InjectorPosition.H index 4ab2fa022..a8d2200e9 100644 --- a/Source/Initialization/InjectorPosition.H +++ b/Source/Initialization/InjectorPosition.H @@ -1,3 +1,10 @@ +/* Copyright 2019 Axel Huebl, David Grote, Maxence Thevenet + * Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef INJECTOR_POSITION_H_ #define INJECTOR_POSITION_H_ diff --git a/Source/Initialization/PlasmaInjector.H b/Source/Initialization/PlasmaInjector.H index 56b32c827..70d99b9a3 100644 --- a/Source/Initialization/PlasmaInjector.H +++ b/Source/Initialization/PlasmaInjector.H @@ -1,3 +1,11 @@ +/* Copyright 2019 Andrew Myers, Axel Huebl, David Grote + * Maxence Thevenet, Remi Lehe, Weiqun Zhang + * + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef PLASMA_INJECTOR_H_ #define PLASMA_INJECTOR_H_ diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index f7c7e498f..96e82d749 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -1,8 +1,18 @@ +/* Copyright 2019-2020 Andrew Myers, Axel Huebl, Cameron Yang + * David Grote, Luca Fedeli, Maxence Thevenet + * Remi Lehe, Revathi Jambunathan, Weiqun Zhang + * + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #include "PlasmaInjector.H" #include <WarpXConst.H> #include <WarpX_f.H> #include <WarpX.H> +#include <WarpXUtil.H> #include <AMReX.H> @@ -168,34 +178,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<std::string> 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. @@ -217,11 +199,7 @@ void PlasmaInjector::parseDensity (ParmParse& pp) // Construct InjectorDensity with InjectorDensityPredefined. inj_rho.reset(new InjectorDensity((InjectorDensityPredefined*)nullptr,species_name)); } else if (rho_prof_s == "parse_density_function") { - std::vector<std::string> f; - pp.getarr("density_function(x,y,z)", f); - for (auto const& s : f) { - str_density_function += s; - } + Store_parserString(pp, "density_function(x,y,z)", str_density_function); // Construct InjectorDensity with InjectorDensityParser. inj_rho.reset(new InjectorDensity((InjectorDensityParser*)nullptr, makeParser(str_density_function))); @@ -339,21 +317,12 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) inj_mom.reset(new InjectorMomentum ((InjectorMomentumRadialExpansion*)nullptr, u_over_r)); } else if (mom_dist_s == "parse_momentum_function") { - std::vector<std::string> f; - pp.getarr("momentum_function_ux(x,y,z)", f); - for (auto const& s : f) { - str_momentum_function_ux += s; - } - f.clear(); - pp.getarr("momentum_function_uy(x,y,z)", f); - for (auto const& s : f) { - str_momentum_function_uy += s; - } - f.clear(); - pp.getarr("momentum_function_uz(x,y,z)", f); - for (auto const& s : f) { - str_momentum_function_uz += s; - } + Store_parserString(pp, "momentum_function_ux(x,y,z)", + str_momentum_function_ux); + Store_parserString(pp, "momentum_function_uy(x,y,z)", + str_momentum_function_uy); + Store_parserString(pp, "momentum_function_uz(x,y,z)", + str_momentum_function_uz); // Construct InjectorMomentum with InjectorMomentumParser. inj_mom.reset(new InjectorMomentum((InjectorMomentumParser*)nullptr, makeParser(str_momentum_function_ux), diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 29c9a8955..8b2fe1831 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -1,4 +1,12 @@ - +/* Copyright 2019-2020 Andrew Myers, Ann Almgren, Aurore Blelly + * Axel Huebl, Burlen Loring, Maxence Thevenet + * Remi Lehe, Revathi Jambunathan, Weiqun Zhang + * + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #include <WarpX.H> #include <WarpX_f.H> #include <BilinearFilter.H> @@ -10,6 +18,9 @@ #ifdef BL_USE_SENSEI_INSITU #include <AMReX_AmrMeshInSituBridge.H> #endif +#include <GpuParser.H> +#include <WarpXUtil.H> + using namespace amrex; @@ -72,11 +83,21 @@ WarpX::InitData () if (plot_int > 0) WritePlotFile(); + if (openpmd_int > 0) + WriteOpenPMDFile(); + if (check_int > 0) WriteCheckPointFile(); if ((insitu_int > 0) && (insitu_start == 0)) UpdateInSitu(); + + // Write reduced diagnostics before the first iteration. + if (reduced_diags->m_plot_rd != 0) + { + reduced_diags->ComputeDiags(-1); + reduced_diags->WriteToFile(-1); + } } } @@ -231,24 +252,161 @@ WarpX::PostRestart () mypc->PostRestart(); } + void WarpX::InitLevelData (int lev, Real time) { + + ParmParse pp("warpx"); + + // 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. + 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); + + 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 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); + 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 (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 (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 (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]); + // 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") { - 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]); - } +#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)", + str_By_ext_grid_function); + Store_parserString(pp, "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(), + 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(), + 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(), + Bxfield_parser.get(), + Byfield_parser.get(), + Bzfield_parser.get(), + Bx_nodal_flag, By_nodal_flag, + Bz_nodal_flag, lev); + } + } + + // 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") { + +#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)", + str_Ey_ext_grid_function); + Store_parserString(pp, "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(), + 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(), + 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(), + Exfield_parser.get(), + Eyfield_parser.get(), + Ezfield_parser.get(), + Ex_nodal_flag, Ey_nodal_flag, + Ez_nodal_flag, lev); + } } if (F_fp[lev]) { @@ -306,3 +464,100 @@ WarpX::InitLevelDataFFT (int lev, Real time) } #endif + +void +WarpX::InitializeExternalFieldsOnGridUsingParser ( + MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, + ParserWrapper *xfield_parser, ParserWrapper *yfield_parser, + ParserWrapper *zfield_parser, IntVect x_nodal_flag, + IntVect y_nodal_flag, IntVect z_nodal_flag, + const int lev) +{ + + const auto dx_lev = geom[lev].CellSizeArray(); + const RealBox& real_box = geom[lev].ProbDomain(); + for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + 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)); + 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) { + // 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 x = i*dx_lev[0] + real_box.lo(0) + fac_x; +#if (AMREX_SPACEDIM==2) + 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 + // Initialize the x-component of the field. + 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; + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; +#if (AMREX_SPACEDIM==2) + 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 - 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. + 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; + Real x = i*dx_lev[0] + real_box.lo(0) + fac_x; +#if (AMREX_SPACEDIM==2) + 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 + // 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 4 doubles (x,y,z,t) are allocated. */ + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4 + ); + + } + +} |