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
102
103
104
106 Eigen::VectorXd interpolate(
107 const FunctionType & q,
108 const int doe_cell = -1
109 ) const;
110
111 //---------------------------------------------------------------------//
112 //---- Gradients and potential reconstructions, and stabilisation -----//
113
114 /* Operators from sXgrad are easily extended into operators on vsXgrad using the Kronecker product
115 These extension corresponds to the abovementioned tensorized basis of sXgrad and, for the codomain,
116 to the tensorized basis of R^2 \otimes P (for P the polynomial space in which the operator of sXgrad
117 lands). We need to do a change of basis of that codomain to represent the operators in the bases
118 stored in the structures EdgeBases, FaceBases and CellBases.
119 */
120
121
122 //Rename spaces so that their name fit with the fact that we will take degree K+1
123
124
125 inline auto PolykE(size_t iE) const -> const PolyBasisEdgeType& {
126 return *m_sxgrad.edgeBases(iE).Polykmo;
127 }
128 inline auto PolykpoE(size_t iE) const -> const PolyBasisEdgeType& {
129 return *m_sxgrad.edgeBases(iE).Polyk;
130 }
131
132 inline auto PolykptwoE(size_t iE) const -> const PolyBasisEdgeType& {
133 return *m_sxgrad.edgeBases(iE).Polykpo;
134 }
135
136
137 inline auto Polykpo(size_t iT) const -> const PolyBasisCellType& {
138 return *m_sxgrad.cellBases(iT).Polyk;
139 }
140
141
142 inline auto Polykmo(size_t iT) const -> const PolyBasisCellType& {
143 return *m_sxgrad.cellBases(iT).Polykmtwo;
144 }
145
146
147 inline auto Polyk(size_t iT) const -> const PolyBasisCellType& {
148 return *m_sxgrad.cellBases(iT).Polykmo;
149 }
150
151
152 inline auto Polykptwo(size_t iT) const -> const PolyBasisCellType& {
153 return *m_sxgrad.cellBases(iT).Polykpo;
154 }
155
156
157 inline auto Polyk2(size_t iT) const -> const Poly2BasisCellType& {
158 return *m_sxgrad.cellBases(iT).Polykmo2;
159 }
160
161 inline auto Rolyk(size_t iT) const -> const RolyBasisCellType& {
162 return *m_sxgrad.cellBases(iT).Rolykmo;
163 }
164
165 inline auto RolyComplk(size_t iT) const -> const RolyComplBasisCellType& {
166 return *m_sxgrad.cellBases(iT).RolyComplkmo;
167 }
168
169
170
172 inline const Eigen::MatrixXd edgeGradient(size_t iE) const
173 {
174 // The codomain for the edge gradient of sXgrad is Polyk, so we need to change from
175 // R^3 \otimes Polyk to Polyk3 (which is, by construction, Polyk \otimes R^3)
176 return PermuteTensorization(m_sxgrad.edgeBases(iE).Polyk->dimension(), dimspace)
177 * Eigen::KroneckerProduct(m_sxgrad.edgeGradient(iE), Eigen::Matrix2d::Identity());
178 }
179
181 inline const Eigen::MatrixXd edgeGradient(const Edge & E) const
182 {
183 return edgeGradient(E.global_index());
184 }
185
187 inline const Eigen::MatrixXd edgePotential(size_t iE) const
188 {
189 // The codomain for the edge potential of sXgrad is Polykpo, so we need to change from
190 // R^3 \otimes Polykpo to Polykpo3 which is, by construction, Polykpo \otimes R^3
191 return PermuteTensorization(m_sxgrad.edgeBases(iE).Polykpo->dimension(), dimspace)
192 * Eigen::KroneckerProduct(m_sxgrad.edgePotential(iE), Eigen::Matrix2d::Identity());
193 }
194
196 inline const Eigen::MatrixXd edgePotential(const Edge & E) const
197 {
198 return edgePotential(E.global_index());
199 }
200
201
203 inline const Eigen::MatrixXd cellGradient(size_t iT) const
204 {
205 // The codomain for the cell gradient of sXgrad is Polyk3, so we need to change from
206 // R^3 \otimes Polyk3 to Polyk3x3.
207 // Here, Polyk3 = Polyk \otimes R^3, where the R^3=R^3_nabla component represents the derivatives.
208 // We first permute the codomain of m_sxgrad.cellGradient(iT) to make it R^3_nabla \otimes Polyk.
209 Eigen::MatrixXd GradPermutedBasis
210 = PermuteTensorization(dimspace, m_sxgrad.cellBases(iT).Polyk->dimension()) * m_sxgrad.cellGradient(iT);
211
212 // The Kronecker product then gives the cellGradient of vsXgrad in (R^3 \otimes R^3_nabla) \otimes Polyk,
213 // where the first copy of R^3 lists the components of the functions in the vectorized vsXgrad.
214 // We permute this basis to Polyk \otimes (R^3 \otimes R^3_nabla). In this basis, the first index
215 // of R^3 \otimes R^3_nabla goes over the components of the functions, and the second over the coordinates
216 // derivatives.
217 // Polyk3x3 is Polyk \otimes M_N(R) with the basis of M_N(R) listing the canonical
218 // basis vectors in columns; so identifying the basis of R^3 \otimes R^3_nabla with the basis of M_N(R)
219 // organises the functions components in columns and their gradients in rows, which is exactly what
220 // we want. Hence, the matrix obtained on Polyk \otimes (R^3 \otimes R^3_nabla) can directly be interpreted
221 // as the matrix on Polyk \otimes M_N(R) = Polyk3x3.
222 return PermuteTensorization(m_sxgrad.cellBases(iT).Polyk->dimension(), dimspace*dimspace)
223 * Eigen::KroneckerProduct(GradPermutedBasis, Eigen::Matrix2d::Identity());
224 }
225
227 inline const Eigen::MatrixXd cellGradient(const Cell & T) const
228 {
229 return cellGradient(T.global_index());
230 }
231
233 inline const Eigen::MatrixXd cellSymGradient(size_t iT) const
234 {
235 return cellBases(iT).Polykpo2x2->symmetriseOperator() * cellGradient(iT);
236 }
237
239 inline const Eigen::MatrixXd cellSymGradient(const Cell & T) const
240 {
241 return cellSymGradient(T.global_index());
242 }
243
245 inline const Eigen::MatrixXd cellDivergence(size_t iT) const
246 {
247 return cellBases(iT).Polykpo2x2->traceOperator() * cellGradient(iT);
248 }
249
251 inline const Eigen::MatrixXd cellDivergence(const Cell & T) const
252 {
253 return cellDivergence(T.global_index());
254 }
255
257 inline const Eigen::MatrixXd cellPotential(size_t iT) const
258 {
259 // The codomain for the cell potential of sXgrad is Polykpo, so we need to change from
260 // R^3 \otimes Polykpo to Polykpo3 which is, by construction, Polykpo \otimes R^3
261 return PermuteTensorization(m_sxgrad.cellBases(iT).Polykpo->dimension(), dimspace)
262 * Eigen::KroneckerProduct(m_sxgrad.cellPotential(iT), Eigen::Matrix2d::Identity());
263 }
264
266 inline const Eigen::MatrixXd cellPotential(const Cell & T) const
267 {
268 return cellPotential(T.global_index());
269 }
270
271 Eigen::MatrixXd _permute_bases(size_t iT);
272
273 Eigen::MatrixXd _injection(size_t iT);
274
276 Eigen::MatrixXd computeStabilisation(
277 const size_t iT,
278 const IntegralWeight & weight = IntegralWeight(1.)
279 ) const
280 {
281 // The H^1-stabilisation is the L^2-stabilisation divided by h_T^2
282 double hTm2 = std::pow(mesh().cell(iT)->diam(), -2);
283 return hTm2 * Eigen::KroneckerProduct(m_sxgrad.computeStabilisation(iT, weight), Eigen::Matrix2d::Identity());
284 }
285
287 std::vector<double> computeH1norms(
288 const std::vector<Eigen::VectorXd> & list_dofs,
289 const std::string typegrad="full"
290 ) const;
291
293 std::vector<VectorRd> computeVertexValues(
294 const Eigen::VectorXd & u
295 ) const;
296
297 //-----------------------//
298 //---- Getters ----------//
299
301 inline const CellBases & cellBases(size_t iT) const
302 {
303 assert( m_cell_bases[iT] );
304 return *m_cell_bases[iT].get();
305 }
306
308 inline const CellBases & cellBases(const Cell & T) const
309 {
310 return cellBases(T.global_index());
311 }
312
313
315 inline const EdgeBases & edgeBases(size_t iE) const
316 {
317 assert( m_edge_bases[iE] );
318 return *m_edge_bases[iE].get();
319 }
320
322 inline const EdgeBases & edgeBases(const Edge & E) const
323 {
324 return edgeBases(E.global_index());
325 }
326
328 inline const LocalOperators & cellOperators(size_t iT) const
329 {
330 return *m_cell_operators[iT];
331 }
332
334 inline const LocalOperators & cellOperators(const Cell & T) const
335 {
336 return *m_cell_operators[T.global_index()];
337 }
338
339
340 private:
341 EdgeBases _compute_edge_bases(size_t iE);
342 CellBases _compute_cell_bases(size_t iT);
343
344 const DDRCore & m_ddr_core;
345 const SerendipityProblem& m_sp; // Warning
346 const SXGrad m_sxgrad; // Not a reference as it is not created outside this class
347 const DDRCore m_ddrcore_for_sxcurl; // NEW
348 const SerendipityProblem m_sp_for_sxcurl; // NEW
349 const SXCurl m_sxcurl; // Not a reference as it is not created outside this class
350
351
352 // Cell bases
353 std::vector<std::unique_ptr<CellBases> > m_cell_bases;
354 // Edge bases
355 std::vector<std::unique_ptr<EdgeBases> > m_edge_bases;
356
357 bool m_use_threads;
358 std::ostream & m_output;
359
360 LocalOperators _compute_cell_operators(size_t iT);
361
362
363 // Containers for local operators
364 std::vector<std::unique_ptr<LocalOperators> > m_cell_operators;
365
366 };
367
368} // end of namespace HArDCore2D
369#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:257
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:172
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:251
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:245
MatrixFamily< DDRCore::PolyBasisCellType, dimspace > Poly2x2BasisCellType
Definition vsxgrad.hpp:57
auto Polyk2(size_t iT) const -> const Poly2BasisCellType &
Definition vsxgrad.hpp:157
const SXGrad & sXgrad() const
Return the underlying sXgrad space.
Definition vsxgrad.hpp:91
auto RolyComplk(size_t iT) const -> const RolyComplBasisCellType &
Definition vsxgrad.hpp:165
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:284
const Eigen::MatrixXd cellSymGradient(const Cell &T) const
Return the symmetric gradient operator (expressed on Polyk3x3) on cell T.
Definition vsxgrad.hpp:239
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:328
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:315
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:181
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:327
auto PolykpoE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:128
auto PolykptwoE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:132
const Eigen::MatrixXd cellPotential(const Cell &T) const
Return the potential operator on cell T.
Definition vsxgrad.hpp:266
auto PolykE(size_t iE) const -> const PolyBasisEdgeType &
Definition vsxgrad.hpp:125
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:322
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:187
const Eigen::MatrixXd edgePotential(const Edge &E) const
Return the potential operator (expressed on Polykpo3) on edge E.
Definition vsxgrad.hpp:196
const CellBases & cellBases(const Cell &T) const
Return vector/matrix cell bases for cell T.
Definition vsxgrad.hpp:308
const Eigen::MatrixXd cellGradient(size_t iT) const
Return the gradient operator (expressed on Polyk3x3) on the cell of index iT.
Definition vsxgrad.hpp:203
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:227
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:142
Eigen::MatrixXd _permute_bases(size_t iT)
Definition vsxgrad.cpp:129
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:276
auto Polykpo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:137
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:233
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:334
auto Rolyk(size_t iT) const -> const RolyBasisCellType &
Definition vsxgrad.hpp:161
const CellBases & cellBases(size_t iT) const
Return vector/matrix cell bases for the face of index iT.
Definition vsxgrad.hpp:301
auto Polykptwo(size_t iT) const -> const PolyBasisCellType &
Definition vsxgrad.hpp:152
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:147
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:66
Definition vsxgrad.hpp:74
Definition vsxgrad.hpp:38