gridap / GridapMakie.jl

Makie plotting recipes for Gridap
MIT License
34 stars 8 forks source link

GSOC-Task #3: Visualizing Triangulation and CellField objects #21

Closed fverdugo closed 3 years ago

fverdugo commented 3 years ago

Given Ω::Triangulation, uh::CellField, cell_to_val::AbstractArray, e.g.,

using Gridap
domain = (0,1,0,1)
cell_nums = (10,10)
model = CartesianDiscreteModel(domain,cell_nums) |> simplexify
Ω = Triangulation(model)
Γ = BoundaryTriangulation(model)
Λ = SkeletonTriangulation(model)
u = CellField(x->x[1]+x[2],Ω)

We want to implement:

cells(Ω,uh,color=:green)
cells(Ω,color=:green)
cells(Ω,color=uh)
cells(Ω,color=cell_to_val)

edges(Ω)
edges(Ω,color=:green)
plot(Ω,uh)  # alias for:
cells(Ω,color=uh)

plot(uh) # alias for:
plot(get_triangulation(uh),uh)

Example:

plot(Γ,uh)
edges!(Γ,color=:blue) # edges!() possible?
fverdugo commented 3 years ago

More examples:

using Gridap
using Gridap.ReferenceFEs
using Gridap.Geometry
using CairoMakie
using GridapMakie
using FileIO

model = CartesianDiscreteModel((0.,1.5,0.,1.),(15,10)) |> simplexify
Ω = Triangulation(model)
u = CellField(x->x[1]+x[2],Ω)
celldata = rand(num_cells(grid))

# Fig. 1: surface 
fig, = plot(Ω)
save("fig_1.png",fig)

# Fig. 2: surface and edges 
fig, = plot(Ω)
edges!()
save("fig_2.png",fig)

# Fig. 3: prescribe edge width 
fig, = plot(Ω)
edges!(linewidth=2.5)
save("fig_3.png",fig)

# Fig. 4: set surface and edge color 
fig, = plot(Ω,:green)
edges!(color=:red,linewidth=2.5)
save("fig_4.png",fig)

# Fig. 5: set surface color via a cell field
fig, = plot(Ω,celldata)
save("fig_5.png",fig)

# Fig. 6: set surface color via a nodal field
fig, = plot(uh)
save("fig_6.png",fig)

# Fig. 7: display colorbar 
fig,ax,tp = plot(uh)
Colorbar(fig[1,2],tp)
save("fig_7.png",fig)

# Fig. 8: change colormap
fig,ax,tp = plot(uh,colormap=:heat,colorrange=[0,1.])
Colorbar(fig[1,2],tp)
save("fig_8.png",fig)

# Fig. 9: edge color via nodal field
# not doable in this case
fverdugo commented 3 years ago

Implementation remarks

The idea us to transform Ω and uh to grid and node_to_val using Gridap.Visualization.visualization_data

cells(Ω,color=uh)

# equivalent to:
vds = visualization_data(Ω,"",cellfields=[""=>Operation(to_scalar)(uh)])
grid = first(vds).grid
node_to_val = first(first(vds).nodaldata)
cells(grid,color=node_to_val)

to_scalar(a) = norm(a)
paurierap commented 3 years ago

Unfortunately, there appears to be an issue when using cells(Ω,color=uh), since Makie does not accept uh as a valid color type. It hence returns the error Unsupported Color type: Gridap.CellData.GenericCellField{PhysicalDomain}. As a workaround, I propose using the attribute celldata and nodaldata for cells, even though this is hidden for plot, since we can achieve plot(Ω,uh).

fverdugo commented 3 years ago

Fixed by PR #24