- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_GLOBALAGGREGATES_HH 00002 #define DUNE_GLOBALAGGREGATES_HH 00003 00004 #include "aggregates.hh" 00005 #include "pinfo.hh" 00006 #include <dune/common/parallel/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 = 00096 std::numeric_limits<typename TI::GlobalIndex>::max(); 00097 00098 template<typename T, typename TI> 00099 struct AggregatesGatherScatter 00100 { 00101 typedef TI ParallelIndexSet; 00102 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex; 00103 00104 static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i) 00105 { 00106 return ga[i]; 00107 } 00108 00109 static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i) 00110 { 00111 ga[i]=global; 00112 } 00113 }; 00114 00115 template<typename T, typename O, typename I> 00116 struct AggregatesPublisher 00117 { 00118 }; 00119 00120 #if HAVE_MPI 00121 00122 #endif 00123 00124 } // namespace Amg 00125 00126 #if HAVE_MPI 00127 // forward declaration 00128 template<class T1, class T2> 00129 class OwnerOverlapCopyCommunication; 00130 #endif 00131 00132 namespace Amg 00133 { 00134 00135 #if HAVE_MPI 00136 00145 template<typename T, typename O, typename T1, typename T2> 00146 struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> > 00147 { 00148 typedef T Vertex; 00149 typedef O OverlapFlags; 00150 typedef OwnerOverlapCopyCommunication<T1,T2> ParallelInformation; 00151 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet; 00152 typedef typename ParallelInformation::ParallelIndexSet IndexSet; 00153 00154 static void publish(AggregatesMap<Vertex>& aggregates, 00155 ParallelInformation& pinfo, 00156 const GlobalLookupIndexSet& globalLookup) 00157 { 00158 typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap; 00159 GlobalMap gmap(aggregates, globalLookup); 00160 pinfo.copyOwnerToAll(gmap,gmap); 00161 00162 typedef typename ParallelInformation::RemoteIndices::const_iterator Lists; 00163 Lists lists = pinfo.remoteIndices().find(pinfo.communicator().rank()); 00164 if(lists!=pinfo.remoteIndices().end()){ 00165 00166 // For periodic boundary conditions we must renumber 00167 // the aggregates of vertices in the overlap whose owners are 00168 // on the same process 00169 Vertex maxAggregate =0; 00170 typedef typename AggregatesMap<Vertex>::const_iterator Iter; 00171 for(Iter i=aggregates.begin(), end=aggregates.end(); i!=end; ++i) 00172 maxAggregate = std::max(maxAggregate, *i); 00173 00174 // Compute new mapping of aggregates in the overlap that we also own 00175 std::map<Vertex,Vertex> newMapping; 00176 00177 // insert all elements into map 00178 typedef typename ParallelInformation::RemoteIndices::RemoteIndexList 00179 ::const_iterator RIter; 00180 for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end(); 00181 ri!=rend; ++ri) 00182 if(O::contains(ri->localIndexPair().local().attribute())) 00183 newMapping.insert(std::make_pair(aggregates[ri->localIndexPair().local()], 00184 maxAggregate)); 00185 // renumber 00186 typedef typename std::map<Vertex,Vertex>::iterator MIter; 00187 for(MIter mi=newMapping.begin(), mend=newMapping.end(); 00188 mi != mend; ++mi) 00189 mi->second=++maxAggregate; 00190 00191 00192 for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end(); 00193 ri!=rend; ++ri) 00194 if(O::contains(ri->localIndexPair().local().attribute())) 00195 aggregates[ri->localIndexPair().local()] = 00196 newMapping[aggregates[ri->localIndexPair().local()]]; 00197 } 00198 } 00199 }; 00200 #endif 00201 00202 template<typename T, typename O> 00203 struct AggregatesPublisher<T,O,SequentialInformation> 00204 { 00205 typedef T Vertex; 00206 typedef SequentialInformation ParallelInformation; 00207 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet; 00208 00209 static void publish(AggregatesMap<Vertex>& aggregates, 00210 ParallelInformation& pinfo, 00211 const GlobalLookupIndexSet& globalLookup) 00212 {} 00213 }; 00214 00215 } // end Amg namespace 00216 00217 00218 #if HAVE_MPI 00219 template<typename T, typename TI> 00220 struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> > 00221 { 00222 typedef Amg::AggregatesMap<T> Type; 00223 typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType; 00224 typedef SizeOne IndexedTypeFlag; 00225 static int getSize(const Type&, int) 00226 { 00227 return 1; 00228 } 00229 }; 00230 #endif 00231 00232 } // end Dune namespace 00233 00234 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].