Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AddForcePaczynskiWiita.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
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 Tscal c = edges.constant_c.data;
37 Tvec cpos = edges.central_pos.data;
38 Tscal rs = 2 * G * cmass / (c * c);
39
41 shamsys::instance::get_compute_scheduler_ptr(),
42 sham::DDMultiRef{edges.spans_positions.get_spans()},
43 sham::DDMultiRef{edges.spans_accel_ext.get_spans()},
44 edges.sizes.indexes,
45 [GM = cmass * G, rs, cpos](u32 gid, const Tvec *xyz, Tvec *axyz_ext) {
46 Tvec r_a = xyz[gid] - cpos;
47 Tscal abs_ra = sycl::length(r_a);
48 Tscal denom = (abs_ra - rs) * (abs_ra - rs) * abs_ra;
49
50 axyz_ext[gid] += -GM * r_a / denom;
51 });
52 }
53
54 template<class Tvec>
56
57 auto constant_G = get_ro_edge_base(0).get_tex_symbol();
58 auto constant_c = get_ro_edge_base(1).get_tex_symbol();
59 auto central_mass = get_ro_edge_base(2).get_tex_symbol();
60 auto central_pos = get_ro_edge_base(3).get_tex_symbol();
61 auto positions = get_ro_edge_base(4).get_tex_symbol();
62 auto axyz_ext = get_rw_edge_base(0).get_tex_symbol();
63
64 std::string tex = R"tex(
65 Add force (Paczynski-Wiita potential)
66
67 \begin{align}
68 r_{\text{s}} &= 2 * {constant_G}* {central_mass} / {constant_c}^2\\
69 r_i &= {positions}_i - {central_pos}_i\\
70 r &= \sqrt{\sum r_i^2}\\
71 {axyz_ext}_i &= -{constant_G} * {central_mass} * r_i / (r * (r - r_{\text{s}})^2)
72 \end{align}
73 )tex";
74
75 shambase::replace_all(tex, "{constant_G}", constant_G);
76 shambase::replace_all(tex, "{central_mass}", central_mass);
77 shambase::replace_all(tex, "{central_pos}", central_pos);
78 shambase::replace_all(tex, "{positions}", positions);
79 shambase::replace_all(tex, "{axyz_ext}", axyz_ext);
80
81 return tex;
82 }
83
85
86} // namespace shammodels::common::modules
Adds the acceleration from a Paczynski Wiita (1980) pseudo-newtonian potential.
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
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:100
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:91
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:110
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.