29 using Direction = shammodels::basegodunov::modules::Direction;
32 inline T slope_function_van_leer_f_form(T sL, T sR) {
35 auto vanleer = [](T f) {
36 return 4. * f * (1. - f);
39 auto slopelim = [&](T f) {
40 if constexpr (std::is_same_v<T, f64_3>) {
41 f.x() = (f.x() >= 0 && f.x() <= 1) ? f.x() : 0;
42 f.y() = (f.y() >= 0 && f.y() <= 1) ? f.y() : 0;
43 f.z() = (f.z() >= 0 && f.z() <= 1) ? f.z() : 0;
45 f = (f >= 0 && f <= 1) ? f : 0;
50 return slopelim(sL / st) * st * 0.5;
54 inline T slope_function_van_leer_symetric(T sL, T sR) {
56 if constexpr (std::is_same_v<T, f64_3>) {
58 shammath::van_leer_slope_symetric(sL[0], sR[0]),
59 shammath::van_leer_slope_symetric(sL[1], sR[1]),
60 shammath::van_leer_slope_symetric(sL[2], sR[2])};
62 return shammath::van_leer_slope_symetric(sL, sR);
67 inline T slope_function_van_leer_standard(T sL, T sR) {
69 if constexpr (std::is_same_v<T, f64_3>) {
80 inline T slope_function_minmod(T sL, T sR) {
82 if constexpr (std::is_same_v<T, f64_3>) {
84 shammath::minmod(sL[0], sR[0]),
85 shammath::minmod(sL[1], sR[1]),
86 shammath::minmod(sL[2], sR[2])};
88 return shammath::minmod(sL, sR);
94 template<
class T, SlopeMode mode>
95 inline T slope_function(T sL, T sR) {
96 if constexpr (mode == SlopeMode::None) {
97 return sham::VectorProperties<T>::get_zero();
100 if constexpr (mode == SlopeMode::VanLeer_f) {
101 return slope_function_van_leer_f_form(sL, sR);
104 if constexpr (mode == SlopeMode::VanLeer_std) {
105 return slope_function_van_leer_standard(sL, sR);
108 if constexpr (mode == SlopeMode::VanLeer_sym) {
109 return slope_function_van_leer_symetric(sL, sR);
112 if constexpr (mode == SlopeMode::Minmod) {
113 return slope_function_minmod(sL, sR);
135 template<
class Tfield,
class Tvec, SlopeMode mode,
class ACCField>
136 inline std::array<Tfield, 3> get_3d_grad(
137 const f64 *cell_sizes,
138 const u32 block_size,
139 const u32 cell_global_id,
140 const AMRGraphLinkiterator &graph_iter_xp,
141 const AMRGraphLinkiterator &graph_iter_xm,
142 const AMRGraphLinkiterator &graph_iter_yp,
143 const AMRGraphLinkiterator &graph_iter_ym,
144 const AMRGraphLinkiterator &graph_iter_zp,
145 const AMRGraphLinkiterator &graph_iter_zm,
146 ACCField &&field_access) {
148 auto cur_cell_block_id = cell_global_id / block_size;
150 auto get_gradiant_dir = [&](
auto &graph_links, Direction dir) -> Tfield {
151 Tfield acc = shambase::VectorProperties<Tfield>::get_zero();
152 auto cell_center_dist = cell_sizes[cur_cell_block_id];
154 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
155 auto neigh_block_id = id_b / block_size;
157 int sign = 1 - 2 * (dir % 2);
158 acc += sign * (field_access(id_b) - field_access(cell_global_id));
160 if (cell_sizes[neigh_block_id] > cell_sizes[cur_cell_block_id]) {
166 if (cell_sizes[neigh_block_id] < cell_sizes[cur_cell_block_id]) {
170 return (cnt > 0) ? acc / (cell_center_dist * fac * cnt)
171 :
shambase::VectorProperties<Tfield>::get_zero();
174 Tfield delta_xp = get_gradiant_dir(graph_iter_xp, Direction::xp);
175 Tfield delta_xm = get_gradiant_dir(graph_iter_xm, Direction::xm);
176 Tfield delta_yp = get_gradiant_dir(graph_iter_yp, Direction::yp);
177 Tfield delta_ym = get_gradiant_dir(graph_iter_ym, Direction::ym);
178 Tfield delta_zp = get_gradiant_dir(graph_iter_zp, Direction::zp);
179 Tfield delta_zm = get_gradiant_dir(graph_iter_zm, Direction::zm);
181 slope_function<Tfield, mode>(
182 get_gradiant_dir(graph_iter_xm, Direction::xm),
183 get_gradiant_dir(graph_iter_xp, Direction::xp)),
184 slope_function<Tfield, mode>(
185 get_gradiant_dir(graph_iter_ym, Direction::ym),
186 get_gradiant_dir(graph_iter_yp, Direction::yp)),
187 slope_function<Tfield, mode>(
188 get_gradiant_dir(graph_iter_zm, Direction::zm),
189 get_gradiant_dir(graph_iter_zp, Direction::zp))};
214 template<
class Tvec, SlopeMode mode,
class ACCField1,
class ACCField2,
class ACCField3>
215 inline std::array<shammath::ConsState<Tvec>, 3> get_3d_grad_cons(
216 const u32 cell_global_id,
217 const shambase::VecComponent<Tvec> delta_cell,
218 const AMRGraphLinkiterator &graph_iter_xp,
219 const AMRGraphLinkiterator &graph_iter_xm,
220 const AMRGraphLinkiterator &graph_iter_yp,
221 const AMRGraphLinkiterator &graph_iter_ym,
222 const AMRGraphLinkiterator &graph_iter_zp,
223 const AMRGraphLinkiterator &graph_iter_zm,
224 ACCField1 &&field_access_rho,
225 ACCField2 &&field_access_rho_vel,
226 ACCField3 &&field_access_rhoe) {
228 using Tscal = shambase::VecComponent<Tvec>;
231 Tscal acc_rho = shambase::VectorProperties<Tscal>::get_zero();
232 Tscal acc_rhoe = shambase::VectorProperties<Tscal>::get_zero();
233 Tvec acc_rho_vel = shambase::VectorProperties<Tvec>::get_zero();
234 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
235 acc_rho += field_access_rho(id_b);
236 acc_rho_vel += field_access_rho_vel(id_b);
237 acc_rhoe += field_access_rhoe(id_b);
241 = {shambase::VectorProperties<Tscal>::get_zero(),
242 shambase::VectorProperties<Tscal>::get_zero(),
244 {shambase::VectorProperties<Tscal>::get_zero(),
245 shambase::VectorProperties<Tscal>::get_zero(),
246 shambase::VectorProperties<Tscal>::get_zero()}};
249 res = {acc_rho, acc_rhoe, acc_rho_vel};
257 = {field_access_rho(cell_global_id),
258 field_access_rhoe(cell_global_id),
259 field_access_rho_vel(cell_global_id)};
276 Tscal fact = 1. / delta_cell;
279 = {slope_function<Tscal, mode>(delta_W_x_m.rho * fact, delta_W_x_p.rho * fact),
280 slope_function<Tscal, mode>(delta_W_x_m.rhoe * fact, delta_W_x_p.rhoe * fact),
281 slope_function<Tvec, mode>(delta_W_x_m.rhovel * fact, delta_W_x_p.rhovel * fact)};
284 = {slope_function<Tscal, mode>(delta_W_y_m.rho * fact, delta_W_y_p.rho * fact),
285 slope_function<Tscal, mode>(delta_W_y_m.rhoe * fact, delta_W_y_p.rhoe * fact),
286 slope_function<Tvec, mode>(delta_W_y_m.rhovel * fact, delta_W_y_p.rhovel * fact)};
289 = {slope_function<Tscal, mode>(delta_W_z_m.rho * fact, delta_W_z_p.rho * fact),
290 slope_function<Tscal, mode>(delta_W_z_m.rhoe * fact, delta_W_z_p.rhoe * fact),
291 slope_function<Tvec, mode>(delta_W_z_m.rhovel * fact, delta_W_z_p.rhovel * fact)};
293 return {lim_slope_W_x, lim_slope_W_y, lim_slope_W_z};
299 template<
class T,
class Tvec,
class ACCField>
300 inline T get_pseudo_grad(
301 const u32 cell_global_id,
302 const AMRGraphLinkiterator &graph_iter_xp,
303 const AMRGraphLinkiterator &graph_iter_xm,
304 const AMRGraphLinkiterator &graph_iter_yp,
305 const AMRGraphLinkiterator &graph_iter_ym,
306 const AMRGraphLinkiterator &graph_iter_zp,
307 const AMRGraphLinkiterator &graph_iter_zm,
308 ACCField &&field_access)
312 using namespace sham;
313 using namespace sham::details;
315 auto get_avg_neigh = [&](
auto &graph_links,
u32 dir) -> T {
316 T acc = shambase::VectorProperties<T>::get_zero();
317 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
318 acc += field_access(id_b);
321 return (cnt > 0) ? acc / cnt : shambase::VectorProperties<T>::get_zero();
324 auto epsilon = shambase::get_epsilon<T>();
325 T u_cur = field_access(cell_global_id);
326 T u_xp = get_avg_neigh(graph_iter_xp, 0);
327 T u_xm = get_avg_neigh(graph_iter_xm, 1);
328 T u_yp = get_avg_neigh(graph_iter_yp, 2);
329 T u_ym = get_avg_neigh(graph_iter_ym, 3);
330 T u_zp = get_avg_neigh(graph_iter_zp, 4);
331 T u_zm = get_avg_neigh(graph_iter_zm, 5);
337 g_sycl_abs((u_cur - u_xm) / (epsilon + u_cur + u_xm)),
338 g_sycl_abs((u_cur - u_xp) / (epsilon + u_cur + u_xp)));
342 g_sycl_abs((u_cur - u_ym) / (epsilon + u_cur + u_ym)),
343 g_sycl_abs((u_cur - u_yp) / (epsilon + u_cur + u_yp)));
346 g_sycl_abs((u_cur - u_zm) / (epsilon + u_cur + u_zm)),
347 g_sycl_abs((u_cur - u_zp) / (epsilon + u_cur + u_zp)));
349 T res = g_sycl_max(x_scal, g_sycl_max(y_scal, z_scal));
355 template<
class T,
class ACCField>
356 inline T baryonic_normalized_slope_criterion(
357 const u32 cell_global_id,
358 const AMRGraphLinkiterator &graph_iter_xp,
359 const AMRGraphLinkiterator &graph_iter_xm,
360 const AMRGraphLinkiterator &graph_iter_yp,
361 const AMRGraphLinkiterator &graph_iter_ym,
362 const AMRGraphLinkiterator &graph_iter_zp,
363 const AMRGraphLinkiterator &graph_iter_zm,
364 ACCField &&field_access)
368 using namespace sham;
369 using namespace sham::details;
371 auto get_avg_neigh = [&](
auto &graph_links,
u32 dir) -> T {
372 T acc = shambase::VectorProperties<T>::get_zero();
373 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
374 acc += field_access(id_b);
377 return (cnt > 0) ? acc / cnt : shambase::VectorProperties<T>::get_zero();
380 auto epsilon = shambase::get_epsilon<T>();
381 T u_cur = field_access(cell_global_id);
382 T u_xp = get_avg_neigh(graph_iter_xp, 0);
383 T u_xm = get_avg_neigh(graph_iter_xm, 1);
384 T u_yp = get_avg_neigh(graph_iter_yp, 2);
385 T u_ym = get_avg_neigh(graph_iter_ym, 3);
386 T u_zp = get_avg_neigh(graph_iter_zp, 4);
387 T u_zm = get_avg_neigh(graph_iter_zm, 5);
389 T norm_slope_x = g_sycl_abs((u_xm - u_xp) / (2 * u_cur + epsilon));
390 T norm_slope_y = g_sycl_abs((u_ym - u_yp) / (2 * u_cur + epsilon));
391 T norm_slope_z = g_sycl_abs((u_zm - u_zp) / (2 * u_cur + epsilon));
393 T res = g_sycl_max(norm_slope_x, g_sycl_max(norm_slope_y, norm_slope_z));
401 template<
class T,
class Tvec,
class ACCField>
402 inline T modif_second_derivative(
403 const u32 cell_global_id,
404 const AMRGraphLinkiterator &graph_iter_xp,
405 const AMRGraphLinkiterator &graph_iter_xm,
406 const AMRGraphLinkiterator &graph_iter_yp,
407 const AMRGraphLinkiterator &graph_iter_ym,
408 const AMRGraphLinkiterator &graph_iter_zp,
409 const AMRGraphLinkiterator &graph_iter_zm,
410 ACCField &&field_access) {
411 using namespace sham;
412 using namespace sham::details;
414 auto get_avg_neigh = [&](
auto &graph_links) -> T {
415 T acc = shambase::VectorProperties<T>::get_zero();
416 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
417 acc += field_access(id_b);
419 return (cnt > 0) ? acc / cnt : shambase::VectorProperties<T>::get_zero();
423 auto epsilon = shambase::get_epsilon<T>();
424 T u_cur = field_access(cell_global_id);
425 T u_xp = get_avg_neigh(graph_iter_xp);
426 T u_xm = get_avg_neigh(graph_iter_xm);
427 T u_yp = get_avg_neigh(graph_iter_yp);
428 T u_ym = get_avg_neigh(graph_iter_ym);
429 T u_zp = get_avg_neigh(graph_iter_zp);
430 T u_zm = get_avg_neigh(graph_iter_zm);
432 T delta_u_xp = u_xp - u_cur;
433 T delta_u_xm = u_xm - u_cur;
434 T delta_u_yp = u_yp - u_cur;
435 T delta_u_ym = u_ym - u_cur;
436 T delta_u_zp = u_zp - u_cur;
437 T delta_u_zm = u_zm - u_cur;
439 T scalar_x = g_sycl_abs(u_xp) + g_sycl_abs(u_xm) + 2 * g_sycl_abs(u_cur);
440 T scalar_y = g_sycl_abs(u_yp) + g_sycl_abs(u_ym) + 2 * g_sycl_abs(u_cur);
441 T scalar_z = g_sycl_abs(u_zp) + g_sycl_abs(u_zm) + 2 * g_sycl_abs(u_cur);
444 = g_sycl_abs(delta_u_xm + delta_u_xp)
445 / (g_sycl_abs(delta_u_xm) + g_sycl_abs(delta_u_xp) + eps_ref * scalar_x + epsilon);
447 = g_sycl_abs(delta_u_ym + delta_u_yp)
448 / (g_sycl_abs(delta_u_ym) + g_sycl_abs(delta_u_yp) + eps_ref * scalar_y + epsilon);
450 = g_sycl_abs(delta_u_zm + delta_u_zp)
451 / (g_sycl_abs(delta_u_zm) + g_sycl_abs(delta_u_zp) + eps_ref * scalar_z + epsilon);
453 return (res_x + res_y + res_z);
459 template<
class Tvec,
class ACCField>
460 inline shambase::VecComponent<Tvec> normalized_shear(
461 const u32 cell_global_id,
462 const f32 sound_speed,
463 const Tvec delta_cells,
464 const AMRGraphLinkiterator &graph_iter_xp,
465 const AMRGraphLinkiterator &graph_iter_xm,
466 const AMRGraphLinkiterator &graph_iter_yp,
467 const AMRGraphLinkiterator &graph_iter_ym,
468 const AMRGraphLinkiterator &graph_iter_zp,
469 const AMRGraphLinkiterator &graph_iter_zm,
470 ACCField &&field_access)
474 using namespace sham;
475 using namespace sham::details;
477 auto get_avg_neigh = [&](
auto &graph_links,
u32 dir) -> Tvec {
478 Tvec acc = shambase::VectorProperties<Tvec>::get_zero();
479 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
480 acc += field_access(id_b);
483 return (cnt > 0) ? acc / cnt : shambase::VectorProperties<Tvec>::get_zero();
486 Tvec u_xp = get_avg_neigh(graph_iter_xp, 0);
487 Tvec u_xm = get_avg_neigh(graph_iter_xm, 1);
488 Tvec u_yp = get_avg_neigh(graph_iter_yp, 2);
489 Tvec u_ym = get_avg_neigh(graph_iter_ym, 3);
490 Tvec u_zp = get_avg_neigh(graph_iter_zp, 4);
491 Tvec u_zm = get_avg_neigh(graph_iter_zm, 5);
493 auto vgy = 0.25 * (u_xp[1] - u_xm[1]) * (u_xp[1] - u_xm[1]);
494 auto vgx = 0.25 * (u_yp[0] - u_ym[0]) * (u_yp[0] - u_ym[0]);
double f64
Alias for double.
float f32
Alias for float.
std::uint32_t u32
32 bit unsigned integer
namespace for backends this one is named only sham since shambackends is too long to write
namespace for basic c++ utilities
T van_leer_slope(T f, T g)
Van leer slope limiter.
SlopeMode
Slope limiter modes.
From original version by Thomas Guillet (T.A.Guillet@exeter.ac.uk).
Math header to compute slope limiters.