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

Work Product of GSoC 2021 project "[Gridap] Visualizing PDE approximations in Julia with Gridap.jl and Makie.jl" #24

Merged
merged 60 commits into from Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
748e700
GridapMakie module clean-up
paurierap Jun 8, 2021
07811af
Mesh and wireframe for Grid
paurierap Jun 9, 2021
d4691e9
Update GridapMakie.jl
paurierap Jun 9, 2021
3d994da
Add tests for nodaldata
paurierap Jun 11, 2021
591dfd1
.DS_Store banished!
paurierap Jun 11, 2021
a794478
Quads, colormap & colorbar
paurierap Jun 14, 2021
79fa6e8
MeshViz introduction
paurierap Jun 16, 2021
4884d0f
Conversion 2D and 3D
paurierap Jun 20, 2021
56b4fe0
changes during meeting (to be tested) [ci skip]
fverdugo Jun 21, 2021
4204cae
push 29/06
paurierap Jun 29, 2021
c4097f4
Refactoring of conversions
fverdugo Jun 29, 2021
3ddfea9
Merge pull request #18 from gridap/paur-task1
fverdugo Jun 29, 2021
bcadf31
Edges and Faces
paurierap Jul 5, 2021
9d71683
Revert "Edges and Faces"
paurierap Jul 5, 2021
82f4415
Faces and Edges
paurierap Jul 5, 2021
464639a
to_egde_grid
paurierap Jul 6, 2021
7e64ef5
all plots task2
paurierap Jul 12, 2021
45823ac
Fix 3D heatmap
paurierap Jul 16, 2021
dc9f075
Change single color edges
paurierap Jul 16, 2021
5e64451
Pre-meeting 20/07
paurierap Jul 19, 2021
7aa9963
Implementation dg_mesh
paurierap Jul 29, 2021
b6f9d29
Avoid boundary plot
paurierap Aug 2, 2021
e38b818
Some redesign of recipies
fverdugo Aug 9, 2021
e36cab6
Start of Task 3
paurierap Aug 9, 2021
8a61f6e
Fix GridapMakie.jl includes
paurierap Aug 9, 2021
8b3fecd
Add a last test
paurierap Aug 9, 2021
1ea60aa
saving changes
fverdugo Aug 10, 2021
72168c8
Merge branch 'paur-task2' of github.com:gridap/GridapMakie.jl into fv
fverdugo Aug 10, 2021
f464536
Solving issues related with observables
fverdugo Aug 10, 2021
5f5c398
Task 4
paurierap Aug 16, 2021
fbf5674
Saving dirty fix
fverdugo Aug 18, 2021
1e50428
Saving changes
fverdugo Aug 18, 2021
c04bd2e
Fixing normal_mesh calls
fverdugo Aug 18, 2021
1a7421f
Fixing color in 3d plots
fverdugo Aug 18, 2021
5275c84
Fixed shading for volume meshes (surface meshes pending)
fverdugo Aug 18, 2021
0b5495f
Adding also 3D tests. Some are broken.
fverdugo Aug 18, 2021
51f198b
README and removing themes
paurierap Aug 19, 2021
f79149f
Removing old png files
amartinhuertas Aug 20, 2021
f7ed6e6
Creating void file within images subfolder
amartinhuertas Aug 20, 2021
c758a56
Tentative figures for README.jl
fverdugo Aug 20, 2021
e3646d9
Merge branch 'paur-task4' of github.com:gridap/GridapMakie.jl into pa…
fverdugo Aug 20, 2021
68352b6
Fixing unwanted calls to norm
fverdugo Aug 20, 2021
5bbbd40
Trying to fix using GLMakie on CI
fverdugo Aug 20, 2021
85ecc21
removing test_broken
fverdugo Aug 20, 2021
aa1ffe1
Merge pull request #25 from gridap/paur-task4
fverdugo Aug 20, 2021
bf4378e
Adding [compat] entry in Project.toml as prerequisite to registering
amartinhuertas Aug 20, 2021
ec81ea2
Update README
paurierap Aug 20, 2021
f0d8d92
Update README.md
paurierap Aug 20, 2021
69d26ee
Update README.md
paurierap Aug 20, 2021
12b0ad2
README changes 1
paurierap Aug 20, 2021
e9750f2
Merge branch 'gsoc2021-master' of https://github.com/gridap/GridapMak…
paurierap Aug 20, 2021
ded7b10
Update 2d_Fig13.png
paurierap Aug 20, 2021
2d354d2
Update README.md
paurierap Aug 20, 2021
087d2be
Update README.md
paurierap Aug 20, 2021
0bec595
README version 2
paurierap Aug 20, 2021
d5d7419
README version 3
paurierap Aug 21, 2021
59d4e9b
Eric review fixes
paurierap Aug 21, 2021
da571c5
README final version
paurierap Aug 21, 2021
0cf6953
Resize README images
paurierap Aug 22, 2021
3f91a21
Center-align README images
paurierap Aug 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,56 @@
name: CI
paurierap marked this conversation as resolved.
Show resolved Hide resolved
on: [push, pull_request]
jobs:
test:
name: Tests ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.6'
os:
- ubuntu-18.04
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- 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
- uses: julia-actions/julia-buildpkg@v1
- run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=@. -e 'using Pkg; Pkg.test(coverage=true)'
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.6'
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()
Pkg.build()'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
/docs/build/
Manifest.toml
.DS_Store
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

