G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVisitorBiharmonic.h
1 
14 #pragma once
15 
17 
18 namespace gismo
19 {
20 
31 template <class T>
32 class gsVisitorBiharmonic
33 {
34 public:
35 
40  : rhs_ptr(static_cast<const gsBiharmonicPde<T>&>(pde).rhs())
41  {}
42 
47  : rhs_ptr(&rhs)
48  {
49  GISMO_ASSERT( rhs.targetDim() == 1, "Not yet tested for multiple right-hand-sides");
50  }
51 
53  void initialize(const gsBasis<T> & basis,
54  gsQuadRule<T> & rule)
55  {
56  gsVector<index_t> numQuadNodes( basis.dim() );
57  for (int i = 0; i < basis.dim(); ++i) // to do: improve
58  numQuadNodes[i] = basis.degree(i) + 1;
59 
60  // Setup Quadrature
61  rule = gsGaussRule<T>(numQuadNodes);// NB!
62 
63  // Set Geometry evaluation flags
64  md.flags = NEED_VALUE | NEED_MEASURE | NEED_GRAD_TRANSFORM | NEED_2ND_DER;
65  }
66 
68  void initialize(const gsBasis<T> & basis,
69  const index_t ,
70  const gsOptionList & options,
71  gsQuadRule<T> & rule)
72  {
73  // Setup Quadrature
74  rule = gsQuadrature::get(basis, options);
75 
76  // Set Geometry evaluation flags
77  md.flags = NEED_VALUE | NEED_MEASURE | NEED_GRAD_TRANSFORM | NEED_2ND_DER;
78  }
79 
81  inline void evaluate(const gsBasis<T> & basis, // to do: more unknowns
82  const gsGeometry<T> & geo,
83  gsMatrix<T> & quNodes)
84  {
85  md.points = quNodes;
86  // Compute the active basis functions
87  // Assumes actives are the same for all quadrature points on the elements
88  basis.active_into(md.points.col(0), actives);
89  numActive = actives.rows();
90 
91  //deriv2_into()
92  //col(point) = B1_xx B2_yy B1_zz B_xy B1_xz B1_xy B2_xx ...
93 
94  // Evaluate basis functions on element
95  basis.evalAllDers_into(md.points, 2, basisData, true);
96 
97  // Compute image of Gauss nodes under geometry mapping as well as Jacobians
98  geo.computeMap(md);
99 
100  // Evaluate right-hand side at the geometry points
101  rhs_ptr->eval_into(md.values[0], rhsVals); // Dim: 1 X NumPts
102 
103  // Initialize local matrix/rhs
104  localMat.setZero(numActive, numActive);
105  localRhs.setZero(numActive, rhsVals.rows());//multiple right-hand sides
106  }
107 
110  const gsVector<T> & quWeights)
111  {
112  gsMatrix<T> & basisVals = basisData[0];
113  gsMatrix<T> & basisGrads = basisData[1];
114  gsMatrix<T> & basis2ndDerivs = basisData[2];
115 
116  for (index_t k = 0; k < quWeights.rows(); ++k) // loop over quadrature nodes
117  {
118  // Multiply weight by the geometry measure
119  const T weight = quWeights[k] * md.measure(k);
120 
121  // Compute physical laplacian at k as a 1 x numActive matrix
122  transformLaplaceHgrad(md, k, basisGrads, basis2ndDerivs, physBasisLaplace);
123 
124  // (\Delta u, \Delta v)
125  localMat.noalias() += weight * (physBasisLaplace.transpose() * physBasisLaplace);
126 
127  localRhs.noalias() += weight * ( basisVals.col(k) * rhsVals.col(k).transpose() ) ;
128  }
129  }
130 
132  inline void localToGlobal(const index_t patchIndex,
133  const std::vector<gsMatrix<T> > & eliminatedDofs,
134  gsSparseSystem<T> & system)
135  {
136  // Map patch-local DoFs to global DoFs
137  system.mapColIndices(actives, patchIndex, actives);
138 
139  // Add contributions to the system matrix and right-hand side
140  system.push(localMat, localRhs, actives, eliminatedDofs[0], 0, 0);
141  }
142 
143  /*
144  inline void localToGlobal(const gsDofMapper & mapper,
145  const gsMatrix<T> & eliminatedDofs,
146  const index_t patchIndex,
147  gsSparseMatrix<T> & sysMatrix,
148  gsMatrix<T> & rhsMatrix )
149  {
150  // Local Dofs to global dofs
151  mapper.localToGlobal(actives, patchIndex, actives);
152  //const int numActive = actives.rows();
153 
154  for (index_t i=0; i < numActive; ++i)
155  {
156  const int ii = actives(i);
157  if ( mapper.is_free_index(ii) )
158  {
159  rhsMatrix.row(ii) += localRhs.row(i);
160 
161  for (index_t j=0; j < numActive; ++j)
162  {
163  const int jj = actives(j);
164  if ( mapper.is_free_index(jj) )
165  {
166  sysMatrix.coeffRef(ii, jj) += localMat(i, j);
167  }
168  else
169  {
170  rhsMatrix.row(ii).noalias() -= localMat(i, j) *
171  eliminatedDofs.row( mapper.global_to_bindex(jj) );
172  }
173  }
174  }
175  }
176  }
177  */
178 
179 
180 protected:
181  // Right hand side
182  const gsFunction<T> * rhs_ptr;
183 
184 protected:
185  // Basis values
186  std::vector<gsMatrix<T> > basisData;
187  gsMatrix<T> physBasisLaplace;
188  gsMatrix<index_t> actives;
189  index_t numActive;
190 
191 
192 protected:
193  // Local values of the right hand side
194  gsMatrix<T> rhsVals;
195 
196 protected:
197  // Local matrices
198  gsMatrix<T> localMat;
199  gsMatrix<T> localRhs;
200 
201  gsMapData<T> md;
202 };
203 
204 
205 } // namespace gismo
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
void mapColIndices(const gsMatrix< index_t > &actives, const index_t patchIndex, gsMatrix< index_t > &result, const index_t c=0) const
mapColIndices Maps a set of basis indices by the corresponding dofMapper.
Definition: gsSparseSystem.h:584
virtual void computeMap(gsMapData< T > &InOut) const
Computes map function data.
Definition: gsFunction.hpp:822
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
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
Abstract class representing a PDE (partial differential equation).
Definition: gsPde.h:43
#define index_t
Definition: gsConfig.h:32
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
void push(const gsMatrix< T > &localMat, const gsMatrix< T > &localRhs, const gsMatrix< index_t > &actives, const gsMatrix< T > &eliminatedDofs, const size_t r=0, const size_t c=0)
push pushes the local system matrix and rhs for an element to the global system,
Definition: gsSparseSystem.h:972
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
virtual short_t targetDim() const
Dimension of the target space.
Definition: gsFunctionSet.h:560
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
Class which enables iteration over all elements of a parameter domain.
Definition: gsDomainIterator.h:67
void assemble(gsDomainIterator< T > &, const gsVector< T > &quWeights)
Assemble on element.
Definition: gsVisitorBiharmonic.h:109
A Biharmonic PDE.
Definition: gsBiharmonicPde.h:47
Creates a variety of quadrature rules.
void localToGlobal(const index_t patchIndex, const std::vector< gsMatrix< T > > &eliminatedDofs, gsSparseSystem< T > &system)
Adds the contributions to the sparse system.
Definition: gsVisitorBiharmonic.h:132
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
gsVisitorBiharmonic(const gsPde< T > &pde)
Constructor.
Definition: gsVisitorBiharmonic.h:39
gsVisitorBiharmonic(const gsFunction< T > &rhs)
Constructor.
Definition: gsVisitorBiharmonic.h:46
Value of the object.
Definition: gsForwardDeclarations.h:72
void initialize(const gsBasis< T > &basis, const index_t, const gsOptionList &options, gsQuadRule< T > &rule)
Initialize.
Definition: gsVisitorBiharmonic.h:68
void evaluate(const gsBasis< T > &basis, const gsGeometry< T > &geo, gsMatrix< T > &quNodes)
Evaluate on element.
Definition: gsVisitorBiharmonic.h:81
Gradient transformation matrix.
Definition: gsForwardDeclarations.h:77
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
void initialize(const gsBasis< T > &basis, gsQuadRule< T > &rule)
Initialize.
Definition: gsVisitorBiharmonic.h:53
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition: gsGaussRule.h:27
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