23 #define MAPPER_PATCH_DOF(a,b,c) m_dofs[c][m_offset[b]+a]
89 ) : m_shift(0), m_bshift(0)
91 init(bases, dirichlet, unk);
130 initSingle(basis, nComp);
141 initPatchDofs(patchDofSizes, nComp);
145 template <
typename T>
149 template <
typename T>
160 m_dofs .swap(other.m_dofs);
163 std::swap(m_shift , other.
m_shift);
164 std::swap(m_bshift , other.
m_bshift);
168 std::swap(m_curElimId , other.m_curElimId);
169 std::swap(m_tagged , other.
m_tagged);
175 template <
typename T>
176 void initSingle(
const gsBasis<T> & basis,
index_t nComp = 1);
179 void initPatchDofs(
const gsVector<index_t> & patchDofSizes,
185 gsVector<index_t> asVector(
index_t comp = 0)
const;
191 gsVector<index_t> inverseAsVector(
index_t comp = 0)
const;
195 void setMatchingInterfaces(
const gsBoxTopology & mp);
202 void colapseDofs(
index_t k,
const gsMatrix<unsigned> & b,
index_t comp = 0);
211 void matchDofs(
index_t u,
const gsMatrix<index_t> & b1,
212 index_t v,
const gsMatrix<index_t> & b2,
222 void markCoupledAsTagged();
226 void markBoundary(
index_t k,
const gsMatrix<index_t> & boundaryDofs,
index_t comp = 0);
239 bool isPermutation()
const {
return static_cast<size_t>(size())==mapSize(); }
242 std::ostream& print( std::ostream& os =
gsInfo )
const;
245 void setIdentity(
index_t nPatches,
size_t nDofs,
size_t nComp = 1);
262 {
return m_numFreeDofs[comp] + m_numElimDofs[comp] + m_shift; }
268 void setBoundaryShift(
index_t shift);
302 GISMO_ASSERT(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
303 return MAPPER_PATCH_DOF(i,k,c);
308 GISMO_ASSERT(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
313 return (gl<m_numFreeDofs.back() ?
314 std::distance(m_numFreeDofs.begin(), std::upper_bound(m_numFreeDofs.begin(), m_numFreeDofs.end(), gl))
315 : std::
distance(m_numElimDofs.begin(),std::upper_bound(m_numElimDofs.begin(), m_numElimDofs.end(), gl-m_numFreeDofs.back())) ) - 1;
327 GISMO_ASSERT(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
328 return MAPPER_PATCH_DOF(i,k,c)+m_shift;
336 GISMO_ASSERT(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
337 return MAPPER_PATCH_DOF(i,k,c) - m_numFreeDofs.back()
344 {
return m_numFreeDofs.back()+m_numElimDofs.back()==m_curElimId; }
349 GISMO_ASSERT(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
350 return MAPPER_PATCH_DOF(i,k,c) - m_numFreeDofs[c+1]
351 + m_numCpldDofs[c+1];
357 GISMO_ASSERT(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
358 return std::distance(m_tagged.begin(),std::lower_bound(m_tagged.begin(),m_tagged.end(),MAPPER_PATCH_DOF(i,k,c)));
367 "global_to_bindex(): dof "<<gl<<
" is not on the boundary");
368 return gl - m_numFreeDofs.back() - m_shift + m_bshift;
378 return gl < m_curElimId + m_shift;
383 {
return is_free_index( index(i, k, c) ); }
387 {
return gl >= m_numFreeDofs.back() + m_shift; }
391 {
return is_boundary_index( index(i, k, c) );}
395 {
return is_coupled_index( index(i, k, c) ); }
400 const index_t gc = componentOf(gl);
401 const index_t vv = m_numFreeDofs[gc+1] + m_shift;
403 (gl + m_numCpldDofs[gc+1] + 1 > vv) );
408 {
return is_tagged_index( index(i, k, c) ); }
413 return std::binary_search(m_tagged.begin(),m_tagged.end(),gl);
418 {
return static_cast<index_t>(m_dofs.size()); }
423 GISMO_ENSURE(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
424 return freeSize() + boundarySize();
430 GISMO_ENSURE(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
431 return m_numFreeDofs[comp+1]-m_numFreeDofs[comp]
432 + m_numElimDofs[comp+1]-m_numElimDofs[comp];
443 return m_numFreeDofs[comp+1]-m_numFreeDofs[comp] +
444 (allFree() ? m_numElimDofs[comp+1]-m_numElimDofs[comp] : 0 );
448 const std::vector<index_t> &
getTagged()
const {
return m_tagged; }
459 GISMO_ENSURE(m_curElimId>=0,
"finalize() was not called on gsDofMapper");
460 return m_numElimDofs.back();
463 index_t boundarySizeWithDuplicates()
const;
466 size_t offset(
int k)
const {
return m_offset[k];}
474 {
return (m_dofs.empty()?0:m_dofs.size() * m_dofs.front().size()); }
476 size_t componentsSize()
const {
return m_dofs.size();}
482 const size_t k1(k+1);
483 GISMO_ASSERT(k1<=numPatches(),
"Invalid patch index "<< k <<
" >= "<< numPatches() );
484 if ( 1==m_offset.size() )
return m_dofs[c].size();
485 else if ( k1==m_offset.size() )
return (m_dofs[c].size() - m_offset.back());
486 else return (m_offset[k1]-m_offset[k]);
489 size_t totalSize(
const index_t c = 0)
const
491 return m_dofs[c].size();
497 void preImage(
index_t gl, std::vector<std::pair<index_t,index_t> > & result)
const;
501 std::pair<index_t,index_t> anyPreImage(
index_t gl)
const;
505 std::vector<std::pair<index_t,index_t> > anyPreImages(
index_t comp = 0)
const;
509 std::map<index_t,index_t> inverseOnPatch(
const index_t k)
const;
520 return m_dofs[n/m_dofs.front().size()]
521 [n%m_dofs.front().size()] + m_shift;
541 template<
class Predicate,
class Iterator>
542 static gsVector<index_t> find_impl(Iterator istart, Iterator iend, Predicate pred);
544 void finalizeComp(
const index_t comp);
568 std::vector<std::vector<index_t> > m_dofs;
596 inline std::ostream& operator<<( std::ostream& os,
const gsDofMapper& b )
598 return b.
print( os );
601 #ifdef GISMO_WITH_PYBIND11
606 void pybind11_init_gsDofMapper(pybind11::module &m);
608 #endif // GISMO_WITH_PYBIND11
613 #ifndef GISMO_BUILD_LIB
614 #include GISMO_HPP_HEADER(gsDofMapper.hpp)
index_t boundarySize() const
Returns the number of eliminated dofs.
Definition: gsDofMapper.h:457
index_t size(index_t comp) const
Returns the total number of dofs (free and eliminated).
Definition: gsDofMapper.h:428
size_t mapSize() const
Returns the total number of patch-local degrees of freedom that are being mapped. ...
Definition: gsDofMapper.h:473
T distance(gsMatrix< T > const &A, gsMatrix< T > const &B, index_t i=0, index_t j=0, bool cols=false)
compute a distance between the point number in the set and the point number <j> in the set ; by def...
size_t offset(int k) const
Returns the offset corresponding to patch k.
Definition: gsDofMapper.h:466
std::vector< size_t > m_offset
Offsets.
Definition: gsDofMapper.h:571
std::vector< index_t > m_numCpldDofs
Offsets of coupled dofs, nComp+1.
Definition: gsDofMapper.h:584
gsDofMapper(std::vector< const gsMultiBasis< T > * > const &bases)
construct a dof mapper that identifies the degrees of freedom for a vector of multibasis ...
Definition: gsDofMapper.h:113
index_t freeIndex(index_t i, index_t k=0, index_t c=0) const
Returns the index associated to local dof i of patch k without shifts.
Definition: gsDofMapper.h:300
Provides structs and classes related to interfaces and boundaries.
std::vector< index_t > m_tagged
Stores the tagged indices.
Definition: gsDofMapper.h:591
bool is_tagged_index(index_t gl) const
Returns true if gl is a tagged dof.
Definition: gsDofMapper.h:411
bool is_coupled_index(index_t gl) const
Returns true if gl is a coupled dof.
Definition: gsDofMapper.h:398
bool is_free(index_t i, index_t k=0, index_t c=0) const
Returns true if local dof i of patch k is not eliminated.
Definition: gsDofMapper.h:382
gsDofMapper(const gsMultiBasis< T > &bases, index_t nComp=1)
construct a dof mapper that identifies the degrees of freedom in the multibasis
Definition: gsDofMapper.h:101
index_t lastIndex() const
Returns one past the biggest value of the free indices.
Definition: gsDofMapper.h:265
index_t m_shift
Shifting of the global index (zero by default)
Definition: gsDofMapper.h:574
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individ...
Definition: gsDofMapper.h:68
Handles shared library creation and other class attributes.
index_t cindex(index_t i, index_t k=0, index_t c=0) const
Returns the coupled dof index.
Definition: gsDofMapper.h:347
index_t index(index_t i, index_t k=0, index_t c=0) const
Returns the global dof index associated to local dof i of patch k.
Definition: gsDofMapper.h:325
index_t global_to_bindex(index_t gl) const
Returns the boundary index of global dof gl.
Definition: gsDofMapper.h:364
bool is_free_index(index_t gl) const
Returns true if global dof gl is not eliminated.
Definition: gsDofMapper.h:376
const std::vector< index_t > & getTagged() const
Returns the vector of tagged (not eliminated) dofs.
Definition: gsDofMapper.h:448
bool is_boundary_index(index_t gl) const
Returns true if global dof gl is eliminated.
Definition: gsDofMapper.h:386
Holds a set of patch-wise bases and their topology information.
Definition: gsMultiBasis.h:36
gsDofMapper(const gsVector< index_t > &patchDofSizes, index_t nComp=1)
construct a dof mapper with a given number of dofs per patch
Definition: gsDofMapper.h:139
index_t tindex(index_t i, index_t k=0, index_t c=0) const
Returns the tagged dof index.
Definition: gsDofMapper.h:355
bool allFree() const
Returns true iff all DoFs are considered as free.
Definition: gsDofMapper.h:343
#define gsInfo
Definition: gsDebug.h:43
Provides forward declarations of types and structs.
bool is_boundary(index_t i, index_t k=0, index_t c=0) const
Returns true if local dof i of patch k is eliminated.
Definition: gsDofMapper.h:390
bool is_tagged(index_t i, index_t k=0, index_t c=0) const
Returns true if local dof i of patch k is tagged.
Definition: gsDofMapper.h:407
index_t bindex(index_t i, index_t k=0, index_t c=0) const
Returns the boundary index of local dof i of patch k.
Definition: gsDofMapper.h:334
size_t patchSize(const index_t k, const index_t c=0) const
Returns the total number of patch-local DoFs that live on patch k for component c.
Definition: gsDofMapper.h:480
size_t numPatches() const
Returns the number of patches present underneath the mapper.
Definition: gsDofMapper.h:469
index_t m_bshift
Shifting of the boundary index (zero by default)
Definition: gsDofMapper.h:577
Class containing a set of boundary conditions.
Definition: gsBoundaryConditions.h:341
index_t size() const
Returns the total number of dofs (free and eliminated).
Definition: gsDofMapper.h:421
std::vector< index_t > m_numFreeDofs
Offsets of free dofs, nComp+1.
Definition: gsDofMapper.h:580
std::vector< index_t > m_numElimDofs
Offsets of eliminated dofs, nComp+1.
Definition: gsDofMapper.h:582
index_t numComponents() const
Returns the number of components present in the mapper.
Definition: gsDofMapper.h:417
bool isFinalized() const
Checks whether finalize() has been called.
Definition: gsDofMapper.h:236
index_t freeSize() const
Returns the number of free (not eliminated) dofs.
Definition: gsDofMapper.h:436
std::ostream & print(std::ostream &os=gsInfo) const
Print summary.
Definition: gsDofMapper.cpp:346
bool is_coupled(index_t i, index_t k=0, index_t c=0) const
Returns true if local dof i of patch k is coupled.
Definition: gsDofMapper.h:394
gsDofMapper(const gsMultiBasis< T > &bases, const gsBoundaryConditions< T > &dirichlet, int unk=0)
construct a dof mapper that identifies the degrees of freedom in the multibasis and eliminates the de...
Definition: gsDofMapper.h:85
bool isPermutation() const
Returns true iff the mapper is a permuatation.
Definition: gsDofMapper.h:239
index_t mapIndex(index_t n) const
For n being an index which is already offsetted, it returns the global index where it is mapped to by...
Definition: gsDofMapper.h:518
index_t firstIndex(index_t comp=0) const
Returns the smallest value of the indices for comp.
Definition: gsDofMapper.h:261
gsDofMapper(const gsBasis< T > &basis, index_t nComp=1)
construct a dof mapper that manages the degrees of freedom in a gsBasis
Definition: gsDofMapper.h:128
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78