MueLu  Version of the Day
MueLu_FactoryFactory_decl.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_FACTORYFACTORY_DECL_HPP
47 #define MUELU_FACTORYFACTORY_DECL_HPP
48 
49 #include <string>
50 #include <vector>
51 
52 #include <Teuchos_ParameterEntry.hpp>
53 #include <Teuchos_Array.hpp>
54 
55 #include "MueLu_ConfigDefs.hpp"
57 
59 
60 #include "MueLu_FactoryBase.hpp"
61 #include "MueLu_FactoryManager.hpp"
65 #include "MueLu_Hierarchy_fwd.hpp"
66 
67 #include "MueLu_Monitor.hpp"
68 #include "MueLu_Exceptions.hpp"
69 
70 #include "MueLu_AggregationExportFactory.hpp"
71 #include "MueLu_AmalgamationFactory.hpp"
72 #ifdef HAVE_MUELU_EXPERIMENTAL
73 #include "MueLu_BlockedCoarseMapFactory.hpp"
74 #include "MueLu_BlockedDirectSolver.hpp"
75 #include "MueLu_BlockedGaussSeidelSmoother.hpp"
76 #include "MueLu_BlockedPFactory.hpp"
77 #include "MueLu_BlockedRAPFactory.hpp"
78 #include "MueLu_BraessSarazinSmoother.hpp"
79 #endif
80 #include "MueLu_BrickAggregationFactory.hpp"
81 #include "MueLu_CloneRepartitionInterface.hpp"
82 #include "MueLu_CoalesceDropFactory.hpp"
83 #include "MueLu_CoarseMapFactory.hpp"
84 #include "MueLu_CoarseningVisualizationFactory.hpp"
85 #include "MueLu_ConstraintFactory.hpp"
86 #include "MueLu_CoupledAggregationFactory.hpp"
87 #include "MueLu_CoordinatesTransferFactory.hpp"
88 #include "MueLu_DirectSolver.hpp"
89 #include "MueLu_DropNegativeEntriesFactory.hpp"
90 #include "MueLu_EminPFactory.hpp"
91 #include "MueLu_FilteredAFactory.hpp"
92 #include "MueLu_GenericRFactory.hpp"
93 #ifdef HAVE_MUELU_EXPERIMENTAL
94 #include "MueLu_IndefBlockedDiagonalSmoother.hpp"
95 #endif
96 #include "MueLu_IsorropiaInterface.hpp"
97 #include "MueLu_LineDetectionFactory.hpp"
98 #include "MueLu_RepartitionInterface.hpp"
99 #include "MueLu_MapTransferFactory.hpp"
100 #include "MueLu_MatrixAnalysisFactory.hpp"
101 #include "MueLu_MultiVectorTransferFactory.hpp"
102 #include "MueLu_NullspaceFactory.hpp"
103 #include "MueLu_NullspacePresmoothFactory.hpp"
104 #include "MueLu_PatternFactory.hpp"
105 #include "MueLu_PgPFactory.hpp"
106 #ifdef HAVE_MUELU_EXPERIMENTAL
107 #include "MueLu_RebalanceBlockInterpolationFactory.hpp"
108 #include "MueLu_RebalanceBlockRestrictionFactory.hpp"
109 #include "MueLu_RebalanceBlockAcFactory.hpp"
110 #endif
111 #include "MueLu_RebalanceTransferFactory.hpp"
112 #include "MueLu_RepartitionFactory.hpp"
113 #include "MueLu_RepartitionHeuristicFactory.hpp"
114 #include "MueLu_RAPFactory.hpp"
115 #include "MueLu_RebalanceAcFactory.hpp"
116 #include "MueLu_ReorderBlockAFactory.hpp"
117 #include "MueLu_SaPFactory.hpp"
118 #include "MueLu_SegregatedAFactory.hpp"
119 #ifdef HAVE_MUELU_EXPERIMENTAL
120 #include "MueLu_SchurComplementFactory.hpp"
121 #include "MueLu_SimpleSmoother.hpp"
122 #endif
123 #include "MueLu_SmootherFactory.hpp"
124 #include "MueLu_SubBlockAFactory.hpp"
125 #ifdef HAVE_MUELU_EXPERIMENTAL
126 #ifdef HAVE_MUELU_TEKO
127 #include "MueLu_TekoSmoother.hpp"
128 #endif
129 #endif
130 #include "MueLu_TentativePFactory.hpp"
131 #include "MueLu_ToggleCoordinatesTransferFactory.hpp"
132 #include "MueLu_TogglePFactory.hpp"
133 #include "MueLu_TrilinosSmoother.hpp"
134 #include "MueLu_TransPFactory.hpp"
135 #include "MueLu_UncoupledAggregationFactory.hpp"
136 #include "MueLu_UserAggregationFactory.hpp"
137 #include "MueLu_UserPFactory.hpp"
138 #include "MueLu_SemiCoarsenPFactory.hpp"
139 #ifdef HAVE_MUELU_EXPERIMENTAL
140 #include "MueLu_UzawaSmoother.hpp"
141 #endif
142 #include "MueLu_ZoltanInterface.hpp"
143 #include "MueLu_Zoltan2Interface.hpp"
144 
145 #ifdef HAVE_MUELU_MATLAB
146 // This is distasteful, but (sadly) neccesary due to peculiarities in MueLu's build system.
147 #include "../matlab/src/MueLu_SingleLevelMatlabFactory_decl.hpp"
148 #include "../matlab/src/MueLu_SingleLevelMatlabFactory_def.hpp"
149 #include "../matlab/src/MueLu_TwoLevelMatlabFactory_decl.hpp"
150 #include "../matlab/src/MueLu_TwoLevelMatlabFactory_def.hpp"
151 #include "../matlab/src/MueLu_MatlabSmoother_decl.hpp"
152 #include "../matlab/src/MueLu_MatlabSmoother_def.hpp"
153 #endif
154 
155 namespace MueLu {
156 
163  template <class Scalar = double, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
164  class FactoryFactory : public BaseClass {
165 #undef MUELU_FACTORYFACTORY_SHORT
166 #include "MueLu_UseShortNames.hpp"
167 
168  typedef std::map<std::string, RCP<const FactoryBase> > FactoryMap; // TODO: remove
169  typedef std::map<std::string, RCP<FactoryManagerBase> > FactoryManagerMap;
170 
171  public:
172 
173  // Parameter List Parsing:
174  // ---------
175  // <Parameter name="smootherFact0" type="string" value="TrilinosSmoother"/>
176  //
177  // or:
178  //
179  // <ParameterList name="smootherFact1">
180  // <Parameter name="factory" type="string" value="TrilinosSmoother"/>
181  // ...
182  // </ParameterList>
183  //
184  virtual RCP<const FactoryBase> BuildFactory(const Teuchos::ParameterEntry& param, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
185  // Find factory
186  std::string factoryName;
187  Teuchos::ParameterList paramList;
188  if (!param.isList()) {
189  factoryName = Teuchos::getValue<std::string>(param);
190  } else {
191  paramList = Teuchos::getValue<Teuchos::ParameterList>(param);
192  factoryName = paramList.get<std::string>("factory");
193  }
194 
195  // TODO: see how Teko handles this (=> register factories).
196  if (factoryName == "AggregationExportFactory") return Build2<AggregationExportFactory> (paramList, factoryMapIn, factoryManagersIn);
197  if (factoryName == "AmalgamationFactory") return Build2<AmalgamationFactory> (paramList, factoryMapIn, factoryManagersIn);
198 #ifdef HAVE_MUELU_EXPERIMENTAL
199  if (factoryName == "BlockedCoarseMapFactory") return Build2<BlockedCoarseMapFactory> (paramList, factoryMapIn, factoryManagersIn);
200  if (factoryName == "BlockedRAPFactory") return BuildRAPFactory<BlockedRAPFactory> (paramList, factoryMapIn, factoryManagersIn);
201 #endif
202  if (factoryName == "BrickAggregationFactory") return Build2<BrickAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
203  if (factoryName == "CloneRepartitionInterface") return Build2<CloneRepartitionInterface> (paramList, factoryMapIn, factoryManagersIn);
204  if (factoryName == "CoarseMapFactory") return Build2<CoarseMapFactory> (paramList, factoryMapIn, factoryManagersIn);
205  if (factoryName == "CoarseningVisualizationFactory") return Build2<CoarseningVisualizationFactory>(paramList, factoryMapIn, factoryManagersIn);
206  if (factoryName == "CoalesceDropFactory") return Build2<CoalesceDropFactory> (paramList, factoryMapIn, factoryManagersIn);
207  if (factoryName == "ConstraintFactory") return Build2<ConstraintFactory> (paramList, factoryMapIn, factoryManagersIn);
208  if (factoryName == "CoupledAggregationFactory") return BuildCoupledAggregationFactory (paramList, factoryMapIn, factoryManagersIn);
209  if (factoryName == "CoordinatesTransferFactory") return Build2<CoordinatesTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
210  if (factoryName == "DirectSolver") return BuildDirectSolver (paramList, factoryMapIn, factoryManagersIn);
211  if (factoryName == "DropNegativeEntriesFactory") return Build2<DropNegativeEntriesFactory> (paramList, factoryMapIn, factoryManagersIn);
212  if (factoryName == "EminPFactory") return Build2<EminPFactory> (paramList, factoryMapIn, factoryManagersIn);
213  if (factoryName == "FilteredAFactory") return Build2<FilteredAFactory> (paramList, factoryMapIn, factoryManagersIn);
214  if (factoryName == "GenericRFactory") return Build2<GenericRFactory> (paramList, factoryMapIn, factoryManagersIn);
215  if (factoryName == "LineDetectionFactory") return Build2<LineDetectionFactory> (paramList, factoryMapIn, factoryManagersIn);
216  if (factoryName == "MapTransferFactory") return Build2<MapTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
217  if (factoryName == "MatrixAnalysisFactory") return Build2<MatrixAnalysisFactory> (paramList, factoryMapIn, factoryManagersIn);
218  if (factoryName == "MultiVectorTransferFactory") return Build2<MultiVectorTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
219  if (factoryName == "NoFactory") return MueLu::NoFactory::getRCP();
220  if (factoryName == "NoSmoother") return rcp(new SmootherFactory(Teuchos::null));
221  if (factoryName == "NullspaceFactory") return Build2<NullspaceFactory> (paramList, factoryMapIn, factoryManagersIn);
222  if (factoryName == "NullspacePresmoothFactory") return Build2<NullspacePresmoothFactory> (paramList, factoryMapIn, factoryManagersIn);
223  if (factoryName == "PatternFactory") return Build2<PatternFactory> (paramList, factoryMapIn, factoryManagersIn);
224  if (factoryName == "PgPFactory") return Build2<PgPFactory> (paramList, factoryMapIn, factoryManagersIn);
225  if (factoryName == "SaPFactory") return Build2<SaPFactory> (paramList, factoryMapIn, factoryManagersIn);
226  if (factoryName == "RAPFactory") return BuildRAPFactory<RAPFactory> (paramList, factoryMapIn, factoryManagersIn);
227  if (factoryName == "RebalanceAcFactory") return Build2<RebalanceAcFactory> (paramList, factoryMapIn, factoryManagersIn);
228  if (factoryName == "RebalanceTransferFactory") return Build2<RebalanceTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
229  if (factoryName == "ReorderBlockAFactory") return Build2<ReorderBlockAFactory> (paramList, factoryMapIn, factoryManagersIn);
230  if (factoryName == "SegregatedAFactory") return Build2<SegregatedAFactory> (paramList, factoryMapIn, factoryManagersIn);
231  if (factoryName == "SubBlockAFactory") return Build2<SubBlockAFactory> (paramList, factoryMapIn, factoryManagersIn);
232  if (factoryName == "TentativePFactory") return Build2<TentativePFactory> (paramList, factoryMapIn, factoryManagersIn);
233  if (factoryName == "ToggleCoordinatesTransferFactory")return BuildToggleCoordinatesTransferFactory (paramList, factoryMapIn, factoryManagersIn);
234  if (factoryName == "TogglePFactory") return BuildTogglePFactory<TogglePFactory> (paramList, factoryMapIn, factoryManagersIn);
235  if (factoryName == "TransPFactory") return Build2<TransPFactory> (paramList, factoryMapIn, factoryManagersIn);
236  if (factoryName == "TrilinosSmoother") return BuildTrilinosSmoother (paramList, factoryMapIn, factoryManagersIn);
237  if (factoryName == "UncoupledAggregationFactory") return Build2<UncoupledAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
238  if (factoryName == "UserAggregationFactory") return Build2<UserAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
239  if (factoryName == "UserPFactory") return Build2<UserPFactory> (paramList, factoryMapIn, factoryManagersIn);
240  if (factoryName == "SemiCoarsenPFactory") return Build2<SemiCoarsenPFactory> (paramList, factoryMapIn, factoryManagersIn);
241  if (factoryName == "RepartitionInterface") return Build2<RepartitionInterface> (paramList, factoryMapIn, factoryManagersIn);
242 
243  if (factoryName == "ZoltanInterface") {
244 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
245  return Build2<ZoltanInterface>(paramList, factoryMapIn, factoryManagersIn);
246 #else
247  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a ZoltanInterface object: Zoltan is disabled: HAVE_MUELU_ZOLTAN && HAVE_MPI == false.");
248 #endif // HAVE_MUELU_ZOLTAN && HAVE_MPI
249  }
250  if (factoryName == "Zoltan2Interface") {
251 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
252  return Build2<Zoltan2Interface>(paramList, factoryMapIn, factoryManagersIn);
253 #else
254  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a Zoltan2Interface object: Zoltan2 is disabled: HAVE_MUELU_ZOLTAN2 && HAVE_MPI == false.");
255 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
256  }
257  if (factoryName == "IsorropiaInterface") {
258 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
259  return Build2<IsorropiaInterface>(paramList, factoryMapIn, factoryManagersIn);
260 #else
261  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a IsorropiaInterface object: Isorropia is disabled: HAVE_MUELU_ISORROPIA && HAVE_MPI == false.");
262 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
263  }
264 
265  if (factoryName == "RepartitionFactory") {
266 #ifdef HAVE_MPI
267  return Build2<RepartitionFactory>(paramList, factoryMapIn, factoryManagersIn);
268 #else
269  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionFactory object: HAVE_MPI == false.");
270 #endif // HAVE_MPI
271  }
272  if (factoryName == "RepartitionHeuristicFactory") {
273 #ifdef HAVE_MPI
274  return Build2<RepartitionHeuristicFactory>(paramList, factoryMapIn, factoryManagersIn);
275 #else
276  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionHeuristicFactory object: HAVE_MPI == false.");
277 #endif // HAVE_MPI
278  }
279  // Blocked factories
280 #ifdef HAVE_MUELU_EXPERIMENTAL
281  if (factoryName == "BlockedDirectSolver") return BuildBlockedDirectSolver(paramList, factoryMapIn, factoryManagersIn);
282  if (factoryName == "BlockedGaussSeidelSmoother") return BuildBlockedSmoother<BlockedGaussSeidelSmoother>(paramList, factoryMapIn, factoryManagersIn);
283  if (factoryName == "BlockedPFactory") return BuildBlockedFactory<BlockedPFactory>(paramList, factoryMapIn, factoryManagersIn);
284  if (factoryName == "BraessSarazinSmoother") return BuildBlockedSmoother<BraessSarazinSmoother>(paramList, factoryMapIn, factoryManagersIn);
285  if (factoryName == "IndefiniteBlockDiagonalSmoother") return BuildBlockedSmoother<IndefBlockedDiagonalSmoother>(paramList, factoryMapIn, factoryManagersIn);
286  if (factoryName == "SimpleSmoother") return BuildBlockedSmoother<SimpleSmoother>(paramList, factoryMapIn, factoryManagersIn);
287  if (factoryName == "SchurComplementFactory") return Build2<SchurComplementFactory> (paramList, factoryMapIn, factoryManagersIn);
288  if (factoryName == "RebalanceBlockRestrictionFactory")return BuildBlockedFactory<RebalanceBlockRestrictionFactory>(paramList, factoryMapIn, factoryManagersIn);
289  if (factoryName == "RebalanceBlockAcFactory") return BuildBlockedFactory<RebalanceBlockAcFactory>(paramList, factoryMapIn, factoryManagersIn);
290  if (factoryName == "RebalanceBlockInterpolationFactory") return BuildBlockedFactory<RebalanceBlockInterpolationFactory>(paramList, factoryMapIn, factoryManagersIn);
291 #ifdef HAVE_MUELU_TEKO
292  if (factoryName == "TekoSmoother") return BuildTekoSmoother(paramList, factoryMapIn, factoryManagersIn);
293 #endif
294  if (factoryName == "UzawaSmoother") return BuildBlockedSmoother<UzawaSmoother>(paramList, factoryMapIn, factoryManagersIn);
295 #endif
296 
297  // Matlab factories
298 #ifdef HAVE_MUELU_MATLAB
299  if (factoryName == "TwoLevelMatlabFactory") return Build2<TwoLevelMatlabFactory> (paramList, factoryMapIn, factoryManagersIn);
300  if (factoryName == "SingleLevelMatlabFactory") return Build2<SingleLevelMatlabFactory> (paramList, factoryMapIn, factoryManagersIn);
301  if (factoryName == "MatlabSmoother") return BuildMatlabSmoother (paramList, factoryMapIn, factoryManagersIn);
302 #endif
303 
304  // Use a user defined factories (in <Factories> node)
305  if (factoryMapIn.find(factoryName) != factoryMapIn.end()) {
306  TEUCHOS_TEST_FOR_EXCEPTION((param.isList() && (++paramList.begin() != paramList.end())), Exceptions::RuntimeError,
307  "MueLu::FactoryFactory: Error during the parsing of: " << std::endl << paramList << std::endl
308  << "'" << factoryName << "' is not a factory name but an existing instance of a factory." << std::endl
309  << "Extra parameters cannot be specified after the creation of the object." << std::endl << std::endl
310  << "Correct syntaxes includes:" << std::endl
311  << " <Parameter name=\"...\" type=\"string\" value=\"" << factoryName << "\"/>" << std::endl
312  << "or" << std::endl
313  << " <ParameterList name=\"...\"><Parameter name=\"factory\" type=\"string\" value=\"" << factoryName << "\"/></ParameterList>" << std::endl
314  );
315 
316  return factoryMapIn.find(factoryName)->second;
317  }
318 
319  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory: unknown factory name : " << factoryName);
320 
321  return Teuchos::null;
322  }
323 
324  //
325  //
326  //
327 
328  // FOLLOWING FUNCTIONS SHOULD LIVE WITH THE CORRESPONDING CLASS
329 
330  //
331  //
332  //
333 
334 #define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))
335 
336  template <class T> // T must implement the Factory interface
337  RCP<T> Build(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
338  RCP<T> factory = rcp(new T());
339 
340  const char* strarray[] = {"A", "P", "R", "Graph", "UnAmalgamationInfo", "Aggregates", "Nullspace", "TransferFactory", "DofsPerNode"};
341  std::vector<std::string> v(strarray, strarray + arraysize(strarray));
342  for (size_t i = 0; i < v.size(); ++i)
343  if (paramList.isParameter(v[i]))
344  factory->SetFactory(v[i], BuildFactory(paramList.getEntry(v[i]), factoryMapIn, factoryManagersIn));
345 
346  return factory;
347  }
348 
349  template <class T> // T must implement the Factory interface
350  RCP<T> Build2(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
351  RCP<T> factory = rcp(new T());
352 
353  ParameterList paramListWithFactories;
354 
355  // Read the RCP<Factory> parameters of the class T
356  RCP<const ParameterList> validParamList = factory->GetValidParameterList();
357  for (ParameterList::ConstIterator param = validParamList->begin(); param != validParamList->end(); ++param) {
358  const std::string& pName = validParamList->name(param);
359 
360  if (!paramList.isParameter(pName)) {
361  // Ignore unknown parameters
362  continue;
363  }
364 
365  if (validParamList->isType< RCP<const FactoryBase> >(pName)) {
366  // Generate or get factory described by param
367  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry(pName), factoryMapIn, factoryManagersIn);
368  paramListWithFactories.set(pName, generatingFact);
369  } else if (validParamList->isType<RCP<const ParameterList> >(pName)) {
370  if (pName == "ParameterList") {
371  // NOTE: we cannot use
372  // subList = sublist(rcpFromRef(paramList), pName)
373  // here as that would result in sublist also being a reference to a temporary object.
374  // The resulting dereferencing in the corresponding factory would then segfault
375  RCP<const ParameterList> subList = Teuchos::sublist(rcp(new ParameterList(paramList)), pName);
376  paramListWithFactories.set(pName, subList);
377  }
378  } else {
379  paramListWithFactories.setEntry(pName, paramList.getEntry(pName));
380  }
381  }
382 
383  // Configure the factory
384  factory->SetParameterList(paramListWithFactories);
385 
386  return factory;
387  }
388 
389  template <class T> // T must implement the Factory interface
390  RCP<T> BuildRAPFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
391  RCP<T> factory;
392  if (paramList.isSublist("TransferFactories") == false) {
393  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
394 
395  } else {
396  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
397  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
398 
399  paramListNonConst->remove("TransferFactories");
400 
401  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
402 
403  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
404  RCP<const FactoryBase> p = BuildFactory(transferFactories->entry(param), factoryMapIn, factoryManagersIn);
405  factory->AddTransferFactory(p);
406  }
407  }
408 
409  return factory;
410  }
411 
412  template <class T> // T must implement the Factory interface
413  RCP<T> BuildTogglePFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
414  RCP<T> factory;
415  if (paramList.isSublist("TransferFactories") == false) {
416  //TODO put in an error message: the TogglePFactory needs a TransferFactories sublist!
417  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
418 
419  } else {
420  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
421  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
422 
423  paramListNonConst->remove("TransferFactories");
424 
425  // build TogglePFactory
426  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
427 
428  // count how many prolongation factories and how many coarse null space factories have been declared.
429  // the numbers must match!
430  int numProlongatorFactories = 0;
431  int numPtentFactories = 0;
432  int numCoarseNspFactories = 0;
433  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
434  size_t foundNsp = transferFactories->name(param).find("Nullspace");
435  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length()==10) {
436  numCoarseNspFactories++;
437  continue;
438  }
439  size_t foundPtent = transferFactories->name(param).find("Ptent");
440  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length()==6) {
441  numPtentFactories++;
442  continue;
443  }
444  size_t foundP = transferFactories->name(param).find("P");
445  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length()==2) {
446  numProlongatorFactories++;
447  continue;
448  }
449  }
450  TEUCHOS_TEST_FOR_EXCEPTION(numProlongatorFactories!=numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of prolongator and coarse nullspace factories!");
451  TEUCHOS_TEST_FOR_EXCEPTION(numPtentFactories!=numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of ptent and coarse nullspace factories!");
452  TEUCHOS_TEST_FOR_EXCEPTION(numProlongatorFactories < 2, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The TogglePFactory needs at least two different prolongation operators. The factories have to be provided using the names P%i and Nullspace %i, where %i denotes a number between 1 and 9.");
453 
454  // create empty vectors with data
455  std::vector<Teuchos::ParameterEntry> prolongatorFactoryNames(numProlongatorFactories);
456  std::vector<Teuchos::ParameterEntry> coarseNspFactoryNames(numProlongatorFactories);
457  std::vector<Teuchos::ParameterEntry> ptentFactoryNames(numProlongatorFactories);
458 
459  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
460  size_t foundNsp = transferFactories->name(param).find("Nullspace");
461  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length()==10) {
462  int number = atoi(&(transferFactories->name(param).at(9)));
463  TEUCHOS_TEST_FOR_EXCEPTION(number < 1 || number > numProlongatorFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: Please use the format Nullspace%i with %i an integer between 1 and the maximum number of prolongation operators in TogglePFactory!");
464  coarseNspFactoryNames[number-1] = transferFactories->entry(param);
465  continue;
466  }
467  size_t foundPtent = transferFactories->name(param).find("Ptent");
468  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length()==6) {
469  int number = atoi(&(transferFactories->name(param).at(5)));
470  TEUCHOS_TEST_FOR_EXCEPTION(number < 1 || number > numPtentFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: Please use the format Ptent%i with %i an integer between 1 and the maximum number of prolongation operators in TogglePFactory!");
471  ptentFactoryNames[number-1] = transferFactories->entry(param);
472  continue;
473  }
474  size_t foundP = transferFactories->name(param).find("P");
475  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length()==2) {
476  int number = atoi(&(transferFactories->name(param).at(1)));
477  TEUCHOS_TEST_FOR_EXCEPTION(number < 1 || number > numProlongatorFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: Please use the format P%i with %i an integer between 1 and the maximum number of prolongation operators in TogglePFactory!");
478  prolongatorFactoryNames[number-1] = transferFactories->entry(param);
479  continue;
480  }
481  }
482 
483  // register all prolongation factories in TogglePFactory
484  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = prolongatorFactoryNames.begin(); it != prolongatorFactoryNames.end(); ++it) {
485  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
486  factory->AddProlongatorFactory(p);
487  }
488 
489  // register all tentative prolongation factories in TogglePFactory
490  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = ptentFactoryNames.begin(); it != ptentFactoryNames.end(); ++it) {
491  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
492  factory->AddPtentFactory(p);
493  }
494 
495  // register all coarse nullspace factories in TogglePFactory
496  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseNspFactoryNames.begin(); it != coarseNspFactoryNames.end(); ++it) {
497  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
498  factory->AddCoarseNullspaceFactory(p);
499  }
500  }
501  return factory;
502  }
503 
504  RCP<ToggleCoordinatesTransferFactory> BuildToggleCoordinatesTransferFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
505  RCP<ToggleCoordinatesTransferFactory> factory;
506  TEUCHOS_TEST_FOR_EXCEPTION(paramList.isSublist("TransferFactories") == false, Exceptions::RuntimeError, "FactoryFactory::BuildToggleCoordinatesTransferFactory: the ToggleCoordinatesTransferFactory needs a sublist 'TransferFactories' containing information about the subfactories for coordinate transfer!");
507 
508  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
509  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
510  paramListNonConst->remove("TransferFactories");
511 
512  // build CoordinatesTransferFactory
513  factory = Build2<ToggleCoordinatesTransferFactory>(*paramListNonConst, factoryMapIn, factoryManagersIn);
514 
515  // count how many coordinate transfer factories have been declared.
516  // the numbers must match!
517  int numCoordTransferFactories = 0;
518  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
519  size_t foundCoordinates = transferFactories->name(param).find("Coordinates");
520  if (foundCoordinates != std::string::npos && foundCoordinates == 0 && transferFactories->name(param).length()==12) {
521  numCoordTransferFactories++;
522  continue;
523  }
524  }
525  TEUCHOS_TEST_FOR_EXCEPTION(numCoordTransferFactories != 2, Exceptions::RuntimeError, "FactoryFactory::BuildToggleCoordinatesTransfer: The ToggleCoordinatesTransferFactory needs two (different) coordinate transfer factories. The factories have to be provided using the names Coordinates%i, where %i denotes a number between 1 and 9.");
526 
527  // create empty vectors with data
528  std::vector<Teuchos::ParameterEntry> coarseCoordsFactoryNames(numCoordTransferFactories);
529 
530  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
531  size_t foundCoords = transferFactories->name(param).find("Coordinates");
532  if (foundCoords != std::string::npos && foundCoords == 0 && transferFactories->name(param).length()==12) {
533  int number = atoi(&(transferFactories->name(param).at(11)));
534  TEUCHOS_TEST_FOR_EXCEPTION(number < 1 || number > numCoordTransferFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleCoordinatesTransfer: Please use the format Coordinates%i with %i an integer between 1 and the maximum number of coordinate transfer factories in ToggleCoordinatesTransferFactory!");
535  coarseCoordsFactoryNames[number-1] = transferFactories->entry(param);
536  continue;
537  }
538  }
539 
540  // register all coarse nullspace factories in TogglePFactory
541  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseCoordsFactoryNames.begin(); it != coarseCoordsFactoryNames.end(); ++it) {
542  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
543  factory->AddCoordTransferFactory(p);
544  }
545 
546  return factory;
547  }
548 
550  RCP<FactoryBase> BuildCoupledAggregationFactory(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
551  RCP<CoupledAggregationFactory> factory = Build<CoupledAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
552 
553  if (paramList.isParameter("aggregation: ordering"))
554  factory->SetOrdering(paramList.get<std::string>("aggregation: ordering"));
555 
556  if (paramList.isParameter("aggregation: max selected neighbors"))
557  factory->SetMaxNeighAlreadySelected(paramList.get<int>("aggregation: max selected neighbors"));
558 
559  if (paramList.isParameter("Phase3AggCreation"))
560  factory->SetPhase3AggCreation(paramList.get<double>("Phase3AggCreation"));
561 
562  if(paramList.isParameter("aggregation: min agg size"))
563  factory->SetMinNodesPerAggregate(paramList.get<int>("aggregation: min agg size"));
564 
565  return factory;
566  }
567 
569  // Parameter List Parsing:
570  // <ParameterList name="smootherFact1">
571  // <Parameter name="factory" type="string" value="TrilinosSmoother"/>
572  // <Parameter name="verbose" type="string" value="Warnings"/>
573  // <Parameter name="type" type="string" value="RELAXATION"/>
574  // <ParameterList name="ParameterList">
575  // ...
576  // </ParameterList>
577  // </ParameterList>
578  RCP<FactoryBase> BuildTrilinosSmoother(const Teuchos::ParameterList & paramList, const FactoryMap & factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
579  if (paramList.begin() == paramList.end())
580  return rcp(new SmootherFactory(rcp(new TrilinosSmoother())));
581 
582  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "TrilinosSmoother", Exceptions::RuntimeError, "");
583 
584  // Is it true? TEUCHOS_TEST_FOR_EXCEPTION(!paramList.isParameter("type"), Exceptions::RuntimeError, "TrilinosSmoother: parameter 'type' is mandatory");
585  // type="" is default in TrilinosSmoother, but what happen then?
586 
587  std::string type=""; if(paramList.isParameter("type")) type = paramList.get<std::string>("type");
588  int overlap=0; if(paramList.isParameter("overlap")) overlap = paramList.get<int> ("overlap");
589  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
590  Teuchos::ParameterList params; if(paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
591 
592  // parameters from SmootherFactory
593  //bool bKeepSmootherData = false; if(paramList.isParameter("keep smoother data")) bKeepSmootherData = paramList.get<bool>("keep smoother data");
594 
595  // Read in factory information for smoothers (if available...)
596  // NOTE: only a selected number of factories can be used with the Trilinos smoother
597  // smoothers usually work with the global data available (which is A and the transfers P and R)
598 
599  Teuchos::RCP<TrilinosSmoother> trilSmoo = Teuchos::rcp(new TrilinosSmoother(type, params, overlap));
600 
601  if (paramList.isParameter("LineDetection_Layers")) {
602  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
603  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
604  }
605  if (paramList.isParameter("LineDetection_VertLineIds")) {
606  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
607  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
608  }
609  if (paramList.isParameter("CoarseNumZLayers")) {
610  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("CoarseNumZLayers"), factoryMapIn, factoryManagersIn);
611  trilSmoo->SetFactory("CoarseNumZLayers", generatingFact);
612  }
613 
614  RCP<SmootherFactory> smooFact = rcp(new SmootherFactory(Teuchos::null));
615  Teuchos::ParameterList smooFactParams;
616  //smooFactParams.setEntry("keep smoother data", paramList.getEntry("keep smoother data"));
617  smooFact->SetParameterList(smooFactParams);
618  smooFact->SetSmootherPrototypes(trilSmoo);
619  return smooFact;
620  }
621 
622 #ifdef HAVE_MUELU_MATLAB
623  // Parameter List Parsing:
625  // <ParameterList name="smootherFact1">
626  // <Parameter name="factory" type="string" value="MatlabSmoother"/>
627  // <Parameter name="Setup Function" type="string" value="mySmootherSetup.m"/>
628  // <Parameter name="Solve Function" type="string" value="mySmootherSolve.m"/>
629  // <!--A is implicitly included in this list and nothing else is needed to get diagonal-->
630  // <Parameter name="Needs" type="string" value=""/>
631  // <!--A,x,b are also assumed inputs to the solver: only one additional arg then (diag)-->
632  // <Parameter name="Number of Solver Args" type="int" value="1"/>
633  // </ParameterList>
634  RCP<FactoryBase> BuildMatlabSmoother(const Teuchos::ParameterList & paramList, const FactoryMap & factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
635  if (paramList.begin() == paramList.end())
636  return rcp(new SmootherFactory(rcp(new MatlabSmoother())));
637 
638  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "MatlabSmoother", Exceptions::RuntimeError, "");
639 
640  // Read in factory information for smoothers (if available...)
641  // NOTE: only a selected number of factories can be used with the Trilinos smoother
642  // smoothers usually work with the global data available (which is A and the transfers P and R)
643 
644  Teuchos::RCP<MatlabSmoother> matSmoo = Teuchos::rcp(new MatlabSmoother(paramList));
645 
646  return rcp(new SmootherFactory(matSmoo));
647  }
648 #endif
649 
650  RCP<FactoryBase> BuildDirectSolver(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
651  if (paramList.begin() == paramList.end())
652  return rcp(new SmootherFactory(rcp(new DirectSolver()), Teuchos::null));
653 
654  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "DirectSolver", Exceptions::RuntimeError, "");
655 
656  std::string type; if(paramList.isParameter("type")) type = paramList.get<std::string>("type");
657  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
658  Teuchos::ParameterList params; if(paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
659 
660  return rcp(new SmootherFactory(rcp(new DirectSolver(type, params)), Teuchos::null));
661  }
662 
663 #ifdef HAVE_MUELU_EXPERIMENTAL
664  template <class T> // T must implement the Factory interface
665  RCP<FactoryBase> BuildBlockedSmoother(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
666  // read in sub lists
667  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
668 
669  // internal vector of factory managers
670  std::vector<RCP<FactoryManager> > facManagers;
671 
672  // loop over all "block%i" sublists in parameter list
673  int blockid = 1;
674  bool blockExists = true;
675  while (blockExists == true) {
676  std::stringstream ss;
677  ss << "block" << blockid;
678 
679  if(paramList.isSublist(ss.str()) == true) {
680  // we either have a parameter group or we have a list of factories in here
681  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
682 
683  RCP<FactoryManager> M = Teuchos::null;
684 
685  if (b->isParameter("group")) {
686  // use a factory manager
687  std::string facManagerName = b->get< std::string >("group");
688  TEUCHOS_TEST_FOR_EXCEPTION(factoryManagersIn.count(facManagerName) != 1, Exceptions::RuntimeError, "Factory manager has not been found. Please check the spelling of the factory managers in your xml file.");
689  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
690  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
691  TEUCHOS_TEST_FOR_EXCEPTION(M==Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
692  } else {
693  // read in the list of factories
694  M = rcp(new FactoryManager());
695  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
696  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
697  M->SetFactory(b->name(param),p);
698  }
699  }
700 
701  // add factory manager to internal vector of factory managers
702  M->SetIgnoreUserData(true);
703  facManagers.push_back(M);
704  paramListNonConst->remove(ss.str());
705  blockid++;
706  } else {
707  blockExists = false;
708  break;
709  }
710 
711  }
712 
713  // create a new blocked smoother
714  RCP<T> bs = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
715 
716  // important: set block factory for A here!
717  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
718  // The user might want to overwrite this in the xml file, so just
719  // use what is declared as "A"
720  //bs->SetFactory("A", MueLu::NoFactory::getRCP());
721 
722  for (int i = 0; i<Teuchos::as<int>(facManagers.size()); i++) {
723  bs->AddFactoryManager(facManagers[i],i);
724  }
725 
726  return rcp(new SmootherFactory(bs));
727  }
728 
729 #ifdef HAVE_MUELU_TEKO
730  RCP<FactoryBase> BuildTekoSmoother(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
731  // read in sub lists
732  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
733  RCP<ParameterList> tekoParams = rcp(new ParameterList(paramListNonConst->sublist("Inverse Factory Library")));
734  paramListNonConst->remove("Inverse Factory Library");
735 
736  // create a new blocked smoother
737  RCP<TekoSmoother> bs = Build2<TekoSmoother>(*paramListNonConst, factoryMapIn, factoryManagersIn);
738 
739  // important: set block factory for A here!
740  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
741  // The user might want to overwrite this in the xml file, so just
742  // use what is declared as "A"
743  //bs->SetFactory("A", MueLu::NoFactory::getRCP());
744 
745  // Set Teko parameters ("Inverse Factory Library")
746  bs->SetTekoParameters(tekoParams);
747 
748  return rcp(new SmootherFactory(bs));
749  }
750 #endif
751 
752  RCP<FactoryBase> BuildBlockedDirectSolver(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
753  //if (paramList.begin() == paramList.end())
754  return rcp(new SmootherFactory(rcp(new BlockedDirectSolver())));
755 
756  /*TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "DirectSolver", Exceptions::RuntimeError, "");
757 
758  std::string type; if(paramList.isParameter("type")) type = paramList.get<std::string>("type");
759  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
760  Teuchos::ParameterList params; if(paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
761 
762  return rcp(new SmootherFactory(rcp(new DirectSolver(type, params))));*/
763  }
764 
765  //RCP<FactoryBase> BuildBlockedPFactory(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
766  // RCP<BlockedPFactory> pfac = rcp(new BlockedPFactory());
767 
768  template <class T> // T must implement the Factory interface
769  RCP<T> BuildBlockedFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
770  RCP<T> pfac = Teuchos::null;
771 
772  // read in sub lists
773  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
774 
775  // internal vector of factory managers
776  std::vector<RCP<FactoryManager> > facManagers;
777 
778  // loop over all "block%i" sublists in parameter list
779  int blockid = 1;
780  bool blockExists = true;
781  while (blockExists == true) {
782  std::stringstream ss;
783  ss << "block" << blockid;
784 
785  if(paramList.isSublist(ss.str()) == true) {
786  // we either have a parameter group or we have a list of factories in here
787  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
788 
789  RCP<FactoryManager> M = Teuchos::null;
790 
791  if (b->isParameter("group")) {
792  // use a factory manager
793  std::string facManagerName = b->get< std::string >("group");
794  TEUCHOS_TEST_FOR_EXCEPTION(factoryManagersIn.count(facManagerName) != 1, Exceptions::RuntimeError, "Factory manager has not been found. Please check the spelling of the factory managers in your xml file.");
795  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
796  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
797  TEUCHOS_TEST_FOR_EXCEPTION(M==Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
798  } else {
799  // read in the list of factories
800  M = rcp(new FactoryManager());
801  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
802  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
803  M->SetFactory(b->name(param),p);
804  }
805  }
806 
807  // add factory manager to internal vector of factory managers
808  M->SetIgnoreUserData(true);
809  facManagers.push_back(M);
810  paramListNonConst->remove(ss.str());
811  blockid++;
812  } else {
813  blockExists = false;
814  break;
815  }
816 
817  }
818 
819  // build BlockedPFactory (without sub block information)
820  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
821 
822  // add FactoryManager objects
823  for(size_t i = 0; i<facManagers.size(); i++) {
824  pfac->AddFactoryManager(facManagers[i]); // add factory manager
825  }
826 
827  return pfac;
828  }
829 #endif /* #ifdef HAVE_MUELU_EXPERIMENTAL */
830  }; // class
831 } // namespace MueLu
832 
833 #define MUELU_FACTORYFACTORY_SHORT
834 #endif // MUELU_FACTORYFACTORY_DECL_HPP
835 
836  // TODO: handle factory parameters
837  // TODO: parameter validator
838  // TODO: static
839  // TODO: default parameters should not be duplicated here and on the Factory (ex: default for overlap (=0) is defined both here and on TrilinosSmoother constructors)
RCP< FactoryBase > BuildMatlabSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
MatlabSmoother.
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
This class specifies the default factory that should generate some data on a Level if the data does n...
RCP< FactoryBase > BuildBlockedSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< T > Build(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Factory that can generate other factories from.
Class that encapsulates external library smoothers.
virtual RCP< const FactoryBase > BuildFactory(const Teuchos::ParameterEntry &param, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< T > BuildBlockedFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< ToggleCoordinatesTransferFactory > BuildToggleCoordinatesTransferFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< T > Build2(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Namespace for MueLu classes and methods.
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
#define arraysize(ar)
std::map< std::string, RCP< FactoryManagerBase > > FactoryManagerMap
std::map< std::string, RCP< const FactoryBase > > FactoryMap
RCP< FactoryBase > BuildBlockedDirectSolver(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
direct solver for nxn blocked matrices
RCP< T > BuildRAPFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Base class for MueLu classes.
Class that encapsulates Matlab smoothers.
RCP< FactoryBase > BuildTekoSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< FactoryBase > BuildTrilinosSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
TrilinosSmoother.
RCP< FactoryBase > BuildCoupledAggregationFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
CoupledAggregationFactory.
Exception throws to report errors in the internal logical of the program.
RCP< T > BuildTogglePFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< FactoryBase > BuildDirectSolver(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
static const RCP< const NoFactory > getRCP()
Static Get() functions.