Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeCFLDust1Fluid.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
26
27#define NODE_EDGES(X_RO, X_RW) \
28 X_RO(shamrock::solvergraph::Indexes<u32>, part_counts) \
29 X_RO(shamrock::solvergraph::ScalarEdge<Tscal>, C_1_fluid) \
30 X_RO(shamrock::solvergraph::ScalarEdge<Tscal>, pmass) \
31 X_RO(shamrock::solvergraph::ScalarEdge<Tscal>, hfactd) \
32 X_RO(shamrock::solvergraph::IFieldSpan<Tscal>, hpart) \
33 X_RO(shamrock::solvergraph::IFieldSpan<Tscal>, soundspeed) \
34 X_RO(shamrock::solvergraph::IFieldSpan<Tscal>, s_j) \
35 X_RO(shamrock::solvergraph::IFieldSpan<Tscal>, Ts_j) \
36 X_RW(shamrock::solvergraph::IFieldSpan<Tscal>, cfl_dt)
37
38template<class Tvec>
39class ComputeCFLDust1Fluid : public shamrock::solvergraph::INode {
40
41 using Tscal = shambase::VecComponent<Tvec>;
42
43 u32 nbins;
44
45 public:
46 ComputeCFLDust1Fluid(u32 nbins) : nbins(nbins) {}
47
48 EXPAND_NODE_EDGES(NODE_EDGES)
49
51 auto edges = get_edges();
52
53 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
54
55 Tscal C_1_fluid = edges.C_1_fluid.value;
56 Tscal pmass = edges.pmass.value;
57 Tscal hfactd = edges.hfactd.value;
58
60 dev_sched,
62 edges.hpart.get_spans(),
63 edges.soundspeed.get_spans(),
64 edges.s_j.get_spans(),
65 edges.Ts_j.get_spans()},
66 sham::DDMultiRef{edges.cfl_dt.get_spans()},
67 edges.part_counts.indexes,
68 [C_1_fluid, pmass, hfactd, nbins = this->nbins](
69 u32 id_a,
70 const Tscal *hpart,
71 const Tscal *soundspeed,
72 const Tscal *s_j,
73 const Tscal *Ts_j,
74 Tscal *cfl_dt) {
75 u32 id_a_d = id_a * nbins;
76
77 Tscal h_a = hpart[id_a];
78 Tscal rho_a = shamrock::sph::rho_h(pmass, h_a, hfactd);
79
80 Tscal cs_a = soundspeed[id_a];
81 Tscal cs2_a = cs_a * cs_a;
82
83 auto rho_dust = [&](int j) {
84 auto tmp = s_j[id_a_d + j];
85 return tmp * tmp;
86 };
87
88 auto epsilon_j = [&](int j) {
89 return rho_dust(j) / rho_a;
90 };
91
92 Tscal sum_eps = 0;
93 for (int j = 0; j < nbins; j++) {
94 sum_eps += epsilon_j(j);
95 }
96
97 Tscal cs_tilde_2_a = cs2_a * (1 - sum_eps);
98
99 Tscal cs4_over_h2 = cs2_a * cs2_a / (h_a * h_a);
100
101 Tscal cfl_tmp = std::numeric_limits<Tscal>::infinity();
102
103 for (int j = 0; j < nbins; j++) {
104 Tscal eps_j_a = epsilon_j(j);
105 Tscal eps2_j_a = eps_j_a * eps_j_a;
106
107 Tscal Ts_j_a = Ts_j[id_a_d + j];
108 Tscal Ts2_j_a = Ts_j_a * Ts_j_a;
109
110 Tscal dt_j = h_a / sycl::sqrt(cs_tilde_2_a + Ts2_j_a * eps2_j_a * cs4_over_h2);
111 cfl_tmp = sycl::min(cfl_tmp, dt_j);
112 }
113
114 cfl_tmp *= C_1_fluid;
115
116 cfl_dt[id_a] = sycl::min(cfl_dt[id_a], cfl_tmp);
117 });
118 }
119
120 inline virtual std::string _impl_get_label() const { return "ComputeCFLDust1Fluid"; };
121
122 inline virtual std::string _impl_get_tex() const { return "C_{1,fluid}"; };
123};
124
125#undef NODE_EDGES
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
virtual std::string _impl_get_label() const
get the label of the node
void _impl_evaluate_internal()
evaluate the node
Inode is node between data edges, takes multiple inputs, multiple outputs.
Definition INode.hpp:31
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.
A variant of sham::MultiRef for distributed data.