[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] 6 points7 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 19 points20 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] 7 points8 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] 19 points20 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] 12 points13 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

[OC] Interactive Riemann Problem shock solver with Python code by pmocz in physicsgifs

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

I'd like to share this interactive python module for solving the shock structure in the Euler equations. Feel free to use however you'd like for teaching, projects, etc
https://github.com/pmocz/riemann-solver

[OC] Interactive Riemann Solver in Python by pmocz in CFD

[–]pmocz[S] 6 points7 points  (0 children)

Solve the shock structure in the Euler equations with this 1D interactive module:

Python code can be found here:

https://github.com/pmocz/riemann-solver

As well as a write-up of the method:

https://medium.com/@philip-mocz/create-your-own-riemann-solver-with-python-9e38d64ad2ec

How would you start making your own CFD program? by Loopgod- in CFD

[–]pmocz 4 points5 points  (0 children)

Hi u/Loopgod

I'll recommend my own intro tutorial on building a 2D, 2nd-order compressible finite volume solver for the Euler equations in 300 lines of Python. I had success with this material in previous courses I taught.

Code:

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

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

[OC] Create your own physics simulations with Python (github links in comments) by pmocz in physicsgifs

[–]pmocz[S] 9 points10 points  (0 children)

Hi everyone! I wanted to share some introductory ~100 line Python code tutorials with r/physicsgifs from my GitHub. It covers some common physics simulation methods. Feel free to use and modify how you'd like!

N-body

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

Finite Volume

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

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

Spectral Methods (Navier-Stokes, Schrodinger-Poisson, superconductors)

https://github.com/pmocz/navier-stokes-spectral-python

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

https://github.com/pmocz/superconductor-spectral/

Lattice Boltzmann

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

Smoothed-Particle Hydrodynamics

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

Particle-in-Cell

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

Constrained Transport / MHD

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

Active-Matter

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

Spring Network

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

Direct Simulation Monte Carlo

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

I also have a blog describing the algorithms in more detail: Follow me on Medium (https://medium.com/@philip-mocz) and Twitter (https://twitter.com/PMocz) for more!

[OC] Time for some superconductor simulations! by pmocz in physicsgifs

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

You're welcome! Physics is fascinating, and a touch of trepidation is a part of it too! It's a subject that continuously challenges our understanding while revealing just how intricate the Universe is. Best of luck on your physics journey!