Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NodeUpdateDerivsVaryingAlphaAVMHD.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
23#include "shamphys/mhd.hpp"
25
26template<class Tvec, template<class> class SPHKernel>
28 using Tscal = shambase::VecComponent<Tvec>;
29 using Kernel = SPHKernel<Tscal>;
30 static constexpr Tscal hfactd = Kernel::hfactd;
31 static constexpr Tscal rker2 = Kernel::Rkern * Kernel::Rkern;
32
33 Tscal pmass;
34 Tscal alpha_u;
35 Tscal beta_AV;
36 Tscal mu_0;
37
38 inline void operator()(
39 unsigned int id_a,
40 const Tvec *__restrict xyz,
41 const Tscal *__restrict hpart,
42 const Tvec *__restrict vxyz,
43 const Tscal *__restrict uint,
44 const Tscal *__restrict omega,
45 const Tscal *__restrict pressure,
46 const Tscal *__restrict cs,
47 const Tscal *__restrict alpha_AV,
48 const Tvec *__restrict B_on_rho,
50 Tvec *__restrict axyz,
51 Tscal *__restrict duint) const {
52
53 using namespace shamrock::sph;
54
55 shamrock::tree::ObjectCacheIterator particle_looper(ploop_ptrs);
56
57 Tvec xyz_a = xyz[id_a];
58 Tscal h_a = hpart[id_a];
59 Tvec vxyz_a = vxyz[id_a];
60 Tscal u_a = uint[id_a];
61 Tscal omega_a = omega[id_a];
62 Tscal P_a = pressure[id_a];
63 Tscal cs_a = cs[id_a];
64 Tscal alpha_a = alpha_AV[id_a];
65
66 Tscal rho_a = rho_h(pmass, h_a, hfactd);
67 Tscal rho_a_sq = rho_a * rho_a;
68 Tscal rho_a_inv = 1. / rho_a;
69
70 Tscal omega_a_rho_a_inv = 1 / (omega_a * rho_a);
71
72 Tvec B_a = B_on_rho[id_a] * rho_a;
73
74 Tvec force_pressure = Tvec{0, 0, 0};
75 Tscal tmpdU_pressure = Tscal{0};
76
77 particle_looper.for_each_object(id_a, [&](u32 id_b) {
78 Tvec dr = xyz_a - xyz[id_b];
79 Tscal rab2 = sycl::dot(dr, dr);
80 Tscal h_b = hpart[id_b];
81
82 if (rab2 > h_a * h_a * rker2 && rab2 > h_b * h_b * rker2) {
83 return;
84 }
85
86 Tvec vxyz_b = vxyz[id_b];
87 const Tscal u_b = uint[id_b];
88 Tscal P_b = pressure[id_b];
89 Tscal omega_b = omega[id_b];
90 const Tscal alpha_b = alpha_AV[id_b];
91 Tscal cs_b = cs[id_b];
92
93 Tscal rab = sycl::sqrt(rab2);
94
95 Tscal rho_b = rho_h(pmass, h_b, hfactd);
96 Tvec B_b = B_on_rho[id_b] * rho_b;
97
98 Tscal Fab_a = Kernel::dW_3d(rab, h_a);
99 Tscal Fab_b = Kernel::dW_3d(rab, h_b);
100
101 Tvec v_ab = vxyz_a - vxyz_b;
102
103 Tvec r_ab_unit = dr * sham::inv_sat_positive(rab);
104
105 Tscal v_ab_r_ab = sycl::dot(v_ab, r_ab_unit);
106
107 // same as the hydro case but with the fast magnetosonic speed instead of cs
108 Tscal vsig_a = shamphys::MHD_physics<Tvec, Tscal>::vsig_MHD(
109 v_ab, r_ab_unit, cs_a, B_a, rho_a, mu_0, alpha_a, beta_AV);
110 Tscal vsig_b = shamphys::MHD_physics<Tvec, Tscal>::vsig_MHD(
111 v_ab, r_ab_unit, cs_b, B_b, rho_b, mu_0, alpha_b, beta_AV);
112
113 Tscal vsig_u = shamrock::sph::vsig_u(P_a, P_b, rho_a, rho_b);
114
115 Tscal qa_ab = shamrock::sph::q_av(rho_a, vsig_a, v_ab_r_ab);
116 Tscal qb_ab = shamrock::sph::q_av(rho_b, vsig_b, v_ab_r_ab);
117
118 add_to_derivs_sph_artif_visco_cond(
119 pmass,
120 rho_a_sq,
121 omega_a_rho_a_inv,
122 rho_a_inv,
123 rho_b,
124 omega_a,
125 omega_b,
126 Fab_a,
127 Fab_b,
128 u_a,
129 u_b,
130 P_a,
131 P_b,
132 alpha_u,
133 v_ab,
134 r_ab_unit,
135 vsig_u,
136 qa_ab,
137 qb_ab,
138
139 force_pressure,
140 tmpdU_pressure);
141 });
142
143 axyz[id_a] = force_pressure;
144 duint[id_a] = tmpdU_pressure;
145 }
146};
147
148template<class Tvec, template<class> class SPHKernel>
151
153
154 auto edges = get_edges();
155
156 auto &part_counts_with_ghost = edges.part_counts_with_ghost.indexes;
157 auto &part_counts = edges.part_counts.indexes;
158
159 // check that all input edges have the particles with ghosts zones
160 edges.xyz.check_sizes(part_counts_with_ghost);
161 edges.hpart.check_sizes(part_counts_with_ghost);
162 edges.vxyz.check_sizes(part_counts_with_ghost);
163 edges.uint.check_sizes(part_counts_with_ghost);
164 edges.omega.check_sizes(part_counts_with_ghost);
165 edges.pressure.check_sizes(part_counts_with_ghost);
166 edges.cs.check_sizes(part_counts_with_ghost);
167 edges.alpha_AV.check_sizes(part_counts_with_ghost);
168 edges.B_on_rho.check_sizes(part_counts_with_ghost);
169
170 // ensure that the output edges are of size part_counts (output without ghosts zones)
171 edges.axyz.ensure_sizes(part_counts);
172 edges.duint.ensure_sizes(part_counts);
173
174 const Tscal pmass = edges.gpart_mass.data;
175 const Tscal alpha_u = edges.alpha_u.data;
176 const Tscal beta_AV = edges.beta_AV.data;
177 const Tscal mu_0 = edges.mu_0.data;
178
180
181 // call the kernel for each patches with part_counts.get(id_patch) threads of patch id_patch
183 shamsys::instance::get_compute_scheduler_ptr(),
185 edges.xyz.get_spans(),
186 edges.hpart.get_spans(),
187 edges.vxyz.get_spans(),
188 edges.uint.get_spans(),
189 edges.omega.get_spans(),
190 edges.pressure.get_spans(),
191 edges.cs.get_spans(),
192 edges.alpha_AV.get_spans(),
193 edges.B_on_rho.get_spans(),
194 edges.neigh_cache},
195 sham::DDMultiRef{edges.axyz.get_spans(), edges.duint.get_spans()},
196 part_counts,
197 ComputeKernel{pmass, alpha_u, beta_AV, mu_0});
198}
199
200using namespace shammath;
204
Hydro update derivs (pressure, artificial viscosity & conductivity) with a varying alpha AV,...
std::uint32_t u32
32 bit unsigned integer
T inv_sat_positive(T v, T minvsat=T{1e-9}, T satval=T{0.}) noexcept
inverse saturated (positive numbers only)
Definition math.hpp:841
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.
namespace for math utility
Definition AABB.hpp:26
constexpr Tscal q_av(const Tscal &rho, const Tscal &vsig, const Tscal &v_scal_rhat)
phantom_2018 eq.40
Definition q_ab.hpp:37
file containing formulas for sph forces
sph kernels
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.