46 #ifndef MUELU_HIERARCHYUTILS_DEF_HPP
47 #define MUELU_HIERARCHYUTILS_DEF_HPP
56 #include "MueLu_FactoryManager.hpp"
59 #ifdef HAVE_MUELU_INTREPID2
60 #include "Kokkos_DynRankView.hpp"
66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 std::string(
"MueLu::Utils::CopyBetweenHierarchies: unknown data type(") + dataType +
")");
79 if (dataType ==
"RCP<Matrix>") {
87 auto tempMatrix = rcp_dynamic_cast<Matrix>(tempOp);
89 toLevel->
Set(toLabel, tempMatrix);
91 toLevel->
Set(toLabel, tempOp);
93 if (dataType ==
"RCP<const Import>") {
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 realvaluedmultivector_type;
109 const std::string& levelName = nonSerialEntry->first;
111 if (nonSerialList.
isSublist(levelName) && levelName.find(
"level ") == 0 && levelName.size() > 6) {
112 int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
126 const std::string& name = levelListEntry->first;
128 name !=
"D0" && name !=
"Dk_1" && name !=
"Dk_2" &&
129 name !=
"Mk_one" && name !=
"Mk_1_one" && name !=
"M1_beta" && name !=
"M1_alpha" &&
130 name !=
"invMk_1_invBeta" && name !=
"invMk_2_invAlpha" &&
131 name !=
"M1" && name !=
"Ms" && name !=
"M0inv" &&
132 name !=
"Pnodal" && name !=
"NodeMatrix" && name !=
"NodeAggMatrix" &&
133 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"pcoarsen: element to node map" &&
134 name !=
"Node Comm" && name !=
"DualNodeID2PrimalNodeID" && name !=
"Primal interface DOF map" &&
135 name !=
"dropMap1" && name !=
"dropMap2" &&
138 std::string(
"MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type(") + name +
")");
146 level->
Get(
"A", mat);
147 comm = mat->getMap()->getComm();
154 level0->
Get(
"A", mat);
155 comm = mat->getMap()->getComm();
162 if (levelListEntry->second.isType<std::string>())
166 mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
171 }
else if (name ==
"P" || name ==
"R" || name ==
"K" || name ==
"M") {
174 mat = Teuchos::getValue<RCP<Operator>>(levelListEntry->second);
178 level->
Set(name, mat, fact.
get());
184 if (levelListEntry->second.isType<std::string>())
188 mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
192 level->
Set(name, mat, fact.
get());
197 }
else if (name ==
"D0" || name ==
"Dk_1" || name ==
"Dk_2" ||
198 name ==
"Mk_one" || name ==
"Mk_1_one" || name ==
"M1_beta" || name ==
"M1_alpha" ||
199 name ==
"invMk_1_invBeta" || name ==
"invMk_2_invAlpha" ||
200 name ==
"M1" || name ==
"Ms" || name ==
"M0inv" ||
201 name ==
"Pnodal" || name ==
"NodeMatrix" || name ==
"NodeAggMatrix") {
207 }
else if (name ==
"Mdiag") {
210 }
else if (name ==
"Nullspace") {
212 if (levelListEntry->second.isType<std::string>()) {
215 level->
Get(
"A", mat);
216 auto map = mat->getMap();
219 vec = Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second);
224 }
else if (name ==
"Coordinates")
227 if (levelListEntry->second.isType<std::string>()) {
230 level->
Get(
"A", mat);
231 size_t blkSize = mat->GetFixedBlockSize();
236 GO indexBase = dofMap->getIndexBase();
237 size_t numLocalDOFs = dofMap->getLocalNumElements();
239 "HierarchyUtils: block size (" << blkSize <<
") is incompatible with the number of local dofs in a row map (" << numLocalDOFs);
242 Array<GO> nodeGIDs(numLocalDOFs / blkSize);
243 for (
size_t i = 0; i < numLocalDOFs; i += blkSize)
244 nodeGIDs[i / blkSize] = (GIDs[i] - indexBase) / blkSize + indexBase;
247 nodeMap = MapFactory::Build(dofMap->lib(), INVALID, nodeGIDs(), indexBase, dofMap->getComm());
251 vec = Teuchos::getValue<RCP<realvaluedmultivector_type>>(levelListEntry->second);
255 }
else if (name ==
"Node Comm") {
258 }
else if (name ==
"DualNodeID2PrimalNodeID") {
260 level->
Set(name, Teuchos::getValue<
RCP<std::map<LO, LO>>>(levelListEntry->second),
NoFactory::get());
261 }
else if (name ==
"Primal interface DOF map") {
264 }
else if (name ==
"dropMap1") {
267 }
else if (name ==
"dropMap2") {
271 #ifdef HAVE_MUELU_INTREPID2
272 else if (name ==
"pcoarsen: element to node map") {
274 level->
Set(name, Teuchos::getValue<
RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(levelListEntry->second),
NoFactory::get());
278 #ifdef HAVE_MUELU_MATLAB
281 size_t typeNameStart = name.find_first_not_of(
' ');
282 size_t typeNameEnd = name.find(
' ', typeNameStart);
283 std::string
typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
284 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
286 if (typeName ==
"matrix")
288 else if (typeName ==
"multivector")
290 else if (typeName ==
"map")
292 else if (typeName ==
"ordinalvector")
294 else if (typeName ==
"scalar")
295 level->
Set(name, Teuchos::getValue<Scalar>(levelListEntry->second),
NoFactory::get());
296 else if (typeName ==
"double")
297 level->
Set(name, Teuchos::getValue<double>(levelListEntry->second),
NoFactory::get());
298 else if (typeName ==
"complex")
299 level->
Set(name, Teuchos::getValue<std::complex<double>>(levelListEntry->second),
NoFactory::get());
300 else if (typeName ==
"int")
301 level->
Set(name, Teuchos::getValue<int>(levelListEntry->second),
NoFactory::get());
302 else if (typeName ==
"string")
303 level->
Set(name, Teuchos::getValue<std::string>(levelListEntry->second),
NoFactory::get());
307 throw std::runtime_error(
"Invalid non-serializable data on list");
311 }
else if (nonSerialList.
isSublist(levelName) && levelName.find(
"user data") != std::string::npos) {
322 const std::string& name = userListEntry->first;
324 name !=
"D0" && name !=
"Dk_1" && name !=
"Dk_2" &&
325 name !=
"Mk_one" && name !=
"Mk_1_one" && name !=
"M1_beta" && name !=
"M1_alpha" &&
326 name !=
"invMk_1_invBeta" && name !=
"invMk_2_invAlpha" &&
327 name !=
"M1" && name !=
"Ms" && name !=
"M0inv" &&
328 name !=
"NodeMatrix" &&
329 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"pcoarsen: element to node map" &&
330 name !=
"Node Comm" && name !=
"DualNodeID2PrimalNodeID" && name !=
"Primal interface DOF map" &&
331 name !=
"dropMap1" && name !=
"dropMap2" &&
332 name !=
"output stream" &&
335 std::string(
"MueLu::Utils::AddNonSerializableDataToHierarchy: user data parameter list contains unknown data type (") + name +
")");
336 if (name ==
"P" || name ==
"R" || name ==
"K" || name ==
"M" ||
337 name ==
"D0" || name ==
"Dk_1" || name ==
"Dk_2" ||
338 name ==
"Mk_one" || name ==
"Mk_1_one" || name ==
"M1_beta" || name ==
"M1_alpha" ||
339 name ==
"invMk_1_invBeta" || name ==
"invMk_2_invAlpha" ||
340 name ==
"M1" || name ==
"Ms" || name ==
"M0inv" ||
341 name ==
"NodeMatrix") {
344 }
else if (name ==
"Mdiag") {
347 }
else if (name ==
"Nullspace") {
352 }
else if (name ==
"Coordinates") {
355 }
else if (name ==
"Node Comm") {
358 }
else if (name ==
"DualNodeID2PrimalNodeID") {
360 level->
Set(name, Teuchos::getValue<
RCP<std::map<LO, LO>>>(userListEntry->second),
NoFactory::get());
361 }
else if (name ==
"Primal interface DOF map") {
364 }
else if (name ==
"dropMap1") {
367 }
else if (name ==
"dropMap2") {
371 #ifdef HAVE_MUELU_INTREPID2
372 else if (name ==
"pcoarsen: element to node map") {
374 level->
Set(name, Teuchos::getValue<
RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(userListEntry->second),
NoFactory::get());
377 else if (name ==
"output stream") {
381 size_t typeNameStart = name.find_first_not_of(
' ');
382 size_t typeNameEnd = name.find(
' ', typeNameStart);
383 std::string
typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
384 size_t varNameStart = name.find_first_not_of(
' ', typeNameEnd);
385 std::string varName = name.substr(varNameStart, name.size());
386 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
388 if (typeName ==
"matrix")
390 else if (typeName ==
"multivector")
392 else if (typeName ==
"vector")
394 else if (typeName ==
"map")
396 else if (typeName ==
"ordinalvector")
398 else if (typeName ==
"scalar")
399 level->
Set(varName, Teuchos::getValue<Scalar>(userListEntry->second),
NoFactory::get());
400 else if (typeName ==
"double")
401 level->
Set(varName, Teuchos::getValue<double>(userListEntry->second),
NoFactory::get());
402 else if (typeName ==
"complex")
403 level->
Set(varName, Teuchos::getValue<std::complex<double>>(userListEntry->second),
NoFactory::get());
404 else if (typeName ==
"int")
405 level->
Set(varName, Teuchos::getValue<int>(userListEntry->second),
NoFactory::get());
406 else if (typeName ==
"string")
407 level->
Set(varName, Teuchos::getValue<std::string>(userListEntry->second),
NoFactory::get());
408 else if (typeName ==
"array<go>")
410 else if (typeName ==
"array<lo>")
412 else if (typeName ==
"arrayrcp<lo>")
414 else if (typeName ==
"arrayrcp<go>")
417 throw std::runtime_error(
"Invalid non-serializable data on list");
426 #define MUELU_HIERARCHY_UTILS_SHORT
427 #endif // MUELU_HIERARCHYHELPERS_DEF_HPP
This class specifies the default factory that should generate some data on a Level if the data does n...
ConstIterator end() const
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.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
static void AddNonSerializableDataToHierarchy(HierarchyManager &HM, Hierarchy &H, const ParameterList &nonSerialList)
Add non-serializable data to Hierarchy.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void AddNewLevel()
Add a new level at the end of the hierarchy.
User data are always kept. This flag is set automatically when Level::Set("data", data) is used...
std::string tolower(const std::string &str)
bool IsParamMuemexVariable(const std::string &name)
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Get factory associated with a particular data name.
static const NoFactory * get()
MueLu::DefaultGlobalOrdinal GlobalOrdinal
bool isSublist(const std::string &name) const
static RCP< MultiVector > ReadMultiVector(const std::string &fileName, const RCP< const Map > &map)
params_t::ConstIterator ConstIterator
Xpetra::UnderlyingLib lib()
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
ConstIterator begin() const
bool IsParamValidVariable(const std::string &name)
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Set Factory.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Read(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, bool binary=false)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Exception throws to report errors in the internal logical of the program.
#define TEUCHOS_ASSERT(assertion_test)
static void SetMueLuOStream(const Teuchos::RCP< Teuchos::FancyOStream > &mueluOStream)
RCP< const Teuchos::Comm< int > > GetComm() const
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
std::string typeName(const T &t)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
Exception throws to report invalid user entry.
static void CopyBetweenHierarchies(Hierarchy &fromHierarchy, Hierarchy &toHierarchy, const std::string fromLabel, const std::string toLabel, const std::string dataType)
static const RCP< const NoFactory > getRCP()
Static Get() functions.