Closed fverdugo closed 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
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)
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)
.
Fixed by PR #24
Given
Ω::Triangulation
,uh::CellField
,cell_to_val::AbstractArray
, e.g.,We want to implement:
Example:
cell_nums
fromcells
. Otherwise, we cannot writecells(Ω)
, as it returnsMethodError: objects of type Tuple{Int64, Int64} are not callable
(spent more time that I should looking for the bug...)