IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
ParticleBC.h
1//
2// Functor ParticleBC
3// Functors specifying particle boundary conditions.
4//
5#ifndef IPPL_PARTICLE_BC_H
6#define IPPL_PARTICLE_BC_H
7
8#include "Region/NDRegion.h"
9
10namespace ippl {
11 enum BC {
12 PERIODIC,
13 REFLECTIVE,
14 SINK,
15 NO
16 };
17
18 namespace detail {
19
20 template <typename T, unsigned Dim, class ViewType>
21 struct ParticleBC {
22 using value_type = typename ViewType::value_type::value_type;
23
27 // is applied
28 size_t dim_m;
30 double minval_m;
31 double maxval_m;
33 // face (i.e. with greater coordinate values)
35
37 double extent_m;
39 double middle_m;
40
41 KOKKOS_DEFAULTED_FUNCTION
42 ParticleBC() = default;
43
44 KOKKOS_INLINE_FUNCTION ParticleBC(const ViewType& view, const NDRegion<T, Dim>& nr,
45 const unsigned& dim, const bool& isUpper)
46 : view_m(view)
47 , dim_m(dim)
48 , minval_m(nr[dim].min())
49 , maxval_m(nr[dim].max())
50 , isUpper_m(isUpper) {
51 extent_m = nr[dim].length();
52 middle_m = (minval_m + maxval_m) / 2;
53 }
54
55 KOKKOS_DEFAULTED_FUNCTION
56 ~ParticleBC() = default;
57 };
58
59 template <typename T, unsigned Dim, class ViewType>
60 struct PeriodicBC : public ParticleBC<T, Dim, ViewType> {
61 using value_type = typename ParticleBC<T, Dim, ViewType>::value_type;
62
63 using ParticleBC<T, Dim, ViewType>::extent_m;
64 using ParticleBC<T, Dim, ViewType>::middle_m;
65
66 KOKKOS_DEFAULTED_FUNCTION
67 PeriodicBC() = default;
68
69 KOKKOS_INLINE_FUNCTION PeriodicBC(const ViewType& view, const NDRegion<T, Dim>& nr,
70 const unsigned& dim, const bool& isUpper)
71 : ParticleBC<T, Dim, ViewType>(view, nr, dim, isUpper) {}
72
73 KOKKOS_INLINE_FUNCTION void operator()(const size_t& i) const {
74 value_type& value = this->view_m(i)[this->dim_m];
75 value = value - extent_m * (int)((value - middle_m) * 2 / extent_m);
76 }
77
78 KOKKOS_DEFAULTED_FUNCTION
79 ~PeriodicBC() = default;
80 };
81
82 template <typename T, unsigned Dim, class ViewType>
83 struct ReflectiveBC : public ParticleBC<T, Dim, ViewType> {
84 using value_type = typename ParticleBC<T, Dim, ViewType>::value_type;
85
86 using ParticleBC<T, Dim, ViewType>::maxval_m;
87 using ParticleBC<T, Dim, ViewType>::minval_m;
88 using ParticleBC<T, Dim, ViewType>::isUpper_m;
89
90 KOKKOS_DEFAULTED_FUNCTION
91 ReflectiveBC() = default;
92
93 KOKKOS_INLINE_FUNCTION ReflectiveBC(const ViewType& view, const NDRegion<T, Dim>& nr,
94 const unsigned& dim, const bool& isUpper)
95 : ParticleBC<T, Dim, ViewType>(view, nr, dim, isUpper) {}
96
97 KOKKOS_INLINE_FUNCTION void operator()(const size_t& i) const {
98 value_type& value = this->view_m(i)[this->dim_m];
99 bool tooHigh = value >= maxval_m;
100 bool tooLow = value < minval_m;
101 value += 2
102 * ((tooHigh && isUpper_m) * (maxval_m - value)
103 + (tooLow && !isUpper_m) * (minval_m - value));
104 }
105
106 KOKKOS_DEFAULTED_FUNCTION
107 ~ReflectiveBC() = default;
108 };
109
110 template <typename T, unsigned Dim, class ViewType>
111 struct SinkBC : public ParticleBC<T, Dim, ViewType> {
112 using value_type = typename ParticleBC<T, Dim, ViewType>::value_type;
113
114 using ParticleBC<T, Dim, ViewType>::maxval_m;
115 using ParticleBC<T, Dim, ViewType>::minval_m;
116 using ParticleBC<T, Dim, ViewType>::isUpper_m;
117
118 KOKKOS_DEFAULTED_FUNCTION
119 SinkBC() = default;
120
121 KOKKOS_INLINE_FUNCTION SinkBC(const ViewType& view, const NDRegion<T, Dim>& nr,
122 const unsigned& dim, const bool& isUpper)
123 : ParticleBC<T, Dim, ViewType>(view, nr, dim, isUpper) {}
124
125 KOKKOS_INLINE_FUNCTION void operator()(const size_t& i) const {
126 value_type& value = this->view_m(i)[this->dim_m];
127 bool tooHigh = value >= maxval_m;
128 bool tooLow = value < minval_m;
129 value += (tooHigh && isUpper_m) * (maxval_m - value)
130 + (tooLow && !isUpper_m) * (minval_m - value);
131 }
132
133 KOKKOS_DEFAULTED_FUNCTION
134 ~SinkBC() = default;
135 };
136
137 } // namespace detail
138} // namespace ippl
139
140#endif
Definition NDRegion.h:20
Definition Archive.h:20
Definition ParticleBC.h:21
size_t dim_m
The dimension along which this boundary condition.
Definition ParticleBC.h:28
double middle_m
The coordinate of the midpoint of the domain along the given dimension.
Definition ParticleBC.h:39
bool isUpper_m
Whether the boundary conditions are being applied for an upper.
Definition ParticleBC.h:34
ViewType view_m
Kokkos view containing the field data.
Definition ParticleBC.h:25
double extent_m
The length of the domain along the given dimension.
Definition ParticleBC.h:37
double minval_m
Minimum and maximum coordinates of the domain along the given dimension.
Definition ParticleBC.h:30
Definition ParticleBC.h:60
Definition ParticleBC.h:83
Definition ParticleBC.h:111
Definition ViewTypes.h:44