Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_RILUK_decl.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_CRSRILUK_DECL_HPP
44 #define IFPACK2_CRSRILUK_DECL_HPP
45 
46 #include "Ifpack2_ConfigDefs.hpp"
47 #include "Ifpack2_ScalingType.hpp"
48 #include "Ifpack2_IlukGraph.hpp"
49 #include "Ifpack2_Preconditioner.hpp"
50 #include "Tpetra_CrsMatrix.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 
53 #include "Teuchos_RefCountPtr.hpp"
54 
55 namespace Teuchos {
56  class ParameterList;
57 }
58 
59 namespace Ifpack2 {
60 
213 template<class MatrixType>
214 class RILUK: public virtual Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
215 
216  public:
218  typedef typename MatrixType::scalar_type scalar_type;
219 
221  TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
222 
223 
225  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
226 
228  TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
229 
230 
232  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
233 
235  TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
236 
237 
239  typedef typename MatrixType::node_type node_type;
240 
242  TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
243 
244 
246  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
247 
249  TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
250 
252 
257  RILUK(const Teuchos::RCP<const MatrixType>& A_in);
258 
259  private:
261  RILUK(const RILUK<MatrixType> & src);
262 
263  public:
265  virtual ~RILUK();
266 
268  void SetRelaxValue( magnitude_type RelaxValue) {RelaxValue_ = RelaxValue;}
269 
271  void SetAbsoluteThreshold( magnitude_type Athresh) {Athresh_ = Athresh;}
272 
274  void SetRelativeThreshold( magnitude_type Rthresh) {Rthresh_ = Rthresh;}
275 
277  void SetOverlapMode( Tpetra::CombineMode OverlapMode) {OverlapMode_ = OverlapMode;}
278 
290  void setParameters(const Teuchos::ParameterList& params);
291 
293  void initialize();
294 
296  bool isInitialized() const {return isInitialized_;}
297 
299  int getNumInitialize() const {return numInitialize_;}
300 
309  void compute();
310 
312  bool isComputed() const {return(Factored_);}
313 
315  int getNumCompute() const {return numCompute_;}
316 
318  int getNumApply() const {return numApply_;}
319 
320  double getInitializeTime() const {return -1;}
321  double getComputeTime() const {return -1;}
322  double getApplyTime() const {return -1;}
323 
324  // Mathematical functions.
325 
344  void apply(
345  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
346  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
347  Teuchos::ETransp mode = Teuchos::NO_TRANS,
348  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
349  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
350 
351 
366  int Multiply(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
367  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
368  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
369 
371 
379  magnitude_type computeCondEst(Teuchos::ETransp mode) const;
380  magnitude_type computeCondEst(CondestType CT = Ifpack2::Cheap,
381  local_ordinal_type MaxIters = 1550,
382  magnitude_type Tol = 1e-9,
383  const Teuchos::Ptr<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &Matrix = Teuchos::null)
384  {
385  std::cerr << "Warning, Ifpack2::RILUK::computeCondEst currently does not use MaxIters/Tol/etc arguments..." << std::endl;
386  return computeCondEst(Teuchos::NO_TRANS);
387  }
388 
389  magnitude_type getCondEst() const {return Condest_;}
390 
391  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const
392  {
393  return A_;
394  }
395 
396  // Attribute access functions
397 
399  magnitude_type GetRelaxValue() const {return RelaxValue_;}
400 
402  magnitude_type getAbsoluteThreshold() const {return Athresh_;}
403 
405  magnitude_type getRelativeThreshold() const {return Rthresh_;}
406 
407  int getLevelOfFill() const { return LevelOfFill_; }
408 
410  Tpetra::CombineMode getOverlapMode() {return OverlapMode_;}
411 
413  int getGlobalNumEntries() const {return(getL().getGlobalNumEntries()+getU().getGlobalNumEntries());}
414 
416  const Teuchos::RCP<Ifpack2::IlukGraph<local_ordinal_type,global_ordinal_type,node_type> >& getGraph() const {return(Graph_);}
417 
419  const MatrixType& getL() const {return(*L_);}
420 
422  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> & getD() const {return(*D_);}
423 
425  const MatrixType& getU() const {return(*U_);}
426 
428 
430  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getDomainMap() const
431  { return Graph_->getL_Graph()->getDomainMap(); }
432 
434  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getRangeMap() const
435  { return Graph_->getU_Graph()->getRangeMap(); }
436 
438 
439  protected:
440  void setFactored(bool Flag) {Factored_ = Flag;}
441  void setInitialized(bool Flag) {isInitialized_ = Flag;}
442  bool isAllocated() const {return(isAllocated_);}
443  void setAllocated(bool Flag) {isAllocated_ = Flag;}
444 
445  private:
446 
447 
448  void allocate_L_and_U();
449  void initAllValues(const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> & overlapA);
450  void generateXY(Teuchos::ETransp mode,
451  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Xin,
452  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Yin,
453  Teuchos::RCP<const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> >& Xout,
454  Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> >& Yout) const;
455  bool isOverlapped_;
456  Teuchos::RCP<Ifpack2::IlukGraph<local_ordinal_type,global_ordinal_type,node_type> > Graph_;
457  const Teuchos::RCP<const MatrixType> A_;
458  Teuchos::RCP<MatrixType> L_;
459  Teuchos::RCP<MatrixType> U_;
460  Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > D_;
461  bool UseTranspose_;
462 
463  int LevelOfFill_;
464  int LevelOfOverlap_;
465 
466  int NumMyDiagonals_;
467  bool isAllocated_;
468  bool isInitialized_;
469  mutable int numInitialize_;
470  mutable int numCompute_;
471  mutable int numApply_;
472  bool Factored_;
473  magnitude_type RelaxValue_;
474  magnitude_type Athresh_;
475  magnitude_type Rthresh_;
476  mutable magnitude_type Condest_;
477 
478  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > OverlapX_;
479  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > OverlapY_;
480  Tpetra::CombineMode OverlapMode_;
481 };
482 
483 }//namespace Ifpack2
484 
485 #endif /* IFPACK2_CRSRILUK_DECL_HPP */
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
const MatrixType & getU() const
Returns the U factor associated with this factored matrix.
Definition: Ifpack2_RILUK_decl.hpp:425
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition: Ifpack2_RILUK_decl.hpp:402
int getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition: Ifpack2_RILUK_decl.hpp:413
Ifpack2::ScalingType enumerable type.
void SetRelativeThreshold(magnitude_type Rthresh)
Set relative threshold value.
Definition: Ifpack2_RILUK_decl.hpp:274
void SetRelaxValue(magnitude_type RelaxValue)
Set RILU(k) relaxation parameter.
Definition: Ifpack2_RILUK_decl.hpp:268
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:232
TEUCHOS_DEPRECATED typedef MatrixType::global_ordinal_type GlobalOrdinal
Preserved only for backwards compatibility. Please use "global_ordinal_type".
Definition: Ifpack2_RILUK_decl.hpp:235
Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getMatrix() const
Returns a pointer to the input matrix.
Definition: Ifpack2_RILUK_decl.hpp:391
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_RILUK_decl.hpp:322
const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > & getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_RILUK_decl.hpp:434
void SetAbsoluteThreshold(magnitude_type Athresh)
Set absolute threshold value.
Definition: Ifpack2_RILUK_decl.hpp:271
ILU(k) (incomplete LU with fill level k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:214
Tpetra::CombineMode getOverlapMode()
Get overlap mode type.
Definition: Ifpack2_RILUK_decl.hpp:410
magnitude_type getCondEst() const
Returns the computed condition number estimate, or -1.0 if not computed.
Definition: Ifpack2_RILUK_decl.hpp:389
void SetOverlapMode(Tpetra::CombineMode OverlapMode)
Set overlap mode type.
Definition: Ifpack2_RILUK_decl.hpp:277
bool isComputed() const
Whether compute() has been called.
Definition: Ifpack2_RILUK_decl.hpp:312
MatrixType::node_type node_type
The type of the Kokkos Node used by the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:239
const Teuchos::RCP< Ifpack2::IlukGraph< local_ordinal_type, global_ordinal_type, node_type > > & getGraph() const
Returns the Ifpack2::IlukGraph associated with this factored matrix.
Definition: Ifpack2_RILUK_decl.hpp:416
TEUCHOS_DEPRECATED typedef MatrixType::local_ordinal_type LocalOrdinal
Preserved only for backwards compatibility. Please use "local_ordinal_type".
Definition: Ifpack2_RILUK_decl.hpp:228
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:225
const MatrixType & getL() const
Returns the L factor associated with this factored matrix.
Definition: Ifpack2_RILUK_decl.hpp:419
Base class for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:130
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition: Ifpack2_RILUK_decl.hpp:405
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_RILUK_decl.hpp:246
TEUCHOS_DEPRECATED typedef MatrixType::node_type Node
Preserved only for backwards compatibility. Please use "node_type".
Definition: Ifpack2_RILUK_decl.hpp:242
bool isInitialized() const
Whether initialize() has been called.
Definition: Ifpack2_RILUK_decl.hpp:296
const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > & getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition: Ifpack2_RILUK_decl.hpp:430
Definition: Ifpack2_BlockRelaxation_decl.hpp:64
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_RILUK_decl.hpp:321
int getNumCompute() const
How many times compute() has been called for this object.
Definition: Ifpack2_RILUK_decl.hpp:315
TEUCHOS_DEPRECATED typedef Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitudeType
Preserved only for backwards compatibility. Please use "magnitude_type".
Definition: Ifpack2_RILUK_decl.hpp:249
const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > & getD() const
Returns the D factor associated with this factored matrix.
Definition: Ifpack2_RILUK_decl.hpp:422
magnitude_type GetRelaxValue() const
Get RILU(k) relaxation parameter.
Definition: Ifpack2_RILUK_decl.hpp:399
int getNumApply() const
How many times apply() has been called for this object.
Definition: Ifpack2_RILUK_decl.hpp:318
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_RILUK_decl.hpp:320
cheap estimate
Definition: Ifpack2_CondestType.hpp:51
TEUCHOS_DEPRECATED typedef MatrixType::scalar_type Scalar
Preserved only for backwards compatibility. Please use "scalar_type".
Definition: Ifpack2_RILUK_decl.hpp:221
int getNumInitialize() const
How many times initialize() has been called for this object.
Definition: Ifpack2_RILUK_decl.hpp:299
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:218