IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
ParticleBC.h
Go to the documentation of this file.
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 {
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())
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> {
62
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> {
85
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> {
113
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
constexpr unsigned Dim
Definition Archive.h:20
@ REFLECTIVE
Definition ParticleBC.h:13
@ SINK
Definition ParticleBC.h:14
@ PERIODIC
Definition ParticleBC.h:12
KOKKOS_INLINE_FUNCTION Vector< T, Dim > min(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
Definition Vector.hpp:217
bool isUpper(unsigned int face)
size_t dim_m
The dimension along which this boundary condition.
Definition ParticleBC.h:28
KOKKOS_INLINE_FUNCTION ParticleBC(const ViewType &view, const NDRegion< T, Dim > &nr, const unsigned &dim, const bool &isUpper)
Definition ParticleBC.h:44
double middle_m
The coordinate of the midpoint of the domain along the given dimension.
Definition ParticleBC.h:39
KOKKOS_DEFAULTED_FUNCTION ~ParticleBC()=default
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
typename ViewType::value_type::value_type value_type
Definition ParticleBC.h:22
double extent_m
The length of the domain along the given dimension.
Definition ParticleBC.h:37
KOKKOS_DEFAULTED_FUNCTION ParticleBC()=default
double minval_m
Minimum and maximum coordinates of the domain along the given dimension.
Definition ParticleBC.h:30
KOKKOS_INLINE_FUNCTION void operator()(const size_t &i) const
Definition ParticleBC.h:73
KOKKOS_DEFAULTED_FUNCTION ~PeriodicBC()=default
KOKKOS_DEFAULTED_FUNCTION PeriodicBC()=default
KOKKOS_INLINE_FUNCTION PeriodicBC(const ViewType &view, const NDRegion< T, Dim > &nr, const unsigned &dim, const bool &isUpper)
Definition ParticleBC.h:69
typename ParticleBC< T, Dim, ViewType >::value_type value_type
Definition ParticleBC.h:61
KOKKOS_INLINE_FUNCTION void operator()(const size_t &i) const
Definition ParticleBC.h:97
KOKKOS_DEFAULTED_FUNCTION ~ReflectiveBC()=default
KOKKOS_DEFAULTED_FUNCTION ReflectiveBC()=default
KOKKOS_INLINE_FUNCTION ReflectiveBC(const ViewType &view, const NDRegion< T, Dim > &nr, const unsigned &dim, const bool &isUpper)
Definition ParticleBC.h:93
typename ParticleBC< T, Dim, ViewType >::value_type value_type
Definition ParticleBC.h:84
KOKKOS_INLINE_FUNCTION SinkBC(const ViewType &view, const NDRegion< T, Dim > &nr, const unsigned &dim, const bool &isUpper)
Definition ParticleBC.h:121
KOKKOS_DEFAULTED_FUNCTION ~SinkBC()=default
KOKKOS_DEFAULTED_FUNCTION SinkBC()=default
KOKKOS_INLINE_FUNCTION void operator()(const size_t &i) const
Definition ParticleBC.h:125
typename ParticleBC< T, Dim, ViewType >::value_type value_type
Definition ParticleBC.h:112