HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
hho-interpolate.hpp
Go to the documentation of this file.
1#ifndef HHO_INTERPOLATE_HPP
2#define HHO_INTERPOLATE_HPP
3
4#include "discrete-space.hpp"
5#include "hho-dofs-types.hpp"
6
7#include <parallel_for.hpp>
8#include <GMpoly_cell.hpp>
9#include <GMpoly_edge.hpp>
10
11namespace HArDCore2D {
12
13 namespace DSL {
14
16 bool use_threads = true;
17 int doe_cell = -1;
18 int doe_edge = -1;
19 };
20
21 template<TensorRankE Rank, typename F>
22 Eigen::VectorXd hho_interpolate(
23 const DiscreteSpace & Vh,
24 const F & v,
25 const InterpolateParameters & parameters = {}
26 )
27 {
28 const auto & cell_dofs_bases = Vh.get<typename HHODOFsTypes<Rank>::CellDOFsType>("CellDOFs");
29 const auto & edge_dofs_bases = Vh.get<typename HHODOFsTypes<Rank>::EdgeDOFsType>("EdgeDOFs");
30
31 Eigen::VectorXd vh = Eigen::VectorXd::Zero(Vh.dimension());
32
33 int doe_cell = (parameters.doe_cell > 0 ? parameters.doe_cell : 2 * cell_dofs_bases[0]->max_degree() + 3);
34 int doe_edge = (parameters.doe_edge > 0 ? parameters.doe_edge : 2 * edge_dofs_bases[0]->max_degree() + 3);
35
36 // Interpolate at edges
37 std::function<void(size_t, size_t)> interpolate_edges
38 = [&Vh, &edge_dofs_bases, &vh, v, &doe_edge](size_t start, size_t end)->void
39 {
40 for (size_t iE = start; iE < end; iE++) {
41 const Edge & E = *Vh.mesh().edge(iE);
42 QuadratureRule quad = generate_quadrature_rule(E, doe_edge);
43 auto edge_basis_quad = evaluate_quad<Function>::compute(*edge_dofs_bases[iE], quad);
44 vh.segment(Vh.globalOffset(E), edge_dofs_bases[iE]->dimension())
45 = l2_projection(v, *edge_dofs_bases[iE], quad, edge_basis_quad, GramMatrix(E, *edge_dofs_bases[iE]));
46 } // for iE
47 };
48 parallel_for(Vh.mesh().n_edges(), interpolate_edges, parameters.use_threads);
49
50 // Interpolate at cells
51 std::function<void(size_t, size_t)> interpolate_cells
52 = [&Vh, &cell_dofs_bases, &vh, v, &doe_cell](size_t start, size_t end)->void
53 {
54 for (size_t iT = start; iT < end; iT++) {
55 const Cell & T = *Vh.mesh().cell(iT);
57 auto cell_basis_quad = evaluate_quad<Function>::compute(*cell_dofs_bases[iT], quad);
58 vh.segment(Vh.globalOffset(T), cell_dofs_bases[iT]->dimension())
59 = l2_projection(v, *cell_dofs_bases[iT], quad, cell_basis_quad, GramMatrix(T, *cell_dofs_bases[iT]));
60 } // for iT
61 };
62 parallel_for(Vh.mesh().n_cells(), interpolate_cells, parameters.use_threads);
63
64 return vh;
65 }
66
67 } // namespace DSL
68
69} // namespace HArDCore2D
70
71#endif
Definition discrete-space.hpp:20
const std::vector< std::unique_ptr< T > > & get(const std::string &name) const
Definition discrete-space.hpp:84
const Mesh & mesh() const
Definition discrete-space.hpp:68
size_t dimension() const
Returns the dimension of the global space (all DOFs for all geometric entities)
Definition local-dof-table.hpp:58
end
Definition compute_eigs.m:12
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
size_t globalOffset(const Vertex &V) const
Return the global offset for the unknowns on the vertex V.
Definition global-dof-table.hpp:28
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
Cell * cell(std::size_t index) const
get a constant pointer to a cell using its global index
Definition Mesh2D.hpp:178
Edge * edge(std::size_t index) const
get a constant pointer to a edge using its global index
Definition Mesh2D.hpp:168
std::size_t n_cells() const
number of cells in the mesh.
Definition Mesh2D.hpp:63
std::size_t n_edges() const
number of edges in the mesh.
Definition Mesh2D.hpp:61
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
Eigen::VectorXd hho_interpolate(const DiscreteSpace &Vh, const F &v, const InterpolateParameters &parameters={})
Definition hho-interpolate.hpp:22
Definition ddr-klplate.hpp:27
static auto v
Definition ddrcore-test.hpp:32
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