MyraMath
RefineAction.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_REFINEACTION_H
7 #define MYRAMATH_ITERATIVE_REFINEACTION_H
8 
15 
17 
20 
21 namespace myra {
22 namespace detail {
23 
24 // Adapts anything with a method of the form .refine(X,side,op) into an Action.
25 template<class Solver> class RefineAction : public ActionBase<typename ReflectNumber<Solver>::type>
26  {
27  public:
28 
29  // Useful typedefs.
30  typedef typename ReflectNumber<Solver>::type Number;
31  typedef CMatrixRange<Number> X;
32  typedef MatrixRange<Number> B;
33 
34  // Constructor, requires reference to a Solver instance.
35  RefineAction(const Solver& in_solver, char in_op)
36  : solver(&in_solver), op(in_op) { }
37 
38  protected:
39 
40  // Size inspector.
41  virtual std::pair<int,int> size() const
42  { int N = solver->size(); return std::pair<int,int>(N,N); }
43 
44  // Assign B = refine(X)
45  virtual void multiply(const X& x, const B& b) const
46  { b.assign(x); solver->refine(b,'L',op); }
47 
48  // Note, the other multiply(x,b,alpha,beta) just uses ActionBase's implementation.
49 
50  // Virtual copy constructor.
51  virtual ActionBase<Number>* clone() const
52  { return new RefineAction<Solver>(*solver,op); }
53 
54  private:
55 
56  // Underlying solver.
57  const Solver* solver;
58 
59  // op modifier, if any.
60  char op;
61 
62  };
63 
64 } // namespace detail
65 
67 template<class Solver> Action<typename ReflectNumber<Solver>::type> make_RefineAction(const Solver& solver, char op = 'N')
68  { return detail::RefineAction<Solver>(solver,op); }
69 
70 } // namespace myra
71 
72 #endif
Reflects Number trait for a Container, containers of Numbers (Matrix&#39;s, Vector&#39;s, etc) should special...
Definition: Number.h:55
Definition: Action.h:28
Interface class for representing subranges of dense Matrix&#39;s.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
void assign(const CMatrixRange< Number > &that) const
Assigns the values in *this with the values in that.
Definition: MatrixRange.cpp:268
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
Applies the "Action" of a linear operator, b := A*x.
Definition: Action.h:29
Action< typename ReflectNumber< Solver >::type > make_RefineAction(const Solver &solver, char op='N')
Free function for making RefineAction&#39;s.
Definition: RefineAction.h:67
Definition: RefineAction.h:25
Implementation detail, polymorphic base type contained/erased by Action.