LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
laplace_matrix_provider.cc
1#include "laplace_matrix_provider.h"
2
3#include <lf/uscalfe/lagr_fe.h>
4
5#include <cmath>
6#include <iomanip>
7#include <iostream>
8
10
12 const lf::mesh::Entity &entity) const {
13 // Only triangles are supported
14 LF_VERIFY_MSG(entity.RefEl() == lf::base::RefEl::kTria(),
15 "Unsupported cell type " << entity.RefEl());
16
17 // Get the geometry of the entity
18 const auto *geom = entity.Geometry();
19
20 // Compute the global vertex coordinates
21 Eigen::MatrixXd vertices = geom->Global(entity.RefEl().NodeCoords());
22
23 // Construct the basis functions from curl of the standard hat functions
25
26 // The gradients are constant on the triangle
27 const Eigen::MatrixXd ref_grads =
28 hat_func.GradientsReferenceShapeFunctions(Eigen::VectorXd::Zero(2))
29 .transpose();
30
31 // The JacobianInverseGramian is constant on the triangle
32 const Eigen::MatrixXd J_inv_trans =
33 geom->JacobianInverseGramian(Eigen::VectorXd::Zero(2));
34
35 // Compute gradients
36 Eigen::MatrixXd grads = J_inv_trans * ref_grads;
37
38 // Compute the element matrix for the product of baricentric functions
39 Eigen::MatrixXd elem_mat(3, 3);
40
41 elem_mat = grads.transpose() * grads;
42
43 // correct for integral
44 elem_mat *= lf::geometry::Volume(*geom);
45
46 return elem_mat;
47}
48
49} // namespace projects::hldo_sphere::assemble
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
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
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.
Linear Lagrange finite element on triangular reference element.
Definition: lagr_fe.h:58
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > GradientsReferenceShapeFunctions(const Eigen::MatrixXd &refcoords) const override
Computation of the gradients of all reference shape functions in a number of points.
Definition: lagr_fe.h:117
Eigen::MatrixXd Eval(const lf::mesh::Entity &entity) const
Compute the element matrix for a given cell of a mesh.
double Volume(const Geometry &geo)
Compute the (approximate) volume (area) of a shape.
Collection of matrix and vector element providers.
Definition: assemble.h:26