Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
10namespace 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
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
67 getLinearSolver (const std::string& solverName)
68 {
70
71 if (solverName == "1") {
73 }
74 else if (solverName == "2") {
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
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
void solve(MV &, const MV &)
Solve the linear system(s) AX=B.
Definition: PackageA.hpp:25
virtual ~Solver1()
Definition: PackageA.hpp:23
std::string name() const
Definition: PackageA.hpp:18
std::string name() const
Definition: PackageA.hpp:37
virtual ~Solver2()
Definition: PackageA.hpp:42
void solve(MV &X, const MV &Y)
Solve the linear system(s) AX=B.
Definition: PackageA.hpp:44
Smart reference counting pointer class for automatic garbage collection.
T * get() const
Get the raw C++ pointer to the underlying object.
Interface for a "factory" that creates solvers.
Interface for a method for solving linear system(s) AX=B.
Definition: PackageA.cpp:3