Alamo
Constant.H
Go to the documentation of this file.
1 //
2 // Basic IC that just sets the entire field to a constant value.
3 // Works with a single or multiple-component field.
4 //
5 
6 #ifndef IC_CONSTANT_H_
7 #define IC_CONSTANT_H_
8 
9 #include "IC/IC.H"
10 #include "IO/ParmParse.H"
11 #include "Util/Util.H"
12 
13 /// \class Constant
14 /// \brief
15 ///
16 namespace IC
17 {
18 class Constant : public IC
19 {
20 public:
21  Constant (amrex::Vector<amrex::Geometry> &_geom) :IC::IC(_geom) {}
22  Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp) : IC::IC(_geom)
23  {pp_queryclass(*this);}
24  Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp, std::string name) : IC::IC(_geom)
25  {pp_queryclass(name,*this);}
26 
27  Constant(amrex::Vector<amrex::Geometry> &_geom, std::vector<amrex::Real> a_value)
28  : IC(_geom), m_value(a_value)
29  {}
30  ~Constant() { };
31  void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar)
32  {
33  Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == (int)a_field[lev]->nComp())));
34  for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
35  {
36  const amrex::Box& bx = mfi.growntilebox();
37  amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
38  for (int m = 0; m < a_field[lev]->nComp(); m++)
39  amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
40  field(i,j,k,m) += m_value.size() == 1 ? m_value[0] : m_value[m];
41  });
42  }
43  }
44  static void Parse(Constant & value, IO::ParmParse & pp)
45  {
46  // Default: set equal to one everywhere
47  value.m_value.clear();
48  value.m_value.push_back(1.0);
49  pp_queryarr("value",value.m_value); // Array of constant values. The number of values should equal either 1 or N where N is the number of fab components
50  }
51 private:
52  std::vector<Set::Scalar> m_value;
53 };
54 }
55 #endif
IC::Constant::Parse
static void Parse(Constant &value, IO::ParmParse &pp)
Definition: Constant.H:44
Util.H
IC::Constant::~Constant
~Constant()
Definition: Constant.H:30
TEST
#define TEST(x)
Definition: Util.H:21
IC::Constant::Add
void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar)
Definition: Constant.H:31
Set::Field< Set::Scalar >
Definition: Set.H:236
IC::Constant::Constant
Constant(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp)
Definition: Constant.H:22
IC::Constant::Constant
Constant(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
Definition: Constant.H:24
ParmParse.H
IC::Constant::Constant
Constant(amrex::Vector< amrex::Geometry > &_geom)
Definition: Constant.H:21
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
pp_queryclass
#define pp_queryclass(...)
Definition: ParmParse.H:105
Util::Assert
AMREX_FORCE_INLINE void Assert(std::string file, std::string func, int line, std::string smt, bool pass, Args const &... args)
Definition: Util.H:65
IC::Constant
Definition: Constant.H:18
IC
Definition: Affine.H:18
IC::Constant::Constant
Constant(amrex::Vector< amrex::Geometry > &_geom, std::vector< amrex::Real > a_value)
Definition: Constant.H:27
IO::ParmParse
Definition: ParmParse.H:110
INFO
#define INFO
Definition: Util.H:20
IC.H
IC::Constant::m_value
std::vector< Set::Scalar > m_value
Definition: Constant.H:52
pp_queryarr
#define pp_queryarr(...)
Definition: ParmParse.H:103