G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsLinearOperator.h
Go to the documentation of this file.
1
13#pragma once
14
16#include <gsIO/gsOptionList.h>
17
18namespace gismo
19{
20
27template<class T>
29{
30public:
31
33 typedef memory::shared_ptr<gsLinearOperator> Ptr;
34
36 typedef memory::unique_ptr<gsLinearOperator> uPtr;
37
39 static gsIdentityOp<T> Identity(const index_t dim) {return gsIdentityOp<T>(dim); }
40
41 virtual ~gsLinearOperator() {}
42
48 virtual void apply(const gsMatrix<T> & input, gsMatrix<T> & x) const = 0;
49
51 virtual index_t rows() const = 0;
52
54 virtual index_t cols() const = 0;
55
56 // NOTE: this is rather inefficient and is only provided for debugging and testing purposes
57 void toMatrix(gsMatrix<T>& result)
58 {
60 this->apply(eye, result);
61 }
62
64 // This implementation provides an empty object
66
68 // This implementation does not read any input
69 virtual void setOptions(const gsOptionList &) {}
70
71}; // gsLinearOperator
72
76template<class T>
77class gsScaledOp GISMO_FINAL : public gsLinearOperator<T>
78{
79public:
81 typedef memory::shared_ptr<gsScaledOp> Ptr;
82
84 typedef memory::unique_ptr<gsScaledOp> uPtr;
85
88
90 gsScaledOp(BasePtr op, T scalar = 1) : m_op(give(op)), m_scalar(scalar) {}
91
93 static uPtr make(BasePtr op, T scalar = 1)
94 { return uPtr( new gsScaledOp(give(op), scalar) ); }
95
96 virtual void apply(const gsMatrix<T> & input, gsMatrix<T> & x) const
97 {
98 m_op->apply(input, x);
99 x *= m_scalar;
100 }
101
103 index_t rows() const {return m_op->rows();}
104
106 index_t cols() const {return m_op->cols();}
107
108private:
109 const BasePtr m_op;
110 const T m_scalar;
111}; // gsScaladOp
112
113
117template<class T>
118class gsIdentityOp GISMO_FINAL : public gsLinearOperator<T>
119{
120public:
121
123 typedef memory::shared_ptr<gsIdentityOp> Ptr;
124
126 typedef memory::unique_ptr<gsIdentityOp> uPtr;
127
129 gsIdentityOp(index_t dim) : m_dim(dim) {}
130
132 static uPtr make(index_t dim) { return uPtr( new gsIdentityOp(dim) ); }
133
134 void apply(const gsMatrix<T> & input, gsMatrix<T> & x) const
135 {
136 x = input;
137 }
138
139 index_t rows() const {return m_dim;}
140
141 index_t cols() const {return m_dim;}
142
143private:
144 const index_t m_dim;
145};
146
150template<class T, class L>
151class gsLinearLambdaOp GISMO_FINAL : public gsLinearOperator<T>
152{
153public:
156 : m_lambda(lambda), m_rows(rows), m_cols(cols) {}
157 void apply(const gsMatrix<T> & input, gsMatrix<T> & x) const
158 {
159 m_lambda(input, x);
160 }
161 index_t rows() const {return m_rows;}
162 index_t cols() const {return m_cols;}
163private:
164 L m_lambda;
165 index_t m_rows, m_cols;
166};
167
176template<class T=real_t, class L>
178{
179 return typename gsLinearOperator<T>::uPtr(new gsLinearLambdaOp<T,L>(lambda,rows,cols));
180}
181
182
183} // namespace gismo
Identity operator.
Definition gsLinearOperator.h:119
index_t rows() const
Returns the number of rows of the operator.
Definition gsLinearOperator.h:139
gsIdentityOp(index_t dim)
Constructor taking the dimension of the identity operator.
Definition gsLinearOperator.h:129
memory::shared_ptr< gsIdentityOp > Ptr
Shared pointer for gsIdentityOp.
Definition gsLinearOperator.h:123
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition gsLinearOperator.h:134
static uPtr make(index_t dim)
Make function returning a smart pointer.
Definition gsLinearOperator.h:132
index_t cols() const
Returns the number of columns of the operator.
Definition gsLinearOperator.h:141
memory::unique_ptr< gsIdentityOp > uPtr
Unique pointer for gsIdentityOp.
Definition gsLinearOperator.h:126
Wrapper that allows to use lambdas as a gsLinearOperator.
Definition gsLinearOperator.h:152
index_t rows() const
Returns the number of rows of the operator.
Definition gsLinearOperator.h:161
gsLinearOperator< T >::uPtr makeLinearOp(L lambda, index_t rows, index_t cols)
Wrapper that allows to use lambdas as a gsLinearOperator.
Definition gsLinearOperator.h:177
gsLinearLambdaOp(L lambda, index_t rows, index_t cols)
Constructor; see makeLinearOp for details.
Definition gsLinearOperator.h:155
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition gsLinearOperator.h:157
index_t cols() const
Returns the number of columns of the operator.
Definition gsLinearOperator.h:162
Simple abstract class for discrete operators.
Definition gsLinearOperator.h:29
memory::unique_ptr< gsLinearOperator > uPtr
Unique pointer for gsLinearOperator.
Definition gsLinearOperator.h:36
virtual void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const =0
apply the operator on the input vector and store the result in x
static gsIdentityOp< T > Identity(const index_t dim)
Identity operator.
Definition gsLinearOperator.h:39
memory::shared_ptr< gsLinearOperator > Ptr
Shared pointer for gsLinearOperator.
Definition gsLinearOperator.h:33
virtual void setOptions(const gsOptionList &)
Set options based on a gsOptionList object.
Definition gsLinearOperator.h:69
virtual index_t rows() const =0
Returns the number of rows of the operator.
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition gsLinearOperator.h:65
virtual index_t cols() const =0
Returns the number of columns of the operator.
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
Allows an operator to be multiplied with a scalar.
Definition gsLinearOperator.h:78
index_t rows() const
Returns the number of rows in the preconditioner.
Definition gsLinearOperator.h:103
virtual void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition gsLinearOperator.h:96
gsScaledOp(BasePtr op, T scalar=1)
Constructor taking a shared pointer to a linear operator and a scalar.
Definition gsLinearOperator.h:90
static uPtr make(BasePtr op, T scalar=1)
Make function returning a smart pointer.
Definition gsLinearOperator.h:93
memory::unique_ptr< gsScaledOp > uPtr
Unique pointer for gsScaledOp.
Definition gsLinearOperator.h:84
index_t cols() const
Returns the number of columns in the preconditioner.
Definition gsLinearOperator.h:106
gsLinearOperator< T >::Ptr BasePtr
Shared pointer for gsLinearOperator.
Definition gsLinearOperator.h:87
memory::shared_ptr< gsScaledOp > Ptr
Shared pointer for gsScaledOp.
Definition gsLinearOperator.h:81
#define index_t
Definition gsConfig.h:32
This is the main header file that collects wrappers of Eigen for linear algebra.
Provides a list of labeled parameters/options that can be set and accessed easily.
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266