G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVisitorPoisson.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 
18 namespace gismo
19 {
20 
33 template <class T, bool paramCoef = false>
35 {
36 public:
37 
42  : pde_ptr(static_cast<const gsPoissonPde<T>*>(&pde))
43  {}
44 
46  void initialize(const gsBasis<T> & basis,
47  const index_t patchIndex,
48  const gsOptionList & options,
49  gsQuadRule<T> & rule)
50  {
51  // Grab right-hand side for current patch
52  rhs_ptr = &pde_ptr->rhs()->piece(patchIndex);
53 
54  // Setup Quadrature
55  rule = gsQuadrature::get(basis, options); // harmless slicing occurs here
56 
57  // Set Geometry evaluation flags
59  }
60 
62  inline void evaluate(const gsBasis<T> & basis,
63  const gsGeometry<T> & geo,
64  const gsMatrix<T> & quNodes)
65  {
66  md.points = quNodes;
67  // Compute the active basis functions
68  // Assumes actives are the same for all quadrature points on the elements
69  basis.active_into(md.points.col(0), actives);
70  numActive = actives.rows();
71 
72  // Evaluate basis functions on element
73  basis.evalAllDers_into( md.points, 1, basisData, true);
74 
75  // Compute image of Gauss nodes under geometry mapping as well as Jacobians
76  geo.computeMap(md);
77 
78  // Evaluate right-hand side at the geometry points paramCoef
79  // specifies whether the right hand side function should be
80  // evaluated in parametric(true) or physical (false)
81  rhs_ptr->eval_into( (paramCoef ? md.points : md.values[0] ), rhsVals );
82 
83  // Initialize local matrix/rhs
84  localMat.setZero(numActive, numActive );
85  localRhs.setZero(numActive, rhsVals.rows() );//multiple right-hand sides
86  }
87 
89  inline void assemble(gsDomainIterator<T> & ,
90  gsVector<T> const & quWeights)
91  {
92  gsMatrix<T> & bVals = basisData[0];
93  gsMatrix<T> & bGrads = basisData[1];
94 
95  for (index_t k = 0; k < quWeights.rows(); ++k) // loop over quadrature nodes
96  {
97  // Multiply weight by the geometry measure
98  const T weight = quWeights[k] * md.measure(k);
99 
100  // Compute physical gradients at k as a Dim x NumActive matrix
101  transformGradients(md, k, bGrads, physGrad);
102 
103  localRhs.noalias() += weight * ( bVals.col(k) * rhsVals.col(k).transpose() ) ;
104  localMat.noalias() += weight * (physGrad.transpose() * physGrad);
105  }
106  }
107 
109  inline void localToGlobal(const index_t patchIndex,
110  const std::vector<gsMatrix<T> > & eliminatedDofs,
111  gsSparseSystem<T> & system)
112  {
113  // Map patch-local DoFs to global DoFs
114  system.mapColIndices(actives, patchIndex, actives);
115 
116  // Add contributions to the system matrix and right-hand side
117  system.push(localMat, localRhs, actives, eliminatedDofs.front(), 0, 0);
118  }
119 
120 protected:
121  // Pointer to the pde data
122  const gsPoissonPde<T> * pde_ptr;
123 
124 protected:
125  // Basis values
126  std::vector<gsMatrix<T> > basisData;
127  gsMatrix<T> physGrad;
128  gsMatrix<index_t> actives;
129  index_t numActive;
130 
131 protected:
132  // Right hand side ptr for current patch
133  const gsFunction<T> * rhs_ptr;
134 
135  // Local values of the right hand side
136  gsMatrix<T> rhsVals;
137 
138 protected:
139  // Local matrices
140  gsMatrix<T> localMat;
141  gsMatrix<T> localRhs;
142 
143  gsMapData<T> md;
144 };
145 
146 
147 } // namespace gismo
148 
void evaluate(const gsBasis< T > &basis, const gsGeometry< T > &geo, const gsMatrix< T > &quNodes)
Evaluate on element.
Definition: gsVisitorPoisson.h:62
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
Visitor for the Poisson equation.
Definition: gsVisitorPoisson.h:34
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
void initialize(const gsBasis< T > &basis, const index_t patchIndex, const gsOptionList &options, gsQuadRule< T > &rule)
Initialize.
Definition: gsVisitorPoisson.h:46
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
void localToGlobal(const index_t patchIndex, const std::vector< gsMatrix< T > > &eliminatedDofs, gsSparseSystem< T > &system)
Adds the contributions to the sparse system.
Definition: gsVisitorPoisson.h:109
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
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
gsVisitorPoisson(const gsPde< T > &pde)
Constructor.
Definition: gsVisitorPoisson.h:41
A Poisson PDE.
Definition: gsPoissonPde.h:34
Creates a variety of quadrature rules.
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
Value of the object.
Definition: gsForwardDeclarations.h:72
void assemble(gsDomainIterator< T > &, gsVector< T > const &quWeights)
Assemble on element.
Definition: gsVisitorPoisson.h:89
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
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