Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
BarotropicEnergyReset.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
16
20
21template<class Tvec, class TgridVec>
23
24 StackEntry stack_loc{};
25
26 using namespace shamrock::patch;
27
28 using InstantBarotropic = typename CoolingConfig<Tvec>::InstantBarotropic;
29 const InstantBarotropic *cfg
30 = std::get_if<InstantBarotropic>(&solver_config.cooling_config.config);
31 if (cfg == nullptr) {
32 return;
33 }
34
35 const shammath::FluidStateBarotropic<Tvec> barotrope = cfg->get_barotrope();
36 const Tscal gamma = solver_config.get_eos_gamma();
37
38 PatchDataLayerLayout &pdl = scheduler().pdl_old();
39
40 const u32 irho = pdl.get_field_idx<Tscal>("rho");
41 const u32 irhoetot = pdl.get_field_idx<Tscal>("rhoetot");
42 const u32 irhovel = pdl.get_field_idx<Tvec>("rhovel");
43
44 scheduler().for_each_patchdata_nonempty(
46 shamlog_debug_ln("[AMR Flux]", "barotropic energy reset patch", p.id_patch);
47
48 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
49
50 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
51
52 sham::DeviceBuffer<Tscal> &buf_rho = pdat.get_field_buf_ref<Tscal>(irho);
53 sham::DeviceBuffer<Tvec> &buf_rhov = pdat.get_field_buf_ref<Tvec>(irhovel);
54 sham::DeviceBuffer<Tscal> &buf_rhoe = pdat.get_field_buf_ref<Tscal>(irhoetot);
55
57 q,
58 sham::MultiRef{buf_rho, buf_rhov},
59 sham::MultiRef{buf_rhoe},
60 cell_count,
61 [barotrope, gamma](
62 u32 id_a,
63 const Tscal *__restrict rho,
64 const Tvec *__restrict rhov,
65 Tscal *__restrict rhoe) {
66 // the barotropic cons_to_prim ignores rhoe and sets press = P_baro(rho)
67 auto prim = barotrope.cons_to_prim(
68 shammath::ConsState<Tvec>{rho[id_a], rhoe[id_a], rhov[id_a]});
69
70 rhoe[id_a] = shammath::prim_to_cons(prim, gamma).rhoe;
71 });
72 });
73}
74
Internal energy reset onto the barotrope of the InstantBarotropic cooling.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
A SYCL queue associated with a device and a context.
FluidStateSpec implementation for a barotropic equation of state that is isothermal below a threshold...
Overwrite the gas internal energy by the barotropic one (CoolingConfig::InstantBarotropic).
void reset_energy()
Apply the reset, does nothing if the cooling is not CoolingConfig::InstantBarotropic.
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.
u32 get_obj_cnt() const
get the number of objects (particles) stored in this layer
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
Gas and dust conservative/primitive states and axis-transform helpers shared by every gas and dust Ri...
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33
Instantaneous cooling onto a barotrope (RAMSES-like).
Patch object that contain generic patch information.
Definition Patch.hpp:33
u64 id_patch
unique key that identify the patch
Definition Patch.hpp:86