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
31namespace HArDCore2D
32{
38 //------------------------------------------------------------------------------
39 // Navier-Stokes model
40 //------------------------------------------------------------------------------
41
43
52 {
53 typedef Eigen::SparseMatrix<double> systemMatrixType;
54
55 typedef std::function<VectorRd(const VectorRd &)> MomentumForcingTermType;
56 typedef std::function<double(const VectorRd &)> CompressibilityForcingTermType;
57 typedef std::function<double(const VectorRd &)> DensityForcingTermType;
58
59 typedef std::function<VectorRd(const VectorRd &)> VelocityType;
60 typedef std::function<MatrixRd(const VectorRd &)> VelocityGradientType;
61 typedef std::function<double(const VectorRd &)> PressureType;
62 typedef std::function<VectorRd(const VectorRd &)> PressureGradientType;
63 typedef std::function<double(const VectorRd &)> VolumicFractionType;
64
66
69 const VHHOSpace & vhho_space,
70 const GlobalDOFSpace & p_space,
71 const GlobalDOFSpace & phi_space,
72 const BoundaryConditions & BC,
73 bool use_threads,
74 bool stokes = false,
75 std::ostream & output = std::cout
76 );
77
80 const MomentumForcingTermType & f,
82 const VolumicFractionType & rhog,
83 const ViscosityType & mu,
84 const Eigen::VectorXd & u0,
85 const Eigen::VectorXd & uold,
86 const double & time_step
87 );
88
91 const Eigen::VectorXd & uprho,
92 const VolumicFractionType & rho,
93 const double & time_step
94 );
95
97 inline size_t nloc_sc_u() const
98 {
99 return m_nloc_sc_u;
100 }
101
103 inline size_t nloc_sc_p() const
104 {
105 return m_nloc_sc_p;
106 }
107
109 inline size_t numSCDOFs_u() const
110 {
111 return m_vhhospace.mesh().n_cells() * m_nloc_sc_u;
112 }
113
115 inline size_t numSCDOFs_p() const
116 {
117 return m_vhhospace.mesh().n_cells() * m_nloc_sc_p;
118 }
119
121 inline size_t numSCDOFs() const
122 {
123 return numSCDOFs_u() + numSCDOFs_p();
124 }
125
127 inline size_t numDirDOFs() const
128 {
129 return m_BC.n_dir_edges()*m_vhhospace.numLocalDofsEdge();
130 }
131
133 inline size_t dimVelocity() const
134 {
135 return m_vhhospace.dimension();
136 }
137
139 inline size_t dimPressure() const
140 {
141 return m_pspace.dimension();
142 }
143
145 inline size_t dimVolumicFraction() const
146 {
147 return m_phispace.dimension();
148 }
149
151 inline size_t numNonSCDOFs() const
152 {
153 return dimVelocity() + dimPressure() - numSCDOFs() + 1;
154 }
155
157 inline size_t sizeSystemHHO() const
158 {
159 return numNonSCDOFs() - numDirDOFs();
160 }
161
162 inline size_t sizeSystemDG() const
163 {
164 return dimVolumicFraction();
165 }
166
168 inline const VHHOSpace & vhhospace() const
169 {
170 return m_vhhospace;
171 }
172
174 inline const GlobalDOFSpace & pspace() const
175 {
176 return m_pspace;
177 }
178
180 inline const GlobalDOFSpace & phispace() const
181 {
182 return m_phispace;
183 }
184
186 inline const Mesh & mesh() const
187 {
188 return m_vhhospace.mesh();
189 }
190
192 inline const systemMatrixType & systemMatrixHHO() const {
193 return m_A_hho;
194 }
195
198 return m_A_hho;
199 }
200
202 inline const Eigen::VectorXd & systemVector() const {
203 return m_b_hho;
204 }
205
207 inline Eigen::VectorXd & systemVector() {
208 return m_b_hho;
209 }
210
212 inline const double & stabilizationParameter() const {
213 return m_stab_par;
214 }
215
217 inline double & stabilizationParameter() {
218 return m_stab_par;
219 }
220
222 inline const systemMatrixType & scMatrix() const {
223 return m_sc_A_hho;
224 }
225
227 inline Eigen::VectorXd & scVector() {
228 return m_sc_b_hho;
229 }
230
232 inline const systemMatrixType & systemMatrixDG() const {
233 return m_A_dg;
234 }
235
238 return m_A_dg;
239 }
240
242 inline const Eigen::VectorXd & systemVectorDG() const {
243 return m_b_dg;
244 }
245
247 inline Eigen::VectorXd & systemVectorDG() {
248 return m_b_dg;
249 }
250
252 inline bool & isStokes() {
253 return m_stokes;
254 }
255
257 Eigen::VectorXd interpolate(
258 const VelocityType & u,
259 const PressureType & p,
260 const VolumicFractionType & phi,
261 const int doe_cell = -1,
262 const int doe_face = -1
263 ) const;
264
266 std::vector<double> computeEnergyNorms(
267 const std::vector<Eigen::VectorXd> & list_dofs
268 ) const;
269
271 std::vector<double> computePressureL2Norm(
272 const std::vector<Eigen::VectorXd> & list_dofs
273 ) const;
274
276 std::vector<std::tuple<double,double,double>> computeDGNorms(const std::vector<Eigen::VectorXd> & list_dofs, const VelocityType & u) const;
277
278 // Add to hho-nsa.hpp in the public section:
279std::vector<double> computePhysicalEnergies(
280 const Eigen::VectorXd & uprho,
281 const MomentumForcingTermType & f,
282 const ViscosityType & mu
283 ) const;
284
286 Eigen::VectorXd pressureVertexValues(
287 const Eigen::VectorXd & p
288 ) const;
289
291 Eigen::VectorXd volumicFractionVertexValues(
292 const Eigen::VectorXd & phi
293 ) const;
294
296 void writeToVtuFile(
297 const Eigen::VectorXd & upphi,
298 const Eigen::VectorXd & upphiI,
299 const std::unique_ptr<Mesh> & mesh_ptr,
300 const std::string & solution_name,
301 const std::string & mesh_name,
302 const size_t & degree,
303 const int & time_it,
304 const double & reynolds,
305 const std::vector<std::string> & plot_variables,
306 const std::string & output_path
307 );
308
309 // Write data to file
311 const std::string & filename,
312 const int & time_it,
313 const double & time,
314 const double & dt,
315 const double & L2_u_err,
316 const double & H1_u_err,
317 const double & Energy_err,
318 const double & L2_rho_err,
319 const double & cf_rho_err,
320 const double & upw_rho_err,
321 const double & E_kinetic,
322 const double & E_potential,
323 const double & E_dissipation
324 ) const;
325
326 void writeFileHeader(
327 const std::string & filename,
328 const std::string & solution_name,
329 const int & solution_number,
330 const std::string & mesh_name,
331 const size_t & degree,
332 const std::unique_ptr<Mesh> & mesh_ptr,
333 const double & viscosity
334 ) const;
335
337 Eigen::VectorXd imposingBC(
338 const VelocityType & u,
339 const Eigen::VectorXd & uph
340 ) const;
343 const size_t & iE,
344 const size_t & iT,
345 const Eigen::VectorXd & uprho
346 ) const;
348 Eigen::VectorXd newtonRaphson(
350 const std::unique_ptr<Mesh> & mesh_ptr,
351 const size_t & newton_maxit,
352 const double & newton_tol,
353 const Eigen::VectorXd & u_newt,
354 const Eigen::VectorXd & un,
355 const MomentumForcingTermType & f,
357 const VolumicFractionType & rhog,
358 const ViscosityType & mu,
359 const double & time_step
360 );
361
362 private:
364 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
365 _compute_local_contribution(
366 size_t iT,
367 const MomentumForcingTermType & f,
369 const VolumicFractionType & rhog,
370 const ViscosityType & mu,
371 const Eigen::VectorXd & u0,
372 const Eigen::VectorXd & uold,
373 const double & time_step
374 );
375
377 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
378
380 void _assemble_local_contribution(
381 size_t iT,
382 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
383 std::list<Eigen::Triplet<double> > & A1,
384 Eigen::VectorXd & b1,
385 std::list<Eigen::Triplet<double> > & A2,
386 Eigen::VectorXd & b2
387 );
388
390 std::pair<Eigen::MatrixXd, Eigen::VectorXd> _compute_local_cell_dG_contribution(
391 size_t iT,
393 const Eigen::VectorXd & uprho,
394 const double & time_step
395 );
396
398 Eigen::MatrixXd _compute_local_iface_dG_contribution(
399 size_t iF, // local edge index
400 size_t iT1, // global element index
401 size_t iT2,
402 const Eigen::VectorXd & uprho
403 );
404
406 std::pair<Eigen::MatrixXd, Eigen::VectorXd> _compute_local_bface_dG_contribution(
407 size_t iF,
408 size_t iTb,
409 const Eigen::VectorXd & uprho,
410 const VolumicFractionType & rho
411 );
412
414 const VHHOSpace & m_vhhospace;
415 const GlobalDOFSpace & m_pspace;
416 const GlobalDOFSpace & m_phispace;
417 const BoundaryConditions & m_BC;
418 bool m_use_threads;
419 bool m_stokes;
420 std::ostream & m_output;
421
422 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
423 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
424
425 systemMatrixType m_A_hho; // Matrix and RHS of statically condensed system
426 Eigen::VectorXd m_b_hho;
427 systemMatrixType m_sc_A_hho; // Static condensation operator and RHS (to recover statically condensed DOFs)
428 Eigen::VectorXd m_sc_b_hho;
429
430 systemMatrixType m_A_dg; // Matrix and RHS of dG system
431 Eigen::VectorXd m_b_dg;
432
433 double m_stab_par;
434 };
435
436} // end of namespace HArDCore3D
437
438#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
end Construct full filename filename
Definition convergence_analysis.m:142
Determine mesh name based on folder switch folder_name case ca_tri For triangular etc mesh_name
Definition convergence_analysis.m:126
end function h
Definition convergence_analysis.m:146
dt
Definition convergence_analysis.m:120
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:45
Eigen::VectorXd & systemVectorDG()
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:247
const GlobalDOFSpace & phispace() const
Returns the pressure space.
Definition hho-nsa.hpp:180
std::function< VectorRd(const VectorRd &)> PressureGradientType
Definition hho-nsa.hpp:62
const systemMatrixType & systemMatrixHHO() const
Returns the linear system matrix.
Definition hho-nsa.hpp:192
std::function< double(const VectorRd &)> VolumicFractionType
Definition hho-nsa.hpp:63
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
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:1363
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:1472
double & stabilizationParameter()
Returns the stabilization parameter.
Definition hho-nsa.hpp:217
size_t dimPressure() const
Returns the dimension of pressure space.
Definition hho-nsa.hpp:139
const double & stabilizationParameter() const
Returns the stabilization parameter (scaling)
Definition hho-nsa.hpp:212
size_t dimVelocity() const
Returns the dimension of velocity space.
Definition hho-nsa.hpp:133
std::function< double(const VectorRd &)> PressureType
Definition hho-nsa.hpp:61
const Mesh & mesh() const
Returns the mesh.
Definition hho-nsa.hpp:186
Eigen::VectorXd pressureVertexValues(const Eigen::VectorXd &p) const
Create vertex values for the pressure (from the element values), for plotting.
Definition hho-nsa.cpp:1671
size_t nloc_sc_u() const
Returns the local number of velocity statically condensed DOFs.
Definition hho-nsa.hpp:97
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition hho-nsa.hpp:227
std::function< VectorRd(const VectorRd &)> MomentumForcingTermType
Definition hho-nsa.hpp:55
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:975
std::vector< double > computePhysicalEnergies(const Eigen::VectorXd &uprho, const MomentumForcingTermType &f, const ViscosityType &mu) const
UTILS.
Definition hho-nsa.cpp:1530
size_t numDirDOFs() const
Returns the number of Dirichlet DOFs.
Definition hho-nsa.hpp:127
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:202
const GlobalDOFSpace & pspace() const
Returns the pressure space.
Definition hho-nsa.hpp:174
std::function< double(const VectorRd &)> DensityForcingTermType
Definition hho-nsa.hpp:57
void writeTimeStepData(const std::string &filename, const int &time_it, const double &time, const double &dt, const double &L2_u_err, const double &H1_u_err, const double &Energy_err, const double &L2_rho_err, const double &cf_rho_err, const double &upw_rho_err, const double &E_kinetic, const double &E_potential, const double &E_dissipation) const
Writing data to txt file.
Definition hho-nsa.cpp:1856
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:1052
Eigen::VectorXd volumicFractionVertexValues(const Eigen::VectorXd &phi) const
Create vertex values for volumic fraction.
Definition hho-nsa.cpp:1696
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, const double &reynolds, const std::vector< std::string > &plot_variables, const std::string &output_path)
Write solution to vut file.
Definition hho-nsa.cpp:1722
size_t numSCDOFs() const
Returns the number of statically condensed DOFs.
Definition hho-nsa.hpp:121
size_t nloc_sc_p() const
Returns the local number of pressure statically condensed DOFs.
Definition hho-nsa.hpp:103
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hho-nsa.hpp:59
std::function< double(const VectorRd &)> CompressibilityForcingTermType
Definition hho-nsa.hpp:56
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:157
size_t numSCDOFs_p() const
Returns the number of pressure statically condensed DOFs.
Definition hho-nsa.hpp:115
void assembleLinearDGSystem(const CompressibilityForcingTermType &h, const Eigen::VectorXd &uprho, const VolumicFractionType &rho, const double &time_step)
DG ADVECTION SYSTEM.
Definition hho-nsa.cpp:1137
const Eigen::VectorXd & systemVectorDG() const
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:242
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:474
const VHHOSpace & vhhospace() const
Returns the velocity space.
Definition hho-nsa.hpp:168
systemMatrixType & systemMatrixDG()
Returns the linear system matrix.
Definition hho-nsa.hpp:237
const systemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition hho-nsa.hpp:222
Eigen::SparseMatrix< double > systemMatrixType
Definition hho-nsa.hpp:53
std::function< MatrixRd(const VectorRd &)> VelocityGradientType
Definition hho-nsa.hpp:60
const systemMatrixType & systemMatrixDG() const
Returns the linear system matrix.
Definition hho-nsa.hpp:232
IntegralWeight ViscosityType
Definition hho-nsa.hpp:65
size_t dimVolumicFraction() const
Returns the dimension of pressure space.
Definition hho-nsa.hpp:145
size_t sizeSystemDG() const
Definition hho-nsa.hpp:162
systemMatrixType & systemMatrixHHO()
Returns the linear system matrix.
Definition hho-nsa.hpp:197
size_t numNonSCDOFs() const
Returns the number of DOFs after SC and with Lagrange multiplier, but before eliminating Dirichlet DO...
Definition hho-nsa.hpp:151
bool & isStokes()
Returns the Stokes status.
Definition hho-nsa.hpp:252
Eigen::VectorXd imposingBC(const VelocityType &u, const Eigen::VectorXd &uph) const
impose boundary conditions
Definition hho-nsa.cpp:948
std::vector< double > computePressureL2Norm(const std::vector< Eigen::VectorXd > &list_dofs) const
Compute the discrete L2 norm of the pressure.
Definition hho-nsa.cpp:1097
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition hho-nsa.hpp:207
void writeFileHeader(const std::string &filename, const std::string &solution_name, const int &solution_number, const std::string &mesh_name, const size_t &degree, const std::unique_ptr< Mesh > &mesh_ptr, const double &viscosity) const
Writing file header with simulation metadata.
Definition hho-nsa.cpp:1898
size_t numSCDOFs_u() const
Returns the number of velocity statically condensed DOFs.
Definition hho-nsa.hpp:109
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:52