12 #ifndef XPETRA_MATRIX_DEF_HPP
13 #define XPETRA_MATRIX_DEF_HPP
15 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
20 #include "Xpetra_MultiVector.hpp"
26 #include "Xpetra_StridedMap.hpp"
27 #include "Xpetra_StridedMapFactory.hpp"
29 #include <Teuchos_SerialDenseMatrix.hpp>
30 #include <Teuchos_Hashtable.hpp>
34 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
37 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
42 TEUCHOS_TEST_FOR_EXCEPTION(operatorViewTable_.containsKey(viewLabel) ==
true,
Xpetra::Exceptions::RuntimeError,
"Xpetra::Matrix.CreateView(): a view labeled '" + viewLabel +
"' already exist.");
43 RCP<MatrixView> view = rcp(
new MatrixView(rowMap, colMap));
44 operatorViewTable_.put(viewLabel, view);
47 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
49 RCP<const Map> domainMap = Teuchos::null;
50 RCP<const Map> rangeMap = Teuchos::null;
52 const size_t blkSize = 1;
53 std::vector<size_t> stridingInfo(1, blkSize);
54 LocalOrdinal stridedBlockId = -1;
56 if (A->IsView(viewLabel)) {
57 rangeMap = transposeA ? A->getColMap(viewLabel) : A->getRowMap(viewLabel);
58 domainMap = transposeA ? A->getRowMap(viewLabel) : A->getColMap(viewLabel);
61 rangeMap = transposeA ? A->getDomainMap() : A->getRangeMap();
62 domainMap = transposeA ? A->getRangeMap() : A->getDomainMap();
64 if (viewLabel ==
"stridedMaps") {
70 if (B != Teuchos::null) {
73 if (B->IsView(viewLabel)) {
74 domainMap = transposeB ? B->getRowMap(viewLabel) : B->getColMap(viewLabel);
77 domainMap = transposeB ? B->getRangeMap() : B->getDomainMap();
79 if (viewLabel ==
"stridedMaps")
84 if (IsView(viewLabel))
85 RemoveView(viewLabel);
87 CreateView(viewLabel, rangeMap, domainMap);
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
92 int last = out.getOutputToRootOnly();
93 Teuchos::OSTab tab(out);
94 out.setOutputToRootOnly(0);
95 Teuchos::Array<viewLabel_t> viewLabels;
96 Teuchos::Array<RCP<MatrixView>> viewList;
97 operatorViewTable_.arrayify(viewLabels, viewList);
98 out <<
"views associated with this operator" << std::endl;
99 for (
int i = 0; i < viewLabels.size(); ++i)
100 out << viewLabels[i] << std::endl;
101 out.setOutputToRootOnly(last);
104 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 TEUCHOS_TEST_FOR_EXCEPTION(operatorViewTable_.containsKey(viewLabel) ==
false,
Xpetra::Exceptions::RuntimeError,
"Xpetra::Matrix.RemoveView(): view '" + viewLabel +
"' does not exist.");
107 TEUCHOS_TEST_FOR_EXCEPTION(viewLabel == GetDefaultViewLabel(),
Xpetra::Exceptions::RuntimeError,
"Xpetra::Matrix.RemoveView(): view '" + viewLabel +
"' is the default view and cannot be removed.");
108 operatorViewTable_.remove(viewLabel);
111 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
113 TEUCHOS_TEST_FOR_EXCEPTION(operatorViewTable_.containsKey(viewLabel) ==
false,
Xpetra::Exceptions::RuntimeError,
"Xpetra::Matrix.SwitchToView(): view '" + viewLabel +
"' does not exist.");
115 currentViewLabel_ = viewLabel;
119 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
121 return operatorViewTable_.containsKey(viewLabel);
124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
127 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
130 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
133 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 TEUCHOS_TEST_FOR_EXCEPTION(operatorViewTable_.containsKey(viewLabel) ==
false,
Xpetra::Exceptions::RuntimeError,
"Xpetra::Matrix.GetRowMap(): view '" + viewLabel +
"' does not exist.");
139 return operatorViewTable_.get(viewLabel)->GetRowMap();
142 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
145 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
147 TEUCHOS_TEST_FOR_EXCEPTION(operatorViewTable_.containsKey(viewLabel) ==
false,
Xpetra::Exceptions::RuntimeError,
"Xpetra::Matrix.GetColMap(): view '" + viewLabel +
"' does not exist.");
148 return operatorViewTable_.get(viewLabel)->GetColMap();
151 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
153 TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() ==
false,
Exceptions::RuntimeError,
"Xpetra::Matrix::SetFixedBlockSize(): operator is not filled and completed.");
154 std::vector<size_t> stridingInfo;
155 stridingInfo.push_back(Teuchos::as<size_t>(blksize));
156 LocalOrdinal stridedBlockId = -1;
164 this->getDomainMap(),
169 if (IsFixedBlockSizeSet()) RemoveView(
"stridedMaps");
170 CreateView(
"stridedMaps", stridedRangeMap, stridedDomainMap);
173 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 if (IsFixedBlockSizeSet()) {
178 TEUCHOS_TEST_FOR_EXCEPTION(rangeMap == Teuchos::null,
Exceptions::BadCast,
"Xpetra::Matrix::GetFixedBlockSize(): rangeMap is not of type StridedMap");
179 TEUCHOS_TEST_FOR_EXCEPTION(domainMap == Teuchos::null,
Exceptions::BadCast,
"Xpetra::Matrix::GetFixedBlockSize(): domainMap is not of type StridedMap");
180 TEUCHOS_TEST_FOR_EXCEPTION(domainMap->getFixedBlockSize() != rangeMap->getFixedBlockSize(),
Exceptions::RuntimeError,
"Xpetra::Matrix::GetFixedBlockSize(): block size of rangeMap and domainMap are different.");
181 return Teuchos::as<LocalOrdinal>(domainMap->getFixedBlockSize());
187 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
189 return IsView(
"stridedMaps");
192 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
194 operatorViewTable_.get(GetCurrentViewLabel())->SetMaxEigenvalueEstimate(sigma);
197 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
199 return operatorViewTable_.get(GetCurrentViewLabel())->GetMaxEigenvalueEstimate();
204 #define XPETRA_MATRIX_SHORT
205 #endif // XPETRA_MATRIX_DECL_HPP
const viewLabel_t & GetCurrentViewLabel() const
virtual const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
virtual ~Matrix()
Destructor.
void RemoveView(const viewLabel_t viewLabel)
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Exception throws to report errors in the internal logical of the program.
const viewLabel_t & GetDefaultViewLabel() const
Exception indicating invalid cast attempted.
void SetFixedBlockSize(LocalOrdinal blksize, GlobalOrdinal offset=0)
bool IsView(const viewLabel_t viewLabel) const
void CreateView(viewLabel_t viewLabel, const RCP< const Map > &rowMap, const RCP< const Map > &colMap)
void PrintViews(Teuchos::FancyOStream &out) const
Print all of the views associated with the Matrix.
LocalOrdinal GetFixedBlockSize() const
virtual Scalar GetMaxEigenvalueEstimate() const
virtual void SetMaxEigenvalueEstimate(Scalar const &sigma)
bool IsFixedBlockSizeSet() const
Returns true, if SetFixedBlockSize has been called before.
const viewLabel_t SwitchToView(const viewLabel_t viewLabel)
static RCP< Xpetra::StridedMap< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
const viewLabel_t SwitchToDefaultView()
Class that stores a strided map.