LCOV - code coverage report
Current view: top level - src/Region - NDRegion.hpp (source / functions) Coverage Total Hit
Test: final_report.info Lines: 80.8 % 26 21
Test Date: 2025-07-18 17:15:09 Functions: 98.6 % 73 72

            Line data    Source code
       1              : //
       2              : // Class NDRegion
       3              : //   NDRegion is a simple container of N PRegion objects. It is templated
       4              : //   on the type of data (T) and the number of PRegions (Dim).
       5              : //
       6              : #include <iostream>
       7              : 
       8              : namespace ippl {
       9              :     template <typename T, unsigned Dim>
      10              :     template <class... Args>
      11          192 :     KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(const Args&... args)
      12          192 :         : NDRegion({args...}) {
      13              :         static_assert(Dim == sizeof...(args), "Wrong number of arguments.");
      14          192 :     }
      15              : 
      16              :     template <typename T, unsigned Dim>
      17          864 :     KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(std::initializer_list<PRegion<T>> regions) {
      18          192 :         unsigned int i = 0;
      19          864 :         for (auto& r : regions) {
      20          672 :             regions_m[i] = r;
      21          672 :             ++i;
      22              :         }
      23          192 :     }
      24              : 
      25              :     template <typename T, unsigned Dim>
      26          108 :     KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>::NDRegion(const NDRegion<T, Dim>& nr) {
      27          108 :         for (unsigned int i = 0; i < Dim; i++) {
      28           84 :             regions_m[i] = nr.regions_m[i];
      29              :         }
      30           24 :     }
      31              : 
      32              :     template <typename T, unsigned Dim>
      33          696 :     KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator=(
      34              :         const NDRegion<T, Dim>& nr) {
      35         3132 :         for (unsigned int i = 0; i < Dim; i++) {
      36         2436 :             regions_m[i] = nr.regions_m[i];
      37              :         }
      38          696 :         return *this;
      39              :     }
      40              : 
      41              :     template <typename T, unsigned Dim>
      42      4225702 :     KOKKOS_INLINE_FUNCTION const PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) const {
      43      4225702 :         return regions_m[d];
      44              :     }
      45              : 
      46              :     template <typename T, unsigned Dim>
      47        22454 :     KOKKOS_INLINE_FUNCTION PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) {
      48        22454 :         return regions_m[d];
      49              :     }
      50              : 
      51              :     template <typename T, unsigned Dim>
      52              :     KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator+=(const T t) {
      53              :         for (unsigned int i = 0; i < Dim; i++) {
      54              :             regions_m[i] += t;
      55              :         }
      56              :         return *this;
      57              :     }
      58              : 
      59              :     template <typename T, unsigned Dim>
      60              :     KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator-=(const T t) {
      61              :         for (unsigned int i = 0; i < Dim; i++) {
      62              :             regions_m[i] -= t;
      63              :         }
      64              :         return *this;
      65              :     }
      66              : 
      67              :     template <typename T, unsigned Dim>
      68              :     KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator*=(const T t) {
      69              :         for (unsigned int i = 0; i < Dim; i++) {
      70              :             regions_m[i] *= t;
      71              :         }
      72              :         return *this;
      73              :     }
      74              : 
      75              :     template <typename T, unsigned Dim>
      76              :     KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator/=(const T t) {
      77              :         if (t != 0) {
      78              :             for (unsigned int i = 0; i < Dim; i++) {
      79              :                 regions_m[i] /= t;
      80              :             }
      81              :         }
      82              :         return *this;
      83              :     }
      84              : 
      85              :     template <typename T, unsigned Dim>
      86              :     KOKKOS_INLINE_FUNCTION bool NDRegion<T, Dim>::empty() const {
      87              :         bool isEmpty = true;
      88              :         for (unsigned int i = 0; i < Dim; i++) {
      89              :             isEmpty &= regions_m[i].empty();
      90              :         }
      91              :         return isEmpty;
      92              :     }
      93              : 
      94              :     template <typename T, unsigned Dim>
      95            0 :     inline std::ostream& operator<<(std::ostream& out, const NDRegion<T, Dim>& idx) {
      96            0 :         out << '{';
      97            0 :         for (unsigned d = 0; d < Dim; ++d) {
      98            0 :             out << idx[d] << ((d == Dim - 1) ? '}' : ',');
      99              :         }
     100            0 :         return out;
     101              :     }
     102              : }  // namespace ippl
        

Generated by: LCOV version 2.0-1