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 <sxcurl.hpp>
6#include <unsupported/Eigen/KroneckerProduct>
7#include <globaldofspace.hpp>
8
9
10namespace HArDCore2D
11{
18
32 {
33 public:
34 // Type of continuous functions corresponding to the discrete space VSXgrad
35 typedef std::function<Eigen::Vector2d(const Eigen::Vector2d &)> FunctionType;
36
38 {
40 const Eigen::MatrixXd & _rot,
41 const Eigen::MatrixXd & _potential
42 )
43 : rot(_rot),
44 potential(_potential)
45 {
46 // Do nothing
47 }
48
49 Eigen::MatrixXd rot;
50 Eigen::MatrixXd potential;
51 };
52
53
54 // Types for element bases
60 // Type for edge basis
63
64 // Structure to store vectorial/matrix cell bases (the scalar ones are in m_sxgrad)
65 struct CellBases
66 {
67 std::unique_ptr<Poly2BasisCellType> Polykmo2;
68 std::unique_ptr<Poly2BasisCellType> Polykptwo2;
69 std::unique_ptr<Poly2x2BasisCellType> Polykpo2x2;
70 };
71
72 // Structure to store vectorial/matrix edge bases (the scalar ones are in m_sxgrad)
73 struct EdgeBases
74 {
75 std::unique_ptr<Poly2BasisEdgeType> Polykmo2;
76 std::unique_ptr<Poly2BasisEdgeType> Polyk2;
77 std::unique_ptr<Poly2BasisEdgeType> Polykpo2;
78 std::unique_ptr<Poly2BasisEdgeType> Polykptwo2;
79 };
80
82 VSXGrad(const DDRCore & ddr_core, const SerendipityProblem & sp, bool use_threads = true, std::ostream & output = std::cout);
83
85 const Mesh & mesh() const
86 {
87 return m_sxgrad.mesh();
88 }
89
91 const SXGrad & sXgrad() const
92 {
93 return m_sxgrad;
94 }
95
97 const size_t & degree() const
98 {
99 return m_sxgrad.degree();
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 //Rename spaces so that their name fit with the fact that we will take degree K+1
119
120
121 inline auto PolykE(size_t iE) const -> const PolyBasisEdgeType& {
122 return *m_sxgrad.edgeBases(iE).Polykmo;
123 }
124 inline auto PolykpoE(size_t iE) const -> const PolyBasisEdgeType& {
125 return *m_sxgrad.edgeBases(iE).Polyk;
126 }
127
128 inline auto PolykptwoE(size_t iE) const -> const PolyBasisEdgeType& {
129 return *m_sxgrad.edgeBases(iE).Polykpo;
130 }
131
132
133 inline auto Polykpo(size_t iT) const -> const PolyBasisCellType& {
134 return *m_sxgrad.cellBases(iT).Polyk;
135 }
136
137
138 inline auto Polykmo(size_t iT) const -> const PolyBasisCellType& {
139 return *m_sxgrad.cellBases(iT).Polykmtwo;
140 }
141
142
143 inline auto Polyk(size_t iT) const -> const PolyBasisCellType& {
144 return *m_sxgrad.cellBases(iT).Polykmo;
145 }
146
147
148 inline auto Polykptwo(size_t iT) const -> const PolyBasisCellType& {
149 return *m_sxgrad.cellBases(iT).Polykpo;
150 }
151
152
153 inline auto Polyk2(size_t iT) const -> const Poly2BasisCellType& {
154 return *m_sxgrad.cellBases(iT).Polykmo2;
155 }
156
157 inline auto Rolyk(size_t iT) const -> const RolyBasisCellType& {
158 return *m_sxgrad.cellBases(iT).Rolykmo;
159 }
160
161 inline auto RolyComplk(size_t iT) const -> const RolyComplBasisCellType& {
162 return *m_sxgrad.cellBases(iT).RolyComplkmo;
163 }
164
165
166
168 inline const Eigen::MatrixXd edgeGradient(size_t iE) const
169 {
170 // The codomain for the edge gradient of sXgrad is Polyk, so we need to change from
171 // R^3 \otimes Polyk to Polyk3 (which is, by construction, Polyk \otimes R^3)
172 return PermuteTensorization(m_sxgrad.edgeBases(iE).Polyk->dimension(), dimspace)
173 * Eigen::KroneckerProduct(m_sxgrad.edgeGradient(iE), Eigen::Matrix2d::Identity());
174 }
175
177 inline const Eigen::MatrixXd edgeGradient(const Edge & E) const
178 {
179 return edgeGradient(E.global_index());
180 }
181
183 inline const Eigen::MatrixXd edgePotential(size_t iE) const
184 {
185 // The codomain for the edge potential of sXgrad is Polykpo, so we need to change from
186 // R^3 \otimes Polykpo to Polykpo3 which is, by construction, Polykpo \otimes R^3
187 return PermuteTensorization(m_sxgrad.edgeBases(iE).Polykpo->dimension(), dimspace)
188 * Eigen::KroneckerProduct(m_sxgrad.edgePotential(iE), Eigen::Matrix2d::Identity());
189 }
190
192 inline const Eigen::MatrixXd edgePotential(const Edge & E) const
193 {
194 return edgePotential(E.global_index());
195 }
196
197
199 inline const Eigen::MatrixXd cellGradient(size_t iT) const
200 {
201 // The codomain for the cell gradient of sXgrad is Polyk3, so we need to change from
202 // R^3 \otimes Polyk3 to Polyk3x3.
203 // Here, Polyk3 = Polyk \otimes R^3, where the R^3=R^3_nabla component represents the derivatives.
204 // We first permute the codomain of m_sxgrad.cellGradient(iT) to make it R^3_nabla \otimes Polyk.
205 Eigen::MatrixXd GradPermutedBasis
206 = PermuteTensorization(dimspace, m_sxgrad.cellBases(iT).Polyk->dimension()) * m_sxgrad.cellGradient(iT);
207
208 // The Kronecker product then gives the cellGradient of vsXgrad in (R^3 \otimes R^3_nabla) \otimes Polyk,
209 // where the first copy of R^3 lists the components of the functions in the vectorized vsXgrad.
210 // We permute this basis to Polyk \otimes (R^3 \otimes R^3_nabla). In this basis, the first index
211 // of R^3 \otimes R^3_nabla goes over the components of the functions, and the second over the coordinates
212 // derivatives.
213 // Polyk3x3 is Polyk \otimes M_N(R) with the basis of M_N(R) listing the canonical
214 // basis vectors in columns; so identifying the basis of R^3 \otimes R^3_nabla with the basis of M_N(R)
215 // organises the functions components in columns and their gradients in rows, which is exactly what
216 // we want. Hence, the matrix obtained on Polyk \otimes (R^3 \otimes R^3_nabla) can directly be interpreted
217 // as the matrix on Polyk \otimes M_N(R) = Polyk3x3.
218 return PermuteTensorization(m_sxgrad.cellBases(iT).Polyk->dimension(), dimspace*dimspace)
219 * Eigen::KroneckerProduct(GradPermutedBasis, Eigen::Matrix2d::Identity());
220 }
221
223 inline const Eigen::MatrixXd cellGradient(const Cell & T) const
224 {
225 return cellGradient(T.global_index());
226 }
227
229 inline const Eigen::MatrixXd cellSymGradient(size_t iT) const
230 {
231 return cellBases(iT).Polykpo2x2->symmetriseOperator() * cellGradient(iT);
232 }
233
235 inline const Eigen::MatrixXd cellSymGradient(const Cell & T) const
236 {
237 return cellSymGradient(T.global_index());
238 }
239
241 inline const Eigen::MatrixXd cellDivergence(size_t iT) const
242 {
243 return cellBases(iT).Polykpo2x2->traceOperator() * cellGradient(iT);
244 }
245
247 inline const Eigen::MatrixXd cellDivergence(const Cell & T) const
248 {
249 return cellDivergence(T.global_index());
250 }
251
253 inline const Eigen::MatrixXd cellPotential(size_t iT) const
254 {
255 // The codomain for the cell potential of sXgrad is Polykpo, so we need to change from
256 // R^3 \otimes Polykpo to Polykpo3 which is, by construction, Polykpo \otimes R^3
257 return PermuteTensorization(m_sxgrad.cellBases(iT).Polykpo->dimension(), dimspace)
258 * Eigen::KroneckerProduct(m_sxgrad.cellPotential(iT), Eigen::Matrix2d::Identity());
259 }
260
262 inline const Eigen::MatrixXd cellPotential(const Cell & T) const
263 {
264 return cellPotential(T.global_index());
265 }
266
267 Eigen::MatrixXd _permute_bases(size_t iT) const;
268
269 Eigen::MatrixXd _injection(size_t iT);
270
272 Eigen::MatrixXd computeStabilisation(
273 const size_t iT,
274 const IntegralWeight & weight = IntegralWeight(1.)
275 ) const
276 {
277 // The H^1-stabilisation is the L^2-stabilisation divided by h_T^2
278 double hTm2 = std::pow(mesh().cell(iT)->diam(), -2);
279 return hTm2 * Eigen::KroneckerProduct(m_sxgrad.computeStabilisation(iT, weight), Eigen::Matrix2d::Identity());
280 }
281
283 std::vector<double> computeH1norms(
284 const std::vector<Eigen::VectorXd> & list_dofs,
285 const std::string typegrad="full"
286 ) const;
287
289 Eigen::MatrixXd computeL2Stabilisation(
290 const size_t iT,
291 const IntegralWeight & weight = IntegralWeight(1.)
292 ) const
293 {
294 return Eigen::KroneckerProduct(m_sxgrad.computeStabilisation(iT, weight), Eigen::Matrix2d::Identity());
295 }
296
298 Eigen::MatrixXd computeScalarProduct(
299 const size_t iT,
300 const double & penalty_factor = 1.,
301 const Eigen::MatrixXd & mass_Pkpo_T = Eigen::MatrixXd::Zero(1,1),
302 const IntegralWeight & weight = IntegralWeight(1.)
303 ) const ;
304
306 std::vector<VectorRd> computeVertexValues(
307 const Eigen::VectorXd & u
308 ) const;
309
310 //-----------------------//
311 //---- Getters ----------//
312
314 inline const CellBases & cellBases(size_t iT) const
315 {
316 assert( m_cell_bases[iT] );
317 return *m_cell_bases[iT].get();
318 }
319
321 inline const CellBases & cellBases(const Cell & T) const
322 {
323 return cellBases(T.global_index());
324 }
325
327 inline const EdgeBases & edgeBases(size_t iE) const
328 {
329 assert( m_edge_bases[iE] );
330 return *m_edge_bases[iE].get();
331 }
332
334 inline const EdgeBases & edgeBases(const Edge & E) const
335 {
336 return edgeBases(E.global_index());
337 }
338
340 inline const LocalOperators & cellOperators(size_t iT) const
341 {
342 return *m_cell_operators[iT];
343 }
344
346 inline const LocalOperators & cellOperators(const Cell & T) const
347 {
348 return *m_cell_operators[T.global_index()];
349 }
350
351 private:
352 EdgeBases _compute_edge_bases(size_t iE);
353 CellBases _compute_cell_bases(size_t iT);
354
355 const DDRCore & m_ddr_core;
356 const SerendipityProblem& m_sp;
357 const SXGrad m_sxgrad; // Not a reference as it is not created outside this class
358 const DDRCore m_ddrcore_for_sxcurl;
359 const SerendipityProblem m_sp_for_sxcurl;
360 const SXCurl m_sxcurl; // Not a reference as it is not created outside this class
361
362 // Cell bases
363 std::vector<std::unique_ptr<CellBases> > m_cell_bases;
364 // Edge bases
365 std::vector<std::unique_ptr<EdgeBases> > m_edge_bases;
366
367 bool m_use_threads;
368 std::ostream & m_output;
369
370 LocalOperators _compute_cell_operators(size_t iT);
371
372 // Containers for local operators
373 std::vector<std::unique_ptr<LocalOperators> > m_cell_operators;
374
375 };
376
377} // end of namespace HArDCore2D
378#endif
Construct all polynomial spaces for the DDR sequence.
Definition ddrcore.hpp:63
Definition basis.hpp:315
Matrix family obtained from a scalar family.
Definition basis.hpp:750
Discrete Serendipity Hcurl space: local operators, L2 product and global interpolator.
Definition sxcurl.hpp:16
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:564
Vector version of sXgrad, the arbitrary order space with nodal primal unknowns.
Definition vsxgrad.hpp:32
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
Family< RolyComplBasisCell > RolyComplBasisCellType
Definition vsxgrad.hpp:59
const Eigen::MatrixXd cellPotential(size_t iT) const
Return the potential operator (expressed on Polykpo3) on the cell of index iT.
Definition vsxgrad.hpp:253
const size_t & degree() const
Return the polynomial degree.
Definition sxgrad.hpp:55
std::function< Eigen::Vector2d(const Eigen::Vector2d &)> FunctionType
Definition vsxgrad.hpp:35
const Mesh & mesh() const
Return the mesh.
Definition sxgrad.hpp:49
Family< CurlBasis< ShiftedBasis< MonomialScalarBasisCell > > > RolyBasisCellType
Definition vsxgrad.hpp:58
std::unique_ptr< PolyBasisEdgeType > Polykmo
Definition ddrcore.hpp:109
std::unique_ptr< Poly2x2BasisCellType > Polykpo2x2
Definition vsxgrad.hpp:69
const Eigen::MatrixXd edgeGradient(size_t iE) const
Return the gradient operator (expressed on Polyk3) on the edge of index iE.
Definition vsxgrad.hpp:168
std::unique_ptr< Poly2BasisEdgeType > Polyk2
Definition vsxgrad.hpp:76
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:247
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:241
MatrixFamily< DDRCore::PolyBasisCellType, dimspace > Poly2x2BasisCellType
Definition vsxgrad.hpp:57
auto Polyk2(size_t iT) const -> const Poly2BasisCellType &
Definition vsxgrad.hpp:153
const SXGrad & sXgrad() const
Return the underlying sXgrad space.
Definition vsxgrad.hpp:91
auto RolyComplk(size_t iT) const -> const RolyComplBasisCellType &
Definition vsxgrad.hpp:161
std::unique_ptr< Poly2BasisEdgeType > Polykmo2
Definition vsxgrad.hpp:75
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:283
const Eigen::MatrixXd cellSymGradient(const Cell &T) const
Return the symmetric gradient operator (expressed on Polyk3x3) on cell T.
Definition vsxgrad.hpp:235
std::unique_ptr< Poly2BasisCellType > Polykmo2
Definition ddrcore.hpp:91
std::unique_ptr< Poly2BasisCellType > Polykmo2
Definition vsxgrad.hpp:67
std::unique_ptr< Poly2BasisCellType > Polykptwo2
Definition vsxgrad.hpp:68
Eigen::VectorXd interpolate(const FunctionType &q, const int doe_cell=-1) const
Interpolator of a continuous function.
Definition vsxgrad.cpp:82
const LocalOperators & cellOperators(size_t iT) const
Return cell operators for the cell of index iT.
Definition vsxgrad.hpp:340
std::unique_ptr< PolyBasisEdgeType > Polykpo
Definition ddrcore.hpp:107
Eigen::MatrixXd potential
Definition vsxgrad.hpp:50
std::unique_ptr< RolyComplBasisCellType > RolyComplkmo
Definition ddrcore.hpp:95
TensorizedVectorFamily< DDRCore::PolyBasisCellType, dimspace > Poly2BasisCellType
Definition vsxgrad.hpp:56
Family< MonomialScalarBasisCell > PolyBasisCellType
Definition vsxgrad.hpp:55
const EdgeBases & edgeBases(size_t iE) const
Return edge bases for the edge of index iE.
Definition vsxgrad.hpp:327
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:177
TensorizedVectorFamily< DDRCore::PolyBasisEdgeType, dimspace > Poly2BasisEdgeType
Definition vsxgrad.hpp:62
std::vector< VectorRd > computeVertexValues(const Eigen::VectorXd &u) const
Computes the values of the potential reconstruction at the mesh vertices.
Definition vsxgrad.cpp:363
auto PolykpoE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:124
auto PolykptwoE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:128
const Eigen::MatrixXd cellPotential(const Cell &T) const
Return the potential operator on cell T.
Definition vsxgrad.hpp:262
auto PolykE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:121
Eigen::MatrixXd _permute_bases(size_t iT) const
Definition vsxgrad.cpp:129
std::unique_ptr< Poly2BasisEdgeType > Polykptwo2
Definition vsxgrad.hpp:78
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:61
Eigen::MatrixXd rot
Definition vsxgrad.hpp:49
const EdgeBases & edgeBases(const Edge &E) const
Return edge bases for edge E.
Definition vsxgrad.hpp:334
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:85
const Eigen::MatrixXd edgePotential(size_t iE) const
Return the potential operator (expressed on Polykpo3) on the edge of index iE.
Definition vsxgrad.hpp:183
Eigen::MatrixXd computeScalarProduct(const size_t iT, const double &penalty_factor=1., const Eigen::MatrixXd &mass_Pkpo_T=Eigen::MatrixXd::Zero(1, 1), const IntegralWeight &weight=IntegralWeight(1.)) const
Compute the L2 scalar product.
Definition vsxgrad.cpp:325
const Eigen::MatrixXd edgePotential(const Edge &E) const
Return the potential operator (expressed on Polykpo3) on edge E.
Definition vsxgrad.hpp:192
const CellBases & cellBases(const Cell &T) const
Return vector/matrix cell bases for cell T.
Definition vsxgrad.hpp:321
const Eigen::MatrixXd cellGradient(size_t iT) const
Return the gradient operator (expressed on Polyk3x3) on the cell of index iT.
Definition vsxgrad.hpp:199
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:223
std::unique_ptr< Poly2BasisEdgeType > Polykpo2
Definition vsxgrad.hpp:77
std::unique_ptr< RolyBasisCellType > Rolykmo
Definition ddrcore.hpp:93
auto Polykmo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:138
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:272
auto Polykpo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:133
const size_t & degree() const
Return the polynomial degree.
Definition vsxgrad.hpp:97
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:229
Eigen::MatrixXd _injection(size_t iT)
Definition vsxgrad.cpp:157
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:346
auto Rolyk(size_t iT) const -> const RolyBasisCellType &
Definition vsxgrad.hpp:157
Eigen::MatrixXd computeL2Stabilisation(const size_t iT, const IntegralWeight &weight=IntegralWeight(1.)) const
Compute the L2 stabilisation.
Definition vsxgrad.hpp:289
const CellBases & cellBases(size_t iT) const
Return vector/matrix cell bases for the face of index iT.
Definition vsxgrad.hpp:314
auto Polykptwo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:148
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:39
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:143
bool use_threads
Definition HHO_DiffAdvecReac.hpp:45
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:66
Definition vsxgrad.hpp:74
Definition vsxgrad.hpp:38