10 #ifndef MUELU_HIERARCHYUTILS_DEF_HPP
11 #define MUELU_HIERARCHYUTILS_DEF_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>
41 std::string(
"MueLu::Utils::CopyBetweenHierarchies: unknown data type(") + dataType +
")");
43 if (dataType ==
"RCP<Matrix>") {
51 auto tempMatrix = rcp_dynamic_cast<Matrix>(tempOp);
53 toLevel->
Set(toLabel, tempMatrix);
55 toLevel->
Set(toLabel, tempOp);
57 if (dataType ==
"RCP<const Import>") {
66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 realvaluedmultivector_type;
73 const std::string& levelName = nonSerialEntry->first;
75 if (nonSerialList.
isSublist(levelName) && levelName.find(
"level ") == 0 && levelName.size() > 6) {
76 int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
90 const std::string& name = levelListEntry->first;
92 name !=
"D0" && name !=
"Dk_1" && name !=
"Dk_2" &&
93 name !=
"Mk_one" && name !=
"Mk_1_one" && name !=
"M1_beta" && name !=
"M1_alpha" &&
94 name !=
"invMk_1_invBeta" && name !=
"invMk_2_invAlpha" &&
95 name !=
"M1" && name !=
"Ms" && name !=
"M0inv" &&
96 name !=
"Pnodal" && name !=
"NodeMatrix" && name !=
"NodeAggMatrix" &&
97 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"pcoarsen: element to node map" &&
98 name !=
"Node Comm" && name !=
"DualNodeID2PrimalNodeID" && name !=
"Primal interface DOF map" &&
99 name !=
"dropMap1" && name !=
"dropMap2" &&
102 std::string(
"MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type(") + name +
")");
110 level->
Get(
"A", mat);
111 comm = mat->getMap()->getComm();
118 level0->
Get(
"A", mat);
119 comm = mat->getMap()->getComm();
126 if (levelListEntry->second.isType<std::string>())
130 mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
135 }
else if (name ==
"P" || name ==
"R" || name ==
"K" || name ==
"M") {
138 mat = Teuchos::getValue<RCP<Operator>>(levelListEntry->second);
142 level->
Set(name, mat, fact.
get());
148 if (levelListEntry->second.isType<std::string>())
152 mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
156 level->
Set(name, mat, fact.
get());
161 }
else if (name ==
"D0" || name ==
"Dk_1" || name ==
"Dk_2" ||
162 name ==
"Mk_one" || name ==
"Mk_1_one" || name ==
"M1_beta" || name ==
"M1_alpha" ||
163 name ==
"invMk_1_invBeta" || name ==
"invMk_2_invAlpha" ||
164 name ==
"M1" || name ==
"Ms" || name ==
"M0inv" ||
165 name ==
"Pnodal" || name ==
"NodeMatrix" || name ==
"NodeAggMatrix") {
171 }
else if (name ==
"Mdiag") {
174 }
else if (name ==
"Nullspace") {
176 if (levelListEntry->second.isType<std::string>()) {
179 level->
Get(
"A", mat);
180 auto map = mat->getMap();
183 vec = Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second);
188 }
else if (name ==
"Coordinates")
191 if (levelListEntry->second.isType<std::string>()) {
194 level->
Get(
"A", mat);
195 size_t blkSize = mat->GetFixedBlockSize();
200 GO indexBase = dofMap->getIndexBase();
201 size_t numLocalDOFs = dofMap->getLocalNumElements();
203 "HierarchyUtils: block size (" << blkSize <<
") is incompatible with the number of local dofs in a row map (" << numLocalDOFs);
206 Array<GO> nodeGIDs(numLocalDOFs / blkSize);
207 for (
size_t i = 0; i < numLocalDOFs; i += blkSize)
208 nodeGIDs[i / blkSize] = (GIDs[i] - indexBase) / blkSize + indexBase;
211 nodeMap = MapFactory::Build(dofMap->lib(), INVALID, nodeGIDs(), indexBase, dofMap->getComm());
215 vec = Teuchos::getValue<RCP<realvaluedmultivector_type>>(levelListEntry->second);
219 }
else if (name ==
"Node Comm") {
222 }
else if (name ==
"DualNodeID2PrimalNodeID") {
224 level->
Set(name, Teuchos::getValue<
RCP<std::map<LO, LO>>>(levelListEntry->second),
NoFactory::get());
225 }
else if (name ==
"Primal interface DOF map") {
228 }
else if (name ==
"dropMap1") {
231 }
else if (name ==
"dropMap2") {
235 #ifdef HAVE_MUELU_INTREPID2
236 else if (name ==
"pcoarsen: element to node map") {
238 level->
Set(name, Teuchos::getValue<
RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(levelListEntry->second),
NoFactory::get());
242 #ifdef HAVE_MUELU_MATLAB
245 size_t typeNameStart = name.find_first_not_of(
' ');
246 size_t typeNameEnd = name.find(
' ', typeNameStart);
247 std::string
typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
248 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
250 if (typeName ==
"matrix")
252 else if (typeName ==
"multivector")
254 else if (typeName ==
"map")
256 else if (typeName ==
"ordinalvector")
258 else if (typeName ==
"scalar")
259 level->
Set(name, Teuchos::getValue<Scalar>(levelListEntry->second),
NoFactory::get());
260 else if (typeName ==
"double")
261 level->
Set(name, Teuchos::getValue<double>(levelListEntry->second),
NoFactory::get());
262 else if (typeName ==
"complex")
263 level->
Set(name, Teuchos::getValue<std::complex<double>>(levelListEntry->second),
NoFactory::get());
264 else if (typeName ==
"int")
265 level->
Set(name, Teuchos::getValue<int>(levelListEntry->second),
NoFactory::get());
266 else if (typeName ==
"string")
267 level->
Set(name, Teuchos::getValue<std::string>(levelListEntry->second),
NoFactory::get());
271 throw std::runtime_error(
"Invalid non-serializable data on list");
275 }
else if (nonSerialList.
isSublist(levelName) && levelName.find(
"user data") != std::string::npos) {
286 const std::string& name = userListEntry->first;
288 name !=
"D0" && name !=
"Dk_1" && name !=
"Dk_2" &&
289 name !=
"Mk_one" && name !=
"Mk_1_one" && name !=
"M1_beta" && name !=
"M1_alpha" &&
290 name !=
"invMk_1_invBeta" && name !=
"invMk_2_invAlpha" &&
291 name !=
"M1" && name !=
"Ms" && name !=
"M0inv" &&
292 name !=
"NodeMatrix" &&
293 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"pcoarsen: element to node map" &&
294 name !=
"Node Comm" && name !=
"DualNodeID2PrimalNodeID" && name !=
"Primal interface DOF map" &&
295 name !=
"dropMap1" && name !=
"dropMap2" &&
296 name !=
"output stream" &&
299 std::string(
"MueLu::Utils::AddNonSerializableDataToHierarchy: user data parameter list contains unknown data type (") + name +
")");
300 if (name ==
"P" || name ==
"R" || name ==
"K" || name ==
"M" ||
301 name ==
"D0" || name ==
"Dk_1" || name ==
"Dk_2" ||
302 name ==
"Mk_one" || name ==
"Mk_1_one" || name ==
"M1_beta" || name ==
"M1_alpha" ||
303 name ==
"invMk_1_invBeta" || name ==
"invMk_2_invAlpha" ||
304 name ==
"M1" || name ==
"Ms" || name ==
"M0inv" ||
305 name ==
"NodeMatrix") {
308 }
else if (name ==
"Mdiag") {
311 }
else if (name ==
"Nullspace") {
316 }
else if (name ==
"Coordinates") {
319 }
else if (name ==
"Node Comm") {
322 }
else if (name ==
"DualNodeID2PrimalNodeID") {
324 level->
Set(name, Teuchos::getValue<
RCP<std::map<LO, LO>>>(userListEntry->second),
NoFactory::get());
325 }
else if (name ==
"Primal interface DOF map") {
328 }
else if (name ==
"dropMap1") {
331 }
else if (name ==
"dropMap2") {
335 #ifdef HAVE_MUELU_INTREPID2
336 else if (name ==
"pcoarsen: element to node map") {
338 level->
Set(name, Teuchos::getValue<
RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(userListEntry->second),
NoFactory::get());
341 else if (name ==
"output stream") {
345 size_t typeNameStart = name.find_first_not_of(
' ');
346 size_t typeNameEnd = name.find(
' ', typeNameStart);
347 std::string
typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
348 size_t varNameStart = name.find_first_not_of(
' ', typeNameEnd);
349 std::string varName = name.substr(varNameStart, name.size());
350 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
352 if (typeName ==
"matrix")
354 else if (typeName ==
"multivector")
356 else if (typeName ==
"vector")
358 else if (typeName ==
"map")
360 else if (typeName ==
"ordinalvector")
362 else if (typeName ==
"scalar")
363 level->
Set(varName, Teuchos::getValue<Scalar>(userListEntry->second),
NoFactory::get());
364 else if (typeName ==
"double")
365 level->
Set(varName, Teuchos::getValue<double>(userListEntry->second),
NoFactory::get());
366 else if (typeName ==
"complex")
367 level->
Set(varName, Teuchos::getValue<std::complex<double>>(userListEntry->second),
NoFactory::get());
368 else if (typeName ==
"int")
369 level->
Set(varName, Teuchos::getValue<int>(userListEntry->second),
NoFactory::get());
370 else if (typeName ==
"string")
371 level->
Set(varName, Teuchos::getValue<std::string>(userListEntry->second),
NoFactory::get());
372 else if (typeName ==
"array<go>")
374 else if (typeName ==
"array<lo>")
376 else if (typeName ==
"arrayrcp<lo>")
378 else if (typeName ==
"arrayrcp<go>")
381 throw std::runtime_error(
"Invalid non-serializable data on list");
390 #define MUELU_HIERARCHY_UTILS_SHORT
391 #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.
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
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)