HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
vsxgrad.hpp
Go to the documentation of this file.
1#ifndef VSXGRAD_HPP
2#define VSXGRAD_HPP
3
4#include <sxgrad.hpp>
5#include <unsupported/Eigen/KroneckerProduct>
6
7
8namespace HArDCore2D
9{
16
30 {
31 public:
32 // Type of continuous functions corresponding to the discrete space VSXgrad
33 typedef std::function<Eigen::Vector2d(const Eigen::Vector2d &)> FunctionType;
34
36 {
38 const Eigen::MatrixXd & _rot,
39 const Eigen::MatrixXd & _potential
40 )
41 : rot(_rot),
42 potential(_potential)
43 {
44 // Do nothing
45 }
46
47 Eigen::MatrixXd rot;
48 Eigen::MatrixXd potential;
49 };
50
51
52 // Types for element bases
56
57 // Type for edge basis
60
61 // Structure to store vectorial/matrix cell bases (the scalar ones are in m_sxgrad)
62 struct CellBases
63 {
64 std::unique_ptr<Poly2BasisCellType> Polykmo2;
65 std::unique_ptr<Poly2BasisCellType> Polykptwo2;
66 std::unique_ptr<Poly2x2BasisCellType> Polykpo2x2;
67 };
68
69 // Structure to store vectorial/matrix edge bases (the scalar ones are in m_sxgrad)
70 struct EdgeBases
71 {
72 std::unique_ptr<Poly2BasisEdgeType> Polykmo2;
73 std::unique_ptr<Poly2BasisEdgeType> Polyk2;
74 std::unique_ptr<Poly2BasisEdgeType> Polykpo2;
75 std::unique_ptr<Poly2BasisEdgeType> Polykptwo2;
76 };
77
79 VSXGrad(const DDRCore & ddr_core, const SerendipityProblem & sp, bool use_threads = true, std::ostream & output = std::cout);
80
82 const Mesh & mesh() const
83 {
84 return m_sxgrad.mesh();
85 }
86
88 const SXGrad & sXgrad() const
89 {
90 return m_sxgrad;
91 }
92
94 const size_t & degree() const
95 {
96 return m_sxgrad.degree();
97 }
98
99
100
101
103 Eigen::VectorXd interpolate(
104 const FunctionType & q,
105 const int doe_cell = -1
106 ) const;
107
108 //---------------------------------------------------------------------//
109 //---- Gradients and potential reconstructions, and stabilisation -----//
110
111 /* Operators from sXgrad are easily extended into operators on vsXgrad using the Kronecker product
112 These extension corresponds to the abovementioned tensorized basis of sXgrad and, for the codomain,
113 to the tensorized basis of R^2 \otimes P (for P the polynomial space in which the operator of sXgrad
114 lands). We need to do a change of basis of that codomain to represent the operators in the bases
115 stored in the structures EdgeBases, FaceBases and CellBases.
116 */
117
118
119 //Rename spaces so that their name fit with the fact that we will take degree K+1
120
121
122 inline auto PolykE(size_t iE) const -> const PolyBasisEdgeType& {
123 return *m_sxgrad.edgeBases(iE).Polykmo;
124 }
125 inline auto PolykpoE(size_t iE) const -> const PolyBasisEdgeType& {
126 return *m_sxgrad.edgeBases(iE).Polyk;
127 }
128
129 inline auto PolykptwoE(size_t iE) const -> const PolyBasisEdgeType& {
130 return *m_sxgrad.edgeBases(iE).Polykpo;
131 }
132
133
134 inline auto Polykpo(size_t iT) const -> const PolyBasisCellType& {
135 return *m_sxgrad.cellBases(iT).Polyk;
136 }
137
138
139 inline auto Polykmo(size_t iT) const -> const PolyBasisCellType& {
140 return *m_sxgrad.cellBases(iT).Polykmtwo;
141 }
142
143
144 inline auto Polyk(size_t iT) const -> const PolyBasisCellType& {
145 return *m_sxgrad.cellBases(iT).Polykmo;
146 }
147
148
149 inline auto Polykptwo(size_t iT) const -> const PolyBasisCellType& {
150 return *m_sxgrad.cellBases(iT).Polykpo;
151 }
152
153
154 inline auto Polyk2(size_t iT) const -> const Poly2BasisCellType& {
155 return *m_sxgrad.cellBases(iT).Polykmo2;
156 }
157
158
159
161 inline const Eigen::MatrixXd edgeGradient(size_t iE) const
162 {
163 // The codomain for the edge gradient of sXgrad is Polyk, so we need to change from
164 // R^3 \otimes Polyk to Polyk3 (which is, by construction, Polyk \otimes R^3)
165 return PermuteTensorization(m_sxgrad.edgeBases(iE).Polyk->dimension(), dimspace)
166 * Eigen::KroneckerProduct(m_sxgrad.edgeGradient(iE), Eigen::Matrix2d::Identity());
167 }
168
170 inline const Eigen::MatrixXd edgeGradient(const Edge & E) const
171 {
172 return edgeGradient(E.global_index());
173 }
174
176 inline const Eigen::MatrixXd edgePotential(size_t iE) const
177 {
178 // The codomain for the edge potential of sXgrad is Polykpo, so we need to change from
179 // R^3 \otimes Polykpo to Polykpo3 which is, by construction, Polykpo \otimes R^3
180 return PermuteTensorization(m_sxgrad.edgeBases(iE).Polykpo->dimension(), dimspace)
181 * Eigen::KroneckerProduct(m_sxgrad.edgePotential(iE), Eigen::Matrix2d::Identity());
182 }
183
185 inline const Eigen::MatrixXd edgePotential(const Edge & E) const
186 {
187 return edgePotential(E.global_index());
188 }
189
190
192 inline const Eigen::MatrixXd cellGradient(size_t iT) const
193 {
194 // The codomain for the cell gradient of sXgrad is Polyk3, so we need to change from
195 // R^3 \otimes Polyk3 to Polyk3x3.
196 // Here, Polyk3 = Polyk \otimes R^3, where the R^3=R^3_nabla component represents the derivatives.
197 // We first permute the codomain of m_sxgrad.cellGradient(iT) to make it R^3_nabla \otimes Polyk.
198 Eigen::MatrixXd GradPermutedBasis
199 = PermuteTensorization(dimspace, m_sxgrad.cellBases(iT).Polyk->dimension()) * m_sxgrad.cellGradient(iT);
200
201 // The Kronecker product then gives the cellGradient of vsXgrad in (R^3 \otimes R^3_nabla) \otimes Polyk,
202 // where the first copy of R^3 lists the components of the functions in the vectorized vsXgrad.
203 // We permute this basis to Polyk \otimes (R^3 \otimes R^3_nabla). In this basis, the first index
204 // of R^3 \otimes R^3_nabla goes over the components of the functions, and the second over the coordinates
205 // derivatives.
206 // Polyk3x3 is Polyk \otimes M_N(R) with the basis of M_N(R) listing the canonical
207 // basis vectors in columns; so identifying the basis of R^3 \otimes R^3_nabla with the basis of M_N(R)
208 // organises the functions components in columns and their gradients in rows, which is exactly what
209 // we want. Hence, the matrix obtained on Polyk \otimes (R^3 \otimes R^3_nabla) can directly be interpreted
210 // as the matrix on Polyk \otimes M_N(R) = Polyk3x3.
211 return PermuteTensorization(m_sxgrad.cellBases(iT).Polyk->dimension(), dimspace*dimspace)
212 * Eigen::KroneckerProduct(GradPermutedBasis, Eigen::Matrix2d::Identity());
213 }
214
216 inline const Eigen::MatrixXd cellGradient(const Cell & T) const
217 {
218 return cellGradient(T.global_index());
219 }
220
222 inline const Eigen::MatrixXd cellSymGradient(size_t iT) const
223 {
224 return cellBases(iT).Polykpo2x2->symmetriseOperator() * cellGradient(iT);
225 }
226
228 inline const Eigen::MatrixXd cellSymGradient(const Cell & T) const
229 {
230 return cellSymGradient(T.global_index());
231 }
232
234 inline const Eigen::MatrixXd cellDivergence(size_t iT) const
235 {
236 return cellBases(iT).Polykpo2x2->traceOperator() * cellGradient(iT);
237 }
238
240 inline const Eigen::MatrixXd cellDivergence(const Cell & T) const
241 {
242 return cellDivergence(T.global_index());
243 }
244
246 inline const Eigen::MatrixXd cellPotential(size_t iT) const
247 {
248 // The codomain for the cell potential of sXgrad is Polykpo, so we need to change from
249 // R^3 \otimes Polykpo to Polykpo3 which is, by construction, Polykpo \otimes R^3
250 return PermuteTensorization(m_sxgrad.cellBases(iT).Polykpo->dimension(), dimspace)
251 * Eigen::KroneckerProduct(m_sxgrad.cellPotential(iT), Eigen::Matrix2d::Identity());
252 }
253
255 inline const Eigen::MatrixXd cellPotential(const Cell & T) const
256 {
257 return cellPotential(T.global_index());
258 }
259
260 Eigen::MatrixXd _permute_bases(size_t iT);
261
263 Eigen::MatrixXd computeStabilisation(
264 const size_t iT,
265 const IntegralWeight & weight = IntegralWeight(1.)
266 ) const
267 {
268 // The H^1-stabilisation is the L^2-stabilisation divided by h_T^2
269 double hTm2 = std::pow(mesh().cell(iT)->diam(), -2);
270 return hTm2 * Eigen::KroneckerProduct(m_sxgrad.computeStabilisation(iT, weight), Eigen::Matrix2d::Identity());
271 }
272
274 std::vector<double> computeH1norms(
275 const std::vector<Eigen::VectorXd> & list_dofs,
276 const std::string typegrad="full"
277 ) const;
278
280 std::vector<VectorRd> computeVertexValues(
281 const Eigen::VectorXd & u
282 ) const;
283
284 //-----------------------//
285 //---- Getters ----------//
286
288 inline const CellBases & cellBases(size_t iT) const
289 {
290 assert( m_cell_bases[iT] );
291 return *m_cell_bases[iT].get();
292 }
293
295 inline const CellBases & cellBases(const Cell & T) const
296 {
297 return cellBases(T.global_index());
298 }
299
300
302 inline const EdgeBases & edgeBases(size_t iE) const
303 {
304 assert( m_edge_bases[iE] );
305 return *m_edge_bases[iE].get();
306 }
307
309 inline const EdgeBases & edgeBases(const Edge & E) const
310 {
311 return edgeBases(E.global_index());
312 }
313
315 inline const LocalOperators & cellOperators(size_t iT) const
316 {
317 return *m_cell_operators[iT];
318 }
319
321 inline const LocalOperators & cellOperators(const Cell & T) const
322 {
323 return *m_cell_operators[T.global_index()];
324 }
325
326
327 private:
328 EdgeBases _compute_edge_bases(size_t iE);
329 CellBases _compute_cell_bases(size_t iT);
330
331 const DDRCore & m_ddr_core;
332 const SerendipityProblem& m_sp; // Warning
333 const SXGrad m_sxgrad; // Not a reference as it is not created outside this class
334
335
336 // Cell bases
337 std::vector<std::unique_ptr<CellBases> > m_cell_bases;
338 // Edge bases
339 std::vector<std::unique_ptr<EdgeBases> > m_edge_bases;
340
341 bool m_use_threads;
342 std::ostream & m_output;
343
344 LocalOperators _compute_cell_operators(size_t iT);
345
346
347 // Containers for local operators
348 std::vector<std::unique_ptr<LocalOperators> > m_cell_operators;
349
350 };
351
352} // end of namespace HArDCore2D
353#endif
Construct all polynomial spaces for the DDR sequence.
Definition ddrcore.hpp:63
Definition basis.hpp:313
Matrix family obtained from a scalar family.
Definition basis.hpp:721
Discrete Serendipity Hgrad space: local operators, L2 product and global interpolator.
Definition sxgrad.hpp:20
Construct all polynomial spaces for the DDR sequence.
Definition serendipity_problem.hpp:20
Vector family obtained by tensorization of a scalar family.
Definition basis.hpp:561
Vector version of sXgrad, the arbitrary order space with nodal primal unknowns.
Definition vsxgrad.hpp:30
Base class for global DOF spaces.
Definition variabledofspace.hpp:17
Definition Mesh2D.hpp:26
Eigen::MatrixXd PermuteTensorization(const size_t a, const size_t b)
Returns the matrix giving the permutation of the tensorization of a family of size a with a family of...
Definition basis.cpp:224
constexpr int dimspace
Dimension, and generic types for vector in correct dimension (makes it easier to translate a code bet...
Definition basis.hpp:53
const Eigen::MatrixXd cellPotential(size_t iT) const
Return the potential operator (expressed on Polykpo3) on the cell of index iT.
Definition vsxgrad.hpp:246
const size_t & degree() const
Return the polynomial degree.
Definition sxgrad.hpp:55
std::function< Eigen::Vector2d(const Eigen::Vector2d &)> FunctionType
Definition vsxgrad.hpp:33
const Mesh & mesh() const
Return the mesh.
Definition sxgrad.hpp:49
std::unique_ptr< PolyBasisEdgeType > Polykmo
Definition ddrcore.hpp:109
std::unique_ptr< Poly2x2BasisCellType > Polykpo2x2
Definition vsxgrad.hpp:66
const Eigen::MatrixXd edgeGradient(size_t iE) const
Return the gradient operator (expressed on Polyk3) on the edge of index iE.
Definition vsxgrad.hpp:161
std::unique_ptr< Poly2BasisEdgeType > Polyk2
Definition vsxgrad.hpp:73
const Eigen::MatrixXd cellDivergence(const Cell &T) const
Return the divergence operator (expressed on the ancester of Polyk3x3, which should be m_sxgrad....
Definition vsxgrad.hpp:240
const Eigen::MatrixXd cellDivergence(size_t iT) const
Return the divergence operator (expressed on the ancester of Polyk3x3, which should be m_sxgrad....
Definition vsxgrad.hpp:234
MatrixFamily< DDRCore::PolyBasisCellType, dimspace > Poly2x2BasisCellType
Definition vsxgrad.hpp:55
auto Polyk2(size_t iT) const -> const Poly2BasisCellType &
Definition vsxgrad.hpp:154
const SXGrad & sXgrad() const
Return the underlying sXgrad space.
Definition vsxgrad.hpp:88
std::unique_ptr< Poly2BasisEdgeType > Polykmo2
Definition vsxgrad.hpp:72
std::vector< double > computeH1norms(const std::vector< Eigen::VectorXd > &list_dofs, const std::string typegrad="full") const
Compute the H^1 discrete norm, with full or symmetric gradient.
Definition vsxgrad.cpp:237
const Eigen::MatrixXd cellSymGradient(const Cell &T) const
Return the symmetric gradient operator (expressed on Polyk3x3) on cell T.
Definition vsxgrad.hpp:228
std::unique_ptr< Poly2BasisCellType > Polykmo2
Definition ddrcore.hpp:91
std::unique_ptr< Poly2BasisCellType > Polykmo2
Definition vsxgrad.hpp:64
std::unique_ptr< Poly2BasisCellType > Polykptwo2
Definition vsxgrad.hpp:65
Eigen::VectorXd interpolate(const FunctionType &q, const int doe_cell=-1) const
Interpolator of a continuous function.
Definition vsxgrad.cpp:79
const LocalOperators & cellOperators(size_t iT) const
Return cell operators for the cell of index iT.
Definition vsxgrad.hpp:315
std::unique_ptr< PolyBasisEdgeType > Polykpo
Definition ddrcore.hpp:107
Eigen::MatrixXd potential
Definition vsxgrad.hpp:48
TensorizedVectorFamily< DDRCore::PolyBasisCellType, dimspace > Poly2BasisCellType
Definition vsxgrad.hpp:54
Family< MonomialScalarBasisCell > PolyBasisCellType
Definition vsxgrad.hpp:53
const EdgeBases & edgeBases(size_t iE) const
Return edge bases for the edge of index iE.
Definition vsxgrad.hpp:302
std::unique_ptr< PolyBasisCellType > Polykpo
Definition ddrcore.hpp:85
const Eigen::MatrixXd edgeGradient(const Edge &E) const
Return the gradient operator (expressed on Polyk3) on edge E.
Definition vsxgrad.hpp:170
TensorizedVectorFamily< DDRCore::PolyBasisEdgeType, dimspace > Poly2BasisEdgeType
Definition vsxgrad.hpp:59
std::vector< VectorRd > computeVertexValues(const Eigen::VectorXd &u) const
Computes the values of the potential reconstruction at the mesh vertices.
Definition vsxgrad.cpp:281
auto PolykpoE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:125
auto PolykptwoE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:129
const Eigen::MatrixXd cellPotential(const Cell &T) const
Return the potential operator on cell T.
Definition vsxgrad.hpp:255
auto PolykE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:122
std::unique_ptr< Poly2BasisEdgeType > Polykptwo2
Definition vsxgrad.hpp:75
const Eigen::MatrixXd edgePotential(size_t iE) const
Return the potential operator on the edge of index iE.
Definition sxgrad.hpp:134
Family< MonomialScalarBasisEdge > PolyBasisEdgeType
Definition vsxgrad.hpp:58
Eigen::MatrixXd rot
Definition vsxgrad.hpp:47
const EdgeBases & edgeBases(const Edge &E) const
Return edge bases for edge E.
Definition vsxgrad.hpp:309
const DDRCore::CellBases & cellBases(size_t iT) const
Return cell bases for the cell of index iT.
Definition sxgrad.hpp:208
const Mesh & mesh() const
Return the mesh.
Definition vsxgrad.hpp:82
const Eigen::MatrixXd edgePotential(size_t iE) const
Return the potential operator (expressed on Polykpo3) on the edge of index iE.
Definition vsxgrad.hpp:176
const Eigen::MatrixXd edgePotential(const Edge &E) const
Return the potential operator (expressed on Polykpo3) on edge E.
Definition vsxgrad.hpp:185
const CellBases & cellBases(const Cell &T) const
Return vector/matrix cell bases for cell T.
Definition vsxgrad.hpp:295
const Eigen::MatrixXd cellGradient(size_t iT) const
Return the gradient operator (expressed on Polyk3x3) on the cell of index iT.
Definition vsxgrad.hpp:192
std::unique_ptr< PolyBasisCellType > Polykmo
Definition ddrcore.hpp:87
std::unique_ptr< PolyBasisCellType > Polykmtwo
Definition ddrcore.hpp:88
const Eigen::MatrixXd cellGradient(const Cell &T) const
Return the gradient operator (expressed on Polyk3x3) on cell T.
Definition vsxgrad.hpp:216
std::unique_ptr< Poly2BasisEdgeType > Polykpo2
Definition vsxgrad.hpp:74
auto Polykmo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:139
Eigen::MatrixXd _permute_bases(size_t iT)
Definition vsxgrad.cpp:128
Eigen::MatrixXd computeStabilisation(const size_t iT, const IntegralWeight &weight=IntegralWeight(1.)) const
Compute the H^1-stabilisation (based on the L^2 stabilisation implemented in SXgrad)
Definition vsxgrad.hpp:263
auto Polykpo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:134
const size_t & degree() const
Return the polynomial degree.
Definition vsxgrad.hpp:94
const Eigen::MatrixXd cellSymGradient(size_t iT) const
Return the symmetric gradient operator (expressed on Polyk3x3) on the cell of index iT.
Definition vsxgrad.hpp:222
Eigen::MatrixXd computeStabilisation(const size_t iT, const IntegralWeight &weight=IntegralWeight(1.)) const
Computes only the stabilisation matrix of the (weighted) L2-product for the cell of index iT.
Definition sxgrad.hpp:186
const Eigen::MatrixXd cellGradient(size_t iT) const
Return the full gradient operator on the cell of index iT.
Definition sxgrad.hpp:146
const LocalOperators & cellOperators(const Cell &T) const
Return cell operators for cell T.
Definition vsxgrad.hpp:321
const CellBases & cellBases(size_t iT) const
Return vector/matrix cell bases for the face of index iT.
Definition vsxgrad.hpp:288
auto Polykptwo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:149
const DDRCore::EdgeBases & edgeBases(size_t iE) const
Return edge bases for the edge of index iE.
Definition sxgrad.hpp:221
const Eigen::MatrixXd cellPotential(size_t iT) const
Return the potential operator on the cell of index iT.
Definition sxgrad.hpp:158
LocalOperators(const Eigen::MatrixXd &_rot, const Eigen::MatrixXd &_potential)
Definition vsxgrad.hpp:37
std::unique_ptr< PolyBasisEdgeType > Polyk
Definition ddrcore.hpp:108
std::unique_ptr< PolyBasisCellType > Polyk
Definition ddrcore.hpp:86
const Eigen::MatrixXd edgeGradient(size_t iE) const
Return the full gradient operator on the edge of index iE.
Definition sxgrad.hpp:122
auto Polyk(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:144
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
if(strcmp(field, 'real')) % real valued entries T
Definition mmread.m:93
Definition ddr-klplate.hpp:27
static auto q
Definition ddrcore-test.hpp:14
Structure for weights (scalar, at the moment) in integral.
Definition integralweight.hpp:33
Definition vsxgrad.hpp:63
Definition vsxgrad.hpp:71
Definition vsxgrad.hpp:36