Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ApplyExtForceGas.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
18
19#include "shambase/string.hpp"
24
26
27 template<class Tvec>
29 auto edges = get_edges();
30
31 edges.spans_rho.check_sizes(edges.sizes.indexes);
32 edges.spans_dt_rho.check_sizes(edges.sizes.indexes);
33 edges.spans_dt_rhov.check_sizes(edges.sizes.indexes);
34 edges.spans_a_ext.check_sizes(edges.sizes.indexes);
35 edges.spans_rhov.check_sizes(edges.sizes.indexes);
36 edges.spans_rhoe.check_sizes(edges.sizes.indexes);
37
38 Tscal dt = edges.dt.value;
39 Tscal dt_over2 = dt / 2;
40
42 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 block_count) {
43 return block_count * block_size;
44 });
45
47 shamsys::instance::get_compute_scheduler_ptr(),
49 edges.spans_rho.get_spans(),
50 edges.spans_dt_rho.get_spans(),
51 edges.spans_dt_rhov.get_spans(),
52 edges.spans_a_ext.get_spans()},
53 sham::DDMultiRef{edges.spans_rhov.get_spans(), edges.spans_rhoe.get_spans()},
54 cell_counts,
55 [dt, dt_over2](
56 u32 i,
57 const Tscal *__restrict rho,
58 const Tscal *__restrict dt_rho,
59 const Tvec *__restrict dt_rhov,
60 const Tvec *__restrict a_ext,
61 Tvec *__restrict rhov,
62 Tscal *__restrict rhoe) {
63 // time centered density & momentum at t^{n+1/2}
64 Tscal rho_half = rho[i] + dt_over2 * dt_rho[i];
65 Tvec rhov_half = rhov[i] + dt_over2 * dt_rhov[i];
66
67 Tvec a = a_ext[i];
68
69 // TODO: to be confirmed, rhov_half does not include the kick of the external
70 // forces, so for a free fall the internal energy should drift by
71 // ~rho a^2 dt^2 / 2 per step (first order). Check if the energy update should
72 // instead use the momentum including the kick (as in RAMSES, which recomputes
73 // the kinetic energy after the kick).
74 rhov[i] += dt * rho_half * a;
75 rhoe[i] += dt * sycl::dot(a, rhov_half);
76 });
77 }
78
79 template<class Tvec>
81 auto dt = get_ro_edge_base(0).get_tex_symbol();
82 auto rho = get_ro_edge_base(2).get_tex_symbol();
83 auto dt_rho = get_ro_edge_base(3).get_tex_symbol();
84 auto dt_rhov = get_ro_edge_base(4).get_tex_symbol();
85 auto a_ext = get_ro_edge_base(5).get_tex_symbol();
86 auto rhov = get_rw_edge_base(0).get_tex_symbol();
87 auto rhoe = get_rw_edge_base(1).get_tex_symbol();
88
89 std::string tex = R"tex(
90 Apply external forces to the gas
91
92 \begin{align}
93 \rho^{n+1/2}_i &= {rho}_i + \frac{{dt}}{2} \, {dt_rho}_i \
94 (\rho \mathbf{v})^{n+1/2}_i &= {rhov}_i + \frac{{dt}}{2} \, {dt_rhov}_i \
95 {rhov}_i &= {rhov}_i + {dt} \, \rho^{n+1/2}_i {a_ext}_i \
96 {rhoe}_i &= {rhoe}_i + {dt} \, {a_ext}_i \cdot (\rho \mathbf{v})^{n+1/2}_i
97 \end{align}
98 )tex";
99
100 shambase::replace_all(tex, "{dt}", dt);
101 shambase::replace_all(tex, "{rho}", rho);
102 shambase::replace_all(tex, "{dt_rho}", dt_rho);
103 shambase::replace_all(tex, "{dt_rhov}", dt_rhov);
104 shambase::replace_all(tex, "{a_ext}", a_ext);
105 shambase::replace_all(tex, "{rhov}", rhov);
106 shambase::replace_all(tex, "{rhoe}", rhoe);
107
108 return tex;
109 }
110
111} // namespace shammodels::basegodunov::modules
112
Node applying the external forces acceleration to the gas conservative state.
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Represents a collection of objects distributed across patches identified by a u64 id.
Apply the external forces acceleration a_ext to the gas momentum and total energy,...
virtual std::string _impl_get_tex() const
get the tex of the node
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
Definition INode.hpp:147
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:138
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:106
namespace for the basegodunov model modules
A variant of sham::MultiRef for distributed data.