LCOV - code coverage report
Current view: top level - src/IC - Random.H (source / functions) Coverage Total Hit
Test: coverage_merged.info Lines: 90.5 % 21 19
Test Date: 2025-02-27 04:17:48 Functions: 100.0 % 4 4

            Line data    Source code
       1              : #ifndef IC_RANDOM_H_
       2              : #define IC_RANDOM_H_
       3              : 
       4              : #include "AMReX_Vector.H"
       5              : 
       6              : #include "IO/ParmParse.H"
       7              : #include "IC/IC.H"
       8              : #include "Util/Util.H"
       9              : #include "Set/Set.H"
      10              : #include "IO/ParmParse.H"
      11              : 
      12              : namespace IC
      13              : {
      14              : /// Set each point to a random value.
      15              : class Random : public IC<Set::Scalar>
      16              : {
      17              : public:
      18              :     static constexpr const char* name = "random";
      19              : 
      20              :     Random (amrex::Vector<amrex::Geometry> &_geom, Set::Scalar a_mult) :
      21              :         IC(_geom), mult(a_mult)
      22              :     {}
      23            2 :     Random(amrex::Vector<amrex::Geometry>& _geom, IO::ParmParse& pp, std::string name) : IC(_geom)
      24              :     {
      25            6 :         pp.queryclass(name, *this);
      26            2 :     }
      27              :   
      28           10 :     void Add(const int &lev, Set::Field<Set::Scalar> &a_field, Set::Scalar)
      29              :     {
      30           20 :         for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
      31              :         {
      32           10 :             amrex::Box bx;
      33           10 :             amrex::IndexType type = a_field[lev]->ixType();
      34           20 :             if (type == amrex::IndexType::TheCellType())      bx = mfi.growntilebox();
      35            0 :             else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
      36            0 :             else Util::Abort(INFO, "Unkonwn index type");
      37              :             
      38           10 :             Set::Patch<Set::Scalar> field = a_field.Patch(lev,mfi);
      39           20 :             for (int n = 0; n < a_field[lev]->nComp(); n++)
      40              :             {
      41           10 :                 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
      42              :                 {
      43       309616 :                     field(i,j,k,n) += offset + mult * Util::Random();
      44       309616 :                 });
      45              :             }
      46           10 :         }
      47           10 :     }
      48              : 
      49              :     using IC::Add;
      50              : 
      51            2 :     static void Parse(Random & value, IO::ParmParse & pp)
      52              :     {
      53           12 :         pp.query_default("offset",value.offset,0.0); // offset
      54           10 :         pp.query_default("mult",value.mult,1.0); // Multiplier
      55            2 :     }
      56              :     
      57              : private:
      58              :     Set::Scalar mult = NAN; 
      59              :     Set::Scalar offset = NAN;
      60              : 
      61              : };
      62              : }
      63              : #endif
      64              : 
        

Generated by: LCOV version 2.0-1