G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVisitorNitscheBiharmonic.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 namespace gismo
18 {
19 
33 template <class T>
35 {
36 public:
37 
43  gsVisitorNitscheBiharmonic(const gsFunction<T> & dirdata, T penalty, boxSide s)
44  : dirdata_ptr(&dirdata), m_penalty(penalty), side(s)
45  { }
46 
48  void initialize(const gsBasis<T> & basis,
49  gsQuadRule<T> & rule)
50  {
51  const int dir = side.direction();
52  gsVector<int> numQuadNodes(basis.dim());
53  for (int i = 0; i < basis.dim(); ++i)
54  numQuadNodes[i] = basis.degree(i) + 1;
55  numQuadNodes[dir] = 1;
56 
57  // Setup Quadrature
58  rule = gsGaussRule<T>(numQuadNodes);// harmless slicing occurs here
59 
60  // Set Geometry evaluation flags
61  md.flags = NEED_VALUE | NEED_MEASURE | NEED_GRAD_TRANSFORM | NEED_2ND_DER;
62  }
63 
65  inline void evaluate(const gsBasis<T> & basis, // to do: more unknowns
66  const gsGeometry<T> & geo,
67  // todo: add element here for efficiency
68  gsMatrix<T> & quNodes)
69  {
70  md.points = quNodes;
71  // Compute the active basis functions
72  // Assumes actives are the same for all quadrature points on the current element
73  basis.active_into(md.points.col(0), actives);
74  const index_t numActive = actives.rows();
75 
76  // Evaluate basis values and derivatives on element
77  basis.evalAllDers_into(md.points, 2, basisData, true);
78 
79  // Compute geometry related values
80  geo.computeMap(md);
81 
82  // Evaluate the Dirichlet data
83  dirdata_ptr->eval_into(md.values[0], dirData);
84 
85  // Initialize local matrix/rhs
86  localMat.setZero(numActive, numActive);
87  localRhs.setZero(numActive, dirdata_ptr->targetDim());
88  }
89 
91  inline void assemble(gsDomainIterator<T> & element,
92  const gsVector<T> & quWeights)
93  {
94  const unsigned d = element.dim();
95 
96  const index_t numActive = actives.rows();
97 
98  for (index_t k = 0; k < quWeights.rows(); ++k) // loop over quadrature nodes
99  {
100  //const typename gsMatrix<T>::Block basisVals = basisData.topRows(numActive);
101  const typename gsMatrix<T>::Block basisGrads =
102  basisData.middleRows(numActive, numActive * d);
103  const typename gsMatrix<T>::Block basis2ndDerivs =
104  basisData.bottomRows(numActive * (d * (d + 1)) / 2);
105 
106  // Compute the outer normal vector on the side
107  outerNormal(md, k, side, unormal);
108 
109  // Multiply quadrature weight by the geometry measure
110  const T weight = quWeights[k] * unormal.norm();
111 
112  // Compute the unit normal vector : Dim x 1
113  unormal.normalize();
114 
115  // Compute physical gradients at k as a Dim x NumActive matrix
116  transformGradients(md, k, basisGrads, physBasisGrads);
117  // Compute physical laplacian at k as a 1 x numActive matrix
118  transformLaplaceHgrad(md, k, basisGrads, basis2ndDerivs, physBasisLaplace);
119 
120  // Get penalty parameter
121  const T h = element.getCellSize();
122  const T mu = m_penalty / (0 != h ? h : 1);
123 
124  // Sum up quadrature point evaluations
125  localRhs.noalias() += weight * ((physBasisLaplace.transpose() + mu * physBasisGrads.transpose() * unormal)
126  * dirData.col(k).transpose());
127 
128  localMat.noalias() += weight * (physBasisGrads.transpose() * unormal * physBasisLaplace
129  + (physBasisGrads.transpose() * unormal * physBasisLaplace).transpose()
130  - mu * physBasisGrads.transpose() * physBasisGrads);
131  }
132  }
133 
135  void localToGlobal(const gsDofMapper & mapper,
136  const gsMatrix<T> & eliminatedDofs,
137  const index_t patchIndex,
138  gsSparseMatrix<T> & sysMatrix,
139  gsMatrix<T> & rhsMatrix )
140  {
141  // Local DoFs to global DoFs
142  mapper.localToGlobal(actives, patchIndex, actives);
143  const index_t numActive = actives.rows();
144 
145  // Push element contribution to the global matrix and load vector
146  for (index_t j=0; j!=numActive; ++j)
147  {
148  const unsigned jj = actives(j);
149  rhsMatrix.row(jj) -= localRhs.row(j);
150  for (index_t i=0; i!=numActive; ++i)
151  {
152  const unsigned ii = actives(i);
153  if ( jj <= ii ) // assuming symmetric problem (!) probably we must not.
154  sysMatrix( ii, jj ) -= localMat(i,j);
155  }
156  }
157 
158  }
159 
160 private:
161  // Dirichlet function
162  const gsFunction<T> * dirdata_ptr;
163 
164  // Penalty constant
165  T m_penalty;
166 
167  // Side
168  boxSide side;
169 
170 private:
171  // Basis values
172  gsMatrix<T> basisData;
173  gsMatrix<T> physBasisGrads;
174  gsMatrix<T> physBasisLaplace;
175  gsMatrix<index_t> actives;
176 
177  // Normal and Neumann values
178  gsVector<T> unormal;
179  gsMatrix<T> dirData;
180 
181  // Local matrix and rhs
182  gsMatrix<T> localMat;
183  gsMatrix<T> localRhs;
184 
185  gsMapData<T> md;
186 };
187 
188 
189 } // namespace gismo
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
T getCellSize() const
Return the diagonal of the element.
Definition: gsDomainIterator.h:171
virtual void computeMap(gsMapData< T > &InOut) const
Computes map function data.
Definition: gsFunction.hpp:822
gsVisitorNitscheBiharmonic(const gsFunction< T > &dirdata, T penalty, boxSide s)
Constructor.
Definition: gsVisitorNitscheBiharmonic.h:43
virtual void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result...
Definition: gsFunctionSet.hpp:81
short_t dim() const
Return dimension of the elements.
Definition: gsDomainIterator.h:115
virtual short_t degree(short_t i) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsBasis.hpp:650
the gsMapData is a cache of pre-computed function (map) values.
Definition: gsFuncData.h:324
#define index_t
Definition: gsConfig.h:32
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
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.
Definition: gsDofMapper.cpp:25
void assemble(gsDomainIterator< T > &element, const gsVector< T > &quWeights)
Assemble on element.
Definition: gsVisitorNitscheBiharmonic.h:91
Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individ...
Definition: gsDofMapper.h:68
Class which enables iteration over all elements of a parameter domain.
Definition: gsDomainIterator.h:67
Visitor for the weak imposition of the first-type dirichlet boundary condition.
Definition: gsVisitorNitscheBiharmonic.h:34
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
void localToGlobal(const gsDofMapper &mapper, const gsMatrix< T > &eliminatedDofs, const index_t patchIndex, gsSparseMatrix< T > &sysMatrix, gsMatrix< T > &rhsMatrix)
Adds the contributions to the sparse system.
Definition: gsVisitorNitscheBiharmonic.h:135
void evaluate(const gsBasis< T > &basis, const gsGeometry< T > &geo, gsMatrix< T > &quNodes)
Evaluate on element.
Definition: gsVisitorNitscheBiharmonic.h:65
Value of the object.
Definition: gsForwardDeclarations.h:72
void initialize(const gsBasis< T > &basis, gsQuadRule< T > &rule)
Initialize.
Definition: gsVisitorNitscheBiharmonic.h:48
Gradient transformation matrix.
Definition: gsForwardDeclarations.h:77
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition: gsGaussRule.h:27
short_t direction() const
Returns the parametric direction orthogonal to this side.
Definition: gsBoundary.h:113
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
virtual void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active basis functions at points u, as a list of indices, in result...
Definition: gsBasis.hpp:293