LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
segment_o1.cc
1#include "segment_o1.h"
2
3#include "point.h"
4
5namespace lf::geometry {
6
7Eigen::MatrixXd SegmentO1::Global(const Eigen::MatrixXd& local) const {
8 return coords_.col(1) * local + coords_.col(0) * (1 - local.array()).matrix();
9}
10
11Eigen::MatrixXd SegmentO1::Jacobian(const Eigen::MatrixXd& local) const {
12 return (coords_.col(1) - coords_.col(0)).replicate(1, local.cols());
13}
14
16 const Eigen::MatrixXd& local) const {
17 if (DimGlobal() == 1) {
18 return (coords_.col(1) - coords_.col(0))
19 .cwiseInverse()
20 .replicate(1, local.cols());
21 }
22 return ((coords_.col(1) - coords_.col(0)) /
23 (coords_.col(1) - coords_.col(0)).squaredNorm())
24 .replicate(1, local.cols());
25}
26
28 const Eigen::MatrixXd& local) const {
29 return Eigen::VectorXd::Constant(local.cols(),
30 (coords_.col(1) - coords_.col(0)).norm());
31}
32
33std::unique_ptr<Geometry> SegmentO1::SubGeometry(dim_t codim, dim_t i) const {
34 if (codim == 0) {
35 LF_ASSERT_MSG(i == 0, "i is out of bounds.");
36 return std::make_unique<SegmentO1>(coords_);
37 }
38 if (codim == 1) {
39 LF_ASSERT_MSG(i >= 0 && i < 2, "i is out of bounds.");
40 return std::make_unique<Point>(coords_.col(i));
41 }
42 LF_VERIFY_MSG(false, "codim is out of bounds.");
43}
44
45std::vector<std::unique_ptr<Geometry>> SegmentO1::ChildGeometry(
46 const RefinementPattern& ref_pat, base::dim_t codim) const {
47 // The refinement pattern must be for a segment
48 LF_VERIFY_MSG(ref_pat.RefEl() == lf::base::RefEl::kSegment(),
49 "Refinement pattern for " << ref_pat.RefEl().ToString());
50 LF_VERIFY_MSG((codim < 2), "Illegal codim = " << codim);
51
52 // Lattice meshwidth
53 const double h_lattice = 1.0 / static_cast<double>(ref_pat.LatticeConst());
54 // Return variable
55 std::vector<std::unique_ptr<Geometry>> child_geo_uptrs{};
56
57 // Obtain geometry of children as vector of pairs of lattice coordinates
58 std::vector<Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic>>
59 child_polygons(ref_pat.ChildPolygons(codim));
60 // Number of child entities
61 const int no_children = base::narrow<int>(child_polygons.size());
62 LF_VERIFY_MSG(
63 no_children == ref_pat.NumChildren(codim),
64 "no_children = " << no_children << " <-> " << ref_pat.NumChildren(codim));
65 // For each child create a geometry object and a unique pointer to it.
66 for (int i = 0; i < no_children; i++) {
67 // codim == 0:A single child must be described by an interval, that is
68 // two different lattice coordinates
69 // codim == 1: a point's location is just one number
70 LF_VERIFY_MSG(child_polygons[i].rows() == 1,
71 "child_polygons[l].rows() = " << child_polygons[i].rows());
72 LF_VERIFY_MSG(child_polygons[i].cols() == (2 - codim),
73 "child_polygons[l].cols() = " << child_polygons[i].cols());
74 // Normalize lattice coordinates
75 const Eigen::MatrixXd child_geo(
76 Global(h_lattice * child_polygons[i].cast<double>()));
77
78 switch (codim) {
79 case 0: {
80 child_geo_uptrs.push_back(std::make_unique<SegmentO1>(child_geo));
81 break;
82 }
83 case 1: {
84 child_geo_uptrs.push_back(std::make_unique<Point>(child_geo));
85 break;
86 }
87 default:
88 LF_VERIFY_MSG(false, "codim out of bounds.");
89 } // end switch codim
90 } // end loop over child entities
91 return child_geo_uptrs;
92}
93
94} // namespace lf::geometry
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
Definition ref_el.h:153
std::string ToString() const
Return a string representation of this Reference element.
Definition ref_el.h:458
base::RefEl::dim_t dim_t
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.
Eigen::MatrixXd Jacobian(const Eigen::MatrixXd &local) const override
Evaluate the jacobian of the mapping simultaneously at numPoints points.
Definition segment_o1.cc:11
Eigen::MatrixXd JacobianInverseGramian(const Eigen::MatrixXd &local) const override
Evaluate the Jacobian * Inverse Gramian ( ) simultaneously at numPoints.
Definition segment_o1.cc:15
std::unique_ptr< Geometry > SubGeometry(dim_t codim, dim_t i) const override
Construct a new Geometry() object that describes the geometry of the i-th sub-entity with codimension...
Definition segment_o1.cc:33
Eigen::VectorXd IntegrationElement(const Eigen::MatrixXd &local) const override
The integration element (factor appearing in integral transformation formula, see below) at number of...
Definition segment_o1.cc:27
Eigen::Matrix< double, Eigen::Dynamic, 2 > coords_
Definition segment_o1.h:35
dim_t DimGlobal() const override
Dimension of the image of this mapping.
Definition segment_o1.h:17
Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const override
Map a number of points in local coordinates into the global coordinate system.
Definition segment_o1.cc:7
std::vector< std::unique_ptr< Geometry > > ChildGeometry(const RefinementPattern &ref_pat, base::dim_t codim) const override
Generate geometry objects for child entities created in the course of refinement.
Definition segment_o1.cc:45
unsigned int dim_t
type for dimensions and co-dimensions and numbers derived from them
Definition types.h:32
Defines the Geometry interface and provides a number of classes that implement this interface + addit...
Definition compose.h:13