Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ConsToPrimDust.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
22
23namespace {
24
25 template<class Tvec>
26 struct KernelConsToPrimDust {
27 using Tscal = shambase::VecComponent<Tvec>;
28
29 inline static void kernel(
30 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>>
31 &spans_rho_dust,
32 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tvec>>
33 &spans_rhov_dust,
34
35 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tvec>> &spans_vel_dust,
36 const shambase::DistributedData<u32> &sizes,
37 u32 block_size,
38 u32 ndust) {
39
40 shambase::DistributedData<u32> cell_counts
41 = sizes.map<u32>([&](u64 id, u32 block_count) {
42 u32 cell_count = block_count * block_size * ndust;
43 return cell_count;
44 });
45
47 shamsys::instance::get_compute_scheduler_ptr(),
48 sham::DDMultiRef{spans_rho_dust, spans_rhov_dust},
49 sham::DDMultiRef{spans_vel_dust},
50 cell_counts,
51 [](u32 i,
52 const Tscal *__restrict rho_dust,
53 const Tvec *__restrict rhov_dust,
54 Tvec *__restrict vel_dust) {
55 auto d_conststate = shammath::DustConsState<Tvec>{rho_dust[i], rhov_dust[i]};
56 shammath::FluidStateDust<Tvec> dust_fluid{};
57 auto d_prim_state = dust_fluid.cons_to_prim(d_conststate);
58
59 vel_dust[i] = d_prim_state.vel;
60 });
61 }
62 };
63
64} // namespace
65
67
68 template<class Tvec>
71 auto edges = get_edges();
72
73 edges.spans_rho_dust.check_sizes(edges.sizes.indexes);
74 edges.spans_rhov_dust.check_sizes(edges.sizes.indexes);
75
76 edges.spans_vel_dust.ensure_sizes(edges.sizes.indexes);
77
78 KernelConsToPrimDust<Tvec>::kernel(
79 edges.spans_rho_dust.get_spans(),
80 edges.spans_rhov_dust.get_spans(),
81 edges.spans_vel_dust.get_spans(),
82 edges.sizes.indexes,
83 block_size,
84 ndust);
85 }
86
87 template<class Tvec>
89 std::string tex = R"tex(
90 Conservative to primitive variable (dust)
91
92 \begin{align}
93 {spans_vel_dust}_{i,j} &= \frac{ {spans_rhov_dust}_{i,j} }{ {spans_rho_dust}_{i,j} } \\
94 i &\in [0,{sizes} * N_{\rm cell/block}) \\
95 j &\in [0,n_{\rm dust}) \\
96 n_{\rm dust} & = {ndust} \\
97 N_{\rm cell/block} & = {block_size}
98 \end{align}
99 )tex";
100
101 replace_edges_tex_symbols(tex);
102
103 shambase::replace_all(tex, "{ndust}", sham::format("{}", ndust));
104 shambase::replace_all(tex, "{block_size}", sham::format("{}", block_size));
105
106 return tex;
107 }
108
109} // namespace shammodels::basegodunov::modules
110
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
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 dust states and all dust Riemann solvers (HLL, Huang & Bai).
#define __shamrock_stack_entry()
Macro to create a stack entry.