GridSelector.hpp

00001 #ifndef __FIBER_GRIDSELECTOR_HPP
00002 #define __FIBER_GRIDSELECTOR_HPP
00003 
00004 #include "BundleAPI.h"
00005 #include "Bundle.hpp"
00006 
00007 namespace Fiber
00008 {
00009 
00019 struct  BUNDLE_API GridSelector
00020 {
00021 public:
00027         BundlePtr               theSourceBundle;
00028 
00030         string                  theGridname; 
00031 
00033         const string&getGridname() const { return theGridname; }
00034 
00036         GridSelector();
00037 
00039         GridSelector(const string&gridname, const Fiber::BundlePtr&Source = Fiber::BundlePtr(NullPtr() ) )
00040         : theSourceBundle(Source)
00041         , theGridname(gridname)
00042         {}
00043 
00045         GridSelector(const Fiber::BundlePtr&Source, const string&gridname)
00046         : theSourceBundle(Source)
00047         , theGridname(gridname)
00048         {}
00049 
00051         ~GridSelector();
00052 
00054         friend bool operator==(const GridSelector&L, const GridSelector&R)
00055         {
00056                 return  L.theSourceBundle == R.theSourceBundle &&
00057                         L.theGridname == R.theGridname;
00058         } 
00059 
00061         friend bool operator!=(const GridSelector&L, const GridSelector&R)
00062         {
00063                 return  !(L==R);
00064         }
00065 
00067         const string&Gridname() const
00068         {
00069                 return theGridname;
00070         }
00071 
00073         const Fiber::BundlePtr&BundleSource() const
00074         {
00075                 return theSourceBundle;
00076         }
00077 
00079         const Fiber::BundlePtr&getBundle() const
00080         {
00081                 return theSourceBundle;
00082         }
00083 
00085         bool selectGrid(const string&name)
00086         {
00087                 theGridname = name;
00088                 return true;
00089 
00090                 /*
00091                 if (!theSpacetime)
00092                         return false;
00093 
00094                 theGridID = (*theSpacetime)[ name ];
00095                 return theGridID.valid();
00096                 */
00097         }
00098 
00104         Info<Grid> findMostRecentGrid(const Fiber::BundlePtr&theSpacetime, double time) const
00105         {
00106                 if (!theSpacetime)
00107                         return Info<Grid>();
00108 
00109                 return  theSpacetime->findMostRecentGrid(time, theGridname);
00110         } 
00111 
00115         Info<Grid>      findMostRecentGrid(double time, 
00116                                            const Fiber::BundlePtr&theSpacetime = Fiber::BundlePtr(NullPtr() ) ) const
00117         {
00118                 if (!theSpacetime)
00119                 {
00120                         if (!theSourceBundle)
00121                                 return Info<Grid>();
00122                         else
00123                                 return theSourceBundle->findMostRecentGrid(time, theGridname);
00124                 }
00125 
00126                 return  theSpacetime->findMostRecentGrid(time, theGridname);
00127         } 
00128 
00134         Info<Skeleton> getRefinementLevel(double time,
00135                                           int Level, int IndexDepth,
00136                                           const BundlePtr&SpaceTime = BundlePtr(NullPtr() ) );
00137 
00141         Info<Grid> findPrev(double time, const BundlePtr&theSpacetime = BundlePtr(NullPtr()) ) const
00142         {
00143                 if (!theSpacetime)
00144                 {
00145                         if (!theSourceBundle)
00146                                 return Info<Grid>();
00147                         else
00148                                 theSourceBundle->findPrev(time, theGridname);
00149                 }
00150 
00151                 return theSpacetime->findPrev(time, theGridname);
00152         } 
00153 
00157         Info<Grid> findNext(double time, const BundlePtr&theSpacetime = BundlePtr(NullPtr() ) ) const
00158         {
00159                 if (!theSpacetime)
00160                 {
00161                         if (!theSourceBundle)
00162                                 return Info<Grid>();
00163                         else
00164                                 theSourceBundle->findNext(time, theGridname);
00165                 }
00166 
00167                 return theSpacetime->findNext(time, theGridname);
00168         }
00169 
00170         Fiber::Grid&operator[](double time)
00171         {
00172                 return theSourceBundle[time][ Gridname() ];
00173         } 
00174 
00180         RefPtr<Fiber::Grid> operator()(double time, 
00181                                        const Fiber::BundlePtr&theSpacetime = Fiber::BundlePtr(NullPtr() )) const
00182         {
00183         Fiber::Bundle::GridInfo_t G = findMostRecentGrid(time, theSpacetime); 
00184                 return G.getGrid();
00185         } 
00186 
00187         RefPtr<Fiber::Grid> operator()(double time, const GridSelector&GS)
00188         {
00189         Fiber::Bundle::GridInfo_t G = findMostRecentGrid(time, GS.theSourceBundle); 
00190                 return G.getGrid();
00191         }
00192 };
00193 
00194 
00195 } /* namespace Fiber */ 
00196 
00197 #endif /* __FIBER_GRIDSELECTOR_HPP */
00198