G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsProductOp.h
Go to the documentation of this file.
1
16#pragma once
17
19
20namespace gismo {
32template<typename T>
33class gsProductOp GISMO_FINAL : public gsLinearOperator<T>
34{
35 typedef typename gsLinearOperator<T>::Ptr BasePtr;
36public:
37
39 typedef memory::shared_ptr<gsProductOp> Ptr;
40
42 typedef memory::unique_ptr<gsProductOp> uPtr;
43
45 gsProductOp() : m_ops() {}
46
48 gsProductOp(std::vector<BasePtr> ops) : m_ops(give(ops))
49 {
50#ifndef NDEBUG
51 const index_t sz = m_ops.size();
52 for (index_t i=0; i<sz-1; ++i)
53 {
54 GISMO_ASSERT ( m_ops[i]->rows() == m_ops[i+1]->cols(),
55 "Dimensions of the operators do not fit." );
56 }
57#endif
58 }
59
61 gsProductOp(BasePtr op0, BasePtr op1) : m_ops(2)
62 {
63 GISMO_ASSERT ( op0->rows() == op1->cols(),
64 "Dimensions of the operators do not fit." );
65 m_ops[0]=give(op0); m_ops[1]=give(op1);
66 }
67
69 gsProductOp(BasePtr op0, BasePtr op1, BasePtr op2) : m_ops(3)
70 {
71 GISMO_ASSERT ( op0->rows() == op1->cols() && op1->rows() == op2->cols(),
72 "Dimensions of the operators do not fit." );
73 m_ops[0]=give(op0); m_ops[1]=give(op1); m_ops[2]=give(op2);
74 }
75
77 static uPtr make()
78 { return uPtr( new gsProductOp() ); }
79
81 static uPtr make(std::vector<BasePtr> ops)
82 { return uPtr( new gsProductOp(give(ops)) ); }
83
85 static uPtr make(BasePtr op0, BasePtr op1)
86 { return uPtr( new gsProductOp(give(op0),give(op1)) ); }
87
89 static uPtr make(BasePtr op0, BasePtr op1, BasePtr op2)
90 { return uPtr( new gsProductOp(give(op0),give(op1),give(op2)) ); }
91
93 void addOperator( BasePtr op )
94 {
95 GISMO_ASSERT ( m_ops.empty() || m_ops.back()->rows() == op->cols(),
96 "Dimensions of the operators do not fit." );
97 m_ops.push_back(give(op));
98 }
99
100 void apply(const gsMatrix<T> & input, gsMatrix<T> & x) const
101 {
102 // The product of 0 operators is the identity
103 if ( m_ops.empty() ) { x = input; return; }
104
105 // Here, we could make a permanently allocated vector
106 gsMatrix<T> temp;
107 const size_t sz = m_ops.size();
108
109 m_ops[0]->apply(input,x);
110 for(size_t i=1; i<sz;++i)
111 {
112 temp.swap(x);
113 m_ops[i]->apply(temp,x);
114 }
115 }
116
117 index_t rows() const {
118 GISMO_ASSERT( !m_ops.empty(), "gsProductOp::rows does not work for 0 operators.");
119 return m_ops.back()->rows();
120
121 }
122
123 index_t cols() const {
124 GISMO_ASSERT( !m_ops.empty(), "gsProductOp::cols does not work for 0 operators.");
125 return m_ops.front()->cols();
126 }
127
129 const std::vector<BasePtr>& getOps() const { return m_ops; }
130
131private:
132 std::vector<BasePtr> m_ops;
133};
134
135} // namespace gismo
Simple abstract class for discrete operators.
Definition gsLinearOperator.h:29
memory::shared_ptr< gsLinearOperator > Ptr
Shared pointer for gsLinearOperator.
Definition gsLinearOperator.h:33
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class for representing the product of objects of type gsLinearOperator as gsLinearOperator.
Definition gsProductOp.h:34
index_t rows() const
Returns the number of rows of the operator.
Definition gsProductOp.h:117
static uPtr make(BasePtr op0, BasePtr op1, BasePtr op2)
Make command returning a smart pointer.
Definition gsProductOp.h:89
gsProductOp(BasePtr op0, BasePtr op1, BasePtr op2)
Constructor taking three Linear Operators.
Definition gsProductOp.h:69
void addOperator(BasePtr op)
Add another operator at the end.
Definition gsProductOp.h:93
const std::vector< BasePtr > & getOps() const
Return a vector of shared pointers to all operators.
Definition gsProductOp.h:129
memory::unique_ptr< gsProductOp > uPtr
Unique pointer for gsProductOp.
Definition gsProductOp.h:42
static uPtr make(std::vector< BasePtr > ops)
Make command returning a smart pointer.
Definition gsProductOp.h:81
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition gsProductOp.h:100
gsProductOp()
Empty constructor. To be filled with addOperator()
Definition gsProductOp.h:45
static uPtr make(BasePtr op0, BasePtr op1)
Make command returning a smart pointer.
Definition gsProductOp.h:85
index_t cols() const
Returns the number of columns of the operator.
Definition gsProductOp.h:123
gsProductOp(BasePtr op0, BasePtr op1)
Constructor taking two Linear Operators.
Definition gsProductOp.h:61
gsProductOp(std::vector< BasePtr > ops)
Constructor taking a vector of Linear Operators.
Definition gsProductOp.h:48
static uPtr make()
Make command returning a smart pointer.
Definition gsProductOp.h:77
memory::shared_ptr< gsProductOp > Ptr
Shared pointer for gsProductOp.
Definition gsProductOp.h:39
#define index_t
Definition gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Simple abstract class for (discrete) linear operators.
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266