Debian Codegraph @

packages/shylu/shylu_dd/frosch/src/SolverInterfaces/FROSch_MueLuPreconditioner_def.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // ShyLU: Scalable Hybrid LU Preconditioner and Solver
4 //
5 // Copyright 2011 NTESS and the ShyLU contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef _FROSCH_MUELUPRECONDITIONER_DEF_HPP
11 #define _FROSCH_MUELUPRECONDITIONER_DEF_HPP
12
13 #include <FROSch_MueLuPreconditioner_decl.hpp>
14
15
16 namespace FROSch {
17
18 using namespace Teuchos;
19 using namespace Xpetra;
20
21 template<class SC,class LO,class GO,class NO>
22 int MueLuPreconditioner<SC,LO,GO,NO>::initialize()
23 {
24 FROSCH_TIMER_START_SOLVER(initializeTime,"MueLuPreconditioner::initialize");
25 this->IsInitialized_ = true;
26 this->IsComputed_ = false;
27 return 0;
28 }
29
30 template<class SC,class LO,class GO,class NO>
31 int MueLuPreconditioner<SC,LO,GO,NO>::compute()
32 {
33 FROSCH_TIMER_START_SOLVER(computeTime,"MueLuPreconditioner::compute");
34 FROSCH_ASSERT(this->IsInitialized_,"FROSch::MueLuPreconditioner: !this->IsInitialized_");
35 MueLuFactory_->SetupHierarchy(*MueLuHierarchy_);
36 MueLuHierarchy_->IsPreconditioner(false);
37 this->IsComputed_ = true;
38 return 0;
39 }
40
41 template<class SC,class LO,class GO,class NO>
42 void MueLuPreconditioner<SC,LO,GO,NO>::apply(const XMultiVector &x,
43 XMultiVector &y,
44 ETransp mode,
45 SC alpha,
46 SC beta) const
47 {
48 FROSCH_TIMER_START_SOLVER(applyTime,"MueLuPreconditioner::apply");
49 FROSCH_ASSERT(this->IsComputed_,"FROSch::MueLuPreconditioner: !this->IsComputed_.");
50
51 if (Y_.is_null()) Y_ = XMultiVectorFactory::Build(y.getMap(),y.getNumVectors());
52
53 int mgridSweeps = this->ParameterList_->sublist("MueLu").get("mgridSweeps",-1);
54 if (mgridSweeps>0) {
55 MueLuHierarchy_->Iterate(x,*Y_,mgridSweeps);
56 }
57 else{
58 typename ScalarTraits<SC>::magnitudeType tol = this->ParameterList_->sublist("MueLu").get("tol",1.e-6);
59 MueLuHierarchy_->Iterate(x,*Y_,tol);
60 }
61 y.update(alpha,*Y_,beta);
62 }
63
64 template<class SC,class LO,class GO,class NO>
65 int MueLuPreconditioner<SC,LO,GO,NO>::updateMatrix(ConstXMatrixPtr k,
66 bool reuseInitialize)
67 {
68 FROSCH_ASSERT(false,"FROSch::MueLuPreconditioner: updateMatrix() is not implemented for the MueLuPreconditioner yet.");
69 return 0;
70 }
71
72 template<class SC,class LO,class GO,class NO>
73 MueLuPreconditioner<SC,LO,GO,NO>::MueLuPreconditioner(ConstXMatrixPtr k,
74 ParameterListPtr parameterList,
75 string description) :
76 Solver<SC,LO,GO,NO> (k,parameterList,description)
77 {
78 FROSCH_TIMER_START_SOLVER(MueLuPreconditionerTime,"MueLuPreconditioner::MueLuPreconditioner");
79 FROSCH_ASSERT(!this->K_.is_null(),"FROSch::MueLuPreconditioner: K_ is null.");
80
81 MueLuFactory_ = rcp(new MueLu::ParameterListInterpreter<SC,LO,GO,NO>(this->ParameterList_->sublist("MueLu").sublist("MueLu Parameter")));
82 RCP<XMultiVector> nullspace;
83
84 if (!this->ParameterList_->sublist("MueLu").get("NullSpace","Laplace").compare("Laplace")) {
85 nullspace = XMultiVectorFactory::Build(this->K_->getRowMap(), 1);
86 nullspace->putScalar(1.);
87 } else {
88 FROSCH_ASSERT(false,"FROSch::MueLuPreconditioner: Only Laplacian null space is supported so far.");
89 }
90 MueLuHierarchy_ = MueLuFactory_->CreateHierarchy(); // Das vor den if block
91 MueLuHierarchy_->GetLevel(0)->Set("A", Teuchos::rcp_const_cast<XMatrix>(this->K_)); // Das in den if block
92 MueLuHierarchy_->GetLevel(0)->Set("Nullspace", nullspace);
93 }
94
95 }
96
97 #endif