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
22
23namespace {
24
25 template<class Tvec>
26 struct KernelConsToPrimDust {
27 using Tscal = shambase::VecComponent<Tvec>;
28
29 inline static void kernel(
31 &spans_rho_dust,
33 &spans_rhov_dust,
34
37 u32 block_size,
38 u32 ndust) {
39
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 auto d_prim_state = shammath::d_cons_to_prim(d_conststate);
57
58 vel_dust[i] = d_prim_state.vel;
59 });
60 }
61 };
62
63} // namespace
64
66
67 template<class Tvec>
69 auto edges = get_edges();
70
71 edges.spans_rho_dust.check_sizes(edges.sizes.indexes);
72 edges.spans_rhov_dust.check_sizes(edges.sizes.indexes);
73
74 edges.spans_vel_dust.ensure_sizes(edges.sizes.indexes);
75
76 KernelConsToPrimDust<Tvec>::kernel(
77 edges.spans_rho_dust.get_spans(),
78 edges.spans_rhov_dust.get_spans(),
79 edges.spans_vel_dust.get_spans(),
80 edges.sizes.indexes,
81 block_size,
82 ndust);
83 }
84
85 template<class Tvec>
87
88 auto block_count = get_ro_edge_base(0).get_tex_symbol();
89 auto rho = get_ro_edge_base(1).get_tex_symbol();
90 auto rhov = get_ro_edge_base(2).get_tex_symbol();
91 auto vel = get_rw_edge_base(0).get_tex_symbol();
92
93 std::string tex = R"tex(
94 Conservative to primitive variable (dust)
95
96 \begin{align}
97 {vel}_{i,j} &= \frac{ {rhov}_{i,j} }{ {rho}_{i,j} } \\
98 i &\in [0,{block_count} * N_{\rm cell/block}) \\
99 j &\in [0,n_{\rm dust}) \\
100 n_{\rm dust} & = {ndust} \\
101 N_{\rm cell/block} & = {block_size}
102 \end{align}
103 )tex";
104
105 shambase::replace_all(tex, "{vel}", vel);
106 shambase::replace_all(tex, "{rho}", rho);
107 shambase::replace_all(tex, "{rhov}", rhov);
108 shambase::replace_all(tex, "{block_count}", block_count);
109 shambase::replace_all(tex, "{ndust}", shambase::format("{}", ndust));
110 shambase::replace_all(tex, "{block_size}", shambase::format("{}", block_size));
111
112 return tex;
113 }
114
115} // namespace shammodels::basegodunov::modules
116
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
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
This file contain states and Riemann solvers for dust.
A variant of sham::MultiRef for distributed data.