-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSOC-Task #2: Implement Faces and Edges recipies for Grid #17
Comments
Some comments:
|
This function would extract the "edge" skeleton of a given grid: function to_edge_grid(grid::UnstructuredGrid)
topo = GridTopology(grid)
labels = FaceLabeling(topo)
model = DiscreteModel(grid,topo,labels)
edge_grid = Grid(ReferenceFE{1},model)
end thus using this function, |
I have edited the code snippet in #17 (comment) to fix some inconsistencies with the figure numbering. Now, I think the snippet and the figures below match. |
Comments on the current implementation:
|
Task 2 final API & RemarksThe implementation of both using Gridap
using Gridap.ReferenceFEs
using Gridap.Geometry
using CairoMakie
using GridapMakie
using FileIO
model = CartesianDiscreteModel((0.,1.5,0.,1.),(15,10)) |> simplexify
grid = get_grid(model)
celldata = rand(num_cells(grid))
nodaldata = rand(num_nodes(grid))
# Fig. 1: surface
fig = faces(grid)
save("fig_1.png", fig)
# Fig. 2: surface and edges
fig, ax = faces(grid)
edges!(ax, grid)
save("fig_2.png", fig)
# Fig. 3: prescribe edge width
fig, ax = faces(grid)
edges!(ax, grid, linewidth=2.5)
save("fig_3.png", fig)
# Fig. 4: set surface and edge color
fig, ax = faces(grid, color=:lightseagreen)
edges!(ax, grid, color=:darkslategray)
save("fig_4.png", fig)
# Fig. 5: set surface color via a cell field
fig = faces(grid, color=celldata, fieldstyle=:cells)
save("fig_5.png", fig)
# Fig. 6: set surface color via a nodal field
fig = faces(grid, color=nodaldata, fieldstyle=:nodes)
save("fig_6.png", fig)
# Fig. 7: display colorbar
fig, ax, plt = faces(grid, color=nodaldata, colorrange=(0,1))
Colorbar(fig[1,2], plt, ticks=0:0.25:1)
save("fig_7.png",fig)
# Fig. 8: change colormap
fig, ax, plt = faces(grid, color=nodaldata, colormap=:heat, colorrange=(0,1))
Colorbar(fig[1,2], plt, ticks=0:0.25:1)
save("fig_8.png",fig)
# Fig. 9: edge color via nodal field
fig, ax, plt = edges(grid, color=nodaldata, colorrange=(0,1))
Colorbar(fig[1,2], plt, ticks=0:0.25:1)
save("fig_9.png",fig)
The outcome of the figures will be:
|
Great! Is the code in this branch ready to merge? |
Not yet. We still need to account for general polytopes in the cell field plot, which should be fixed as soon as we have the simplex-to-face mapping. |
Excellent job, Pau! 👏 I am happy to see that you can do all the plots with the planned interface (with the only change of superposing the plots on the axis). |
Wow both figures and API look really nice! Great Job! |
Pull requested! There is just the minor detail of cell fields with quads but should be soon fixed. |
Hi @paurierap! Let's take a look at your PR tomorrow. |
How to compute boundary grid and corresponding boundary face to cell map: function to_boundary_grid_with_map(grid::Grid)
Df = 2
Dc = 3
topo = GridTopology(grid)
labels = FaceLabeling(topo)
model = DiscreteModel(grid,topo,labels)
face_grid = Grid(ReferenceFE{Df},model)
face_to_mask = get_face_mask(labels,"boundary",Df)
face_to_cells = get_faces(topo,Df,Dc)
face_to_cell = lazy_map(first,face_to_cells)
bface_to_face = findall(face_to_mask)
bface_to_cell = lazy_map(Reindex(face_to_cell),bface_to_face)
GridPortion(face_grid,bface_to_face), bface_to_cell
end
|
How to plot discontinuous fields (in particular cell-weise constant data) using Gridap
using Gridap.Geometry
using Gridap.ReferenceFEs
using CairoMakie
using Makie.GeometryBasics
using FileIO
function to_point(x::VectorValue{D,T}) where {D,T}
GeometryBasics.Point{D,T}(Tuple(x))
end
function to_dg_mesh(grid)
ps = to_dg_points(grid)
Dc = num_cell_dims(grid)
Tc = Int32
cns = Vector{Vector{Tc}}(undef,num_cells(grid))
i = 1
for cell in 1:num_cells(grid)
cn = zeros(Tc,Dc+1)
for lnode in 1:(Dc+1)
cn[lnode] = i
i += one(Tc)
end
cns[cell] = cn
end
fs = lazy_map(GeometryBasics.NgonFace{Dc+1,Tc},cns) |> collect
GeometryBasics.connect(ps,fs) |> GeometryBasics.Mesh |> GeometryBasics.normal_mesh
end
function to_dg_points(grid)
node_x = get_node_coordinates(grid)
coords = to_dg_node_values(grid,node_x)
ps = [ to_point(x) for x in coords]
ps
end
function to_dg_node_values(grid,node_value)
cell_nodes = get_cell_node_ids(grid)
i = 0
cache = array_cache(cell_nodes)
for cell in 1:length(cell_nodes)
nodes = getindex!(cache,cell_nodes,cell)
for node in nodes
i += 1
end
end
T = eltype(node_value)
values = zeros(T,i)
i = 0
for cell in 1:length(cell_nodes)
nodes = getindex!(cache,cell_nodes,cell)
for node in nodes
i += 1
values[i] = node_value[node]
end
end
values
end
function to_dg_cell_values(grid,cell_value)
cell_nodes = get_cell_node_ids(grid)
i = 0
cache = array_cache(cell_nodes)
for cell in 1:length(cell_nodes)
nodes = getindex!(cache,cell_nodes,cell)
for node in nodes
i += 1
end
end
T = eltype(cell_value)
values = zeros(T,i)
i = 0
for cell in 1:length(cell_nodes)
nodes = getindex!(cache,cell_nodes,cell)
for node in nodes
i += 1
values[i] = cell_value[cell]
end
end
values
end
n=5
domain = (0,1,0,1)
cells = (n,n)
model = CartesianDiscreteModel(domain,cells) |> simplexify
grid2 = Grid(ReferenceFE{2},model)
grid1 = Grid(ReferenceFE{1},model)
grid0 = Grid(ReferenceFE{0},model)
data2 = 2*rand(num_faces(model,2))
data1 = 2*rand(num_faces(model,1))
data0 = 2*rand(num_faces(model,0))
mesh2 = to_dg_mesh(grid2)
values2 = to_dg_node_values(grid2,data0)
fig,ax,sc = mesh(mesh2,color=values2)
save("f_2d_2_0.png",fig)
values2 = to_dg_cell_values(grid2,data2)
fig,ax,sc = mesh(mesh2,color=values2)
save("f_2d_2_2.png",fig)
ps1 = to_dg_points(grid1)
values1 = to_dg_node_values(grid1,data0)
fig,ax,sc = linesegments(ps1,color=values1)
save("f_2d_1_0.png",fig)
ps1 = to_dg_points(grid1)
values1 = to_dg_cell_values(grid1,data1)
fig,ax,sc = linesegments(ps1,color=values1)
save("f_2d_1_1.png",fig)
ps0 = to_dg_points(grid0)
values0 = to_dg_node_values(grid0,data0)
fig,ax,sc = scatter(ps0,color=values0)
save("f_2d_0_0.png",fig)
fig,ax,sc = mesh(mesh2,color=rand(length(coordinates(mesh2))))
linesegments!(ps1,color=:yellow)
scatter!(ps0,color=:cyan)
save("f_2d_012.png",fig)
# now in 3d
domain = (0,1,0,1,0,1)
cells = (n,n,n)
model = CartesianDiscreteModel(domain,cells) |> simplexify
grid2 = Grid(ReferenceFE{2},model)
grid1 = Grid(ReferenceFE{1},model)
grid0 = Grid(ReferenceFE{0},model)
data2 = 2*rand(num_faces(model,2))
data1 = 2*rand(num_faces(model,1))
data0 = 2*rand(num_faces(model,0))
mesh2 = to_dg_mesh(grid2)
values2 = to_dg_node_values(grid2,data0)
fig,ax,sc = mesh(mesh2,color=values2)
save("f_3d_2_0.png",fig)
values2 = to_dg_cell_values(grid2,data2)
fig,ax,sc = mesh(mesh2,color=values2)
save("f_3d_2_2.png",fig)
ps1 = to_dg_points(grid1)
values1 = to_dg_node_values(grid1,data0)
fig,ax,sc = linesegments(ps1,color=values1)
save("f_3d_1_0.png",fig)
ps1 = to_dg_points(grid1)
values1 = to_dg_cell_values(grid1,data1)
fig,ax,sc = linesegments(ps1,color=values1)
save("f_3d_1_1.png",fig)
ps0 = to_dg_points(grid0)
values0 = to_dg_node_values(grid0,data0)
fig,ax,sc = scatter(ps0,color=values0)
save("f_3d_0_0.png",fig)
fig,ax,sc = mesh(mesh2,color=rand(length(coordinates(mesh2))))
linesegments!(ps1,color=:yellow,linewidth=4)
scatter!(ps0,color=:cyan,markersize=30)
save("f_3d_012.png",fig)
Edit: Added |
|
|
Comments on the current implementation v2:
|
Fixed by PR #24 |
In meeting on 2021-06-21, we agreed to introduce a new recipie, namelySurfaceWithEdges
,surfacewithedges
. Surface and wireframe plot will be a particular case.I think that is better to have two separate recipies (this will be much more modular). I would call these recipies
Faces
andEdges
for the plot types andfaces
andedges
will be the functions automatically created by the@recipie
macro.With these recipies, we want to reproduce ALL plots in #16, in 1D, 2D, 3D, and different cell types, (e.g., quads and tris) in an unified API.
The text was updated successfully, but these errors were encountered: