LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
whitney_two_vector_provider.h
1#ifndef HLDO_SPHERE_ASSEMBLE_WHITNEY_TWO_VECTOR_PROVIDER_H
2#define HLDO_SPHERE_ASSEMBLE_WHITNEY_TWO_VECTOR_PROVIDER_H
3
8#include <lf/mesh/entity.h>
9#include <lf/mesh/utils/mesh_data_set.h>
10#include <lf/quad/quad.h>
11#include <lf/uscalfe/lagr_fe.h>
12
13#include <Eigen/Dense>
14#include <functional>
15#include <utility>
16
17namespace projects::hldo_sphere {
18
19namespace assemble {
20
48template <typename SCALAR>
50 public:
57 const std::function<SCALAR(const Eigen::Vector3d &)> &f)
58 : f_(std::move(f)) {}
59
67 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> Eval(
68 const lf::mesh::Entity &entity) const {
69 const auto *const geom = entity.Geometry();
70
71 // Only triangles are supported
72 LF_VERIFY_MSG(entity.RefEl() == lf::base::RefEl::kTria(),
73 "Unsupported cell type " << entity.RefEl());
74
75 // Compute the global vertex coordinates
76 Eigen::MatrixXd vertices = geom->Global(entity.RefEl().NodeCoords());
77
78 // define quad rule with sufficiantly high degree since the
79 // baricentric coordinate functions have degree 1
81
82 // Compute the elements of the vector with given quadrature rule
83 const Eigen::MatrixXd points = geom->Global(quadrule.Points());
84 const Eigen::VectorXd weights =
85 (geom->IntegrationElement(quadrule.Points()).array() *
86 quadrule.Weights().array())
87 .matrix();
88
89 SCALAR sum = 0;
90 for (lf::base::size_type n = 0; n < quadrule.NumPoints(); ++n) {
91 Eigen::VectorXd x = points.col(n);
92 sum += weights[n] * f_(x);
93 }
94
95 Eigen::Matrix<SCALAR, 1, 1> element_vector;
96 element_vector(0) = sum;
97
98 return element_vector;
99 }
100
104 bool isActive(const lf::mesh::Entity &entity) const { return true; }
105
106 private:
107 const std::function<SCALAR(const Eigen::Vector3d &)> f_;
108};
109
110} // end namespace assemble
111
112} // namespace projects::hldo_sphere
113
114#endif // HLDO_SPHERE_ASSEMBLE_WHITNEY_TWO_VECTOR_PROVIDER_H
const Eigen::MatrixXd & NodeCoords() const
Get the coordinates of the nodes of this reference element.
Definition: ref_el.h:238
static constexpr RefEl kTria()
Returns the reference triangle.
Definition: ref_el.h:158
Interface class representing a topological entity in a cellular complex
Definition: entity.h:39
virtual const geometry::Geometry * Geometry() const =0
Describes the geometry of this entity.
virtual base::RefEl RefEl() const =0
Describes the reference element type of this entity.
Represents a Quadrature Rule over one of the Reference Elements.
Definition: quad_rule.h:58
Element vector provider for piecewise constant whitney two forms.
const std::function< SCALAR(const Eigen::Vector3d &)> f_
bool isActive(const lf::mesh::Entity &entity) const
All entities are regarded as active.
WhitneyTwoVectorProvider(const std::function< SCALAR(const Eigen::Vector3d &)> &f)
Constructor.
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > Eval(const lf::mesh::Entity &entity) const
Compute the element vector for some trinagle of the mesh.
unsigned int size_type
general type for variables related to size of arrays
Definition: base.h:24
QuadRule make_TriaQR_EdgeMidpointRule()
edge midpoint quadrature rule for reference triangles
Implementation of the thesis Hogde Laplacians and Dirac Operators on the surface of the 3-Sphere.
Definition: assemble.h:15