Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
DiffOperator.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
22
23template<class Tvec, class TgridVec>
25
26 using namespace shamrock::patch;
27 using namespace shamrock;
28 using namespace shammath;
29 using MergedPDat = shamrock::MergedPatchData;
30
31 using Flagger = FaceFlagger<Tvec, TgridVec>;
32
33 shamrock::SchedulerUtility utility(scheduler());
34 storage.gradu.set(utility.make_compute_field<Tvec>("gradu", 3, [&](u64 id) {
35 return storage.merged_patchdata_ghost.get().get(id).total_elements;
36 }));
37
39 = shambase::get_check_ref(storage.ghost_layout.get());
40 u32 ivel_interf = ghost_layout.get_field_idx<Tvec>("vel");
41
42 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
43 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
44
45 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
46 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
47
49 = storage.face_lists.get().get(p.id_patch);
50
51 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
52 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
53 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
54
55 Tscal coord_conv_fact = solver_config.grid_coord_to_pos_fact;
56
57 sham::DeviceBuffer<Tvec> &buf_vel = mpdat.pdat.get_field_buf_ref<Tvec>(ivel_interf);
58 sham::DeviceBuffer<Tvec> &buf_grad_u = storage.gradu.get().get_buf_check(p.id_patch);
59
60 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
61
62 sham::EventList depends_list;
63
64 auto cell_min = buf_cell_min.get_read_access(depends_list);
65 auto cell_max = buf_cell_max.get_read_access(depends_list);
66
67 auto vel = buf_vel.get_read_access(depends_list);
68 auto grad_u = buf_grad_u.get_write_access(depends_list);
69
70 auto faces_xm_ptr = face_xm.neigh_info.get_read_access(depends_list);
71
72 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
73 tree::ObjectCacheIterator faces_xm(faces_xm_ptr);
74
75 shambase::parallel_for(cgh, pdat.get_obj_cnt(), "subsetp1", [=](u64 id_a) {
76 Tvec cell2_a = (cell_min[id_a] + cell_max[id_a]).template convert<Tscal>()
77 * coord_conv_fact * 0.5f;
78
79 Tvec sum_grad_ux = {};
80
81 // looks like it's on the double preicision roofline there is
82 // nothing to optimize here turn around
83 faces_xm.for_each_object(id_a, [&](u32 id_b) {
84 Tvec cell2_b = (cell_min[id_b] + cell_max[id_b]).template convert<Tscal>()
85 * coord_conv_fact * 0.5f;
86
87 Tvec n = {-1, 0, 0};
88 Tscal dr_proj = sycl::dot(cell2_b - cell2_a, n);
89
90 Tvec drm1_n = n / dr_proj;
91
92 // buf_grad_u += drm1_n * rho[id_b];
93 });
94
95 // grad_p[id_a] = -buf_grad_u;
96 });
97 });
98
99 buf_cell_min.complete_event_state(e);
100 buf_cell_max.complete_event_state(e);
101 buf_vel.complete_event_state(e);
102 buf_grad_u.complete_event_state(e);
103
104 sham::EventList resulting_events;
105 resulting_events.add_event(e);
106 face_xm.neigh_info.complete_event_state(resulting_events);
107 });
108}
109
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
void add_event(sycl::event e)
Add an event to the list of events.
Definition EventList.hpp:87
void compute_gradu()
compute gradient tensor of the velocity from existing data
flag faces with a lookup index for the orientation
ComputeField< T > make_compute_field(std::string new_name, u32 nvar)
create a compute field and init it to zeros
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
PatchDataLayer container class, the layout is described in patchdata_layout.
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
namespace for the main framework
Definition __init__.py:1
Patch object that contain generic patch information.
Definition Patch.hpp:33