DOLFIN
DOLFIN C++ interface
CellType.h
1 // Copyright (C) 2006-2017 Anders Logg
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Kristoffer Selim 2008
19 // Modified by Andre Massing 2009-2010
20 // Modified by Jan Blechta 2013
21 //
22 // First added: 2006-06-05
23 // Last changed: 2017-09-26
24 
25 #ifndef __CELL_TYPE_H
26 #define __CELL_TYPE_H
27 
28 #include <cstdint>
29 #include <string>
30 #include <vector>
31 #include <boost/multi_array.hpp>
32 
33 namespace dolfin
34 {
35 
36  class Cell;
37  class MeshEditor;
38  class MeshEntity;
39  template <typename T> class MeshFunction;
40  class Point;
41 
45 
46  class CellType
47  {
48  public:
49 
51  enum class Type : int { point, interval, triangle, quadrilateral, tetrahedron, hexahedron };
52 
55 
57  virtual ~CellType();
58 
60  static CellType* create(Type type);
61 
63  static CellType* create(std::string type);
64 
66  static Type string2type(std::string type);
67 
69  static std::string type2string(Type type);
70 
72  Type cell_type() const
73  { return _cell_type; }
74 
76  Type facet_type() const
77  { return _facet_type; }
78 
80  Type entity_type(std::size_t i) const;
81 
83  virtual bool is_simplex() const = 0;
84 
86  virtual std::size_t dim() const = 0;
87 
89  virtual std::size_t num_entities(std::size_t dim) const = 0;
90 
92  std::size_t num_vertices() const
93  { return num_vertices(dim()); }
94 
96  virtual std::size_t num_vertices(std::size_t dim) const = 0;
97 
99  virtual std::size_t orientation(const Cell& cell) const = 0;
100 
102  std::size_t orientation(const Cell& cell, const Point& up) const;
103 
106  virtual void create_entities(boost::multi_array<unsigned int, 2>& e,
107  std::size_t dim,
108  const unsigned int* v) const = 0;
109 
111  virtual double volume(const MeshEntity& entity) const = 0;
112 
114  virtual double h(const MeshEntity& entity) const;
115 
117  virtual double circumradius(const MeshEntity& entity) const = 0;
118 
120  virtual double inradius(const Cell& cell) const;
121 
123  virtual double radius_ratio(const Cell& cell) const;
124 
126  virtual double squared_distance(const Cell& cell,
127  const Point& point) const = 0;
128 
130  virtual double normal(const Cell& cell, std::size_t facet,
131  std::size_t i) const = 0;
132 
134  virtual Point normal(const Cell& cell, std::size_t facet) const = 0;
135 
137  virtual Point cell_normal(const Cell& cell) const = 0;
138 
140  virtual double facet_area(const Cell& cell, std::size_t facet) const = 0;
141 
142  // FIXME: The order() function should be reimplemented and use one common
143  // FIXME: implementation for all cell types, just as we have for ordered()
144 
146  virtual void order(Cell& cell,
147  const std::vector<std::int64_t>& local_to_global_vertex_indices) const = 0;
148 
150  bool ordered(const Cell& cell,
151  const std::vector<std::int64_t>& local_to_global_vertex_indices) const;
152 
154  virtual bool collides(const Cell& cell, const Point& point) const = 0;
155 
157  virtual bool collides(const Cell& cell, const MeshEntity& entity) const = 0;
158 
160  virtual std::string description(bool plural) const = 0;
161 
163  virtual std::vector<std::int8_t> vtk_mapping() const = 0;
164 
165  protected:
166 
167  Type _cell_type;
168  Type _facet_type;
169 
171  static void sort_entities(std::size_t num_vertices,
172  unsigned int* vertices,
173  const std::vector<std::int64_t>& local_to_global_vertex_indices);
174 
175  private:
176 
177  // Check if list of vertices is increasing
178  static bool increasing(std::size_t num_vertices, const unsigned int* vertices,
179  const std::vector<std::int64_t>& local_to_global_vertex_indices);
180 
181  // Check that <entity e0 with vertices v0> <= <entity e1 with vertices v1>
182  static bool increasing(std::size_t n0, const unsigned int* v0,
183  std::size_t n1, const unsigned int* v1,
184  std::size_t num_vertices, const unsigned int* vertices,
185  const std::vector<std::int64_t>& local_to_global_vertex_indices);
186 
187  };
188 
189 }
190 
191 #endif
Type entity_type(std::size_t i) const
Return type of cell for entity of dimension i.
Definition: CellType.cpp:134
virtual double normal(const Cell &cell, std::size_t facet, std::size_t i) const =0
Compute component i of normal of given facet with respect to the cell.
Definition: adapt.h:29
static Type string2type(std::string type)
Convert from string to cell type.
Definition: CellType.cpp:85
virtual bool is_simplex() const =0
Check if cell is a simplex.
Definition: Point.h:40
virtual double radius_ratio(const Cell &cell) const
Compute dim*inradius/circumradius for given cell.
Definition: CellType.cpp:210
Type
Enum for different cell types.
Definition: CellType.h:51
virtual double facet_area(const Cell &cell, std::size_t facet) const =0
Compute the area/length of given facet with respect to the cell.
Type cell_type() const
Return type of cell.
Definition: CellType.h:72
A Cell is a MeshEntity of topological codimension 0.
Definition: Cell.h:42
virtual ~CellType()
Destructor.
Definition: CellType.cpp:50
virtual bool collides(const Cell &cell, const Point &point) const =0
Check whether given point collides with cell.
bool ordered(const Cell &cell, const std::vector< std::int64_t > &local_to_global_vertex_indices) const
Check if entities are ordered.
Definition: CellType.cpp:221
virtual double volume(const MeshEntity &entity) const =0
Compute (generalized) volume of mesh entity.
virtual double inradius(const Cell &cell) const
Compute inradius of cell.
Definition: CellType.cpp:178
std::size_t num_vertices() const
Return number of vertices for cell.
Definition: CellType.h:92
Definition: CellType.h:46
static void sort_entities(std::size_t num_vertices, unsigned int *vertices, const std::vector< std::int64_t > &local_to_global_vertex_indices)
Sort vertices based on global entity indices.
Definition: CellType.cpp:276
static CellType * create(Type type)
Create cell type from type (factory function)
Definition: CellType.cpp:55
virtual void create_entities(boost::multi_array< unsigned int, 2 > &e, std::size_t dim, const unsigned int *v) const =0
virtual double circumradius(const MeshEntity &entity) const =0
Compute circumradius of mesh entity.
virtual std::vector< std::int8_t > vtk_mapping() const =0
Mapping of DOLFIN/UFC vertex ordering to VTK/XDMF ordering.
virtual std::size_t num_entities(std::size_t dim) const =0
Return number of entities of given topological dimension.
virtual Point cell_normal(const Cell &cell) const =0
Compute normal to given cell (viewed as embedded in 3D)
virtual std::string description(bool plural) const =0
Return description of cell type.
static std::string type2string(Type type)
Convert from cell type to string.
Definition: CellType.cpp:109
Definition: MeshEntity.h:42
virtual double squared_distance(const Cell &cell, const Point &point) const =0
Compute squared distance to given point.
CellType(Type cell_type, Type facet_type)
Constructor.
Definition: CellType.cpp:44
Type facet_type() const
Return type of cell for facets.
Definition: CellType.h:76
virtual double h(const MeshEntity &entity) const
Compute greatest distance between any two vertices.
Definition: CellType.cpp:151
virtual std::size_t dim() const =0
Return topological dimension of cell.
virtual std::size_t orientation(const Cell &cell) const =0
Return orientation of the cell (assuming flat space)
virtual void order(Cell &cell, const std::vector< std::int64_t > &local_to_global_vertex_indices) const =0
Order entities locally.