Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SedovTaylor.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
17#include <array>
18#include <cstddef>
19#include <limits>
20
21template<typename T, typename arr_t>
22std::array<size_t, 2> get_closest_range(const arr_t &arr, const T &val, size_t size) {
23 size_t low = 0, high = size - 1;
24
25 if (val < arr[low]) {
26 return {low, low};
27 }
28
29 if (val > arr[high]) {
30 return {high, high};
31 }
32
33 while (high - low > 1) {
34
35 size_t mid = (low + high) / 2;
36
37 if (arr[mid] < val) {
38 low = mid;
39 } else {
40 high = mid;
41 }
42 }
43
44 return {low, high};
45}
46
47template<typename T, typename arr_t>
48T linear_interpolate(const arr_t &arr_x, const arr_t &arr_y, size_t arr_size, const T &x) {
49
50 auto closest_range = get_closest_range(arr_x, x, arr_size);
51 size_t left_idx = closest_range[0];
52 size_t right_idx = closest_range[1];
53
54 if (left_idx == right_idx) {
55 return arr_y[left_idx];
56 }
57
58 T x0 = arr_x[left_idx];
59 T x1 = arr_x[right_idx];
60 T y0 = arr_y[left_idx];
61 T y1 = arr_y[right_idx];
62
63 if (x1 == x0) {
64 return std::numeric_limits<T>::signaling_NaN();
65 }
66
67 T interpolated_y = y0 + (x - x0) / (x1 - x0) * (y1 - y0);
68
69 return interpolated_y;
70}
71
73
74inline size_t ntheoval = sizeof(r_theo) / sizeof(r_theo[0]);
75
77
78 f64 rho = linear_interpolate(r_theo, rho_theo, ntheoval, x);
79 f64 vx = linear_interpolate(r_theo, vr_theo, ntheoval, x);
80 f64 P = linear_interpolate(r_theo, p_theo, ntheoval, x);
81
82 return {rho, vx, P};
83}
double f64
Alias for double.
field_val get_value(f64 x)
Compute field values at radial distance x.
Sod tube analytical solution adapted from a script of Leodasce Sewanou.
Field values at a given position.