DOLFINx
DOLFINx C++
Loading...
Searching...
No Matches
cell_types.h
1// Copyright (C) 2019-2026 Garth N. Wells
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include <array>
10#include <basix/cell.h>
11#include <dolfinx/graph/AdjacencyList.h>
12#include <map>
13#include <set>
14#include <string>
15#include <vector>
16
17namespace dolfinx::mesh
18{
20enum class CellType : std::int8_t
21{
22 // NOTE: Simplex cells have index > 0, see mesh::is_simplex
23 point = 1,
24 interval = 2,
25 triangle = 3,
26 tetrahedron = 4,
27 quadrilateral = -4,
28 pyramid = -5,
29 prism = -6,
30 hexahedron = -8
31};
32
36std::string to_string(CellType type);
37
41CellType to_type(const std::string& cell);
42
44inline int cell_dim(CellType type)
45{
46 switch (type)
47 {
48 case CellType::point:
49 return 0;
50 case CellType::interval:
51 return 1;
52 case CellType::triangle:
53 return 2;
54 case CellType::quadrilateral:
55 return 2;
56 case CellType::tetrahedron:
57 return 3;
58 case CellType::hexahedron:
59 return 3;
60 case CellType::prism:
61 return 3;
62 case CellType::pyramid:
63 return 3;
64 default:
65 throw std::runtime_error("Unsupported cell type");
66 }
67}
68
78inline CellType cell_facet_type(CellType type, int index)
79{
80 switch (type)
81 {
82 case CellType::point:
83 return CellType::point;
84 case CellType::interval:
85 return CellType::point;
86 case CellType::triangle:
87 return CellType::interval;
88 case CellType::tetrahedron:
89 return CellType::triangle;
90 case CellType::quadrilateral:
91 return CellType::interval;
92 case CellType::pyramid:
93 if (index == 0)
94 return CellType::quadrilateral;
95 else
96 return CellType::triangle;
97 case CellType::prism:
98 if (index == 0 or index == 4)
99 return CellType::triangle;
100 else
101 return CellType::quadrilateral;
102 case CellType::hexahedron:
103 return CellType::quadrilateral;
104 default:
105 throw std::runtime_error("Unknown cell type.");
106 }
107}
108
110inline CellType cell_entity_type(CellType type, int d, int index)
111{
112 if (int dim = mesh::cell_dim(type); d == dim)
113 return type;
114 else if (d == 1)
115 return CellType::interval;
116 else if (d == (dim - 1))
117 return mesh::cell_facet_type(type, index);
118 else
119 return CellType::point;
120}
121
125
128graph::AdjacencyList<int> get_sub_entities(CellType type, int dim0, int dim1);
129
135int cell_num_entities(CellType type, int dim);
136
141bool is_simplex(CellType type);
142
148
149// [dim, entity] -> closure{sub_dim, (sub_entities)}
150
154std::map<std::array<int, 2>, std::vector<std::set<int>>>
156
158basix::cell::type cell_type_to_basix_type(CellType celltype);
159
161CellType cell_type_from_basix_type(basix::cell::type celltype);
162
163} // namespace dolfinx::mesh
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
CellType cell_facet_type(CellType type, int index)
Return facet type of cell.
Definition cell_types.h:78
int cell_dim(CellType type)
Return topological dimension of cell type.
Definition cell_types.h:44
CellType cell_type_from_basix_type(basix::cell::type celltype)
Get a cell type from a Basix cell type.
Definition cell_types.cpp:188
CellType
Cell type identifier.
Definition cell_types.h:21
int num_cell_vertices(CellType type)
Number vertices for a cell type.
Definition cell_types.cpp:98
graph::AdjacencyList< int > get_entity_vertices(CellType type, int dim)
List of entities, where entity (e, k) is the local vertex index for the kth vertex of entity e of dim...
Definition cell_types.cpp:64
basix::cell::type cell_type_to_basix_type(CellType celltype)
Convert a cell type to a Basix cell type.
Definition cell_types.cpp:163
std::map< std::array< int, 2 >, std::vector< std::set< int > > > cell_entity_closure(CellType cell_type)
Definition cell_types.cpp:104
int cell_num_entities(CellType type, int dim)
Number of entities of dimension.
Definition cell_types.cpp:90
bool is_simplex(CellType type)
Check if cell is a simplex.
Definition cell_types.cpp:96
std::string to_string(CellType type)
Definition cell_types.cpp:17
CellType to_type(const std::string &cell)
Definition cell_types.cpp:42
CellType cell_entity_type(CellType type, int d, int index)
Return type of cell for entity of dimension d at given entity index.
Definition cell_types.h:110
graph::AdjacencyList< int > get_sub_entities(CellType type, int dim0, int dim1)
Definition cell_types.cpp:71