LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
norms.h
1#ifndef HLDO_SPHERE_NORMS_L2NORM_H
2#define HLDO_SPHERE_NORMS_L2NORM_H
3
11
32template <typename MF, typename SQ_F>
33std::pair<double, lf::mesh::utils::CodimMeshDataSet<double>> L2norm(
34 const std::shared_ptr<const lf::mesh::Mesh>& mesh_p, const MF& f,
35 const SQ_F& sq_f, const lf::quad::QuadRule& quadrule) {
36 // store the intermediate squared sums of cells
37 double squared_sum = 0;
38
39 // create codim mesh dataset to store the cellwise integrals
41
42 // get ref quad points and weights for each cell
43 const Eigen::MatrixXd loc_points = quadrule.Points();
44 const Eigen::VectorXd weights = quadrule.Weights();
45 const lf::base::size_type n_points = quadrule.NumPoints();
46
47 // loop over all cells in the mesh
48 for (const lf::mesh::Entity* e : mesh_p->Entities(0)) {
49 // get determinante of the pullpack this is constant for all points
50 Eigen::VectorXd det{e->Geometry()->IntegrationElement(loc_points)};
51 // get funciton values
52 auto values = f(*e, loc_points);
53 // compute local quadrature of the squared norm
54 double cell_error = 0;
55 for (lf::base::size_type i = 0; i < n_points; i++) {
56 cell_error += det[i] * weights[i] * sq_f(values[i]);
57 }
58 cellErrors(*e) = std::sqrt(cell_error);
59 squared_sum += cell_error;
60 }
61
62 return std::make_pair(sqrt(squared_sum), cellErrors);
63}
64
83template <typename MF, typename SQ_F>
84std::pair<double, lf::mesh::utils::CodimMeshDataSet<double>> SupNorm(
85 const std::shared_ptr<const lf::mesh::Mesh>& mesh_p, const MF& f,
86 const SQ_F& sq_f, const lf::quad::QuadRule& quadrule) {
87 // store the intermediate squared sums of cells
88 double glob_max = 0;
89
90 // create codim mesh dataset to store the cellwise integrals
92
93 // get ref quad points and weights for each cell
94 const Eigen::MatrixXd loc_points = quadrule.Points();
95 const lf::base::size_type n_points = quadrule.NumPoints();
96
97 // loop over all cells in the mesh
98 for (const lf::mesh::Entity* e : mesh_p->Entities(0)) {
99 // get determinante of the pullpack this is constant for all points
100 auto values = f(*e, loc_points);
101
102 // compute local quadrature of the squared norm
103 double loc_max = 0.;
104 for (lf::base::size_type i = 0; i < n_points; i++) {
105 double temp = sq_f(values[i]);
106 if (temp > loc_max) loc_max = temp;
107 if (temp > glob_max) glob_max = temp;
108 }
109 cellErrors(*e) = sqrt(loc_max);
110 }
111
112 return std::make_pair(sqrt(glob_max), cellErrors);
113}
114
115} // namespace projects::hldo_sphere::post_processing
116#endif // HLDO_SPHERE_NORMS_L2NORM_H
Interface class representing a topological entity in a cellular complex
Definition: entity.h:39
A MeshDataSet that attaches data of type T to every entity of a mesh that has a specified codimension...
Represents a Quadrature Rule over one of the Reference Elements.
Definition: quad_rule.h:58
const Eigen::VectorXd & Weights() const
All quadrature weights as a vector.
Definition: quad_rule.h:152
const Eigen::MatrixXd & Points() const
All quadrature points as column vectors.
Definition: quad_rule.h:145
base::size_type NumPoints() const
Return the total number of quadrature points (num of columns of points/weights)
Definition: quad_rule.h:158
unsigned int size_type
general type for variables related to size of arrays
Definition: base.h:24
Postprocessing such as computing norms and Mesh Functions and plot scripts.
std::pair< double, lf::mesh::utils::CodimMeshDataSet< double > > SupNorm(const std::shared_ptr< const lf::mesh::Mesh > &mesh_p, const MF &f, const SQ_F &sq_f, const lf::quad::QuadRule &quadrule)
Computes the supremum norm of the squared values of some MeshFunction (type MF) f.
Definition: norms.h:84
std::pair< double, lf::mesh::utils::CodimMeshDataSet< double > > L2norm(const std::shared_ptr< const lf::mesh::Mesh > &mesh_p, const MF &f, const SQ_F &sq_f, const lf::quad::QuadRule &quadrule)
Computes the L2Norm of some MeshFunction (type MF) f.
Definition: norms.h:33