Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_AdditiveSchwarz_decl.hpp
Go to the documentation of this file.
1/*@HEADER
2// ***********************************************************************
3//
4// Ifpack2: Templated 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
51
52#ifndef IFPACK2_ADDITIVESCHWARZ_DECL_HPP
53#define IFPACK2_ADDITIVESCHWARZ_DECL_HPP
54
55#include "Ifpack2_ConfigDefs.hpp"
59#include "Ifpack2_OverlappingRowMatrix.hpp"
60#include "Tpetra_Map.hpp"
61#include "Tpetra_MultiVector.hpp"
62#include "Tpetra_RowMatrix.hpp"
63#include <memory>
64#include <type_traits>
65
66namespace Trilinos {
67namespace Details {
68template<class MV, class OP, class NormType>
69class LinearSolver; // forward declaration
70} // namespace Details
71} // namespace Trilinos
72
73
74namespace Ifpack2 {
75
277template<class MatrixType,
278 class LocalInverseType =
279 Preconditioner<typename MatrixType::scalar_type,
280 typename MatrixType::local_ordinal_type,
281 typename MatrixType::global_ordinal_type,
282 typename MatrixType::node_type> >
284 virtual public Preconditioner<typename MatrixType::scalar_type,
285 typename MatrixType::local_ordinal_type,
286 typename MatrixType::global_ordinal_type,
287 typename MatrixType::node_type>,
288 virtual public Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
289 typename MatrixType::local_ordinal_type,
290 typename MatrixType::global_ordinal_type,
291 typename MatrixType::node_type> >,
292 virtual public Details::NestedPreconditioner<Preconditioner<typename MatrixType::scalar_type,
293 typename MatrixType::local_ordinal_type,
294 typename MatrixType::global_ordinal_type,
295 typename MatrixType::node_type> >
296{
297public:
298 static_assert(std::is_same<LocalInverseType,
299 Preconditioner<typename MatrixType::scalar_type,
300 typename MatrixType::local_ordinal_type,
301 typename MatrixType::global_ordinal_type,
302 typename MatrixType::node_type> >::value, "Ifpack2::AdditiveSchwarz: You are not allowed to use nondefault values for the LocalInverseType template parameter. Please stop specifying this explicitly. The default template parameter is perfectly fine.");
303
304 static_assert(std::is_same<MatrixType,
305 Tpetra::RowMatrix<typename MatrixType::scalar_type,
306 typename MatrixType::local_ordinal_type,
307 typename MatrixType::global_ordinal_type,
308 typename MatrixType::node_type> >::value, "Ifpack2::AdditiveSchwarz: Please use MatrixType = Tpetra::RowMatrix instead of MatrixType = Tpetra::CrsMatrix. Don't worry, AdditiveSchwarz's constructor can take either type of matrix; it does a dynamic cast if necessary inside. Restricting the set of allowed types here will improve build times and reduce library and executable sizes.");
309
311
312
314 using scalar_type = typename MatrixType::scalar_type;
315
317 using local_ordinal_type = typename MatrixType::local_ordinal_type;
318
320 using global_ordinal_type = typename MatrixType::global_ordinal_type;
321
323 using node_type = typename MatrixType::node_type;
324
327 typename Teuchos::ScalarTraits<scalar_type>::magnitudeType;
328
331 Tpetra::RowMatrix<scalar_type, local_ordinal_type,
333
336 Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
338
340 // \name Constructors and destructor
342
346 AdditiveSchwarz (const Teuchos::RCP<const row_matrix_type>& A);
347
357 AdditiveSchwarz (const Teuchos::RCP<const row_matrix_type>& A,
358 const int overlapLevel);
359
361 virtual ~AdditiveSchwarz () = default;
362
364
366
368 virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
369
371 virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
372
374 virtual void
375 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
376 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
377 Teuchos::ETransp mode = Teuchos::NO_TRANS,
378 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
379 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
380
382
384
419 virtual void
423 node_type> >& innerPrec);
424
426
428
451 virtual void
452 setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
454
456 virtual Teuchos::RCP<const row_matrix_type> getMatrix() const;
457
627 virtual void setParameters (const Teuchos::ParameterList& plist);
628
652 void
653 setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist);
654
655 bool supportsZeroStartingSolution() { return true; }
656
657 void setZeroStartingSolution (bool zeroStartingSolution) { ZeroStartingSolution_ = zeroStartingSolution; };
658
663 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters () const;
664
666 virtual void initialize();
667
669 virtual bool isInitialized() const;
670
672 virtual void compute();
673
675 virtual bool isComputed() const;
676
678 virtual int getNumInitialize() const;
679
681 virtual int getNumCompute() const;
682
684 virtual int getNumApply() const;
685
687 virtual double getInitializeTime() const;
688
690 virtual double getComputeTime() const;
691
693 virtual double getApplyTime() const;
694
696
697
699 std::string description() const;
700
702 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
703
705
707 virtual std::ostream& print(std::ostream& os) const;
708
710 virtual int getOverlapLevel() const;
711
712
713private:
715 typedef Tpetra::Map<local_ordinal_type,
717 node_type> map_type;
719 typedef Tpetra::Import<local_ordinal_type,
721 node_type> import_type;
723 typedef Tpetra::MultiVector<scalar_type,
726 node_type> MV;
728 typedef Tpetra::Operator<scalar_type,
731 node_type> OP;
736 node_type> prec_type;
737
739 typedef Trilinos::Details::LinearSolver<MV, OP, typename MV::mag_type> inner_solver_type;
740
742 AdditiveSchwarz (const AdditiveSchwarz& RHS);
743
745 void setup ();
746
748 void localApply(MV &OverlappingX, MV &OverlappingY) const;
749
752 bool hasInnerPrecName () const;
753
754
756 std::string innerPrecName () const;
757
760 void removeInnerPrecName ();
761
767 std::pair<Teuchos::ParameterList, bool> innerPrecParams () const;
768
771 void removeInnerPrecParams ();
772
774 static std::string defaultInnerPrecName ();
775
779 Teuchos::RCP<const row_matrix_type> Matrix_;
780
784 Teuchos::RCP<OverlappingRowMatrix<row_matrix_type>> OverlappingMatrix_;
785
787 Teuchos::RCP<row_matrix_type> ReorderedLocalizedMatrix_;
788
790 Teuchos::RCP<row_matrix_type> innerMatrix_;
791
793 bool IsInitialized_ = false;
795 bool IsComputed_ = false;
797 bool IsOverlapping_ = false;
799 int OverlapLevel_ = 0;
800
806 Teuchos::ParameterList List_;
807
809 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
810
816 Tpetra::CombineMode CombineMode_ = Tpetra::ZERO;
817 bool AvgOverlap_ = false;
819 bool UseReordering_ = false;
821 std::string ReorderingAlgorithm_ = "none";
823 bool FilterSingletons_ = false;
825 Teuchos::RCP<row_matrix_type> SingletonMatrix_;
827 int NumIterations_ = 1;
829 bool ZeroStartingSolution_ = true;
831 scalar_type UpdateDamping_ = Teuchos::ScalarTraits<scalar_type>::one ();
832
834 int NumInitialize_ = 0;
836 int NumCompute_ = 0;
838 mutable int NumApply_ = 0;
840 double InitializeTime_ = 0.0;
842 double ComputeTime_ = 0.0;
844 mutable double ApplyTime_ = 0.0;
846 double InitializeFlops_ = 0.0;
848 double ComputeFlops_ = 0.0;
850 mutable double ApplyFlops_ = 0.0;
852 Teuchos::RCP<inner_solver_type> Inverse_;
854 Teuchos::RCP<const map_type> localMap_;
856 mutable std::unique_ptr<MV> overlapping_B_;
858 mutable std::unique_ptr<MV> overlapping_Y_;
860 mutable std::unique_ptr<MV> num_overlap_copies_;
862 mutable std::unique_ptr<MV> R_;
864 mutable std::unique_ptr<MV> C_;
865
872 mutable Teuchos::RCP<const import_type> DistributedImporter_;
873}; // class AdditiveSchwarz
874
875}// end namespace
876
877#endif // IFPACK2_ADDITIVESCHWARZ_DECL_HPP
Declaration of interface for preconditioners that can change their matrix after construction.
Declaration of interface for nested preconditioners.
Additive Schwarz domain decomposition for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:296
typename MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:317
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1183
virtual bool isInitialized() const
Returns true if the preconditioner has been successfully initialized, false otherwise.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1060
virtual int getOverlapLevel() const
Returns the level of overlap.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1355
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a list of the preconditioner's default parameters.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:937
typename MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:320
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
The Tpetra::CrsMatrix specialization that is a subclass of MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:337
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:657
virtual int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1148
virtual ~AdditiveSchwarz()=default
Destructor.
virtual int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1155
virtual double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1169
virtual double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1176
typename Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:327
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1722
typename MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:323
virtual void initialize()
Computes all (graph-related) data necessary to initialize the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:983
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set the preconditioner's parameters.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:741
virtual void setInnerPreconditioner(const Teuchos::RCP< Preconditioner< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > &innerPrec)
Set the inner preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1651
virtual double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1162
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
The range Map of this operator.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:273
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
The domain Map of this operator.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:260
virtual void compute()
Computes all (coefficient) data necessary to apply the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1067
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1345
typename MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:314
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:1238
virtual void setParameters(const Teuchos::ParameterList &plist)
Set the preconditioner's parameters.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:728
virtual Teuchos::RCP< const row_matrix_type > getMatrix() const
The input matrix.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:285
virtual void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Apply the preconditioner to X, putting the result in Y.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:294
virtual bool isComputed() const
Returns true if the preconditioner has been successfully computed, false otherwise.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1134
virtual int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1141
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
The Tpetra::RowMatrix specialization matching MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:332
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Mix-in interface for nested preconditioners.
Definition: Ifpack2_Details_NestedPreconditioner.hpp:97
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:108
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:74