G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFunctionSet.hpp
Go to the documentation of this file.
1 
14 #include <gsCore/gsFuncData.h>
15 #include <gsCore/gsFunction.h>
16 #include <gsCore/gsBasis.h>
17 
18 namespace gismo
19 {
20 
21 template <class T>
22 gsFunctionSet<T>::~gsFunctionSet () {}
23 
24 template <class T>
26 {
27  GISMO_ASSERT(dynamic_cast<const gsFunction<T>*>(&piece(k)),
28  "No function found, instead: "<< piece(k));
29  return static_cast<const gsFunction<T>&>(piece(k));
30 }
31 
32 template <class T>
34 {
35  GISMO_ASSERT(dynamic_cast<const gsBasis<T>*>(&piece(k)),
36  "No basis found, instead: "<< piece(k));
37  return static_cast<const gsBasis<T>&>(piece(k));
38 }
39 
40 // support (domain of definition)
41 template <class T>
43 {
44  return gsMatrix<T>();
45 }
46 
47 template <class T>
48 gsMatrix<T> gsFunctionSet<T>::supportOf(const index_t &) const
49 {
51 }
52 
53 // actives
54 
55 template <typename T>
57 {
59  // Single function 0 globally active:
60  // result.setConstant(1,u.cols(),0);
61 }
62 
63 // evaluation
64 
65 template <typename T>
67 {
68  gsWarn << "eval: Is piece(.) needed/implemented ?\n";
70 }
71 
72 template <typename T>
75 
76 template <typename T>
79 
80 template <typename T> //__attribute__ ((fallthrough)) // todo
81 void gsFunctionSet<T>::evalAllDers_into(const gsMatrix<T> & u, const int n,
82  std::vector<gsMatrix<T> > & result,
83  bool sameElement) const
84 {
85  GISMO_UNUSED(sameElement);
86  //gsWarn << "generic evalAllDers called from "<<typeid(*this).name()<< "\n";
87  result.resize(n+1);
88 
89  switch(n)
90  {
91  case 0:
92  eval_into(u, result[0]);
93  break;
94  case 1:
95  eval_into (u, result[0]);
96  deriv_into(u, result[1]);
97  break;
98  case 2:
99  eval_into (u, result[0]);
100  deriv_into (u, result[1]);
101  deriv2_into(u, result[2]);
102  break;
103  default:
104  GISMO_ERROR("evalAllDers implemented for order up to 2<"<<n ); //<< " for "<<*this);
105  break;
106  }
107 }
108 
109 template <class T>
110 std::vector<gsMatrix<T> >
111 gsFunctionSet<T>::evalAllDers(const gsMatrix<T>& u, int n, bool sameElement) const
112 {
113  std::vector<gsMatrix<T> > result;
114  this->evalAllDers_into( u, n, result, sameElement);
115  return result;
116 }
117 
118 template <class T>
121 {
122  gsMatrix<T> result;
123  this->eval_into( u, result );
124  return result;
125 }
126 
127 template <class T>
130 {
131  gsMatrix<T> result;
132  this->deriv_into( u, result );
133  return result;
134 }
135 
136 template <class T>
139 {
140  gsMatrix<T> result;
141  this->deriv2_into( u, result );
142  return result;
143 }
144 
145 /*
146 template <typename T>
147 void gsFunctionSet<T>::div_into (const gsMatrix<T> & u, gsMatrix<T> &result) const
148 {
149  gsMatrix<T> tmp;
150  deriv_into(u,tmp);
151  convertValue<T>::derivToDiv(tmp, result, info());
152 }
153 
154 template <typename T>
155 void gsFunctionSet<T>::curl_into (const gsMatrix<T> & u, gsMatrix<T> &result) const
156 {
157  gsMatrix<T> tmp;
158  deriv_into(u,tmp);
159  convertValue<T>::derivToCurl(tmp, result, info());
160 }
161 
162 template <typename T>
163 void gsFunctionSet<T>::laplacian_into (const gsMatrix<T> & u, gsMatrix<T> &result) const
164 {
165  gsMatrix<T> tmp;
166  deriv2_into(u,tmp);
167  convertValue<T>::deriv2ToLaplacian(tmp, result, info());
168 }
169 */
170 
171 
172 // Returns quantities either on the target domain or on the parametric
173 // domain depending on the representation of the object
174 template <typename T>
176  gsFuncData<T> & out ) const
177 {
178  const unsigned flags = out.flags;
179 
180  out.dim = this->dimensions();
181 
182  const int md = out.maxDeriv();
183  if (md != -1)
184  evalAllDers_into(in, md, out.values, flags & SAME_ELEMENT);
185 
186  if (flags & NEED_ACTIVE && flags & SAME_ELEMENT)
187  {
188  GISMO_ASSERT(0!=in.cols(), "The points are empty.");
189  active_into(in.col(0), out.actives);
190  }
191  else if (flags & NEED_ACTIVE)
192  active_into(in, out.actives);
193 
194  // if ( flags & NEED_DIV )
195  // convertValue<T>::derivToDiv(out.values[1], out.divs, info());
196  // if ( flags & NEED_CURL )
197  // convertValue<T>::derivToCurl(out.values[1], out.curls, info());
198  if (flags & NEED_LAPLACIAN)
199  {
200  const index_t dsz = out.deriv2Size();
201  const index_t numact = out.values[2].rows() / dsz;
202  out.laplacians.resize(numact, in.cols());
203  for (index_t i=0; i!= numact; ++i)
204  out.laplacians.row(i) =
205  out.values[2].middleRows(dsz*i,out.dim.first).colwise().sum();
206  }
207 }
208 
209 } // namespace gismo
gsMatrix< T > deriv2(const gsMatrix< T > &u) const
Evaluates the second derivatives of active (i.e., non-zero) functions at points u.
Definition: gsFunctionSet.hpp:138
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
virtual void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition: gsFunctionSet.hpp:175
const gsFunction< T > & function(const index_t k) const
Helper which casts and returns the k-th piece of this function set as a gsFunction.
Definition: gsFunctionSet.hpp:25
virtual 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: gsFunctionSet.hpp:81
gsMatrix< T > deriv(const gsMatrix< T > &u) const
Evaluate the derivatives,.
Definition: gsFunctionSet.hpp:129
Provides declaration of Basis abstract interface.
gsMatrix< T > eval(const gsMatrix< T > &u) const
Evaluate the function,.
Definition: gsFunctionSet.hpp:120
#define index_t
Definition: gsConfig.h:32
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Laplacian.
Definition: gsForwardDeclarations.h:83
#define gsWarn
Definition: gsDebug.h:50
virtual void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Indices of active (non-zero) function(s) for each point.
Definition: gsFunctionSet.hpp:56
const gsBasis< T > & basis(const index_t k) const
Helper which casts and returns the k-th piece of this function set as a gsBasis.
Definition: gsFunctionSet.hpp:33
Active function ids.
Definition: gsForwardDeclarations.h:84
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
virtual void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Second derivatives.
Definition: gsFunctionSet.hpp:77
Enable optimizations based on the assumption that all evaluation points are in the same bezier domain...
Definition: gsForwardDeclarations.h:89
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
std::vector< gsMatrix< T > > evalAllDers(const gsMatrix< T > &u, int n, bool sameElement=false) const
Evaluate all derivatives upto order n,.
Definition: gsFunctionSet.hpp:111
Provides declaration of Function abstract interface.
This object is a cache for computed values from an evaluator.
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
First derivatives.
Definition: gsFunctionSet.hpp:73
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the function(s).
Definition: gsFunctionSet.hpp:66