1#ifndef THESIS_POST_PROCESSING_NORMS_H
2#define THESIS_POST_PROCESSING_NORMS_H
11#include <lf/mesh/entity.h>
12#include <lf/mesh/mesh.h>
13#include <lf/mesh/utils/utils.h>
14#include <lf/quad/quad.h>
15#include <lf/uscalfe/uscalfe.h>
22namespace post_processing {
39template <
typename MF,
typename QR_
SELECTOR>
40double L2norm(
const std::shared_ptr<const lf::mesh::Mesh> &mesh,
const MF &f,
41 const QR_SELECTOR &qr_selector) {
43 *mesh, lf::mesh::utils::squaredNorm(f), qr_selector));
67template <
typename MF_F,
typename MF_GRAD,
typename QR_
SELECTOR>
68double DGnorm(
const std::shared_ptr<const lf::mesh::Mesh> &mesh,
const MF_F &f,
69 const MF_GRAD &f_grad,
const QR_SELECTOR &qr_selector) {
73 *mesh, lf::mesh::utils::squaredNorm(f_grad), qr_selector);
76 using jump_t = std::remove_cv_t<
decltype(
77 (std::declval<lf::mesh::utils::MeshFunctionReturnType<MF_F>>() *
78 std::declval<Eigen::Vector2d>().transpose())
81 for (
const auto entity : mesh->Entities(0)) {
82 const auto edges = entity->SubEntities(1);
83 const auto orientations = entity->RelativeOrientations();
86 std::array<lf::quad::QuadRule, 3> quadrules;
87 std::array<Eigen::MatrixXd, 3> quadpoints;
88 for (
int i = 0; i < 3; ++i) {
89 quadrules[i] = qr_selector(*edges[i]);
90 quadpoints[i] = Eigen::MatrixXd(2, quadrules[i].NumPoints());
92 quadpoints[0] << quadrules[0].Points(),
93 Eigen::VectorXd::Zero(quadrules[0].NumPoints());
94 quadpoints[1] << Eigen::VectorXd::Ones(quadrules[1].NumPoints()) -
95 quadrules[1].Points(),
96 quadrules[1].Points();
97 quadpoints[2] << Eigen::VectorXd::Zero(quadrules[2].NumPoints()),
98 Eigen::VectorXd::Ones(quadrules[2].NumPoints()) - quadrules[2].Points();
99 for (
int i = 0; i < 3; ++i) {
100 const auto edge = edges[i];
101 const auto segment_eval = f(*entity, quadpoints[i]);
103 if (eval(*edge).size() == 0) {
104 eval(*edge).resize(segment_eval.size());
105 for (
int j = 0; j < segment_eval.size(); ++j) {
106 eval(*edge)[j] = segment_eval[j] * normals.col(i).transpose();
109 for (
int j = 0; j < segment_eval.size(); ++j) {
110 eval(*edge)[j] += segment_eval[j] * normals.col(i).transpose();
114 if (eval(*edge).size() == 0) {
115 eval(*edge).resize(segment_eval.size());
116 for (
int j = 0; j < segment_eval.size(); ++j) {
117 eval(*edge)[j] = segment_eval[segment_eval.size() - j - 1] *
118 normals.col(i).transpose();
121 for (
int j = 0; j < segment_eval.size(); ++j) {
122 eval(*edge)[j] += segment_eval[segment_eval.size() - j - 1] *
123 normals.col(i).transpose();
129 for (
const auto edge : mesh->Entities(1)) {
130 if (!boundary(*edge)) {
131 const auto qr = qr_selector(*edge);
132 const auto geom = edge->Geometry();
133 const auto ie = geom->IntegrationElement(qr.Points());
134 const Eigen::VectorXd weights =
135 (qr.Weights().array() * ie.array()).matrix() /
137 const auto &p = eval(*edge);
138 for (
int i = 0; i < p.size(); ++i) {
139 norm2 += weights[i] * p[i].squaredNorm();
143 return std::sqrt(norm2);
A MeshDataSet that attaches data of type T to every entity of a mesh that has a specified codimension...
auto IntegrateMeshFunction(const lf::mesh::Mesh &mesh, const MF &mf, const QR_SELECTOR &qr_selector, const ENTITY_PREDICATE &ep=base::PredicateTrue{}, int codim=0) -> mesh::utils::MeshFunctionReturnType< MF >
Integrate a MeshFunction over a mesh (with quadrature rules)
double Volume(const Geometry &geo)
Compute the (approximate) volume (area) of a shape.
CodimMeshDataSet< bool > flagEntitiesOnBoundary(const std::shared_ptr< const Mesh > &mesh_p, lf::base::dim_t codim)
flag entities of a specific co-dimension located on the boundary
Eigen::Matrix< double, 2, 3 > computeOutwardNormals(const lf::mesh::Entity &entity)
Compute the outward pointing normals of a triangle.
double DGnorm(const std::shared_ptr< const lf::mesh::Mesh > &mesh, const MF_F &f, const MF_GRAD &f_grad, const QR_SELECTOR &qr_selector)
Compute the DG-norm of a vector valued function over a mesh.
double L2norm(const std::shared_ptr< const lf::mesh::Mesh > &mesh, const MF &f, const QR_SELECTOR &qr_selector)
Compute the -norm of a vector valued function over a mesh.