LCOV - code coverage report
Current view: top level - src/Field - HaloCells.h (source / functions) Coverage Total Hit
Test: report.info Lines: 20.0 % 5 1
Test Date: 2025-05-12 09:25:18 Functions: 6.9 % 87 6

            Line data    Source code
       1              : //
       2              : // Class HaloCells
       3              : //   The guard / ghost cells of BareField.
       4              : //
       5              : #ifndef IPPL_HALO_CELLS_H
       6              : #define IPPL_HALO_CELLS_H
       7              : 
       8              : #include <array>
       9              : 
      10              : #include "Types/IpplTypes.h"
      11              : #include "Types/ViewTypes.h"
      12              : 
      13              : #include "Communicate/Archive.h"
      14              : #include "FieldLayout/FieldLayout.h"
      15              : #include "Index/NDIndex.h"
      16              : 
      17              : namespace ippl {
      18              :     namespace detail {
      19              :         /*!
      20              :          * Helper class to send / receive field data.
      21              :          */
      22              :         template <typename T, class... ViewArgs>
      23              :         struct FieldBufferData {
      24              :             using view_type    = typename detail::ViewType<T, 1, ViewArgs...>::view_type;
      25              :             using archive_type = Archive<typename view_type::memory_space>;
      26              : 
      27            0 :             void serialize(archive_type& ar, size_type nsends) { ar.serialize(buffer, nsends); }
      28              : 
      29            0 :             void deserialize(archive_type& ar, size_type nrecvs) { ar.deserialize(buffer, nrecvs); }
      30              : 
      31              :             view_type buffer;
      32              :         };
      33              : 
      34              :         /*!
      35              :          * This class provides the functionality to do field halo exchange.
      36              :          * @file HaloCells.h
      37              :          */
      38              :         template <typename T, unsigned Dim, class... ViewArgs>
      39              :         class HaloCells {
      40              :         public:
      41              :             using view_type       = typename detail::ViewType<T, Dim, ViewArgs...>::view_type;
      42              :             using Layout_t        = FieldLayout<Dim>;
      43              :             using bound_type      = typename Layout_t::bound_type;
      44              :             using databuffer_type = FieldBufferData<T, ViewArgs...>;
      45              : 
      46              :             enum SendOrder {
      47              :                 HALO_TO_INTERNAL,
      48              :                 INTERNAL_TO_HALO
      49              :             };
      50              : 
      51              :             HaloCells();
      52              : 
      53              :             /*!
      54              :              * Send halo data to internal cells. This operation uses
      55              :              * assign_plus functor to assign the data.
      56              :              * @param view the original field data
      57              :              * @param layout the field layout storing the domain decomposition
      58              :              */
      59              :             void accumulateHalo(view_type& view, Layout_t* layout);
      60              : 
      61              :             /*!
      62              :              * Send interal data to halo cells. This operation uses
      63              :              * assign functor to assign the data.
      64              :              * @param view the original field data
      65              :              * @param layout the field layout storing the domain decomposition
      66              :              */
      67              :             void fillHalo(view_type&, Layout_t* layout);
      68              : 
      69              :             /*!
      70              :              * Pack the field data to be sent into a contiguous array.
      71              :              * @param range the bounds of the subdomain to be sent
      72              :              * @param view the original view
      73              :              * @param fd the buffer to pack into
      74              :              */
      75              :             void pack(const bound_type& range, const view_type& view, databuffer_type& fd,
      76              :                       size_type& nsends);
      77              : 
      78              :             /*!
      79              :              * Unpack the received field data and assign it.
      80              :              * @param range the bounds of the subdomain to be received
      81              :              * @param view the original view
      82              :              * @param fd the buffer to unpack from (received data)
      83              :              * @tparam Op the data assigment operator
      84              :              */
      85              :             template <typename Op>
      86              :             void unpack(const bound_type& range, const view_type& view, databuffer_type& fd);
      87              : 
      88              :             /*!
      89              :              * Operator for the unpack function.
      90              :              * This operator is used in case of INTERNAL_TO_HALO.
      91              :              */
      92              :             struct assign {
      93            0 :                 KOKKOS_INLINE_FUNCTION void operator()(T& lhs, const T& rhs) const { lhs = rhs; }
      94              :             };
      95              : 
      96              :             /*!
      97              :              * Operator for the unpack function.
      98              :              * This operator is used in case of HALO_TO_INTERNAL.
      99              :              */
     100              :             struct lhs_plus_assign {
     101            0 :                 KOKKOS_INLINE_FUNCTION void operator()(T& lhs, const T& rhs) const { lhs += rhs; }
     102              :             };
     103              : 
     104              :             /*!
     105              :              * This operator is used in case of HALO_TO_INTERNAL for
     106              :              * all periodic BCs application in BareField.
     107              :              */
     108              :             struct rhs_plus_assign {
     109      7233804 :                 KOKKOS_INLINE_FUNCTION void operator()(const T& lhs, T& rhs) const { rhs += lhs; }
     110              :             };
     111              : 
     112              :             /*!
     113              :              * Apply all periodic boundary conditions for the
     114              :              * serial dimensions. Used in case of both fillHalo
     115              :              * and accumulateHalo with the help of operator as
     116              :              * template parameter.
     117              :              */
     118              :             template <typename Op>
     119              :             void applyPeriodicSerialDim(view_type& view, const Layout_t* layout, const int nghost);
     120              : 
     121              :         private:
     122              :             /*!
     123              :              * Exchange the data of halo cells.
     124              :              * @param view is the original field data
     125              :              * @param layout the field layout storing the domain decomposition
     126              :              * @param order the data send orientation
     127              :              * @tparam Op the data assigment operator of the
     128              :              * unpack function call
     129              :              */
     130              :             template <class Op>
     131              :             void exchangeBoundaries(view_type& view, Layout_t* layout, SendOrder order);
     132              : 
     133              :             /*!
     134              :              * Extract the subview of the original data. This does not copy.
     135              :              * A subview points to the same memory.
     136              :              * @param view is the original field data
     137              :              * @param intersect the bounds of the intersection
     138              :              */
     139              :             auto makeSubview(const view_type& view, const bound_type& intersect);
     140              : 
     141              :             databuffer_type haloData_m;
     142              :         };
     143              :     }  // namespace detail
     144              : }  // namespace ippl
     145              : 
     146              : #include "Field/HaloCells.hpp"
     147              : 
     148              : #endif
        

Generated by: LCOV version 2.0-1