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
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(
34
38 u32 block_size,
39 Tscal gamma) {
40
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 auto prim_state = shammath::cons_to_prim(conststate, gamma);
62
63 SHAM_ASSERT(prim_state.press >= 0.0);
64
65 vel[i] = prim_state.vel;
66 P[i] = prim_state.press;
67 });
68 }
69 };
70
71} // namespace
72
74
75 template<class Tvec>
77 auto edges = get_edges();
78
79 edges.spans_rho.check_sizes(edges.sizes.indexes);
80 edges.spans_rhov.check_sizes(edges.sizes.indexes);
81 edges.spans_rhoe.check_sizes(edges.sizes.indexes);
82
83 edges.spans_vel.ensure_sizes(edges.sizes.indexes);
84 edges.spans_P.ensure_sizes(edges.sizes.indexes);
85
86 KernelConsToPrimGas<Tvec>::kernel(
87 edges.spans_rho.get_spans(),
88 edges.spans_rhov.get_spans(),
89 edges.spans_rhoe.get_spans(),
90 edges.spans_vel.get_spans(),
91 edges.spans_P.get_spans(),
92 edges.sizes.indexes,
93 block_size,
94 gamma);
95 }
96
97 template<class Tvec>
99
100 auto block_count = get_ro_edge_base(0).get_tex_symbol();
101 auto rho = get_ro_edge_base(1).get_tex_symbol();
102 auto rhov = get_ro_edge_base(2).get_tex_symbol();
103 auto rhoe = get_ro_edge_base(3).get_tex_symbol();
104 auto vel = get_rw_edge_base(0).get_tex_symbol();
105 auto P = get_rw_edge_base(1).get_tex_symbol();
106
107 std::string tex = R"tex(
108 Conservative to primitive variable (gas)
109
110 \begin{align}
111 {vel}_i &= \frac{ {rhov}_i }{ {rho}_i } \\
112 {P}_i &= (\gamma - 1) \left( {rhoe}_i - \frac{ {rhov}_i^2 }{ 2 {rho}_i } \right) \\
113 i &\in [0,{block_count} * N_{\rm cell/block}) \\
114 \gamma &= {gamma} \\
115 N_{\rm cell/block} & = {block_size}
116 \end{align}
117 )tex";
118
119 shambase::replace_all(tex, "{vel}", vel);
120 shambase::replace_all(tex, "{P}", P);
121 shambase::replace_all(tex, "{rho}", rho);
122 shambase::replace_all(tex, "{rhov}", rhov);
123 shambase::replace_all(tex, "{rhoe}", rhoe);
124 shambase::replace_all(tex, "{block_count}", block_count);
125 shambase::replace_all(tex, "{gamma}", shambase::format("{}", gamma));
126 shambase::replace_all(tex, "{block_size}", shambase::format("{}", block_size));
127
128 return tex;
129 }
130
131} // namespace shammodels::basegodunov::modules
132
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
Represents a collection of objects distributed across patches identified by a u64 id.
virtual std::string _impl_get_tex() const
get the tex of the node
Represents a span of data within a PatchDataField.
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:183
namespace for the basegodunov model modules
From original version by Thomas Guillet (T.A.Guillet@exeter.ac.uk)
A variant of sham::MultiRef for distributed data.