Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AddForceCentralGravPotential.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
21
22namespace shammodels::common::modules {
23
24 template<class Tvec>
26
28
29 auto edges = get_edges();
30
31 edges.spans_positions.check_sizes(edges.sizes.indexes);
32 edges.spans_accel_ext.ensure_sizes(edges.sizes.indexes);
33
34 Tscal cmass = edges.central_mass.data;
35 Tscal G = edges.constant_G.data;
36 Tvec cpos = edges.central_pos.data;
37
39 shamsys::instance::get_compute_scheduler_ptr(),
40 sham::DDMultiRef{edges.spans_positions.get_spans()},
41 sham::DDMultiRef{edges.spans_accel_ext.get_spans()},
42 edges.sizes.indexes,
43 [mGM = -cmass * G, cpos](u32 gid, const Tvec *xyz, Tvec *axyz_ext) {
44 Tvec r_a = xyz[gid] - cpos;
45 Tscal abs_ra = sycl::length(r_a);
46 Tscal abs_ra_3 = abs_ra * abs_ra * abs_ra;
47 axyz_ext[gid] += mGM * r_a / abs_ra_3;
48 });
49 }
50
51 template<class Tvec>
53
54 auto constant_G = get_ro_edge_base(0).get_tex_symbol();
55 auto central_mass = get_ro_edge_base(1).get_tex_symbol();
56 auto central_pos = get_ro_edge_base(2).get_tex_symbol();
57 auto positions = get_ro_edge_base(3).get_tex_symbol();
58 auto axyz_ext = get_rw_edge_base(0).get_tex_symbol();
59
60 std::string tex = R"tex(
61 Add force (central gravitational potential)
62
63 \begin{align}
64 {axyz_ext}_i = -{constant_G} * {central_mass} * {central_pos}_i / {positions}_i^3
65 \end{align}
66 )tex";
67
68 shambase::replace_all(tex, "{constant_G}", constant_G);
69 shambase::replace_all(tex, "{central_mass}", central_mass);
70 shambase::replace_all(tex, "{central_pos}", central_pos);
71 shambase::replace_all(tex, "{positions}", positions);
72 shambase::replace_all(tex, "{axyz_ext}", axyz_ext);
73
74 return tex;
75 }
76
78
79} // namespace shammodels::common::modules
Adds the acceleration from a central gravitational potential (point mass).
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
virtual std::string _impl_get_tex() const
get the tex of the node
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:183
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.