G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsDofMapper Class Reference

Detailed Description

Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individual dofs.

A dof (degree of freedom) is, roughly speaking, an unknown in a discretization of a PDE. However, some dofs may be eliminated before solving the system and won't actually translate into unknowns. An example are dofs on Dirichlet boundaries.

This class creates a mapping between an arbitrary number of per-patch local dofs to an enumeration of global dofs. Furthermore, dofs can also be marked as eliminated.

This is a a many-to-one mapping: many patch-local dofs are mapped to a single global dfo (index). Every global dof gets a unique number, forming a continuous range starting from 0. This range has length gsDofMapper::size(). The dofs are numbered in the following order:

  • first the standard free (non-eliminated) dofs, ie. dofs that are not coupled on the boundary. For the standard dofs there is unique pre-image pair (patch,localdof).
  • then the free dofs which are coupled with other dofs For the coupled dofs there is a list of pre-image pairs of the form (patch,localdof).

    Upto here we get all the dofs which are free (number: gsDofMapper::freeSize() ). Then a final group follows:

  • then the dofs that are on Dirichlet boundaries (number: gsDofMapper::boundarySize()). These dofs might have a unique pre-image or not.

The boundary (eg. eliminated) dofs have their own 0-based numbering. The index of an boundary global dof in this numbering can be queried with gsDofMapper::bindex().

The object must be finalized before it is used, i.e. gsDofMapper::finalize() has to be called once before use.

Public Member Functions

void addShift (index_t shift)
 Add a shift amount to the global numbering.
 
bool allFree () const
 Returns true iff all DoFs are considered as free.
 
std::pair< index_t, index_tanyPreImage (index_t gl) const
 For gl being a global index, this function returns a pair (patch,dof) that maps to gl.
 
std::vector< std::pair< index_t, index_t > > anyPreImages (index_t comp=0) const
 For all global index, this function assigns a pair (patch,dof) that maps to that global index.
 
gsVector< index_tasVector (index_t comp=0) const
 Returns a vector taking flat local indices to global.
 
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.
 
index_t boundarySize () const
 Returns the number of eliminated dofs.
 
index_t cindex (index_t i, index_t k=0, index_t c=0) const
 Returns the coupled dof index.
 
void colapseDofs (index_t k, const gsMatrix< unsigned > &b, index_t comp=0)
 Calls matchDof() for all dofs on the given patch side i ps. Thus, the whole set of dofs collapses to a single global dof.
 
index_t coupledSize () const
 Returns the number of coupled (not eliminated) dofs.
 
void eliminateDof (index_t i, index_t k, index_t comp=0)
 Mark the local dof i of patch k as eliminated.
 
void finalize ()
 Must be called after all boundaries and interfaces have been marked to set up the dof numbering.
 
gsVector< index_tfindBoundary (const index_t k) const
 Returns all boundary dofs on patch k (local dof indices)
 
gsVector< index_tfindCoupled (const index_t k, const index_t j=-1) const
 Returns all coupled dofs on patch k (local dof indices)
 
gsVector< index_tfindFree (const index_t k) const
 Returns all free dofs on patch k (local dof indices)
 
gsVector< index_tfindFreeUncoupled (const index_t k) const
 Returns all free, not coupled dofs on patch k (local dof indices)
 
gsVector< index_tfindTagged (const index_t k) const
 Returns all tagged dofs on patch k (local dof indices)
 
index_t firstIndex (index_t comp=0) const
 Returns the smallest value of the indices for comp.
 
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.
 
index_t freeSize () const
 Returns the number of free (not eliminated) dofs.
 
const std::vector< index_t > & getTagged () const
 Returns the vector of tagged (not eliminated) dofs.
 
index_t global_to_bindex (index_t gl) const
 Returns the boundary index of global dof gl.
 
 gsDofMapper ()
 Default empty constructor.
 
template<class T >
 gsDofMapper (const gsBasis< T > &basis, index_t nComp=1)
 construct a dof mapper that manages the degrees of freedom in a gsBasis
 
template<class T >
 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 degrees of freedom on the Dirichlet boundary
 
template<class T >
 gsDofMapper (const gsMultiBasis< T > &bases, index_t nComp=1)
 construct a dof mapper that identifies the degrees of freedom in the multibasis
 
 gsDofMapper (const gsVector< index_t > &patchDofSizes, index_t nComp=1)
 construct a dof mapper with a given number of dofs per patch
 
template<class T >
 gsDofMapper (std::vector< const gsMultiBasis< T > * > const &bases)
 construct a dof mapper that identifies the degrees of freedom for a vector of multibasis
 
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.
 
bool indexOnPatch (const index_t gl, const index_t k) const
 For gl being a global index, this function returns true whenever gl corresponds to patch k.
 
