Ifpack2 Templated Preconditioning Package
Version 1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Ifpack2_Details_LinearSolverFactory_def.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4
//
5
// Copyright 2009 NTESS and the Ifpack2 contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
13
14
#ifndef IFPACK2_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
15
#define IFPACK2_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
16
17
#include "Trilinos_Details_LinearSolverFactory.hpp"
18
#include "
Ifpack2_Details_CanChangeMatrix.hpp
"
19
#include "Ifpack2_Details_LinearSolver.hpp"
20
#include "Ifpack2_Factory.hpp"
21
#include "Tpetra_RowMatrix.hpp"
22
#include <type_traits>
// std::is_same
23
24
namespace
Ifpack2
{
25
namespace
Details {
26
27
template
<
class
SC,
class
LO,
class
GO,
class
NT>
28
Teuchos::RCP<typename LinearSolverFactory<SC, LO, GO, NT>::solver_type>
29
LinearSolverFactory<SC, LO, GO, NT>::
30
getLinearSolver
(
const
std::string& solverName) {
31
using
Teuchos::null;
32
using
Teuchos::RCP;
33
using
Teuchos::rcp_dynamic_cast;
34
using
Teuchos::TypeNameTraits;
35
typedef
Ifpack2::Preconditioner<SC, LO, GO, NT>
prec_type;
36
typedef
Tpetra::RowMatrix<SC, LO, GO, NT> ROW;
37
const
char
prefix[] =
"Ifpack2::Details::LinearSolverFactory::getLinearSolver: "
;
38
39
RCP<prec_type> solver;
40
try
{
41
// The solver to create must be a subclass of
42
// Ifpack2::Details::CanChangeMatrix (see documentation of
43
// Ifpack2::Details::LinearSolver). As a result, it should be
44
// possible to create the solver with a null matrix.
45
solver = Ifpack2::Factory::template create<ROW>(solverName, null);
46
}
catch
(std::exception& e) {
47
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::invalid_argument, prefix <<
"Failed to create Ifpack2 "
48
"preconditioner named \""
49
<< solverName <<
"\", for the following "
50
"template parameters: "
51
<<
"SC = "
<< TypeNameTraits<SC>::name() <<
", LO = "
<< TypeNameTraits<LO>::name() <<
", GO = "
<< TypeNameTraits<GO>::name() <<
", NT = "
<< TypeNameTraits<NT>::name() <<
". Ifpack2::Factory::create threw an exception: "
<< e.what());
52
}
53
TEUCHOS_TEST_FOR_EXCEPTION(solver.is_null(), std::invalid_argument, prefix <<
"Failed to create "
54
"Ifpack2 preconditioner named \""
55
<< solverName <<
"\", for the "
56
"following template parameters: "
57
<<
"SC = "
<< TypeNameTraits<SC>::name() <<
", LO = "
<< TypeNameTraits<LO>::name() <<
", GO = "
<< TypeNameTraits<GO>::name() <<
", NT = "
<< TypeNameTraits<NT>::name() <<
". Ifpack2::Factory::create returned null."
);
58
59
typedef
Ifpack2::Details::LinearSolver<SC, LO, GO, NT>
impl_type;
60
return
Teuchos::rcp(
new
impl_type(solver, solverName));
61
}
62
63
template
<
class
SC,
class
LO,
class
GO,
class
NT>
64
void
LinearSolverFactory<SC, LO, GO, NT>::
65
registerLinearSolverFactory
() {
66
typedef
Tpetra::MultiVector<SC, LO, GO, NT> MV;
67
typedef
Tpetra::Operator<SC, LO, GO, NT> OP;
68
typedef
typename
MV::mag_type mag_type;
69
typedef
Trilinos::Details::LinearSolverFactory<MV, OP, mag_type> factory_base_type;
70
typedef
Ifpack2::Details::LinearSolverFactory<SC, LO, GO, NT>
factory_impl_type;
71
72
#ifdef HAVE_TEUCHOSCORE_CXX11
73
typedef
std::shared_ptr<factory_base_type> base_ptr_type;
74
typedef
std::shared_ptr<factory_impl_type> impl_ptr_type;
75
#else
76
typedef
Teuchos::RCP<factory_base_type> base_ptr_type;
77
typedef
Teuchos::RCP<factory_impl_type> impl_ptr_type;
78
#endif
// HAVE_TEUCHOSCORE_CXX11
79
80
impl_ptr_type factory(
new
factory_impl_type());
81
base_ptr_type factoryBase = factory;
// implicit cast to base class
82
83
TEUCHOS_TEST_FOR_EXCEPTION(factoryBase.get() == NULL, std::logic_error,
84
"Factory is null! This "
85
"should never happen! Please report this bug to the Ifpack2 developers."
);
86
87
// #ifdef HAVE_IFPACK2_DEBUG
88
// {
89
// using std::cerr;
90
// using std::endl;
91
// using Teuchos::TypeNameTraits;
92
// cerr << "Registering Ifpack2 LinearSolverFactory for"
93
// << " SC = " << TypeNameTraits<SC>::name ()
94
// << ", LO = " << TypeNameTraits<LO>::name ()
95
// << ", GO = " << TypeNameTraits<GO>::name ()
96
// << ", NT = " << TypeNameTraits<NT>::name ()
97
// << ", and mag_type = " << TypeNameTraits<mag_type>::name ()
98
// << endl;
99
// }
100
// #endif // HAVE_IFPACK2_DEBUG
101
Trilinos::Details::registerLinearSolverFactory<MV, OP, mag_type>(
"Ifpack2"
, factoryBase);
102
}
103
104
}
// namespace Details
105
}
// namespace Ifpack2
106
107
// Do explicit instantiation of Ifpack2::Details::LinearSolverFactory,
108
// for Tpetra objects, with the given Tpetra template parameters.
109
#define IFPACK2_DETAILS_LINEARSOLVERFACTORY_INSTANT(SC, LO, GO, NT) \
110
template class Ifpack2::Details::LinearSolverFactory<SC, LO, GO, NT>;
111
112
#endif
// IFPACK2_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
Ifpack2_Details_CanChangeMatrix.hpp
Declaration of interface for preconditioners that can change their matrix after construction.
Ifpack2::Details::LinearSolverFactory
Interface for a "factory" that creates Ifpack2 solvers.
Definition
Ifpack2_Details_LinearSolverFactory_decl.hpp:33
Ifpack2::Details::LinearSolverFactory::getLinearSolver
virtual Teuchos::RCP< solver_type > getLinearSolver(const std::string &solverName)
Get an instance of a Ifpack2 solver.
Definition
Ifpack2_Details_LinearSolverFactory_def.hpp:30
Ifpack2::Details::LinearSolverFactory::registerLinearSolverFactory
static void registerLinearSolverFactory()
Register this LinearSolverFactory with the central registry.
Definition
Ifpack2_Details_LinearSolverFactory_def.hpp:65
Ifpack2::Details::LinearSolver
Ifpack2's implementation of Trilinos::Details::LinearSolver interface.
Definition
Ifpack2_Details_LinearSolver_decl.hpp:75
Ifpack2::Preconditioner
Interface for all Ifpack2 preconditioners.
Definition
Ifpack2_Preconditioner.hpp:74
Ifpack2
Preconditioners and smoothers for Tpetra sparse matrices.
Definition
Ifpack2_AdditiveSchwarz_decl.hpp:40
Generated by
1.17.0