LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
triangle.cc
1
9#include "triangle.h"
10
11#include "point.h"
12#include "segment.h"
13
14namespace lf::mesh::hybrid2d {
15
17 std::unique_ptr<geometry::Geometry>&& geometry,
18 const Point* corner0, const Point* corner1,
19 const Point* corner2, const Segment* edge0,
20 const Segment* edge1, const Segment* edge2)
21 : index_(index),
22 geometry_(std::move(geometry)),
23 nodes_({corner0, corner1, corner2}),
24 edges_({edge0, edge1, edge2}),
25 edge_ori_(),
26 this_(this) {
27 LF_VERIFY_MSG(corner0 != nullptr, "Invalid pointer to corner 0");
28 LF_VERIFY_MSG(corner1 != nullptr, "Invalid pointer to corner 1");
29 LF_VERIFY_MSG(corner2 != nullptr, "Invalid pointer to corner 2");
30 LF_VERIFY_MSG(edge0 != nullptr, "Invalid pointer to edge 0");
31 LF_VERIFY_MSG(edge1 != nullptr, "Invalid pointer to edge 1");
32 LF_VERIFY_MSG(edge2 != nullptr, "Invalid pointer to edge 2");
33 if (geometry_) {
34 LF_VERIFY_MSG(geometry_->DimLocal() == 2,
35 "Geometry must describe a 2D cell");
36 LF_VERIFY_MSG(geometry_->RefEl() == base::RefEl::kTria(),
37 "Cell geometry must fit a triangle");
38 }
39
40 // Consistency check: make sure that sub-entities of sub-entities
41 // agree with sub-sub-entities
42
44 // Run through all edges
45 for (int ed_loc_idx = 0; ed_loc_idx < 3; ed_loc_idx++) {
46 // Pointer to current edge
47 const Segment* ed_ptr = edges_.at(ed_loc_idx);
48 // Check for segement type
49 LF_VERIFY_MSG(ed_ptr->RefEl() == lf::base::RefEl::kSegment(),
50 "Wrong type for edge " << ed_loc_idx);
51 // Fetch nodes from current edge
52 auto ed_nodes = ed_ptr->SubEntities(1);
53
54 // Obtain local indices of endpoints of edge
55 const size_type loc_idx_p0 =
56 ref_el_tria.SubSubEntity2SubEntity(1, ed_loc_idx, 1, 0);
57 const size_type loc_idx_p1 =
58 ref_el_tria.SubSubEntity2SubEntity(1, ed_loc_idx, 1, 1);
59 const Point* p0_ptr = nodes_.at(loc_idx_p0);
60 const Point* p1_ptr = nodes_.at(loc_idx_p1);
61
62 // Verify that the nodes of the triangle are nodes of the edge as well
63 LF_VERIFY_MSG((ed_nodes[0] == p0_ptr) || (ed_nodes[0] == p1_ptr),
64 "Node 0 of edge " << ed_loc_idx << " not a triangle node");
65 LF_VERIFY_MSG((ed_nodes[1] == p0_ptr) || (ed_nodes[1] == p1_ptr),
66 "Node 1 of edge " << ed_loc_idx << " not a triangle node");
67 }
68
69 // Finally set relative orientations for the edges. Edge i has positive
70 // orientation, if its first node agrees with vertex i
71 for (int ed_loc_idx = 0; ed_loc_idx < 3; ed_loc_idx++) {
72 // Fetch nodes of current edge
73 auto ed_nodes = edges_[ed_loc_idx]->SubEntities(1);
74 edge_ori_[ed_loc_idx] = (ed_nodes[0] == nodes_[ed_loc_idx])
76 : lf::mesh::Orientation::negative;
77 }
78}
79
80// Acessing sub-entities
81std::span<const Entity* const> Triangle::SubEntities(unsigned rel_codim) const {
82 auto l = [&](auto i) -> const mesh::Entity& { return **i; };
83 switch (rel_codim) {
84 case 2:
85 return {reinterpret_cast<const Entity* const*>(nodes_.data()), 3};
86 case 1:
87 return {reinterpret_cast<const Entity* const*>(edges_.data()), 3};
88 case 0:
89 return {&this_, 1};
90 default:
91 LF_VERIFY_MSG(false, "Triangle: rel_codim out of range");
92 }
93}
94} // namespace lf::mesh::hybrid2d
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 kTria()
Returns the reference triangle.
Definition ref_el.h:161
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
A node object for a 2D hybrid mesh.
Definition point.h:28
An edge object for a 2D hybrid mesh.
Definition segment.h:29
std::array< const Point *, 3 > nodes_
Definition triangle.h:111
mesh::Mesh::size_type size_type
Definition triangle.h:29
std::span< const Entity *const > SubEntities(unsigned rel_codim) const override
Access to all subentities selected by relative co-dimension.
Definition triangle.cc:81
Triangle()=default
default constructors, needed by std::vector
std::array< const Segment *, 3 > edges_
Definition triangle.h:112
@ kTria
Returns the reference triangle.
An alternative implementation of a hybrid2d mesh manager that uses Pointers to store sub-entity relat...
Definition hybrid2d.h:11
Orientation
Relative orientation of a sub-entity.
Definition entity.h:22
Definition assemble.h:31