MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_HierarchyUtils_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_HIERARCHYUTILS_DEF_HPP
11 #define MUELU_HIERARCHYUTILS_DEF_HPP
12 
13 #include "Teuchos_ScalarTraits.hpp"
14 
15 #include <Xpetra_Matrix.hpp>
16 #include <Xpetra_Operator.hpp>
17 
19 #include "MueLu_HierarchyManager.hpp"
20 #include "MueLu_FactoryManager.hpp"
21 
22 // TODO/FIXME: DeclareInput(, **this**) cannot be used here
23 #ifdef HAVE_MUELU_INTREPID2
24 #include "Kokkos_DynRankView.hpp"
25 #endif
26 
27 namespace MueLu {
28 
29 // Copy object from one level to another
30 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
31 void HierarchyUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::CopyBetweenLevels(Level& fromLevel, Level& toLevel, const std::string fromLabel, const std::string toLabel, const std::string dataType) {
32  TEUCHOS_TEST_FOR_EXCEPTION(dataType != "RCP<Matrix>" && dataType != "RCP<const Import>", Exceptions::InvalidArgument,
33  std::string("MueLu::Utils::CopyBetweenLevels: unknown data type(") + dataType + ")");
34 
35  if (!fromLevel.IsAvailable(fromLabel)) return;
36 
37  if (dataType == "RCP<Matrix>") {
38  // Normally, we should only do
39  // toLevel->Set(toLabel,fromLevel->Get<RCP<Matrix> >(fromLabel));
40  // The logic below is meant to handle a special case when we
41  // repartition a processor away, leaving behind a RCP<Operator> on
42  // on the level instead of an RCP<Matrix>
43 
44  auto tempOp = fromLevel.Get<RCP<Operator>>(fromLabel);
45  auto tempMatrix = rcp_dynamic_cast<Matrix>(tempOp);
46  if (!tempMatrix.is_null())
47  toLevel.Set(toLabel, tempMatrix);
48  else
49  toLevel.Set(toLabel, tempOp);
50  }
51 
52  if (dataType == "RCP<const Import>") {
53  toLevel.Set(toLabel, fromLevel.Get<RCP<const Import>>(fromLabel));
54  }
55 }
56 
57 // Copy object from one hierarchy to another calling AddNewLevel as appropriate.
58 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
59 void HierarchyUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::CopyBetweenHierarchies(Hierarchy& fromHierarchy, Hierarchy& toHierarchy, const std::string fromLabel, const std::string toLabel, const std::string dataType) {
60  // add any necessary levels
61  for (int i = toHierarchy.GetNumLevels(); i < fromHierarchy.GetNumLevels(); i++)
62  toHierarchy.AddNewLevel();
63 
64  for (int i = 0; i < fromHierarchy.GetNumLevels(); i++) {
65  RCP<Level> fromLevel = fromHierarchy.GetLevel(i);
66  RCP<Level> toLevel = toHierarchy.GetLevel(i);
67 
68  CopyBetweenLevels(*fromLevel, *toLevel, fromLabel, toLabel, dataType);
69  }
70 }
71 
72 // Adds the following non-serializable data (A,P,R,Nullspace,Coordinates) from level-specific sublist nonSerialList,
73 // calling AddNewLevel as appropriate.
74 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
78  realvaluedmultivector_type;
79 
80  for (ParameterList::ConstIterator nonSerialEntry = nonSerialList.begin(); nonSerialEntry != nonSerialList.end(); nonSerialEntry++) {
81  const std::string& levelName = nonSerialEntry->first;
82  // Check for match of the form "level X" where X is a positive integer
83  if (nonSerialList.isSublist(levelName) && levelName.find("level ") == 0 && levelName.size() > 6) {
84  int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
85  if (levelID > 0) {
86  // Do enough level adding so we can be sure to add the data to the right place
87  for (int i = H.GetNumLevels(); i <= levelID; i++)
88  H.AddNewLevel();
89  }
90  RCP<Level> level = H.GetLevel(levelID);
91 
92  RCP<FactoryManager> M = Teuchos::rcp_dynamic_cast<FactoryManager>(HM.GetFactoryManager(levelID));
93  TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
94 
95  // Grab the level sublist & loop over parameters
96  const ParameterList& levelList = nonSerialList.sublist(levelName);
97  for (ParameterList::ConstIterator levelListEntry = levelList.begin(); levelListEntry != levelList.end(); levelListEntry++) {
98  const std::string& name = levelListEntry->first;
99  TEUCHOS_TEST_FOR_EXCEPTION(name != "A" && name != "P" && name != "R" && name != "K" && name != "M" && name != "Mdiag" &&
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" &&
108  !IsParamMuemexVariable(name),
110  std::string("MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type(") + name + ")");
111 
112  // Get a valid communicator and lib
114  if (!level->GetComm().is_null())
115  comm = level->GetComm();
116  else if (level->IsAvailable("A")) {
117  RCP<Matrix> mat;
118  level->Get("A", mat);
119  comm = mat->getMap()->getComm();
120  } else {
121  RCP<Level> level0 = H.GetLevel(0);
122  if (!level0->GetComm().is_null())
123  comm = level0->GetComm();
124  else {
125  RCP<Matrix> mat;
126  level0->Get("A", mat);
127  comm = mat->getMap()->getComm();
128  }
129  }
130  Xpetra::UnderlyingLib lib = level->lib();
131 
132  if (name == "A") {
133  RCP<Matrix> mat;
134  if (levelListEntry->second.isType<std::string>())
135  // We might also want to read maps here.
136  mat = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read(Teuchos::getValue<std::string>(levelListEntry->second), lib, comm);
137  else
138  mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
139  level->Set(name, mat, NoFactory::get());
140  M->SetFactory(name, NoFactory::getRCP()); // TAW: not sure about this: be aware that this affects all levels
141  // However, A is accessible through NoFactory anyway, so it should
142  // be fine here.
143  } else if (name == "P" || name == "R" || name == "K" || name == "M") {
144  if (levelListEntry->second.isType<RCP<Operator>>()) {
145  RCP<Operator> mat;
146  mat = Teuchos::getValue<RCP<Operator>>(levelListEntry->second);
147 
148  RCP<const FactoryBase> fact = M->GetFactory(name);
149  level->AddKeepFlag(name, fact.get(), MueLu::UserData);
150  level->Set(name, mat, fact.get());
151 
152  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
153  level->Set(name, mat, NoFactory::get());
154  } else {
155  RCP<Matrix> mat;
156  if (levelListEntry->second.isType<std::string>())
157  // We might also want to read maps here.
158  mat = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read(Teuchos::getValue<std::string>(levelListEntry->second), lib, comm);
159  else
160  mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
161 
162  RCP<const FactoryBase> fact = M->GetFactory(name);
163  level->AddKeepFlag(name, fact.get(), MueLu::UserData);
164  level->Set(name, mat, fact.get());
165 
166  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
167  level->Set(name, mat, NoFactory::get());
168  }
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") {
174  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
175  if (levelListEntry->second.isType<RCP<Operator>>())
176  level->Set(name, Teuchos::getValue<RCP<Operator>>(levelListEntry->second), NoFactory::get());
177  else
178  level->Set(name, Teuchos::getValue<RCP<Matrix>>(levelListEntry->second), NoFactory::get());
179  } else if (name == "Mdiag") {
180  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
181  level->Set(name, Teuchos::getValue<RCP<Vector>>(levelListEntry->second), NoFactory::get());
182  } else if (name == "Nullspace") {
183  RCP<MultiVector> vec;
184  if (levelListEntry->second.isType<std::string>()) {
185  TEUCHOS_ASSERT(level->IsAvailable("A"));
186  RCP<Matrix> mat;
187  level->Get("A", mat);
188  auto map = mat->getMap();
189  vec = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(Teuchos::getValue<std::string>(levelListEntry->second), map);
190  } else
191  vec = Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second);
192  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
193  level->Set(name, vec, NoFactory::get());
194  // M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here
195  // One should do this only in very special cases
196  } else if (name == "Material") {
197  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
198  level->Set(name, Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second), NoFactory::get());
199  } else if (name == "BlockNumber") {
200  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
201  level->Set(name, Teuchos::getValue<RCP<LocalOrdinalVector>>(levelListEntry->second), NoFactory::get());
202  } else if (name == "Coordinates") // Scalar of Coordinates MV is always double
203  {
205  if (levelListEntry->second.isType<std::string>()) {
206  TEUCHOS_ASSERT(level->IsAvailable("A"));
207  RCP<Matrix> mat;
208  level->Get("A", mat);
209  size_t blkSize = mat->GetFixedBlockSize();
210  RCP<const Map> nodeMap = mat->getRowMap();
211  if (blkSize > 1) {
212  // Create a nodal map, as coordinates have not been expanded to a DOF map yet.
213  RCP<const Map> dofMap = mat->getRowMap();
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);
218  ArrayView<const GO> GIDs = dofMap->getLocalElementList();
219 
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;
223 
225  nodeMap = MapFactory::Build(dofMap->lib(), INVALID, nodeGIDs(), indexBase, dofMap->getComm());
226  }
227  vec = Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::coordinateType, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(Teuchos::getValue<std::string>(levelListEntry->second), nodeMap);
228  } else
229  vec = Teuchos::getValue<RCP<realvaluedmultivector_type>>(levelListEntry->second);
230  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
231  level->Set(name, vec, NoFactory::get());
232  // M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here
233  } else if (name == "Node Comm") {
234  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
235  level->Set(name, Teuchos::getValue<RCP<const Teuchos::Comm<int>>>(levelListEntry->second), NoFactory::get());
236  } else if (name == "DualNodeID2PrimalNodeID") {
237  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
238  level->Set(name, Teuchos::getValue<RCP<std::map<LO, LO>>>(levelListEntry->second), NoFactory::get());
239  } else if (name == "Primal interface DOF map") {
240  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
241  level->Set(name, Teuchos::getValue<RCP<const Map>>(levelListEntry->second), NoFactory::get());
242  } else if (name == "dropMap1") {
243  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
244  level->Set(name, Teuchos::getValue<RCP<const Map>>(levelListEntry->second), NoFactory::get());
245  } else if (name == "dropMap2") {
246  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
247  level->Set(name, Teuchos::getValue<RCP<const Map>>(levelListEntry->second), NoFactory::get());
248  }
249 #ifdef HAVE_MUELU_INTREPID2
250  else if (name == "pcoarsen: element to node map") {
251  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
252  level->Set(name, Teuchos::getValue<RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(levelListEntry->second), NoFactory::get());
253  }
254 #endif
255  else
256 #ifdef HAVE_MUELU_MATLAB
257  {
258  // Custom variable for Muemex
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);
263  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
264  if (typeName == "matrix")
265  level->Set(name, Teuchos::getValue<RCP<Matrix>>(levelListEntry->second), NoFactory::get());
266  else if (typeName == "multivector")
267  level->Set(name, Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second), NoFactory::get());
268  else if (typeName == "map")
269  level->Set(name, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>>(levelListEntry->second), NoFactory::get());
270  else if (typeName == "ordinalvector")
271  level->Set(name, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>>(levelListEntry->second), NoFactory::get());
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());
282  }
283 #else
284  {
285  throw std::runtime_error("Invalid non-serializable data on list");
286  }
287 #endif
288  }
289  } else if (nonSerialList.isSublist(levelName) && levelName.find("user data") != std::string::npos) {
290  // So far only put data on level 0
291  int levelID = 0;
292  RCP<Level> level = H.GetLevel(levelID);
293 
294  RCP<FactoryManager> M = Teuchos::rcp_dynamic_cast<FactoryManager>(HM.GetFactoryManager(levelID));
295  TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
296 
297  // Grab the user data sublist & loop over parameters
298  const ParameterList& userList = nonSerialList.sublist(levelName);
299  for (ParameterList::ConstIterator userListEntry = userList.begin(); userListEntry != userList.end(); userListEntry++) {
300  const std::string& name = userListEntry->first;
301  // Check if the name starts with "Nullspace", has length > 9, and the last character is a digit
302  bool isNumberedNullspace = (name.rfind("Nullspace", 0) == 0 && name.length() > 9 && std::isdigit(name.back(), std::locale::classic()));
303 
304  TEUCHOS_TEST_FOR_EXCEPTION(name != "P" && name != "R" && name != "K" && name != "M" && name != "Mdiag" &&
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 &&
316  !IsParamValidVariable(name),
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") {
325  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
326  level->Set(name, Teuchos::getValue<RCP<Matrix>>(userListEntry->second), NoFactory::get());
327  } else if (name == "Mdiag") {
328  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
329  level->Set(name, Teuchos::getValue<RCP<Vector>>(userListEntry->second), NoFactory::get());
330  } else if (name == "Nullspace" || isNumberedNullspace) {
331  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
332  level->Set(name, Teuchos::getValue<RCP<MultiVector>>(userListEntry->second), NoFactory::get());
333  // M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here
334  // One should do this only in very special cases
335  } else if (name == "Material") {
336  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
337  level->Set(name, Teuchos::getValue<RCP<MultiVector>>(userListEntry->second), NoFactory::get());
338  } else if (name == "BlockNumber") {
339  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
340  level->Set(name, Teuchos::getValue<RCP<LocalOrdinalVector>>(userListEntry->second), NoFactory::get());
341  } else if (name == "Coordinates") { // Scalar of Coordinates MV is always double
342  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
343  level->Set(name, Teuchos::getValue<RCP<realvaluedmultivector_type>>(userListEntry->second), NoFactory::get());
344  } else if (name == "Node Comm") {
345  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
346  level->Set(name, Teuchos::getValue<RCP<const Teuchos::Comm<int>>>(userListEntry->second), NoFactory::get());
347  } else if (name == "DualNodeID2PrimalNodeID") {
348  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
349  level->Set(name, Teuchos::getValue<RCP<std::map<LO, LO>>>(userListEntry->second), NoFactory::get());
350  } else if (name == "Primal interface DOF map") {
351  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
352  level->Set(name, Teuchos::getValue<RCP<const Map>>(userListEntry->second), NoFactory::get());
353  } else if (name == "dropMap1") {
354  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
355  level->Set(name, Teuchos::getValue<RCP<const Map>>(userListEntry->second), NoFactory::get());
356  } else if (name == "dropMap2") {
357  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
358  level->Set(name, Teuchos::getValue<RCP<const Map>>(userListEntry->second), NoFactory::get());
359  }
360 #ifdef HAVE_MUELU_INTREPID2
361  else if (name == "pcoarsen: element to node map") {
362  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
363  level->Set(name, Teuchos::getValue<RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(userListEntry->second), NoFactory::get());
364  }
365 #endif
366  else if (name == "output stream") {
367  H.SetMueLuOStream(Teuchos::getValue<RCP<Teuchos::FancyOStream>>(userListEntry->second));
368  } else {
369  // Custom variable
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);
376  level->AddKeepFlag(varName, NoFactory::get(), MueLu::UserData);
377  if (typeName == "matrix")
378  level->Set(varName, Teuchos::getValue<RCP<Matrix>>(userListEntry->second), NoFactory::get());
379  else if (typeName == "multivector")
380  level->Set(varName, Teuchos::getValue<RCP<MultiVector>>(userListEntry->second), NoFactory::get());
381  else if (typeName == "vector")
382  level->Set(varName, Teuchos::getValue<RCP<Vector>>(userListEntry->second), NoFactory::get());
383  else if (typeName == "map")
384  level->Set(varName, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>>(userListEntry->second), NoFactory::get());
385  else if (typeName == "ordinalvector")
386  level->Set(varName, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>>(userListEntry->second), NoFactory::get());
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>")
398  level->Set(varName, Teuchos::getValue<Array<GlobalOrdinal>>(userListEntry->second), NoFactory::get());
399  else if (typeName == "array<lo>")
400  level->Set(varName, Teuchos::getValue<Array<LocalOrdinal>>(userListEntry->second), NoFactory::get());
401  else if (typeName == "arrayrcp<lo>")
402  level->Set(varName, Teuchos::getValue<ArrayRCP<LocalOrdinal>>(userListEntry->second), NoFactory::get());
403  else if (typeName == "arrayrcp<go>")
404  level->Set(varName, Teuchos::getValue<ArrayRCP<GlobalOrdinal>>(userListEntry->second), NoFactory::get());
405  else
406  throw std::runtime_error("Invalid non-serializable data on list");
407  }
408  }
409  // level->print(std::cout, MueLu::Debug);
410  }
411  }
412 }
413 } // namespace MueLu
414 
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-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; 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.
GlobalOrdinal GO
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(&quot;data&quot;, data) is used...
T * get() const
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.
MueLu::DefaultNode Node
static const NoFactory * get()
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
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)
size_t global_size_t
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&#39;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)
bool is_null() const