Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
Matrix_decl.hpp
1#ifndef MATRIX_DECL_hpp
2#define MATRIX_DECL_hpp
3
4#include "feddlib/core/FEDDCore.hpp"
5#include "feddlib/core/General/DefaultTypeDefs.hpp"
6
7#include "Map.hpp"
8#include "MultiVector.hpp"
9#include "BlockMultiVector.hpp"
10
11#include <Xpetra_MatrixFactory.hpp>
12#include <Xpetra_ThyraUtils.hpp>
13#include <Teuchos_VerboseObject.hpp>
14#include <Xpetra_MatrixMatrix.hpp>
15#include <MatrixMarket_Tpetra.hpp>
16
17#include <Tpetra_CrsMatrix.hpp>
18//#include <Tpetra_MatrixMatrix.hpp>
19#include <MatrixMarket_Tpetra.hpp>
20
29
30namespace FEDD {
31template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
32class Matrix {
33
34public:
35
36 typedef Matrix<SC,LO,GO,NO> Matrix_Type;
37 typedef Teuchos::RCP<Matrix_Type> MatrixPtr_Type;
38
39 /*typedef Xpetra::Matrix<SC,LO,GO,NO> XpetraMatrix_Type;
40 typedef Teuchos::RCP<XpetraMatrix_Type> XpetraMatrixPtr_Type;
41 typedef Teuchos::RCP<const XpetraMatrix_Type> XpetraMatrixConstPtr_Type;
42 typedef const Teuchos::RCP<XpetraMatrixConstPtr_Type> XpetraMatrixConstPtrConst_Type;
43
44 typedef Xpetra::MultiVector<SC,LO,GO,NO> XpetraMV_Type;
45 typedef Teuchos::RCP<XpetraMV_Type> XpetraMVPtr_Type;*/
46
47 typedef Map<LO,GO,NO> Map_Type;
48 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
49 typedef Teuchos::RCP<const Map_Type> MapConstPtr_Type;
50
51 typedef MultiVector<SC,LO,GO,NO> MultiVector_Type;
52 typedef Teuchos::RCP<MultiVector_Type> MultiVectorPtr_Type;
53 typedef Teuchos::RCP<const MultiVector_Type> MultiVectorConstPtr_Type;
54
55 typedef MultiVector<SC,LO,GO,NO> BlockMultiVector_Type;
56 typedef Teuchos::RCP<BlockMultiVector_Type> BlockMultiVectorPtr_Type;
57// typedef Teuchos::RCP<const MultiVector_Type> BlockMultiVectorConstPtr_Type;
58
59 typedef Teuchos::Comm<int> Comm_Type;
60 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
61
62 typedef Tpetra::Import<LO,GO,NO> TpetraImport_Type;
63 typedef Teuchos::RCP<TpetraImport_Type> TpetraImportPtr_Type;
64
65 typedef Tpetra::Export<LO,GO,NO> TpetraExport_Type;
66 typedef Teuchos::RCP<TpetraExport_Type> TpetraExportPtr_Type;
67
68
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::CrsMatrix<SC,LO,GO,NO> TpetraMatrix_Type;
76 typedef Teuchos::RCP<TpetraMatrix_Type> TpetraMatrixPtr_Type;
77 typedef Teuchos::RCP<const TpetraMatrix_Type> TpetraMatrixConstPtr_Type;
78 typedef const Teuchos::RCP<TpetraMatrixConstPtr_Type> TpetraMatrixConstPtrConst_Type;
79
80 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMV_Type;
81 typedef Teuchos::RCP<TpetraMV_Type> TpetraMVPtr_Type;
82
83 Matrix();
84
85 Matrix( TpetraMatrixPtr_Type& tpetraMatPtrIn );
86
87 Matrix( MapConstPtr_Type map , LO numEntries);
88
89 Matrix( MatrixPtr_Type matrixIn );
90
91 ~Matrix();
92
93 Matrix& operator+=(const Matrix& matIn);
94
99 void insertGlobalValues (GO globalRow, const Teuchos::ArrayView< const GO > &cols, const Teuchos::ArrayView< const SC > &vals);
100
105 LO getNodeNumRows() const;
106
110 MapConstPtr_Type getMap(std::string map_string="");
111
115 MapConstPtr_Type getMap(std::string map_string="") const;
116
120 TpetraMapConstPtr_Type getMapTpetra(std::string map_string="");
121
125 Teuchos::RCP<const Thyra::LinearOpBase<SC> > getThyraLinOp() const;
126
130 Teuchos::RCP<Thyra::LinearOpBase<SC> > getThyraLinOpNonConst();
131
135 void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME);
136
141
146
150 void fillComplete(MapConstPtr_Type domainMap, MapConstPtr_Type rangeMap);
151
155 bool isLocallyIndexed();
156
161// void fillComplete(with maps);
162
163// ThyraLinOpPtr_Type getThyraLinOp();
164
168 void getGlobalRowView(GO globalRow, Teuchos::ArrayView< const GO > &indices, Teuchos::ArrayView< const SC > &values) const;
169
173 void getLocalRowView(LO localRow, Teuchos::ArrayView< const LO > &indices, Teuchos::ArrayView< const SC > &values) const;
174
178 void replaceGlobalValues(GO globalRow, const Teuchos::ArrayView< const GO > &indices, const Teuchos::ArrayView< const SC > &values);
179
183 void replaceLocalValues(LO localRow, const Teuchos::ArrayView< const LO > &indices, const Teuchos::ArrayView< const SC > &values);
184
188 TpetraMatrixConstPtr_Type getTpetraMatrix() const;
189
193 void apply(const MultiVector_Type& X,
194 MultiVector_Type& Y,
195 Teuchos::ETransp mode = Teuchos::NO_TRANS,
196 SC alpha = Teuchos::ScalarTraits<SC>::one(),
197 SC beta = Teuchos::ScalarTraits<SC>::zero() ) const;
198
202 void scale(const SC& alpha);
203
207 void writeMM(std::string fileName="matrix.mm") const;
208
212 void addMatrix(SC alpha, const MatrixPtr_Type &B, SC beta);// --------!
213
217 void toMV( MultiVectorPtr_Type& mv );
218
223
224 void insertLocalValues (LO localRow, const Teuchos::ArrayView< const LO > &cols, const Teuchos::ArrayView< const SC > &vals);
225 /* !
226 Matrix Analogue to MultiVector Import. Based on Row Map of Matrix mvIn.
227 */
228
229 void importFromVector( MatrixPtr_Type mvIn, bool reuseImport = false, std::string combineMode = "Insert", std::string type="Forward" );
230
231 /* !
232 Matrix Analogue to MultiVector Export. Based on Row Map of Matrix mvIn.
233 */
234 void exportFromVector( MatrixPtr_Type mvIn, bool reuseExport = false, std::string combineMode = "Insert", std::string type="Forward" );
235
236
237private:
238
239 TpetraMatrixPtr_Type matrix_;
240 TpetraImportPtr_Type importer_;
241 TpetraExportPtr_Type exporter_;
242};
243}
244
245#endif
Definition Map_decl.hpp:36
void fillComplete(MapConstPtr_Type domainMap, MapConstPtr_Type rangeMap)
Filling of Matrix based on specific domainmap (column map) and rangeMap (rowmap).
Definition Matrix_def.hpp:205
void getLocalRowView(LO localRow, Teuchos::ArrayView< const LO > &indices, Teuchos::ArrayView< const SC > &values) const
Extracting single rows of Matrix with local row ID. Indices returns local indices of entries stored i...
Definition Matrix_def.hpp:240
Teuchos::RCP< const Thyra::LinearOpBase< SC > > getThyraLinOp() const
i.e. for NOX
Definition Matrix_def.hpp:154
LO getNodeNumRows() const
Returns the local number of rows.
Definition Matrix_def.hpp:81
void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME)
printing matrix
Definition Matrix_def.hpp:188
void replaceLocalValues(LO localRow, const Teuchos::ArrayView< const LO > &indices, const Teuchos::ArrayView< const SC > &values)
Replacing single rows of Matrix with local row ID. Indices returns local indices of entries stored in...
Definition Matrix_def.hpp:260
void replaceGlobalValues(GO globalRow, const Teuchos::ArrayView< const GO > &indices, const Teuchos::ArrayView< const SC > &values)
Replacing single rows of Matrix with global row ID. Indices returns global indices of entries stored ...
Definition Matrix_def.hpp:255
void getGlobalRowView(GO globalRow, Teuchos::ArrayView< const GO > &indices, Teuchos::ArrayView< const SC > &values) const
Extracting single rows of Matrix with global row ID. Indices returns global indices of entries stored...
Definition Matrix_def.hpp:225
void toMV(MultiVectorPtr_Type &mv)
Turning Matrix into MultiVector Format.
Definition Matrix_def.hpp:321
void scale(const SC &alpha)
Scaling this with constant alpha.
Definition Matrix_def.hpp:282
TpetraMapConstPtr_Type getMapTpetra(std::string map_string="")
Return map in Xpetra Format of type " ".
Definition Matrix_def.hpp:134
MapConstPtr_Type getMap(std::string map_string="") const
Returns map of type " ". i.e. row or column map.
Definition Matrix_def.hpp:110
MapConstPtr_Type getMap(std::string map_string="")
Returns map of type " ". i.e. row or column map.
Definition Matrix_def.hpp:87
Teuchos::RCP< Thyra::LinearOpBase< SC > > getThyraLinOpNonConst()
i.e. for NOX
Definition Matrix_def.hpp:172
void insertGlobalValues(GO globalRow, const Teuchos::ArrayView< const GO > &cols, const Teuchos::ArrayView< const SC > &vals)
Intertion of values in global row 'globalRow'. Matrix is distributed nodewise. If values are added to...
Definition Matrix_def.hpp:74
bool isFillComplete()
Check if matrix is already filled complete.
Definition Matrix_def.hpp:210
void writeMM(std::string fileName="matrix.mm") const
Writing Matrix in file.
Definition Matrix_def.hpp:289
void resumeFill()
Resuming filling process. But only limited options i.e. scaling remain.
Definition Matrix_def.hpp:195
void addMatrix(SC alpha, const MatrixPtr_Type &B, SC beta)
B = alpha*this + beta*B.
Definition Matrix_def.hpp:306
void apply(const MultiVector_Type &X, MultiVector_Type &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const
Matrix Vector Operation. Applying MultiVector X to this. Y = alpha * (this)^mode * X + beta * Y....
Definition Matrix_def.hpp:270
void fillComplete()
after inserting global values into matrix. After this step the column map is fixed....
Definition Matrix_def.hpp:200
LO getGlobalMaxNumRowEntries() const
Maximum number of entries in any row of the matrix, over all processes.
Definition Matrix_def.hpp:343
TpetraMatrixConstPtr_Type getTpetraMatrix() const
Return matrix in Xpetra Format of type " ".
Definition Matrix_def.hpp:265
Definition MultiVector_decl.hpp:36
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5