HArD::Core3D
Hybrid Arbitrary Degree::Core 3D - Library to implement 3D schemes with vertex, edge, face and cell polynomials as unknowns
Loading...
Searching...
No Matches
ddr-stokes.hpp
Go to the documentation of this file.
1// Implementation of the discrete de Rham sequence for the Stokes problem in curl-curl formulation.
2//
3// Authors: Daniele Di Pietro (daniele.di-pietro@umontpellier.fr)
4// Jerome Droniou (jerome.droniou@monash.edu)
5//
6
7
8#ifndef STOKES_HPP
9#define STOKES_HPP
10
11#include <iostream>
12
13#include <boost/math/constants/constants.hpp>
14
15#include <Eigen/Sparse>
16#include <unsupported/Eigen/SparseExtra>
17
18#include <mesh.hpp>
19#include <mesh_builder.hpp>
21
22#include <xgrad.hpp>
23#include <xcurl.hpp>
24#include <xdiv.hpp>
25
31namespace HArDCore3D
32{
33
40 struct StokesNorms
41 {
43 StokesNorms(double norm_u, double norm_curl_u, double norm_p, double norm_grad_p):
44 u(norm_u),
46 p(norm_p),
48 hcurl_u( std::sqrt( std::pow(norm_u, 2) + std::pow(norm_curl_u, 2) ) ),
49 hgrad_p( std::sqrt( std::pow(norm_p, 2) + std::pow(norm_grad_p, 2) ) )
50 {
51 // do nothing
52 };
53
54 // Constructor without arguments
55 StokesNorms() : StokesNorms(0., 0., 0., 0.) {};
56
57 double u;
58 double curl_u;
59 double p;
60 double grad_p;
61 double hcurl_u;
62 double hgrad_p;
63
64 };
65
67 struct Stokes
68 {
69 typedef Eigen::SparseMatrix<double> SystemMatrixType;
70
71 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> ForcingTermType;
72 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> VelocityType;
73 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> VorticityType;
74 typedef std::function<double(const Eigen::Vector3d &)> PressureType;
75 typedef std::function<Eigen::Vector3d(const Eigen::Vector3d &)> PressureGradientType;
77
79 Stokes(
80 const DDRCore & ddrcore,
81 bool use_threads,
82 std::ostream & output = std::cout
83 );
84
87 const ForcingTermType & f,
88 const VelocityType & u,
89 const VorticityType & omega,
90 const ViscosityType & nu
91 );
92
94 inline size_t dimension() const
95 {
96 return m_xcurl.dimension() + m_xgrad.dimension();
97 }
98
100 inline size_t nbSCDOFs_u() const
101 {
102 return m_ddrcore.mesh().n_cells() * m_nloc_sc_u;
103 }
104
106 inline size_t nbSCDOFs_p() const
107 {
108 return m_ddrcore.mesh().n_cells() * m_nloc_sc_p;
109 }
110
112 inline size_t nbSCDOFs() const
113 {
114 return m_ddrcore.mesh().n_cells() * (m_nloc_sc_u + m_nloc_sc_p);
115 }
116
118 inline size_t sizeSystem() const
119 {
120 return dimension() + 1 - nbSCDOFs();
121 }
122
124 inline const XGrad & xGrad() const
125 {
126 return m_xgrad;
127 }
128
130 inline const XCurl & xCurl() const
131 {
132 return m_xcurl;
133 }
134
136 inline const XDiv & xDiv() const
137 {
138 return m_xdiv;
139 }
140
142 inline const SystemMatrixType & systemMatrix() const {
143 return m_A;
144 }
145
148 return m_A;
149 }
150
152 inline const Eigen::VectorXd & systemVector() const {
153 return m_b;
154 }
155
157 inline Eigen::VectorXd & systemVector() {
158 return m_b;
159 }
160
162 inline const SystemMatrixType & scMatrix() const {
163 return m_sc_A;
164 }
165
167 inline Eigen::VectorXd & scVector() {
168 return m_sc_b;
169 }
170
172 inline const double & stabilizationParameter() const {
173 return m_stab_par;
174 }
175
177 inline double & stabilizationParameter() {
178 return m_stab_par;
179 }
180
182 std::vector<StokesNorms> computeStokesNorms(
183 const std::vector<Eigen::VectorXd> & list_dofs
184 ) const;
185
187 std::pair<StokesNorms, StokesNorms> computeContinuousErrorsNorms(
188 const Eigen::VectorXd & v,
189 const VelocityType & u,
190 const VorticityType & curl_u,
191 const PressureType & p,
192 const PressureGradientType & grad_p
193 ) const;
194
197 const PressureType & p,
198 const PressureGradientType & grad_p,
199 const size_t deg_quad_interpolate
200 ) const;
201
202 private:
204 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
205 _compute_local_contribution(
206 size_t iT,
207 const Eigen::VectorXd & interp_f,
208 const ViscosityType & nu
209 );
210
212 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
213
215 void _assemble_local_contribution(
216 size_t iT,
217 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
218 std::list<Eigen::Triplet<double> > & A1,
219 Eigen::VectorXd & b1,
220 std::list<Eigen::Triplet<double> > & A2,
221 Eigen::VectorXd & b2
222 );
223
224 const DDRCore & m_ddrcore;
225 bool m_use_threads;
226 std::ostream & m_output;
227 const XGrad m_xgrad;
228 const XCurl m_xcurl;
229 const XDiv m_xdiv;
230 const size_t m_nloc_sc_u; // Nb of statically condensed DOFs for velocity in each cell (cell unknowns)
231 const size_t m_nloc_sc_p; // Nb of statically condensed DOFs for pressure in each cell (cell unknowns)
232 SystemMatrixType m_A; // Matrix and RHS of statically condensed system
233 Eigen::VectorXd m_b;
234 SystemMatrixType m_sc_A; // Static condensation operator and RHS (to recover statically condensed DOFs)
235 Eigen::VectorXd m_sc_b;
236 double m_stab_par;
237 };
238
239 //------------------------------------------------------------------------------
240 // Exact solutions
241 //------------------------------------------------------------------------------
242
243 static const double PI = boost::math::constants::pi<double>();
244 using std::sin;
245 using std::cos;
246 using std::pow;
247
248 //------------------------------------------------------------------------------
249 // Trigonometric solution
250 //------------------------------------------------------------------------------
251
252 double pressure_scaling = 1.;
254 trigonometric_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
255 return Eigen::Vector3d(
256 0.5 * sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
257 0.5 * cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
258 -cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2))
259 );
260 };
261
263 trigonometric_curl_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
264 return 3. * PI * Eigen::Vector3d(
265 cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2)),
266 -sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2)),
267 0.
268 );
269 };
270
272 trigonometric_p = [](const Eigen::Vector3d & x) -> double {
273 return pressure_scaling * sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2));
274 };
275
277 trigonometric_grad_p = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
278 return pressure_scaling * 2. * PI * Eigen::Vector3d(
279 cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2)),
280 sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2)),
281 sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2))
282 );
283 };
284
286 trigonometric_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
287 return 6. * std::pow(PI, 2) * Eigen::Vector3d(
288 sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
289 cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
290 -2. * cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2))
291 )
293 };
294
297
298 //------------------------------------------------------------------------------
299 // Linear solution
300 //------------------------------------------------------------------------------
301
303 linear_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
304 return Eigen::Vector3d(x(0), -x(1), 0.);
305 };
306
308 linear_curl_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
309 return Eigen::Vector3d::Zero();
310 };
311
313 linear_p = [](const Eigen::Vector3d & x) -> double {
314 return pressure_scaling * (x(0) - x(1));
315 };
316
318 linear_grad_p = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
319 return pressure_scaling * Eigen::Vector3d(1., -1., 0.);
320 };
321
323 linear_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
324 return linear_grad_p(x);
325 };
326
329
330
331 //------------------------------------------------------------------------------
332 // Solution derived from a field
333 //------------------------------------------------------------------------------
334 // Setting f(x,y,z)= (sin(pi x) sin(pi y) sin(pi z))^3, we take
335 // U=(-d_y f, d_x f, 0), p=0
336 // Calculations are made symbolically in matlab
337
339 field_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
340 double ux = PI*cos(PI*x(1))*pow(sin(PI*x(0)),3.0)*pow(sin(PI*x(1)),2.0)*pow(sin(PI*x(2)),3.0)*3.0;
341 double uy = PI*cos(PI*x(0))*pow(sin(PI*x(0)),2.0)*pow(sin(PI*x(1)),3.0)*pow(sin(PI*x(2)),3.0)*(-3.0);
342 return Eigen::Vector3d(ux, uy, 0.);
343 };
344
346 field_curl_u = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
347 double cux = (PI*PI)*cos(PI*x(0))*cos(PI*x(2))*pow(sin(PI*x(0)),2.0)*pow(sin(PI*x(1)),3.0)*pow(sin(PI*x(2)),2.0)*9.0;
348 double cuy = (PI*PI)*cos(PI*x(1))*cos(PI*x(2))*pow(sin(PI*x(0)),3.0)*pow(sin(PI*x(1)),2.0)*pow(sin(PI*x(2)),2.0)*9.0;
349 double cuz = (PI*PI)*pow(sin(PI*x(0)),3.0)*pow(sin(PI*x(1)),3.0)*pow(sin(PI*x(2)),3.0)*6.0-(PI*PI)*pow(cos(PI*x(0)),2.0)*sin(PI*x(0))*pow(sin(PI*x(1)),3.0)*pow(sin(PI*x(2)),3.0)*6.0-(PI*PI)*pow(cos(PI*x(1)),2.0)*pow(sin(PI*x(0)),3.0)*sin(PI*x(1))*pow(sin(PI*x(2)),3.0)*6.0;
350
351 return Eigen::Vector3d(cux, cuy, cuz);
352 };
353
355 field_p = [](const Eigen::Vector3d & x) -> double {
356 return 0.;
357 };
358
360 field_grad_p = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
361 return Eigen::Vector3d(0., 0., 0.);
362 };
363
365 field_f = [](const Eigen::Vector3d & x) -> Eigen::Vector3d {
366 double fx = (PI*PI*PI)*pow(cos(PI*x(1)),3.0)*pow(sin(PI*x(0)),3.0)*pow(sin(PI*x(2)),3.0)*-6.0+(PI*PI*PI)*cos(PI*x(1))*pow(sin(PI*x(0)),3.0)*pow(sin(PI*x(1)),2.0)*pow(sin(PI*x(2)),3.0)*3.9E+1-(PI*PI*PI)*pow(cos(PI*x(0)),2.0)*cos(PI*x(1))*sin(PI*x(0))*pow(sin(PI*x(1)),2.0)*pow(sin(PI*x(2)),3.0)*1.8E+1-(PI*PI*PI)*cos(PI*x(1))*pow(cos(PI*x(2)),2.0)*pow(sin(PI*x(0)),3.0)*pow(sin(PI*x(1)),2.0)*sin(PI*x(2))*1.8E+1;
367
368 double fy = (PI*PI*PI)*pow(cos(PI*x(0)),3.0)*pow(sin(PI*x(1)),3.0)*pow(sin(PI*x(2)),3.0)*6.0-(PI*PI*PI)*cos(PI*x(0))*pow(sin(PI*x(0)),2.0)*pow(sin(PI*x(1)),3.0)*pow(sin(PI*x(2)),3.0)*3.9E+1+(PI*PI*PI)*cos(PI*x(0))*pow(cos(PI*x(1)),2.0)*pow(sin(PI*x(0)),2.0)*sin(PI*x(1))*pow(sin(PI*x(2)),3.0)*1.8E+1+(PI*PI*PI)*cos(PI*x(0))*pow(cos(PI*x(2)),2.0)*pow(sin(PI*x(0)),2.0)*pow(sin(PI*x(1)),3.0)*sin(PI*x(2))*1.8E+1;
369
370 double fz = 0.;
371 return Eigen::Vector3d(fx, fy, fz);
372 };
373
376
377 //------------------------------------------------------------------------------
378
379
380} // end of namespace HArDCore3D
381
382#endif
Construct all polynomial spaces for the DDR sequence.
Definition ddrcore.hpp:62
Discrete Hcurl space: local operators, L2 product and global interpolator.
Definition xcurl.hpp:19
Discrete Hdiv space: local operators, L2 product and global interpolator.
Definition xdiv.hpp:20
Discrete H1 space: local operators, L2 product and global interpolator.
Definition xgrad.hpp:18
@ Matrix
Definition basis.hpp:67
size_t dimension() const
Returns the dimension of the global space (all DOFs for all geometric entities)
Definition localdofspace.hpp:80
const Mesh & mesh() const
Return a const reference to the mesh.
Definition ddrcore.hpp:134
static const double PI
Definition ddr-magnetostatics.hpp:187
static Magnetostatics::SolutionPotentialType linear_u
Definition ddr-magnetostatics.hpp:214
static Magnetostatics::SolutionPotentialType trigonometric_u
Definition ddr-magnetostatics.hpp:238
static Magnetostatics::ForcingTermType trigonometric_f
Definition ddr-magnetostatics.hpp:256
static Magnetostatics::ForcingTermType linear_f
Definition ddr-magnetostatics.hpp:228
static NavierStokes::PressureType linear_p
Definition sddr-navier-stokes.hpp:577
static NavierStokes::PressureGradientType linear_grad_p
Definition sddr-navier-stokes.hpp:582
static NavierStokes::VorticityType trigonometric_curl_u
Definition sddr-navier-stokes.hpp:482
static NavierStokes::PressureGradientType trigonometric_grad_p
Definition sddr-navier-stokes.hpp:496
static NavierStokes::PressureType trigonometric_p
Definition sddr-navier-stokes.hpp:491
static NavierStokes::VorticityType linear_curl_u
Definition sddr-navier-stokes.hpp:567
double pressure_scaling
Definition sddr-navier-stokes.hpp:464
double grad_p
Norm of grad of pressure.
Definition sddr-navier-stokes.hpp:81
static Stokes::ForcingTermType field_f
Definition ddr-stokes.hpp:365
double & stabilizationParameter()
Returns the stabilization parameter.
Definition ddr-stokes.hpp:177
void assembleLinearSystem(const ForcingTermType &f, const VelocityType &u, const VorticityType &omega, const ViscosityType &nu)
Assemble the global system
Definition ddr-stokes.cpp:298
static Stokes::ViscosityType field_nu
Definition ddr-stokes.hpp:375
size_t nbSCDOFs_u() const
Returns the number of statically condensed DOFs (velocity)
Definition ddr-stokes.hpp:100
std::pair< StokesNorms, StokesNorms > computeContinuousErrorsNorms(const Eigen::VectorXd &v, const VelocityType &u, const VorticityType &curl_u, const PressureType &p, const PressureGradientType &grad_p) const
Compute the continuous Hcurl errors in u and Hgrad error in p (1st component), and same with continuo...
Definition ddr-stokes.cpp:572
static Stokes::ViscosityType trigonometric_nu
Definition ddr-stokes.hpp:296
Eigen::SparseMatrix< double > SystemMatrixType
Definition ddr-stokes.hpp:69
double hgrad_p
Hgrad norm of p.
Definition sddr-navier-stokes.hpp:83
std::vector< StokesNorms > computeStokesNorms(const std::vector< Eigen::VectorXd > &list_dofs) const
Compute the discrete L2 norms, for a family of Eigen::VectorXd representing velocities & pressures,...
Definition ddr-stokes.cpp:516
static Stokes::VelocityType field_u
Definition ddr-stokes.hpp:339
size_t nbSCDOFs_p() const
Returns the number of statically condensed DOFs (pressure)
Definition ddr-stokes.hpp:106
static Stokes::PressureGradientType field_grad_p
Definition ddr-stokes.hpp:360
double hcurl_u
Hcurl norm of u.
Definition sddr-navier-stokes.hpp:82
double evaluateDefectCommutationGradInterp(const PressureType &p, const PressureGradientType &grad_p, const size_t deg_quad_interpolate) const
Evaluate the defect of commutation G_h (Igrad p) = Icurl (grad p) by computing the norm of the differ...
Definition ddr-stokes.cpp:666
const double & stabilizationParameter() const
Returns the stabilization parameter.
Definition ddr-stokes.hpp:172
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition ddr-stokes.hpp:142
static Stokes::ViscosityType linear_nu
Definition ddr-stokes.hpp:328
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> VelocityType
Definition ddr-stokes.hpp:72
size_t nbSCDOFs() const
Returns the number of statically condensed DOFs (both velocity and pressure)
Definition ddr-stokes.hpp:112
size_t sizeSystem() const
Returns the size of the statically condensed system (with Lagrange multiplier)
Definition ddr-stokes.hpp:118
StokesNorms()
Definition ddr-stokes.hpp:55
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> PressureGradientType
Definition ddr-stokes.hpp:75
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition ddr-stokes.hpp:167
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> VorticityType
Definition ddr-stokes.hpp:73
double u
Norm of velocity.
Definition sddr-navier-stokes.hpp:78
std::function< double(const Eigen::Vector3d &)> PressureType
Definition ddr-stokes.hpp:74
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition ddr-stokes.hpp:157
size_t dimension() const
Returns the global problem dimension (without Lagrange multiplier, just velocity & pressure)
Definition ddr-stokes.hpp:94
IntegralWeight ViscosityType
Definition ddr-stokes.hpp:76
StokesNorms(double norm_u, double norm_curl_u, double norm_p, double norm_grad_p)
Constructor.
Definition ddr-stokes.hpp:43
const SystemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition ddr-stokes.hpp:162
const XCurl & xCurl() const
Returns the space XCurl.
Definition ddr-stokes.hpp:130
double p
Norm of pressure.
Definition sddr-navier-stokes.hpp:80
const XDiv & xDiv() const
Returns the space XDiv.
Definition ddr-stokes.hpp:136
static Stokes::VorticityType field_curl_u
Definition ddr-stokes.hpp:346
const XGrad & xGrad() const
Returns the space XGrad.
Definition ddr-stokes.hpp:124
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition ddr-stokes.hpp:152
std::function< Eigen::Vector3d(const Eigen::Vector3d &)> ForcingTermType
Definition ddr-stokes.hpp:71
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition ddr-stokes.hpp:147
double curl_u
Norm of curl of velocity (vorticity)
Definition sddr-navier-stokes.hpp:79
static Stokes::PressureType field_p
Definition ddr-stokes.hpp:355
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
std::size_t n_cells() const
number of cells in the mesh.
Definition MeshND.hpp:60
Definition ddr-magnetostatics.hpp:41
Structure for weights (scalar, at the moment) in integral.
Definition integralweight.hpp:36
Structure to store information for, and perform, local static condensation.
Definition local_static_condensation.hpp:25
Structure to store norm components (for velocity, its curl, pressure, and its gradient),...
Definition sddr-navier-stokes.hpp:62
Assemble a Stokes problem.
Definition ddr-stokes.hpp:68