4 changes: 0 additions & 4 deletions Justfile

This file was deleted.

22 changes: 14 additions & 8 deletions Project.toml
Expand Up @@ -4,20 +4,26 @@ authors = ["Francesc Verdugo <fverdugo@cimne.upc.edu>", "Jan Weidner <jw3126@gma
version = "0.1.0"

[deps]
AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e"
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[compat]
julia = "1.4"
CairoMakie = "0.6"
FileIO = "1"
FillArrays = "0.12"
GLMakie = "0.4"
GeometryBasics = "0.3"
Gridap = "0.16"
Makie = "0.15"
julia = "1.6"

[extras]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Makie", "FileIO", "ImageMagick"]
test = ["Test"]
198 changes: 142 additions & 56 deletions README.md
@@ -1,83 +1,169 @@
```@meta
EditURL = "<unknown>/README.jl"
```

# GridapMakie

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://gridap.github.io/GridapMakie.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://gridap.github.io/GridapMakie.jl/dev)
[![Build Status](https://travis-ci.com/gridap/GridapMakie.jl.svg?branch=master)](https://travis-ci.com/gridap/GridapMakie.jl)
[![Build Status](https://github.com/gridap/GridapMakie.jl/workflows/CI/badge.svg?branch=master)](https://github.com/gridap/GridapMakie.jl/actions)
[![Coverage](https://codecov.io/gh/gridap/GridapMakie.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/gridap/GridapMakie.jl)

# This package is experimental
## Overview

Things can and will break without deprecation or warning
The visualization of numerical results is an important part of finite element (FE) computations. However, before the inception of GridapMakie.jl, the
only approach available to data visualization of [Gridap.jl](https://github.com/gridap/Gridap.jl) computations was to write simulation
data to data files (e.g., in vtu format) for later visualization with, e.g., Paraview or VisIt. From the idea of visually inspecting
data from Julia code directly or to manipulate it with packages of the Julia
open-source package ecosystem, [GridapMakie.jl](https://github.com/gridap/GridapMakie.jl) is born. As a part of the Google Summer of
Code 2021 program, GridapMakie adopts [Makie.jl](https://github.com/JuliaPlots/Makie.jl) as a second visualization back-end for
Gridap.jl simulations. This package is thought as a built-in tool to assess the user in their FE calculations with a smoother workflow
in a highly intuitive API.

# Examples
## Installation

```@example README
using Gridap, GridapMakie, Makie
According to Makie's guidelines, it is enough to install one of its backends, e.g. GLMakie. Additionally, Gridap provides the plot objects
to be visualized and `FileIO` allows to save the figures plotted.

model = simplexify(CartesianDiscreteModel((-2pi,2pi,-pi,pi), (20,10)))
scene = plot(model)
```julia
julia> ]
pkg> add Gridap, GridapMakie, GLMakie, FileIO
```

![](_readme/images/2d.png)
## Examples

```@example README
data = GridapMakie.demo_data(spacedim=1, valuetype=Float64)
scene = plot(data.u, data.model)
```
First things first, we shall be using the three packages as well as `FileIO`.
We may as well create directories to store downloaded meshes and output files

![](_readme/images/plot_1d_Scalar.png)
````julia
using Gridap, GridapMakie, GLMakie
using FileIO
mkdir("models")
mkdir("images")
````

```@example README
model = simplexify(CartesianDiscreteModel((-2pi,2pi,-pi,pi), (10,10)))
V = TestFESpace(reffe=:Lagrangian, order=1, valuetype = Float64,
conformity=:H1, model=model)
f(pt) = sin(pt[1])*cos(pt[2])
u = interpolate(V, f)
scene = mesh(u, model, color=:yellow)
```
### 2D Plots

![](_readme/images/mesh_2d_Scalar.png)
Then, let us consider a simple, 2D simplexified cartesian triangulation Ω

```@example README
model = simplexify(CartesianDiscreteModel((-2pi,2pi,-pi,pi), (10,10)))
V = TestFESpace(reffe=:Lagrangian, order=1, valuetype = Float64,
conformity=:H1, model=model)
f(pt) = sin(pt[1])*cos(pt[2])
u = interpolate(V, f)
scene = wireframe(u, model)
```
````julia
domain = (0, 1, 0, 1)
cell_nums = (10, 10)
model = CartesianDiscreteModel(domain, cell_nums) |> simplexify
Ω = Triangulation(model)
````

![](_readme/images/wireframe_2d_Scalar.png)
The visualization of the vertices, edges, and faces of Ω can be achieved as follows

```@example README
model = CartesianDiscreteModel((-1,1,-1,1), (10,10))
V = TestFESpace(reffe=:Lagrangian, order=1, valuetype = VectorValue{2, Float64},
conformity=:H1, model=model)
f(pt) = VectorValue(-pt[2], pt[1])
u = interpolate(V, f)
scene = arrows(u, model, arrowsize=0.1, lengthscale=0.5)
```
````julia
fig = plot(Ω)
wireframe!(Ω, color=:black, linewidth=2)
scatter!(Ω, marker=:star8, markersize=20, color=:blue)
save("images/2d_Fig1.png", fig)
````

![](_readme/images/arrows_2d_Vec2d.png)
![](_readme/images/2d_Fig1.png)
paurierap marked this conversation as resolved.
Show resolved Hide resolved

```@example README
model = CartesianDiscreteModel((-1,1,-1,1, -1, 1), (10,10, 10))
V_pressure = TestFESpace(reffe=:Lagrangian, order=1, valuetype=Float64, conformity=:H1, model=model)
V_velo = TestFESpace(reffe=:Lagrangian, order=1, valuetype=VectorValue{3, Float64},
conformity=:H1, model=model)
We now consider a FE function `uh` constructed with Gridap

pressure = interpolate(V_pressure, pt -> pt[1]*pt[2]*pt[3])
velocity = interpolate(V_velo, pt -> VectorValue(-pt[3]*pt[2],pt[3]*pt[1], 0.1*pt[1]*pt[2]))
````julia
reffe = ReferenceFE(lagrangian, Float64, 1)
V = FESpace(model, reffe)
uh = interpolate(x->sin(π*(x[1]+x[2])), V)
````

color = GridapMakie.to_visualization_data(pressure, model) |> GridapMakie.get_nodalvalues
scene = arrows(velocity, model, arrowsize=0.1, lengthscale=0.2, arrowcolor=color)
```
and plot it over Ω, adding a colorbar

````julia
fig, _ , plt = plot(Ω, uh)
Colorbar(fig[1,2], plt)
save("images/2d_Fig11.png", fig)
````

![](_readme/images/2d_Fig11.png)

On the other hand, we may as well plot cell values

````julia
celldata = π*rand(num_cells(Ω)) .-1
fig, _ , plt = plot(Ω, color=celldata, colormap=:heat)
Colorbar(fig[2,1], plt, vertical=false)
save("images/2d_Fig13.png", fig)
````

![](_readme/images/2d_Fig13.png)

If we are only interested in the boundary of Ω, namely Γ

````julia
Γ = BoundaryTriangulation(model)
fig, _ , plt = plot(Γ, uh, colormap=:algae, linewidth=10)
Colorbar(fig[1,2], plt)
save("images/2d_Fig111.png", fig)
````

![](_readme/images/2d_Fig111.png)

### 3D Plots

In addition to the 2D plots, GridapMakie is able to handle more complex geometries. For example,
take the mesh from the [first Gridap tutorial](https://gridap.github.io/Tutorials/stable/pages/t001_poisson/#Tutorial-1:-Poisson-equation-1),
which can be downloaded using

````julia
url = "https://github.com/gridap/GridapMakie.jl/raw/d5d74190e68bd310483fead8a4154235a61815c5/_readme/model.json"
download(url,"models/model.json")
````

Therefore, we may as well visualize such mesh

````julia
model = DiscreteModelFromFile("models/model.json")
Ω = Triangulation(model)
∂Ω = BoundaryTriangulation(model)
fig = plot(Ω, shading=true)
wireframe!(∂Ω, color=:black)
save("images/3d_Fig1.png", fig)
````

![](_readme/images/3d_Fig1.png)

````julia
v(x) = sin(π*(x[1]+x[2]+x[3]))
fig, ax, plt = plot(Ω, v, shading=true)
Colorbar(fig[1,2], plt)
save("images/3d_Fig3.png", fig)
````

![](_readme/images/3d_Fig3.png)

we can even plot functions in certain subdomains, e.g.

````julia
Γ = BoundaryTriangulation(model, tags=["square", "triangle", "circle"])
fig = plot(Γ, v, colormap=:rainbow, shading=true)
wireframe!(∂Ω, linewidth=0.5, color=:gray)
save("images/3d_Fig2.png", fig)
````

![](_readme/images/3d_Fig2.png)

### Animations and interactivity

Finally, by using Makie [Observables](https://makie.juliaplots.org/stable/interaction/nodes.html), we
can create animations or interactive plots. For example, if the nodal field has a time dependence

![](_readme/images/arrows_3d_Vec3d_Fancy.png)
````julia
t = Observable(0.0)
u = lift(t) do t
x->sin(π*(x[1]+x[2]+x[3]))*cos(π*t)
end
fig = plot(Ω, u, colormap=:rainbow, shading=true, colorrange=(-1,1))
wireframe!(∂Ω, color=:black, linewidth=0.5)
framerate = 30
timestamps = range(0, 2, step=1/framerate)
record(fig, "images/animation.gif", timestamps; framerate=framerate) do this_t
t[] = this_t
end
````

![](_readme/images/animation.gif)

---

Expand Down
1 change: 1 addition & 0 deletions _readme/Project.toml
@@ -1,5 +1,6 @@
[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
GridapMakie = "41f30b06-6382-4b60-a5f7-79d86b35bf5d"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Expand Down