G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsAdditiveOp.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 
18 namespace gismo
19 {
20 
48 
49 template<class T>
50 class gsAdditiveOp GISMO_FINAL : public gsLinearOperator<T>
51 {
52  typedef typename gsLinearOperator<T>::Ptr OpPtr;
53  typedef std::vector<OpPtr> OpContainer;
55  typedef memory::shared_ptr<Transfer> TransferPtr;
56  typedef std::vector<Transfer> TransferContainer;
57  typedef std::vector<TransferPtr> TransferPtrContainer;
58 
59 public:
60 
62  typedef memory::shared_ptr<gsAdditiveOp> Ptr;
63 
65  typedef memory::unique_ptr<gsAdditiveOp> uPtr;
66 
69 
76  gsAdditiveOp(TransferContainer transfers, OpContainer ops)
77  : m_transfers(), m_ops(give(ops))
78  {
79  const size_t sz = transfers.size();
80  m_transfers.reserve(sz);
81  for (size_t i=0; i<sz; ++i)
82  m_transfers.push_back( transfers[i].moveToPtr() );
83 #ifndef NDEBUG
84  GISMO_ASSERT( m_transfers.size() == m_ops.size(), "Sizes do not agree" );
85  for (size_t i=0; i<sz; ++i)
86  {
88  && m_transfers[i]->cols() == m_ops[i]->rows()
89  && m_ops[i]->cols() == m_ops[i]->rows(),
90  "Dimensions of the operators do not fit." );
91  }
92 #endif
93  }
94 
101  gsAdditiveOp(TransferPtrContainer transfers, OpContainer ops)
102  : m_transfers(give(transfers)), m_ops(give(ops))
103  {
104 #ifndef NDEBUG
105  GISMO_ASSERT( m_transfers.size() == m_ops.size(), "Sizes do not agree" );
106  const size_t sz = m_transfers.size();
107  for (size_t i=0; i<sz; ++i)
108  {
110  && m_transfers[i]->cols() == m_ops[i]->rows()
111  && m_ops[i]->cols() == m_ops[i]->rows(),
112  "Dimensions of the operators do not fit." );
113  }
114 #endif
115  }
116 
120  static uPtr make()
121  { return uPtr( new gsAdditiveOp() ); }
122 
129  static uPtr make(TransferContainer transfers, OpContainer ops)
130  { return uPtr( new gsAdditiveOp( give(transfers), give(ops) ) ); }
131 
138  static uPtr make(TransferPtrContainer transfers, OpContainer ops)
139  { return uPtr( new gsAdditiveOp( give(transfers), give(ops) ) ); }
140 
141 
146  void addOperator(Transfer transfer, OpPtr op)
147  {
148  m_transfers.push_back(transfer.moveToPtr());
149  m_ops.push_back(give(op));
150  GISMO_ASSERT ( m_transfers.back()->rows()==m_transfers[0]->rows()
151  && m_transfers.back()->cols() == m_ops.back()->rows()
152  && m_ops.back()->cols() == m_ops.back()->rows(),
153  "Dimensions of the operators do not fit." );
154  }
155 
160  void addOperator(TransferPtr transfer, OpPtr op)
161  {
162  m_transfers.push_back(give(transfer));
163  m_ops.push_back(give(op));
164  GISMO_ASSERT ( m_transfers.back()->rows()==m_transfers[0]->rows()
165  && m_transfers.back()->cols() == m_ops.back()->rows()
166  && m_ops.back()->cols() == m_ops.back()->rows(),
167  "Dimensions of the operators do not fit." );
168  }
169 
170  void apply(const gsMatrix<T>& input, gsMatrix<T>& x) const;
171 
172  index_t rows() const
173  {
174  GISMO_ASSERT( !m_transfers.empty(), "gsAdditiveOp::rows does not work for 0 operators." );
175  return m_transfers[0]->rows();
176  }
177 
178  index_t cols() const
179  {
180  GISMO_ASSERT( !m_transfers.empty(), "gsAdditiveOp::cols does not work for 0 operators." );
181  return m_transfers[0]->rows();
182  }
183 
184 protected:
185  TransferPtrContainer m_transfers;
186  OpContainer m_ops;
187 
188 };
189 
190 } // namespace gismo
191 
192 #ifndef GISMO_BUILD_LIB
193 #include GISMO_HPP_HEADER(gsAdditiveOp.hpp)
194 #endif
memory::unique_ptr< gsAdditiveOp > uPtr
Unique pointer.
Definition: gsAdditiveOp.h:65
gsAdditiveOp(TransferPtrContainer transfers, OpContainer ops)
Constructor.
Definition: gsAdditiveOp.h:101
gsAdditiveOp(TransferContainer transfers, OpContainer ops)
Constructor.
Definition: gsAdditiveOp.h:76
static uPtr make(TransferPtrContainer transfers, OpContainer ops)
Definition: gsAdditiveOp.h:138
uPtr moveToPtr()
This function returns a smart pointer to the matrix. After calling it, the matrix object becomes empt...
Definition: gsSparseMatrix.h:249
Generic preconditioner which applies an arbitrary linear operator to the residual.
Definition: gsAdditiveOp.h:50
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
index_t cols() const
Returns the number of columns of the operator.
Definition: gsAdditiveOp.h:178
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
gsAdditiveOp()
Default Constructor.
Definition: gsAdditiveOp.h:68
memory::shared_ptr< gsLinearOperator > Ptr
Shared pointer for gsLinearOperator.
Definition: gsLinearOperator.h:33
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition: gsAdditiveOp.hpp:18
index_t rows() const
Returns the number of rows of the operator.
Definition: gsAdditiveOp.h:172
TransferPtrContainer m_transfers
Transfer matrices.
Definition: gsAdditiveOp.h:185
Simple abstract class for discrete operators.
Definition: gsLinearOperator.h:28
memory::shared_ptr< gsAdditiveOp > Ptr
Shared pointer.
Definition: gsAdditiveOp.h:62
static uPtr make()
Definition: gsAdditiveOp.h:120
static uPtr make(TransferContainer transfers, OpContainer ops)
Definition: gsAdditiveOp.h:129
OpContainer m_ops
Operators to be applied in the subspaces.
Definition: gsAdditiveOp.h:186
void addOperator(TransferPtr transfer, OpPtr op)
Definition: gsAdditiveOp.h:160
void addOperator(Transfer transfer, OpPtr op)
Definition: gsAdditiveOp.h:146
Simple abstract class for (discrete) linear operators.