Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ApplyExtForceDustTrapezoidal.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
18#include "shambase/string.hpp"
23
25
26 template<class Tvec>
28 auto edges = get_edges();
29
30 edges.spans_rho_dust.check_sizes(edges.sizes.indexes);
31 edges.spans_dt_rho_dust.check_sizes(edges.sizes.indexes);
32 edges.spans_a_ext_n.check_sizes(edges.sizes.indexes);
33 edges.spans_a_ext_np1.check_sizes(edges.sizes.indexes);
34 edges.spans_rhov_dust.check_sizes(edges.sizes.indexes);
35
36 Tscal dt = edges.dt.value;
37 Tscal dt_over2 = dt / 2;
38
39 shambase::DistributedData<u32> dust_cell_counts
40 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 block_count) {
41 return block_count * block_size * ndust;
42 });
43
45 shamsys::instance::get_compute_scheduler_ptr(),
47 edges.spans_rho_dust.get_spans(),
48 edges.spans_dt_rho_dust.get_spans(),
49 edges.spans_a_ext_n.get_spans(),
50 edges.spans_a_ext_np1.get_spans()},
51 sham::DDMultiRef{edges.spans_rhov_dust.get_spans()},
52 dust_cell_counts,
53 [dt, dt_over2, ndust = ndust](
54 u32 i,
55 const Tscal *__restrict rho_dust,
56 const Tscal *__restrict dt_rho_dust,
57 const Tvec *__restrict a_ext_n,
58 const Tvec *__restrict a_ext_np1,
59 Tvec *__restrict rhov_dust) {
60 // dust fields are laid out as [cell * ndust + idust]
61 u32 cell_id = i / ndust;
62
63 Tscal rho_n = rho_dust[i];
64
65 // dust density at t^{n+1}
66 Tscal rho_np1 = rho_n + dt * dt_rho_dust[i];
67
68 rhov_dust[i]
69 += dt_over2 * (rho_n * a_ext_n[cell_id] + rho_np1 * a_ext_np1[cell_id]);
70 });
71 }
72
73 template<class Tvec>
75 auto dt = get_ro_edge_base(0).get_tex_symbol();
76 auto rho_dust = get_ro_edge_base(2).get_tex_symbol();
77 auto dt_rho_dust = get_ro_edge_base(3).get_tex_symbol();
78 auto a_ext_n = get_ro_edge_base(4).get_tex_symbol();
79 auto a_ext_np1 = get_ro_edge_base(5).get_tex_symbol();
80 auto rhov_dust = get_rw_edge_base(0).get_tex_symbol();
81
82 std::string tex = R"tex(
83 Apply external forces to the dust species (trapezoidal rule)
84
85 \begin{align}
86 \rho^{n+1}_{d,i} &= {rho_dust}_i + {dt} \, {dt_rho_dust}_i \
87 {rhov_dust}_i &= {rhov_dust}_i + \frac{{dt}}{2} \left( {rho_dust}_i {a_ext_n}_i
88 + \rho^{n+1}_{d,i} {a_ext_np1}_i \right)
89 \end{align}
90 )tex";
91
92 shambase::replace_all(tex, "{dt}", dt);
93 shambase::replace_all(tex, "{rho_dust}", rho_dust);
94 shambase::replace_all(tex, "{dt_rho_dust}", dt_rho_dust);
95 shambase::replace_all(tex, "{a_ext_np1}", a_ext_np1);
96 shambase::replace_all(tex, "{a_ext_n}", a_ext_n);
97 shambase::replace_all(tex, "{rhov_dust}", rhov_dust);
98
99 return tex;
100 }
101
102} // namespace shammodels::basegodunov::modules
103
Node applying the external forces accelerations at t^n and t^{n+1} to the dust conservative state (tr...
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 momentum of every dust species with the trapezoidal ru...
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.