G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFunction.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsFunctionSet.h>
17 
18 namespace gismo
19 {
20 
58 template<class T>
59 class gsFunction : public gsFunctionSet<T>
60 {
61 public:
62  typedef gsFunctionSet<T> Base;
63 
65  typedef memory::shared_ptr< gsFunction > Ptr;
66 
68  typedef memory::unique_ptr< gsFunction > uPtr;
69 
70  using Base::support;
71  using Base::domainDim;
72  using Base::targetDim;
73 
74  GISMO_UPTR_FUNCTION_NO_IMPLEMENTATION(gsFunction, clone)
75 
76  virtual const gsFunction & piece(const index_t k) const
77  {
78  GISMO_ENSURE(0==k, "Single function of type "<< typeid(*this).name() <<" is defined on single subdomain, received: "<<k<<". Is piece(k) implemented?" );
79  return *this;
80  }
81 
83  gsFuncCoordinate<T> coord(const index_t c) const;
84 
85  void active_into (const gsMatrix<T> & u, gsMatrix<index_t> &result) const
86  { result.setConstant(1,u.cols(),0); }
87 
98  /*
99  Member functions with non-virtual implementations
100  (override the _into versions in derived classes).
101  */
102 
115  virtual void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const = 0;
116 
118  virtual void eval_component_into(const gsMatrix<T>& u,
119  const index_t comp,
120  gsMatrix<T>& result) const;
121 
165  virtual void deriv_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
166 
170  virtual void jacobian_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
171 
175  void div_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
176 
177  gsMatrix<T> jacobian(const gsMatrix<T>& u) const;
178 
197  virtual void deriv2_into( const gsMatrix<T>& u, gsMatrix<T>& result ) const;
198 
199  virtual void hessian_into(const gsMatrix<T>& u, gsMatrix<T>& result,
200  index_t coord = 0) const;
201 
204  virtual gsMatrix<T> hessian(const gsMatrix<T>& u, index_t coord = 0) const
205  {
206  gsMatrix<T> res;
207  hessian_into(u,res,coord);
208  return res;
209  }
210 
214  virtual gsMatrix<T> laplacian( const gsMatrix<T>& u ) const;
215 
217 
220  virtual T distanceL2(gsFunction<T> const &) const
222 
226  virtual void invertPoints(const gsMatrix<T> & points, gsMatrix<T> & result,
227  const T accuracy = 1e-6,
228  const bool useInitialPoint = false) const;
229 
230  virtual void invertPointGrid(gsGridIterator<T,0> & git,
231  gsMatrix<T> & result, const T accuracy = 1e-6,
232  const bool useInitialPoint = false) const;
233 
238  int newtonRaphson(const gsVector<T> & value,
239  gsVector<T> & arg,
240  bool withSupport = true,
241  const T accuracy = 1e-6,
242  int max_loop = 100,
243  T damping_factor = 1) const;
244 
245  gsMatrix<T> argMin(const T accuracy = 1e-6,//index_t coord = 0
246  int max_loop = 100,
247  gsMatrix<T> init = gsMatrix<T>(),
248  T damping_factor = 1) const;
249 
253  void recoverPoints(gsMatrix<T> & xyz, gsMatrix<T> & uv, index_t k,
254  const T accuracy = 1e-6) const;
255 
256  void recoverPointGrid(gsGridIterator<T,0> & git,
257  gsMatrix<T> & xyz, gsMatrix<T> & uv,
258  index_t k, const T accuracy = 1e-6) const;
259 
261  virtual gsMatrix<T> parameterCenter() const
262  {
263  // default impl. assumes convex support
264  gsMatrix<T> S = this->support();
265  return ( S.col(0) + S.col(1) ) * (T)(0.5);
266  }
267 
269  gsMatrix<T> parameterCenter( const boxCorner& bc ) const;
270 
272  gsMatrix<T> parameterCenter( const boxSide& bs ) const;
273 
274 
276  virtual std::ostream &print(std::ostream &os) const
277  {
278  os << "gsFunction.\n"; return os;
279  }
280 
293  virtual void computeMap(gsMapData<T> & InOut) const;
294 
295  index_t size() const { return 1;}
296 
297 private:
298 
299  template<int mode, int _Dim=-1>
300  int newtonRaphson_impl(
301  const gsVector<T> & value,
302  gsVector<T> & arg, bool withSupport = true,
303  const T accuracy = 1e-6, int max_loop = 100,
304  T damping_factor = 1, T scale = 1.0) const;
305 
306  gsVector<T> _argMinOnGrid(index_t numpts = 20) const;
307 
308  gsVector<T> _argMinNormOnGrid(index_t numpts = 20) const;
309 
310 }; // class gsFunction
311 
312 
314 template<class T>
315 std::ostream &operator<<(std::ostream &os, const gsFunction<T>& b)
316 {return b.print(os); }
317 
318 #ifdef GISMO_WITH_PYBIND11
319 
323  void pybind11_init_gsFunction(pybind11::module &m);
324 
325 #endif // GISMO_WITH_PYBIND11
326 
327 
328 } // namespace gismo
329 
330 #ifndef GISMO_BUILD_LIB
331 #include GISMO_HPP_HEADER(gsFunction.hpp)
332 #endif
virtual void eval_component_into(const gsMatrix< T > &u, const index_t comp, gsMatrix< T > &result) const
Evaluate the function for component comp in the target dimension at points u into result...
Definition: gsFunction.hpp:551
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
virtual void invertPoints(const gsMatrix< T > &points, gsMatrix< T > &result, const T accuracy=1e-6, const bool useInitialPoint=false) const
Definition: gsFunction.hpp:193
virtual T distanceL2(gsFunction< T > const &) const
Computes the L2-distance between this function and the field and a function func. ...
Definition: gsFunction.h:220
virtual void computeMap(gsMapData< T > &InOut) const
Computes map function data.
Definition: gsFunction.hpp:822
virtual gsMatrix< T > parameterCenter() const
Returns a &quot;central&quot; point inside inside the parameter domain.
Definition: gsFunction.h:261
int newtonRaphson(const gsVector< T > &value, gsVector< T > &arg, bool withSupport=true, const T accuracy=1e-6, int max_loop=100, T damping_factor=1) const
Definition: gsFunction.hpp:437
the gsMapData is a cache of pre-computed function (map) values.
Definition: gsFuncData.h:324
virtual const gsFunction & piece(const index_t k) const
Returns the piece(s) of the function(s) at subdomain k.
Definition: gsFunction.h:76
memory::shared_ptr< gsFunction > Ptr
Shared pointer for gsFunction.
Definition: gsFunction.h:65
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
index_t size() const
size
Definition: gsFunction.h:295
void recoverPoints(gsMatrix< T > &xyz, gsMatrix< T > &uv, index_t k, const T accuracy=1e-6) const
Definition: gsFunction.hpp:509
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
memory::unique_ptr< gsFunction > uPtr
Unique pointer for gsFunction.
Definition: gsFunction.h:68
virtual short_t targetDim() const
Dimension of the target space.
Definition: gsFunctionSet.h:560
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition: gsFunction.hpp:87
virtual short_t domainDim() const =0
Dimension of the (source) domain.
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsFunction.h:276
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
gsFuncCoordinate< T > coord(const index_t c) const
Returns the scalar function giving the i-th coordinate of this function.
Definition: gsFunction.hpp:32
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const =0
Evaluate the function at points u into result.
uPtr clone()
Clone methode. Produceds a deep copy inside a uPtr.
void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Indices of active (non-zero) function(s) for each point.
Definition: gsFunction.h:85
void div_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Computes for each point u a block of result containing the divergence matrix.
Definition: gsFunction.hpp:59
virtual gsMatrix< T > laplacian(const gsMatrix< T > &u) const
Evaluate the Laplacian at points u.
Definition: gsFunction.hpp:171
virtual void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate second derivatives of the function at points u into result.
Definition: gsFunction.hpp:124
virtual gsMatrix< T > hessian(const gsMatrix< T > &u, index_t coord=0) const
Definition: gsFunction.h:204
Represents a certain component of a vector-valued function.
Definition: gsFuncCoordinate.h:34
This is the interface of all objects that computes functions on points like gsBasis, gsGeometry and gsFunctions.
Struct which represents a certain corner of a hyper-cube.
Definition: gsBoundary.h:291
virtual void jacobian_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Computes for each point u a block of result containing the Jacobian matrix.
Definition: gsFunction.hpp:47