Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PackageA.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef PACKAGE_A_HPP
11 #define PACKAGE_A_HPP
12 
13 //
14 // Header file for Package A.
15 //
16 
17 #include "Common.hpp"
18 
19 namespace A {
20 
21  //
22  // This solver is independent of other solvers.
23  //
24  template<class MV, class OP, class NormType>
25  class Solver1 : public Common::LinearSolverTestBase<MV, OP, NormType> {
26  protected:
27  std::string name () const {
28  return "Solver1";
29  }
30 
31  public:
32  virtual ~Solver1 () {}
33 
34  void solve (MV& /* X */, const MV& /* Y */) {
35  std::cout << this->name () << "::solve START" << std::endl;
36  std::cout << this->name () << "::solve END" << std::endl;
37  }
38  };
39 
40  //
41  // This solver uses Solver4 from Package B.
42  //
43  template<class MV, class OP, class NormType>
44  class Solver2 : public Common::LinearSolverTestBase<MV, OP, NormType> {
45  protected:
46  std::string name () const {
47  return "Solver2";
48  }
49 
50  public:
51  virtual ~Solver2 () {}
52 
53  void solve (MV& X, const MV& Y) {
54  std::cout << this->name () << "::solve START" << std::endl;
55 
57  Trilinos::Details::getLinearSolver<MV, OP, NormType> ("B", "4");
58  if (solverB4.get () == NULL) {
59  throw std::runtime_error ("Solver4 from package B has not been registered!");
60  }
61  // A real implementation would probably do something to X and Y
62  // before or after calling the "inner" solver.
63  solverB4->solve (X, Y);
64  std::cout << this->name () << "::solve END" << std::endl;
65  }
66  };
67 
68  //
69  // Package A's solver factory.
70  //
71  template<class MV, class OP, class NormType>
72  class FactoryA : public Trilinos::Details::LinearSolverFactory<MV, OP, NormType> {
73  public:
74  // Get an instance of a solver from a particular package
76  getLinearSolver (const std::string& solverName)
77  {
79 
80  if (solverName == "1") {
82  }
83  else if (solverName == "2") {
85  }
86  else {
87  std::ostringstream err;
88  err << "A::FactoryA::getLinearSolver: Invalid solver name \"" << solverName << "\"";
89  throw std::invalid_argument (err.str ());
90  }
91  }
92  };
93 
94 } // namespace A
95 
96 #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:76
Interface for a method for solving linear system(s) AX=B.
T * get() const
Get the raw C++ pointer to the underlying object.
virtual ~Solver1()
Definition: PackageA.hpp:32
void solve(MV &, const MV &)
Solve the linear system(s) AX=B.
Definition: PackageA.hpp:34
Interface for a &quot;factory&quot; that creates solvers.
std::string name() const
Definition: PackageA.hpp:27
virtual ~Solver2()
Definition: PackageA.hpp:51
std::string name() const
Definition: PackageA.hpp:46
Smart reference counting pointer class for automatic garbage collection.
void solve(MV &X, const MV &Y)
Solve the linear system(s) AX=B.
Definition: PackageA.hpp:53