LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
whitney_one_grad_matrix_provider.cc
1#include "whitney_one_grad_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 // The gradients are constant on the triangle
26 const Eigen::MatrixXd ref_grads =
27 hat_func.GradientsReferenceShapeFunctions(Eigen::VectorXd::Zero(2))
28 .transpose();
29 // The JacobianInverseGramian is constant on the triangle
30 const Eigen::MatrixXd J_inv_trans =
31 geom->JacobianInverseGramian(Eigen::VectorXd::Zero(2));
32
33 // get the gradients
34 const Eigen::MatrixXd grad = J_inv_trans * ref_grads;
35
36 // create whitney 1-Form basis functions only the constants
37 Eigen::MatrixXd bs(grad.rows(), 3);
38 bs.col(0) = grad.col(1) - grad.col(0);
39 bs.col(1) = grad.col(2) - grad.col(1);
40 bs.col(2) = grad.col(0) - grad.col(2);
41
42 // correct for orientation
43 auto edgeOrientations = entity.RelativeOrientations();
44 bs.col(0) *= lf::mesh::to_sign(edgeOrientations[0]);
45 bs.col(1) *= lf::mesh::to_sign(edgeOrientations[1]);
46 bs.col(2) *= lf::mesh::to_sign(edgeOrientations[2]);
47
48 // fill the element matrix
49 Eigen::MatrixXd elem_mat(3, 3);
50 elem_mat = bs.transpose() * grad;
51
52 // correct for integral
53 elem_mat *= lf::geometry::Volume(*geom) / 3.0;
54
55 return elem_mat;
56}
57
58} // 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 nonstd::span< const Orientation > RelativeOrientations() const =0
return span of relative orientations of sub-entities of the next higher co-dimension.
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 some cell of a mesh.
double Volume(const Geometry &geo)
Compute the (approximate) volume (area) of a shape.
int to_sign(Orientation o)
Definition: entity.cc:7
Collection of matrix and vector element providers.
Definition: assemble.h:26