Created
December 9, 2020 23:26
-
-
Save j-fu/5bbaf0c6ba0d8a4f209ced72bec65014 to your computer and use it in GitHub Desktop.
Test Makie functionality on changing meshes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module trimakie | |
using Triangulate | |
using Makie | |
using GeometryBasics | |
""" | |
Create triangular mesh | |
""" | |
function trimesh(;vol=0.1) | |
tio=TriangulateIO() | |
tio.pointlist=Cdouble[0 0; | |
1 0; | |
1 1; | |
0 1]' | |
tio.segmentlist=[1 2; | |
2 3; | |
3 4; | |
4 1;]' | |
tri,voro=triangulate("pAqa$(vol)",tio) | |
tri | |
end | |
""" | |
Create mesh from triangulation | |
""" | |
function make_mesh(tio) | |
coord=tio.pointlist | |
cellnodes=tio.trianglelist | |
npoints=size(coord,2) | |
nfaces=size(cellnodes,2) | |
points=Vector{Point2f0}(undef,npoints) | |
for i=1:npoints | |
points[i]=Point2f0(coord[1,i],coord[2,i]) | |
end | |
faces=Vector{GLTriangleFace}(undef,nfaces) | |
for i=1:nfaces | |
faces[i]=TriangleFace(cellnodes[1,i],cellnodes[2,i],cellnodes[3,i]) | |
end | |
GeometryBasics.Mesh(points,faces) | |
end | |
""" | |
Plot evolution of finer and finer meshes | |
""" | |
function test1() | |
grid=trimesh(vol=0.1) | |
mnode=Makie.Node(make_mesh(grid)) | |
scene=Makie.Scene() | |
Makie.wireframe!(scene,lift(a->a,mnode)) | |
vol=0.1 | |
for i=1:50 | |
vol=vol*0.9 | |
mnode[]=make_mesh(trimesh(vol=vol)) | |
Makie.update!(scene) | |
Makie.display(scene) | |
Makie.sleep(1.0e-2) | |
end | |
end | |
""" | |
Plot changing function | |
""" | |
function test2() | |
grid=trimesh(vol=1.0e-3) | |
mnode=Makie.Node(make_mesh(grid)) | |
fac=1.0 | |
f(x,y)=sinpi(fac*x)*cospi((fac+1)*y) | |
coord=grid.pointlist | |
func=[f(coord[:,i]...) for i=1:size(coord,2)] | |
mnode=Makie.Node(make_mesh(grid)) | |
fnode=Makie.Node(func) | |
scene=Makie.Scene() | |
Makie.mesh!(scene,lift(a->a,mnode),color=lift(a->a,fnode),colormap="hot") | |
for i=1:50 | |
fac=fac+0.05 | |
fnode[]=[f(coord[:,i]...) for i=1:size(coord,2)] | |
Makie.update!(scene) | |
Makie.display(scene) | |
Makie.sleep(1.0e-2) | |
end | |
end | |
""" | |
Plot changing function on finer and finer meshes | |
""" | |
function test12() | |
grid=trimesh(vol=1.0e-3) | |
mnode=Makie.Node(make_mesh(grid)) | |
fac=1.0 | |
f(x,y)=sinpi(fac*x)*cospi((fac+1)*y) | |
coord=grid.pointlist | |
func=[f(coord[:,i]...) for i=1:size(coord,2)] | |
mnode=Makie.Node(make_mesh(grid)) | |
fnode=Makie.Node(func) | |
scene=Makie.Scene() | |
Makie.mesh!(scene,lift(a->a,mnode),color=lift(a->a,fnode),colormap="hot") | |
vol=0.1 | |
for i=1:50 | |
fac=fac+0.05 | |
vol=vol*0.9 | |
grid=trimesh(vol=vol) | |
tmesh=make_mesh(grid) | |
coord=grid.pointlist | |
mnode[]=tmesh | |
fnode[]=[f(coord[:,i]...) for i=1:size(coord,2)] | |
Makie.update!(scene) | |
Makie.display(scene) | |
Makie.sleep(1.0e-2) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment