Skip to content

Commit 60f576d

Browse files
authored
Merge pull request #121 from WIAS-PDELib/jf/read_ele
Support reading of TetGen .ele files
2 parents ac46d1d + c34a972 commit 60f576d

7 files changed

Lines changed: 1086 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# [1.17.0] - 2026-04-15
44
- new kwargs `not_in_domain_value = nothing` and `check_if_not_in_domain = isnothing(not_in_domain_value)` for grid interpolation.
55
This enables the user to interpolate values between grids which do not share the same domain. The value _outside_ the target domain has to be provided by the user.
6+
- Allow to read simplexgrid data from TetGen .ele file sets
7+
8+
## [1.16.0] - 2026-01-21
9+
- Allow to read/write WIAS-TeSCA dom files
610

711
## [1.15.0] - 2026-01-14
812
- add and export `explode` function that produces a grid with all adjacencies removed

src/io.jl

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ $(TYPEDSIGNATURES)
5555
- format version 2.1: shortened version only with cells, cellnodes, cellregions, bfacenodes, bfaceregions
5656
- format version 2.2: like 2.1, but additional info on cell and node partitioning. Edge partitioning
5757
is not stored in the file and may be re-established by [`induce_edge_partitioning!`](@ref).
58+
- "*.ele": TetGen output format (requires presence of *.ele, *.node and *.face file)
5859
- "*.geo": gmsh geometry description (requires `using Gmsh`)
5960
- "*.msh": gmsh mesh (requires `using Gmsh`)
6061
- "*.dom": WIAS-TeSCA dom format
@@ -265,6 +266,95 @@ function writegrid(fname::String, g::ExtendableGrid, ::Type{Val{:sg}}; version =
265266
return nothing
266267
end
267268

269+
########################################################
270+
## TetGen ele format
271+
#######################################################
272+
function simplexgrid(file::String, ::Type{Val{:ele}}; kwargs...)
273+
Ti = Cint
274+
fname, fext = splitext(file)
275+
tks_ele = TokenStream(fname * ".ele")
276+
tks_face = TokenStream(fname * ".face")
277+
tks_node = TokenStream(fname * ".node")
278+
279+
280+
npoints = parse(Ti, gettoken(tks_node))
281+
dim = parse(Ti, gettoken(tks_node))
282+
if dim != 3
283+
throw(ErrorException("Dimension $dim not supported so far for .ele format"))
284+
end
285+
npointboundarymarkers = parse(Ti, gettoken(tks_node))
286+
if npointboundarymarkers > 0
287+
@warn "ignoring point boundary markers"
288+
end
289+
npointattributes = parse(Ti, gettoken(tks_node))
290+
if npointattributes > 0
291+
@warn "ignoring point attributes"
292+
end
293+
coord = Array{Float64, 2}(undef, dim, npoints)
294+
for ipoint in 1:npoints
295+
idx = parse(Ti, gettoken(tks_node)) + 1
296+
for idim in 1:dim
297+
coord[idim, idx] = parse(Float64, gettoken(tks_node))
298+
end
299+
for i in 1:npointboundarymarkers
300+
gettoken(tks_node)
301+
end
302+
for i in 1:npointattributes
303+
gettoken(tks_node)
304+
end
305+
end
306+
307+
308+
ncells = parse(Ti, gettoken(tks_ele))
309+
ncellnodes = parse(Ti, gettoken(tks_ele))
310+
ncellattributes = parse(Ti, gettoken(tks_ele))
311+
cells = Array{Ti, 2}(undef, ncellnodes, ncells)
312+
regions = Array{Ti, 1}(undef, ncells)
313+
if ncellattributes > 1
314+
@warn "ignoring more than one cell attribute"
315+
end
316+
for icell in 1:ncells
317+
idx = parse(Ti, gettoken(tks_ele)) + 1
318+
for inode in 1:ncellnodes
319+
cells[inode, idx] = parse(Ti, gettoken(tks_ele)) + 1
320+
end
321+
if ncellattributes == 0
322+
regions[idx] = 1
323+
else
324+
regions[idx] = parse(Ti, gettoken(tks_ele))
325+
for i in 2:ncellattributes
326+
gettoken(tks_ele)
327+
end
328+
end
329+
end
330+
331+
nfaces = parse(Ti, gettoken(tks_face))
332+
nfaceattributes = parse(Ti, gettoken(tks_face))
333+
nfacenodes = 3
334+
if nfaceattributes > 1
335+
@warn "ignoring more than one face attribute"
336+
end
337+
faces = Array{Ti, 2}(undef, dim, nfaces)
338+
bregions = Array{Ti, 1}(undef, nfaces)
339+
for iface in 1:nfaces
340+
idx = parse(Ti, gettoken(tks_face)) + 1
341+
for inode in 1:nfacenodes
342+
faces[inode, idx] = parse(Ti, gettoken(tks_face)) + 1
343+
end
344+
if nfaceattributes == 0
345+
bregions[idx] = 1
346+
else
347+
bregions[idx] = parse(Ti, gettoken(tks_face))
348+
for i in 2:nfaceattributes
349+
gettoken(tks_face)
350+
end
351+
end
352+
end
353+
g = simplexgrid(coord, cells, regions, faces, bregions)
354+
return g
355+
end
356+
357+
268358
########################################################
269359
## WIAS-TeSCA dom format
270360
#######################################################

test/cube.1.edge

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
48 1
2+
0 22 42 -1
3+
1 15 66 -1
4+
2 6 41 -1
5+
3 57 130 -1
6+
4 5 74 -1
7+
5 25 150 -1
8+
6 1 83 -1
9+
7 0 126 -1
10+
8 38 6 -1
11+
9 21 38 -1
12+
10 16 112 -1
13+
11 3 129 -1
14+
12 3 154 -1
15+
13 39 75 -1
16+
14 7 82 -1
17+
15 11 114 -1
18+
16 4 149 -1
19+
17 23 139 -1
20+
18 17 87 -1
21+
19 2 117 -1
22+
20 19 51 -1
23+
21 1 72 -1
24+
22 2 98 -1
25+
23 20 76 -1
26+
24 41 19 -1
27+
25 42 6 -1
28+
26 51 7 -1
29+
27 4 134 -1
30+
28 66 7 -1
31+
29 72 25 -1
32+
30 74 22 -1
33+
31 75 3 -1
34+
32 76 4 -1
35+
33 82 20 -1
36+
34 83 57 -1
37+
35 87 1 -1
38+
36 98 39 -1
39+
37 112 0 -1
40+
38 114 0 -1
41+
39 117 21 -1
42+
40 126 17 -1
43+
41 129 15 -1
44+
42 130 2 -1
45+
43 134 16 -1
46+
44 139 5 -1
47+
45 149 23 -1
48+
46 150 5 -1
49+
47 154 11 -1
50+
# Generated by /home/fuhrmann/Wias/work/tetgen/codeberg/TestingDrafts/src/../tetgen-v161/build/tetgen -pqa0.005 /home/fuhrmann/Wias/work/tetgen/codeberg/TestingDrafts/src/../quarry/cube.smesh

0 commit comments

Comments
 (0)