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
267 // Add to hho-nsa.hpp in the public section:
268std::vector<double> computePhysicalEnergies(
269 const Eigen::VectorXd & uprho,
270 const MomentumForcingTermType & f,
271 const ViscosityType & mu
272 ) const;
273
275 Eigen::VectorXd pressureVertexValues(
276 const Eigen::VectorXd & p
277 ) const;
278
280 Eigen::VectorXd volumicFractionVertexValues(
281 const Eigen::VectorXd & phi
282 ) const;
283
285 void writeToVtuFile(
286 const Eigen::VectorXd & upphi,
287 const Eigen::VectorXd & upphiI,
288 const std::unique_ptr<Mesh> & mesh_ptr,
289 const std::string & solution_name,
290 const std::string & mesh_name,
291 const size_t & degree,
292 const int & time_it
293 );
294
296 Eigen::VectorXd imposingBC(
297 const VelocityType & u,
298 const Eigen::VectorXd & uph
299 ) const;
301 double getUpwindDensity(
302 const size_t & iE,
303 const size_t & iT,
304 const Eigen::VectorXd & uprho
305 ) const;
307 Eigen::VectorXd newtonRaphson(
309 const std::unique_ptr<Mesh> & mesh_ptr,
310 const size_t & newton_maxit,
311 const double & newton_tol,
312 const Eigen::VectorXd & u_newt,
313 const Eigen::VectorXd & un,
314 const MomentumForcingTermType & f,
316 const VolumicFractionType & rhog,
317 const ViscosityType & mu,
318 const double & time_step
319 );
320
321 private:
323 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
324 _compute_local_contribution(
325 size_t iT,
326 const MomentumForcingTermType & f,
328 const VolumicFractionType & rhog,
329 const ViscosityType & mu,
330 const Eigen::VectorXd & u0,
331 const Eigen::VectorXd & uold,
332 const double & time_step
333 );
334
336 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
337
339 void _assemble_local_contribution(
340 size_t iT,
341 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
342 std::list<Eigen::Triplet<double> > & A1,
343 Eigen::VectorXd & b1,
344 std::list<Eigen::Triplet<double> > & A2,
345 Eigen::VectorXd & b2
346 );
347
349 std::pair<Eigen::MatrixXd, Eigen::VectorXd> _compute_local_cell_dG_contribution(
350 size_t iT,
351 const DensityForcingTermType & h,
352 const Eigen::VectorXd & uprho,
353 const double & time_step
354 );
355
357 Eigen::MatrixXd _compute_local_iface_dG_contribution(
358 size_t iF, // local edge index
359 size_t iT1, // global element index
360 size_t iT2,
361 const Eigen::VectorXd & uprho
362 );
363
365 std::pair<Eigen::MatrixXd, Eigen::VectorXd> _compute_local_bface_dG_contribution(
366 size_t iF,
367 size_t iTb,
368 const Eigen::VectorXd & uprho,
369 const VolumicFractionType & rho
370 );
371
373 const VHHOSpace & m_vhhospace;
374 const GlobalDOFSpace & m_pspace;
375 const GlobalDOFSpace & m_phispace;
376 const BoundaryConditions & m_BC;
377 bool m_use_threads;
378 bool m_stokes;
379 std::ostream & m_output;
380
381 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
382 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
383
384 systemMatrixType m_A_hho; // Matrix and RHS of statically condensed system
385 Eigen::VectorXd m_b_hho;
386 systemMatrixType m_sc_A_hho; // Static condensation operator and RHS (to recover statically condensed DOFs)
387 Eigen::VectorXd m_sc_b_hho;
388
389 systemMatrixType m_A_dg; // Matrix and RHS of dG system
390 Eigen::VectorXd m_b_dg;
391
392 double m_stab_par;
393 };
394
395} // end of namespace HArDCore3D
396
397#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:1327
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:1437
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:1635
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:937
std::vector< double > computePhysicalEnergies(const Eigen::VectorXd &uprho, const MomentumForcingTermType &f, const ViscosityType &mu) const
UTILS.
Definition hho-nsa.cpp:1495
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:1014
Eigen::VectorXd volumicFractionVertexValues(const Eigen::VectorXd &phi) const
Create vertex values for volumic fraction.
Definition hho-nsa.cpp:1660
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:1099
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:423
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:889
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:1685
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:863
std::vector< double > computePressureL2Norm(const std::vector< Eigen::VectorXd > &list_dofs) const
Compute the discrete L2 norm of the pressure.
Definition hho-nsa.cpp:1059
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