LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
mesh_function_grad_fe.h
1
9#ifndef INCGb6997524e2834b5b8e4bba019fb35cc6
10#define INCGb6997524e2834b5b8e4bba019fb35cc6
11#include "scalar_fe_space.h"
12
13namespace lf::fe {
14
46template <class SCALAR_FE, class SCALAR_COEFF>
48 public:
49 using Scalar = decltype(SCALAR_FE(0) * SCALAR_COEFF(0)); // NOLINT
50
61 MeshFunctionGradFE(std::shared_ptr<const ScalarFESpace<SCALAR_FE>> fe_space,
62 Eigen::Matrix<SCALAR_COEFF, Eigen::Dynamic, 1> dof_vector)
63 : fe_space_(std::move(fe_space)), dof_vector_(std::move(dof_vector)) {}
64
69 [[nodiscard]] std::shared_ptr<const mesh::Mesh> getMesh() const {
70 return fe_space_->Mesh();
71 }
72
79 [[nodiscard]] std::shared_ptr<const ScalarFESpace<SCALAR_FE>> getFESpace()
80 const {
81 return fe_space_;
82 }
83
92 std::vector<Eigen::Matrix<Scalar, Eigen::Dynamic, 1>> operator()(
93 const lf::mesh::Entity& e, const Eigen::MatrixXd& local) const {
94 // Access information on local shape functions for the entity
95 auto grad_sf_eval =
96 fe_space_->ShapeFunctionLayout(e)->GradientsReferenceShapeFunctions(
97 local);
98 // Fetch the coefficients of the global shape functions associated with
99 // the current mesh entity
100 Eigen::Matrix<SCALAR_COEFF, 1, Eigen::Dynamic> local_dofs(
101 1, grad_sf_eval.rows());
102 auto global_dofs = fe_space_->LocGlobMap().GlobalDofIndices(e);
103 for (Eigen::Index i = 0; i < grad_sf_eval.rows(); ++i) {
104 local_dofs(i) = dof_vector_(global_dofs[i]);
105 }
106 // gradients w.r.t. reference element coordinates \hat{x}
107 auto local_grads = (local_dofs * grad_sf_eval).eval();
108 // Transform to Cartesian coordinates
109 auto jac_t = e.Geometry()->JacobianInverseGramian(local);
110 auto dim_local = base::narrow<Eigen::Index>(e.RefEl().Dimension());
111 std::vector<Eigen::Matrix<Scalar, Eigen::Dynamic, 1>> result(local.cols());
112 // Transform all the local gradients in the evaluation points
113 for (Eigen::Index i = 0; i < result.size(); ++i) {
114 result[i] = jac_t.block(0, dim_local * i, jac_t.rows(), dim_local) *
115 local_grads.block(0, i * dim_local, 1, dim_local).transpose();
116 }
117 return result;
118 }
119
120 private:
122 std::shared_ptr<const ScalarFESpace<SCALAR_FE>> fe_space_;
125 Eigen::Matrix<SCALAR_COEFF, Eigen::Dynamic, 1> dof_vector_;
126};
127
128// deduction guide
129template <class T, class SCALAR_COEFF>
130MeshFunctionGradFE(std::shared_ptr<T>,
131 const Eigen::Matrix<SCALAR_COEFF, Eigen::Dynamic, 1>&)
133
134} // namespace lf::fe
135
136#endif // INCGb6997524e2834b5b8e4bba019fb35cc6
constexpr dim_t Dimension() const
Return the dimension of this reference element.
Definition ref_el.h:204
A MeshFunction representing the gradient of a function from a scalar finite element space (e....
std::shared_ptr< const ScalarFESpace< SCALAR_FE > > fe_space_
Pointer to underlying finite element space.
std::shared_ptr< const mesh::Mesh > getMesh() const
Convenience method to retrieve the underlying mesh.
std::shared_ptr< const ScalarFESpace< SCALAR_FE > > getFESpace() const
Convenience method to retrieve the finite element space to which the original function belongs (i....
std::vector< Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > > operator()(const lf::mesh::Entity &e, const Eigen::MatrixXd &local) const
Evaluate the mesh function on a MeshEntity.
Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > dof_vector_
Reference to basis expansion coefficient vector for finite-element function
MeshFunctionGradFE(std::shared_ptr< const ScalarFESpace< SCALAR_FE > > fe_space, Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > dof_vector)
Create a new MeshFunctionGradFE from a ScalarFESpace and a coefficient vector.
decltype(SCALAR_FE(0) *SCALAR_COEFF(0)) Scalar
Space of scalar valued finite element functions on a Mesh.
virtual Eigen::MatrixXd JacobianInverseGramian(const Eigen::MatrixXd &local) const =0
Evaluate the Jacobian * Inverse Gramian ( ) simultaneously at numPoints.
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
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.
Collects data structures and algorithms designed for scalar finite element methods primarily meant fo...
Definition fe.h:47
MeshFunctionGradFE(std::shared_ptr< T >, const Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > &) -> MeshFunctionGradFE< typename T::Scalar, SCALAR_COEFF >