src/Particle/IntSUDS.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 INT_SUDS_H
00012 #define INT_SUDS_H
00013 
00014 /* IntSUDS.h -- Definition of simple class to perform subtracted dipole
00015    interpolation of data for a single particle to or from a IPPL Field.   */
00016 
00017 // include files
00018 #include "Particle/Interpolator.h"
00019 #include "Field/Field.h"
00020 
00021 
00022 // forward declaration
00023 class IntSUDS;
00024 
00025 // specialization of InterpolatorTraits
00026 template <class T, unsigned Dim>
00027 struct InterpolatorTraits<T,Dim,IntSUDS> {
00028   typedef CacheData1<T,Dim> Cache_t;
00029 };
00030 
00031 
00032 // IntSUDSImpl class definition
00033 template <unsigned Dim>
00034 class IntSUDSImpl : public Interpolator {
00035 
00036 public:
00037   // constructor/destructor
00038   IntSUDSImpl() {}
00039   ~IntSUDSImpl() {}
00040 
00041   // gather/scatter functions
00042 
00043   // scatter particle data into Field using particle position and mesh
00044   template <class FT, class M, class C, class PT>
00045   static
00046   void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
00047                const Vektor<PT,Dim>& ppos, const M& mesh) {
00048     CenteringTag<C> ctag;
00049     Vektor<PT,Dim> gpos, dpos, delta;
00050     //    unsigned int d;
00051     // find nearest grid point for particle position, store in NDIndex obj
00052     NDIndex<Dim> ngp = FindNGP(mesh, ppos, ctag);
00053     // get position of ngp
00054     FindPos(gpos, mesh, ngp, ctag);
00055     // get distance from ppos to gpos
00056     dpos = ppos - gpos;
00057     // get mesh spacings
00058     FindDelta(delta, mesh, ngp, ctag);
00059     // normalize dpos by mesh spacing
00060     dpos /= delta;
00061     // Try to find ngp in local fields and get iterator
00062     CompressedBrickIterator<FT,Dim> fiter = getFieldIter(f,ngp);
00063     // accumulate into local elements
00064     ERRORMSG("IntSUDS::scatter: not implemented for Dim>3!!"<<endl);
00065     return;
00066   }
00067 
00068   // scatter particle data into Field using particle position and mesh
00069   // and cache mesh information for reuse
00070   template <class FT, class M, class C, class PT>
00071   static
00072   void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
00073                const Vektor<PT,Dim>& ppos, const M& mesh,
00074                NDIndex<Dim>& ngp, Vektor<PT,Dim>& dpos) {
00075     CenteringTag<C> ctag;
00076     Vektor<PT,Dim> gpos, delta;
00077     //    unsigned int d;
00078     // find nearest grid point for particle position, store in NDIndex obj
00079     ngp = FindNGP(mesh, ppos, ctag);
00080     // get position of ngp
00081     FindPos(gpos, mesh, ngp, ctag);
00082     // get distance from ppos to gpos
00083     dpos = ppos - gpos;
00084     // get mesh spacings
00085     FindDelta(delta, mesh, ngp, ctag);
00086     // normalize dpos by mesh spacing
00087     dpos /= delta;
00088     // Try to find ngp in local fields and get iterator
00089     CompressedBrickIterator<FT,Dim> fiter = getFieldIter(f,ngp);
00090     // accumulate into local elements
00091     ERRORMSG("IntSUDS::scatter: not implemented for Dim>3!!"<<endl);
00092     return;
00093   }
00094 
00095   // scatter particle data into Field using cached mesh information
00096   template <class FT, class M, class C, class PT>
00097   static
00098   void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
00099                const NDIndex<Dim>& ngp, const Vektor<PT,Dim>& dpos) {
00100     // Try to find ngp in local fields and get iterator
00101     CompressedBrickIterator<FT,Dim> fiter = getFieldIter(f,ngp);
00102     // accumulate into local elements
00103     ERRORMSG("IntSUDS::scatter: not implemented for Dim>3!!"<<endl);
00104     return;
00105   }
00106 
00107   // gather particle data from Field using particle position and mesh
00108   template <class FT, class M, class C, class PT>
00109   static
00110   void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
00111               const Vektor<PT,Dim>& ppos, const M& mesh) {
00112     CenteringTag<C> ctag;
00113     Vektor<PT,Dim> gpos, dpos, delta;
00114     //    unsigned int d;
00115     // find nearest grid point for particle position, store in NDIndex obj
00116     NDIndex<Dim> ngp = FindNGP(mesh, ppos, ctag);
00117     // get position of ngp
00118     FindPos(gpos, mesh, ngp, ctag);
00119     // get distance from ppos to gpos
00120     dpos = ppos - gpos;
00121     // get mesh spacings
00122     FindDelta(delta, mesh, ngp, ctag);
00123     // normalize dpos by mesh spacing
00124     dpos /= delta;
00125     // Try to find ngp in local fields and get iterator
00126     CompressedBrickIterator<FT,Dim> fiter = getFieldIter(f,ngp);
00127     // accumulate into particle attrib
00128     ERRORMSG("IntSUDS::gather: not implemented for Dim>3!!"<<endl);
00129     return;
00130   }
00131 
00132   // gather particle data from Field using particle position and mesh
00133   // and cache mesh information for reuse
00134   template <class FT, class M, class C, class PT>
00135   static
00136   void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
00137               const Vektor<PT,Dim>& ppos, const M& mesh,
00138               NDIndex<Dim>& ngp, Vektor<PT,Dim>& dpos) {
00139     CenteringTag<C> ctag;
00140     Vektor<PT,Dim> gpos, delta;
00141     //    unsigned int d;
00142     // find nearest grid point for particle position, store in NDIndex obj
00143     ngp = FindNGP(mesh, ppos, ctag);
00144     // get position of ngp
00145     FindPos(gpos, mesh, ngp, ctag);
00146     // get distance from ppos to gpos
00147     dpos = ppos - gpos;
00148     // get mesh spacings
00149     FindDelta(delta, mesh, ngp, ctag);
00150     // normalize dpos by mesh spacing
00151     dpos /= delta;
00152     // Try to find ngp in local fields and get iterator
00153     CompressedBrickIterator<FT,Dim> fiter = getFieldIter(f,ngp);
00154     // accumulate into particle attrib
00155     ERRORMSG("IntSUDS::gather: not implemented for Dim>3!!"<<endl);
00156     return;
00157   }
00158 
00159   // gather particle data from Field using cached mesh information
00160   template <class FT, class M, class C, class PT>
00161   static
00162   void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
00163               const NDIndex<Dim>& ngp, const Vektor<PT,Dim>& dpos) {
00164     // Try to find ngp in local fields and get iterator
00165     CompressedBrickIterator<FT,Dim> fiter = getFieldIter(f,ngp);
00166     // accumulate into particle attrib
00167     ERRORMSG("IntSUDS::gather: not implemented for Dim>3!!"<<endl);
00168     return;
00169   }
00170 
00171 };
00172 
00173 
00174 template <>
00175 class IntSUDSImpl<1U> : public Interpolator {
00176 
00177 public:
00178   // constructor/destructor
00179   IntSUDSImpl() {}
00180   ~IntSUDSImpl() {}
00181 
00182   // gather/scatter functions
00183 
00184   // scatter particle data into Field using particle position and mesh
00185   template <class FT, class M, class C, class PT>
00186   static
00187   void scatter(const FT& pdata, Field<FT,1U,M,C>& f,
00188                const Vektor<PT,1U>& ppos, const M& mesh) {
00189     CenteringTag<C> ctag;
00190     Vektor<PT,1U> gpos, dpos, delta;
00191     // find nearest grid point for particle position, store in NDIndex obj
00192     NDIndex<1U> ngp = FindNGP(mesh, ppos, ctag);
00193     // get position of ngp
00194     FindPos(gpos, mesh, ngp, ctag);
00195     // get distance from ppos to gpos
00196     dpos = ppos - gpos;
00197     // get mesh spacings
00198     FindDelta(delta, mesh, ngp, ctag);
00199     // normalize dpos by mesh spacing
00200     dpos /= delta;
00201     // Try to find ngp in local fields and get iterator
00202     CompressedBrickIterator<FT,1U> fiter = getFieldIter(f,ngp);
00203     // accumulate into local elements
00204     *fiter += pdata;
00205     fiter.offset( 1) += 0.5 * dpos(0) * pdata;
00206     fiter.offset(-1) -= 0.5 * dpos(0) * pdata;
00207     return;
00208   }
00209 
00210   // scatter particle data into Field using particle position and mesh
00211   // and cache mesh information for reuse
00212   template <class FT, class M, class C, class PT>
00213   static
00214   void scatter(const FT& pdata, Field<FT,1U,M,C>& f,
00215                const Vektor<PT,1U>& ppos, const M& mesh,
00216                NDIndex<1U>& ngp, Vektor<PT,1U>& dpos) {
00217     CenteringTag<C> ctag;
00218     Vektor<PT,1U> gpos, delta;
00219     // find nearest grid point for particle position, store in NDIndex obj
00220     ngp = FindNGP(mesh, ppos, ctag);
00221     // get position of ngp
00222     FindPos(gpos, mesh, ngp, ctag);
00223     // get distance from ppos to gpos
00224     dpos = ppos - gpos;
00225     // get mesh spacings
00226     FindDelta(delta, mesh, ngp, ctag);
00227     // normalize dpos by mesh spacing
00228     dpos /= delta;
00229     // Try to find ngp in local fields and get iterator
00230     CompressedBrickIterator<FT,1U> fiter = getFieldIter(f,ngp);
00231     // accumulate into local elements
00232     *fiter += pdata;
00233     fiter.offset( 1) += 0.5 * dpos(0) * pdata;
00234     fiter.offset(-1) -= 0.5 * dpos(0) * pdata;
00235     return;
00236   }
00237 
00238   // scatter particle data into Field using cached mesh information
00239   template <class FT, class M, class C, class PT>
00240   static
00241   void scatter(const FT& pdata, Field<FT,1U,M,C>& f,
00242                const NDIndex<1U>& ngp, const Vektor<PT,1U>& dpos) {
00243     // Try to find ngp in local fields and get iterator
00244     CompressedBrickIterator<FT,1U> fiter = getFieldIter(f,ngp);
00245     // accumulate into local elements
00246     *fiter += pdata;
00247     fiter.offset( 1) += 0.5 * dpos(0) * pdata;
00248     fiter.offset(-1) -= 0.5 * dpos(0) * pdata;
00249     return;
00250   }
00251 
00252   // gather particle data from Field using particle position and mesh
00253   template <class FT, class M, class C, class PT>
00254   static
00255   void gather(FT& pdata, const Field<FT,1U,M,C>& f,
00256               const Vektor<PT,1U>& ppos, const M& mesh) {
00257     CenteringTag<C> ctag;
00258     Vektor<PT,1U> gpos, dpos, delta;
00259     // find nearest grid point for particle position, store in NDIndex obj
00260     NDIndex<1U> ngp = FindNGP(mesh, ppos, ctag);
00261     // get position of ngp
00262     FindPos(gpos, mesh, ngp, ctag);
00263     // get distance from ppos to gpos
00264     dpos = ppos - gpos;
00265     // get mesh spacings
00266     FindDelta(delta, mesh, ngp, ctag);
00267     // normalize dpos by mesh spacing
00268     dpos /= delta;
00269     // Try to find ngp in local fields and get iterator
00270     CompressedBrickIterator<FT,1U> fiter = getFieldIter(f,ngp);
00271     // accumulate into particle attrib
00272     pdata = (*fiter) +
00273             0.5 * dpos(0) * (fiter.offset(1) - fiter.offset(-1));
00274     return;
00275   }
00276 
00277   // gather particle data from Field using particle position and mesh
00278   // and cache mesh information for reuse
00279   template <class FT, class M, class C, class PT>
00280   static
00281   void gather(FT& pdata, const Field<FT,1U,M,C>& f,
00282               const Vektor<PT,1U>& ppos, const M& mesh,
00283               NDIndex<1U>& ngp, Vektor<PT,1U>& dpos) {
00284     CenteringTag<C> ctag;
00285     Vektor<PT,1U> gpos, delta;
00286     // find nearest grid point for particle position, store in NDIndex obj
00287     ngp = FindNGP(mesh, ppos, ctag);
00288     // get position of ngp
00289     FindPos(gpos, mesh, ngp, ctag);
00290     // get distance from ppos to gpos
00291     dpos = ppos - gpos;
00292     // get mesh spacings
00293     FindDelta(delta, mesh, ngp, ctag);
00294     // normalize dpos by mesh spacing
00295     dpos /= delta;
00296     // Try to find ngp in local fields and get iterator
00297     CompressedBrickIterator<FT,1U> fiter = getFieldIter(f,ngp);
00298     // accumulate into particle attrib
00299     pdata = (*fiter) +
00300             0.5 * dpos(0) * (fiter.offset(1) - fiter.offset(-1));
00301     return;
00302   }
00303 
00304   // gather particle data from Field using cached mesh information
00305   template <class FT, class M, class C, class PT>
00306   static
00307   void gather(FT& pdata, const Field<FT,1U,M,C>& f,
00308               const NDIndex<1U>& ngp, const Vektor<PT,1U>& dpos) {
00309     // Try to find ngp in local fields and get iterator
00310     CompressedBrickIterator<FT,1U> fiter = getFieldIter(f,ngp);
00311     // accumulate into particle attrib
00312     pdata = (*fiter) +
00313             0.5 * dpos(0) * (fiter.offset(1) - fiter.offset(-1));
00314     return;
00315   }
00316 
00317 };
00318 
00319 
00320 template <>
00321 class IntSUDSImpl<2U> : public Interpolator {
00322 
00323 public:
00324   // constructor/destructor
00325   IntSUDSImpl() {}
00326   ~IntSUDSImpl() {}
00327 
00328   // gather/scatter functions
00329 
00330   // scatter particle data into Field using particle position and mesh
00331   template <class FT, class M, class C, class PT>
00332   static
00333   void scatter(const FT& pdata, Field<FT,2U,M,C>& f,
00334                const Vektor<PT,2U>& ppos, const M& mesh) {
00335     CenteringTag<C> ctag;
00336     Vektor<PT,2U> gpos, dpos, delta;
00337     // find nearest grid point for particle position, store in NDIndex obj
00338     NDIndex<2U> ngp = FindNGP(mesh, ppos, ctag);
00339     // get position of ngp
00340     FindPos(gpos, mesh, ngp, ctag);
00341     // get distance from ppos to gpos
00342     dpos = ppos - gpos;
00343     // get mesh spacings
00344     FindDelta(delta, mesh, ngp, ctag);
00345     // normalize dpos by mesh spacing
00346     dpos /= delta;
00347     // Try to find ngp in local fields and get iterator
00348     CompressedBrickIterator<FT,2U> fiter = getFieldIter(f,ngp);
00349     // accumulate into local elements
00350     *fiter += pdata;
00351     fiter.offset( 1,0) += 0.5 * dpos(0) * pdata;
00352     fiter.offset(-1,0) -= 0.5 * dpos(0) * pdata;
00353     fiter.offset(0, 1) += 0.5 * dpos(1) * pdata;
00354     fiter.offset(0,-1) -= 0.5 * dpos(1) * pdata;
00355     return;
00356   }
00357 
00358   // scatter particle data into Field using particle position and mesh
00359   // and cache mesh information for reuse
00360   template <class FT, class M, class C, class PT>
00361   static
00362   void scatter(const FT& pdata, Field<FT,2U,M,C>& f,
00363                const Vektor<PT,2U>& ppos, const M& mesh,
00364                NDIndex<2U>& ngp, Vektor<PT,2U>& dpos) {
00365     CenteringTag<C> ctag;
00366     Vektor<PT,2U> gpos, delta;
00367     // find nearest grid point for particle position, store in NDIndex obj
00368     ngp = FindNGP(mesh, ppos, ctag);
00369     // get position of ngp
00370     FindPos(gpos, mesh, ngp, ctag);
00371     // get distance from ppos to gpos
00372     dpos = ppos - gpos;
00373     // get mesh spacings
00374     FindDelta(delta, mesh, ngp, ctag);
00375     // normalize dpos by mesh spacing
00376     dpos /= delta;
00377     // Try to find ngp in local fields and get iterator
00378     CompressedBrickIterator<FT,2U> fiter = getFieldIter(f,ngp);
00379     // accumulate into local elements
00380     *fiter += pdata;
00381     fiter.offset( 1,0) += 0.5 * dpos(0) * pdata;
00382     fiter.offset(-1,0) -= 0.5 * dpos(0) * pdata;
00383     fiter.offset(0, 1) += 0.5 * dpos(1) * pdata;
00384     fiter.offset(0,-1) -= 0.5 * dpos(1) * pdata;
00385     return;
00386   }
00387 
00388   // scatter particle data into Field using cached mesh information
00389   template <class FT, class M, class C, class PT>
00390   static
00391   void scatter(const FT& pdata, Field<FT,2U,M,C>& f,
00392                const NDIndex<2U>& ngp, const Vektor<PT,2U>& dpos) {
00393     // Try to find ngp in local fields and get iterator
00394     CompressedBrickIterator<FT,2U> fiter = getFieldIter(f,ngp);
00395     // accumulate into local elements
00396     *fiter += pdata;
00397     fiter.offset( 1,0) += 0.5 * dpos(0) * pdata;
00398     fiter.offset(-1,0) -= 0.5 * dpos(0) * pdata;
00399     fiter.offset(0, 1) += 0.5 * dpos(1) * pdata;
00400     fiter.offset(0,-1) -= 0.5 * dpos(1) * pdata;
00401     return;
00402   }
00403 
00404   // gather particle data from Field using particle position and mesh
00405   template <class FT, class M, class C, class PT>
00406   static
00407   void gather(FT& pdata, const Field<FT,2U,M,C>& f,
00408               const Vektor<PT,2U>& ppos, const M& mesh) {
00409     CenteringTag<C> ctag;
00410     Vektor<PT,2U> gpos, dpos, delta;
00411     // find nearest grid point for particle position, store in NDIndex obj
00412     NDIndex<2U> ngp = FindNGP(mesh, ppos, ctag);
00413     // get position of ngp
00414     FindPos(gpos, mesh, ngp, ctag);
00415     // get distance from ppos to gpos
00416     dpos = ppos - gpos;
00417     // get mesh spacings
00418     FindDelta(delta, mesh, ngp, ctag);
00419     // normalize dpos by mesh spacing
00420     dpos /= delta;
00421     // Try to find ngp in local fields and get iterator
00422     CompressedBrickIterator<FT,2U> fiter = getFieldIter(f,ngp);
00423     // accumulate into particle attrib
00424     pdata = (*fiter) +
00425             0.5 * dpos(0) * (fiter.offset(1,0) - fiter.offset(-1,0)) +
00426             0.5 * dpos(1) * (fiter.offset(0,1) - fiter.offset(0,-1));
00427     return;
00428   }
00429 
00430   // gather particle data from Field using particle position and mesh
00431   // and cache mesh information for reuse
00432   template <class FT, class M, class C, class PT>
00433   static
00434   void gather(FT& pdata, const Field<FT,2U,M,C>& f,
00435               const Vektor<PT,2U>& ppos, const M& mesh,
00436               NDIndex<2U>& ngp, Vektor<PT,2U>& dpos) {
00437     CenteringTag<C> ctag;
00438     Vektor<PT,2U> gpos, delta;
00439     // find nearest grid point for particle position, store in NDIndex obj
00440     ngp = FindNGP(mesh, ppos, ctag);
00441     // get position of ngp
00442     FindPos(gpos, mesh, ngp, ctag);
00443     // get distance from ppos to gpos
00444     dpos = ppos - gpos;
00445     // get mesh spacings
00446     FindDelta(delta, mesh, ngp, ctag);
00447     // normalize dpos by mesh spacing
00448     dpos /= delta;
00449     // Try to find ngp in local fields and get iterator
00450     CompressedBrickIterator<FT,2U> fiter = getFieldIter(f,ngp);
00451     // accumulate into particle attrib
00452     pdata = (*fiter) +
00453             0.5 * dpos(0) * (fiter.offset(1,0) - fiter.offset(-1,0)) +
00454             0.5 * dpos(1) * (fiter.offset(0,1) - fiter.offset(0,-1));
00455     return;
00456   }
00457 
00458   // gather particle data from Field using cached mesh information
00459   template <class FT, class M, class C, class PT>
00460   static
00461   void gather(FT& pdata, const Field<FT,2U,M,C>& f,
00462               const NDIndex<2U>& ngp, const Vektor<PT,2U>& dpos) {
00463     // Try to find ngp in local fields and get iterator
00464     CompressedBrickIterator<FT,2U> fiter = getFieldIter(f,ngp);
00465     // accumulate into particle attrib
00466     pdata = (*fiter) +
00467             0.5 * dpos(0) * (fiter.offset(1,0) - fiter.offset(-1,0)) +
00468             0.5 * dpos(1) * (fiter.offset(0,1) - fiter.offset(0,-1));
00469     return;
00470   }
00471 
00472 };
00473 
00474 
00475 template <>
00476 class IntSUDSImpl<3U> : public Interpolator {
00477 
00478 public:
00479   // constructor/destructor
00480   IntSUDSImpl() {}
00481   ~IntSUDSImpl() {}
00482 
00483   // gather/scatter functions
00484 
00485   // scatter particle data into Field using particle position and mesh
00486   template <class FT, class M, class C, class PT>
00487   static
00488   void scatter(const FT& pdata, Field<FT,3U,M,C>& f,
00489                const Vektor<PT,3U>& ppos, const M& mesh) {
00490     CenteringTag<C> ctag;
00491     Vektor<PT,3U> gpos, dpos, delta;
00492     // find nearest grid point for particle position, store in NDIndex obj
00493     NDIndex<3U> ngp = FindNGP(mesh, ppos, ctag);
00494     // get position of ngp
00495     FindPos(gpos, mesh, ngp, ctag);
00496     // get distance from ppos to gpos
00497     dpos = ppos - gpos;
00498     // get mesh spacings
00499     FindDelta(delta, mesh, ngp, ctag);
00500     // normalize dpos by mesh spacing
00501     dpos /= delta;
00502     // Try to find ngp in local fields and get iterator
00503     CompressedBrickIterator<FT,3U> fiter = getFieldIter(f,ngp);
00504     // accumulate into local elements
00505     *fiter += pdata;
00506     fiter.offset( 1,0,0) += 0.5 * dpos(0) * pdata;
00507     fiter.offset(-1,0,0) -= 0.5 * dpos(0) * pdata;
00508     fiter.offset(0, 1,0) += 0.5 * dpos(1) * pdata;
00509     fiter.offset(0,-1,0) -= 0.5 * dpos(1) * pdata;
00510     fiter.offset(0,0, 1) += 0.5 * dpos(2) * pdata;
00511     fiter.offset(0,0,-1) -= 0.5 * dpos(2) * pdata;
00512     return;
00513   }
00514 
00515   // scatter particle data into Field using particle position and mesh
00516   // and cache mesh information for reuse
00517   template <class FT, class M, class C, class PT>
00518   static
00519   void scatter(const FT& pdata, Field<FT,3U,M,C>& f,
00520                const Vektor<PT,3U>& ppos, const M& mesh,
00521                NDIndex<3U>& ngp, Vektor<PT,3U>& dpos) {
00522     CenteringTag<C> ctag;
00523     Vektor<PT,3U> gpos, delta;
00524     // find nearest grid point for particle position, store in NDIndex obj
00525     ngp = FindNGP(mesh, ppos, ctag);
00526     // get position of ngp
00527     FindPos(gpos, mesh, ngp, ctag);
00528     // get distance from ppos to gpos
00529     dpos = ppos - gpos;
00530     // get mesh spacings
00531     FindDelta(delta, mesh, ngp, ctag);
00532     // normalize dpos by mesh spacing
00533     dpos /= delta;
00534     // Try to find ngp in local fields and get iterator
00535     CompressedBrickIterator<FT,3U> fiter = getFieldIter(f,ngp);
00536     // accumulate into local elements
00537     *fiter += pdata;
00538     fiter.offset( 1,0,0) += 0.5 * dpos(0) * pdata;
00539     fiter.offset(-1,0,0) -= 0.5 * dpos(0) * pdata;
00540     fiter.offset(0, 1,0) += 0.5 * dpos(1) * pdata;
00541     fiter.offset(0,-1,0) -= 0.5 * dpos(1) * pdata;
00542     fiter.offset(0,0, 1) += 0.5 * dpos(2) * pdata;
00543     fiter.offset(0,0,-1) -= 0.5 * dpos(2) * pdata;
00544     return;
00545   }
00546 
00547   // scatter particle data into Field using cached mesh information
00548   template <class FT, class M, class C, class PT>
00549   static
00550   void scatter(const FT& pdata, Field<FT,3U,M,C>& f,
00551                const NDIndex<3U>& ngp, const Vektor<PT,3U>& dpos) {
00552     // Try to find ngp in local fields and get iterator
00553     CompressedBrickIterator<FT,3U> fiter = getFieldIter(f,ngp);
00554     // accumulate into local elements
00555     *fiter += pdata;
00556     fiter.offset( 1,0,0) += 0.5 * dpos(0) * pdata;
00557     fiter.offset(-1,0,0) -= 0.5 * dpos(0) * pdata;
00558     fiter.offset(0, 1,0) += 0.5 * dpos(1) * pdata;
00559     fiter.offset(0,-1,0) -= 0.5 * dpos(1) * pdata;
00560     fiter.offset(0,0, 1) += 0.5 * dpos(2) * pdata;
00561     fiter.offset(0,0,-1) -= 0.5 * dpos(2) * pdata;
00562     return;
00563   }
00564 
00565   // gather particle data from Field using particle position and mesh
00566   template <class FT, class M, class C, class PT>
00567   static
00568   void gather(FT& pdata, const Field<FT,3U,M,C>& f,
00569               const Vektor<PT,3U>& ppos, const M& mesh) {
00570     CenteringTag<C> ctag;
00571     Vektor<PT,3U> gpos, dpos, delta;
00572     // find nearest grid point for particle position, store in NDIndex obj
00573     NDIndex<3U> ngp = FindNGP(mesh, ppos, ctag);
00574     // get position of ngp
00575     FindPos(gpos, mesh, ngp, ctag);
00576     // get distance from ppos to gpos
00577     dpos = ppos - gpos;
00578     // get mesh spacings
00579     FindDelta(delta, mesh, ngp, ctag);
00580     // normalize dpos by mesh spacing
00581     dpos /= delta;
00582     // Try to find ngp in local fields and get iterator
00583     CompressedBrickIterator<FT,3U> fiter = getFieldIter(f,ngp);
00584     // accumulate into particle attrib
00585     pdata = (*fiter) +
00586             0.5 * dpos(0) * (fiter.offset(1,0,0) - fiter.offset(-1,0,0)) +
00587             0.5 * dpos(1) * (fiter.offset(0,1,0) - fiter.offset(0,-1,0)) +
00588             0.5 * dpos(2) * (fiter.offset(0,0,1) - fiter.offset(0,0,-1));
00589     return;
00590   }
00591 
00592   // gather particle data from Field using particle position and mesh
00593   // and cache mesh information for reuse
00594   template <class FT, class M, class C, class PT>
00595   static
00596   void gather(FT& pdata, const Field<FT,3U,M,C>& f,
00597               const Vektor<PT,3U>& ppos, const M& mesh,
00598               NDIndex<3U>& ngp, Vektor<PT,3U>& dpos) {
00599     CenteringTag<C> ctag;
00600     Vektor<PT,3U> gpos, delta;
00601     // find nearest grid point for particle position, store in NDIndex obj
00602     ngp = FindNGP(mesh, ppos, ctag);
00603     // get position of ngp
00604     FindPos(gpos, mesh, ngp, ctag);
00605     // get distance from ppos to gpos
00606     dpos = ppos - gpos;
00607     // get mesh spacings
00608     FindDelta(delta, mesh, ngp, ctag);
00609     // normalize dpos by mesh spacing
00610     dpos /= delta;
00611     // Try to find ngp in local fields and get iterator
00612     CompressedBrickIterator<FT,3U> fiter = getFieldIter(f,ngp);
00613     // accumulate into particle attrib
00614     pdata = (*fiter) +
00615             0.5 * dpos(0) * (fiter.offset(1,0,0) - fiter.offset(-1,0,0)) +
00616             0.5 * dpos(1) * (fiter.offset(0,1,0) - fiter.offset(0,-1,0)) +
00617             0.5 * dpos(2) * (fiter.offset(0,0,1) - fiter.offset(0,0,-1));
00618     return;
00619   }
00620 
00621   // gather particle data from Field using cached mesh information
00622   template <class FT, class M, class C, class PT>
00623   static
00624   void gather(FT& pdata, const Field<FT,3U,M,C>& f,
00625               const NDIndex<3U>& ngp, const Vektor<PT,3U>& dpos) {
00626     // Try to find ngp in local fields and get iterator
00627     CompressedBrickIterator<FT,3U> fiter = getFieldIter(f,ngp);
00628     // accumulate into particle attrib
00629     pdata = (*fiter) +
00630             0.5 * dpos(0) * (fiter.offset(1,0,0) - fiter.offset(-1,0,0)) +
00631             0.5 * dpos(1) * (fiter.offset(0,1,0) - fiter.offset(0,-1,0)) +
00632             0.5 * dpos(2) * (fiter.offset(0,0,1) - fiter.offset(0,0,-1));
00633     return;
00634   }
00635 
00636 };
00637 
00638 
00639 // IntSUDS class -- what the user sees
00640 class IntSUDS {
00641 
00642 public:
00643   // constructor/destructor
00644   IntSUDS() {}
00645   ~IntSUDS() {}
00646 
00647   // gather/scatter functions
00648 
00649   // scatter particle data into Field using particle position and mesh
00650   template <class FT, unsigned Dim, class M, class C, class PT>
00651   static
00652   void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
00653                const Vektor<PT,Dim>& ppos, const M& mesh) {
00654     IntSUDSImpl<Dim>::scatter(pdata,f,ppos,mesh);
00655   }
00656 
00657   // scatter particle data into Field using particle position and mesh
00658   // and cache mesh information for reuse
00659   template <class FT, unsigned Dim, class M, class C, class PT>
00660   static
00661   void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
00662                const Vektor<PT,Dim>& ppos, const M& mesh,
00663                CacheData1<PT,Dim>& cache) {
00664     IntSUDSImpl<Dim>::scatter(pdata,f,ppos,mesh,cache.Index_m,cache.Delta_m);
00665   }
00666 
00667   // scatter particle data into Field using cached mesh information
00668   template <class FT, unsigned Dim, class M, class C, class PT>
00669   static
00670   void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
00671                const CacheData1<PT,Dim>& cache) {
00672     IntSUDSImpl<Dim>::scatter(pdata,f,cache.Index_m,cache.Delta_m);
00673   }
00674 
00675   // gather particle data from Field using particle position and mesh
00676   template <class FT, unsigned Dim, class M, class C, class PT>
00677   static
00678   void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
00679               const Vektor<PT,Dim>& ppos, const M& mesh) {
00680     IntSUDSImpl<Dim>::gather(pdata,f,ppos,mesh);
00681   }
00682 
00683   // gather particle data from Field using particle position and mesh
00684   // and cache mesh information for reuse
00685   template <class FT, unsigned Dim, class M, class C, class PT>
00686   static
00687   void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
00688               const Vektor<PT,Dim>& ppos, const M& mesh,
00689               CacheData1<PT,Dim>& cache) {
00690     IntSUDSImpl<Dim>::gather(pdata,f,ppos,mesh,cache.Index_m,cache.Delta_m);
00691   }
00692 
00693   // gather particle data from Field using cached mesh information
00694   template <class FT, unsigned Dim, class M, class C, class PT>
00695   static
00696   void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
00697               const CacheData1<PT,Dim>& cache) {
00698     IntSUDSImpl<Dim>::gather(pdata,f,cache.Index_m,cache.Delta_m);
00699   }
00700 
00701 };
00702 
00703 #endif // INT_SUDS_H
00704 
00705 /***************************************************************************
00706  * $RCSfile: IntSUDS.h,v $   $Author: adelmann $
00707  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:28 $
00708  * IPPL_VERSION_ID: $Id: IntSUDS.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $ 
00709  ***************************************************************************/
00710 

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