Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AddExtForcePointMassGravity.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
16
21
23
24 template<class Tvec>
26 using Tscal = shambase::VecComponent<Tvec>;
27
28 auto edges = get_edges();
29
30 edges.spans_coordinates.check_sizes(edges.sizes.indexes);
31 edges.spans_a_ext.check_sizes(edges.sizes.indexes);
32
33 auto &coordinates_spans = edges.spans_coordinates.get_spans();
34 auto &a_ext_spans = edges.spans_a_ext.get_spans();
35
36 const Tscal gmass = mass * edges.constant_G.value;
37
39 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 block_count) {
40 u32 cell_count = block_count * block_size;
41 return cell_count;
42 });
43
44 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
45
47 shamsys::instance::get_compute_scheduler_ptr(),
48 sham::DDMultiRef{coordinates_spans},
49 sham::DDMultiRef{a_ext_spans},
50 cell_counts,
51 [pos = pos, gmass = gmass, epsilon_soft = epsilon_soft](
52 u32 i, const Tvec *__restrict cell_coor, Tvec *__restrict a_ext) {
53 Tvec cell_pos = cell_coor[i];
54
55 // compute vector from the point mass to the cell
56 Tvec r_vec = cell_pos - pos;
57
58 // compute distance to the point mass
59 Tscal r_squared = sycl::dot(r_vec, r_vec);
60
61 Tscal inv_r_soft = sycl::rsqrt(r_squared + epsilon_soft * epsilon_soft);
62 Tscal one_over_r_cube_soft = inv_r_soft * inv_r_soft * inv_r_soft;
63
64 // compute gravitational acceleration using softened point mass potential
65 a_ext[i] -= gmass * r_vec * one_over_r_cube_soft;
66 });
67 }
68
69 template<class Tvec>
71 auto coords = get_ro_edge_base(1).get_tex_symbol();
72 auto a_ext = get_rw_edge_base(0).get_tex_symbol();
73
74 std::string tex = R"tex(
75 Add the gravity of a softened point mass to the external forces acceleration
76
77 \begin{align}
78 {{a_ext}}_i &= {{a_ext}}_i - \frac{G M \left({{coords}}_i - \mathbf{r}_0\right)}
79 {\left(\left|{{coords}}_i - \mathbf{r}_0\right|^2 + \epsilon^2\right)^{3/2}}
80 \end{align}
81 )tex";
82
83 shambase::replace_all(tex, "{a_ext}", a_ext);
84 shambase::replace_all(tex, "{coords}", coords);
85
86 return tex;
87 }
88
89} // namespace shammodels::basegodunov::modules
90
Compute a gravitational acceleration at the center of each cell, using an analytical formula.
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.
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.