MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_SteepestDescentSolver_def.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// MueLu: A package for multigrid based preconditioning
4
//
5
// Copyright 2012 NTESS and the MueLu contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef MUELU_STEEPESTDESCENTSOLVER_DEF_HPP
11
#define MUELU_STEEPESTDESCENTSOLVER_DEF_HPP
12
13
#include <Xpetra_CrsMatrixFactory.hpp>
14
#include <Xpetra_CrsMatrixWrap.hpp>
15
#include <Xpetra_MatrixMatrix.hpp>
16
17
#include "MueLu_Constraint.hpp"
18
#include "
MueLu_Monitor.hpp
"
19
#include "MueLu_Utilities.hpp"
20
21
#include "
MueLu_SteepestDescentSolver_decl.hpp
"
22
23
namespace
MueLu
{
24
25
using
Teuchos::rcp_const_cast;
26
27
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
28
SteepestDescentSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SteepestDescentSolver
(
size_t
Its, SC StepLength)
29
:
nIts_
(Its)
30
,
stepLength_
(StepLength) {}
31
32
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
33
void
SteepestDescentSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Iterate
(
const
Matrix& Aref,
const
Constraint
& C,
const
Matrix& P0, RCP<Matrix>& P)
const
{
34
PrintMonitor
m(*
this
,
"SD iterations"
);
35
36
RCP<const Matrix> A = rcpFromRef(Aref);
37
RCP<Matrix> AP, G;
38
39
Teuchos::FancyOStream& mmfancy = this->
GetOStream
(
Statistics2
);
40
41
RCP<CrsMatrix> Ptmp_ = CrsMatrixFactory::Build(C.
GetPattern
());
42
Ptmp_->fillComplete(P0.getDomainMap(), P0.getRangeMap());
43
RCP<Matrix> Ptmp = rcp(
new
CrsMatrixWrap(Ptmp_));
44
45
// Initial P0 would only be used for multiplication
46
P = rcp_const_cast<Matrix>(rcpFromRef(P0));
47
48
const
auto
rowMap = A->getRowMap();
49
auto
invDiag = Xpetra::VectorFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(rowMap,
true
);
50
A->getLocalDiagCopy(*invDiag);
51
invDiag->reciprocal(*invDiag);
52
53
for
(
size_t
k = 0; k <
nIts_
; k++) {
54
AP = Xpetra::MatrixMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Multiply(*A,
false
, *P,
false
, mmfancy,
true
,
true
);
55
#if 0
56
// gradient = -2 A^T * A * P
57
SC stepLength = 2*
stepLength_
;
58
G = Xpetra::MatrixMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Multiply(*A,
true
, *AP,
false
,
true
,
true
);
59
C.
Apply
(*G, *Ptmp);
60
#else
61
// gradient = - A * P
62
SC stepLength =
stepLength_
;
63
AP->leftScale(*invDiag);
64
C.
Apply
(*AP, *Ptmp);
65
#endif
66
67
RCP<Matrix> newP;
68
Xpetra::MatrixMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TwoMatrixAdd(*Ptmp,
false
, -stepLength, *P,
false
, Teuchos::ScalarTraits<Scalar>::one(), newP, mmfancy);
69
newP->fillComplete(P->getDomainMap(), P->getRangeMap());
70
P = newP;
71
}
72
}
73
}
// namespace MueLu
74
75
#endif
// ifndef MUELU_STEEPESTDESCENTSOLVER_DECL_HPP
MueLu_Monitor.hpp
MueLu_SteepestDescentSolver_decl.hpp
MueLu::Constraint
Constraint space information for the potential prolongator.
Definition
MueLu_Constraint_decl.hpp:69
MueLu::Constraint::GetPattern
RCP< const CrsGraph > GetPattern() const
Definition
MueLu_Constraint_decl.hpp:102
MueLu::Constraint::Apply
void Apply(const Matrix &P, Matrix &Projected) const
Apply constraint.
Definition
MueLu_Constraint_def.hpp:120
MueLu::PrintMonitor
Definition
MueLu_Monitor.hpp:41
MueLu::SteepestDescentSolver::nIts_
size_t nIts_
Number of performed iterations.
Definition
MueLu_SteepestDescentSolver_decl.hpp:58
MueLu::SteepestDescentSolver::Iterate
void Iterate(const Matrix &A, const Constraint &C, const Matrix &P0, RCP< Matrix > &P) const
Iterate.
Definition
MueLu_SteepestDescentSolver_def.hpp:33
MueLu::SteepestDescentSolver::SteepestDescentSolver
SteepestDescentSolver(size_t Its, SC StepLength=Teuchos::ScalarTraits< Scalar >::one())
Definition
MueLu_SteepestDescentSolver_def.hpp:28
MueLu::SteepestDescentSolver::stepLength_
SC stepLength_
Modifier of the step length.
Definition
MueLu_SteepestDescentSolver_decl.hpp:59
MueLu::VerboseObject::GetOStream
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Definition
MueLu_VerboseObject.cpp:72
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:42
MueLu::Statistics2
@ Statistics2
Print even more statistics.
Definition
MueLu_VerbosityLevel.hpp:35
src
Transfers
Energy-Minimization
Solvers
MueLu_SteepestDescentSolver_def.hpp
Generated by
1.17.0