43 #ifndef IFPACK2_ADDITIVESCHWARZ_DEF_HPP
44 #define IFPACK2_ADDITIVESCHWARZ_DEF_HPP
46 #include "Ifpack2_AdditiveSchwarz_decl.hpp"
48 #if defined(HAVE_IFPACK2_XPETRA) && defined(HAVE_IFPACK2_ZOLTAN2)
49 #include "Xpetra_RowMatrix.hpp"
50 #include "Xpetra_TpetraRowMatrix.hpp"
51 #include "Zoltan2_XpetraRowMatrixInput.hpp"
52 #include "Zoltan2_OrderingProblem.hpp"
55 #include "Ifpack2_Condest.hpp"
56 #include "Ifpack2_OverlappingRowMatrix_def.hpp"
57 #include "Ifpack2_LocalFilter_def.hpp"
58 #include "Ifpack2_ReorderFilter_def.hpp"
59 #include "Ifpack2_SingletonFilter_def.hpp"
61 #include "Teuchos_DefaultMpiComm.hpp"
67 template<
class MatrixType,
class LocalInverseType>
70 IsInitialized_(false),
72 IsOverlapping_(false),
73 OverlapLevel_(OverlapLevel_in),
74 CombineMode_(Tpetra::ADD),
76 ComputeCondest_(true),
77 UseReordering_(false),
79 FilterSingletons_(false),
89 if (
Matrix_->getComm()->getSize() == 1)
102 template<
class MatrixType,
class LocalInverseType>
109 template<
class MatrixType,
class LocalInverseType>
112 return Matrix_->getDomainMap();
117 template<
class MatrixType,
class LocalInverseType>
120 return Matrix_->getRangeMap();
124 template<
class MatrixType,
class LocalInverseType>
132 template<
class MatrixType,
class LocalInverseType>
134 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
143 typedef typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MultiVectorType;
146 "Ifpack2::AdditiveSchwarz::apply ERROR: isComputed() must be true prior to calling apply.");
149 "Ifpack2::AdditiveSchwarz::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
151 size_t NumVectors = X.getNumVectors();
159 OverlappingX =
Teuchos::rcp(
new MultiVectorType(OverlappingMatrix_->getRowMap(), X.getNumVectors()) );
160 OverlappingY =
Teuchos::rcp(
new MultiVectorType(OverlappingMatrix_->getRowMap(), X.getNumVectors()) );
161 OverlappingY->putScalar(0.0);
162 OverlappingX->putScalar(0.0);
163 OverlappingMatrix_->importMultiVector(X,*OverlappingX,Tpetra::INSERT);
172 if (FilterSingletons_) {
174 MultiVectorType ReducedX(SingletonMatrix_->getRowMap(),NumVectors);
175 MultiVectorType ReducedY(SingletonMatrix_->getRowMap(),NumVectors);
176 SingletonMatrix_->SolveSingletons(*OverlappingX,*OverlappingY);
177 SingletonMatrix_->CreateReducedRHS(*OverlappingY,*OverlappingX,ReducedX);
180 if (!UseReordering_) {
181 Inverse_->apply(ReducedX,ReducedY);
184 MultiVectorType ReorderedX(ReducedX);
185 MultiVectorType ReorderedY(ReducedY);
186 ReorderedLocalizedMatrix_->permuteOriginalToReordered(ReducedX,ReorderedX);
187 Inverse_->apply(ReorderedX,ReorderedY);
188 ReorderedLocalizedMatrix_->permuteReorderedToOriginal(ReorderedY,ReducedY);
192 SingletonMatrix_->UpdateLHS(ReducedY,*OverlappingY);
197 if (!UseReordering_) {
198 Inverse_->apply(*OverlappingX,*OverlappingY);
201 MultiVectorType ReorderedX(*OverlappingX);
202 MultiVectorType ReorderedY(*OverlappingY);
203 ReorderedLocalizedMatrix_->permuteOriginalToReordered(*OverlappingX,ReorderedX);
204 Inverse_->apply(ReorderedX,ReorderedY);
205 ReorderedLocalizedMatrix_->permuteReorderedToOriginal(ReorderedY,*OverlappingY);
210 OverlappingMatrix_->exportMultiVector(*OverlappingY,Y,CombineMode_);
213 ApplyTime_ += Time_->stop();
218 template<
class MatrixType,
class LocalInverseType>
219 template<
class DomainScalar,
class RangeScalar>
221 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
224 RangeScalar beta)
const
226 typedef typename Tpetra::MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node> DomainMultiVectorType;
227 typedef typename Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> RangeMultiVectorType;
230 "Ifpack2::AdditiveSchwarz::apply ERROR: isComputed() must be true prior to calling apply.");
233 "Ifpack2::AdditiveSchwarz::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
235 size_t NumVectors = X.getNumVectors();
244 OverlappingX =
Teuchos::rcp(
new DomainMultiVectorType(OverlappingMatrix_->getRowMap(), X.getNumVectors()) );
245 OverlappingY =
Teuchos::rcp(
new RangeMultiVectorType(OverlappingMatrix_->getRowMap(), X.getNumVectors()) );
246 OverlappingY->putScalar(0.0);
247 OverlappingX->putScalar(0.0);
248 OverlappingMatrix_->template importMultiVectorTempl<DomainScalar>(X,*OverlappingX,Tpetra::INSERT);
257 if (FilterSingletons_) {
259 DomainMultiVectorType ReducedX(SingletonMatrix_->getRowMap(),NumVectors);
260 RangeMultiVectorType ReducedY(SingletonMatrix_->getRowMap(),NumVectors);
261 SingletonMatrix_->template SolveSingletonsTempl<DomainScalar,RangeScalar>(*OverlappingX,*OverlappingY);
262 SingletonMatrix_->template CreateReducedRHSTempl<RangeScalar,DomainScalar>(*OverlappingY,*OverlappingX,ReducedX);
265 if (!UseReordering_) {
266 Inverse_->template applyTempl<DomainScalar,RangeScalar>(ReducedX,ReducedY);
269 DomainMultiVectorType ReorderedX(ReducedX);
270 RangeMultiVectorType ReorderedY(ReducedY);
271 ReorderedLocalizedMatrix_->template permuteOriginalToReorderedTempl<DomainScalar,DomainScalar>(ReducedX,ReorderedX);
272 Inverse_->template applyTempl<DomainScalar,RangeScalar>(ReorderedX,ReorderedY);
273 ReorderedLocalizedMatrix_->template permuteReorderedToOriginalTempl<RangeScalar,RangeScalar>(ReorderedY,ReducedY);
277 SingletonMatrix_->template UpdateLHSTempl<RangeScalar,RangeScalar>(ReducedY,*OverlappingY);
282 if (!UseReordering_) {
283 Inverse_->template applyTempl<DomainScalar,RangeScalar>(*OverlappingX,*OverlappingY);
286 DomainMultiVectorType ReorderedX(*OverlappingX);
287 RangeMultiVectorType ReorderedY(*OverlappingY);
288 ReorderedLocalizedMatrix_->template permuteOriginalToReorderedTempl<DomainScalar,DomainScalar>(*OverlappingX,ReorderedX);
289 Inverse_->template applyTempl<DomainScalar,RangeScalar>(ReorderedX,ReorderedY);
290 ReorderedLocalizedMatrix_->template permuteReorderedToOriginalTempl<RangeScalar,RangeScalar>(ReorderedY,*OverlappingY);
295 OverlappingMatrix_->template exportMultiVectorTempl<RangeScalar>(*OverlappingY,Y,CombineMode_);
298 ApplyTime_ += Time_->stop();
303 template<
class MatrixType,
class LocalInverseType>
309 ComputeCondest_ = List_.
get(
"schwarz: compute condest", ComputeCondest_);
312 if(
typeid(std::string) == combineModeEntry->getAny().type() ) {
313 std::string mode = List_.get(
"schwarz: combine mode",
"Add");
315 CombineMode_ = Tpetra::ADD;
316 else if (mode ==
"Insert")
317 CombineMode_ = Tpetra::INSERT;
318 else if (mode ==
"Replace")
319 CombineMode_ = Tpetra::REPLACE;
320 else if (mode ==
"AbsMax")
321 CombineMode_ = Tpetra::ABSMAX;
324 ,
"Error, The Tpetra combine mode of \""<<mode<<
"\" is not valid! Only the values"
325 " \"Add\", \"Insert\", \"Replace\", and \"AbsMax\" are accepted!"
329 else if (
typeid(Tpetra::CombineMode) == combineModeEntry->getAny().type() ) {
330 CombineMode_ = Teuchos::any_cast<Tpetra::CombineMode>(combineModeEntry->getAny());
334 Teuchos::getParameter<std::string>(List_,
"schwarz: combine mode");
339 List_.get(
"schwarz: combine mode",
"Add");
343 if(OverlapLevel_>0) {
349 UseReordering_ = List_.get(
"schwarz: use reordering",
false);
351 #if !defined(HAVE_IFPACK2_XPETRA) || !defined(HAVE_IFPACK2_ZOLTAN2)
353 UseReordering_=
false;
357 if (List_.isParameter(
"schwarz: subdomain id") && List_.get(
"schwarz: subdomain id",-1) > 0)
364 FilterSingletons_ = List_.get(
"schwarz: filter singletons", FilterSingletons_);
370 template<
class MatrixType,
class LocalInverseType>
373 IsInitialized_ =
false;
377 if (Time_ == Teuchos::null)
383 if (IsOverlapping_) {
385 int sid = List_.get(
"subdomain id",-1);
392 "Ifpack2::AdditiveSchwarz::initialize ERROR: OverlappingRowMatrix constructor failed.");
400 "Ifpack2::AdditiveSchwarz::initialize ERROR: Setup() failed.");
403 Inverse_->setParameters(List_);
404 Inverse_->initialize();
406 IsInitialized_ =
true;
408 InitializeTime_ += Time_->stop();
413 template<
class MatrixType,
class LocalInverseType>
416 return IsInitialized_;
421 template<
class MatrixType,
class LocalInverseType>
424 if (!IsInitialized_) initialize();
434 ComputeTime_ += Time_->stop();
440 template<
class MatrixType,
class LocalInverseType>
448 template<
class MatrixType,
class LocalInverseType>
451 LocalOrdinal MaxIters,
453 const Teuchos::Ptr<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &Matrix_in)
459 Condest_ = Ifpack2::Condest(*
this, CT, MaxIters, Tol, Matrix_in);
466 template<
class MatrixType,
class LocalInverseType>
475 template<
class MatrixType,
class LocalInverseType>
478 return NumInitialize_;
483 template<
class MatrixType,
class LocalInverseType>
491 template<
class MatrixType,
class LocalInverseType>
499 template<
class MatrixType,
class LocalInverseType>
502 return InitializeTime_;
507 template<
class MatrixType,
class LocalInverseType>
515 template<
class MatrixType,
class LocalInverseType>
522 template<
class MatrixType,
class LocalInverseType>
525 std::ostringstream oss;
527 if (isInitialized()) {
529 oss <<
"{status = initialized, computed";
532 oss <<
"{status = initialized, not computed";
536 oss <<
"{status = not initialized, not computed";
538 oss<<
"overlap level ="<<OverlapLevel_;
545 template<
class MatrixType,
class LocalInverseType>
551 os <<
"================================================================================" << endl;
552 os <<
"Ifpack2::AdditiveSchwarz, overlap level = " << OverlapLevel_ << endl;
553 if (CombineMode_ == Tpetra::INSERT)
554 os <<
"Combine mode = Insert" << endl;
555 else if (CombineMode_ == Tpetra::ADD)
556 os <<
"Combine mode = Add" << endl;
557 else if (CombineMode_ == Tpetra::REPLACE)
558 os <<
"Combine mode = Replace" << endl;
559 else if (CombineMode_ == Tpetra::ABSMAX)
560 os <<
"Combine mode = AbsMax" << endl;
562 os <<
"Condition number estimate = " << Condest_ << endl;
563 os <<
"Global number of rows = " << Matrix_->getGlobalNumRows() << endl;
566 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
567 os <<
"----- ------- -------------- ------------ --------" << endl;
568 os <<
"Initialize() " << std::setw(5) << getNumInitialize()
569 <<
" " << std::setw(15) << getInitializeTime() << endl;
570 os <<
"Compute() " << std::setw(5) << getNumCompute()
571 <<
" " << std::setw(15) << getComputeTime() << endl;
572 os <<
"Apply() " << std::setw(5) << getNumApply()
573 <<
" " << std::setw(15) << getApplyTime() <<endl;
574 os <<
"================================================================================" << endl;
580 template<
class MatrixType,
class LocalInverseType>
591 template<
class MatrixType,
class LocalInverseType>
594 return OverlapLevel_;
599 template<
class MatrixType,
class LocalInverseType>
602 #if defined(HAVE_IFPACK2_XPETRA) && defined(HAVE_IFPACK2_ZOLTAN2)
603 typedef typename Xpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpetraMatrixType;
604 typedef typename Xpetra::TpetraRowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpetraTpetraMatrixType;
610 if (OverlappingMatrix_ != Teuchos::null) {
613 throw std::runtime_error(
"Ifpack2::AdditiveSchwarz subdomain code not yet supported.");
623 throw std::runtime_error(
"Ifpack2::AdditiveSchwarz subdomain code not yet supported.");
630 ActiveMatrix = LocalizedMatrix_;
632 "Ifpack2::AdditiveSchwarz::Setup() ERROR: LocalFilter failed.");
635 if (FilterSingletons_) {
637 ActiveMatrix = SingletonMatrix_;
642 if (UseReordering_) {
643 #if defined(HAVE_IFPACK2_XPETRA) && defined(HAVE_IFPACK2_ZOLTAN2)
646 XpetraTpetraMatrixType XpetraMatrix(ActiveMatrix);
647 Zoltan2::XpetraRowMatrixInput<XpetraMatrixType> Zoltan2Matrix(Teuchos::rcp<XpetraMatrixType>(&XpetraMatrix,
false));
654 if(mpicomm == Teuchos::null) mycomm = MPI_COMM_SELF;
655 else mycomm = *(mpicomm->getRawMpiComm());
656 Zoltan2::OrderingProblem<Zoltan2::XpetraRowMatrixInput<XpetraMatrixType> > MyOrderingProblem(&Zoltan2Matrix, &zlist,mycomm);
658 Zoltan2::OrderingProblem<Zoltan2::XpetraRowMatrixInput<XpetraMatrixType> > MyOrderingProblem(&Zoltan2Matrix, &zlist);
660 MyOrderingProblem.solve();
665 ActiveMatrix = ReorderedLocalizedMatrix_;
667 throw std::runtime_error(
"Ifpack2::AdditiveSchwarz::Setup() You need to compile with Zoltan2 to support reordering.");
672 Inverse_ =
Teuchos::rcp(
new LocalInverseType(ActiveMatrix));
674 "Ifpack2::AdditiveSchwarz::Setup() ERROR: Inverse constructor failed.");
680 #endif // IFPACK2_ADDITIVESCHWARZ_DECL_HPP
void applyTempl(const Tpetra::MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, RangeScalar alpha=Teuchos::ScalarTraits< Scalar >::one(), RangeScalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Applies the effect of the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:220
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
Ifpack2::ReorderFilter: a class for light-weight reorder of local rows and columns of an Tpetra::RowM...
Definition: Ifpack2_ReorderFilter_decl.hpp:82
virtual void compute()
Computes all (coefficient) data necessary to apply the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:422
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the Map associated with the domain of this operator, which must be compatible with X...
Definition: Ifpack2_AdditiveSchwarz_def.hpp:110
virtual int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:492
void setup()
Sets up the localized matrix and the singleton filter.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:600
T & get(const std::string &name, T def_value)
virtual bool isInitialized() const
Returns true if the preconditioner has been successfully initialized, false otherwise.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:414
virtual double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:500
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:546
virtual void setParameters(const Teuchos::ParameterList &List)
Sets all parameters for the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:304
void getParameter(const Teuchos::ParameterList ¶ms, const std::string &name, T &value)
Set a value from a ParameterList if a parameter with the specified name exists.
Definition: Ifpack2_Parameters.hpp:59
virtual magnitudeType computeCondEst(CondestType CT=Ifpack2::Cheap, LocalOrdinal MaxIters=1550, magnitudeType Tol=1e-9, const Teuchos::Ptr< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix=Teuchos::null)
Computes the condition number estimate and returns its value.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:450
virtual double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:508
const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Matrix_
Pointers to the matrix to be preconditioned.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:258
virtual ~AdditiveSchwarz()
Destructor.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:103
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:523
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:581
virtual double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:516
virtual void initialize()
Computes all (graph-related) data necessary to initialize the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:371
virtual magnitudeType getCondEst() const
Returns the computed condition number estimate, or -1.0 if not computed.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:468
AdditiveSchwarz(const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix_in, int OverlapLevel_in=0)
Ifpack2::AdditiveSchwarz constructor with given Tpetra::RowMatrix.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:68
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::string description() const
virtual Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getMatrix() const
Returns a pointer to the input matrix.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:125
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
bool IsOverlapping_
If true, overlapping is used.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:274
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
Definition: Ifpack2_AdditiveSchwarz_def.hpp:118
int OverlapLevel_
Level of overlap among the processors.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:276
virtual int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:484
Ifpack2::OverlappingRowMatrix: matrix with ghost rows, based on Tpetra::RowMatrix.
Definition: Ifpack2_OverlappingRowMatrix_decl.hpp:60
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual bool isComputed() const
Returns true if the preconditioner has been successfully computed, false otherwise.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:441
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:100
Ifpack2_SingletonFilter: Filter based on matrix entries.
Definition: Ifpack2_SingletonFilter_decl.hpp:58
virtual int getOverlapLevel() const
Returns the level of overlap.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:592
virtual void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Applies the effect of the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:133
virtual int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:476