Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AnalysisDustMass.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
19#include "shambase/memory.hpp"
27#include <shambackends/sycl.hpp>
28
30
31 template<class Tvec, template<class> class SPHKernel>
32 class AnalysisDustMass {
33 public:
34 using Tscal = shambase::VecComponent<Tvec>;
35 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
36
37 using Solver = Solver<Tvec, SPHKernel>;
38
39 using Kernel = SPHKernel<Tscal>;
40
42 Solver &solver;
43 ShamrockCtx &ctx;
44
45 AnalysisDustMass(Model<Tvec, SPHKernel> &model)
46 : model(model), ctx(model.ctx), solver(model.solver) {};
47
48 auto get_dust_mass() -> std::vector<Tscal> {
49
50 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
51 auto dev_sched_ptr = shamsys::instance::get_compute_scheduler_ptr();
52 sham::DeviceQueue &q = shambase::get_check_ref(dev_sched_ptr).get_queue();
53
54 u64 ndust = solver.solver_config.dust_config.get_dust_nvar();
55
56 const u32 ihpart = sched.pdl_old().template get_field_idx<Tscal>("hpart");
57 const u32 is_j = sched.pdl_old().template get_field_idx<Tscal>("s_j");
58
59 Tscal pmass = solver.solver_config.gpart_mass;
60
61 std::vector<Tscal> dust_mass(ndust, 0.0);
62
63 sham::DeviceBuffer<Tscal> dust_mass_j_part(0, dev_sched_ptr);
64
65 sched.for_each_patchdata_nonempty(
67 u32 len = pdat.get_obj_cnt();
68
69 dust_mass_j_part.resize(len);
70
71 sham::DeviceBuffer<Tscal> &hpart_buf = pdat.get_field_buf_ref<Tscal>(ihpart);
72 sham::DeviceBuffer<Tscal> &s_j_buf = pdat.get_field_buf_ref<Tscal>(is_j);
73
74 for (u32 jdust = 0; jdust < ndust; jdust++) {
76 q,
77 sham::MultiRef{hpart_buf, s_j_buf},
78 sham::MultiRef{dust_mass_j_part},
79 len,
80 [pmass, jdust, ndust](
81 u32 i,
82 const Tscal *__restrict hpart,
83 const Tscal *__restrict s_j,
84 Tscal *__restrict dust_mass_j_part) {
85 Tscal h_a = hpart[i];
86 Tscal rho_a = shamrock::sph::rho_h(pmass, h_a, Kernel::hfactd);
87 Tscal s_ja = s_j[i * ndust + jdust];
88 Tscal epsilon_ja = s_ja * s_ja / rho_a;
89
90 dust_mass_j_part[i] = pmass * epsilon_ja;
91 });
92
93 dust_mass[jdust]
94 += shamalgs::primitives::sum(dev_sched_ptr, dust_mass_j_part, 0, len);
95 }
96 });
97
98 for (u32 jdust = 0; jdust < ndust; jdust++) {
99 dust_mass[jdust] = shamalgs::collective::allreduce_sum(dust_mass[jdust]);
100 }
101
102 return dust_mass;
103 }
104 };
105} // namespace shammodels::sph::modules
MPI scheduler.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
The MPI scheduler.
A buffer allocated in USM (Unified Shared Memory).
void resize(size_t new_size, bool keep_data=true)
Resizes the buffer to a given size.
A SYCL queue associated with a device and a context.
The shamrock SPH model.
Definition Model.hpp:55
PatchDataLayer container class, the layout is described in patchdata_layout.
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
T sum(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Compute the sum of elements in a device buffer within a specified range.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
namespace for the sph model modules
A class that references multiple buffers or similar objects.
Patch object that contain generic patch information.
Definition Patch.hpp:33