Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
GeneratorMCDisc.hpp
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
10#pragma once
11
25
27
28 template<class Tvec, template<class> class SPHKernel>
30 using Tscal = shambase::VecComponent<Tvec>;
32 using Kernel = SPHKernel<Tscal>;
33
35
36 ShamrockCtx &context;
37 Config &solver_config;
38
39 struct DiscOutput {
40 sycl::vec<Tscal, 3> pos;
41 sycl::vec<Tscal, 3> velocity;
42 Tscal cs;
43 Tscal rho;
44 };
45
46 Tscal pmass;
47
48 class DiscIterator;
49 DiscIterator generator;
50 Tscal init_h_factor;
51
52 static DiscIterator make_generator(
53 Tscal part_mass,
54 Tscal disc_mass,
55 Tscal r_in,
56 Tscal r_out,
57 std::function<Tscal(Tscal)> sigma_profile,
58 std::function<Tscal(Tscal)> H_profile,
59 std::function<Tscal(Tscal)> rot_profile,
60 std::function<Tscal(Tscal)> cs_profile,
61 std::mt19937_64 eng) {
62 return DiscIterator(
63 part_mass,
64 disc_mass,
65 r_in,
66 r_out,
67 sigma_profile,
68 H_profile,
69 rot_profile,
70 cs_profile,
71 eng);
72 }
73
74 public:
76 ShamrockCtx &context,
77 Config &solver_config,
78 Tscal part_mass,
79 Tscal disc_mass,
80 Tscal r_in,
81 Tscal r_out,
82 std::function<Tscal(Tscal)> sigma_profile,
83 std::function<Tscal(Tscal)> H_profile,
84 std::function<Tscal(Tscal)> rot_profile,
85 std::function<Tscal(Tscal)> cs_profile,
86 std::mt19937_64 eng,
87 Tscal init_h_factor)
88 : context(context), solver_config(solver_config), generator(make_generator(
89 part_mass,
90 disc_mass,
91 r_in,
92 r_out,
93 sigma_profile,
94 H_profile,
95 rot_profile,
96 cs_profile,
97 eng)),
98 init_h_factor(init_h_factor), pmass(part_mass) {}
99
100 bool is_done();
101
103
104 std::string get_name() { return "GeneratorMCDisc"; }
106 };
107
108} // namespace shammodels::sph::modules
109
110template<class Tvec, template<class> class SPHKernel>
112
113 bool done = false;
114 u64 current_index = 0;
115
116 Tscal part_mass;
117 Tscal disc_mass;
118 u64 Npart;
119
120 Tscal r_in;
121 Tscal r_out;
122 std::function<Tscal(Tscal)> sigma_profile;
123 std::function<Tscal(Tscal)> H_profile;
124 std::function<Tscal(Tscal)> rot_profile;
125 std::function<Tscal(Tscal)> cs_profile;
126
128
129 static constexpr Tscal _2pi = 2 * shambase::constants::pi<Tscal>;
130
131 Tscal f_func(Tscal r) { return r * sigma_profile(r); }
132
133 DiscOutput next(u64 seed);
134
135 public:
137 Tscal part_mass,
138 Tscal disc_mass,
139 Tscal r_in,
140 Tscal r_out,
141 std::function<Tscal(Tscal)> sigma_profile,
142 std::function<Tscal(Tscal)> H_profile,
143 std::function<Tscal(Tscal)> rot_profile,
144 std::function<Tscal(Tscal)> cs_profile,
145 std::mt19937_64 eng)
146 : DiscIterator(
147 part_mass,
148 disc_mass,
149 r_in,
150 r_out,
151 sigma_profile,
152 H_profile,
153 rot_profile,
154 cs_profile,
155 eng,
156 disc_mass / part_mass) {}
157
159 Tscal part_mass,
160 Tscal disc_mass,
161 Tscal r_in,
162 Tscal r_out,
163 std::function<Tscal(Tscal)> sigma_profile,
164 std::function<Tscal(Tscal)> H_profile,
165 std::function<Tscal(Tscal)> rot_profile,
166 std::function<Tscal(Tscal)> cs_profile,
167 std::mt19937_64 eng,
168 u64 Npart)
169 : part_mass(part_mass), disc_mass(disc_mass), Npart(Npart), r_in(r_in), r_out(r_out),
170 sigma_profile(sigma_profile), H_profile(H_profile), rot_profile(rot_profile),
171 cs_profile(cs_profile), generator(eng, Npart), current_index(0) {
172
173 shamlog_debug_ln(
174 "GeneratorMCDisc",
175 "part_mass",
176 part_mass,
177 "disc_mass",
178 disc_mass,
179 "r_in",
180 r_in,
181 "r_out",
182 r_out,
183 "Npart",
184 Npart);
185 }
186
187 inline bool is_done() {
188 return generator.is_done();
189 } // just to make sure the result is not tempered with
190
191 inline std::vector<DiscOutput> next_n(u64 nmax) {
192 std::vector<u64> seeds = generator.next_n(nmax);
193 std::vector<DiscOutput> ret{};
194 for (u64 seed : seeds) {
195 ret.push_back(next(seed));
196 }
197 return ret;
198 }
199};
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A parallel generator that will spit the same sequence regardless of the number of ranks.
std::vector< u64 > next_n(u64 val_count, bool sequential=false)
Generate the next val_count values.
shamrock::patch::PatchDataLayer next_n(u32 nmax)
This function generate patchdata with at most nmax per MPI ranks This function is always assumed as c...
ISPHSetupNode_Dot get_dot_subgraph()
Get a dot subgraph describing the node and its childrens (recursively)
std::string get_name()
Get the name of the node.
bool is_done()
This function return true if the setup is done.
This class is an interface that all SPH setup nodes must implement. It describe an operation associat...
PatchDataLayer container class, the layout is described in patchdata_layout.
Class holding the value of numerous constants generated from the following source.
namespace for the sph model modules
The configuration for a sph solver.
This struct is used to generate a dot graph of the setup tree.