LCOV - code coverage report
Current view: top level - src/Field - BcTypes.h (source / functions) Coverage Total Hit
Test: report.info Lines: 76.2 % 21 16
Test Date: 2025-05-15 13:47:30 Functions: 42.2 % 445 188
Branches: 50.0 % 2 1

             Branch data     Line data    Source code
       1                 :             : //   This file contains the abstract base class for
       2                 :             : //   field boundary conditions and other child classes
       3                 :             : //   which represent specific BCs. At the moment the
       4                 :             : //   following field BCs are supported
       5                 :             : //
       6                 :             : //   1. Periodic BC
       7                 :             : //   2. Zero BC
       8                 :             : //   3. Specifying a constant BC
       9                 :             : //   4. No BC (default option)
      10                 :             : //   5. Constant extrapolation BC
      11                 :             : //   Only cell-centered field BCs are implemented
      12                 :             : //   at the moment.
      13                 :             : //
      14                 :             : #ifndef IPPL_FIELD_BC_TYPES_H
      15                 :             : #define IPPL_FIELD_BC_TYPES_H
      16                 :             : 
      17                 :             : #include "Types/IpplTypes.h"
      18                 :             : #include "Types/ViewTypes.h"
      19                 :             : 
      20                 :             : #include "Communicate/Archive.h"
      21                 :             : #include "FieldLayout/FieldLayout.h"
      22                 :             : #include "Index/NDIndex.h"
      23                 :             : #include "Meshes/UniformCartesian.h"
      24                 :             : 
      25                 :             : namespace ippl {
      26                 :             :     /*
      27                 :             :      * Enum type to identify different kinds of
      28                 :             :      * field boundary conditions. Since ZeroFace is
      29                 :             :      * a special case of ConstantFace, both will match
      30                 :             :      * a bitwise AND with CONSTANT_FACE
      31                 :             :      * (to avoid conflict with particle BC enum, add _FACE)
      32                 :             :      */
      33                 :             :     enum FieldBC {
      34                 :             :         PERIODIC_FACE    = 0b0000,
      35                 :             :         CONSTANT_FACE    = 0b0001,
      36                 :             :         ZERO_FACE        = 0b0011,
      37                 :             :         EXTRAPOLATE_FACE = 0b0100,
      38                 :             :         NO_FACE          = 0b1000,
      39                 :             :     };
      40                 :             : 
      41                 :             :     namespace detail {
      42                 :             :         template <typename Field>
      43                 :             :         class BCondBase {
      44                 :             :             constexpr static unsigned Dim = Field::dim;
      45                 :             : 
      46                 :             :         public:
      47                 :             :             using Layout_t = FieldLayout<Dim>;
      48                 :             : 
      49                 :             :             // Constructor takes:
      50                 :             :             // face: the face to apply the boundary condition on.
      51                 :             :             // i : what component of T to apply the boundary condition to.
      52                 :             :             // The components default to setting all components.
      53                 :             :             BCondBase(unsigned int face);
      54                 :             : 
      55                 :        6336 :             virtual ~BCondBase() = default;
      56                 :             : 
      57                 :           0 :             virtual FieldBC getBCType() const { return NO_FACE; }
      58                 :             : 
      59                 :             :             virtual void findBCNeighbors(Field& field) = 0;
      60                 :             :             virtual void apply(Field& field)           = 0;
      61                 :             :             virtual void write(std::ostream&) const    = 0;
      62                 :             : 
      63                 :             :             // Return face on which BC applies
      64                 :             :             unsigned int getFace() const { return face_m; }
      65                 :             : 
      66                 :             :             // Returns whether or not this BC changes physical cells.
      67                 :             :             bool changesPhysicalCells() const { return changePhysical_m; }
      68                 :             : 
      69                 :             :         protected:
      70                 :             :             // What face to apply the boundary condition to.
      71                 :             :             unsigned int face_m;
      72                 :             : 
      73                 :             :             // True if this boundary condition changes physical cells.
      74                 :             :             bool changePhysical_m;
      75                 :             :         };
      76                 :             : 
      77                 :             :         template <typename Field>
      78                 :             :         std::ostream& operator<<(std::ostream&, const BCondBase<Field>&);
      79                 :             : 
      80                 :             :     }  // namespace detail
      81                 :             : 
      82                 :             :     template <typename Field>
      83                 :             :     class ExtrapolateFace : public detail::BCondBase<Field> {
      84                 :             :         constexpr static unsigned Dim = Field::dim;
      85                 :             :         using T                       = typename Field::value_type;
      86                 :             : 
      87                 :             :     public:
      88                 :             :         // Constructor takes zero, one, or two int's specifying components of
      89                 :             :         // multicomponent types like Vector this BC applies to.
      90                 :             :         // Zero int's specified means apply to all components; one means apply to
      91                 :             :         // component (i), and two means apply to component (i,j),
      92                 :             :         using base_type = detail::BCondBase<Field>;
      93                 :             :         using Layout_t  = typename detail::BCondBase<Field>::Layout_t;
      94                 :             : 
      95                 :         336 :         ExtrapolateFace(unsigned face, T offset, T slope)
      96                 :             :             : base_type(face)
      97                 :         336 :             , offset_m(offset)
      98                 :         336 :             , slope_m(slope) {}
      99                 :             : 
     100                 :        1344 :         virtual ~ExtrapolateFace() = default;
     101                 :             : 
     102                 :           0 :         virtual FieldBC getBCType() const { return EXTRAPOLATE_FACE; }
     103                 :             : 
     104                 :         420 :         virtual void findBCNeighbors(Field& /*field*/) {}
     105                 :             :         virtual void apply(Field& field);
     106                 :             : 
     107                 :             :         virtual void write(std::ostream& out) const;
     108                 :             : 
     109                 :             :         const T& getOffset() const { return offset_m; }
     110                 :             :         const T& getSlope() const { return slope_m; }
     111                 :             : 
     112                 :             :     protected:
     113                 :             :         T offset_m;
     114                 :             :         T slope_m;
     115                 :             :     };
     116                 :             : 
     117                 :             :     template <typename Field>
     118                 :             :     class NoBcFace : public detail::BCondBase<Field> {
     119                 :             :     public:
     120                 :        3732 :         NoBcFace(int face)
     121                 :        3732 :             : detail::BCondBase<Field>(face) {}
     122                 :             : 
     123                 :          84 :         virtual void findBCNeighbors(Field& /*field*/) {}
     124                 :         348 :         virtual void apply(Field& /*field*/) {}
     125                 :             : 
     126                 :             :         virtual void write(std::ostream& out) const;
     127                 :             :     };
     128                 :             : 
     129                 :             :     template <typename Field>
     130                 :             :     class ConstantFace : public ExtrapolateFace<Field> {
     131                 :             :         using T = typename Field::value_type;
     132                 :             : 
     133                 :             :     public:
     134                 :         252 :         ConstantFace(unsigned int face, T constant)
     135                 :         252 :             : ExtrapolateFace<Field>(face, constant, 0) {}
     136                 :             : 
     137                 :           0 :         virtual FieldBC getBCType() const { return CONSTANT_FACE; }
     138                 :             : 
     139                 :             :         virtual void write(std::ostream& out) const;
     140                 :             :     };
     141                 :             : 
     142                 :             :     template <typename Field>
     143                 :             :     class ZeroFace : public ConstantFace<Field> {
     144                 :             :     public:
     145                 :          84 :         ZeroFace(unsigned face)
     146                 :          84 :             : ConstantFace<Field>(face, 0.0) {}
     147                 :             : 
     148                 :           0 :         virtual FieldBC getBCType() const { return ZERO_FACE; }
     149                 :             : 
     150                 :             :         virtual void write(std::ostream& out) const;
     151                 :             :     };
     152                 :             : 
     153                 :             :     template <typename Field>
     154                 :             :     class PeriodicFace : public detail::BCondBase<Field> {
     155                 :             :         constexpr static unsigned Dim = Field::dim;
     156                 :             :         using T                       = typename Field::value_type;
     157                 :             : 
     158                 :             :     public:
     159                 :             :         using face_neighbor_type = std::array<std::vector<int>, 2 * Dim>;
     160                 :             :         using Layout_t           = typename detail::BCondBase<Field>::Layout_t;
     161                 :             : 
     162                 :         252 :         PeriodicFace(unsigned face)
     163         [ +  - ]:         252 :             : detail::BCondBase<Field>(face) {}
     164                 :             : 
     165                 :           0 :         virtual FieldBC getBCType() const { return PERIODIC_FACE; }
     166                 :             : 
     167                 :             :         virtual void findBCNeighbors(Field& field);
     168                 :             :         virtual void apply(Field& field);
     169                 :             : 
     170                 :             :         virtual void write(std::ostream& out) const;
     171                 :             : 
     172                 :             :     private:
     173                 :             :         face_neighbor_type faceNeighbors_m;
     174                 :             :         typename Field::halo_type::databuffer_type haloData_m;
     175                 :             :     };
     176                 :             : }  // namespace ippl
     177                 :             : 
     178                 :             : #include "Field/BcTypes.hpp"
     179                 :             : 
     180                 :             : #endif
        

Generated by: LCOV version 2.0-1