Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ConsToPrimGas.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 KernelConsToPrimGas {
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 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>> &spans_rhoe,
34
35 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tvec>> &spans_vel,
36 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>> &spans_P,
37 const shambase::DistributedData<u32> &sizes,
38 u32 block_size,
39 Tscal gamma) {
40
41 shambase::DistributedData<u32> cell_counts
42 = sizes.map<u32>([&](u64 id, u32 block_count) {
43 u32 cell_count = block_count * block_size;
44 return cell_count;
45 });
46
48 shamsys::instance::get_compute_scheduler_ptr(),
49 sham::DDMultiRef{spans_rho, spans_rhov, spans_rhoe},
50 sham::DDMultiRef{spans_vel, spans_P},
51 cell_counts,
52 [gamma](
53 u32 i,
54 const Tscal *__restrict rho,
55 const Tvec *__restrict rhov,
56 const Tscal *__restrict rhoe,
57 Tvec *__restrict vel,
58 Tscal *__restrict P) {
59 auto conststate = shammath::ConsState<Tvec>{rho[i], rhoe[i], rhov[i]};
60
61 shammath::FluidStateAdiabatic<Tvec> adiab_fluid{.m_gamma = gamma};
62 auto prim_state = adiab_fluid.cons_to_prim(conststate);
63
64 SHAM_ASSERT(prim_state.press >= 0.0);
65
66 vel[i] = prim_state.vel;
67 P[i] = prim_state.press;
68 });
69 }
70 };
71
72} // namespace
73
75
76 template<class Tvec>
79 auto edges = get_edges();
80
81 edges.spans_rho.check_sizes(edges.sizes.indexes);
82 edges.spans_rhov.check_sizes(edges.sizes.indexes);
83 edges.spans_rhoe.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 KernelConsToPrimGas<Tvec>::kernel(
89 edges.spans_rho.get_spans(),
90 edges.spans_rhov.get_spans(),
91 edges.spans_rhoe.get_spans(),
92 edges.spans_vel.get_spans(),
93 edges.spans_P.get_spans(),
94 edges.sizes.indexes,
95 block_size,
96 gamma);
97 }
98
99 template<class Tvec>
101 std::string tex = R"tex(
102 Conservative to primitive variable (gas)
103
104 \begin{align}
105 {spans_vel}_i &= \frac{ {spans_rhov}_i }{ {spans_rho}_i } \\
106 {spans_P}_i &= (\gamma - 1) \left( {spans_rhoe}_i - \frac{ {spans_rhov}_i^2 }{ 2 {spans_rho}_i } \right) \\
107 i &\in [0,{sizes} * N_{\rm cell/block}) \\
108 \gamma &= {gamma} \\
109 N_{\rm cell/block} & = {block_size}
110 \end{align}
111 )tex";
112
113 replace_edges_tex_symbols(tex);
114
115 shambase::replace_all(tex, "{gamma}", sham::format("{}", gamma));
116 shambase::replace_all(tex, "{block_size}", sham::format("{}", block_size));
117
118 return tex;
119 }
120
121} // namespace shammodels::basegodunov::modules
122
Field variant object to instanciate a variant on the patch types.
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
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.