Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MLPreconditionerFactory.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_ML
16 #include "ml_include.h"
17 #include "ml_MultiLevelPreconditioner.h"
18 #endif
19 
22  precParams(p)
23 {
24 #ifdef HAVE_STOKHOS_ML
25  // Set default parameters
26  if (precParams->isType<std::string>("default values")) {
27  Teuchos::ParameterList ml_defaults;
28  ML_Epetra::SetDefaults(precParams->get<std::string>("default values"),
29  ml_defaults);
31  }
32 #endif
33 }
34 
37 compute(const Teuchos::RCP<Epetra_Operator>& op, bool compute_prec) {
38 #ifdef HAVE_STOKHOS_ML
40  Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(op, true);
42  Teuchos::rcp(new ML_Epetra::MultiLevelPreconditioner(*mat, *precParams,
43  compute_prec));
44  //ml_prec->PrintUnused(0);
45  return ml_prec;
46 #else
47  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
48  "Stokhos::MLPreconditionerFactory is available " <<
49  "only with configured with ML support!");
50  return Teuchos::null;
51 #endif // HAVE_STOKHOS_ML
52 }
53 
54 void
57  const Teuchos::RCP<Epetra_Operator>& prec_op) {
58 #ifdef HAVE_STOKHOS_ML
59  // Copy matrix represented by "op" into underlying matrix in ML
61  Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(op, true);
63  Teuchos::rcp_dynamic_cast<ML_Epetra::MultiLevelPreconditioner>(prec_op);
64  const Epetra_RowMatrix& prec_mat = ml_prec->RowMatrix();
65  const Epetra_CrsMatrix& prec_crs_mat =
66  dynamic_cast<const Epetra_CrsMatrix&>(prec_mat);
67  Epetra_CrsMatrix& non_const_prec_crs_mat =
68  const_cast<Epetra_CrsMatrix&>(prec_crs_mat);
69  non_const_prec_crs_mat = *mat;
70 
71  // Compute preconditioner
72  ml_prec->ComputePreconditioner();
73 #else
74  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
75  "Stokhos::MLPreconditionerFactory is available " <<
76  "only with configured with ML support!");
77 #endif // HAVE_STOKHOS_ML
78 }
virtual Teuchos::RCP< Epetra_Operator > compute(const Teuchos::RCP< Epetra_Operator > &op, bool compute_prec=true)
Compute preconditioner.
MLPreconditionerFactory(const Teuchos::RCP< Teuchos::ParameterList > &p)
Constructor.
Teuchos::RCP< Teuchos::ParameterList > precParams
Preconditioner parameters.
T & get(ParameterList &l, const std::string &name)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
bool isType(const std::string &name) const