LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
discontinuous_fe_constant.h
1
9#ifndef PROJECTS_DPG_DISCONTINUOUS_FE_CONSTANT_H
10#define PROJECTS_DPG_DISCONTINUOUS_FE_CONSTANT_H
11
12#include <lf/fe/fe.h>
13#include <lf/uscalfe/uscalfe.h>
14
15#include <typeinfo>
16
17#include "dpg.h"
18
19namespace projects::dpg {
20
32template <typename SCALAR>
35 public:
38 FeDiscontinuousO0Tria& operator=(const FeDiscontinuousO0Tria&) = default;
39 FeDiscontinuousO0Tria& operator=(FeDiscontinuousO0Tria&&) noexcept = default;
41 ~FeDiscontinuousO0Tria() override = default;
42
43 [[nodiscard]] lf::base::RefEl RefEl() const override {
45 }
46
47 [[nodiscard]] unsigned Degree() const override { return 0; }
48
52 [[nodiscard]] size_type NumRefShapeFunctions() const override { return 1; }
53
56 [[nodiscard]] size_type NumRefShapeFunctions(dim_t codim) const override {
57 LF_ASSERT_MSG(codim <= 2, "Illegal codim" << codim);
58 return (codim == 0) ? 1 : 0;
59 }
63 dim_t codim, sub_idx_t /*subidx*/) const override {
64 LF_ASSERT_MSG(codim <= 2, "Illegal codim" << codim);
65 return (codim == 0) ? 1 : 0;
66 }
67
68 // clang-format off
70 // clang-format on
71 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
72 EvalReferenceShapeFunctions(const Eigen::MatrixXd& refcoords) const override {
73 LF_ASSERT_MSG(refcoords.rows() == 2,
74 "Reference coordinates must be 2-vectors");
75 const size_type n_pts(refcoords.cols());
76 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> result(1, n_pts);
77 result.row(0) = Eigen::RowVectorXd::Constant(n_pts, 1);
78 return result;
79 }
80
81 // clang-format off
83 // clang-format on
84 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
86 const Eigen::MatrixXd& refcoords) const override {
87 LF_ASSERT_MSG(refcoords.rows() == 2,
88 "Reference coordinates must be 2-vectors");
89
90 const size_type n_pts(refcoords.cols());
91 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> result(1, 2 * n_pts);
92 result.row(0) = Eigen::RowVectorXd::Constant(2 * n_pts, 0);
93 return result;
94 }
95
99 [[nodiscard]] Eigen::MatrixXd EvaluationNodes() const override {
100 Eigen::MatrixXd nodes(2, 1);
101 nodes << 1.0 / 3.0, 1.0 / 3.0;
102 return nodes;
103 }
104
108 [[nodiscard]] size_type NumEvaluationNodes() const override {
109 return NumRefShapeFunctions();
110 }
111};
112
124template <typename SCALAR>
126 : public lf::fe::ScalarReferenceFiniteElement<SCALAR> {
127 public:
130 FeDiscontinuousO0Quad& operator=(const FeDiscontinuousO0Quad&) = default;
131 FeDiscontinuousO0Quad& operator=(FeDiscontinuousO0Quad&&) noexcept = default;
133 ~FeDiscontinuousO0Quad() override = default;
134
135 [[nodiscard]] lf::base::RefEl RefEl() const override {
136 return lf::base::RefEl::kQuad();
137 }
138
139 [[nodiscard]] unsigned Degree() const override { return 0; }
140
143 [[nodiscard]] size_type NumRefShapeFunctions() const override { return 1; }
144
147 [[nodiscard]] size_type NumRefShapeFunctions(dim_t codim) const override {
148 LF_ASSERT_MSG(codim <= 2, "Illegal codim" << codim);
149 return (codim == 0) ? 1 : 0;
150 }
154 dim_t codim, sub_idx_t /*subidx*/) const override {
155 LF_ASSERT_MSG(codim <= 2, "Illegal codim" << codim);
156 return (codim == 0) ? 1 : 0;
157 }
158
159 // clang-format off
161 // clang-format on
162 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
163 EvalReferenceShapeFunctions(const Eigen::MatrixXd& refcoords) const override {
164 LF_ASSERT_MSG(refcoords.rows() == 2,
165 "Reference coordinates must be 2-vectors");
166 const size_type n_pts(refcoords.cols());
167 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> result(1, n_pts);
168 result.row(0) = Eigen::RowVectorXd::Constant(n_pts, 1);
169 return result;
170 }
171
172 // clang-format off
174 // clang-format on
175 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
177 const Eigen::MatrixXd& refcoords) const override {
178 LF_ASSERT_MSG(refcoords.rows() == 2,
179 "Reference coordinates must be 2-vectors");
180
181 const size_type n_pts(refcoords.cols());
182 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> result(1, 2 * n_pts);
183 result.row(0) = Eigen::RowVectorXd::Constant(2 * n_pts, 0);
184 return result;
185 }
186
190 [[nodiscard]] Eigen::MatrixXd EvaluationNodes() const override {
191 Eigen::MatrixXd nodes(2, 1);
192 nodes << 0.5, 0.5;
193 return nodes;
194 }
198 [[nodiscard]] size_type NumEvaluationNodes() const override {
199 return NumRefShapeFunctions();
200 }
201};
202
213template <typename SCALAR>
215 : public lf::fe::ScalarReferenceFiniteElement<SCALAR> {
216 public:
220 default;
222 default;
224 ~FeDiscontinuousO0Segment() override = default;
225
226 [[nodiscard]] lf::base::RefEl RefEl() const override {
228 }
229
230 [[nodiscard]] unsigned Degree() const override { return 0; }
231
234 [[nodiscard]] size_type NumRefShapeFunctions() const override { return 1; }
235
238 [[nodiscard]] size_type NumRefShapeFunctions(dim_t codim) const override {
239 LF_ASSERT_MSG(codim <= 2, "Illegal codim" << codim);
240 return (codim == 0) ? 1 : 0;
241 }
245 dim_t codim, sub_idx_t /*subidx*/) const override {
246 LF_ASSERT_MSG(codim <= 2, "Illegal codim" << codim);
247 return (codim == 0) ? 1 : 0;
248 }
249
250 // clang-format off
252 // clang-format on
253 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
254 EvalReferenceShapeFunctions(const Eigen::MatrixXd& refcoords) const override {
255 LF_ASSERT_MSG(refcoords.rows() == 1,
256 "Reference coordinates must be 1-vectors");
257 const size_type n_pts(refcoords.cols());
258 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> result(1, n_pts);
259 result.row(0) = Eigen::RowVectorXd::Constant(n_pts, 1);
260 return result;
261 }
262
263 // clang-format off
265 // clang-format on
266 [[nodiscard]] Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>
268 const Eigen::MatrixXd& refcoords) const override {
269 LF_ASSERT_MSG(refcoords.rows() == 1,
270 "Reference coordinates must be 1-vectors");
271
272 const size_type n_pts(refcoords.cols());
273 Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> result(1, n_pts);
274 result.row(0) = Eigen::RowVectorXd::Constant(n_pts, 0);
275 return result;
276 }
277
282 [[nodiscard]] Eigen::MatrixXd EvaluationNodes() const override {
283 Eigen::MatrixXd nodes(1, 1);
284 nodes << 0.5;
285 return nodes;
286 }
290 [[nodiscard]] size_type NumEvaluationNodes() const override {
291 return NumRefShapeFunctions();
292 }
293};
294
295} // namespace projects::dpg
296
297#endif // PROJECTS_DPG_DISCONTINUOUS_FE_CONSTANT_H
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
Definition: ref_el.h:150
static constexpr RefEl kTria()
Returns the reference triangle.
Definition: ref_el.h:158
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
Definition: ref_el.h:166
Interface class for parametric scalar valued finite elements.
Discontinuous constant finite element on a quadrilateral reference element.
size_type NumRefShapeFunctions(dim_t codim, sub_idx_t) const override
FeDiscontinuousO0Quad(FeDiscontinuousO0Quad &&) noexcept=default
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.
size_type NumEvaluationNodes() const override
Only one evaluation node.
size_type NumRefShapeFunctions(dim_t codim) const override
FeDiscontinuousO0Quad(const FeDiscontinuousO0Quad &)=default
size_type NumRefShapeFunctions() const override
Total number of reference shape functions associated with the reference cell.
lf::base::RefEl RefEl() const override
Tells the type of reference cell underlying the parametric finite element.
Eigen::MatrixXd EvaluationNodes() const override
Only evaluation node is the center of the reference quadrilateral.
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > EvalReferenceShapeFunctions(const Eigen::MatrixXd &refcoords) const override
Evaluation of all reference shape functions in a number of points.
unsigned Degree() const override
Request the maximal polynomial degree of the basis functions in this finite element.
Discontinuous constant finite element on a line segment.
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > EvalReferenceShapeFunctions(const Eigen::MatrixXd &refcoords) const override
Evaluation of all reference shape functions in a number of points.
FeDiscontinuousO0Segment(const FeDiscontinuousO0Segment &)=default
size_type NumRefShapeFunctions() const override
Total number of reference shape functions associated with the reference cell.
FeDiscontinuousO0Segment(FeDiscontinuousO0Segment &&) noexcept=default
size_type NumEvaluationNodes() const override
Only one evaluation node.
size_type NumRefShapeFunctions(dim_t codim, sub_idx_t) const override
Eigen::MatrixXd EvaluationNodes() const override
The only evaluation node is the center of the reference line segment.
unsigned Degree() const override
Request the maximal polynomial degree of the basis functions in this finite element.
lf::base::RefEl RefEl() const override
Tells the type of reference cell underlying the parametric finite element.
size_type NumRefShapeFunctions(dim_t codim) const override
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.
Discontinuous constant finite element on a triangular reference element.
size_type NumRefShapeFunctions(dim_t codim) const override
Eigen::MatrixXd EvaluationNodes() const override
Only evaluation node is the barycenter of the reference triangle.
size_type NumRefShapeFunctions(dim_t codim, sub_idx_t) const override
size_type NumRefShapeFunctions() const override
Total number of reference shape functions associated with the reference cell.
unsigned Degree() const override
Request the maximal polynomial degree of the basis functions in this finite element.
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > EvalReferenceShapeFunctions(const Eigen::MatrixXd &refcoords) const override
Evaluation of all reference shape functions in a number of points.
size_type NumEvaluationNodes() const override
One evaluation node.
FeDiscontinuousO0Tria(FeDiscontinuousO0Tria &&) noexcept=default
lf::base::RefEl RefEl() const override
Tells the type of reference cell underlying the parametric finite element.
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.
FeDiscontinuousO0Tria(const FeDiscontinuousO0Tria &)=default
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