You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2025-06-05-nr105.markdown
+25-41Lines changed: 25 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,9 @@ First up: Some background (and a dog)
24
24
25
25
# What is hydrodynamics?
26
26
27
-
If you're like me, at some point you might not even really have known why hydrodynamics is a separate area of inquiry to solving differential equations in general. Or, you might think it's an umbrella term for people who solve PDEs which just so happen involve fluids, but that it's pretty much the same as anything else
27
+
If you're like me, at some point you might not even really have known why hydrodynamics is a separate area of inquiry to solving differential equations in general. Or, you might think it's an umbrella term for people who solve PDEs which just so happen to involve fluids - but that it's pretty much the same as anything else
28
28
29
-
As it turns out, there's good reason to treat the equations we're dealing with differently to regular differential equations. A fair chunk of this article is going to be explaining what hydrodynamics is, why we need to use different solving methods, and how that fits into general relativity. A lot of programmers' experience of fluid dynamics is the incompressible Navier-Stokes equations, so you might be wondering how similar that it is to what we're doing today (disclaimer: not very)
29
+
As it turns out, there's good reason to treat the equations we're dealing with differently to regular differential equations. A fair chunk of this article is going to be explaining what hydrodynamics is, why we need to use different solving methods, and how that fits into general relativity. A lot of programmers' experience of fluid dynamics is the Navier-Stokes equations, so you might be wondering how similar that it is to what we're doing today (disclaimer: not very)
30
30
31
31
## Hydrodynamic Formalisms
32
32
@@ -66,15 +66,15 @@ In this scheme, there are the following definitions for the various quantities w
66
66
|$e_*$ | $(\rho_0 \epsilon)^\frac{1}{\Gamma} \alpha u^0 W^{-3}$ | Unclear how a numerical equation of state would work. Represents energy |
67
67
|$\tilde{S}_k$ | $\rho_* h u_k$ | Some kind of momentum term |
68
68
| $h$ | $1 + \epsilon + \frac{P}{\rho_0}$ | Enthalpy. $1 + \Gamma \epsilon$ with the perfect fluid equation of state, $P = (\Gamma - 1) \rho_0 \epsilon$ |
69
-
|$w$ | $\rho_* \alpha u^0$ | Densitised lorentz factor. Must be calculated via an iterative procedure |
69
+
|$w$ | $\rho_* \alpha u^0$ | Densitised lorentz factor. Must be calculated via an iterative procedure in general |
70
70
|$v^i$ | $\frac{u^i}{u^0}$ | Represents a coordinate velocity |
71
-
| $P$ | Equation of state, $P=(\Gamma - 1) \rho_0 \epsilon$ here |Perfect fluid equation of state |
71
+
| $P$ | Equation of state, $P=(\Gamma - 1) \rho_0 \epsilon$ here |Pressure with the perfect fluid equation of state |
72
72
73
73
The notation in this article is harmonised with the previous one. $\rho_0$ is the rest-mass density, $\epsilon$ is the specific energy density, $u^0$ is the lorentz factor, and $\alpha$ is the lapse. We'll be using a $\Gamma = 2$ perfect fluid equation of state - because it's unclear how a numerical one would work here
74
74
75
75
## Initial conditions
76
76
77
-
At the end of the previous article, we ended up with the fluid quantities: $\rho_0$, $\epsilon$, $u^i$, and $u^0$. These are the same variables as used in the definitions up above, there's nothing weird going on
77
+
At the end of the previous article, we ended up with the fluid quantities $\rho_0$, $\epsilon$, $u^i$, and $u^0$. These are the same variables used in the definitions up above, there's nothing weird going on
78
78
79
79
There are two pitfall traps here:
80
80
@@ -83,7 +83,7 @@ There are two pitfall traps here:
83
83
84
84
[^check]: You can check this from the hamiltonian constraint definition, and doing a roundtrip from the source terms. It only works out if $\alpha = 1$
85
85
86
-
We can now carry on immediately from our last article, which follows on as such:
86
+
We can now carry on immediately from the last article, which follows on as such:
This is the standard representation in hydrodynamics of advection equations, with the right hand side being called a source term (which you shouldn't confuse with an ADM source term). Here the source terms are split out, and no special treatment is given to their solving[^solving], so we're going to now unceremoniously ignore them
171
+
This is the standard representation in hydrodynamics of an advection equation, with the right hand side being called a source term (which you shouldn't confuse with an ADM source term). Here the source terms are split out, and no special treatment is given to their solving[^solving], so we're going to now unceremoniously ignore them
172
172
173
173
[^solving]: We'll just be literally adding them afterwards
174
174
@@ -231,7 +231,7 @@ In numerical relativity, 'shocks' are partially handled via Kreiss-Oliger dissip
231
231
232
232
## Conservative discretisation
233
233
234
-
A better discretisation of these equations is the flux conservative form, which guarantees conservation of your quantities when solved correctly ([4.4](https://www.tevza.org/home/course/modelling-II_2016/books/Leveque%20-%20Finite%20Volume%20Methods%20for%20Hyperbolic%20Equations.pdf) or [4.9](https://www.ita.uni-heidelberg.de/~dullemond/lectures/num_fluid_2012/Chapter_4.pdf)):
234
+
A better discretisation of these equations compared to the naive form, is the flux conservative form. This guarantees conservation of your quantity when solved correctly ([4.4](https://www.tevza.org/home/course/modelling-II_2016/books/Leveque%20-%20Finite%20Volume%20Methods%20for%20Hyperbolic%20Equations.pdf) or [4.9](https://www.ita.uni-heidelberg.de/~dullemond/lectures/num_fluid_2012/Chapter_4.pdf)):
In general, it's a good idea to avoid calculating $\rho_0$ if possible, as calculating $\rho_*^2$ is numerically suspect[^sus]. Some usefully optimised quantities are:
500
-
501
-
[^sus]: It's also better to calculate quantities of the form $\frac{a^2}{b}$ as $a \frac{a}{b}$ if you have to do this
In theory with a more modern formalism (eg the [Valencia](https://arxiv.org/pdf/1309.7808) form, [here](https://iopscience.iop.org/article/10.1086/303604/pdf), and [2.1.3](https://link.springer.com/content/pdf/10.12942/lrr-2008-7.pdf)), we'd be done. Unfortunately, we come to the major problem with this paper
@@ -544,10 +524,10 @@ Where:
544
524
545
525
$$\begin{align}
546
526
A &= e_*^\Gamma (W^3)^{\Gamma-1} (\frac{\rho_*}{w})^{\Gamma-1}\\
547
-
\delta v &= 2 \partial_k v^k \Delta h
527
+
\delta v &= 2 \partial_k v^k \Delta x
548
528
\end{align}$$
549
529
550
-
And $$\Delta h$$ is the scale. $C_{Qvis}$ is a damping constant, which I set to $0.1$, and this paper recommends the range $[0.1, 1]$
530
+
And $$\Delta x$$ is the scale. $C_{Qvis}$ is a damping constant, which I set to $0.1$, and this paper recommends the range $[0.1, 1]$
551
531
552
532
```c++
553
533
valuef dkvk = 0;
@@ -604,11 +584,11 @@ The radial oscillations are damped quite a bit
604
584
605
585
#### Viscosity for $e_*$
606
586
607
-
When using viscosity, you have to modify the evolution equation of $e_*$. The term to add is:
587
+
When using viscosity, $e_*$ gains a source term on the right hand side. The term to add is:
The term $(\rho_0 \epsilon)^{-1 + \frac{1}{\Gamma}}$ is numerically bad to calculate directly, and a better form is this:
591
+
$(\rho_0 \epsilon)^{-1 + \frac{1}{\Gamma}}$ is very numerically inaccurate to calculate the direct route, and a better form is this:
612
592
613
593
$$\begin{align}
614
594
I &= e_* W^3 \frac{\rho_*}{w}\\
@@ -816,7 +796,7 @@ There's nothing terribly exciting here. There's an option to not calculate sourc
816
796
817
797
# ADM Source terms
818
798
819
-
The evolution equations are now done, so next up is how this integrates into the BSSN equations. The way that matter interacts with general relativity is via the 4x4 symmetric [stress-energy tensor](https://en.wikipedia.org/wiki/Stress%E2%80%93energy_tensor). In the ADM formalism, this is broken up into a number of components - which are frequently collectively called source terms. These source terms are then plugged into the BSSN equations, and this enables matter to directly act on spacetime
799
+
The evolution equations are now done! Next up is how this integrates into the BSSN equations. The way that matter interacts with general relativity is via the 4x4 symmetric [stress-energy tensor](https://en.wikipedia.org/wiki/Stress%E2%80%93energy_tensor). In the ADM formalism, this is broken up into a number of components - which are frequently collectively called source terms. These source terms are then plugged into the BSSN equations, and this enables matter to directly act on spacetime
820
800
821
801
There are four standard ADM source terms, representing the ADM projections of the 4D stress-energy tensor. They are calculated from the matter variables as follows:
822
802
@@ -871,7 +851,7 @@ Before we get to the results, and overall discussion, it's worth talking about t
871
851
872
852
[^real]: I only encountered this when using a non conservative discretisation of the equations. It may be a product of the specific hydrodynamic scheme, and/or related to the $-\beta^i$ limit issue mentioned in the appendix
873
853
874
-
This - in theory - would all be solved by a fully conservative formalism - there's a lot of interesting discussion [here (2.1.2)](https://link.springer.com/content/pdf/10.12942/lrr-2008-7.pdf) around the limitations of this approach. This formalism isn't 'bad' however, and it seems to work quite well - and apparently it has seen fairly widespread use in various forms. This is probably going to be a future project for me, as it shouldn't be too much work now that there's a solid base here
854
+
This - in theory - would all be solved by a fully conservative formalism. There's a lot of interesting discussion [here (2.1.2)](https://link.springer.com/content/pdf/10.12942/lrr-2008-7.pdf) around the limitations of this approach. This formalism isn't 'bad' however - it seems to work quite well - and apparently it has seen fairly widespread use in various forms. This is probably going to be a future project for me, as it shouldn't be too much work now that there's a solid base here (..famous last words)
875
855
876
856

877
857
@@ -899,6 +879,8 @@ In our case, it collapses to a black hole[^discussion]:
899
879
900
880
<iframewidth="560"height="315"src="https://www.youtube.com/embed/YCckygeH9II?si=rlbwZtzFdaera0nI"title="YouTube video player"frameborder="0"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"referrerpolicy="strict-origin-when-cross-origin"allowfullscreen></iframe>
901
881
882
+
See the implementation details ('black hole collapse') section for how to manage neutron stars turning into black holes
883
+
902
884
## Stationary Spinning Test
903
885
904
886
This is test case C1, with dimensionless spin $\chi = 0.5$:
@@ -922,7 +904,7 @@ These $\mathrm{rgb}_*$ quantities can then be advected using the advection equat
922
904
923
905
$$\partial_t r_* = -\partial_i (r_* v^i)$$
924
906
925
-
Creating an arbitrary[^arbitrary] initial colour distribution can be done either as a function, or if you're willing to put an absolutely cat-astrophic amount of implementation work in: as a texture
907
+
Creating an arbitrary[^arbitrary] initial colour distribution can be done either as a function, or if you're willing to put an absolutely cat-astrophic amount of implementation work in: as a [texture](https://github.com/20k/20k.github.io/blob/master/code/common/weslr.png)
926
908
927
909
[^arbitrary]: I don't *think* an arbitrary colour distribution actually reproduces $\rho_*$ and the correct motion of an advected quantity, so it's good to treat this as illustrative of the velocity flow
928
910
@@ -971,7 +953,7 @@ Which gives this:
971
953
972
954
<iframewidth="560"height="315"src="https://www.youtube.com/embed/czDYhdyuMO0?si=YodMhX4B9llOyX6L"title="YouTube video player"frameborder="0"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"referrerpolicy="strict-origin-when-cross-origin"allowfullscreen></iframe>
973
955
974
-
Without an exact value for linear momentum, I can't precisely attempt to replicate[^testability] the original paper, but this appears to produce a reasonable inspiral. With the caveat around testing in mind, this scheme does appear to work, and there's nothing obviously unphysical going on. The hamiltonian constraint errors (top left) appear to stay low and bounded which is great as well
956
+
Without an exact value for linear momentum, I can't precisely attempt to replicate[^testability] the original paper, but this appears to produce a reasonable inspiral. With the caveats around testing in mind, this scheme does appear to work, and there's nothing obviously unphysical going on. The hamiltonian constraint errors (top left) appear to stay low and bounded which is great as well
975
957
976
958
[^testability]: It's a little unsatisfying - I've been searching around for test cases which give exact values, but many if not most are missing key parameters. It seems like a particular initial conditions solver is used in the literature, and so papers frequently omit key details. Within a few articles I'll probably get around to gravitational waves, which is when I'll be investing in a post Newtonian expansion or energy minimisation scheme, and then we can find out precisely how physically accurate this is
977
959
@@ -985,15 +967,15 @@ The main overhead is actually the amount of extra buffers required. There are $5
985
967
986
968
I've discussed the relativistic hydrodynamics formalism specifically in depth up above, so this is a general review of this project
987
969
988
-
Overall, this has gone pretty well. I'm not *super* jazzed at the lack of rigorous testing here, but this makes a very good stepping stone on the way to more advanced techniques and new ideas like post Newtonian formalisms - so I think this is perfect as an introduction. I'm also not super convinced on the actual hydrodynamics solver I've implemented - but that just means more work to implement something snazzy
970
+
Overall, this has gone pretty well. I'm not *super* jazzed at the lack of rigorous testing here, but this makes a very good stepping stone on the way to more advanced techniques and new ideas like post Newtonian formalisms - so I think this is perfect as an introduction. I'm also not super convinced on the actual hydrodynamics solver I've implemented as it may be slightly too basic - but that just means more work to implement something snazzy
989
971
990
972
This also pushing the limits of single precision here as well, it's right on the boundary of what's acceptable: if you're interested in novel precision techniques, like unums, or projective reals, this would be a good playground
991
973
992
974
It's clear though seeing that we easily can get multiple orbits, collapse neutron stars into stable black holes, and produce visible gravitational waves, that this is working well enough. So I'm very happy with it overall, and it's a solid base to build on. And importantly: it doesn't take 6 months to get a result back
993
975
994
976
# Next time
995
977
996
-
The next article is going to be N-body particle dynamics, because that should be a lot easier than hydrodynamics. This has taken a very large amount of work to put together, and there's still a lot to come back to and iron out. It'll be fun!
978
+
The next article is going to be N-body particle dynamics, because that should be a lot easier than hydrodynamics. This article has taken a very large amount of work to put together, and there's still a lot to come back to and iron out. It'll be fun!
997
979
998
980

999
981
@@ -1639,4 +1621,6 @@ Equations of state for neutron stars [https://arxiv.org/pdf/0812.2163](https://a
Intersting notes on Godunov's scheme [https://www.astro.uzh.ch/~stadel/lib/exe/fetch.php?media=spin:compastro_godunov.pdf](https://www.astro.uzh.ch/~stadel/lib/exe/fetch.php?media=spin:compastro_godunov.pdf)
1624
+
Interesting notes on Godunov's scheme [https://www.astro.uzh.ch/~stadel/lib/exe/fetch.php?media=spin:compastro_godunov.pdf](https://www.astro.uzh.ch/~stadel/lib/exe/fetch.php?media=spin:compastro_godunov.pdf)
1625
+
1626
+
2008 hydro review paper with some good comparative information [https://link.springer.com/content/pdf/10.12942/lrr-2008-7.pdf](https://link.springer.com/content/pdf/10.12942/lrr-2008-7.pdf)
0 commit comments