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 #1: Visualizing 2D and 3D Grid objects #16

Closed
fverdugo opened this issue May 21, 2021 · 8 comments
Closed

GSOC-Task #1: Visualizing 2D and 3D Grid objects #16

fverdugo opened this issue May 21, 2021 · 8 comments
Assignees
Labels

Comments

@fverdugo
Copy link
Member

fverdugo commented May 21, 2021

cc @paurierap @ericneiva @amartinhuertas

This task is to be further defined in the kick-off meeting

Intro

Being able to visualize instances of Gridap.Geometry.Grid is the cornerstone to visualize other Gridap objects. So, it is a good place to start.

Given a 2D Grid object (3D and 1D will be covered in subsequent tasks), we typically want the following kind of visualizations (now they are done with paraview). Here, I am using this code to generate a simple grid of triangles:

using Gridap
using Gridap.ReferenceFEs
using Gridap.Geometry
using Gridap.Visualization

model = CartesianDiscreteModel((0.,1.5,0.,1.),(15,10)) |> simplexify
grid = get_grid(model)
celldata = rand(num_cells(grid))
nodaldata = rand(num_nodes(grid))
write_vtk_file(grid,"grid",celldata=["d1"=>celldata],nodaldata=["d2"=>nodaldata])
fig1 fig2 fig3
surface surface and edges prescribe edge width
fig4 fig7 fig5
set surface and edge color set surface color via a cell field set surface color via a nodal field
fig6 fig8
display colorbar change colormap

TODO (outdated, see below for the updated steps)

  • Familiarize with Makie.jl and find out which are the low level plotting command needed to reproduce these images
  • Propose a user API to generate these figures in a convenient way
  • Implement the API (possibly by reusing code in the src folder)
  • Extend to quads

Notes

Most of the functionality we need is provided by the Makie function mesh, but it is likely that this does not cover all cases.

@fverdugo fverdugo changed the title CSOC-Task #1: Visualizing 2D Grid objects GSOC-Task #1: Visualizing 2D Grid objects May 21, 2021
@fverdugo fverdugo added the gsoc label May 21, 2021
@fverdugo
Copy link
Member Author

fverdugo commented Jun 7, 2021

Steps:

  • create a new branch gsoc2021-master (consensus branch, all test should pass)
  • Create you own work branch e.g. pr-task1 (you are free to use this branch as you want)
  • Clear code in GridapMakie module
  • Add Gridap="0.16" in Project.toml [compat] section. You perhaps need to resolve your environment at this point. pkg> resolve.
  • Implement conversion Griadp.Grid -> GeometryBasics.Mesh
function AbstractPlotting.convert_arguments(pt::PlotType, grid::Grid)
  convert_arguments(pt,UnstructuredGrid(grid))
end
function AbstractPlotting.convert_arguments(::PlotType, grid::UnstructuredGrid)  
  xs = get_node_coordinates(grid)
  Tp = eltype(eltype(xs))
  D = length(eltype(xs))
  ps = collect(reinterpret(GeometryBasics.Point{D,Tp},xs))
  cns = get_cell_node_ids(grid)
  Tf = eltype(eltype(cns))
  fs = collect(lazy_map(GeometryBasics.NgonFace{D+1,Tf},cns))
  m = GeometryBasics.Mesh(GeometryBasics.connect(ps,fs))
  m
end
  • Try to reproduce the plots above using Makie functions like mesh and wireframe. Add this code into a test.
  • Move from Travis to GH actions to run the tests.
  • Explore the extension to quadrilateral elements (i.e., remove simplexify).

@amartinhuertas
Copy link
Member

Some relevant links/info interchanged during 07/06/21 meeting:

Eric Neiva17:41
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev
- run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=@. -e 'using Pkg; Pkg.test(coverage=true)'
Eric Neiva17:43
https://github.com/JuliaPlots/GLMakie.jl/blob/master/.github/workflows/ci.yml
https://github.com/JuliaPlots/GLMakie.jl/blob/3762f689ec785ff40b429c9ecca7d81a54895ed0/.github/workflows/ci.yml#L41
Eric Neiva17:45
https://github.com/JuliaPlots/GLMakie.jl#troubleshooting-opengl

@fverdugo
Copy link
Member Author

fverdugo commented Jun 7, 2021

@paurierap perhaps it is better to use convert_single_argument instead of convert_arguments.

@fverdugo
Copy link
Member Author

fverdugo commented Jun 11, 2021

Some updated steps after the meeting on 2021-06-11:

  • gitignore .DS_STORE files
  • Add dependences of tests in the library Project.toml via pkg manager (for the moment).
  • import AbstractPlotting instead of Makie
  • Try to define conversion for all plot types at once (if possible). Try to use PlotType PlotFunc.
  • Extend conversion to quadrilaterals
    can makie represent quads?
    if yes: quad Grid -> quad Mesh -> Makie
    if no: quad Grid -> tri Mesh -> Makie (ok for plotting mesh, but not wireframe)

@paurierap
Copy link
Collaborator

Before the meeting on 21/06/2021, the conversions implemented from Gridap types to Makie types allow us to plot:

fig1 fig2 fig3
2D surface + set color (extended to quads too) 2D edges + set color and linewidth (only for simplices) 2D surface color via a nodal field + choice of colormap (and colorbar)
fig4 fig5 fig6
3D surface + set color (extended to quads too) 3D edges + set color and linewidth (only for simplices) 3D surface color via a nodal field + choice of colormap (and colorbar)

So far, we still need to address the drawing of quadrilateral edges in either dimension as well as the plotting of a cell field.

@fverdugo
Copy link
Member Author

Code discussed in meeting 2021-06-21 for visualizing 3D meshes. (i.e., convert volume mesh to boundary mesh of triangles)

using Gridap
using Gridap.Geometry
using Gridap.Visualization


domain = (0,1,0,1,0,1)
cells = (2,2,2)
grid = CartesianGrid(domain,cells)

write_vtk_file(grid,"grid")

topo = GridTopology(grid)

labels = FaceLabeling(topo)

model = DiscreteModel(grid,topo,labels)

face_grid = Grid(ReferenceFE{2},model)


face_to_mask = get_face_mask(labels,"boundary",2)

@show num_cells(face_grid)
@show length(face_to_mask)

write_vtk_file(face_grid,"face_grid",celldata=["mask"=>collect(Int,face_to_mask)])

boundary_grid = GridPortion(face_grid,face_to_mask) |> simplexify

write_vtk_file(boundary_grid,"boundary_grid")

@ericneiva ericneiva changed the title GSOC-Task #1: Visualizing 2D Grid objects GSOC-Task #1: Visualizing 2D and 3D Grid objects Jun 21, 2021
@fverdugo
Copy link
Member Author

fverdugo commented Jun 21, 2021

TODO steps

@fverdugo
Copy link
Member Author

closed via #18

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

3 participants