MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
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>
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>
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>
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 
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
void Build(Level &currentLevel) const
Build an object with this factory.
static Scalar PowerMethod(const Matrix &A, bool scaleByDiag=true, LocalOrdinal niters=10, Magnitude tolerance=1e-2, bool verbose=false, unsigned int seed=123)
Power method.
Timer to be used in factories. Similar to Monitor but with additional timers.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
LocalOrdinal LO
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
static Teuchos::ArrayRCP< Scalar > GetMatrixDiagonal_arcp(const Matrix &A)
Extract Matrix Diagonal.
Scalar SC
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
int GetLevelID() const
Return level number.
Definition: MueLu_Level.cpp:51