Ifpack2 Templated Preconditioning Package Version 1.0
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 "Tpetra_Map.hpp"
60#include "Tpetra_MultiVector.hpp"
61#include "Tpetra_RowMatrix.hpp"
62#include <memory>
63#include <type_traits>
64
65namespace Trilinos {
66namespace Details {
67template<class MV, class OP, class NormType>
68class LinearSolver; // forward declaration
69} // namespace Details
70} // namespace Trilinos
71
72
73namespace Ifpack2 {
74
276template<class MatrixType,
277 class LocalInverseType =
278 Preconditioner<typename MatrixType::scalar_type,
279 typename MatrixType::local_ordinal_type,
280 typename MatrixType::global_ordinal_type,
281 typename MatrixType::node_type> >
283 virtual public Preconditioner<typename MatrixType::scalar_type,
284 typename MatrixType::local_ordinal_type,
285 typename MatrixType::global_ordinal_type,
286 typename MatrixType::node_type>,
287 virtual public Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
288 typename MatrixType::local_ordinal_type,
289 typename MatrixType::global_ordinal_type,
290 typename MatrixType::node_type> >,
291 virtual public Details::NestedPreconditioner<Preconditioner<typename MatrixType::scalar_type,
292 typename MatrixType::local_ordinal_type,
293 typename MatrixType::global_ordinal_type,
294 typename MatrixType::node_type> >
295{
296public:
297 static_assert(std::is_same<LocalInverseType,
298 Preconditioner<typename MatrixType::scalar_type,
299 typename MatrixType::local_ordinal_type,
300 typename MatrixType::global_ordinal_type,
301 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.");
302
303 static_assert(std::is_same<MatrixType,
304 Tpetra::RowMatrix<typename MatrixType::scalar_type,
305 typename MatrixType::local_ordinal_type,
306 typename MatrixType::global_ordinal_type,
307 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.");
308
310
311
313 using scalar_type = typename MatrixType::scalar_type;
314
316 using local_ordinal_type = typename MatrixType::local_ordinal_type;
317
319 using global_ordinal_type = typename MatrixType::global_ordinal_type;
320
322 using node_type = typename MatrixType::node_type;
323
326 typename Teuchos::ScalarTraits<scalar_type>::magnitudeType;
327
330 Tpetra::RowMatrix<scalar_type, local_ordinal_type,
333 // \name Constructors and destructor
335
339 AdditiveSchwarz (const Teuchos::RCP<const row_matrix_type>& A);
340
350 AdditiveSchwarz (const Teuchos::RCP<const row_matrix_type>& A,
351 const int overlapLevel);
352
354 virtual ~AdditiveSchwarz () = default;
355
357
359
361 virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
362
364 virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
365
367 virtual void
368 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
369 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
370 Teuchos::ETransp mode = Teuchos::NO_TRANS,
371 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
372 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
373
375
377
412 virtual void
416 node_type> >& innerPrec);
417
419
421
444 virtual void
445 setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
447
449 virtual Teuchos::RCP<const row_matrix_type> getMatrix() const;
450
620 virtual void setParameters (const Teuchos::ParameterList& plist);
621
645 void
646 setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist);
647
648 bool supportsZeroStartingSolution() { return true; }
649
650 void setZeroStartingSolution (bool zeroStartingSolution) { ZeroStartingSolution_ = zeroStartingSolution; };
651
656 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters () const;
657
659 virtual void initialize();
660
662 virtual bool isInitialized() const;
663
665 virtual void compute();
666
668 virtual bool isComputed() const;
669
671 virtual int getNumInitialize() const;
672
674 virtual int getNumCompute() const;
675
677 virtual int getNumApply() const;
678
680 virtual double getInitializeTime() const;
681
683 virtual double getComputeTime() const;
684
686 virtual double getApplyTime() const;
687
689
690
692 std::string description() const;
693
695 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
696
698
700 virtual std::ostream& print(std::ostream& os) const;
701
703 virtual int getOverlapLevel() const;
704
705
706private:
708 typedef Tpetra::Map<local_ordinal_type,
710 node_type> map_type;
712 typedef Tpetra::Import<local_ordinal_type,
714 node_type> import_type;
716 typedef Tpetra::MultiVector<scalar_type,
719 node_type> MV;
721 typedef Tpetra::Operator<scalar_type,
724 node_type> OP;
729 node_type> prec_type;
730
732 typedef Trilinos::Details::LinearSolver<MV, OP, typename MV::mag_type> inner_solver_type;
733
735 AdditiveSchwarz (const AdditiveSchwarz& RHS);
736
738 void setup ();
739
741 void localApply(MV &OverlappingX, MV &OverlappingY) const;
742
745 bool hasInnerPrecName () const;
746
747
749 std::string innerPrecName () const;
750
753 void removeInnerPrecName ();
754
760 std::pair<Teuchos::ParameterList, bool> innerPrecParams () const;
761
764 void removeInnerPrecParams ();
765
767 static std::string defaultInnerPrecName ();
768
772 Teuchos::RCP<const row_matrix_type> Matrix_;
773
777 Teuchos::RCP<row_matrix_type> OverlappingMatrix_;
778
780 Teuchos::RCP<row_matrix_type> ReorderedLocalizedMatrix_;
781
783 Teuchos::RCP<row_matrix_type> innerMatrix_;
784
786 bool IsInitialized_ = false;
788 bool IsComputed_ = false;
790 bool IsOverlapping_ = false;
792 int OverlapLevel_ = 0;
793
799 Teuchos::ParameterList List_;
800
802 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
803
805 Tpetra::CombineMode CombineMode_ = Tpetra::ZERO;
807 bool UseReordering_ = false;
809 std::string ReorderingAlgorithm_ = "none";
811 bool FilterSingletons_ = false;
813 Teuchos::RCP<row_matrix_type> SingletonMatrix_;
815 int NumIterations_ = 1;
817 bool ZeroStartingSolution_ = true;
819 scalar_type UpdateDamping_ = Teuchos::ScalarTraits<scalar_type>::one ();
820
822 int NumInitialize_ = 0;
824 int NumCompute_ = 0;
826 mutable int NumApply_ = 0;
828 double InitializeTime_ = 0.0;
830 double ComputeTime_ = 0.0;
832 mutable double ApplyTime_ = 0.0;
834 double InitializeFlops_ = 0.0;
836 double ComputeFlops_ = 0.0;
838 mutable double ApplyFlops_ = 0.0;
840 Teuchos::RCP<inner_solver_type> Inverse_;
842 Teuchos::RCP<const map_type> localMap_;
844 mutable std::unique_ptr<MV> overlapping_B_;
846 mutable std::unique_ptr<MV> overlapping_Y_;
848 mutable std::unique_ptr<MV> R_;
850 mutable std::unique_ptr<MV> C_;
851
858 mutable Teuchos::RCP<const import_type> DistributedImporter_;
859}; // class AdditiveSchwarz
860
861}// end namespace
862
863#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:295
typename MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:316
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1104
virtual bool isInitialized() const
Returns true if the preconditioner has been successfully initialized, false otherwise.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1000
virtual int getOverlapLevel() const
Returns the level of overlap.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1276
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a list of the preconditioner's default parameters.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:877
typename MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:319
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:650
virtual int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1069
virtual ~AdditiveSchwarz()=default
Destructor.
virtual int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1076
virtual double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1090
virtual double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1097
typename Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:326
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1544
typename MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:322
virtual void initialize()
Computes all (graph-related) data necessary to initialize the preconditioner.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:923
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set the preconditioner's parameters.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:710
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:1476
virtual double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1083
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:1007
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1266
typename MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:313
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:1159
virtual void setParameters(const Teuchos::ParameterList &plist)
Set the preconditioner's parameters.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:697
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:1055
virtual int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_AdditiveSchwarz_def.hpp:1062
AdditiveSchwarz(const Teuchos::RCP< const row_matrix_type > &A)
Constructor that takes a matrix.
Definition: Ifpack2_AdditiveSchwarz_def.hpp:245
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:331
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:73