46 #ifndef MUELU_NULLSPACEFACTORY_DEF_HPP
47 #define MUELU_NULLSPACEFACTORY_DEF_HPP
52 #include <Xpetra_MultiVectorFactory.hpp>
57 #include "Xpetra_Access.hpp"
61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
67 #undef SET_VALID_ENTRY
68 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).");
70 validParamList->
set<
RCP<const FactoryBase>>(
"A", Teuchos::null,
"Generating factory of the fine level matrix (only needed if default null space is generated)");
71 validParamList->
set<
RCP<const FactoryBase>>(
"Nullspace", Teuchos::null,
"Generating factory of the fine level null space");
77 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.");
78 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.");
79 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.");
80 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.");
81 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.");
82 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.");
83 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.");
84 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.");
85 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.");
87 return validParamList;
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 std::string nspName = pL.
get<std::string>(
"Fine level nullspace");
99 Input(currentLevel,
"A");
103 pL.
get<
bool>(
"nullspace: calculate rotations")) {
104 calculateRotations_ =
true;
105 Input(currentLevel,
"Coordinates");
115 "MueLu::NullspaceFactory::DeclareInput(): You must declare an existing factory which "
116 "produces the variable \"Nullspace\" in the NullspaceFactory (e.g. a TentativePFactory).");
117 currentLevel.
DeclareInput(
"Nullspace", GetFactory(nspName).
get(),
this);
121 template <
class NullspaceType,
class CoordsType,
class MeanCoordsType,
class LO>
129 typedef typename NullspaceType::value_type
SC;
130 typedef Kokkos::ArithTraits<SC>
ATS;
133 NullspaceFunctor(NullspaceType nullspace_, CoordsType coords_, MeanCoordsType mean_,
LO numPDEs_,
LO nullspaceDim_)
139 static_assert(static_cast<int>(NullspaceType::rank) == 2,
"Nullspace needs to be a rank 2 view.");
140 static_assert(static_cast<int>(CoordsType::rank) == 2,
"Coords needs to be a rank 2 view.");
141 static_assert(static_cast<int>(MeanCoordsType::rank) == 1,
"Mean needs to be a rank 1 view.");
144 KOKKOS_INLINE_FUNCTION
166 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 std::string nspName = pL.
get<std::string>(
"Fine level nullspace");
185 GetOStream(
Runtime1) <<
"Use user-given nullspace " << nspName <<
":"
186 <<
" nullspace dimension=" << nullspace->getNumVectors()
187 <<
" nullspace length=" << nullspace->getGlobalLength() << std::endl;
191 auto A = Get<RCP<Matrix>>(currentLevel,
"A");
195 if (A->IsView(
"stridedMaps") ==
true) {
198 "MueLu::CoalesceFactory::Build: cast to strided row map failed.");
199 numPDEs = rcp_dynamic_cast<
const StridedMap>(A->getRowMap())->getFixedBlockSize();
200 oldView = A->SwitchToView(oldView);
203 LO nullspaceDim = numPDEs;
207 if (calculateRotations_) {
208 Coords = Get<RCP<RealValuedMultiVector>>(currentLevel,
"Coordinates");
209 if (Coords->getNumVectors() > 1) nullspaceDim++;
210 if (Coords->getNumVectors() > 2) nullspaceDim += 2;
212 meanView =
MeanCoordsType(
"mean coords", Coords->getNumVectors());
214 Coords->meanValue(hostMeans);
215 Kokkos::View<typename RealValuedMultiVector::impl_scalar_type*, Kokkos::HostSpace> hostMeanView(hostMeans.getRawPtr(), hostMeans.size());
216 Kokkos::deep_copy(meanView, hostMeanView);
217 coordsView = Coords->getDeviceLocalView(Xpetra::Access::ReadOnly);
218 GetOStream(
Runtime1) <<
"Generating nullspace with rotations: dimension = " << nullspaceDim << std::endl;
220 GetOStream(
Runtime1) <<
"Generating canonical nullspace: dimension = " << numPDEs << std::endl;
222 nullspace = MultiVectorFactory::Build(A->getDomainMap(), nullspaceDim);
224 fillNullspaceVector(nullspace, numPDEs, nullspaceDim, coordsView, meanView);
234 Set(currentLevel,
"Nullspace", nullspace);
238 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
242 auto nullspaceView = nullspace->getDeviceLocalView(Xpetra::Access::OverwriteAll);
244 int numBlocks = nullspace->getLocalLength() / numPDEs;
245 if (nullspaceDim > numPDEs)
249 Kokkos::parallel_for(
"MueLu:NullspaceF:Build:for",
range_type(0, numBlocks), nullspaceFunctor);
267 for (
size_t r = 0; r < bmap->getNumMaps(); r++) {
269 fillNullspaceVector(part, numPDEs, nullspaceDim, coordsView, meanView);
276 #endif // MUELU_NULLSPACEFACTORY_DEF_HPP
Exception indicating invalid cast attempted.
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->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
bool is_null(const boost::shared_ptr< T > &p)
RCP< const ParameterList > GetValidParameterList() const
Define valid parameters for internal factory parameters.
Kokkos::RangePolicy< local_ordinal_type, execution_space > range_type
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
typename RealValuedMultiVector::dual_view_type::t_dev_const_um CoordsType
static const NoFactory * get()
void fillNullspaceVector(const RCP< MultiVector > &nullspace, LocalOrdinal numPDEs, LocalOrdinal nullspaceDim, CoordsType coordsView, MeanCoordsType meanView) const
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Kokkos::View< typename RealValuedMultiVector::impl_scalar_type *, typename Node::memory_space > MeanCoordsType
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
KOKKOS_INLINE_FUNCTION void operator()(const LO j) const
NullspaceType::value_type SC
NullspaceFunctor(NullspaceType nullspace_, CoordsType coords_, MeanCoordsType mean_, LO numPDEs_, LO nullspaceDim_)
Kokkos::ArithTraits< SC > ATS
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
Description of what is happening (more verbose)
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
#define SET_VALID_ENTRY(name)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void Build(Level ¤tLevel) const
Build an object with this factory.