MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_NullspacePresmoothFactory_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_NULLSPACEPRESMOOTHFACTORY_DEF_HPP
11
#define MUELU_NULLSPACEPRESMOOTHFACTORY_DEF_HPP
12
13
#include <Xpetra_Matrix.hpp>
14
#include <Xpetra_MultiVector.hpp>
15
#include <Xpetra_MultiVectorFactory.hpp>
16
17
#include "
MueLu_NullspacePresmoothFactory_decl.hpp
"
18
#include "MueLu_Utilities.hpp"
19
20
#include "
MueLu_Monitor.hpp
"
21
22
namespace
MueLu
{
23
24
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
25
RCP<const ParameterList>
NullspacePresmoothFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::GetValidParameterList
()
const
{
26
RCP<ParameterList> validParamList = rcp(
new
ParameterList());
27
28
validParamList->set<RCP<const FactoryBase> >(
"A"
, Teuchos::null,
"Generating factory for A"
);
29
validParamList->set<RCP<const FactoryBase> >(
"Nullspace"
, Teuchos::null,
"Generating factory for the nonsmoothed nullspace"
);
30
31
return
validParamList;
32
}
33
34
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
35
void
NullspacePresmoothFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput
(
Level
¤tLevel)
const
{
36
Input
(currentLevel,
"Nullspace"
);
37
38
if
(currentLevel.
GetLevelID
() == 0)
39
Input
(currentLevel,
"A"
);
40
}
41
42
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
43
void
NullspacePresmoothFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build
(
Level
¤tLevel)
const
{
44
FactoryMonitor
m(*
this
,
"Nullspace presmooth factory"
, currentLevel);
45
46
RCP<MultiVector> newB;
47
if
(currentLevel.
GetLevelID
() == 0) {
48
RCP<Matrix> A =
Get<RCP<Matrix>
>(currentLevel,
"A"
);
49
RCP<MultiVector> B =
Get<RCP<MultiVector>
>(currentLevel,
"Nullspace"
);
50
newB = MultiVectorFactory::Build(B->getMap(), B->getNumVectors());
51
52
Teuchos::ArrayRCP<SC> D =
Utilities::GetMatrixDiagonal_arcp
(*A);
53
54
SC damping = 4. / 3;
55
damping /=
Utilities::PowerMethod
(*A,
true
, (LO)10, 1e-4);
56
57
A->apply(*B, *newB, Teuchos::NO_TRANS);
58
59
size_t
numVec = newB->getNumVectors();
60
LO numElements = newB->getLocalLength();
61
for
(
size_t
j = 0; j < numVec; j++) {
62
Teuchos::ArrayRCP<const SC> Bj = B->getData(j);
63
Teuchos::ArrayRCP<SC> newBj = newB->getDataNonConst(j);
64
65
for
(LO i = 0; i < numElements; i++)
66
newBj[i] = Bj[i] - damping * newBj[i] / D[i];
67
}
68
}
else
{
69
newB =
Get<RCP<MultiVector>
>(currentLevel,
"Nullspace"
);
70
}
71
72
// provide "Nullspace" variable on current level
73
Set
(currentLevel,
"Nullspace"
, newB);
74
75
}
// Build
76
77
}
// namespace MueLu
78
79
#endif
// MUELU_NULLSPACEPRESMOOTHFACTORY_DEF_HPP
MueLu_Monitor.hpp
MueLu_NullspacePresmoothFactory_decl.hpp
MueLu::Factory::Input
void Input(Level &level, const std::string &varName) const
Definition
MueLu_Factory.cpp:72
MueLu::Factory::Get
T Get(Level &level, const std::string &varName) const
Definition
MueLu_Factory.hpp:69
MueLu::Factory::Set
void Set(Level &level, const std::string &varName, const T &data) const
Definition
MueLu_Factory.hpp:80
MueLu::FactoryMonitor
Timer to be used in factories. Similar to Monitor but with additional timers.
Definition
MueLu_Monitor.hpp:165
MueLu::Level
Class that holds all level-specific information.
Definition
MueLu_Level.hpp:63
MueLu::Level::GetLevelID
int GetLevelID() const
Return level number.
Definition
MueLu_Level.cpp:51
MueLu::NullspacePresmoothFactory::DeclareInput
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Definition
MueLu_NullspacePresmoothFactory_def.hpp:35
MueLu::NullspacePresmoothFactory::Build
void Build(Level ¤tLevel) const
Build an object with this factory.
Definition
MueLu_NullspacePresmoothFactory_def.hpp:43
MueLu::NullspacePresmoothFactory::GetValidParameterList
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Definition
MueLu_NullspacePresmoothFactory_def.hpp:25
MueLu::UtilitiesBase< Scalar, DefaultLocalOrdinal, DefaultGlobalOrdinal, DefaultNode >::GetMatrixDiagonal_arcp
static Teuchos::ArrayRCP< Scalar > GetMatrixDiagonal_arcp(const Matrix &A)
Definition
MueLu_UtilitiesBase_def.hpp:179
MueLu::UtilitiesBase< Scalar, DefaultLocalOrdinal, DefaultGlobalOrdinal, DefaultNode >::PowerMethod
static Scalar PowerMethod(const Matrix &A, bool scaleByDiag=true, DefaultLocalOrdinal niters=10, Magnitude tolerance=1e-2, bool verbose=false, unsigned int seed=123)
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:42
src
Transfers
Energy-Minimization
MueLu_NullspacePresmoothFactory_def.hpp
Generated by
1.17.0