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;
29 if (val > arr[high]) {
33 while (high - low > 1) {
35 size_t mid = (low + high) / 2;
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) {
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];
54 if (left_idx == right_idx) {
55 return arr_y[left_idx];
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];
64 return std::numeric_limits<T>::signaling_NaN();
67 T interpolated_y = y0 + (x - x0) / (x1 - x0) * (y1 - y0);
69 return interpolated_y;
74inline size_t ntheoval =
sizeof(r_theo) /
sizeof(r_theo[0]);
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);
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.