G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsBaseAssembler.hpp
Go to the documentation of this file.
1 
15 #pragma once
16 
18 
19 namespace gismo
20 {
21 
22 template <class T>
24  const std::vector<gsMatrix<T> > & fixedDoFs,
25  gsMultiPatch<T> & result,
26  const gsVector<index_t> & unknowns) const
27 {
28  result.clear();
29  GISMO_ENSURE(unknowns.rows() > 0, "No unknowns provided!");
30  index_t nRhs = m_system.rhs().cols();
31  index_t idx;
32  for (size_t p = 0; p < m_pde_ptr->domain().nPatches(); ++p)
33  {
34  index_t size = m_bases[unknowns[0]][p].size();
35  // check that all unknowns have the same basis size
36  for (index_t i = 1; i < unknowns.rows(); ++i)
37  {
38  GISMO_ENSURE(m_bases[unknowns[i]][p].size() == size,"Unknowns do not have the same size!");
39  }
40  gsMatrix<T> coeffs(size,unknowns.rows()*nRhs);
41  for (index_t unk = 0; unk < unknowns.rows(); ++unk)
42  for (index_t i = 0; i < size; ++i)
43  if (m_system.colMapper(unknowns[unk]).is_free(i,p)) // DoF is in the solVector
44  {
45  m_system.mapToGlobalColIndex(i,p,idx,unknowns[unk]);
46  coeffs.block(i,unk*nRhs,1,nRhs) = solVector.block(idx,0,1,nRhs);
47  }
48  else // DoF is eliminated; it is the Dirichlet Dofs
49  {
50  idx = m_system.colMapper(unknowns[unk]).bindex(i, p);
51  coeffs.block(i,unk*nRhs,1,nRhs) = fixedDoFs[unknowns[unk]].block(idx,0,1,nRhs);
52  }
53  result.addPatch(m_bases[unknowns[0]][p].makeGeometry(give(coeffs)));
54  }
55 }
56 
57 //--------------------- DIRICHLET BC SHENANIGANS ----------------------------------//
58 
59 
60 template <class T>
61 void gsBaseAssembler<T>::setFixedDofs(index_t patch, boxSide side, const gsMatrix<T> & ddofs, bool oneUnk)
62 {
63  bool dirBcExists = false;
64  typename gsBoundaryConditions<T>::const_iterator it = m_pde_ptr->bc().dirichletBegin();
65  while (!dirBcExists && it != m_pde_ptr->bc().dirichletEnd())
66  {
67  if (it->patch() == patch && it->side() == side)
68  dirBcExists = true;
69  ++it;
70  }
71  GISMO_ENSURE(dirBcExists,"Side " + util::to_string(side) + " of patch " + util::to_string(patch)
72  + " does not belong to the Dirichlet boundary.");
73 
74  gsMatrix<index_t> localBIndices = m_bases[0][patch].boundary(side);
75  GISMO_ENSURE(localBIndices.rows() == ddofs.rows(),
76  "Wrong size of a given matrix with Dirichlet DoFs: " + util::to_string(ddofs.rows()) +
77  ". Must be:" + util::to_string(localBIndices.rows()));
78 
79  if (oneUnk)
80  {
81  gsMatrix<index_t> globalIndices;
82  m_system.mapColIndices(localBIndices, patch, globalIndices, 0);
83  for (index_t i = 0; i < globalIndices.rows(); ++i)
84  m_ddof[0].row(m_system.colMapper(0).global_to_bindex(globalIndices(i,0))) = ddofs.row(i);
85  }
86  else
87  {
88  gsMatrix<index_t> globalIndices;
89  for (short_t d = 0; d < ddofs.cols(); ++d )
90  {
91  m_system.mapColIndices(localBIndices, patch, globalIndices, d);
92  for (index_t i = 0; i < globalIndices.rows(); ++i)
93  m_ddof[d](m_system.colMapper(d).global_to_bindex(globalIndices(i,0)),0) = ddofs(i,d);
94  }
95  }
96 }
97 
98 template <class T>
99 void gsBaseAssembler<T>::setFixedDofs(const std::vector<gsMatrix<T> > & ddofs)
100 {
101  GISMO_ENSURE(ddofs.size() >= m_ddof.size(), "Wrong size of the container with fixed DoFs: " + util::to_string(ddofs.size()) +
102  ". Must be at least: " + util::to_string(m_ddof.size()));
103 
104  for (short_t d = 0; d < (short_t)(m_ddof.size()); ++d)
105  {
106  GISMO_ENSURE(m_ddof[d].rows() == ddofs[d].rows(),"Wrong number of fixed DoFs for " + util::to_string(d) + "component: " +
107  util::to_string(ddofs[d].rows()) + ". Must be: " + util::to_string(m_ddof[d].rows()));
108  m_ddof[d] = ddofs[d];
109  }
110 }
111 
112 template <class T>
114 {
115  bool dirBcExists = false;
116  typename gsBoundaryConditions<T>::const_iterator it = m_pde_ptr->bc().dirichletBegin();
117  while (!dirBcExists && it != m_pde_ptr->bc().dirichletEnd())
118  {
119  if (it->patch() == patch && it->side() == side)
120  dirBcExists = true;
121  ++it;
122  }
123  GISMO_ENSURE(dirBcExists,"Side " + util::to_string(side) + " of patch " + util::to_string(patch)
124  + " does not belong to the Dirichlet boundary.");
125 
126  short_t m_dim = m_pde_ptr->domain().targetDim();
127  gsMatrix<index_t> localBIndices = m_bases[0][patch].boundary(side);
128  ddofs.clear();
129  ddofs.resize(localBIndices.rows(),m_dim);
130  gsMatrix<index_t> globalIndices;
131  for (short_t d = 0; d < m_dim; ++d )
132  {
133  m_system.mapColIndices(localBIndices, patch, globalIndices, d);
134 
135  for (index_t i = 0; i < globalIndices.rows(); ++i)
136  ddofs(i,d) = m_ddof[d](m_system.colMapper(d).global_to_bindex(globalIndices(i,0)),0);
137  }
138 
139 }
140 
141 template <class T>
143 {
144  index_t nFixedDofs = 0;
145  for (size_t i = 0; i < m_ddof.size(); ++i)
146  nFixedDofs += m_ddof[i].rows();
147  return nFixedDofs;
148 }
149 
150 template <class T>
152 {
153  // allocate a vector of fixed degrees of freedom
154  gsMatrix<T> fixedDofs(numFixedDofs(),m_system.rhs().cols());
155  // from a vector of fixed degrees of freedom
156  index_t nFixedDofs = 0;
157  for (size_t i = 0; i < m_ddof.size(); ++i)
158  {
159  fixedDofs.middleRows(nFixedDofs,m_ddof[i].rows()) = m_ddof[i];
160  nFixedDofs += m_ddof[i].rows();
161  }
162  // eliminate fixed degrees of freedom
163  m_system.rhs() = rhsWithZeroDDofs - eliminationMatrix*fixedDofs;
164 }
165 
166 }// namespace gismo ends
index_t addPatch(typename gsGeometry< T >::uPtr g)
Add a patch from a gsGeometry&lt;T&gt;::uPtr.
Definition: gsMultiPatch.hpp:210
void clear()
Clear (delete) all patches.
Definition: gsMultiPatch.h:319
#define short_t
Definition: gsConfig.h:35
virtual void constructSolution(const gsMatrix< T > &solVector, const std::vector< gsMatrix< T > > &fixedDDofs, gsMultiPatch< T > &result, const gsVector< index_t > &unknowns) const
Constructs solution as a gsMultiPatch object from the solution vector and fixed DoFs.
Definition: gsBaseAssembler.hpp:23
std::string to_string(const C &value)
Converts value to string, assuming &quot;operator&lt;&lt;&quot; defined on C.
Definition: gsUtils.h:56
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
virtual void setFixedDofs(index_t patch, boxSide side, const gsMatrix< T > &ddofs, bool oneUnk=false)
Set Dirichet degrees of freedom on a given side of a given patch from a given matrix.
Definition: gsBaseAssembler.hpp:61
virtual void eliminateFixedDofs()
Eliminates new Dirichelt degrees of fredom.
Definition: gsBaseAssembler.hpp:151
virtual void getFixedDofs(index_t patch, boxSide side, gsMatrix< T > &ddofs) const
Definition: gsBaseAssembler.hpp:113
Base class for assemblers of gsElasticity.
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
virtual index_t numFixedDofs() const
get the size of the Dirichlet vector for elimination
Definition: gsBaseAssembler.hpp:142
const_iterator dirichletEnd() const
Definition: gsBoundaryConditions.h:495