Alamo
Constant.H
Go to the documentation of this file.
1//
2// Basic IC that just sets the entire field to a constant value.
3// Works with a single or multiple-component field.
4//
5
6#ifndef IC_CONSTANT_H_
7#define IC_CONSTANT_H_
8
9#include "AMReX_Config.H"
10#include "IC/IC.H"
11#include "IO/ParmParse.H"
12#include "Util/Util.H"
13#include "Unit/Unit.H"
14
15namespace IC
16{
17class Constant : public IC<Set::Scalar>, public IC<Set::Vector>
18{
19public:
20 class Zero;
21 class One;
22
23 static constexpr const char* name = "constant";
24
25 virtual ~Constant() = default;
26
27 Constant (amrex::Vector<amrex::Geometry> &_geom) :
28 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom) {}
29 Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp) :
30 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom)
31 {pp_queryclass(*this);}
32 Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp, std::string name) :
33 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom)
34 {pp_queryclass(name,*this);}
35 Constant (amrex::Vector<amrex::Geometry> &_geom, Unit a_unit, IO::ParmParse &pp, std::string name) :
36 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom), unit(a_unit)
37 {pp_queryclass(name,*this);}
38
39
40 virtual void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar /*time*/) override
41 {
42 Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == (int)a_field[lev]->nComp())));
43 for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
44 {
45 const amrex::Box& bx = mfi.growntilebox();
46 amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
47 for (int m = 0; m < a_field[lev]->nComp(); m++)
48 {
49 const Set::Scalar value =
50 m_value.size() == 1 ? m_value[0] : m_value[m];
51 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
52 field(i,j,k,m) += value;
53 });
54 }
55 }
56 }
57
58 virtual void Add(const int &lev, Set::Field<Set::Vector> &a_field, Set::Scalar /*time*/) override
59 {
60 Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == AMREX_SPACEDIM)));
61 for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
62 {
63 const amrex::Box& bx = mfi.growntilebox();
64 amrex::Array4<Set::Vector> const& field = a_field[lev]->array(mfi);
65 for (int m = 0; m < a_field[lev]->nComp(); m++)
66 {
67 const Set::Scalar value =
68 m_value.size() == 1 ? m_value[0] : m_value[m];
69 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
70 field(i,j,k)(m) += value;
71 });
72 }
73 }
74 }
75
76 static void Parse(Constant & value, IO::ParmParse & pp)
77 {
78 // Default: set equal to one everywhere
79 value.m_value.clear();
80
81 // Value (or values if multicomponent) to set field to
82 pp.queryarr_required("value", value.m_value, value.unit);
83 }
84protected:
85 std::vector<Set::Scalar> m_value;
87};
88
90{
91public:
92 explicit Zero(amrex::Vector<amrex::Geometry> &_geom) :
93 Constant(_geom)
94 {
95 m_value = {0.0};
96 }
97};
98
99class Constant::One : public Constant
100{
101public:
102 explicit One(amrex::Vector<amrex::Geometry> &_geom) :
103 Constant(_geom)
104 {
105 m_value = {1.0};
106 }
107};
108}
109#endif
#define pp_queryclass(...)
Definition ParmParse.H:130
#define TEST(x)
Definition Util.H:25
#define INFO
Definition Util.H:24
One(amrex::Vector< amrex::Geometry > &_geom)
Definition Constant.H:102
Zero(amrex::Vector< amrex::Geometry > &_geom)
Definition Constant.H:92
static void Parse(Constant &value, IO::ParmParse &pp)
Definition Constant.H:76
Constant(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
Definition Constant.H:32
Constant(amrex::Vector< amrex::Geometry > &_geom)
Definition Constant.H:27
Constant(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp)
Definition Constant.H:29
virtual void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar) override
Definition Constant.H:40
static constexpr const char * name
Definition Constant.H:23
Constant(amrex::Vector< amrex::Geometry > &_geom, Unit a_unit, IO::ParmParse &pp, std::string name)
Definition Constant.H:35
virtual void Add(const int &lev, Set::Field< Set::Vector > &a_field, Set::Scalar) override
Definition Constant.H:58
std::vector< Set::Scalar > m_value
Definition Constant.H:85
virtual ~Constant()=default
int queryarr_required(std::string name, std::vector< T > &value, const std::source_location &location=std::source_location::current())
Definition ParmParse.H:1223
Initialize a spherical inclusion.
Definition BMP.H:20
A collection of data types and symmetry-reduced data structures.
Definition Base.H:18
amrex::Real Scalar
Definition Base.H:19
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:21
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void Assert(const char *file, const char *func, int line, const char *smt, bool pass, Args const &... args)
Definition Util.H:60
Definition Unit.H:21