G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVisitorMoments.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 namespace gismo
17 {
18 
28 template <class T, bool paramCoef = false>
30 {
31 public:
32 
37  : rhs_ptr(&rhs)
38  { }
39 
41  void initialize(const gsBasis<T> & basis,
42  const index_t,
43  const gsOptionList & options,
44  gsQuadRule<T> & rule)
45  {
46  // Setup Quadrature
47  rule = gsQuadrature::get(basis, options); // harmless slicing occurs here
48 
49  // Set Geometry evaluation flags
50  md.flags = NEED_MEASURE | NEED_VALUE;
51  }
52 
54  inline void evaluate(const gsBasis<T> & basis, // to do: more unknowns
55  const gsGeometry<T> & geo,
56  const gsMatrix<T> & quNodes)
57  {
58  md.points = quNodes;
59  // Compute the active basis functions
60  // Assumes actives are the same for all quadrature points on the elements
61  basis.active_into(md.points.col(0), actives);
62  numActive = actives.rows();
63 
64  // Evaluate basis functions on element
65  basis.evalAllDers_into(md.points, 0, basisData, true);
66 
67  // Compute image of Gauss nodes under geometry mapping as well as Jacobians
68  geo.computeMap(md);
69 
70  // Evaluate right-hand side at the geometry points paramCoef
71  // specifies whether the right hand side function should be
72  // evaluated in parametric(true) or physical (false)
73  rhs_ptr->eval_into((paramCoef ? md.points : md.values[0]), rhsVals);
74 
75  // Initialize local matrix/rhs
76  localRhs.setZero(numActive, rhsVals.rows());//multiple right-hand sides
77  }
78 
80  inline void assemble(gsDomainIterator<T> & /*element*/,
81  gsVector<T> const & quWeights)
82  {
83  gsMatrix<T> &bVals = basisData[0];
84 
85  // localRhs.noalias() = quWeights.array() * md.measures().array() *
86  // bVals * rhsVals.transpose();
87 
88  for (index_t k = 0; k < quWeights.rows(); ++k) // loop over quadrature nodes
89  {
90  // Multiply weight by the geometry measure
91  const T weight = quWeights[k] * md.measure(k);
92 
93  localRhs.noalias() += weight * (bVals.col(k) * rhsVals.col(k).transpose());
94  }
95  //gsDebugVar(localRhs.transpose() );
96  //gsDebugVar(localMat.asVector().transpose() );
97  }
98 
100  inline void localToGlobal(const index_t patchIndex,
101  const std::vector<gsMatrix<T> > & /*eliminatedDofs*/,
102  gsSparseSystem<T> & system)
103  {
104  // Map patch-local DoFs to global DoFs
105  system.mapColIndices(actives, patchIndex, actives);
106 
107  // Add contributions to the right-hand side
108  system.pushToRhs(localRhs, actives, 0);
109  }
110 
112  inline void localToGlobal(const gsDofMapper & mapper,
113  const gsMatrix<T> & eliminatedDofs,
114  const index_t patchIndex,
115  gsSparseMatrix<T> & sysMatrix,
116  gsMatrix<T> & rhsMatrix )
117  {
118  //Assert eliminatedDofs.rows() == mapper.boundarySize()
119 
120  // Local DoFs to global DoFs
121  mapper.localToGlobal(actives, patchIndex, actives);
122  //const int numActive = actives.rows();
123 
124  for (index_t i=0; i < numActive; ++i)
125  {
126  const index_t ii = actives(i);
127  if ( mapper.is_free_index(ii) )
128  {
129  rhsMatrix.row(ii) += localRhs.row(i);
130  }
131  }
132  }
133 
134 protected:
135  // Right hand side
136  const gsFunction<T> * rhs_ptr;
137 
138 protected:
139  // Basis values
140  std::vector<gsMatrix<T> > basisData;
141  gsMatrix<index_t> actives;
142  index_t numActive;
143 
144 protected:
145  // Local values of the right hand side
146  gsMatrix<T> rhsVals;
147  // Local matrices
148  gsMatrix<T> localRhs;
149 
150  gsMapData<T> md;
151 };
152 
153 
154 } // namespace gismo
Visitor for the moment vector of a function.
Definition: gsVisitorMoments.h:29
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
void initialize(const gsBasis< T > &basis, const index_t, const gsOptionList &options, gsQuadRule< T > &rule)
Initialize.
Definition: gsVisitorMoments.h:41
virtual void computeMap(gsMapData< T > &InOut) const
Computes map function data.
Definition: gsFunction.hpp:822
void assemble(gsDomainIterator< T > &, gsVector< T > const &quWeights)
Assemble on element.
Definition: gsVisitorMoments.h:80
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
gsVisitorMoments(const gsFunction< T > &rhs)
Constructor for gsVisitorMoments.
Definition: gsVisitorMoments.h:36
the gsMapData is a cache of pre-computed function (map) values.
Definition: gsFuncData.h:324
void localToGlobal(const index_t patchIndex, const std::vector< gsMatrix< T > > &, gsSparseSystem< T > &system)
Adds the contributions to the sparse system.
Definition: gsVisitorMoments.h:100
#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
Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individ...
Definition: gsDofMapper.h:68
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
bool is_free_index(index_t gl) const
Returns true if global dof gl is not eliminated.
Definition: gsDofMapper.h:376
Class which enables iteration over all elements of a parameter domain.
Definition: gsDomainIterator.h:67
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
void pushToRhs(const gsMatrix< T > &localRhs, const gsMatrix< index_t > &actives, const size_t r=0)
pushToRhs pushes the local rhs for an element to the global system
Definition: gsSparseSystem.h:884
void evaluate(const gsBasis< T > &basis, const gsGeometry< T > &geo, const gsMatrix< T > &quNodes)
Evaluate on element.
Definition: gsVisitorMoments.h:54
Value of the object.
Definition: gsForwardDeclarations.h:72
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: gsVisitorMoments.h:112
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