HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
hho-ns.hpp
Go to the documentation of this file.
1// Implementation of the HHO scheme, with full gradient, for the Navier-Stokes equations
2//
3// Authors: Daniele Di Pietro (daniele.di-pietro@umontpellier.fr),
4// Jerome Droniou (jerome.droniou@umontpellier.fr)
5//
6
7/*
8 *
9 * This implementation of HHO was developped following the principles described in
10 * Appendix B of the book
11 *
12 * The Hybrid High-Order Method for Polytopal Meshes: Design, Analysis, and Applications.
13 * D. A. Di Pietro and J. Droniou. Modeling, Simulation and Applications, vol. 19.
14 * Springer International Publishing, 2020, xxxi + 525p. doi: 10.1007/978-3-030-37203-3.
15 * url: https://hal.archives-ouvertes.fr/hal-02151813.
16 *
17 * If you use this code or part of it for a scientific publication, please cite the book
18 * above as a reference for the implementation.
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
36#include <vhhospace.hpp>
38#include <integralweight.hpp>
39
40#include "ns-solutions.hpp"
41
42namespace HArDCore2D
43{
44
45 //------------------------------------------------------------------------------
46 // Navier-Stokes model
47 //------------------------------------------------------------------------------
48
50
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 bool stokes = false,
77 std::ostream & output = std::cout
78 );
79
83 const Eigen::VectorXd & uph_old
84 );
85
87 inline size_t nloc_sc_u() const
88 {
89 return m_nloc_sc_u;
90 }
91
93 inline size_t nloc_sc_p() const
94 {
95 return m_nloc_sc_p;
96 }
97
99 inline size_t numSCDOFs_u() const
100 {
101 return m_vhhospace.mesh().n_cells() * m_nloc_sc_u;
102 }
103
105 inline size_t numSCDOFs_p() const
106 {
107 return m_vhhospace.mesh().n_cells() * m_nloc_sc_p;
108 }
109
111 inline size_t numSCDOFs() const
112 {
113 return numSCDOFs_u() + numSCDOFs_p();
114 }
115
117 inline size_t numDirDOFs() const
118 {
119 return m_BC.n_dir_edges()*m_vhhospace.numLocalDofsEdge();
120 }
121
123 inline size_t dimVelocity() const
124 {
125 return m_vhhospace.dimension();
126 }
127
129 inline size_t dimPressure() const
130 {
131 return m_pspace.dimension();
132 }
133
135 inline size_t numNonSCDOFs() const
136 {
137 return dimVelocity() + dimPressure() - numSCDOFs() + 1;
138 }
139
141 inline size_t sizeSystem() const
142 {
143 return numNonSCDOFs() - numDirDOFs();
144 }
145
147 inline const VHHOSpace & vhhospace() const
148 {
149 return m_vhhospace;
150 }
151
153 inline const GlobalDOFSpace & pspace() const
154 {
155 return m_pspace;
156 }
157
159 inline const Mesh & mesh() const
160 {
161 return m_vhhospace.mesh();
162 }
163
165 inline const SystemMatrixType & systemMatrix() const {
166 return m_A;
167 }
168
171 return m_A;
172 }
173
175 inline const Eigen::VectorXd & systemVector() const {
176 return m_b;
177 }
178
180 inline Eigen::VectorXd & systemVector() {
181 return m_b;
182 }
183
185 inline const double & stabilizationParameter() const {
186 return m_stab_par;
187 }
188
190 inline double & stabilizationParameter() {
191 return m_stab_par;
192 }
193
195 inline const SystemMatrixType & scMatrix() const {
196 return m_sc_A;
197 }
198
200 inline Eigen::VectorXd & scVector() {
201 return m_sc_b;
202 }
203
205 inline bool & isStokes() { return m_stokes; }
206
208 Eigen::VectorXd interpolate(
209 const VelocityType & u,
210 const PressureType & p,
211 const int doe_cell = -1,
212 const int doe_face = -1
213 ) const;
214
216 std::vector<double> computeEnergyNorms(
217 const std::vector<Eigen::VectorXd> & list_dofs
218 ) const;
219
220 private:
222 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
223 _compute_local_contribution(
224 size_t iT,
225 const NavierStokesSolutions::IExactSolution * isolution,
226 const Eigen::VectorXd & uph_old
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 bool m_stokes;
249 std::ostream & m_output;
250 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
251 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
252 SystemMatrixType m_A; // Matrix and RHS of statically condensed system
253 Eigen::VectorXd m_b;
254 SystemMatrixType m_sc_A; // Static condensation operator and RHS (to recover statically condensed DOFs)
255 Eigen::VectorXd m_sc_b;
256 double m_stab_par;
257 };
258
259} // namespace HArDCore2D
260
261#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 the Navier-Stokes model.
Definition hho-ns.hpp:59
bool & isStokes()
Returns the Stokes status.
Definition hho-ns.hpp:205
const GlobalDOFSpace & pspace() const
Returns the pressure space.
Definition hho-ns.hpp:153
size_t nloc_sc_p() const
Returns the local number of pressure statically condensed DOFs.
Definition hho-ns.hpp:93
size_t numNonSCDOFs() const
Returns the number of DOFs after SC and with Lagrange multiplier, but before eliminating Dirichlet DO...
Definition hho-ns.hpp:135
const Mesh & mesh() const
Returns the mesh.
Definition hho-ns.hpp:159
size_t numSCDOFs_p() const
Returns the number of pressure statically condensed DOFs.
Definition hho-ns.hpp:105
size_t numSCDOFs_u() const
Returns the number of velocity statically condensed DOFs.
Definition hho-ns.hpp:99
std::function< VectorRd(const VectorRd &)> MomentumForcingTermType
Definition hho-ns.hpp:62
size_t nloc_sc_u() const
Returns the local number of velocity statically condensed DOFs.
Definition hho-ns.hpp:87
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-ns.cpp:640
IntegralWeight ViscosityType
Definition hho-ns.hpp:68
std::function< VectorRd(const VectorRd &)> PressureGradientType
Definition hho-ns.hpp:67
double & stabilizationParameter()
Returns the stabilization parameter.
Definition hho-ns.hpp:190
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition hho-ns.hpp:165
const double & stabilizationParameter() const
Returns the stabilization parameter (scaling)
Definition hho-ns.hpp:185
size_t numDirDOFs() const
Returns the number of Dirichlet DOFs.
Definition hho-ns.hpp:117
size_t dimVelocity() const
Returns the dimension of velocity space.
Definition hho-ns.hpp:123
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hho-ns.hpp:64
Eigen::SparseMatrix< double > SystemMatrixType
Definition hho-ns.hpp:60
size_t dimPressure() const
Returns the dimension of pressure space.
Definition hho-ns.hpp:129
size_t sizeSystem() const
Returns the size of the final system with Lagrange multiplier, after application of SC and removal of...
Definition hho-ns.hpp:141
std::function< MatrixRd(const VectorRd &)> VelocityGradientType
Definition hho-ns.hpp:65
size_t numSCDOFs() const
Returns the number of statically condensed DOFs.
Definition hho-ns.hpp:111
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-ns.cpp:676
std::function< double(const VectorRd &)> PressureType
Definition hho-ns.hpp:66
void assembleLinearisedSystem(const NavierStokesSolutions::IExactSolution *isolution, const Eigen::VectorXd &uph_old)
Assemble the global system
Definition hho-ns.cpp:316
const VHHOSpace & vhhospace() const
Returns the velocity space.
Definition hho-ns.hpp:147
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition hho-ns.hpp:175
std::function< double(const VectorRd &)> CompressibilityForcingTermType
Definition hho-ns.hpp:63
const SystemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition hho-ns.hpp:195
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition hho-ns.hpp:200
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition hho-ns.hpp:170
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition hho-ns.hpp:180