Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ApplyExtForceDust.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.check_sizes(edges.sizes.indexes);
33 edges.spans_rhov_dust.check_sizes(edges.sizes.indexes);
34
35 Tscal dt = edges.dt.value;
36 Tscal dt_over2 = dt / 2;
37
38 shambase::DistributedData<u32> dust_cell_counts
39 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 block_count) {
40 return block_count * block_size * ndust;
41 });
42
44 shamsys::instance::get_compute_scheduler_ptr(),
46 edges.spans_rho_dust.get_spans(),
47 edges.spans_dt_rho_dust.get_spans(),
48 edges.spans_a_ext.get_spans()},
49 sham::DDMultiRef{edges.spans_rhov_dust.get_spans()},
50 dust_cell_counts,
51 [dt, dt_over2, ndust = ndust](
52 u32 i,
53 const Tscal *__restrict rho_dust,
54 const Tscal *__restrict dt_rho_dust,
55 const Tvec *__restrict a_ext,
56 Tvec *__restrict rhov_dust) {
57 // dust fields are laid out as [cell * ndust + idust]
58 u32 cell_id = i / ndust;
59
60 // time centered dust density at t^{n+1/2}
61 Tscal rho_half = rho_dust[i] + dt_over2 * dt_rho_dust[i];
62
63 rhov_dust[i] += dt * rho_half * a_ext[cell_id];
64 });
65 }
66
67 template<class Tvec>
69 auto dt = get_ro_edge_base(0).get_tex_symbol();
70 auto rho_dust = get_ro_edge_base(2).get_tex_symbol();
71 auto dt_rho_dust = get_ro_edge_base(3).get_tex_symbol();
72 auto a_ext = get_ro_edge_base(4).get_tex_symbol();
73 auto rhov_dust = get_rw_edge_base(0).get_tex_symbol();
74
75 std::string tex = R"tex(
76 Apply external forces to the dust species
77
78 \begin{align}
79 \rho^{n+1/2}_{d,i} &= {rho_dust}_i + \frac{{dt}}{2} \, {dt_rho_dust}_i \
80 {rhov_dust}_i &= {rhov_dust}_i + {dt} \, \rho^{n+1/2}_{d,i} {a_ext}_i
81 \end{align}
82 )tex";
83
84 shambase::replace_all(tex, "{dt}", dt);
85 shambase::replace_all(tex, "{rho_dust}", rho_dust);
86 shambase::replace_all(tex, "{dt_rho_dust}", dt_rho_dust);
87 shambase::replace_all(tex, "{a_ext}", a_ext);
88 shambase::replace_all(tex, "{rhov_dust}", rhov_dust);
89
90 return tex;
91 }
92
93} // namespace shammodels::basegodunov::modules
94
Node applying the external forces acceleration to the dust 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 momentum of every dust species,...
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.