46#ifndef MUELU_NULLSPACEFACTORY_DEF_HPP
47#define MUELU_NULLSPACEFACTORY_DEF_HPP
49#include <Xpetra_Matrix.hpp>
50#include <Xpetra_MultiVectorFactory.hpp>
51#include <Xpetra_BlockedMultiVector.hpp>
52#include <Xpetra_VectorFactory.hpp>
60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 RCP<ParameterList> validParamList = rcp(
new ParameterList());
64 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\"). For block matrices also \"Nullspace1\" to \"Nullspace9\" are accepted to describe the null space vectors for the (i,i) block (i=1..9).");
66 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the fine level matrix (only needed if default null space is generated)");
67 validParamList->set< RCP<const FactoryBase> >(
"Nullspace", Teuchos::null,
"Generating factory of the fine level null space");
71 validParamList->set< RCP<const FactoryBase> >(
"Nullspace1", Teuchos::null,
"Generating factory of the fine level null space associated with the (1,1) block in your n x n block matrix.");
72 validParamList->set< RCP<const FactoryBase> >(
"Nullspace2", Teuchos::null,
"Generating factory of the fine level null space associated with the (2,2) block in your n x n block matrix.");
73 validParamList->set< RCP<const FactoryBase> >(
"Nullspace3", Teuchos::null,
"Generating factory of the fine level null space associated with the (3,3) block in your n x n block matrix.");
74 validParamList->set< RCP<const FactoryBase> >(
"Nullspace4", Teuchos::null,
"Generating factory of the fine level null space associated with the (4,4) block in your n x n block matrix.");
75 validParamList->set< RCP<const FactoryBase> >(
"Nullspace5", Teuchos::null,
"Generating factory of the fine level null space associated with the (5,5) block in your n x n block matrix.");
76 validParamList->set< RCP<const FactoryBase> >(
"Nullspace6", Teuchos::null,
"Generating factory of the fine level null space associated with the (6,6) block in your n x n block matrix.");
77 validParamList->set< RCP<const FactoryBase> >(
"Nullspace7", Teuchos::null,
"Generating factory of the fine level null space associated with the (7,7) block in your n x n block matrix.");
78 validParamList->set< RCP<const FactoryBase> >(
"Nullspace8", Teuchos::null,
"Generating factory of the fine level null space associated with the (8,8) block in your n x n block matrix.");
79 validParamList->set< RCP<const FactoryBase> >(
"Nullspace9", Teuchos::null,
"Generating factory of the fine level null space associated with the (9,9) block in your n x n block matrix.");
81 return validParamList;
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 const ParameterList & pL = GetParameterList();
88 std::string nspName = pL.get<std::string>(
"Fine level nullspace");
94 Input(currentLevel,
"A");
102 TEUCHOS_TEST_FOR_EXCEPTION(GetFactory(nspName)==Teuchos::null,
Exceptions::RuntimeError,
"MueLu::NullspaceFactory::DeclareInput(): You must declare an existing factory which produces the variable \"Nullspace\" in the NullspaceFactory (e.g. a TentativePFactory).");
103 currentLevel.
DeclareInput(
"Nullspace", GetFactory(nspName).get(),
this);
107 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
111 RCP<MultiVector> nullspace;
114 const ParameterList & pL = GetParameterList();
115 std::string nspName = pL.get<std::string>(
"Fine level nullspace");
123 GetOStream(
Runtime1) <<
"Use user-given nullspace " << nspName <<
": nullspace dimension=" << nullspace->getNumVectors() <<
" nullspace length=" << nullspace->getGlobalLength() << std::endl;
126 RCP<Matrix> A = Get< RCP<Matrix> >(currentLevel,
"A");
130 if(A->IsView(
"stridedMaps")==
true) {
131 Xpetra::viewLabel_t oldView = A->SwitchToView(
"stridedMaps");
132 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap()) == Teuchos::null,
Exceptions::BadCast,
"MueLu::CoalesceFactory::Build: cast to strided row map failed.");
133 numPDEs = Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap())->getFixedBlockSize();
134 oldView = A->SwitchToView(oldView);
137 GetOStream(
Runtime1) <<
"Generating canonical nullspace: dimension = " << numPDEs << std::endl;
138 nullspace = MultiVectorFactory::Build(A->getDomainMap(), numPDEs);
140 RCP<BlockedMultiVector> bnsp = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(nullspace);
141 if(bnsp.is_null() ==
true) {
142 for (
int i=0; i<numPDEs; ++i) {
143 ArrayRCP<Scalar> nsValues = nullspace->getDataNonConst(i);
144 int numBlocks = nsValues.size() / numPDEs;
145 for (
int j=0; j< numBlocks; ++j) {
146 nsValues[j*numPDEs + i] = 1.0;
150 fillNullspaceVector(bnsp,numPDEs);
157 nullspace = currentLevel.
Get< RCP<MultiVector> >(
"Nullspace", GetFactory(nspName).get());
162 Set(currentLevel,
"Nullspace", nullspace);
166 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
168 RCP< const BlockedMap> bmap = nsp->getBlockedMap();
170 for(
size_t r = 0; r < bmap->getNumMaps(); r++) {
171 Teuchos::RCP<MultiVector> part = nsp->getMultiVector(r);
172 Teuchos::RCP<BlockedMultiVector> bpart = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(part);
173 if(bpart.is_null() ==
true) {
174 for (
int i=0; i<numPDEs; ++i) {
175 ArrayRCP<Scalar> nsValues = part->getDataNonConst(i);
176 int numBlocks = nsValues.size() / numPDEs;
177 for (
int j=0; j< numBlocks; ++j) {
178 nsValues[j*numPDEs + i] = 1.0;
183 fillNullspaceVector(bpart,numPDEs);
MueLu::DefaultLocalOrdinal LocalOrdinal
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
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.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
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()
void Build(Level ¤tLevel) const
Build an object with this factory.
void fillNullspaceVector(const RCP< BlockedMultiVector > &nsp, LocalOrdinal numPDEs) const
Helper function to recursively fill BlockedMultiVector with default null space vectors.
RCP< const ParameterList > GetValidParameterList() const
Define valid parameters for internal factory parameters.
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Namespace for MueLu classes and methods.
@ Runtime1
Description of what is happening (more verbose)