globalaggregates.hh

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     template<typename T, typename O, typename T1>
00121     struct AggregatesPublisher<T,O,ParallelInformation<T1> >
00122     {
00123       typedef T Vertex;
00124       typedef O OverlapFlags;
00125       typedef Dune::Amg::ParallelInformation<T1> ParallelInformation;
00126       typedef typename ParallelInformation::ParallelIndexSet IndexSet;
00127       
00128       static void publish(AggregatesMap<Vertex>& aggregates, 
00129                           ParallelInformation& pinfo,
00130                           const GlobalLookupIndexSet<IndexSet>& globalLookup)
00131       {
00132         typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
00133         GlobalMap gmap(aggregates, globalLookup);
00134         pinfo.template buildInterface<OverlapFlags>();
00135         pinfo.template buildCommunicator<GlobalMap>(gmap, gmap);
00136         pinfo.template communicateForward<AggregatesGatherScatter<Vertex,IndexSet> >(gmap, gmap);
00137         pinfo.freeCommunicator();
00138       }
00139       
00140     };
00141     
00142 #endif
00143 
00144   } // namespace Amg
00145 
00146 #if HAVE_MPI  
00147     // forward declaration
00148     template<class T1, class T2>
00149     class OwnerOverlapCopyCommunication;
00150 #endif
00151 
00152   namespace Amg
00153   {
00154 
00155 #if HAVE_MPI    
00156     template<typename T, typename O, typename T1, typename T2>
00157     struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
00158     {
00159       typedef T Vertex;
00160       typedef O OverlapFlags;
00161       typedef OwnerOverlapCopyCommunication<T1,T2> ParallelInformation;
00162       typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
00163       typedef typename ParallelInformation::ParallelIndexSet IndexSet;
00164       
00165       static void publish(AggregatesMap<Vertex>& aggregates, 
00166                           ParallelInformation& pinfo,
00167                           const GlobalLookupIndexSet& globalLookup)
00168       {
00169         typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
00170         GlobalMap gmap(aggregates, globalLookup);
00171         pinfo.copyOwnerToAll(gmap,gmap);
00172       }
00173       
00174     };
00175 #endif
00176 
00177     template<typename T, typename O>
00178     struct AggregatesPublisher<T,O,SequentialInformation>
00179     {
00180       typedef T Vertex;
00181       typedef SequentialInformation ParallelInformation;
00182       typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
00183       
00184       static void publish(AggregatesMap<Vertex>& aggregates, 
00185                           ParallelInformation& pinfo,
00186                           const GlobalLookupIndexSet& globalLookup)
00187       {} 
00188     };
00189     
00190   } // end Amg namespace
00191 
00192 
00193 #if HAVE_MPI 
00194   template<typename T, typename TI>
00195   struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
00196   {
00197     typedef Amg::AggregatesMap<T> Type;
00198     typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
00199     typedef SizeOne IndexedTypeFlag;
00200     static int getSize(const Type&, int)
00201     {
00202       return 1;
00203     }
00204   };
00205 #endif
00206 
00207 } // end Dune namespace
00208 
00209 #endif

Generated on Thu Apr 2 10:40:14 2009 for dune-istl by  doxygen 1.5.6