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 is
7 simple using concepts in C++20. But for backwards compatibility, we
8 offer a C++17 alternative. This alternative is based on SFINAE. A new
9 function template parameter is introduced, which is necessary to make
10 use of SFINAE. We cannot use substitution failure directly on the
11 class template parameters, as this would lead to a compilation error.
12 On the function level, if substitution fails, the corresponding
13 function is removed. Thus, we can keep SC = double and remove all
14 other possibilities. Since the function now has a new template
15 parameter, it must be explicitly instantiated if this is done for
16 the class as well. The problematic functions, for which only
17 SC = double is supported, are functions that return a Thyra vector.
18 A Thyra vector does not exist for SC = int, for example.
19 TODO: The C++17 compatible code is quite difficult to read.
20 I suggest to remove it rather sooner than later when C++17
21 compatibility can be dropped.
22*/
23#if __cplusplus >= 202002L // >= C++20
24 #include <concepts>
25#else // <= C++17
26 #include <type_traits>
27#endif
28
29#include <MatrixMarket_Tpetra.hpp>
30#include <Teuchos_VerboseObject.hpp>
31#include <Tpetra_MultiVector.hpp>
32#include <Tpetra_Map.hpp>
33#include <Tpetra_MultiVector.hpp>
34#include <Tpetra_Vector.hpp>
35#include <Tpetra_Export.hpp>
36#include <Tpetra_Import.hpp>
37#include <Thyra_DefaultProductVectorSpace.hpp>
38#include <Thyra_TpetraThyraWrappers.hpp>
39
40#include "feddlib/core/FEDDCore.hpp"
41#include "Map.hpp"
42#include "BlockMap.hpp"
43#include "BlockMultiVector.hpp"
44
53
54namespace FEDD {
55// Forward Declaration of BlockMultiVector to avoid circular includes (BlockMultiVector includes MultiVector) and speed up compilation time.
56template <class SC, class LO, class GO, class NO>
58template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
59// template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
60
61class MultiVector {
62
63public:
64
65 typedef MultiVector<SC,LO,GO,NO> MultiVector_Type;
66 typedef Teuchos::RCP<MultiVector_Type> MultiVectorPtr_Type;
67 typedef Teuchos::RCP<const MultiVector_Type> MultiVectorConstPtr_Type;
68
69 typedef BlockMultiVector<SC,LO,GO,NO> BlockMultiVector_Type;
70 typedef Teuchos::RCP<BlockMultiVector_Type> BlockMultiVectorPtr_Type;
71 typedef Teuchos::RCP<const BlockMultiVector_Type> BlockMultiVectorConstPtr_Type;
72
73
74 typedef Teuchos::Comm<int> Comm_Type;
75 typedef Teuchos::RCP<Comm_Type> CommPtr_Type;
76 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
77
78 // -------------
79 typedef Map<LO,GO,NO> Map_Type;
80 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
81 typedef Teuchos::RCP<const Map_Type> MapConstPtr_Type;
82
83 typedef Tpetra::Map<LO,GO,NO> TpetraMap_Type;
84 typedef Teuchos::RCP<TpetraMap_Type> TpetraMapPtr_Type;
85 typedef Teuchos::RCP<const TpetraMap_Type> TpetraMapConstPtr_Type;
86 typedef const TpetraMapConstPtr_Type TpetraMapConstPtrConst_Type;
87
88 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMultiVector_Type;
89 typedef Teuchos::RCP<TpetraMultiVector_Type> TpetraMultiVectorPtr_Type;
90 typedef Teuchos::RCP<const TpetraMultiVector_Type> TpetraMultiVectorConstPtr_Type;
91 typedef const TpetraMultiVectorConstPtr_Type TpetraMultiVectorConstPtrConst_Type;
92
93 typedef Tpetra::Import<LO,GO,NO> TpetraImport_Type;
94 typedef Teuchos::RCP<TpetraImport_Type> TpetraImportPtr_Type;
95
96 typedef Tpetra::Export<LO,GO,NO> TpetraExport_Type;
97 typedef Teuchos::RCP<TpetraExport_Type> TpetraExportPtr_Type;
98
99
100
101 MultiVector();
102
103
107 MultiVector( MapConstPtr_Type map, UN nmbVectors=1 );
108
111 MultiVector( TpetraMultiVectorPtr_Type& TpetraMVPtrIn );
112
115 MultiVector( MultiVectorConstPtr_Type mvIn );
116
119
126 MultiVector_Type& operator= (const MultiVector_Type& rhs) {
127 Tpetra::deep_copy<SC,LO,GO,NO>(*multiVector_,*rhs.getTpetraMultiVector()); // (destination, source)
128 return *this;
129 }
130
132 bool is_null() const;
133
136 MapConstPtr_Type getMap() const;
137
140 MapPtr_Type getMapNonConst();
141
144 TpetraMapConstPtr_Type getMapTpetra() const;
145
152 void replaceGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
153
159 void replaceLocalValue (LO localRow, UN vectorIndex, const SC &value);
160
171 void sumIntoGlobalValue (GO globalRow, UN vectorIndex, const SC &value);
172
173 LO getLocalLength() const;
174
178 Teuchos::ArrayRCP< const SC > getData(UN i) const;
179
183 Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const;
184
186 UN getNumVectors() const;
187
189 void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const;
190
191 TpetraMultiVectorConstPtr_Type getTpetraMultiVector() const;
192
193 TpetraMultiVectorPtr_Type getTpetraMultiVectorNonConst();
194
195#if __cplusplus >= 202002L // >= C++20
196 Teuchos::RCP< Thyra::MultiVectorBase<SC> > getThyraMultiVector( ) requires std::same_as<SC,double>;
197
198 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > getThyraMultiVectorConst( ) const requires std::same_as<SC,double>;
199#else // <= C++17
200 template <typename SCALAR = SC, typename = std::enable_if_t<std::is_same_v<SCALAR,double>>>
201 Teuchos::RCP< Thyra::MultiVectorBase<SCALAR> > getThyraMultiVector( );
202
203 template <typename SCALAR = SC, typename = std::enable_if_t<std::is_same_v<SCALAR,double>>>
204 Teuchos::RCP<const Thyra::MultiVectorBase<SCALAR> > getThyraMultiVectorConst( ) const;
205#endif
206
207 void fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV);
208
209 void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
210
211 void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const;
212
213 void dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots) const;
214
215 // Calculate absolute value of Multivector
216 void abs(MultiVectorConstPtr_Type a);
217 //this = alpha*A + beta*this
218 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta );
219
220 //this = alpha*A + beta*B + gamma*this
221 void update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma);
222
223 // Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
224 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B, const SC &beta);
225
226#if __cplusplus >= 202002L // >= C++20
227 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>;
228#else // <= C++17
229 template <typename SCALAR = SC, typename = std::enable_if_t<std::is_same_v<SCALAR,double>>>
230 void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SCALAR &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const SCALAR &beta);
231#endif
232
233 void putScalar( const SC& alpha );
234
235 void scale( const SC& alpha );
236
237 void importFromVector( MultiVectorConstPtr_Type mvIn, bool reuseImport = false, std::string combineMode = "Insert", std::string type="Forward" );
238
239 void exportFromVector( MultiVectorConstPtr_Type mvIn, bool reuseExport = false, std::string combineMode = "Insert", std::string type="Forward" );
240
241 void writeMM(std::string fileName="mv.mm") const;
242
243 void readMM(std::string fileName) const;
244
245 MultiVectorConstPtr_Type getVector( int i ) const;
246
247 MultiVectorPtr_Type sumColumns() const;
248
249 SC getMax() const;
250
251private:
252
253 TpetraMultiVectorPtr_Type multiVector_;
254 MapConstPtr_Type map_;
255 TpetraImportPtr_Type importer_;
256 TpetraExportPtr_Type exporter_;
257};
258}
259
260#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:126
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