MueLu Version of the Day
Loading...
Searching...
No Matches
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
23namespace MueLu {
24
25template <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
36template <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
43template <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
82 Xpetra::MatrixUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::extractBlockDiagonal(*A, *blockDiagonal);
83 Xpetra::MatrixUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::inverseScaleBlockDiagonal(*blockDiagonal, true, *nullspace);
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
MueLu::DefaultLocalOrdinal LocalOrdinal
Exception indicating invalid cast attempted.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
static const NoFactory * get()
RCP< const ParameterList > GetValidParameterList() const
Define valid parameters for internal factory parameters.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
void Build(Level &currentLevel) const
Build an object with this factory.
Namespace for MueLu classes and methods.
@ Runtime1
Description of what is happening (more verbose)