Alamo
PS.H
Go to the documentation of this file.
1 //
2 // Fill a domain with randomly packed and sized spheres.
3 //
4 // .. WARNING::
5 //
6 // This is not used for anything useful as far as we can see.
7 // It will likely be removed shortly.
8 //
9 
10 #ifndef IC_PS_H_
11 #define IC_PS_H_
12 
13 #include "Set/Set.H"
14 #include "IC/IC.H"
15 
16 namespace IC
17 {
18 class PS : public IC
19 {
20 public:
22 
23  PS (amrex::Vector<amrex::Geometry> &a_geom) : IC(a_geom) {}
24 
25  PS (amrex::Vector<amrex::Geometry> &a_geom, int a_nspheres, Set::Scalar a_matrix, Set::Scalar a_inclusion)
26  : IC(a_geom)
27  {
28  Define(a_nspheres,a_matrix,a_inclusion);
29  }
30 
31  void Define(int a_nspheres, Set::Scalar a_matrix, Set::Scalar a_inclusion)
32  {
33  nspheres = a_nspheres;
34  matrix = a_matrix;
35  inclusion = a_inclusion;
36  points.resize(nspheres);
37  radii.resize(nspheres);
38  for (int n = 0; n<nspheres; n++)
39  {
40  AMREX_D_TERM(points[n](0) = geom[0].ProbLo(0) + (geom[0].ProbHi(0)-geom[0].ProbLo(0))*Util::Random();,
41  points[n](1) = geom[0].ProbLo(1) + (geom[0].ProbHi(1)-geom[0].ProbLo(1))*Util::Random();,
42  points[n](2) = geom[0].ProbLo(2) + (geom[0].ProbHi(2)-geom[0].ProbLo(2))*Util::Random(););
43  radii[n] = 0.25*Util::Random();
44  }
45  }
46 
47  //void Add(const int lev, amrex::Vector<amrex::MultiFab * > &a_field)
48  void Add(const int &lev,Set::Field<Set::Scalar> &a_field)
49  {
50  Set::Vector size;
51  AMREX_D_TERM(size(0) = geom[0].ProbHi()[0] - geom[0].ProbLo()[0];,
52  size(1) = geom[0].ProbHi()[1] - geom[0].ProbLo()[1];,
53  size(2) = geom[0].ProbHi()[2] - geom[0].ProbLo()[2];)
54  amrex::IndexType type = a_field[lev]->ixType();
55 
56  for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
57  {
58  amrex::Box bx = mfi.tilebox();
59  //bx.grow(a_field[lev]->nGrow());
60  amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
61  amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
62 
63  Set::Vector x = Set::Position(i,j,k,geom[lev],type);
64 
65  bool inside = false;
66  for (int n = 0; n<nspheres; n++)
67  {
68  Set::Scalar d = (x - points[n]).lpNorm<2>();
69 
70  if (geom[lev].isPeriodic(0))
71  {
72  d = std::min(d,std::min((x-points[n] + size(0)*Set::Vector::Unit(0)).lpNorm<2>(),
73  (x-points[n] - size(0)*Set::Vector::Unit(0)).lpNorm<2>()));
74  }
75 #if AMREX_SPACEDIM>1
76  if (geom[lev].isPeriodic(1))
77  {
78  d = std::min(d,std::min((x-points[n] + size(1)*Set::Vector::Unit(1)).lpNorm<2>(),
79  (x-points[n] - size(1)*Set::Vector::Unit(1)).lpNorm<2>()));
80  }
81 #endif
82 #if AMREX_SPACEDIM>2
83  if (geom[lev].isPeriodic(2))
84  {
85  d = std::min(d,std::min((x-points[n] + size(2)*Set::Vector::Unit(2)).lpNorm<2>(),
86  (x-points[n] - size(2)*Set::Vector::Unit(2)).lpNorm<2>()));
87  }
88 #endif
89  if (d<radii[n]) inside = true;
90  }
91 
92  if (inside) field(i,j,k) += inclusion;
93  else field(i,j,k) += matrix;
94  });
95  }
96  }
97 
98 private:
99  int nspheres;
101  std::vector<Set::Scalar> radii;
102  std::vector<Set::Vector> points;
103 
104 public:
105  static void Parse(PS & value, IO::ParmParse & pp)
106  {
107  int tmp_nspheres;
108  Set::Scalar tmp_matrix = 0.0, tmp_inclusion = 1.0;
109  pp_query("nspheres",tmp_nspheres); // Total number of spheres
110  pp_query("matrix",tmp_matrix); // Value for the matrix [0.0]
111  pp_query("inclusion",tmp_inclusion); // Value for the inclusion [1.0]
112  value.Define(tmp_nspheres,tmp_matrix,tmp_inclusion);
113  }
114 };
115 }
116 #endif
IC::IC::geom
amrex::Vector< amrex::Geometry > & geom
Definition: IC.H:45
Set::Position
AMREX_FORCE_INLINE Vector Position(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
Definition: Base.H:121
IC::PS::points
std::vector< Set::Vector > points
Definition: PS.H:102
IC::PS::matrix
Set::Scalar matrix
Definition: PS.H:100
IC::PS::inclusion
Set::Scalar inclusion
Definition: PS.H:100
Set::Field< Set::Scalar >
Definition: Set.H:236
Set::Vector
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition: Base.H:20
pp_query
#define pp_query(...)
Definition: ParmParse.H:104
IC::PS::nspheres
int nspheres
Definition: PS.H:99
IC::PS::Add
void Add(const int &lev, Set::Field< Set::Scalar > &a_field)
Definition: PS.H:48
Util::Random
Set::Scalar Random()
Definition: Set.cpp:9
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
IC::PS
Definition: PS.H:18
IC::PS::radii
std::vector< Set::Scalar > radii
Definition: PS.H:101
Set.H
IC
Definition: Affine.H:18
IC::PS::PS
PS(amrex::Vector< amrex::Geometry > &a_geom)
Definition: PS.H:23
IO::ParmParse
Definition: ParmParse.H:110
IC::PS::Define
void Define(int a_nspheres, Set::Scalar a_matrix, Set::Scalar a_inclusion)
Definition: PS.H:31
IC::PS::Partition
@ Partition
Definition: PS.H:21
IC::PS::Values
@ Values
Definition: PS.H:21
IC::PS::Type
Type
Definition: PS.H:21
IC.H
IC::PS::Parse
static void Parse(PS &value, IO::ParmParse &pp)
Definition: PS.H:105
IC::PS::PS
PS(amrex::Vector< amrex::Geometry > &a_geom, int a_nspheres, Set::Scalar a_matrix, Set::Scalar a_inclusion)
Definition: PS.H:25