MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_FineLevelInputDataFactory_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 PACKAGES_MUELU_SRC_MISC_MUELU_FINELEVELINPUTDATAFACTORY_DEF_HPP_
11 #define PACKAGES_MUELU_SRC_MISC_MUELU_FINELEVELINPUTDATAFACTORY_DEF_HPP_
12 
13 #include "Xpetra_Matrix.hpp"
14 
16 #include "MueLu_Level.hpp"
17 #include "MueLu_Monitor.hpp"
18 
19 namespace MueLu {
20 
21 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
23  RCP<ParameterList> validParamList = rcp(new ParameterList());
24 
25  // Variable name (e.g. A or P or Coordinates)
26  validParamList->set<std::string>("Variable", std::string("A"), "Variable name on all coarse levels (except the finest level).");
27 
28  // Names of generating factories (on finest level and coarse levels)
29  validParamList->set<RCP<const FactoryBase> >("Fine level factory", Teuchos::null, "Generating factory of the fine level variable");
30  validParamList->set<RCP<const FactoryBase> >("Coarse level factory", Teuchos::null, "Generating factory for data on all coarse levels (except the finest)");
31 
32  // Type of variable (see source code for a complete list of all available types)
33  validParamList->set<std::string>("Variable type", std::string("Matrix"), "Type of variable");
34 
35  return validParamList;
36 }
37 
38 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
40  const ParameterList& pL = GetParameterList();
41 
42  std::string variableName = "";
43  if (pL.isParameter("Variable"))
44  variableName = pL.get<std::string>("Variable");
45 
46  std::string factoryName = "NoFactory";
47  if (currentLevel.GetLevelID() == 0) {
48  factoryName = "Fine level factory";
49  } else {
50  factoryName = "Coarse level factory";
51  }
52 
53  TEUCHOS_TEST_FOR_EXCEPTION(variableName == "", MueLu::Exceptions::RuntimeError, "FineLevelInputDataFactory: no variable name provided. Please set \'Variable\' parameter in your input deck.");
54 
55  // data must be specified in factory! (not in factory manager)
56  RCP<const FactoryBase> fact = GetFactory(factoryName);
57  currentLevel.DeclareInput(variableName, fact.get(), this);
58 }
59 
60 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
62  FactoryMonitor m(*this, "InputUserData", currentLevel);
63 
64  const ParameterList& pL = GetParameterList();
65 
66  std::string variableName = "";
67  if (pL.isParameter("Variable"))
68  variableName = pL.get<std::string>("Variable");
69 
70  std::string variableType = "";
71  if (pL.isParameter("Variable type"))
72  variableType = pL.get<std::string>("Variable type");
73 
74  std::string factoryName = "NoFactory";
75  if (currentLevel.GetLevelID() == 0) {
76  factoryName = "Fine level factory";
77  } else {
78  factoryName = "Coarse level factory";
79  }
80  RCP<const FactoryBase> fact = GetFactory(factoryName);
81 
82  GetOStream(Debug) << "Use " << variableName << " of type " << variableType << " from " << factoryName << "(" << fact.get() << ")" << std::endl;
83 
84  // check data type
85  // std::string strType = currentLevel.GetTypeName(variableName, fact.get());
86  if (variableType == "int") {
87  int data = currentLevel.Get<int>(variableName, fact.get());
88  Set(currentLevel, variableName, data);
89  } else if (variableType == "double") {
90  double data = currentLevel.Get<double>(variableName, fact.get());
91  Set(currentLevel, variableName, data);
92  } else if (variableType == "string") {
93  std::string data = currentLevel.Get<std::string>(variableName, fact.get());
94  Set(currentLevel, variableName, data);
95  } else {
96  size_t npos = std::string::npos;
97 
98  if (variableType.find("Aggregates") != npos) {
99  RCP<Aggregates> data = currentLevel.Get<RCP<Aggregates> >(variableName, fact.get());
100  Set(currentLevel, variableName, data);
101  } else if (variableType.find("SmootherBase") != npos) {
102  RCP<SmootherBase> data = currentLevel.Get<RCP<SmootherBase> >(variableName, fact.get());
103  Set(currentLevel, variableName, data);
104  } else if (variableType.find("SmootherPrototype") != npos) {
105  RCP<SmootherPrototype> data = currentLevel.Get<RCP<SmootherPrototype> >(variableName, fact.get());
106  Set(currentLevel, variableName, data);
107  } else if (variableType.find("Export") != npos) {
108  RCP<Export> data = currentLevel.Get<RCP<Export> >(variableName, fact.get());
109  Set(currentLevel, variableName, data);
110  } else if (variableType.find("Import") != npos) {
111  RCP<Import> data = currentLevel.Get<RCP<Import> >(variableName, fact.get());
112  Set(currentLevel, variableName, data);
113  } else if (variableType.find("Map") != npos) {
114  RCP<Map> data = currentLevel.Get<RCP<Map> >(variableName, fact.get());
115  Set(currentLevel, variableName, data);
116  } else if (variableType.find("Matrix") != npos) {
117  RCP<Matrix> data = currentLevel.Get<RCP<Matrix> >(variableName, fact.get());
118  Set(currentLevel, variableName, data);
119  } else if (variableType.find("MultiVector") != npos) {
120  RCP<MultiVector> data = currentLevel.Get<RCP<MultiVector> >(variableName, fact.get());
121  Set(currentLevel, variableName, data);
122  } else if (variableType.find("Operator") != npos) {
123  RCP<Operator> data = currentLevel.Get<RCP<Operator> >(variableName, fact.get());
124  Set(currentLevel, variableName, data);
125  } else {
126  // TAW: is this working with empty procs?
127  TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "FineLevelInputDataFactory: cannot detect type of variable " << variableName << " generated by " << fact.get() << ". User provided type " << variableType);
128  }
129  }
130 }
131 
132 } // namespace MueLu
133 
134 #endif /* PACKAGES_MUELU_SRC_MISC_MUELU_FINELEVELINPUTDATAFACTORY_DEF_HPP_ */
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.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Print additional debugging information.
T * get() const
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
void Build(Level &currentLevel) const
Build method.
void DeclareInput(Level &currentLevel) const
Input.
int GetLevelID() const
Return level number.
Definition: MueLu_Level.cpp:51
Exception throws to report errors in the internal logical of the program.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()