Alamo
IC.H
Go to the documentation of this file.
1//
2// Initial condition (IC) objects are used to set fields to specified values,
3// through mathematical expressions, images, etc.
4// They are often used as initial conditions, but may be used generally to
5// incorporate static or time-dependent values.
6// All IC methods inherit from the base IC class, and are implemented by
7// overriding the "Add" method.
8// (Initialize uses Add after setting the field to zero.)
9//
10#ifndef IC_IC_H_
11#define IC_IC_H_
12
13#include <AMReX.H>
14#include <AMReX_MultiFab.H>
15#include "Util/Util.H"
16#include "Set/Set.H"
17
18namespace IC
19{
20/// Pure abstract IC object from which all other IC objects inherit.
21template<class T = Set::Scalar>
22class IC
23{
24public:
25 IC (amrex::Vector<amrex::Geometry> &_geom)
26 : geom(_geom) {} ;
27 virtual ~IC() {}
28
29 virtual void Add(const int &lev, Set::Field<T> &field, Set::Scalar time) = 0;
30 void Add(const int &lev, Set::Field<T> &field)
31 {
32 Add(lev,field,0.0);
33 }
34
35
36 // SFINAE solution: this is how we initialize if the type is arithmetic and has a
37 // "0" value
38 template <typename U = T, typename std::enable_if_t<std::is_arithmetic_v<U>, int> = 0>
39 void Initialize(const int &a_lev,
40 Set::Field<T> &a_field,
41 Set::Scalar a_time = 0.0)
42 {
43 Util::Assert(INFO,TEST(a_lev < a_field.size())," a_lev=",a_lev," size=",a_field.size());
44 a_field[a_lev]->setVal(0.0);
45 Add(a_lev,a_field,a_time);
46 }
47
48 // SFINAE solution: we initialize using "Zero" if it is a class type.
49 template <typename U = T, typename std::enable_if_t<!std::is_arithmetic_v<U>, int> = 0>
50 void Initialize(const int &a_lev,
51 Set::Field<T> &a_field,
52 Set::Scalar a_time = 0.0)
53 {
54 Util::Assert(INFO,TEST(a_lev < a_field.size())," a_lev=",a_lev," size=",a_field.size());
55 a_field[a_lev]->setVal(T::Zero());
56 Add(a_lev,a_field,a_time);
57 }
58
59 virtual void SetComp(int a_comp) final {comp = a_comp;}
60protected:
61 amrex::Vector<amrex::Geometry> &geom;
62 int comp = 0;
63};
64}
65#endif
#define TEST(x)
Definition Util.H:21
#define INFO
Definition Util.H:20
void Add(const int &lev, Set::Field< T > &field)
Definition IC.H:30
IC(amrex::Vector< amrex::Geometry > &_geom)
Definition IC.H:25
virtual ~IC()
Definition IC.H:27
virtual void SetComp(int a_comp) final
Definition IC.H:59
void Initialize(const int &a_lev, Set::Field< T > &a_field, Set::Scalar a_time=0.0)
Definition IC.H:39
amrex::Vector< amrex::Geometry > & geom
Definition IC.H:61
virtual void Add(const int &lev, Set::Field< T > &field, Set::Scalar time)=0
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
AMREX_FORCE_INLINE void Assert(std::string file, std::string func, int line, std::string smt, bool pass, Args const &... args)
Definition Util.H:70