template<typename T >
void init (const gsMultiBasis< T > &bases, index_t nComp=1)
 Initialize by a gsMultiBasis.
 
template<class T >
void init (const gsMultiBasis< T > &basis, const gsBoundaryConditions< T > &dirichlet, int unk=0)
 
template<typename T >
void init (std::vector< const gsMultiBasis< T > * > const &bases)
 Initialize by a vector of gsMultiBasis.
 
gsVector< index_tinverseAsVector (index_t comp=0) const
 Returns a vector taking global indices to flat local.
 
std::map< index_t, index_tinverseOnPatch (const index_t k) const
 Produces the inverse of the mapping on patch k assuming that the map is invertible on that patch.
 
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.
 
bool is_boundary_index (index_t gl) const
 Returns true if global dof gl is eliminated.
 
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.
 
bool is_coupled_index (index_t gl) const
 Returns true if gl is a coupled dof.
 
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.
 
bool is_free_index (index_t gl) const
 Returns true if global dof gl is not eliminated.
 
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.
 
bool is_tagged_index (index_t gl) const
 Returns true if gl is a tagged dof.
 
bool isFinalized () const
 Checks whether finalize() has been called.
 
bool isPermutation () const
 Returns true iff the mapper is a permuatation.
 
index_t lastIndex () const
 Returns one past the biggest value of the free indices.
 
void localToGlobal (const gsMatrix< index_t > &locals, index_t patchIndex, gsMatrix< index_t > &globals, index_t comp=0) const
 Computes the global indices of the input local indices.
 
void localToGlobal2 (const gsMatrix< index_t > &locals, index_t patchIndex, gsMatrix< index_t > &globals, index_t &numFree, index_t comp=0) const
 Computes the global indices of the input local indices.
 
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 the dof mapper.
 
size_t mapSize () const
 Returns the total number of patch-local degrees of freedom that are being mapped.
 
void markBoundary (index_t k, const gsMatrix< index_t > &boundaryDofs, index_t comp=0)
 Mark the local dofs boundaryDofs of patch k as eliminated.
 
void markCoupled (index_t i, index_t k, index_t comp=0)
 Mark the local dof i of patch k as coupled.
 
void markCoupledAsTagged ()
 Mark all coupled dofs as tagged.
 
void markTagged (index_t i, index_t k, index_t comp=0)
 Mark a local dof i of patch k as tagged.
 
void matchDof (index_t u, index_t i, index_t v, index_t j, index_t comp=0)
 Couples dof i of patch u with dof j of patch v such that they refer to the same global dof at component comp.
 
void matchDofs (index_t u, const gsMatrix< index_t > &b1, index_t v, const gsMatrix< index_t > &b2, index_t comp=0)
 Couples dofs b1 of patch u with dofs b2 of patch v one by one such that they refer to the same global dof.
 
index_t numComponents () const
 Returns the number of components present in the mapper.
 
size_t numPatches () const
 Returns the number of patches present underneath the mapper.
 
size_t offset (int k) const
 Returns the offset corresponding to patch k.
 
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.
 
void permuteFreeDofs (const gsVector< index_t > &permutation, index_t comp=0)
 Permutes the mapped free indices according to permutation, i.e., dofs_perm[idx] = dofs_old[permutation[idx]].
 
void preImage (index_t gl, std::vector< std::pair< index_t, index_t > > &result) const
 For gl being a global index, this function returns a vector of pairs (patch,dof) that contains all the pairs which map to gl.
 
std::ostream & print (std::ostream &os=gsInfo) const
 Print summary.
 
void setBoundaryShift (index_t shift)
 Set the shift amount for the boundary numbering.
 
void setIdentity (index_t nPatches, size_t nDofs, size_t nComp=1)
 Set this mapping to be the identity.
 
void setMatchingInterfaces (const gsBoxTopology &mp)
 
void setShift (index_t shift)
 Set the shift amount for the global numbering.
 
index_t size () const
 Returns the total number of dofs (free and eliminated).
 
index_t size (index_t comp) const
 Returns the total number of dofs (free and eliminated).
 
index_t taggedSize () const
 Returns the number of tagged dofs.
 
index_t tindex (index_t i, index_t k=0, index_t c=0) const
 Returns the tagged dof index.
 

Private Member Functions

void initPatchDofs (const gsVector< index_t > &patchDofSizes, index_t nComp=1)
 Initialize by vector of DoF indices and dimension.
 
template<typename T >
void initSingle (const gsBasis< T > &basis, index_t nComp=1)
 Initialize by a single basis patch.
 

Private Attributes

index_t m_bshift
 Shifting of the boundary index (zero by default)
 
std::vector< index_tm_numCpldDofs
 Offsets of coupled dofs, nComp+1.
 
std::vector< index_tm_numElimDofs
 Offsets of eliminated dofs, nComp+1.
 
