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