Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeLuminosity.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
25
26template<class Tvec, template<class> class SPHKernel>
28
30
31 auto edges = get_edges();
32
33 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
34
35 edges.luminosity.ensure_sizes(edges.part_counts.indexes);
36
38 dev_sched,
40 edges.xyz.get_spans(),
41 edges.hpart.get_spans(),
42 edges.omega.get_spans(),
43 edges.u.get_spans(),
44 edges.pressure.get_spans(),
45 edges.neigh_cache.neigh_cache},
46 sham::DDMultiRef{edges.luminosity.get_spans()},
47 edges.part_counts.indexes,
48 [part_mass = this->part_mass, alpha_u = this->alpha_u](
49 u32 id_a,
50 const Tvec *r,
51 const Tscal *hpart,
52 const Tscal *omega,
53 const Tscal *u,
54 const Tscal *pressure,
55 const auto ploop_ptrs,
56 Tscal *luminosity) {
57 shamrock::tree::ObjectCacheIterator particle_looper(ploop_ptrs);
58
59 using namespace shamrock::sph;
60
61 Tscal h_a = hpart[id_a];
62 Tvec xyz_a = r[id_a];
63 const Tscal u_a = u[id_a];
64 const Tscal omega_a = omega[id_a];
65 const Tscal rho_a = rho_h(part_mass, h_a, SPHKernel<Tscal>::hfactd);
66 const Tscal P_a = pressure[id_a];
67 Tscal omega_a_rho_a_inv = 1 / (omega_a * rho_a);
68 Tscal tmp_luminosity = 0;
69
70 particle_looper.for_each_object(id_a, [&](u32 id_b) {
71 const Tscal u_b = u[id_b];
72 const Tscal h_b = hpart[id_b];
73 const Tscal omega_b = omega[id_b];
74 const Tscal P_b = pressure[id_b];
75 const Tscal rho_b = rho_h(part_mass, h_b, SPHKernel<Tscal>::hfactd);
76 Tvec dr = xyz_a - r[id_b];
77 Tscal rab2 = sycl::dot(dr, dr);
78 Tscal rab = sycl::sqrt(rab2);
79
80 Tscal vsigu = vsig_u(P_a, P_b, rho_a, rho_b);
81 Tscal Fab_a = SPHKernel<Tscal>::dW_3d(rab, h_a);
82 Tscal Fab_b = SPHKernel<Tscal>::dW_3d(rab, h_b);
83
84 tmp_luminosity += lambda_shock_conductivity(
85 part_mass,
86 alpha_u,
87 vsigu,
88 u_a - u_b,
89 Fab_a * omega_a_rho_a_inv,
90 Fab_b / (rho_b * omega_b));
91 });
92
93 luminosity[id_a] = tmp_luminosity;
94 });
95}
96
97template<class Tvec, template<class> class SPHKernel>
99 const {
100 auto xyz = get_ro_edge_base(0).get_tex_symbol();
101 auto hpart = get_ro_edge_base(1).get_tex_symbol();
102 auto omega = get_ro_edge_base(2).get_tex_symbol();
103 auto u = get_ro_edge_base(3).get_tex_symbol();
104 auto pressure = get_ro_edge_base(4).get_tex_symbol();
105 auto luminosity = get_rw_edge_base(0).get_tex_symbol();
106
107 std::string tex = R"tex(
108 Compute idealized luminosity from shocks only: energy dissipated immidiately emitted
109 \begin{align}
110 {luminosity}_i &= pmass * alpha_u * vsigu * u_ab * \frac{1}{2}
111 * (Fab_inv_omega_a_rho_a + Fab_inv_omega_b_rho_b)\\
112 &= pmass * alpha_u * \sqrt(\frac{\abs({pressure}_a - {pressure}_b)}{2 (rho_a + rho_b)}); * ({u}_a - {u}_b) * \frac{1}{2}
113 * (\frac{Fab_a}{{omega}_a * rho_a} + \frac{Fab_b}{{omega}_b * rho_b})
114 \end{align}
115 )tex";
116
117 shambase::replace_all(tex, "{xyz}", xyz);
118 shambase::replace_all(tex, "{hpart}", hpart);
119 shambase::replace_all(tex, "{omega}", omega);
120 shambase::replace_all(tex, "{u}", u);
121 shambase::replace_all(tex, "{pressure}", pressure);
122 shambase::replace_all(tex, "{luminosity}", luminosity);
123 return tex;
124}
125
126using namespace shammath;
130
std::uint32_t u32
32 bit unsigned integer
virtual std::string _impl_get_tex() const
get the tex of the node
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:183
namespace for math utility
Definition AABB.hpp:26
file containing formulas for sph forces
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.