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 <Thyra_LinearOpBase_decl.hpp>
8#include <Xpetra_ThyraUtils.hpp>
9#include <Teuchos_VerboseObject.hpp>
10#include <MatrixMarket_Tpetra.hpp>
11
12#include <Tpetra_MultiVector.hpp>
13#include <Tpetra_Map.hpp>
14#include <Tpetra_MultiVector.hpp>
15#include <Tpetra_Vector.hpp>
16#include <Tpetra_Export.hpp>
17#include <Tpetra_Import.hpp>
18
27
28namespace FEDD {
29// Forward Declaration of BlockMultiVector to avoid circular includes (BlockMultiVector includes MultiVector) and speed up compilation time.
30template <class SC, class LO, class GO, class NO>
32template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
33class MultiVector {
34
35public:
36 /*typedef Xpetra::Map<LO,GO,NO> XpetraMap_Type;
37 typedef Teuchos::RCP<XpetraMap_Type> XpetraMapPtr_Type;
38 typedef Teuchos::RCP<const XpetraMap_Type> XpetraMapConstPtr_Type;
39 typedef const XpetraMapConstPtr_Type XpetraMapConstPtrConst_Type;*/
40
41 typedef MultiVector<SC,LO,GO,NO> MultiVector_Type;
42 typedef Teuchos::RCP<MultiVector_Type> MultiVectorPtr_Type;
43 typedef Teuchos::RCP<const MultiVector_Type> MultiVectorConstPtr_Type;
44
45 typedef BlockMultiVector<SC,LO,GO,NO> BlockMultiVector_Type;
46 typedef Teuchos::RCP<BlockMultiVector_Type> BlockMultiVectorPtr_Type;
47 typedef Teuchos::RCP<const BlockMultiVector_Type> BlockMultiVectorConstPtr_Type;
48
49 // typedef Xpetra::MultiVector<SC,LO,GO,NO> XpetraMultiVector_Type;
50 // typedef Teuchos::RCP<XpetraMultiVector_Type> XpetraMultiVectorPtr_Type;
51 // typedef Teuchos::RCP<const XpetraMultiVector_Type> XpetraMultiVectorConstPtr_Type;
52 // typedef const XpetraMultiVectorConstPtr_Type XpetraMultiVectorConstPtrConst_Type;
53
54
55 // typedef Xpetra::Import<LO,GO,NO> XpetraImport_Type;
56 // typedef Teuchos::RCP<XpetraImport_Type> XpetraImportPtr_Type;
57
58 // typedef Xpetra::Export<LO,GO,NO> XpetraExport_Type;
59 // typedef Teuchos::RCP<XpetraExport_Type> XpetraExportPtr_Type;
60
61 typedef Teuchos::Comm<int> Comm_Type;
62 typedef Teuchos::RCP<Comm_Type> CommPtr_Type;
63 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
64
65 // -------------
66 typedef Map<LO,GO,NO> Map_Type;
67 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
68 typedef Teuchos::RCP<const Map_Type> MapConstPtr_Type;
69
70 typedef Tpetra::Map<LO,GO,NO> TpetraMap_Type;
71 typedef Teuchos::RCP<TpetraMap_Type> TpetraMapPtr_Type;
72 typedef Teuchos::RCP<const TpetraMap_Type> TpetraMapConstPtr_Type;
73 typedef const TpetraMapConstPtr_Type TpetraMapConstPtrConst_Type;
74
75 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMultiVector_Type;
76 typedef Teuchos::RCP<TpetraMultiVector_Type> TpetraMultiVectorPtr_Type;
77 typedef Teuchos::RCP<const TpetraMultiVector_Type> TpetraMultiVectorConstPtr_Type;
78 typedef const TpetraMultiVectorConstPtr_Type TpetraMultiVectorConstPtrConst_Type;
79
80 typedef Tpetra::Import<LO,GO,NO> TpetraImport_Type;
81 typedef Teuchos::RCP<TpetraImport_Type> TpetraImportPtr_Type;
82
83 typedef Tpetra::Export<LO,GO,NO> TpetraExport_Type;
84 typedef Teuchos::RCP<TpetraExport_Type> TpetraExportPtr_Type;
85
86
87
88 MultiVector();
89
90
94 MultiVector( MapConstPtr_Type map, UN nmbVectors=1 );
95
98 MultiVector( TpetraMultiVectorPtr_Type& TpetraMVPtrIn );
99
102 MultiVector( MultiVectorConstPtr_Type mvIn );
103
106
113 MultiVector_Type& operator= (const MultiVector_Type& rhs) {
114 Tpetra::deep_copy<SC,LO,GO,NO>(*multiVector_,*rhs.getTpetraMultiVector()); // (destination, source)
115 return *this;
116 }
117
119 bool is_null() const;
120
123 MapConstPtr_Type getMap() const;
124
127 MapPtr_Type getMapNonConst();
128
131 TpetraMapConstPtr_Type getMapTpetra() const;
132
139 void replaceGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
140
146 void replaceLocalValue (LO localRow, UN vectorIndex, const SC &value);
147
158 void sumIntoGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
159
160 LO getLocalLength() const;
161
165 Teuchos::ArrayRCP< const SC > getData(UN i) const;
166
170 Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const;
171
173 UN getNumVectors() const;
174
176 void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const;
177
178 TpetraMultiVectorConstPtr_Type getTpetraMultiVector() const;
179
180 TpetraMultiVectorPtr_Type getTpetraMultiVectorNonConst();
181
182 Teuchos::RCP< Thyra::MultiVectorBase<SC> > getThyraMultiVector( );
183
184 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > getThyraMultiVectorConst( ) const;
185
186 void fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV);
187
188 void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
189
190 void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
191
192 void dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots) const;
193
194 // Calculate absolute value of Multivector
195 void abs(MultiVectorConstPtr_Type a);
196 //this = alpha*A + beta*this
197 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta );
198
199 //this = alpha*A + beta*B + gamma*this
200 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma);
201
202 // Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
203 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B, const SC &beta);
204
205 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const SC &beta);
206
207 void putScalar( const SC& alpha );
208
209 void scale( const SC& alpha );
210
211 void importFromVector( MultiVectorConstPtr_Type mvIn, bool reuseImport = false, std::string combineMode = "Insert", std::string type="Forward" );
212
213 void exportFromVector( MultiVectorConstPtr_Type mvIn, bool reuseExport = false, std::string combineMode = "Insert", std::string type="Forward" );
214
215 void writeMM(std::string fileName="mv.mm") const;
216
217 void readMM(std::string fileName) const;
218
219 MultiVectorConstPtr_Type getVector( int i ) const;
220
221 MultiVectorPtr_Type sumColumns() const;
222
223 SC getMax() const;
224
225private:
226
227 TpetraMultiVectorPtr_Type multiVector_;
228 MapConstPtr_Type map_;
229 TpetraImportPtr_Type importer_;
230 TpetraExportPtr_Type exporter_;
231};
232}
233
234#endif
Definition BlockMultiVector_decl.hpp:25
Definition Map_decl.hpp:36
void replaceLocalValue(LO localRow, UN vectorIndex, const SC &value)
Definition MultiVector_def.hpp:99
MultiVector(TpetraMultiVectorPtr_Type &TpetraMVPtrIn)
Wrap an existing tpetra multivector. TpetraMVPtrIn is left intact and points to the same Tpetra::Mult...
Definition MultiVector_def.hpp:39
Teuchos::ArrayRCP< const SC > getData(UN i) const
Get data of multivector.
Definition MultiVector_def.hpp:114
Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const
Get data of multivector.
Definition MultiVector_def.hpp:119
bool is_null() const
checking whether the multiVector exists
Definition MultiVector_def.hpp:89
MultiVector(MultiVectorConstPtr_Type mvIn)
Initialize tpetra multivector based on input multivector. Uses underlying map and value information t...
Definition MultiVector_def.hpp:49
MapPtr_Type getMapNonConst()
Return non constant version of underlying map.
Definition MultiVector_def.hpp:76
MapConstPtr_Type getMap() const
Return underlying map.
Definition MultiVector_def.hpp:71
TpetraMapConstPtr_Type getMapTpetra() const
Return direct tpetra map of underlying map.
Definition MultiVector_def.hpp:81
MultiVector_Type & operator=(const MultiVector_Type &rhs)
Copy assignment operator. This does a deep copy of the rhs into *this. The Xpetra::MultiVector copy a...
Definition MultiVector_decl.hpp:113
void replaceGlobalValue(GO globalRow, UN vectorIndex, const SC &value)
Replace global value in mv.
Definition MultiVector_def.hpp:94
void sumIntoGlobalValue(GO globalRow, UN vectorIndex, const SC &value)
Update (+=) a value in host memory, using global row index.
Definition MultiVector_def.hpp:104
~MultiVector()
Destructor.
Definition MultiVector_def.hpp:66
UN getNumVectors() const
Get number of multivector (columns)
Definition MultiVector_def.hpp:125
MultiVector(MapConstPtr_Type map, UN nmbVectors=1)
Initialize tpetra multivector based on underyling map and number of vectors within....
Definition MultiVector_def.hpp:29
void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const
Printing mv. Depending on verbosity level, output increases.
Definition MultiVector_def.hpp:140
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:33