Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ModifierApplyDiscWarp.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
25
26template<class Tvec, template<class> class SPHKernel>
28 next_n(u32 nmax) {
29
31 Config solver_config;
32 ShamrockCtx &ctx = context;
33 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
34 shamrock::patch::PatchDataLayer tmp = parent->next_n(nmax);
35
37 constexpr Tscal _2pi = 2 * shambase::constants::pi<Tscal>;
38 Tscal Rwarp = Rwarp_;
39 Tscal Hwarp = Hwarp_;
40 Tscal inclination = inclination_;
41 Tscal posangle = posangle_;
42
44 auto &pdl = sched.pdl_old();
45 sham::DeviceBuffer<Tvec> &buf_xyz = tmp.get_field_buf_ref<Tvec>(pdl.get_field_idx<Tvec>("xyz"));
47 = tmp.get_field_buf_ref<Tvec>(pdl.get_field_idx<Tvec>("vxyz"));
48
49 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
50 sham::EventList depends_list;
51
52 auto acc_xyz = buf_xyz.get_write_access(depends_list);
53 auto acc_vxyz = buf_vxyz.get_write_access(depends_list);
54
55 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
56 shambase::parallel_for(cgh, tmp.get_obj_cnt(), "Warp", [=](i32 id_a) {
57 Tvec &xyz_a = acc_xyz[id_a];
58 Tvec &vxyz_a = acc_vxyz[id_a];
59
60 Tscal r = sycl::sqrt(sycl::dot(xyz_a, xyz_a));
61
62 Tvec k = Tvec(-sycl::sin(posangle), sycl::cos(posangle), 0.);
63 Tscal psi = 0.;
64
65 // convert to radians (sycl functions take radians)
66 Tscal incl_rad = inclination * shambase::constants::pi<Tscal> / 180.;
67
68 Tscal effective_inc;
69 if (r < Rwarp - Hwarp) {
70 effective_inc = 0.;
71 } else if (r < Rwarp + Hwarp && r > Rwarp - Hwarp) {
72 effective_inc = sycl::asin(
73 0.5
74 * (1. + sycl::sin(shambase::constants::pi<Tscal> / (2. * Hwarp) * (r - Rwarp)))
75 * sycl::sin(incl_rad));
76 psi = shambase::constants::pi<Tscal> * Rwarp / (4. * Hwarp) * sycl::sin(incl_rad)
77 / sycl::sqrt(1. - (0.5 * sycl::pown(sycl::sin(incl_rad), 2)));
78 Tscal psimax = sycl::max(psimax, psi);
79 } else {
80 effective_inc = incl_rad;
81 }
82
83 Tvec w = sycl::cross(k, xyz_a);
84 Tvec wv = sycl::cross(k, vxyz_a);
85 // Rodrigues' rotation formula
86 xyz_a = xyz_a * sycl::cos(effective_inc) + w * sycl::sin(effective_inc)
87 + k * sycl::dot(k, xyz_a) * (1. - sycl::cos(effective_inc));
88 vxyz_a = vxyz_a * sycl::cos(effective_inc) + wv * sycl::sin(effective_inc)
89 + k * sycl::dot(k, vxyz_a) * (1. - sycl::cos(effective_inc));
90 });
91 });
92
93 buf_xyz.complete_event_state(e);
94 buf_vxyz.complete_event_state(e);
95
96 return tmp;
97}
98
99using namespace shammath;
103
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)
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
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
The configuration for a sph solver.