18#include "libmesh/cell_polyhedron.h"
21#include "libmesh/face_polygon.h"
22#include "libmesh/enum_elem_quality.h"
23#include "libmesh/hashword.h"
28#include <unordered_map>
29#include <unordered_set>
45 Cell( 0, sides.size(), p, nullptr, nullptr),
46 _elemlinks_data(sides.size()+2),
48 _sidelinks_data(sides.size())
55 std::unordered_map<Node *, unsigned int> local_node_number;
56 std::unordered_set<std::pair<const Node *, const Node *>,
58 std::unique_ptr<const Elem> edge;
63 std::get<0>(side_tuple) = sides[s];
69 if (
auto it = local_node_number.find(node);
70 it != local_node_number.end())
72 std::get<2>(side_tuple).push_back(it->second);
76 std::get<2>(side_tuple).push_back(nn);
77 local_node_number[node] = nn++;
85 auto edge_vertices = std::make_pair(edge->node_ptr(0), edge->node_ptr(1));
86 if (edge_vertices.first > edge_vertices.second)
87 std::swap(edge_vertices.first, edge_vertices.second);
89 if (!edges_seen.count(edge_vertices))
91 edges_seen.insert(edge_vertices);
108 libmesh_assert_equal_to(nn, this->
n_nodes());
116 center.
add (this->point(n));
117 center /=
static_cast<Real>(nn);
121 const Polygon & side = *sides[s];
128 inward_normal = (n_i * (center - x_i) >
TOLERANCE);
136 const Polygon & side = *sides[s];
143 (inward_normal ? -1 : 1);
147 const Point d_n = node - x_i;
149 libmesh_not_implemented_msg
150 (
"Cannot create a non-convex polyhedron");
164#ifdef LIBMESH_ENABLE_AMR
177 return this->
point(i);
193 (inward_normal ? -1 : 1);
197 const Point d_n = node - x_i;
208 const Real eps)
const
210 const unsigned int ns = this->
n_sides();
231 (inward_normal ? -1 : 1);
238 const Point d_j = x_j - x_i;
239 if (std::abs(d_j * n_i) > eps * d_j.
norm())
240 libmesh_not_implemented_msg
241 (
"Polyhedra with non-flat sides are not fully supported.");
245 if (n_i * (p - x_i) > eps)
256 libmesh_assert_less (s, this->
n_sides());
267 libmesh_assert_less (s, this->
n_sides());
272 std::vector<dof_id_type> vertex_ids(nv);
274 vertex_ids[v] = face.
node_id(v);
284 std::sort(vertex_ids.begin(), vertex_ids.end());
292 unsigned int side_node)
const
294 libmesh_assert_less (side, this->
n_sides());
296 const std::vector<unsigned int> & node_map =
298 libmesh_assert_less (side_node, node_map.size());
300 return node_map[side_node];
306 unsigned int edge_node)
const
308 libmesh_assert_less (edge, this->
n_edges());
315 const std::vector<unsigned int> & node_map =
325 std::vector<dof_id_type> node_ids;
327 node_ids.push_back(n.id());
343 libmesh_assert_less (i, this->
n_sides());
348 face_copy->set_node(n, face.
node_ptr(n));
356 const unsigned int i)
358 libmesh_assert_less (i, this->
n_sides());
370 returnval->set_interior_parent(
this);
371 returnval->inherit_data_from(*
this);
378 const unsigned int i)
381 side->set_interior_parent(
this);
382 side->inherit_data_from(*
this);
397 const unsigned int i)
407 const unsigned int )
const
409 libmesh_not_implemented();
418 libmesh_not_implemented();
425 const unsigned int )
const
428 libmesh_not_implemented();
449std::vector<unsigned int>
452 libmesh_assert_less(n, this->
n_nodes());
460 std::vector<unsigned int> adjacent_edges;
466 const std::vector<unsigned int> & node_map =
470 libmesh_assert_equal_to(fnv, face.
n_edges());
471 libmesh_assert_equal_to(fnv, face.
n_sides());
472 libmesh_assert_less_equal(fnv, node_map.size());
473 libmesh_assert_less(side_edge, fnv);
475 const unsigned int vn = node_map[side_edge];
476 const unsigned int vnp = node_map[(side_edge + 1) % fnv];
479 if (vn == n || vnp == n)
480 adjacent_edges.push_back(edge);
483 return adjacent_edges;
489 std::pair<Real, Real> bounds;
500 bounds.second = 180.;
505 bounds.second = 180.;
528 libmesh_warning(
"Invalid quality measure chosen.");
538std::vector<std::shared_ptr<Polygon>>
541 const auto ns = this->
n_sides();
545 std::vector<std::shared_ptr<Polygon>> cloned_sides(ns);
552 Polygon * polygon_clone = cast_ptr<Polygon *>(clone);
553 cloned_sides[i] = std::shared_ptr<Polygon>(polygon_clone);
571 unsigned int min_node,
572 unsigned int max_node)
const
575 const std::vector<unsigned int> & node_map =
598std::vector<unsigned int>
601 std::vector<unsigned int> returnval(2);
606 const std::vector<unsigned int> & node_map =
639 const unsigned int s)
const
648 const std::vector<unsigned int> & node_map =
650 std::vector<unsigned int> nodes_on_edge1 =
652 libmesh_assert_equal_to(nodes_on_edge1.size(), 2);
654 nodes_on_edge1[0] = node_map[nodes_on_edge1[0]];
655 nodes_on_edge1[1] = node_map[nodes_on_edge1[1]];
656 if (nodes_on_edge1[0] > nodes_on_edge1[1])
657 std::swap(nodes_on_edge1[0], nodes_on_edge1[1]);
680std::tuple<unsigned int, Real, Real, Real>
683 std::tuple<unsigned int, Real, Real, Real> returnval =
686 Real best_bad_coord = -1;
690 const std::array<Point, 4> subtet =
694 const Point v0 = p - subtet[0];
697 const Point v01 = subtet[1] - subtet[0];
698 const Point v02 = subtet[2] - subtet[0];
699 const Point v03 = subtet[3] - subtet[0];
711 const Real xi = tp1 / six_vol;
712 const Real eta = tp2 / six_vol;
713 const Real zeta = tp3 / six_vol;
715 if (xi>=0 && eta>=0 && zeta>=0 && xi+eta+zeta<=1)
716 return { s, xi, eta, zeta };
718 const Real my_best_bad_coord =
719 std::min(std::min(std::min(xi, eta), zeta), 1-xi-eta-zeta);
721 if (my_best_bad_coord > best_bad_coord)
723 best_bad_coord = my_best_bad_coord;
724 returnval = { s, xi, eta, zeta };
728 if (best_bad_coord > -tol)
The Cell is an abstract element type that lives in three dimensions.
processor_id_type processor_id() const
This is the base class from which all geometric element types are derived.
virtual std::unique_ptr< Elem > disconnected_clone() const
virtual Node *& set_node(const unsigned int i)
unsigned char mapping_data() const
virtual unsigned int n_vertices() const =0
const Point & point(const unsigned int i) const
SimpleRange< NodeRefIter > node_ref_range()
Returns a range with all nodes of an element, usable in range-based for loops.
Node ** _nodes
Pointers to the nodes we are connected to.
virtual std::vector< unsigned int > nodes_on_side(const unsigned int) const =0
void set_interior_parent(Elem *p)
Sets the pointer to the element's interior_parent.
unsigned char _map_data
Mapping function data; currently used when needed to store the RATIONAL_BERNSTEIN nodal weight data i...
virtual std::vector< unsigned int > nodes_on_edge(const unsigned int) const =0
subdomain_id_type subdomain_id() const
Elem ** _elemlinks
Pointers to this element's parent and neighbors, and for lower-dimensional elements' interior_parent.
unsigned char _map_type
Mapping function type; currently either 0 (LAGRANGE) or 1 (RATIONAL_BERNSTEIN).
ElemMappingType mapping_type() const
const Node * node_ptr(const unsigned int i) const
IntRange< unsigned short > node_index_range() const
dof_id_type node_id(const unsigned int i) const
unsigned int p_level() const
void set_p_level(const unsigned int p)
Sets the value of the p-refinement level for the element.
virtual std::unique_ptr< Elem > build_edge_ptr(const unsigned int i) override final
build_side and build_edge are identical for faces.
A Node is like a Point, but with more information.
A Point defines a location in LIBMESH_DIM dimensional Real space.
The Polygon is an element in 2D with an arbitrary (but fixed) number of sides.
virtual unsigned int local_edge_node(unsigned int edge, unsigned int edge_node) const override
Calls local_side_node(edge, edge_node).
virtual dof_id_type key() const override
virtual unsigned int n_edges() const override final
virtual unsigned int n_nodes() const override
virtual unsigned int n_sides() const override final
virtual unsigned int n_vertices() const override final
The Polyhedron is an element in 3D with an arbitrary number of polygonal faces.
virtual std::array< Point, 4 > master_subelement(unsigned int i) const
virtual unsigned int n_edges() const override final
virtual Point master_point(const unsigned int i) const override
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i) override
Copies the Polygon side coincident with side i.
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const override
virtual std::vector< unsigned int > edges_adjacent_to_node(const unsigned int n) const override
virtual std::vector< unsigned int > sides_on_edge(const unsigned int e) const override final
virtual std::unique_ptr< Elem > side_ptr(const unsigned int i) override final
virtual bool is_edge_on_side(const unsigned int e, const unsigned int s) const override final
virtual unsigned int opposite_side(const unsigned int s) const override final
Throws an error.
virtual dof_id_type low_order_key(const unsigned int s) const override
virtual unsigned int local_side_node(unsigned int side, unsigned int side_node) const override
virtual bool is_flipped() const override final
virtual unsigned int n_nodes() const override
unsigned int n_subelements() const
Polyhedron(const std::vector< std::shared_ptr< Polygon > > &sides, Elem *p)
Arbitrary polyhedral element, takes a vector of shared pointers to sides (which should already be con...
virtual unsigned int opposite_node(const unsigned int n, const unsigned int s) const override final
Throws an error - opposite_side(s) is too hard to define in general on polyhedra.
static const int num_children
std::vector< Elem * > _elemlinks_data
Data for links to parent/neighbor/interior_parent elements.
virtual unsigned int n_sides() const override final
virtual dof_id_type key() const override
virtual bool on_reference_element(const Point &p, const Real eps=TOLERANCE) const override final
std::tuple< unsigned int, Real, Real, Real > subelement_coordinates(const Point &p, Real tol=TOLERANCE *TOLERANCE) const
std::vector< std::shared_ptr< Polygon > > side_clones() const
virtual std::unique_ptr< Elem > build_edge_ptr(const unsigned int i) override final
std::vector< std::pair< unsigned int, unsigned int > > _edge_lookup
One entry for each polyhedron edge, a pair indicating the side number and the edge-of-side number whi...
std::vector< Node * > _nodelinks_data
Data for links to nodes.
virtual unsigned int local_edge_node(unsigned int edge, unsigned int edge_node) const override
Similar to Elem::local_side_node(), but instead of a side id, takes an edge id and a node id on that ...
virtual std::pair< Real, Real > qual_bounds(const ElemQuality q) const override
std::vector< std::tuple< std::shared_ptr< Polygon >, bool, std::vector< unsigned int > > > _sidelinks_data
Data for links to sides.
std::vector< std::array< int, 4 > > _triangulation
Data for a triangulation (tetrahedralization) of the polyhedron.
bool side_has_edge_nodes(unsigned int side, unsigned int min_node, unsigned int max_node) const
Helper method for finding the non-cached side that shares an edge, by examining the local node ids th...
LIBMESH_DEVICE_INLINE TypeVector< T > unit() const
void add(const TypeVector< T2 > &)
Add to this vector without creating a temporary.
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval=0)
The hashword function takes an array of uint32_t's of length 'length' and computes a single key from ...
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
LIBMESH_DEVICE_INLINE T triple_product(const TypeVector< T > &a, const TypeVector< T > &b, const TypeVector< T > &c)
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
ElemQuality
Defines an enum for element quality metrics.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...