Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
remainder
example
SolverFactory
PackageB.hpp
Go to the documentation of this file.
1
#ifndef PACKAGE_B_HPP
2
#define PACKAGE_B_HPP
3
4
//
5
// Header file for Package B.
6
//
7
8
#include "
Common.hpp
"
9
10
namespace
B
{
11
12
//
13
// This solver is independent of other solvers.
14
//
15
template
<
class
MV,
class
OP,
class
NormType>
16
class
Solver3
:
public
Common::LinearSolverTestBase
<MV, OP, NormType> {
17
protected
:
18
std::string
name
()
const
{
19
return
"Solver3"
;
20
}
21
22
public
:
23
virtual
~Solver3
() {}
24
25
void
solve
(MV&
/* X */
,
const
MV&
/* Y */
) {
26
std::cout << this->
name
() <<
"::solve START"
<< std::endl;
27
std::cout << this->
name
() <<
"::solve END"
<< std::endl;
28
}
29
};
30
31
//
32
// This solver uses Solver1 from package A.
33
//
34
template
<
class
MV,
class
OP,
class
NormType>
35
class
Solver4
:
public
Common::LinearSolverTestBase
<MV, OP, NormType> {
36
protected
:
37
std::string
name
()
const
{
38
return
"Solver3"
;
39
}
40
41
public
:
42
virtual
~Solver4
() {}
43
44
void
solve
(MV& X,
const
MV&
B
) {
45
std::cout << this->
name
() <<
"::solve START"
<< std::endl;
46
47
Teuchos::RCP<Trilinos::Details::LinearSolver<MV, OP, NormType>
> solverA1 =
48
Trilinos::Details::getLinearSolver<MV, OP, NormType> (
"A"
,
"1"
);
49
if
(solverA1.
get
() == NULL) {
50
std::runtime_error (
"Solver1 from package A has not been registered!"
);
51
}
52
solverA1->solve (X,
B
);
53
54
std::cout << this->
name
() <<
"::solve END"
<< std::endl;
55
}
56
};
57
58
//
59
// Package B's solver factory.
60
//
61
template
<
class
MV,
class
OP,
class
NormType>
62
class
FactoryB
:
public
Trilinos::Details::LinearSolverFactory
<MV, OP, NormType> {
63
public
:
64
Teuchos::RCP<Trilinos::Details::LinearSolver<MV, OP, NormType>
>
65
getLinearSolver
(
const
std::string& solverName)
66
{
67
typedef
Trilinos::Details::LinearSolver<MV, OP, NormType>
solver_type;
68
69
if
(solverName ==
"3"
) {
70
return
Teuchos::RCP<solver_type>
(
new
Solver3<MV, OP, NormType>
());
71
}
72
else
if
(solverName ==
"4"
) {
73
return
Teuchos::RCP<solver_type>
(
new
Solver4<MV, OP, NormType>
());
74
}
75
else
{
76
std::ostringstream err;
77
err <<
"B::FactoryB::getLinearSolver: Invalid solver name \""
78
<< solverName <<
"\""
;
79
throw
std::invalid_argument (err.str ());
80
}
81
}
82
};
83
84
}
// namespace B
85
86
#endif // PACKAGE_B_HPP
87
B::FactoryB
Definition:
PackageB.hpp:62
B::Solver3
Definition:
PackageB.hpp:16
Common.hpp
B::Solver3::solve
void solve(MV &, const MV &)
Solve the linear system(s) AX=B.
Definition:
PackageB.hpp:25
B::Solver3::~Solver3
virtual ~Solver3()
Definition:
PackageB.hpp:23
Common::LinearSolverTestBase
Definition:
Common.hpp:39
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition:
Teuchos_RCPDecl.hpp:429
B::Solver3::name
std::string name() const
Definition:
PackageB.hpp:18
Trilinos::Details::LinearSolverFactory
Interface for a "factory" that creates solvers.
Definition:
Trilinos_Details_LinearSolverFactory.hpp:235
Trilinos::Details::LinearSolver
Interface for a method for solving linear system(s) AX=B.
Definition:
Trilinos_Details_LinearSolver.hpp:146
B::Solver4
Definition:
PackageB.hpp:35
B
Definition:
PackageB.cpp:3
B::Solver4::name
std::string name() const
Definition:
PackageB.hpp:37
Teuchos::RCP::get
T * get() const
Get the raw C++ pointer to the underlying object.
Definition:
Teuchos_RCP.hpp:363
B::Solver4::~Solver4
virtual ~Solver4()
Definition:
PackageB.hpp:42
B::FactoryB::getLinearSolver
Teuchos::RCP< Trilinos::Details::LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &solverName)
Get an instance of a solver from a particular package.
Definition:
PackageB.hpp:65
B::Solver4::solve
void solve(MV &X, const MV &B)
Solve the linear system(s) AX=B.
Definition:
PackageB.hpp:44
Generated by
1.8.16