MueLu  Version of the Day
MueLu_FactoryFactory_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_FACTORYFACTORY_DECL_HPP
47 #define MUELU_FACTORYFACTORY_DECL_HPP
48 
49 #include <string>
50 #include <vector>
51 
52 #include <Teuchos_ParameterEntry.hpp>
53 #include <Teuchos_Array.hpp>
54 
55 #include "MueLu_ConfigDefs.hpp"
57 
59 
60 #include "MueLu_FactoryBase.hpp"
61 #include "MueLu_FactoryManager.hpp"
65 #include "MueLu_Hierarchy_fwd.hpp"
66 
67 #include "MueLu_Monitor.hpp"
68 #include "MueLu_Exceptions.hpp"
69 
70 #include "MueLu_AggregateQualityEstimateFactory.hpp"
71 #include "MueLu_AggregationExportFactory.hpp"
72 #include "MueLu_AmalgamationFactory.hpp"
73 #include "MueLu_BlackBoxPFactory.hpp"
74 #include "MueLu_BlockedCoarseMapFactory.hpp"
75 #include "MueLu_BlockedCoordinatesTransferFactory.hpp"
76 #include "MueLu_BlockedDirectSolver.hpp"
77 #include "MueLu_BlockedGaussSeidelSmoother.hpp"
78 #include "MueLu_BlockedJacobiSmoother.hpp"
79 #include "MueLu_BlockedPFactory.hpp"
80 #include "MueLu_BlockedRAPFactory.hpp"
81 #include "MueLu_BraessSarazinSmoother.hpp"
82 #include "MueLu_BrickAggregationFactory.hpp"
83 #include "MueLu_ClassicalMapFactory.hpp"
84 #include "MueLu_ClassicalPFactory.hpp"
85 #include "MueLu_CloneRepartitionInterface.hpp"
86 #include "MueLu_CoalesceDropFactory.hpp"
87 #include "MueLu_SmooVecCoalesceDropFactory.hpp"
88 #include "MueLu_CoarseMapFactory.hpp"
89 #include "MueLu_CoarseningVisualizationFactory.hpp"
90 #include "MueLu_ConstraintFactory.hpp"
91 #include "MueLu_CoupledAggregationFactory.hpp"
92 #include "MueLu_CoordinatesTransferFactory.hpp"
93 #include "MueLu_DirectSolver.hpp"
94 #include "MueLu_DropNegativeEntriesFactory.hpp"
95 #include "MueLu_EminPFactory.hpp"
96 #include "MueLu_FilteredAFactory.hpp"
97 #include "MueLu_FineLevelInputDataFactory.hpp"
98 #include "MueLu_GeneralGeometricPFactory.hpp"
99 #include "MueLu_ReplicatePFactory.hpp"
100 #include "MueLu_GenericRFactory.hpp"
101 #include "MueLu_GeometricInterpolationPFactory.hpp"
102 #include "MueLu_InterfaceAggregationFactory.hpp"
103 #include "MueLu_InterfaceMappingTransferFactory.hpp"
104 #include "MueLu_InitialBlockNumberFactory.hpp"
105 #include "MueLu_IndefBlockedDiagonalSmoother.hpp"
106 #include "MueLu_InverseApproximationFactory.hpp"
107 #include "MueLu_IsorropiaInterface.hpp"
108 #include "MueLu_LineDetectionFactory.hpp"
109 #include "MueLu_LocalOrdinalTransferFactory.hpp"
110 #include "MueLu_RepartitionInterface.hpp"
111 #include "MueLu_RepartitionBlockDiagonalFactory.hpp"
112 #include "MueLu_MapTransferFactory.hpp"
113 #include "MueLu_MatrixAnalysisFactory.hpp"
114 #include "MueLu_MultiVectorTransferFactory.hpp"
115 #include "MueLu_NotayAggregationFactory.hpp"
116 #include "MueLu_NullspaceFactory.hpp"
117 #include "MueLu_NullspacePresmoothFactory.hpp"
118 #include "MueLu_PatternFactory.hpp"
119 #include "MueLu_PgPFactory.hpp"
120 #include "MueLu_RebalanceBlockInterpolationFactory.hpp"
121 #include "MueLu_RebalanceBlockRestrictionFactory.hpp"
122 #include "MueLu_RebalanceBlockAcFactory.hpp"
123 #include "MueLu_RebalanceTransferFactory.hpp"
124 #include "MueLu_RegionRFactory.hpp"
125 #include "MueLu_RepartitionFactory.hpp"
126 #include "MueLu_RepartitionHeuristicFactory.hpp"
127 #include "MueLu_RAPFactory.hpp"
128 #include "MueLu_RAPShiftFactory.hpp"
129 #include "MueLu_RebalanceAcFactory.hpp"
130 #include "MueLu_ReorderBlockAFactory.hpp"
131 #include "MueLu_SaPFactory.hpp"
132 #include "MueLu_ScaledNullspaceFactory.hpp"
133 #include "MueLu_SegregatedAFactory.hpp"
134 #include "MueLu_SemiCoarsenPFactory.hpp"
135 #include "MueLu_SchurComplementFactory.hpp"
136 #include "MueLu_SimpleSmoother.hpp"
137 #include "MueLu_SmootherFactory.hpp"
138 #include "MueLu_StructuredAggregationFactory.hpp"
139 #include "MueLu_StructuredLineDetectionFactory.hpp"
140 #include "MueLu_SubBlockAFactory.hpp"
141 #ifdef HAVE_MUELU_TEKO
142 #include "MueLu_TekoSmoother.hpp"
143 #endif
144 #include "MueLu_TentativePFactory.hpp"
145 #include "MueLu_ToggleCoordinatesTransferFactory.hpp"
146 #include "MueLu_TogglePFactory.hpp"
147 #include "MueLu_TrilinosSmoother.hpp"
148 #include "MueLu_TransPFactory.hpp"
149 #include "MueLu_RfromP_Or_TransP.hpp"
150 #include "MueLu_UncoupledAggregationFactory.hpp"
151 #include "MueLu_HybridAggregationFactory.hpp"
152 #include "MueLu_UnsmooshFactory.hpp"
153 #include "MueLu_UserAggregationFactory.hpp"
154 #include "MueLu_UserPFactory.hpp"
155 #include "MueLu_UzawaSmoother.hpp"
156 #include "MueLu_VariableDofLaplacianFactory.hpp"
157 #include "MueLu_ZeroSubBlockAFactory.hpp"
158 #include "MueLu_ZoltanInterface.hpp"
159 #include "MueLu_Zoltan2Interface.hpp"
160 #include "MueLu_NodePartitionInterface.hpp"
161 
162 
163 #include "MueLu_AmalgamationFactory_kokkos.hpp"
164 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
165 #include "MueLu_CoarseMapFactory_kokkos.hpp"
166 #include "MueLu_CoordinatesTransferFactory_kokkos.hpp"
167 #include "MueLu_GeometricInterpolationPFactory_kokkos.hpp"
168 #include "MueLu_NullspaceFactory_kokkos.hpp"
169 #include "MueLu_SaPFactory_kokkos.hpp"
170 #include "MueLu_SemiCoarsenPFactory_kokkos.hpp"
171 #include "MueLu_StructuredAggregationFactory_kokkos.hpp"
172 #include "MueLu_TentativePFactory_kokkos.hpp"
173 #include "MueLu_MatrixFreeTentativePFactory_kokkos.hpp"
174 #include "MueLu_UncoupledAggregationFactory_kokkos.hpp"
175 #include "MueLu_RegionRFactory_kokkos.hpp"
176 
177 #ifdef HAVE_MUELU_MATLAB
178 // This is distasteful, but (sadly) neccesary due to peculiarities in MueLu's build system.
179 #include "../matlab/src/MueLu_SingleLevelMatlabFactory_decl.hpp"
180 #include "../matlab/src/MueLu_SingleLevelMatlabFactory_def.hpp"
181 #include "../matlab/src/MueLu_TwoLevelMatlabFactory_decl.hpp"
182 #include "../matlab/src/MueLu_TwoLevelMatlabFactory_def.hpp"
183 #include "../matlab/src/MueLu_MatlabSmoother_decl.hpp"
184 #include "../matlab/src/MueLu_MatlabSmoother_def.hpp"
185 #endif
186 
187 #ifdef HAVE_MUELU_INTREPID2
188 #include "MueLu_IntrepidPCoarsenFactory.hpp"
189 #endif
190 
191 namespace MueLu {
192 
199  template <class Scalar = DefaultScalar,
202  class Node = DefaultNode>
203  class FactoryFactory : public BaseClass {
204 #undef MUELU_FACTORYFACTORY_SHORT
205 #include "MueLu_UseShortNames.hpp"
206 
207  typedef std::map<std::string, RCP<const FactoryBase> > FactoryMap; // TODO: remove
208  typedef std::map<std::string, RCP<FactoryManagerBase> > FactoryManagerMap;
209 
210  public:
211 
229  virtual RCP<const FactoryBase> BuildFactory(const Teuchos::ParameterEntry& param, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
230  // Find factory
231  std::string factoryName;
232  Teuchos::ParameterList paramList;
233  if (!param.isList()) {
234  factoryName = Teuchos::getValue<std::string>(param);
235  } else {
236  paramList = Teuchos::getValue<Teuchos::ParameterList>(param);
237  factoryName = paramList.get<std::string>("factory");
238  }
239 
240  // TODO: see how Teko handles this (=> register factories).
241  if (factoryName == "AggregateQualityEstimateFactory") return Build2<AggregateQualityEstimateFactory> (paramList, factoryMapIn, factoryManagersIn);
242  if (factoryName == "AggregationExportFactory") return Build2<AggregationExportFactory> (paramList, factoryMapIn, factoryManagersIn);
243  if (factoryName == "AmalgamationFactory") return Build2<AmalgamationFactory> (paramList, factoryMapIn, factoryManagersIn);
244  if (factoryName == "BlockedCoarseMapFactory") return Build2<BlockedCoarseMapFactory> (paramList, factoryMapIn, factoryManagersIn);
245  if (factoryName == "BlockedRAPFactory") return BuildRAPFactory<BlockedRAPFactory> (paramList, factoryMapIn, factoryManagersIn);
246  if (factoryName == "BrickAggregationFactory") return Build2<BrickAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
247  if (factoryName == "ClassicalMapFactory") return Build2<ClassicalMapFactory> (paramList, factoryMapIn, factoryManagersIn);
248  if (factoryName == "ClassicalPFactory") return Build2<ClassicalPFactory> (paramList, factoryMapIn, factoryManagersIn);
249  if (factoryName == "CloneRepartitionInterface") return Build2<CloneRepartitionInterface> (paramList, factoryMapIn, factoryManagersIn);
250  if (factoryName == "CoarseMapFactory") return Build2<CoarseMapFactory> (paramList, factoryMapIn, factoryManagersIn);
251  if (factoryName == "CoarseningVisualizationFactory") return Build2<CoarseningVisualizationFactory> (paramList, factoryMapIn, factoryManagersIn);
252  if (factoryName == "CoalesceDropFactory") return Build2<CoalesceDropFactory> (paramList, factoryMapIn, factoryManagersIn);
253  if (factoryName == "SmooVecCoalesceDropFactory") return Build2<SmooVecCoalesceDropFactory> (paramList, factoryMapIn, factoryManagersIn);
254  if (factoryName == "ConstraintFactory") return Build2<ConstraintFactory> (paramList, factoryMapIn, factoryManagersIn);
255  if (factoryName == "CoupledAggregationFactory") return BuildCoupledAggregationFactory (paramList, factoryMapIn, factoryManagersIn);
256  if (factoryName == "CoordinatesTransferFactory") return Build2<CoordinatesTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
257  if (factoryName == "DirectSolver") return BuildDirectSolver (paramList, factoryMapIn, factoryManagersIn);
258  if (factoryName == "DropNegativeEntriesFactory") return Build2<DropNegativeEntriesFactory> (paramList, factoryMapIn, factoryManagersIn);
259  if (factoryName == "EminPFactory") return Build2<EminPFactory> (paramList, factoryMapIn, factoryManagersIn);
260  if (factoryName == "FilteredAFactory") return Build2<FilteredAFactory> (paramList, factoryMapIn, factoryManagersIn);
261  if (factoryName == "FineLevelInputDataFactory") return Build2<FineLevelInputDataFactory> (paramList, factoryMapIn, factoryManagersIn);
262  if (factoryName == "GeneralGeometricPFactory") return Build2<GeneralGeometricPFactory> (paramList, factoryMapIn, factoryManagersIn);
263  if (factoryName == "ReplicatePFactory") return Build2<ReplicatePFactory> (paramList, factoryMapIn, factoryManagersIn);
264  if (factoryName == "GenericRFactory") return Build2<GenericRFactory> (paramList, factoryMapIn, factoryManagersIn);
265  if (factoryName == "GeometricInterpolationPFactory") return Build2<GeometricInterpolationPFactory> (paramList, factoryMapIn, factoryManagersIn);
266  if (factoryName == "HybridAggregationFactory") return Build2<HybridAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
267  if (factoryName == "InterfaceAggregationFactory") return Build2<InterfaceAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
268  if (factoryName == "InterfaceMappingTransferFactory") return Build2<InterfaceMappingTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
269  if (factoryName == "InverseApproximationFactory") return Build2<InverseApproximationFactory> (paramList, factoryMapIn, factoryManagersIn);
270  if (factoryName == "InitialBlockNumberFactory") return Build2<InitialBlockNumberFactory> (paramList, factoryMapIn, factoryManagersIn);
271  if (factoryName == "LineDetectionFactory") return Build2<LineDetectionFactory> (paramList, factoryMapIn, factoryManagersIn);
272  // LocalOrdinalTransferFactory is a utility factory that can be used for multiple things, so there is no default
273  // if (factoryName == "LocalOrdinalTransferFactory") return Build2<LocalOrdinalTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
274  if (factoryName == "MapTransferFactory") return Build2<MapTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
275  if (factoryName == "MatrixAnalysisFactory") return Build2<MatrixAnalysisFactory> (paramList, factoryMapIn, factoryManagersIn);
276  if (factoryName == "MultiVectorTransferFactory") return Build2<MultiVectorTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
277  if (factoryName == "NoFactory") return MueLu::NoFactory::getRCP();
278  if (factoryName == "NoSmoother") return rcp(new SmootherFactory(Teuchos::null));
279  if (factoryName == "NotayAggregationFactory") return Build2<NotayAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
280  if (factoryName == "NullspaceFactory") return Build2<NullspaceFactory> (paramList, factoryMapIn, factoryManagersIn);
281  if (factoryName == "NullspacePresmoothFactory") return Build2<NullspacePresmoothFactory> (paramList, factoryMapIn, factoryManagersIn);
282  if (factoryName == "PatternFactory") return Build2<PatternFactory> (paramList, factoryMapIn, factoryManagersIn);
283  if (factoryName == "PgPFactory") return Build2<PgPFactory> (paramList, factoryMapIn, factoryManagersIn);
284  if (factoryName == "SaPFactory") return Build2<SaPFactory> (paramList, factoryMapIn, factoryManagersIn);
285  if (factoryName == "RAPFactory") return BuildRAPFactory<RAPFactory> (paramList, factoryMapIn, factoryManagersIn);
286  if (factoryName == "RAPShiftFactory") return BuildRAPFactory<RAPShiftFactory> (paramList, factoryMapIn, factoryManagersIn);
287  if (factoryName == "RebalanceAcFactory") return Build2<RebalanceAcFactory> (paramList, factoryMapIn, factoryManagersIn);
288  if (factoryName == "RebalanceTransferFactory") return Build2<RebalanceTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
289  if (factoryName == "RegionRFactory") return Build2<RegionRFactory> (paramList, factoryMapIn, factoryManagersIn);
290  if (factoryName == "RegionRFactory_kokkos") return Build2<RegionRFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
291  if (factoryName == "ReorderBlockAFactory") return Build2<ReorderBlockAFactory> (paramList, factoryMapIn, factoryManagersIn);
292  if (factoryName == "RepartitionInterface") return Build2<RepartitionInterface> (paramList, factoryMapIn, factoryManagersIn);
293  if (factoryName == "ScaledNullspaceFactory") return Build2<ScaledNullspaceFactory> (paramList, factoryMapIn, factoryManagersIn);
294  if (factoryName == "SegregatedAFactory") return Build2<SegregatedAFactory> (paramList, factoryMapIn, factoryManagersIn);
295  if (factoryName == "SemiCoarsenPFactory") return Build2<SemiCoarsenPFactory> (paramList, factoryMapIn, factoryManagersIn);
296  if (factoryName == "StructuredAggregationFactory") return Build2<StructuredAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
297  if (factoryName == "StructuredLineDetectionFactory") return Build2<StructuredLineDetectionFactory> (paramList, factoryMapIn, factoryManagersIn);
298  if (factoryName == "SubBlockAFactory") return Build2<SubBlockAFactory> (paramList, factoryMapIn, factoryManagersIn);
299  if (factoryName == "TentativePFactory") return Build2<TentativePFactory> (paramList, factoryMapIn, factoryManagersIn);
300  if (factoryName == "ToggleCoordinatesTransferFactory") return BuildToggleCoordinatesTransferFactory (paramList, factoryMapIn, factoryManagersIn);
301  if (factoryName == "TogglePFactory") return BuildTogglePFactory<TogglePFactory> (paramList, factoryMapIn, factoryManagersIn);
302  if (factoryName == "TransPFactory") return Build2<TransPFactory> (paramList, factoryMapIn, factoryManagersIn);
303  if (factoryName == "RfromP_Or_TransP") return Build2<RfromP_Or_TransP> (paramList, factoryMapIn, factoryManagersIn);
304  if (factoryName == "TrilinosSmoother") return BuildTrilinosSmoother (paramList, factoryMapIn, factoryManagersIn);
305  if (factoryName == "UncoupledAggregationFactory") return Build2<UncoupledAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
306  if (factoryName == "UnsmooshFactory") return Build2<UnsmooshFactory> (paramList, factoryMapIn, factoryManagersIn);
307  if (factoryName == "UserAggregationFactory") return Build2<UserAggregationFactory> (paramList, factoryMapIn, factoryManagersIn);
308  if (factoryName == "UserPFactory") return Build2<UserPFactory> (paramList, factoryMapIn, factoryManagersIn);
309  if (factoryName == "VariableDofLaplacianFactory") return Build2<VariableDofLaplacianFactory> (paramList, factoryMapIn, factoryManagersIn);
310  if (factoryName == "ZeroSubBlockAFactory") return Build2<ZeroSubBlockAFactory> (paramList, factoryMapIn, factoryManagersIn);
311  if (factoryName == "AmalgamationFactory_kokkos") return Build2<AmalgamationFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
312  if (factoryName == "CoalesceDropFactory_kokkos") return Build2<CoalesceDropFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
313  if (factoryName == "CoarseMapFactory_kokkos") return Build2<CoarseMapFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
314  if (factoryName == "CoordinatesTransferFactory_kokkos") return Build2<CoordinatesTransferFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
315  if (factoryName == "GeometricInterpolationPFactory_kokkos") return Build2<GeometricInterpolationPFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
316  if (factoryName == "NullspaceFactory_kokkos") return Build2<NullspaceFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
317  if (factoryName == "SaPFactory_kokkos") return Build2<SaPFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
318  if (factoryName == "SemiCoarsenPFactory_kokkos") return Build2<SemiCoarsenPFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
319  if (factoryName == "StructuredAggregationFactory_kokkos") return Build2<StructuredAggregationFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
320  if (factoryName == "TentativePFactory_kokkos") return Build2<TentativePFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
321  if (factoryName == "MatrixFreeTentativePFactory_kokkos") return Build2<MatrixFreeTentativePFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
322  if (factoryName == "UncoupledAggregationFactory_kokkos") return Build2<UncoupledAggregationFactory_kokkos> (paramList, factoryMapIn, factoryManagersIn);
323 
324  if (factoryName == "ZoltanInterface") {
325 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
326  return Build2<ZoltanInterface>(paramList, factoryMapIn, factoryManagersIn);
327 #else
328  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a ZoltanInterface object: Zoltan is disabled: HAVE_MUELU_ZOLTAN && HAVE_MPI == false.");
329 #endif // HAVE_MUELU_ZOLTAN && HAVE_MPI
330  }
331  if (factoryName == "Zoltan2Interface") {
332 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
333  return Build2<Zoltan2Interface>(paramList, factoryMapIn, factoryManagersIn);
334 #else
335  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a Zoltan2Interface object: Zoltan2 is disabled: HAVE_MUELU_ZOLTAN2 && HAVE_MPI == false.");
336 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
337  }
338  if (factoryName == "IsorropiaInterface") {
339 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
340  return Build2<IsorropiaInterface>(paramList, factoryMapIn, factoryManagersIn);
341 #else
342  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a IsorropiaInterface object: Isorropia is disabled: HAVE_MUELU_ISORROPIA && HAVE_MPI == false.");
343 #endif // HAVE_MUELU_ZOLTAN2 && HAVE_MPI
344  }
345 
346  if (factoryName == "NodePartitionInterface") {
347 #if defined(HAVE_MPI)
348  return Build2<NodePartitionInterface>(paramList, factoryMapIn, factoryManagersIn);
349 #else
350  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a NodePartitionInterface object: HAVE_MPI == false.");
351 #endif // HAVE_MPI
352  }
353 
354  if (factoryName == "RepartitionFactory") {
355 #ifdef HAVE_MPI
356  return Build2<RepartitionFactory>(paramList, factoryMapIn, factoryManagersIn);
357 #else
358  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionFactory object: HAVE_MPI == false.");
359 #endif // HAVE_MPI
360  }
361  if (factoryName == "RepartitionHeuristicFactory") {
362 #ifdef HAVE_MPI
363  return Build2<RepartitionHeuristicFactory>(paramList, factoryMapIn, factoryManagersIn);
364 #else
365  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory:BuildFactory(): Cannot create a RepartitionHeuristicFactory object: HAVE_MPI == false.");
366 #endif // HAVE_MPI
367  }
368  // Blocked factories
369  if (factoryName == "BlockedCoordinatesTransferFactory") return BuildBlockedCoordFactory<BlockedCoordinatesTransferFactory> (paramList, factoryMapIn, factoryManagersIn);
370  if (factoryName == "BlockedDirectSolver") return BuildBlockedDirectSolver(paramList, factoryMapIn, factoryManagersIn);
371  if (factoryName == "BlockedGaussSeidelSmoother") return BuildBlockedSmoother<BlockedGaussSeidelSmoother>(paramList, factoryMapIn, factoryManagersIn);
372  if (factoryName == "BlockedJacobiSmoother") return BuildBlockedSmoother<BlockedJacobiSmoother>(paramList, factoryMapIn, factoryManagersIn);
373  if (factoryName == "BlockedPFactory") return BuildBlockedFactory<BlockedPFactory>(paramList, factoryMapIn, factoryManagersIn);
374  if (factoryName == "BraessSarazinSmoother") return BuildBlockedSmoother<BraessSarazinSmoother>(paramList, factoryMapIn, factoryManagersIn);
375  if (factoryName == "IndefiniteBlockDiagonalSmoother") return BuildBlockedSmoother<IndefBlockedDiagonalSmoother>(paramList, factoryMapIn, factoryManagersIn);
376  if (factoryName == "SimpleSmoother") return BuildBlockedSmoother<SimpleSmoother>(paramList, factoryMapIn, factoryManagersIn);
377  if (factoryName == "SchurComplementFactory") return Build2<SchurComplementFactory> (paramList, factoryMapIn, factoryManagersIn);
378  if (factoryName == "RebalanceBlockRestrictionFactory")return BuildBlockedFactory<RebalanceBlockRestrictionFactory>(paramList, factoryMapIn, factoryManagersIn);
379  if (factoryName == "RebalanceBlockAcFactory") return BuildBlockedFactory<RebalanceBlockAcFactory>(paramList, factoryMapIn, factoryManagersIn);
380  if (factoryName == "RebalanceBlockInterpolationFactory") return BuildBlockedFactory<RebalanceBlockInterpolationFactory>(paramList, factoryMapIn, factoryManagersIn);
381 #ifdef HAVE_MPI
382  if (factoryName == "RepartitionBlockDiagonalFactory") return Build2<RepartitionBlockDiagonalFactory> (paramList, factoryMapIn, factoryManagersIn);
383 #endif
384 #ifdef HAVE_MUELU_TEKO
385  if (factoryName == "TekoSmoother") return BuildTekoSmoother(paramList, factoryMapIn, factoryManagersIn);
386 #endif
387  if (factoryName == "UzawaSmoother") return BuildBlockedSmoother<UzawaSmoother>(paramList, factoryMapIn, factoryManagersIn);
388 
389  // Matlab factories
390 #ifdef HAVE_MUELU_MATLAB
391  if (factoryName == "TwoLevelMatlabFactory") return Build2<TwoLevelMatlabFactory> (paramList, factoryMapIn, factoryManagersIn);
392  if (factoryName == "SingleLevelMatlabFactory") return Build2<SingleLevelMatlabFactory> (paramList, factoryMapIn, factoryManagersIn);
393  if (factoryName == "MatlabSmoother") return BuildMatlabSmoother (paramList, factoryMapIn, factoryManagersIn);
394 #endif
395 
396 #ifdef HAVE_MUELU_INTREPID2
397  if (factoryName == "IntrepidPCoarsenFactory") return Build2<IntrepidPCoarsenFactory> (paramList, factoryMapIn, factoryManagersIn);
398 #endif
399 
400  // Use a user defined factories (in <Factories> node)
401  if (factoryMapIn.find(factoryName) != factoryMapIn.end()) {
402  TEUCHOS_TEST_FOR_EXCEPTION((param.isList() && (++paramList.begin() != paramList.end())), Exceptions::RuntimeError,
403  "MueLu::FactoryFactory: Error during the parsing of: " << std::endl << paramList << std::endl
404  << "'" << factoryName << "' is not a factory name but an existing instance of a factory." << std::endl
405  << "Extra parameters cannot be specified after the creation of the object." << std::endl << std::endl
406  << "Correct syntaxes includes:" << std::endl
407  << " <Parameter name=\"...\" type=\"string\" value=\"" << factoryName << "\"/>" << std::endl
408  << "or" << std::endl
409  << " <ParameterList name=\"...\"><Parameter name=\"factory\" type=\"string\" value=\"" << factoryName << "\"/></ParameterList>" << std::endl
410  );
411 
412  return factoryMapIn.find(factoryName)->second;
413  }
414 
415  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::FactoryFactory: unknown factory name : " << factoryName);
416 
417  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
418  }
419 
420  //
421  //
422  //
423 
424  // FOLLOWING FUNCTIONS SHOULD LIVE WITH THE CORRESPONDING CLASS
425 
426  //
427  //
428  //
429 
430 #define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))
431 
432  template <class T> // T must implement the Factory interface
433  RCP<T> Build(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
434  RCP<T> factory = rcp(new T());
435 
436  const char* strarray[] = {"A", "P", "R", "Graph", "UnAmalgamationInfo", "Aggregates", "Nullspace", "TransferFactory", "DofsPerNode"};
437  std::vector<std::string> v(strarray, strarray + arraysize(strarray));
438  for (size_t i = 0; i < v.size(); ++i)
439  if (paramList.isParameter(v[i]))
440  factory->SetFactory(v[i], BuildFactory(paramList.getEntry(v[i]), factoryMapIn, factoryManagersIn));
441 
442  return factory;
443  }
444 
445  template <class T> // T must implement the Factory interface
446  RCP<T> Build2(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
447  RCP<T> factory = rcp(new T());
448 
449  ParameterList paramListWithFactories;
450 
451  // Read the RCP<Factory> parameters of the class T
452  RCP<const ParameterList> validParamList = factory->GetValidParameterList(); // TODO check for Teuchos::null (no parameter list validation)
453  TEUCHOS_TEST_FOR_EXCEPTION(validParamList == Teuchos::null, Exceptions::RuntimeError, "FactoryFactory::Build2: default parameter list is null. Please fix this.");
454  for (ParameterList::ConstIterator param = validParamList->begin(); param != validParamList->end(); ++param) {
455  const std::string& pName = validParamList->name(param);
456 
457  if (!paramList.isParameter(pName)) {
458  // Ignore unknown parameters
459  continue;
460  }
461 
462  if (validParamList->isType< RCP<const FactoryBase> >(pName)) {
463  // Generate or get factory described by param
464  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry(pName), factoryMapIn, factoryManagersIn);
465  paramListWithFactories.set(pName, generatingFact);
466  } else if (validParamList->isType<RCP<const ParameterList> >(pName)) {
467  if (pName == "ParameterList") {
468  // NOTE: we cannot use
469  // subList = sublist(rcpFromRef(paramList), pName)
470  // here as that would result in sublist also being a reference to a temporary object.
471  // The resulting dereferencing in the corresponding factory would then segfault
472  RCP<const ParameterList> subList = Teuchos::sublist(rcp(new ParameterList(paramList)), pName);
473  paramListWithFactories.set(pName, subList);
474  }
475  } else {
476  paramListWithFactories.setEntry(pName, paramList.getEntry(pName));
477  }
478  }
479 
480  // Configure the factory
481  factory->SetParameterList(paramListWithFactories);
482 
483  return factory;
484  }
485 
486  template <class T> // T must implement the Factory interface
487  RCP<T> BuildRAPFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
488  RCP<T> factory;
489  if (paramList.isSublist("TransferFactories") == false) {
490  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
491 
492  } else {
493  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
494  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
495 
496  paramListNonConst->remove("TransferFactories");
497 
498  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
499 
500  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
501  RCP<const FactoryBase> p = BuildFactory(transferFactories->entry(param), factoryMapIn, factoryManagersIn);
502  factory->AddTransferFactory(p);
503  }
504  }
505 
506  return factory;
507  }
508 
509  template <class T> // T must implement the Factory interface
510  RCP<T> BuildTogglePFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
511  RCP<T> factory;
512  if (paramList.isSublist("TransferFactories") == false) {
513  //TODO put in an error message: the TogglePFactory needs a TransferFactories sublist!
514  factory = Build2<T>(paramList, factoryMapIn, factoryManagersIn);
515 
516  } else {
517  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
518  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
519 
520  paramListNonConst->remove("TransferFactories");
521 
522  // build TogglePFactory
523  factory = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
524 
525  // count how many prolongation factories and how many coarse null space factories have been declared.
526  // the numbers must match!
527  int numProlongatorFactories = 0;
528  int numPtentFactories = 0;
529  int numCoarseNspFactories = 0;
530  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
531  size_t foundNsp = transferFactories->name(param).find("Nullspace");
532  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length()==10) {
533  numCoarseNspFactories++;
534  continue;
535  }
536  size_t foundPtent = transferFactories->name(param).find("Ptent");
537  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length()==6) {
538  numPtentFactories++;
539  continue;
540  }
541  size_t foundP = transferFactories->name(param).find("P");
542  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length()==2) {
543  numProlongatorFactories++;
544  continue;
545  }
546  }
547  TEUCHOS_TEST_FOR_EXCEPTION(numProlongatorFactories!=numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of prolongator and coarse nullspace factories!");
548  TEUCHOS_TEST_FOR_EXCEPTION(numPtentFactories!=numCoarseNspFactories, Exceptions::RuntimeError, "FactoryFactory::BuildToggleP: The user has to provide the same number of ptent and coarse nullspace factories!");
549  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.");
550 
551  // create empty vectors with data
552  std::vector<Teuchos::ParameterEntry> prolongatorFactoryNames(numProlongatorFactories);
553  std::vector<Teuchos::ParameterEntry> coarseNspFactoryNames(numProlongatorFactories);
554  std::vector<Teuchos::ParameterEntry> ptentFactoryNames(numProlongatorFactories);
555 
556  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
557  size_t foundNsp = transferFactories->name(param).find("Nullspace");
558  if (foundNsp != std::string::npos && foundNsp == 0 && transferFactories->name(param).length()==10) {
559  int number = atoi(&(transferFactories->name(param).at(9)));
560  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!");
561  coarseNspFactoryNames[number-1] = transferFactories->entry(param);
562  continue;
563  }
564  size_t foundPtent = transferFactories->name(param).find("Ptent");
565  if (foundPtent != std::string::npos && foundPtent == 0 && transferFactories->name(param).length()==6) {
566  int number = atoi(&(transferFactories->name(param).at(5)));
567  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!");
568  ptentFactoryNames[number-1] = transferFactories->entry(param);
569  continue;
570  }
571  size_t foundP = transferFactories->name(param).find("P");
572  if (foundP != std::string::npos && foundP == 0 && transferFactories->name(param).length()==2) {
573  int number = atoi(&(transferFactories->name(param).at(1)));
574  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!");
575  prolongatorFactoryNames[number-1] = transferFactories->entry(param);
576  continue;
577  }
578  }
579 
580  // register all prolongation factories in TogglePFactory
581  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = prolongatorFactoryNames.begin(); it != prolongatorFactoryNames.end(); ++it) {
582  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
583  factory->AddProlongatorFactory(p);
584  }
585 
586  // register all tentative prolongation factories in TogglePFactory
587  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = ptentFactoryNames.begin(); it != ptentFactoryNames.end(); ++it) {
588  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
589  factory->AddPtentFactory(p);
590  }
591 
592  // register all coarse nullspace factories in TogglePFactory
593  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseNspFactoryNames.begin(); it != coarseNspFactoryNames.end(); ++it) {
594  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
595  factory->AddCoarseNullspaceFactory(p);
596  }
597  }
598  return factory;
599  }
600 
601  RCP<ToggleCoordinatesTransferFactory> BuildToggleCoordinatesTransferFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
602  RCP<ToggleCoordinatesTransferFactory> factory;
603  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!");
604 
605  RCP<Teuchos::ParameterList> paramListNonConst = rcp(new Teuchos::ParameterList(paramList));
606  RCP<const Teuchos::ParameterList> transferFactories = rcp(new Teuchos::ParameterList(*sublist(paramListNonConst, "TransferFactories")));
607  paramListNonConst->remove("TransferFactories");
608 
609  // build CoordinatesTransferFactory
610  factory = Build2<ToggleCoordinatesTransferFactory>(*paramListNonConst, factoryMapIn, factoryManagersIn);
611 
612  // count how many coordinate transfer factories have been declared.
613  // the numbers must match!
614  int numCoordTransferFactories = 0;
615  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
616  size_t foundCoordinates = transferFactories->name(param).find("Coordinates");
617  if (foundCoordinates != std::string::npos && foundCoordinates == 0 && transferFactories->name(param).length()==12) {
618  numCoordTransferFactories++;
619  continue;
620  }
621  }
622  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.");
623 
624  // create empty vectors with data
625  std::vector<Teuchos::ParameterEntry> coarseCoordsFactoryNames(numCoordTransferFactories);
626 
627  for (Teuchos::ParameterList::ConstIterator param = transferFactories->begin(); param != transferFactories->end(); ++param) {
628  size_t foundCoords = transferFactories->name(param).find("Coordinates");
629  if (foundCoords != std::string::npos && foundCoords == 0 && transferFactories->name(param).length()==12) {
630  int number = atoi(&(transferFactories->name(param).at(11)));
631  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!");
632  coarseCoordsFactoryNames[number-1] = transferFactories->entry(param);
633  continue;
634  }
635  }
636 
637  // register all coarse nullspace factories in TogglePFactory
638  for (std::vector<Teuchos::ParameterEntry>::const_iterator it = coarseCoordsFactoryNames.begin(); it != coarseCoordsFactoryNames.end(); ++it) {
639  RCP<const FactoryBase> p = BuildFactory(*it, factoryMapIn, factoryManagersIn);
640  factory->AddCoordTransferFactory(p);
641  }
642 
643  return factory;
644  }
645 
647  RCP<FactoryBase> BuildCoupledAggregationFactory(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
648  RCP<CoupledAggregationFactory> factory = Build<CoupledAggregationFactory>(paramList, factoryMapIn, factoryManagersIn);
649 
650  if (paramList.isParameter("aggregation: ordering"))
651  factory->SetOrdering(paramList.get<std::string>("aggregation: ordering"));
652 
653  if (paramList.isParameter("aggregation: max selected neighbors"))
654  factory->SetMaxNeighAlreadySelected(paramList.get<int>("aggregation: max selected neighbors"));
655 
656  if (paramList.isParameter("Phase3AggCreation"))
657  factory->SetPhase3AggCreation(paramList.get<double>("Phase3AggCreation"));
658 
659  if(paramList.isParameter("aggregation: min agg size"))
660  factory->SetMinNodesPerAggregate(paramList.get<int>("aggregation: min agg size"));
661 
662  return factory;
663  }
664 
666  // Parameter List Parsing:
667  // <ParameterList name="smootherFact1">
668  // <Parameter name="factory" type="string" value="TrilinosSmoother"/>
669  // <Parameter name="verbose" type="string" value="Warnings"/>
670  // <Parameter name="type" type="string" value="RELAXATION"/>
671  // <ParameterList name="ParameterList">
672  // ...
673  // </ParameterList>
674  // </ParameterList>
675  RCP<FactoryBase> BuildTrilinosSmoother(const Teuchos::ParameterList & paramList, const FactoryMap & factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
676  if (paramList.begin() == paramList.end())
677  return rcp(new SmootherFactory(rcp(new TrilinosSmoother())));
678 
679  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "TrilinosSmoother", Exceptions::RuntimeError, "");
680 
681  // Is it true? TEUCHOS_TEST_FOR_EXCEPTION(!paramList.isParameter("type"), Exceptions::RuntimeError, "TrilinosSmoother: parameter 'type' is mandatory");
682  // type="" is default in TrilinosSmoother, but what happen then?
683 
684  std::string type=""; if(paramList.isParameter("type")) type = paramList.get<std::string>("type");
685  int overlap=0; if(paramList.isParameter("overlap")) overlap = paramList.get<int> ("overlap");
686  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
687  Teuchos::ParameterList params; if(paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
688 
689  // parameters from SmootherFactory
690  //bool bKeepSmootherData = false; if(paramList.isParameter("keep smoother data")) bKeepSmootherData = paramList.get<bool>("keep smoother data");
691 
692  // Read in factory information for smoothers (if available...)
693  // NOTE: only a selected number of factories can be used with the Trilinos smoother
694  // smoothers usually work with the global data available (which is A and the transfers P and R)
695 
696  Teuchos::RCP<TrilinosSmoother> trilSmoo = Teuchos::rcp(new TrilinosSmoother(type, params, overlap));
697 
698  if (paramList.isParameter("LineDetection_Layers")) {
699  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
700  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
701  }
702  if (paramList.isParameter("LineDetection_VertLineIds")) {
703  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("LineDetection_Layers"), factoryMapIn, factoryManagersIn);
704  trilSmoo->SetFactory("LineDetection_Layers", generatingFact);
705  }
706  if (paramList.isParameter("CoarseNumZLayers")) {
707  RCP<const FactoryBase> generatingFact = BuildFactory(paramList.getEntry("CoarseNumZLayers"), factoryMapIn, factoryManagersIn);
708  trilSmoo->SetFactory("CoarseNumZLayers", generatingFact);
709  }
710 
711  RCP<SmootherFactory> smooFact = rcp(new SmootherFactory(Teuchos::null));
712  Teuchos::ParameterList smooFactParams;
713  //smooFactParams.setEntry("keep smoother data", paramList.getEntry("keep smoother data"));
714  smooFact->SetParameterList(smooFactParams);
715  smooFact->SetSmootherPrototypes(trilSmoo);
716  return smooFact;
717  }
718 
719 #ifdef HAVE_MUELU_MATLAB
720  // Parameter List Parsing:
722  // <ParameterList name="smootherFact1">
723  // <Parameter name="factory" type="string" value="MatlabSmoother"/>
724  // <Parameter name="Setup Function" type="string" value="mySmootherSetup.m"/>
725  // <Parameter name="Solve Function" type="string" value="mySmootherSolve.m"/>
726  // <!--A is implicitly included in this list and nothing else is needed to get diagonal-->
727  // <Parameter name="Needs" type="string" value=""/>
728  // <!--A,x,b are also assumed inputs to the solver: only one additional arg then (diag)-->
729  // <Parameter name="Number of Solver Args" type="int" value="1"/>
730  // </ParameterList>
731  RCP<FactoryBase> BuildMatlabSmoother(const Teuchos::ParameterList & paramList, const FactoryMap & factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
732  if (paramList.begin() == paramList.end())
733  return rcp(new SmootherFactory(rcp(new MatlabSmoother())));
734 
735  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "MatlabSmoother", Exceptions::RuntimeError, "");
736 
737  // Read in factory information for smoothers (if available...)
738  // NOTE: only a selected number of factories can be used with the Trilinos smoother
739  // smoothers usually work with the global data available (which is A and the transfers P and R)
740 
741  Teuchos::RCP<MatlabSmoother> matSmoo = Teuchos::rcp(new MatlabSmoother(paramList));
742 
743  return rcp(new SmootherFactory(matSmoo));
744  }
745 #endif
746 
747  RCP<FactoryBase> BuildDirectSolver(const Teuchos::ParameterList& paramList, const FactoryMap& /* factoryMapIn */, const FactoryManagerMap& /* factoryManagersIn */) const {
748  if (paramList.begin() == paramList.end())
749  return rcp(new SmootherFactory(rcp(new DirectSolver()), Teuchos::null));
750 
751  TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "DirectSolver", Exceptions::RuntimeError, "");
752 
753  std::string type; if(paramList.isParameter("type")) type = paramList.get<std::string>("type");
754  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
755  Teuchos::ParameterList params; if(paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
756 
757  return rcp(new SmootherFactory(rcp(new DirectSolver(type, params)), Teuchos::null));
758  }
759 
760  template <class T> // T must implement the Factory interface
761  RCP<FactoryBase> BuildBlockedSmoother(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
762  // read in sub lists
763  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
764 
765  // internal vector of factory managers
766  std::vector<RCP<FactoryManager> > facManagers;
767 
768  // loop over all "block%i" sublists in parameter list
769  int blockid = 1;
770  bool blockExists = true;
771  while (blockExists == true) {
772  std::stringstream ss;
773  ss << "block" << blockid;
774 
775  if(paramList.isSublist(ss.str()) == true) {
776  // we either have a parameter group or we have a list of factories in here
777  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
778 
779  RCP<FactoryManager> M = Teuchos::null;
780 
781  if (b->isParameter("group")) {
782  // use a factory manager
783  std::string facManagerName = b->get< std::string >("group");
784  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.");
785  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
786  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
787  TEUCHOS_TEST_FOR_EXCEPTION(M==Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
788  } else {
789  // read in the list of factories
790  M = rcp(new FactoryManager());
791  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
792  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
793  M->SetFactory(b->name(param),p);
794  }
795  }
796 
797  // add factory manager to internal vector of factory managers
798  M->SetIgnoreUserData(true);
799  facManagers.push_back(M);
800  paramListNonConst->remove(ss.str());
801  blockid++;
802  } else {
803  blockExists = false;
804  break;
805  }
806 
807  }
808 
809  // create a new blocked smoother
810  RCP<T> bs = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
811 
812  // important: set block factory for A here!
813  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
814  // The user might want to overwrite this in the xml file, so just
815  // use what is declared as "A"
816  //bs->SetFactory("A", MueLu::NoFactory::getRCP());
817 
818  for (int i = 0; i<Teuchos::as<int>(facManagers.size()); i++) {
819  bs->AddFactoryManager(facManagers[i],i);
820  }
821 
822  return rcp(new SmootherFactory(bs));
823  }
824 
825 #ifdef HAVE_MUELU_TEKO
826  RCP<FactoryBase> BuildTekoSmoother(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
827  // read in sub lists
828  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
829  RCP<ParameterList> tekoParams = rcp(new ParameterList(paramListNonConst->sublist("Inverse Factory Library")));
830  paramListNonConst->remove("Inverse Factory Library");
831 
832  // create a new blocked smoother
833  RCP<TekoSmoother> bs = Build2<TekoSmoother>(*paramListNonConst, factoryMapIn, factoryManagersIn);
834 
835  // important: set block factory for A here!
836  // TAW: 7/6/2016: We should not need to set/hardcode the blocked operator here.
837  // The user might want to overwrite this in the xml file, so just
838  // use what is declared as "A"
839  //bs->SetFactory("A", MueLu::NoFactory::getRCP());
840 
841  // Set Teko parameters ("Inverse Factory Library")
842  bs->SetTekoParameters(tekoParams);
843 
844  return rcp(new SmootherFactory(bs));
845  }
846 #endif
847 
848  RCP<FactoryBase> BuildBlockedDirectSolver(const Teuchos::ParameterList& /* paramList */, const FactoryMap& /* factoryMapIn */, const FactoryManagerMap& /* factoryManagersIn */) const {
849  //if (paramList.begin() == paramList.end())
850  return rcp(new SmootherFactory(rcp(new BlockedDirectSolver())));
851 
852  /*TEUCHOS_TEST_FOR_EXCEPTION(paramList.get<std::string>("factory") != "DirectSolver", Exceptions::RuntimeError, "");
853 
854  std::string type; if(paramList.isParameter("type")) type = paramList.get<std::string>("type");
855  // std::string verbose; if(paramList.isParameter("verbose")) verbose = paramList.get<std::string>("verbose");
856  Teuchos::ParameterList params; if(paramList.isParameter("ParameterList")) params = paramList.get<Teuchos::ParameterList>("ParameterList");
857 
858  return rcp(new SmootherFactory(rcp(new DirectSolver(type, params))));*/
859  }
860 
861  //RCP<FactoryBase> BuildBlockedPFactory(const Teuchos::ParameterList& paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
862  // RCP<BlockedPFactory> pfac = rcp(new BlockedPFactory());
863 
864  template <class T> // T must implement the Factory interface
865  RCP<T> BuildBlockedFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
866  RCP<T> pfac = Teuchos::null;
867 
868  // read in sub lists
869  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
870 
871  // internal vector of factory managers
872  std::vector<RCP<FactoryManager> > facManagers;
873 
874  // loop over all "block%i" sublists in parameter list
875  int blockid = 1;
876  bool blockExists = true;
877  while (blockExists == true) {
878  std::stringstream ss;
879  ss << "block" << blockid;
880 
881  if(paramList.isSublist(ss.str()) == true) {
882  // we either have a parameter group or we have a list of factories in here
883  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
884 
885  RCP<FactoryManager> M = Teuchos::null;
886 
887  if (b->isParameter("group")) {
888  // use a factory manager
889  std::string facManagerName = b->get< std::string >("group");
890  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.");
891  RCP<FactoryManagerBase> Mb = factoryManagersIn.find(facManagerName)->second;
892  M = Teuchos::rcp_dynamic_cast<FactoryManager>(Mb);
893  TEUCHOS_TEST_FOR_EXCEPTION(M==Teuchos::null, Exceptions::RuntimeError, "Failed to cast FactoryManagerBase object to FactoryManager.");
894  } else {
895  // read in the list of factories
896  M = rcp(new FactoryManager());
897  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
898  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
899  M->SetFactory(b->name(param),p);
900  }
901  }
902 
903  // add factory manager to internal vector of factory managers
904  M->SetIgnoreUserData(true);
905  facManagers.push_back(M);
906  paramListNonConst->remove(ss.str());
907  blockid++;
908  } else {
909  blockExists = false;
910  break;
911  }
912 
913  }
914 
915  // build BlockedPFactory (without sub block information)
916  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
917 
918  // add FactoryManager objects
919  for(size_t i = 0; i<facManagers.size(); i++) {
920  pfac->AddFactoryManager(facManagers[i]); // add factory manager
921  }
922 
923  return pfac;
924  }
925 
926 
927  template <class T> // T must implement the Factory interface
928  RCP<T> BuildBlockedCoordFactory(const Teuchos::ParameterList & paramList, const FactoryMap& factoryMapIn, const FactoryManagerMap& factoryManagersIn) const {
929  RCP<T> pfac = Teuchos::null;
930 
931  // read in sub lists
932  RCP<ParameterList> paramListNonConst = rcp(new ParameterList(paramList));
933 
934  // internal vector of factory managers
935  std::vector<RCP<const FactoryBase> > facBase;
936 
937  // loop over all "block%i" sublists in parameter list
938  int blockid = 1;
939  bool blockExists = true;
940  while (blockExists == true) {
941  std::stringstream ss;
942  ss << "block" << blockid;
943 
944  if(paramList.isSublist(ss.str()) == true) {
945  // we either have a parameter group or we have a list of factories in here
946  RCP<const ParameterList> b = rcp(new ParameterList(*sublist(paramListNonConst, ss.str())));
947 
948  // read in the list of factories
949  for (ParameterList::ConstIterator param = b->begin(); param != b->end(); ++param) {
950  RCP<const FactoryBase> p = BuildFactory(b->entry(param), factoryMapIn, factoryManagersIn);
951  facBase.push_back(p);
952  }
953 
954  // add factory manager to internal vector of factory managers
955  paramListNonConst->remove(ss.str());
956  blockid++;
957  } else {
958  blockExists = false;
959  break;
960  }
961 
962  }
963 
964  // build BlockedPFactory (without sub block information)
965  pfac = Build2<T>(*paramListNonConst, factoryMapIn, factoryManagersIn);
966 
967  // add FactoryManager objects
968  for(size_t i = 0; i<facBase.size(); i++) {
969  pfac->AddFactory(facBase[i]); // add factory manager
970  }
971 
972  return pfac;
973  }
974 
975  }; // class
976 } // namespace MueLu
977 
978 #define MUELU_FACTORYFACTORY_SHORT
979 #endif // MUELU_FACTORYFACTORY_DECL_HPP
980 
981  // TODO: handle factory parameters
982  // TODO: parameter validator
983  // TODO: static
984  // TODO: default parameters should not be duplicated here and on the Factory (ex: default for overlap (=0) is defined both here and on TrilinosSmoother constructors)
RCP< FactoryBase > BuildMatlabSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
MatlabSmoother.
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
This class specifies the default factory that should generate some data on a Level if the data does n...
RCP< FactoryBase > BuildBlockedSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
MueLu::DefaultLocalOrdinal LocalOrdinal
KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
RCP< T > Build(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Factory that can generate other factories from.
Class that encapsulates external library smoothers.
virtual RCP< const FactoryBase > BuildFactory(const Teuchos::ParameterEntry &param, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
: Interpret Factory parameter list and build new factory
RCP< T > BuildBlockedFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< ToggleCoordinatesTransferFactory > BuildToggleCoordinatesTransferFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< T > Build2(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Namespace for MueLu classes and methods.
MueLu::DefaultNode Node
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
#define arraysize(ar)
std::map< std::string, RCP< FactoryManagerBase > > FactoryManagerMap
MueLu::DefaultScalar Scalar
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
std::map< std::string, RCP< const FactoryBase > > FactoryMap
RCP< T > BuildBlockedCoordFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
direct solver for nxn blocked matrices
RCP< T > BuildRAPFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
Base class for MueLu classes.
Class that encapsulates Matlab smoothers.
RCP< FactoryBase > BuildTekoSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< FactoryBase > BuildTrilinosSmoother(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
TrilinosSmoother.
RCP< FactoryBase > BuildCoupledAggregationFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
CoupledAggregationFactory.
Exception throws to report errors in the internal logical of the program.
RCP< FactoryBase > BuildBlockedDirectSolver(const Teuchos::ParameterList &, const FactoryMap &, const FactoryManagerMap &) const
RCP< T > BuildTogglePFactory(const Teuchos::ParameterList &paramList, const FactoryMap &factoryMapIn, const FactoryManagerMap &factoryManagersIn) const
RCP< FactoryBase > BuildDirectSolver(const Teuchos::ParameterList &paramList, const FactoryMap &, const FactoryManagerMap &) const
static const RCP< const NoFactory > getRCP()
Static Get() functions.