00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef PARTICLE_BCONDS_H
00012 #define PARTICLE_BCONDS_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Region/NDRegion.h"
00023 #include "Index/NDIndex.h"
00024
00025
00026
00028
00029
00030
00031 template<class T>
00032 T ParticleNoBCond(const T t, const T , const T ) {
00033 return t;
00034 }
00035
00036
00037 template<class T>
00038 T ParticlePeriodicBCond(const T t, const T minval, const T maxval) {
00039 if (t < minval)
00040 return (maxval - (minval - t));
00041 else if (t >= maxval)
00042 return (minval + (t - maxval));
00043 else
00044 return t;
00045 }
00046
00047
00048 template<class T>
00049 T ParticleReflectiveBCond(const T t, const T minval, const T maxval) {
00050 if (t < minval)
00051 return (minval + (minval - t));
00052 else if (t >= maxval)
00053 return (maxval - (t - maxval));
00054 else
00055 return t;
00056 }
00057
00058
00059 template<class T>
00060 T ParticleSinkBCond(const T t, const T minval, const T maxval) {
00061 if (t < minval)
00062 return minval;
00063 else if (t >= maxval)
00064 return maxval;
00065 else
00066 return t;
00067 }
00068
00069
00071
00072 template<class T, unsigned Dim>
00073 class ParticleBConds {
00074
00075 public:
00076
00077 typedef T (*ParticleBCond)(const T, const T, const T);
00078
00079 public:
00080
00081
00082 ParticleBConds() {
00083 for (int d=(2*Dim - 1); d >= 0; --d)
00084 BCList[d] = ParticleNoBCond;
00085 }
00086
00087
00088 ParticleBConds<T,Dim>& operator=(const ParticleBConds<T,Dim>& pbc) {
00089 for (int d=(2*Dim - 1); d >= 0; --d)
00090 BCList[d] = pbc.BCList[d];
00091 return *this;
00092 }
00093
00094
00095 ParticleBCond& operator[](unsigned d) { return BCList[d]; }
00096
00097
00098
00099 T apply(const T t, const unsigned d, const NDRegion<T,Dim>& nr) const {
00100 return apply(t, d, nr[d].min(), nr[d].max());
00101 }
00102
00103
00104
00105
00106
00107 T apply(const T t, const unsigned d, const NDIndex<Dim>& ni) const {
00108 return apply(t, d, ni[d].first(), ni[d].last() + 1);
00109 }
00110
00111
00112
00113 T apply(const T t, const unsigned d, const T m1, const T m2) const {
00114 if (t < m1)
00115 return (BCList[d+d])(t, m1, m2);
00116 else if (t >= m2)
00117 return (BCList[d+d+1])(t, m1, m2);
00118 else
00119 return t;
00120 }
00121
00122 private:
00123
00124 ParticleBCond BCList[2*Dim];
00125
00126 };
00127
00128 #endif // PARTICLE_BCONDS_H
00129
00130
00131
00132
00133
00134