G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsMappedSingleBasis.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <gsCore/gsBasis.h>
19
20namespace gismo
21{
22
23template<short_t d,class T> class gsMappedBasis;
24
33template<short_t d,class T>
35{
36private:
37 typedef memory::unique_ptr< gsDomainIterator<T> > domainIter;
38 typedef gsBasis<T> Base;
39
40public:
42 typedef memory::shared_ptr< gsMappedSingleBasis > Ptr;
43
45 typedef memory::unique_ptr< gsMappedSingleBasis > uPtr;
46
47private:
49 gsMappedSingleBasis() : m_basis(nullptr) { }
50
51public:
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
74public:
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
209 virtual void evalAllDersSingle_into(index_t i, const gsMatrix<T> & u, int n, std::vector<gsMatrix<T> >& result) const override
210 {
213 }
214
217 void evalDerSingle_into(index_t i, const gsMatrix<T> & u, int n, gsMatrix<T>& result) const
218 {
221 }
222
223 GISMO_CLONE_FUNCTION(gsMappedSingleBasis)
224
225 memory::unique_ptr<gsGeometry<T> > makeGeometry( gsMatrix<T> coefs ) const
226 {
227 GISMO_UNUSED(coefs);
229 }
230
231 std::ostream &print(std::ostream &os) const
232 {
233 GISMO_UNUSED(os);
234 os << "Mapped basis function "<< m_index << " / "<< m_basis->size()-1 <<"\n";
235 return os;
236 }
237
239 std::string detail() const
240 {
241 // By default just uses print(..)
242 std::ostringstream os;
243 print(os);
244 return os.str();
245 }
246
248 // Virtual member that may be implemented or not by the derived class
250
251 index_t size() const
252 {
253 return m_basis->size(m_index);
254 }
255
258 {
259 // TODO Not always working: make it more general
260 return degree();
261 }
262
265 {
266 // TODO Not always working: make it more general
267 return degree();
268 }
269
272 {
273 // TODO Not always working: make it more general
274 return m_basis->maxDegree(); // must fix this (just took max_degree)
275 }
276
279 {
280 return m_basis->degree(m_index,i);
281 }
282
284 bool check() const
285 {
287 }
288
291 void setBasis( unsigned const & i ) const
292 {
293 GISMO_ASSERT( i<unsigned(m_basis->nPatches()),"Invalid basis index" );
294 m_index = i;
295 }
296
297
299 void first() const
300 {
301 m_index = 0;
302 }
303
306 bool next() const
307 {
308 return ( ++m_index < (index_t)m_basis->nPatches() );
309 }
310
313 {
314 // TODO Not always working: make it more general
315 return m_basis->getBase(m_index).component(i);
316 }
317
319 {
320 // TODO Not always working: make it more general
321 // return gsMappedSingleBasisComponent<d-1,T> (this, i);
322 return m_basis->getBase(m_index).component(i);
323 }
324
325 typename gsBasis<T>::domainIter makeDomainIterator() const
326 {
327 // TODO Not always working: make it more general
328 return m_basis->getBase(m_index).makeDomainIterator();
329 }
330
331 typename gsBasis<T>::domainIter makeDomainIterator(const boxSide & s) const
332 {
333 // TODO Not always working: make it more general
334 return m_basis->getBase(m_index).makeDomainIterator(s);
335 }
336
337
339 {
340 std::vector<index_t> temp, rtemp;
341 m_basis->addLocalIndicesOfPatchSide(patchSide(m_index,s),offset,temp);
342 m_basis->getMapper().sourceToTarget(temp,rtemp);
343
344 // Better way for offset one: compute (anchors()) the normal derivatives at the boundary and return the indices
345 if (offset == 1) // Small fix
346 {
347 GISMO_ASSERT(offset==1, "The indices of boundaryOffset(s,1) "
348 "will be substract from boundaryOffset(s,0)");
349
350 std::vector<index_t> diff, temp2, rtemp2;
351
352 m_basis->addLocalIndicesOfPatchSide(patchSide(m_index,s),0,temp2);
353 m_basis->getMapper().sourceToTarget(temp2,rtemp2);
354 // Subtract the indizes of Offset = 0
355 std::set_difference(rtemp.begin(), rtemp.end(), rtemp2.begin(), rtemp2.end(),
356 std::inserter(diff, diff.begin()));
357 rtemp = diff;
358 }
359
360 return makeMatrix<index_t>(rtemp.begin(),rtemp.size(),1 );
361 }
362
363 index_t functionAtCorner(boxCorner const & c) const
364 {
365 index_t cindex = m_basis->getBase(m_index).functionAtCorner(c);
366 cindex = m_basis->_getLocalIndex(m_index,cindex);
367 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?");
368 std::vector<index_t> indices;
369 m_basis->getMapper().sourceToTarget(cindex,indices);
370 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");
371 return indices.front();
372 }
373
374
375// Data members
376private:
377 gsMappedBasis<d,T> * m_basis;
378 mutable index_t m_index;
379
380}; // class gsMappedSingleBasis
381
382#ifdef GISMO_WITH_PYBIND11
383
387 // void pybind11_init_gsMappedSingleBasis1(pybind11::module &m);
388 void pybind11_init_gsMappedSingleBasis2(pybind11::module &m);
389 // void pybind11_init_gsMappedSingleBasis3(pybind11::module &m);
390
391#endif // GISMO_WITH_PYBIND11
392
393} // namespace gismo
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
virtual void evalAllDersSingle_into(index_t i, const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result) const
Evaluate the basis function i and its derivatives up to order n at points u into result.
Definition gsBasis.hpp:494
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
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
Class gsMappedSingleBasis represents an indivisual .....of a.
Definition gsMappedSingleBasis.h:35
virtual void evalAllDersSingle_into(index_t i, const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result) const override
Evaluate the basis function i and its derivatives up to order n at points u into result.
Definition gsMappedSingleBasis.h:209
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
short_t maxDegree() const
Returns the polynomial degree.
Definition gsMappedSingleBasis.h:257
void setBasis(unsigned const &i) const
Definition gsMappedSingleBasis.h:291
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
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
void connectivity(const gsMatrix< T > &nodes, gsMesh< T > &mesh) const
Definition gsMappedSingleBasis.h:81
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:225
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:325
void first() const
Point to the first basis function of the basis.
Definition gsMappedSingleBasis.h:299
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:318
short_t degree(short_t i) const
Returns the polynomial degree.
Definition gsMappedSingleBasis.h:278
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
bool check() const
Check the LagrangeBasis for consistency.
Definition gsMappedSingleBasis.h:284
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the non-zero basis functions at value u.
Definition gsMappedSingleBasis.h:158
index_t size() const
size
Definition gsMappedSingleBasis.h:251
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,...
Definition gsMappedSingleBasis.h:101
std::string detail() const
Prints the object as a string with extended details.
Definition gsMappedSingleBasis.h:239
gsMappedSingleBasis()
Default empty constructor.
Definition gsMappedSingleBasis.h:49
gsMatrix< index_t > boundaryOffset(boxSide const &s, index_t offset) const
Definition gsMappedSingleBasis.h:338
short_t domainDim() const
Dimension of the (source) domain.
Definition gsMappedSingleBasis.h:76
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
gsBasis< T > * boundaryBasis_impl(boxSide const &s) const
Returns the boundary basis on side s.
Definition gsMappedSingleBasis.h:152
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
memory::shared_ptr< gsMappedSingleBasis > Ptr
Shared pointer for gsMappedSingleBasis.
Definition gsMappedSingleBasis.h:42
gsMatrix< T > support() const
Returns a bounding box for the basis' domain.
Definition gsMappedSingleBasis.h:114
bool next() const
Definition gsMappedSingleBasis.h:306
memory::unique_ptr< gsMappedSingleBasis > uPtr
Unique pointer for gsMappedSingleBasis.
Definition gsMappedSingleBasis.h:45
size_t numElements(boxSide const &s=0) const
The number of elements on side s.
Definition gsMappedSingleBasis.h:90
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
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:312
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsMappedSingleBasis.h:231
short_t minDegree() const
Returns the polynomial degree.
Definition gsMappedSingleBasis.h:264
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
static const int Dim
Dimension of the parameter domain.
Definition gsMappedSingleBasis.h:54
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:331
short_t degree() const
Returns the polynomial degree.
Definition gsMappedSingleBasis.h:271
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:217
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
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides declaration of Basis abstract interface.
#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_ENSURE(cond, message)
Definition gsDebug.h:102
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of Basis abstract interface.
Provides declaration of the Mesh class.
The G+Smo namespace, containing all definitions for the library.
Struct which represents a certain corner of a hyper-cube.
Definition gsBoundary.h:292
Struct which represents a certain side of a patch.
Definition gsBoundary.h:232