12template <
class LO,
class GO,
class NO>
19template <
class LO,
class GO,
class NO>
20Map<LO,GO,NO>::Map( TpetraMapConstPtrConst_Type& tpetraMapPtrIn ):
26template <
class LO,
class GO,
class NO>
27Map<LO,GO,NO>::Map(
const Map_Type& mapIn ):
30 map_ = Teuchos::RCP(
new TpetraMap_Type(mapIn.getGlobalNumElements(), mapIn.getNodeElementList(),mapIn.getIndexBase(), mapIn.getComm()));
34template <
class LO,
class GO,
class NO>
35Map<LO,GO,NO>::Map(GO numGlobalElements,
36 const Teuchos::ArrayView<const GO> &elementList,
38 const CommConstPtr_Type &comm):
41 map_ = Teuchos::RCP(
new TpetraMap_Type(numGlobalElements, elementList, indexBase, comm));
44template <
class LO,
class GO,
class NO>
45Map<LO,GO,NO>::Map(GO numGlobalElements,
48 const CommConstPtr_Type &comm):
51 map_ = Teuchos::RCP(
new TpetraMap_Type(numGlobalElements, numLocalElements, indexBase, comm));
55template <
class LO,
class GO,
class NO>
61template <
class LO,
class GO,
class NO>
62GO Map<LO,GO,NO>::getGlobalElement(LO
id)
const{
63 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
64 return map_->getGlobalElement(
id);
67template <
class LO,
class GO,
class NO>
68LO Map<LO,GO,NO>::getLocalElement(GO
id)
const{
69 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
70 return map_->getLocalElement(
id);
73template <
class LO,
class GO,
class NO>
74LO Map<LO,GO,NO>::getNodeNumElements()
const{
75 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
76 return map_->getLocalNumElements();
79template <
class LO,
class GO,
class NO>
80GO Map<LO,GO,NO>::getGlobalNumElements()
const{
81 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
82 return map_->getGlobalNumElements();
85template <
class LO,
class GO,
class NO>
86typename Map<LO,GO,NO>::CommConstPtr_Type Map<LO,GO,NO>::getComm()
const{
88 return map_->getComm();
91template <
class LO,
class GO,
class NO>
92GO Map<LO,GO,NO>::getIndexBase()
const{
93 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
94 return map_->getIndexBase();
97template <
class LO,
class GO,
class NO>
98Teuchos::ArrayView< const GO > Map<LO,GO,NO>::getNodeElementList()
const{
99 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
100 return map_->getLocalElementList();
103template <
class LO,
class GO,
class NO>
104typename Map<LO,GO,NO>::MapPtr_Type Map<LO,GO,NO>::buildVecFieldMap(UN numDofs, std::string ordering)
const{
106 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
107 TEUCHOS_TEST_FOR_EXCEPTION(ordering.compare(
"NodeWise"), std::logic_error,
"Select a valid ordering: NodeWise");
108 Teuchos::ArrayView<const GO> elementList = map_->getLocalElementList();
109 Teuchos::Array<GO> elementListField( numDofs * elementList.size() );
110 for (UN i=0; i<elementList.size(); i++) {
111 for (UN dof=0; dof<numDofs; dof++)
112 elementListField[ numDofs * i + dof ] = numDofs * elementList[i] + dof;
114 typedef Teuchos::OrdinalTraits<GO> GOOT;
115 return Teuchos::rcp(
new Map_Type(GOOT::invalid(), elementListField(), map_->getIndexBase(), map_->getComm() ) );
119template <
class LO,
class GO,
class NO>
120typename Map<LO,GO,NO>::TpetraMapConstPtr_Type Map<LO,GO,NO>::getTpetraMap()
const{
122 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"getTpetraMap(): map_ is null.");
127template <
class LO,
class GO,
class NO>
128GO Map<LO,GO,NO>::getMaxAllGlobalIndex()
const{
129 return map_->getMaxAllGlobalIndex();
132template <
class LO,
class GO,
class NO>
133LO Map<LO,GO,NO>::getMaxLocalIndex()
const{
134 return map_->getMaxLocalIndex();
137template <
class LO,
class GO,
class NO>
138void Map<LO,GO,NO>::print(Teuchos::EVerbosityLevel verbLevel)
const{
140 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
141 map_->describe(*out,verbLevel);
144template <
class LO,
class GO,
class NO>
145typename Map<LO,GO,NO>::ThyraVSBConstPtr_Type Map<LO,GO,NO>::getThyraVectorSpaceBase()
const{
147 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"getThyraVectorSpaceBase(): map_ is null.");
149 Teuchos::RCP<Thyra::TpetraVectorSpace<default_sc,LO,GO,NO> > thyraTpetraMap = Thyra::tpetraVectorSpace<default_sc,LO,GO,NO>(map_);
150 return thyraTpetraMap;
153template <
class LO,
class GO,
class NO>
154typename Map<LO,GO,NO>::CommPtr_Type Map<LO,GO,NO>::getCommNonConst() {
155 CommConstPtr_Type commConst = map_->getComm();
156 return Teuchos::rcp_const_cast<Comm_Type>(commConst);
159template <
class LO,
class GO,
class NO>
162 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
163 if (numFreeProcs==0) {
165 Teuchos::RCP<Tpetra::Vector<GO,LO,GO,NO> > myIndices = Teuchos::RCP(
new Tpetra::Vector<GO,LO,GO,NO>(map_));
166 myIndices->putScalar(map_->getComm()->getRank()+1);
168 TpetraMapPtr_Type linearMap = Teuchos::RCP(
new TpetraMap_Type( map_->getMaxAllGlobalIndex()+1, 0, map_->getComm()));
169 Teuchos::RCP<Tpetra::Vector<GO,LO,GO,NO> > globalIndices = Teuchos::RCP(
new Tpetra::Vector<GO,LO,GO,NO>(linearMap));
171 Teuchos::RCP<Tpetra::Import<LO,GO,NO> > importer = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>( map_,linearMap));
172 Teuchos::RCP<Tpetra::Import<LO,GO,NO> > importer2 = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(linearMap, map_));
173 globalIndices->doImport(*myIndices,*importer,Tpetra::INSERT);
174 myIndices->putScalar(0);
175 myIndices->doImport(*globalIndices,*importer2,Tpetra::ADD);
177 Teuchos::Array<GO> uniqueVector;
178 for (
unsigned i=0; i<myIndices->getLocalLength(); i++) {
179 if (myIndices->getData(0)[i] == map_->getComm()->getRank()+1) {
180 uniqueVector.push_back(map_->getGlobalElement(i));
183 TpetraMapPtr_Type mapTpetra = Teuchos::RCP(
new TpetraMap_Type(-1, uniqueVector(),0,map_->getComm()));
184 Teuchos::RCP<Map<LO,GO,NO> > map = Teuchos::rcp(
new Map<LO,GO,NO>( mapTpetra ) );
188 Teuchos::RCP<Tpetra::Vector<GO,LO,GO,NO> > myIndices = Teuchos::RCP(
new Tpetra::Vector<GO,LO,GO,NO>(map_));
189 myIndices->putScalar(map_->getComm()->getRank()+1);
190 GO maxGID = map_->getMaxAllGlobalIndex();
191 int numAvailableRanks = map_->getComm()->getSize() - numFreeProcs;
192 int numElementsForAvailRank = (int) ( ( (maxGID+1) / numAvailableRanks ) + 100.*std::numeric_limits<double>::epsilon() );
194 int remainingElement = maxGID+1 - numAvailableRanks * numElementsForAvailRank;
195 bool hasOneMoreElement =
false;
197 if ( remainingElement > map_->getComm()->getRank() ) {
198 numElementsForAvailRank++;
199 hasOneMoreElement =
true;
202 if ( map_->getComm()->getRank() + 1 > map_->getComm()->getSize() - numFreeProcs){
203 numElementsForAvailRank = 0;
206 Teuchos::Array<GO> myElements( numElementsForAvailRank );
207 GO offset = numElementsForAvailRank * map_->getComm()->getRank();
208 if (!hasOneMoreElement) {
209 offset += remainingElement;
211 for (
int i=0; i<myElements.size(); i++) {
212 myElements[i] = i + offset;
215 TpetraMapPtr_Type linearMapAvailRanks = Teuchos::RCP(
new TpetraMap_Type(Teuchos::OrdinalTraits<GO>::invalid(), myElements(), 0, map_->getComm()));
216 Teuchos::RCP<Tpetra::Vector<GO,LO,GO,NO> > globalIndices = Teuchos::RCP(
new Tpetra::Vector<GO,LO,GO,NO>(linearMapAvailRanks));
218 Teuchos::RCP<Tpetra::Import<LO,GO,NO> > importer = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(map_, linearMapAvailRanks ));
219 Teuchos::RCP<Tpetra::Import<LO,GO,NO> > importer2 = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>( linearMapAvailRanks, map_));
221 globalIndices->doImport(*myIndices,*importer,Tpetra::INSERT);
223 myIndices->putScalar(0);
224 myIndices->doImport(*globalIndices,*importer2,Tpetra::ADD);
226 Teuchos::Array<GO> uniqueVector;
227 for (
unsigned i=0; i<myIndices->getLocalLength(); i++) {
228 if (myIndices->getData(0)[i] == map_->getComm()->getRank()+1) {
229 uniqueVector.push_back(map_->getGlobalElement(i));
232 TpetraMapPtr_Type mapTpetra = Teuchos::RCP(
new TpetraMap_Type(-1, uniqueVector(),0,map_->getComm()));
233 Teuchos::RCP<Map<LO,GO,NO> > map = Teuchos::rcp(
new Map<LO,GO,NO>( mapTpetra ) );
240template <
class LO,
class GO,
class NO>
243 TEUCHOS_TEST_FOR_EXCEPTION(map_.is_null(),std::runtime_error,
"map is null.");
244 int rank = map_->getComm()->getRank();
245 Teuchos::RCP<Tpetra::Vector<GO,LO,GO,NO> > myIndices = Teuchos::RCP(
new Tpetra::Vector<GO,LO,GO,NO>(map_));
247 myIndices->putScalar(rank + 1);
248 GO maxGID = map_->getMaxAllGlobalIndex();
250 int numAvailableRanks = std::get<1>(rankRange) - std::get<0>(rankRange) + 1;
251 int numElementsForAvailRank = (int) ( ( (maxGID+1) / numAvailableRanks ) + 100.*std::numeric_limits<double>::epsilon() );
253 int remainingElement = maxGID+1 - numAvailableRanks * numElementsForAvailRank;
254 bool hasOneMoreElement =
false;
256 if ( remainingElement > map_->getComm()->getRank() - std::get<0>(rankRange) ) {
257 numElementsForAvailRank++;
258 hasOneMoreElement =
true;
260 if ( map_->getComm()->getRank() < std::get<0>(rankRange) || map_->getComm()->getRank() > std::get<1>(rankRange) )
261 numElementsForAvailRank = 0;
264 Teuchos::Array<GO> myElements( numElementsForAvailRank );
265 GO offset = numElementsForAvailRank * ( map_->getComm()->getRank() - std::get<0>(rankRange) );
267 if (!hasOneMoreElement)
268 offset += remainingElement;
270 for (
int i=0; i<myElements.size(); i++)
271 myElements[i] = i + offset;
273 TpetraMapPtr_Type linearMapAvailRanks = Teuchos::RCP(
new TpetraMap_Type( Teuchos::OrdinalTraits<GO>::invalid(), myElements(), 0, map_->getComm()));
274 Teuchos::RCP<Tpetra::Vector<GO,LO,GO,NO> > globalIndices = Teuchos::RCP(
new Tpetra::Vector<GO,LO,GO,NO>(linearMapAvailRanks));
276 Teuchos::RCP<Tpetra::Import<LO,GO,NO> > importer = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>( map_,linearMapAvailRanks));
277 Teuchos::RCP<Tpetra::Import<LO,GO,NO> > importer2 = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(linearMapAvailRanks, map_));
279 globalIndices->doImport(*myIndices,*importer,Tpetra::INSERT);
281 myIndices->putScalar(0);
282 myIndices->doImport(*globalIndices,*importer2,Tpetra::ADD);
284 Teuchos::Array<GO> uniqueVector;
285 for (
unsigned i=0; i<myIndices->getLocalLength(); i++) {
286 if (myIndices->getData(0)[i] == map_->getComm()->getRank()+1) {
287 uniqueVector.push_back(map_->getGlobalElement(i));
291 TpetraMapPtr_Type mapTpetra = Teuchos::RCP(
new TpetraMap_Type(-1, uniqueVector(),0,map_->getComm()));
292 Teuchos::RCP<Map<LO,GO,NO> > map = Teuchos::rcp(
new Map<LO,GO,NO>( mapTpetra ) );
Teuchos::RCP< Map< LO, GO, NO > > buildUniqueMap(int numFreeProcs=0) const
Definition Map_def.hpp:160
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36