G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFuncCoordinate.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsFunction.h>
17 #include <gsCore/gsFunctionSet.h>
18 
19 namespace gismo
20 {
21 
33 template<class T>
34 class gsFuncCoordinate : public gsFunction<T>
35 {
36 public:
38  gsFuncCoordinate() : m_index(1) { }
39 
41  typedef memory::shared_ptr< gsFuncCoordinate > Ptr;
42 
44  typedef memory::unique_ptr< gsFuncCoordinate > uPtr;
45 
47  gsFuncCoordinate(const gsFunctionSet<T> & function, unsigned const i);
48 
50  : m_function(&function), m_index(give(ind)) { }
51 
52  ~gsFuncCoordinate() { } //destructor
53 
54  GISMO_CLONE_FUNCTION(gsFuncCoordinate)
55 
56 public:
57 
58  short_t domainDim () const {return m_function->domainDim();}
59 
60  short_t targetDim () const {return (short_t)m_index.size();} // It is a coordinate of a vector function
61 
62  gsMatrix<T> support() const;
63 
64  void eval_into (const gsMatrix<T>& u, gsMatrix<T>& result ) const;
65 
66  void deriv_into(const gsMatrix<T>& u, gsMatrix<T>& result ) const;
67 
68  void deriv2_into(const gsMatrix<T>& u, gsMatrix<T>& result ) const;
69 
72  void setCoordinate( unsigned const & i );
73 
75  void first();
76 
79  bool next();
80 
82  bool valid();
83 
84  index_t index() const { return m_index.value(); }
85 
86  // // temporary hack
87  virtual const gsFuncCoordinate & piece(const index_t k) const
88  {
89  auto it = m_pieces.find(k);
90  if (m_pieces.end()!=it) return it->second;
91  std::pair<typename std::map<index_t,gsFuncCoordinate>::iterator,bool> ins;
92 # pragma omp critical (m_pieces_touch)
93  ins = m_pieces.emplace(k, gsFuncCoordinate(m_function->piece(k),m_index));
94  return ins.first->second;
95  }
96 
97 // Data members
98 private:
99  const gsFunctionSet<T> * m_function;
100  gsVector<index_t> m_index;
101 
102  mutable std::map<index_t,gsFuncCoordinate> m_pieces;
103 }; // class gsFuncCoordinate
104 
105 
106 template<class T>
107 gsFuncCoordinate<T>::gsFuncCoordinate(const gsFunctionSet<T> & function, const unsigned i )
108 : m_function(&function), m_index(1)
109 {
110  GISMO_ASSERT( i<unsigned(m_function->targetDim()),"Invalid coordinate" );
111  m_index[0] = i;
112 }
113 
114 template<class T> void
116 {
117  GISMO_ASSERT( i<unsigned(m_function->targetDim()),"Invalid coordinate" );
118  m_index[0] = i;
119 }
120 
121 template<class T> void
123 {
124  m_index.resize(1);
125  m_index[0] = 0;
126 }
127 
128 template<class T> bool
130 {
131  return ( ++m_index[0] < static_cast<index_t>(m_function->targetDim()) );
132 }
133 
134 template<class T> bool
136 {
137  return ( m_index[0] < static_cast<index_t>(m_function->targetDim()) );
138 }
139 
140 template<class T> gsMatrix<T>
142 {
143  return m_function->support();
144 }
145 
146 template<class T> void
148 {
149  gsMatrix<T> tmp;
150  m_function->eval_into(u, tmp);
151  result = tmp(m_index, gsEigen::all);
152 }
153 
154 template<class T> void
156 {
157  gsMatrix<T> tmp;
158  m_function->deriv_into(u, tmp);
159  const index_t stride = domainDim();
160  result.resize(m_index.size()*stride, u.cols() );
161  for (index_t i = 0; i != m_index.size(); ++i)
162  result.middleRows(i*stride,stride) = tmp.middleRows(stride*m_index[i], stride);
163 }
164 
165 template<class T> void
167 {
168  gsMatrix<T> tmp;
169  m_function->deriv2_into(u, tmp);
170  const index_t dim = domainDim();
171  const index_t stride = dim*(dim+1)/2;
172  result.resize(m_index.size()*stride, u.cols() );
173  for (index_t i = 0; i != m_index.size(); ++i)
174  result.middleRows(i*stride,stride) = tmp.middleRows(stride*m_index[i], stride);
175 }
176 
177 
178 } // namespace gismo
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsFuncCoordinate.h:147
void setCoordinate(unsigned const &i)
Definition: gsFuncCoordinate.h:115
virtual const gsFuncCoordinate & piece(const index_t k) const
Returns the piece(s) of the function(s) at subdomain k.
Definition: gsFuncCoordinate.h:87
short_t targetDim() const
Dimension of the target space.
Definition: gsFuncCoordinate.h:60
#define short_t
Definition: gsConfig.h:35
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
S give(S &x)
Definition: gsMemory.h:266
#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
void first()
Point to the first coordinate.
Definition: gsFuncCoordinate.h:122
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsFuncCoordinate.h:58
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
gsFuncCoordinate()
Default empty constructor.
Definition: gsFuncCoordinate.h:38
memory::unique_ptr< gsFuncCoordinate > uPtr
Unique pointer for gsFuncCoordinate.
Definition: gsFuncCoordinate.h:44
bool next()
Definition: gsFuncCoordinate.h:129
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.
Provides declaration of Function abstract interface.
memory::shared_ptr< gsFuncCoordinate > Ptr
Shared pointer for gsFuncCoordinate.
Definition: gsFuncCoordinate.h:41
bool valid()
Return false if the the function iteration is invalidated.
Definition: gsFuncCoordinate.h:135
void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate second derivatives of the function at points u into result.
Definition: gsFuncCoordinate.h:166
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition: gsFuncCoordinate.h:155