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 static constexpr const char* name = "constant";
21
22 virtual ~Constant() = default;
23
24 Constant (amrex::Vector<amrex::Geometry> &_geom) :
25 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom) {}
26 Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp) :
27 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom)
28 {pp_queryclass(*this);}
29 Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp, std::string name) :
30 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom)
31 {pp_queryclass(name,*this);}
32 Constant (amrex::Vector<amrex::Geometry> &_geom, Unit a_unit, IO::ParmParse &pp, std::string name) :
33 IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom), unit(a_unit)
34 {pp_queryclass(name,*this);}
35
36
37 virtual void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar /*time*/) override
38 {
39 Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == (int)a_field[lev]->nComp())));
40 for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
41 {
42 const amrex::Box& bx = mfi.growntilebox();
43 amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
44 for (int m = 0; m < a_field[lev]->nComp(); m++)
45 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
46 field(i,j,k,m) += m_value.size() == 1 ? m_value[0] : m_value[m];
47 });
48 }
49 }
50
51 virtual void Add(const int &lev, Set::Field<Set::Vector> &a_field, Set::Scalar /*time*/) override
52 {
53 Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == AMREX_SPACEDIM)));
54 for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
55 {
56 const amrex::Box& bx = mfi.growntilebox();
57 amrex::Array4<Set::Vector> const& field = a_field[lev]->array(mfi);
58 for (int m = 0; m < a_field[lev]->nComp(); m++)
59 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
60 field(i,j,k)(m) += m_value.size() == 1 ? m_value[0] : m_value[m];
61 });
62 }
63 }
64
65 static void Parse(Constant & value, IO::ParmParse & pp)
66 {
67 // Default: set equal to one everywhere
68 value.m_value.clear();
69
70 // Value (or values if multicomponent) to set field to
71 pp.queryarr_required("value", value.m_value, value.unit);
72 }
73private:
74 std::vector<Set::Scalar> m_value;
76};
77}
78#endif
#define pp_queryclass(...)
Definition ParmParse.H:109
#define TEST(x)
Definition Util.H:22
#define INFO
Definition Util.H:21
static void Parse(Constant &value, IO::ParmParse &pp)
Definition Constant.H:65
Constant(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
Definition Constant.H:29
Constant(amrex::Vector< amrex::Geometry > &_geom)
Definition Constant.H:24
Constant(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp)
Definition Constant.H:26
virtual void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar) override
Definition Constant.H:37
static constexpr const char * name
Definition Constant.H:20
Constant(amrex::Vector< amrex::Geometry > &_geom, Unit a_unit, IO::ParmParse &pp, std::string name)
Definition Constant.H:32
virtual void Add(const int &lev, Set::Field< Set::Vector > &a_field, Set::Scalar) override
Definition Constant.H:51
std::vector< Set::Scalar > m_value
Definition Constant.H:74
virtual ~Constant()=default
int queryarr_required(std::string name, std::vector< T > &value)
Definition ParmParse.H:637
Initialize a spherical inclusion.
Definition BMP.H:20
A collection of data types and symmetry-reduced data structures.
Definition Base.H:17
amrex::Real Scalar
Definition Base.H:18
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:19
AMREX_FORCE_INLINE void Assert(std::string file, std::string func, int line, std::string smt, bool pass, Args const &... args)
Definition Util.H:55
Definition Unit.H:20