G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMappedBasis.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsBoxTopology.h>
17 #include <gsCore/gsMultiPatch.h>
18 
23 #include <gsCore/gsBasisFun.h>
24 
25 namespace gismo
26 {
27 
28 // forward declarations of the mapper classes
29 template<short_t d,class T> class gsMappedSingleBasis;
30 
31 template<short_t d,class T>
32 class gsMappedBasis : public gsFunctionSet<T>
33 {
34  friend class gsMappedSingleBasis<d,T>;
35 
36 private:
37  typedef std::vector<std::pair<int,int> >::iterator step_iter;
38  typedef gsBasis<T> BasisType;
39  typedef typename std::vector<BasisType *>::const_iterator ConstBasisIter;
40  typedef typename std::vector<BasisType *>::iterator BasisIter;
41  typedef typename std::vector<gsMatrix<T> *>::const_iterator ConstMatrixPtrIter;
42  typedef typename gsSparseMatrix<T,0,index_t>::InnerIterator InIterMat;
43  typedef typename std::vector<index_t> IndexContainer;
44  typedef typename std::vector<index_t>::const_iterator ConstIndexIter;
45  typedef typename std::vector<T> WeightContainer;
46  typedef typename std::vector<T>::const_iterator ConstWeightIter;
47  typedef gsEigen::PermutationMatrix<Dynamic,Dynamic,index_t> gsPermutationMatrix;
48 
49  typedef memory::unique_ptr< gsDomainIterator<T> > domainIter;
50 
51 public:
53  typedef memory::shared_ptr< gsMappedBasis > Ptr;
54 
56  typedef memory::unique_ptr< gsMappedBasis > uPtr;
57 
58  gsMappedBasis() : m_mapper(nullptr)
59  { }
60 
61  gsMappedBasis(gsMultiBasis<T> const & mb, const gsSparseMatrix<T> & m)
62  : m_mapper(nullptr)
63  {
64  init(mb,m);
65  }
66 
67  gsMappedBasis( const gsMappedBasis& other );
68 
69  virtual ~gsMappedBasis();
70 
71  void init(gsMultiBasis<T> const & mb, const gsSparseMatrix<T> & m)
72  {
73  GISMO_ASSERT(mb.domainDim()==d, "Error in dimensions");
74  m_topol = mb.topology();
75 
76  delete m_mapper;
77  m_mapper = new gsWeightMapper<T>(m);
78 
79  freeAll(m_bases);
80  m_bases.reserve(mb.nBases());
81  cloneAll(mb.patchBases(),m_bases);
82  m_sb.clear();
83  m_sb.reserve(m_bases.size());
84  for ( size_t q=0; q!=m_bases.size(); ++q )
85  m_sb.push_back( gsMappedSingleBasis<d,T>(this,q) );
86 
87  m_mapper->optimize(gsWeightMapper<T>::optSourceToTarget);
88  }
89 
90  index_t nPieces() const {return m_topol.nBoxes();}
91 
92 public:
94  // getters for the private fields
96 
98  BasisType const & getBase(index_t i) const
99  { return *m_bases[i]; }
100 
102  BasisType & getBase(index_t i)
103  { return *m_bases[i]; }
104 
106  const std::vector<BasisType*> getBases() const;
107 
109  std::vector<BasisType*> getBasesCopy() const
110  {
111  std::vector<BasisType*> bases;
112  cloneAll(m_bases,bases);
113  return bases;
114  }
115 
117  gsWeightMapper<T> const & getMapper() const
118  { return *m_mapper; }
119 
121  gsWeightMapper<T> * getMapPointer() const
122  { return m_mapper; }
123 
125  gsBoxTopology const & getTopol() const
126  { return m_topol; }
127 
128 public:
130  // general functions for interacting with this class
132 
134  GISMO_CLONE_FUNCTION(gsMappedBasis)
135 
136  // Prints the object to the stream
137  //std::ostream & print(std::ostream & os) const { }
138 
139  short_t domainDim() const
140  {
141  GISMO_ASSERT(m_bases.size()>0,"there should be at least one basis provided.");
142  return m_bases[0]->domainDim();
143  }
144 
148  index_t size(const index_t index) const;
149  index_t size() const { return m_mapper->getNrOfTargets(); }
150 
151  index_t globalSize() const { return m_mapper->getNrOfTargets(); }
152 
154  index_t localSize() const { return m_mapper->getNrOfSources(); }
155 
157  index_t localSize(const index_t index) const
158  { return m_bases[index]->size(); }
159 
161  short_t maxDegree() const;
162 
164  short_t degree(const index_t patch,const short_t i) const
165  { return m_bases[patch]->degree(i); }
166 
168  size_t nPatches() const
169  { return m_bases.size(); }
170 
171 private:
173  void addLocalIndicesOfPatchSide(const patchSide& ps,index_t offset,std::vector<index_t>& locals) const;
174 
175 public:
176  void reorderDofs(const gsPermutationMatrix& permMatrix)
177  {
178  (*m_mapper)*=permMatrix;
179  m_mapper->optimize(gsWeightMapper<T>::optSourceToTarget);
180  }
181 
182  void reorderDofs_withCoef(const gsPermutationMatrix& permMatrix,gsMatrix<T>& coefs)
183  {
184  reorderDofs(permMatrix);
185  coefs*=permMatrix;
186  }
187 
190  void boundary(std::vector<index_t> & indices,index_t offset = 0) const;
191 
194  void innerBoundaries(std::vector<index_t> & indices,index_t offset = 0) const;
195 
198  gsMappedSingleBasis<d,T> & getMappedSingleBasis(const index_t i) const
199  {
200  // if (m_sb.empty())
201  // {
202  // m_sb.reserve(m_bases.size());
203  // for (size_t q = 0; q!=m_bases.size(); ++q)
204  // m_sb.push_back( gsMappedSingleBasis<d,T>(this,q) );
205  // }
206  return m_sb[i];
207  }
208 
209  const gsMappedSingleBasis<d,T> & piece(const index_t k) const { return getMappedSingleBasis(k); }
210  //const gsFunctionSet & piece(const index_t k) const { return m_sb[k]; }
211 
213  domainIter makeDomainIterator(const index_t patch,const boxSide & s) const
214  { return m_bases[patch]->makeDomainIterator(s); }
215 
222  gsGeometry<T>* exportPatch(const index_t i,gsMatrix<T> const & localCoef) const;
223 
228  gsMultiPatch<T> exportToPatches(gsMatrix<T> const & localCoef) const;
229 
230 private:
231  // Avoid warnings for hidden overloads w.r.t gsFunctionSet
232  void active_into(const gsMatrix<T> &,gsMatrix<index_t>&) const
234  void eval_into(const gsMatrix<T> &,gsMatrix<T>&) const
236  void deriv_into(const gsMatrix<T> &,gsMatrix<T>&) const
238  void deriv2_into(const gsMatrix<T> &,gsMatrix<T>&) const
240  void evalAllDers_into(const gsMatrix<T> &, int,
241  std::vector<gsMatrix<T> >&, bool) const
243 
244 public:
246  // functions for evaluating and derivatives
248 
256  void active_into(const index_t patch, const gsMatrix<T> & u,
257  gsMatrix<index_t>& result) const; //global BF active on patch at point
258 
260  virtual void numActive_into(const index_t patch,const gsMatrix<T> & u, gsVector<index_t>& result) const
261  {
262  GISMO_UNUSED(patch); GISMO_UNUSED(u); GISMO_UNUSED(result);
264  }
265 
268 
292  void eval_into(const index_t patch, const gsMatrix<T> & u, gsMatrix<T>& result ) const;
293  void deriv_into(const index_t patch, const gsMatrix<T> & u, gsMatrix<T>& result ) const;
294  void deriv2_into(const index_t patch, const gsMatrix<T> & u, gsMatrix<T>& result ) const;
295 
296  gsPiecewiseFunction<T> basisFunction(index_t global_BF)
297  {
298  const size_t np = nPatches();
299  gsPiecewiseFunction<T> bf(np);
300  for( size_t i = 0; i!=np; ++i)
301  bf.addPiece( getMappedSingleBasis(i).function(global_BF) );
302  return bf;
303  }
304 
306  void evalSingle_into(const index_t patch, const index_t global_BF, const gsMatrix<T> & u, gsMatrix<T>& result ) const;
307  void derivSingle_into(const index_t patch, const index_t global_BF, const gsMatrix<T> & u, gsMatrix<T>& result ) const;
308  void deriv2Single_into(const index_t patch, const index_t global_BF, const gsMatrix<T> & u, gsMatrix<T>& result ) const;
309 
311  gsMatrix<T> evalSingle(const index_t patch, const index_t global_BF, const gsMatrix<T> & u) const
312  {
313  gsMatrix<T> result;
314  this->evalSingle_into(patch, global_BF, u, result);
315  return result;
316  }
317 
319  gsMatrix<T> derivSingle(const index_t patch, const index_t global_BF, const gsMatrix<T> & u) const
320  {
321  gsMatrix<T> result;
322  this->derivSingle_into(patch, global_BF, u, result);
323  return result;
324  }
325 
327  gsMatrix<T> deriv2Single(const index_t patch, const index_t global_BF, const gsMatrix<T> & u) const
328  {
329  gsMatrix<T> result;
330  this->deriv2Single_into(patch, global_BF, u, result);
331  return result;
332  }
333 
336  void evalAllDers_into(const index_t patch, const gsMatrix<T> & u,
337  const index_t n, std::vector<gsMatrix<T> >& result,
338  bool sameElement = false) const;
339 
342  void evalAllDersSingle_into(const index_t patch,const index_t global_BF, const gsMatrix<T> & u,const index_t n,gsMatrix<T> & result ) const;
343 
345 
347  std::ostream &print(std::ostream &os) const;
348 
349 public:
351  // functions for converting global to local coefs and back
353 
359  void global_coef_to_local_coef(gsMatrix<T> const & globalCoefs,gsMatrix<T> & localCoefs) const
360  { m_mapper->mapToSourceCoefs(globalCoefs,localCoefs); }
361 
367  void local_coef_to_global_coef(gsMatrix<T> const & localCoefs,gsMatrix<T> & globalCoefs) const
368  { m_mapper->mapToTargetCoefs(localCoefs,globalCoefs); }
369 
371  index_t getPatch(index_t const localIndex)
372  {
373  return _getPatch(localIndex);
374  }
375  index_t getPatchIndex(index_t const localIndex)
376  {
377  return _getPatchIndex(localIndex);
378  }
379 
380 protected:
382  // functions for working with Indexes
384 
390  index_t _getPatch(index_t const localIndex) const;
391 
397  index_t _getPatchIndex(const index_t localIndex) const;
398 
405  index_t _getLocalIndex(index_t const patch,index_t const patchIndex) const
406  { return _getFirstLocalIndex(patch)+patchIndex; }
407 
413  index_t _getFirstLocalIndex(index_t const patch) const;
414 
420  index_t _getLastLocalIndex(index_t const patch) const
421  { return _getFirstLocalIndex(patch)+m_bases[patch]->size()-1; }
422 
423  // Data members
424 protected:
426  gsBoxTopology m_topol;
427 
429  std::vector<BasisType *> m_bases;
430 
432  gsWeightMapper<T> * m_mapper;
433  // gsSparseMatrix<T> r:C, c:B
434 
436  mutable std::vector<gsMappedSingleBasis<d,T> > m_sb;
437 
438  // Make gsMultiBasis a member instead of m_bases and m_topol?
439 };
440 
441 #ifdef GISMO_WITH_PYBIND11
442 
446  // void pybind11_init_gsMappedBasis1(pybind11::module &m);
447  void pybind11_init_gsMappedBasis2(pybind11::module &m);
448  // void pybind11_init_gsMappedBasis3(pybind11::module &m);
449 
450 #endif // GISMO_WITH_PYBIND11
451 
452 }
453 
454 #ifndef GISMO_BUILD_LIB
455 #include GISMO_HPP_HEADER(gsMappedBasis.hpp)
456 #endif
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
Provides declaration of the BoxTopology class.
Class gsMappedSingleBasis represents an indivisual .....of a.
Definition: gsMappedBasis.h:29
#define short_t
Definition: gsConfig.h:35
gsEigen::PermutationMatrix< Dynamic, Dynamic, index_t > gsPermutationMatrix
reorderMapperTarget permutes the target indices of mapper according to permutation. If permutation does not contain all indices then the order of the remaining indices is preserved and the specified indices are appended to the end.
Definition: gsWeightMapperUtils.h:36
Provides definition of the BasisFun class.
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void cloneAll(It start, It end, ItOut out)
Clones all pointers in the range [start end) and stores new raw pointers in iterator out...
Definition: gsMemory.h:295
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition: gsSparseMatrix.h:140
Provides declaration of gsWeightMapper class.
Holds a set of patch-wise bases and their topology information.
Definition: gsMultiBasis.h:36
Provides declaration of the MultiPatch class.
memory::shared_ptr< gsBasis > Ptr
Shared pointer for gsBasis.
Definition: gsBasis.h:86
Provides declaration of DomainIterator abstract interface.
Implementation of a piece of the gsMappedBasis.
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
Provides declaration of a gsPiecewiseFunction class.
memory::unique_ptr< gsBasis > uPtr
Unique pointer for gsBasis.
Definition: gsBasis.h:89
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78