globalaggregates.hh

Go to the documentation of this file.
00001 #ifndef GLOBALAGGREGATES_HH
00002 #define GLOBALAGGREGATES_HH
00003 
00004 #include "aggregates.hh"
00005 #include "pinfo.hh"
00006 #include <dune/istl/indexset.hh>
00007 
00008 namespace Dune
00009 {
00010   namespace Amg
00011   {
00012     
00013     template<typename T, typename TI>
00014     struct GlobalAggregatesMap
00015     {
00016     public:
00017       typedef TI ParallelIndexSet;
00018       
00019       typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
00020       
00021       typedef typename ParallelIndexSet::GlobalIndex IndexedType;
00022   
00023       typedef typename ParallelIndexSet::LocalIndex LocalIndex;
00024       
00025       typedef T Vertex;
00026       
00027       GlobalAggregatesMap(AggregatesMap<Vertex>& aggregates,
00028                           const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
00029         : aggregates_(aggregates), indexset_(indexset)
00030       {}
00031   
00032       inline const GlobalIndex& operator[](std::size_t index)const
00033       {
00034         const Vertex& aggregate = aggregates_[index];
00035         if(aggregate >= AggregatesMap<Vertex>::ISOLATED){
00036           assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
00037           return isolatedMarker;
00038         }else{
00039           const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
00040           assert(pair!=0);
00041           return pair->global();
00042         }
00043       }
00044   
00045       
00046       inline GlobalIndex& get(std::size_t index)
00047       {
00048         const Vertex& aggregate = aggregates_[index];
00049         assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
00050         const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
00051         assert(pair!=0);
00052         return const_cast<GlobalIndex&>(pair->global());
00053       }
00054 
00055       class Proxy
00056       {
00057       public:
00058         Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
00059           : indexset_(&indexset), aggregate_(&aggregate)
00060         {}
00061         
00062         Proxy& operator=(const GlobalIndex& global)
00063         {
00064           if(global==isolatedMarker)
00065             *aggregate_ = AggregatesMap<Vertex>::ISOLATED;
00066           else{
00067             //assert(global < AggregatesMap<Vertex>::ISOLATED);
00068             *aggregate_ = indexset_->operator[](global).local();
00069           }
00070           return *this;
00071         }
00072       private:
00073         const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
00074         Vertex* aggregate_;
00075       };
00076       
00077       inline Proxy operator[](std::size_t index)
00078       {
00079         return Proxy(indexset_, aggregates_[index]);
00080       }
00081 
00082       inline void put(const GlobalIndex& global, size_t i)
00083       {
00084         aggregates_[i]=indexset_[global].local();
00085     
00086       }
00087 
00088     private:
00089       AggregatesMap<Vertex>& aggregates_;
00090       const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
00091       static const GlobalIndex isolatedMarker;
00092     };
00093 
00094     template<typename T, typename TI>
00095     const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker = -1;
00096     
00097     template<typename T, typename TI>
00098     struct AggregatesGatherScatter
00099     {
00100       typedef TI ParallelIndexSet;
00101       typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
00102       
00103       static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
00104       {
00105         return ga[i];
00106       }
00107   
00108       static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
00109       {
00110         ga[i]=global;
00111       }
00112     };
00113 
00114     template<typename T, typename O, typename I>
00115     struct AggregatesPublisher
00116     {
00117     };
00118 
00119 #if HAVE_MPI    
00120     
00121 #endif
00122 
00123   } // namespace Amg
00124 
00125 #if HAVE_MPI  
00126     // forward declaration
00127     template<class T1, class T2>
00128     class OwnerOverlapCopyCommunication;
00129 #endif
00130 
00131   namespace Amg
00132   {
00133 
00134 #if HAVE_MPI    
00135     template<typename T, typename O, typename T1, typename T2>
00136     struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
00137     {
00138       typedef T Vertex;
00139       typedef O OverlapFlags;
00140       typedef OwnerOverlapCopyCommunication<T1,T2> ParallelInformation;
00141       typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
00142       typedef typename ParallelInformation::ParallelIndexSet IndexSet;
00143       
00144       static void publish(AggregatesMap<Vertex>& aggregates, 
00145                           ParallelInformation& pinfo,
00146                           const GlobalLookupIndexSet& globalLookup)
00147       {
00148         typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
00149         GlobalMap gmap(aggregates, globalLookup);
00150         pinfo.copyOwnerToAll(gmap,gmap);
00151       }
00152       
00153     };
00154 #endif
00155 
00156     template<typename T, typename O>
00157     struct AggregatesPublisher<T,O,SequentialInformation>
00158     {
00159       typedef T Vertex;
00160       typedef SequentialInformation ParallelInformation;
00161       typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
00162       
00163       static void publish(AggregatesMap<Vertex>& aggregates, 
00164                           ParallelInformation& pinfo,
00165                           const GlobalLookupIndexSet& globalLookup)
00166       {} 
00167     };
00168     
00169   } // end Amg namespace
00170 
00171 
00172 #if HAVE_MPI 
00173   template<typename T, typename TI>
00174   struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
00175   {
00176     typedef Amg::AggregatesMap<T> Type;
00177     typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
00178     typedef SizeOne IndexedTypeFlag;
00179     static int getSize(const Type&, int)
00180     {
00181       return 1;
00182     }
00183   };
00184 #endif
00185 
00186 } // end Dune namespace
00187 
00188 #endif
Generated on Sat Apr 24 11:13:45 2010 for dune-istl by  doxygen 1.6.3