G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsMappedBasis.h
Go to the documentation of this file.
1
14#pragma once
15
17#include <gsCore/gsMultiPatch.h>
18
23#include <gsCore/gsBasisFun.h>
24
25namespace gismo
26{
27
28// forward declarations of the mapper classes
29template<short_t d,class T> class gsMappedSingleBasis;
30
31template<short_t d,class T>
32class gsMappedBasis : public gsFunctionSet<T>
33{
34 friend class gsMappedSingleBasis<d,T>;
35
36private:
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
51public:
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
92public:
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
128public:
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
171private:
173 void addLocalIndicesOfPatchSide(const patchSide& ps,index_t offset,std::vector<index_t>& locals) const;
174
175public:
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
230private:
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
244public:
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,std::vector<gsMatrix<T> >& result) const;
343
345
347 std::ostream &print(std::ostream &os) const;
348
349public:
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
384 index_t getGlobalIndex(index_t patch, index_t localIndex);
385
390 gsMatrix<index_t> getGlobalIndex(index_t patch, gsMatrix<index_t> localIndices);
391
392protected:
394 // functions for working with Indexes
396
402 index_t _getPatch(index_t const localIndex) const;
403
409 index_t _getPatchIndex(const index_t localIndex) const;
410
417 index_t _getLocalIndex(index_t const patch,index_t const patchIndex) const
418 { return _getFirstLocalIndex(patch)+patchIndex; }
419
425 index_t _getFirstLocalIndex(index_t const patch) const;
426
432 index_t _getLastLocalIndex(index_t const patch) const
433 { return _getFirstLocalIndex(patch)+m_bases[patch]->size()-1; }
434
435 // Data members
436protected:
438 gsBoxTopology m_topol;
439
441 std::vector<BasisType *> m_bases;
442
444 gsWeightMapper<T> * m_mapper;
445 // gsSparseMatrix<T> r:C, c:B
446
448 mutable std::vector<gsMappedSingleBasis<d,T> > m_sb;
449
450 // Make gsMultiBasis a member instead of m_bases and m_topol?
451};
452
453#ifdef GISMO_WITH_PYBIND11
454
458 // void pybind11_init_gsMappedBasis1(pybind11::module &m);
459 void pybind11_init_gsMappedBasis2(pybind11::module &m);
460 // void pybind11_init_gsMappedBasis3(pybind11::module &m);
461
462#endif // GISMO_WITH_PYBIND11
463
464}
465
466#ifndef GISMO_BUILD_LIB
467#include GISMO_HPP_HEADER(gsMappedBasis.hpp)
468#endif
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
Provides definition of the BasisFun class.
Provides declaration of the BoxTopology class.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of DomainIterator abstract interface.
Implementation of a piece of the gsMappedBasis.
Provides declaration of the MultiPatch class.
Provides declaration of a gsPiecewiseFunction class.
Provides declaration of gsWeightMapper class.
The G+Smo namespace, containing all definitions for the library.
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
gsEigen::PermutationMatrix< Dynamic, Dynamic, index_t > gsPermutationMatrix
reorderMapperTarget permutes the target indices of mapper according to permutation....
Definition gsWeightMapperUtils.h:36
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition gsMemory.h:312