Line data Source code
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 "IC/IC.H" 10 : #include "IO/ParmParse.H" 11 : #include "Util/Util.H" 12 : 13 : /// \class Constant 14 : /// \brief 15 : /// 16 : namespace IC 17 : { 18 : class Constant : public IC 19 : { 20 : public: 21 : static constexpr const char* name = "constant"; 22 : 23 : Constant (amrex::Vector<amrex::Geometry> &_geom) :IC::IC(_geom) {} 24 : Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp) : IC::IC(_geom) 25 : {pp_queryclass(*this);} 26 9 : Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp, std::string name) : IC::IC(_geom) 27 9 : {pp_queryclass(name,*this);} 28 : 29 : Constant(amrex::Vector<amrex::Geometry> &_geom, std::vector<amrex::Real> a_value) 30 : : IC(_geom), m_value(a_value) 31 : {} 32 6 : ~Constant() { }; 33 170 : void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar) 34 : { 35 340 : Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == (int)a_field[lev]->nComp()))); 36 480 : for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) 37 : { 38 310 : const amrex::Box& bx = mfi.growntilebox(); 39 310 : amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi); 40 620 : for (int m = 0; m < a_field[lev]->nComp(); m++) 41 310 : amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) { 42 124324 : field(i,j,k,m) += m_value.size() == 1 ? m_value[0] : m_value[m]; 43 124324 : }); 44 : } 45 170 : } 46 9 : static void Parse(Constant & value, IO::ParmParse & pp) 47 : { 48 : // Default: set equal to one everywhere 49 9 : value.m_value.clear(); 50 : // Array of constant values. The number of values should equal either 1 or N where N is the number of fab components 51 9 : pp_queryarr_required("value",value.m_value); 52 9 : } 53 : private: 54 : std::vector<Set::Scalar> m_value; 55 : }; 56 : } 57 : #endif