std::vector< index_tm_numFreeDofs
 Offsets of free dofs, nComp+1.
 
std::vector< size_t > m_offset
 Offsets.
 
index_t m_shift
 Shifting of the global index (zero by default)
 
std::vector< index_tm_tagged
 Stores the tagged indices.
 

Constructor & Destructor Documentation

◆ gsDofMapper() [1/5]

template<class T >
gsDofMapper ( const gsMultiBasis< T > &  bases,
const gsBoundaryConditions< T > &  dirichlet,
int  unk = 0 
)
inline

construct a dof mapper that identifies the degrees of freedom in the multibasis and eliminates the degrees of freedom on the Dirichlet boundary

Parameters
bases
dirichlet
unk

◆ gsDofMapper() [2/5]

template<class T >
gsDofMapper ( const gsMultiBasis< T > &  bases,
index_t  nComp = 1 
)
inline

construct a dof mapper that identifies the degrees of freedom in the multibasis

Parameters
bases

◆ gsDofMapper() [3/5]

template<class T >
gsDofMapper ( std::vector< const gsMultiBasis< T > * > const &  bases)
inline

construct a dof mapper that identifies the degrees of freedom for a vector of multibasis

Parameters
bases

◆ gsDofMapper() [4/5]

template<class T >
gsDofMapper ( const gsBasis< T > &  basis,
index_t  nComp = 1 
)
inline

construct a dof mapper that manages the degrees of freedom in a gsBasis

Parameters
basis

◆ gsDofMapper() [5/5]

gsDofMapper ( const gsVector< index_t > &  patchDofSizes,
index_t  nComp = 1 
)
inline

construct a dof mapper with a given number of dofs per patch

Parameters
patchDofSizes

Member Function Documentation

◆ bindex()

index_t bindex ( index_t  i,
index_t  k = 0,
index_t  c = 0 
) const
inline

Returns the boundary index of local dof i of patch k.

Produces undefined results if local dof (i,k) does not lie on the boundary.

◆ freeIndex()

index_t freeIndex ( index_t  i,
index_t  k = 0,
index_t  c = 0 
) const
inline

Returns the index associated to local dof i of patch k without shifts.

Note
This method only works after all interfaces and boundaries have been marked and finalize() has been called.

◆ global_to_bindex()

index_t global_to_bindex ( index_t  gl) const
inline

Returns the boundary index of global dof gl.

Produces undefined results if dof gl does not lie on the boundary.

◆ index()

index_t index ( index_t  i,
index_t  k = 0,
index_t  c = 0 
) const
inline

Returns the global dof index associated to local dof i of patch k.

Note
This method only works after all interfaces and boundaries have been marked and finalize() has been called.

◆ init()

template<class T >
void init ( const gsMultiBasis< T > &  basis,
const gsBoundaryConditions< T > &  dirichlet,
int  unk = 0 
)

Initialize by gsMultiBasis, boundary conditions and the index of the unknown to be eliminated

Todo:
move this code to gsMultiBasis::getMapper

◆ inverseAsVector()

gsVector< index_t > inverseAsVector ( index_t  comp = 0) const

Returns a vector taking global indices to flat local.

Assumes that the mapper is a permutation

◆ localToGlobal()

void localToGlobal ( const gsMatrix< index_t > &  locals,
index_t  patchIndex,
gsMatrix< index_t > &  globals,
index_t  comp = 0 
) const

Computes the global indices of the input local indices.

Parameters
[in]localsa column matrix with the local indices
[in]patchIndexthe index of the patch where the local indices belong to
[out]globalsthe global indices of the patch

◆ localToGlobal2()

void localToGlobal2 ( const gsMatrix< index_t > &  locals,
index_t  patchIndex,
gsMatrix< index_t > &  globals,
index_t numFree,
index_t  comp = 0 
) const

Computes the global indices of the input local indices.

Parameters
[in]localsa column matrix with the local indices
[in]patchIndexthe index of the patch where the local indices belong to
[out]globalsthe local-global correspondance
[out]numFreethe number of free indices in local

◆ permuteFreeDofs()

void permuteFreeDofs ( const gsVector< index_t > &  permutation,
index_t  comp = 0 
)

Permutes the mapped free indices according to permutation, i.e., dofs_perm[idx] = dofs_old[permutation[idx]].

Warning
Applying a permutation makes the functions regarding coupled dofs (cindex, is_coupled_index,.. ) invalid. The dofs are still coupled, but you have no way of extracting them. If you need this functions, first call markCoupledAsTagged() and then use the corresponding functions for tagged dofs.

◆ setMatchingInterfaces()

void setMatchingInterfaces ( const gsBoxTopology mp)

Called to initialize the gsDofMapper with matching interfaces after m_bases have already been set