HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
pkpo-pk-pk-pk.hpp
Go to the documentation of this file.
1#ifndef PKPO_PK_PK_PK_HPP
2#define PKPO_PK_PK_PK_HPP
3
4#include "hypre.hpp"
5
6#include <globaldofspace.hpp>
7
8namespace HArDCore2D {
9
10 namespace DSL {
11
12 class PkpoPkPkPk: 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, const double & viscosity);
38
39 std::vector<Eigen::MatrixXd> m_rtn_to_potential;
40
41 std::unique_ptr<GlobalDOFSpace> m_auxiliary_dof_table;
42 };
43
44 //------------------------------------------------------------------------------
45
46 template<typename F>
47 Eigen::VectorXd PkpoPkPkPk::_interpolate_velocity(
48 const F & v,
49 const InterpolateParameters & parameters
50 ) const
51 {
52 Eigen::VectorXd vh = Eigen::VectorXd::Zero(m_velocity_space->dimension());
53
54 // Degrees of quadrature rules
55 int doe_cell = (parameters.doe_cell > 0 ? doe_cell : 2 * m_degree + 1);
56 int doe_edge = (parameters.doe_edge > 0 ? doe_edge : 2 * m_degree + 3);
57
58 // Interpolate at edges
59 std::function<void(size_t, size_t)> interpolate_edges
60 = [this, v, &vh, &doe_edge](size_t start, size_t end)->void
61 {
62 const auto & edge_dofs = m_velocity_space->get<PolynEdgeType>("EdgeDOFs");
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, &doe_cell, &doe_edge](size_t start, size_t end)->void
78 {
79 const auto & rtn_edge_dofs = m_velocity_space->get<PolyEdgeType>("RTNEdgeDOFs");
80 const auto & rtn_roly = m_velocity_space->get<RolyCellType>("RTNRoly");
81 const auto & rtn_roly_compl = m_velocity_space->get<RolyComplCellType>("RTNRolyCompl");
82
83 // Dimensions
84 size_t dim_rtn_cell_dofs = LocalSpaceDimensions<PolynCellType>::get(m_degree - 1);
85 size_t dim_rtn_edge_dofs = LocalSpaceDimensions<PolyEdgeType>::get(m_degree);
86 size_t dim_rtn_roly = LocalSpaceDimensions<RolyCellType>::get(m_degree);
87 size_t dim_rtn_roly_compl = LocalSpaceDimensions<RolyComplCellType>::get(m_degree + 1);
88 size_t dim_rtn = dim_rtn_roly + dim_rtn_roly_compl;
89
90 for (size_t iT = start; iT < end; iT++) {
91 const Cell & T = *this->m_velocity_space->mesh().cell(iT);
92
93 // Interpolator
94 Eigen::MatrixXd MIT = Eigen::MatrixXd::Zero(dim_rtn, dim_rtn);
95 Eigen::VectorXd bIT = Eigen::VectorXd(dim_rtn);
96
97 MonomialCellIntegralsType int_mono_cell = IntegrateCellMonomials(T, 2 * (this->m_degree + 1));
99
100 if (dim_rtn_cell_dofs > 0) {
101 const auto & rtn_cell_dofs = m_velocity_space->get<PolynCellType>("RTNCellDOFs")[iT];
102
103 MIT.block(m_auxiliary_dof_table->localOffset(T), 0, dim_rtn_cell_dofs, dim_rtn_roly)
104 = GramMatrix(T, *rtn_cell_dofs, *rtn_roly[iT], int_mono_cell);
105 MIT.block(m_auxiliary_dof_table->localOffset(T), dim_rtn_roly, dim_rtn_cell_dofs, dim_rtn_roly_compl)
106 = GramMatrix(T, *rtn_cell_dofs, *rtn_roly_compl[iT], int_mono_cell);
107
108 auto rtn_cell_dofs_quad = evaluate_quad<Function>::compute(*rtn_cell_dofs, quad);
109 bIT.segment(m_auxiliary_dof_table->localOffset(T), dim_rtn_cell_dofs)
110 = l2_projection(v, *rtn_cell_dofs, quad, rtn_cell_dofs_quad, GramMatrix(T, *rtn_cell_dofs, int_mono_cell));
111 } // if
112
113 for (size_t iE = 0; iE < T.n_edges(); iE++) {
114 const Edge & E = *T.edge(iE);
115 auto nTE = T.edge_normal(iE);
116
117 const auto & rtn_edge_dofs_E = rtn_edge_dofs[E.global_index()];
118
119 auto normal_component = [&nTE](const VectorRd & w)->double { return w.dot(nTE); };
120
121 QuadratureRule quad_E = generate_quadrature_rule(E, doe_edge);
122 auto rtn_roly_quad
123 = transform_values_quad<double>( evaluate_quad<Function>::compute(*rtn_roly[iT], quad_E),
124 normal_component );
125 auto rtn_roly_compl_quad
126 = transform_values_quad<double>( evaluate_quad<Function>::compute(*rtn_roly_compl[iT], quad_E),
127 normal_component );
128
129 auto rtn_edge_dofs_quad = evaluate_quad<Function>::compute(*rtn_edge_dofs[E.global_index()], quad_E);
130
131 std::function<double(const VectorRd &)> evaluate_normal_component
132 = [v, &nTE](const VectorRd & x) { return v(x).dot(nTE); };
133
134 MIT.block(m_auxiliary_dof_table->localOffset(T, E), 0, dim_rtn_edge_dofs, dim_rtn_roly)
135 = compute_gram_matrix(rtn_edge_dofs_quad, rtn_roly_quad, quad_E);
136 MIT.block(m_auxiliary_dof_table->localOffset(T, E), dim_rtn_roly, dim_rtn_edge_dofs, dim_rtn_roly_compl)
137 = compute_gram_matrix(rtn_edge_dofs_quad, rtn_roly_compl_quad, quad_E);
138
139 bIT.segment(m_auxiliary_dof_table->localOffset(T, E), dim_rtn_edge_dofs)
140 = l2_projection(evaluate_normal_component, *rtn_edge_dofs_E, quad_E, rtn_edge_dofs_quad, GramMatrix(E, *rtn_edge_dofs_E));
141 } // for iE
142
143 vh.segment(this->m_velocity_space->globalOffset(T), this->m_velocity_space->numberOfLocalCellDofs())
144 = m_rtn_to_potential[iT] * MIT.fullPivLu().solve(bIT);
145 } // for iT
146 };
147 parallel_for(m_velocity_space->mesh().n_cells(), interpolate_cells, m_use_threads);
148
149 return vh;
150 }
151
152 } // namespace DSL
153
154} // namespace HArDCore2D
155
156#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
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
bool m_use_threads
Definition hypre.hpp:348
PkpoPkPkPk(const Mesh &mesh, size_t degree, const BoundaryConditions &bc, const HYPREParameters &parameters)
Constructor.
Eigen::VectorXd interpolate(const VelocityType &u, const PressureType &p) const
Interpolate both velocity and pressure.
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
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< DIMENSION > Cell
Definition Polytope2D.hpp:151
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
std::unordered_map< VectorZd, double, VecHash > MonomialCellIntegralsType
Type for list of integrals of monomials.
Definition GMpoly_cell.hpp:53
MonomialCellIntegralsType IntegrateCellMonomials(const Cell &T, const size_t maxdeg)
Compute all integrals on a cell of monomials up to a total degree, using vertex values.
Definition GMpoly_cell.cpp:7
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
TensorizedVectorFamily< PolyCellType, dimspace > PolynCellType
Definition discrete-space-descriptor.hpp:23
TensorizedVectorFamily< Family< MonomialScalarBasisEdge >, dimspace > PolynEdgeType
Definition discrete-space-descriptor.hpp:24
Family< RolyComplBasisCell > RolyComplCellType
Definition discrete-space-descriptor.hpp:30
Family< CurlBasis< ShiftedBasis< MonomialScalarBasisCell > > > RolyCellType
Definition discrete-space-descriptor.hpp:29
Family< MonomialScalarBasisEdge > PolyEdgeType
Definition discrete-space-descriptor.hpp:22
Definition ddr-klplate.hpp:27
static auto v
Definition ddrcore-test.hpp:32
Definition hypre.hpp:21
Definition hho-interpolate.hpp:15
Evaluate a basis at quadrature nodes. 'BasisFunction' (=Function, Gradient, Curl, Divergence,...
Definition basis.hpp:2284