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
53#include "MueLu_Level.hpp"
54#include "MueLu_Monitor.hpp"
55
56namespace MueLu {
57
58 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
60 RCP<ParameterList> validParamList = rcp(new ParameterList());
61
62 // Variable name (e.g. A or P or Coordinates)
63 validParamList->set< std::string >("Variable", std::string("A"), "Variable name on all coarse levels (except the finest level).");
64
65 // Names of generating factories (on finest level and coarse levels)
66 validParamList->set< RCP<const FactoryBase> >("Fine level factory", Teuchos::null, "Generating factory of the fine level variable");
67 validParamList->set< RCP<const FactoryBase> >("Coarse level factory", Teuchos::null, "Generating factory for data on all coarse levels (except the finest)");
68
69 // Type of variable (see source code for a complete list of all available types)
70 validParamList->set<std::string> ("Variable type", std::string("Matrix"), "Type of variable");
71
72 return validParamList;
73 }
74
75 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
77
78 const ParameterList & pL = GetParameterList();
79
80 std::string variableName = "";
81 if(pL.isParameter("Variable"))
82 variableName = pL.get<std::string>("Variable");
83
84 std::string factoryName = "NoFactory";
85 if (currentLevel.GetLevelID() == 0) {
86 factoryName = "Fine level factory";
87 } else {
88 factoryName = "Coarse level factory";
89 }
90
91 TEUCHOS_TEST_FOR_EXCEPTION(variableName == "", MueLu::Exceptions::RuntimeError, "FineLevelInputDataFactory: no variable name provided. Please set \'Variable\' parameter in your input deck.");
92
93 // data must be specified in factory! (not in factory manager)
94 RCP<const FactoryBase> fact = GetFactory(factoryName);
95 currentLevel.DeclareInput(variableName, fact.get(), this);
96 }
97
98 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
100 FactoryMonitor m(*this, "InputUserData", currentLevel);
101
102 const ParameterList& pL = GetParameterList();
103
104 std::string variableName = "";
105 if (pL.isParameter("Variable"))
106 variableName = pL.get<std::string>("Variable");
107
108 std::string variableType = "";
109 if(pL.isParameter("Variable type"))
110 variableType = pL.get<std::string>("Variable type");
111
112 std::string factoryName = "NoFactory";
113 if (currentLevel.GetLevelID() == 0) {
114 factoryName = "Fine level factory";
115 } else {
116 factoryName = "Coarse level factory";
117 }
118 RCP<const FactoryBase> fact = GetFactory(factoryName);
119
120 GetOStream(Debug) << "Use " << variableName << " of type " << variableType << " from " << factoryName << "(" << fact.get() << ")" << std::endl;
121
122 // check data type
123 //std::string strType = currentLevel.GetTypeName(variableName, fact.get());
124 if (variableType == "int") {
125 int data = currentLevel.Get<int>(variableName, fact.get());
126 Set(currentLevel, variableName, data);
127 } else if (variableType == "double") {
128 double data = currentLevel.Get<double>(variableName, fact.get());
129 Set(currentLevel, variableName, data);
130 } else if (variableType == "string") {
131 std::string data = currentLevel.Get<std::string>(variableName, fact.get());
132 Set(currentLevel, variableName, data);
133 } else {
134 size_t npos = std::string::npos;
135
136 if (variableType.find("Aggregates") != npos) {
137 RCP<Aggregates> data = currentLevel.Get<RCP<Aggregates> >(variableName, fact.get());
138 Set(currentLevel, variableName, data);
139 }
140 else if (variableType.find("Graph") != npos) {
141 RCP<Graph> data = currentLevel.Get<RCP<Graph> >(variableName, fact.get());
142 Set(currentLevel, variableName, data);
143 }
144 else if (variableType.find("SmootherBase") != npos) {
145 RCP<SmootherBase> data = currentLevel.Get<RCP<SmootherBase> >(variableName, fact.get());
146 Set(currentLevel, variableName, data);
147 }
148 else if (variableType.find("SmootherPrototype") != npos) {
149 RCP<SmootherPrototype> data = currentLevel.Get<RCP<SmootherPrototype> >(variableName, fact.get());
150 Set(currentLevel, variableName, data);
151 }
152 else if (variableType.find("Export") != npos) {
153 RCP<Export> data = currentLevel.Get<RCP<Export> >(variableName, fact.get());
154 Set(currentLevel, variableName, data);
155 }
156 else if (variableType.find("Import") != npos) {
157 RCP<Import> data = currentLevel.Get<RCP<Import> >(variableName, fact.get());
158 Set(currentLevel, variableName, data);
159 }
160 else if (variableType.find("Map") != npos) {
161 RCP<Map> data = currentLevel.Get<RCP<Map> >(variableName, fact.get());
162 Set(currentLevel, variableName, data);
163 }
164 else if (variableType.find("Matrix") != npos) {
165 RCP<Matrix> data = currentLevel.Get<RCP<Matrix> >(variableName, fact.get());
166 Set(currentLevel, variableName, data);
167 }
168 else if (variableType.find("MultiVector") != npos) {
169 RCP<MultiVector> data = currentLevel.Get<RCP<MultiVector> >(variableName, fact.get());
170 Set(currentLevel, variableName, data);
171 }
172 else if (variableType.find("Operator") != npos) {
173 RCP<Operator> data = currentLevel.Get<RCP<Operator> >(variableName, fact.get());
174 Set(currentLevel, variableName, data);
175 }
176 else {
177 // TAW: is this working with empty procs?
178 TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "FineLevelInputDataFactory: cannot detect type of variable " << variableName << " generated by " << fact.get() << ". User provided type " << variableType );
179 }
180 }
181 }
182
183} //namespace MueLu
184
185#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 Set(Level &level, const std::string &varName, const T &data) const
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory().
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)....
virtual const Teuchos::ParameterList & GetParameterList() const
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
@ Debug
Print additional debugging information.