G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsConstantFunction.h
Go to the documentation of this file.
1
14#pragma once
15
17#include <gsCore/gsGeometry.h>
19
20namespace gismo
21{
22
32template <class T>
34{
35public:
36 typedef gsGeometry<T> Base;
37
39 typedef memory::shared_ptr< gsConstantFunction > Ptr;
40
42 typedef memory::unique_ptr< gsConstantFunction > uPtr;
43
45 static const gsConstantFunction Zero(short_t domDim, short_t tarDim)
46 { return gsConstantFunction(gsVector<T>::Zero(tarDim),domDim); }
47
49 static uPtr makeZero(short_t domDim, short_t tarDim)
50 { return uPtr(new gsConstantFunction(domDim, tarDim)); }
51
53
57 {
58 m_coefs = val.transpose();
59 }
60
61
65 {
66 m_coefs.resize(1,1);
67 m_coefs(0,0) = x;
68 }
69
73 {
74 m_coefs.resize(1,2);
75 m_coefs(0,0) = x;
76 m_coefs(0,1) = y;
77 }
78
82 {
83 m_coefs.resize(1,3);
84 m_coefs(0,0) = x;
85 m_coefs(0,1) = y;
86 m_coefs(0,2) = z;
87 }
88
92 {
93 m_coefs.resize(1,4);
94 m_coefs(0,0) = x;
95 m_coefs(0,1) = y;
96 m_coefs(0,2) = z;
97 m_coefs(0,3) = w;
98 }
99
102 : m_domainDim(1)
103 {
104 m_coefs = cb.value()*coef;
105 }
106
109 { return uPtr(new gsConstantFunction(val, domainDim)); }
110
113 { return uPtr(new gsConstantFunction(x, domainDim)); }
114
116 static uPtr make(T x, T y, short_t domainDim)
117 { return uPtr(new gsConstantFunction(x, y, domainDim)); }
118
120 static uPtr make(T x, T y, T z, short_t domainDim)
121 { return uPtr(new gsConstantFunction(x, y, z, domainDim)); }
122
124 static uPtr make(T x, T y, T z, T w, short_t domainDim)
125 { return uPtr(new gsConstantFunction(x, y, z, w, domainDim)); }
126
127 GISMO_CLONE_FUNCTION(gsConstantFunction)
128
129 const gsConstantFunction<T> & piece(const index_t) const
130 {
131 // same on all pieces
132 return *this;
133 }
134
135 // Documentation in gsFunction class
136 virtual short_t domainDim() const { return m_domainDim ; }
137
138 // Documentation in gsFunction class
139 virtual short_t targetDim() const
140 { return static_cast<short_t>(m_coefs.cols()); }
141
142 const gsVector<T> value() const { return m_coefs.transpose();}
143
144 T value(size_t i) const { return m_coefs.at(i);}
145
146 void setValue(T val, short_t domainDim)
147 { m_coefs.setConstant(1,1,val); m_domainDim = domainDim;}
148
149 void setValue(const gsVector<T> & val, short_t domainDim)
150 { m_coefs = val.transpose(); m_domainDim = domainDim;}
151
152 // Documentation in gsFunction class
153 virtual void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
154 {
155 GISMO_ASSERT(u.rows() == m_domainDim, "Wrong domain dimension "<< u.rows()
156 << ", expected "<< m_domainDim);
157 result = m_coefs.transpose().rowwise().replicate( u.cols() );
158 }
159
160 // Documentation in gsFunction class
161 virtual void deriv_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
162 {
163 GISMO_ASSERT(u.rows() == m_domainDim, "Wrong domain dimension "<< u.rows()
164 << ", expected "<< m_domainDim);
165 result = gsMatrix<T>::Zero( this->targetDim()*this->domainDim(), u.cols() );
166 }
167
168 // Documentation in gsFunction class
169 virtual void deriv2_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
170 {
171 GISMO_ASSERT(u.rows() == m_domainDim, "Wrong domain dimension "<< u.rows()
172 << ", expected "<< m_domainDim);
173 result = gsMatrix<T>::Zero(this->targetDim()*(this->domainDim()*(this->domainDim()+1))/2,
174 u.cols() );
175 }
176
177 void evalAllDers_into(const gsMatrix<T> & u, int n,
178 std::vector<gsMatrix<T> > & result,
179 bool sameElement = false) const
180 {
181 GISMO_UNUSED(sameElement);
182 GISMO_ASSERT(u.rows() == m_domainDim, "Wrong domain dimension "<< u.rows()
183 << ", expected "<< m_domainDim);
184
185 result.resize(n+1,gsMatrix<T>());
186 eval_into(u,result.front());
187 for (int i = 1; i<=n; ++i)
188 result[i].resize( this->targetDim()*binomial(i+m_domainDim-1,m_domainDim-1)
189 , u.cols() );
190 }
191
192 // Documentation in gsFunction class
193 virtual std::ostream &print(std::ostream &os) const
194 {
195 os << m_coefs.transpose();
196 return os;
197 }
198
199 virtual const gsBasis<T> & basis() const {GISMO_NO_IMPLEMENTATION}
201
202 void compute(const gsMatrix<T> & in, gsFuncData<T> & out) const
203 { gsFunction<T>::compute(in, out); }
204
205private:
206
208 using Base::m_coefs;
209
212};
213
214}
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
Class defining a dummy basis of constant functions. This is used for compatibility reasons.
Definition gsConstantBasis.h:35
Class defining a globally constant function.
Definition gsConstantFunction.h:34
static const gsConstantFunction Zero(short_t domDim, short_t tarDim)
Returns a null function.
Definition gsConstantFunction.h:45
virtual short_t domainDim() const
Dimension d of the parameter domain (overriding gsFunction::domainDim()).
Definition gsConstantFunction.h:136
virtual gsBasis< T > & basis()
Returns a reference to the basis of the geometry.
Definition gsConstantFunction.h:200
virtual short_t targetDim() const
Dimension of the target space.
Definition gsConstantFunction.h:139
gsConstantFunction(T x, short_t domainDim)
Constructs a constant function .
Definition gsConstantFunction.h:63
static uPtr make(T x, T y, T z, short_t domainDim)
Constructs a constant Function .
Definition gsConstantFunction.h:120
static uPtr make(T x, T y, T z, T w, short_t domainDim)
Constructs a constant Function .
Definition gsConstantFunction.h:124
gsConstantFunction(const gsConstantBasis< T > &cb, const gsMatrix< T > &coef)
Compatibility constructor.
Definition gsConstantFunction.h:101
gsConstantFunction(T x, T y, T z, T w, short_t domainDim)
Constructs a constant Function .
Definition gsConstantFunction.h:90
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition gsConstantFunction.h:161
void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result.
Definition gsConstantFunction.h:177
memory::shared_ptr< gsConstantFunction > Ptr
Shared pointer for gsConstantFunction.
Definition gsConstantFunction.h:39
static uPtr makeZero(short_t domDim, short_t tarDim)
Returns a uPtr to a null function.
Definition gsConstantFunction.h:49
const gsConstantFunction< T > & piece(const index_t) const
Returns the piece(s) of the function(s) at subdomain k.
Definition gsConstantFunction.h:129
void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition gsConstantFunction.h:202
memory::unique_ptr< gsConstantFunction > uPtr
Unique pointer for gsConstantFunction.
Definition gsConstantFunction.h:42
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsConstantFunction.h:193
gsConstantFunction(T x, T y, T z, short_t domainDim)
Constructs a constant Function .
Definition gsConstantFunction.h:80
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsConstantFunction.h:153
gsConstantFunction(T x, T y, short_t domainDim)
Constructs a constant function .
Definition gsConstantFunction.h:71
short_t m_domainDim
Spatial dimension of the domain of definition of this function.
Definition gsConstantFunction.h:211
gsMatrix< T > m_coefs
Global value of this function.
Definition gsGeometry.h:629
virtual void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate second derivatives of the function at points u into result.
Definition gsConstantFunction.h:169
static uPtr make(T x, short_t domainDim)
Constructs a constant function .
Definition gsConstantFunction.h:112
static uPtr make(const gsVector< T > &val, short_t domainDim)
Constructs a constant function .
Definition gsConstantFunction.h:108
gsConstantFunction(const gsVector< T > &val, short_t domainDim)
Constructs a constant function .
Definition gsConstantFunction.h:55
virtual const gsBasis< T > & basis() const
Returns a const reference to the basis of the geometry.
Definition gsConstantFunction.h:199
static uPtr make(T x, T y, short_t domainDim)
Constructs a constant function .
Definition gsConstantFunction.h:116
virtual void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition gsFunctionSet.hpp:175
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
gsMatrix< T >::RowXpr coef(index_t i)
Returns the i-th coefficient of the geometry as a row expression.
Definition gsGeometry.h:346
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition gsGeometry.h:629
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition gsMatrix.h:211
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
unsigned binomial()
Returns binomial(n,r) as a compile time constant.
Definition gsCombinatorics.h:125
Provides combinatorial unitilies.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of Geometry abstract interface.
This is the main header file that collects wrappers of Eigen for linear algebra.
The G+Smo namespace, containing all definitions for the library.