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