MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_FactoryFactory_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 #ifndef MUELU_FACTORYFACTORY_DEF_HPP
10 #define MUELU_FACTORYFACTORY_DEF_HPP
12 
13 #include "MueLu_AggregateQualityEstimateFactory.hpp"
14 #include "MueLu_AggregationExportFactory.hpp"
15 #include "MueLu_AmalgamationFactory.hpp"
16 #include "MueLu_BlackBoxPFactory.hpp"
17 #include "MueLu_BlockedCoarseMapFactory.hpp"
18 #include "MueLu_BlockedCoordinatesTransferFactory.hpp"
19 #include "MueLu_BlockedDirectSolver.hpp"
20 #include "MueLu_BlockedGaussSeidelSmoother.hpp"
21 #include "MueLu_BlockedJacobiSmoother.hpp"
22 #include "MueLu_BlockedPFactory.hpp"
23 #include "MueLu_BlockedRAPFactory.hpp"
24 #include "MueLu_BraessSarazinSmoother.hpp"
25 #include "MueLu_BrickAggregationFactory.hpp"
26 #include "MueLu_ClassicalMapFactory.hpp"
27 #include "MueLu_ClassicalPFactory.hpp"
28 #include "MueLu_CloneRepartitionInterface.hpp"
29 #include "MueLu_CoalesceDropFactory.hpp"
30 #include "MueLu_SmooVecCoalesceDropFactory.hpp"
31 #include "MueLu_CoarseMapFactory.hpp"
32 #include "MueLu_CoarseningVisualizationFactory.hpp"
33 #include "MueLu_ConstraintFactory.hpp"
34 #include "MueLu_CoordinatesTransferFactory.hpp"
35 #include "MueLu_DirectSolver.hpp"
36 #include "MueLu_DropNegativeEntriesFactory.hpp"
37 #include "MueLu_EminPFactory.hpp"
38 #include "MueLu_FilteredAFactory.hpp"
39 #include "MueLu_FineLevelInputDataFactory.hpp"
40 #include "MueLu_GeneralGeometricPFactory.hpp"
41 #include "MueLu_ReplicatePFactory.hpp"
42 #include "MueLu_CombinePFactory.hpp"
43 #include "MueLu_GenericRFactory.hpp"
44 #include "MueLu_GeometricInterpolationPFactory.hpp"
45 #include "MueLu_InterfaceAggregationFactory.hpp"
46 #include "MueLu_InterfaceMappingTransferFactory.hpp"
47 #include "MueLu_InitialBlockNumberFactory.hpp"
48 #include "MueLu_IndefBlockedDiagonalSmoother.hpp"
49 #include "MueLu_InverseApproximationFactory.hpp"
50 #include "MueLu_IsorropiaInterface.hpp"
51 #include "MueLu_LineDetectionFactory.hpp"
52 #include "MueLu_LocalOrdinalTransferFactory.hpp"
53 #include "MueLu_RepartitionInterface.hpp"
54 #include "MueLu_RepartitionBlockDiagonalFactory.hpp"
55 #include "MueLu_MapTransferFactory.hpp"
56 #include "MueLu_MatrixAnalysisFactory.hpp"
57 #include "MueLu_MultiVectorTransferFactory.hpp"
58 #include "MueLu_NotayAggregationFactory.hpp"
59 #include "MueLu_NullspaceFactory.hpp"
60 #include "MueLu_NullspacePresmoothFactory.hpp"
61 #include "MueLu_PatternFactory.hpp"
62 #include "MueLu_PgPFactory.hpp"
63 #include "MueLu_RebalanceBlockInterpolationFactory.hpp"
64 #include "MueLu_RebalanceBlockRestrictionFactory.hpp"
65 #include "MueLu_RebalanceBlockAcFactory.hpp"
66 #include "MueLu_RebalanceTransferFactory.hpp"
67 #include "MueLu_RegionRFactory.hpp"
68 #include "MueLu_RepartitionFactory.hpp"
69 #include "MueLu_RepartitionHeuristicFactory.hpp"
70 #include "MueLu_RAPFactory.hpp"
71 #include "MueLu_RAPShiftFactory.hpp"
72 #include "MueLu_RebalanceAcFactory.hpp"
73 #include "MueLu_ReorderBlockAFactory.hpp"
74 #include "MueLu_SaPFactory.hpp"
75 #include "MueLu_ScaledNullspaceFactory.hpp"
76 #include "MueLu_SegregatedAFactory.hpp"
77 #include "MueLu_SemiCoarsenPFactory.hpp"
78 #include "MueLu_SchurComplementFactory.hpp"
79 #include "MueLu_SimpleSmoother.hpp"
80 #include "MueLu_SmootherFactory.hpp"
81 #include "MueLu_StructuredAggregationFactory.hpp"
82 #include "MueLu_StructuredLineDetectionFactory.hpp"
83 #include "MueLu_SubBlockAFactory.hpp"
84 #ifdef HAVE_MUELU_TEKO
85 #include "MueLu_TekoSmoother.hpp"
86 #endif
87 #include "MueLu_TentativePFactory.hpp"
88 #include "MueLu_ToggleCoordinatesTransferFactory.hpp"
89 #include "MueLu_TogglePFactory.hpp"
90 #include "MueLu_TrilinosSmoother.hpp"
91 #include "MueLu_TransPFactory.hpp"
92 #include "MueLu_RfromP_Or_TransP.hpp"
93 #include "MueLu_UncoupledAggregationFactory.hpp"
94 #include "MueLu_HybridAggregationFactory.hpp"
95 #include "MueLu_UnsmooshFactory.hpp"
96 #include "MueLu_UserAggregationFactory.hpp"
97 #include "MueLu_UserPFactory.hpp"
98 #include "MueLu_UzawaSmoother.hpp"
99 #include "MueLu_VariableDofLaplacianFactory.hpp"
100 #include "MueLu_ZeroSubBlockAFactory.hpp"
101 #include "MueLu_ZoltanInterface.hpp"
102 #include "MueLu_Zoltan2Interface.hpp"
103 #include "MueLu_NodePartitionInterface.hpp"
104 
105 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
106 #include "MueLu_GeometricInterpolationPFactory_kokkos.hpp"
107 #ifdef HAVE_MUELU_DEPRECATED_CODE
108 #include "MueLu_NullspaceFactory_kokkos.hpp"
109 #include "MueLu_SaPFactory_kokkos.hpp"
110 #endif
111 #include "MueLu_SemiCoarsenPFactory_kokkos.hpp"
112 #include "MueLu_StructuredAggregationFactory_kokkos.hpp"
113 #include "MueLu_TentativePFactory_kokkos.hpp"
114 #include "MueLu_MatrixFreeTentativePFactory.hpp"
115 #include "MueLu_RegionRFactory_kokkos.hpp"
116 
117 #ifdef HAVE_MUELU_MATLAB
118 // This is distasteful, but (sadly) neccesary due to peculiarities in MueLu's build system.
119 #include "../matlab/src/MueLu_SingleLevelMatlabFactory_decl.hpp"
120 #include "../matlab/src/MueLu_SingleLevelMatlabFactory_def.hpp"
121 #include "../matlab/src/MueLu_TwoLevelMatlabFactory_decl.hpp"
122 #include "../matlab/src/MueLu_TwoLevelMatlabFactory_def.hpp"
123 #include "../matlab/src/MueLu_MatlabSmoother_decl.hpp"
124 #include "../matlab/src/MueLu_MatlabSmoother_def.hpp"
125 #endif
126 
127 #ifdef HAVE_MUELU_INTREPID2
128 #include "MueLu_IntrepidPCoarsenFactory.hpp"
129 #endif
130 
131 namespace MueLu {
132 
133 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
135  // Find factory
136  std::string factoryName;
137  Teuchos::ParameterList paramList;
138  if (!param.isList()) {
139  factoryName = Teuchos::getValue<std::string>(param);
140  } else {
141  paramList = Teuchos::getValue<Teuchos::ParameterList>(param);
142  factoryName = paramList.get<std::string>("factory");
143  }
144 
145  // TODO: see how Teko handles this (=> register factories).
146  if (factoryName == "AggregateQualityEstimateFactory") return Build2<AggregateQualityEstimateFactory>(paramList, factoryMapIn, factoryManagersIn);
147  if (factoryName == "AggregationExportFactory") return Build2<AggregationExportFactory>(paramList, factoryMapIn, factoryManagersIn);
148  if (factoryName == "AmalgamationFactory") return Build2<AmalgamationFactory>(paramList, factoryMapIn, factoryManagersIn);
149  if (factoryName == "BlockedCoarseMapFactory") return Build2<BlockedCoarseMapFactory>(paramList, factoryMapIn, factoryManagersIn);
150  if (factoryName == "BlockedRAPFactory") return BuildRAPFactory<BlockedRAPFactory>(paramList, factoryMapIn, factoryManagersIn);
151  if (factoryName == "BrickAggregationFactory") return Build2<BrickAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
152  if (factoryName == "ClassicalMapFactory") return Build2<ClassicalMapFactory>(paramList, factoryMapIn, factoryManagersIn);
153  if (factoryName == "ClassicalPFactory") return Build2<ClassicalPFactory>(paramList, factoryMapIn, factoryManagersIn);
154  if (factoryName == "CloneRepartitionInterface") return Build2<CloneRepartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
155  if (factoryName == "CoarseMapFactory") return Build2<CoarseMapFactory>(paramList, factoryMapIn, factoryManagersIn);
156  if (factoryName == "CoarseningVisualizationFactory") return Build2<CoarseningVisualizationFactory>(paramList, factoryMapIn, factoryManagersIn);
157  if (factoryName == "CoalesceDropFactory") return Build2<CoalesceDropFactory>(paramList, factoryMapIn, factoryManagersIn);
158  if (factoryName == "SmooVecCoalesceDropFactory") return Build2<SmooVecCoalesceDropFactory>(paramList, factoryMapIn, factoryManagersIn);
159  if (factoryName == "ConstraintFactory") return Build2<ConstraintFactory>(paramList, factoryMapIn, factoryManagersIn);
160  if (factoryName == "CoordinatesTransferFactory") return Build2<CoordinatesTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
161  if (factoryName == "DirectSolver") return BuildDirectSolver(paramList, factoryMapIn, factoryManagersIn);
162  if (factoryName == "DropNegativeEntriesFactory") return Build2<DropNegativeEntriesFactory>(paramList, factoryMapIn, factoryManagersIn);
163  if (factoryName == "EminPFactory") return Build2<EminPFactory>(paramList, factoryMapIn, factoryManagersIn);
164  if (factoryName == "FilteredAFactory") return Build2<FilteredAFactory>(paramList, factoryMapIn, factoryManagersIn);
165  if (factoryName == "FineLevelInputDataFactory") return Build2<FineLevelInputDataFactory>(paramList, factoryMapIn, factoryManagersIn);
166  if (factoryName == "GeneralGeometricPFactory") return Build2<GeneralGeometricPFactory>(paramList, factoryMapIn, factoryManagersIn);
167  if (factoryName == "ReplicatePFactory") return Build2<ReplicatePFactory>(paramList, factoryMapIn, factoryManagersIn);
168  if (factoryName == "CombinePFactory") return Build2<CombinePFactory>(paramList, factoryMapIn, factoryManagersIn);
169  if (factoryName == "GenericRFactory") return Build2<GenericRFactory>(paramList, factoryMapIn, factoryManagersIn);
170  if (factoryName == "GeometricInterpolationPFactory") return Build2<GeometricInterpolationPFactory>(paramList, factoryMapIn, factoryManagersIn);
171  if (factoryName == "HybridAggregationFactory") return Build2<HybridAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
172  if (factoryName == "InterfaceAggregationFactory") return Build2<InterfaceAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
173  if (factoryName == "InterfaceMappingTransferFactory") return Build2<InterfaceMappingTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
174  if (factoryName == "InverseApproximationFactory") return Build2<InverseApproximationFactory>(paramList, factoryMapIn, factoryManagersIn);
175  if (factoryName == "InitialBlockNumberFactory") return Build2<InitialBlockNumberFactory>(paramList, factoryMapIn, factoryManagersIn);
176  if (factoryName == "LineDetectionFactory") return Build2<LineDetectionFactory>(paramList, factoryMapIn, factoryManagersIn);
177  // LocalOrdinalTransferFactory is a utility factory that can be used for multiple things, so there is no default
178  // if (factoryName == "LocalOrdinalTransferFactory") return Build2<LocalOrdinalTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
179  if (factoryName == "MapTransferFactory") return Build2<MapTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
180  if (factoryName == "MatrixAnalysisFactory") return Build2<MatrixAnalysisFactory>(paramList, factoryMapIn, factoryManagersIn);
181  if (factoryName == "MultiVectorTransferFactory") return Build2<MultiVectorTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
182  if (factoryName == "NoFactory") return MueLu::NoFactory::getRCP();
183  if (factoryName == "NoSmoother") return rcp(new SmootherFactory(Teuchos::null));
184  if (factoryName == "NotayAggregationFactory") return Build2<NotayAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
185  if (factoryName == "NullspaceFactory") return Build2<NullspaceFactory>(paramList, factoryMapIn, factoryManagersIn);
186  if (factoryName == "NullspacePresmoothFactory") return Build2<NullspacePresmoothFactory>(paramList, factoryMapIn, factoryManagersIn);
187  if (factoryName == "PatternFactory") return Build2<PatternFactory>(paramList, factoryMapIn, factoryManagersIn);
188  if (factoryName == "PgPFactory") return Build2<PgPFactory>(paramList, factoryMapIn, factoryManagersIn);
189  if (factoryName == "SaPFactory") return Build2<SaPFactory>(paramList, factoryMapIn, factoryManagersIn);
190  if (factoryName == "RAPFactory") return BuildRAPFactory<RAPFactory>(paramList, factoryMapIn, factoryManagersIn);
191  if (factoryName == "RAPShiftFactory") return BuildRAPFactory<RAPShiftFactory>(paramList, factoryMapIn, factoryManagersIn);
192  if (factoryName == "RebalanceAcFactory") return Build2<RebalanceAcFactory>(paramList, factoryMapIn, factoryManagersIn);
193  if (factoryName == "RebalanceTransferFactory") return Build2<RebalanceTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
194  if (factoryName == "RegionRFactory") return Build2<RegionRFactory>(paramList, factoryMapIn, factoryManagersIn);
195  if (factoryName == "RegionRFactory_kokkos") return Build2<RegionRFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
196  if (factoryName == "ReorderBlockAFactory") return Build2<ReorderBlockAFactory>(paramList, factoryMapIn, factoryManagersIn);
197  if (factoryName == "RepartitionInterface") return Build2<RepartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
198  if (factoryName == "ScaledNullspaceFactory") return Build2<ScaledNullspaceFactory>(paramList, factoryMapIn, factoryManagersIn);
199  if (factoryName == "SegregatedAFactory") return Build2<SegregatedAFactory>(paramList, factoryMapIn, factoryManagersIn);
200  if (factoryName == "SemiCoarsenPFactory") return Build2<SemiCoarsenPFactory>(paramList, factoryMapIn, factoryManagersIn);
201  if (factoryName == "StructuredAggregationFactory") return Build2<StructuredAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
202  if (factoryName == "StructuredLineDetectionFactory") return Build2<StructuredLineDetectionFactory>(paramList, factoryMapIn, factoryManagersIn);
203  if (factoryName == "SubBlockAFactory") return Build2<SubBlockAFactory>(paramList, factoryMapIn, factoryManagersIn);
204  if (factoryName == "TentativePFactory") return Build2<TentativePFactory>(paramList, factoryMapIn, factoryManagersIn);
205  if (factoryName == "ToggleCoordinatesTransferFactory") return BuildToggleCoordinatesTransferFactory(paramList, factoryMapIn, factoryManagersIn);
206  if (factoryName == "TogglePFactory") return BuildTogglePFactory<TogglePFactory>(paramList, factoryMapIn, factoryManagersIn);
207  if (factoryName == "TransPFactory") return Build2<TransPFactory>(paramList, factoryMapIn, factoryManagersIn);
208  if (factoryName == "RfromP_Or_TransP") return Build2<RfromP_Or_TransP>(paramList, factoryMapIn, factoryManagersIn);
209  if (factoryName == "TrilinosSmoother") return BuildTrilinosSmoother(paramList, factoryMapIn, factoryManagersIn);
210  if (factoryName == "UncoupledAggregationFactory") return Build2<UncoupledAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
211  if (factoryName == "UnsmooshFactory") return Build2<UnsmooshFactory>(paramList, factoryMapIn, factoryManagersIn);
212  if (factoryName == "UserAggregationFactory") return Build2<UserAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
213  if (factoryName == "UserPFactory") return Build2<UserPFactory>(paramList, factoryMapIn, factoryManagersIn);
214  if (factoryName == "VariableDofLaplacianFactory") return Build2<VariableDofLaplacianFactory>(paramList, factoryMapIn, factoryManagersIn);
215  if (factoryName == "ZeroSubBlockAFactory") return Build2<ZeroSubBlockAFactory>(paramList, factoryMapIn, factoryManagersIn);
216  if (factoryName == "CoalesceDropFactory_kokkos") return Build2<CoalesceDropFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
217  if (factoryName == "GeometricInterpolationPFactory_kokkos") return Build2<GeometricInterpolationPFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
218 #ifdef HAVE_MUELU_DEPRECATED_CODE
219  if (factoryName == "NullspaceFactory_kokkos") return Build2<NullspaceFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
220  if (factoryName == "SaPFactory_kokkos") return Build2<SaPFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
221 #endif
222  if (factoryName == "SemiCoarsenPFactory_kokkos") return Build2<SemiCoarsenPFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
223  if (factoryName == "StructuredAggregationFactory_kokkos") return Build2<StructuredAggregationFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
224  if (factoryName == "TentativePFactory_kokkos") return Build2<TentativePFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
225  if (factoryName == "MatrixFreeTentativePFactory") return Build2<MatrixFreeTentativePFactory>(paramList, factoryMapIn, factoryManagersIn);
226 
227  // Handle removed Kokkos factories
228  if (factoryName == "CoarseMapFactory_kokkos") return Build2<CoarseMapFactory>(paramList, factoryMapIn, factoryManagersIn);
229  if (factoryName == "CoordinatesTransferFactory_kokkos") return Build2<CoordinatesTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
230 
231  if (factoryName == "ZoltanInterface") {
232 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
233  return Build2<ZoltanInterface>(paramList, factoryMapIn, factoryManagersIn);
234 #else
235  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a ZoltanInterface object: Zoltan is disabled: HAVE_MUELU_ZOLTAN && HAVE_MPI == false.");
236 #endif // HAVE_MUELU_ZOLTAN && HAVE_MPI
237  }
238  if (factoryName == "Zoltan2Interface") {
239 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
240  return Build2<Zoltan2Interface>(paramList, factoryMapIn, factoryManagersIn);
241 #else
242  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a Zoltan2Interface object: Zoltan2 is disabled: HAVE_MUELU_ZOLTAN2 && HAVE_MPI == false.");
243 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
244  }
245  if (factoryName == "IsorropiaInterface") {
246 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
247  return Build2<IsorropiaInterface>(paramList, factoryMapIn, factoryManagersIn);
248 #else
249  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a IsorropiaInterface object: Isorropia is disabled: HAVE_MUELU_ISORROPIA && HAVE_MPI == false.");
250 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
251  }
252 
253  if (factoryName == "NodePartitionInterface") {
254 #if defined(HAVE_MPI)
255  return Build2<NodePartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
256 #else
257  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a NodePartitionInterface object: HAVE_MPI == false.");
258 #endif // HAVE_MPI
259  }
260 
261  if (factoryName == "RepartitionFactory") {
262 #ifdef HAVE_MPI
263  return Build2<RepartitionFactory>(paramList, factoryMapIn, factoryManagersIn);
264 #else
265  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionFactory object: HAVE_MPI == false.");
266 #endif // HAVE_MPI
267  }
268  if (factoryName == "RepartitionHeuristicFactory") {
269 #ifdef HAVE_MPI
270  return Build2<RepartitionHeuristicFactory>(paramList, factoryMapIn, factoryManagersIn);
271 #else
272  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionHeuristicFactory object: HAVE_MPI == false.");
273 #endif // HAVE_MPI
274  }
275  // Blocked factories
276  if (factoryName == "BlockedCoordinatesTransferFactory") return BuildBlockedCoordFactory<BlockedCoordinatesTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
277  if (factoryName == "BlockedDirectSolver") return BuildBlockedDirectSolver(paramList, factoryMapIn, factoryManagersIn);
278  if (factoryName == "BlockedGaussSeidelSmoother") return BuildBlockedSmoother<BlockedGaussSeidelSmoother>(paramList, factoryMapIn, factoryManagersIn);
279  if (factoryName == "BlockedJacobiSmoother") return BuildBlockedSmoother<BlockedJacobiSmoother>(paramList, factoryMapIn, factoryManagersIn);
280  if (factoryName == "BlockedPFactory") return BuildBlockedFactory<BlockedPFactory>(paramList, factoryMapIn, factoryManagersIn);
281  if (factoryName == "BraessSarazinSmoother") return BuildBlockedSmoother<BraessSarazinSmoother>(paramList, factoryMapIn, factoryManagersIn);
282  if (factoryName == "IndefiniteBlockDiagonalSmoother") return BuildBlockedSmoother<IndefBlockedDiagonalSmoother>(paramList, factoryMapIn, factoryManagersIn);
283  if (factoryName == "SimpleSmoother") return BuildBlockedSmoother<SimpleSmoother>(paramList, factoryMapIn, factoryManagersIn);
284  if (factoryName == "SchurComplementFactory") return Build2<SchurComplementFactory>(paramList, factoryMapIn, factoryManagersIn);
285  if (factoryName == "RebalanceBlockRestrictionFactory") return BuildBlockedFactory<RebalanceBlockRestrictionFactory>(paramList, factoryMapIn, factoryManagersIn);
286  if (factoryName == "RebalanceBlockAcFactory") return BuildBlockedFactory<RebalanceBlockAcFactory>(paramList, factoryMapIn, factoryManagersIn);
287  if (factoryName == "RebalanceBlockInterpolationFactory") return BuildBlockedFactory<RebalanceBlockInterpolationFactory>(paramList, factoryMapIn, factoryManagersIn);
288 #ifdef HAVE_MPI
289  if (factoryName == "RepartitionBlockDiagonalFactory") return Build2<RepartitionBlockDiagonalFactory>(paramList, factoryMapIn, factoryManagersIn);
290 #endif
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 
296  // Matlab factories
297 #ifdef HAVE_MUELU_MATLAB
298  if (factoryName == "TwoLevelMatlabFactory") return Build2<TwoLevelMatlabFactory>(paramList, factoryMapIn, factoryManagersIn);
299  if (factoryName == "SingleLevelMatlabFactory") return Build2<SingleLevelMatlabFactory>(paramList, factoryMapIn, factoryManagersIn);
300  if (factoryName == "MatlabSmoother") return BuildMatlabSmoother(paramList, factoryMapIn, factoryManagersIn);
301 #endif
302 
303 #ifdef HAVE_MUELU_INTREPID2
304  if (factoryName == "IntrepidPCoarsenFactory") return Build2<IntrepidPCoarsenFactory>(paramList, factoryMapIn, factoryManagersIn);
305 #endif
306 
307  // Use a user defined factories (in <Factories> node)
308  if (factoryMapIn.find(factoryName) != factoryMapIn.end()) {
309  TEUCHOS_TEST_FOR_EXCEPTION((param.isList() && (++paramList.begin() != paramList.end())), Exceptions::RuntimeError,
310  "MueLu::FactoryFactory: Error during the parsing of: " << std::endl
311  << paramList << std::endl
312  << "'" << factoryName << "' is not a factory name but an existing instance of a factory." << std::endl
313  << "Extra parameters cannot be specified after the creation of the object." << std::endl
314  << std::endl
315  << "Correct syntaxes includes:" << std::endl
316  << " <Parameter name=\"...\" type=\"string\" value=\"" << factoryName << "\"/>" << std::endl
317  << "or" << std::endl
318  << " <ParameterList name=\"...\"><Parameter name=\"factory\" type=\"string\" value=\"" << factoryName << "\"/></ParameterList>" << std::endl);
319 
320  return factoryMapIn.find(factoryName)->second;
321  }
322 
323  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory: unknown factory name : " << factoryName);
324 
325  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
326 }
327 
328 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
329 template <class T>
331  RCP<T> factory = rcp(new T());
332 
333  const char* strarray[] = {"A", "P", "R", "Graph", "UnAmalgamationInfo", "Aggregates", "Nullspace", "TransferFactory", "DofsPerNode"};
334 #define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))
335  std::vector<std::string> v(strarray, strarray + arraysize(strarray));
336  for (size_t i = 0; i < v.size(); ++i)
337  if (paramList.isParameter(v[i]))
338  factory->SetFactory(v[i], BuildFactory(paramList.getEntry(v[i]), factoryMapIn, factoryManagersIn));
339 
340  return factory;
341 }
342 
343 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
344 template <class T> // T must implement the Factory interface
346  RCP<T> factory = rcp(new T());
347 
348  ParameterList paramListWithFactories;
349 
350  // Read the RCP<Factory> parameters of the class T
351  RCP<const ParameterList> validParamList = factory->GetValidParameterList(); // TODO check for Teuchos::null (no parameter list validation)
352  TEUCHOS_TEST_FOR_EXCEPTION(validParamList == Teuchos::null, Exceptions::RuntimeError, "FactoryFactory::Build2: default parameter list is null. Please fix this.");
353  for (ParameterList::ConstIterator param = validParamList->begin(); param != validParamList->end(); ++param) {
354  const std::string& pName = validParamList->name(param);
355 
356  if (!paramList.isParameter(pName)) {
357  // Ignore unknown parameters
358  continue;
359  }
360 
361  if (validParamList->isType<RCP<const FactoryBase> >(pName)) {
362  // Generate or get factory described by param
363  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry(pName), factoryMapIn, factoryManagersIn);
364  paramListWithFactories.set(pName, generatingFact);
365  } else if (validParamList->isType<RCP<const ParameterList> >(pName)) {
366  if (pName == "ParameterList") {
367  // NOTE: we cannot use
368  // subList = sublist(rcpFromRef(paramList), pName)
369  // here as that would result in sublist also being a reference to a temporary object.
370  // The resulting dereferencing in the corresponding factory would then segfault
371  RCP<const ParameterList> subList = Teuchos::sublist(rcp(new ParameterList(paramList)), pName);
372  paramListWithFactories.set(pName, subList);
373  }
374  } else {
375  paramListWithFactories.setEntry(pName, paramList.getEntry(pName));
376  }
377  }
378 
379  // Configure the factory
380  factory->SetParameterList(paramListWithFactories);
381 
382  return factory;
383 }
384 
385 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
386 template <class T> // T must implement the Factory interface
388  RCP<T> factory;
389  if (paramList.isSublist("TransferFactories") == false) {
390  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
391 
392  } else {
393  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
394  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
395 
396  paramListNonConst->remove("TransferFactories");
397 
398  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
399 
400  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
401  RCP<const FactoryBase> p = BuildFactory(transferFactories->entry(param), factoryMapIn, factoryManagersIn);
402  factory->AddTransferFactory(p);
403  }
404  }
405 
406  return factory;
407 }
408 
409 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
410 template <class T> // T must implement the Factory interface
412  RCP<T> factory;
413  if (paramList.isSublist("TransferFactories") == false) {
414  // TODO put in an error message: the TogglePFactory needs a TransferFactories sublist!
415  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
416 
417  } else {
418  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
419  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
420 
421  paramListNonConst->remove("TransferFactories");
422 
423  // build TogglePFactory
424  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
425 
426  // count how many prolongation factories and how many coarse null space factories have been declared.
427  // the numbers must match!
428  int numProlongatorFactories = 0;
429  int numPtentFactories = 0;
430  int numCoarseNspFactories = 0;
431  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
432  size_t foundNsp = transferFactories->name(param).find("Nullspace");
433  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length() == 10) {
434  numCoarseNspFactories++;
435  continue;
436  }
437  size_t foundPtent = transferFactories->name(param).find("Ptent");
438  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length() == 6) {
439  numPtentFactories++;
440  continue;
441  }
442  size_t foundP = transferFactories->name(param).find("P");
443  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length() == 2) {
444  numProlongatorFactories++;
445  continue;
446  }
447  }
448  TEUCHOS_TEST_FOR_EXCEPTION(numProlongatorFactories != numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of prolongator and coarse nullspace factories!");
449  TEUCHOS_TEST_FOR_EXCEPTION(numPtentFactories != numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of ptent and coarse nullspace factories!");
450  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.");
451 
452  // create empty vectors with data
453  std::vector<Teuchos::ParameterEntry> prolongatorFactoryNames(numProlongatorFactories);
454  std::vector<Teuchos::ParameterEntry> coarseNspFactoryNames(numProlongatorFactories);
455  std::vector<Teuchos::ParameterEntry> ptentFactoryNames(numProlongatorFactories);
456 
457  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
458  size_t foundNsp = transferFactories->name(param).find("Nullspace");
459  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length() == 10) {
460  int number = atoi(&(transferFactories->name(param).at(9)));
461  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!");
462  coarseNspFactoryNames[number - 1] = transferFactories->entry(param);
463  continue;
464  }
465  size_t foundPtent = transferFactories->name(param).find("Ptent");
466  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length() == 6) {
467  int number = atoi(&(transferFactories->name(param).at(5)));
468  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!");
469  ptentFactoryNames[number - 1] = transferFactories->entry(param);
470  continue;
471  }
472  size_t foundP = transferFactories->name(param).find("P");
473  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length() == 2) {
474  int number = atoi(&(transferFactories->name(param).at(1)));
475  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!");
476  prolongatorFactoryNames[number - 1] = transferFactories->entry(param);
477  continue;
478  }
479  }
480 
481  // register all prolongation factories in TogglePFactory
482  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = prolongatorFactoryNames.begin(); it != prolongatorFactoryNames.end(); ++it) {
483  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
484  factory->AddProlongatorFactory(p);
485  }
486 
487  // register all tentative prolongation factories in TogglePFactory
488  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = ptentFactoryNames.begin(); it != ptentFactoryNames.end(); ++it) {
489  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
490  factory->AddPtentFactory(p);
491  }
492 
493  // register all coarse nullspace factories in TogglePFactory
494  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseNspFactoryNames.begin(); it != coarseNspFactoryNames.end(); ++it) {
495  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
496  factory->AddCoarseNullspaceFactory(p);
497  }
498  }
499  return factory;
500 }
501 
502 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
505  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!");
506 
507  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
508  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
509  paramListNonConst->remove("TransferFactories");
510 
511  // build CoordinatesTransferFactory
512  factory = Build2<ToggleCoordinatesTransferFactory>(*paramListNonConst, factoryMapIn, factoryManagersIn);
513 
514  // count how many coordinate transfer factories have been declared.
515  // the numbers must match!
516  int numCoordTransferFactories = 0;
517  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
518  size_t foundCoordinates = transferFactories->name(param).find("Coordinates");
519  if (foundCoordinates != std::string::npos && foundCoordinates == 0 && transferFactories->name(param).length() == 12) {
520  numCoordTransferFactories++;
521  continue;
522  }
523  }
524  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.");
525 
526  // create empty vectors with data
527  std::vector<Teuchos::ParameterEntry> coarseCoordsFactoryNames(numCoordTransferFactories);
528 
529  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
530  size_t foundCoords = transferFactories->name(param).find("Coordinates");
531  if (foundCoords != std::string::npos && foundCoords == 0 && transferFactories->name(param).length() == 12) {
532  int number = atoi(&(transferFactories->name(param).at(11)));
533  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!");
534  coarseCoordsFactoryNames[number - 1] = transferFactories->entry(param);
535  continue;
536  }
537  }
538 
539  // register all coarse nullspace factories in TogglePFactory
540  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseCoordsFactoryNames.begin(); it != coarseCoordsFactoryNames.end(); ++it) {
541  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
542  factory->AddCoordTransferFactory(p);
543  }
544 
545  return factory;
546 }
547 
548 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
550  if (paramList.begin() == paramList.end())
551  return rcp(new SmootherFactory(rcp(new TrilinosSmoother())));
552 
553  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "TrilinosSmoother", Exceptions::RuntimeError, "");
554 
555  // Is it true? TEUCHOS_TEST_FOR_EXCEPTION(!paramList.isParameter("type"), Exceptions::RuntimeError, "TrilinosSmoother: parameter 'type' is mandatory");
556  // type="" is default in TrilinosSmoother, but what happen then?
557 
558  std::string type = "";
559  if (paramList.isParameter("type")) type = paramList.get<std::string>("type");
560  int overlap = 0;
561  if (paramList.isParameter("overlap")) overlap = paramList.get<int>("overlap");
562  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
563  Teuchos::ParameterList params;
564  if (paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
565 
566  // parameters from SmootherFactory
567  // bool bKeepSmootherData = false; if(paramList.isParameter("keep smoother data")) bKeepSmootherData = paramList.get<bool>("keep smoother data");
568 
569  // Read in factory information for smoothers (if available...)
570  // NOTE: only a selected number of factories can be used with the Trilinos smoother
571  // smoothers usually work with the global data available (which is A and the transfers P and R)
572 
573  Teuchos::RCP<TrilinosSmoother> trilSmoo = Teuchos::rcp(new TrilinosSmoother(type, params, overlap));
574 
575  if (paramList.isParameter("LineDetection_Layers")) {
576  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
577  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
578  }
579  if (paramList.isParameter("LineDetection_VertLineIds")) {
580  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
581  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
582  }
583  if (paramList.isParameter("CoarseNumZLayers")) {
584  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("CoarseNumZLayers"), factoryMapIn, factoryManagersIn);
585  trilSmoo->SetFactory("CoarseNumZLayers", generatingFact);
586  }
587 
588  RCP<SmootherFactory> smooFact = rcp(new SmootherFactory(Teuchos::null));
589  Teuchos::ParameterList smooFactParams;
590  // smooFactParams.setEntry("keep smoother data", paramList.getEntry("keep smoother data"));
591  smooFact->SetParameterList(smooFactParams);
592  smooFact->SetSmootherPrototypes(trilSmoo);
593  return smooFact;
594 }
595 
596 #ifdef HAVE_MUELU_MATLAB
600  if (paramList.begin() == paramList.end())
601  return rcp(new SmootherFactory(rcp(new MatlabSmoother())));
602 
603  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "MatlabSmoother", Exceptions::RuntimeError, "");
604 
605  // Read in factory information for smoothers (if available...)
606  // NOTE: only a selected number of factories can be used with the Trilinos smoother
607  // smoothers usually work with the global data available (which is A and the transfers P and R)
608 
609  Teuchos::RCP<MatlabSmoother> matSmoo = Teuchos::rcp(new MatlabSmoother(paramList));
610 
611  return rcp(new SmootherFactory(matSmoo));
612 }
613 #endif
614 
615 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
617  if (paramList.begin() == paramList.end())
618  return rcp(new SmootherFactory(rcp(new DirectSolver()), Teuchos::null));
619 
620  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "DirectSolver", Exceptions::RuntimeError, "");
621 
622  std::string type;
623  if (paramList.isParameter("type")) type = paramList.get<std::string>("type");
624  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
625  Teuchos::ParameterList params;
626  if (paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
627 
628  return rcp(new SmootherFactory(rcp(new DirectSolver(type, params)), Teuchos::null));
629 }
630 
631 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
632 template <class T> // T must implement the Factory interface
634  // read in sub lists
635  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
636 
637  // internal vector of factory managers
638  std::vector<RCP<FactoryManager> > facManagers;
639 
640  // loop over all "block%i" sublists in parameter list
641  int blockid = 1;
642  bool blockExists = true;
643  while (blockExists == true) {
644  std::stringstream ss;
645  ss << "block" << blockid;
646 
647  if (paramList.isSublist(ss.str()) == true) {
648  // we either have a parameter group or we have a list of factories in here
649  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
650 
651  RCP<FactoryManager> M = Teuchos::null;
652 
653  if (b->isParameter("group")) {
654  // use a factory manager
655  std::string facManagerName = b->get<std::string>("group");
656  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.");
657  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
658  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
659  TEUCHOS_TEST_FOR_EXCEPTION(M == Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
660  } else {
661  // read in the list of factories
662  M = rcp(new FactoryManager());
663  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
664  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
665  M->SetFactory(b->name(param), p);
666  }
667  }
668 
669  // add factory manager to internal vector of factory managers
670  M->SetIgnoreUserData(true);
671  facManagers.push_back(M);
672  paramListNonConst->remove(ss.str());
673  blockid++;
674  } else {
675  blockExists = false;
676  break;
677  }
678  }
679 
680  // create a new blocked smoother
681  RCP<T> bs = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
682 
683  // important: set block factory for A here!
684  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
685  // The user might want to overwrite this in the xml file, so just
686  // use what is declared as "A"
687  // bs->SetFactory("A", MueLu::NoFactory::getRCP());
688 
689  for (int i = 0; i < Teuchos::as<int>(facManagers.size()); i++) {
690  bs->AddFactoryManager(facManagers[i], i);
691  }
692 
693  return rcp(new SmootherFactory(bs));
694 }
695 
696 #ifdef HAVE_MUELU_TEKO
697 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
699  // read in sub lists
700  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
701  RCP<ParameterList> tekoParams = rcp(new ParameterList(paramListNonConst->sublist("Inverse Factory Library")));
702  paramListNonConst->remove("Inverse Factory Library");
703 
704  // create a new blocked smoother
705  RCP<TekoSmoother> bs = Build2<TekoSmoother>(*paramListNonConst, factoryMapIn, factoryManagersIn);
706 
707  // important: set block factory for A here!
708  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
709  // The user might want to overwrite this in the xml file, so just
710  // use what is declared as "A"
711  // bs->SetFactory("A", MueLu::NoFactory::getRCP());
712 
713  // Set Teko parameters ("Inverse Factory Library")
714  bs->SetTekoParameters(tekoParams);
715 
716  return rcp(new SmootherFactory(bs));
717 }
718 #endif
719 
720 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
722  if (paramList.numParams() == 0)
723  return rcp(new SmootherFactory(rcp(new BlockedDirectSolver())));
724 
725  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "BlockedDirectSolver", Exceptions::RuntimeError, "FactoryFactory::BuildBlockedDirectSolver: Generating factory needs to be a BlockedDirectSolver.");
726 
727  std::string type;
728  if (paramList.isParameter("type")) type = paramList.get<std::string>("type");
729  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
730  Teuchos::ParameterList params;
731  if (paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
732 
733  return rcp(new SmootherFactory(rcp(new BlockedDirectSolver(type, params))));
734 }
735 
736 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
737 template <class T> // T must implement the Factory interface
739  RCP<T> pfac = Teuchos::null;
740 
741  // read in sub lists
742  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
743 
744  // internal vector of factory managers
745  std::vector<RCP<FactoryManager> > facManagers;
746 
747  // loop over all "block%i" sublists in parameter list
748  int blockid = 1;
749  bool blockExists = true;
750  while (blockExists == true) {
751  std::stringstream ss;
752  ss << "block" << blockid;
753 
754  if (paramList.isSublist(ss.str()) == true) {
755  // we either have a parameter group or we have a list of factories in here
756  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
757 
758  RCP<FactoryManager> M = Teuchos::null;
759 
760  if (b->isParameter("group")) {
761  // use a factory manager
762  std::string facManagerName = b->get<std::string>("group");
763  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.");
764  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
765  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
766  TEUCHOS_TEST_FOR_EXCEPTION(M == Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
767  } else {
768  // read in the list of factories
769  M = rcp(new FactoryManager());
770  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
771  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
772  M->SetFactory(b->name(param), p);
773  }
774  }
775 
776  // add factory manager to internal vector of factory managers
777  M->SetIgnoreUserData(true);
778  facManagers.push_back(M);
779  paramListNonConst->remove(ss.str());
780  blockid++;
781  } else {
782  blockExists = false;
783  break;
784  }
785  }
786 
787  // build BlockedPFactory (without sub block information)
788  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
789 
790  // add FactoryManager objects
791  for (size_t i = 0; i < facManagers.size(); i++) {
792  pfac->AddFactoryManager(facManagers[i]); // add factory manager
793  }
794 
795  return pfac;
796 }
797 
798 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
799 template <class T> // T must implement the Factory interface
801  RCP<T> pfac = Teuchos::null;
802 
803  // read in sub lists
804  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
805 
806  // internal vector of factory managers
807  std::vector<RCP<const FactoryBase> > facBase;
808 
809  // loop over all "block%i" sublists in parameter list
810  int blockid = 1;
811  bool blockExists = true;
812  while (blockExists == true) {
813  std::stringstream ss;
814  ss << "block" << blockid;
815 
816  if (paramList.isSublist(ss.str()) == true) {
817  // we either have a parameter group or we have a list of factories in here
818  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
819 
820  // read in the list of factories
821  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
822  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
823  facBase.push_back(p);
824  }
825 
826  // add factory manager to internal vector of factory managers
827  paramListNonConst->remove(ss.str());
828  blockid++;
829  } else {
830  blockExists = false;
831  break;
832  }
833  }
834 
835  // build BlockedPFactory (without sub block information)
836  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
837 
838  // add FactoryManager objects
839  for (size_t i = 0; i < facBase.size(); i++) {
840  pfac->AddFactory(facBase[i]); // add factory manager
841  }
842 
843  return pfac;
844 }
845 } // namespace MueLu
846 
847 #endif
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
RCP< ToggleCoordinatesTransferFactory > BuildToggleCoordinatesTransferFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
const std::string & name() const
This class specifies the default factory that should generate some data on a Level if the data does n...
ParameterList & setEntry(const std::string &name, U &&entry)
ConstIterator end() const
RCP< FactoryBase > BuildMatlabSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
MatlabSmoother.
virtual RCP< const FactoryBase > BuildFactory(const Teuchos::ParameterEntry &param, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
: Interpret Factory parameter list and build new factory
Factory that can generate other factories from.
T & get(const std::string &name, T def_value)
Class that encapsulates external library smoothers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< T > Build2(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< T > BuildTogglePFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Ordinal numParams() const
RCP< T > BuildBlockedFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void AddCoordTransferFactory(const RCP< const FactoryBase > &factory)
Add a coordinate transfer factory in the end of list of coordinate transfer factories.
RCP< FactoryBase > BuildDirectSolver(const Teuchos::ParameterList &paramList, const FactoryMap &, const FactoryManagerMap &) const
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
void SetTekoParameters(RCP< ParameterList > tekoParams)
bool isParameter(const std::string &name) const
std::map< std::string, RCP< FactoryManagerBase > > FactoryManagerMap
bool remove(std::string const &name, bool throwIfNotExists=true)
RCP< FactoryBase > BuildTrilinosSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
TrilinosSmoother.
RCP< T > Build(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
void SetSmootherPrototypes(RCP< SmootherPrototype > preAndPostSmootherPrototype)
Set smoother prototypes.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::map< std::string, RCP< const FactoryBase > > FactoryMap
bool isSublist(const std::string &name) const
RCP< FactoryBase > BuildBlockedDirectSolver(const Teuchos::ParameterList &paramList, const FactoryMap &, const FactoryManagerMap &) const
params_t::ConstIterator ConstIterator
static const RCP< const NoFactory > getRCP()
Static Get() functions.
ConstIterator begin() const
direct solver for nxn blocked matrices
const ParameterEntry & entry(ConstIterator i) const
Class that encapsulates Matlab smoothers.
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
RCP< FactoryBase > BuildBlockedSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< T > BuildRAPFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
bool isType(const std::string &name) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define arraysize(ar)
Exception throws to report errors in the internal logical of the program.
RCP< FactoryBase > BuildTekoSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
ParameterEntry & getEntry(const std::string &name)
RCP< T > BuildBlockedCoordFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.