Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ModifierApplyCustomWarp.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
20#include "shamcomm/logs.hpp"
26
27template<class Tvec, template<class> class SPHKernel>
29 next_n(u32 nmax) {
30
31 ShamrockCtx &ctx = context;
32 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
33 shamrock::patch::PatchDataLayer tmp = parent->next_n(nmax);
34
36 auto &pdl = sched.pdl_old();
37 sham::DeviceBuffer<Tvec> &buf_xyz = tmp.get_field_buf_ref<Tvec>(pdl.get_field_idx<Tvec>("xyz"));
39 = tmp.get_field_buf_ref<Tvec>(pdl.get_field_idx<Tvec>("vxyz"));
40
41 auto acc_xyz = buf_xyz.copy_to_stdvec();
42 auto acc_vxyz = buf_vxyz.copy_to_stdvec();
43
44 for (i32 id_a = 0; id_a < tmp.get_obj_cnt(); ++id_a) {
45 Tvec &xyz_a = acc_xyz[id_a];
46 Tvec &vxyz_a = acc_vxyz[id_a];
47
48 Tscal r = sycl::sqrt(sycl::dot(xyz_a, xyz_a));
49
50 Tvec k = k_profile(r);
51 Tscal psi = psi_profile(r);
52 Tscal effective_inc = inc_profile(r);
53
54 Tvec w = sycl::cross(k, xyz_a);
55 Tvec wv = sycl::cross(k, vxyz_a);
56 // Rodrigues' rotation formula
57 xyz_a = xyz_a * sycl::cos(effective_inc) + w * sycl::sin(effective_inc)
58 + k * sycl::dot(k, xyz_a) * (1. - sycl::cos(effective_inc));
59 vxyz_a = vxyz_a * sycl::cos(effective_inc) + wv * sycl::sin(effective_inc)
60 + k * sycl::dot(k, vxyz_a) * (1. - sycl::cos(effective_inc));
61 };
62
63 buf_xyz.copy_from_stdvec(acc_xyz);
64 buf_vxyz.copy_from_stdvec(acc_vxyz);
65
66 return tmp;
67}
68
69using namespace shammath;
73
std::uint32_t u32
32 bit unsigned integer
std::int32_t i32
32 bit integer
The MPI scheduler.
A buffer allocated in USM (Unified Shared Memory)
void copy_from_stdvec(const std::vector< T > &vec)
Copy the content of a std::vector into the buffer.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
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...
PatchDataLayer container class, the layout is described in patchdata_layout.
Class holding the value of numerous constants generated from the following source.
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 math utility
Definition AABB.hpp:26