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 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_HIERARCHYUTILS_DEF_HPP
47 #define MUELU_HIERARCHYUTILS_DEF_HPP
48 
49 #include "Teuchos_ScalarTraits.hpp"
50 
51 #include <Xpetra_Matrix.hpp>
52 #include <Xpetra_Operator.hpp>
53 
56 #include "MueLu_FactoryManager.hpp"
57 
58 // TODO/FIXME: DeclareInput(, **this**) cannot be used here
59 #ifdef HAVE_MUELU_INTREPID2
60 #include "Kokkos_DynRankView.hpp"
61 #endif
62 
63 namespace MueLu {
64 
65 // Copy object from one hierarchy to another calling AddNewLevel as appropriate.
66 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
67 void HierarchyUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::CopyBetweenHierarchies(Hierarchy& fromHierarchy, Hierarchy& toHierarchy, const std::string fromLabel, const std::string toLabel, const std::string dataType) {
68  // add any necessary levels
69  for (int i = toHierarchy.GetNumLevels(); i < fromHierarchy.GetNumLevels(); i++)
70  toHierarchy.AddNewLevel();
71 
72  for (int i = 0; i < fromHierarchy.GetNumLevels(); i++) {
73  RCP<Level> fromLevel = fromHierarchy.GetLevel(i);
74  RCP<Level> toLevel = toHierarchy.GetLevel(i);
75 
76  TEUCHOS_TEST_FOR_EXCEPTION(dataType != "RCP<Matrix>" && dataType != "RCP<const Import>", Exceptions::InvalidArgument,
77  std::string("MueLu::Utils::CopyBetweenHierarchies: unknown data type(") + dataType + ")");
78  if (fromLevel->IsAvailable(fromLabel)) {
79  if (dataType == "RCP<Matrix>") {
80  // Normally, we should only do
81  // toLevel->Set(toLabel,fromLevel->Get<RCP<Matrix> >(fromLabel));
82  // The logic below is meant to handle a special case when we
83  // repartition a processor away, leaving behind a RCP<Operator> on
84  // on the level instead of an RCP<Matrix>
85 
86  auto tempOp = fromLevel->Get<RCP<Operator>>(fromLabel);
87  auto tempMatrix = rcp_dynamic_cast<Matrix>(tempOp);
88  if (!tempMatrix.is_null())
89  toLevel->Set(toLabel, tempMatrix);
90  else
91  toLevel->Set(toLabel, tempOp);
92  }
93  if (dataType == "RCP<const Import>") {
94  toLevel->Set(toLabel, fromLevel->Get<RCP<const Import>>(fromLabel));
95  }
96  }
97  }
98 }
99 
100 // Adds the following non-serializable data (A,P,R,Nullspace,Coordinates) from level-specific sublist nonSerialList,
101 // calling AddNewLevel as appropriate.
102 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
106  realvaluedmultivector_type;
107 
108  for (ParameterList::ConstIterator nonSerialEntry = nonSerialList.begin(); nonSerialEntry != nonSerialList.end(); nonSerialEntry++) {
109  const std::string& levelName = nonSerialEntry->first;
110  // Check for match of the form "level X" where X is a positive integer
111  if (nonSerialList.isSublist(levelName) && levelName.find("level ") == 0 && levelName.size() > 6) {
112  int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
113  if (levelID > 0) {
114  // Do enough level adding so we can be sure to add the data to the right place
115  for (int i = H.GetNumLevels(); i <= levelID; i++)
116  H.AddNewLevel();
117  }
118  RCP<Level> level = H.GetLevel(levelID);
119 
120  RCP<FactoryManager> M = Teuchos::rcp_dynamic_cast<FactoryManager>(HM.GetFactoryManager(levelID));
121  TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
122 
123  // Grab the level sublist & loop over parameters
124  const ParameterList& levelList = nonSerialList.sublist(levelName);
125  for (ParameterList::ConstIterator levelListEntry = levelList.begin(); levelListEntry != levelList.end(); levelListEntry++) {
126  const std::string& name = levelListEntry->first;
127  TEUCHOS_TEST_FOR_EXCEPTION(name != "A" && name != "P" && name != "R" && name != "K" && name != "M" && name != "Mdiag" &&
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" &&
136  !IsParamMuemexVariable(name),
138  std::string("MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type(") + name + ")");
139 
140  // Get a valid communicator and lib
142  if (!level->GetComm().is_null())
143  comm = level->GetComm();
144  else if (level->IsAvailable("A")) {
145  RCP<Matrix> mat;
146  level->Get("A", mat);
147  comm = mat->getMap()->getComm();
148  } else {
149  RCP<Level> level0 = H.GetLevel(0);
150  if (!level0->GetComm().is_null())
151  comm = level0->GetComm();
152  else {
153  RCP<Matrix> mat;
154  level0->Get("A", mat);
155  comm = mat->getMap()->getComm();
156  }
157  }
158  Xpetra::UnderlyingLib lib = level->lib();
159 
160  if (name == "A") {
161  RCP<Matrix> mat;
162  if (levelListEntry->second.isType<std::string>())
163  // We might also want to read maps here.
164  mat = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read(Teuchos::getValue<std::string>(levelListEntry->second), lib, comm);
165  else
166  mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
167  level->Set(name, mat, NoFactory::get());
168  M->SetFactory(name, NoFactory::getRCP()); // TAW: not sure about this: be aware that this affects all levels
169  // However, A is accessible through NoFactory anyway, so it should
170  // be fine here.
171  } else if (name == "P" || name == "R" || name == "K" || name == "M") {
172  if (levelListEntry->second.isType<RCP<Operator>>()) {
173  RCP<Operator> mat;
174  mat = Teuchos::getValue<RCP<Operator>>(levelListEntry->second);
175 
176  RCP<const FactoryBase> fact = M->GetFactory(name);
177  level->AddKeepFlag(name, fact.get(), MueLu::UserData);
178  level->Set(name, mat, fact.get());
179 
180  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
181  level->Set(name, mat, NoFactory::get());
182  } else {
183  RCP<Matrix> mat;
184  if (levelListEntry->second.isType<std::string>())
185  // We might also want to read maps here.
186  mat = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read(Teuchos::getValue<std::string>(levelListEntry->second), lib, comm);
187  else
188  mat = Teuchos::getValue<RCP<Matrix>>(levelListEntry->second);
189 
190  RCP<const FactoryBase> fact = M->GetFactory(name);
191  level->AddKeepFlag(name, fact.get(), MueLu::UserData);
192  level->Set(name, mat, fact.get());
193 
194  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
195  level->Set(name, mat, NoFactory::get());
196  }
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") {
202  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
203  if (levelListEntry->second.isType<RCP<Operator>>())
204  level->Set(name, Teuchos::getValue<RCP<Operator>>(levelListEntry->second), NoFactory::get());
205  else
206  level->Set(name, Teuchos::getValue<RCP<Matrix>>(levelListEntry->second), NoFactory::get());
207  } else if (name == "Mdiag") {
208  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
209  level->Set(name, Teuchos::getValue<RCP<Vector>>(levelListEntry->second), NoFactory::get());
210  } else if (name == "Nullspace") {
211  RCP<MultiVector> vec;
212  if (levelListEntry->second.isType<std::string>()) {
213  TEUCHOS_ASSERT(level->IsAvailable("A"));
214  RCP<Matrix> mat;
215  level->Get("A", mat);
216  auto map = mat->getMap();
217  vec = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(Teuchos::getValue<std::string>(levelListEntry->second), map);
218  } else
219  vec = Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second);
220  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
221  level->Set(name, vec, NoFactory::get());
222  // M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here
223  // One should do this only in very special cases
224  } else if (name == "Coordinates") // Scalar of Coordinates MV is always double
225  {
227  if (levelListEntry->second.isType<std::string>()) {
228  TEUCHOS_ASSERT(level->IsAvailable("A"));
229  RCP<Matrix> mat;
230  level->Get("A", mat);
231  size_t blkSize = mat->GetFixedBlockSize();
232  RCP<const Map> nodeMap = mat->getRowMap();
233  if (blkSize > 1) {
234  // Create a nodal map, as coordinates have not been expanded to a DOF map yet.
235  RCP<const Map> dofMap = mat->getRowMap();
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);
240  ArrayView<const GO> GIDs = dofMap->getLocalElementList();
241 
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;
245 
247  nodeMap = MapFactory::Build(dofMap->lib(), INVALID, nodeGIDs(), indexBase, dofMap->getComm());
248  }
249  vec = Xpetra::IO<typename Teuchos::ScalarTraits<Scalar>::coordinateType, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(Teuchos::getValue<std::string>(levelListEntry->second), nodeMap);
250  } else
251  vec = Teuchos::getValue<RCP<realvaluedmultivector_type>>(levelListEntry->second);
252  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
253  level->Set(name, vec, NoFactory::get());
254  // M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here
255  } else if (name == "Node Comm") {
256  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
257  level->Set(name, Teuchos::getValue<RCP<const Teuchos::Comm<int>>>(levelListEntry->second), NoFactory::get());
258  } else if (name == "DualNodeID2PrimalNodeID") {
259  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
260  level->Set(name, Teuchos::getValue<RCP<std::map<LO, LO>>>(levelListEntry->second), NoFactory::get());
261  } else if (name == "Primal interface DOF map") {
262  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
263  level->Set(name, Teuchos::getValue<RCP<const Map>>(levelListEntry->second), NoFactory::get());
264  } else if (name == "dropMap1") {
265  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
266  level->Set(name, Teuchos::getValue<RCP<const Map>>(levelListEntry->second), NoFactory::get());
267  } else if (name == "dropMap2") {
268  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
269  level->Set(name, Teuchos::getValue<RCP<const Map>>(levelListEntry->second), NoFactory::get());
270  }
271 #ifdef HAVE_MUELU_INTREPID2
272  else if (name == "pcoarsen: element to node map") {
273  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
274  level->Set(name, Teuchos::getValue<RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(levelListEntry->second), NoFactory::get());
275  }
276 #endif
277  else
278 #ifdef HAVE_MUELU_MATLAB
279  {
280  // Custom variable for Muemex
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);
285  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
286  if (typeName == "matrix")
287  level->Set(name, Teuchos::getValue<RCP<Matrix>>(levelListEntry->second), NoFactory::get());
288  else if (typeName == "multivector")
289  level->Set(name, Teuchos::getValue<RCP<MultiVector>>(levelListEntry->second), NoFactory::get());
290  else if (typeName == "map")
291  level->Set(name, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>>(levelListEntry->second), NoFactory::get());
292  else if (typeName == "ordinalvector")
293  level->Set(name, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>>(levelListEntry->second), NoFactory::get());
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());
304  }
305 #else
306  {
307  throw std::runtime_error("Invalid non-serializable data on list");
308  }
309 #endif
310  }
311  } else if (nonSerialList.isSublist(levelName) && levelName.find("user data") != std::string::npos) {
312  // So far only put data on level 0
313  int levelID = 0;
314  RCP<Level> level = H.GetLevel(levelID);
315 
316  RCP<FactoryManager> M = Teuchos::rcp_dynamic_cast<FactoryManager>(HM.GetFactoryManager(levelID));
317  TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
318 
319  // Grab the user data sublist & loop over parameters
320  const ParameterList& userList = nonSerialList.sublist(levelName);
321  for (ParameterList::ConstIterator userListEntry = userList.begin(); userListEntry != userList.end(); userListEntry++) {
322  const std::string& name = userListEntry->first;
323  TEUCHOS_TEST_FOR_EXCEPTION(name != "P" && name != "R" && name != "K" && name != "M" && name != "Mdiag" &&
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" &&
333  !IsParamValidVariable(name),
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") {
342  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
343  level->Set(name, Teuchos::getValue<RCP<Matrix>>(userListEntry->second), NoFactory::get());
344  } else if (name == "Mdiag") {
345  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
346  level->Set(name, Teuchos::getValue<RCP<Vector>>(userListEntry->second), NoFactory::get());
347  } else if (name == "Nullspace") {
348  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
349  level->Set(name, Teuchos::getValue<RCP<MultiVector>>(userListEntry->second), NoFactory::get());
350  // M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here
351  // One should do this only in very special cases
352  } else if (name == "Coordinates") { // Scalar of Coordinates MV is always double
353  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
354  level->Set(name, Teuchos::getValue<RCP<realvaluedmultivector_type>>(userListEntry->second), NoFactory::get());
355  } else if (name == "Node Comm") {
356  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
357  level->Set(name, Teuchos::getValue<RCP<const Teuchos::Comm<int>>>(userListEntry->second), NoFactory::get());
358  } else if (name == "DualNodeID2PrimalNodeID") {
359  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
360  level->Set(name, Teuchos::getValue<RCP<std::map<LO, LO>>>(userListEntry->second), NoFactory::get());
361  } else if (name == "Primal interface DOF map") {
362  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
363  level->Set(name, Teuchos::getValue<RCP<const Map>>(userListEntry->second), NoFactory::get());
364  } else if (name == "dropMap1") {
365  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
366  level->Set(name, Teuchos::getValue<RCP<const Map>>(userListEntry->second), NoFactory::get());
367  } else if (name == "dropMap2") {
368  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
369  level->Set(name, Teuchos::getValue<RCP<const Map>>(userListEntry->second), NoFactory::get());
370  }
371 #ifdef HAVE_MUELU_INTREPID2
372  else if (name == "pcoarsen: element to node map") {
373  level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData);
374  level->Set(name, Teuchos::getValue<RCP<Kokkos::DynRankView<LocalOrdinal, typename Node::device_type>>>(userListEntry->second), NoFactory::get());
375  }
376 #endif
377  else if (name == "output stream") {
378  H.SetMueLuOStream(Teuchos::getValue<RCP<Teuchos::FancyOStream>>(userListEntry->second));
379  } else {
380  // Custom variable
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);
387  level->AddKeepFlag(varName, NoFactory::get(), MueLu::UserData);
388  if (typeName == "matrix")
389  level->Set(varName, Teuchos::getValue<RCP<Matrix>>(userListEntry->second), NoFactory::get());
390  else if (typeName == "multivector")
391  level->Set(varName, Teuchos::getValue<RCP<MultiVector>>(userListEntry->second), NoFactory::get());
392  else if (typeName == "vector")
393  level->Set(varName, Teuchos::getValue<RCP<Vector>>(userListEntry->second), NoFactory::get());
394  else if (typeName == "map")
395  level->Set(varName, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>>(userListEntry->second), NoFactory::get());
396  else if (typeName == "ordinalvector")
397  level->Set(varName, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>>(userListEntry->second), NoFactory::get());
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>")
409  level->Set(varName, Teuchos::getValue<Array<GlobalOrdinal>>(userListEntry->second), NoFactory::get());
410  else if (typeName == "array<lo>")
411  level->Set(varName, Teuchos::getValue<Array<LocalOrdinal>>(userListEntry->second), NoFactory::get());
412  else if (typeName == "arrayrcp<lo>")
413  level->Set(varName, Teuchos::getValue<ArrayRCP<LocalOrdinal>>(userListEntry->second), NoFactory::get());
414  else if (typeName == "arrayrcp<go>")
415  level->Set(varName, Teuchos::getValue<ArrayRCP<GlobalOrdinal>>(userListEntry->second), NoFactory::get());
416  else
417  throw std::runtime_error("Invalid non-serializable data on list");
418  }
419  }
420  // level->print(std::cout, MueLu::Debug);
421  }
422  }
423 }
424 } // namespace MueLu
425 
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-&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
#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
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)
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)
static const RCP< const NoFactory > getRCP()
Static Get() functions.
bool is_null() const