# \[ANN\] SodShockTube.jl - analytic solution of Sod shock tube problem for fluid dynamics code verification

**URL:** https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601
**Category:** Package Announcements
**Created:** [November 16, 2021, 5:20pm UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601 "2021-11-16T17:20:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![archermarx](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@archermarx](https://discourse.julialang.org/u/archermarx)
#### Post date: [November 16, 2021, 5:20pm UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601/1 "2021-11-16T17:20:21Z")

</div>

I’ve just released [SodShockTube.jl](https://github.com/archermarx/SodShockTube.jl), which is a pure-Julia implementation of the python Sod Shock tube solver by ibackus ([GitHub - ibackus/sod-shocktube: A simple pythonic implementation of a Riemann solver for the analytic solution of the sod shock tube.](https://github.com/ibackus/sod-shocktube)), which is “a fork of the Riemann solver implemented at [fantaz / Sod shock tube calculator · GitLab](https://gitlab.com/fantaz/Riemann_exact), which is itself just a pythonic clone of the fortran code by Bruce Fryxell.”

The Sod Shock Tube Problem is a standard test problem in computational fluid dynamics. It is especially useful in the development of shock-capturing numerical schemes. This package allows users to set up and run Sod Shock Tube problems with user-configurable geometry and user-defined left and right states.

# Example

```julia

# Set up a shock tube problem
problem = ShockTubeProblem(
    geometry = (0.0, 1.0, 0.5), # left edge, right edge, initial shock location
    left_state = (ρ = 1.0, u = 0.0, p = 1.0),
    right_state = (ρ = 0.125, u = 0.0, p = 0.1),
    t = 0.1,
    γ = 1.4
);

xs = LinRange(0.0, 1.0, 500); # x locations at which to solve

positions, regions, values = solve(problem, xs);

```

This should give the following result

```julia-repl
julia> positions
Dict{String, Float64} with 4 entries:
  "Shock" => 1.17522
  "Foot of rarefaction" => 0.992973
  "Head of rarefaction" => 0.881678
  "Contact Discontinuity" => 1.09275

julia> regions
Dict{String, Any} with 5 entries:
  "Region 5" => (0.1, 0.125, 0.0)
  "Region 1" => (1.0, 1.0, 0.0)
  "Region 4" => (0.30313, 0.265574, 0.927453)
  "Region 3" => (0.30313, 0.426319, 0.927453)
  "Region 2" => "RAREFACTION"

```

We can use Makie (or other plotting package of choice) to plot our result

```julia
using CairoMakie
f = Figure(resolution = (1000, 1000))
ax_ρ = Axis(f[1,1], xlabel = "x", ylabel = "ρ", title = "Density")
ax_u = Axis(f[2,1], xlabel = "x", ylabel = "u", title = "Velocity")
ax_p = Axis(f[1,2], xlabel = "x", ylabel = "p", title = "Pressure")
ax_E = Axis(f[2,2], xlabel = "x", ylabel = "E", title = "Stagnation Energy")

opts = (;linewidth = 4)

lines!(ax_ρ, values.x, values.ρ; opts...)
lines!(ax_u, values.x, values.u; opts...)
lines!(ax_p, values.x, values.p; opts...)
lines!(ax_E, values.x, values.e; opts...)

display(f)

```

 ![fig](https://global.discourse-cdn.com/julialang/original/3X/b/b/bb84a2cf151a1a6c2c082bcb30b56a4ce232f8b0.png)

---

<div class="post-metadata">

### Author: ![bilderbuchi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bilderbuchi/32/13562_2.png) [@bilderbuchi](https://discourse.julialang.org/u/bilderbuchi)
#### Post date: [November 17, 2021, 6:22am UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601/2 "2021-11-17T06:22:15Z")

</div>

This looks interesting! Do you have any plans to go towards a general Riemann solver for hyperbolic problems, a la [https://www.clawpack.org/](https://www.clawpack.org/) ?

---

<div class="post-metadata">

### Author: ![archermarx](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@archermarx](https://discourse.julialang.org/u/archermarx)
#### Post date: [November 17, 2021, 1:48pm UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601/3 "2021-11-17T13:48:59Z")

</div>

Probably not. I put this together to help me implement a 1D code for my own research and figured it might help others, tho I’d welcome any feature requests

---

<div class="post-metadata">

### Author: ![bilderbuchi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bilderbuchi/32/13562_2.png) [@bilderbuchi](https://discourse.julialang.org/u/bilderbuchi)
#### Post date: [November 18, 2021, 6:38am UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601/4 "2021-11-18T06:38:10Z")

</div>

Sure, thanks!

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [November 18, 2021, 9:24pm UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601/5 "2021-11-18T21:24:26Z")

</div>

Note that several approximate Riemann solvers are implemented in Trixi.jl: [https://github.com/trixi-framework/Trixi.jl/blob/37dc9b6d522c94898eefd0689c9cffe901ad739e/src/equations/compressible\_euler\_1d.jl#L402-L472](https://github.com/trixi-framework/Trixi.jl/blob/37dc9b6d522c94898eefd0689c9cffe901ad739e/src/equations/compressible_euler_1d.jl#L402-L472).

There’s some discussion of the Sod problem here: [https://github.com/trixi-framework/Trixi.jl/issues/962](https://github.com/trixi-framework/Trixi.jl/issues/962)

---

<div class="post-metadata">

### Author: ![archermarx](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@archermarx](https://discourse.julialang.org/u/archermarx)
#### Post date: [November 18, 2021, 9:44pm UTC](https://discourse.julialang.org/t/ann-sodshocktube-jl-analytic-solution-of-sod-shock-tube-problem-for-fluid-dynamics-code-verification/71601/6 "2021-11-18T21:44:17Z")

</div>

Trixi looks real cool! I’d love to play around with it some time.
