WarpX
ElectrostaticSolver.H
Go to the documentation of this file.
1 /* Copyright 2021 Modern Electron
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_ELECTROSTATICSOLVER_H_
8 #define WARPX_ELECTROSTATICSOLVER_H_
9 
10 #include <AMReX_Array.H>
11 #include <AMReX_Geometry.H>
12 #include <AMReX_MultiFab.H>
13 #include <AMReX_MLMG.H>
14 #include <AMReX_REAL.H>
15 #include <AMReX_Parser.H>
16 
17 #include <array>
18 #include <string>
19 #include <utility>
20 
21 
23 
24  struct PhiCalculatorEB {
25 
26  amrex::Real t;
28 
30  amrex::Real operator()(const amrex::Real x, const amrex::Real z) const noexcept {
31  using namespace amrex::literals;
32  return potential_eb(x, 0.0_rt, z, t);
33  }
34 
36  amrex::Real operator()(const amrex::Real x, const amrex::Real y, const amrex::Real z) const noexcept {
37  return potential_eb(x, y, z, t);
38  }
39  };
40 
42  public:
43 
45  bool bcs_set = false;
46  std::array<bool, AMREX_SPACEDIM * 2> dirichlet_flag;
47  bool has_non_periodic = false;
48  bool phi_EB_only_t = true;
49 
50  void definePhiBCs (const amrex::Geometry& geom);
51 
52  void buildParsers ();
53  void buildParsersEB ();
54 
55  /* \brief Sets the EB potential string and updates the function parser
56  *
57  * \param [in] potential The string value of the potential
58  */
59  void setPotentialEB(const std::string& potential) {
60  potential_eb_str = potential;
61  buildParsersEB();
62  }
63 
64  [[nodiscard]] PhiCalculatorEB
65  getPhiEB(amrex::Real t) const noexcept
66  {
68  }
69 
70  // set default potentials to zero in order for current tests to pass
71  // but forcing the user to specify a potential might be better
72  std::string potential_xlo_str = "0";
73  std::string potential_xhi_str = "0";
74  std::string potential_ylo_str = "0";
75  std::string potential_yhi_str = "0";
76  std::string potential_zlo_str = "0";
77  std::string potential_zhi_str = "0";
78  std::string potential_eb_str = "0";
79 
88 
89  private:
90 
98  };
99 
105  private:
109 
110  public:
112  : m_e_field(std::move(e_field)) {}
113 
114  void operator()(amrex::MLMG & mlmg, int const lev) {
115  using namespace amrex::literals;
116 
117  mlmg.getGradSolution({m_e_field[lev]});
118  for (auto &field: m_e_field[lev]) {
119  field->mult(-1._rt);
120  }
121  }
122  };
123 } // namespace ElectrostaticSolver
124 
125 #endif // WARPX_ELECTROSTATICSOLVER_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
Definition: ElectrostaticSolver.H:104
amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > m_e_field
Definition: ElectrostaticSolver.H:108
EBCalcEfromPhiPerLevel(amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > e_field)
Definition: ElectrostaticSolver.H:111
void operator()(amrex::MLMG &mlmg, int const lev)
Definition: ElectrostaticSolver.H:114
Definition: ElectrostaticSolver.H:41
amrex::ParserExecutor< 1 > potential_xhi
Definition: ElectrostaticSolver.H:81
amrex::ParserExecutor< 1 > potential_yhi
Definition: ElectrostaticSolver.H:83
PhiCalculatorEB getPhiEB(amrex::Real t) const noexcept
Definition: ElectrostaticSolver.H:65
amrex::Parser potential_xlo_parser
Definition: ElectrostaticSolver.H:91
amrex::Parser potential_yhi_parser
Definition: ElectrostaticSolver.H:94
amrex::Parser potential_zlo_parser
Definition: ElectrostaticSolver.H:95
amrex::Parser potential_ylo_parser
Definition: ElectrostaticSolver.H:93
amrex::ParserExecutor< 1 > potential_zlo
Definition: ElectrostaticSolver.H:84
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > hibc
Definition: ElectrostaticSolver.H:44
amrex::ParserExecutor< 1 > potential_xlo
Definition: ElectrostaticSolver.H:80
void setPotentialEB(const std::string &potential)
Definition: ElectrostaticSolver.H:59
amrex::ParserExecutor< 1 > potential_ylo
Definition: ElectrostaticSolver.H:82
amrex::ParserExecutor< 1 > potential_zhi
Definition: ElectrostaticSolver.H:85
amrex::ParserExecutor< 4 > potential_eb
Definition: ElectrostaticSolver.H:87
amrex::Parser potential_xhi_parser
Definition: ElectrostaticSolver.H:92
amrex::Parser potential_zhi_parser
Definition: ElectrostaticSolver.H:96
std::array< bool, AMREX_SPACEDIM *2 > dirichlet_flag
Definition: ElectrostaticSolver.H:46
amrex::Parser potential_eb_parser
Definition: ElectrostaticSolver.H:97
amrex::ParserExecutor< 1 > potential_eb_t
Definition: ElectrostaticSolver.H:86
void getGradSolution(const Vector< Array< AMF *, AMREX_SPACEDIM > > &a_grad_sol, Location a_loc=Location::FaceCenter)
Definition: ElectrostaticSolver.H:22
std::array< T, N > Array
string field
Definition: video_yt.py:31
Definition: ElectrostaticSolver.H:24
amrex::ParserExecutor< 4 > potential_eb
Definition: ElectrostaticSolver.H:27
amrex::Real t
Definition: ElectrostaticSolver.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real operator()(const amrex::Real x, const amrex::Real y, const amrex::Real z) const noexcept
Definition: ElectrostaticSolver.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real operator()(const amrex::Real x, const amrex::Real z) const noexcept
Definition: ElectrostaticSolver.H:30