HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
hho-nsa.hpp
Go to the documentation of this file.
1// Implementation of the HHO scheme, with full gradient, for the Navier-Stokes variable density
2
3
4#ifndef HHONSA_HPP
5#define HHONSA_HPP
6
7#include <iostream>
8
9#include <boost/math/constants/constants.hpp>
10
11#include <Eigen/Sparse>
12#include <unsupported/Eigen/SparseExtra>
13
14#include <mesh.hpp>
15// #include <mesh_builder.hpp>
17#include <linearsolver.hpp>
18
19#include <vhhospace.hpp>
21#include <integralweight.hpp>
22
23
24namespace HArDCore2D
25{
26
27 //------------------------------------------------------------------------------
28 // Navier-Stokes model
29 //------------------------------------------------------------------------------
30
32
41 {
42 typedef Eigen::SparseMatrix<double> systemMatrixType;
43
44 typedef std::function<VectorRd(const VectorRd &)> MomentumForcingTermType;
45 typedef std::function<double(const VectorRd &)> CompressibilityForcingTermType;
46 typedef std::function<double(const VectorRd &)> DensityForcingTermType;
47
48 typedef std::function<VectorRd(const VectorRd &)> VelocityType;
49 typedef std::function<MatrixRd(const VectorRd &)> VelocityGradientType;
50 typedef std::function<double(const VectorRd &)> PressureType;
51 typedef std::function<VectorRd(const VectorRd &)> PressureGradientType;
52 typedef std::function<double(const VectorRd &)> VolumicFractionType;
53
55
58 const VHHOSpace & vhho_space,
59 const GlobalDOFSpace & p_space,
60 const GlobalDOFSpace & phi_space,
61 const BoundaryConditions & BC,
62 bool use_threads,
63 bool stokes = false,
64 std::ostream & output = std::cout
65 );
66
69 const MomentumForcingTermType & f,
71 const VolumicFractionType & rhog,
72 const ViscosityType & mu,
73 const Eigen::VectorXd & u0,
74 const Eigen::VectorXd & uold,
75 const double & time_step
76 );
77
80 const Eigen::VectorXd & uprho,
81 const VolumicFractionType & rho,
82 const double & time_step
83 );
84
86 inline size_t nloc_sc_u() const
87 {
88 return m_nloc_sc_u;
89 }
90
92 inline size_t nloc_sc_p() const
93 {
94 return m_nloc_sc_p;
95 }
96
98 inline size_t numSCDOFs_u() const
99 {
100 return m_vhhospace.mesh().n_cells() * m_nloc_sc_u;
101 }
102
104 inline size_t numSCDOFs_p() const
105 {
106 return m_vhhospace.mesh().n_cells() * m_nloc_sc_p;
107 }
108
110 inline size_t numSCDOFs() const
111 {
112 return numSCDOFs_u() + numSCDOFs_p();
113 }
114
116 inline size_t numDirDOFs() const
117 {
118 return m_BC.n_dir_edges()*m_vhhospace.numLocalDofsEdge();
119 }
120
122 inline size_t dimVelocity() const
123 {
124 return m_vhhospace.dimension();
125 }
126
128 inline size_t dimPressure() const
129 {
130 return m_pspace.dimension();
131 }
132
134 inline size_t dimVolumicFraction() const
135 {
136 return m_phispace.dimension();
137 }
138
140 inline size_t numNonSCDOFs() const
141 {
142 return dimVelocity() + dimPressure() - numSCDOFs() + 1;
143 }
144
146 inline size_t sizeSystemHHO() const
147 {
148 return numNonSCDOFs() - numDirDOFs();
149 }
150
151 inline size_t sizeSystemDG() const
152 {
153 return dimVolumicFraction();
154 }
155
157 inline const VHHOSpace & vhhospace() const
158 {
159 return m_vhhospace;
160 }
161
163 inline const GlobalDOFSpace & pspace() const
164 {
165 return m_pspace;
166 }
167
169 inline const GlobalDOFSpace & phispace() const
170 {
171 return m_phispace;
172 }
173
175 inline const Mesh & mesh() const
176 {
177 return m_vhhospace.mesh();
178 }
179
181 inline const systemMatrixType & systemMatrixHHO() const {
182 return m_A_hho;
183 }
184
187 return m_A_hho;
188 }
189
191 inline const Eigen::VectorXd & systemVector() const {
192 return m_b_hho;
193 }
194
196 inline Eigen::VectorXd & systemVector() {
197 return m_b_hho;
198 }
199
201 inline const double & stabilizationParameter() const {
202 return m_stab_par;
203 }
204
206 inline double & stabilizationParameter() {
207 return m_stab_par;
208 }
209
211 inline const systemMatrixType & scMatrix() const {
212 return m_sc_A_hho;
213 }
214
216 inline Eigen::VectorXd & scVector() {
217 return m_sc_b_hho;
218 }
219
221 inline const systemMatrixType & systemMatrixDG() const {
222 return m_A_dg;
223 }
224
227 return m_A_dg;
228 }
229
231 inline const Eigen::VectorXd & systemVectorDG() const {
232 return m_b_dg;
233 }
234
236 inline Eigen::VectorXd & systemVectorDG() {
237 return m_b_dg;
238 }
239
241 inline bool & isStokes() {
242 return m_stokes;
243 }
244
246 Eigen::VectorXd interpolate(
247 const VelocityType & u,
248 const PressureType & p,
249 const VolumicFractionType & phi,
250 const int doe_cell = -1,
251 const int doe_face = -1
252 ) const;
253
255 std::vector<double> computeEnergyNorms(
256 const std::vector<Eigen::VectorXd> & list_dofs
257 ) const;
258
260 std::vector<double> computePressureL2Norm(
261 const std::vector<Eigen::VectorXd> & list_dofs
262 ) const;
263
265 std::vector<std::tuple<double,double,double>> computeDGNorms(const std::vector<Eigen::VectorXd> & list_dofs, const VelocityType & u) const;
266
268 Eigen::VectorXd pressureVertexValues(
269 const Eigen::VectorXd & p
270 ) const;
271
273 Eigen::VectorXd volumicFractionVertexValues(
274 const Eigen::VectorXd & phi
275 ) const;
276
278 void writeToVtuFile(
279 const Eigen::VectorXd & upphi,
280 const Eigen::VectorXd & upphiI,
281 const std::unique_ptr<Mesh> & mesh_ptr,
282 const std::string & solution_name,
283 const std::string & mesh_name,
284 const size_t & degree,
285 const int & time_it
286 );
287
289 Eigen::VectorXd imposingBC(
290 const VelocityType & u,
291 const Eigen::VectorXd & uph
292 ) const;
294 double getUpwindDensity(
295 const size_t & iE,
296 const size_t & iT,
297 const Eigen::VectorXd & uprho
298 ) const;
300 Eigen::VectorXd newtonRaphson(
302 const std::unique_ptr<Mesh> & mesh_ptr,
303 const size_t & newton_maxit,
304 const double & newton_tol,
305 const Eigen::VectorXd & u_newt,
306 const Eigen::VectorXd & un,
307 const MomentumForcingTermType & f,
309 const VolumicFractionType & rhog,
310 const ViscosityType & mu,
311 const double & time_step
312 );
313
314 private:
316 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
317 _compute_local_contribution(
318 size_t iT,
319 const MomentumForcingTermType & f,
321 const VolumicFractionType & rhog,
322 const ViscosityType & mu,
323 const Eigen::VectorXd & u0,
324 const Eigen::VectorXd & uold,
325 const double & time_step
326 );
327
329 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
330
332 void _assemble_local_contribution(
333 size_t iT,
334 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
335 std::list<Eigen::Triplet<double> > & A1,
336 Eigen::VectorXd & b1,
337 std::list<Eigen::Triplet<double> > & A2,
338 Eigen::VectorXd & b2
339 );
340
342 std::pair<Eigen::MatrixXd, Eigen::VectorXd> _compute_local_cell_dG_contribution(
343 size_t iT,
344 const DensityForcingTermType & h,
345 const Eigen::VectorXd & uprho,
346 const double & time_step
347 );
348
350 Eigen::MatrixXd _compute_local_iface_dG_contribution(
351 size_t iF, // local edge index
352 size_t iT1, // global element index
353 size_t iT2,
354 const Eigen::VectorXd & uprho
355 );
356
358 std::pair<Eigen::MatrixXd, Eigen::VectorXd> _compute_local_bface_dG_contribution(
359 size_t iF,
360 size_t iTb,
361 const Eigen::VectorXd & uprho,
362 const VolumicFractionType & rho
363 );
364
366 const VHHOSpace & m_vhhospace;
367 const GlobalDOFSpace & m_pspace;
368 const GlobalDOFSpace & m_phispace;
369 const BoundaryConditions & m_BC;
370 bool m_use_threads;
371 bool m_stokes;
372 std::ostream & m_output;
373
374 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
375 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
376
377 systemMatrixType m_A_hho; // Matrix and RHS of statically condensed system
378 Eigen::VectorXd m_b_hho;
379 systemMatrixType m_sc_A_hho; // Static condensation operator and RHS (to recover statically condensed DOFs)
380 Eigen::VectorXd m_sc_b_hho;
381
382 systemMatrixType m_A_dg; // Matrix and RHS of dG system
383 Eigen::VectorXd m_b_dg;
384
385 double m_stab_par;
386 };
387
388} // end of namespace HArDCore3D
389
390#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
This structure is a wrapper to allow a given code to select various linear solvers.
Definition linearsolver.hpp:146
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::string mesh_name
Definition HHO_DiffAdvecReac.hpp:44
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 Navier-Stokes model.
Definition hho-nsa.hpp:41
Eigen::VectorXd & systemVectorDG()
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:236
const GlobalDOFSpace & phispace() const
Returns the pressure space.
Definition hho-nsa.hpp:169
std::function< VectorRd(const VectorRd &)> PressureGradientType
Definition hho-nsa.hpp:51
const systemMatrixType & systemMatrixHHO() const
Returns the linear system matrix.
Definition hho-nsa.hpp:181
std::function< double(const VectorRd &)> VolumicFractionType
Definition hho-nsa.hpp:52
std::vector< std::tuple< double, double, double > > computeDGNorms(const std::vector< Eigen::VectorXd > &list_dofs, const VelocityType &u) const
Compute the discrete energy norm of a family of vectors representing the dofs.
Definition hho-nsa.cpp:1318
Eigen::VectorXd interpolate(const VelocityType &u, const PressureType &p, const VolumicFractionType &phi, const int doe_cell=-1, const int doe_face=-1) const
Interpolates velocity and pressure.
Definition hho-nsa.cpp:1428
double & stabilizationParameter()
Returns the stabilization parameter.
Definition hho-nsa.hpp:206
size_t dimPressure() const
Returns the dimension of pressure space.
Definition hho-nsa.hpp:128
const double & stabilizationParameter() const
Returns the stabilization parameter (scaling)
Definition hho-nsa.hpp:201
size_t dimVelocity() const
Returns the dimension of velocity space.
Definition hho-nsa.hpp:122
std::function< double(const VectorRd &)> PressureType
Definition hho-nsa.hpp:50
const Mesh & mesh() const
Returns the mesh.
Definition hho-nsa.hpp:175
Eigen::VectorXd pressureVertexValues(const Eigen::VectorXd &p) const
Create vertex values for the pressure (from the element values), for plotting.
Definition hho-nsa.cpp:1570
size_t nloc_sc_u() const
Returns the local number of velocity statically condensed DOFs.
Definition hho-nsa.hpp:86
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition hho-nsa.hpp:216
std::function< VectorRd(const VectorRd &)> MomentumForcingTermType
Definition hho-nsa.hpp:44
Eigen::VectorXd newtonRaphson(LinearSolver< VarDensityNavierStokes::systemMatrixType > &solver, const std::unique_ptr< Mesh > &mesh_ptr, const size_t &newton_maxit, const double &newton_tol, const Eigen::VectorXd &u_newt, const Eigen::VectorXd &un, const MomentumForcingTermType &f, const CompressibilityForcingTermType &g, const VolumicFractionType &rhog, const ViscosityType &mu, const double &time_step)
newton method
Definition hho-nsa.cpp:928
size_t numDirDOFs() const
Returns the number of Dirichlet DOFs.
Definition hho-nsa.hpp:116
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:191
const GlobalDOFSpace & pspace() const
Returns the pressure space.
Definition hho-nsa.hpp:163
std::function< double(const VectorRd &)> DensityForcingTermType
Definition hho-nsa.hpp:46
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-nsa.cpp:1005
Eigen::VectorXd volumicFractionVertexValues(const Eigen::VectorXd &phi) const
Create vertex values for volumic fraction.
Definition hho-nsa.cpp:1595
size_t numSCDOFs() const
Returns the number of statically condensed DOFs.
Definition hho-nsa.hpp:110
size_t nloc_sc_p() const
Returns the local number of pressure statically condensed DOFs.
Definition hho-nsa.hpp:92
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hho-nsa.hpp:48
std::function< double(const VectorRd &)> CompressibilityForcingTermType
Definition hho-nsa.hpp:45
size_t sizeSystemHHO() const
Returns the size of the final system with Lagrange multiplier, after application of SC and removal of...
Definition hho-nsa.hpp:146
size_t numSCDOFs_p() const
Returns the number of pressure statically condensed DOFs.
Definition hho-nsa.hpp:104
void assembleLinearDGSystem(const CompressibilityForcingTermType &h, const Eigen::VectorXd &uprho, const VolumicFractionType &rho, const double &time_step)
DG ADVECTION SYSTEM.
Definition hho-nsa.cpp:1090
const Eigen::VectorXd & systemVectorDG() const
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:231
void assembleLinearHHOSystem(const MomentumForcingTermType &f, const CompressibilityForcingTermType &g, const VolumicFractionType &rhog, const ViscosityType &mu, const Eigen::VectorXd &u0, const Eigen::VectorXd &uold, const double &time_step)
Assemble the global system
Definition hho-nsa.cpp:414
const VHHOSpace & vhhospace() const
Returns the velocity space.
Definition hho-nsa.hpp:157
systemMatrixType & systemMatrixDG()
Returns the linear system matrix.
Definition hho-nsa.hpp:226
double getUpwindDensity(const size_t &iE, const size_t &iT, const Eigen::VectorXd &uprho) const
get upwind value of the density at the face E
Definition hho-nsa.cpp:880
const systemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition hho-nsa.hpp:211
Eigen::SparseMatrix< double > systemMatrixType
Definition hho-nsa.hpp:42
std::function< MatrixRd(const VectorRd &)> VelocityGradientType
Definition hho-nsa.hpp:49
const systemMatrixType & systemMatrixDG() const
Returns the linear system matrix.
Definition hho-nsa.hpp:221
void writeToVtuFile(const Eigen::VectorXd &upphi, const Eigen::VectorXd &upphiI, const std::unique_ptr< Mesh > &mesh_ptr, const std::string &solution_name, const std::string &mesh_name, const size_t &degree, const int &time_it)
Write solution to vut file.
Definition hho-nsa.cpp:1620
IntegralWeight ViscosityType
Definition hho-nsa.hpp:54
size_t dimVolumicFraction() const
Returns the dimension of pressure space.
Definition hho-nsa.hpp:134
size_t sizeSystemDG() const
Definition hho-nsa.hpp:151
systemMatrixType & systemMatrixHHO()
Returns the linear system matrix.
Definition hho-nsa.hpp:186
size_t numNonSCDOFs() const
Returns the number of DOFs after SC and with Lagrange multiplier, but before eliminating Dirichlet DO...
Definition hho-nsa.hpp:140
bool & isStokes()
Returns the Stokes status.
Definition hho-nsa.hpp:241
Eigen::VectorXd imposingBC(const VelocityType &u, const Eigen::VectorXd &uph) const
impose boundary conditions
Definition hho-nsa.cpp:854
std::vector< double > computePressureL2Norm(const std::vector< Eigen::VectorXd > &list_dofs) const
Compute the discrete L2 norm of the pressure.
Definition hho-nsa.cpp:1050
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:196
size_t numSCDOFs_u() const
Returns the number of velocity statically condensed DOFs.
Definition hho-nsa.hpp:98