G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVisitorMass.h
1 
16 #pragma once
17 
19 #include <gsCore/gsFuncData.h>
20 
21 namespace gismo
22 {
23 
24 template <class T>
25 class gsVisitorMass
26 {
27 public:
28 
29  gsVisitorMass(gsSparseMatrix<T> * elimMatrix = nullptr) :
30  elimMat(elimMatrix) {}
31 
32  void initialize(const gsBasisRefs<T> & basisRefs,
33  const index_t patchIndex,
34  const gsOptionList & options,
35  gsQuadRule<T> & rule)
36  {
37  // parametric dimension of the first displacement component
38  dim = basisRefs.front().dim();
39  // a quadrature rule is defined by the basis for the first displacement component.
40  rule = gsQuadrature::get(basisRefs.front(), options);
41  // saving necessary info
42  density = options.getReal("Density");
43  // resize containers for global indices
44  globalIndices.resize(dim);
45  blockNumbers.resize(dim);
46  }
47 
48  inline void evaluate(const gsBasisRefs<T> & basisRefs,
49  const gsGeometry<T> & geo,
50  const gsMatrix<T> & quNodes)
51  {
52  // store quadrature points of the element for geometry evaluation
53  md.points = quNodes;
54  // NEED_MEASURE to get the Jacobian determinant values for integration
55  md.flags = NEED_MEASURE;
56  // Compute the geometry mapping at the quadrature points
57  geo.computeMap(md);
58  // Evaluate displacement basis functions on the element
59  basisRefs.front().eval_into(quNodes,basisValuesDisp);
60  // find local indices of the displacement basis functions active on the element
61  basisRefs.front().active_into(quNodes.col(0),localIndicesDisp);
62  N_D = localIndicesDisp.rows();
63 
64  }
65 
66  inline void assemble(gsDomainIterator<T> & element,
67  const gsVector<T> & quWeights)
68  {
69  // initialize local matrix and rhs
70  localMat.setZero(dim*N_D,dim*N_D);
71  block = density*basisValuesDisp * quWeights.asDiagonal() * md.measures.asDiagonal() * basisValuesDisp.transpose();
72  for (short_t d = 0; d < dim; ++d)
73  localMat.block(d*N_D,d*N_D,N_D,N_D) = block.block(0,0,N_D,N_D);
74  }
75 
76  inline void localToGlobal(const int patchIndex,
77  const std::vector<gsMatrix<T> > & eliminatedDofs,
78  gsSparseSystem<T> & system)
79  {
80  // computes global indices for displacement components
81  for (short_t d = 0; d < dim; ++d)
82  {
83  system.mapColIndices(localIndicesDisp, patchIndex, globalIndices[d], d);
84  blockNumbers.at(d) = d;
85  }
86  // push to global system
87  system.pushToMatrix(localMat,globalIndices,eliminatedDofs,blockNumbers,blockNumbers);
88 
89  // push to the elimination system
90  if (elimMat != nullptr)
91  {
92  index_t globalI,globalElimJ;
93  index_t elimSize = 0;
94  for (short_t dJ = 0; dJ < dim; ++dJ)
95  {
96  for (short_t dI = 0; dI < dim; ++dI)
97  for (index_t i = 0; i < N_D; ++i)
98  if (system.colMapper(dI).is_free_index(globalIndices[dI].at(i)))
99  {
100  system.mapToGlobalRowIndex(localIndicesDisp.at(i),patchIndex,globalI,dI);
101  for (index_t j = 0; j < N_D; ++j)
102  if (!system.colMapper(dJ).is_free_index(globalIndices[dJ].at(j)))
103  {
104  globalElimJ = system.colMapper(dJ).global_to_bindex(globalIndices[dJ].at(j));
105  elimMat->coeffRef(globalI,elimSize+globalElimJ) += localMat(N_D*dI+i,N_D*dJ+j);
106  }
107  }
108  elimSize += eliminatedDofs[dJ].rows();
109  }
110  }
111  }
112 
113 protected:
114  // problem info
115  short_t dim;
116  //density
117  T density;
118  // geometry mapping
119  gsMapData<T> md;
120  // local components of the global linear system
121  gsMatrix<T> localMat;
122  // local indices (at the current patch) of the displacement basis functions active at the current element
123  gsMatrix<index_t> localIndicesDisp;
124  // number of displacement basis functions active at the current element
125  index_t N_D;
126  // values of displacement basis functions at quadrature points at the current element stored as a N_D x numQuadPoints matrix;
127  gsMatrix<T> basisValuesDisp;
128  bool assembleMatrix;
129  // elimination matrix to efficiently change Dirichlet degrees of freedom
130  gsSparseMatrix<T> * elimMat;
131 
132  // all temporary matrices defined here for efficiency
133  gsMatrix<T> block;
134  // containers for global indices
135  std::vector< gsMatrix<index_t> > globalIndices;
136  gsVector<index_t> blockNumbers;
137 };
138 
139 } // namespace gismo
140 
void assemble(gsDomainIterator< T > &, gsVector< T > const &quWeights)
Assemble on element.
Definition: gsVisitorMass.h:79
#define short_t
Definition: gsConfig.h:35
void evaluate(const gsBasis< T > &basis, const gsGeometry< T > &geo, gsMatrix< T > &quNodes)
Evaluate on element.
Definition: gsVisitorMass.h:57
void initialize(const gsBasis< T > &basis, const index_t, const gsOptionList &options, gsQuadRule< T > &rule)
Initialize.
Definition: gsVisitorMass.h:44
#define index_t
Definition: gsConfig.h:32
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition: gsMatrix.h:211
static gsQuadRule< T > get(const gsBasis< T > &basis, const gsOptionList &options, short_t fixDir=-1)
Constructs a quadrature rule based on input options.
Definition: gsQuadrature.h:48
T at(index_t i) const
Returns the i-th element of the vector.
Definition: gsVector.h:177
Creates a variety of quadrature rules.
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
void localToGlobal(const index_t patchIndex, const std::vector< gsMatrix< T > > &eliminatedDofs, gsSparseSystem< T > &system)
Adds the contributions to the sparse system.
Definition: gsVisitorMass.h:88
This object is a cache for computed values from an evaluator.
gsVisitorMass()
Constructor.
Definition: gsVisitorMass.h:34