HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
botti-massa.hpp
Go to the documentation of this file.
1#ifndef BOTTI_MASSA_HPP
2#define BOTTI_MASSA_HPP
3
4#include "hypre.hpp"
5
6#include <globaldofspace.hpp>
7
8namespace HArDCore2D {
9
10 namespace DSL {
11
12 class BottiMassa: public HYPRE {
13 public:
16 const Mesh & mesh,
17 size_t degree,
18 const BoundaryConditions & bc,
19 const HYPREParameters & parameters
20 );
21
23 Eigen::VectorXd interpolate(
24 const VelocityType & u,
25 const PressureType & p
26 ) const;
27
28 private:
30 template<typename F>
31 Eigen::VectorXd _interpolate_velocity(
32 const F & v,
33 const InterpolateParameters & parameters = {}
34 ) const;
35
37 void _construct_stabilization(size_t iT);
38
39 std::unique_ptr<DiscreteSpace> m_bdmn_space;
40 };
41
42 //------------------------------------------------------------------------------
43
44 template<typename F>
45 Eigen::VectorXd BottiMassa::_interpolate_velocity(
46 const F & v,
47 const InterpolateParameters & parameters
48 ) const
49 {
50 Eigen::VectorXd vh = Eigen::VectorXd::Zero(m_velocity_space->dimension());
51
52 const auto & cell_dofs = m_velocity_space->get<PolynCellType>("CellDOFs");
53 const auto & edge_dofs = m_velocity_space->get<PolynEdgeType>("EdgeDOFs");
54 const auto & bdmn_edge_dofs = m_bdmn_space->get<PolyEdgeType>("EdgeDOFs");
55
56 // Degrees of quadrature rules
57 int doe_cell = (parameters.doe_cell > 0 ? doe_cell : 2 * m_degree + 1);
58 int doe_edge = (parameters.doe_edge > 0 ? doe_edge : 2 * m_degree + 3);
59
60 // Interpolate at edges
61 std::function<void(size_t, size_t)> interpolate_edges
62 = [this, v, &vh, &edge_dofs, &doe_edge](size_t start, size_t end)->void
63 {
64 for (size_t iE = start; iE < end; iE++) {
65 const Edge & E = *this->m_velocity_space->mesh().edge(iE);
66 const auto & edge_dofs_E = edge_dofs[E.global_index()];
67 QuadratureRule quad = generate_quadrature_rule(E, doe_edge);
68 auto edge_dofs_quad = evaluate_quad<Function>::compute(*edge_dofs_E, quad);
69 vh.segment(this->m_velocity_space->globalOffset(E), this->m_velocity_space->numberOfLocalEdgeDofs())
70 = l2_projection(v, *edge_dofs_E, quad, edge_dofs_quad, GramMatrix(E, *edge_dofs_E));
71 } // for iE
72 };
73 parallel_for(m_velocity_space->mesh().n_edges(), interpolate_edges, parameters.use_threads);
74
75 // Interpolate at cells
76 std::function<void(size_t, size_t)> interpolate_cells
77 = [this, &vh, v, &cell_dofs, &bdmn_edge_dofs, &doe_cell, &doe_edge](size_t start, size_t end)->void
78 {
79 for (size_t iT = start; iT < end; iT++) {
80 const Cell & T = *this->m_velocity_space->mesh().cell(iT);
81
82 // Dimensions
83 int dim_cell_dofs = this->m_velocity_space->numberOfLocalCellDofs("CellDOFs");
84
85 // Local system matrix and vector
86 Eigen::MatrixXd MIT = Eigen::MatrixXd::Zero(dim_cell_dofs, dim_cell_dofs);
87 Eigen::VectorXd bIT = Eigen::VectorXd::Zero(dim_cell_dofs);
88
89 QuadratureRule quad_T = generate_quadrature_rule(T, doe_cell);
90 const auto & cell_dofs_T = cell_dofs[iT];
91 auto cell_dofs_quad = evaluate_quad<Function>::compute(*cell_dofs_T, quad_T);
92
93 if (m_degree >= 1) {
94 int dim_bdmn_goly_dofs = this->m_bdmn_space->numberOfLocalCellDofs("GolyCellDOFs");
95 int offset_bdmn_goly_dofs = this->m_bdmn_space->localOffset(T, "GolyCellDOFs");
96 const auto & bdmn_goly_dofs = this->m_bdmn_space->get<GolyCellType>("GolyCellDOFs")[iT];
97 auto bdmn_goly_dofs_quad = evaluate_quad<Function>::compute(*bdmn_goly_dofs, quad_T);
98 MIT.block(offset_bdmn_goly_dofs, 0, dim_bdmn_goly_dofs, dim_cell_dofs)
99 = compute_gram_matrix(bdmn_goly_dofs_quad, cell_dofs_quad, quad_T);
100
101 bIT.segment(offset_bdmn_goly_dofs, dim_bdmn_goly_dofs) = integrate(v, bdmn_goly_dofs_quad, quad_T);
102 } // if
103
104 if (m_degree >= 1) {
105 int dim_bdmn_goly_compl_dofs = this->m_bdmn_space->numberOfLocalCellDofs("GolyComplCellDOFs");
106 int offset_bdmn_goly_compl_dofs = this->m_bdmn_space->localOffset(T, "GolyComplCellDOFs");
107 const auto & bdmn_goly_compl_dofs = this->m_bdmn_space->get<GolyComplCellType>("GolyComplCellDOFs")[iT];
108 auto bdmn_goly_compl_quad = evaluate_quad<Function>::compute(*bdmn_goly_compl_dofs, quad_T);
109 MIT.block(offset_bdmn_goly_compl_dofs, 0, dim_bdmn_goly_compl_dofs, dim_cell_dofs)
110 = compute_gram_matrix(bdmn_goly_compl_quad, cell_dofs_quad, quad_T);
111
112 bIT.segment(offset_bdmn_goly_compl_dofs, dim_bdmn_goly_compl_dofs) = integrate(v, bdmn_goly_compl_quad, quad_T);
113 } // if
114
115 for (size_t iE = 0; iE < T.n_edges(); iE++) {
116 const Edge & E = *T.edge(iE);
117 auto nTE = T.edge_normal(iE);
118
119 const auto & bdmn_edge_dofs_E = bdmn_edge_dofs[E.global_index()];
120
121 QuadratureRule quad_E = generate_quadrature_rule(E, doe_edge);
122 auto cell_dofs_nTE_quad
123 = transform_values_quad<double>(
124 evaluate_quad<Function>::compute(*cell_dofs_T, quad_E),
125 [&nTE](const VectorRd & w)->double { return w.dot(nTE); }
126 );
127 auto bdmn_edge_dofs_quad = evaluate_quad<Function>::compute(*bdmn_edge_dofs_E, quad_E);
128
129 int dim_bdmn_edge_dofs = this->m_bdmn_space->numberOfLocalEdgeDofs("EdgeDOFs"); // PolynomialSpaceDimension<Edge>::Poly(this->m_degree + 1);
130
131 std::function<double(const VectorRd &)> v_dot_nTE
132 = [v, &nTE](const VectorRd & x) { return v(x).dot(nTE); };
133
134 MIT.block(this->m_bdmn_space->localOffset(T, E), 0, dim_bdmn_edge_dofs, dim_cell_dofs)
135 = compute_gram_matrix(bdmn_edge_dofs_quad, cell_dofs_nTE_quad, quad_E);
136
137 bIT.segment(this->m_bdmn_space->localOffset(T, E), dim_bdmn_edge_dofs)
138 = integrate(v_dot_nTE, bdmn_edge_dofs_quad, quad_E);
139 } // for
140 vh.segment(this->m_velocity_space->globalOffset(T), this->m_velocity_space->numberOfLocalCellDofs())
141 = MIT.fullPivLu().solve(bIT);
142 } // for iT
143 };
144 parallel_for(m_velocity_space->mesh().n_cells(), interpolate_cells, parameters.use_threads);
145
146 return vh;
147 }
148
149 } // namespace DSL
150
151} // namespace HArDCore2D
152
153#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
Definition botti-massa.hpp:12
Eigen::VectorXd interpolate(const VelocityType &u, const PressureType &p) const
Interpolate both velocity and pressure.
Definition botti-massa.cpp:112
Definition hypre.hpp:31
std::function< VectorRd(const VectorRd &)> VelocityType
Definition hypre.hpp:37
size_t degree() const
Returns the degree.
Definition hypre.hpp:64
const Mesh & mesh() const
Returns the mesh.
Definition hypre.hpp:166
std::unique_ptr< DiscreteSpace > m_velocity_space
Definition hypre.hpp:366
size_t m_degree
Definition hypre.hpp:345
std::function< double(const VectorRd &)> PressureType
Definition hypre.hpp:39
Definition basis.hpp:311
Vector family obtained by tensorization of a scalar family.
Definition basis.hpp:559
Definition Mesh2D.hpp:26
end
Definition compute_eigs.m:12
Eigen::Vector2d VectorRd
Definition basis.hpp:55
Eigen::MatrixXd compute_gram_matrix(const boost::multi_array< VectorRd, 2 > &B1, const boost::multi_array< double, 2 > &B2, const QuadratureRule &qr)
Compute the Gram-like matrix given a family of vector-valued and one of scalar-valued functions by te...
Definition basis.cpp:225
Eigen::VectorXd l2_projection(const std::function< typename BasisType::FunctionValue(const VectorRd &)> &f, const BasisType &basis, QuadratureRule &quad, const boost::multi_array< typename BasisType::FunctionValue, 2 > &basis_quad, const Eigen::MatrixXd &mass_basis=Eigen::MatrixXd::Zero(1, 1))
Compute the L2-projection of a function.
Definition basis.hpp:2886
Eigen::VectorXd integrate(const FType< T > &f, const BasisQuad< T > &B, const QuadratureRule &qr, size_t n_rows=0)
Compute the integral of a given function against all functions from a family.
Definition basis.hpp:2700
static boost::multi_array< typename detail::basis_evaluation_traits< BasisType, BasisFunction >::ReturnValue, 2 > compute(const BasisType &basis, const QuadratureRule &quad)
Generic basis evaluation.
Definition basis.hpp:2288
static void parallel_for(unsigned nb_elements, std::function< void(size_t start, size_t end)> functor, bool use_threads=true, unsigned nb_threads_max=1e9)
Generic function to execute threaded processes.
Definition parallel_for.hpp:42
Polytope< 1 > Edge
A Face is a Polytope with object_dim = DIMENSION - 1.
Definition Polytope2D.hpp:147
std::vector< QuadratureNode > QuadratureRule
Definition quadraturerule.hpp:55
Eigen::MatrixXd GramMatrix(const Cell &T, const MonomialScalarBasisCell &basis1, const MonomialScalarBasisCell &basis2, MonomialCellIntegralsType mono_int_map={})
Computes the Gram Matrix of a pair of local scalar monomial bases.
Definition GMpoly_cell.cpp:86
QuadratureRule generate_quadrature_rule(const Cell &T, const int doe, const bool force_split)
Generate quadrature rule on mesh element.
Definition quadraturerule.cpp:10
if(strcmp(field, 'real')) % real valued entries T
Definition mmread.m:93
Family< GradientBasis< ShiftedBasis< MonomialScalarBasisCell > > > GolyCellType
Definition discrete-space-descriptor.hpp:19
Family< GolyComplBasisCell > GolyComplCellType
Definition discrete-space-descriptor.hpp:20
Definition ddr-klplate.hpp:27
static auto v
Definition ddrcore-test.hpp:32
Definition hypre.hpp:21
Definition hho-interpolate.hpp:15
int doe_cell
Definition hho-interpolate.hpp:17
bool use_threads
Definition hho-interpolate.hpp:16
int doe_edge
Definition hho-interpolate.hpp:18
Evaluate a basis at quadrature nodes. 'BasisFunction' (=Function, Gradient, Curl, Divergence,...
Definition basis.hpp:2284