Skip to content
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 #3: Visualizing Triangulation and CellField objects #21

Closed
fverdugo opened this issue Aug 3, 2021 · 4 comments
Closed

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

fverdugo opened this issue Aug 3, 2021 · 4 comments
Assignees
Labels

Comments

@fverdugo
Copy link
Member

fverdugo commented Aug 3, 2021

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?
  • Edit: I changed to name of the variable cell_nums from cells. Otherwise, we cannot write cells(Ω), as it returns MethodError: objects of type Tuple{Int64, Int64} are not callable (spent more time that I should looking for the bug...)
@fverdugo
Copy link
Member Author

fverdugo commented Aug 3, 2021

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
Copy link
Member Author

fverdugo commented Aug 3, 2021

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 paurierap changed the title GSOC-Task#3: Visualizing Triangulation and CellField objects GSOC-Task #3: Visualizing Triangulation and CellField objects Aug 3, 2021
@paurierap paurierap added the gsoc label Aug 3, 2021
@paurierap paurierap self-assigned this Aug 3, 2021
@paurierap
Copy link
Collaborator

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
Copy link
Member Author

Fixed by PR #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants