1#ifndef MAP_XPETRA_DEF_hpp
2#define MAP_XPETRA_DEF_hpp
14template <
class LO,
class GO,
class NO>
15Map_Xpetra<LO,GO,NO>::Map_Xpetra():
21template <
class LO,
class GO,
class NO>
22Map_Xpetra<LO,GO,NO>::Map_Xpetra( XpetraMapConstPtrConst_Type& xpetraMapPtrIn ):
28template <
class LO,
class GO,
class NO>
29Map_Xpetra<LO,GO,NO>::Map_Xpetra(
const Map_Type& mapIn ):
32 map_ = Xpetra::MapFactory<LO,GO,NO>::Build( Xpetra::UseTpetra, mapIn.getGlobalNumElements(), mapIn.getNodeElementList(), mapIn.getIndexBase(), mapIn.getComm() );
35template <
class LO,
class GO,
class NO>
36Map_Xpetra<LO,GO,NO>::Map_Xpetra(
38 const Teuchos::ArrayView<const GO> &elementList,
40 const CommConstPtr_Type &comm):
43 map_ = Xpetra::MapFactory<LO,GO,NO>::Build( Xpetra::UseTpetra, numGlobalElements, elementList, indexBase, comm);
46template <
class LO,
class GO,
class NO>
47Map_Xpetra<LO,GO,NO>::Map_Xpetra(
51 const CommConstPtr_Type &comm):
54 map_ = Xpetra::MapFactory<LO,GO,NO>::Build( Xpetra::UseTpetra, numGlobalElements, numLocalElements, indexBase, comm);
57template <
class LO,
class GO,
class NO>
58Map_Xpetra<LO,GO,NO>::~Map_Xpetra(){
62template <
class LO,
class GO,
class NO>
63typename Map_Xpetra<LO,GO,NO>::MapPtr_Type Map_Xpetra<LO,GO,NO>::buildVecFieldMap(UN numDofs, std::string ordering)
const{
65 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
66 TEUCHOS_TEST_FOR_EXCEPTION(ordering.compare(
"NodeWise"), std::logic_error,
"Select a valid ordering: NodeWise");
67 Teuchos::ArrayView<const GO> elementList = map_->getLocalElementList();
68 Teuchos::Array<GO> elementListField( numDofs * elementList.size() );
69 for (UN i=0; i<elementList.size(); i++) {
70 for (UN dof=0; dof<numDofs; dof++)
71 elementListField[ numDofs * i + dof ] = numDofs * elementList[i] + dof;
73 typedef Teuchos::OrdinalTraits<GO> GOOT;
74 return Teuchos::rcp(
new Map_Type( GOOT::invalid(), elementListField(), map_->getIndexBase(), map_->getComm() ) );
77template <
class LO,
class GO,
class NO>
78typename Map_Xpetra<LO,GO,NO>::XpetraMapConstPtr_Type Map_Xpetra<LO,GO,NO>::getXpetraMap()
const{
80 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"getXpetraMap(): map_ is null.");
84template <
class LO,
class GO,
class NO>
85typename Map_Xpetra<LO,GO,NO>::ThyraVSBConstPtr_Type Map_Xpetra<LO,GO,NO>::getThyraVectorSpaceBase()
const{
87 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"getThyraVectorSpaceBase(): map_ is null.");
88 return Xpetra::ThyraUtils<default_sc,LO,GO,NO>::toThyra( map_ );
92template <
class LO,
class GO,
class NO>
93GO Map_Xpetra<LO,GO,NO>::getGlobalElement(LO
id)
const{
94 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
95 return map_->getGlobalElement(
id);
98template <
class LO,
class GO,
class NO>
99LO Map_Xpetra<LO,GO,NO>::getLocalElement(GO
id)
const{
100 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
101 return map_->getLocalElement(
id);
104template <
class LO,
class GO,
class NO>
105LO Map_Xpetra<LO,GO,NO>::getNodeNumElements()
const{
106 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
107 return map_->getLocalNumElements();
110template <
class LO,
class GO,
class NO>
111GO Map_Xpetra<LO,GO,NO>::getGlobalNumElements()
const{
112 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
113 return map_->getGlobalNumElements();
116template <
class LO,
class GO,
class NO>
117Teuchos::ArrayView< const GO > Map_Xpetra<LO,GO,NO>::getNodeElementList()
const{
118 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
119 return map_->getLocalElementList();
122template <
class LO,
class GO,
class NO>
123GO Map_Xpetra<LO,GO,NO>::getMaxAllGlobalIndex()
const{
124 return map_->getMaxAllGlobalIndex();
127template <
class LO,
class GO,
class NO>
128LO Map_Xpetra<LO,GO,NO>::getMaxLocalIndex()
const{
129 return map_->getMaxLocalIndex();
132template <
class LO,
class GO,
class NO>
133void Map_Xpetra<LO,GO,NO>::print(Teuchos::EVerbosityLevel verbLevel)
const{
135 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
136 map_->describe(*out,verbLevel);
139template <
class LO,
class GO,
class NO>
140typename Map_Xpetra<LO,GO,NO>::CommConstPtr_Type Map_Xpetra<LO,GO,NO>::getComm()
const{
142 return map_->getComm();
145template <
class LO,
class GO,
class NO>
146typename Map_Xpetra<LO,GO,NO>::CommPtr_Type Map_Xpetra<LO,GO,NO>::getCommNonConst() {
147 CommConstPtr_Type commConst = map_->getComm();
148 return Teuchos::rcp_const_cast<Comm_Type>(commConst);
151template <
class LO,
class GO,
class NO>
154 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
155 if (numFreeProcs==0) {
157 Teuchos::RCP<Xpetra::Vector<GO,LO,GO,NO> > myIndices = Xpetra::VectorFactory<GO,LO,GO,NO>::Build(map_);
158 myIndices->putScalar(map_->getComm()->getRank()+1);
160 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > linearMap = Xpetra::MapFactory<LO,GO,NO>::Build(Xpetra::UseTpetra,map_->getMaxAllGlobalIndex()+1,0,map_->getComm());
161 Teuchos::RCP<Xpetra::Vector<GO,LO,GO,NO> > globalIndices = Xpetra::VectorFactory<GO,LO,GO,NO>::Build(linearMap);
163 Teuchos::RCP<Xpetra::Import<LO,GO,NO> > importer = Xpetra::ImportFactory<LO,GO,NO>::Build(map_,linearMap);
164 Teuchos::RCP<Xpetra::Import<LO,GO,NO> > importer2 = Xpetra::ImportFactory<LO,GO,NO>::Build(linearMap,map_);
165 globalIndices->doImport(*myIndices,*importer,Xpetra::INSERT);
166 myIndices->putScalar(0);
167 myIndices->doImport(*globalIndices,*importer2,Xpetra::ADD);
169 Teuchos::Array<GO> uniqueVector;
170 for (
unsigned i=0; i<myIndices->getLocalLength(); i++) {
171 if (myIndices->getData(0)[i] == map_->getComm()->getRank()+1) {
172 uniqueVector.push_back(map_->getGlobalElement(i));
175 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > mapXpetra = Xpetra::MapFactory<LO,GO,NO>::Build(Xpetra::UseTpetra,-1,uniqueVector(),0,map_->getComm());
176 Teuchos::RCP<Map_Xpetra<LO,GO,NO> > map = Teuchos::rcp(
new Map_Xpetra<LO,GO,NO>( mapXpetra ) );
180 Teuchos::RCP<Xpetra::Vector<GO,LO,GO,NO> > myIndices = Xpetra::VectorFactory<GO,LO,GO,NO>::Build(map_);
181 myIndices->putScalar(map_->getComm()->getRank()+1);
182 GO maxGID = map_->getMaxAllGlobalIndex();
183 int numAvailableRanks = map_->getComm()->getSize() - numFreeProcs;
184 int numElementsForAvailRank = (int) ( ( (maxGID+1) / numAvailableRanks ) + 100.*std::numeric_limits<double>::epsilon() );
186 int remainingElement = maxGID+1 - numAvailableRanks * numElementsForAvailRank;
187 bool hasOneMoreElement =
false;
189 if ( remainingElement > map_->getComm()->getRank() ) {
190 numElementsForAvailRank++;
191 hasOneMoreElement =
true;
194 if ( map_->getComm()->getRank() + 1 > map_->getComm()->getSize() - numFreeProcs){
195 numElementsForAvailRank = 0;
198 Teuchos::Array<GO> myElements( numElementsForAvailRank );
199 GO offset = numElementsForAvailRank * map_->getComm()->getRank();
200 if (!hasOneMoreElement) {
201 offset += remainingElement;
203 for (
int i=0; i<myElements.size(); i++) {
204 myElements[i] = i + offset;
207 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > linearMapAvailRanks = Xpetra::MapFactory<LO,GO,NO>::Build( Xpetra::UseTpetra,Teuchos::OrdinalTraits<GO>::invalid(), myElements(), 0, map_->getComm() );
209 Teuchos::RCP<Xpetra::Vector<GO,LO,GO,NO> > globalIndices = Xpetra::VectorFactory<GO,LO,GO,NO>::Build(linearMapAvailRanks);
211 Teuchos::RCP<Xpetra::Import<LO,GO,NO> > importer = Xpetra::ImportFactory<LO,GO,NO>::Build( map_, linearMapAvailRanks );
212 Teuchos::RCP<Xpetra::Import<LO,GO,NO> > importer2 = Xpetra::ImportFactory<LO,GO,NO>::Build( linearMapAvailRanks, map_ );
214 globalIndices->doImport(*myIndices,*importer,Xpetra::INSERT);
216 myIndices->putScalar(0);
217 myIndices->doImport(*globalIndices,*importer2,Xpetra::ADD);
219 Teuchos::Array<GO> uniqueVector;
220 for (
unsigned i=0; i<myIndices->getLocalLength(); i++) {
221 if (myIndices->getData(0)[i] == map_->getComm()->getRank()+1) {
222 uniqueVector.push_back(map_->getGlobalElement(i));
225 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > mapXpetra = Xpetra::MapFactory<LO,GO,NO>::Build(Xpetra::UseTpetra,-1,uniqueVector(),0,map_->getComm());
226 Teuchos::RCP<Map_Xpetra<LO,GO,NO> > map = Teuchos::rcp(
new Map_Xpetra<LO,GO,NO>( mapXpetra ) );
233template <
class LO,
class GO,
class NO>
236 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
237 int rank = map_->getComm()->getRank();
238 Teuchos::RCP<Xpetra::Vector<GO,LO,GO,NO> > myIndices = Xpetra::VectorFactory<GO,LO,GO,NO>::Build(map_);
239 myIndices->putScalar(rank + 1);
240 GO maxGID = map_->getMaxAllGlobalIndex();
242 int numAvailableRanks = std::get<1>(rankRange) - std::get<0>(rankRange) + 1;
243 int numElementsForAvailRank = (int) ( ( (maxGID+1) / numAvailableRanks ) + 100.*std::numeric_limits<double>::epsilon() );
245 int remainingElement = maxGID+1 - numAvailableRanks * numElementsForAvailRank;
246 bool hasOneMoreElement =
false;
248 if ( remainingElement > map_->getComm()->getRank() - std::get<0>(rankRange) ) {
249 numElementsForAvailRank++;
250 hasOneMoreElement =
true;
252 if ( map_->getComm()->getRank() < std::get<0>(rankRange) || map_->getComm()->getRank() > std::get<1>(rankRange) )
253 numElementsForAvailRank = 0;
256 Teuchos::Array<GO> myElements( numElementsForAvailRank );
257 GO offset = numElementsForAvailRank * ( map_->getComm()->getRank() - std::get<0>(rankRange) );
259 if (!hasOneMoreElement)
260 offset += remainingElement;
262 for (
int i=0; i<myElements.size(); i++)
263 myElements[i] = i + offset;
266 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > linearMapAvailRanks = Xpetra::MapFactory<LO,GO,NO>::Build( Xpetra::UseTpetra,Teuchos::OrdinalTraits<GO>::invalid(), myElements(), 0, map_->getComm() );
268 Teuchos::RCP<Xpetra::Vector<GO,LO,GO,NO> > globalIndices = Xpetra::VectorFactory<GO,LO,GO,NO>::Build(linearMapAvailRanks);
270 Teuchos::RCP<Xpetra::Import<LO,GO,NO> > importer = Xpetra::ImportFactory<LO,GO,NO>::Build( map_, linearMapAvailRanks );
271 Teuchos::RCP<Xpetra::Import<LO,GO,NO> > importer2 = Xpetra::ImportFactory<LO,GO,NO>::Build( linearMapAvailRanks, map_ );
273 globalIndices->doImport(*myIndices,*importer,Xpetra::INSERT);
275 myIndices->putScalar(0);
276 myIndices->doImport(*globalIndices,*importer2,Xpetra::ADD);
278 Teuchos::Array<GO> uniqueVector;
279 for (
unsigned i=0; i<myIndices->getLocalLength(); i++) {
280 if (myIndices->getData(0)[i] == map_->getComm()->getRank()+1) {
281 uniqueVector.push_back(map_->getGlobalElement(i));
284 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > mapXpetra = Xpetra::MapFactory<LO,GO,NO>::Build(Xpetra::UseTpetra,-1,uniqueVector(),0,map_->getComm());
285 Teuchos::RCP<Map_Xpetra<LO,GO,NO> > map = Teuchos::rcp(
new Map_Xpetra<LO,GO,NO>( mapXpetra ) );
291template <
class LO,
class GO,
class NO>
292GO Map_Xpetra<LO,GO,NO>::getIndexBase()
const{
293 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
294 return map_->getIndexBase();
Teuchos::RCP< Map_Xpetra< LO, GO, NO > > buildUniqueMap(int numFreeProcs=0) const
Definition Map_Xpetra_def.hpp:152
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36