Alamo
Cuboid.H
Go to the documentation of this file.
1 #ifndef IC_CUBOID_H_
2 #define IC_CUBOID_H_
3 
4 #include <iostream>
5 #include <cstdlib>
6 #include <climits>
7 #include "IC/IC.H"
8 #include "Util/Util.H"
9 #include "Set/Set.H"
10 using namespace std;
11 #include <iostream>
12 #include <vector>
13 #include <algorithm>
14 #include <iterator>
15 #include "mpi.h"
16 #include "IO/ParmParse.H"
17 
18 namespace IC
19 {
20 class Cuboid : public IC
21 {
22 public:
23  Cuboid(amrex::Vector<amrex::Geometry>& _geom) : IC(_geom) {}
24 
25  Cuboid(amrex::Vector<amrex::Geometry>& _geom, IO::ParmParse& pp, std::string name) : IC(_geom)
26  {
27  pp_queryclass(name, *this);
28  }
29 
30  void Define() {
31 
32  };
33 
34  //void Add(const int lev,amrex::Vector<amrex::MultiFab * > &a_field)
35  void Add(const int& lev, Set::Field<Set::Scalar>& a_field, Set::Scalar)
36  {
37  bool cellcentered = (a_field[0]->boxArray().ixType() == amrex::IndexType(amrex::IntVect::TheCellVector()));
38 
39  for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
40  {
41  amrex::Box bx;
42  amrex::IndexType type = a_field[lev]->ixType();
43  if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
44  else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
45  else Util::Abort(INFO, "Unkonwn index type");
46 
47  amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
48  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
49 
50  Set::Scalar AMREX_D_DECL(x, y, z);
51  if (cellcentered)
52  {
53  AMREX_D_TERM(x = geom[lev].ProbLo()[0] + ((amrex::Real)(i)+0.5) * geom[lev].CellSize()[0];,
54  y = geom[lev].ProbLo()[1] + ((amrex::Real)(j)+0.5) * geom[lev].CellSize()[1];,
55  z = geom[lev].ProbLo()[2] + ((amrex::Real)(k)+0.5) * geom[lev].CellSize()[2];);
56  }
57  else
58  {
59  AMREX_D_TERM(x = geom[lev].ProbLo()[0] + (amrex::Real)(i)*geom[lev].CellSize()[0];,
60  y = geom[lev].ProbLo()[1] + (amrex::Real)(j)*geom[lev].CellSize()[1];,
61  z = geom[lev].ProbLo()[2] + (amrex::Real)(k)*geom[lev].CellSize()[2];);
62  }
63  //Set::Scalar rsq = 0.0;
64 
65 
66  Set::Scalar xdir = std::abs((x - center[0])) - (length[0] / 2.0);
67  Set::Scalar ydir = std::abs((y - center[1])) - (length[1] / 2.0);
68  #if AMREX_SPACEDIM==3
69  Set::Scalar zdir = std::abs((z - center[2])) - (length[2] / 2.0);
70  field(i, j, k, 0) = 0.5 - 0.5 * std::erf((xdir + ydir + zdir) / eps);
71  if (field.nComp() > 1) field(i, j, k, 1) = 1. - (0.5 - 0.5 * std::erf((xdir + ydir + zdir) / eps));
72  #elif AMREX_SPACEDIM==2
73  field(i, j, k, 0) = 0.5 - 0.5 * std::erf((xdir + ydir) / eps);
74  if (field.nComp() > 1) field(i, j, k, 1) = 1. - (0.5 - 0.5 * std::erf((xdir + ydir) / eps));
75  #endif
76  });
77  }
78 
79  };
80 
81  static void Parse(Cuboid& value, IO::ParmParse& pp)
82  {
83  pp_queryarr("center", value.center); // Coordinates (X Y Z) of the center of the square/cube.
84  pp_queryarr("length", value.length); // Side legnth of cuboid
85  pp_query("eps", value.eps); // Regularization value
86  }
87 
88 private:
89  amrex::Vector<amrex::Real> center;
90  amrex::Vector<amrex::Real> length;
91  //amrex::Vector<Set::Vector> orientation=(1,0,0);
93 };
94 }
95 #endif
IC::Cuboid::eps
Set::Scalar eps
Definition: Cuboid.H:92
BC::AMREX_D_DECL
@ AMREX_D_DECL
Definition: BC.H:34
Util.H
IC::Cuboid::Add
void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar)
Definition: Cuboid.H:35
IC::Cuboid::Define
void Define()
Definition: Cuboid.H:30
IC::Cuboid::Cuboid
Cuboid(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
Definition: Cuboid.H:25
Set::Field< Set::Scalar >
Definition: Set.H:236
IC::Cuboid::Cuboid
Cuboid(amrex::Vector< amrex::Geometry > &_geom)
Definition: Cuboid.H:23
ParmParse.H
pp_query
#define pp_query(...)
Definition: ParmParse.H:104
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
pp_queryclass
#define pp_queryclass(...)
Definition: ParmParse.H:105
IC::Cuboid::length
amrex::Vector< amrex::Real > length
Definition: Cuboid.H:90
IC::Cuboid::Parse
static void Parse(Cuboid &value, IO::ParmParse &pp)
Definition: Cuboid.H:81
IC::Cuboid
Definition: Cuboid.H:20
IC::Cuboid::center
amrex::Vector< amrex::Real > center
Definition: Cuboid.H:89
Util::Abort
void Abort(const char *msg)
Definition: Util.cpp:165
Set.H
IC
Definition: Affine.H:18
IO::ParmParse
Definition: ParmParse.H:110
INFO
#define INFO
Definition: Util.H:20
IC.H
pp_queryarr
#define pp_queryarr(...)
Definition: ParmParse.H:103