Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
TimeIntegrator.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
17
18template<class Tvec, class TgridVec>
20
21 StackEntry stack_loc{};
22
23 using namespace shamrock::patch;
24 using namespace shamrock;
25 using namespace shammath;
26
28 shamrock::solvergraph::Field<Tvec> &cfield_dtrhov = shambase::get_check_ref(storage.dtrhov);
29 shamrock::solvergraph::Field<Tscal> &cfield_dtrhoe = shambase::get_check_ref(storage.dtrhoe);
30
31 // load layout info
32 PatchDataLayerLayout &pdl = scheduler().pdl_old();
33
34 const u32 icell_min = pdl.get_field_idx<TgridVec>("cell_min");
35 const u32 icell_max = pdl.get_field_idx<TgridVec>("cell_max");
36 const u32 irho = pdl.get_field_idx<Tscal>("rho");
37 const u32 irhoetot = pdl.get_field_idx<Tscal>("rhoetot");
38 const u32 irhovel = pdl.get_field_idx<Tvec>("rhovel");
39
40 scheduler().for_each_patchdata_nonempty(
42 shamlog_debug_ln("[AMR Flux]", "forward euler integration patch", p.id_patch);
43
44 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
45 u32 id = p.id_patch;
46
47 sham::DeviceBuffer<Tscal> &dt_rho_patch = cfield_dtrho.get_buf(id);
48 sham::DeviceBuffer<Tvec> &dt_rhov_patch = cfield_dtrhov.get_buf(id);
49 sham::DeviceBuffer<Tscal> &dt_rhoe_patch = cfield_dtrhoe.get_buf(id);
50
51 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
52
53 sham::DeviceBuffer<Tscal> &buf_rho = pdat.get_field_buf_ref<Tscal>(irho);
54 sham::DeviceBuffer<Tvec> &buf_rhov = pdat.get_field_buf_ref<Tvec>(irhovel);
55 sham::DeviceBuffer<Tscal> &buf_rhoe = pdat.get_field_buf_ref<Tscal>(irhoetot);
56
57 sham::EventList depends_list;
58 auto acc_dt_rho_patch = dt_rho_patch.get_read_access(depends_list);
59 auto acc_dt_rhov_patch = dt_rhov_patch.get_read_access(depends_list);
60 auto acc_dt_rhoe_patch = dt_rhoe_patch.get_read_access(depends_list);
61
62 auto rho = buf_rho.get_write_access(depends_list);
63 auto rhov = buf_rhov.get_write_access(depends_list);
64 auto rhoe = buf_rhoe.get_write_access(depends_list);
65
66 auto e = q.submit(depends_list, [&, dt](sycl::handler &cgh) {
67 shambase::parallel_for(cgh, cell_count, "accumulate fluxes", [=](u32 id_a) {
68 const u32 cell_global_id = (u32) id_a;
69
70 rho[id_a] += dt * acc_dt_rho_patch[id_a];
71 rhov[id_a] += dt * acc_dt_rhov_patch[id_a];
72 rhoe[id_a] += dt * acc_dt_rhoe_patch[id_a];
73 });
74 });
75
76 dt_rho_patch.complete_event_state(e);
77 dt_rhov_patch.complete_event_state(e);
78 dt_rhoe_patch.complete_event_state(e);
79
80 buf_rho.complete_event_state(e);
81 buf_rhov.complete_event_state(e);
82 buf_rhoe.complete_event_state(e);
83 });
84
85 if (solver_config.is_dust_on()) {
86
88 = shambase::get_check_ref(storage.dtrho_dust);
89 shamrock::solvergraph::Field<Tvec> &cfield_dtrhov_dust
90 = shambase::get_check_ref(storage.dtrhov_dust);
91
92 const u32 irho_dust = pdl.get_field_idx<Tscal>("rho_dust");
93 const u32 irhovel_dust = pdl.get_field_idx<Tvec>("rhovel_dust");
94
95 scheduler().for_each_patchdata_nonempty([&, dt](
98 shamlog_debug_ln(
99 "[AMR Flux]", "forward euler integration patch for dust fields", p.id_patch);
100
101 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
102 u32 id = p.id_patch;
103
104 sham::DeviceBuffer<Tscal> &dt_rho_dust_patch = cfield_dtrho_dust.get_buf(id);
105 sham::DeviceBuffer<Tvec> &dt_rhov_dust_patch = cfield_dtrhov_dust.get_buf(id);
106
107 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
108 u32 ndust = solver_config.dust_config.ndust;
109
110 sham::DeviceBuffer<Tscal> &buf_rho_dust = pdat.get_field_buf_ref<Tscal>(irho_dust);
111 sham::DeviceBuffer<Tvec> &buf_rhov_dust = pdat.get_field_buf_ref<Tvec>(irhovel_dust);
112
113 sham::EventList depends_list;
114 auto acc_dt_rho_dust_patch = dt_rho_dust_patch.get_read_access(depends_list);
115 auto acc_dt_rhov_dust_patch = dt_rhov_dust_patch.get_read_access(depends_list);
116
117 auto rho_dust = buf_rho_dust.get_write_access(depends_list);
118 auto rhov_dust = buf_rhov_dust.get_write_access(depends_list);
119
120 auto e = q.submit(depends_list, [&, dt](sycl::handler &cgh) {
121 shambase::parallel_for(cgh, ndust * cell_count, "accumulate fluxes", [=](u32 id_a) {
122 rho_dust[id_a] += dt * acc_dt_rho_dust_patch[id_a];
123 rhov_dust[id_a] += dt * acc_dt_rhov_dust_patch[id_a];
124 });
125 });
126
127 dt_rho_dust_patch.complete_event_state(e);
128 dt_rhov_dust_patch.complete_event_state(e);
129 buf_rho_dust.complete_event_state(e);
130 buf_rhov_dust.complete_event_state(e);
131 });
132 }
133}
134
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
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
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