diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 27d7682899d..79ba8016e8e 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -1440,6 +1440,17 @@ Grid initialization the field solver. In particular, do not use any other boundary condition than periodic. +* ``warpx.maxlevel_extEMfield_init`` (default is maximum number of levels in the simulation) + With this parameter, the externally applied electric and magnetic fields with paramters + ``warpx.E_ext_grid_init_style="constant"``, + ``warpx.B_ext_grid_init_style="constant"``, + ``warpx.E_ext_grid_init_style="parse_E_ext_grid_function"`` and + ``warpx.B_ext_grid_init_style="parse_B_ext_grid_function"`` will not be initialized with the external field + for levels strictly greater than ``warpx.maxlevel_extEMfield_init``. For some mesh-refinement simulations, + the external fields are only applied to the parent grid and not the refined patches. In such cases, + ``warpx.maxlevel_extEMfield_init`` can be set to 0. Note that the other levels will be initialized to + a default value of 0. + Applied to Particles ^^^^^^^^^^^^^^^^^^^^ diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index bfac6db544d..1d255ce0c02 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -747,6 +747,17 @@ WarpX::InitLevelData (int lev, Real /*time*/) E_ext_grid_s.begin(), ::tolower); + // Externally imposed fields are only initialized until the user-defined maxlevel_extEMfield_init. + // The default maxlevel_extEMfield_init value is the total number of levels in the simulation + // Note that if the external fields are not provided, the fields, E and B, on all levels + // will still be initialized with the default value of 0. + if ( (B_ext_grid_s == "constant") || (B_ext_grid_s == "parse_b_ext_grid_function")) { + if (lev > maxlevel_extEMfield_init) continue; + } + if ( (E_ext_grid_s == "constant") || (E_ext_grid_s == "parse_e_ext_grid_function")) { + if (lev > maxlevel_extEMfield_init) continue; + } + // if the input string is "constant", the values for the // external grid must be provided in the input. if (B_ext_grid_s == "constant") diff --git a/Source/WarpX.H b/Source/WarpX.H index 7466bd92496..54e1bf430a1 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -159,6 +159,12 @@ public: //! User-defined parser to initialize z-component of the electric field on the grid std::unique_ptr Ezfield_parser; + /** Maximum level upto which the externally defined electric and magnetic fields are initialized. + * The default value is set to the max levels in the simulation. + * if lev > maxlevel_extEMfield_init, the fields on those levels will have a default value of 0 + */ + int maxlevel_extEMfield_init; + // Algorithms //! Integer that corresponds to the current deposition algorithm (Esirkepov, direct, Vay) static short current_deposition_algo; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 6857ad85bcf..1b1ae910243 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -734,6 +734,9 @@ WarpX::ReadParameters () add_external_E_field = true; } + maxlevel_extEMfield_init = maxLevel(); + pp_warpx.query("maxlevel_extEMfield_init", maxlevel_extEMfield_init); + electrostatic_solver_id = GetAlgorithmInteger(pp_warpx, "do_electrostatic"); // if an electrostatic solver is used, set the Maxwell solver to None if (electrostatic_solver_id != ElectrostaticSolverAlgo::None) {