Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AnalysisAngularMomentum.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
19#include "shambase/memory.hpp"
26#include <shambackends/sycl.hpp>
27
29
30 template<class Tvec, template<class> class SPHKernel>
32 public:
33 using Tscal = shambase::VecComponent<Tvec>;
35
36 using Solver = Solver<Tvec, SPHKernel>;
37
39 Solver &solver;
40 ShamrockCtx &ctx;
41
43 : model(model), ctx(model.ctx), solver(model.solver) {};
44
45 auto get_angular_momentum() -> Tvec {
46 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
47 auto dev_sched_ptr = shamsys::instance::get_compute_scheduler_ptr();
48 sham::DeviceQueue &q = shambase::get_check_ref(dev_sched_ptr).get_queue();
49
50 const u32 ivxyz = sched.pdl_old().template get_field_idx<Tvec>("vxyz");
51 const u32 ixyz = sched.pdl_old().template get_field_idx<Tvec>("xyz");
52 const Tscal pmass = solver.solver_config.gpart_mass;
53
54 Tvec angular_momentum = {};
55
56 sham::DeviceBuffer<Tvec> angular_momentum_part(0, dev_sched_ptr);
57
58 sched.for_each_patchdata_nonempty(
60 u32 len = pdat.get_obj_cnt();
61
62 angular_momentum_part.resize(len);
63
64 sham::DeviceBuffer<Tvec> &xyz_buf = pdat.get_field_buf_ref<Tvec>(ixyz);
65 sham::DeviceBuffer<Tvec> &vxyz_buf = pdat.get_field_buf_ref<Tvec>(ivxyz);
66
68 q,
69 sham::MultiRef{xyz_buf, vxyz_buf},
70 sham::MultiRef{angular_momentum_part},
71 len,
72 [pmass](
73 u32 i,
74 const Tvec *__restrict xyz,
75 const Tvec *__restrict vxyz,
76 Tvec *__restrict angular_momentum_part) {
77 angular_momentum_part[i] = pmass * sycl::cross(xyz[i], vxyz[i]);
78 });
79
80 angular_momentum
81 += shamalgs::primitives::sum(dev_sched_ptr, angular_momentum_part, 0, len);
82 });
83
84 Tvec tot_angular_momentum = shamalgs::collective::allreduce_sum(angular_momentum);
85
86 if (!solver.storage.sinks.is_empty()) {
87 for (auto &sink : solver.storage.sinks.get()) {
88 tot_angular_momentum
89 += sink.mass * sycl::cross(sink.pos, sink.velocity) + sink.angular_momentum;
90 }
91 }
92
93 return tot_angular_momentum;
94 }
95 };
96} // namespace shammodels::sph::modules
MPI scheduler.
std::uint32_t u32
32 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