MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_ScaledNullspaceFactory_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_SCALEDNULLSPACEFACTORY_DEF_HPP
11 #define MUELU_SCALEDNULLSPACEFACTORY_DEF_HPP
12 
13 #include <Xpetra_Matrix.hpp>
14 #include <Xpetra_MatrixUtils.hpp>
15 #include <Xpetra_MultiVectorFactory.hpp>
16 #include <Xpetra_BlockedMultiVector.hpp>
17 #include <Xpetra_VectorFactory.hpp>
18 
20 #include "MueLu_Level.hpp"
21 #include "MueLu_Monitor.hpp"
22 
23 namespace MueLu {
24 
25 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
27  RCP<ParameterList> validParamList = rcp(new ParameterList());
28  validParamList->set<std::string>("Fine level nullspace", "Nullspace", "Variable name which is used to store null space multi vector on the finest level (default=\"Nullspace\").");
29 
30  validParamList->set<RCP<const FactoryBase> >("A", Teuchos::null, "Generating factory of the fine level matrix (only needed if default null space is generated)");
31  validParamList->set<RCP<const FactoryBase> >("Nullspace", Teuchos::null, "Generating factory of the fine level null space");
32 
33  return validParamList;
34 }
35 
36 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
38  // Scaled Nullspace always needs A & a Nullspace from somewhere
39  Input(currentLevel, "A");
40  Input(currentLevel, "Nullspace");
41 }
42 
43 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
45  FactoryMonitor m(*this, "Build", currentLevel);
46 
47  RCP<MultiVector> nullspace, tentativeNullspace;
48 
49  // TEUCHOS_TEST_FOR_EXCEPTION(currentLevel.GetLevelID() != 0, Exceptions::RuntimeError, "MueLu::ScaledNullspaceFactory::Build(): ScaledNullspaceFactory can be used for finest level (LevelID == 0) only.");
50 
51  if (currentLevel.GetLevelID() == 0) {
52  if (currentLevel.IsAvailable("Nullspace", NoFactory::get())) {
53  // When a fine nullspace have already been defined by user using Set("Nullspace", ...) or
54  // Set("Nullspace1", ...), we use it.
55  tentativeNullspace = currentLevel.Get<RCP<MultiVector> >("Nullspace", NoFactory::get());
56  } else {
57  // A User "Nullspace" (nspName) is not available (use factory)
58  tentativeNullspace = currentLevel.Get<RCP<MultiVector> >("Nullspace", GetFactory("Nullspace").get());
59 
60  } // end if "Nullspace" not available
61  } else {
62  tentativeNullspace = currentLevel.Get<RCP<MultiVector> >("Nullspace", GetFactory("Nullspace").get());
63  }
64 
65  // Scale!
66  RCP<Matrix> A = Get<RCP<Matrix> >(currentLevel, "A");
67 
68  // determine numPDEs
69  LocalOrdinal numPDEs = 1;
70  if (A->IsView("stridedMaps") == true) {
71  Xpetra::viewLabel_t oldView = A->SwitchToView("stridedMaps"); // note: "stridedMaps are always non-overlapping (correspond to range and domain maps!)
72  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap()) == Teuchos::null, Exceptions::BadCast, "MueLu::ScaledNullspaceFactory::Build: cast to strided row map failed.");
73  numPDEs = Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap())->getFixedBlockSize();
74  oldView = A->SwitchToView(oldView);
75  }
76 
77  GetOStream(Runtime1) << "ScaledNullspaceFactory: Generating scaled nullspace, blocksize = " << tentativeNullspace->getNumVectors() << std::endl;
78  nullspace = MultiVectorFactory::Build(tentativeNullspace->getMap(), tentativeNullspace->getNumVectors());
79  *nullspace = *tentativeNullspace; // Copy the tentative nullspace
80  RCP<MultiVector> blockDiagonal = MultiVectorFactory::Build(A->getDomainMap(), numPDEs);
81 
84 
85  // provide "Scaled Nullspace" variable on current level (used by TentativePFactory)
86  Set(currentLevel, "Scaled Nullspace", nullspace);
87 
88 } // Build
89 
90 } // namespace MueLu
91 
92 #endif // MUELU_SCALEDNULLSPACEFACTORY_DEF_HPP
Exception indicating invalid cast attempted.
void Build(Level &currentLevel) const
Build an object with this factory.
MueLu::DefaultLocalOrdinal LocalOrdinal
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; use default factory.
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static const NoFactory * get()
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
RCP< const ParameterList > GetValidParameterList() const
Define valid parameters for internal factory parameters.
static void inverseScaleBlockDiagonal(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &blockDiagonal, bool doTranspose, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &toBeScaled)
std::string viewLabel_t
static void extractBlockDiagonal(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diagonal)
int GetLevelID() const
Return level number.
Definition: MueLu_Level.cpp:51
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Description of what is happening (more verbose)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need&#39;s value has been saved.