G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsCompositePrecOp.h
Go to the documentation of this file.
1 
14 #pragma once
15 
18 
19 namespace gismo
20 {
21 
32 template <class T>
33 class gsCompositePrecOp GISMO_FINAL : public gsPreconditionerOp<T>
34 {
35  typedef typename gsPreconditionerOp<T>::Ptr BasePtr;
36 public:
37 
39  typedef memory::shared_ptr<gsCompositePrecOp> Ptr;
40 
42  typedef memory::unique_ptr<gsCompositePrecOp> uPtr;
43 
45  gsCompositePrecOp() : m_ops() {}
46 
48  gsCompositePrecOp(std::vector< BasePtr > ops)
49  : m_ops(give(ops)) {}
50 
52  gsCompositePrecOp(BasePtr op0, BasePtr op1)
53  : m_ops(2)
54  {
55  m_ops[0] = give(op0); m_ops[1] = give(op1);
56  }
57 
59  gsCompositePrecOp(BasePtr op0, BasePtr op1, BasePtr op2)
60  : m_ops(3)
61  {
62  m_ops[0] = give(op0); m_ops[1] = give(op1); m_ops[2] = give(op2);
63  }
64 
66  static uPtr make(std::vector< BasePtr > ops)
67  {
68  return uPtr( new gsCompositePrecOp(give(ops)) );
69  }
70 
72  static uPtr make(BasePtr op0, BasePtr op1)
73  {
74  return uPtr( new gsCompositePrecOp(give(op0),give(op1)) );
75  }
76 
78  static uPtr make(BasePtr op0, BasePtr op1, BasePtr op2)
79  {
80  return uPtr( new gsCompositePrecOp(give(op0),give(op1),give(op2)) );
81  }
82 
84  void addOperator(BasePtr op)
85  {
86  m_ops.push_back(give(op));
87  }
88 
90  virtual void step(const gsMatrix<T>& rhs, gsMatrix<T>& x) const
91  {
92  const size_t sz = m_ops.size();
93  for ( size_t i=0; i<sz; ++i )
94  m_ops[i]->step(rhs,x);
95  }
96 
98  virtual void stepT(const gsMatrix<T>& rhs, gsMatrix<T>& x) const
99  {
100  const index_t sz = m_ops.size();
101  for ( index_t i=sz-1; i>=0; --i )
102  m_ops[i]->stepT(rhs,x);
103  }
104 
107 
108  index_t rows() const
109  {
110  GISMO_ASSERT( !m_ops.empty(), "gsCompositePrecOp::rows does not work for 0 operators.");
111  return m_ops[0]->rows();
112  }
113 
114  index_t cols() const
115  {
116  GISMO_ASSERT( !m_ops.empty(), "gsCompositePrecOp::rows does not work for 0 operators.");
117  return m_ops[0]->cols();
118  }
119 
120 private:
121  std::vector< BasePtr > m_ops;
122 };
123 
124 
125 } // namespace gismo
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
memory::unique_ptr< gsCompositePrecOp > uPtr
Unique pointer for gsCompositePrecOp.
Definition: gsCompositePrecOp.h:42
S give(S &x)
Definition: gsMemory.h:266
virtual void stepT(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the transposed smoother for the equation Ax=rhs and update the current iterate x...
Definition: gsCompositePrecOp.h:98
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void addOperator(BasePtr op)
Add another operator at the end.
Definition: gsCompositePrecOp.h:84
static uPtr make(BasePtr op0, BasePtr op1)
Make command returning a smart pointer.
Definition: gsCompositePrecOp.h:72
static uPtr make(BasePtr op0, BasePtr op1, BasePtr op2)
Make command returning a smart pointer.
Definition: gsCompositePrecOp.h:78
index_t cols() const
Returns the number of columns of the operator.
Definition: gsCompositePrecOp.h:114
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition: gsCompositePrecOp.h:105
index_t rows() const
Returns the number of rows of the operator.
Definition: gsCompositePrecOp.h:108
memory::shared_ptr< gsLinearOperator > Ptr
Shared pointer for gsLinearOperator.
Definition: gsLinearOperator.h:33
gsCompositePrecOp(std::vector< BasePtr > ops)
Constructor taking a vector of preconditioners.
Definition: gsCompositePrecOp.h:48
virtual void step(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the smoother for the equation Ax=rhs and update the current iterate x.
Definition: gsCompositePrecOp.h:90
gsCompositePrecOp()
Empty constructor. To be filled with addOperator()
Definition: gsCompositePrecOp.h:45
memory::shared_ptr< gsCompositePrecOp > Ptr
Shared pointer for gsCompositePrecOp.
Definition: gsCompositePrecOp.h:39
Simple abstract class for perconditioners.
Definition: gsPreconditioner.h:42
gsCompositePrecOp(BasePtr op0, BasePtr op1)
Convenience constructor taking two preconditioners.
Definition: gsCompositePrecOp.h:52
This class represents the composition of preconditioners of type gsPreconditionerOp.
Definition: gsCompositePrecOp.h:33
static uPtr make(std::vector< BasePtr > ops)
Make command returning a smart pointer.
Definition: gsCompositePrecOp.h:66
This is the main header file that collects wrappers of Eigen for linear algebra.
gsCompositePrecOp(BasePtr op0, BasePtr op1, BasePtr op2)
Convenience constructor taking three preconditioners.
Definition: gsCompositePrecOp.h:59
Simple abstract class for (discrete) linear operators.
memory::shared_ptr< gsPreconditionerOp > Ptr
Shared pointer for gsLinearOperator.
Definition: gsPreconditioner.h:47