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 <Teuchos_VerboseObject.hpp>
5#include <MatrixMarket_Tpetra.hpp>
6#include <TpetraExt_MatrixMatrix.hpp>
7
8
9#include <Tpetra_CrsMatrix.hpp>
10//#include <Tpetra_MatrixMatrix.hpp>
11#include <MatrixMarket_Tpetra.hpp>
12
13#include "feddlib/core/FEDDCore.hpp"
14#include "Map.hpp"
15#include "MultiVector.hpp"
16#include "BlockMultiVector.hpp"
17
18
27
28namespace FEDD {
29template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
30class Matrix {
31
32public:
33
34 typedef Matrix<SC,LO,GO,NO> Matrix_Type;
35 typedef Teuchos::RCP<Matrix_Type> MatrixPtr_Type;
36
37 typedef Map<LO,GO,NO> Map_Type;
38 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
39 typedef Teuchos::RCP<const Map_Type> MapConstPtr_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 MultiVector<SC,LO,GO,NO> BlockMultiVector_Type;
46 typedef Teuchos::RCP<BlockMultiVector_Type> BlockMultiVectorPtr_Type;
47// typedef Teuchos::RCP<const MultiVector_Type> BlockMultiVectorConstPtr_Type;
48
49 typedef Teuchos::Comm<int> Comm_Type;
50 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
51
52 typedef Tpetra::Import<LO,GO,NO> TpetraImport_Type;
53 typedef Teuchos::RCP<TpetraImport_Type> TpetraImportPtr_Type;
54
55 typedef Tpetra::Export<LO,GO,NO> TpetraExport_Type;
56 typedef Teuchos::RCP<TpetraExport_Type> TpetraExportPtr_Type;
57
58 // -----------------------
59 typedef Tpetra::Map<LO,GO,NO> TpetraMap_Type;
60 typedef Teuchos::RCP<TpetraMap_Type> TpetraMapPtr_Type;
61 typedef Teuchos::RCP<const TpetraMap_Type> TpetraMapConstPtr_Type;
62 typedef const TpetraMapConstPtr_Type TpetraMapConstPtrConst_Type;
63
64 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraMatrix_Type;
65 typedef Teuchos::RCP<TpetraMatrix_Type> TpetraMatrixPtr_Type;
66 typedef Teuchos::RCP<const TpetraMatrix_Type> TpetraMatrixConstPtr_Type;
67 typedef const Teuchos::RCP<TpetraMatrixConstPtr_Type> TpetraMatrixConstPtrConst_Type;
68
69 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMV_Type;
70 typedef Teuchos::RCP<TpetraMV_Type> TpetraMVPtr_Type;
71
72 Matrix();
73
74 Matrix( TpetraMatrixPtr_Type& tpetraMatPtrIn );
75
76 Matrix( MapConstPtr_Type map , LO numEntries);
77
78 Matrix( MatrixPtr_Type matrixIn );
79
80 ~Matrix();
81
82 Matrix& operator+=(const Matrix& matIn);
83
88 void insertGlobalValues (GO globalRow, const Teuchos::ArrayView< const GO > &cols, const Teuchos::ArrayView< const SC > &vals);
89
94 LO getNodeNumRows() const;
95
99 MapConstPtr_Type getMap(std::string map_string="");
100
104 MapConstPtr_Type getMap(std::string map_string="") const;
105
109 TpetraMapConstPtr_Type getMapTpetra(std::string map_string="");
110
114 Teuchos::RCP<const Thyra::LinearOpBase<SC> > getThyraLinOp() const;
115
119 Teuchos::RCP<Thyra::LinearOpBase<SC> > getThyraLinOpNonConst();
120
124 void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME);
125
130
135
139 void fillComplete(MapConstPtr_Type domainMap, MapConstPtr_Type rangeMap);
140
144 bool isLocallyIndexed();
145
150// void fillComplete(with maps);
151
152// ThyraLinOpPtr_Type getThyraLinOp();
153
157 void getGlobalRowView(GO globalRow, Teuchos::ArrayView< const GO > &indices, Teuchos::ArrayView< const SC > &values) const;
158
162 void getLocalRowView(LO localRow, Teuchos::ArrayView< const LO > &indices, Teuchos::ArrayView< const SC > &values) const;
163
167 void replaceGlobalValues(GO globalRow, const Teuchos::ArrayView< const GO > &indices, const Teuchos::ArrayView< const SC > &values);
168
172 void replaceLocalValues(LO localRow, const Teuchos::ArrayView< const LO > &indices, const Teuchos::ArrayView< const SC > &values);
173
177 TpetraMatrixConstPtr_Type getTpetraMatrix() const;
178
182 void Multiply( const MatrixPtr_Type &tpA, bool transposeA , const MatrixPtr_Type &tpB, bool transposeB, bool fillComplete=true);
183
187 void apply(const MultiVector_Type& X,
188 MultiVector_Type& Y,
189 Teuchos::ETransp mode = Teuchos::NO_TRANS,
190 SC alpha = Teuchos::ScalarTraits<SC>::one(),
191 SC beta = Teuchos::ScalarTraits<SC>::zero() ) const;
192
196 void scale(const SC& alpha);
197
201 void writeMM(std::string fileName="matrix.mm") const;
202
206 void addMatrix(SC alpha, const MatrixPtr_Type &B, SC beta);// --------!
207
211 void toMV( MultiVectorPtr_Type& mv );
212
217
218 void insertLocalValues (LO localRow, const Teuchos::ArrayView< const LO > &cols, const Teuchos::ArrayView< const SC > &vals);
222
223 void importFromVector( MatrixPtr_Type mvIn, bool reuseImport = false, std::string combineMode = "Insert", std::string type="Forward" );
224
228 void exportFromVector( MatrixPtr_Type mvIn, bool reuseExport = false, std::string combineMode = "Insert", std::string type="Forward" );
229
233 MatrixPtr_Type buildDiagonalInverse( std::string diagonalType);
234
235
236private:
237
238 TpetraMatrixPtr_Type matrix_;
239 TpetraImportPtr_Type importer_;
240 TpetraExportPtr_Type exporter_;
241};
242}
243
244#endif
Definition Map_decl.hpp:30
void fillComplete(MapConstPtr_Type domainMap, MapConstPtr_Type rangeMap)
Filling of Matrix based on specific domainmap (column map) and rangeMap (rowmap).
Definition Matrix_def.hpp:200
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:316
MatrixPtr_Type buildDiagonalInverse(std::string diagonalType)
Definition Matrix_def.hpp:228
Teuchos::RCP< const Thyra::LinearOpBase< SC > > getThyraLinOp() const
i.e. for NOX
Definition Matrix_def.hpp:153
LO getNodeNumRows() const
Returns the local number of rows.
Definition Matrix_def.hpp:80
void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME)
printing matrix
Definition Matrix_def.hpp:183
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:336
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:331
void exportFromVector(MatrixPtr_Type mvIn, bool reuseExport=false, std::string combineMode="Insert", std::string type="Forward")
Definition Matrix_def.hpp:461
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:301
void toMV(MultiVectorPtr_Type &mv)
Turning Matrix into MultiVector Format.
Definition Matrix_def.hpp:387
void scale(const SC &alpha)
Scaling this with constant alpha.
Definition Matrix_def.hpp:358
TpetraMapConstPtr_Type getMapTpetra(std::string map_string="")
Return map in Tpetra Format of type " ".
Definition Matrix_def.hpp:133
MapConstPtr_Type getMap(std::string map_string="") const
Returns map of type " ". i.e. row or column map.
Definition Matrix_def.hpp:109
MapConstPtr_Type getMap(std::string map_string="")
Returns map of type " ". i.e. row or column map.
Definition Matrix_def.hpp:86
Teuchos::RCP< Thyra::LinearOpBase< SC > > getThyraLinOpNonConst()
i.e. for NOX
Definition Matrix_def.hpp:168
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:73
bool isFillComplete()
Check if matrix is already filled complete.
Definition Matrix_def.hpp:205
void writeMM(std::string fileName="matrix.mm") const
Writing Matrix in file.
Definition Matrix_def.hpp:365
void importFromVector(MatrixPtr_Type mvIn, bool reuseImport=false, std::string combineMode="Insert", std::string type="Forward")
Definition Matrix_def.hpp:422
void resumeFill()
Resuming filling process. But only limited options i.e. scaling remain.
Definition Matrix_def.hpp:190
void addMatrix(SC alpha, const MatrixPtr_Type &B, SC beta)
B = alpha*this + beta*B.
Definition Matrix_def.hpp:376
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:346
void fillComplete()
after inserting global values into matrix. After this step the column map is fixed....
Definition Matrix_def.hpp:195
void Multiply(const MatrixPtr_Type &tpA, bool transposeA, const MatrixPtr_Type &tpB, bool transposeB, bool fillComplete=true)
Definition Matrix_def.hpp:215
LO getGlobalMaxNumRowEntries() const
Maximum number of entries in any row of the matrix, over all processes.
Definition Matrix_def.hpp:409
TpetraMatrixConstPtr_Type getTpetraMatrix() const
Return matrix in Tpetra Format.
Definition Matrix_def.hpp:341
Definition MultiVector_decl.hpp:61
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36