Skip to content

Commit

Permalink
add new option to initialize external fields on grid upto a max user…
Browse files Browse the repository at this point in the history
…-defined level
  • Loading branch information
RevathiJambunathan committed Sep 27, 2023
1 parent f52205b commit 40bd951
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^

Expand Down
11 changes: 11 additions & 0 deletions Source/Initialization/WarpXInitData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public:
//! User-defined parser to initialize z-component of the electric field on the grid
std::unique_ptr<amrex::Parser> 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;
Expand Down
3 changes: 3 additions & 0 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 40bd951

Please sign in to comment.