46 #ifndef MUELU_HIERARCHYUTILS_DEF_HPP 47 #define MUELU_HIERARCHYUTILS_DEF_HPP 49 #include <Xpetra_Matrix.hpp> 50 #include <Xpetra_Operator.hpp> 55 #include "MueLu_SmootherFactory.hpp" 56 #include "MueLu_FactoryManager.hpp" 59 #ifdef HAVE_MUELU_INTREPID2 60 #ifdef HAVE_MUELU_INTREPID2_REFACTOR 63 #include "Intrepid2_FieldContainer.hpp" 72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 for (ParameterList::ConstIterator it = paramList.begin(); it != paramList.end(); it++) {
76 const std::string& levelName = it->first;
78 if (paramList.isSublist(levelName) && levelName.find(
"level ") == 0 && levelName.size() > 6) {
79 int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
86 RCP<Level> level = H.
GetLevel(levelID);
89 TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(),
Exceptions::InvalidArgument,
"MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
92 const ParameterList& levelList = paramList.sublist(levelName);
93 for (ParameterList::ConstIterator it2 = levelList.begin(); it2 != levelList.end(); it2++) {
94 const std::string& name = it2->first;
95 TEUCHOS_TEST_FOR_EXCEPTION(name !=
"A" && name !=
"P" && name !=
"R" &&
96 name !=
"Nullspace" && name !=
"Coordinates" && name !=
"pcoarsen: element to node map" &&
98 "MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type");
101 level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second),
NoFactory::get());
106 else if( name ==
"P" || name ==
"R") {
108 level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second),
NoFactory::get());
110 else if (name ==
"Nullspace")
113 level->Set(name, Teuchos::getValue<RCP<MultiVector > >(it2->second),
NoFactory::get());
117 else if(name ==
"Coordinates")
120 level->Set(name, Teuchos::getValue<RCP<Xpetra::MultiVector<double, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
123 #ifdef HAVE_MUELU_INTREPID2 124 else if (name ==
"pcoarsen: element to node map")
127 #ifdef HAVE_MUELU_INTREPID2_REFACTOR 128 level->Set(name, Teuchos::getValue<RCP<Kokkos::DynRankView<LocalOrdinal,typename Node::device_type> > >(it2->second),
NoFactory::get());
130 level->Set(name, Teuchos::getValue<RCP< Intrepid2::FieldContainer<LocalOrdinal> > >(it2->second),
NoFactory::get());
135 #ifdef HAVE_MUELU_MATLAB 138 size_t typeNameStart = name.find_first_not_of(
' ');
139 size_t typeNameEnd = name.find(
' ', typeNameStart);
140 std::string typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
141 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
143 if(typeName ==
"matrix")
144 level->Set(name, Teuchos::getValue<RCP<Matrix> >(it2->second),
NoFactory::get());
145 else if(typeName ==
"multivector")
146 level->Set(name, Teuchos::getValue<RCP<MultiVector> >(it2->second),
NoFactory::get());
147 else if(typeName ==
"map")
148 level->Set(name, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
149 else if(typeName ==
"ordinalvector")
150 level->Set(name, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
151 else if(typeName ==
"scalar")
152 level->Set(name, Teuchos::getValue<Scalar>(it2->second),
NoFactory::get());
153 else if(typeName ==
"double")
154 level->Set(name, Teuchos::getValue<double>(it2->second),
NoFactory::get());
155 else if(typeName ==
"complex")
156 level->Set(name, Teuchos::getValue<std::complex<double> >(it2->second),
NoFactory::get());
157 else if(typeName ==
"int")
158 level->Set(name, Teuchos::getValue<int>(it2->second),
NoFactory::get());
159 else if(typeName ==
"string")
160 level->Set(name, Teuchos::getValue<std::string>(it2->second),
NoFactory::get());
164 throw std::runtime_error(
"Invalid non-serializable data on list");
168 }
else if (paramList.isSublist(levelName) && levelName.find(
"user data") != std::string::npos) {
171 RCP<Level> level = H.
GetLevel(levelID);
174 TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(),
Exceptions::InvalidArgument,
"MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
177 const ParameterList& userList = paramList.sublist(levelName);
178 for (ParameterList::ConstIterator it2 = userList.begin(); it2 != userList.end(); it2++) {
179 const std::string& name = it2->first;
180 TEUCHOS_TEST_FOR_EXCEPTION(name !=
"P" && name !=
"R" &&
181 name !=
"Nullspace" && name !=
"Coordinates" &&
183 "MueLu::Utils::AddNonSerializableDataToHierarchy: user data parameter list contains unknown data type!");
184 if( name ==
"P" || name ==
"R") {
186 level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second),
NoFactory::get());
187 }
else if (name ==
"Nullspace") {
189 level->Set(name, Teuchos::getValue<RCP<MultiVector > >(it2->second),
NoFactory::get());
192 }
else if(name ==
"Coordinates") {
194 level->Set(name, Teuchos::getValue<RCP<Xpetra::MultiVector<double, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
198 size_t typeNameStart = name.find_first_not_of(
' ');
199 size_t typeNameEnd = name.find(
' ', typeNameStart);
200 std::string typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
201 size_t varNameStart = name.find_first_not_of(
' ', typeNameEnd);
202 std::string varName = name.substr(varNameStart, name.size());
203 std::transform(typeName.begin(), typeName.end(), typeName.begin(),
::tolower);
205 if(typeName ==
"matrix")
206 level->Set(varName, Teuchos::getValue<RCP<Matrix> >(it2->second),
NoFactory::get());
207 else if(typeName ==
"multivector")
208 level->Set(varName, Teuchos::getValue<RCP<MultiVector> >(it2->second),
NoFactory::get());
209 else if(typeName ==
"map")
210 level->Set(varName, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
211 else if(typeName ==
"ordinalvector")
212 level->Set(varName, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
213 else if(typeName ==
"scalar")
214 level->Set(varName, Teuchos::getValue<Scalar>(it2->second),
NoFactory::get());
215 else if(typeName ==
"double")
216 level->Set(varName, Teuchos::getValue<double>(it2->second),
NoFactory::get());
217 else if(typeName ==
"complex")
218 level->Set(varName, Teuchos::getValue<std::complex<double> >(it2->second),
NoFactory::get());
219 else if(typeName ==
"int")
220 level->Set(varName, Teuchos::getValue<int>(it2->second),
NoFactory::get());
221 else if(typeName ==
"string")
222 level->Set(varName, Teuchos::getValue<std::string>(it2->second),
NoFactory::get());
223 else if(typeName ==
"array<go>")
224 level->Set(varName, Teuchos::getValue<Array<GlobalOrdinal> > (it2->second),
NoFactory::get());
225 else if(typeName ==
"array<lo>")
226 level->Set(varName, Teuchos::getValue<Array<LocalOrdinal> >(it2->second),
NoFactory::get());
227 else if(typeName ==
"arrayrcp<lo>")
228 level->Set(varName, Teuchos::getValue<ArrayRCP<LocalOrdinal> >(it2->second),
NoFactory::get());
229 else if(typeName ==
"arrayrcp<go>")
230 level->Set(varName, Teuchos::getValue<ArrayRCP<GlobalOrdinal> >(it2->second),
NoFactory::get());
232 throw std::runtime_error(
"Invalid non-serializable data on list");
240 #define MUELU_HIERARCHY_UTILS_SHORT 241 #endif // MUELU_HIERARCHYHELPERS_DEF_HPP This class specifies the default factory that should generate some data on a Level if the data does n...
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
static void AddNonSerializableDataToHierarchy(HierarchyManager &HM, Hierarchy &H, const ParameterList &nonSerialList)
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)
Namespace for MueLu classes and methods.
bool IsParamMuemexVariable(const std::string &name)
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
static const NoFactory * get()
bool IsParamValidVariable(const std::string &name)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Exception throws to report invalid user entry.
static const RCP< const NoFactory > getRCP()
Static Get() functions.