LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
trace_scalar_reference_finite_element.h
1#ifndef PROJECTS_DPG_TRACE_SCALAR_REFERENCE_FINITE_ELEMENT
2#define PROJECTS_DPG_TRACE_SCALAR_REFERENCE_FINITE_ELEMENT
3
13#include <lf/fe/fe.h>
14#include <lf/uscalfe/uscalfe.h>
15
16#include <iostream>
17#include <typeinfo>
18
19#include "dpg.h"
20
21namespace projects::dpg {
22
41template <typename SCALAR>
44 public:
51
53 delete;
55 TraceScalarReferenceFiniteElement&&) noexcept = default;
57 const TraceScalarReferenceFiniteElement&) = delete;
59 TraceScalarReferenceFiniteElement&&) noexcept = default;
60
62 std::shared_ptr<const lf::fe::ScalarReferenceFiniteElement<SCALAR>> cfe)
63 : lf::fe::ScalarReferenceFiniteElement<SCALAR>(), cfe_(std::move(cfe)) {}
64
70 [[nodiscard]] inline bool isInitialized() const { return (cfe_ != nullptr); }
71
72 [[nodiscard]] lf::base::RefEl RefEl() const override {
73 LF_ASSERT_MSG(isInitialized(), "Not initialized!");
74 return cfe_->RefEl();
75 }
76
77 [[nodiscard]] unsigned Degree() const override {
78 LF_ASSERT_MSG(isInitialized(), "Not Initialized");
79 return cfe_->Degree();
80 }
81
82 [[nodiscard]] size_type NumRefShapeFunctions() const override {
83 LF_ASSERT_MSG(isInitialized(), "Not initialized");
84 return cfe_->NumRefShapeFunctions() - cfe_->NumRefShapeFunctions(0);
85 }
86
87 [[nodiscard]] size_type NumRefShapeFunctions(dim_t codim) const override {
88 LF_ASSERT_MSG(isInitialized(), "Not initialized");
89 return (codim == 0) ? 0 : cfe_->NumRefShapeFunctions(codim);
90 }
91
93 dim_t codim, sub_idx_t subidx) const override {
94 LF_ASSERT_MSG(isInitialized(), "Not initialized");
95 return (codim == 0) ? 0 : cfe_->NumRefShapeFunctions(codim, subidx);
96 }
97
98 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
99 EvalReferenceShapeFunctions(const Eigen::MatrixXd& local) const override {
100 LF_ASSERT_MSG(isInitialized(), "Not initialized");
101 return cfe_->EvalReferenceShapeFunctions(local).topRows(
103 }
104
105 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
107 const Eigen::MatrixXd& local) const override {
108 LF_ASSERT_MSG(isInitialized(), "Not initialized");
109 return cfe_->GradientsReferenceShapeFunctions(local).topRows(
111 }
112
113 [[nodiscard]] Eigen::MatrixXd EvaluationNodes() const override {
114 LF_ASSERT_MSG(isInitialized(), "Not initialized");
115 return cfe_->EvaluationNodes().leftCols(NumRefShapeFunctions());
116 }
117
118 [[nodiscard]] lf::fe::size_type NumEvaluationNodes() const override {
119 LF_ASSERT_MSG(isInitialized(), "Not initialized");
120 return cfe_->NumEvaluationNodes() - cfe_->NumRefShapeFunctions(0);
121 }
122
123 [[nodiscard]] Eigen::Matrix<SCALAR, 1, Eigen::Dynamic> NodalValuesToDofs(
124 const Eigen::Matrix<SCALAR, 1, Eigen::Dynamic>& nodvals) const override {
125 LF_ASSERT_MSG(isInitialized(), "Not initialized");
126 LF_ASSERT_MSG(nodvals.cols() == NumEvaluationNodes(),
127 "nodvals = " << nodvals << " <-> " << NumEvaluationNodes());
128
129 // the inner element expects more nodal values, than the trace element
130 // since the internal shape functions were dropped, so
131 // the nodal values are extended by zeroes
132 Eigen::Matrix<SCALAR, 1, Eigen::Dynamic> extendedNodvals(
133 cfe_->NumEvaluationNodes());
134 Eigen::Matrix<SCALAR, 1, Eigen::Dynamic> zeros(cfe_->NumEvaluationNodes() -
136 zeros.setZero();
137 extendedNodvals << nodvals, zeros;
138 return cfe_->NodalValuesToDofs(extendedNodvals)
139 .leftCols(NumRefShapeFunctions());
140 }
141
144
145 private:
147 std::shared_ptr<const lf::fe::ScalarReferenceFiniteElement<SCALAR>> cfe_;
148};
149
150} // namespace projects::dpg
151
152#endif // PROJECTS_DPG_TRACE_SCALAR_REFERENCE_FINITE_ELEMENT
Represents a reference element with all its properties.
Definition: ref_el.h:106
Interface class for parametric scalar valued finite elements.
Decorator class around a ScalarReferenceFiniteElement to represent traces on the cell boundary.
size_type NumRefShapeFunctions(dim_t codim) const override
The number of interior reference shape functions for sub-entities of a particular co-dimension.
TraceScalarReferenceFiniteElement()=default
Default constructor, does not initialize this class (invalid state).
lf::base::RefEl RefEl() const override
Tells the type of reference cell underlying the parametric finite element.
lf::fe::size_type NumEvaluationNodes() const override
Tell the number of evaluation (interpolation) nodes.
size_type NumRefShapeFunctions() const override
Total number of reference shape functions associated with the reference cell.
TraceScalarReferenceFiniteElement(TraceScalarReferenceFiniteElement &&) noexcept=default
Eigen::Matrix< SCALAR, 1, Eigen::Dynamic > NodalValuesToDofs(const Eigen::Matrix< SCALAR, 1, Eigen::Dynamic > &nodvals) const override
Computes the linear combination of reference shape functions matching function values at evaluation n...
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > GradientsReferenceShapeFunctions(const Eigen::MatrixXd &local) const override
Computation of the gradients of all reference shape functions in a number of points.
bool isInitialized() const
Report the initialization status of the object.
unsigned Degree() const override
Request the maximal polynomial degree of the basis functions in this finite element.
TraceScalarReferenceFiniteElement(const TraceScalarReferenceFiniteElement &)=delete
Eigen::MatrixXd EvaluationNodes() const override
Returns reference coordinates of "evaluation nodes" for evaluation of parametric degrees of freedom,...
std::shared_ptr< const lf::fe::ScalarReferenceFiniteElement< SCALAR > > cfe_
size_type NumRefShapeFunctions(dim_t codim, sub_idx_t subidx) const override
The number of interior reference shape functions for every sub-entity.
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > EvalReferenceShapeFunctions(const Eigen::MatrixXd &local) const override
Evaluation of all reference shape functions in a number of points.
lf::assemble::size_type size_type
Definition: fe.h:54
Definition: assemble.h:30
Contains functionality for the implementation of DPG methods.
Definition: primal_dpg.h:33
lf::uscalfe::sub_idx_t sub_idx_t
Type for indexing of sub-entities.
Definition: dpg.h:26
lf::uscalfe::dim_t dim_t
Tpe for (co)-dimensions.
Definition: dpg.h:20
lf::uscalfe::size_type size_type
Type for vector length/matrix sizes.
Definition: dpg.h:17