OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
ParticleBConds.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 *
7 * Visit http://people.web.psi.ch/adelmann/ for more details
8 *
9 ***************************************************************************/
10
11#ifndef PARTICLE_BCONDS_H
12#define PARTICLE_BCONDS_H
13
14/***************************************************************************
15 * ParticleBConds is a container for a set of particle boundary condition
16 * functions. Boundary conditions for particles are not objects, but just
17 * functions which map a position X -> X', given the minimum and maximum
18 * values of the spatial domain.
19 ***************************************************************************/
20
21// include files
22#include "Region/NDRegion.h"
23#include "Index/NDIndex.h"
24
25
26
28// particle boundary condition functions ...
29
30// null BC; value is not changed
31template<class T>
32inline T ParticleNoBCond(const T t, const T /* minval */, const T /* maxval */) {
33 return t;
34}
35
36// periodic BC; values wrap around at endpoints of the interval
37template<class T>
38inline T ParticlePeriodicBCond(const T t, const T minval, const T maxval) {
39 if (t < minval)
40 return (maxval - (minval - t));
41 else if (t >= maxval)
42 return (minval + (t - maxval));
43 else
44 return t;
45}
46
47// reflective BC; values bounce back from endpoints
48template<class T>
49inline T ParticleReflectiveBCond(const T t, const T minval, const T maxval) {
50 if (t < minval)
51 return (minval + (minval - t));
52 else if (t >= maxval)
53 return (maxval - (t - maxval));
54 else
55 return t;
56}
57
58// sink BC; particles stick to the selected face
59template<class T>
60inline T ParticleSinkBCond(const T t, const T minval, const T maxval) {
61 if (t < minval)
62 return minval;
63 else if (t >= maxval)
64 return maxval;
65 else
66 return t;
67}
68
69
71// general container for a set of particle boundary conditions
72template<class T, unsigned Dim>
74
75public:
76 // typedef for a pointer to boundary condition function
77 typedef T (*ParticleBCond)(const T, const T, const T);
78
79public:
80 // constructor: initialize all BC's to null ones, which do not change
81 // the value of the data any
83 for (int d=(2*Dim - 1); d >= 0; --d)
85 }
86
87 // operator= to copy values from another container
89 for (int d=(2*Dim - 1); d >= 0; --d)
90 BCList[d] = pbc.BCList[d];
91 return *this;
92 }
93
94 // operator[] to get value of Nth boundary condition
95 ParticleBCond& operator[](unsigned d) { return BCList[d]; }
96
97 // for the given value in the given dimension over the given NDRegion,
98 // apply the proper BC and return back the new value
99 T apply(const T t, const unsigned d, const NDRegion<T,Dim>& nr) const {
100 return apply(t, d, nr[d].min(), nr[d].max());
101 }
102
103 // for the given value in the given dimension over the given NDIndex,
104 // apply the proper BC and return back the new value. The extra +1
105 // added to the max value is due to the assumption of a cell-centered
106 // field.
107 T apply(const T t, const unsigned d, const NDIndex<Dim>& ni) const {
108 return apply(t, d, ni[d].first(), ni[d].last() + 1);
109 }
110
111 // a different version of apply, where the user just specifies the min
112 // and max values of the given dimension
113 T apply(const T t, const unsigned d, const T m1, const T m2) const {
114 if (t < m1)
115 return (BCList[d+d])(t, m1, m2);
116 else if (t >= m2) // here we take into account that
117 return (BCList[d+d+1])(t, m1, m2); // Region's store intervals [A,B)
118 else
119 return t;
120 }
121
122private:
123 // array storing the function pointers
125
126};
127
128#endif // PARTICLE_BCONDS_H
129
130/***************************************************************************
131 * $RCSfile: ParticleBConds.h,v $ $Author: adelmann $
132 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $
133 * IPPL_VERSION_ID: $Id: ParticleBConds.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $
134 ***************************************************************************/
const int nr
Definition: ClassicRandom.h:24
const unsigned Dim
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
T ParticlePeriodicBCond(const T t, const T minval, const T maxval)
T ParticleSinkBCond(const T t, const T minval, const T maxval)
T ParticleReflectiveBCond(const T t, const T minval, const T maxval)
T ParticleNoBCond(const T t, const T, const T)
T apply(const T t, const unsigned d, const NDRegion< T, Dim > &nr) const
T(* ParticleBCond)(const T, const T, const T)
ParticleBCond BCList[2 *Dim]
ParticleBCond & operator[](unsigned d)
ParticleBConds< T, Dim > & operator=(const ParticleBConds< T, Dim > &pbc)
T apply(const T t, const unsigned d, const NDIndex< Dim > &ni) const
T apply(const T t, const unsigned d, const T m1, const T m2) const