Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeCFLSinkSink.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
18
21#include "shambase/string.hpp"
22#include "shambackends/math.hpp"
23#include "shambackends/sycl.hpp"
24#include "shambackends/vec.hpp"
27#include <vector>
28
29#define NODE_EDGES(X_RO, X_RW) \
30 X_RO(shamrock::solvergraph::IDataEdge<Tscal>, G) \
31 X_RO(shamrock::solvergraph::IDataEdge<Tscal>, C_force) \
32 X_RO(shamrock::solvergraph::IDataEdge<Tscal>, eta_phi) \
33 X_RO(shamrock::solvergraph::IDataEdge<std::vector<Tvec>>, positions) \
34 X_RO(shamrock::solvergraph::IDataEdge<std::vector<Tscal>>, masses) \
35 X_RO(shamrock::solvergraph::IDataEdge<std::vector<Tvec>>, acc_ext) \
36 X_RW(shamrock::solvergraph::IDataEdge<Tscal>, cfl_dt)
37
47template<class Tvec>
48class ComputeCFLSinkSink : public shamrock::solvergraph::INode {
49
50 using Tscal = shambase::VecComponent<Tvec>;
51
52 public:
53 ComputeCFLSinkSink() = default;
54
55 EXPAND_NODE_EDGES(NODE_EDGES)
56
59
60 auto edges = get_edges();
61
62 Tscal G = edges.G.data;
63 Tscal C_force = edges.C_force.data;
64 Tscal eta_phi = edges.eta_phi.data;
65
66 const std::vector<Tvec> &pos = edges.positions.data;
67 const std::vector<Tscal> &mass = edges.masses.data;
68 const std::vector<Tvec> &acc_ext = edges.acc_ext.data;
69
70 Tscal sink_sink_cfl = shambase::get_infty<Tscal>();
71
72 for (u32 i = 0; i < pos.size(); i++) {
73 Tscal sink_sink_cfl_i = shambase::get_infty<Tscal>();
74
75 Tvec f_i = acc_ext[i];
76
77 Tscal grad_phi_i_sq = sham::dot(f_i, f_i); // m^2.s^-4
78
79 if (grad_phi_i_sq == 0) {
80 continue;
81 }
82
83 for (u32 j = 0; j < pos.size(); j++) {
84 if (i == j) {
85 continue;
86 }
87
88 Tvec rij = pos[i] - pos[j];
89 Tscal rij_scal = sycl::length(rij);
90
91 Tscal phi_ij = G * mass[j] / rij_scal; // J / kg = m^2.s^-2
92 Tscal term_ij = sham::abs(phi_ij) / grad_phi_i_sq; // s^2
93 Tscal dt_ij = C_force * eta_phi * sycl::sqrt(term_ij); // s
94
95 sink_sink_cfl_i = sham::min(sink_sink_cfl_i, dt_ij);
96 }
97
98 sink_sink_cfl = sham::min(sink_sink_cfl, sink_sink_cfl_i);
99 }
100
101 edges.cfl_dt.data = sink_sink_cfl;
102 }
103
104 inline virtual std::string _impl_get_label() const { return "ComputeCFLSinkSink"; };
105
106 inline virtual std::string _impl_get_tex() const {
107 std::string tex = R"tex(
108 Sink-sink CFL
109
110 \begin{align}
111 \phi_{ij} &= \frac{{G} {masses}_j}{\vert {positions}_i - {positions}_j \vert} \\
112 {cfl_dt} &= \min_{i, j \neq i, {acc_ext}_i \neq 0} {C_force} {eta_phi}
113 \sqrt{\frac{\vert \phi_{ij} \vert}{{acc_ext}_i \cdot {acc_ext}_i}}
114 \end{align}
115 )tex";
116
117 replace_edges_tex_symbols(tex);
118
119 return tex;
120 };
121};
122
123#undef NODE_EDGES
std::uint32_t u32
32 bit unsigned integer
void _impl_evaluate_internal()
evaluate the node
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
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.