Skip to content

Commit 0e54fd1

Browse files
committed
added gresho vortex
1 parent 8b10ec1 commit 0e54fd1

File tree

7 files changed

+146
-1
lines changed

7 files changed

+146
-1
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Adirondax Examples
22

3-
Simple examples to demonstrate adirondax' capabilities and help you get started with your own simulations
3+
Simple examples to demonstrate the capabilities of adirondax and help you get started with your own simulations

examples/gresho/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Gresho
2+
3+
Simulate the Gresho Vortex
4+
5+
Philip Mocz (2025)
6+
7+
Usage:
8+
9+
```console
10+
python gresho.py
11+
```
12+
13+
Takes around 10 seconds to run on my macbook (cpu).
14+
15+
16+
## Simulation snapshots
17+
18+
<div style="display:flex;flex-wrap:wrap;gap:8px">
19+
<img src="output.png" alt="output" width="45%"/>
20+
</div>
21+
22+
23+
## References
24+
25+
[Gresho, P.M.; Chen, S.T.; On the theory of semi-implicit projection methods for viscous incompressible flow and its implementation via a finite element method that also introduces a nearly consistent mass matrix. II - Implementation. International Journal for Numerical Methods in Fluids (1990)](https://ui.adsabs.harvard.edu/abs/1990IJNMF..11..621G)
26+
27+
[Liska, R. ; Wendroff, B.; Comparison of Several Difference Schemes on 1D and 2D Test Problems for the Euler Equations. SIAM Journal on Scientific Computing (2003)](https://ui.adsabs.harvard.edu/abs/2003SJSC...25..995L)

examples/gresho/gresho.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import jax.numpy as jnp
2+
3+
# TODO: REMOVE THE FOLLOWING LINES
4+
import sys
5+
6+
sys.path.append("../../")
7+
8+
import adirondax as adx
9+
import time
10+
import matplotlib.pyplot as plt
11+
12+
"""
13+
Simulate the Gresho Vortex
14+
15+
Philip Mocz (2025)
16+
"""
17+
18+
19+
def set_up_simulation():
20+
# Define the parameters for the simulation
21+
nx = 128
22+
nt = -1
23+
t_stop = 3.0
24+
25+
params = {
26+
"physics": {
27+
"hydro": True,
28+
},
29+
"mesh": {
30+
"type": "cartesian",
31+
"resolution": [nx, nx],
32+
"box_size": [1.0, 1.0],
33+
},
34+
"time": {
35+
"span": t_stop,
36+
"num_timesteps": nt,
37+
},
38+
"output": {
39+
"num_checkpoints": 100,
40+
"save": False,
41+
"plot_dynamic_range": 2.0,
42+
},
43+
"hydro": {
44+
"eos": {"type": "ideal", "gamma": 5.0 / 3.0},
45+
"slope_limiting": True,
46+
},
47+
}
48+
49+
# Initialize the simulation
50+
sim = adx.Simulation(params)
51+
52+
# Set initial conditions
53+
sim.state["t"] = 0.0
54+
X, Y = sim.mesh
55+
R = jnp.sqrt((X - 0.5) ** 2 + (Y - 0.5) ** 2)
56+
def v_phi(r):
57+
return jnp.where(
58+
r < 0.2,
59+
5.0 * r,
60+
jnp.where(r < 0.4, 2.0 - 5.0 * r, 0.0),
61+
)
62+
def P0(r):
63+
return jnp.where(
64+
r < 0.2,
65+
5.0 + 12.5 * r**2,
66+
jnp.where(r < 0.4, 9.0 + 12.5 * r**2 - 20.0 * r + 4.0 * jnp.log(r / 0.2), 3.0 + 4.0 * jnp.log(2.0)),
67+
)
68+
vx = -v_phi(R) * (Y - 0.5) / (R + (R==0))
69+
vy = v_phi(R) * (X - 0.5) / (R + (R==0))
70+
sim.state["rho"] = jnp.ones(X.shape)
71+
sim.state["vx"] = vx
72+
sim.state["vy"] = vy
73+
sim.state["P"] = P0(R)
74+
75+
return sim
76+
77+
78+
def make_plot(sim):
79+
# Plot the solution
80+
plt.figure(figsize=(6, 4), dpi=80)
81+
v_phi = jnp.sqrt(sim.state["vx"]**2 + sim.state["vy"]**2)
82+
plt.imshow(v_phi.T, cmap="jet", vmin=0.0, vmax=1.0)
83+
plt.gca().invert_yaxis()
84+
plt.colorbar(label="v_phi")
85+
plt.tight_layout()
86+
plt.savefig("output.png", dpi=240)
87+
plt.show()
88+
89+
90+
def main():
91+
sim = set_up_simulation()
92+
93+
# Evolve the system
94+
t0 = time.time()
95+
sim.run()
96+
print("Run time (s): ", time.time() - t0)
97+
print("Steps taken:", sim.steps_taken)
98+
99+
make_plot(sim)
100+
101+
102+
if __name__ == "__main__":
103+
main()

examples/gresho/output.png

59.4 KB
Loading

examples/kelvin_helmholtz/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ Takes around 6 seconds to run on my macbook (cpu).
1818
<div style="display:flex;flex-wrap:wrap;gap:8px">
1919
<img src="output.png" alt="output" width="45%"/>
2020
</div>
21+
22+
23+
## References
24+
25+
[Springel, V.; E pur si muove: Galilean-invariant cosmological hydrodynamical simulations on a moving mesh. Monthly Notices of the Royal Astronomical Society (2020)](https://ui.adsabs.harvard.edu/abs/2010MNRAS.401..791S)

examples/orszag_tang/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ Takes around 55 seconds ('llf') / 105 seconds ('hlld') to run on my macbook (cpu
1818
<div style="display:flex;flex-wrap:wrap;gap:8px">
1919
<img src="output.png" alt="output" width="45%"/>
2020
</div>
21+
22+
23+
## References
24+
25+
[Orszag, S.A.; Tang, C.M.; Small-scale structure of two-dimensional magnetohydrodynamic turbulence. Journal of Fluid Mechanics (1979)](https://ui.adsabs.harvard.edu/abs/1979JFM....90..129O)

examples/rayleigh_taylor/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ Takes around 9 seconds to run on my macbook (cpu).
1818
<div style="display:flex;flex-wrap:wrap;gap:8px">
1919
<img src="output.png" alt="output" width="45%"/>
2020
</div>
21+
22+
23+
## References
24+
25+
[Springel, V.; E pur si muove: Galilean-invariant cosmological hydrodynamical simulations on a moving mesh. Monthly Notices of the Royal Astronomical Society (2020)](https://ui.adsabs.harvard.edu/abs/2010MNRAS.401..791S)

0 commit comments

Comments
 (0)