HArD::Core3D
Hybrid Arbitrary Degree::Core 3D - Library to implement 3D schemes with vertex, edge, face and cell polynomials as unknowns
Loading...
Searching...
No Matches
hho-brinkman.hpp
Go to the documentation of this file.
1// Implementation of the HHO scheme, with full gradient, for the Brinkman equations -div(mu grad u) + nu u + grad p=f, div u = g.
2//
3// Author: Jerome Droniou (jerome.droniou@monash.edu)
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 HHOBRINKMAN_HPP
23#define HHOBRINKMAN_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
46namespace HArDCore3D
47{
48
54 //------------------------------------------------------------------------------
55 // Brinkman model
56 //------------------------------------------------------------------------------
57
60 {
63
66 const ViscosityType & _mu,
68 )
69 : mu(_mu),
71 {
72 // do nothing
73 }
74
76 double Cf(const Cell & T) const
77 {
78 double muT = mu.value(T, T.center_mass());
79 double kappainvT = kappainv.value(T, T.center_mass());
80
81 // Thres is the level at which the parameter is put at 0; note that Cf is also bounded below by thres
82 // to avoid singularities when taking Cf^{-1}.
83 double thres = 1e-14;
84 return (muT > thres ? std::max(thres, kappainvT * std::pow(T.diam(), 2) / muT) : 1./thres);
85 }
86
89 };
90
93 {
95 BrinkmanNorms(double norm_u, double norm_p):
96 u(norm_u),
97 p(norm_p),
98 energy( std::sqrt( std::pow(norm_u, 2) + std::pow(norm_p, 2) ) )
99 {
100 // do nothing
101 };
102
103 double u;
104 double p;
105 double energy;
106 };
107
108
110
118 struct Brinkman
119 {
120 typedef Eigen::SparseMatrix<double> SystemMatrixType;
121
122 typedef std::function<VectorRd(const VectorRd &)> MomentumForcingTermType;
123 typedef std::function<double(const VectorRd &)> CompressibilityForcingTermType;
124 typedef std::function<VectorRd(const VectorRd &)> VelocityType;
125 typedef std::function<MatrixRd(const VectorRd &)> VelocityGradientType;
126 typedef std::function<double(const VectorRd &)> PressureType;
127 typedef std::function<VectorRd(const VectorRd &)> PressureGradientType;
128
130 Brinkman(
131 const VHHOSpace & vhho_space,
132 const GlobalDOFSpace & p_space,
133 const BoundaryConditions & BC,
134 bool use_threads,
135 std::ostream & output = std::cout
136 );
137
140 const MomentumForcingTermType & f,
142 const BrinkmanParameters & para,
143 const VelocityType & u,
144 Eigen::VectorXd & UDir
145 );
146
148 inline size_t nloc_sc_u() const
149 {
150 return m_nloc_sc_u;
151 }
152
154 inline size_t nloc_sc_p() const
155 {
156 return m_nloc_sc_p;
157 }
158
160 inline size_t numSCDOFs_u() const
161 {
162 return mesh().n_cells() * m_nloc_sc_u;
163 }
164
166 inline size_t numSCDOFs_p() const
167 {
168 return mesh().n_cells() * m_nloc_sc_p;
169 }
170
172 inline size_t numSCDOFs() const
173 {
174 return numSCDOFs_u() + numSCDOFs_p();
175 }
176
178 inline size_t numDirDOFs() const
179 {
180 return m_BC.n_dir_faces()*m_vhhospace.numLocalDofsFace();
181 }
182
184 inline size_t dimVelocity() const
185 {
186 return m_vhhospace.dimension();
187 }
188
190 inline size_t dimPressure() const
191 {
192 return m_pspace.dimension();
193 }
194
196 inline size_t numNonSCDOFs() const
197 {
198 return dimVelocity() + dimPressure() - numSCDOFs() + 1;
199 }
200
202 inline size_t sizeSystem() const
203 {
204 return numNonSCDOFs() - numDirDOFs();
205 }
206
208 inline const VHHOSpace & vhhospace() const
209 {
210 return m_vhhospace;
211 }
212
214 inline const GlobalDOFSpace & pspace() const
215 {
216 return m_pspace;
217 }
218
220 inline const Mesh & mesh() const
221 {
222 return m_vhhospace.mesh();
223 }
224
226 inline const SystemMatrixType & systemMatrix() const {
227 return m_A;
228 }
229
232 return m_A;
233 }
234
236 inline const Eigen::VectorXd & systemVector() const {
237 return m_b;
238 }
239
241 inline Eigen::VectorXd & systemVector() {
242 return m_b;
243 }
244
246 inline const std::pair<double,double> & stabilizationParameter() const {
247 return m_stab_par;
248 }
249
251 inline std::pair<double,double> & stabilizationParameter() {
252 return m_stab_par;
253 }
254
256 inline const SystemMatrixType & scMatrix() const {
257 return m_sc_A;
258 }
259
261 inline Eigen::VectorXd & scVector() {
262 return m_sc_b;
263 }
264
266 Eigen::VectorXd interpolate(
267 const VelocityType & u,
268 const PressureType & p,
269 const int doe_cell = -1,
270 const int doe_face = -1
271 ) const;
272
274 std::vector<BrinkmanNorms> computeBrinkmanNorms(
275 const std::vector<Eigen::VectorXd> & list_dofs,
276 const BrinkmanParameters & para
277 ) const;
278
280 std::vector<double> pressureVertexValues(
281 const Eigen::VectorXd & p
282 ) const;
283
285 std::pair<double, double> computeConditionNum() const;
286
288 std::pair<double,double> computeFlux(
289 const Eigen::VectorXd & u,
290 const std::pair<std::vector<VectorRd>, VectorRd> & surf
291 ) const;
292
293 private:
295 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
296 _compute_local_contribution(
297 size_t iT,
298 const MomentumForcingTermType & f,
300 const BrinkmanParameters & para
301 );
302
304 LocalStaticCondensation _compute_static_condensation(const size_t & iT) const;
305
307 void _assemble_local_contribution(
308 size_t iT,
309 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
310 std::list<Eigen::Triplet<double> > & A1,
311 Eigen::VectorXd & b1,
312 std::list<Eigen::Triplet<double> > & A2,
313 Eigen::VectorXd & b2
314 );
315
317 const VHHOSpace & m_vhhospace;
318 const GlobalDOFSpace & m_pspace;
319
320 const BoundaryConditions & m_BC;
321 bool m_use_threads;
322 std::ostream & m_output;
323 const size_t m_nloc_sc_u; // Number of statically condensed velocity DOFs in each cell
324 const size_t m_nloc_sc_p; // Number of statically condensed pressure DOFs in each cell
325 SystemMatrixType m_A; // Matrix and RHS of statically condensed system
326 Eigen::VectorXd m_b;
327 SystemMatrixType m_sc_A; // Static condensation operator and RHS (to recover statically condensed DOFs)
328 Eigen::VectorXd m_sc_b;
329 std::pair<double,double> m_stab_par; // Stabilisation parameters: first for Stokes, second for Darcy
330 };
331
332
333 //------------------------------------------------------------------------------
334 // Exact solutions
335 //------------------------------------------------------------------------------
336
337 static const double PI = boost::math::constants::pi<double>();
338 using std::sin;
339 using std::cos;
340
341 double scaling_mu = 1.;
342 double scaling_kappainv = 1.;
343
344 // Threshold for checking that quantities are zero or not
345 double constexpr eps=1e-14;
346
347 //---------------- Linear -----------------------------------------------------------
348
349
352
355
356 static const MatrixRd mat_u = (MatrixRd() << 1.,2.,3., 0.,-1.,1. , 0.,1.,1.).finished();
357 static const VectorRd vec_p = VectorRd(-1., 2., -5.);
358
360 linear_u = [](const VectorRd & x) -> VectorRd {
361 return mat_u * x;
362 };
363
365 linear_p = [](const VectorRd & x) -> double {
366 return vec_p.dot(x - VectorRd(.5,.5,.5)); // Assuming domain (0,1)^3 to have zero average
367 };
368
370 linear_gradu = [](const VectorRd & x) -> MatrixRd {
371 return mat_u;
372 };
373
375 linear_gradp = [](const VectorRd & x) -> VectorRd {
376 return vec_p;
377 };
378
380 linear_f = [](const VectorRd & x) -> VectorRd {
381 return VectorRd::Zero() + scaling_kappainv*linear_u(x) + linear_gradp(x);
382 };
383
385 linear_g = [](const VectorRd & x)->double { return linear_gradu(x).trace();};
386
387
388 //---------------- Quadratic ------------------------------------------------
391
394
396 quadratic_u = [](const VectorRd & x) -> VectorRd {
397 return VectorRd(
398 std::pow(x(0), 2),
399 std::pow(x(1), 2),
400 std::pow(x(2), 2)
401 );
402 };
403
405 quadratic_gradu = [](const VectorRd & x) -> MatrixRd {
406 MatrixRd M = MatrixRd::Zero();
407 M.row(0) << 2. * x(0),
408 0.,
409 0.;
410 M.row(1) << 0.,
411 2 * x(1),
412 0.;
413 M.row(2) << 0.,
414 0.,
415 2 * x(2);
416
417 return M;
418 };
419
421 quadratic_p = [](const VectorRd & x) -> double {
422 return std::pow(x(0), 2) + x(1)*x(2) - 1./3. - 1./4.;
423 };
424
426 quadratic_gradp = [](const VectorRd & x) -> VectorRd {
427 return VectorRd( 2 * x(0),
428 x(2),
429 x(1)
430 );
431 };
432
434 quadratic_f = [](const VectorRd & x) -> VectorRd {
435 return - scaling_mu * VectorRd( 2., 2., 2.) + scaling_kappainv * quadratic_u(x) + quadratic_gradp(x);
436 };
437
439 quadratic_g = [](const VectorRd & x)->double { return quadratic_gradu(x).trace();};
440
441
442 //---------------- Cubic ------------------------------------------------
445
448
450 cubic_u = [](const VectorRd & x) -> VectorRd {
451 return VectorRd(
452 std::pow(x(0), 3) + std::pow(x(0), 2)*x(1),
453 std::pow(x(1), 2) + x(0) * x(1) * x(2),
454 std::pow(x(2), 3)
455 );
456 };
457
459 cubic_gradu = [](const VectorRd & x) -> MatrixRd {
460 MatrixRd M = MatrixRd::Zero();
461 M.row(0) << 3. * std::pow(x(0), 2) + 2 * x(0) * x(1),
462 std::pow(x(0), 2),
463 0.;
464 M.row(1) << x(1) * x(2),
465 2 * x(1) + x(0) * x(2),
466 x(0) * x(1);
467 M.row(2) << 0.,
468 0.,
469 3 * std::pow(x(2), 2);
470
471 return M;
472 };
473
475 cubic_p = [](const VectorRd & x) -> double {
476 return std::pow(x(0), 3) + x(1)*x(2) - 1./4. - 1./4.;
477 };
478
480 cubic_gradp = [](const VectorRd & x) -> VectorRd {
481 return VectorRd( 3 * std::pow(x(0), 2),
482 x(2),
483 x(1)
484 );
485 };
486
488 cubic_f = [](const VectorRd & x) -> VectorRd {
489 return - scaling_mu * VectorRd( 6 * x(0) + 2 * x(1), 2., 6 * x(2)) + scaling_kappainv * cubic_u(x) + cubic_gradp(x);
490 };
491
493 cubic_g = [](const VectorRd & x)->double { return cubic_gradu(x).trace();};
494
495
496 //---------------- Trigonometric ------------------------------------------------
499
502
503 double constexpr pressure_scaling = 1.;
504
506 trigonometric_u = [](const VectorRd & x) -> VectorRd {
507 return VectorRd(
508 0.5 * sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
509 0.5 * cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
510 -cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2))
511 );
512 };
513
515 trigonometric_gradu = [](const VectorRd & x) -> MatrixRd {
516 MatrixRd M = MatrixRd::Zero();
517 M.row(0) << PI * cos(2 * PI * x(0)) * cos(2 * PI * x(1)) * cos(2 * PI * x(2)),
518 -PI * sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
519 -PI * sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2));
520 M.row(1) << - PI * sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
521 PI * cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
522 -PI * cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2));
523 M.row(2) << 2 * PI * sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2)),
524 2 * PI * cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2)),
525 - 2 * PI * cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2));
526
527 return M;
528 };
529
531 trigonometric_p = [](const VectorRd & x) -> double {
532 return pressure_scaling * sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2));
533 };
534
536 trigonometric_gradp = [](const VectorRd & x) -> VectorRd {
537 return pressure_scaling * 2. * PI * VectorRd(
538 cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2)),
539 sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2)),
540 sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2))
541 );
542 };
543
545 trigonometric_f = [](const VectorRd & x) -> VectorRd {
546 return scaling_mu * 6. * std::pow(PI, 2) * VectorRd(
547 sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
548 cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
549 -2. * cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2))
550 )
552 };
553
555 trigonometric_g = [](const VectorRd & x)->double { return trigonometric_gradu(x).trace();};
556
557
558
559 //---------------- Various regimes parametrised by global friction coefficient --------------------------------------------
560
563
566
569
572
573 // u_D = - kappainv^{-1} grad p
575 regimes_uD = [](const VectorRd & x) -> VectorRd {
576 VectorRd uDvalue = VectorRd::Zero();
577 if (scaling_kappainv > eps) {
578 uDvalue = - std::pow(scaling_kappainv, -1) * regimes_gradp(x) ;
579 }
580 return uDvalue;
581 };
582
584 regimes_graduD = [](const VectorRd & x) -> MatrixRd {
585 MatrixRd M = MatrixRd::Zero();
586
588 M.row(0) << sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2)),
589 -cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2)),
590 -cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2));
591 M.row(1) << -cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2)),
592 sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2)),
593 -sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2));
594 M.row(2) << -cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
595 -sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
596 sin(2. * PI * x(0)) * sin(2. * PI * x(1)) * sin(2. * PI * x(2));
597 M *= 4. * std::pow(PI, 2) / scaling_kappainv;
598 }
599
600 return M;
601 };
602
603 // u_S = trigonometric u
606
607 static std::function<double(const VectorRd &)>
608 XiS = [](const VectorRd & x) -> double {
609 return (scaling_mu > eps ? std::exp(-scaling_kappainv/scaling_mu) : 0.);
610 };
611
613 regimes_u = [](const VectorRd & x) -> VectorRd { return XiS(x) * regimes_uS(x) + (1.-XiS(x)) * regimes_uD(x);};
614
616 regimes_gradu = [](const VectorRd & x) -> MatrixRd { return XiS(x) * regimes_graduS(x) + (1.-XiS(x)) * regimes_graduD(x);};
617
619 regimes_f = [](const VectorRd & x) -> VectorRd {
620 VectorRd fvalue = XiS(x) * scaling_mu * 6. * std::pow(PI, 2) * VectorRd(
621 sin(2. * PI * x(0)) * cos(2. * PI * x(1)) * cos(2. * PI * x(2)),
622 cos(2. * PI * x(0)) * sin(2. * PI * x(1)) * cos(2. * PI * x(2)),
623 -2. * cos(2. * PI * x(0)) * cos(2. * PI * x(1)) * sin(2. * PI * x(2))
624 )
625 + regimes_gradp(x);
626
627 if (scaling_kappainv > eps){
629 - scaling_mu * (1-XiS(x))/scaling_kappainv * 12. * std::pow(PI, 2) * regimes_gradp(x);
630 }
631
632 return fvalue;
633 };
634
636 regimes_g = [](const VectorRd & x)->double { return regimes_gradu(x).trace() ;};
637
638
639 //---------------- V-cracked boundary conditions and data (no exact solution here)------------------------------------
640
641 // Returns 1 in the crack, 0 outside
642 static std::function<double(const VectorRd &)>
643 XiV = [](const VectorRd & x)->double { return (x.z() > 2*std::abs(x.x()-1.)+0.5-eps); };
644
645 // Viscosity only in crack
647 vcracked_mu = BrinkmanParameters::ViscosityType([](const VectorRd & x)->double { return 0.01 * XiV(x);});
648
649 // Permeability only outside crack
651 vcracked_kappainv = BrinkmanParameters::PermeabilityInvType([](const VectorRd & x)->double { return 1e-5*(1.-XiV(x)) + 0.001*XiV(x);});
652
653 // u: entry on the left (surface (0,0,0)-(0,0.2,0)-(0,0.2,1)-(0,0,1),
654 // and "wind" on the top above the crack (surface (0.75,0,1)-(1.25,0,1)-(1.25,0.2,1)-(0.75,0.2,1))
656 vcracked_u = [](const VectorRd & x) -> VectorRd {
657 VectorRd value = VectorRd::Zero();
658 if ( x.x() < .2) {
659 // Entry on the left
660 value = VectorRd(.3, 0., 0.);
661 }else if ( (x.z() > 0.8) && (x.x() > 0.75-eps) && (x.x() < 1.25+eps) ){
662 // Wind top
663 value = VectorRd(1, 0., 0.);
664 }
665
666 return value;
667 };
668
669
671 vcracked_gradu = [](const VectorRd & x) -> MatrixRd {
672 return MatrixRd::Zero();
673 };
674
676 vcracked_p = [](const VectorRd & x) -> double {
677 return 0.;
678 };
679
681 vcracked_gradp = [](const VectorRd & x) -> VectorRd {
682 return VectorRd::Zero();
683 };
684
685 // Source is gravity
687 vcracked_f = [](const VectorRd & x) -> VectorRd {
688 return VectorRd(0., 0., -.98);
689 };
690
692 vcracked_g = [](const VectorRd & x) -> double {
693 return 0.;
694 };
695
696 //---------------- BCs for the cavity in porous medium ------------------------------------
697
698 // Characteristic functions of cavity, wedge, and surrounding box
699 static std::function<double(const VectorRd &)>
700 XiCavity = [](const VectorRd & x)->double {
701 return ( (x.x()>0) && (x.x()<1) && (x.y()>0) && (x.y()<1) && (x.z()>-1) ? 1. : 0.);
702 };
703 static std::function<double(const VectorRd &)>
704 XiWedge = [](const VectorRd & x)->double {
705 return ( (x.x()>=1) && (x.x()<2) && (x.y()>0) && (x.y()<1) && (x.z()> -.75 + .25*(x.x()-1)) ? 1. : 0.);
706 };
707 static std::function<double(const VectorRd &)>
708 XiBox = [](const VectorRd & x)->double { return 1. - XiCavity(x) - XiWedge(x); };
709
710 // Viscosity in cavity
711 constexpr double viscosity_in_cavity = 0.01;
713
714 // Permeability in wedge and box
715 constexpr double permeability_in_wedge = 1e-2;
716 constexpr double permeability_in_box = 1e-7;
720
721 // u: wind above cavity (only for BCs anyway).
723 cavity_u = [](const VectorRd & x) -> VectorRd {
724 return XiCavity(x) * VectorRd(x.x()*(1.-x.x()), 0., 0.);
725 };
726
728 cavity_gradu = [](const VectorRd & x) -> MatrixRd {
729 return MatrixRd::Zero();
730 };
731
733 cavity_p = [](const VectorRd & x) -> double {
734 return 0.;
735 };
736
738 cavity_gradp = [](const VectorRd & x) -> VectorRd {
739 return VectorRd::Zero();
740 };
741
742 // Source is gravity
744 cavity_f = [](const VectorRd & x) -> VectorRd {
745 return VectorRd(0., 0., -.98);
746 };
747
749 cavity_g = [](const VectorRd & x) -> double {
750 return 0.;
751 };
752
753
754 //---------------- Two regions ------------------------------------------------
755 // Two regions with different parameters, separated by x=1/2 (region S is x<1/2, D is x>1/2)
756 // u = alpha(y,z) + cos(pi x) beta_i(y,z) where i=S or D
757 // This ensures that u is continuous, and that nu \nabla u n is continuous across x=1/2
758
759 // Characteristic functions
760 static std::function<double(const VectorRd &)>
761 Xi_S = [](const VectorRd & x)->double {
762 return ( (x.x()<0.5) ? 1. : 0.);
763 };
764 static std::function<double(const VectorRd &)>
765 Xi_D = [](const VectorRd & x)->double {
766 return 1.-Xi_S(x);
767 };
768
769 // Viscosity and permeability
770 constexpr double viscosity_S = 1.;
771 constexpr double viscosity_D = 0.;
775
776 constexpr double permeability_S = 1e-7;
777 constexpr double permeability_D = 1e-2;
781
782 // Velocity (alpha and beta only depend on y,z)
783 static std::function<VectorRd(const VectorRd &)>
784 alpha = [](const VectorRd & x)->VectorRd {
785 return VectorRd(
786 exp(-x.y()-x.z()),
787 sin(PI * x.y()) * sin(PI * x.z()),
788 x.y() * x.z()
789 );
790 };
791
792 static std::function<VectorRd(const VectorRd &)>
793 beta_S = [](const VectorRd & x)->VectorRd {
794 return cos(PI * x.x()) * (x.x() - 0.5)
795 * VectorRd(
796 x.y() + x.z(),
797 x.y() + cos(PI * x.z()),
798 sin(PI * x.y())
799 );
800 };
801
802 static std::function<VectorRd(const VectorRd &)>
803 beta_D = [](const VectorRd & x)->VectorRd {
804 return cos(PI * x.x()) * (x.x() - 0.5)
805 * VectorRd(
806 sin(PI * x.y()) + cos(PI * x.z()),
807 std::pow(x.z(), 3),
808 std::pow(x.y(), 2) * std::pow(x.z(), 2)
809 );
810 };
811
813 tworegions_u = [](const VectorRd & x) -> VectorRd {
814 return alpha(x) + Xi_S(x) * beta_S(x) + Xi_D(x) * beta_D(x);
815 };
816
818 grad_alpha = [](const VectorRd & x) -> MatrixRd {
819 MatrixRd M = MatrixRd::Zero();
820 M.row(0) << 0, -exp(-x.y() - x.z()), -exp(-x.y() - x.z());
821 M.row(1) << 0, PI*sin(PI*x.z())*cos(PI*x.y()), PI*sin(PI*x.y())*cos(PI*x.z());
822 M.row(2) << 0, x.z(), x.y();
823
824 return M;
825 };
826
828 grad_beta_S = [](const VectorRd & x) -> MatrixRd {
829 MatrixRd M = MatrixRd::Zero();
830 M.row(0) << -PI*(x.x() - 0.5)*(x.y() + x.z())*sin(PI*x.x()) + (x.y() + x.z())*cos(PI*x.x()),
831 (x.x() - 0.5)*cos(PI*x.x()),
832 (x.x() - 0.5)*cos(PI*x.x());
833 M.row(1) << -PI*(x.x() - 0.5)*(x.y() + cos(PI*x.z()))*sin(PI*x.x()) + (x.y() + cos(PI*x.z()))*cos(PI*x.x()),
834 (x.x() - 0.5)*cos(PI*x.x()),
835 -PI*(x.x() - 0.5)*sin(PI*x.z())*cos(PI*x.x());
836 M.row(2) << -PI*(x.x() - 0.5)*sin(PI*x.x())*sin(PI*x.y()) + sin(PI*x.y())*cos(PI*x.x()),
837 PI*(x.x() - 0.5)*cos(PI*x.x())*cos(PI*x.y()),
838 0;
839
840 return M;
841 };
842
844 grad_beta_D = [](const VectorRd & x) -> MatrixRd {
845 MatrixRd M = MatrixRd::Zero();
846 M.row(0) << -PI*(x.x() - 0.5)*(sin(PI*x.y()) + cos(PI*x.z()))*sin(PI*x.x()) + (sin(PI*x.y()) + cos(PI*x.z()))*cos(PI*x.x()),
847 PI*(x.x() - 0.5)*cos(PI*x.x())*cos(PI*x.y()),
848 -PI*(x.x() - 0.5)*sin(PI*x.z())*cos(PI*x.x());
849 M.row(1) << -PI*pow(x.z(), 3)*(x.x() - 0.5)*sin(PI*x.x()) + pow(x.z(), 3)*cos(PI*x.x()),
850 0,
851 3*pow(x.z(), 2)*(x.x() - 0.5)*cos(PI*x.x());
852 M.row(2) << -PI*pow(x.y(), 2)*pow(x.z(), 2)*(x.x() - 0.5)*sin(PI*x.x()) + pow(x.y(), 2)*pow(x.z(), 2)*cos(PI*x.x()),
853 2*x.y()*pow(x.z(), 2)*(x.x() - 0.5)*cos(PI*x.x()),
854 2*pow(x.y(), 2)*x.z()*(x.x() - 0.5)*cos(PI*x.x());
855
856 return M;
857 };
858
860 tworegions_gradu = [](const VectorRd & x) -> MatrixRd {
861 return grad_alpha(x) + Xi_S(x) * grad_beta_S(x) + Xi_D(x) * grad_beta_D(x);
862 };
863
866
869
870// static Brinkman::PressureType
871// tworegions_p = [](const VectorRd & x) -> double {
872// return (x.x()-0.5) * x.y() * x.z();
873// };
874
875// static Brinkman::PressureGradientType
876// tworegions_gradp = [](const VectorRd & x) -> VectorRd {
877// return VectorRd( x.y() * x.z(), (x.x()-0.5) * x.z(), (x.x()-0.5) * x.y());
878// };
879
881 DivGrad_alpha = [](const VectorRd & x) -> VectorRd {
882 return VectorRd(
883 2*exp(-x.y() - x.z()),
884 -2*pow(PI, 2)*sin(PI*x.y())*sin(PI*x.z()),
885 0
886 );
887 };
888
890 DivGrad_beta_S = [](const VectorRd & x) -> VectorRd {
891 return VectorRd(
892 -pow(PI, 2)*(x.x() - 0.5)*(x.y() + x.z())*cos(PI*x.x()) - 2*PI*(x.y() + x.z())*sin(PI*x.x()),
893 -pow(PI, 2)*(x.x() - 0.5)*(x.y() + cos(PI*x.z()))*cos(PI*x.x()) - pow(PI, 2)*(x.x() - 0.5)*cos(PI*x.x())*cos(PI*x.z()) - 2*PI*(x.y() + cos(PI*x.z()))*sin(PI*x.x()),
894 -2*pow(PI, 2)*(x.x() - 0.5)*sin(PI*x.y())*cos(PI*x.x()) - 2*PI*sin(PI*x.x())*sin(PI*x.y())
895 );
896
897 };
898
900 DivGrad_beta_D = [](const VectorRd & x) -> VectorRd {
901 return VectorRd(
902 -pow(PI, 2)*(x.x() - 0.5)*(sin(PI*x.y()) + cos(PI*x.z()))*cos(PI*x.x()) - pow(PI, 2)*(x.x() - 0.5)*sin(PI*x.y())*cos(PI*x.x()) - pow(PI, 2)*(x.x() - 0.5)*cos(PI*x.x())*cos(PI*x.z()) - 2*PI*(sin(PI*x.y()) + cos(PI*x.z()))*sin(PI*x.x()),
903 -pow(PI, 2)*pow(x.z(), 3)*(x.x() - 0.5)*cos(PI*x.x()) - 2*PI*pow(x.z(), 3)*sin(PI*x.x()) + 6*x.z()*(x.x() - 0.5)*cos(PI*x.x()),
904 -pow(PI, 2)*pow(x.y(), 2)*pow(x.z(), 2)*(x.x() - 0.5)*cos(PI*x.x()) - 2*PI*pow(x.y(), 2)*pow(x.z(), 2)*sin(PI*x.x()) + 2*pow(x.y(), 2)*(x.x() - 0.5)*cos(PI*x.x()) + 2*pow(x.z(), 2)*(x.x() - 0.5)*cos(PI*x.x())
905 );
906 };
907
909 tworegions_f = [](const VectorRd & x) -> VectorRd {
910 return - scaling_mu * ( viscosity_S * Xi_S(x) * (DivGrad_alpha(x) + DivGrad_beta_S(x)) +
913 ( std::pow(permeability_S, -1) * Xi_S(x) + std::pow(permeability_D, -1) * Xi_D(x) ) * tworegions_u(x)
914 + tworegions_gradp(x);
915 };
916
918 tworegions_g = [](const VectorRd & x)->double { return tworegions_gradu(x).trace();};
919
920
921} // end of namespace HArDCore3D
922
923#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:129
const size_t n_dir_faces() const
Returns the number of Dirichlet faces.
Definition BoundaryConditions.hpp:160
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
Class to describe a mesh.
Definition MeshND.hpp:17
Eigen::Matrix3d MatrixRd
Definition basis.hpp:51
@ Matrix
Definition basis.hpp:67
size_t dimension() const
Returns the dimension of the global space (all DOFs for all geometric entities)
Definition localdofspace.hpp:80
size_t numLocalDofsFace() const
Returns the number of local face DOFs.
Definition localdofspace.hpp:49
IntegralWeightValueType value
Definition integralweight.hpp:69
static const double PI
Definition ddr-magnetostatics.hpp:187
static Magnetostatics::SolutionPotentialType linear_u
Definition ddr-magnetostatics.hpp:214
static Magnetostatics::PermeabilityType linear_mu
Definition ddr-magnetostatics.hpp:233
static Magnetostatics::SolutionPotentialType trigonometric_u
Definition ddr-magnetostatics.hpp:238
static Magnetostatics::PermeabilityType trigonometric_mu
Definition ddr-magnetostatics.hpp:265
static Magnetostatics::ForcingTermType trigonometric_f
Definition ddr-magnetostatics.hpp:256
static Magnetostatics::ForcingTermType linear_f
Definition ddr-magnetostatics.hpp:228
static NavierStokes::PressureType linear_p
Definition sddr-navier-stokes.hpp:577
static NavierStokes::PressureType trigonometric_p
Definition sddr-navier-stokes.hpp:491
double pressure_scaling
Definition sddr-navier-stokes.hpp:464
const Mesh & mesh() const
Return a const reference to the mesh.
Definition vhhospace.hpp:128
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
static std::function< VectorRd(const VectorRd &)> beta_D
Definition hho-brinkman.hpp:803
static Brinkman::CompressibilityForcingTermType vcracked_g
Definition hho-brinkman.hpp:692
static Brinkman::PressureType regimes_p
Definition hho-brinkman.hpp:568
constexpr double viscosity_in_cavity
Definition hho-brinkman.hpp:711
size_t numDirDOFs() const
Returns the number of Dirichlet DOFs.
Definition hho-brinkman.hpp:178
static BrinkmanParameters::PermeabilityInvType regimes_kappainv
Definition hho-brinkman.hpp:565
static Brinkman::CompressibilityForcingTermType regimes_g
Definition hho-brinkman.hpp:636
std::pair< double, double > & stabilizationParameter()
Returns the stabilization parameter.
Definition hho-brinkman.hpp:251
static Brinkman::MomentumForcingTermType cavity_f
Definition hho-brinkman.hpp:744
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-brinkman.cpp:674
double energy
Global energy norm
Definition hho-brinkman.hpp:105
static Brinkman::PressureType vcracked_p
Definition hho-brinkman.hpp:676
static Brinkman::VelocityType cavity_u
Definition hho-brinkman.hpp:723
std::function< VectorRd(const VectorRd &)> MomentumForcingTermType
Definition hho-brinkman.hpp:122
static Brinkman::MomentumForcingTermType DivGrad_alpha
Definition hho-brinkman.hpp:881
static Brinkman::PressureGradientType cubic_gradp
Definition hho-brinkman.hpp:480
static Brinkman::VelocityType cubic_u
Definition hho-brinkman.hpp:450
static Brinkman::VelocityGradientType regimes_graduD
Definition hho-brinkman.hpp:584
double u
Energy norm of velocity.
Definition hho-brinkman.hpp:103
static const VectorRd vec_p
Definition hho-brinkman.hpp:357
static Brinkman::VelocityType regimes_u
Definition hho-brinkman.hpp:613
static std::function< double(const VectorRd &)> XiBox
Definition hho-brinkman.hpp:708
IntegralWeight PermeabilityInvType
Definition hho-brinkman.hpp:62
std::function< double(const VectorRd &)> PressureType
Definition hho-brinkman.hpp:126
static Brinkman::PressureGradientType cavity_gradp
Definition hho-brinkman.hpp:738
size_t sizeSystem() const
Returns the size of the final system with Lagrange multiplier, after application of SC and removal of...
Definition hho-brinkman.hpp:202
const VHHOSpace & vhhospace() const
Returns the velocity space.
Definition hho-brinkman.hpp:208
static Brinkman::VelocityGradientType tworegions_gradu
Definition hho-brinkman.hpp:860
constexpr double permeability_in_wedge
Definition hho-brinkman.hpp:715
static std::function< double(const VectorRd &)> XiWedge
Definition hho-brinkman.hpp:704
static BrinkmanParameters::ViscosityType cavity_mu
Definition hho-brinkman.hpp:712
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition hho-brinkman.hpp:226
double constexpr eps
Definition hho-brinkman.hpp:345
static Brinkman::VelocityGradientType quadratic_gradu
Definition hho-brinkman.hpp:405
IntegralWeight ViscosityType
Definition hho-brinkman.hpp:61
static BrinkmanParameters::PermeabilityInvType tworegions_kappainv
Definition hho-brinkman.hpp:779
static BrinkmanParameters::PermeabilityInvType vcracked_kappainv
Definition hho-brinkman.hpp:651
static Brinkman::VelocityGradientType regimes_gradu
Definition hho-brinkman.hpp:616
static std::function< double(const VectorRd &)> Xi_D
Definition hho-brinkman.hpp:765
constexpr double permeability_D
Definition hho-brinkman.hpp:777
std::pair< double, double > computeFlux(const Eigen::VectorXd &u, const std::pair< std::vector< VectorRd >, VectorRd > &surf) const
Compute the velocity flux (integral of u.n) across a given surface, and the area of the surface,...
Definition hho-brinkman.cpp:825
static BrinkmanParameters::PermeabilityInvType trigonometric_kappainv
Definition hho-brinkman.hpp:501
const GlobalDOFSpace & pspace() const
Returns the pressure space.
Definition hho-brinkman.hpp:214
size_t numNonSCDOFs() const
Returns the number of DOFs after SC and with Lagrange multiplier, but before eliminating Dirichlet DO...
Definition hho-brinkman.hpp:196
static std::function< VectorRd(const VectorRd &)> beta_S
Definition hho-brinkman.hpp:793
static std::function< double(const VectorRd &)> XiV
Definition hho-brinkman.hpp:643
static std::function< VectorRd(const VectorRd &)> alpha
Definition hho-brinkman.hpp:784
size_t dimVelocity() const
Returns the dimension of velocity space.
Definition hho-brinkman.hpp:184
ViscosityType mu
Definition hho-brinkman.hpp:87
PermeabilityInvType kappainv
Definition hho-brinkman.hpp:88
static Brinkman::VelocityGradientType cavity_gradu
Definition hho-brinkman.hpp:728
static Brinkman::VelocityType regimes_uD
Definition hho-brinkman.hpp:575
static Brinkman::MomentumForcingTermType regimes_f
Definition hho-brinkman.hpp:619
static BrinkmanParameters::ViscosityType tworegions_mu
Definition hho-brinkman.hpp:773
static Brinkman::CompressibilityForcingTermType cubic_g
Definition hho-brinkman.hpp:493
static BrinkmanParameters::PermeabilityInvType cubic_kappainv
Definition hho-brinkman.hpp:447
constexpr double permeability_in_box
Definition hho-brinkman.hpp:716
static Brinkman::PressureType cavity_p
Definition hho-brinkman.hpp:733
static Brinkman::MomentumForcingTermType DivGrad_beta_S
Definition hho-brinkman.hpp:890
static Brinkman::PressureType cubic_p
Definition hho-brinkman.hpp:475
double Cf(const Cell &T) const
Returns the friction coefficient.
Definition hho-brinkman.hpp:76
static BrinkmanParameters::ViscosityType cubic_mu
Definition hho-brinkman.hpp:444
std::function< MatrixRd(const VectorRd &)> VelocityGradientType
Definition hho-brinkman.hpp:125
static Brinkman::PressureGradientType linear_gradp
Definition hho-brinkman.hpp:375
static Brinkman::PressureType quadratic_p
Definition hho-brinkman.hpp:421
double scaling_mu
Definition hho-brinkman.hpp:341
std::vector< double > pressureVertexValues(const Eigen::VectorXd &p) const
Create vertex values for the pressure (from the element values), for plotting.
Definition hho-brinkman.cpp:774
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hho-brinkman.hpp:124
const std::pair< double, double > & stabilizationParameter() const
Returns the stabilization parameter (scaling)
Definition hho-brinkman.hpp:246
static Brinkman::PressureType tworegions_p
Definition hho-brinkman.hpp:865
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition hho-brinkman.hpp:231
static Brinkman::PressureGradientType vcracked_gradp
Definition hho-brinkman.hpp:681
static std::function< double(const VectorRd &)> XiCavity
Definition hho-brinkman.hpp:700
std::pair< double, double > computeConditionNum() const
Computes the condition number of the matrix.
Definition hho-brinkman.cpp:800
static Brinkman::PressureGradientType regimes_gradp
Definition hho-brinkman.hpp:571
static Brinkman::MomentumForcingTermType vcracked_f
Definition hho-brinkman.hpp:687
static Brinkman::MomentumForcingTermType tworegions_f
Definition hho-brinkman.hpp:909
static Brinkman::VelocityType regimes_uS
Definition hho-brinkman.hpp:604
Eigen::VectorXd & scVector()
Returns the static condensation rhs.
Definition hho-brinkman.hpp:261
static Brinkman::CompressibilityForcingTermType cavity_g
Definition hho-brinkman.hpp:749
size_t nloc_sc_u() const
Returns the local number of velocity statically condensed DOFs.
Definition hho-brinkman.hpp:148
static Brinkman::MomentumForcingTermType quadratic_f
Definition hho-brinkman.hpp:434
static BrinkmanParameters::ViscosityType quadratic_mu
Definition hho-brinkman.hpp:390
static Brinkman::VelocityGradientType grad_beta_S
Definition hho-brinkman.hpp:828
static BrinkmanParameters::PermeabilityInvType quadratic_kappainv
Definition hho-brinkman.hpp:393
static Brinkman::PressureGradientType trigonometric_gradp
Definition hho-brinkman.hpp:536
static BrinkmanParameters::ViscosityType regimes_mu
Definition hho-brinkman.hpp:562
double scaling_kappainv
Definition hho-brinkman.hpp:342
size_t numSCDOFs_p() const
Returns the number of pressure statically condensed DOFs.
Definition hho-brinkman.hpp:166
std::vector< BrinkmanNorms > computeBrinkmanNorms(const std::vector< Eigen::VectorXd > &list_dofs, const BrinkmanParameters &para) const
Compute the discrete energy norm of a family of vectors representing the dofs.
Definition hho-brinkman.cpp:710
static Brinkman::VelocityGradientType linear_gradu
Definition hho-brinkman.hpp:370
const SystemMatrixType & scMatrix() const
Returns the static condensation recovery operator.
Definition hho-brinkman.hpp:256
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition hho-brinkman.hpp:236
static BrinkmanParameters::ViscosityType vcracked_mu
Definition hho-brinkman.hpp:647
void assembleLinearSystem(const MomentumForcingTermType &f, const CompressibilityForcingTermType &g, const BrinkmanParameters &para, const VelocityType &u, Eigen::VectorXd &UDir)
Assemble the global system
Definition hho-brinkman.cpp:447
static Brinkman::MomentumForcingTermType cubic_f
Definition hho-brinkman.hpp:488
static BrinkmanParameters::PermeabilityInvType cavity_kappainv
Definition hho-brinkman.hpp:718
static Brinkman::VelocityType vcracked_u
Definition hho-brinkman.hpp:656
static Brinkman::VelocityGradientType trigonometric_gradu
Definition hho-brinkman.hpp:515
BrinkmanParameters(const ViscosityType &_mu, const PermeabilityInvType &_kappainv)
Constructor.
Definition hho-brinkman.hpp:65
static BrinkmanParameters::PermeabilityInvType linear_kappainv
Definition hho-brinkman.hpp:354
size_t dimPressure() const
Returns the dimension of pressure space.
Definition hho-brinkman.hpp:190
static std::function< double(const VectorRd &)> Xi_S
Definition hho-brinkman.hpp:761
static Brinkman::CompressibilityForcingTermType trigonometric_g
Definition hho-brinkman.hpp:555
static const MatrixRd mat_u
Definition hho-brinkman.hpp:356
std::function< VectorRd(const VectorRd &)> PressureGradientType
Definition hho-brinkman.hpp:127
static Brinkman::PressureGradientType tworegions_gradp
Definition hho-brinkman.hpp:868
Eigen::SparseMatrix< double > SystemMatrixType
Definition hho-brinkman.hpp:120
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition hho-brinkman.hpp:241
static Brinkman::MomentumForcingTermType DivGrad_beta_D
Definition hho-brinkman.hpp:900
static Brinkman::PressureGradientType quadratic_gradp
Definition hho-brinkman.hpp:426
static Brinkman::VelocityGradientType regimes_graduS
Definition hho-brinkman.hpp:605
static Brinkman::VelocityType quadratic_u
Definition hho-brinkman.hpp:396
std::function< double(const VectorRd &)> CompressibilityForcingTermType
Definition hho-brinkman.hpp:123
constexpr double viscosity_S
Definition hho-brinkman.hpp:770
static Brinkman::CompressibilityForcingTermType tworegions_g
Definition hho-brinkman.hpp:918
static Brinkman::VelocityType tworegions_u
Definition hho-brinkman.hpp:813
static Brinkman::VelocityGradientType grad_alpha
Definition hho-brinkman.hpp:818
double p
L2 norm of p.
Definition hho-brinkman.hpp:104
const Mesh & mesh() const
Returns the mesh.
Definition hho-brinkman.hpp:220
static Brinkman::VelocityGradientType cubic_gradu
Definition hho-brinkman.hpp:459
constexpr double viscosity_D
Definition hho-brinkman.hpp:771
static Brinkman::VelocityGradientType grad_beta_D
Definition hho-brinkman.hpp:844
size_t numSCDOFs() const
Returns the number of statically condensed DOFs.
Definition hho-brinkman.hpp:172
size_t numSCDOFs_u() const
Returns the number of velocity statically condensed DOFs.
Definition hho-brinkman.hpp:160
constexpr double permeability_S
Definition hho-brinkman.hpp:776
BrinkmanNorms(double norm_u, double norm_p)
Constructor.
Definition hho-brinkman.hpp:95
static Brinkman::CompressibilityForcingTermType linear_g
Definition hho-brinkman.hpp:385
size_t nloc_sc_p() const
Returns the local number of pressure statically condensed DOFs.
Definition hho-brinkman.hpp:154
static Brinkman::VelocityGradientType vcracked_gradu
Definition hho-brinkman.hpp:671
static Brinkman::CompressibilityForcingTermType quadratic_g
Definition hho-brinkman.hpp:439
static std::function< double(const VectorRd &)> XiS
Definition hho-brinkman.hpp:608
std::size_t n_cells() const
number of cells in the mesh.
Definition MeshND.hpp:60
Definition ddr-magnetostatics.hpp:41
Structure to store norm components (energy for velocity, L2 pressure, and global)
Definition hho-brinkman.hpp:93
Structure to store physical parameter (and compute derived parameters)
Definition hho-brinkman.hpp:60
Structure for Brinkman model.
Definition hho-brinkman.hpp:119
Structure for weights (scalar, at the moment) in integral.
Definition integralweight.hpp:36
Structure to store information for, and perform, local static condensation.
Definition local_static_condensation.hpp:25