10 #ifndef MUELU_GMRESSOLVER_DEF_HPP
11 #define MUELU_GMRESSOLVER_DEF_HPP
16 #include <Xpetra_MatrixFactory2.hpp>
22 #include "MueLu_Constraint.hpp"
24 #include "MueLu_Utilities.hpp"
28 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
32 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
34 for (
int i = 0; i < k; i++) {
35 SC w1 = c[i] * v[i] - s[i] * v[i + 1];
36 SC w2 = s[i] * v[i] + c[i] * v[i + 1];
42 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
46 finalP = MatrixFactory2::BuildCopy(rcpFromRef(P0));
51 "For now, solving Hessenberg system works only for a single iteration");
68 RCP<Matrix> X = rcp_const_cast<Matrix>(rcpFromRef(P0)), tmpAP, newV;
69 std::vector<RCP<Matrix> > V(nIts_ + 1);
73 T_->fillComplete(P0.getDomainMap(), P0.getRangeMap());
80 tmpAP = MatrixMatrix::Multiply(*A,
false, *X,
false, mmfancy,
true ,
true );
83 V[0] = MatrixFactory2::BuildCopy(T);
88 V[0]->scale(-one / rho);
91 std::vector<SC> h((nIts_ + 1) * (nIts_ + 1));
92 std::vector<SC> c(nIts_ + 1, 0.0);
93 std::vector<SC> s(nIts_ + 1, 0.0);
94 std::vector<SC> g(nIts_ + 1, 0.0);
97 #define I(i, j) ((i) + (j) * (nIts_ + 1)) // column ordering
98 for (
size_t i = 0; i < nIts_; i++) {
100 tmpAP = MatrixMatrix::Multiply(*A,
false, *V[i],
false, mmfancy,
true ,
true );
103 V[i + 1] = MatrixFactory2::BuildCopy(T);
107 for (
size_t j = 0; j <= i; j++) {
111 #ifndef TWO_ARG_MATRIX_ADD
112 newV = Teuchos::null;
113 MatrixMatrix::TwoMatrixAdd(*V[j],
false, -h[
I(j, i)], *V[i + 1],
false, one, newV, mmfancy);
114 newV->fillComplete(V[i + 1]->getDomainMap(), V[i + 1]->getRangeMap());
125 MatrixMatrix::TwoMatrixAdd(*V[j],
false, -h[
I(j, i)], *V[i + 1], one);
144 if (h[
I(i + 1, i)] != zero) {
146 V[i + 1]->scale(one / h[
I(i + 1, i)]);
150 givapp(&c[0], &s[0], &h[
I(0, i)], i);
152 SC nu = sqrt(h[
I(i, i)] * h[
I(i, i)] + h[
I(i + 1, i)] * h[
I(i + 1, i)]);
154 c[i] = h[
I(i, i)] / nu;
155 s[i] = -h[
I(i + 1, i)] / nu;
156 h[
I(i, i)] = c[i] * h[
I(i, i)] - s[i] * h[
I(i + 1, i)];
157 h[
I(i + 1, i)] = zero;
159 givapp(&c[i], &s[i], &g[i], 1);
165 std::vector<SC> y(nIts_);
167 y[0] = g[0] / h[
I(0, 0)];
172 for (
size_t i = 0; i < nIts_; i++) {
173 #ifndef TWO_ARG_MATRIX_ADD
174 newV = Teuchos::null;
175 MatrixMatrix::TwoMatrixAdd(*V[i],
false, y[i], *finalP,
false, one, newV, mmfancy);
176 newV->fillComplete(finalP->getDomainMap(), finalP->getRangeMap());
179 MatrixMatrix::TwoMatrixAdd(*V[i],
false, y[i], *finalP, one);
186 #endif // ifndef MUELU_GMRESSOLVER_DECL_HPP
void givapp(SC *c, SC *s, SC *v, int k) const
static void MyOldScaleMatrix(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< const Scalar > &scalingVector, bool doInverse=true, bool doFillComplete=true, bool doOptimizeStorage=true)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Constraint space information for the potential prolongator.
void swap(RCP< T > &r_ptr)
RCP< const CrsGraph > GetPattern() const
Print even more statistics.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
static Teuchos::ArrayRCP< Scalar > GetMatrixDiagonal_arcp(const Matrix &A)
Extract Matrix Diagonal.
void Iterate(const Matrix &A, const Constraint &C, const Matrix &P0, RCP< Matrix > &P) const
Iterate.
void Apply(const Matrix &P, Matrix &Projected) const
Apply constraint.
Exception throws to report errors in the internal logical of the program.
static Scalar Frobenius(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B)
Frobenius inner product of two matrices.