G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsVisitorBiharmonic.h
Go to the documentation of this file.
1
15#pragma once
16
18#include <gsCore/gsFuncData.h>
19
20namespace gismo
21{
22
23template <class T>
25{
26public:
27
28 gsVisitorBiharmonic(const gsPde<T> & pde_, gsSparseMatrix<T> * elimMatrix = nullptr)
29 : pde_ptr(static_cast<const gsPoissonPde<T>*>(&pde_)),
30 N_M(), N_A(), localStiffening(),
31 elimMat(elimMatrix)
32 {}
33
34 void initialize(const gsBasisRefs<T> & basisRefs,
35 const index_t patchIndex,
36 const gsOptionList & options,
37 gsQuadRule<T> & rule)
38 {
39 GISMO_UNUSED(patchIndex);
40 // a quadrature rule is defined by the basis for the auxiliary variable.
41 // the same rule is used for the main variable
42 rule = gsQuadrature::get(basisRefs.back(), options);
43 // saving necessary info
44 localStiffening = options.getReal("LocalStiff");
45 // resize containers for global indices
46 globalIndices.resize(2);
47 blockNumbers.resize(2);
48 }
49
50 inline void evaluate(const gsBasisRefs<T> & basisRefs,
51 const gsGeometry<T> & geo,
52 const gsMatrix<T> & quNodes)
53 {
54 // store quadrature points of the element for geometry evaluation
55 md.points = quNodes;
56 // NEED_VALUE to get points in the physical domain for evaluation of the RHS
57 // NEED_MEASURE to get the Jacobian determinant values for integration
58 // NEED_GRAD_TRANSFORM to get the Jacobian matrix to transform gradient from the parametric to physical domain
60 // Compute image of the quadrature points plus gradient, jacobian and other necessary data
61 geo.computeMap(md);
62 // find local indices of the main and auxiliary basis functions active on the element
63 basisRefs.front().active_into(quNodes.col(0),localIndicesMain);
64 N_M = localIndicesMain.rows();
65 basisRefs.back().active_into(quNodes.col(0), localIndicesAux);
66 N_A = localIndicesAux.rows();
67 // Evaluate basis functions and their derivatives on the element
68 basisRefs.front().evalAllDers_into(quNodes,1,basisValuesMain);
69 basisRefs.back().evalAllDers_into(quNodes,1,basisValuesAux);
70 // Evaluate right-hand side at the image of the quadrature points
71 pde_ptr->rhs()->eval_into(md.values[0],forceValues);
72 }
73
74 inline void assemble(gsDomainIterator<T> & element,
75 const gsVector<T> & quWeights)
76 {
77 GISMO_UNUSED(element);
78 // Initialize local matrix/rhs // 0 | B^T = L
79 localMat.setZero(N_M + N_A, N_M + N_A); // --|-- matrix structure
80 localRhs.setZero(N_M + N_A,pde_ptr->numRhs()); // B | A = 0
81
82 // Loop over the quadrature nodes
83 for (index_t q = 0; q < quWeights.rows(); ++q)
84 {
85 // Multiply quadrature weight by the geometry measure
86 const T weightMatrix = quWeights[q] * pow(md.measure(q),1-localStiffening);
87 const T weightRHS = quWeights[q] * md.measure(q);
88 // Compute physical gradients of the basis functions at q as a 1 x numActiveFunction matrix
89 transformGradients(md, q, basisValuesAux[1], physGradAux);
90 transformGradients(md, q, basisValuesMain[1], physGradMain);
91 // matrix A
92 block = weightMatrix * basisValuesAux[0].col(q) * basisValuesAux[0].col(q).transpose();
93 localMat.block(N_M,N_M,N_A,N_A) += block.block(0,0,N_A,N_A);
94 // matrix B
95 block = weightMatrix * physGradAux.transpose()*physGradMain; // N_A x N_M
96 localMat.block(0,N_M,N_M,N_A) += block.block(0,0,N_A,N_M).transpose();
97 localMat.block(N_M,0,N_A,N_M) += block.block(0,0,N_A,N_M);
98 // rhs contribution
99 localRhs.middleRows(0,N_M).noalias() += weightRHS * basisValuesMain[0].col(q) * forceValues.col(q).transpose();
100 }
101 }
102
103 inline void localToGlobal(const int patchIndex,
104 const std::vector<gsMatrix<T> > & eliminatedDofs,
105 gsSparseSystem<T> & system)
106 {
107 // compute global indices
108 system.mapColIndices(localIndicesMain,patchIndex,globalIndices[0],0);
109 system.mapColIndices(localIndicesAux,patchIndex,globalIndices[1],1);
110 blockNumbers.at(0) = 0;
111 blockNumbers.at(1) = 1;
112 // push to global system
113 system.pushToRhs(localRhs,globalIndices,blockNumbers);
114 system.pushToMatrix(localMat,globalIndices,eliminatedDofs,blockNumbers,blockNumbers);
115
116 // push to the elimination system
117 if (elimMat != nullptr)
118 {
119 index_t globalI,globalElimJ;
120 index_t elimSize = 0;
121 for (short_t dJ = 0; dJ < 2; ++dJ)
122 {
123 for (short_t dI = 0; dI < 2; ++dI)
124 for (index_t i = 0; i < N_M; ++i)
125 if (system.colMapper(dI).is_free_index(globalIndices[dI].at(i)))
126 {
127 system.mapToGlobalRowIndex(localIndicesMain.at(i),patchIndex,globalI,dI);
128 for (index_t j = 0; j < N_M; ++j)
129 if (!system.colMapper(dJ).is_free_index(globalIndices[dJ].at(j)))
130 {
131 globalElimJ = system.colMapper(dJ).global_to_bindex(globalIndices[dJ].at(j));
132 elimMat->coeffRef(globalI,elimSize+globalElimJ) += localMat(N_M*dI+i,N_M*dJ+j);
133 }
134 }
135 elimSize += eliminatedDofs[dJ].rows();
136 }
137 }
138 }
139
140protected:
141 // problem info
142 const gsPoissonPde<T> * pde_ptr;
143 // geometry mapping
144 gsMapData<T> md;
145 // local components of the global linear system
146 gsMatrix<T> localMat;
147 gsMatrix<T> localRhs;
148 // local indices (at the current patch) of basis functions active at the current element
149 gsMatrix<index_t> localIndicesMain;
150 gsMatrix<index_t> localIndicesAux;
151 // number of main and auxiliary basis functions active at the current element
152 index_t N_M, N_A;
153 // values and derivatives of main basis functions at quadrature points at the current element
154 // values are stored as a N_M x numQuadPoints matrix; not sure about derivatives, must be smth like N_M x numQuadPoints
155 // same for the auxiliary basis functions
156 std::vector<gsMatrix<T> > basisValuesMain;
157 std::vector<gsMatrix<T> > basisValuesAux;
158 // RHS values at quadrature points at the current element; stored as a 1 x numQuadPoints matrix
159 gsMatrix<T> forceValues;
160 // all temporary matrices defined here for efficiency
161 gsMatrix<T> block, physGradMain, physGradAux;
162 real_t localStiffening;
163 // elimination matrix to efficiently change Dirichlet degrees of freedom
164 gsSparseMatrix<T> * elimMat;
165 // containers for global indices
166 std::vector< gsMatrix<index_t> > globalIndices;
167 gsVector<index_t> blockNumbers;
168};
169
170} // namespace gismo
Simple class to hold a list of gsBasis which discretize a PDE system on a given patch.
Definition gsBasisRefs.h:26
const gsBasis< T > & back() const
Back.
Definition gsBasisRefs.h:54
const gsBasis< T > & front() const
Front.
Definition gsBasisRefs.h:50
bool is_free_index(index_t gl) const
Returns true if global dof gl is not eliminated.
Definition gsDofMapper.h:376
index_t global_to_bindex(index_t gl) const
Returns the boundary index of global dof gl.
Definition gsDofMapper.h:364
Class which enables iteration over all elements of a parameter domain.
Definition gsDomainIterator.h:68
virtual void computeMap(gsMapData< T > &InOut) const
Computes map function data.
Definition gsFunction.hpp:817
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
the gsMapData is a cache of pre-computed function (map) values.
Definition gsFuncData.h:349
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition gsMatrix.h:211
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
Real getReal(const std::string &label) const
Reads value for option label from options.
Definition gsOptionList.cpp:44
Abstract class representing a PDE (partial differential equation).
Definition gsPde.h:44
A Poisson PDE.
Definition gsPoissonPde.h:35
Class representing a reference quadrature rule.
Definition gsQuadRule.h:29
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
A sparse linear system indexed by sets of degrees of freedom.
Definition gsSparseSystem.h:30
void pushToMatrix(const gsMatrix< T > &localMat, const gsMatrix< index_t > &actives, const gsMatrix< T > &eliminatedDofs, const size_t r=0, const size_t c=0)
pushToMatrix pushes the local matrix for an element to the global system,
Definition gsSparseSystem.h:638
const gsDofMapper & colMapper(const index_t c) const
colMapper returns the dofMapper for column block c
Definition gsSparseSystem.h:498
void mapToGlobalRowIndex(const index_t active, const index_t patchIndex, index_t &result, const index_t r=0) const
mapToGlobalRowIndex Maps a single basis index to the final position in the system,...
Definition gsSparseSystem.h:600
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 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
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
T at(index_t i) const
Returns the i-th element of the vector.
Definition gsVector.h:177
Visitor for the biharmonic equation.
Definition gsVisitorBiharmonic.h:25
void assemble(gsDomainIterator< T > &, const gsVector< T > &quWeights)
Assemble on element.
Definition gsVisitorBiharmonic.h:109
void initialize(const gsBasis< T > &basis, gsQuadRule< T > &rule)
Initialize.
Definition gsVisitorBiharmonic.h:53
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
void evaluate(const gsBasis< T > &basis, const gsGeometry< T > &geo, gsMatrix< T > &quNodes)
Evaluate on element.
Definition gsVisitorBiharmonic.h:81
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
This object is a cache for computed values from an evaluator.
Creates a variety of quadrature rules.
The G+Smo namespace, containing all definitions for the library.
@ NEED_VALUE
Value of the object.
Definition gsForwardDeclarations.h:72
@ NEED_GRAD_TRANSFORM
Gradient transformation matrix.
Definition gsForwardDeclarations.h:77
@ NEED_MEASURE
The density of the measure pull back.
Definition gsForwardDeclarations.h:76
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:51