LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
piecewise_const_element_vector_provider.cc
1#include "piecewise_const_element_vector_provider.h"
2
3#include <lf/base/base.h>
4#include <lf/uscalfe/lagr_fe.h>
5#include <utils.h>
6
7#include <iostream>
8
10
12 double sigma, std::function<Eigen::Vector2d(const Eigen::Vector2d &)> f,
13 lf::quad::QuadRule quadrule,
16 : sigma_(sigma),
17 f_(std::move(f)),
18 quadrule_(std::move(quadrule)),
19 boundary_(boundary),
20 dirichlet_data_(dirichlet_data) {}
21
23 const lf::mesh::Entity &entity) const {
24 const auto *const geom = entity.Geometry();
25 // Construct the basis functions from the curl of the standard hat functions
27 const Eigen::MatrixXd ref_grads =
28 hat_func.GradientsReferenceShapeFunctions(Eigen::VectorXd::Zero(2))
29 .transpose();
30 const Eigen::MatrixXd J_inv_trans =
31 geom->JacobianInverseGramian(Eigen::VectorXd::Zero(2));
32 const Eigen::MatrixXd grads = J_inv_trans * ref_grads;
33 Eigen::MatrixXd basis_funct(2, 3);
34 basis_funct << grads.row(1), -grads.row(0);
35 // Compute the elements of the vector via the given quadrature rule
36 Eigen::VectorXd element_vector = Eigen::VectorXd::Zero(6);
37 const Eigen::MatrixXd points = geom->Global(quadrule_.Points());
38 const Eigen::VectorXd weights =
39 (geom->IntegrationElement(quadrule_.Points()).array() *
40 quadrule_.Weights().array())
41 .matrix();
42 for (lf::base::size_type n = 0; n < quadrule_.NumPoints(); ++n) {
43 const auto f_eval = f_(points.col(n));
44 element_vector.head(3) += basis_funct.transpose() * weights[n] * f_eval;
45 }
46 // Weakly impose the dirichlet boundary conditions
47 Eigen::MatrixXd vertices = geom->Global(entity.RefEl().NodeCoords());
48 // Use the vertex coordinates to compute the local normals on the edges
49 const Eigen::Matrix<double, 2, 3> normals =
51 // Iterate over all edges of the current entity and set the boundary
52 // conditions where necessary
53 const auto edges = entity.SubEntities(1);
54 for (int edge_idx = 0; edge_idx < 3; ++edge_idx) {
55 const auto &edge = *edges[edge_idx];
56 if (boundary_(edge)) {
57 Eigen::Vector2d t;
58 t << -normals(1, edge_idx), normals(0, edge_idx);
59 element_vector[edge_idx + 3] = dirichlet_data_(edge).transpose() * t;
60 }
61 }
62 return element_vector;
63}
64
65} // end namespace projects::ipdg_stokes::assemble
const Eigen::MatrixXd & NodeCoords() const
Get the coordinates of the nodes of this reference element.
Definition: ref_el.h:238
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 Entity *const > SubEntities(unsigned rel_codim) const =0
Return all sub entities of this entity that have the given codimension (w.r.t. 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
const Eigen::VectorXd & Weights() const
All quadrature weights as a vector.
Definition: quad_rule.h:152
const Eigen::MatrixXd & Points() const
All quadrature points as column vectors.
Definition: quad_rule.h:145
base::size_type NumPoints() const
Return the total number of quadrature points (num of columns of points/weights)
Definition: quad_rule.h:158
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::VectorXd Eval(const lf::mesh::Entity &entity) const
Compute the element vector for some entity of the mesh.
PiecewiseConstElementVectorProvider(double sigma, std::function< Eigen::Vector2d(const Eigen::Vector2d &)> f, lf::quad::QuadRule quadrule, const lf::mesh::utils::MeshDataSet< bool > &boundary, const lf::mesh::utils::MeshDataSet< Eigen::Vector2d > &dirichlet_data)
Constructor.
unsigned int size_type
general type for variables related to size of arrays
Definition: base.h:24
Eigen::Matrix< double, 2, 3 > computeOutwardNormals(const lf::mesh::Entity &entity)
Compute the outward pointing normals of a triangle.
Definition: utils.cc:7