Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
BlockMap_def.hpp
1#ifndef BlockMap_DEF_hpp
2#define BlockMap_DEF_hpp
3#include "BlockMap_decl.hpp"
12
13namespace FEDD {
14template <class LO, class GO, class NO>
15BlockMap<LO,GO,NO>::BlockMap():
16blockMap_(0),
17mergedMap_()
18{
19
20}
21
22template < class LO, class GO, class NO>
23BlockMap<LO,GO,NO>::BlockMap(UN size):
24blockMap_(size),
25mergedMap_()
26{
27
28}
29
30template <class LO, class GO, class NO>
31BlockMap<LO,GO,NO>::~BlockMap(){
32
33}
34
35template <class LO, class GO, class NO>
36void BlockMap<LO,GO,NO>::resize(UN size) {
37 blockMap_.resize( size );
38 mergedMap_.reset();
39}
40
41template <class LO, class GO, class NO>
42void BlockMap<LO,GO,NO>::addBlock(MapConstPtr_Type map, int i){
43 TEUCHOS_TEST_FOR_EXCEPTION( map.is_null(), std::runtime_error,"Map which you want to add to BlockMap is null.");
44 if (i>blockMap_.size()-1)
45 blockMap_.resize( blockMap_.size()+1 );
46 if (!blockMap_[i].is_null())
47 blockMap_[i].reset();
48
49 MapPtr_Type mapNonConst = Teuchos::rcp_const_cast<Map_Type>(map);
50 blockMap_[i] = mapNonConst;
51}
52
53
54template <class LO, class GO, class NO>
56 if ( mergedMap_.is_null() ) {
57 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_.size()==0, std::logic_error,"BlockMap has no maps - we cannot merge.");
58 typedef Teuchos::ScalarTraits<GO> GOST;
59 GO globalOffset = GOST::zero();
60 LO offset = Teuchos::ScalarTraits<LO>::zero();
61 Teuchos::Array<GO> globalElementList(0);
62 for (UN i=0; i<blockMap_.size(); i++) {
63 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[i].is_null(), std::runtime_error,"Map in BlockMap is null. This should not happen.");
64 Teuchos::ArrayView<const GO> blockGlobElementList = blockMap_[i]->getNodeElementList();
65 globalElementList.resize( globalElementList.size() + blockGlobElementList.size() );
66 for (UN j=0; j<blockGlobElementList.size(); j++) {
67 globalElementList[offset] = blockGlobElementList[j] + globalOffset;
68 offset++;
69 }
70 globalOffset += blockMap_[i]->getMaxAllGlobalIndex() + 1;
71 }
72
73 CommConstPtr_Type comm = blockMap_[0]->getComm();
74 typedef Teuchos::OrdinalTraits<GO> GOOT;
75
76 mergedMap_ = Teuchos::rcp( new Map_Type( GOOT::invalid(), globalElementList(), GOST::zero(), comm ) );
77 }
78}
79
80template <class LO, class GO, class NO>
81void BlockMap<LO,GO,NO>::print( ){
82 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_.size()==0, std::logic_error,"BlockMap has no maps - nothing to print.");
83 std::cout << " --- Blockmap size: " << blockMap_.size() << " --- " << std::endl;
84 for (UN i=0; i<blockMap_.size(); i++) {
85 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[i].is_null(), std::runtime_error,"Map in BlockMap is null. This should not happen.");
86 blockMap_[i]->print();
87
88 }
89
90}
91template <class LO, class GO, class NO>
92void BlockMap<LO,GO,NO>::info( ){
93 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_.size()==0, std::logic_error,"BlockMap has no maps - nothing to inform.");
94 if(blockMap_[0]->getComm()->getRank() == 0){
95 std::cout << " ------------------------------------------------- " << std::endl;
96 std::cout << " --- Blockmap size: " << blockMap_.size() << " --- " << std::endl;
97 for (UN i=0; i<blockMap_.size(); i++) {
98 std::cout << " ------------------------------------------------- " << std::endl;
99 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[i].is_null(), std::runtime_error,"Map in BlockMap is null. This should not happen.");
100 std::cout << " Block Map i=" << i << std::endl;
101 std::cout << " Global number of elements " << blockMap_[i]->getGlobalNumElements() << std::endl;
102 std::cout << " Maximum index " << blockMap_[i]->getMaxAllGlobalIndex() << std::endl;
103 std::cout << " ------------------------------------------------- " << std::endl;
104
105 }
106 std::cout << " ------------------------------------------------- " << std::endl;
107
108 }
109
110}
111
112template <class LO, class GO, class NO>
113std::string BlockMap<LO,GO,NO>::getUnderlyingLib( ) const{
114 TEUCHOS_TEST_FOR_EXCEPTION(blockMap_.size()==0,std::runtime_error,"BlockMap size is 0, there is no underlying Lib.");
115 TEUCHOS_TEST_FOR_EXCEPTION(blockMap_[0].is_null(),std::runtime_error,"BlockMap[0] is null.");
116 return blockMap_[0]->getUnderlyingLib();
117}
118
119template <class LO, class GO, class NO>
120typename BlockMap<LO,GO,NO>::MapConstPtr_Type BlockMap<LO,GO,NO>::getMergedMap() {
121 if ( mergedMap_.is_null() )
122 this->merge();
123 return mergedMap_;
124}
125
126template <class LO, class GO, class NO>
127typename BlockMap<LO,GO,NO>::CommConstPtr_Type BlockMap<LO,GO,NO>::getComm(){
128 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_.size()==0, std::logic_error,"BlockMap has no maps - no Comm available.");
129 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[0].is_null(), std::logic_error,"BlockMap[0] is null.");
130 return blockMap_[0]->getComm();
131}
132
133template <class LO, class GO, class NO>
134typename BlockMap<LO,GO,NO>::CommPtr_Type BlockMap<LO,GO,NO>::getCommNonConst(){
135 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_.size()==0, std::logic_error,"BlockMap has no maps - no Comm available.");
136 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[0].is_null(), std::logic_error,"BlockMap[0] is null.");
137 return blockMap_[0]->getCommNonConst();
138}
139
140template <class LO, class GO, class NO>
141typename BlockMap<LO,GO,NO>::MapPtr_Type BlockMap<LO,GO,NO>::getBlock(UN i){
142 TEUCHOS_TEST_FOR_EXCEPTION( i > blockMap_.size()-1, std::logic_error,"BlockMap entry does not exist.");
143 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[i].is_null(), std::logic_error,"Map in BlockMap entry is null.");
144 return blockMap_[i];
145}
146
147template <class LO, class GO, class NO>
148typename BlockMap<LO,GO,NO>::MapConstPtr_Type BlockMap<LO,GO,NO>::getBlock(UN i) const{
149 TEUCHOS_TEST_FOR_EXCEPTION( i > blockMap_.size()-1, std::logic_error,"BlockMap entry does not exist.");
150 TEUCHOS_TEST_FOR_EXCEPTION( blockMap_[i].is_null(), std::logic_error,"Map in BlockMap entry is null.");
151 return blockMap_[i];
152}
153
154
155}
156#endif
CommConstPtr_Type getComm()
Get underlying communicator.
Definition BlockMap_def.hpp:127
void merge()
Merging the map of different blocks together. Relevant for monolithic solving/precondtioning.
Definition BlockMap_def.hpp:55
MapConstPtr_Type getMergedMap()
Getting merged map of block maps.
Definition BlockMap_def.hpp:120
void addBlock(MapConstPtr_Type map, int i)
Adding map to corresponding block i. Block i is row-wise distrubted according to the underlying map.
Definition BlockMap_def.hpp:42
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5