| 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_FROSCHPRECONDITIONER_DEF_HPP |
| 11 |
#define _FROSCH_FROSCHPRECONDITIONER_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_FROSchPreconditioner_decl.hpp> |
| 14 |
#include <FROSch_TwoLevelBlockPreconditioner_def.hpp> |
| 15 |
#include <FROSch_TwoLevelPreconditioner_def.hpp> |
| 16 |
|
| 17 |
namespace FROSch { |
| 18 |
|
| 19 |
using namespace std; |
| 20 |
using namespace Teuchos; |
| 21 |
using namespace Xpetra; |
| 22 |
|
| 23 |
template<class SC,class LO,class GO,class NO> |
| 24 |
int FROSchPreconditioner<SC,LO,GO,NO>::initialize() |
| 25 |
{ |
| 26 |
FROSCH_TIMER_START_SOLVER(initializeTime,"FROSchPreconditioner::initialize"); |
| 27 |
this->IsInitialized_ = true; |
| 28 |
this->IsComputed_ = false; |
| 29 |
return 0; |
| 30 |
} |
| 31 |
|
| 32 |
template<class SC,class LO,class GO,class NO> |
| 33 |
int FROSchPreconditioner<SC,LO,GO,NO>::compute() |
| 34 |
{ |
| 35 |
FROSCH_TIMER_START_SOLVER(computeTime,"FROSchPreconditioner::compute"); |
| 36 |
FROSCH_ASSERT(this->IsInitialized_,"FROSch::FROSchPreconditioner: !this->IsInitialized_"); |
| 37 |
this->IsComputed_ = true; |
| 38 |
FROSchPreconditioner_->compute(); |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
template<class SC,class LO,class GO,class NO> |
| 43 |
void FROSchPreconditioner<SC,LO,GO,NO>::apply(const XMultiVector &x, |
| 44 |
XMultiVector &y, |
| 45 |
ETransp mode, |
| 46 |
SC alpha, |
| 47 |
SC beta) const |
| 48 |
{ |
| 49 |
FROSCH_TIMER_START_SOLVER(applyTime,"FROSchPreconditioner::apply"); |
| 50 |
FROSCH_ASSERT(this->IsComputed_,"FROSch::FROSchPreconditioner: !this->IsComputed_."); |
| 51 |
|
| 52 |
FROSchPreconditioner_->apply(x,y,mode,alpha,beta); |
| 53 |
} |
| 54 |
|
| 55 |
template<class SC,class LO,class GO,class NO> |
| 56 |
int FROSchPreconditioner<SC,LO,GO,NO>::updateMatrix(ConstXMatrixPtr k, |
| 57 |
bool reuseInitialize) |
| 58 |
{ |
| 59 |
FROSCH_ASSERT(false,"FROSch::FROSchPreconditioner: updateMatrix() is not implemented for the FROSchPreconditioner yet."); |
| 60 |
} |
| 61 |
|
| 62 |
template<class SC,class LO,class GO,class NO> |
| 63 |
FROSchPreconditioner<SC,LO,GO,NO>::FROSchPreconditioner(ConstXMatrixPtr k, |
| 64 |
ParameterListPtr parameterList, |
| 65 |
string description) : |
| 66 |
Solver<SC,LO,GO,NO> (k,parameterList,description) |
| 67 |
{ |
| 68 |
FROSCH_TIMER_START_SOLVER(FROSchPreconditionerTime,"FROSchPreconditioner::FROSchPreconditioner"); |
| 69 |
FROSCH_ASSERT(!this->K_.is_null(),"FROSch::FROSchPreconditioner: K_ is null."); |
| 70 |
|
| 71 |
if (!this->ParameterList_->get("Solver","TwoLevelPreconditioner").compare("TwoLevelPreconditioner")) { |
| 72 |
ParameterListPtr froschParameterList = sublist(this->ParameterList_,"FROSchPreconditioner"); |
| 73 |
if (froschParameterList->isSublist(this->ParameterList_->get("Solver","TwoLevelPreconditioner"))) froschParameterList = sublist(froschParameterList,this->ParameterList_->get("Solver","TwoLevelPreconditioner")); |
| 74 |
// if (this->K_->getMap()->getComm()->getRank() == 0) froschParameterList->print(cout); |
| 75 |
|
| 76 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > RepeatedMaps(1); |
| 77 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > NodesMaps(1); |
| 78 |
|
| 79 |
UNVecPtr dofsPerNodeVector(1); |
| 80 |
ArrayRCP<DofOrdering> dofOrderings(1); |
| 81 |
ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > > dofsMapsVec(1); |
| 82 |
ArrayRCP<RCP<Map<LO,GO,NO> > > MainCoarseMapVector(1); |
| 83 |
|
| 84 |
if (froschParameterList->isParameter("Repeated Map Vector")) { |
| 85 |
RepeatedMaps = ExtractVectorFromParameterList<RCP<const Map<LO,GO,NO> > >(*froschParameterList,"Repeated Map Vector"); |
| 86 |
} |
| 87 |
|
| 88 |
if (froschParameterList->isParameter("Nodes Map Vector")) { |
| 89 |
NodesMaps = ExtractVectorFromParameterList<RCP<const Map<LO,GO,NO> > >(*froschParameterList,"Nodes Map Vector"); |
| 90 |
} |
| 91 |
|
| 92 |
if (froschParameterList->isParameter("DofsPerNode Vector")) { |
| 93 |
dofsPerNodeVector = ExtractVectorFromParameterList<UN>(*froschParameterList,"DofsPerNode Vector"); |
| 94 |
} |
| 95 |
|
| 96 |
if (froschParameterList->isParameter("DofOrdering Vector")) { |
| 97 |
dofOrderings = ExtractVectorFromParameterList<DofOrdering>(*froschParameterList,"DofOrdering Vector"); |
| 98 |
} |
| 99 |
|
| 100 |
if (froschParameterList->isParameter("Main Map Vector")) { |
| 101 |
MainCoarseMapVector = ExtractVectorFromParameterList<RCP<Map<LO,GO,NO> > >(*froschParameterList,"Main Map Vector"); |
| 102 |
} |
| 103 |
if (froschParameterList->isParameter("Dofs Maps Vector")) { |
| 104 |
dofsMapsVec = ExtractVectorFromParameterList<ArrayRCP<RCP<const Map<LO,GO,NO> > >>(*froschParameterList,"Dofs Maps Vector"); |
| 105 |
} |
| 106 |
|
| 107 |
ConstXMultiVectorPtr nodeList = null; |
| 108 |
GOVecPtr dirichletBoundaryDofs = null; |
| 109 |
ConstXMultiVectorPtr nullSpaceBasisVec = null; |
| 110 |
|
| 111 |
TwoLevelPreconditionerPtr twoLevelPreconditioner = rcp(new TwoLevelPreconditioner<SC,LO,GO,NO>(this->K_,froschParameterList)); |
| 112 |
twoLevelPreconditioner->initialize(froschParameterList->get("Dimension",3), |
| 113 |
dofsPerNodeVector[0], |
| 114 |
froschParameterList->get("Overlap",1), |
| 115 |
nullSpaceBasisVec, |
| 116 |
nodeList, |
| 117 |
dofOrderings[0], |
| 118 |
RepeatedMaps[0], |
| 119 |
dofsMapsVec[0], |
| 120 |
dirichletBoundaryDofs); |
| 121 |
|
| 122 |
FROSchPreconditioner_ = twoLevelPreconditioner; |
| 123 |
} else if (!this->ParameterList_->get("Solver","TwoLevelPreconditioner").compare("TwoLevelBlockPreconditioner")) { |
| 124 |
ParameterListPtr froschParameterList = sublist(this->ParameterList_,"FROSchPreconditioner"); |
| 125 |
if (froschParameterList->isSublist(this->ParameterList_->get("Solver","TwoLevelPreconditioner"))) froschParameterList = sublist(froschParameterList,this->ParameterList_->get("Solver","TwoLevelPreconditioner")); |
| 126 |
// if (this->K_->getMap()->getComm()->getRank() == 0) froschParameterList->print(cout); |
| 127 |
|
| 128 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > RepeatedMaps(1); |
| 129 |
UNVecPtr dofsPerNodeVector; |
| 130 |
ConstXMultiVectorPtrVecPtr nullSpaceBasisVec = null; |
| 131 |
ArrayRCP<DofOrdering> dofOrderings = null; |
| 132 |
ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > > dofsMapsVec = null; |
| 133 |
|
| 134 |
FROSCH_ASSERT(froschParameterList->isParameter("Repeated Map Vector"),"FROSch::FROSchPreconditioner: Currently TwoLevelBlockPreconditioner cannot be constructed without Repeated Maps Vector "); |
| 135 |
FROSCH_ASSERT(froschParameterList->isParameter("DofsPerNode Vector"),"FROSch::FROSchPreconditioner: Currently, TwoLevelBlockPreconditioner cannot be constructed without DofsPerNode Vector."); |
| 136 |
FROSCH_ASSERT(froschParameterList->isParameter("DofOrdering Vector"),"FROSch::FROSchPreconditioner: Currently, TwoLevelBlockPreconditioner cannot be constructed without DofOrdering Vector."); |
| 137 |
|
| 138 |
if (froschParameterList->isParameter("Repeated Map Vector")) { |
| 139 |
RepeatedMaps = ExtractVectorFromParameterList<RCP<const Map<LO,GO,NO> > >(*froschParameterList,"Repeated Map Vector"); |
| 140 |
} |
| 141 |
if (froschParameterList->isParameter("DofsPerNode Vector")) { |
| 142 |
dofsPerNodeVector = ExtractVectorFromParameterList<UN>(*froschParameterList,"DofsPerNode Vector"); |
| 143 |
} |
| 144 |
if (froschParameterList->isParameter("DofOrdering Vector")) { |
| 145 |
dofOrderings = ExtractVectorFromParameterList<DofOrdering>(*froschParameterList,"DofOrdering Vector"); |
| 146 |
} |
| 147 |
if (froschParameterList->isParameter("Dofs Maps Vector")) { |
| 148 |
dofsMapsVec = ExtractVectorFromParameterList<ArrayRCP<RCP<const Map<LO,GO,NO> > >>(*froschParameterList,"Dofs Maps Vector"); |
| 149 |
} |
| 150 |
|
| 151 |
FROSCH_ASSERT(RepeatedMaps.size()==dofsPerNodeVector.size(),"FROSch::FROSchPreconditioner: RepeatedMaps.size()!=dofsPerNodeVector.size()"); |
| 152 |
FROSCH_ASSERT(RepeatedMaps.size()==dofOrderings.size(),"FROSch::FROSchPreconditioner: RepeatedMaps.size()!=dofOrderings.size()"); |
| 153 |
TwoLevelBlockPreconditionerPtr twoLevelBlockPreconditioner = rcp(new TwoLevelBlockPreconditioner<SC,LO,GO,NO>(this->K_,froschParameterList)); |
| 154 |
twoLevelBlockPreconditioner->initialize(froschParameterList->get("Dimension",3), |
| 155 |
dofsPerNodeVector, |
| 156 |
dofOrderings, |
| 157 |
froschParameterList->get("Overlap",1), |
| 158 |
RepeatedMaps, |
| 159 |
nullSpaceBasisVec); |
| 160 |
|
| 161 |
FROSchPreconditioner_ = twoLevelBlockPreconditioner; |
| 162 |
} else { |
| 163 |
FROSCH_ASSERT(false,"FROSch::FROSchPreconditioner: Solver unkown."); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
#endif |