Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// Defines functions for computing the connectivity of an element
6 :
7 : #pragma once
8 :
9 : #include <cstddef>
10 : #include <ostream>
11 : #include <utility>
12 : #include <vector>
13 :
14 : template <size_t Dim>
15 : class Index;
16 :
17 : /// Holds functions needed for visualizing data
18 1 : namespace vis {
19 : namespace detail {
20 : /*!
21 : * \brief The set of cell topologies used for visualization
22 : *
23 : * Tensor-product topologies (Line, Quad, Hexahedron) can be generated by
24 : * `compute_cells()`. Non-tensor-product topologies (Triangle, Tetrahedron,
25 : * Wedge) are necessary for filled cylinders, shells, and balls.
26 : *
27 : * The numerical values correspond to the XDMF topology types.
28 : */
29 : enum class Topology : int {
30 : Line = 2,
31 : Triangle = 4,
32 : Quad = 5,
33 : Tetrahedron = 6,
34 : Wedge = 8,
35 : Hexahedron = 9
36 : };
37 :
38 : std::ostream& operator<<(std::ostream& os, const Topology& topology);
39 :
40 : /*!
41 : * \brief Represents the number of cells in a particular topology
42 : *
43 : * Each `CellInTopology` holds an enum of type `Topology` whose
44 : * value denotes the type of the topology, e.g. line, quad or hexahedron, and a
45 : * vector of bounding indices which are the indices of the grid coordinates in
46 : * the contiguous arrays of x, y, and z coordinates that bound the cell.
47 : */
48 : struct CellInTopology {
49 : // cppcheck-suppress passedByValue
50 : CellInTopology(const Topology& top, std::vector<size_t> bounding_ind)
51 : : topology(top), bounding_indices(std::move(bounding_ind)) {}
52 : CellInTopology() = default;
53 : CellInTopology(const CellInTopology& /*rhs*/) = default;
54 : CellInTopology(CellInTopology&& /*rhs*/) = default;
55 : CellInTopology& operator=(const CellInTopology& /*rhs*/) = default;
56 : CellInTopology& operator=(CellInTopology&& /*rhs*/) = default;
57 : ~CellInTopology() = default;
58 : Topology topology{Topology::Line};
59 : std::vector<size_t> bounding_indices{};
60 : };
61 :
62 : /// @{
63 : /*!
64 : * \brief Compute the cells in the element.
65 : *
66 : * Returns a vector of the cells in the topology I1^Dim, i.e. a line if Dim ==
67 : * 1, or a hexahedron if Dim == 3. The cells are bounded by lines connecting
68 : * grid points along the axes of the element, so if you have (n_x by n_y by n_z)
69 : * grid points, you have ((n_x-1) by (n_y-1) by (n_z-1)) cells.
70 : *
71 : * \note As more topologies are added, e.g. S2, the interface will need slight
72 : * modification, however the return type is likely to be able to remain the
73 : * same.
74 : */
75 : template <size_t Dim>
76 : std::vector<CellInTopology> compute_cells(const Index<Dim>& extents);
77 :
78 : std::vector<CellInTopology> compute_cells(const std::vector<size_t>& extents);
79 : /// @}
80 :
81 : /*!
82 : * \brief Return the XDMF 3.0 integer type tag for a given topology.
83 : *
84 : * The mapping is: Line=2, Triangle=4, Quad=5, Tetrahedron=6, Wedge=8,
85 : * Hexahedron=9.
86 : * Used when writing mixed-topology connectivity arrays to HDF5 files.
87 : */
88 : int xdmf_topology_type(Topology topology);
89 :
90 : } // namespace detail
91 : } // namespace vis
|