Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_IfpackPreconditionerFactory.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Stokhos_ConfigDefs.h"
12 #include "Epetra_RowMatrix.h"
13 #include "Epetra_CrsMatrix.h"
14 #include "Teuchos_Assert.hpp"
15 #ifdef HAVE_STOKHOS_IFPACK
16 #include "Ifpack.h"
17 #endif
18 
21  precParams(p)
22 {
23 }
24 
27 compute(const Teuchos::RCP<Epetra_Operator>& op, bool compute_prec) {
28 #ifdef HAVE_STOKHOS_IFPACK
30  Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(op, true);
31  Ifpack Factory;
32  std::string prec = precParams->get("Ifpack Preconditioner", "ILU");
33  int overlap = precParams->get("Overlap", 0);
35  Teuchos::rcp(Factory.Create(prec, mat.get(), overlap));
36  ifpackPrec->SetParameters(*precParams);
37  ifpackPrec->Initialize();
38  if (compute_prec)
39  ifpackPrec->Compute();
40  return ifpackPrec;
41 #else
42  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
43  "Stokhos::IfpackPreconditionerFactory is available " <<
44  "only with configured with Ifpack support!");
45  return Teuchos::null;
46 #endif // HAVE_STOKHOS_IFPACK
47 }
48 
49 void
52  const Teuchos::RCP<Epetra_Operator>& prec_op) {
53 #ifdef HAVE_STOKHOS_IFPACK
54  // Copy matrix represented by "op" into underlying matrix in Ifpack
56  Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(op, true);
58  Teuchos::rcp_dynamic_cast<Ifpack_Preconditioner>(prec_op);
59  const Epetra_RowMatrix& prec_mat = ifpackPrec->Matrix();
60  const Epetra_CrsMatrix& prec_crs_mat =
61  dynamic_cast<const Epetra_CrsMatrix&>(prec_mat);
62  Epetra_CrsMatrix& non_const_prec_crs_mat =
63  const_cast<Epetra_CrsMatrix&>(prec_crs_mat);
64  non_const_prec_crs_mat = *mat;
65 
66  // Compute preconditioenr
67  ifpackPrec->Compute();
68 #else
69  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
70  "Stokhos::IfpackPreconditionerFactory is available " <<
71  "only with configured with Ifpack support!");
72 #endif // HAVE_STOKHOS_IFPACK
73 }
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T * get() const
IfpackPreconditionerFactory(const Teuchos::RCP< Teuchos::ParameterList > &p)
Constructor.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void recompute(const Teuchos::RCP< Epetra_Operator > &op, const Teuchos::RCP< Epetra_Operator > &prec)
Recompute preconditioner operator for a new matrix.
virtual Teuchos::RCP< Epetra_Operator > compute(const Teuchos::RCP< Epetra_Operator > &op, bool compute_prec=true)
Compute preconditioner.