Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SinkParticlesFlagAccreteHard.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
21#include <shambackends/sycl.hpp>
22
24
25 template<class Tvec>
27
29
30 auto edges = get_edges();
31
32 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
33 auto &q = shambase::get_check_ref(dev_sched).get_queue();
34
35 auto &sink_positions = edges.sink_positions.data;
36 auto &sink_radii = edges.sink_accr_radii.data;
37
38 if (sink_positions.size() != sink_radii.size()) {
40 "Sink positions and accretion radii must have the same size");
41 }
42
43 if (!sink_pos) {
44 sink_pos = std::make_unique<sham::DeviceBuffer<Tvec>>(sink_positions.size(), dev_sched);
45 }
46 if (!sink_accr_radii) {
47 sink_accr_radii
48 = std::make_unique<sham::DeviceBuffer<Tscal>>(sink_radii.size(), dev_sched);
49 }
50
51 sink_pos->resize(sink_positions.size());
52 sink_accr_radii->resize(sink_radii.size());
53
54 sink_pos->copy_from_stdvec(sink_positions);
55 sink_accr_radii->copy_from_stdvec(sink_radii);
56
57 edges.positions.check_sizes(edges.part_counts.indexes);
58 edges.sink_accretion_table.ensure_sizes(edges.part_counts.indexes);
59
60 auto &pos_spans = edges.positions.get_spans();
61 auto &table_acc_spans = edges.sink_accretion_table.get_spans();
62
63 u32 sink_count = shambase::narrow_or_throw<u32>(sink_positions.size());
64
65 edges.part_counts.indexes.for_each([&](u64 id_patch, u32 part_count) {
67 q,
68 sham::MultiRef{pos_spans.get(id_patch), *sink_pos, *sink_accr_radii},
69 sham::MultiRef{table_acc_spans.get(id_patch)},
70 part_count,
71 [sink_count](
72 u32 id_a,
73 const Tvec *__restrict part_pos,
74 const Tvec *__restrict sink_pos,
75 const Tscal *__restrict sink_accr_radii,
76 u32 *__restrict sink_accretion_table) {
77 Tvec r_a = part_pos[id_a];
78
79 u32 result = u32_max;
80
81 for (u32 i_sink = 0; i_sink < sink_count; i_sink++) {
82 Tscal acc_radii = sink_accr_radii[i_sink];
83 Tvec d = r_a - sink_pos[i_sink];
84
85 bool should_accrete = sycl::dot(d, d) <= acc_radii * acc_radii;
86 if (should_accrete) {
87 result = i_sink;
88 break;
89 }
90 }
91
92 sink_accretion_table[id_a] = result;
93 });
94 });
95 }
96
97 template<class Tvec>
99 return "TODO";
100 }
101
102} // namespace shammodels::sph::modules
103
Header file describing a Node Instance.
Flag SPH particles inside sink accretion radii into an accretion table.
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 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 & 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:112
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
namespace for the sph model modules
Utilities for safe type narrowing conversions.
constexpr u32 u32_max
u32 max value
#define __shamrock_stack_entry()
Macro to create a stack entry.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33