Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputePressure.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
21
22template<class Tvec, class TgridVec>
24
25 StackEntry stack_loc{};
26
27 using namespace shamrock::patch;
28 using namespace shamrock;
29 using namespace shammath;
30 using MergedPDat = shamrock::MergedPatchData;
31
32 shamrock::SchedulerUtility utility(scheduler());
33
34 using Block = typename Config::AMRBlock;
35
36 storage.pressure.set(
37 utility.make_compute_field<Tscal>("pressure", Block::block_size, [&](u64 id) {
38 return storage.merged_patchdata_ghost.get().get(id).total_elements;
39 }));
40
41 ComputeField<Tscal> &pressure_field = storage.pressure.get();
42
44 = shambase::get_check_ref(storage.ghost_layout.get());
45 u32 irho_interf = ghost_layout.get_field_idx<Tscal>("rho");
46 u32 ieint_interf = ghost_layout.get_field_idx<Tscal>("eint");
47
48 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
49 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
50
51 PatchDataField<Tscal> &press = storage.pressure.get().get_field(p.id_patch);
52
53 sham::DeviceBuffer<Tscal> &buf_p = pressure_field.get_buf_check(p.id_patch);
54 sham::DeviceBuffer<Tscal> &buf_rho = mpdat.pdat.get_field_buf_ref<Tscal>(irho_interf);
55 sham::DeviceBuffer<Tscal> &buf_eint = mpdat.pdat.get_field_buf_ref<Tscal>(ieint_interf);
56
57 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
58
59 sham::EventList depends_list;
60 auto rho = buf_rho.get_read_access(depends_list);
61 auto eint = buf_eint.get_read_access(depends_list);
62 auto pressure = buf_p.get_write_access(depends_list);
63
64 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
65 Tscal gamma = solver_config.eos_gamma;
66
67 shambase::parallel_for(
68 cgh, mpdat.total_elements * Block::block_size, "compute pressure", [=](u64 id_a) {
69 pressure[id_a] = (gamma - 1) * eint[id_a];
70 });
71 });
72
73 buf_rho.complete_event_state(e);
74 buf_eint.complete_event_state(e);
75 buf_p.complete_event_state(e);
76 });
77}
78
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 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.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
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
This file contains the definition for the stacktrace related functionality.
utility class to handle AMR blocks
Definition AMRBlock.hpp:35
Patch object that contain generic patch information.
Definition Patch.hpp:33