LCOV - code coverage report
Current view: top level - src/IC - Random.H (source / functions) Coverage Total Hit
Test: coverage_merged.info Lines: 0.0 % 25 0
Test Date: 2025-12-10 23:45:13 Functions: 0.0 % 4 0

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

Generated by: LCOV version 2.0-1