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)
96 Teuchos::ParameterList List_in;
102 template<
class MatrixType,
class LocalInverseType>
109 template<
class MatrixType,
class LocalInverseType>
112 return Matrix_->getDomainMap();
117 template<
class MatrixType,
class LocalInverseType>
124 template<
class MatrixType,
class LocalInverseType>
132 template<
class MatrixType,
class LocalInverseType>
134 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
135 Teuchos::ETransp mode,
143 typedef typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MultiVectorType;
145 TEUCHOS_TEST_FOR_EXCEPTION(
IsComputed_ ==
false, std::runtime_error,
146 "Ifpack2::AdditiveSchwarz::apply ERROR: isComputed() must be true prior to calling apply.");
148 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
149 "Ifpack2::AdditiveSchwarz::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
151 size_t NumVectors = X.getNumVectors();
155 Teuchos::RCP<MultiVectorType> OverlappingX,OverlappingY,Xtmp;
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);
167 Xtmp=Teuchos::rcp(
new MultiVectorType(X));
169 OverlappingY=Teuchos::rcp(&Y,
false);
184 MultiVectorType ReorderedX(ReducedX);
185 MultiVectorType ReorderedY(ReducedY);
187 Inverse_->apply(ReorderedX,ReorderedY);
198 Inverse_->apply(*OverlappingX,*OverlappingY);
201 MultiVectorType ReorderedX(*OverlappingX);
202 MultiVectorType ReorderedY(*OverlappingY);
204 Inverse_->apply(ReorderedX,ReorderedY);
218 template<
class MatrixType,
class LocalInverseType>
219 template<
class DomainScalar,
class RangeScalar>
221 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
222 Teuchos::ETransp mode,
224 RangeScalar beta)
const 226 typedef typename Tpetra::MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node> DomainMultiVectorType;
227 typedef typename Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> RangeMultiVectorType;
229 TEUCHOS_TEST_FOR_EXCEPTION(
IsComputed_ ==
false, std::runtime_error,
230 "Ifpack2::AdditiveSchwarz::apply ERROR: isComputed() must be true prior to calling apply.");
232 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
233 "Ifpack2::AdditiveSchwarz::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
235 size_t NumVectors = X.getNumVectors();
239 Teuchos::RCP<DomainMultiVectorType> OverlappingX,Xtmp;
240 Teuchos::RCP<RangeMultiVectorType> OverlappingY;
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);
252 Xtmp=Teuchos::rcp(
new DomainMultiVectorType(X));
254 OverlappingY=Teuchos::rcp(&Y,
false);
261 SingletonMatrix_->template SolveSingletonsTempl<DomainScalar,RangeScalar>(*OverlappingX,*OverlappingY);
262 SingletonMatrix_->template CreateReducedRHSTempl<RangeScalar,DomainScalar>(*OverlappingY,*OverlappingX,ReducedX);
266 Inverse_->template applyTempl<DomainScalar,RangeScalar>(ReducedX,ReducedY);
269 DomainMultiVectorType ReorderedX(ReducedX);
270 RangeMultiVectorType ReorderedY(ReducedY);
272 Inverse_->template applyTempl<DomainScalar,RangeScalar>(ReorderedX,ReorderedY);
277 SingletonMatrix_->template UpdateLHSTempl<RangeScalar,RangeScalar>(ReducedY,*OverlappingY);
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);
303 template<
class MatrixType,
class LocalInverseType>
311 if( Teuchos::ParameterEntry *combineModeEntry =
List_.getEntryPtr(
"schwarz: combine mode") ) {
312 if(
typeid(std::string) == combineModeEntry->getAny().type() ) {
313 std::string mode =
List_.get(
"schwarz: combine mode",
"Add");
316 else if (mode ==
"Insert")
318 else if (mode ==
"Replace")
320 else if (mode ==
"AbsMax")
323 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error
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");
351 #if !defined(HAVE_IFPACK2_XPETRA) || !defined(HAVE_IFPACK2_ZOLTAN2) 357 if (
List_.isParameter(
"schwarz: subdomain id") &&
List_.get(
"schwarz: subdomain id",-1) > 0)
370 template<
class MatrixType,
class LocalInverseType>
377 if (
Time_ == Teuchos::null)
378 Time_ = Teuchos::rcp(
new Teuchos::Time(
"Ifpack2::AdditiveSchwarz"));
385 int sid =
List_.get(
"subdomain id",-1);
392 "Ifpack2::AdditiveSchwarz::initialize ERROR: OverlappingRowMatrix constructor failed.");
399 TEUCHOS_TEST_FOR_EXCEPTION(
Inverse_ == Teuchos::null, std::runtime_error,
400 "Ifpack2::AdditiveSchwarz::initialize ERROR: Setup() failed.");
413 template<
class MatrixType,
class LocalInverseType>
421 template<
class MatrixType,
class LocalInverseType>
440 template<
class MatrixType,
class LocalInverseType>
448 template<
class MatrixType,
class LocalInverseType>
449 typename Teuchos::ScalarTraits<typename MatrixType::scalar_type>::magnitudeType
451 LocalOrdinal MaxIters,
453 const Teuchos::Ptr<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &Matrix_in)
457 if (!
isComputed())
return (-Teuchos::ScalarTraits<magnitudeType>::one());
459 Condest_ = Ifpack2::Condest(*
this, CT, MaxIters, Tol, Matrix_in);
466 template<
class MatrixType,
class LocalInverseType>
467 typename Teuchos::ScalarTraits<typename MatrixType::scalar_type>::magnitudeType
475 template<
class MatrixType,
class LocalInverseType>
483 template<
class MatrixType,
class LocalInverseType>
491 template<
class MatrixType,
class LocalInverseType>
499 template<
class MatrixType,
class LocalInverseType>
507 template<
class MatrixType,
class LocalInverseType>
515 template<
class MatrixType,
class LocalInverseType>
522 template<
class MatrixType,
class LocalInverseType>
525 std::ostringstream oss;
526 oss << Teuchos::Describable::description();
529 oss <<
"{status = initialized, computed";
532 oss <<
"{status = initialized, not computed";
536 oss <<
"{status = not initialized, not computed";
545 template<
class MatrixType,
class LocalInverseType>
551 os <<
"================================================================================" << endl;
552 os <<
"Ifpack2::AdditiveSchwarz, overlap level = " <<
OverlapLevel_ << endl;
554 os <<
"Combine mode = Insert" << endl;
556 os <<
"Combine mode = Add" << endl;
558 os <<
"Combine mode = Replace" << endl;
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;
574 os <<
"================================================================================" << endl;
580 template<
class MatrixType,
class LocalInverseType>
583 Teuchos::FancyOStream fos(Teuchos::rcp(&os,
false));
584 fos.setOutputToRootOnly(0);
591 template<
class MatrixType,
class LocalInverseType>
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;
607 Teuchos::RCP<LocalMatrixType> ActiveMatrix;
613 throw std::runtime_error(
"Ifpack2::AdditiveSchwarz subdomain code not yet supported.");
623 throw std::runtime_error(
"Ifpack2::AdditiveSchwarz subdomain code not yet supported.");
631 TEUCHOS_TEST_FOR_EXCEPTION(
LocalizedMatrix_ == Teuchos::null, std::runtime_error,
632 "Ifpack2::AdditiveSchwarz::Setup() ERROR: LocalFilter failed.");
643 #if defined(HAVE_IFPACK2_XPETRA) && defined(HAVE_IFPACK2_ZOLTAN2) 645 Teuchos::ParameterList zlist =
List_.sublist(
"schwarz: reordering list");
646 XpetraTpetraMatrixType XpetraMatrix(ActiveMatrix);
647 Zoltan2::XpetraRowMatrixInput<XpetraMatrixType> Zoltan2Matrix(Teuchos::rcp<XpetraMatrixType>(&XpetraMatrix,
false));
653 Teuchos::RCP<const Teuchos::MpiComm<int> > mpicomm = rcp_dynamic_cast<
const Teuchos::MpiComm<int> >(ActiveMatrix->getComm());
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();
667 throw std::runtime_error(
"Ifpack2::AdditiveSchwarz::Setup() You need to compile with Zoltan2 to support reordering.");
672 Inverse_ = Teuchos::rcp(
new LocalInverseType(ActiveMatrix));
673 TEUCHOS_TEST_FOR_EXCEPTION(
Inverse_ == Teuchos::null, std::runtime_error,
674 "Ifpack2::AdditiveSchwarz::Setup() ERROR: Inverse constructor failed.");
680 #endif // IFPACK2_ADDITIVESCHWARZ_DECL_HPP int NumInitialize_
Contains the number of successful calls to Initialize().
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:295
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
double ComputeTime_
Contains the time for all successful calls to compute().
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:303
Tpetra::CombineMode CombineMode_
Combine mode for off-process elements (only if overlap is used)
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:280
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
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
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
Teuchos::RCP< Ifpack2::OverlappingRowMatrix< LocalMatrixType > > OverlappingMatrix_
Pointers to the overlapping matrix.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:261
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
double InitializeTime_
Contains the time for all successful calls to initialize().
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:301
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
bool IsComputed_
If true, the preconditioner has been successfully computed.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:272
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::RCP< Teuchos::Time > Time_
Object used for timing purposes.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:313
Teuchos::RCP< Ifpack2::SingletonFilter< LocalMatrixType > > SingletonMatrix_
filtering object.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:293
bool ComputeCondest_
If true, compute the condition number estimate each time Compute() is called.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:284
bool FilterSingletons_
Filter for singletons.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:291
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
int NumApply_
Contains the number of successful call to apply().
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:299
double ApplyTime_
Contains the time for all successful calls to apply().
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:305
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
bool IsInitialized_
If true, the preconditioner has been successfully initialized.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:270
bool UseSubdomain_
If true, subdomain filtering is used.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:288
Teuchos::RCP< Ifpack2::ReorderFilter< LocalMatrixType > > ReorderedLocalizedMatrix_
Pointer to the reordered matrix.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:267
bool UseReordering_
If true, reorder the local matrix.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:286
int NumCompute_
Contains the number of successful call to Compute().
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:297
Teuchos::RCP< LocalInverseType > Inverse_
Pointer to the local solver.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:315
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
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
Teuchos::RCP< LocalMatrixType > LocalizedMatrix_
Localized version of Matrix_ or OverlappingMatrix_.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:265
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
Ifpack2_SingletonFilter: Filter based on matrix entries.
Definition: Ifpack2_SingletonFilter_decl.hpp:58
magnitudeType Condest_
Contains the estimated condition number.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:282
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
Teuchos::ParameterList List_
Stores a copy of the list given in SetParameters()
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:278