46#ifndef MUELU_SHIFTEDLAPLACIAN_DEF_HPP
47#define MUELU_SHIFTEDLAPLACIAN_DEF_HPP
51#if defined(HAVE_MUELU_IFPACK2) and defined(HAVE_MUELU_TPETRA)
53#include <MueLu_AmalgamationFactory.hpp>
54#include <MueLu_CoalesceDropFactory.hpp>
55#include <MueLu_CoarseMapFactory.hpp>
56#include <MueLu_CoupledRBMFactory.hpp>
57#include <MueLu_DirectSolver.hpp>
58#include <MueLu_GenericRFactory.hpp>
59#include <MueLu_Hierarchy.hpp>
60#include <MueLu_Ifpack2Smoother.hpp>
61#include <MueLu_PFactory.hpp>
62#include <MueLu_PgPFactory.hpp>
63#include <MueLu_RAPFactory.hpp>
64#include <MueLu_RAPShiftFactory.hpp>
65#include <MueLu_SaPFactory.hpp>
66#include <MueLu_ShiftedLaplacian.hpp>
67#include <MueLu_ShiftedLaplacianOperator.hpp>
68#include <MueLu_SmootherFactory.hpp>
69#include <MueLu_SmootherPrototype.hpp>
70#include <MueLu_TentativePFactory.hpp>
71#include <MueLu_TransPFactory.hpp>
72#include <MueLu_UncoupledAggregationFactory.hpp>
73#include <MueLu_Utilities.hpp>
78template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 coarseGridSize_ = paramList->get(
"MueLu: coarse size", 1000);
87 numLevels_ = paramList->get(
"MueLu: levels", 3);
88 int stype = paramList->get(
"MueLu: smoother", 8);
89 if(stype==1) { Smoother_=
"jacobi"; }
90 else if(stype==2) { Smoother_=
"gauss-seidel"; }
91 else if(stype==3) { Smoother_=
"symmetric gauss-seidel"; }
92 else if(stype==4) { Smoother_=
"chebyshev"; }
93 else if(stype==5) { Smoother_=
"krylov"; }
94 else if(stype==6) { Smoother_=
"ilut"; }
95 else if(stype==7) { Smoother_=
"riluk"; }
96 else if(stype==8) { Smoother_=
"schwarz"; }
97 else if(stype==9) { Smoother_=
"superilu"; }
98 else if(stype==10) { Smoother_=
"superlu"; }
99 else { Smoother_=
"schwarz"; }
100 smoother_sweeps_ = paramList->get(
"MueLu: sweeps", 5);
101 smoother_damping_ = paramList->get(
"MueLu: relax val", 1.0);
102 ncycles_ = paramList->get(
"MueLu: cycles", 1);
103 iters_ = paramList->get(
"MueLu: iterations", 500);
104 solverType_ = paramList->get(
"MueLu: solver type", 1);
105 restart_size_ = paramList->get(
"MueLu: restart size", 100);
106 recycle_size_ = paramList->get(
"MueLu: recycle size", 25);
107 isSymmetric_ = paramList->get(
"MueLu: symmetric",
true);
108 ilu_leveloffill_ = paramList->get(
"MueLu: level-of-fill", 5);
109 ilu_abs_thresh_ = paramList->get(
"MueLu: abs thresh", 0.0);
110 ilu_rel_thresh_ = paramList->get(
"MueLu: rel thresh", 1.0);
111 ilu_diagpivotthresh_ = paramList->get(
"MueLu: piv thresh", 0.1);
112 ilu_drop_tol_ = paramList->get(
"MueLu: drop tol", 0.01);
113 ilu_fill_tol_ = paramList->get(
"MueLu: fill tol", 0.01);
114 schwarz_overlap_ = paramList->get(
"MueLu: overlap", 0);
115 schwarz_usereorder_ = paramList->get(
"MueLu: use reorder",
true);
116 int combinemode = paramList->get(
"MueLu: combine mode", 1);
117 if(combinemode==0) { schwarz_combinemode_ = Tpetra::ZERO; }
118 else { schwarz_combinemode_ = Tpetra::ADD; }
119 tol_ = paramList->get(
"MueLu: tolerance", 0.001);
123template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
127 if(A_!=Teuchos::null)
129#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
130 if(LinearProblem_!=Teuchos::null)
131 LinearProblem_ -> setOperator ( TpetraA_ );
133 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
138template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
142#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
143 if(LinearProblem_!=Teuchos::null)
144 LinearProblem_ -> setOperator ( TpetraA_ );
149template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
153 GridTransfersExist_=
false;
157template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
160 RCP< Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Atmp
161 = rcp(
new Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(TpetraP) );
162 P_= rcp(
new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(Atmp) );
163 GridTransfersExist_=
false;
167template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
177 RCP< Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Atmp
178 = rcp(
new Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(TpetraK) );
179 K_= rcp(
new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(Atmp) );
183template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
190template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
193 RCP< Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Atmp
194 = rcp(
new Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(TpetraM) );
195 M_= rcp(
new Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(Atmp) );
199template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
206template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
209 NullSpace_=NullSpace;
213template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
216 levelshifts_=levelshifts;
217 numLevels_=levelshifts_.size();
222template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
237 Manager_ -> SetFactory(
"UnAmalgamationInfo", Amalgfact_);
238 Teuchos::ParameterList params;
239 params.set(
"lightweight wrap",
true);
240 params.set(
"aggregation: drop scheme",
"classical");
241 Dropfact_ -> SetParameterList(params);
242 Manager_ -> SetFactory(
"Graph", Dropfact_);
243 Manager_ -> SetFactory(
"Aggregates", UCaggfact_ );
244 Manager_ -> SetFactory(
"CoarseMap", CoarseMapfact_);
245 Manager_ -> SetFactory(
"Ptent", TentPfact_);
246 if(isSymmetric_==
true) {
247 Manager_ -> SetFactory(
"P", Pfact_);
248 Manager_ -> SetFactory(
"R", TransPfact_);
251 Manager_ -> SetFactory(
"P", PgPfact_);
252 Manager_ -> SetFactory(
"R", Rfact_);
257 if(Smoother_==
"jacobi") {
258 precType_ =
"RELAXATION";
259 precList_.set(
"relaxation: type",
"Jacobi");
260 precList_.set(
"relaxation: sweeps", smoother_sweeps_);
261 precList_.set(
"relaxation: damping factor", smoother_damping_);
263 else if(Smoother_==
"gauss-seidel") {
264 precType_ =
"RELAXATION";
265 precList_.set(
"relaxation: type",
"Gauss-Seidel");
266 precList_.set(
"relaxation: sweeps", smoother_sweeps_);
267 precList_.set(
"relaxation: damping factor", smoother_damping_);
269 else if(Smoother_==
"symmetric gauss-seidel") {
270 precType_ =
"RELAXATION";
271 precList_.set(
"relaxation: type",
"Symmetric Gauss-Seidel");
272 precList_.set(
"relaxation: sweeps", smoother_sweeps_);
273 precList_.set(
"relaxation: damping factor", smoother_damping_);
275 else if(Smoother_==
"chebyshev") {
276 precType_ =
"CHEBYSHEV";
278 else if(Smoother_==
"krylov") {
279 precType_ =
"KRYLOV";
280 precList_.set(
"krylov: iteration type", krylov_type_);
281 precList_.set(
"krylov: number of iterations", krylov_iterations_);
282 precList_.set(
"krylov: residual tolerance",1.0e-8);
283 precList_.set(
"krylov: block size",1);
284 precList_.set(
"krylov: preconditioner type", krylov_preconditioner_);
285 precList_.set(
"relaxation: sweeps",1);
288 else if(Smoother_==
"ilut") {
290 precList_.set(
"fact: ilut level-of-fill", ilu_leveloffill_);
291 precList_.set(
"fact: absolute threshold", ilu_abs_thresh_);
292 precList_.set(
"fact: relative threshold", ilu_rel_thresh_);
293 precList_.set(
"fact: drop tolerance", ilu_drop_tol_);
294 precList_.set(
"fact: relax value", ilu_relax_val_);
296 else if(Smoother_==
"riluk") {
298 precList_.set(
"fact: iluk level-of-fill", ilu_leveloffill_);
299 precList_.set(
"fact: absolute threshold", ilu_abs_thresh_);
300 precList_.set(
"fact: relative threshold", ilu_rel_thresh_);
301 precList_.set(
"fact: drop tolerance", ilu_drop_tol_);
302 precList_.set(
"fact: relax value", ilu_relax_val_);
304 else if(Smoother_==
"schwarz") {
305 precType_ =
"SCHWARZ";
306 precList_.set(
"schwarz: overlap level", schwarz_overlap_);
307 precList_.set(
"schwarz: combine mode", schwarz_combinemode_);
308 precList_.set(
"schwarz: use reordering", schwarz_usereorder_);
310 precList_.set(
"order_method",schwarz_ordermethod_);
311 precList_.sublist(
"schwarz: reordering list").set(
"order_method",schwarz_ordermethod_);
312 precList_.sublist(
"schwarz: subdomain solver parameters").set(
"fact: ilut level-of-fill", ilu_leveloffill_);
313 precList_.sublist(
"schwarz: subdomain solver parameters").set(
"fact: absolute threshold", ilu_abs_thresh_);
314 precList_.sublist(
"schwarz: subdomain solver parameters").set(
"fact: relative threshold", ilu_rel_thresh_);
315 precList_.sublist(
"schwarz: subdomain solver parameters").set(
"fact: drop tolerance", ilu_drop_tol_);
316 precList_.sublist(
"schwarz: subdomain solver parameters").set(
"fact: relax value", ilu_relax_val_);
318 else if(Smoother_==
"superilu") {
319 precType_ =
"superlu";
320 precList_.set(
"RowPerm", ilu_rowperm_);
321 precList_.set(
"ColPerm", ilu_colperm_);
322 precList_.set(
"DiagPivotThresh", ilu_diagpivotthresh_);
323 precList_.set(
"ILU_DropRule",ilu_drop_rule_);
324 precList_.set(
"ILU_DropTol",ilu_drop_tol_);
325 precList_.set(
"ILU_FillFactor",ilu_leveloffill_);
326 precList_.set(
"ILU_Norm",ilu_normtype_);
327 precList_.set(
"ILU_MILU",ilu_milutype_);
328 precList_.set(
"ILU_FillTol",ilu_fill_tol_);
329 precList_.set(
"ILU_Flag",
true);
331 else if(Smoother_==
"superlu") {
332 precType_ =
"superlu";
333 precList_.set(
"ColPerm", ilu_colperm_);
334 precList_.set(
"DiagPivotThresh", ilu_diagpivotthresh_);
336#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
340#if defined(HAVE_MUELU_AMESOS2) and defined(HAVE_AMESOS2_SUPERLU)
341 coarsestSmooProto_ = rcp(
new DirectSolver(
"Superlu",coarsestSmooList_) );
342#elif defined(HAVE_MUELU_AMESOS2) and defined(HAVE_AMESOS2_KLU2)
343 coarsestSmooProto_ = rcp(
new DirectSolver(
"Klu",coarsestSmooList_) );
344#elif defined(HAVE_MUELU_AMESOS2) and defined(HAVE_AMESOS2_SUPERLUDIST)
345 coarsestSmooProto_ = rcp(
new DirectSolver(
"Superludist",coarsestSmooList_) );
349 coarsestSmooFact_ = rcp(
new SmootherFactory(coarsestSmooProto_, Teuchos::null) );
357 if(K_!=Teuchos::null) {
358 Manager_ -> SetFactory(
"Smoother", Teuchos::null);
359 Manager_ -> SetFactory(
"CoarseSolver", Teuchos::null);
361 if(NullSpace_!=Teuchos::null)
362 Hierarchy_ -> GetLevel(0) -> Set(
"Nullspace", NullSpace_);
363 if(isSymmetric_==
true) {
364 Hierarchy_ ->
Keep(
"P", Pfact_.get());
365 Hierarchy_ ->
Keep(
"R", TransPfact_.get());
366 Hierarchy_ -> SetImplicitTranspose(
true);
369 Hierarchy_ ->
Keep(
"P", PgPfact_.get());
370 Hierarchy_ ->
Keep(
"R", Rfact_.get());
372 Hierarchy_ ->
Keep(
"Ptent", TentPfact_.get());
373 Hierarchy_ -> SetMaxCoarseSize( coarseGridSize_ );
374 Hierarchy_ -> Setup(*Manager_, 0, numLevels_);
375 GridTransfersExist_=
true;
379 Manager_ -> SetFactory(
"Smoother", smooFact_);
380 Manager_ -> SetFactory(
"CoarseSolver", coarsestSmooFact_);
382 if(NullSpace_!=Teuchos::null)
383 Hierarchy_ -> GetLevel(0) -> Set(
"Nullspace", NullSpace_);
384 if(isSymmetric_==
true)
385 Hierarchy_ -> SetImplicitTranspose(
true);
386 Hierarchy_ -> SetMaxCoarseSize( coarseGridSize_ );
387 Hierarchy_ -> Setup(*Manager_, 0, numLevels_);
388 GridTransfersExist_=
true;
392 BelosList_ = rcp(
new Teuchos::ParameterList(
"GMRES") );
393 BelosList_ -> set(
"Maximum Iterations",iters_ );
394 BelosList_ -> set(
"Convergence Tolerance",tol_ );
395 BelosList_ -> set(
"Verbosity", Belos::Errors + Belos::Warnings + Belos::StatusTestDetails);
396 BelosList_ -> set(
"Output Frequency",1);
397 BelosList_ -> set(
"Output Style",Belos::Brief);
398 BelosList_ -> set(
"Num Blocks",restart_size_);
399 BelosList_ -> set(
"Num Recycled Blocks",recycle_size_);
401 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
406template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
409 int numLevels = Hierarchy_ -> GetNumLevels();
410 Manager_ -> SetFactory(
"Smoother", smooFact_);
411 Manager_ -> SetFactory(
"CoarseSolver", coarsestSmooFact_);
412 Hierarchy_ -> GetLevel(0) -> Set(
"A", P_);
413 Hierarchy_ -> Setup(*Manager_, 0, numLevels);
419template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
422 int numLevels = Hierarchy_ -> GetNumLevels();
423 Acshift_->SetShifts(levelshifts_);
424 Manager_ -> SetFactory(
"Smoother", smooFact_);
425 Manager_ -> SetFactory(
"CoarseSolver", coarsestSmooFact_);
426 Manager_ -> SetFactory(
"A", Acshift_);
427 Manager_ -> SetFactory(
"K", Acshift_);
428 Manager_ -> SetFactory(
"M", Acshift_);
429 Hierarchy_ -> GetLevel(0) -> Set(
"A", P_);
430 Hierarchy_ -> GetLevel(0) -> Set(
"K", K_);
431 Hierarchy_ -> GetLevel(0) -> Set(
"M", M_);
432 Hierarchy_ -> Setup(*Manager_, 0, numLevels);
438template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
442 if( GridTransfersExist_ ==
false ) {
444 if(NullSpace_!=Teuchos::null)
445 Hierarchy_ -> GetLevel(0) -> Set(
"Nullspace", NullSpace_);
446 if(isSymmetric_==
true)
447 Hierarchy_ -> SetImplicitTranspose(
true);
448 Hierarchy_ -> SetMaxCoarseSize( coarseGridSize_ );
449 Hierarchy_ -> Setup(*Manager_, 0, numLevels_);
450 GridTransfersExist_=
true;
456template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
459#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
462 (Hierarchy_, A_, ncycles_, subiters_, option_, tol_) );
464 if(LinearProblem_==Teuchos::null)
465 LinearProblem_ = rcp(
new LinearProblem );
466 LinearProblem_ -> setOperator ( TpetraA_ );
467 LinearProblem_ -> setRightPrec( MueLuOp_ );
468 if(SolverManager_==Teuchos::null) {
469 std::string solverName;
470 SolverFactory_= rcp(
new SolverFactory() );
471 if(solverType_==1) { solverName=
"Block GMRES"; }
472 else if(solverType_==2) { solverName=
"Recycling GMRES"; }
473 else { solverName=
"Flexible GMRES"; }
474 SolverManager_ = SolverFactory_->create( solverName, BelosList_ );
475 SolverManager_ -> setProblem( LinearProblem_ );
478 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
482template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
485#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
486 LinearProblem_ -> setOperator ( TpetraA_ );
488 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
493template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
496#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
498 LinearProblem_ -> setProblem(X, B);
500 SolverManager_ -> solve();
502 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
508template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
513 Hierarchy_ -> Iterate(*B, *X, 1,
true, 0);
517template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
519 RCP<Tpetra::MultiVector<SC,LO,GO,NO> >& X)
521 Teuchos::RCP< Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > XpetraX
522 = Teuchos::rcp(
new Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(X) );
523 Teuchos::RCP< Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > XpetraB
524 = Teuchos::rcp(
new Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(B) );
526 Hierarchy_ -> Iterate(*XpetraB, *XpetraX, 1,
true, 0);
530template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
533#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
534 int numiters = SolverManager_ -> getNumIters();
537 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
543template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
544typename Teuchos::ScalarTraits<Scalar>::magnitudeType
547 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType MT;
548#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
549 MT residual = SolverManager_ -> achievedTol();
552 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"ShiftedLaplacian only available with Tpetra and GO=int enabled.");
559#define MUELU_SHIFTEDLAPLACIAN_SHORT
AmalgamationFactory for subblocks of strided map based amalgamation data.
Factory for creating a graph based on a given matrix.
Factory for generating coarse level map. Used by TentativePFactory.
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
Exception throws to report errors in the internal logical of the program.
This class specifies the default factory that should generate some data on a Level if the data does n...
Factory for building restriction operators using a prolongator factory.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Class that encapsulates Ifpack2 smoothers.
Factory for building Petrov-Galerkin Smoothed Aggregation prolongators.
Factory for building coarse matrices.
Factory for building coarse grid matrices, when the matrix is of the form K+a*M. Useful when you want...
Factory for building Smoothed Aggregation prolongators.
Wraps an existing MueLu::Hierarchy as a Tpetra::Operator, with an optional two-level correction....
void setPreconditioningMatrix(RCP< Matrix > &P)
void setmass(RCP< Matrix > &M)
void resetLinearProblem()
void setNullSpace(RCP< MultiVector > NullSpace)
void setcoords(RCP< MultiVector > &Coords)
Teuchos::ScalarTraits< Scalar >::magnitudeType GetResidual()
int solve(const RCP< TMV > B, RCP< TMV > &X)
void setLevelShifts(std::vector< Scalar > levelshifts)
void setParameters(Teuchos::RCP< Teuchos::ParameterList > paramList)
virtual ~ShiftedLaplacian()
void setstiff(RCP< Matrix > &K)
void setProblemMatrix(RCP< Matrix > &A)
void multigrid_apply(const RCP< MultiVector > B, RCP< MultiVector > &X)
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
Factory for building tentative prolongator.
Factory for building restriction operators.
Factory for building uncoupled aggregates.
static RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
Namespace for MueLu classes and methods.
@ Keep
Always keep data, even accross run. This flag is set by Level::Keep(). This flag is propagated to coa...