-
Notifications
You must be signed in to change notification settings - Fork 79
/
topologies.jl
137 lines (104 loc) · 2.78 KB
/
topologies.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------
"""
Topology
A data structure for constructing topological relations in a [`Mesh`](@ref).
## References
* Floriani, L. & Hui, A. 2007. [Shape representations
based on simplicial and cell complexes]
(https://diglib.eg.org/handle/10.2312/egst.20071055.063-087)
"""
abstract type Topology end
"""
vertex(topology, ind)
Return the vertex of a `topology` at index `ind`.
"""
vertex(::Topology, ind) = ind
"""
vertices(topology)
Return the vertices of the `topology`.
"""
vertices(t::Topology) = 1:nvertices(t)
"""
nvertices(topology)
Return the number of vertices of the `topology`.
"""
function nvertices end
"""
faces(topology, rank)
Return an iterator with `rank`-faces of the `topology`.
## Examples
Consider a mesh of tetrahedrons embedded in a 3D space. We can loop over
all 3-faces (a.k.a. elements) or over all 2-faces to handle the interfaces
(i.e. triangles) between adjacent elements:
```julia
tetrahedrons = faces(topology, 3)
triangles = faces(topology, 2)
segments = faces(topology, 1)
```
"""
function faces(t::Topology, rank)
D = paramdim(t)
if rank == D
elements(t)
elseif rank == D - 1
facets(t)
else
throw(ErrorException("not implemented"))
end
end
"""
nfaces(topology, rank)
Return the number of `rank`-faces of the `topology`.
"""
function nfaces(t::Topology, rank)
D = paramdim(t)
if rank == D
nelements(t)
elseif rank == D - 1
nfacets(t)
else
throw(ErrorException("not implemented"))
end
end
"""
elements(topology)
Return the top-faces (a.k.a. elements) of the `topology`.
## Examples
The elements of a volume embedded in 3D space can be tetrahedrons, hexahedrons,
or any 3-face. The elements of a surface embedded in 3D space can be triangles,
quadrangles or any 2-face.
"""
elements(t::Topology) = (element(t, i) for i in 1:nelements(t))
"""
element(topology, ind)
Return the element of the `topology` at index `ind`.
"""
function element(::Topology, ind) end
"""
nelements(topology)
Return the number of elements of the `topology`.
"""
function nelements(::Topology) end
"""
facets(topology)
Return the (top-1)-faces (a.k.a. facets) of the `topology`.
"""
facets(t::Topology) = (facet(t, i) for i in 1:nfacets(t))
"""
facet(topology, ind)
Return the facet of the `topology` at index `ind`.
"""
function facet(::Topology, ind) end
"""
nfacets(topology)
Return the number of facets of the `topology`.
"""
function nfacets(::Topology) end
# ----------------
# IMPLEMENTATIONS
# ----------------
include("topologies/grid.jl")
include("topologies/halfedge.jl")
include("topologies/simple.jl")