Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
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:
65  getLinearSolver (const std::string& solverName)
66  {
68 
69  if (solverName == "3") {
71  }
72  else if (solverName == "4") {
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 
void solve(MV &, const MV &)
Solve the linear system(s) AX=B.
Definition: PackageB.hpp:25
Interface for a method for solving linear system(s) AX=B.
T * get() const
Get the raw C++ pointer to the underlying object.
std::string name() const
Definition: PackageB.hpp:18
Interface for a &quot;factory&quot; that creates solvers.
void solve(MV &X, const MV &B)
Solve the linear system(s) AX=B.
Definition: PackageB.hpp:44
std::string name() const
Definition: PackageB.hpp:37
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
Smart reference counting pointer class for automatic garbage collection.
virtual ~Solver3()
Definition: PackageB.hpp:23
virtual ~Solver4()
Definition: PackageB.hpp:42