LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
whitney_zero_hodge_laplacian.h
1#ifndef HLDO_SPHERE_OPERATORS_WHITNEY_ZERO_HODGE_LAPLACE_H
2#define HLDO_SPHERE_OPERATORS_WHITNEY_ZERO_HODEE_LAPLACE_H
3
10#include <laplace_matrix_provider.h>
11#include <lf/assemble/assembler.h>
12#include <lf/assemble/coomatrix.h>
13#include <lf/assemble/dofhandler.h>
14#include <lf/mesh/entity.h>
15#include <lf/mesh/hybrid2d/mesh.h>
16#include <lf/mesh/hybrid2d/mesh_factory.h>
17#include <lf/mesh/mesh_interface.h>
18#include <load_vector_provider.h>
19#include <sphere_triag_mesh_builder.h>
20
21#include <Eigen/Dense>
22#include <cmath>
23#include <iomanip>
24#include <iostream>
25
26namespace projects::hldo_sphere {
27
28namespace operators {
29
44template <typename SCALAR>
46 public:
55 : coo_matrix_(lf::assemble::COOMatrix<SCALAR>(1, 1)) {
56 // create mesh factory for basic mesh
57 std::unique_ptr<lf::mesh::MeshFactory> factory =
58 std::make_unique<lf::mesh::hybrid2d::MeshFactory>(3);
59
60 std::shared_ptr<projects::hldo_sphere::mesh::SphereTriagMeshBuilder>
61 sphere = std::make_shared<
63 std::move(factory));
64 sphere->setRefinementLevel(0);
65 sphere->setRadius(1);
66
67 mesh_p_ = sphere->Build();
68
69 // create basic function
70 auto f = [](Eigen::Matrix<double, 3, 1> x) -> SCALAR { return 0; };
71 f_ = f;
72 }
73
81 void Compute() {
82 // create element matrix provider
84
85 const lf::assemble::DofHandler& dof_handler =
88
89 // create COO Matrix
90 const lf::assemble::size_type n_dofs(dof_handler.NumDofs());
91
92 lf::assemble::COOMatrix<SCALAR> coo_mat(n_dofs, n_dofs);
93 coo_mat.setZero();
94
95 lf::assemble::AssembleMatrixLocally<lf::assemble::COOMatrix<SCALAR>>(
96 0, dof_handler, dof_handler, matrix_provider, coo_mat);
97
98 // create element vector provider
100 f_};
101
102 // create load vector
103 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> phi(n_dofs);
104 phi.setZero();
105
106 // assemble the global vector over entities with codim=0:
107 AssembleVectorLocally(0, dof_handler, vector_provider, phi);
108
109 // set the class attributes
110 phi_ = phi;
111 coo_matrix_ = coo_mat;
112 }
113
122 void SetMesh(std::shared_ptr<const lf::mesh::Mesh> mesh_p) {
123 // check if cells are triagles
124 for (const lf::mesh::Entity* tria : mesh_p->Entities(0)) {
125 LF_ASSERT_MSG(
126 tria->RefEl() == lf::base::RefEl::kTria(),
127 "Mesh must be Triangular, unsupported cell " << tria->RefEl());
128 }
129
130 // check if dimension of the mesh is 3
131 LF_ASSERT_MSG(mesh_p->DimWorld() == 3,
132 "World Dimension must be 3 but is" << mesh_p->DimWorld());
133
134 // set mesh
135 mesh_p_ = mesh_p;
136 }
137
148 std::function<SCALAR(const Eigen::Matrix<double, 3, 1>&)>& f) {
149 f_ = f;
150 }
151
161 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> GetLoadVector() { return phi_; }
162
173
174 private:
175 std::shared_ptr<const lf::mesh::Mesh> mesh_p_;
176 std::function<SCALAR(const Eigen::Matrix<double, 3, 1>&)> f_;
178 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> phi_;
179};
180
181} // namespace operators
182
183} // namespace projects::hldo_sphere
184
185#endif // HLDO_SPHERE_OPERATORS_WHITNEY_ZERO_HODGE_LAPLACE_H
A temporary data structure for matrix in COO format.
Definition: coomatrix.h:52
void setZero()
Erase all entries of the matrix.
Definition: coomatrix.h:98
A general (interface) class for DOF handling, see Lecture Document Paragraph 2.7.4....
Definition: dofhandler.h:109
virtual size_type NumDofs() const =0
total number of dof's handled by the object
Dofhandler for uniform finite element spaces.
Definition: dofhandler.h:257
constexpr RefEl(RefElType type) noexcept
Create a RefEl from a lf::base::RefElType enum.
Definition: ref_el.h:172
static constexpr RefEl kPoint()
Returns the (0-dimensional) reference point.
Definition: ref_el.h:141
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
Element Matrix Provider for the Laplace operator using picewise linear barycentric basis functions.
Element Vector Provider for scalar valued load functions using picewise linear barycentric basis func...
void setRefinementLevel(lf::base::size_type n)
Set the refinement level.
Computes the Galerkin LSE for the Hodge Laplacian of the whitney zero form.
void SetMesh(std::shared_ptr< const lf::mesh::Mesh > mesh_p)
Sets the mesh for later computations.
lf::assemble::COOMatrix< SCALAR > GetGalerkinMatrix()
returns the Galerkin Matrix
std::function< SCALAR(const Eigen::Matrix< double, 3, 1 > &)> f_
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > GetLoadVector()
returns the Loadvector
void SetLoadFunction(std::function< SCALAR(const Eigen::Matrix< double, 3, 1 > &)> &f)
Sets the load function for later computations.
void AssembleVectorLocally(dim_t codim, const DofHandler &dof_handler, ENTITY_VECTOR_PROVIDER &entity_vector_provider, VECTOR &resultvector)
entity-local assembly of (right-hand-side) vectors from element vectors
Definition: assembler.h:297
lf::base::size_type size_type
Definition: assemble.h:30
Implementation of the thesis Hogde Laplacians and Dirac Operators on the surface of the 3-Sphere.
Definition: assemble.h:15