Skip to content

Commit 6299b6f

Browse files
authored
Merge pull request #27 from j-fu/handle-partitioning
Handle partitioning
2 parents 9fa2d0c + db0209f commit 6299b6f

File tree

10 files changed

+69
-32
lines changed

10 files changed

+69
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
version:
1818
- '1.9' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
1919
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
20-
- 'nightly'
20+
# - 'nightly'
2121
os:
2222
- ubuntu-latest
2323
- macos-latest

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GridVisualize"
22
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
33
authors = ["Juergen Fuhrmann <[email protected]>"]
4-
version = "1.6"
4+
version = "1.7"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
@@ -26,7 +26,7 @@ ColorSchemes = "3"
2626
Colors = "0.12,1"
2727
DocStringExtensions = "0.8,0.9"
2828
ElasticArrays = "1"
29-
ExtendableGrids = "0.9,1"
29+
ExtendableGrids = "1.7"
3030
GLMakie = "0.9, 0.10"
3131
GeometryBasics = "0.4.1"
3232
GridVisualizeTools = "1.1"

src/common.jl

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ Return corresponding points and facets for each region for drawing as mesh (Maki
99
or trisurf (pyplot)
1010
"""
1111
function GridVisualizeTools.extract_visible_cells3D(grid::ExtendableGrid, xyzcut;
12+
cellcoloring = :cellregions,
1213
gridscale = 1.0,
1314
primepoints = zeros(0, 0),
1415
Tp = SVector{3, Float32},
1516
Tf = SVector{3, Int32})
1617
coord = grid[Coordinates] * gridscale
1718
cellnodes = grid[CellNodes]
18-
cellregions = grid[CellRegions]
19-
nregions = grid[NumCellRegions]
19+
cellregions = cellcolors(grid, cellcoloring)
20+
nregions = num_cellcolors(grid, cellcoloring)
2021
extract_visible_cells3D(coord, cellnodes, cellregions, nregions, [xyzcut...] * gridscale;
2122
primepoints = primepoints,
2223
Tp = Tp, Tf = Tf)
@@ -86,10 +87,10 @@ end
8687

8788
##############################################
8889
# Create meshes from grid data
89-
function regionmesh(grid, gridscale, iregion)
90+
function regionmesh(grid, gridscale, iregion; cellcoloring = :cellregions)
9091
coord = grid[Coordinates]
9192
cn = grid[CellNodes]
92-
cr = grid[CellRegions]
93+
cr = cellcolors(grid, cellcoloring)
9394
@views points = [Point2f(coord[:, i] * gridscale) for i = 1:size(coord, 2)]
9495
faces = Vector{GLTriangleFace}(undef, 0)
9596
for i = 1:length(cr)
@@ -425,3 +426,37 @@ function bary!(λ, invA, L2G, x)
425426
end
426427
ExtendableGrids.postprocess_xreftest!(λ, Triangle2D)
427428
end
429+
430+
function cellcolors(grid, coloring)
431+
xr = grid[CellRegions]
432+
if coloring == :partitions
433+
xr = similar(xr)
434+
for icol in pcolors(grid)
435+
for ipart in pcolor_partitions(grid, icol)
436+
for icell in partition_cells(grid, ipart)
437+
xr[icell] = ipart
438+
end
439+
end
440+
end
441+
elseif coloring == :pcolors
442+
xr = similar(xr)
443+
for icol in pcolors(grid)
444+
for ipart in pcolor_partitions(grid, icol)
445+
for icell in partition_cells(grid, ipart)
446+
xr[icell] = icol
447+
end
448+
end
449+
end
450+
end
451+
xr
452+
end
453+
454+
function num_cellcolors(grid, coloring)
455+
if coloring == :partitions
456+
num_partitions(grid)
457+
elseif coloring == :pcolors
458+
num_pcolors(grid)
459+
else
460+
num_cellregions(grid)
461+
end
462+
end

src/dispatch.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ function default_plot_kwargs()
336336
:zplanes => Pair([prevfloat(Inf)], "3D z plane positions or number thereof"),
337337
:zoom => Pair(1.0, "Zoom level"),
338338
:gridscale => Pair(1, "Grid scale factor. Will be applied also to planes, spacing"),
339+
:cellcoloring => Pair(:cellregions,
340+
"Coloring of cells: one of [:cellregions, :pcolors, :partitions]"),
339341
:azim => Pair(-60, "3D azimuth angle (in degrees)"),
340342
:elev => Pair(30, "3D elevation angle (in degrees)"),
341343
:perspectiveness => Pair(0.25,

src/makie.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ function basemesh1d(grid, gridscale)
203203
end
204204

205205
# Point list for intervals
206-
function regionmesh1d(grid, gridscale, iregion)
206+
function regionmesh1d(grid, gridscale, iregion; cellcoloring = :cellregions)
207207
coord = vec(grid[Coordinates])
208208
points = Vector{Point2f}(undef, 0)
209209
cn = grid[CellNodes]
210-
cr = grid[CellRegions]
210+
cr = cellcolors(grid, cellcoloring)
211211
ncells = length(cr)
212212
for i = 1:ncells
213213
if cr[i] == iregion
@@ -275,7 +275,7 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{1}}, grid)
275275
# Colored cell regions
276276
for i = 1:nregions
277277
XMakie.linesegments!(ctx[:scene],
278-
map(g -> regionmesh1d(g, gridscale, i), ctx[:grid]);
278+
map(g -> regionmesh1d(g, gridscale, i; cellcoloring = ctx[:cellcoloring]), ctx[:grid]);
279279
color = cmap[i],
280280
linewidth = 4,
281281
label = "c $(i)",)
@@ -528,7 +528,7 @@ end
528528
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid)
529529
XMakie = ctx[:Plotter]
530530

531-
nregions = num_cellregions(grid)
531+
nregions = num_cellcolors(grid, ctx[:cellcoloring])
532532

533533
nbregions = num_bfaceregions(grid)
534534

@@ -562,7 +562,7 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid)
562562
ctx[:cmap] = cmap
563563
for i = 1:nregions
564564
XMakie.poly!(ctx[:scene],
565-
map(g -> regionmesh(g, ctx[:gridscale], i), ctx[:grid]);
565+
map(g -> regionmesh(g, ctx[:gridscale], i; cellcoloring = ctx[:cellcoloring]), ctx[:grid]);
566566
color = cmap[i],
567567
strokecolor = :black,
568568
strokewidth = ctx[:linewidth],)
@@ -958,6 +958,7 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid)
958958
if ctx[:interior]
959959
ctx[:celldata] = map(d -> extract_visible_cells3D(d.g,
960960
[d.x, d.y, d.z] / ctx[:gridscale];
961+
cellcoloring = ctx[:cellcoloring],
961962
gridscale = ctx[:gridscale],
962963
primepoints = hcat(xyzmin, xyzmax),
963964
Tp = Point3f,

src/meshcat.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function gridplot!(ctx, TP::Type{MeshCatType}, ::Type{Val{2}}, grid)
3838
cmap = region_cmap(nregions)
3939
bcmap = bregion_cmap(nbregions)
4040
for i = 1:nregions
41-
mesh = regionmesh(grid, i)
41+
mesh = regionmesh(grid, i; cellcoloring = ctx[:cellcoloring])
4242
MeshCat.setobject!(vis["interior"]["r$(i)"],
4343
mesh,
4444
MeshCat.MeshLambertMaterial(; color = RGBA{Float32}(cmap[i], 1.0)))
@@ -86,6 +86,7 @@ function gridplot!(ctx, TP::Type{MeshCatType}, ::Type{Val{3}}, grid)
8686
if ctx[:interior]
8787
pts, fcs = extract_visible_cells3D(grid,
8888
xyzcut;
89+
cellcoloring = ctx[:cellcoloring],
8990
primepoints = hcat(xyzmin, xyzmax),
9091
Tp = Point3f,
9192
Tf = GLTriangleFace,)

src/plots.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ function gridplot!(ctx, TP::Type{PlotsType}, ::Type{Val{1}}, grid)
8484
end
8585
p = ctx[:ax]
8686

87-
cellregions = grid[CellRegions]
87+
cellregions = cellcolors(grid, ctx[:cellcoloring])
88+
ncellregions = num_cellcolors(grid, ctx[:cellcoloring])
8889
cellnodes = grid[CellNodes]
8990
coord = grid[Coordinates]
90-
ncellregions = grid[NumCellRegions]
9191
bfacenodes = grid[BFaceNodes]
9292
bfaceregions = grid[BFaceRegions]
9393
nbfaceregions = grid[NumBFaceRegions]
@@ -132,10 +132,10 @@ function gridplot!(ctx, TP::Type{PlotsType}, ::Type{Val{2}}, grid)
132132
ctx[:ax] = Plots.plot(; title = ctx[:title])
133133
end
134134
p = ctx[:ax]
135-
cellregions = grid[CellRegions]
135+
cellregions = cellcolors(grid, ctx[:cellcoloring])
136+
ncellregions = num_cellcolors(grid, ctx[:cellcoloring])
136137
cellnodes = grid[CellNodes]
137138
coord = grid[Coordinates] * ctx[:gridscale]
138-
ncellregions = grid[NumCellRegions]
139139
bfacenodes = grid[BFaceNodes]
140140
bfaceregions = grid[BFaceRegions]
141141
nbfaceregions = grid[NumBFaceRegions]

src/plutovista.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ function gridplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{1}}, grid)
9696
PlutoVista.backend!(ctx[:figure]; backend = ctx[:backend], datadim = 1)
9797

9898
coord = grid[Coordinates]
99-
cellregions = grid[CellRegions]
99+
cellregions = cellcolors(grid, ctx[:cellcoloring])
100+
ncellregions = num_cellcolors(grid, ctx[:cellcoloring])
100101
cellnodes = grid[CellNodes]
101102
coord = grid[Coordinates] * ctx[:gridscale]
102-
ncellregions = grid[NumCellRegions]
103103
bfacenodes = grid[BFaceNodes]
104104
bfaceregions = grid[BFaceRegions]
105105
nbfaceregions = grid[NumBFaceRegions]
106-
ncellregions = grid[NumCellRegions]
107106

108107
crflag = ones(Bool, ncellregions)
109108
brflag = ones(Bool, nbfaceregions)
@@ -224,14 +223,14 @@ function scalarplot!(ctx,
224223
end
225224

226225
function gridplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{2}}, grid)
227-
nregions = num_cellregions(grid)
226+
nregions = num_cellcolors(grid, ctx[:cellcoloring])
228227
nbregions = num_bfaceregions(grid)
229228
cmap = region_cmap(nregions)
230229
bcmap = bregion_cmap(nbregions)
231230
PlutoVista = ctx[:Plotter]
232231
pts = grid[Coordinates]
233232
tris = grid[CellNodes]
234-
markers = grid[CellRegions]
233+
markers = cellcolors(grid, ctx[:cellcoloring])
235234
edges = grid[BFaceNodes]
236235
edgemarkers = grid[BFaceRegions]
237236

@@ -316,16 +315,16 @@ end
316315
function streamplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{2}}, grid, func) end
317316

318317
function gridplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{3}}, grid)
319-
nregions = num_cellregions(grid)
320318
nbregions = num_bfaceregions(grid)
319+
nregions = num_cellcolors(grid, ctx[:cellcoloring])
321320
cmap = region_cmap(nregions)
322321
bcmap = bregion_cmap(nbregions)
323322

324323
PlutoVista = ctx[:Plotter]
325324
pts = grid[Coordinates]
326325
tris = grid[CellNodes]
327326
faces = grid[BFaceNodes]
328-
markers = grid[CellRegions]
327+
markers = cellcolors(grid, ctx[:cellcoloring])
329328
facemarkers = grid[BFaceRegions]
330329

331330
PlutoVista.backend!(ctx[:figure]; backend = ctx[:backend], datadim = 3)

src/pyplot.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{1}}, grid)
134134
ax = ctx[:ax]
135135
fig = ctx[:figure]
136136

137-
cellregions = grid[CellRegions]
137+
cellregions = cellcolors(grid, ctx[:cellcoloring])
138+
ncellregions = num_cellcolors(grid, ctx[:cellcoloring])
138139
cellnodes = grid[CellNodes]
139140
coord = grid[Coordinates]
140-
ncellregions = grid[NumCellRegions]
141141
bfacenodes = grid[BFaceNodes]
142142
bfaceregions = grid[BFaceRegions]
143143
nbfaceregions = grid[NumBFaceRegions]
144-
ncellregions = grid[NumCellRegions]
145144

146145
crflag = ones(Bool, ncellregions)
147146
brflag = ones(Bool, nbfaceregions)
@@ -213,11 +212,10 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid)
213212
end
214213
ax = ctx[:ax]
215214
fig = ctx[:figure]
216-
cellregions = grid[CellRegions]
215+
cellregions = cellcolors(grid, ctx[:cellcoloring])
216+
ncellregions = num_cellcolors(grid, ctx[:cellcoloring])
217217
cellnodes = grid[CellNodes]
218-
ncellregions = grid[NumCellRegions]
219218
nbfaceregions = grid[NumBFaceRegions]
220-
ncellregions = grid[NumCellRegions]
221219
if nbfaceregions > 0
222220
bfacenodes = grid[BFaceNodes]
223221
bfaceregions = grid[BFaceRegions]
@@ -229,7 +227,7 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid)
229227
tridat = tridata(grid, ctx[:gridscale])
230228
cmap = region_cmap(ncellregions)
231229
cdata = ax.tripcolor(tridat...;
232-
facecolors = grid[CellRegions],
230+
facecolors = cellcolors(grid, ctx[:cellcoloring]),
233231
cmap = PyPlot.ColorMap(cmap, length(cmap)),
234232
vmin = 1.0,
235233
vmax = length(cmap),)
@@ -310,6 +308,7 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{3}}, grid)
310308

311309
if ctx[:interior]
312310
regpoints0, regfacets0 = extract_visible_cells3D(grid, xyzcut; gridscale = ctx[:gridscale],
311+
cellcoloring = ctx[:cellcoloring],
313312
primepoints = hcat(xyzmin, xyzmax))
314313
regfacets = [reshape(reinterpret(Int32, regfacets0[i]), (3, length(regfacets0[i]))) for
315314
i = 1:nregions]

src/vtkview.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function gridplot!(ctx, TP::Type{VTKViewType}, grid)
5656
VTKView.simplexgrid!(ctx[:dataset], grid[Coordinates], grid[CellNodes])
5757
VTKView.boundarygrid!(ctx[:dataset], grid[BFaceNodes])
5858
VTKView.boundarymarker!(ctx[:dataset], grid[BFaceRegions])
59-
VTKView.cellmarker!(ctx[:dataset], grid[CellRegions])
59+
VTKView.cellmarker!(ctx[:dataset], cellcolors(grid, ctx[:cellcoloring]))
6060
if !haskey(ctx, :gridview)
6161
ctx[:gridview] = VTKView.GridView()
6262
VTKView.data!(ctx[:gridview], ctx[:dataset])

0 commit comments

Comments
 (0)