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 // @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_B_HPP
11 #define PACKAGE_B_HPP
12 
13 //
14 // Header file for Package B.
15 //
16 
17 #include "Common.hpp"
18 
19 namespace B {
20 
21  //
22  // This solver is independent of other solvers.
23  //
24  template<class MV, class OP, class NormType>
25  class Solver3 : public Common::LinearSolverTestBase<MV, OP, NormType> {
26  protected:
27  std::string name () const {
28  return "Solver3";
29  }
30 
31  public:
32  virtual ~Solver3 () {}
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 Solver1 from package A.
42  //
43  template<class MV, class OP, class NormType>
44  class Solver4 : public Common::LinearSolverTestBase<MV, OP, NormType> {
45  protected:
46  std::string name () const {
47  return "Solver3";
48  }
49 
50  public:
51  virtual ~Solver4 () {}
52 
53  void solve (MV& X, const MV& B) {
54  std::cout << this->name () << "::solve START" << std::endl;
55 
57  Trilinos::Details::getLinearSolver<MV, OP, NormType> ("A", "1");
58  if (solverA1.get () == NULL) {
59  std::runtime_error ("Solver1 from package A has not been registered!");
60  }
61  solverA1->solve (X, B);
62 
63  std::cout << this->name () << "::solve END" << std::endl;
64  }
65  };
66 
67  //
68  // Package B's solver factory.
69  //
70  template<class MV, class OP, class NormType>
71  class FactoryB : public Trilinos::Details::LinearSolverFactory<MV, OP, NormType> {
72  public:
74  getLinearSolver (const std::string& solverName)
75  {
77 
78  if (solverName == "3") {
80  }
81  else if (solverName == "4") {
83  }
84  else {
85  std::ostringstream err;
86  err << "B::FactoryB::getLinearSolver: Invalid solver name \""
87  << solverName << "\"";
88  throw std::invalid_argument (err.str ());
89  }
90  }
91  };
92 
93 } // namespace B
94 
95 #endif // PACKAGE_B_HPP
96 
void solve(MV &, const MV &)
Solve the linear system(s) AX=B.
Definition: PackageB.hpp:34
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:27
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:53
std::string name() const
Definition: PackageB.hpp:46
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:74
Smart reference counting pointer class for automatic garbage collection.
virtual ~Solver3()
Definition: PackageB.hpp:32
virtual ~Solver4()
Definition: PackageB.hpp:51