G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMappedSingleBasis.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsBasis.h>
17 #include <gsUtils/gsMesh/gsMesh.h>
19 
20 namespace gismo
21 {
22 
23 template<short_t d,class T> class gsMappedBasis;
24 
33 template<short_t d,class T>
34 class gsMappedSingleBasis : public gsBasis<T>
35 {
36 private:
37  typedef memory::unique_ptr< gsDomainIterator<T> > domainIter;
38  typedef gsBasis<T> Base;
39 
40 public:
42  typedef memory::shared_ptr< gsMappedSingleBasis > Ptr;
43 
45  typedef memory::unique_ptr< gsMappedSingleBasis > uPtr;
46 
47 private:
49  gsMappedSingleBasis() : m_basis(nullptr) { }
50 
51 public:
52 
54  static const int Dim = d;
55 
57  gsMappedSingleBasis(gsMappedBasis<d,T> * basis, unsigned const & i = 0)
58  : m_basis(basis),m_index(i)
59  {
60  GISMO_ASSERT( i<unsigned(m_basis->nPatches()),"Invalid basis function index" );
61  }
62 
63  gsMappedSingleBasis( const gsMappedSingleBasis& other ) : Base( other )
64  {
65  m_basis = other.m_basis;
66  m_index = other.m_index;
67  }
68 
69  static uPtr make( const gsMappedSingleBasis& other)
70  { return uPtr( new gsMappedSingleBasis( other ) ); }
71 
72  ~gsMappedSingleBasis() { } //destructor
73 
74 public:
75 
77  {
78  return d;
79  }
80 
81  void connectivity(const gsMatrix<T> & nodes,
82  gsMesh<T> & mesh) const
83  {
84  GISMO_UNUSED(nodes); GISMO_UNUSED(mesh);
86  //m_basis->connectivity(nodes,mesh);
87  }
88 
89  // Look at gsBasis class for a description
90  size_t numElements(boxSide const & s = 0) const { return m_basis->getBase(m_index).numElements(s); }
91 
92  /*
93  void refine(gsMatrix<T> const & boxes)
94  { m_basis->refine(m_index,boxes); }
95 
96  void refineElements(std::vector<unsigned> const & boxes)
97  { m_basis->refineElements(m_index,boxes); }
98  */
99 
101  void active_into(const gsMatrix<T> & u, gsMatrix<index_t>& result) const
102  {
103  m_basis->active_into(m_index,u,result);
104  }
105 
107  void numActive_into(const gsMatrix<T> & u, gsVector<index_t>& result) const
108  {
109  // Assuming all patches have the same degree
110  m_basis->numActive_into(m_index,u,result);
111  }
112 
115  {
116  return m_basis->getBase(m_index).support();
117  }
118 
120  gsMatrix<T> support(const index_t & kk) const
121  {
122  typename gsMappedBasis<d,T>::IndexContainer sourceIndices;
123  m_basis->getMapper().targetToSource(kk,sourceIndices);
124  // Get the support on the whole patch
125  gsMatrix<T> supp = gsMatrix<T>::Zero(d,2);
126  gsMatrix<T> localSupp;
127  for (typename gsMappedBasis<d,T>::IndexContainer::iterator i = sourceIndices.begin(); i!=sourceIndices.end(); i++)
128  {
129  // Only consider local basis functions on the same patch
130  if (m_basis->getPatch(*i)!=m_index) continue;
131  // Get the support of the basis function
132  localSupp = m_basis->getBase(m_index).support(m_basis->getPatchIndex(*i));
133  // If no support is available, we assign it
134  if (supp.rows()==0 && supp.cols()==0)
135  {
136  supp = localSupp;
137  continue;
138  }
139  // If a support is available, we increase it if needd
140  for (index_t dim=0; dim!=d; dim++)
141  {
142  if (localSupp(dim,0) < supp(dim,0))
143  supp(dim,0) = localSupp(dim,0);
144  if (localSupp(dim,1) > supp(dim,1))
145  supp(dim,1) = localSupp(dim,1);
146  }
147  }
148  return supp;
149  // return m_basis->getBase(m_index).support();
150  }
153  {
154  return m_basis->getBase(m_index).boundaryBasis(s).release(); // Wrong, Should return 1-D mappedSingleBasis
155  }
156 
158  void eval_into(const gsMatrix<T> & u, gsMatrix<T>& result) const
159  {
160  // m_basis->evalGlobal_into(m_index,u,result);
161  m_basis->eval_into(m_index,u,result);
162  }
163 
165  void evalSingle_into(index_t i, const gsMatrix<T> & u, gsMatrix<T>& result) const
166  {
167  m_basis->evalSingle_into(m_index,i,u,result);
168  }
169 
171  void deriv_into(const gsMatrix<T> & u, gsMatrix<T>& result ) const
172  {
173  m_basis->deriv_into(m_index,u,result);
174  }
175 
177  void derivSingle_into(index_t i, const gsMatrix<T> & u, gsMatrix<T>& result ) const
178  {
179  //GISMO_UNUSED(i); GISMO_UNUSED(u); GISMO_UNUSED(result);
180  //GISMO_NO_IMPLEMENTATION;
181  m_basis->derivSingle_into(m_index,i,u,result);
182  }
183 
185  void deriv2_into(const gsMatrix<T> & u, gsMatrix<T>& result ) const
186  {
187  m_basis->deriv2_into(m_index,u,result);
188  }
189 
192  void deriv2Single_into(index_t i, const gsMatrix<T> & u, gsMatrix<T>& result ) const
193  {
194  GISMO_UNUSED(i); GISMO_UNUSED(u); GISMO_UNUSED(result);
196  }
197 
200  void evalAllDers_into(const gsMatrix<T> & u, int n, std::vector<gsMatrix<T> >& result,
201  bool sameElement = false) const
202  {
203  m_basis->evalAllDers_into(m_index,u,n,result,sameElement);
204  }
205 
208  void evalAllDersSingle_into(index_t i, const gsMatrix<T> & u, int n, gsMatrix<T>& result) const
209  {
212  }
213 
216  void evalDerSingle_into(index_t i, const gsMatrix<T> & u, int n, gsMatrix<T>& result) const
217  {
220  }
221 
222  GISMO_CLONE_FUNCTION(gsMappedSingleBasis)
223 
224  memory::unique_ptr<gsGeometry<T> > makeGeometry( gsMatrix<T> coefs ) const
225  {
226  GISMO_UNUSED(coefs);
228  }
229 
230  std::ostream &print(std::ostream &os) const
231  {
232  GISMO_UNUSED(os);
233  os << "Mapped basis function "<< m_index << " / "<< m_basis->size()-1 <<"\n";
234  return os;
235  }
236 
238  std::string detail() const
239  {
240  // By default just uses print(..)
241  std::ostringstream os;
242  print(os);
243  return os.str();
244  }
245 
247  // Virtual member that may be implemented or not by the derived class
249 
250  index_t size() const
251  {
252  return m_basis->size(m_index);
253  }
254 
257  {
258  // TODO Not always working: make it more general
259  return degree();
260  }
261 
264  {
265  // TODO Not always working: make it more general
266  return degree();
267  }
268 
270  short_t degree() const
271  {
272  // TODO Not always working: make it more general
273  return m_basis->maxDegree(); // must fix this (just took max_degree)
274  }
275 
278  {
279  return m_basis->degree(m_index,i);
280  }
281 
283  bool check() const
284  {
286  }
287 
290  void setBasis( unsigned const & i ) const
291  {
292  GISMO_ASSERT( i<unsigned(m_basis->nPatches()),"Invalid basis index" );
293  m_index = i;
294  }
295 
296 
298  void first() const
299  {
300  m_index = 0;
301  }
302 
305  bool next() const
306  {
307  return ( ++m_index < (index_t)m_basis->nPatches() );
308  }
309 
311  const gsBasis<T>& component(short_t i) const
312  {
313  // TODO Not always working: make it more general
314  return m_basis->getBase(m_index).component(i);
315  }
316 
318  {
319  // TODO Not always working: make it more general
320  // return gsMappedSingleBasisComponent<d-1,T> (this, i);
321  return m_basis->getBase(m_index).component(i);
322  }
323 
324  typename gsBasis<T>::domainIter makeDomainIterator() const
325  {
326  // TODO Not always working: make it more general
327  return m_basis->getBase(m_index).makeDomainIterator();
328  }
329 
330  typename gsBasis<T>::domainIter makeDomainIterator(const boxSide & s) const
331  {
332  // TODO Not always working: make it more general
333  return m_basis->getBase(m_index).makeDomainIterator(s);
334  }
335 
336 
338  {
339  std::vector<index_t> temp, rtemp;
340  m_basis->addLocalIndicesOfPatchSide(patchSide(m_index,s),offset,temp);
341  m_basis->getMapper().sourceToTarget(temp,rtemp);
342 
343  // Better way for offset one: compute (anchors()) the normal derivatives at the boundary and return the indices
344  if (offset == 1) // Small fix
345  {
346  GISMO_ASSERT(offset==1, "The indices of boundaryOffset(s,1) "
347  "will be substract from boundaryOffset(s,0)");
348 
349  std::vector<index_t> diff, temp2, rtemp2;
350 
351  m_basis->addLocalIndicesOfPatchSide(patchSide(m_index,s),0,temp2);
352  m_basis->getMapper().sourceToTarget(temp2,rtemp2);
353  // Subtract the indizes of Offset = 0
354  std::set_difference(rtemp.begin(), rtemp.end(), rtemp2.begin(), rtemp2.end(),
355  std::inserter(diff, diff.begin()));
356  rtemp = diff;
357  }
358 
359  return makeMatrix<index_t>(rtemp.begin(),rtemp.size(),1 );
360  }
361 
362  index_t functionAtCorner(boxCorner const & c) const
363  {
364  index_t cindex = m_basis->getBase(m_index).functionAtCorner(c);
365  cindex = m_basis->_getLocalIndex(m_index,cindex);
366  GISMO_ENSURE(m_basis->getMapper().sourceIsId(cindex),"Corner function has no identity map, i.e. there are more than 1 functions associated to the corner?");
367  std::vector<index_t> indices;
368  m_basis->getMapper().sourceToTarget(cindex,indices);
369  GISMO_ASSERT(indices.size()==1,"Size of the indices returned for the corner basis function should be 1 but is "<<indices.size()<<". Otherwise, there are more than 1 functions associated to the corner");
370  return indices.front();
371  }
372 
373 
374 // Data members
375 private:
376  gsMappedBasis<d,T> * m_basis;
377  mutable index_t m_index;
378 
379 }; // class gsMappedSingleBasis
380 
381 #ifdef GISMO_WITH_PYBIND11
382 
386  // void pybind11_init_gsMappedSingleBasis1(pybind11::module &m);
387  void pybind11_init_gsMappedSingleBasis2(pybind11::module &m);
388  // void pybind11_init_gsMappedSingleBasis3(pybind11::module &m);
389 
390 #endif // GISMO_WITH_PYBIND11
391 
392 } // namespace gismo
static const int Dim
Dimension of the parameter domain.
Definition: gsMappedSingleBasis.h:54
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsMappedSingleBasis.h:76
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
void first() const
Point to the first basis function of the basis.
Definition: gsMappedSingleBasis.h:298
Struct which represents a certain side of a patch.
Definition: gsBoundary.h:231
void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero basis functions and their derivatives up to order n at points u into result...
Definition: gsMappedSingleBasis.h:200
void evalAllDersSingle_into(index_t i, const gsMatrix< T > &u, int n, gsMatrix< T > &result) const
Evaluate the basis function i and its derivatives up to order n at points u into result.
Definition: gsMappedSingleBasis.h:208
Class gsMappedSingleBasis represents an indivisual .....of a.
Definition: gsMappedBasis.h:29
#define short_t
Definition: gsConfig.h:35
std::string detail() const
Prints the object as a string with extended details.
Definition: gsMappedSingleBasis.h:238
memory::unique_ptr< gsMappedSingleBasis > uPtr
Unique pointer for gsMappedSingleBasis.
Definition: gsMappedSingleBasis.h:45
Provides declaration of Basis abstract interface.
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
void connectivity(const gsMatrix< T > &nodes, gsMesh< T > &mesh) const
Definition: gsMappedSingleBasis.h:81
gsBasis< T >::domainIter makeDomainIterator(const boxSide &s) const
Create a boundary domain iterator for the computational mesh this basis, that points to the first ele...
Definition: gsMappedSingleBasis.h:330
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the non-zero basis functions at value u.
Definition: gsMappedSingleBasis.h:158
short_t minDegree() const
Returns the polynomial degree.
Definition: gsMappedSingleBasis.h:263
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Class Representing a triangle mesh with 3D vertices.
Definition: gsMesh.h:31
short_t degree(short_t i) const
Returns the polynomial degree.
Definition: gsMappedSingleBasis.h:277
void evalSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates i-th basis functions at value u.
Definition: gsMappedSingleBasis.h:165
memory::unique_ptr< gsGeometry< T > > makeGeometry(gsMatrix< T > coefs) const
Create a gsGeometry of proper type for this basis with the given coefficient matrix.
Definition: gsMappedSingleBasis.h:224
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial) derivatives of non-zero basis functions at (the columns of) u...
Definition: gsMappedSingleBasis.h:171
Provides declaration of Basis abstract interface.
void numActive_into(const gsMatrix< T > &u, gsVector< index_t > &result) const
Returns the number of active (nonzero) basis functions at points u in result.
Definition: gsMappedSingleBasis.h:107
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
const gsBasis< T > & component(short_t i) const
Return the 1-d basis of the underlying tensor product basis for the i-th parameter component...
Definition: gsMappedSingleBasis.h:311
void setBasis(unsigned const &i) const
Definition: gsMappedSingleBasis.h:290
gsMatrix< T > support(const index_t &kk) const
Returns a bounding box for basis function kk domain on the domain of *this.
Definition: gsMappedSingleBasis.h:120
gsMatrix< index_t > boundaryOffset(boxSide const &s, index_t offset) const
Definition: gsMappedSingleBasis.h:337
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
void derivSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial)derivatives of the i-th basis function at (the columns of) u...
Definition: gsMappedSingleBasis.h:177
gsMappedSingleBasis()
Default empty constructor.
Definition: gsMappedSingleBasis.h:49
bool next() const
Definition: gsMappedSingleBasis.h:305
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsMappedSingleBasis.h:230
Provides declaration of the Mesh class.
void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active (non zero) basis functions at points (columns of) u, as a list of indices, in result.
Definition: gsMappedSingleBasis.h:101
memory::shared_ptr< gsMappedSingleBasis > Ptr
Shared pointer for gsMappedSingleBasis.
Definition: gsMappedSingleBasis.h:42
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
size_t numElements(boxSide const &s=0) const
The number of elements on side s.
Definition: gsMappedSingleBasis.h:90
short_t degree() const
Returns the polynomial degree.
Definition: gsMappedSingleBasis.h:270
gsBasis< T > * boundaryBasis_impl(boxSide const &s) const
Returns the boundary basis on side s.
Definition: gsMappedSingleBasis.h:152
void evalDerSingle_into(index_t i, const gsMatrix< T > &u, int n, gsMatrix< T > &result) const
Evaluate the (partial) derivative(s) of order n the i-th basis function at points u into result...
Definition: gsMappedSingleBasis.h:216
gsMatrix< T > support() const
Returns a bounding box for the basis&#39; domain.
Definition: gsMappedSingleBasis.h:114
bool check() const
Check the LagrangeBasis for consistency.
Definition: gsMappedSingleBasis.h:283
short_t maxDegree() const
Returns the polynomial degree.
Definition: gsMappedSingleBasis.h:256
gsBasis< T > & component(short_t i)
For a tensor product basis, return the 1-d basis for the i-th parameter component.
Definition: gsMappedSingleBasis.h:317
gsBasis< T >::domainIter makeDomainIterator() const
Create a domain iterator for the computational mesh of this basis, that points to the first element o...
Definition: gsMappedSingleBasis.h:324
void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial) derivatives of the nonzero basis functions at points u into result...
Definition: gsMappedSingleBasis.h:185
void deriv2Single_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the (partial) derivatives of the i-th basis function at points u into result.
Definition: gsMappedSingleBasis.h:192
Struct which represents a certain corner of a hyper-cube.
Definition: gsBoundary.h:291
gsMappedSingleBasis(gsMappedBasis< d, T > *basis, unsigned const &i=0)
Construct a basis function by a pointer to a basis and an index i.
Definition: gsMappedSingleBasis.h:57
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
index_t size() const
size
Definition: gsMappedSingleBasis.h:250