HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
hho-stokes.hpp
Go to the documentation of this file.
1// Implementation of the HHO scheme, with full gradient, for the Stokes equations -div(mu grad u)+grad p=f, div u = g.
2//
3// Author: Jerome Droniou (jerome.droniou@umontpellier.fr), Daniele Di Pietro (daniele.di-pietro@umontpellier.fr)
4//
5
6/*
7 *
8 * This implementation of HHO was developped following the principles described in
9 * Appendix B of the book
10 *
11 * The Hybrid High-Order Method for Polytopal Meshes: Design, Analysis, and Applications.
12 * D. A. Di Pietro and J. Droniou. Modeling, Simulation and Applications, vol. 19.
13 * Springer International Publishing, 2020, xxxi + 525p. doi: 10.1007/978-3-030-37203-3.
14 * url: https://hal.archives-ouvertes.fr/hal-02151813.
15 *
16 * If you use this code or part of it for a scientific publication, please cite the book
17 * above as a reference for the implementation.
18 *
19 */
20
21
22#ifndef HHOSTOKES_HPP
23#define HHOSTOKES_HPP
24
25#include <iostream>
26
27#include <boost/math/constants/constants.hpp>
28
29#include <Eigen/Sparse>
30#include <unsupported/Eigen/SparseExtra>
31
32#include <mesh.hpp>
33// #include <mesh_builder.hpp>
35#include <linearsolver.hpp>
36
37#include <vhhospace.hpp>
39#include <integralweight.hpp>
40
41
42namespace HArDCore2D
43{
44
45 //------------------------------------------------------------------------------
46 // Stokes model
47 //------------------------------------------------------------------------------
48
50
58 struct Stokes
59 {
60 typedef Eigen::SparseMatrix<double> SystemMatrixType;
61
62 typedef std::function<VectorRd(const VectorRd &)> MomentumForcingTermType;
63 typedef std::function<double(const VectorRd &)> CompressibilityForcingTermType;
64 typedef std::function<VectorRd(const VectorRd &)> VelocityType;
65 typedef std::function<MatrixRd(const VectorRd &)> VelocityGradientType;
66 typedef std::function<double(const VectorRd &)> PressureType;
67 typedef std::function<VectorRd(const VectorRd &)> PressureGradientType;
69
71 Stokes(
72 const VHHOSpace & vhho_space,
73 const GlobalDOFSpace & p_space,
74 const BoundaryConditions & BC,
75 bool use_threads,
76 std::ostream & output = std::cout
77 );
78
81 const MomentumForcingTermType & f,
83 const ViscosityType & mu,
84 const VelocityType & u,
85 Eigen::VectorXd & UDir
86 );
87
89 inline size_t nloc_sc_u() const
90 {
91 return m_nloc_sc_u;
92 }
93
95 inline size_t nloc_sc_p() const
96 {
97 return m_nloc_sc_p;
98 }
99
101 inline size_t numSCDOFs_u() const
102 {
103 return m_vhhospace.mesh().n_cells() * m_nloc_sc_u;
104 }
105
107 inline size_t numSCDOFs_p() const
108 {
109 return m_vhhospace.mesh().n_cells() * m_nloc_sc_p;
110 }
111
113 inline size_t numSCDOFs() const
114 {
115 return numSCDOFs_u() + numSCDOFs_p();
116 }
117
119 inline size_t numDirDOFs() const
120 {
121 return m_BC.n_dir_edges()*m_vhhospace.numLocalDofsEdge();
122 }
123
125 inline size_t dimVelocity() const
126 {
127 return m_vhhospace.dimension();
128 }
129
131 inline size_t dimPressure() const
132 {
133 return m_pspace.dimension();
134 }
135
137 inline size_t numNonSCDOFs() const
138 {
139 return dimVelocity() + dimPressure() - numSCDOFs() + 1;
140 }
141
143 inline size_t sizeSystem() const
144 {
145 return numNonSCDOFs() - numDirDOFs();
146 }
147
149 inline const VHHOSpace & vhhospace() const
150 {
151 return m_vhhospace;
152 }
153
155 inline const GlobalDOFSpace & pspace() const
156 {
157 return m_pspace;
158 }
159
161 inline const Mesh & mesh() const
162 {
163 return m_vhhospace.mesh();
164 }
165
167 inline const SystemMatrixType & systemMatrix() const {
168 return m_A;
169 }
170
173 return m_A;
174 }
175
177 inline const Eigen::VectorXd & systemVector() const {
178 return m_b;
179 }
180
182 inline Eigen::VectorXd & systemVector() {
183 return m_b;
184 }
185
187 inline const double & stabilizationParameter() const {
188 return m_stab_par;
189 }
190
192 inline double & stabilizationParameter() {
193 return m_stab_par;
194 }
195
197 inline const SystemMatrixType & scMatrix() const {
198 return m_sc_A;
199 }
200
202 inline Eigen::VectorXd & scVector() {
203 return m_sc_b;
204 }
205
207 Eigen::VectorXd interpolate(
208 const VelocityType & u,
209 const PressureType & p,
210 const int doe_cell = -1,
211 const int doe_face = -1
212 ) const;
213
215 std::vector<double> computeEnergyNorms(
216 const std::vector<Eigen::VectorXd> & list_dofs
217 ) const;
218
219 private:
221 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
222 _compute_local_contribution(
223 size_t iT,
224 const MomentumForcingTermType & f,
226 const ViscosityType & mu
227 );
228
230 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
231
233 void _assemble_local_contribution(
234 size_t iT,
235 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
236 std::list<Eigen::Triplet<double> > & A1,
237 Eigen::VectorXd & b1,
238 std::list<Eigen::Triplet<double> > & A2,
239 Eigen::VectorXd & b2
240 );
241
243 const VHHOSpace & m_vhhospace;
244 const GlobalDOFSpace & m_pspace;
245
246 const BoundaryConditions & m_BC;
247 bool m_use_threads;
248 std::ostream & m_output;
249 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
250 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
251 SystemMatrixType m_A; // Matrix and RHS of statically condensed system
252 Eigen::VectorXd m_b;
253 SystemMatrixType m_sc_A; // Static condensation operator and RHS (to recover statically condensed DOFs)
254 Eigen::VectorXd m_sc_b;
255 double m_stab_par;
256 };
257
258
259 //------------------------------------------------------------------------------
260 // Exact solutions
261 //------------------------------------------------------------------------------
262
263 static const double PI = boost::math::constants::pi<double>();
264 using std::sin;
265 using std::cos;
266
267 //------------------------------------------------------------------------------
268 // Linear
269
270 double pressure_scaling = 1.;
271
273 linear_u = [](const VectorRd & x) -> VectorRd {
274 return VectorRd(x(0), -x(1));
275 };
276
278 linear_gradu = [](const VectorRd & x) -> MatrixRd {
279 MatrixRd M = MatrixRd::Zero();
280 M << 1., 0., 0., -1.;
281 return M;
282 };
283
285 linear_p = [](const VectorRd & x) -> double {
286 return 0.;
287 };
288
290 linear_gradp = [](const VectorRd & x) -> VectorRd {
291 return VectorRd::Zero();
292 };
293
295 linear_f = [](const VectorRd & x) -> VectorRd {
296 return VectorRd::Zero();
297 };
298
300 linear_g = [](const VectorRd & x)->double { return linear_gradu(x).trace();};
301
304
305 //------------------------------------------------------------------------------
306 // Trigonometric
307
309 trigonometric_u = [](const VectorRd & x) -> VectorRd {
310 return exp(x(0)) * VectorRd(
311 -(x(1) * cos(x(1)) + sin(x(1))),
312 x(1) * sin(x(1))
313 );
314 };
315
318 MatrixRd M = MatrixRd::Zero();
319 M <<
320 -x(1) * cos(x(1)) - sin(x(1)), -2. * cos(x(1)) + x(1) * sin(x(1)),
321 x(1) * sin(x(1)), sin(x(1)) + x(1) * cos(x(1));
322 M *= exp(x(0));
323 return M;
324 };
325
327 trigonometric_p = [](const VectorRd & x) -> double {
328 return 2. * exp(x(0)) * sin(x(1)) - 2. * (exp(1) - 1.) * (1. - cos(1.));
329 };
330
333 return 2. * exp(x(0)) * VectorRd(sin(x(1)), cos(x(1)));
334 };
335
337 trigonometric_f = [](const VectorRd & x) -> VectorRd {
338 return -2. * exp(x(0)) * VectorRd(sin(x(1)), cos(x(1)))
340 };
341
343 trigonometric_g = [](const VectorRd & x)->double { return trigonometric_gradu(x).trace();};
344
347
348
349} // end of namespace HArDCore3D
350
351#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
const size_t n_dir_edges() const
Returns the number of Dirichlet edges.
Definition BoundaryConditions.hpp:70
Base class for global DOF spaces. Provides functions to manipulate global DOFs (the local version bei...
Definition globaldofspace.hpp:16
Class definition: polynomial bases and operators.
Definition vhhospace.hpp:52
Definition Mesh2D.hpp:26
Eigen::Vector2d VectorRd
Definition basis.hpp:55
Eigen::Matrix2d MatrixRd
Definition basis.hpp:54
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
const Mesh & mesh() const
Return a const reference to the mesh.
Definition vhhospace.hpp:140
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
static FullGradientDiffusion::SolutionGradientType linear_gradu
Definition hho-fullgradientdiff.hpp:212
static FullGradientDiffusion::SolutionGradientType trigonometric_gradu
Definition hho-fullgradientdiff.hpp:233
std::size_t n_cells() const
number of cells in the mesh.
Definition Mesh2D.hpp:63
Definition ddr-klplate.hpp:27
double pressure_scaling
Definition hho-stokes.hpp:270
static QuadRot::PotentialType linear_u
Definition ddr-quadrot.hpp:200
static QuadRot::ForcingTermType trigonometric_f
Definition ddr-quadrot.hpp:367
static Stokes::PressureGradientType linear_gradp
Definition hho-stokes.hpp:290
static Stokes::CompressibilityForcingTermType trigonometric_g
Definition hho-stokes.hpp:343
static QuadRot::LagrangeMultiplierType linear_p
Definition ddr-quadrot.hpp:217
static QuadRot::ForcingTermType linear_f
Definition ddr-quadrot.hpp:222
static Stokes::ViscosityType linear_mu
Definition hho-stokes.hpp:303
static Stokes::PressureGradientType trigonometric_gradp
Definition hho-stokes.hpp:332
static QuadRot::LagrangeMultiplierType trigonometric_p
Definition ddr-quadrot.hpp:362
static Stokes::CompressibilityForcingTermType linear_g
Definition hho-stokes.hpp:300
static Stokes::ViscosityType trigonometric_mu
Definition hho-stokes.hpp:346
Structure for weights (scalar, at the moment) in integral.
Definition integralweight.hpp:33
Structure to store information for, and perform, local static condensation.
Definition local_static_condensation.hpp:25
Class for Stokes model.
Definition hho-stokes.hpp:59
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition hho-stokes.hpp:202
const VHHOSpace & vhhospace() const
Returns the velocity space.
Definition hho-stokes.hpp:149
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hho-stokes.hpp:64
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition hho-stokes.hpp:172
std::function< double(const VectorRd &)> PressureType
Definition hho-stokes.hpp:66
std::function< MatrixRd(const VectorRd &)> VelocityGradientType
Definition hho-stokes.hpp:65
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition hho-stokes.hpp:182
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition hho-stokes.hpp:177
std::function< VectorRd(const VectorRd &)> PressureGradientType
Definition hho-stokes.hpp:67
size_t numSCDOFs_u() const
Returns the number of velocity statically condensed DOFs.
Definition hho-stokes.hpp:101
const GlobalDOFSpace & pspace() const
Returns the pressure space.
Definition hho-stokes.hpp:155
size_t nloc_sc_u() const
Returns the local number of velocity statically condensed DOFs.
Definition hho-stokes.hpp:89
Eigen::VectorXd interpolate(const VelocityType &u, const PressureType &p, const int doe_cell=-1, const int doe_face=-1) const
Interpolates velocity and pressure.
Definition hho-stokes.cpp:506
const Mesh & mesh() const
Returns the mesh.
Definition hho-stokes.hpp:161
Eigen::SparseMatrix< double > SystemMatrixType
Definition hho-stokes.hpp:60
std::function< double(const VectorRd &)> CompressibilityForcingTermType
Definition hho-stokes.hpp:63
size_t nloc_sc_p() const
Returns the local number of pressure statically condensed DOFs.
Definition hho-stokes.hpp:95
void assembleLinearSystem(const MomentumForcingTermType &f, const CompressibilityForcingTermType &g, const ViscosityType &mu, const VelocityType &u, Eigen::VectorXd &UDir)
Assemble the global system
Definition hho-stokes.cpp:292
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition hho-stokes.hpp:167
size_t dimPressure() const
Returns the dimension of pressure space.
Definition hho-stokes.hpp:131
size_t dimVelocity() const
Returns the dimension of velocity space.
Definition hho-stokes.hpp:125
double & stabilizationParameter()
Returns the stabilization parameter.
Definition hho-stokes.hpp:192
size_t numDirDOFs() const
Returns the number of Dirichlet DOFs.
Definition hho-stokes.hpp:119
size_t numSCDOFs() const
Returns the number of statically condensed DOFs.
Definition hho-stokes.hpp:113
size_t sizeSystem() const
Returns the size of the final system with Lagrange multiplier, after application of SC and removal of...
Definition hho-stokes.hpp:143
const double & stabilizationParameter() const
Returns the stabilization parameter (scaling)
Definition hho-stokes.hpp:187
IntegralWeight ViscosityType
Definition hho-stokes.hpp:68
const SystemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition hho-stokes.hpp:197
size_t numNonSCDOFs() const
Returns the number of DOFs after SC and with Lagrange multiplier, but before eliminating Dirichlet DO...
Definition hho-stokes.hpp:137
size_t numSCDOFs_p() const
Returns the number of pressure statically condensed DOFs.
Definition hho-stokes.hpp:107
std::function< VectorRd(const VectorRd &)> MomentumForcingTermType
Definition hho-stokes.hpp:62
std::vector< double > computeEnergyNorms(const std::vector< Eigen::VectorXd > &list_dofs) const
Compute the discrete energy norm of a family of vectors representing the dofs.
Definition hho-stokes.cpp:542