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/*
5 We need to remove some functions from the MultiVector class that are
6 only supported for a scalar type (SC) of double. To achieve this we use
7 concepts, which are supported since C++20. The problematic functions,
8 for which only SC = double is supported, are functions that return
9 a Thyra vector. A Thyra vector does not exist for SC = int, for example.
10*/
11#include <concepts>
12
13#include <MatrixMarket_Tpetra.hpp>
14#include <Teuchos_VerboseObject.hpp>
15#include <Tpetra_MultiVector.hpp>
16#include <Tpetra_Map.hpp>
17#include <Tpetra_MultiVector.hpp>
18#include <Tpetra_Vector.hpp>
19#include <Tpetra_Export.hpp>
20#include <Tpetra_Import.hpp>
21#include <Thyra_DefaultProductVectorSpace.hpp>
22#include <Thyra_TpetraThyraWrappers.hpp>
23
24#include "feddlib/core/FEDDCore.hpp"
25#include "Map.hpp"
26#include "BlockMap.hpp"
27#include "BlockMultiVector.hpp"
28
37
38namespace FEDD {
39// Forward Declaration of BlockMultiVector to avoid circular includes (BlockMultiVector includes MultiVector) and speed up compilation time.
40template <class SC, class LO, class GO, class NO>
42template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
43// template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
44
45class MultiVector {
46
47public:
48
49 typedef MultiVector<SC,LO,GO,NO> MultiVector_Type;
50 typedef Teuchos::RCP<MultiVector_Type> MultiVectorPtr_Type;
51 typedef Teuchos::RCP<const MultiVector_Type> MultiVectorConstPtr_Type;
52
53 typedef BlockMultiVector<SC,LO,GO,NO> BlockMultiVector_Type;
54 typedef Teuchos::RCP<BlockMultiVector_Type> BlockMultiVectorPtr_Type;
55 typedef Teuchos::RCP<const BlockMultiVector_Type> BlockMultiVectorConstPtr_Type;
56
57
58 typedef Teuchos::Comm<int> Comm_Type;
59 typedef Teuchos::RCP<Comm_Type> CommPtr_Type;
60 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
61
62 // -------------
63 typedef Map<LO,GO,NO> Map_Type;
64 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
65 typedef Teuchos::RCP<const Map_Type> MapConstPtr_Type;
66
67 typedef Tpetra::Map<LO,GO,NO> TpetraMap_Type;
68 typedef Teuchos::RCP<TpetraMap_Type> TpetraMapPtr_Type;
69 typedef Teuchos::RCP<const TpetraMap_Type> TpetraMapConstPtr_Type;
70 typedef const TpetraMapConstPtr_Type TpetraMapConstPtrConst_Type;
71
72 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMultiVector_Type;
73 typedef Teuchos::RCP<TpetraMultiVector_Type> TpetraMultiVectorPtr_Type;
74 typedef Teuchos::RCP<const TpetraMultiVector_Type> TpetraMultiVectorConstPtr_Type;
75 typedef const TpetraMultiVectorConstPtr_Type TpetraMultiVectorConstPtrConst_Type;
76
77 typedef Tpetra::Import<LO,GO,NO> TpetraImport_Type;
78 typedef Teuchos::RCP<TpetraImport_Type> TpetraImportPtr_Type;
79
80 typedef Tpetra::Export<LO,GO,NO> TpetraExport_Type;
81 typedef Teuchos::RCP<TpetraExport_Type> TpetraExportPtr_Type;
82
83
84
85 MultiVector();
86
87
91 MultiVector( MapConstPtr_Type map, UN nmbVectors=1 );
92
95 MultiVector( TpetraMultiVectorPtr_Type& TpetraMVPtrIn );
96
99 MultiVector( MultiVectorConstPtr_Type mvIn );
100
103
110 MultiVector_Type& operator= (const MultiVector_Type& rhs) {
111 Tpetra::deep_copy<SC,LO,GO,NO>(*multiVector_,*rhs.getTpetraMultiVector()); // (destination, source)
112 return *this;
113 }
114
116 bool is_null() const;
117
120 MapConstPtr_Type getMap() const;
121
124 MapPtr_Type getMapNonConst();
125
128 TpetraMapConstPtr_Type getMapTpetra() const;
129
136 void replaceGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
137
143 void replaceLocalValue (LO localRow, UN vectorIndex, const SC &value);
144
155 void sumIntoGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
156
157 LO getLocalLength() const;
158
162 Teuchos::ArrayRCP< const SC > getData(UN i) const;
163
167 Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const;
168
170 UN getNumVectors() const;
171
173 void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const;
174
175 TpetraMultiVectorConstPtr_Type getTpetraMultiVector() const;
176
177 TpetraMultiVectorPtr_Type getTpetraMultiVectorNonConst();
178
179 Teuchos::RCP< Thyra::MultiVectorBase<SC> > getThyraMultiVector( ) requires std::same_as<SC,double>;
180
181 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > getThyraMultiVectorConst( ) const requires std::same_as<SC,double>;
182
183 void fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV);
184
185 void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
186
187 void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
188
189 void dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots) const;
190
191 // Calculate absolute value of Multivector
192 void abs(MultiVectorConstPtr_Type a);
193 //this = alpha*A + beta*this
194 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta );
195
196 //this = alpha*A + beta*B + gamma*this
197 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma);
198
199 // Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
200 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B, const SC &beta);
201
202 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const SC &beta) requires std::same_as<SC,double>;
203
204 void putScalar( const SC& alpha );
205
206 void scale( const SC& alpha );
207
208 void importFromVector( MultiVectorConstPtr_Type mvIn, bool reuseImport = false, std::string combineMode = "Insert", std::string type="Forward" );
209
210 void exportFromVector( MultiVectorConstPtr_Type mvIn, bool reuseExport = false, std::string combineMode = "Insert", std::string type="Forward" );
211
212 void writeMM(std::string fileName="mv.mm") const;
213
214 void readMM(std::string fileName) const;
215
216 MultiVectorConstPtr_Type getVector( int i ) const;
217
218 MultiVectorPtr_Type sumColumns() const;
219
220 SC getMax() const;
221
222private:
223
224 TpetraMultiVectorPtr_Type multiVector_;
225 MapConstPtr_Type map_;
226 TpetraImportPtr_Type importer_;
227 TpetraExportPtr_Type exporter_;
228};
229}
230
231#endif
Definition BlockMultiVector_decl.hpp:25
Definition Map_decl.hpp:30
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:110
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:36