LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
load_vector_provider.h
1#ifndef HLDO_SPHERE_ASSEMBLE_LOAD_VECTOR_PROVIDER_H
2#define HLDO_SPHERE_ASSEMBLE_LOAD_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:
59 LoadVectorProvider(const std::function<SCALAR(const Eigen::Vector3d &)> &f)
60 : f_(f) {}
61
69 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> Eval(
70 const lf::mesh::Entity &entity) const {
71 const auto *const geom = entity.Geometry();
72
73 // Only triangles are supported
74 LF_VERIFY_MSG(entity.RefEl() == lf::base::RefEl::kTria(),
75 "Unsupported cell type " << entity.RefEl());
76
77 // Compute the global vertex coordinates
78 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> vertices =
79 geom->Global(entity.RefEl().NodeCoords());
80
81 // define quad rule with sufficiantly high degree since the
82 // baricentric coordinate functions have degree 1
84
86 const auto lambda_hat = [&](Eigen::Vector2d x_hat)
87 -> Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> {
88 return hat_func.EvalReferenceShapeFunctions(x_hat);
89 };
90
91 // returns evaluation of @f$ \lambda @f$ for at a given point on the
92 // reference triangle f is evaluated at the global coordinates
93 const auto f_tilde_hat =
94 [&](Eigen::Vector2d x_hat) -> Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> {
95 Eigen::MatrixXd x = geom->Global(x_hat);
96 return lambda_hat(x_hat) * f_(x);
97 };
98
99 // Compute the elements of the vector with given quadrature rule
100 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> element_vector =
101 Eigen::Matrix<SCALAR, 3, 1>::Zero();
102 const Eigen::MatrixXd points = quadrule.Points();
103 const Eigen::VectorXd weights =
104 (geom->IntegrationElement(points).array() * quadrule.Weights().array())
105 .matrix();
106 for (lf::base::size_type n = 0; n < quadrule.NumPoints(); ++n) {
107 const Eigen::Matrix<SCALAR, 3, 1> f_eval = f_tilde_hat(points.col(n));
108 element_vector += weights[n] * f_eval;
109 }
110 return element_vector;
111 }
112
116 bool isActive(const lf::mesh::Entity &entity) const { return true; }
117
118 private:
119 const std::function<SCALAR(const Eigen::Vector3d &)> f_;
120};
121
122} // end namespace assemble
123
124} // namespace projects::hldo_sphere
125
126#endif // HLDO_SPHERE_ASSEMBLE_LOAD_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
Linear Lagrange finite element on triangular reference element.
Definition: lagr_fe.h:58
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > EvalReferenceShapeFunctions(const Eigen::MatrixXd &refcoords) const override
Evaluation of all reference shape functions in a number of points.
Definition: lagr_fe.h:104
Element Vector Provider for scalar valued load functions using picewise linear barycentric basis func...
const std::function< SCALAR(const Eigen::Vector3d &)> f_
bool isActive(const lf::mesh::Entity &entity) const
All entities are regarded as active.
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > Eval(const lf::mesh::Entity &entity) const
Compute the element vector for some cell on the mesh.
LoadVectorProvider(const std::function< SCALAR(const Eigen::Vector3d &)> &f)
Constructor setting the load function.
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