MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_FineLevelInputDataFactory_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// Tobias Wiesner (tawiesn@sandia.gov)
42// Ray Tuminaro (rstumin@sandia.gov)
43//
44// ***********************************************************************
45//
46// @HEADER
47#ifndef PACKAGES_MUELU_SRC_MISC_MUELU_FINELEVELINPUTDATAFACTORY_DEF_HPP_
48#define PACKAGES_MUELU_SRC_MISC_MUELU_FINELEVELINPUTDATAFACTORY_DEF_HPP_
49
50#include "Xpetra_Matrix.hpp"
51
54#include "MueLu_Level.hpp"
55#include "MueLu_Monitor.hpp"
56
57namespace MueLu {
58
59 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
61 RCP<ParameterList> validParamList = rcp(new ParameterList());
62
63 // Variable name (e.g. A or P or Coordinates)
64 validParamList->set< std::string >("Variable", std::string("A"), "Variable name on all coarse levels (except the finest level).");
65
66 // Names of generating factories (on finest level and coarse levels)
67 validParamList->set< RCP<const FactoryBase> >("Fine level factory", Teuchos::null, "Generating factory of the fine level variable");
68 validParamList->set< RCP<const FactoryBase> >("Coarse level factory", Teuchos::null, "Generating factory for data on all coarse levels (except the finest)");
69
70 // Type of variable (see source code for a complete list of all available types)
71 validParamList->set<std::string> ("Variable type", std::string("Matrix"), "Type of variable");
72
73 return validParamList;
74 }
75
76 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
78
79 const ParameterList & pL = GetParameterList();
80
81 std::string variableName = "";
82 if(pL.isParameter("Variable"))
83 variableName = pL.get<std::string>("Variable");
84
85 std::string factoryName = "NoFactory";
86 if (currentLevel.GetLevelID() == 0) {
87 factoryName = "Fine level factory";
88 } else {
89 factoryName = "Coarse level factory";
90 }
91
92 TEUCHOS_TEST_FOR_EXCEPTION(variableName == "", MueLu::Exceptions::RuntimeError, "FineLevelInputDataFactory: no variable name provided. Please set \'Variable\' parameter in your input deck.");
93
94 // data must be specified in factory! (not in factory manager)
95 RCP<const FactoryBase> fact = GetFactory(factoryName);
96 currentLevel.DeclareInput(variableName, fact.get(), this);
97 }
98
99 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
101 FactoryMonitor m(*this, "InputUserData", currentLevel);
102
103 const ParameterList& pL = GetParameterList();
104
105 std::string variableName = "";
106 if (pL.isParameter("Variable"))
107 variableName = pL.get<std::string>("Variable");
108
109 std::string variableType = "";
110 if(pL.isParameter("Variable type"))
111 variableType = pL.get<std::string>("Variable type");
112
113 std::string factoryName = "NoFactory";
114 if (currentLevel.GetLevelID() == 0) {
115 factoryName = "Fine level factory";
116 } else {
117 factoryName = "Coarse level factory";
118 }
119 RCP<const FactoryBase> fact = GetFactory(factoryName);
120
121 GetOStream(Debug) << "Use " << variableName << " of type " << variableType << " from " << factoryName << "(" << fact.get() << ")" << std::endl;
122
123 // check data type
124 //std::string strType = currentLevel.GetTypeName(variableName, fact.get());
125 if (variableType == "int") {
126 int data = currentLevel.Get<int>(variableName, fact.get());
127 Set(currentLevel, variableName, data);
128 } else if (variableType == "double") {
129 double data = currentLevel.Get<double>(variableName, fact.get());
130 Set(currentLevel, variableName, data);
131 } else if (variableType == "string") {
132 std::string data = currentLevel.Get<std::string>(variableName, fact.get());
133 Set(currentLevel, variableName, data);
134 } else {
135 size_t npos = std::string::npos;
136
137 if (variableType.find("Aggregates") != npos) {
138 RCP<Aggregates> data = currentLevel.Get<RCP<Aggregates> >(variableName, fact.get());
139 Set(currentLevel, variableName, data);
140 }
141 else if (variableType.find("Graph") != npos) {
142 RCP<Graph> data = currentLevel.Get<RCP<Graph> >(variableName, fact.get());
143 Set(currentLevel, variableName, data);
144 }
145 else if (variableType.find("SmootherBase") != npos) {
146 RCP<SmootherBase> data = currentLevel.Get<RCP<SmootherBase> >(variableName, fact.get());
147 Set(currentLevel, variableName, data);
148 }
149 else if (variableType.find("SmootherPrototype") != npos) {
150 RCP<SmootherPrototype> data = currentLevel.Get<RCP<SmootherPrototype> >(variableName, fact.get());
151 Set(currentLevel, variableName, data);
152 }
153 else if (variableType.find("Export") != npos) {
154 RCP<Export> data = currentLevel.Get<RCP<Export> >(variableName, fact.get());
155 Set(currentLevel, variableName, data);
156 }
157 else if (variableType.find("Import") != npos) {
158 RCP<Import> data = currentLevel.Get<RCP<Import> >(variableName, fact.get());
159 Set(currentLevel, variableName, data);
160 }
161 else if (variableType.find("Map") != npos) {
162 RCP<Map> data = currentLevel.Get<RCP<Map> >(variableName, fact.get());
163 Set(currentLevel, variableName, data);
164 }
165 else if (variableType.find("Matrix") != npos) {
166 RCP<Matrix> data = currentLevel.Get<RCP<Matrix> >(variableName, fact.get());
167 Set(currentLevel, variableName, data);
168 }
169 else if (variableType.find("MultiVector") != npos) {
170 RCP<MultiVector> data = currentLevel.Get<RCP<MultiVector> >(variableName, fact.get());
171 Set(currentLevel, variableName, data);
172 }
173 else if (variableType.find("Operator") != npos) {
174 RCP<Operator> data = currentLevel.Get<RCP<Operator> >(variableName, fact.get());
175 Set(currentLevel, variableName, data);
176 }
177 else {
178 // TAW: is this working with empty procs?
179 TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "FineLevelInputDataFactory: cannot detect type of variable " << variableName << " generated by " << fact.get() << ". User provided type " << variableType );
180 }
181 }
182 }
183
184} //namespace MueLu
185
186#endif /* PACKAGES_MUELU_SRC_MISC_MUELU_FINELEVELINPUTDATAFACTORY_DEF_HPP_ */
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
void DeclareInput(Level &currentLevel) const
Input.
void Build(Level &currentLevel) const
Build method.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
Namespace for MueLu classes and methods.
@ Debug
Print additional debugging information.