Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
forces.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
30#include "shambackends/math.hpp"
31#include "shambackends/sycl.hpp"
34
35namespace shammodels::gsph {
36
37 // Note: For GSPH acceleration, use shamrock::sph::sph_pressure_symetric() with p_star
38 // as both P_a and P_b. This provides proper handling of zero denominators via
39 // sham::inv_sat_zero() and avoids code duplication.
40
67 template<class Tvec, class Tscal>
68 inline Tscal gsph_energy_rate(
69 Tscal m_b,
70 Tscal p_star,
71 Tscal v_star,
72 Tscal rho_a_sq,
73 Tscal rho_b_sq,
74 Tscal omega_a,
75 Tscal omega_b,
76 Tvec v_a,
77 Tvec r_ab_unit,
78 Tvec nabla_W_a,
79 Tvec nabla_W_b) {
80
81 // Interface velocity vector (in direction of pair axis)
82 Tvec v_star_vec = v_star * r_ab_unit;
83
84 // Compute symmetric force (same as momentum equation)
85 // f = m_b * p* * (nabla_W_a / (rho_a^2 * Omega_a) + nabla_W_b / (rho_b^2 * Omega_b))
86 Tscal sub_fact_a = rho_a_sq * omega_a;
87 Tscal sub_fact_b = rho_b_sq * omega_b;
88 Tvec f = m_b * p_star
89 * (nabla_W_a * sham::inv_sat_zero(sub_fact_a)
90 + nabla_W_b * sham::inv_sat_zero(sub_fact_b));
91
92 // Energy rate: -f dot (v* - v_a)
93 return -sycl::dot(f, v_star_vec - v_a);
94 }
95
118 template<class Tvec, class Tscal>
120 Tscal m_b,
121 Tscal p_star,
122 Tscal v_star,
123 Tscal rho_a,
124 Tscal rho_b,
125 Tscal omega_a,
126 Tscal omega_b,
127 Tscal Fab_a,
128 Tscal Fab_b,
129 Tvec r_ab_unit,
130 Tvec v_a,
131 Tvec &dv_dt,
132 Tscal &du_dt) {
133
134 const Tscal rho_a_sq = rho_a * rho_a;
135 const Tscal rho_b_sq = rho_b * rho_b;
136
137 // Kernel gradient vectors (pointing from a to b)
138 Tvec nabla_W_a = Fab_a * r_ab_unit;
139 Tvec nabla_W_b = Fab_b * r_ab_unit;
140
141 // Acceleration: use sph_pressure_symetric with p_star as both P_a and P_b
142 // This provides proper handling of zero denominators via sham::inv_sat_zero()
143 dv_dt += shamrock::sph::sph_pressure_symetric<Tvec, Tscal>(
144 m_b, rho_a_sq, rho_b_sq, p_star, p_star, omega_a, omega_b, nabla_W_a, nabla_W_b);
145
146 // Energy rate (uses symmetric force, same as momentum equation)
147 du_dt += gsph_energy_rate<Tvec, Tscal>(
148 m_b,
149 p_star,
150 v_star,
151 rho_a_sq,
152 rho_b_sq,
153 omega_a,
154 omega_b,
155 v_a,
156 r_ab_unit,
157 nabla_W_a,
158 nabla_W_b);
159 }
160
161 // Note: For velocity projection onto pair axis, use sycl::dot(v, r_ab_unit) directly.
162 // For density from smoothing length, use shamrock::sph::rho_h() from density.hpp.
163
164} // namespace shammodels::gsph
void add_gsph_force_contribution(Tscal m_b, Tscal p_star, Tscal v_star, Tscal rho_a, Tscal rho_b, Tscal omega_a, Tscal omega_b, Tscal Fab_a, Tscal Fab_b, Tvec r_ab_unit, Tvec v_a, Tvec &dv_dt, Tscal &du_dt)
Add GSPH force contribution from a single neighbor pair.
Definition forces.hpp:119
Tscal gsph_energy_rate(Tscal m_b, Tscal p_star, Tscal v_star, Tscal rho_a_sq, Tscal rho_b_sq, Tscal omega_a, Tscal omega_b, Tvec v_a, Tvec r_ab_unit, Tvec nabla_W_a, Tvec nabla_W_b)
Compute GSPH energy equation contribution.
Definition forces.hpp:68
Iterative Riemann solver for GSPH (van Leer 1997)
T inv_sat_zero(T v, T satval=T{0.}) noexcept
inverse saturated (zero version)
Definition math.hpp:870
file containing formulas for sph forces