HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
hho-ustokes.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 HHOUSTOKES_HPP
23#define HHOUSTOKES_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
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 Eigen::VectorXd & u0,
87 double & time_step
88 );
89
91 inline size_t nloc_sc_u() const
92 {
93 return m_nloc_sc_u;
94 }
95
97 inline size_t nloc_sc_p() const
98 {
99 return m_nloc_sc_p;
100 }
101
103 inline size_t numSCDOFs_u() const
104 {
105 return m_vhhospace.mesh().n_cells() * m_nloc_sc_u;
106 }
107
109 inline size_t numSCDOFs_p() const
110 {
111 return m_vhhospace.mesh().n_cells() * m_nloc_sc_p;
112 }
113
115 inline size_t numSCDOFs() const
116 {
117 return numSCDOFs_u() + numSCDOFs_p();
118 }
119
121 inline size_t numDirDOFs() const
122 {
123 return m_BC.n_dir_edges()*m_vhhospace.numLocalDofsEdge();
124 }
125
127 inline size_t dimVelocity() const
128 {
129 return m_vhhospace.dimension();
130 }
131
133 inline size_t dimPressure() const
134 {
135 return m_pspace.dimension();
136 }
137
139 inline size_t numNonSCDOFs() const
140 {
141 return dimVelocity() + dimPressure() - numSCDOFs() + 1;
142 }
143
145 inline size_t sizeSystem() const
146 {
147 return numNonSCDOFs() - numDirDOFs();
148 }
149
151 inline const VHHOSpace & vhhospace() const
152 {
153 return m_vhhospace;
154 }
155
157 inline const GlobalDOFSpace & pspace() const
158 {
159 return m_pspace;
160 }
161
163 inline const Mesh & mesh() const
164 {
165 return m_vhhospace.mesh();
166 }
167
169 inline const SystemMatrixType & systemMatrix() const {
170 return m_A;
171 }
172
175 return m_A;
176 }
177
179 inline const Eigen::VectorXd & systemVector() const {
180 return m_b;
181 }
182
184 inline Eigen::VectorXd & systemVector() {
185 return m_b;
186 }
187
189 inline const double & stabilizationParameter() const {
190 return m_stab_par;
191 }
192
194 inline double & stabilizationParameter() {
195 return m_stab_par;
196 }
197
199 inline const SystemMatrixType & scMatrix() const {
200 return m_sc_A;
201 }
202
204 inline Eigen::VectorXd & scVector() {
205 return m_sc_b;
206 }
207
209 Eigen::VectorXd interpolate(
210 const VelocityType & u,
211 const PressureType & p,
212 const int doe_cell = -1,
213 const int doe_face = -1
214 ) const;
215
217 std::vector<double> computeEnergyNorms(
218 const std::vector<Eigen::VectorXd> & list_dofs
219 ) const;
220
222 Eigen::VectorXd pressureVertexValues(
223 const Eigen::VectorXd & p
224 ) const;
225
226 private:
228 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
229 _compute_local_contribution(
230 size_t iT,
231 const MomentumForcingTermType & f,
233 const ViscosityType & mu,
234 const Eigen::VectorXd & u0,
235 const double & time_step
236 );
237
239 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
240
242 void _assemble_local_contribution(
243 size_t iT,
244 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
245 std::list<Eigen::Triplet<double> > & A1,
246 Eigen::VectorXd & b1,
247 std::list<Eigen::Triplet<double> > & A2,
248 Eigen::VectorXd & b2
249 );
250
252 const VHHOSpace & m_vhhospace;
253 const GlobalDOFSpace & m_pspace;
254
255 const BoundaryConditions & m_BC;
256 bool m_use_threads;
257 std::ostream & m_output;
258 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
259 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
260 SystemMatrixType m_A; // Matrix and RHS of statically condensed system
261 Eigen::VectorXd m_b;
262 SystemMatrixType m_sc_A; // Static condensation operator and RHS (to recover statically condensed DOFs)
263 Eigen::VectorXd m_sc_b;
264 double m_stab_par;
265 };
266
267
268 //------------------------------------------------------------------------------
269 // Exact solutions
270 //------------------------------------------------------------------------------
271/*
272 static const double PI = boost::math::constants::pi<double>();
273 using std::sin;
274 using std::cos;
275
276 //------------------------------------------------------------------------------
277 // Linear
278
279 double pressure_scaling = 1.;
280
281 static Stokes::VelocityType
282 linear_u = [](const VectorRd & x) -> VectorRd {
283 return VectorRd(x(0), -x(1));
284 };
285
286 static Stokes::VelocityGradientType
287 linear_gradu = [](const VectorRd & x) -> MatrixRd {
288 MatrixRd M = MatrixRd::Zero();
289 M << 1., 0., 0., -1.;
290 return M;
291 };
292
293 static Stokes::PressureType
294 linear_p = [](const VectorRd & x) -> double {
295 return 0.;
296 };
297
298 static Stokes::PressureGradientType
299 linear_gradp = [](const VectorRd & x) -> VectorRd {
300 return VectorRd::Zero();
301 };
302
303 static Stokes::MomentumForcingTermType
304 linear_f = [](const VectorRd & x) -> VectorRd {
305 return VectorRd::Zero();
306 };
307
308 static Stokes::CompressibilityForcingTermType
309 linear_g = [](const VectorRd & x)->double { return linear_gradu(x).trace();};
310
311 static Stokes::ViscosityType
312 linear_mu = Stokes::ViscosityType(1.);
313
314 //------------------------------------------------------------------------------
315 // Trigonometric
316
317 static Stokes::VelocityType
318 trigonometric_u = [](const VectorRd & x) -> VectorRd {
319 return exp(x(0)) * VectorRd(
320 -(x(1) * cos(x(1)) + sin(x(1))),
321 x(1) * sin(x(1))
322 );
323 };
324
325 static Stokes::VelocityGradientType
326 trigonometric_gradu = [](const VectorRd & x) -> MatrixRd {
327 MatrixRd M = MatrixRd::Zero();
328 M <<
329 -x(1) * cos(x(1)) - sin(x(1)), -2. * cos(x(1)) + x(1) * sin(x(1)),
330 x(1) * sin(x(1)), sin(x(1)) + x(1) * cos(x(1));
331 M *= exp(x(0));
332 return M;
333 };
334
335 static Stokes::PressureType
336 trigonometric_p = [](const VectorRd & x) -> double {
337 return 2. * exp(x(0)) * sin(x(1)) - 2. * (exp(1) - 1.) * (1. - cos(1.));
338 };
339
340 static Stokes::PressureGradientType
341 trigonometric_gradp = [](const VectorRd & x) -> VectorRd {
342 return 2. * exp(x(0)) * VectorRd(sin(x(1)), cos(x(1)));
343 };
344
345 static Stokes::MomentumForcingTermType
346 trigonometric_f = [](const VectorRd & x) -> VectorRd {
347 return -2. * exp(x(0)) * VectorRd(sin(x(1)), cos(x(1)))
348 + trigonometric_gradp(x);
349 };
350
351 static Stokes::CompressibilityForcingTermType
352 trigonometric_g = [](const VectorRd & x)->double { return trigonometric_gradu(x).trace();};
353
354 static Stokes::ViscosityType
355 trigonometric_mu = Stokes::ViscosityType(1.);
356*/
357
358} // end of namespace HArDCore3D
359
360#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
const Mesh & mesh() const
Return a const reference to the mesh.
Definition vhhospace.hpp:140
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
std::size_t n_cells() const
number of cells in the mesh.
Definition Mesh2D.hpp:63
Definition ddr-klplate.hpp:27
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
Stokes(const VHHOSpace &vhho_space, const GlobalDOFSpace &p_space, const BoundaryConditions &BC, bool use_threads, std::ostream &output=std::cout)
Constructor.
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition hho-ustokes.hpp:204
const VHHOSpace & vhhospace() const
Returns the velocity space.
Definition hho-ustokes.hpp:151
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hho-ustokes.hpp:64
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition hho-ustokes.hpp:174
std::function< double(const VectorRd &)> PressureType
Definition hho-ustokes.hpp:66
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.
std::function< MatrixRd(const VectorRd &)> VelocityGradientType
Definition hho-ustokes.hpp:65
Eigen::VectorXd interpolate(const VelocityType &u, const PressureType &p, const int doe_cell=-1, const int doe_face=-1) const
Interpolates velocity and pressure.
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition hho-ustokes.hpp:184
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition hho-ustokes.hpp:179
std::function< VectorRd(const VectorRd &)> PressureGradientType
Definition hho-ustokes.hpp:67
size_t numSCDOFs_u() const
Returns the number of velocity statically condensed DOFs.
Definition hho-ustokes.hpp:103
const GlobalDOFSpace & pspace() const
Returns the pressure space.
Definition hho-ustokes.hpp:157
size_t nloc_sc_u() const
Returns the local number of velocity statically condensed DOFs.
Definition hho-ustokes.hpp:91
Eigen::VectorXd pressureVertexValues(const Eigen::VectorXd &p) const
Create vertex values for the pressure (from the element values), for plotting.
Definition hho-ustokes.cpp:690
const Mesh & mesh() const
Returns the mesh.
Definition hho-ustokes.hpp:163
Eigen::SparseMatrix< double > SystemMatrixType
Definition hho-ustokes.hpp:60
std::function< double(const VectorRd &)> CompressibilityForcingTermType
Definition hho-ustokes.hpp:63
size_t nloc_sc_p() const
Returns the local number of pressure statically condensed DOFs.
Definition hho-ustokes.hpp:97
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-ustokes.hpp:169
size_t dimPressure() const
Returns the dimension of pressure space.
Definition hho-ustokes.hpp:133
size_t dimVelocity() const
Returns the dimension of velocity space.
Definition hho-ustokes.hpp:127
double & stabilizationParameter()
Returns the stabilization parameter.
Definition hho-ustokes.hpp:194
size_t numDirDOFs() const
Returns the number of Dirichlet DOFs.
Definition hho-ustokes.hpp:121
size_t numSCDOFs() const
Returns the number of statically condensed DOFs.
Definition hho-ustokes.hpp:115
size_t sizeSystem() const
Returns the size of the final system with Lagrange multiplier, after application of SC and removal of...
Definition hho-ustokes.hpp:145
const double & stabilizationParameter() const
Returns the stabilization parameter (scaling)
Definition hho-ustokes.hpp:189
IntegralWeight ViscosityType
Definition hho-ustokes.hpp:68
const SystemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition hho-ustokes.hpp:199
size_t numNonSCDOFs() const
Returns the number of DOFs after SC and with Lagrange multiplier, but before eliminating Dirichlet DO...
Definition hho-ustokes.hpp:139
size_t numSCDOFs_p() const
Returns the number of pressure statically condensed DOFs.
Definition hho-ustokes.hpp:109
std::function< VectorRd(const VectorRd &)> MomentumForcingTermType
Definition hho-ustokes.hpp:62