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_SaPFactory_kokkos.hpp"
109 #endif
110 #include "MueLu_SemiCoarsenPFactory_kokkos.hpp"
111 #include "MueLu_StructuredAggregationFactory_kokkos.hpp"
112 #include "MueLu_TentativePFactory_kokkos.hpp"
113 #include "MueLu_MatrixFreeTentativePFactory.hpp"
114 #include "MueLu_RegionRFactory_kokkos.hpp"
115 
116 #ifdef HAVE_MUELU_MATLAB
117 #include "MueLu_SingleLevelMatlabFactory.hpp"
118 #include "MueLu_TwoLevelMatlabFactory.hpp"
119 #include "MueLu_MatlabSmoother.hpp"
120 #endif
121 
122 #ifdef HAVE_MUELU_INTREPID2
123 #include "MueLu_IntrepidPCoarsenFactory.hpp"
124 #endif
125 
126 namespace MueLu {
127 
128 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
130  // Find factory
131  std::string factoryName;
132  Teuchos::ParameterList paramList;
133  if (!param.isList()) {
134  factoryName = Teuchos::getValue<std::string>(param);
135  } else {
136  paramList = Teuchos::getValue<Teuchos::ParameterList>(param);
137  factoryName = paramList.get<std::string>("factory");
138  }
139 
140  // TODO: see how Teko handles this (=> register factories).
141  if (factoryName == "AggregateQualityEstimateFactory") return Build2<AggregateQualityEstimateFactory>(paramList, factoryMapIn, factoryManagersIn);
142  if (factoryName == "AggregationExportFactory") return Build2<AggregationExportFactory>(paramList, factoryMapIn, factoryManagersIn);
143  if (factoryName == "AmalgamationFactory") return Build2<AmalgamationFactory>(paramList, factoryMapIn, factoryManagersIn);
144  if (factoryName == "BlockedCoarseMapFactory") return Build2<BlockedCoarseMapFactory>(paramList, factoryMapIn, factoryManagersIn);
145  if (factoryName == "BlockedRAPFactory") return BuildRAPFactory<BlockedRAPFactory>(paramList, factoryMapIn, factoryManagersIn);
146  if (factoryName == "BrickAggregationFactory") return Build2<BrickAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
147  if (factoryName == "ClassicalMapFactory") return Build2<ClassicalMapFactory>(paramList, factoryMapIn, factoryManagersIn);
148  if (factoryName == "ClassicalPFactory") return Build2<ClassicalPFactory>(paramList, factoryMapIn, factoryManagersIn);
149  if (factoryName == "CloneRepartitionInterface") return Build2<CloneRepartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
150  if (factoryName == "CoarseMapFactory") return Build2<CoarseMapFactory>(paramList, factoryMapIn, factoryManagersIn);
151  if (factoryName == "CoarseningVisualizationFactory") return Build2<CoarseningVisualizationFactory>(paramList, factoryMapIn, factoryManagersIn);
152  if (factoryName == "CoalesceDropFactory") return Build2<CoalesceDropFactory>(paramList, factoryMapIn, factoryManagersIn);
153  if (factoryName == "SmooVecCoalesceDropFactory") return Build2<SmooVecCoalesceDropFactory>(paramList, factoryMapIn, factoryManagersIn);
154  if (factoryName == "ConstraintFactory") return Build2<ConstraintFactory>(paramList, factoryMapIn, factoryManagersIn);
155  if (factoryName == "CoordinatesTransferFactory") return Build2<CoordinatesTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
156  if (factoryName == "DirectSolver") return BuildDirectSolver(paramList, factoryMapIn, factoryManagersIn);
157  if (factoryName == "DropNegativeEntriesFactory") return Build2<DropNegativeEntriesFactory>(paramList, factoryMapIn, factoryManagersIn);
158  if (factoryName == "EminPFactory") return Build2<EminPFactory>(paramList, factoryMapIn, factoryManagersIn);
159  if (factoryName == "FilteredAFactory") return Build2<FilteredAFactory>(paramList, factoryMapIn, factoryManagersIn);
160  if (factoryName == "FineLevelInputDataFactory") return Build2<FineLevelInputDataFactory>(paramList, factoryMapIn, factoryManagersIn);
161  if (factoryName == "GeneralGeometricPFactory") return Build2<GeneralGeometricPFactory>(paramList, factoryMapIn, factoryManagersIn);
162  if (factoryName == "ReplicatePFactory") return Build2<ReplicatePFactory>(paramList, factoryMapIn, factoryManagersIn);
163  if (factoryName == "CombinePFactory") return Build2<CombinePFactory>(paramList, factoryMapIn, factoryManagersIn);
164  if (factoryName == "GenericRFactory") return Build2<GenericRFactory>(paramList, factoryMapIn, factoryManagersIn);
165  if (factoryName == "GeometricInterpolationPFactory") return Build2<GeometricInterpolationPFactory>(paramList, factoryMapIn, factoryManagersIn);
166  if (factoryName == "HybridAggregationFactory") return Build2<HybridAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
167  if (factoryName == "InterfaceAggregationFactory") return Build2<InterfaceAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
168  if (factoryName == "InterfaceMappingTransferFactory") return Build2<InterfaceMappingTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
169  if (factoryName == "InverseApproximationFactory") return Build2<InverseApproximationFactory>(paramList, factoryMapIn, factoryManagersIn);
170  if (factoryName == "InitialBlockNumberFactory") return Build2<InitialBlockNumberFactory>(paramList, factoryMapIn, factoryManagersIn);
171  if (factoryName == "LineDetectionFactory") return Build2<LineDetectionFactory>(paramList, factoryMapIn, factoryManagersIn);
172  // LocalOrdinalTransferFactory is a utility factory that can be used for multiple things, so there is no default
173  // if (factoryName == "LocalOrdinalTransferFactory") return Build2<LocalOrdinalTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
174  if (factoryName == "MapTransferFactory") return Build2<MapTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
175  if (factoryName == "MatrixAnalysisFactory") return Build2<MatrixAnalysisFactory>(paramList, factoryMapIn, factoryManagersIn);
176  if (factoryName == "MultiVectorTransferFactory") return Build2<MultiVectorTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
177  if (factoryName == "NoFactory") return MueLu::NoFactory::getRCP();
178  if (factoryName == "NoSmoother") return rcp(new SmootherFactory(Teuchos::null));
179  if (factoryName == "NotayAggregationFactory") return Build2<NotayAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
180  if (factoryName == "NullspaceFactory") return Build2<NullspaceFactory>(paramList, factoryMapIn, factoryManagersIn);
181  if (factoryName == "NullspacePresmoothFactory") return Build2<NullspacePresmoothFactory>(paramList, factoryMapIn, factoryManagersIn);
182  if (factoryName == "PatternFactory") return Build2<PatternFactory>(paramList, factoryMapIn, factoryManagersIn);
183  if (factoryName == "PgPFactory") return Build2<PgPFactory>(paramList, factoryMapIn, factoryManagersIn);
184  if (factoryName == "SaPFactory") return Build2<SaPFactory>(paramList, factoryMapIn, factoryManagersIn);
185  if (factoryName == "RAPFactory") return BuildRAPFactory<RAPFactory>(paramList, factoryMapIn, factoryManagersIn);
186  if (factoryName == "RAPShiftFactory") return BuildRAPFactory<RAPShiftFactory>(paramList, factoryMapIn, factoryManagersIn);
187  if (factoryName == "RebalanceAcFactory") return Build2<RebalanceAcFactory>(paramList, factoryMapIn, factoryManagersIn);
188  if (factoryName == "RebalanceTransferFactory") return Build2<RebalanceTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
189  if (factoryName == "RegionRFactory") return Build2<RegionRFactory>(paramList, factoryMapIn, factoryManagersIn);
190  if (factoryName == "RegionRFactory_kokkos") return Build2<RegionRFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
191  if (factoryName == "ReorderBlockAFactory") return Build2<ReorderBlockAFactory>(paramList, factoryMapIn, factoryManagersIn);
192  if (factoryName == "RepartitionInterface") return Build2<RepartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
193  if (factoryName == "ScaledNullspaceFactory") return Build2<ScaledNullspaceFactory>(paramList, factoryMapIn, factoryManagersIn);
194  if (factoryName == "SegregatedAFactory") return Build2<SegregatedAFactory>(paramList, factoryMapIn, factoryManagersIn);
195  if (factoryName == "SemiCoarsenPFactory") return Build2<SemiCoarsenPFactory>(paramList, factoryMapIn, factoryManagersIn);
196  if (factoryName == "StructuredAggregationFactory") return Build2<StructuredAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
197  if (factoryName == "StructuredLineDetectionFactory") return Build2<StructuredLineDetectionFactory>(paramList, factoryMapIn, factoryManagersIn);
198  if (factoryName == "SubBlockAFactory") return Build2<SubBlockAFactory>(paramList, factoryMapIn, factoryManagersIn);
199  if (factoryName == "TentativePFactory") return Build2<TentativePFactory>(paramList, factoryMapIn, factoryManagersIn);
200  if (factoryName == "ToggleCoordinatesTransferFactory") return BuildToggleCoordinatesTransferFactory(paramList, factoryMapIn, factoryManagersIn);
201  if (factoryName == "TogglePFactory") return BuildTogglePFactory<TogglePFactory>(paramList, factoryMapIn, factoryManagersIn);
202  if (factoryName == "TransPFactory") return Build2<TransPFactory>(paramList, factoryMapIn, factoryManagersIn);
203  if (factoryName == "RfromP_Or_TransP") return Build2<RfromP_Or_TransP>(paramList, factoryMapIn, factoryManagersIn);
204  if (factoryName == "TrilinosSmoother") return BuildTrilinosSmoother(paramList, factoryMapIn, factoryManagersIn);
205  if (factoryName == "UncoupledAggregationFactory") return Build2<UncoupledAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
206  if (factoryName == "UnsmooshFactory") return Build2<UnsmooshFactory>(paramList, factoryMapIn, factoryManagersIn);
207  if (factoryName == "UserAggregationFactory") return Build2<UserAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
208  if (factoryName == "UserPFactory") return Build2<UserPFactory>(paramList, factoryMapIn, factoryManagersIn);
209  if (factoryName == "VariableDofLaplacianFactory") return Build2<VariableDofLaplacianFactory>(paramList, factoryMapIn, factoryManagersIn);
210  if (factoryName == "ZeroSubBlockAFactory") return Build2<ZeroSubBlockAFactory>(paramList, factoryMapIn, factoryManagersIn);
211  if (factoryName == "CoalesceDropFactory_kokkos") return Build2<CoalesceDropFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
212  if (factoryName == "GeometricInterpolationPFactory_kokkos") return Build2<GeometricInterpolationPFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
213 #ifdef HAVE_MUELU_DEPRECATED_CODE
214  if (factoryName == "SaPFactory_kokkos") return Build2<SaPFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
215 #endif
216  if (factoryName == "SemiCoarsenPFactory_kokkos") return Build2<SemiCoarsenPFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
217  if (factoryName == "StructuredAggregationFactory_kokkos") return Build2<StructuredAggregationFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
218  if (factoryName == "TentativePFactory_kokkos") return Build2<TentativePFactory_kokkos>(paramList, factoryMapIn, factoryManagersIn);
219  if (factoryName == "MatrixFreeTentativePFactory") return Build2<MatrixFreeTentativePFactory>(paramList, factoryMapIn, factoryManagersIn);
220 
221  // Handle removed Kokkos factories
222  if (factoryName == "CoarseMapFactory_kokkos") return Build2<CoarseMapFactory>(paramList, factoryMapIn, factoryManagersIn);
223  if (factoryName == "CoordinatesTransferFactory_kokkos") return Build2<CoordinatesTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
224 
225  if (factoryName == "ZoltanInterface") {
226 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
227  return Build2<ZoltanInterface>(paramList, factoryMapIn, factoryManagersIn);
228 #else
229  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a ZoltanInterface object: Zoltan is disabled: HAVE_MUELU_ZOLTAN && HAVE_MPI == false.");
230 #endif // HAVE_MUELU_ZOLTAN && HAVE_MPI
231  }
232  if (factoryName == "Zoltan2Interface") {
233 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
234  return Build2<Zoltan2Interface>(paramList, factoryMapIn, factoryManagersIn);
235 #else
236  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a Zoltan2Interface object: Zoltan2 is disabled: HAVE_MUELU_ZOLTAN2 && HAVE_MPI == false.");
237 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
238  }
239  if (factoryName == "IsorropiaInterface") {
240 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
241  return Build2<IsorropiaInterface>(paramList, factoryMapIn, factoryManagersIn);
242 #else
243  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a IsorropiaInterface object: Isorropia is disabled: HAVE_MUELU_ISORROPIA && HAVE_MPI == false.");
244 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
245  }
246 
247  if (factoryName == "NodePartitionInterface") {
248 #if defined(HAVE_MPI)
249  return Build2<NodePartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
250 #else
251  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a NodePartitionInterface object: HAVE_MPI == false.");
252 #endif // HAVE_MPI
253  }
254 
255  if (factoryName == "RepartitionFactory") {
256 #ifdef HAVE_MPI
257  return Build2<RepartitionFactory>(paramList, factoryMapIn, factoryManagersIn);
258 #else
259  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionFactory object: HAVE_MPI == false.");
260 #endif // HAVE_MPI
261  }
262  if (factoryName == "RepartitionHeuristicFactory") {
263 #ifdef HAVE_MPI
264  return Build2<RepartitionHeuristicFactory>(paramList, factoryMapIn, factoryManagersIn);
265 #else
266  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionHeuristicFactory object: HAVE_MPI == false.");
267 #endif // HAVE_MPI
268  }
269  // Blocked factories
270  if (factoryName == "BlockedCoordinatesTransferFactory") return BuildBlockedCoordFactory<BlockedCoordinatesTransferFactory>(paramList, factoryMapIn, factoryManagersIn);
271  if (factoryName == "BlockedDirectSolver") return BuildBlockedDirectSolver(paramList, factoryMapIn, factoryManagersIn);
272  if (factoryName == "BlockedGaussSeidelSmoother") return BuildBlockedSmoother<BlockedGaussSeidelSmoother>(paramList, factoryMapIn, factoryManagersIn);
273  if (factoryName == "BlockedJacobiSmoother") return BuildBlockedSmoother<BlockedJacobiSmoother>(paramList, factoryMapIn, factoryManagersIn);
274  if (factoryName == "BlockedPFactory") return BuildBlockedFactory<BlockedPFactory>(paramList, factoryMapIn, factoryManagersIn);
275  if (factoryName == "BraessSarazinSmoother") return BuildBlockedSmoother<BraessSarazinSmoother>(paramList, factoryMapIn, factoryManagersIn);
276  if (factoryName == "IndefiniteBlockDiagonalSmoother") return BuildBlockedSmoother<IndefBlockedDiagonalSmoother>(paramList, factoryMapIn, factoryManagersIn);
277  if (factoryName == "SimpleSmoother") return BuildBlockedSmoother<SimpleSmoother>(paramList, factoryMapIn, factoryManagersIn);
278  if (factoryName == "SchurComplementFactory") return Build2<SchurComplementFactory>(paramList, factoryMapIn, factoryManagersIn);
279  if (factoryName == "RebalanceBlockRestrictionFactory") return BuildBlockedFactory<RebalanceBlockRestrictionFactory>(paramList, factoryMapIn, factoryManagersIn);
280  if (factoryName == "RebalanceBlockAcFactory") return BuildBlockedFactory<RebalanceBlockAcFactory>(paramList, factoryMapIn, factoryManagersIn);
281  if (factoryName == "RebalanceBlockInterpolationFactory") return BuildBlockedFactory<RebalanceBlockInterpolationFactory>(paramList, factoryMapIn, factoryManagersIn);
282 #ifdef HAVE_MPI
283  if (factoryName == "RepartitionBlockDiagonalFactory") return Build2<RepartitionBlockDiagonalFactory>(paramList, factoryMapIn, factoryManagersIn);
284 #endif
285 #ifdef HAVE_MUELU_TEKO
286  if (factoryName == "TekoSmoother") return BuildTekoSmoother(paramList, factoryMapIn, factoryManagersIn);
287 #endif
288  if (factoryName == "UzawaSmoother") return BuildBlockedSmoother<UzawaSmoother>(paramList, factoryMapIn, factoryManagersIn);
289 
290  // Matlab factories
291 #ifdef HAVE_MUELU_MATLAB
292  if (factoryName == "SingleLevelMatlabFactory") return Build2<SingleLevelMatlabFactory>(paramList, factoryMapIn, factoryManagersIn);
293  if (factoryName == "TwoLevelMatlabFactory") return Build2<TwoLevelMatlabFactory>(paramList, factoryMapIn, factoryManagersIn);
294  if (factoryName == "MatlabSmoother") return BuildMatlabSmoother(paramList, factoryMapIn, factoryManagersIn);
295 #endif
296 
297 #ifdef HAVE_MUELU_INTREPID2
298  if (factoryName == "IntrepidPCoarsenFactory") return Build2<IntrepidPCoarsenFactory>(paramList, factoryMapIn, factoryManagersIn);
299 #endif
300 
301  // Use a user defined factories (in <Factories> node)
302  if (factoryMapIn.find(factoryName) != factoryMapIn.end()) {
303  TEUCHOS_TEST_FOR_EXCEPTION((param.isList() && (++paramList.begin() != paramList.end())), Exceptions::RuntimeError,
304  "MueLu::FactoryFactory: Error during the parsing of: " << std::endl
305  << paramList << std::endl
306  << "'" << factoryName << "' is not a factory name but an existing instance of a factory." << std::endl
307  << "Extra parameters cannot be specified after the creation of the object." << std::endl
308  << std::endl
309  << "Correct syntaxes includes:" << std::endl
310  << " <Parameter name=\"...\" type=\"string\" value=\"" << factoryName << "\"/>" << std::endl
311  << "or" << std::endl
312  << " <ParameterList name=\"...\"><Parameter name=\"factory\" type=\"string\" value=\"" << factoryName << "\"/></ParameterList>" << std::endl);
313 
314  return factoryMapIn.find(factoryName)->second;
315  }
316 
317  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory: unknown factory name : " << factoryName);
318 
319  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
320 }
321 
322 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
323 template <class T>
325  RCP<T> factory = rcp(new T());
326 
327  const char* strarray[] = {"A", "P", "R", "Graph", "UnAmalgamationInfo", "Aggregates", "Nullspace", "TransferFactory", "DofsPerNode"};
328 #define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))
329  std::vector<std::string> v(strarray, strarray + arraysize(strarray));
330  for (size_t i = 0; i < v.size(); ++i)
331  if (paramList.isParameter(v[i]))
332  factory->SetFactory(v[i], BuildFactory(paramList.getEntry(v[i]), factoryMapIn, factoryManagersIn));
333 
334  return factory;
335 }
336 
337 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
338 template <class T> // T must implement the Factory interface
340  RCP<T> factory = rcp(new T());
341 
342  ParameterList paramListWithFactories;
343 
344  // Read the RCP<Factory> parameters of the class T
345  RCP<const ParameterList> validParamList = factory->GetValidParameterList(); // TODO check for Teuchos::null (no parameter list validation)
346  TEUCHOS_TEST_FOR_EXCEPTION(validParamList == Teuchos::null, Exceptions::RuntimeError, "FactoryFactory::Build2: default parameter list is null. Please fix this.");
347  for (ParameterList::ConstIterator param = validParamList->begin(); param != validParamList->end(); ++param) {
348  const std::string& pName = validParamList->name(param);
349 
350  if (!paramList.isParameter(pName)) {
351  // Ignore unknown parameters
352  continue;
353  }
354 
355  if (validParamList->isType<RCP<const FactoryBase> >(pName)) {
356  // Generate or get factory described by param
357  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry(pName), factoryMapIn, factoryManagersIn);
358  paramListWithFactories.set(pName, generatingFact);
359  } else if (validParamList->isType<RCP<const ParameterList> >(pName)) {
360  if (pName == "ParameterList") {
361  // NOTE: we cannot use
362  // subList = sublist(rcpFromRef(paramList), pName)
363  // here as that would result in sublist also being a reference to a temporary object.
364  // The resulting dereferencing in the corresponding factory would then segfault
365  RCP<const ParameterList> subList = Teuchos::sublist(rcp(new ParameterList(paramList)), pName);
366  paramListWithFactories.set(pName, subList);
367  }
368  } else {
369  paramListWithFactories.setEntry(pName, paramList.getEntry(pName));
370  }
371  }
372 
373  // Configure the factory
374  factory->SetParameterList(paramListWithFactories);
375 
376  return factory;
377 }
378 
379 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
380 template <class T> // T must implement the Factory interface
382  RCP<T> factory;
383  if (paramList.isSublist("TransferFactories") == false) {
384  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
385 
386  } else {
387  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
388  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
389 
390  paramListNonConst->remove("TransferFactories");
391 
392  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
393 
394  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
395  RCP<const FactoryBase> p = BuildFactory(transferFactories->entry(param), factoryMapIn, factoryManagersIn);
396  factory->AddTransferFactory(p);
397  }
398  }
399 
400  return factory;
401 }
402 
403 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
404 template <class T> // T must implement the Factory interface
406  RCP<T> factory;
407  if (paramList.isSublist("TransferFactories") == false) {
408  // TODO put in an error message: the TogglePFactory needs a TransferFactories sublist!
409  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
410 
411  } else {
412  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
413  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
414 
415  paramListNonConst->remove("TransferFactories");
416 
417  // build TogglePFactory
418  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
419 
420  // count how many prolongation factories and how many coarse null space factories have been declared.
421  // the numbers must match!
422  int numProlongatorFactories = 0;
423  int numPtentFactories = 0;
424  int numCoarseNspFactories = 0;
425  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
426  size_t foundNsp = transferFactories->name(param).find("Nullspace");
427  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length() == 10) {
428  numCoarseNspFactories++;
429  continue;
430  }
431  size_t foundPtent = transferFactories->name(param).find("Ptent");
432  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length() == 6) {
433  numPtentFactories++;
434  continue;
435  }
436  size_t foundP = transferFactories->name(param).find("P");
437  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length() == 2) {
438  numProlongatorFactories++;
439  continue;
440  }
441  }
442  TEUCHOS_TEST_FOR_EXCEPTION(numProlongatorFactories != numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of prolongator and coarse nullspace factories!");
443  TEUCHOS_TEST_FOR_EXCEPTION(numPtentFactories != numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of ptent and coarse nullspace factories!");
444  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.");
445 
446  // create empty vectors with data
447  std::vector<Teuchos::ParameterEntry> prolongatorFactoryNames(numProlongatorFactories);
448  std::vector<Teuchos::ParameterEntry> coarseNspFactoryNames(numProlongatorFactories);
449  std::vector<Teuchos::ParameterEntry> ptentFactoryNames(numProlongatorFactories);
450 
451  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
452  size_t foundNsp = transferFactories->name(param).find("Nullspace");
453  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length() == 10) {
454  int number = atoi(&(transferFactories->name(param).at(9)));
455  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!");
456  coarseNspFactoryNames[number - 1] = transferFactories->entry(param);
457  continue;
458  }
459  size_t foundPtent = transferFactories->name(param).find("Ptent");
460  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length() == 6) {
461  int number = atoi(&(transferFactories->name(param).at(5)));
462  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!");
463  ptentFactoryNames[number - 1] = transferFactories->entry(param);
464  continue;
465  }
466  size_t foundP = transferFactories->name(param).find("P");
467  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length() == 2) {
468  int number = atoi(&(transferFactories->name(param).at(1)));
469  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!");
470  prolongatorFactoryNames[number - 1] = transferFactories->entry(param);
471  continue;
472  }
473  }
474 
475  // register all prolongation factories in TogglePFactory
476  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = prolongatorFactoryNames.begin(); it != prolongatorFactoryNames.end(); ++it) {
477  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
478  factory->AddProlongatorFactory(p);
479  }
480 
481  // register all tentative prolongation factories in TogglePFactory
482  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = ptentFactoryNames.begin(); it != ptentFactoryNames.end(); ++it) {
483  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
484  factory->AddPtentFactory(p);
485  }
486 
487  // register all coarse nullspace factories in TogglePFactory
488  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseNspFactoryNames.begin(); it != coarseNspFactoryNames.end(); ++it) {
489  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
490  factory->AddCoarseNullspaceFactory(p);
491  }
492  }
493  return factory;
494 }
495 
496 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
499  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!");
500 
501  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
502  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
503  paramListNonConst->remove("TransferFactories");
504 
505  // build CoordinatesTransferFactory
506  factory = Build2<ToggleCoordinatesTransferFactory>(*paramListNonConst, factoryMapIn, factoryManagersIn);
507 
508  // count how many coordinate transfer factories have been declared.
509  // the numbers must match!
510  int numCoordTransferFactories = 0;
511  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
512  size_t foundCoordinates = transferFactories->name(param).find("Coordinates");
513  if (foundCoordinates != std::string::npos && foundCoordinates == 0 && transferFactories->name(param).length() == 12) {
514  numCoordTransferFactories++;
515  continue;
516  }
517  }
518  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.");
519 
520  // create empty vectors with data
521  std::vector<Teuchos::ParameterEntry> coarseCoordsFactoryNames(numCoordTransferFactories);
522 
523  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
524  size_t foundCoords = transferFactories->name(param).find("Coordinates");
525  if (foundCoords != std::string::npos && foundCoords == 0 && transferFactories->name(param).length() == 12) {
526  int number = atoi(&(transferFactories->name(param).at(11)));
527  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!");
528  coarseCoordsFactoryNames[number - 1] = transferFactories->entry(param);
529  continue;
530  }
531  }
532 
533  // register all coarse nullspace factories in TogglePFactory
534  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseCoordsFactoryNames.begin(); it != coarseCoordsFactoryNames.end(); ++it) {
535  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
536  factory->AddCoordTransferFactory(p);
537  }
538 
539  return factory;
540 }
541 
542 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
544  if (paramList.begin() == paramList.end())
545  return rcp(new SmootherFactory(rcp(new TrilinosSmoother())));
546 
547  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "TrilinosSmoother", Exceptions::RuntimeError, "");
548 
549  // Is it true? TEUCHOS_TEST_FOR_EXCEPTION(!paramList.isParameter("type"), Exceptions::RuntimeError, "TrilinosSmoother: parameter 'type' is mandatory");
550  // type="" is default in TrilinosSmoother, but what happen then?
551 
552  std::string type = "";
553  if (paramList.isParameter("type")) type = paramList.get<std::string>("type");
554  int overlap = 0;
555  if (paramList.isParameter("overlap")) overlap = paramList.get<int>("overlap");
556  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
557  Teuchos::ParameterList params;
558  if (paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
559 
560  // parameters from SmootherFactory
561  // bool bKeepSmootherData = false; if(paramList.isParameter("keep smoother data")) bKeepSmootherData = paramList.get<bool>("keep smoother data");
562 
563  // Read in factory information for smoothers (if available...)
564  // NOTE: only a selected number of factories can be used with the Trilinos smoother
565  // smoothers usually work with the global data available (which is A and the transfers P and R)
566 
567  Teuchos::RCP<TrilinosSmoother> trilSmoo = Teuchos::rcp(new TrilinosSmoother(type, params, overlap));
568 
569  if (paramList.isParameter("LineDetection_Layers")) {
570  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
571  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
572  }
573  if (paramList.isParameter("LineDetection_VertLineIds")) {
574  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
575  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
576  }
577  if (paramList.isParameter("CoarseNumZLayers")) {
578  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("CoarseNumZLayers"), factoryMapIn, factoryManagersIn);
579  trilSmoo->SetFactory("CoarseNumZLayers", generatingFact);
580  }
581 
582  RCP<SmootherFactory> smooFact = rcp(new SmootherFactory(Teuchos::null));
583  Teuchos::ParameterList smooFactParams;
584  // smooFactParams.setEntry("keep smoother data", paramList.getEntry("keep smoother data"));
585  smooFact->SetParameterList(smooFactParams);
586  smooFact->SetSmootherPrototypes(trilSmoo);
587  return smooFact;
588 }
589 
590 #ifdef HAVE_MUELU_MATLAB
591 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
594  if (paramList.begin() == paramList.end())
595  return rcp(new SmootherFactory(rcp(new MatlabSmoother())));
596 
597  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "MatlabSmoother", Exceptions::RuntimeError, "");
598 
599  // Read in factory information for smoothers (if available...)
600  // NOTE: only a selected number of factories can be used with the Trilinos smoother
601  // smoothers usually work with the global data available (which is A and the transfers P and R)
602 
603  Teuchos::RCP<MatlabSmoother> matSmoo = Teuchos::rcp(new MatlabSmoother(paramList));
604 
605  return rcp(new SmootherFactory(matSmoo));
606 }
607 #endif
608 
609 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
611  if (paramList.begin() == paramList.end())
612  return rcp(new SmootherFactory(rcp(new DirectSolver()), Teuchos::null));
613 
614  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "DirectSolver", Exceptions::RuntimeError, "");
615 
616  std::string type;
617  if (paramList.isParameter("type")) type = paramList.get<std::string>("type");
618  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
619  Teuchos::ParameterList params;
620  if (paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
621 
622  return rcp(new SmootherFactory(rcp(new DirectSolver(type, params)), Teuchos::null));
623 }
624 
625 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
626 template <class T> // T must implement the Factory interface
628  // read in sub lists
629  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
630 
631  // internal vector of factory managers
632  std::vector<RCP<FactoryManager> > facManagers;
633 
634  // loop over all "block%i" sublists in parameter list
635  int blockid = 1;
636  bool blockExists = true;
637  while (blockExists == true) {
638  std::stringstream ss;
639  ss << "block" << blockid;
640 
641  if (paramList.isSublist(ss.str()) == true) {
642  // we either have a parameter group or we have a list of factories in here
643  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
644 
645  RCP<FactoryManager> M = Teuchos::null;
646 
647  if (b->isParameter("group")) {
648  // use a factory manager
649  std::string facManagerName = b->get<std::string>("group");
650  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.");
651  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
652  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
653  TEUCHOS_TEST_FOR_EXCEPTION(M == Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
654  } else {
655  // read in the list of factories
656  M = rcp(new FactoryManager());
657  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
658  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
659  M->SetFactory(b->name(param), p);
660  }
661  }
662 
663  // add factory manager to internal vector of factory managers
664  M->SetIgnoreUserData(true);
665  facManagers.push_back(M);
666  paramListNonConst->remove(ss.str());
667  blockid++;
668  } else {
669  blockExists = false;
670  break;
671  }
672  }
673 
674  // create a new blocked smoother
675  RCP<T> bs = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
676 
677  // important: set block factory for A here!
678  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
679  // The user might want to overwrite this in the xml file, so just
680  // use what is declared as "A"
681  // bs->SetFactory("A", MueLu::NoFactory::getRCP());
682 
683  for (int i = 0; i < Teuchos::as<int>(facManagers.size()); i++) {
684  bs->AddFactoryManager(facManagers[i], i);
685  }
686 
687  return rcp(new SmootherFactory(bs));
688 }
689 
690 #ifdef HAVE_MUELU_TEKO
691 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
693  // read in sub lists
694  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
695  RCP<ParameterList> tekoParams = rcp(new ParameterList(paramListNonConst->sublist("Inverse Factory Library")));
696  paramListNonConst->remove("Inverse Factory Library");
697 
698  // create a new blocked smoother
699  RCP<TekoSmoother> bs = Build2<TekoSmoother>(*paramListNonConst, factoryMapIn, factoryManagersIn);
700 
701  // important: set block factory for A here!
702  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
703  // The user might want to overwrite this in the xml file, so just
704  // use what is declared as "A"
705  // bs->SetFactory("A", MueLu::NoFactory::getRCP());
706 
707  // Set Teko parameters ("Inverse Factory Library")
708  bs->SetTekoParameters(tekoParams);
709 
710  return rcp(new SmootherFactory(bs));
711 }
712 #endif
713 
714 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
716  if (paramList.numParams() == 0)
717  return rcp(new SmootherFactory(rcp(new BlockedDirectSolver())));
718 
719  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "BlockedDirectSolver", Exceptions::RuntimeError, "FactoryFactory::BuildBlockedDirectSolver: Generating factory needs to be a BlockedDirectSolver.");
720 
721  std::string type;
722  if (paramList.isParameter("type")) type = paramList.get<std::string>("type");
723  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
724  Teuchos::ParameterList params;
725  if (paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
726 
727  return rcp(new SmootherFactory(rcp(new BlockedDirectSolver(type, params))));
728 }
729 
730 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
731 template <class T> // T must implement the Factory interface
733  RCP<T> pfac = Teuchos::null;
734 
735  // read in sub lists
736  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
737 
738  // internal vector of factory managers
739  std::vector<RCP<FactoryManager> > facManagers;
740 
741  // loop over all "block%i" sublists in parameter list
742  int blockid = 1;
743  bool blockExists = true;
744  while (blockExists == true) {
745  std::stringstream ss;
746  ss << "block" << blockid;
747 
748  if (paramList.isSublist(ss.str()) == true) {
749  // we either have a parameter group or we have a list of factories in here
750  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
751 
752  RCP<FactoryManager> M = Teuchos::null;
753 
754  if (b->isParameter("group")) {
755  // use a factory manager
756  std::string facManagerName = b->get<std::string>("group");
757  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.");
758  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
759  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
760  TEUCHOS_TEST_FOR_EXCEPTION(M == Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
761  } else {
762  // read in the list of factories
763  M = rcp(new FactoryManager());
764  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
765  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
766  M->SetFactory(b->name(param), p);
767  }
768  }
769 
770  // add factory manager to internal vector of factory managers
771  M->SetIgnoreUserData(true);
772  facManagers.push_back(M);
773  paramListNonConst->remove(ss.str());
774  blockid++;
775  } else {
776  blockExists = false;
777  break;
778  }
779  }
780 
781  // build BlockedPFactory (without sub block information)
782  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
783 
784  // add FactoryManager objects
785  for (size_t i = 0; i < facManagers.size(); i++) {
786  pfac->AddFactoryManager(facManagers[i]); // add factory manager
787  }
788 
789  return pfac;
790 }
791 
792 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
793 template <class T> // T must implement the Factory interface
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<const FactoryBase> > facBase;
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  // read in the list of factories
815  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
816  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
817  facBase.push_back(p);
818  }
819 
820  // add factory manager to internal vector of factory managers
821  paramListNonConst->remove(ss.str());
822  blockid++;
823  } else {
824  blockExists = false;
825  break;
826  }
827  }
828 
829  // build BlockedPFactory (without sub block information)
830  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
831 
832  // add FactoryManager objects
833  for (size_t i = 0; i < facBase.size(); i++) {
834  pfac->AddFactory(facBase[i]); // add factory manager
835  }
836 
837  return pfac;
838 }
839 } // namespace MueLu
840 
841 #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
virtual RCP< const FactoryBase > BuildFactory(const Teuchos::ParameterEntry &param, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
: Interpret Factory parameter list and build new factory
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< FactoryBase > BuildMatlabSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
MatlabSmoother.
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.