HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
ddr-quadrot.hpp
Go to the documentation of this file.
1//
2// Solver for a quad-rot problem
3// Author: Daniele Di Pietro (daniele.di-pietro@umontpellier.fr)
4//
5
6
7#ifndef QUADROT_HPP
8#define QUADROT_HPP
9
10#include <iostream>
11
12#include <boost/math/constants/constants.hpp>
13
14#include <Eigen/Sparse>
15#include <unsupported/Eigen/SparseExtra>
16
17#include <mesh.hpp>
18#include <BoundaryConditions/BoundaryConditions.hpp> // To re-order the boundary edges and vertices
20
21#include <xgrad.hpp>
22#include <xrotrot.hpp>
23#include <xrot.hpp>
24
30namespace HArDCore2D
31{
32
38 struct QuadRot {
39 typedef Eigen::SparseMatrix<double> SystemMatrixType;
40
41 typedef std::function<VectorRd(const VectorRd &)> PotentialType;
42 typedef std::function<double(const VectorRd &)> RotorType;
43 typedef std::function<VectorRd(const VectorRd &)> RotRotType;
44 typedef std::function<double(const VectorRd &)> LagrangeMultiplierType;
45 typedef std::function<VectorRd(const VectorRd &)> ForcingTermType;
46
48 QuadRot(
49 const DDRCore & ddrcore,
50 const BoundaryConditions & bc_u,
51 const BoundaryConditions & bc_p,
52 bool use_threads = true,
53 std::ostream & output = std::cout
54 );
55
57 inline const XGrad & xGrad() const
58 {
59 return m_xgrad;
60 }
61
63 inline const XRotRot & xRotRot() const
64 {
65 return m_xrotrot;
66 }
67
69 inline const XRot & xRot() const
70 {
71 return m_xrot;
72 }
73
75 inline const double & stabilizationParameter() const {
76 return m_stab_par;
77 }
78
80 inline double & stabilizationParameter() {
81 return m_stab_par;
82 }
83
85 inline const SystemMatrixType & systemMatrix() const {
86 return m_A;
87 }
88
91 return m_A;
92 }
93
95 inline const Eigen::VectorXd & systemVector() const {
96 return m_b;
97 }
98
100 inline Eigen::VectorXd & systemVector() {
101 return m_b;
102 }
103
105 std::vector<size_t> globalDOFIndices(const Cell & T) const;
106
108 inline size_t dimensionLocalSpace(size_t iT) const
109 {
110 return m_xrotrot.dimensionCell(iT) + m_xgrad.dimensionCell(iT);
111 }
112
114 inline size_t dimensionSpace() const
115 {
116 return m_xrotrot.dimension() + m_xgrad.dimension();
117 }
118
120 inline size_t numBoundaryDofs() const
121 {
122 return m_bc_u.n_dir_vertices() * m_xrotrot.numLocalDofsVertex()
123 + m_bc_u.n_dir_edges() * m_xrotrot.numLocalDofsEdge()
124 + m_bc_p.n_dir_vertices() * m_xgrad.numLocalDofsVertex()
125 + m_bc_p.n_dir_edges() * m_xgrad.numLocalDofsEdge();
126 }
127
129 inline size_t dimensionLinearSystem() const
130 {
131 return dimensionSpace() - numBoundaryDofs();
132 }
133
135 inline int dofToUnknown(size_t i) const
136 {
137 return m_dof_to_unknown(i);
138 }
139
143 Eigen::VectorXd assembleLinearSystem(
144 const ForcingTermType & f,
145 const PotentialType & u,
146 const RotorType & rot_u,
147 const LagrangeMultiplierType & p
148 );
149 private:
151 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
152 _compute_local_contribution(
153 size_t iT,
154 const ForcingTermType & f
155 );
156
158 void _assemble_local_contribution(
159 size_t iT,
160 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
161 std::list<Eigen::Triplet<double> > & triplets_A,
162 Eigen::VectorXd & rsh_b,
163 std::list<Eigen::Triplet<double> > & triplets_boundary_A
164 );
165
166 const DDRCore & m_ddrcore;
167 BoundaryConditions m_bc_u;
168 BoundaryConditions m_bc_p;
169 bool m_use_threads;
170 std::ostream & m_output;
171 double m_stab_par;
172 XGrad m_xgrad;
173 XRotRot m_xrotrot;
174 XRot m_xrot;
177 Eigen::VectorXd m_b;
178 // Indicates the location, among the DOFs, of the unknowns after the Dirichlet DOFs are removed
179 // (m_unknowns_stride[i].first = starting index, m_unknowns_stride[i].second = number of unknowns)
180 std::vector<std::pair<size_t, size_t>> m_unknowns_stride;
181 Eigen::VectorXi m_dof_to_unknown;
182 };
183
188 //------------------------------------------------------------------------------
189 // Exact solutions
190 //------------------------------------------------------------------------------
191
192 static const double PI = boost::math::constants::pi<double>();
193 using std::sin;
194 using std::cos;
195
196 //------------------------------------------------------------------------------
197 // Linear
198
200 linear_u = [](const VectorRd & x) -> VectorRd {
201 VectorRd u_x;
202 u_x << -(x(1) - 0.5), (x(0) - 0.5);
203 return u_x;
204 };
205
206 static QuadRot::RotorType
207 linear_rot_u = [](const VectorRd & x) -> double {
208 return 2.;
209 };
210
213 return VectorRd::Zero();
214 };
215
217 linear_p = [](const VectorRd & x) -> double {
218 return 0.;
219 };
220
222 linear_f = [](const VectorRd & x) -> VectorRd {
223 VectorRd f_x;
224 f_x << 0, 0;
225 return f_x;
226 };
227
228 //------------------------------------------------------------------------------
229 // Quadratic
230
232 quadratic_u = [](const VectorRd & x) -> VectorRd {
233 VectorRd u_x;
234 u_x << -pow(x(1) - 0.5, 2), pow(x(0) - 0.5, 2);
235 return u_x;
236 };
237
238 static QuadRot::RotorType
239 quadratic_rot_u = [](const VectorRd & x) -> double {
240 return 2. * ( x(0) + x(1) - 1 );
241 };
242
245 VectorRd rotrot_u_x;
246 rotrot_u_x << 2., -2.;
247 return rotrot_u_x;
248 };
249
251 quadratic_p = [](const VectorRd & x) -> double {
252 return 0.;
253 };
254
256 quadratic_f = [](const VectorRd & x) -> VectorRd {
257 VectorRd f_x;
258 f_x << 0., 0.;
259 return f_x;
260 };
261
262 //------------------------------------------------------------------------------
263 // Cubic
264
266 cubic_u = [](const VectorRd & x) -> VectorRd {
267 VectorRd u_x;
268 u_x << -pow(x(1) - 0.5, 3), pow(x(0) - 0.5, 3);
269 return u_x;
270 };
271
272 static QuadRot::RotorType
273 cubic_rot_u = [](const VectorRd & x) -> double {
274 return 3. * ( pow(x(0) - 0.5, 2) + pow(x(1) - 0.5, 2) );
275 };
276
279 VectorRd rotrot_u_x;
280 rotrot_u_x << 6. * (x(1) - 0.5), -6. * (x(0) - 0.5);
281 return rotrot_u_x;
282 };
283
285 cubic_p = [](const VectorRd & x) -> double {
286 return 0.;
287 };
288
290 cubic_f = [](const VectorRd & x) -> VectorRd {
291 VectorRd f_x;
292 f_x << 0., 0.;
293 return f_x;
294 };
295
296 //------------------------------------------------------------------------------
297 // Quartic
298
300 quartic_u = [](const VectorRd & x) -> VectorRd {
301 VectorRd u_x;
302 u_x << -pow(x(1) - 0.5, 4), pow(x(0) - 0.5, 4);
303 return u_x;
304 };
305
306 static QuadRot::RotorType
307 quartic_rot_u = [](const VectorRd & x) -> double {
308 return 4. * ( pow(x(0)- 0.5, 3) + pow(x(1) - 0.5, 3) );
309 };
310
313 VectorRd rotrot_u_x;
314 rotrot_u_x << 12. * pow(x(1) - 0.5, 2),
315 -12. * pow(x(0) - 0.5 , 2);
316 return rotrot_u_x;
317 };
318
319 // rot rot rot (u) = -24. * ( x(0) + x(1) - 1 )
320
322 quartic_p = [](const VectorRd & x) -> double {
323 return x(0) * (1. - x(0)) * x(1) * (1. - x(1));
324 };
325
327 quartic_f = [](const VectorRd & x) -> VectorRd {
328 VectorRd f_x;
329 f_x << -24. + (1. - 2. * x(0)) * x(1) * (1. - x(1)),
330 24. + x(0) * (1. - x(0)) * (1. - 2. * x(1));
331 return f_x;
332 };
333
334 //------------------------------------------------------------------------------
335 // Trigonometric
336
338 trigonometric_u = [](const VectorRd & x) -> VectorRd {
339 VectorRd u_x;
340 u_x << -sin(PI * (x(0) + x(1))), sin(PI * (x(0) + x(1)));
341 return u_x;
342 };
343
344 static QuadRot::RotorType
345 trigonometric_rot_u = [](const VectorRd & x) -> double {
346 return 2. * PI * cos(PI * (x(0) + x(1)));
347 };
348
351 VectorRd rotrot_u_x;
352 rotrot_u_x << -sin(PI * (x(0) + x(1))), sin(PI * (x(0) + x(1)));
353 return pow(PI, 2) * rotrot_u_x;
354 };
355
356 static QuadRot::RotorType
357 trigonometric_rotrotrot_u = [](const VectorRd & x) -> double {
358 return 4. * pow(PI, 3) * cos(PI * (x(0) + x(1)));
359 };
360
362 trigonometric_p = [](const VectorRd & x) -> double {
363 return sin(PI * x(0)) * sin(PI * x(1));
364 };
365
367 trigonometric_f = [](const VectorRd & x) -> VectorRd {
368 VectorRd f_x;
369 f_x << -4. * pow(PI, 4) * sin(PI * (x(0) + x(1))) + PI * cos(PI * x(0)) * sin(PI * x(1)),
370 4. * pow(PI, 4) * sin(PI * (x(0) + x(1))) + PI * sin(PI * x(0)) * cos(PI * x(1));
371 return f_x;
372 };
373
374} // end of namespace HArDCore2D
375
376#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
const size_t n_dir_vertices() const
Returns the number of Dirichlet vertices.
Definition BoundaryConditions.hpp:75
const size_t n_dir_edges() const
Returns the number of Dirichlet edges.
Definition BoundaryConditions.hpp:70
Construct all polynomial spaces for the DDR sequence.
Definition ddrcore.hpp:63
Discrete H1 space: local operators, L2 product and global interpolator.
Definition xgrad.hpp:17
Discrete HRotRot space: local operators, L2 product and global interpolator.
Definition xrotrot.hpp:20
Discrete H1 space: local operators, L2 product and global interpolator.
Definition xrot.hpp:18
Compute max and min eigenvalues of all matrices for i
Definition compute_eigs.m:5
Eigen::Vector2d VectorRd
Definition basis.hpp:55
size_t numLocalDofsVertex() const
Returns the number of local vertex DOFs.
Definition localdofspace.hpp:39
size_t dimensionCell(const Cell &T) const
Returns the dimension of the local space on the cell T (including faces, edges and vertices)
Definition localdofspace.hpp:112
size_t dimension() const
Returns the dimension of the global space (all DOFs for all geometric entities)
Definition localdofspace.hpp:61
size_t numLocalDofsEdge() const
Returns the number of local edge DOFs.
Definition localdofspace.hpp:45
static KirchhoffLove::DeflectionType trigonometric_u
Definition ddr-klplate.hpp:197
static const double PI
Definition ddr-klplate.hpp:187
static KirchhoffLove::DeflectionType quartic_u
Definition ddr-klplate.hpp:270
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 QuadRot::RotRotType cubic_rotrot_u
Definition ddr-quadrot.hpp:278
static QuadRot::PotentialType linear_u
Definition ddr-quadrot.hpp:200
static QuadRot::RotRotType quadratic_rotrot_u
Definition ddr-quadrot.hpp:244
static QuadRot::ForcingTermType trigonometric_f
Definition ddr-quadrot.hpp:367
static QuadRot::RotorType quadratic_rot_u
Definition ddr-quadrot.hpp:239
static QuadRot::RotRotType linear_rotrot_u
Definition ddr-quadrot.hpp:212
static QuadRot::RotorType trigonometric_rot_u
Definition ddr-quadrot.hpp:345
static QuadRot::ForcingTermType quartic_f
Definition ddr-quadrot.hpp:327
static QuadRot::RotorType trigonometric_rotrotrot_u
Definition ddr-quadrot.hpp:357
static QuadRot::LagrangeMultiplierType quadratic_p
Definition ddr-quadrot.hpp:251
static QuadRot::LagrangeMultiplierType quartic_p
Definition ddr-quadrot.hpp:322
static QuadRot::RotorType linear_rot_u
Definition ddr-quadrot.hpp:207
static QuadRot::RotRotType quartic_rotrot_u
Definition ddr-quadrot.hpp:312
static QuadRot::LagrangeMultiplierType linear_p
Definition ddr-quadrot.hpp:217
static QuadRot::RotRotType trigonometric_rotrot_u
Definition ddr-quadrot.hpp:350
static QuadRot::RotorType quartic_rot_u
Definition ddr-quadrot.hpp:307
static QuadRot::ForcingTermType linear_f
Definition ddr-quadrot.hpp:222
static QuadRot::ForcingTermType cubic_f
Definition ddr-quadrot.hpp:290
static QuadRot::PotentialType cubic_u
Definition ddr-quadrot.hpp:266
static QuadRot::LagrangeMultiplierType trigonometric_p
Definition ddr-quadrot.hpp:362
static QuadRot::PotentialType quadratic_u
Definition ddr-quadrot.hpp:232
static QuadRot::ForcingTermType quadratic_f
Definition ddr-quadrot.hpp:256
static QuadRot::LagrangeMultiplierType cubic_p
Definition ddr-quadrot.hpp:285
static QuadRot::RotorType cubic_rot_u
Definition ddr-quadrot.hpp:273
Definition ddr-quadrot.hpp:38
int dofToUnknown(size_t i) const
DOF-to-unknown mapping.
Definition ddr-quadrot.hpp:135
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition ddr-quadrot.hpp:85
Eigen::VectorXd assembleLinearSystem(const ForcingTermType &f, const PotentialType &u, const RotorType &rot_u, const LagrangeMultiplierType &p)
Definition ddr-quadrot.cpp:486
const XGrad & xGrad() const
Returns the space XGrad.
Definition ddr-quadrot.hpp:57
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition ddr-quadrot.hpp:100
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition ddr-quadrot.hpp:95
double & stabilizationParameter()
Returns the stabilization parameter.
Definition ddr-quadrot.hpp:80
const double & stabilizationParameter() const
Returns the stabilization parameter.
Definition ddr-quadrot.hpp:75
std::function< double(const VectorRd &)> RotorType
Definition ddr-quadrot.hpp:42
std::vector< size_t > globalDOFIndices(const Cell &T) const
Create the vector of DOF indices for the cell T, which combines the DOFs for the spaces XRotRot and X...
Definition ddr-quadrot.cpp:541
size_t dimensionLocalSpace(size_t iT) const
Returns the dimension of the local potential + Lagrange multiplier space on the element of index iT.
Definition ddr-quadrot.hpp:108
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition ddr-quadrot.hpp:90
const XRot & xRot() const
Returns the space XGrad.
Definition ddr-quadrot.hpp:69
std::function< VectorRd(const VectorRd &)> PotentialType
Definition ddr-quadrot.hpp:41
size_t dimensionLinearSystem() const
Returns the dimension of the linear system.
Definition ddr-quadrot.hpp:129
std::function< double(const VectorRd &)> LagrangeMultiplierType
Definition ddr-quadrot.hpp:44
std::function< VectorRd(const VectorRd &)> RotRotType
Definition ddr-quadrot.hpp:43
std::function< VectorRd(const VectorRd &)> ForcingTermType
Definition ddr-quadrot.hpp:45
size_t numBoundaryDofs() const
Returns the number of boundary DOFs.
Definition ddr-quadrot.hpp:120
const XRotRot & xRotRot() const
Returns the space XRotRot.
Definition ddr-quadrot.hpp:63
size_t dimensionSpace() const
Returns the dimension of the potential + Lagrange multiplier space.
Definition ddr-quadrot.hpp:114
Eigen::SparseMatrix< double > SystemMatrixType
Definition ddr-quadrot.hpp:39