LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
check_child_geometry.cc
1
9#include "check_child_geometry.h"
10
11#include <gtest/gtest.h>
12
14
16 const lf::geometry::Geometry &geom,
18 const std::function<lf::quad::QuadRule(lf::base::RefEl)> &qr_provider) {
19 LF_ASSERT_MSG(geom.RefEl() == ref_pat.RefEl(),
20 "This refinement pattern is not made for a " << geom.RefEl());
21 double h = 1. / ref_pat.LatticeConst();
22
23 for (auto codim = 0; codim <= geom.RefEl().Dimension(); ++codim) {
24 auto children = geom.ChildGeometry(ref_pat, codim);
25 auto child_polygons = ref_pat.ChildPolygons(codim);
26
27 EXPECT_EQ(children.size(), ref_pat.NumChildren(codim));
28
29 for (int i = 0; i < children.size(); ++i) {
30 auto &child = children[i];
31 EXPECT_EQ(child->RefEl().Dimension(), geom.DimLocal() - codim);
32 EXPECT_EQ(child->DimGlobal(), geom.DimGlobal());
33 EXPECT_EQ(child->DimLocal(), geom.DimLocal() - codim);
34
35 if (child->RefEl() == lf::base::RefEl::kPoint()) {
36 // check that child == geom.Global(...)
37 EXPECT_EQ(child_polygons[i].rows(), geom.DimLocal());
38 EXPECT_EQ(child_polygons[i].cols(), 1);
39 auto child_coord = geom.Global(child_polygons[i].cast<double>() * h);
40
41 auto zero = Eigen::Matrix<double, 0, 1>::Zero();
42 EXPECT_TRUE(child_coord.isApprox(child->Global(zero)));
43 } else {
44 // Check that the mapping child is the same as geom \cdot
45 // refinementPattern
46 auto qr = qr_provider(child->RefEl());
47 auto a = child->Global(qr.Points());
48
49 std::unique_ptr<lf::geometry::Geometry> ref_pat_geo = nullptr;
50
51 switch (child->RefEl()) {
53 ref_pat_geo = std::make_unique<lf::geometry::SegmentO1>(
54 child_polygons[i].cast<double>() * h);
55 break;
57 ref_pat_geo = std::make_unique<lf::geometry::TriaO1>(
58 child_polygons[i].cast<double>() * h);
59 break;
61 ref_pat_geo = std::make_unique<lf::geometry::QuadO1>(
62 child_polygons[i].cast<double>() * h);
63 break;
64 default:
65 LF_VERIFY_MSG(
66 false,
67 "This reference element is not yet supported by the test.");
68 }
69
70 auto b = geom.Global(ref_pat_geo->Global(qr.Points()));
71
72 EXPECT_TRUE(a.isApprox(b)) << std::endl
73 << a << "\n is not \n"
74 << b << std::endl;
75 }
76 }
77 }
78}
79
81 const lf::refinement::RefPat &refPat,
82 const lf::base::sub_idx_t &anchor) {
83 // compute volume by means of overkill quadrature
84 auto computeVolume = [](const lf::geometry::Geometry &geom) {
85 const auto qr = lf::quad::make_QuadRule(geom.RefEl(), 23);
86
87 const auto &points = qr.Points();
88 const auto &weights = qr.Weights();
89 const auto &integrationElements = geom.IntegrationElement(points);
90
91 double vol = 0.;
92
93 for (size_t j = 0; j < points.cols(); ++j) {
94 vol += weights(j) * integrationElements(j);
95 }
96
97 return vol;
98 };
99
100 const double volume = computeVolume(geom);
101 double refinedVolume = 0.;
102 auto children = geom.ChildGeometry(
103 lf::refinement::Hybrid2DRefinementPattern(geom.RefEl(), refPat, anchor),
104 0);
105
106 for (auto &childGeom : children) {
107 refinedVolume += computeVolume(*childGeom);
108 }
109
110 switch (refPat) {
112 EXPECT_EQ(refinedVolume, 0.)
113 << refPat << " should not produce any children";
114 break;
115 default:
116 EXPECT_FLOAT_EQ(volume, refinedVolume)
117 << "Parent and children volumes differ for " << refPat;
118 }
119}
120
121} // namespace lf::geometry::test_utils
Represents a reference element with all its properties.
Definition ref_el.h:109
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
Definition ref_el.h:153
static constexpr RefEl kPoint()
Returns the (0-dimensional) reference point.
Definition ref_el.h:144
static constexpr RefEl kTria()
Returns the reference triangle.
Definition ref_el.h:161
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
Definition ref_el.h:169
Interface class for shape information on a mesh cell in the spirit of parametric finite element metho...
virtual base::RefEl RefEl() const =0
The Reference element that defines the domain of this mapping.
virtual std::vector< std::unique_ptr< Geometry > > ChildGeometry(const RefinementPattern &ref_pat, lf::base::dim_t codim) const =0
Generate geometry objects for child entities created in the course of refinement.
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
virtual dim_t DimLocal() const =0
Dimension of the domain of this mapping.
virtual dim_t DimGlobal() const =0
Dimension of the image of this mapping.
virtual Eigen::VectorXd IntegrationElement(const Eigen::MatrixXd &local) const =0
The integration element (factor appearing in integral transformation formula, see below) at number of...
Abstract interface class for encoding topological local refinement
lf::base::size_type LatticeConst() const
Provides information about lattice constant used.
virtual lf::base::size_type NumChildren(lf::base::dim_t codim) const =0
provide number of child entities of a given co-dimension to be created by refinement
virtual std::vector< Eigen::Matrix< int, Eigen::Dynamic, Eigen::Dynamic > > ChildPolygons(lf::base::dim_t codim) const =0
provide lattice reference coordinates of vertices of child polygons
lf::base::RefEl RefEl() const
Returns topological type of entity for which the current object is set up.
Represents a Quadrature Rule over one of the Reference Elements.
Definition quad_rule.h:58
Class containing information about the refinement of a cell.
unsigned int sub_idx_t
type for local indices of sub-entities
Definition types.h:28
Defines the Geometry::test_utils module and provides a number of test functions to check geometry obj...
void checkChildGeometry(const lf::geometry::Geometry &geom, const lf::geometry::RefinementPattern &ref_pat, const std::function< lf::quad::QuadRule(lf::base::RefEl)> &qr_provider)
Checks that the mapping geom.ChildGeometry() is the same as geom composed with the mapping imposed by...
void checkChildGeometryVolume(const lf::geometry::Geometry &geom, const lf::refinement::RefPat &refPat, const lf::base::sub_idx_t &anchor)
Checks if the total volume is conserved after call to ChildGeometry()
QuadRule make_QuadRule(base::RefEl ref_el, unsigned degree)
Returns a QuadRule object for the given Reference Element and Degree.
RefPat
(possibly incomplete) list of refinement patterns for triangles/quadrilaterals