Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_AdditiveSchwarz_def.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_ADDITIVESCHWARZ_DEF_HPP
44 #define IFPACK2_ADDITIVESCHWARZ_DEF_HPP
45 
46 #include "Ifpack2_AdditiveSchwarz_decl.hpp"
47 
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"
53 #endif
54 
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"
60 #ifdef HAVE_MPI
61 #include "Teuchos_DefaultMpiComm.hpp"
62 #endif
63 
64 namespace Ifpack2 {
65 
66 //==============================================================================
67 template<class MatrixType,class LocalInverseType>
68 AdditiveSchwarz<MatrixType,LocalInverseType>::AdditiveSchwarz(const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > & Matrix_in, int OverlapLevel_in):
69  Matrix_(Matrix_in),
70  IsInitialized_(false),
71  IsComputed_(false),
72  IsOverlapping_(false),
73  OverlapLevel_(OverlapLevel_in),
74  CombineMode_(Tpetra::ADD),
75  Condest_(-1.0),
76  ComputeCondest_(true),
77  UseReordering_(false),
78  UseSubdomain_(false),
79  FilterSingletons_(false),
80  NumInitialize_(0),
81  NumCompute_(0),
82  NumApply_(0),
83  InitializeTime_(0.0),
84  ComputeTime_(0.0),
85  ApplyTime_(0.0)
86 {
87 
88  // Reset Overlap parameters
89  if (Matrix_->getComm()->getSize() == 1)
90  OverlapLevel_ = 0;
91 
92  if ((OverlapLevel_ != 0) && (Matrix_->getComm()->getSize() > 1))
93  IsOverlapping_ = true;
94 
95  // Sets parameters to default values
96  Teuchos::ParameterList List_in;
97  setParameters(List_in);
98 }
99 
100 //==============================================================================
101 // Destructor
102 template<class MatrixType,class LocalInverseType>
104 {
105 }
106 
107 //==============================================================================
108 // Returns the Map associated with the domain of this operator, which must be compatible with X.getMap().
109 template<class MatrixType,class LocalInverseType>
111 {
112  return Matrix_->getDomainMap();
113 }
114 
115 //==============================================================================
116 // Returns the Map associated with the range of this operator, which must be compatible with Y.getMap().
117 template<class MatrixType,class LocalInverseType>
119 {
120  return Matrix_->getRangeMap();
121 }
122 
123 //==============================================================================
124 template<class MatrixType,class LocalInverseType>
126 {
127  return Matrix_;
128 }
129 
130 //==============================================================================
131 // Applies the effect of the preconditione.
132 template<class MatrixType,class LocalInverseType>
133 void AdditiveSchwarz<MatrixType,LocalInverseType>::apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &X,
134  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
135  Teuchos::ETransp mode,
136  Scalar alpha,
137  Scalar beta) const
138 {
139  // This method will not just call applyTempl() for now because that method relies on the underlying
140  // LocalInverseType having a templated applyTempl() method implemented. Currently applyTempl() methods
141  // are only implemented for ILUT and Diagonal.
142 
143  typedef typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MultiVectorType;
144 
145  TEUCHOS_TEST_FOR_EXCEPTION(IsComputed_ == false, std::runtime_error,
146  "Ifpack2::AdditiveSchwarz::apply ERROR: isComputed() must be true prior to calling apply.");
147 
148  TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
149  "Ifpack2::AdditiveSchwarz::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
150 
151  size_t NumVectors = X.getNumVectors();
152 
153  Time_->start();
154 
155  Teuchos::RCP<MultiVectorType> OverlappingX,OverlappingY,Xtmp;
156 
157  if(IsOverlapping_){
158  // Setup if we're overlapping
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);
164  // FIXME from Ifpack1: Will not work with non-zero starting solutions.
165  }
166  else{
167  Xtmp=Teuchos::rcp(new MultiVectorType(X));
168  OverlappingX=Xtmp;
169  OverlappingY=Teuchos::rcp(&Y,false);
170  }
171 
172  if (FilterSingletons_) {
173  // process singleton filter
174  MultiVectorType ReducedX(SingletonMatrix_->getRowMap(),NumVectors);
175  MultiVectorType ReducedY(SingletonMatrix_->getRowMap(),NumVectors);
176  SingletonMatrix_->SolveSingletons(*OverlappingX,*OverlappingY);
177  SingletonMatrix_->CreateReducedRHS(*OverlappingY,*OverlappingX,ReducedX);
178 
179  // process reordering
180  if (!UseReordering_) {
181  Inverse_->apply(ReducedX,ReducedY);
182  }
183  else {
184  MultiVectorType ReorderedX(ReducedX);
185  MultiVectorType ReorderedY(ReducedY);
186  ReorderedLocalizedMatrix_->permuteOriginalToReordered(ReducedX,ReorderedX);
187  Inverse_->apply(ReorderedX,ReorderedY);
188  ReorderedLocalizedMatrix_->permuteReorderedToOriginal(ReorderedY,ReducedY);
189  }
190 
191  // finish up with singletons
192  SingletonMatrix_->UpdateLHS(ReducedY,*OverlappingY);
193  }
194  else {
195 
196  // process reordering
197  if (!UseReordering_) {
198  Inverse_->apply(*OverlappingX,*OverlappingY);
199  }
200  else {
201  MultiVectorType ReorderedX(*OverlappingX);
202  MultiVectorType ReorderedY(*OverlappingY);
203  ReorderedLocalizedMatrix_->permuteOriginalToReordered(*OverlappingX,ReorderedX);
204  Inverse_->apply(ReorderedX,ReorderedY);
205  ReorderedLocalizedMatrix_->permuteReorderedToOriginal(ReorderedY,*OverlappingY);
206  }
207  }
208 
209  if(IsOverlapping_)
210  OverlappingMatrix_->exportMultiVector(*OverlappingY,Y,CombineMode_);
211 
212  NumApply_++;
213  ApplyTime_ += Time_->stop();
214 }
215 
216 //==============================================================================
217 // Applies the effect of the preconditione.
218 template<class MatrixType,class LocalInverseType>
219 template<class DomainScalar, class RangeScalar>
220 void AdditiveSchwarz<MatrixType,LocalInverseType>::applyTempl(const Tpetra::MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node> &X,
221  Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
222  Teuchos::ETransp mode,
223  RangeScalar alpha,
224  RangeScalar beta) const
225 {
226  typedef typename Tpetra::MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node> DomainMultiVectorType;
227  typedef typename Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> RangeMultiVectorType;
228 
229  TEUCHOS_TEST_FOR_EXCEPTION(IsComputed_ == false, std::runtime_error,
230  "Ifpack2::AdditiveSchwarz::apply ERROR: isComputed() must be true prior to calling apply.");
231 
232  TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
233  "Ifpack2::AdditiveSchwarz::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
234 
235  size_t NumVectors = X.getNumVectors();
236 
237  Time_->start();
238 
239  Teuchos::RCP<DomainMultiVectorType> OverlappingX,Xtmp;
241 
242  if(IsOverlapping_){
243  // Setup if we're overlapping
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);
249  // FIXME from Ifpack1: Will not work with non-zero starting solutions.
250  }
251  else{
252  Xtmp=Teuchos::rcp(new DomainMultiVectorType(X));
253  OverlappingX=Xtmp;
254  OverlappingY=Teuchos::rcp(&Y,false);
255  }
256 
257  if (FilterSingletons_) {
258  // process singleton filter
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);
263 
264  // process reordering
265  if (!UseReordering_) {
266  Inverse_->template applyTempl<DomainScalar,RangeScalar>(ReducedX,ReducedY);
267  }
268  else {
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);
274  }
275 
276  // finish up with singletons
277  SingletonMatrix_->template UpdateLHSTempl<RangeScalar,RangeScalar>(ReducedY,*OverlappingY);
278  }
279  else {
280 
281  // process reordering
282  if (!UseReordering_) {
283  Inverse_->template applyTempl<DomainScalar,RangeScalar>(*OverlappingX,*OverlappingY);
284  }
285  else {
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);
291  }
292  }
293 
294  if(IsOverlapping_)
295  OverlappingMatrix_->template exportMultiVectorTempl<RangeScalar>(*OverlappingY,Y,CombineMode_);
296 
297  NumApply_++;
298  ApplyTime_ += Time_->stop();
299 }
300 
301 //==============================================================================
302 // Sets all parameters for the preconditioner.
303 template<class MatrixType,class LocalInverseType>
305 {
306  List_=List_in;
307 
308  // compute the condition number each time compute() is invoked.
309  ComputeCondest_ = List_.get("schwarz: compute condest", ComputeCondest_);
310  // combine mode
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");
314  if (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;
322  else {
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!"
326  );
327  }
328  }
329  else if ( typeid(Tpetra::CombineMode) == combineModeEntry->getAny().type() ) {
330  CombineMode_ = Teuchos::any_cast<Tpetra::CombineMode>(combineModeEntry->getAny());
331  }
332  else {
333  // Throw exception with good error message!
334  Teuchos::getParameter<std::string>(List_,"schwarz: combine mode");
335  }
336  }
337  else {
338  // Make the default be a string to be consistent with the valid parameters!
339  List_.get("schwarz: combine mode","Add");
340  }
341 
342  Ifpack2::getParameter(List_, "schwarz: overlap level",OverlapLevel_);
343  if(OverlapLevel_>0) {
344  IsOverlapping_=true;
345  }
346 
347  // Will we be doing reordering?
348  // Note: Unlike Ifpack we'll use a "schwarz: reordering list" to give to Zoltan2...
349  UseReordering_ = List_.get("schwarz: use reordering",false);
350 
351 #if !defined(HAVE_IFPACK2_XPETRA) || !defined(HAVE_IFPACK2_ZOLTAN2)
352  // If we don't have Zoltan2, we just turn the reordering off completely...
353  UseReordering_=false;
354 #endif
355 
356  // Subdomain check
357  if (List_.isParameter("schwarz: subdomain id") && List_.get("schwarz: subdomain id",-1) > 0)
358  UseSubdomain_=true;
359 
360  // if true, filter singletons. NOTE: the filtered matrix can still have
361  // singletons! A simple example: upper triangular matrix, if I remove
362  // the lower node, I still get a matrix with a singleton! However, filter
363  // singletons should help for PDE problems with Dirichlet BCs.
364  FilterSingletons_ = List_.get("schwarz: filter singletons", FilterSingletons_);
365 }
366 
367 
368 //==============================================================================
369 // Computes all (graph-related) data necessary to initialize the preconditioner.
370 template<class MatrixType,class LocalInverseType>
372 {
373  IsInitialized_ = false;
374  IsComputed_ = false; // values required
375  Condest_ = -1.0; // zero-out condest
376 
377  if (Time_ == Teuchos::null)
378  Time_ = Teuchos::rcp( new Teuchos::Time("Ifpack2::AdditiveSchwarz"));
379 
380  Time_->start();
381 
382  // compute the overlapping matrix if necessary
383  if (IsOverlapping_) {
384  if(UseSubdomain_) {
385  int sid = List_.get("subdomain id",-1);
386  OverlappingMatrix_ = Teuchos::rcp( new Ifpack2::OverlappingRowMatrix<LocalMatrixType>(Matrix_, OverlapLevel_, sid) );
387  }
388  else
389  OverlappingMatrix_ = Teuchos::rcp( new Ifpack2::OverlappingRowMatrix<LocalMatrixType>(Matrix_, OverlapLevel_) );
390 
391  TEUCHOS_TEST_FOR_EXCEPTION(OverlappingMatrix_ == Teuchos::null, std::runtime_error,
392  "Ifpack2::AdditiveSchwarz::initialize ERROR: OverlappingRowMatrix constructor failed.");
393  }
394 
395  // Setup
396  setup();
397 
398  // Sanity Checks
399  TEUCHOS_TEST_FOR_EXCEPTION(Inverse_ == Teuchos::null, std::runtime_error,
400  "Ifpack2::AdditiveSchwarz::initialize ERROR: Setup() failed.");
401 
402  // Initialize inverse
403  Inverse_->setParameters(List_);
404  Inverse_->initialize();
405 
406  IsInitialized_ = true;
407  NumInitialize_++;
408  InitializeTime_ += Time_->stop();
409 }
410 
411 //==============================================================================
412 // Returns true if the preconditioner has been successfully initialized, false otherwise.
413 template<class MatrixType,class LocalInverseType>
415 {
416  return IsInitialized_;
417 }
418 
419 //==============================================================================
420 // Computes all (coefficient) data necessary to apply the preconditioner.
421 template<class MatrixType,class LocalInverseType>
423 {
424  if (!IsInitialized_) initialize();
425 
426  Time_->start();
427  IsComputed_ = false;
428  Condest_ = -1.0;
429 
430  Inverse_->compute();
431 
432  IsComputed_ = true;
433  ++NumCompute_;
434  ComputeTime_ += Time_->stop();
435 
436 }
437 
438 //==============================================================================
439 // Returns true if the preconditioner has been successfully computed, false otherwise.
440 template<class MatrixType,class LocalInverseType>
442 {
443  return IsComputed_;
444 }
445 
446 //==============================================================================
447 // Computes the condition number estimate and returns its value.
448 template<class MatrixType,class LocalInverseType>
451  LocalOrdinal MaxIters,
452  magnitudeType Tol,
453  const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &Matrix_in)
454 {
455 
456  // If we haven't computed, we can't do a condest
457  if (!isComputed()) return (-Teuchos::ScalarTraits<magnitudeType>::one());
458 
459  Condest_ = Ifpack2::Condest(*this, CT, MaxIters, Tol, Matrix_in);
460  return(Condest_);
461 }
462 
463 
464 //==============================================================================
465 // Returns the computed condition number estimate, or -1.0 if not computed.
466 template<class MatrixType,class LocalInverseType>
469 {
470  return Condest_;
471 }
472 
473 //==============================================================================
474 // Returns the number of calls to initialize().
475 template<class MatrixType,class LocalInverseType>
477 {
478  return NumInitialize_;
479 }
480 
481 //==============================================================================
482 // Returns the number of calls to compute().
483 template<class MatrixType,class LocalInverseType>
485 {
486  return NumCompute_;
487 }
488 
489 //==============================================================================
490 // Returns the number of calls to apply().
491 template<class MatrixType,class LocalInverseType>
493 {
494  return NumApply_;
495 }
496 
497 //==============================================================================
498 // Returns the time spent in initialize().
499 template<class MatrixType,class LocalInverseType>
501 {
502  return InitializeTime_;
503 }
504 
505 //==============================================================================
506 // Returns the time spent in compute().
507 template<class MatrixType,class LocalInverseType>
509 {
510  return ComputeTime_;
511 }
512 
513 //==============================================================================
514 // Returns the time spent in Apply().
515 template<class MatrixType,class LocalInverseType>
517 {
518  return ApplyTime_;
519 }
520 //==============================================================================
521 /* Return a simple one-line description of this object. */
522 template<class MatrixType,class LocalInverseType>
524 {
525  std::ostringstream oss;
527  if (isInitialized()) {
528  if (isComputed()) {
529  oss << "{status = initialized, computed";
530  }
531  else {
532  oss << "{status = initialized, not computed";
533  }
534  }
535  else {
536  oss << "{status = not initialized, not computed";
537  }
538  oss<<"overlap level ="<<OverlapLevel_;
539  oss << "}";
540  return oss.str();
541 }
542 
543 //==============================================================================
544 /* Print the object with some verbosity level to an FancyOStream object. */
545 template<class MatrixType,class LocalInverseType>
547 {
548  using std::endl;
549 
550  os << endl;
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;
561 
562  os << "Condition number estimate = " << Condest_ << endl;
563  os << "Global number of rows = " << Matrix_->getGlobalNumRows() << endl;
564 
565  os << 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;
575  os << endl;
576 }
577 
578 //==============================================================================
579 // Prints basic information on iostream. This function is used by operator<<.
580 template<class MatrixType,class LocalInverseType>
581 std::ostream& AdditiveSchwarz<MatrixType,LocalInverseType>::print(std::ostream& os) const
582 {
583  Teuchos::FancyOStream fos(Teuchos::rcp(&os,false));
584  fos.setOutputToRootOnly(0);
585  describe(fos);
586  return(os);
587 }
588 
589 //==============================================================================
590 // Returns the level of overlap.
591 template<class MatrixType,class LocalInverseType>
593 {
594  return OverlapLevel_;
595 }
596 
597 //==============================================================================
598 // Sets up the localized matrix and the singleton filter.
599 template<class MatrixType,class LocalInverseType>
601 {
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;
605 #endif
606 
607  Teuchos::RCP<LocalMatrixType> ActiveMatrix;
608 
609  // Create Localized Matrix
610  if (OverlappingMatrix_ != Teuchos::null) {
611  if (UseSubdomain_) {
612  // int sid = List_.get("subdomain id",-1);
613  throw std::runtime_error("Ifpack2::AdditiveSchwarz subdomain code not yet supported.");
614  //Ifpack2_NodeFilter *tt = new Ifpack2_NodeFilter(OverlappingMatrix_,nodeID); //FIXME
615  //LocalizedMatrix_ = Teuchos::rcp(tt);
616  }
617  else
618  LocalizedMatrix_ = Teuchos::rcp( new Ifpack2::LocalFilter<LocalMatrixType>(OverlappingMatrix_) );
619  }
620  else {
621  if (UseSubdomain_) {
622  // int sid = List_.get("subdomain id",-1);
623  throw std::runtime_error("Ifpack2::AdditiveSchwarz subdomain code not yet supported.");
624  }
625  else
626  LocalizedMatrix_ = Teuchos::rcp( new Ifpack2::LocalFilter<LocalMatrixType>(Matrix_) );
627  }
628 
629  // Mark localized matrix as active
630  ActiveMatrix = LocalizedMatrix_;
631  TEUCHOS_TEST_FOR_EXCEPTION(LocalizedMatrix_ == Teuchos::null, std::runtime_error,
632  "Ifpack2::AdditiveSchwarz::Setup() ERROR: LocalFilter failed.");
633 
634  // Singleton Filtering
635  if (FilterSingletons_) {
636  SingletonMatrix_ = Teuchos::rcp( new Ifpack2::SingletonFilter<LocalMatrixType>(LocalizedMatrix_) );
637  ActiveMatrix = SingletonMatrix_;
638  }
639 
640 
641  // Do reordering
642  if (UseReordering_) {
643 #if defined(HAVE_IFPACK2_XPETRA) && defined(HAVE_IFPACK2_ZOLTAN2)
644  // Unlike Ifpack, Zoltan2 does all the dirty work here.
645  Teuchos::ParameterList zlist = List_.sublist("schwarz: reordering list");
646  XpetraTpetraMatrixType XpetraMatrix(ActiveMatrix);
647  Zoltan2::XpetraRowMatrixInput<XpetraMatrixType> Zoltan2Matrix(Teuchos::rcp<XpetraMatrixType>(&XpetraMatrix,false));
648 
649 #ifdef HAVE_MPI
650  // Grab the MPI Communicator and build the ordering problem with that
651  MPI_Comm mycomm;
652 
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);
657 #else
658  Zoltan2::OrderingProblem<Zoltan2::XpetraRowMatrixInput<XpetraMatrixType> > MyOrderingProblem(&Zoltan2Matrix, &zlist);
659 #endif
660  MyOrderingProblem.solve();
661 
662  // Now create the reordered matrix & mark it as active
663  ReorderedLocalizedMatrix_ = Teuchos::rcp(new Ifpack2::ReorderFilter<LocalMatrixType>(ActiveMatrix,Teuchos::rcp( new Zoltan2::OrderingSolution<GlobalOrdinal,LocalOrdinal>(*MyOrderingProblem.getSolution()))));
664 
665  ActiveMatrix = ReorderedLocalizedMatrix_;
666 #else
667  throw std::runtime_error("Ifpack2::AdditiveSchwarz::Setup() You need to compile with Zoltan2 to support reordering.");
668 #endif
669  }
670 
671  // Build the inverse
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.");
675 }
676 
677 
678 }// namespace Ifpack2
679 
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 &params, 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&lt;&lt;.
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