Skip to content

Commit 71f6d69

Browse files
committed
do an article pass, its alright
1 parent 242a6cc commit 71f6d69

File tree

1 file changed

+25
-41
lines changed

1 file changed

+25
-41
lines changed

_posts/2025-06-05-nr105.markdown

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ First up: Some background (and a dog)
2424

2525
# What is hydrodynamics?
2626

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
2828

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)
3030

3131
## Hydrodynamic Formalisms
3232

@@ -66,15 +66,15 @@ In this scheme, there are the following definitions for the various quantities w
6666
|$e_*$ | $(\rho_0 \epsilon)^\frac{1}{\Gamma} \alpha u^0 W^{-3}$ | Unclear how a numerical equation of state would work. Represents energy |
6767
|$\tilde{S}_k$ | $\rho_* h u_k$ | Some kind of momentum term |
6868
| $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 |
7070
|$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 |
7272

7373
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
7474

7575
## Initial conditions
7676

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
7878

7979
There are two pitfall traps here:
8080

@@ -83,7 +83,7 @@ There are two pitfall traps here:
8383

8484
[^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$
8585

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:
8787

8888
```c++
8989
valuef pressure = mu_to_P(mu);
@@ -134,7 +134,7 @@ valuef calculate_h_from_epsilon(valuef epsilon)
134134
}
135135
```
136136

137-
That's it, no other surprises
137+
That's it, no other surprises - the initial conditions are done
138138

139139
## Evolution equations
140140

@@ -150,7 +150,7 @@ $$\begin{align}
150150
\end{align}
151151
$$
152152

153-
I'll get into what everything means in detail soon - the most important piece is that $v^i$ is a velocity
153+
I'll get into what everything means in detail soon - the most important piece is that $v^i$ is the coordinate velocity
154154

155155
### The reason why hydrodynamics is a thing
156156

@@ -168,7 +168,7 @@ $$
168168
\partial_t q + \nabla (q \textbf{v}) = \mathrm{Source}
169169
$$
170170

171-
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
172172

173173
[^solving]: We'll just be literally adding them afterwards
174174

@@ -231,7 +231,7 @@ In numerical relativity, 'shocks' are partially handled via Kreiss-Oliger dissip
231231

232232
## Conservative discretisation
233233

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)):
235235

236236
$$\partial_t q = \frac{1}{\Delta x} (F^n_{i-\frac{1}{2}} - F^n_{i+\frac{1}{2}})$$
237237

@@ -486,26 +486,6 @@ Iterating $w$ is extremely cheap, and the iteration count is way more than neces
486486
487487
It's worth noting that when $\Gamma = 2$, the factor of $\rho_*$ drops out in $D$
488488
489-
## Recovering the primitive variables
490-
491-
$\rho_0$ and $\epsilon$ are called the primitive hydrodynamic variables, and recovering them requires $w$. Once you have that, you can calculate:
492-
493-
$$\begin{align}
494-
\rho_0 &= \frac{W^3 \rho_*^2}{w}\\
495-
\epsilon &= e_*^\Gamma \rho_*^{\Gamma - 2} (\frac{W^3}{w})^{\Gamma - 1}
496-
\end{align}
497-
$$
498-
499-
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
502-
503-
$$\begin{align}
504-
\rho_0 \epsilon &= \left (e_* W^3 \frac{\rho_*}{w} \right)^\Gamma\\
505-
h &= 1 + \Gamma \epsilon
506-
\end{align}
507-
$$
508-
509489
## 2002 Relativistic hydrodynamics - specifically
510490
511491
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:
544524
545525
$$\begin{align}
546526
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
548528
\end{align}$$
549529
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]$
551531
552532
```c++
553533
valuef dkvk = 0;
@@ -604,11 +584,11 @@ The radial oscillations are damped quite a bit
604584
605585
#### Viscosity for $e_*$
606586
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:
608588
609589
$$\partial_t e_* \mathrel{+}= -(\rho_0 \epsilon)^{(-1 + \frac{1}{\Gamma})} \;\; \frac{Q}{\Gamma} \; \partial_k (w W^{-3} v^k \rho_*^{-1})$$
610590
611-
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:
612592
613593
$$\begin{align}
614594
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
816796

817797
# ADM Source terms
818798

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
820800

821801
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:
822802

@@ -871,7 +851,7 @@ Before we get to the results, and overall discussion, it's worth talking about t
871851

872852
[^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
873853

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)
875855

876856
![catty](/assets/nr5_cat4.jpg)
877857

@@ -899,6 +879,8 @@ In our case, it collapses to a black hole[^discussion]:
899879

900880
<iframe width="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>
901881

882+
See the implementation details ('black hole collapse') section for how to manage neutron stars turning into black holes
883+
902884
## Stationary Spinning Test
903885

904886
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
922904

923905
$$\partial_t r_* = -\partial_i (r_* v^i)$$
924906

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)
926908

927909
[^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
928910

@@ -971,7 +953,7 @@ Which gives this:
971953

972954
<iframe width="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>
973955

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
975957

976958
[^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
977959

@@ -985,15 +967,15 @@ The main overhead is actually the amount of extra buffers required. There are $5
985967

986968
I've discussed the relativistic hydrodynamics formalism specifically in depth up above, so this is a general review of this project
987969

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
989971

990972
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
991973

992974
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
993975

994976
# Next time
995977

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!
997979

998980
![catend](/assets/nr5_catend.jpg)
999981

@@ -1639,4 +1621,6 @@ Equations of state for neutron stars [https://arxiv.org/pdf/0812.2163](https://a
16391621
16401622
Radiative transfer: [https://arxiv.org/pdf/1207.4234](https://arxiv.org/pdf/1207.4234)
16411623
1642-
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

Comments
 (0)