G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsConstantFunction.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsLinearAlgebra.h>
17 #include <gsCore/gsGeometry.h>
19 
20 namespace gismo
21 {
22 
32 template <class T>
33 class gsConstantFunction : public gsGeometry<T>
34 {
35 public:
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 
52  gsConstantFunction() { }
53 
56  : m_domainDim(domainDim)
57  {
58  m_coefs = val.transpose();
59  }
60 
61 
64  : m_domainDim(domainDim)
65  {
66  m_coefs.resize(1,1);
67  m_coefs(0,0) = x;
68  }
69 
72  : m_domainDim(domainDim)
73  {
74  m_coefs.resize(1,2);
75  m_coefs(0,0) = x;
76  m_coefs(0,1) = y;
77  }
78 
81  : m_domainDim(domainDim)
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 
90  gsConstantFunction(T x, T y, T z, T w, short_t domainDim)
91  : m_domainDim(domainDim)
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 
108  static uPtr make(const gsVector<T>& val, short_t domainDim)
109  { return uPtr(new gsConstantFunction(val, domainDim)); }
110 
112  static uPtr make(T x, short_t domainDim)
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 
205 private:
206 
208  using Base::m_coefs;
209 
212 };
213 
214 }
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition: gsGeometry.h:624
Class defining a dummy basis of constant functions. This is used for compatibility reasons...
Definition: gsConstantBasis.h:34
gsMatrix< T >::RowXpr coef(index_t i)
Returns the i-th coefficient of the geometry as a row expression.
Definition: gsGeometry.h:346
gsConstantFunction(T x, T y, T z, short_t domainDim)
Constructs a constant Function .
Definition: gsConstantFunction.h:80
static uPtr make(T x, short_t domainDim)
Constructs a constant function .
Definition: gsConstantFunction.h:112
const gsConstantFunction< T > & piece(const index_t) const
Returns the piece(s) of the function(s) at subdomain k.
Definition: gsConstantFunction.h:129
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
Z binomial(const Z n, const Z r)
Computes the binomial expansion coefficient binomial(n,r)
Definition: gsCombinatorics.h:69
virtual void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition: gsFunctionSet.hpp:175
#define short_t
Definition: gsConfig.h:35
virtual short_t domainDim() const
Dimension d of the parameter domain (overriding gsFunction::domainDim()).
Definition: gsConstantFunction.h:136
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsConstantFunction.h:193
short_t m_domainDim
Spatial dimension of the domain of definition of this function.
Definition: gsConstantFunction.h:211
static uPtr make(const gsVector< T > &val, short_t domainDim)
Constructs a constant function .
Definition: gsConstantFunction.h:108
Provides declaration of Geometry abstract interface.
#define index_t
Definition: gsConfig.h:32
gsConstantFunction(T x, T y, short_t domainDim)
Constructs a constant function .
Definition: gsConstantFunction.h:71
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsConstantFunction.h:153
Provides combinatorial unitilies.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
memory::shared_ptr< gsConstantFunction > Ptr
Shared pointer for gsConstantFunction.
Definition: gsConstantFunction.h:39
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
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:35
static uPtr makeZero(short_t domDim, short_t tarDim)
Returns a uPtr to a null function.
Definition: gsConstantFunction.h:49
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, T y, short_t domainDim)
Constructs a constant function .
Definition: gsConstantFunction.h:116
gsConstantFunction(const gsVector< T > &val, short_t domainDim)
Constructs a constant function .
Definition: gsConstantFunction.h:55
static uPtr make(T x, T y, T z, T w, short_t domainDim)
Constructs a constant Function .
Definition: gsConstantFunction.h:124
void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition: gsConstantFunction.h:202
gsConstantFunction(const gsConstantBasis< T > &cb, const gsMatrix< T > &coef)
Compatibility constructor.
Definition: gsConstantFunction.h:101
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
static const gsConstantFunction Zero(short_t domDim, short_t tarDim)
Returns a null function.
Definition: gsConstantFunction.h:45
This is the main header file that collects wrappers of Eigen for linear algebra.
gsConstantFunction(T x, T y, T z, T w, short_t domainDim)
Constructs a constant Function .
Definition: gsConstantFunction.h:90
virtual short_t targetDim() const
Dimension of the target space.
Definition: gsConstantFunction.h:139
memory::unique_ptr< gsConstantFunction > uPtr
Unique pointer for gsConstantFunction.
Definition: gsConstantFunction.h:42
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
static uPtr make(T x, T y, T z, short_t domainDim)
Constructs a constant Function .
Definition: gsConstantFunction.h:120
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
virtual gsBasis< T > & basis()
Returns a reference to the basis of the geometry.
Definition: gsConstantFunction.h:200
gsConstantFunction(T x, short_t domainDim)
Constructs a constant function .
Definition: gsConstantFunction.h:63
virtual const gsBasis< T > & basis() const
Returns a const reference to the basis of the geometry.
Definition: gsConstantFunction.h:199
Class defining a globally constant function.
Definition: gsConstantFunction.h:33