src/Particle/ParticleBConds.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef PARTICLE_BCONDS_H
00012 #define PARTICLE_BCONDS_H
00013 
00014 /***************************************************************************
00015  * ParticleBConds is a container for a set of particle boundary condition
00016  * functions.  Boundary conditions for particles are not objects, but just
00017  * functions which map a position X -> X', given the minimum and maximum
00018  * values of the spatial domain.
00019  ***************************************************************************/
00020 
00021 // include files
00022 #include "Region/NDRegion.h"
00023 #include "Index/NDIndex.h"
00024 
00025 
00026 
00028 // particle boundary condition functions ...
00029 
00030 // null BC; value is not changed
00031 template<class T>
00032 T ParticleNoBCond(const T t, const T /* minval */, const T /* maxval */) {
00033   return t;
00034 }
00035 
00036 // periodic BC; values wrap around at endpoints of the interval
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 // reflective BC; values bounce back from endpoints
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 // sink BC; particles stick to the selected face
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 // general container for a set of particle boundary conditions
00072 template<class T, unsigned Dim>
00073 class ParticleBConds {
00074 
00075 public:
00076   // typedef for a pointer to boundary condition function
00077   typedef T (*ParticleBCond)(const T, const T, const T);
00078 
00079 public:
00080   // constructor: initialize all BC's to null ones, which do not change
00081   // the value of the data any
00082   ParticleBConds() {
00083     for (int d=(2*Dim - 1); d >= 0; --d)
00084       BCList[d] = ParticleNoBCond;
00085   }
00086 
00087   // operator= to copy values from another container
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   // operator[] to get value of Nth boundary condition
00095   ParticleBCond& operator[](unsigned d) { return BCList[d]; }
00096 
00097   // for the given value in the given dimension over the given NDRegion,
00098   // apply the proper BC and return back the new value
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   // for the given value in the given dimension over the given NDIndex,
00104   // apply the proper BC and return back the new value.  The extra +1
00105   // added to the max value is due to the assumption of a cell-centered
00106   // field.
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   // a different version of apply, where the user just specifies the min
00112   // and max values of the given dimension
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)                      // here we take into account that
00117       return (BCList[d+d+1])(t, m1, m2);   // Region's store intervals [A,B)
00118     else
00119       return t;
00120   }
00121 
00122 private:
00123   // array storing the function pointers
00124   ParticleBCond BCList[2*Dim];
00125 
00126 };
00127 
00128 #endif // PARTICLE_BCONDS_H
00129 
00130 /***************************************************************************
00131  * $RCSfile: ParticleBConds.h,v $   $Author: adelmann $
00132  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:28 $
00133  * IPPL_VERSION_ID: $Id: ParticleBConds.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $ 
00134  ***************************************************************************/

Generated on Mon Jan 16 13:23:53 2006 for IPPL by  doxygen 1.4.6