I have shown the Github robot a passing interest in CFD-related repos and it now suggests repos I might find interesting. Waterlilly.jl was the latest. It grabbed my attention since I initially misread “WaterLily.jl is a simple and fast fluid simulator…” as “WaterLily.jl is a (very) fast (i.e. realtime) fluid simulator…”. I dabbled in Fast Fluid Dynamics (FFD) a while ago – hope to pick it up again soon.
Waterlily.jl is not an FFD simulator (things take a while to solve). Anyway these different simulation implementations are well beyond my abilities, but I wanted to have a little play with Waterlily.jl. Unfortunately (or fortunately, depending on your perspective) it is written in Julia, a language I had never heard of.
Julia setup
FYI: I got things going eventually with some screwing around (mostly to do with adding dependencies) and the steps below are what I can remember doing! You will need to fill in the gaps.
I am using VS Code on a Win10 machine. You need to install Julia from julialang.org/downloads/, and the VS Code Julia extension and clone the Waterlilly.jl repo.
Like Python, you can set up a local/ project-specific Julia environment, which I did…
From PowerShell/terminal in cloned repo’s root directory:
- type
julia
to enter julia REPL ]
will enter the pkg REPL (akin to Python’s pip, I think )activate .
(including full-stop) activates the local environment. The waterlly.jl repo containers a Project.toml file which describes the environment (eg its dependencies)- Type
instantiate
to add waterlily.jl’s dependencies (takes a while) - To run code in
examples/
I just click the run button with example file open in VS Code. THe computer thinks for a bit then starts clicking out iteration info in console as it solves.
Tentative toe-dip into Julia
GIF below shows one of the 2D samples in the repo, moving a paddle through a fluid. It is generated by running TwoD_block.jl
in examples/
My version below just modifies the motion to a circular mixing motion. The paddle is also 50% longer, simulation time increased and time-step reduced.
In hindsight starting with Julia via CFD is probably not a great place to start, but more interesting than ‘hello world’….and I am not really ‘doing’ CFD – this is all done by people who know what they are doing.
I found this set of instructions good as a reference & introduction to Julia. Plus some useful tit-bits I worked out after some head-scratching along the way:
- Arrays are indexed starting with 1, not zero (link), eg
x[2]
in line 13 above. - Array broadcasting (as a syntatic thing), eg
.-
in line 13 - If no implicit return in function, the result of the last line is returned (not sure if this is so in other non-typed languages like Python and Javacript), eg the result of
√sum(abs2,y)-thk/2
in returned in line 16 - unicode symbols for varables and functions, eg
ϵ
and√
in line 6. You access these (in VSCode) using latex-eque syntax, so\delta
forδ
. Certainly make things more readable. - Function names ending with
!
modify the parameters assed to them. This is by convention, so more a stylistic thing I think. egsim_gif!
called in line 32 could be calledsim_gif
but in doing so we would be (wrongly) suggesting that the parameters passed to is un unaltered in the function – the simulation instance returned byblock()
is altered insim_gif
function. - Line ending
;
is not required, but can be used, eg line 20
Anyway. All kind of interesting in an alternative-option-to-Python sort of way?