Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ApplyExtForceGasTrapezoidal.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
19
20#include "shambase/string.hpp"
25
27
28 template<class Tvec>
30 auto edges = get_edges();
31
32 edges.spans_rho.check_sizes(edges.sizes.indexes);
33 edges.spans_dt_rho.check_sizes(edges.sizes.indexes);
34 edges.spans_dt_rhov.check_sizes(edges.sizes.indexes);
35 edges.spans_a_ext_n.check_sizes(edges.sizes.indexes);
36 edges.spans_a_ext_np1.check_sizes(edges.sizes.indexes);
37 edges.spans_rhov.check_sizes(edges.sizes.indexes);
38 edges.spans_rhoe.check_sizes(edges.sizes.indexes);
39
40 Tscal dt = edges.dt.value;
41 Tscal dt_over2 = dt / 2;
42
44 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 block_count) {
45 return block_count * block_size;
46 });
47
49 shamsys::instance::get_compute_scheduler_ptr(),
51 edges.spans_rho.get_spans(),
52 edges.spans_dt_rho.get_spans(),
53 edges.spans_dt_rhov.get_spans(),
54 edges.spans_a_ext_n.get_spans(),
55 edges.spans_a_ext_np1.get_spans()},
56 sham::DDMultiRef{edges.spans_rhov.get_spans(), edges.spans_rhoe.get_spans()},
57 cell_counts,
58 [dt, dt_over2](
59 u32 i,
60 const Tscal *__restrict rho,
61 const Tscal *__restrict dt_rho,
62 const Tvec *__restrict dt_rhov,
63 const Tvec *__restrict a_ext_n,
64 const Tvec *__restrict a_ext_np1,
65 Tvec *__restrict rhov,
66 Tscal *__restrict rhoe) {
67 Tscal rho_n = rho[i];
68 Tvec rhov_n = rhov[i];
69
70 // density at t^{n+1}
71 Tscal rho_np1 = rho_n + dt * dt_rho[i];
72
73 Tvec kick = dt_over2 * (rho_n * a_ext_n[i] + rho_np1 * a_ext_np1[i]);
74
75 // momentum at t^{n+1}, including the kick of the external forces
76 Tvec rhov_np1 = rhov_n + dt * dt_rhov[i] + kick;
77
78 rhov[i] += kick;
79 rhoe[i] += dt_over2
80 * (sycl::dot(a_ext_n[i], rhov_n) + sycl::dot(a_ext_np1[i], rhov_np1));
81 });
82 }
83
84 template<class Tvec>
86 auto dt = get_ro_edge_base(0).get_tex_symbol();
87 auto rho = get_ro_edge_base(2).get_tex_symbol();
88 auto dt_rho = get_ro_edge_base(3).get_tex_symbol();
89 auto dt_rhov = get_ro_edge_base(4).get_tex_symbol();
90 auto a_ext_n = get_ro_edge_base(5).get_tex_symbol();
91 auto a_ext_np1 = get_ro_edge_base(6).get_tex_symbol();
92 auto rhov = get_rw_edge_base(0).get_tex_symbol();
93 auto rhoe = get_rw_edge_base(1).get_tex_symbol();
94
95 std::string tex = R"tex(
96 Apply external forces to the gas (trapezoidal rule)
97
98 \begin{align}
99 \rho^{n+1}_i &= {rho}_i + {dt} \, {dt_rho}_i \
100 \Delta (\rho \mathbf{v})_i &= \frac{{dt}}{2} \left( {rho}_i {a_ext_n}_i
101 + \rho^{n+1}_i {a_ext_np1}_i \right) \
102 (\rho \mathbf{v})^{n+1}_i &= {rhov}_i + {dt} \, {dt_rhov}_i
103 + \Delta (\rho \mathbf{v})_i \
104 {rhoe}_i &= {rhoe}_i + \frac{{dt}}{2} \left( {a_ext_n}_i \cdot {rhov}_i
105 + {a_ext_np1}_i \cdot (\rho \mathbf{v})^{n+1}_i \right) \
106 {rhov}_i &= {rhov}_i + \Delta (\rho \mathbf{v})_i
107 \end{align}
108 )tex";
109
110 shambase::replace_all(tex, "{dt}", dt);
111 shambase::replace_all(tex, "{rho}", rho);
112 shambase::replace_all(tex, "{dt_rho}", dt_rho);
113 shambase::replace_all(tex, "{dt_rhov}", dt_rhov);
114 shambase::replace_all(tex, "{a_ext_np1}", a_ext_np1);
115 shambase::replace_all(tex, "{a_ext_n}", a_ext_n);
116 shambase::replace_all(tex, "{rhov}", rhov);
117 shambase::replace_all(tex, "{rhoe}", rhoe);
118
119 return tex;
120 }
121
122} // namespace shammodels::basegodunov::modules
123
Node applying the external forces accelerations at t^n and t^{n+1} to the gas conservative state (tra...
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 accelerations to the gas momentum and total energy with the trapezoidal rul...
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.