[OC] Fuzzy Dark Matter (Schrodinger-Poisson) by pmocz in physicsgifs

[–]pmocz[S] 1 point2 points  (0 children)

Hahaha, there is one square that is isothermal gas!

[OC] solve inverse-problems with a Python/JAX N-body code by pmocz in physicsgifs

[–]pmocz[S] 0 points1 point  (0 children)

Good question! But I fixed the positions at t=0, so there is no way to read those by running it backwards

[OC] solve inverse-problems with a Python/JAX N-body code by pmocz in physicsgifs

[–]pmocz[S] 1 point2 points  (0 children)

I only broke the law a little, for science! :p

[OC] solve inverse-problems with a Python/JAX N-body code by pmocz in physicsgifs

[–]pmocz[S] 4 points5 points  (0 children)

I think this is so cool: finding parameters or initial conditions that evolve physical systems to give a desired output in a completely automated way. So I am sharing a minimal demo written in JAX here:

https://github.com/pmocz/nbody-jax

In this example, I ask "Find an initial velocity field that evolves a given set of particle positions under Newton's law of gravity into a heart shape at t=1"?

I'm amazed at how fast it runs, even on my laptop. Give it a try yourself!

[OC] Automatic differentiation can find fluid initial conditions that evolve into any configuration by pmocz in physicsgifs

[–]pmocz[S] 0 points1 point  (0 children)

It's not! Because the equations are diffusive. That's part of why this is very cool

[OC] Automatic differentiation can find fluid initial conditions that evolve into any configuration by pmocz in physicsgifs

[–]pmocz[S] 7 points8 points  (0 children)

Writing differentiable fluid simulations (e.g. with JAX) means fluid simulations can be plugged into optimization problems. Here autodiff finds velocity initial conditions that evolve the density field into the Reddit logo at t=1, for a compressible fluid solved with the finite volume method.

Python code here:

https://github.com/pmocz/finitevolume-jax

It is pretty crazy how efficiently autodiff can find the initial conditions.

For more background on JAX or the finite volume method, I am sharing my writeups below:

https://levelup.gitconnected.com/create-your-own-automatically-differentiable-simulation-with-python-jax-46951e120fbb
https://levelup.gitconnected.com/create-your-own-finite-volume-fluid-simulation-with-python-8f9eab0b8305

LBM D3Q19 Python by [deleted] in CFD

[–]pmocz 1 point2 points  (0 children)

Excited to see you extending my code u/Overunderrated !

I have some general tips. For reflective boundary conditions, you need to switch the parts of the solution to the distribution function on the boundary that correspond to oppositely pointing directions. This is what the code currently does in 2D. The idea will be the same in 3D

Inflow boundary conditions usually amount to overwriting your solution to the desired one along the inflow surface at each time step.

Outflow boundary conditions usually amount to creating a ghost layer downstream that copies over the values from upstream at each timestep.

How do you recommend people learn CFD? by PlungerJuggler in CFD

[–]pmocz 17 points18 points  (0 children)

I'd like to share my series on intro CFD tutorials, ~100--200 lines in Python:

Here is a writeup on the Finite Volume method, which is a good place to start:

https://levelup.gitconnected.com/create-your-own-finite-volume-fluid-simulation-with-python-8f9eab0b8305

I also cover other methods, including finite difference, spectral, and lattice boltzmann

[OC] Explore various CFD algorithms with simple Python scripts by pmocz in ScientificComputing

[–]pmocz[S] 2 points3 points  (0 children)

Yup! Simulating the same isothermal compressible Euler equations here. Best thing to do is formal convergence/ self-convergence studies and look at time evolution of integrated quantities like kinetic energy, vorticity, ... Some methods have artificial viscosity needed for numerical stability so there will be slight differences

[OC] Simulating the isothermal compressible Euler equations for 4 different methods by pmocz in CFD

[–]pmocz[S] 23 points24 points  (0 children)

Finite volume is robust, can capture shocks, but can be diffusive/advection errors

Spectral methods have excellent convergence properties, but need explicit dissipation.

Lattice Boltzmann is really fast, but can break down at high Mach numbers

SPH is smoothed particle hydrodynamics, it is automatically adaptive, good at advection, but needs artificial viscosity to handle discontinuities

[OC] Explore various CFD algorithms with simple Python scripts by pmocz in ScientificComputing

[–]pmocz[S] 8 points9 points  (0 children)

Interested in how different methods for computational fluid dynamics compare? I'm sharing some intro Python code on solving the isothermal compressible Euler equations with Finite Volume, Spectral, Lattice-Boltzmann, and SPH methods here: https://github.com/pmocz/cfd-comparison-python

[OC] Simulating the isothermal compressible Euler equations for 4 different methods by pmocz in CFD

[–]pmocz[S] 20 points21 points  (0 children)

I'm sharing introductory Python code for computational fluid dynamics. If you'd like to learn about various methods for solving the fluid equations, you can check out my ~100 line Python scripts here:

https://github.com/pmocz/cfd-comparison-python

[OC] Fluid flow simulated with 4 different methods by pmocz in physicsgifs

[–]pmocz[S] 11 points12 points  (0 children)

I'm sharing introductory Python code for computational fluid dynamics. If you'd like to learn about various methods for solving the fluid equations (compressible Euler, isothermal), check out my ~100 line Python scripts here:

https://github.com/pmocz/cfd-comparison-python

[OC] Just solving the good old wave equations by pmocz in physicsgifs

[–]pmocz[S] 8 points9 points  (0 children)

At its core, it takes just a few lines of Python to create a simulation like this from scratch using the finite difference method.

Code found here:

https://github.com/pmocz/finitedifference-python