Alamo
Random.H
Go to the documentation of this file.
1 #ifndef IC_RANDOM_H_
2 #define IC_RANDOM_H_
3 
4 #include "AMReX_Vector.H"
5 
6 #include "IO/ParmParse.H"
7 #include "IC/IC.H"
8 #include "Util/Util.H"
9 #include "Set/Set.H"
10 #include "IO/ParmParse.H"
11 
12 namespace IC
13 {
14 /// \brief Set each point to a random value.
15 class Random : public IC
16 {
17 public:
18  Random (amrex::Vector<amrex::Geometry> &_geom, Set::Scalar a_mult) :
19  IC(_geom), mult(a_mult)
20  {}
21  Random(amrex::Vector<amrex::Geometry>& _geom, IO::ParmParse& pp, std::string name) : IC(_geom)
22  {
23  pp.queryclass(name, *this);
24  }
25 
26  void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar)
27  {
28  for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
29  {
30  amrex::Box bx;
31  amrex::IndexType type = a_field[lev]->ixType();
32  if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
33  else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
34  else Util::Abort(INFO, "Unkonwn index type");
35 
36  Set::Patch<Set::Scalar> field = a_field.Patch(lev,mfi);
37  for (int n = 0; n < a_field[lev]->nComp(); n++)
38  {
39  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
40  {
41  field(i,j,k,n) += mult * Util::Random();
42  });
43  }
44  }
45  }
46 
47  using IC::Add;
48 
49  static void Parse(Random & value, IO::ParmParse & pp)
50  {
51  pp.query_default("mult",value.mult,1.0); // Multiplier
52  }
53 
54 private:
56 
57 };
58 }
59 #endif
60 
IO::ParmParse::query_default
int query_default(std::string name, T &value, T defaultvalue, std::string="", std::string="", int=-1)
Definition: ParmParse.H:182
IC::IC::Add
virtual void Add(const int &lev, Set::Field< Set::Scalar > &field, Set::Scalar time)=0
Util.H
IC::Random::Random
Random(amrex::Vector< amrex::Geometry > &_geom, Set::Scalar a_mult)
Definition: Random.H:18
IC::Random::Random
Random(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
Definition: Random.H:21
Set::Field< Set::Scalar >
Definition: Set.H:236
ParmParse.H
IC::Random::Add
void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar)
Definition: Random.H:26
Util::Random
Set::Scalar Random()
Definition: Set.cpp:9
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
IC::Random::Parse
static void Parse(Random &value, IO::ParmParse &pp)
Definition: Random.H:49
Util::Abort
void Abort(const char *msg)
Definition: Util.cpp:165
IC::Random
Set each point to a random value.
Definition: Random.H:15
Set.H
IC
Definition: Affine.H:18
IO::ParmParse
Definition: ParmParse.H:110
Set::Patch
amrex::Array4< T > const & Patch
Definition: Set.H:88
IO::ParmParse::queryclass
void queryclass(std::string name, T *value, std::string file="", std::string func="", int line=-1)
Definition: ParmParse.H:443
INFO
#define INFO
Definition: Util.H:20
IC.H
Set::Field< Set::Scalar >::Patch
amrex::Array4< Set::Scalar > Patch(int lev, amrex::MFIter &mfi) const &
Definition: Set.H:263
IC::Random::mult
Set::Scalar mult
Definition: Random.H:55