Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ConsToPrimGasBarotropic.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
16
17#include "shambase/assert.hpp"
19#include "shammath/riemann.hpp"
23
24namespace {
25
26 template<class Tvec>
27 struct KernelConsToPrimGasBarotropic {
28 using Tscal = shambase::VecComponent<Tvec>;
29
30 inline static void kernel(
31 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>> &spans_rho,
32 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tvec>> &spans_rhov,
33
34 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tvec>> &spans_vel,
35 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>> &spans_P,
36 const shambase::DistributedData<u32> &sizes,
37 u32 block_size,
38 Tscal rho_crit,
39 Tscal cs0,
40 Tscal gamma) {
41
42 shambase::DistributedData<u32> cell_counts
43 = sizes.map<u32>([&](u64 id, u32 block_count) {
44 u32 cell_count = block_count * block_size;
45 return cell_count;
46 });
47
49 shamsys::instance::get_compute_scheduler_ptr(),
50 sham::DDMultiRef{spans_rho, spans_rhov},
51 sham::DDMultiRef{spans_vel, spans_P},
52 cell_counts,
53 [rho_crit, cs0, gamma](
54 u32 i,
55 const Tscal *__restrict rho,
56 const Tvec *__restrict rhov,
57 Tvec *__restrict vel,
58 Tscal *__restrict P) {
59 // rhoe is ignored by the barotropic cons_to_prim
60 auto conststate = shammath::ConsState<Tvec>{rho[i], 0, rhov[i]};
61
62 shammath::FluidStateBarotropic<Tvec> barotropic_fluid{rho_crit, cs0, gamma};
63 auto prim_state = barotropic_fluid.cons_to_prim(conststate);
64
65 SHAM_ASSERT(prim_state.press >= 0.0);
66
67 vel[i] = prim_state.vel;
68 P[i] = prim_state.press;
69 });
70 }
71 };
72
73} // namespace
74
76
77 template<class Tvec>
80 auto edges = get_edges();
81
82 edges.spans_rho.check_sizes(edges.sizes.indexes);
83 edges.spans_rhov.check_sizes(edges.sizes.indexes);
84
85 edges.spans_vel.ensure_sizes(edges.sizes.indexes);
86 edges.spans_P.ensure_sizes(edges.sizes.indexes);
87
88 KernelConsToPrimGasBarotropic<Tvec>::kernel(
89 edges.spans_rho.get_spans(),
90 edges.spans_rhov.get_spans(),
91 edges.spans_vel.get_spans(),
92 edges.spans_P.get_spans(),
93 edges.sizes.indexes,
94 block_size,
95 rho_crit,
96 cs0,
97 gamma);
98 }
99
100 template<class Tvec>
102 std::string tex = R"tex(
103 Conservative to primitive variable (gas, barotropic)
104
105 \begin{align}
106 {spans_vel}_i &= \frac{ {spans_rhov}_i }{ {spans_rho}_i } \\
107 {spans_P}_i &= c_{s,0}^2 {spans_rho}_i \left( 1 + \left( \frac{ {spans_rho}_i }{ \rho_c } \right)^{\gamma - 1} \right) \\
108 i &\in [0,{sizes} * N_{\rm cell/block}) \\
109 \rho_c &= {rho_crit} \\
110 c_{s,0} &= {cs0} \\
111 \gamma &= {gamma} \\
112 N_{\rm cell/block} & = {block_size}
113 \end{align}
114 )tex";
115
116 replace_edges_tex_symbols(tex);
117
118 shambase::replace_all(tex, "{rho_crit}", sham::format("{}", rho_crit));
119 shambase::replace_all(tex, "{cs0}", sham::format("{}", cs0));
120 shambase::replace_all(tex, "{gamma}", sham::format("{}", gamma));
121 shambase::replace_all(tex, "{block_size}", sham::format("{}", block_size));
122
123 return tex;
124 }
125
126} // namespace shammodels::basegodunov::modules
127
Conservative to primitive conversion of the gas for a barotropic equation of state.
constexpr const char * sizes
Temporary sizes for h-iteration.
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Shamrock assertion utility.
#define SHAM_ASSERT(x)
Shorthand for SHAM_ASSERT_NAMED without a message.
Definition assert.hpp:67
Conservative to primitive conversion of the gas using shammath::FluidStateBarotropic.
virtual std::string _impl_get_tex() const
get the tex of the node
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:106
namespace for the basegodunov model modules
Umbrella header pulling in the gas states and all gas Riemann solvers (Rusanov, HLL,...
#define __shamrock_stack_entry()
Macro to create a stack entry.