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
// ***********************************************************************
4
//
5
// MueLu: A package for multigrid based preconditioning
6
// Copyright 2012 Sandia Corporation
7
//
8
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9
// the U.S. Government retains certain rights in this software.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact
39
// Jonathan Hu (jhu@sandia.gov)
40
// Andrey Prokopenko (aprokop@sandia.gov)
41
// Ray Tuminaro (rstumin@sandia.gov)
42
//
43
// ***********************************************************************
44
//
45
// @HEADER
46
#ifndef MUELU_STEEPESTDESCENTSOLVER_DEF_HPP
47
#define MUELU_STEEPESTDESCENTSOLVER_DEF_HPP
48
49
#include <Xpetra_CrsMatrixFactory.hpp>
50
#include <Xpetra_CrsMatrixWrap.hpp>
51
#include <Xpetra_MatrixMatrix.hpp>
52
53
#include "MueLu_Constraint.hpp"
54
#include "
MueLu_Monitor.hpp
"
55
#include "MueLu_Utilities.hpp"
56
57
#include "
MueLu_SteepestDescentSolver_decl.hpp
"
58
59
namespace
MueLu
{
60
61
using
Teuchos::rcp_const_cast;
62
63
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
64
SteepestDescentSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SteepestDescentSolver
(
size_t
Its, SC StepLength)
65
:
nIts_
(Its),
stepLength_
(StepLength)
66
{ }
67
68
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
69
void
SteepestDescentSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Iterate
(
const
Matrix& Aref,
const
Constraint
& C,
const
Matrix& P0, RCP<Matrix>& P)
const
{
70
PrintMonitor
m(*
this
,
"SD iterations"
);
71
72
RCP<const Matrix> A = rcpFromRef(Aref);
73
RCP<Matrix> AP, G;
74
75
Teuchos::FancyOStream& mmfancy = this->
GetOStream
(
Statistics2
);
76
77
Teuchos::ArrayRCP<const SC> D =
Utilities::GetMatrixDiagonal_arcp
(*A);
78
79
RCP<CrsMatrix> Ptmp_ = CrsMatrixFactory::Build(C.
GetPattern
());
80
Ptmp_->fillComplete(P0.getDomainMap(), P0.getRangeMap());
81
RCP<Matrix> Ptmp = rcp(
new
CrsMatrixWrap(Ptmp_));
82
83
// Initial P0 would only be used for multiplication
84
P = rcp_const_cast<Matrix>(rcpFromRef(P0));
85
86
for
(
size_t
k = 0; k <
nIts_
; k++) {
87
AP = Xpetra::MatrixMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Multiply(*A,
false
, *P,
false
, mmfancy,
true
,
true
);
88
#if 0
89
// gradient = -2 A^T * A * P
90
SC stepLength = 2*
stepLength_
;
91
G = Xpetra::MatrixMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Multiply(*A,
true
, *AP,
false
,
true
,
true
);
92
C.
Apply
(*G, *Ptmp);
93
#else
94
// gradient = - A * P
95
SC stepLength =
stepLength_
;
96
Utilities::MyOldScaleMatrix
(*AP, D,
true
,
true
,
false
);
97
C.
Apply
(*AP, *Ptmp);
98
#endif
99
100
RCP<Matrix> newP;
101
Xpetra::MatrixMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TwoMatrixAdd(*Ptmp,
false
, -stepLength, *P,
false
, Teuchos::ScalarTraits<Scalar>::one(), newP, mmfancy);
102
newP->fillComplete(P->getDomainMap(), P->getRangeMap() );
103
P = newP;
104
}
105
}
106
}
107
108
#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:105
MueLu::Constraint::GetPattern
RCP< const CrsGraph > GetPattern() const
Definition
MueLu_Constraint_decl.hpp:135
MueLu::Constraint::Apply
void Apply(const Matrix &P, Matrix &Projected) const
Apply constraint.
Definition
MueLu_Constraint_def.hpp:137
MueLu::PrintMonitor
Definition
MueLu_Monitor.hpp:78
MueLu::SteepestDescentSolver::nIts_
size_t nIts_
Number of performed iterations.
Definition
MueLu_SteepestDescentSolver_decl.hpp:96
MueLu::SteepestDescentSolver::Iterate
void Iterate(const Matrix &A, const Constraint &C, const Matrix &P0, RCP< Matrix > &P) const
Iterate.
Definition
MueLu_SteepestDescentSolver_def.hpp:69
MueLu::SteepestDescentSolver::SteepestDescentSolver
SteepestDescentSolver(size_t Its, SC StepLength=Teuchos::ScalarTraits< Scalar >::one())
Definition
MueLu_SteepestDescentSolver_def.hpp:64
MueLu::SteepestDescentSolver::stepLength_
SC stepLength_
Modifier of the step length.
Definition
MueLu_SteepestDescentSolver_decl.hpp:97
MueLu::UtilitiesBase< Scalar, DefaultLocalOrdinal, DefaultGlobalOrdinal, DefaultNode >::GetMatrixDiagonal_arcp
static Teuchos::ArrayRCP< Scalar > GetMatrixDiagonal_arcp(const Matrix &A)
Definition
MueLu_UtilitiesBase_def.hpp:178
MueLu::Utilities::MyOldScaleMatrix
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)
Definition
MueLu_Utilities_def.hpp:423
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:107
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:78
MueLu::Statistics2
@ Statistics2
Print even more statistics.
Definition
MueLu_VerbosityLevel.hpp:72
src
Transfers
Energy-Minimization
Solvers
MueLu_SteepestDescentSolver_def.hpp
Generated by
1.17.0