10 #ifndef MUELU_HIERARCHYUTILS_DEF_HPP
11 #define MUELU_HIERARCHYUTILS_DEF_HPP
19 #include "MueLu_HierarchyManager.hpp"
20 #include "MueLu_FactoryManager.hpp"
23 #ifdef HAVE_MUELU_INTREPID2
24 #include "Kokkos_DynRankView.hpp"
30 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
33 std::string(
"MueLu::Utils::CopyBetweenLevels: unknown data type(") + dataType +
")");
37 if (dataType ==
"RCP<Matrix>") {
45 auto tempMatrix = rcp_dynamic_cast<Matrix>(tempOp);
47 toLevel.
Set(toLabel, tempMatrix);
49 toLevel.
Set(toLabel, tempOp);
52 if (dataType ==
"RCP<const Import>") {
58 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 CopyBetweenLevels(*fromLevel, *toLevel, fromLabel, toLabel, dataType);
74 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 realvaluedmultivector_type;
81 const std::string& levelName = nonSerialEntry->first;
83 if (nonSerialList.
isSublist(levelName) && levelName.find(
"level ") == 0 && levelName.size() > 6) {
84 int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
98 const std::string& name = levelListEntry->first;
100 name !=
"D0" && name !=
"Dk_1" && name !=
"Dk_2" &&
101 name !=
"Mk_one" && name !=
"Mk_1_one" && name !=
"M1_beta" && name !=
"M1_alpha" &&
102 name !=
"invMk_1_invBeta" && name !=
"invMk_2_invAlpha" &&
103 name !=
"M1" && name !=
"Ms" && name !=
"M0inv" &&
104 name !=
"Pnodal" && name !=
"NodeMatrix" && name !=
"NodeAggMatrix" &&
105 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"pcoarsen: element to node map" &&
106 name !=
"Node Comm" && name !=
"DualNodeID2PrimalNodeID" && name !=
"Primal interface DOF map" &&
107 name !=
"dropMap1" && name !=
"dropMap2" &&
110 std::string(
"MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type(") + name +
")");
118 level->
Get(
"A", mat);
119 comm = mat->getMap()->getComm();
126 level0->
Get(
"A", mat);
127 comm = mat->getMap()->getComm();
134 if (levelListEntry->second.isType<std::string>())
138 mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
143 }
else if (name ==
"P" || name ==
"R" || name ==
"K" || name ==
"M") {
146 mat = Teuchos::getValue<RCP<Operator>>(levelListEntry->second);
150 level->
Set(name, mat, fact.
get());
156 if (levelListEntry->second.isType<std::string>())
160 mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
164 level->
Set(name, mat, fact.
get());
169 }
else if (name ==
"D0" || name ==
"Dk_1" || name ==
"Dk_2" ||
170 name ==
"Mk_one" || name ==
"Mk_1_one" || name ==
"M1_beta" || name ==
"M1_alpha" ||
171 name ==
"invMk_1_invBeta" || name ==
"invMk_2_invAlpha" ||
172 name ==
"M1" || name ==
"Ms" || name ==
"M0inv" ||
173 name ==
"Pnodal" || name ==
"NodeMatrix" || name ==
"NodeAggMatrix") {
179 }
else if (name ==
"Mdiag") {
182 }
else if (name ==
"Nullspace") {
184 if (levelListEntry->second.isType<std::string>()) {
187 level->
Get(
"A", mat);
188 auto map = mat->getMap();
191 vec = Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second);
196 }
else if (name ==
"Material") {
199 }
else if (name ==
"BlockNumber") {
202 }
else if (name ==
"Coordinates")
205 if (levelListEntry->second.isType<std::string>()) {
208 level->
Get(
"A", mat);
209 size_t blkSize = mat->GetFixedBlockSize();
214 GO indexBase = dofMap->getIndexBase();
215 size_t numLocalDOFs = dofMap->getLocalNumElements();
217 "HierarchyUtils: block size (" << blkSize <<
") is incompatible with the number of local dofs in a row map (" << numLocalDOFs);
220 Array<GO> nodeGIDs(numLocalDOFs / blkSize);
221 for (
size_t i = 0; i < numLocalDOFs; i += blkSize)
222 nodeGIDs[i / blkSize] = (GIDs[i] - indexBase) / blkSize + indexBase;
225 nodeMap = MapFactory::Build(dofMap->lib(), INVALID, nodeGIDs(), indexBase, dofMap->getComm());
229 vec = Teuchos::getValue<RCP<realvaluedmultivector_type>>(levelListEntry->second);
233 }
else if (name ==
"Node Comm") {
236 }
else if (name ==
"DualNodeID2PrimalNodeID") {
238 level->
Set(name, Teuchos::getValue<
RCP<std::map<LO, LO>>>(levelListEntry->second),
NoFactory::get());
239 }
else if (name ==
"Primal interface DOF map") {
242 }
else if (name ==
"dropMap1") {
245 }
else if (name ==
"dropMap2") {
249 #ifdef HAVE_MUELU_INTREPID2
250 else if (name ==
"pcoarsen: element to node map") {
252 level->
Set(name, Teuchos::getValue<
RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(levelListEntry->second),
NoFactory::get());
256 #ifdef HAVE_MUELU_MATLAB
259 size_t typeNameStart = name.find_first_not_of(
' ');
260 size_t typeNameEnd = name.find(
' ', typeNameStart);
261 std::string
typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
262 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
264 if (typeName ==
"matrix")
266 else if (typeName ==
"multivector")
268 else if (typeName ==
"map")
270 else if (typeName ==
"ordinalvector")
272 else if (typeName ==
"scalar")
273 level->
Set(name, Teuchos::getValue<Scalar>(levelListEntry->second),
NoFactory::get());
274 else if (typeName ==
"double")
275 level->
Set(name, Teuchos::getValue<double>(levelListEntry->second),
NoFactory::get());
276 else if (typeName ==
"complex")
277 level->
Set(name, Teuchos::getValue<std::complex<double>>(levelListEntry->second),
NoFactory::get());
278 else if (typeName ==
"int")
279 level->
Set(name, Teuchos::getValue<int>(levelListEntry->second),
NoFactory::get());
280 else if (typeName ==
"string")
281 level->
Set(name, Teuchos::getValue<std::string>(levelListEntry->second),
NoFactory::get());
285 throw std::runtime_error(
"Invalid non-serializable data on list");
289 }
else if (nonSerialList.
isSublist(levelName) && levelName.find(
"user data") != std::string::npos) {
300 const std::string& name = userListEntry->first;
302 bool isNumberedNullspace = (name.rfind(
"Nullspace", 0) == 0 && name.length() > 9 && std::isdigit(name.back(), std::locale::classic()));
305 name !=
"D0" && name !=
"Dk_1" && name !=
"Dk_2" &&
306 name !=
"Mk_one" && name !=
"Mk_1_one" && name !=
"M1_beta" && name !=
"M1_alpha" &&
307 name !=
"invMk_1_invBeta" && name !=
"invMk_2_invAlpha" &&
308 name !=
"M1" && name !=
"Ms" && name !=
"M0inv" &&
309 name !=
"NodeMatrix" &&
310 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"Material" &&
311 name !=
"BlockNumber" && name !=
"pcoarsen: element to node map" &&
312 name !=
"Node Comm" && name !=
"DualNodeID2PrimalNodeID" && name !=
"Primal interface DOF map" &&
313 name !=
"dropMap1" && name !=
"dropMap2" &&
314 name !=
"output stream" &&
315 !isNumberedNullspace &&
318 std::string(
"MueLu::Utils::AddNonSerializableDataToHierarchy: user data parameter list contains unknown data type (") + name +
")");
319 if (name ==
"P" || name ==
"R" || name ==
"K" || name ==
"M" ||
320 name ==
"D0" || name ==
"Dk_1" || name ==
"Dk_2" ||
321 name ==
"Mk_one" || name ==
"Mk_1_one" || name ==
"M1_beta" || name ==
"M1_alpha" ||
322 name ==
"invMk_1_invBeta" || name ==
"invMk_2_invAlpha" ||
323 name ==
"M1" || name ==
"Ms" || name ==
"M0inv" ||
324 name ==
"NodeMatrix") {
327 }
else if (name ==
"Mdiag") {
330 }
else if (name ==
"Nullspace" || isNumberedNullspace) {
335 }
else if (name ==
"Material") {
338 }
else if (name ==
"BlockNumber") {
341 }
else if (name ==
"Coordinates") {
344 }
else if (name ==
"Node Comm") {
347 }
else if (name ==
"DualNodeID2PrimalNodeID") {
349 level->
Set(name, Teuchos::getValue<
RCP<std::map<LO, LO>>>(userListEntry->second),
NoFactory::get());
350 }
else if (name ==
"Primal interface DOF map") {
353 }
else if (name ==
"dropMap1") {
356 }
else if (name ==
"dropMap2") {
360 #ifdef HAVE_MUELU_INTREPID2
361 else if (name ==
"pcoarsen: element to node map") {
363 level->
Set(name, Teuchos::getValue<
RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(userListEntry->second),
NoFactory::get());
366 else if (name ==
"output stream") {
370 size_t typeNameStart = name.find_first_not_of(
' ');
371 size_t typeNameEnd = name.find(
' ', typeNameStart);
372 std::string
typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
373 size_t varNameStart = name.find_first_not_of(
' ', typeNameEnd);
374 std::string varName = name.substr(varNameStart, name.size());
375 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
377 if (typeName ==
"matrix")
379 else if (typeName ==
"multivector")
381 else if (typeName ==
"vector")
383 else if (typeName ==
"map")
385 else if (typeName ==
"ordinalvector")
387 else if (typeName ==
"scalar")
388 level->
Set(varName, Teuchos::getValue<Scalar>(userListEntry->second),
NoFactory::get());
389 else if (typeName ==
"double")
390 level->
Set(varName, Teuchos::getValue<double>(userListEntry->second),
NoFactory::get());
391 else if (typeName ==
"complex")
392 level->
Set(varName, Teuchos::getValue<std::complex<double>>(userListEntry->second),
NoFactory::get());
393 else if (typeName ==
"int")
394 level->
Set(varName, Teuchos::getValue<int>(userListEntry->second),
NoFactory::get());
395 else if (typeName ==
"string")
396 level->
Set(varName, Teuchos::getValue<std::string>(userListEntry->second),
NoFactory::get());
397 else if (typeName ==
"array<go>")
399 else if (typeName ==
"array<lo>")
401 else if (typeName ==
"arrayrcp<lo>")
403 else if (typeName ==
"arrayrcp<go>")
406 throw std::runtime_error(
"Invalid non-serializable data on list");
415 #define MUELU_HIERARCHY_UTILS_SHORT
416 #endif // MUELU_HIERARCHYHELPERS_DEF_HPP
static void CopyBetweenLevels(Level &fromLevel, Level &toLevel, const std::string fromLabel, const std::string toLabel, const std::string dataType)
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.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
#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
Class that holds all level-specific information.
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()
static const RCP< const NoFactory > getRCP()
Static Get() functions.
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)