46 #ifndef MUELU_NULLSPACEFACTORY_KOKKOS_DEF_HPP 47 #define MUELU_NULLSPACEFACTORY_KOKKOS_DEF_HPP 49 #ifdef HAVE_MUELU_KOKKOS_REFACTOR 53 #include <Xpetra_Matrix.hpp> 54 #include <Xpetra_MultiVectorFactory.hpp> 61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
62 RCP<const ParameterList> NullspaceFactory_kokkos<Scalar,LocalOrdinal,GlobalOrdinal,Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>>::GetValidParameterList()
const {
63 RCP<ParameterList> validParamList = rcp(
new ParameterList());
65 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the fine level matrix (only needed if default null space is generated)");
66 validParamList->set< RCP<const FactoryBase> >(
"Nullspace", Teuchos::null,
"Generating factory of the fine level null space");
69 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\"");
71 validParamList->set< RCP<const FactoryBase> >(
"Nullspace1", Teuchos::null,
"Generating factory of the fine level null space");
72 validParamList->set< RCP<const FactoryBase> >(
"Nullspace2", Teuchos::null,
"Generating factory of the fine level null space");
74 return validParamList;
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
78 void NullspaceFactory_kokkos<Scalar,LocalOrdinal,GlobalOrdinal,Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>>::DeclareInput(Level& currentLevel)
const {
79 const ParameterList& pL = GetParameterList();
80 std::string nspName = pL.get<std::string>(
"Fine level nullspace");
85 if (currentLevel.IsAvailable(nspName,
NoFactory::get()) ==
false && currentLevel.GetLevelID() == 0)
86 Input(currentLevel,
"A");
88 if (currentLevel.GetLevelID() != 0) {
95 currentLevel.DeclareInput(
"Nullspace", GetFactory(nspName).
get(),
this);
99 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
100 void NullspaceFactory_kokkos<Scalar,LocalOrdinal,GlobalOrdinal,Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>>::Build(Level& currentLevel)
const {
101 FactoryMonitor m(*
this,
"Nullspace factory", currentLevel);
103 RCP<MultiVector> nullspace;
106 const ParameterList& pL = GetParameterList();
107 std::string nspName = pL.get<std::string>(
"Fine level nullspace");
109 if (currentLevel.GetLevelID() == 0) {
114 nullspace = currentLevel.Get< RCP<MultiVector> >(nspName,
NoFactory::get());
115 GetOStream(
Runtime1) <<
"Use user-given nullspace " << nspName <<
": nullspace dimension=" << nullspace->getNumVectors() <<
" nullspace length=" << nullspace->getGlobalLength() << std::endl;
119 auto A = Get< RCP<Matrix> >(currentLevel,
"A");
123 if (A->IsView(
"stridedMaps") ==
true) {
124 Xpetra::viewLabel_t oldView = A->SwitchToView(
"stridedMaps");
125 TEUCHOS_TEST_FOR_EXCEPTION(rcp_dynamic_cast<const StridedMap>(A->getRowMap()).is_null(), Exceptions::BadCast,
"MueLu::CoalesceFactory::Build: cast to strided row map failed.");
126 numPDEs = rcp_dynamic_cast<
const StridedMap>(A->getRowMap())->getFixedBlockSize();
127 oldView = A->SwitchToView(oldView);
130 GetOStream(
Runtime1) <<
"Generating canonical nullspace: dimension = " << numPDEs << std::endl;
132 nullspace = MultiVectorFactory::Build(A->getDomainMap(), numPDEs);
133 auto nullspaceView = nullspace->template getLocalView<DeviceType>();
135 int numBlocks = nullspace->getLocalLength() / numPDEs;
137 SC one = Teuchos::ScalarTraits<SC>::one();
138 for (
int i = 0; i < numPDEs; i++) {
140 nullspaceView(j*numPDEs + i, i) = one;
148 nullspace = currentLevel.Get< RCP<MultiVector> >(
"Nullspace", GetFactory(nspName).get());
152 Set(currentLevel,
"Nullspace", nullspace);
158 #endif // HAVE_MUELU_KOKKOS_REFACTOR 159 #endif // MUELU_NULLSPACEFACTORY_KOKKOS_DEF_HPP
Namespace for MueLu classes and methods.
static const NoFactory * get()
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< !Impl::is_integral< ExecPolicy >::value >::type *=0)
Description of what is happening (more verbose)