38 #include <lifev/core/algorithm/PreconditionerML.hpp> 40 #include <lifev/core/LifeV.hpp> 61 M_preconditioner.reset();
75 M_preconditioner.reset();
78 M_precType = M_list.get (
"prec type",
"undefined??" );
84 M_preconditioner.reset (
new prec_raw_type ( * (M_operator->matrixPtr() ),
this->parametersList(),
true ) );
88 ML_Epetra::MultiLevelPreconditioner* prec;
89 prec =
dynamic_cast<ML_Epetra::MultiLevelPreconditioner*> ( M_preconditioner.get() );
91 Int NumPostCycles = 1;
93 prec->AnalyzeHierarchy (
true, NumPreCycles, NumPostCycles, NumMLCycles );
98 return ( EXIT_SUCCESS );
107 M_preconditioner.reset();
116 const std::string& section,
117 const std::string& subSection,
118 const bool& verbose )
120 list.setName (
"ML paramters list" );
122 std::string defList = dataFile ( (section +
"/" + subSection +
"/default_parameter_list").data(),
"SA" );
123 if ( defList !=
"none" )
125 ML_Epetra::SetDefaults ( defList, list );
130 bool MLPrintParameterList = dataFile ( (section +
"/displayList").data(),
false, found );
132 Int MLOutput = dataFile ( (section +
"/" + subSection +
"/MLOuput").data(), 0, found);
135 list.set (
"ML output", MLOutput );
138 Int printUnused = dataFile ( (section +
"/" + subSection +
"/print_unused").data(), -2, found);
141 list.set (
"print unused", printUnused );
144 Int PDEEquations = dataFile ( (section +
"/" + subSection +
"/pde_equations").data(), 1, found);
147 list.set (
"PDE equations", PDEEquations );
150 Int CycleApplications = dataFile ( (section +
"/" + subSection +
"/cycle_applications").data(), 1, found);
153 list.set (
"cycle applications", CycleApplications );
156 Int MaxLevels = dataFile ( (section +
"/" + subSection +
"/max_levels").data(), 2, found);
159 list.set (
"max levels", MaxLevels );
162 std::string IncOrDec = dataFile ( (section +
"/" + subSection +
"/inc_or_dec").data(),
"increasing", found);
165 list.set (
"increasing or decreasing", IncOrDec );
168 std::string precType = dataFile ( (section +
"/" + subSection +
"/prec_type").data(),
"MGV", found);
171 list.set (
"prec type", precType );
177 std::string eigenAnalysisType = dataFile ( (section +
"/" + subSection +
"/eigne-analysis/type").data(),
"cg", found );
180 list.set (
"eigen-analysis: type", eigenAnalysisType );
183 Int eigenAnalysisIterations = dataFile ( (section +
"/" + subSection +
"/eigne-analysis/iterations").data(), 10, found );
186 list.set (
"eigen-analysis: iterations", eigenAnalysisIterations );
191 std::string AggregationType = dataFile ( (section +
"/" + subSection +
"/aggregation/type").data(),
"Uncoupled", found );
194 list.set (
"aggregation: type", AggregationType );
197 bool AggregationBlockScaling = dataFile ( (section +
"/" + subSection +
"/aggregation/block_scaling").data(),
false, found );
200 list.set (
"aggregation: block scaling", AggregationBlockScaling );
203 Real AggregationThreshold = dataFile ( (section +
"/" + subSection +
"/aggregation/threshold").data(), 0.0 , found );
206 list.set (
"aggregation: threshold", AggregationThreshold );
209 Real AggregationDampingFactor = dataFile ( (section +
"/" + subSection +
"/aggregation/damping_factor").data(), 4. / 3. , found );
212 list.set (
"aggregation: damping factor", AggregationDampingFactor );
215 Int AggregationSmoothingSweeps = dataFile ( (section +
"/" + subSection +
"/aggregation/smoothing_sweeps").data(), 1, found );
218 list.set (
"aggregation: smoothing sweeps", AggregationSmoothingSweeps );
221 Int AggregationGlobalAggregates = dataFile ( (section +
"/" + subSection +
"/aggregation/global_aggregates").data(), 1, found );
224 list.set (
"aggregation: global aggregates", AggregationGlobalAggregates );
227 Int AggregationLocalAggregates = dataFile ( (section +
"/" + subSection +
"/aggregation/local_aggregates").data(), 1, found );
230 list.set (
"aggregation: local aggregates", AggregationLocalAggregates );
233 Int AggregationNodesPerAggregate = dataFile ( (section +
"/" + subSection +
"/aggregation/nodes_per_aggregate").data(), 1, found );
236 list.set (
"aggregation: nodes per aggregate", AggregationNodesPerAggregate );
239 Int AggregationNextLevelAggregatesPerProcess = dataFile ( (section +
"/" + subSection +
"/aggregation/next-level_aggregates_per_process").data(), 128, found );
242 list.set (
"aggregation: next level aggregates per process", AggregationNextLevelAggregatesPerProcess );
245 bool AggregationUseTentativeRestriction = dataFile ( (section +
"/" + subSection +
"/aggregation/tentative_restriction").data(),
false, found );
248 list.set (
"aggregation: use tentative restriction", AggregationUseTentativeRestriction );
251 bool AggregationSymmetrize = dataFile ( (section +
"/" + subSection +
"/aggregation/symmetrize").data(),
false, found );
254 list.set (
"aggregation: symmetrize", AggregationSymmetrize );
257 Int AggregationNumLevelTypes = dataFile ( (section +
"/" + subSection +
"/aggregation/level_type").data(), 0, found );
260 for (
Int i (0); i < AggregationNumLevelTypes; ++i)
262 std::string levelIndex = dataFile ( (section +
"/" + subSection +
"/aggregation/level_type").data(),
"0", 2 * i + 1 );
263 std::string levelParamValue = dataFile ( (section +
"/" + subSection +
"/aggregation/level_type").data(),
"METIS", 2 * i + 2 );
264 list.set ( (
"aggregation: type (level " + levelIndex +
")").data(), levelParamValue );
268 bool EnergyMinimizationEnable = dataFile ( (section +
"/" + subSection +
"/energy_minimization/enable").data(),
false, found );
271 list.set (
"energy minimization: enable", EnergyMinimizationEnable );
274 Int EnergyMinimizationType = dataFile ( (section +
"/" + subSection +
"/energy_minimization/type").data(), 2, found );
277 list.set (
"energy minimization: type", EnergyMinimizationType );
280 Real EnergyMinimizationDropTol = dataFile ( (section +
"/" + subSection +
"/energy_minimization/droptol").data(), 0., found );
283 list.set (
"energy minimization: droptol", EnergyMinimizationDropTol );
286 bool EnergyMinimizationCheap = dataFile ( (section +
"/" + subSection +
"/energy_minimization/cheap").data(),
false, found );
289 list.set (
"energy minimization: cheap", EnergyMinimizationCheap );
294 std::string SmootherType = dataFile ( (section +
"/" + subSection +
"/smoother/type").data(),
"IFPACK", found );
297 list.set (
"smoother: type", SmootherType );
300 Int SmootherSweeps = dataFile ( (section +
"/" + subSection +
"/smoother/sweeps").data(), 2, found );
303 list.set (
"smoother: sweeps", SmootherSweeps );
306 Real SmootherDampingFactor = dataFile ( (section +
"/" + subSection +
"/smoother/damping_factor").data(), 1.0, found );
309 list.set (
"smoother: damping factor", SmootherDampingFactor );
312 std::string SmootherPreOrPost = dataFile ( (section +
"/" + subSection +
"/smoother/pre_or_post").data(),
"both", found );
315 list.set (
"smoother: pre or post", SmootherPreOrPost );
318 Real SmootherChebyshevAlpha = dataFile ( (section +
"/" + subSection +
"/smoother/Chebyshev_alpha").data(), 20., found );
321 list.set (
"smoother: Chebyshev alpha", SmootherChebyshevAlpha );
324 bool SmootherHiptmairEfficientSymmetric = dataFile ( (section +
"/" + subSection +
"/smoother/Hiptmair_efficient_symmetric").data(),
true, found );
327 list.set (
"smoother: Hiptmair efficient symmetric", SmootherHiptmairEfficientSymmetric );
330 std::string SmootherIfpackType = dataFile ( (section +
"/" + subSection +
"/smoother/ifpack_type").data(),
"ILU", found );
333 list.set (
"smoother: ifpack type", SmootherIfpackType );
336 Int SmootherIfpackOverlap = dataFile ( (section +
"/" + subSection +
"/smoother/ifpack_overlap").data(), 1, found );
339 list.set (
"smoother: ifpack overlap", SmootherIfpackOverlap );
342 Int SmootherNumLevelTypes = dataFile ( (section +
"/" + subSection +
"/smoother/level_type").data(), 0, found );
345 for (
Int i (0); i < SmootherNumLevelTypes; ++i)
347 std::string levelIndex = dataFile ( (section +
"/" + subSection +
"/smoother/level_type").data(),
"0", 2 * i + 1 );
348 std::string levelParamValue = dataFile ( (section +
"/" + subSection +
"/smoother/level_type").data(),
"IFPACK", 2 * i + 2 );
349 list.set ( (
"smoother: type (level " + levelIndex +
")").data(), levelParamValue );
353 Int SmootherNumLevelSweeps = dataFile ( (section +
"/" + subSection +
"/smoother/level_sweeps").data(), 0, found );
356 for (
Int i (0); i < SmootherNumLevelSweeps; ++i)
358 std::string levelIndex = dataFile ( (section +
"/" + subSection +
"/smoother/level_sweeps").data(),
"0", 2 * i + 1 );
359 Int levelParamValue = dataFile ( (section +
"/" + subSection +
"/smoother/level_sweeps").data(), 1, 2 * i + 2 );
360 list.set ( (
"smoother: sweeps (level " + levelIndex +
")").data(), levelParamValue );
366 std::string SubSmootherType = dataFile ( (section +
"/" + subSection +
"/subsmoother/type").data(),
"Chebyshev", found );
369 list.set (
"subsmoother: type", SubSmootherType );
372 Real SubSmootherChebyshevAlpha = dataFile ( (section +
"/" + subSection +
"/subsmoother/Chebyshev_alpha").data(), 20., found );
375 list.set (
"subsmoother: Chebyshev alpha", SubSmootherChebyshevAlpha );
379 Int SubSmootherEdgeSweeps = dataFile ( (section +
"/" + subSection +
"/subsmoother/edge_sweeps").data(), 2, found );
382 list.set (
"subsmoother: edge sweeps", SubSmootherEdgeSweeps );
385 Int SubSmootherNodeSweeps = dataFile ( (section +
"/" + subSection +
"/subsmoother/node_sweeps").data(), 2, found );
388 list.set (
"subsmoother: node sweeps", SubSmootherNodeSweeps );
394 Int CoarseMaxSize = dataFile ( (section +
"/" + subSection +
"/coarse/max_size").data(), 128, found );
397 list.set (
"coarse: max size", CoarseMaxSize );
400 std::string CoarseType = dataFile ( (section +
"/" + subSection +
"/coarse/type").data(),
"Chebyshev", found );
403 list.set (
"coarse: type", CoarseType );
406 std::string CoarsePreOrPost = dataFile ( (section +
"/" + subSection +
"/coarse/pre_or_post").data(),
"post", found );
409 list.set (
"coarse: pre or post", CoarsePreOrPost );
412 Int CoarseSweeps = dataFile ( (section +
"/" + subSection +
"/coarse/sweeps").data(), 2, found );
415 list.set (
"coarse: sweeps", CoarseSweeps );
418 Real CoarseDampingFactor = dataFile ( (section +
"/" + subSection +
"/coarse/damping_factor").data(), 1.0, found );
421 list.set (
"coarse: damping factor", CoarseDampingFactor );
424 std::string CoarseSubsmootherType = dataFile ( (section +
"/" + subSection +
"/coarse/subsmoother_type").data(),
"Chebyshev", found );
427 list.set (
"coarse: subsmoother type", CoarseSubsmootherType );
430 Int CoarseNodeSweeps = dataFile ( (section +
"/" + subSection +
"/coarse/node_sweeps").data(), 2, found );
433 list.set (
"coarse: node sweeps", CoarseNodeSweeps );
436 Int CoarseEdgeSweeps = dataFile ( (section +
"/" + subSection +
"/coarse/edge_sweeps").data(), 2, found );
439 list.set (
"coarse: edge sweeps", CoarseEdgeSweeps );
442 Real CoarseChebyshevAlpha = dataFile ( (section +
"/" + subSection +
"/coarse/Chebyshev_alpha").data(), 30., found );
445 list.set (
"coarse: Chebyshev alpha", CoarseChebyshevAlpha );
448 Int CoarseMaxProcesses = dataFile ( (section +
"/" + subSection +
"/coarse/max_processes").data(), -1, found );
451 list.set (
"coarse: max processes", CoarseMaxProcesses );
456 Int RepartitionEnable = dataFile ( (section +
"/" + subSection +
"/repartition/enable").data(), 0, found );
459 list.set (
"repartition: enable", RepartitionEnable );
462 std::string RepartitionPartitioner = dataFile ( (section +
"/" + subSection +
"/repartition/partitioner").data(),
"ParMETIS", found );
465 list.set (
"repartition: partitioner", RepartitionPartitioner );
468 Real RepartitionMaxMinRatio = dataFile ( (section +
"/" + subSection +
"/repartition/max_min_ratio").data(), 1.3, found );
471 list.set (
"repartition: max min ratio", RepartitionMaxMinRatio );
474 Int RepartitionMinPerProc = dataFile ( (section +
"/" + subSection +
"/repartition/min_per_proc").data(), 512, found );
477 list.set (
"repartition: min per proc", RepartitionMinPerProc );
480 Real RepartitionNodeMaxMinRatio = dataFile ( (section +
"/" + subSection +
"/repartition/node_max_min_ratio").data(), 1.3, found );
483 list.set (
"repartition: node max min ratio", RepartitionNodeMaxMinRatio );
486 Int RepartitionNodeMinPerProc = dataFile ( (section +
"/" + subSection +
"/repartition/node_min_per_proc").data(), 170, found );
489 list.set (
"repartition: node min per proc", RepartitionNodeMinPerProc );
492 Int RepartitionZoltanDimensions = dataFile ( (section +
"/" + subSection +
"/repartition/Zoltan_dimensions").data(), 2, found );
495 list.set (
"repartition: Zoltan dimensions", RepartitionZoltanDimensions );
498 if ( MLPrintParameterList && verbose )
500 std::cout <<
"ML parameters list:" << std::endl;
501 std::cout <<
"-----------------------------" << std::endl;
502 list.print ( std::cout );
503 std::cout <<
"-----------------------------" << std::endl;
509 output <<
"showMe must be implemented for the PreconditionerML class" << std::endl;
517 const std::string& section )
519 bool verbose = M_comm->MyPID() == 0;
521 M_analyze = dataFile ( (section +
"/" +
"ML" +
"/analyze_smoother" ).data(),
false);
524 createMLList ( M_list, dataFile, section,
"ML", verbose );
528 bool enableViz = dataFile ( (section +
"/" +
"ML" +
"/visualization/enable").data(),
false, found );
538 M_list.set (
"viz: enable", enableViz);
539 M_list.set (
"viz: output format",
"vtk");
540 M_list.set (
"x-coordinates", & ( (*M_xCoord) [0]) );
541 M_list.set (
"y-coordinates", & ( (*M_yCoord) [0]) );
542 M_list.set (
"z-coordinates", & ( (*M_zCoord) [0]) );
546 std::cout <<
"Warning: Visualization options are not available if you have not use setVerticesCoordinates first!" << std::endl;
551 bool MLPrintParameterList = dataFile ( (section +
"/displayList").data(),
false );
552 if ( MLPrintParameterList && verbose )
554 std::cout <<
"Smoother: ";
556 list_Type& SmootherIFSubList = M_list.sublist (
"smoother: ifpack list" );
557 PreconditionerIfpack::createIfpackList ( SmootherIFSubList, dataFile, section,
"ML", verbose );
bool M_preconditionerCreated
int32_type Int
Generic integer data.
void updateInverseJacobian(const UInt &iQuadPt)
prec_type M_preconditioner
void resetPreconditioner()
Reset the preconditioner.
virtual ~PreconditionerML()
destructor.
void setDataFromGetPot(const GetPot &dataFile, const std::string §ion)
Set the data of the preconditioner using a GetPot object.
bool M_visualizationDataAvailable
Preconditioner(const commPtr_Type &comm=commPtr_Type())
Constructor.
double Real
Generic real data.
virtual void showMe(std::ostream &output=std::cout) const
Show informations about the preconditioner.
Teuchos::ParameterList list_Type
static void createMLList(list_Type &list, const GetPot &dataFile, const std::string §ion, const std::string &subSection="ML", const bool &verbose=true)
Create the list of parameters of the preconditioner.
PreconditionerML(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
Empty constructor.
Int buildPreconditioner(operator_type &matrix)
Build a preconditioner based on the given matrix.