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