Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SinkSelfGravityHost.hpp
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
10#pragma once
11
17
19#include "shambackends/sycl.hpp"
20#include "shambackends/vec.hpp"
23#include <vector>
24
25#define NODE_EDGES(X_RO, X_RW) \
26 X_RO(shamrock::solvergraph::IDataEdge<Tscal>, G) \
27 X_RO(shamrock::solvergraph::IDataEdge<Tscal>, epsilon) \
28 X_RO(shamrock::solvergraph::IDataEdge<std::vector<Tvec>>, positions) \
29 X_RO(shamrock::solvergraph::IDataEdge<std::vector<Tscal>>, masses) \
30 X_RW(shamrock::solvergraph::IDataEdge<std::vector<Tvec>>, acc_ext)
31
33
41 template<class Tvec>
42 class SinkSelfGravityHost : public shamrock::solvergraph::INode {
43
44 using Tscal = shambase::VecComponent<Tvec>;
45
46 public:
47 SinkSelfGravityHost() = default;
48
49 EXPAND_NODE_EDGES(NODE_EDGES)
50
53
54 auto edges = get_edges();
55
56 Tscal G = edges.G.data;
57 Tscal epsilon = edges.epsilon.data;
58 const std::vector<Tvec> &pos = edges.positions.data;
59 const std::vector<Tscal> &mass = edges.masses.data;
60 std::vector<Tvec> &acc_ext = edges.acc_ext.data;
61
62 for (size_t i = 0; i < pos.size(); i++) {
63 Tvec sum{};
64 for (size_t j = 0; j < pos.size(); j++) {
65 Tvec rij = pos[i] - pos[j];
66 Tscal rij_scal = sycl::length(rij);
67 sum -= G * mass[j] * rij / (rij_scal * rij_scal * rij_scal + epsilon);
68 }
69 acc_ext[i] = sum;
70 }
71 }
72
73 inline virtual std::string _impl_get_label() const { return "SinkSelfGravityHost"; }
74
75 inline virtual std::string _impl_get_tex() const { return "TODO"; }
76 };
77
78} // namespace shammodels::sph::modules
79
80#undef NODE_EDGES
virtual std::string _impl_get_tex() const
get the tex of the node
virtual std::string _impl_get_label() const
get the label of the node
Inode is node between data edges, takes multiple inputs, multiple outputs.
Definition INode.hpp:31
namespace for the sph model modules
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.