src/Field/AssignDefs.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 ASSIGN_DEFS_H
00012 #define ASSIGN_DEFS_H
00013 
00014 // include files
00015 #include "Field/AssignTags.h"
00016 
00017 // forward declarations
00018 template<class T, unsigned int D> class BareField;
00019 template<class T, unsigned int D> class BareFieldIterator;
00020 template<class T, unsigned int D> class IndexedBareFieldIterator;
00021 
00023 //
00024 // Do any of the terms in an expression have an ID equal to a given one?
00025 //
00027 
00028 template<class T, class C, unsigned int D>
00029 inline bool
00030 for_each(const BareFieldIterator<T,D>& p, SameFieldID s, C)
00031 {
00032   return p.GetBareField().get_Id() == s.ID;
00033 }
00034 
00035 template<class T, class C, unsigned int D>
00036 inline bool
00037 for_each(const IndexedBareFieldIterator<T,D>& p, SameFieldID s, C)
00038 {
00039   return p.GetBareField().get_Id() == s.ID;
00040 }
00041 
00042 //
00043 // If there is an index in the expr, it can't have the same ID.
00044 //
00045 template<class C>
00046 inline bool
00047 for_each(const Index::cursor&, SameFieldID, C)
00048 {
00049   return false;
00050 }
00051 
00052 //
00053 // If there is a scalar in the expr, it can't have the same ID.
00054 //
00055 template<class T, class C>
00056 inline bool
00057 for_each(const PETE_Scalar<T>&, SameFieldID, C)
00058 {
00059   return false;
00060 }
00061 
00063 //
00064 // Plugbase.
00065 //
00067 
00068 template<unsigned D>
00069 struct PlugBase
00070 {
00071   NDIndex<D> Domain;
00072   PlugBase( const NDIndex<D>& domain ) : Domain(domain) {}
00073   typedef bool PETE_Return_t;
00074 };
00075 
00076 //
00077 // Plug into an IndexedBareField.
00078 //
00079 template<class T, unsigned int D1, unsigned D2, class C>
00080 inline bool
00081 for_each(IndexedBareFieldIterator<T,D1>& p, const PlugBase<D2>& f, C)
00082 {
00083   return p.plugBase(f.Domain);
00084 }
00085 
00086 //
00087 // plugbase
00088 //
00089 template<class C, unsigned D>
00090 inline bool
00091 for_each(Index::cursor& p, const PlugBase<D>& f, C)
00092 {
00093   //cout << "Plugging " << f.Domain << endl;
00094   //cout << "  p.id() = " << p.id() << endl;
00095   for (unsigned d=0; d<D; ++d) 
00096     {
00097       //cout << "  d=" << d << ", id=" << f.Domain[d].id() << endl;
00098       if ( p.id() == f.Domain[d].id() )
00099         {
00100           //cout << "  matched." << endl;
00101           return p.plugBase( f.Domain[d], d );
00102         }
00103     }
00104   return false;
00105 }
00106 
00107 //
00108 // just return true for scalar
00109 //
00110 template<class T, class C, unsigned D>
00111 inline bool
00112 for_each(const PETE_Scalar<T>&, const PlugBase<D>&, C)
00113 {
00114   return true;
00115 }
00116 
00118 //
00119 // Ask each term if it is compressed.
00120 //
00122 
00123 template<class T, class C, unsigned int D>
00124 inline bool
00125 for_each(const IndexedBareFieldIterator<T,D>& p, IsCompressed, C)
00126 {
00127   return p.IsCompressed();
00128 }
00129 
00130 template<class T, class C, unsigned int D>
00131 inline bool
00132 for_each(const BareFieldIterator<T,D>& p, IsCompressed, C)
00133 {
00134   return p.IsCompressed();
00135 }
00136 
00137 //
00138 // Indexes are never compressed.
00139 //
00140 template<class C>
00141 inline bool
00142 for_each(const Index::cursor&, IsCompressed, C)
00143 {
00144   return false;
00145 }
00146 
00147 //
00148 // Scalars are always compressed.
00149 //
00150 template<class T, class C>
00151 inline bool
00152 for_each(const PETE_Scalar<T>&, IsCompressed, C)
00153 {
00154   return true;
00155 }
00156 
00158 //
00159 // Evaluation functors.
00160 // First, no arguments.
00161 //
00163 
00164 template<class T, unsigned int D>
00165 inline T&
00166 for_each(const BrickIterator<T,D>& p, EvalFunctor_0)
00167 {
00168   return *p;
00169 }
00170 
00171 //
00172 // Evaluate an Index.
00173 //
00174 inline int
00175 for_each(const Index::cursor& p, EvalFunctor_0)
00176 {
00177   return *p;
00178 }
00179 
00181 //
00182 // Evaluation functors.
00183 // One argument.
00184 //
00186 
00187 template<class T, unsigned int D>
00188 inline T&
00189 for_each(const BrickIterator<T,D>& p, const EvalFunctor_1& e)
00190 {
00191   return p.offset(e.I);
00192 }
00193 
00194 template<class T, unsigned int D>
00195 inline T&
00196 for_each(const BrickIterator<T,D>& p, const UnitEvalFunctor_1& e)
00197 {
00198   return p.unit_offset(e.I);
00199 }
00200 
00201 //
00202 // Evaluate an Index.
00203 //
00204 inline int
00205 for_each(const Index::cursor& p, const EvalFunctor_1& e)
00206 {
00207   return p.offset(e.I);
00208 }
00209 
00210 //
00211 // Evaluate a scalar.
00212 //
00213 template<class T>
00214 inline T
00215 for_each(const PETE_Scalar<T>& p, const EvalFunctor_1&)
00216 {
00217   return T(p);
00218 }
00219 
00221 //
00222 // Evaluation functors.
00223 // Two arguments.
00224 //
00226 
00227 template<class T, unsigned int D>
00228 inline T&
00229 for_each(const BrickIterator<T,D>& p, const EvalFunctor_2& e)
00230 {
00231   return p.offset(e.I, e.J);
00232 }
00233 
00234 template<class T, unsigned int D>
00235 inline T&
00236 for_each(const BrickIterator<T,D>& p, const UnitEvalFunctor_2& e)
00237 {
00238   return p.unit_offset(e.I, e.J);
00239 }
00240 
00241 //
00242 // Evaluate an Index.
00243 //
00244 inline int
00245 for_each(const Index::cursor& p, const EvalFunctor_2& e)
00246 {
00247   return p.offset(e.I, e.J);
00248 }
00249 
00250 //
00251 // Evaluate a scalar.
00252 //
00253 template<class T>
00254 inline T
00255 for_each(const PETE_Scalar<T>& p, const EvalFunctor_2&)
00256 {
00257   return T(p);
00258 }
00259 
00261 //
00262 // Evaluation functors.
00263 // Three arguments.
00264 //
00266 
00267 template<class T, unsigned int D>
00268 inline T&
00269 for_each(const BrickIterator<T,D>& p, const EvalFunctor_3& e)
00270 {
00271   return p.offset(e.I, e.J, e.K);
00272 }
00273 
00274 template<class T, unsigned int D>
00275 inline T&
00276 for_each(const BrickIterator<T,D>& p, const UnitEvalFunctor_3& e)
00277 {
00278   return p.offset(e.I, e.J, e.K);
00279 }
00280 
00281 //
00282 // Evaluate an Index.
00283 //
00284 inline int
00285 for_each(const Index::cursor& p, const EvalFunctor_3& e)
00286 {
00287   return p.offset(e.I, e.J, e.K);
00288 }
00289 
00290 //
00291 // Evaluate a scalar.
00292 //
00293 template<class T>
00294 inline T
00295 for_each(const PETE_Scalar<T>& p, const EvalFunctor_3&)
00296 {
00297   return T(p);
00298 }
00299 
00301 //
00302 // Get started in a given LField 
00303 //
00305 
00306 template<class T, class C, unsigned int D>
00307 inline int
00308 for_each(BareFieldIterator<T,D>& p, BeginLField, C)
00309 {
00310   p.beginLField();
00311   return 0;
00312 }
00313 
00314 //
00315 // ignore this signal
00316 //
00317 template<class T, class C>
00318 inline int
00319 for_each(PETE_Scalar<T>&, BeginLField, C)
00320 {
00321   return 0;
00322 }
00323 
00325 //
00326 // Go on to the next LField.
00327 //
00329 
00330 template<class T, class C, unsigned int D>
00331 inline int
00332 for_each(BareFieldIterator<T,D>& p, NextLField, C)
00333 {
00334   p.nextLField();
00335   return 0;
00336 }
00337 
00338 //
00339 // If there is a scalar in the expr, it ignores this signal.
00340 //
00341 template<class T, class C>
00342 inline int
00343 for_each(PETE_Scalar<T>&, NextLField, C)
00344 {
00345   return 0;
00346 }
00347 
00349 //
00350 // Step in some dimension.
00351 //
00353 
00354 template<class T,  class C, unsigned int D>
00355 inline int
00356 for_each(IndexedBareFieldIterator<T,D>& p, StepFunctor s, C)
00357 {
00358   p.step(s.D);
00359   return 0;
00360 }
00361 
00362 template<class T,  class C, unsigned int D>
00363 inline int
00364 for_each(BareFieldIterator<T,D>& p, StepFunctor s, C)
00365 {
00366   p.step(s.D);
00367   return 0;
00368 }
00369 
00370 template<class T,  class C, unsigned int D>
00371 inline int
00372 for_each(BrickIterator<T,D>& p, StepFunctor s, C)
00373 {
00374   p.step(s.D);
00375   return 0;
00376 }
00377 
00378 //
00379 // Step along an Index.
00380 //
00381 template<class C>
00382 inline int
00383 for_each(Index::cursor& p, StepFunctor s, C)
00384 {
00385   p.step(s.D);
00386   return 0;
00387 }
00388 
00389 //
00390 // scalar ignores step functor
00391 //
00392 template<class T, class C>
00393 inline int
00394 for_each(PETE_Scalar<T>&, StepFunctor, C)
00395 {
00396   return 0;
00397 }
00398 
00400 //
00401 // Rewind in some dimension.
00402 //
00404 
00405 template<class T, class C, unsigned int D>
00406 inline int
00407 for_each(IndexedBareFieldIterator<T,D>& p, RewindFunctor s, C)
00408 {
00409   p.rewind(s.D);
00410   return 0;
00411 }
00412 
00413 
00414 template<class T, class C, unsigned int D>
00415 inline int
00416 for_each(BareFieldIterator<T,D>& p, RewindFunctor s, C)
00417 {
00418   p.rewind(s.D);
00419   return 0;
00420 }
00421 
00422 
00423 template<class T, class C, unsigned int D>
00424 inline int
00425 for_each(BrickIterator<T,D>& p, RewindFunctor s, C)
00426 {
00427   p.rewind(s.D);
00428   return 0;
00429 }
00430 
00431 //
00432 // Rewind an Index.
00433 //
00434 template<class C>
00435 inline int
00436 for_each(Index::cursor& p, RewindFunctor s, C)
00437 {
00438   p.rewind(s.D);
00439   return 0;
00440 }
00441 
00442 //
00443 // scalar ignores rewind functor
00444 //
00445 template<class T, class C>
00446 inline int
00447 for_each(PETE_Scalar<T>&, RewindFunctor, C)
00448 {
00449   return 0;
00450 }
00451 
00453 //
00454 // Count the number of elements in an expression.
00455 //
00457 
00458 template<class T, class C, unsigned int D>
00459 inline int
00460 for_each(BrickIterator<T,D>& p, PETE_CountElems, C)
00461 {
00462   int size = p.size(0);
00463   for (unsigned int i=1; i<D; ++i)
00464     size *= p.size(i);
00465   return size;
00466 }
00467 
00468 template<class T, class C, unsigned int D>
00469 inline int
00470 for_each(BareFieldIterator<T,D>& p, PETE_CountElems, C)
00471 {
00472   BareField<T,D>& f = p.GetBareField();
00473   int n = 0;
00474   for (typename BareField<T,D>::iterator_if lf=f.begin_if(); lf!=f.end_if(); ++lf)
00475     n += (*lf).second->getOwned().size();
00476   return n;
00477 }
00478 
00479 template<class T, class C, unsigned int D>
00480 inline int
00481 for_each(IndexedBareFieldIterator<T,D>& p, PETE_CountElems, C)
00482 {
00483   BareField<T,D>& f = p.GetBareField();
00484   int n = 0;
00485   for (typename BareField<T,D>::iterator_if lf=f.begin_if(); lf!=f.end_if(); ++lf) {
00486     const NDIndex<D>& domain = (*lf).second->getOwned();
00487     if ( p.getDomain().touches(domain) )
00488       n += p.getDomain().intersect(domain).size();
00489   }
00490   return n;
00491 }
00492 
00494 //
00495 // Increment the pointers in an expression.
00496 //
00498 
00499 template<class T, class C, unsigned int D>
00500 inline int
00501 for_each(IndexedBareFieldIterator<T,D>& p, PETE_Increment s, C)
00502 {
00503   ++p;
00504   return 0;
00505 }
00506 
00507 
00508 template<class T, class C, unsigned int D>
00509 inline int
00510 for_each(BareFieldIterator<T,D>& p, PETE_Increment s, C)
00511 {
00512   ++p;
00513   return 0;
00514 }
00515 
00516 
00517 template<class T, class C, unsigned int D>
00518 inline int
00519 for_each(BrickIterator<T,D>& p, PETE_Increment s, C)
00520 {
00521   ++p;
00522   return 0;
00523 }
00524 
00526 //
00527 // Find out if all the BrickIterators in an expression 
00528 // have unit stride in the first dimension.
00529 //
00531 
00532 template<class T, class C, unsigned int D>
00533 inline bool
00534 for_each(const IndexedBareFieldIterator<T,D>& iter, HasUnitStride, C)
00535 {
00536   return iter.Stride(0) == 1;
00537 }
00538 
00539 template<class T, class C, unsigned int D>
00540 inline bool
00541 for_each(const BareFieldIterator<T,D>& iter, HasUnitStride, C)
00542 {
00543   return iter.Stride(0) == 1;
00544 }
00545 
00546 template<class T, class C, unsigned int D>
00547 inline bool
00548 for_each(const BrickIterator<T,D>& iter, HasUnitStride, C)
00549 {
00550   return iter.Stride(0) == 1;
00551 }
00552 
00553 template<class C>
00554 inline bool
00555 for_each(const Index::cursor&, HasUnitStride, C)
00556 {
00557   return true;
00558 }
00559 
00560 template<class T, class C>
00561 inline bool
00562 for_each(const PETE_Scalar<T>&, HasUnitStride, C)
00563 {
00564   return true;
00565 }
00566 
00568 //
00569 // Ask each term to fill guard cells and compress itself
00570 //
00572 
00573 template<class T, class C, unsigned int D, unsigned int D1, class T1>
00574 inline int
00575 for_each(const IndexedBareFieldIterator<T,D>& p, 
00576   const FillGCIfNecessaryTag<D1,T1> &f, C)
00577 {
00578   p.FillGCIfNecessary(*(f.bf_m));
00579   return 0;
00580 }
00581 
00582 template<class T, class C, unsigned int D, unsigned int D1, class T1>
00583 inline int
00584 for_each(const BareFieldIterator<T,D>& p, 
00585   const FillGCIfNecessaryTag<D1,T1> &, C)
00586 {
00587   return 0;
00588 }
00589 
00590 template<class T, class C, unsigned int D, class T1>
00591 inline int
00592 for_each(const PETE_Scalar<T>&, const FillGCIfNecessaryTag<D,T1> &, C)
00593 {
00594   return 0;
00595 }
00596 
00597 template<class C, unsigned int D, class T1>
00598 inline int
00599 for_each(const Index::cursor&, const FillGCIfNecessaryTag<D,T1> &, C)
00600 {
00601   return 0;
00602 }
00603 
00604 #endif // ASSIGN_DEFS_H
00605 
00606 /***************************************************************************
00607  * $RCSfile: AssignDefs.h,v $   $Author: adelmann $
00608  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
00609  * IPPL_VERSION_ID: $Id: AssignDefs.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
00610  ***************************************************************************/

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