LCOV - code coverage report
Current view: top level - src/IC - Constant.H (source / functions) Coverage Total Hit
Test: coverage_merged.info Lines: 63.3 % 30 19
Test Date: 2025-04-03 04:02:21 Functions: 60.0 % 10 6

            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 "AMReX_Config.H"
      10              : #include "IC/IC.H"
      11              : #include "IO/ParmParse.H"
      12              : #include "Util/Util.H"
      13              : 
      14              : namespace IC
      15              : {
      16              : class Constant : public IC<Set::Scalar>, public IC<Set::Vector>
      17              : {
      18              : public:
      19              :     static constexpr const char* name = "constant";
      20              : 
      21           66 :     virtual ~Constant() = default;
      22              : 
      23              :     Constant (amrex::Vector<amrex::Geometry> &_geom) :
      24              :         IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom) {}
      25              :     Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp) : 
      26              :         IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom)
      27              :     {pp_queryclass(*this);}
      28           33 :     Constant (amrex::Vector<amrex::Geometry> &_geom, IO::ParmParse &pp, std::string name) : 
      29           33 :         IC<Set::Scalar>(_geom), IC<Set::Vector>(_geom)
      30          132 :     {pp_queryclass(name,*this);}
      31              : 
      32              : 
      33         3201 :     virtual void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar /*time*/) override
      34              :     {
      35        22407 :         Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == (int)a_field[lev]->nComp())));
      36         6542 :         for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
      37              :         {
      38         3341 :             const amrex::Box& bx = mfi.growntilebox();
      39         3341 :             amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
      40         6693 :             for (int m = 0; m < a_field[lev]->nComp(); m++)
      41         3352 :                 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
      42     12619780 :                 field(i,j,k,m) += m_value.size() == 1 ? m_value[0] : m_value[m];
      43     12619780 :             });  
      44         3201 :         }
      45         3201 :     }
      46              : 
      47            0 :     virtual void Add(const int &lev, Set::Field<Set::Vector> &a_field, Set::Scalar /*time*/) override
      48              :     {
      49            0 :         Util::Assert(INFO,TEST((m_value.size() == 1 || (int)m_value.size() == AMREX_SPACEDIM)));
      50            0 :         for (amrex::MFIter mfi(*a_field[lev],amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
      51              :         {
      52            0 :             const amrex::Box& bx = mfi.growntilebox();
      53            0 :             amrex::Array4<Set::Vector> const& field = a_field[lev]->array(mfi);
      54            0 :             for (int m = 0; m < a_field[lev]->nComp(); m++)
      55            0 :                 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
      56            0 :                     field(i,j,k)(m) += m_value.size() == 1 ? m_value[0] : m_value[m];
      57            0 :             });  
      58            0 :         }
      59            0 :     }
      60              : 
      61           33 :     static void Parse(Constant & value, IO::ParmParse & pp)
      62              :     {
      63              :         // Default: set equal to one everywhere
      64           33 :         value.m_value.clear();
      65              :         // Array of constant values. The number of values should equal either 1 or N where N is the number of fab components
      66          165 :         pp_queryarr_required("value",value.m_value); 
      67           33 :     }
      68              : private:
      69              :     std::vector<Set::Scalar> m_value;
      70              : };
      71              : }
      72              : #endif
        

Generated by: LCOV version 2.0-1