Skip to content

Instantly share code, notes, and snippets.

@aegis1980
Last active August 8, 2021 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aegis1980/307dc98679e056a50bdfd470540f2917 to your computer and use it in GitHub Desktop.
Save aegis1980/307dc98679e056a50bdfd470540f2917 to your computer and use it in GitHub Desktop.
Modified TwoD_block.jl example for Waterlilly.jl' CFD library.
using WaterLily
using StaticArrays
function block(L=2^5;Re=250,U=1,amp=0,ϵ=0.5,thk=2ϵ+√2)
# Set viscosity
ν=U*L/Re
# Create dynamic block geometry
function sdf(x,t)
# SDF defines form a paddle (a rectangle)
y = x .- SVector(0.,clamp(x[2],-L/2,L))
# this confuses me! the last line of function is returned.
# so this the same as `return √sum(abs2,y)-thk/2`
√sum(abs2,y)-thk/2
end
function map(x,t)
α = -t*U/L # rotation of paddle at time 't' in simulation
R = @SMatrix [cos(α) sin(α); -sin(α) cos(α)] #2D rotation matrix
val = R * (x.-SVector(3L+L*sin(t*U/L)+0.01,3L+L*cos(t*U/L)+0.01))
return val
end
body = AutoBody(sdf,map)
Simulation((6L+2,6L+2),zeros(2),L;U,ν,body,ϵ) # new instance of Simulation
end
include("TwoD_plots.jl")
sim_gif!(block();duration=20π,step=π/32,remeasure=true,μbody=true,cfill=:Blues,legend=false,border=:none)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment