33 using Tscal = shambase::VecComponent<Tvec>;
36 using Solver = Solver<Tvec, SPHKernel>;
43 : model(model), ctx(model.ctx), solver(model.solver) {};
52 auto get_barycenter() ->
result {
54 auto dev_sched_ptr = shamsys::instance::get_compute_scheduler_ptr();
57 const u32 ixyz = sched.pdl_old().template get_field_idx<Tvec>(
"xyz");
58 const Tscal pmass = solver.solver_config.gpart_mass;
60 Tvec barycenter = {0, 0, 0};
63 sched.for_each_patchdata_nonempty(
76 u32 len = pdat.get_obj_cnt();
77 mass_disc += pmass * len;
87 [pmass](
u32 i,
const Tvec *__restrict xyz, Tvec *__restrict pm) {
88 pm[i] = pmass * xyz[i];
93 Tvec tot_barycenter = shamalgs::collective::allreduce_sum(barycenter);
94 Tscal tot_mass_disc = shamalgs::collective::allreduce_sum(mass_disc);
95 Tscal tot_mass = tot_mass_disc;
97 if (!solver.storage.sinks.is_empty()) {
98 for (
auto &sink : solver.storage.sinks.get()) {
99 Tvec star_xyz = sink.pos;
100 Tscal star_mass = sink.mass;
102 tot_barycenter += star_xyz * star_mass;
103 tot_mass += star_mass;
106 tot_barycenter /= tot_mass;
107 return result{tot_barycenter, tot_mass_disc};
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...