Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NodeComputePressureGrad.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
24
25template<class Tvec, template<class> class SPHKernel>
27 using Tscal = shambase::VecComponent<Tvec>;
28 using Kernel = SPHKernel<Tscal>;
29 static constexpr Tscal hfactd = Kernel::hfactd;
30 static constexpr Tscal Rkern = Kernel::Rkern;
31 static constexpr Tscal Rker2 = Rkern * Rkern;
32
33 Tscal pmass;
34
35 inline void operator()(
36 unsigned int id_a,
37 const Tvec *__restrict xyz,
38 const Tscal *__restrict hpart,
39 const Tscal *__restrict omega,
40 const Tscal *__restrict pressure,
42 Tvec *__restrict grad_P_on_rho) const {
43
44 using namespace shamrock::sph;
45
46 shamrock::tree::ObjectCacheIterator particle_looper(ploop_ptrs);
47
48 Tvec xyz_a = xyz[id_a];
49 Tscal h_a = hpart[id_a];
50 Tscal omega_a = omega[id_a];
51 Tscal P_a = pressure[id_a];
52
53 Tscal rho_a = rho_h(pmass, h_a, hfactd);
54 Tscal rho_a_sq = rho_a * rho_a;
55 Tscal rho_a_inv = 1. / rho_a;
56
57 Tscal omega_a_rho_a_inv = 1 / (omega_a * rho_a);
58
59 Tvec force_pressure = Tvec{0, 0, 0};
60
61 particle_looper.for_each_object(id_a, [&](u32 id_b) {
62 Tvec dr = xyz_a - xyz[id_b];
63 Tscal rab2 = sycl::dot(dr, dr);
64 Tscal h_b = hpart[id_b];
65
66 if (rab2 > h_a * h_a * Rker2 && rab2 > h_b * h_b * Rker2) {
67 return;
68 }
69
70 Tscal P_b = pressure[id_b];
71 Tscal omega_b = omega[id_b];
72
73 Tscal rab = sycl::sqrt(rab2);
74
75 Tscal rho_b = rho_h(pmass, h_b, hfactd);
76
77 Tscal Fab_a = Kernel::dW_3d(rab, h_a);
78 Tscal Fab_b = Kernel::dW_3d(rab, h_b);
79
80 Tvec r_ab_unit = dr * sham::inv_sat_positive(rab);
81
82 force_pressure += sph_pressure_symetric(
83 pmass,
84 rho_a_sq,
85 rho_b * rho_b,
86 P_a,
87 P_b,
88 omega_a,
89 omega_b,
90 r_ab_unit * Fab_a,
91 r_ab_unit * Fab_b);
92 });
93
94 grad_P_on_rho[id_a] = force_pressure;
95 }
96};
97
98template<class Tvec, template<class> class SPHKernel>
100
102
103 auto edges = get_edges();
104
105 auto &part_counts_with_ghost = edges.part_counts_with_ghost.indexes;
106 auto &part_counts = edges.part_counts.indexes;
107
108 // check that all input edges have the particles with ghosts zones
109 edges.xyz.check_sizes(part_counts_with_ghost);
110 edges.hpart.check_sizes(part_counts_with_ghost);
111 edges.omega.check_sizes(part_counts_with_ghost);
112 edges.pressure.check_sizes(part_counts_with_ghost);
113
114 // ensure that the output edges are of size part_counts (output without ghosts zones)
115 edges.grad_P_on_rho.ensure_sizes(part_counts);
116
117 const Tscal pmass = edges.gpart_mass.value;
118
119 using ComputeKernel = KernelComputePressureGrad<Tvec, SPHKernel>;
120
121 // call the kernel for each patches with part_counts.get(id_patch) threads of patch id_patch
123 shamsys::instance::get_compute_scheduler_ptr(),
125 edges.xyz.get_spans(),
126 edges.hpart.get_spans(),
127 edges.omega.get_spans(),
128 edges.pressure.get_spans(),
129 edges.neigh_cache},
130 sham::DDMultiRef{edges.grad_P_on_rho.get_spans()},
131 part_counts,
132 ComputeKernel{pmass});
133}
134
135using namespace shammath;
139
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
file containing formulas for sph forces
Tvec sph_pressure_symetric(const Tscal &m_b, const Tscal &rho_a_sq, const Tscal &rho_b_sq, const Tscal &P_a, const Tscal &P_b, const Tscal &omega_a, const Tscal &omega_b, const Tvec &nabla_Wab_ha, const Tvec &nabla_Wab_hb)
phantom_2018 eq.34, with
Definition forces.hpp:60
sph kernels
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.