LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
mesh_function_fe.h
1
9
10#ifndef INCG4ee2d6e8004446558bc6d2186596e392
11#define INCG4ee2d6e8004446558bc6d2186596e392
12
13#include <memory>
14
15#include "scalar_fe_space.h"
16
17namespace lf::fe {
18
43template <class SCALAR_FE, class SCALAR_COEFF>
45 public:
46 // Why this? Because we can use real-valued finite element spaces to represent
47 // complex-valued functions by using complex degrees of freedom!
48 using Scalar = decltype(SCALAR_FE(0) * SCALAR_COEFF(0)); // NOLINT
49
61 MeshFunctionFE(std::shared_ptr<const ScalarFESpace<SCALAR_FE>> fe_space,
62 Eigen::Matrix<SCALAR_COEFF, Eigen::Dynamic, 1> coeff_vector)
63 : fe_space_(std::move(fe_space)), dof_vector_(std::move(coeff_vector)) {}
64
72 std::vector<Scalar> operator()(const lf::mesh::Entity& e,
73 const Eigen::MatrixXd& local) const {
74 // Obtain values of all shape functions in the evaluation points
75 auto sf_eval =
76 fe_space_->ShapeFunctionLayout(e)->EvalReferenceShapeFunctions(local);
77 // Extract the d.o.f.s for the current entity from the vector of global
78 // d.o.f. values
79 Eigen::Matrix<SCALAR_COEFF, 1, Eigen::Dynamic> local_dofs(1,
80 sf_eval.rows());
81 auto global_dofs = fe_space_->LocGlobMap().GlobalDofIndices(e);
82 for (Eigen::Index i = 0; i < sf_eval.rows(); ++i) {
83 local_dofs(i) = dof_vector_(global_dofs[i]);
84 }
85 // Trick to combine Eigen data types with STL containers
86 std::vector<Scalar> result(local.cols());
87 Eigen::Map<Eigen::Matrix<Scalar, 1, Eigen::Dynamic>> temp(result.data(), 1,
88 local.cols());
89 temp = local_dofs * sf_eval;
90 return result;
91 }
92
97 [[nodiscard]] std::shared_ptr<const mesh::Mesh> getMesh() const {
98 return fe_space_->Mesh();
99 }
100
107 [[nodiscard]] std::shared_ptr<const ScalarFESpace<SCALAR_FE>> getFESpace()
108 const {
109 return fe_space_;
110 }
111
112 private:
113 std::shared_ptr<const ScalarFESpace<SCALAR_FE>> fe_space_;
114 Eigen::Matrix<SCALAR_COEFF, Eigen::Dynamic, 1> dof_vector_;
115};
116
117// deduction guide
118template <class T, class SCALAR_COEFF>
119MeshFunctionFE(std::shared_ptr<T>,
120 const Eigen::Matrix<SCALAR_COEFF, Eigen::Dynamic, 1>&)
122
123} // namespace lf::fe
124
125#endif // INCG4ee2d6e8004446558bc6d2186596e392
A MeshFunction representing an element from a ScalarFESpace (e.g. solution of BVP)
std::shared_ptr< const ScalarFESpace< SCALAR_FE > > getFESpace() const
Convenience method to retrieve the finite element space in which the mesh function lives.
Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > dof_vector_
std::shared_ptr< const mesh::Mesh > getMesh() const
Convenience method to retrieve the underlying mesh.
decltype(SCALAR_FE(0) *SCALAR_COEFF(0)) Scalar
MeshFunctionFE(std::shared_ptr< const ScalarFESpace< SCALAR_FE > > fe_space, Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > coeff_vector)
Create a new MeshFunctionFE from a ScalarFESpace and a coefficient vector.
std::shared_ptr< const ScalarFESpace< SCALAR_FE > > fe_space_
std::vector< Scalar > operator()(const lf::mesh::Entity &e, const Eigen::MatrixXd &local) const
Evaluate the mesh function on a MeshEntity.
Space of scalar valued finite element functions on a Mesh.
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
Collects data structures and algorithms designed for scalar finite element methods primarily meant fo...
Definition fe.h:47
MeshFunctionFE(std::shared_ptr< T >, const Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > &) -> MeshFunctionFE< typename T::Scalar, SCALAR_COEFF >