IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
BcTypes.h
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
25namespace 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:
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 KOKKOS_FUNCTION
56 virtual ~BCondBase() {}
57
58 virtual FieldBC getBCType() const { return NO_FACE; }
59
60 virtual void findBCNeighbors(Field& field) = 0;
61 virtual void apply(Field& field) = 0;
62 virtual void assignGhostToPhysical(Field& field) = 0;
63 virtual void write(std::ostream&) const = 0;
64
65 // Return face on which BC applies
66 unsigned int getFace() const { return face_m; }
67
68 // Returns whether or not this BC changes physical cells.
69 bool changesPhysicalCells() const { return changePhysical_m; }
70
71 protected:
72 // What face to apply the boundary condition to.
73 unsigned int face_m;
74
75 // True if this boundary condition changes physical cells.
76 bool changePhysical_m;
77 };
78
79 template <typename Field>
80 std::ostream& operator<<(std::ostream&, const BCondBase<Field>&);
81
82 } // namespace detail
83
84 template <typename Field>
85 class ExtrapolateFace : public detail::BCondBase<Field> {
86 constexpr static unsigned Dim = Field::dim;
87 using T = typename Field::value_type;
88
89 public:
90 // Constructor takes zero, one, or two int's specifying components of
91 // multicomponent types like Vector this BC applies to.
92 // Zero int's specified means apply to all components; one means apply to
93 // component (i), and two means apply to component (i,j),
95 using Layout_t = typename detail::BCondBase<Field>::Layout_t;
96
97 ExtrapolateFace(unsigned face, T offset, T slope)
98 : base_type(face)
99 , offset_m(offset)
100 , slope_m(slope) {}
101
102 KOKKOS_FUNCTION
103 virtual ~ExtrapolateFace() {}
104
105 virtual FieldBC getBCType() const { return EXTRAPOLATE_FACE; }
106
107 virtual void findBCNeighbors(Field& /*field*/) {}
108 virtual void apply(Field& field);
109 virtual void assignGhostToPhysical(Field& field);
110
111 virtual void write(std::ostream& out) const;
112
113 const T& getOffset() const { return offset_m; }
114 const T& getSlope() const { return slope_m; }
115
116 protected:
117 T offset_m;
118 T slope_m;
119 };
120
121 template <typename Field>
122 class NoBcFace : public detail::BCondBase<Field> {
123 public:
124 NoBcFace(int face)
125 : detail::BCondBase<Field>(face) {}
126
127 virtual void findBCNeighbors(Field& /*field*/) {}
128 virtual void apply(Field& /*field*/) {}
129 virtual void assignGhostToPhysical(Field& /*field*/) {}
130
131 virtual void write(std::ostream& out) const;
132 };
133
134 template <typename Field>
135 class ConstantFace : public ExtrapolateFace<Field> {
136 using T = typename Field::value_type;
137
138 public:
139 ConstantFace(unsigned int face, T constant)
140 : ExtrapolateFace<Field>(face, constant, 0) {}
141
142 virtual FieldBC getBCType() const { return CONSTANT_FACE; }
143
144 virtual void write(std::ostream& out) const;
145 };
146
147 template <typename Field>
148 class ZeroFace : public ConstantFace<Field> {
149 public:
150 ZeroFace(unsigned face)
151 : ConstantFace<Field>(face, 0.0) {}
152
153 virtual FieldBC getBCType() const { return ZERO_FACE; }
154
155 virtual void write(std::ostream& out) const;
156 };
157
158 template <typename Field>
159 class PeriodicFace : public detail::BCondBase<Field> {
160 constexpr static unsigned Dim = Field::dim;
161 using T = typename Field::value_type;
162
163 public:
164 using face_neighbor_type = std::array<std::vector<int>, 2 * Dim>;
165 using Layout_t = typename detail::BCondBase<Field>::Layout_t;
166
167 PeriodicFace(unsigned face)
168 : detail::BCondBase<Field>(face) {}
169
170 virtual FieldBC getBCType() const { return PERIODIC_FACE; }
171
172 virtual void findBCNeighbors(Field& field);
173 virtual void apply(Field& field);
174 virtual void assignGhostToPhysical(Field& field);
175
176 virtual void write(std::ostream& out) const;
177
178 private:
179 face_neighbor_type faceNeighbors_m;
180 typename Field::halo_type::databuffer_type haloData_m;
181 };
182} // namespace ippl
183
184#include "Field/BcTypes.hpp"
185
186#endif
Definition BcTypes.h:135
Definition BcTypes.h:85
Definition FieldLayout.h:166
Definition Field.h:18
Definition BcTypes.h:122
Definition BcTypes.h:159
Definition BcTypes.h:148
Definition BcTypes.h:43
Definition Archive.h:20