# \[ANN\] WaterLily.jl: A differentiable fluid simulator with fast heterogeneous execution

**URL:** <https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941>\
**Category:** Package Announcements\
**Tags:** announcement, gpu\
**Created:** [April 26, 2023, 12:10pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941 "2023-04-26T12:10:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![b-fg](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@b-fg](https://discourse.julialang.org/u/b-fg)\
**Post date:** [April 26, 2023, 12:10pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/1 "2023-04-26T12:10:52Z")

</div>

**[WaterLily.jl](https://github.com/weymouth/WaterLily.jl) v1.0 is out! 🎉**

WaterLily is a simple and fast fluid simulator written in pure Julia. It solves the unsteady incompressible 2D or 3D [Navier-Stokes equations](https://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations) on a Cartesian grid. The pressure Poisson equation is solved with a [geometric multigrid](https://en.wikipedia.org/wiki/Multigrid_method) method. Solid boundaries are modelled using the [Boundary Data Immersion Method](https://eprints.soton.ac.uk/369635/).

[v1.0](https://github.com/weymouth/WaterLily.jl/releases/tag/v1.0.0) has ported the solver from a serial CPU execution to a backend-agnostic execution including multi-threaded CPU and GPU from different vendors (NVIDIA and AMD tested so far) thanks to [KernelAbstractions.jl](https://github.com/JuliaGPU/KernelAbstractions.jl). Compared to the previous serial version, we have benchmarked up to [x182 speed-up](https://arxiv.org/abs/2304.08159) on a GPU.

The most impressive fact is that the solver source code remains only around 800 LOC! We implement the `@loop` macro, which wraps `@kernel` from KernelAbstraction.jl and produces a kernel for an expression such as `@loop <expr> over <I in R>`, where `I` is a `CartesianIndex` and `R` is a `CartesianIndices` range. And just by changing the array type of our `Simulation` struct from `Array` to `CuArray` or `ROCArray`, we can run in CPU, NVIDIA GPUs, or AMD GPUs, respectively.

All this would not have been possible without [CUDA.jl](https://github.com/JuliaGPU/CUDA.jl), [AMDGPU.jl](https://github.com/JuliaGPU/AMDGPU.jl) and [KernelAbstractions.jl](https://github.com/JuliaGPU/KernelAbstractions.jl), so, again, thank you! ❤

Feel free to ping @weymouth or myself for more info 😄

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [April 26, 2023, 1:09pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/2 "2023-04-26T13:09:31Z")

</div>

The speed-up with GPUs enables impressive 3D flow simulations on a PC. This jelly fish simulation runs and visualizes real-time on my laptop:

[https://global.discourse-cdn.com/julialang/original/3X/e/0/e0f03ac8a3d715a1a4652156496eafaaab1fc1df.mp4](https://global.discourse-cdn.com/julialang/original/3X/e/0/e0f03ac8a3d715a1a4652156496eafaaab1fc1df.mp4)
  
And this 50 million degree-of-freedom turbulent flow simulation only took 30 minutes to run and render:  

[https://global.discourse-cdn.com/julialang/original/3X/8/2/82b318898da4e8e71d721e004653de43ac881986.mp4](https://global.discourse-cdn.com/julialang/original/3X/8/2/82b318898da4e8e71d721e004653de43ac881986.mp4)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [April 26, 2023, 1:41pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/3 "2023-04-26T13:41:48Z")

</div>

very impressive!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 26, 2023, 1:47pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/4 "2023-04-26T13:47:28Z")

</div>

What mathematical shape was used for the jellyfish? What was the size of the spatial grid and the time step?

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [April 26, 2023, 2:18pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/6 "2023-04-26T14:18:53Z")

</div>

Spherical shell sliced below the equator. Then pumped wider/shorter and narrower/longer to preserve the solid volume. All of this, and the resolution, is variable. [Take a look at the code](https://github.com/weymouth/WaterLily.jl/blob/master/examples/ThreeD_jelly.jl). The time step is automatically set by the CFL condition.

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [April 26, 2023, 6:59pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/7 "2023-04-26T18:59:59Z")

</div>

Very impressive!

What do you use for differentiation of the kernels, Enzyme?

---

<div class="post-metadata">

**Author:** ![ahmad\_saeed](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad_saeed/32/51651_2.png) [@ahmad\_saeed](https://discourse.julialang.org/u/ahmad_saeed)\
**Post date:** [March 3, 2024, 7:19pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/8 "2024-03-03T19:19:39Z")

</div>

I am trying some flapping airfoil simulations in waterlily. I am having difficulty about how to get moments of flapping airfoils in waterlily to calculate power coefficients? Is there any possible solution? Thanks

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 4, 2024, 9:06am UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/9 "2024-03-04T09:06:21Z")

</div>

That’s been done before, but it’s not a provided function. I suggest you might open an issue on the github.

---

<div class="post-metadata">

**Author:** ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)\
**Post date:** [March 8, 2024, 2:05pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/11 "2024-03-08T14:05:51Z")

</div>

impressive!

---

<div class="post-metadata">

**Author:** ![Arun\_Kumar\_Varanasi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arun_kumar_varanasi/32/211663_2.png) [@Arun\_Kumar\_Varanasi](https://discourse.julialang.org/u/Arun_Kumar_Varanasi)\
**Post date:** [August 29, 2024, 12:40pm UTC](https://discourse.julialang.org/t/ann-waterlily-jl-a-differentiable-fluid-simulator-with-fast-heterogeneous-execution/97941/12 "2024-08-29T12:40:19Z")

</div>

A quick question, can this be used to solve a single sphere settling in 3D in unbounded domains?
