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
18
25
27
28 template<class Tvec, template<class> class SPHKernel>
29 class GeneratorMCDisc : public ISPHSetupNode {
30 using Tscal = shambase::VecComponent<Tvec>;
31 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
32 using Kernel = SPHKernel<Tscal>;
33
34 using Config = SolverConfig<Tvec, SPHKernel>;
35
36 ShamrockCtx &context;
37 Config &solver_config;
38
39 struct DiscOutput {
40 sycl::vec<Tscal, 3> pos;
41 Tscal rho;
42 };
43
44 Tscal pmass;
45
46 class DiscIterator;
47 DiscIterator generator;
48 Tscal init_h_factor;
49
50 std::function<Tvec(Tvec)> vel_profile;
51 std::function<Tscal(Tvec)> cs_profile;
52
53 static DiscIterator make_generator(
54 Tscal part_mass,
55 Tscal disc_mass,
56 Tscal r_in,
57 Tscal r_out,
58 std::function<Tscal(Tscal)> sigma_profile,
59 std::function<Tscal(Tscal)> H_profile,
60 std::mt19937_64 eng) {
61 return DiscIterator(part_mass, disc_mass, r_in, r_out, sigma_profile, H_profile, eng);
62 }
63
64 public:
65 GeneratorMCDisc(
66 ShamrockCtx &context,
67 Config &solver_config,
68 Tscal part_mass,
69 Tscal disc_mass,
70 Tscal r_in,
71 Tscal r_out,
72 std::function<Tscal(Tscal)> sigma_profile,
73 std::function<Tscal(Tscal)> H_profile,
74 std::function<Tvec(Tvec)> vel_profile,
75 std::function<Tscal(Tvec)> cs_profile,
76 std::mt19937_64 eng,
77 Tscal init_h_factor)
78 : context(context), solver_config(solver_config),
79 generator(
80 make_generator(part_mass, disc_mass, r_in, r_out, sigma_profile, H_profile, eng)),
81 init_h_factor(init_h_factor), pmass(part_mass), vel_profile(vel_profile),
82 cs_profile(cs_profile) {}
83
84 bool is_done();
85
87
88 std::string get_name() { return "GeneratorMCDisc"; }
90 };
91
92} // namespace shammodels::sph::modules
93
94template<class Tvec, template<class> class SPHKernel>
95class shammodels::sph::modules::GeneratorMCDisc<Tvec, SPHKernel>::DiscIterator {
96
97 bool done = false;
98 u64 current_index = 0;
99
100 Tscal part_mass;
101 Tscal disc_mass;
102 u64 Npart;
103
104 Tscal r_in;
105 Tscal r_out;
106 std::function<Tscal(Tscal)> sigma_profile;
107 std::function<Tscal(Tscal)> H_profile;
108
110
111 static constexpr Tscal _2pi = 2 * shambase::constants::pi<Tscal>;
112
113 Tscal f_func(Tscal r) { return r * sigma_profile(r); }
114
115 DiscOutput next(u64 seed);
116
117 public:
118 DiscIterator(
119 Tscal part_mass,
120 Tscal disc_mass,
121 Tscal r_in,
122 Tscal r_out,
123 std::function<Tscal(Tscal)> sigma_profile,
124 std::function<Tscal(Tscal)> H_profile,
125 std::mt19937_64 eng)
126 : DiscIterator(
127 part_mass,
128 disc_mass,
129 r_in,
130 r_out,
131 sigma_profile,
132 H_profile,
133 eng,
134 disc_mass / part_mass) {}
135
136 DiscIterator(
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::mt19937_64 eng,
144 u64 Npart)
145 : part_mass(part_mass), disc_mass(disc_mass), Npart(Npart), r_in(r_in), r_out(r_out),
146 sigma_profile(sigma_profile), H_profile(H_profile), generator(eng, Npart),
147 current_index(0) {
148
149 shamlog_debug_ln(
150 "GeneratorMCDisc",
151 "part_mass",
152 part_mass,
153 "disc_mass",
154 disc_mass,
155 "r_in",
156 r_in,
157 "r_out",
158 r_out,
159 "Npart",
160 Npart);
161 }
162
163 inline bool is_done() {
164 return generator.is_done();
165 } // just to make sure the result is not tempered with
166
167 inline std::vector<DiscOutput> next_n(u64 nmax) {
168 std::vector<u64> seeds = generator.next_n(nmax);
169 std::vector<DiscOutput> ret{};
170 for (u64 seed : seeds) {
171 ret.push_back(next(seed));
172 }
173 return ret;
174 }
175};
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.
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.