Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
MultiVector_decl.hpp
1#ifndef MULTIVECTOR_DECL_hpp
2#define MULTIVECTOR_DECL_hpp
3
4#include "feddlib/core/FEDDCore.hpp"
5#include "feddlib/core/General/DefaultTypeDefs.hpp"
6#include "Map.hpp"
7#include "BlockMap.hpp"
8#include "BlockMultiVector.hpp"
9#include <Xpetra_MultiVectorFactory.hpp>
10#include <Xpetra_ImportFactory.hpp>
11#include <Thyra_LinearOpBase_decl.hpp>
12#include <Xpetra_ThyraUtils.hpp>
13#include <Teuchos_VerboseObject.hpp>
14#include <MatrixMarket_Tpetra.hpp>
15
16#include <Tpetra_MultiVector.hpp>
17#include <Tpetra_Map.hpp>
18#include <Tpetra_MultiVector.hpp>
19#include <Tpetra_Vector.hpp>
20#include <Tpetra_Export.hpp>
21#include <Tpetra_Import.hpp>
22
31
32namespace FEDD {
33template <class SC, class LO, class GO, class NO>
35template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
36class MultiVector {
37
38public:
39 /*typedef Xpetra::Map<LO,GO,NO> XpetraMap_Type;
40 typedef Teuchos::RCP<XpetraMap_Type> XpetraMapPtr_Type;
41 typedef Teuchos::RCP<const XpetraMap_Type> XpetraMapConstPtr_Type;
42 typedef const XpetraMapConstPtr_Type XpetraMapConstPtrConst_Type;*/
43
44 typedef MultiVector<SC,LO,GO,NO> MultiVector_Type;
45 typedef Teuchos::RCP<MultiVector_Type> MultiVectorPtr_Type;
46 typedef Teuchos::RCP<const MultiVector_Type> MultiVectorConstPtr_Type;
47
48 typedef BlockMultiVector<SC,LO,GO,NO> BlockMultiVector_Type;
49 typedef Teuchos::RCP<BlockMultiVector_Type> BlockMultiVectorPtr_Type;
50 typedef Teuchos::RCP<const BlockMultiVector_Type> BlockMultiVectorConstPtr_Type;
51
52 // typedef Xpetra::MultiVector<SC,LO,GO,NO> XpetraMultiVector_Type;
53 // typedef Teuchos::RCP<XpetraMultiVector_Type> XpetraMultiVectorPtr_Type;
54 // typedef Teuchos::RCP<const XpetraMultiVector_Type> XpetraMultiVectorConstPtr_Type;
55 // typedef const XpetraMultiVectorConstPtr_Type XpetraMultiVectorConstPtrConst_Type;
56
57
58 // typedef Xpetra::Import<LO,GO,NO> XpetraImport_Type;
59 // typedef Teuchos::RCP<XpetraImport_Type> XpetraImportPtr_Type;
60
61 // typedef Xpetra::Export<LO,GO,NO> XpetraExport_Type;
62 // typedef Teuchos::RCP<XpetraExport_Type> XpetraExportPtr_Type;
63
64 typedef Teuchos::Comm<int> Comm_Type;
65 typedef Teuchos::RCP<Comm_Type> CommPtr_Type;
66 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
67
68 // -------------
69 typedef Map<LO,GO,NO> Map_Type;
70 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
71 typedef Teuchos::RCP<const Map_Type> MapConstPtr_Type;
72
73 typedef Tpetra::Map<LO,GO,NO> TpetraMap_Type;
74 typedef Teuchos::RCP<TpetraMap_Type> TpetraMapPtr_Type;
75 typedef Teuchos::RCP<const TpetraMap_Type> TpetraMapConstPtr_Type;
76 typedef const TpetraMapConstPtr_Type TpetraMapConstPtrConst_Type;
77
78 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMultiVector_Type;
79 typedef Teuchos::RCP<TpetraMultiVector_Type> TpetraMultiVectorPtr_Type;
80 typedef Teuchos::RCP<const TpetraMultiVector_Type> TpetraMultiVectorConstPtr_Type;
81 typedef const TpetraMultiVectorConstPtr_Type TpetraMultiVectorConstPtrConst_Type;
82
83 typedef Tpetra::Import<LO,GO,NO> TpetraImport_Type;
84 typedef Teuchos::RCP<TpetraImport_Type> TpetraImportPtr_Type;
85
86 typedef Tpetra::Export<LO,GO,NO> TpetraExport_Type;
87 typedef Teuchos::RCP<TpetraExport_Type> TpetraExportPtr_Type;
88
89
90
91 MultiVector();
92
93
97 MultiVector( MapConstPtr_Type map, UN nmbVectors=1 );
98
101 MultiVector( TpetraMultiVectorPtr_Type& TpetraMVPtrIn );
102
105 MultiVector( MultiVectorConstPtr_Type mvIn );
106
109
110
114 MultiVector_Type& operator= (const MultiVector_Type& rhs) {
115 //*multiVector_ = *rhs.getTpetraMultiVector(); // old version which worked with xpetra
116 FEDDLIB_NOTIFICATION("MultiVector_decl",rhs.getMap()->getComm()->getRank() == 0, " '=' creating a deep copy of input vector into this.");
117 Tpetra::deep_copy<SC,LO,GO,NO>(*multiVector_,*rhs.getTpetraMultiVector()); // (destination, source)
118 return *this;
119 }
120
122 bool is_null() const;
123
126 MapConstPtr_Type getMap() const;
127
130 MapPtr_Type getMapNonConst();
131
134 TpetraMapConstPtr_Type getMapTpetra() const;
135
142 void replaceGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
143
149 void replaceLocalValue (LO localRow, UN vectorIndex, const SC &value);
150
161 void sumIntoGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
162
163 LO getLocalLength() const;
164
168 Teuchos::ArrayRCP< const SC > getData(UN i) const;
169
173 Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const;
174
176 UN getNumVectors() const;
177
179 void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const;
180
181 TpetraMultiVectorConstPtr_Type getTpetraMultiVector() const;
182
183 TpetraMultiVectorPtr_Type getTpetraMultiVectorNonConst();
184
185 Teuchos::RCP< Thyra::MultiVectorBase<SC> > getThyraMultiVector( );
186
187 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > getThyraMultiVectorConst( ) const;
188
189 void fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV);
190
191 void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
192
193 void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
194
195 void dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots) const;
196
197 // Calculate absolute value of Multivector
198 void abs(MultiVectorConstPtr_Type a);
199 //this = alpha*A + beta*this
200 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta );
201
202 //this = alpha*A + beta*B + gamma*this
203 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma);
204
205 // Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
206 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B, const SC &beta);
207
208 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const SC &beta);
209
210 void putScalar( const SC& alpha );
211
212 void scale( const SC& alpha );
213
214 void importFromVector( MultiVectorConstPtr_Type mvIn, bool reuseImport = false, std::string combineMode = "Insert", std::string type="Forward" );
215
216 void exportFromVector( MultiVectorConstPtr_Type mvIn, bool reuseExport = false, std::string combineMode = "Insert", std::string type="Forward" );
217
218 void writeMM(std::string fileName="mv.mm") const;
219
220 void readMM(std::string fileName) const;
221
222 MultiVectorConstPtr_Type getVector( int i ) const;
223
224 MultiVectorPtr_Type sumColumns() const;
225
226 SC getMax() const;
227
228private:
229
230 TpetraMultiVectorPtr_Type multiVector_;
231 MapConstPtr_Type map_;
232 TpetraImportPtr_Type importer_;
233 TpetraExportPtr_Type exporter_;
234};
235}
236
237#endif
Definition BlockMultiVector_decl.hpp:25
Definition Map_decl.hpp:36
void replaceLocalValue(LO localRow, UN vectorIndex, const SC &value)
Definition MultiVector_def.hpp:107
MultiVector(TpetraMultiVectorPtr_Type &TpetraMVPtrIn)
Initialize tpetra multivector based on input multivector. Uses underlying map. !! Probably,...
Definition MultiVector_def.hpp:40
Teuchos::ArrayRCP< const SC > getData(UN i) const
Get data of multivector.
Definition MultiVector_def.hpp:122
Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const
Get data of multivector.
Definition MultiVector_def.hpp:127
bool is_null() const
checking whether the multiVector exists
Definition MultiVector_def.hpp:97
MultiVector(MultiVectorConstPtr_Type mvIn)
Initialize tpetra multivector based on input multivector. Uses underlying map and value information t...
Definition MultiVector_def.hpp:54
MapPtr_Type getMapNonConst()
Return non constant version of underlying map.
Definition MultiVector_def.hpp:84
MapConstPtr_Type getMap() const
Return underlying map.
Definition MultiVector_def.hpp:79
TpetraMapConstPtr_Type getMapTpetra() const
Return direct tpetra map of underlying map.
Definition MultiVector_def.hpp:89
MultiVector_Type & operator=(const MultiVector_Type &rhs)
This will replace *this contents with the rhs input. Updated to deep copy, as this is necessary so bo...
Definition MultiVector_decl.hpp:114
void replaceGlobalValue(GO globalRow, UN vectorIndex, const SC &value)
Replace global value in mv.
Definition MultiVector_def.hpp:102
void sumIntoGlobalValue(GO globalRow, UN vectorIndex, const SC &value)
Update (+=) a value in host memory, using global row index.
Definition MultiVector_def.hpp:112
~MultiVector()
Destructor.
Definition MultiVector_def.hpp:74
UN getNumVectors() const
Get number of multivector (columns)
Definition MultiVector_def.hpp:133
MultiVector(MapConstPtr_Type map, UN nmbVectors=1)
Initialize tpetra multivector based on underyling map and number of vectors within....
Definition MultiVector_def.hpp:30
void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const
Printing mv. Depending on verbosity level, output increases.
Definition MultiVector_def.hpp:148
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5