MyraMath
UserAction.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_ITERATIVE_USERACTION_H
7 #define MYRAMATH_ITERATIVE_USERACTION_H
8 
17 
18 namespace myra {
19 namespace detail {
20 
21 // Implementation detail.
22 template<class UserClass> class UserAction : public ActionBase<typename UserClass::Number>
23  {
24  public:
25 
26  // Reflect the Number type, it must be present as a typedef on the user's class.
27  typedef typename UserClass::Number Number;
28  typedef CMatrixRange<Number> X;
29  typedef MatrixRange<Number> B;
30 
31  // Constructor, requires a copy constructible UserClass.
32  UserAction(const UserClass& in_u)
33  : u(in_u) { }
34 
35  protected:
36 
37  // Size inspector.
38  virtual std::pair<int,int> size() const
39  { return u.size(); }
40 
41  // Assigns b = U*x.
42  virtual void multiply(const X& x, const B& b) const
43  { u.multiply(x,b); }
44 
45  // Note, the other multiply(x,b,alpha,beta) just uses ActionBase's implementation.
46 
47  // Virtual copy constructor.
48  virtual ActionBase<Number>* clone() const
49  { return new UserAction<UserClass>(u); }
50 
51  private:
52 
53  // Deep copy of user's class.
54  UserClass u;
55 
56  };
57 
58 } // namespace detail
59 
61 template<class UserClass> Action<typename UserClass::Number> make_UserAction(const UserClass& u)
62  { return detail::UserAction<UserClass>(u); }
63 
64 } // namespace myra
65 
66 #endif
Action< typename UserClass::Number > make_UserAction(const UserClass &u)
Helper function to adapt some user code (encapsulated in a class) into an Action. ...
Definition: UserAction.h:61
Definition: Action.h:28
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
Definition: syntax.dox:1
Represents a const MatrixRange.
Definition: bothcat.h:22
Definition: random.cpp:45
Various utility functions/classes related to scalar Number types.
Represents a mutable MatrixRange.
Definition: conjugate.h:26
Definition: UserAction.h:22
Applies the "Action" of a linear operator, b := A*x.
Definition: Action.h:29
Implementation detail, polymorphic base type contained/erased by Action.