G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsDofMapper.hpp
Go to the documentation of this file.
1 
14 #include <gsCore/gsMultiBasis.h>
15 
16 namespace gismo
17 {
18 
19 template<class T>
20 void gsDofMapper::init( const gsMultiBasis<T> & bases, index_t nComp)
21 {
22  GISMO_ASSERT(nComp>0,"Zero components");
23  m_shift = m_bshift = 0;
24  m_curElimId = -1;
25  m_numCpldDofs.assign(nComp+1, 1); m_numCpldDofs.front()=0;
26  m_numElimDofs.assign(nComp+1,0);
27  m_offset.clear();
28 
29  const size_t nPatches = bases.nBases();
30 
31  // Initialize offsets and dof holder
32  m_offset.reserve( nPatches );
33  m_offset.push_back(0);
34  for (size_t k = 1; k < nPatches; ++k)
35  m_offset.push_back( m_offset.back() + bases[k-1].size() );
36 
37  m_numFreeDofs.assign(1+nComp,m_offset.back() + bases.back().size()); m_numFreeDofs.front()=0;
38 
39  m_dofs.resize(nComp, std::vector<index_t>(m_numFreeDofs.back(), 0));
40 }
41 
42 template<class T>
43 void gsDofMapper::init( std::vector<const gsMultiBasis<T> *> const & bases)
44 {
45  const index_t numComp = bases.size();
46  m_shift = m_bshift = 0;
47  m_curElimId = -1;
48  m_numCpldDofs.assign(numComp+1,1); m_numCpldDofs.front()=0;
49  m_offset.clear();
50 
51  const size_t nPatches = bases[0]->nBases();
52 
53  //Checking if bases are same size in for components.
54  std::vector<index_t> offsets(nPatches);
55  for (index_t comp = 0; comp < numComp; ++comp)
56  {
57  for (size_t k = 0; k < nPatches; ++k)
58  {
59  if (comp != 0)
60  {
61  GISMO_ASSERT(offsets[k] == bases[comp]->basis(k).size(),
62  "The sizes of the bases are not the same for every component. Dofmapper requries this!");
63  }
64  offsets[k] = bases[comp]->basis(k).size();
65  }
66  }
67 
68  // Initialize offsets and dof holder
69  m_offset.reserve( nPatches );
70  m_offset.push_back(0);
71  for (size_t k = 1; k < nPatches; ++k)
72  m_offset.push_back( m_offset.back() + bases[0]->basis(k-1).size() );
73 
74  if (nPatches == 1)
75  {
76  index_t dofsPatches = 0;
77  for (index_t comp = 0; comp < numComp; ++comp)
78  dofsPatches += bases[comp]->back().size();
79  m_numFreeDofs.assign(numComp+1,m_offset.back() + dofsPatches);
80  m_numFreeDofs.front()=0;
81  }
82  //Assuming each component are of same size;
83  //i.e. bases[comp]->back().size() are equal for all comp
84  else
85  {
86  m_numFreeDofs.assign(numComp+1, (m_offset.back() + bases[0]->back().size())); m_numFreeDofs.front()=0;
87  }
88 
89  m_numElimDofs.assign(numComp+1,0);
90  m_dofs.resize(numComp, std::vector<index_t>(m_numFreeDofs.back(), 0));
91 }
92 
93 template<class T>
95  const gsBoundaryConditions<T> &bc, int unk)
96 {
97  init(basis, 1); //one component
98 
100  for (typename gsBoundaryConditions<T>::const_iterator
101  it = bc.dirichletBegin() ; it != bc.dirichletEnd(); ++it )
102  {
103  if (unk == -1 || it->unknown() == unk) // special value -1 eliminates all BCs found
104  {
105  GISMO_ASSERT(it->ps.patch < static_cast<index_t>(m_offset.size()),
106  "Problem: a boundary condition is set on a patch id which does not exist.");
107 
108  gsMatrix<index_t> bnd = basis[it->ps.patch].boundary(it->ps.side());
109  markBoundary(it->ps.patch, bnd);
110  }
111  }
112 
113  // corners
114  for (typename gsBoundaryConditions<T>::const_citerator
115  it = bc.cornerBegin() ; it != bc.cornerEnd(); ++it )
116  {
117  if (unk == -1 || it->unknown == unk)
118  {
119  GISMO_ASSERT(it->patch < static_cast<index_t>(m_offset.size()),
120  "Problem: a corner boundary condition is set on a patch id which does not exist.");
121 
122  eliminateDof(basis[it->patch].functionAtCorner(it->corner), it->patch);
123  }
124  }
125 }
126 
127 template<class T>
128 void gsDofMapper::initSingle( const gsBasis<T> & basis, index_t nComp)
129 {
130  GISMO_ASSERT(nComp>0,"Zero components");
131  m_shift = m_bshift = 0;
132  m_curElimId = -1;
133  m_numFreeDofs.assign(nComp+1,basis.size()); m_numFreeDofs.front()=0;
134  m_numCpldDofs.assign(nComp+1,1); m_numCpldDofs.front()=0;
135  m_numElimDofs.assign(nComp+1,0);
136  m_offset.resize(1,0);
137  m_dofs.resize(nComp, std::vector<index_t>(m_numFreeDofs.back(), 0));
138 }
139 
140 }//namespace gismo
141 
void init(const gsMultiBasis< T > &bases, index_t nComp=1)
Initialize by a gsMultiBasis.
Definition: gsDofMapper.hpp:20
const_citerator cornerBegin() const
Definition: gsBoundaryConditions.h:561
const_iterator dirichletBegin() const
Definition: gsBoundaryConditions.h:490
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
int size(size_t i) const
The number of basis functions in basis i.
Definition: gsMultiBasis.h:232
Provides declaration of MultiBasis class.
void initSingle(const gsBasis< T > &basis, index_t nComp=1)
Initialize by a single basis patch.
Definition: gsDofMapper.hpp:128
virtual index_t size() const
size
Definition: gsFunctionSet.h:578
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_ASSERT(cond, message)
Definition: gsDebug.h:89
void markBoundary(index_t k, const gsMatrix< index_t > &boundaryDofs, index_t comp=0)
Mark the local dofs boundaryDofs of patch k as eliminated.
Definition: gsDofMapper.cpp:188
Holds a set of patch-wise bases and their topology information.
Definition: gsMultiBasis.h:36
void eliminateDof(index_t i, index_t k, index_t comp=0)
Mark the local dof i of patch k as eliminated.
Definition: gsDofMapper.cpp:214
const_citerator cornerEnd() const
Definition: gsBoundaryConditions.h:566
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
size_t nBases() const
Number of patch-wise bases.
Definition: gsMultiBasis.h:264
std::vector< index_t > m_numElimDofs
Offsets of eliminated dofs, nComp+1.
Definition: gsDofMapper.h:582
const_iterator dirichletEnd() const
Definition: gsBoundaryConditions.h:495
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78