Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CGLaplacianStencil.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
20#include "shambackends/vec.hpp"
21#include "shamcomm/logs.hpp"
23#include <shambackends/sycl.hpp>
24
27 using Direction = shammodels::basegodunov::modules::Direction;
28
46 template<class T, class Tvec, class ACCField>
47 inline T laplacian_7pt(
48 const u32 cell_global_id,
49 const shambase::VecComponent<Tvec> delta_cell,
50 const AMRGraphLinkiterator &graph_iter_xp,
51 const AMRGraphLinkiterator &graph_iter_xm,
52 const AMRGraphLinkiterator &graph_iter_yp,
53 const AMRGraphLinkiterator &graph_iter_ym,
54 const AMRGraphLinkiterator &graph_iter_zp,
55 const AMRGraphLinkiterator &graph_iter_zm,
56 ACCField &&field_access) {
57 auto get_avg_neigh = [&](auto &graph_links) -> T {
59 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](u32 id_b) {
60 acc += field_access(id_b);
61 });
62
63 T err_val = std::numeric_limits<T>::quiet_NaN();
64 return (cnt > 0) ? acc / cnt : err_val;
65 // return (cnt > 0) ? acc / cnt : shambase::VectorProperties<T>::get_zero();
66 };
67
68 T W_i = field_access(cell_global_id);
69 T W_xp = get_avg_neigh(graph_iter_xp);
70 T W_xm = get_avg_neigh(graph_iter_xm);
71 T W_yp = get_avg_neigh(graph_iter_yp);
72 T W_ym = get_avg_neigh(graph_iter_ym);
73 T W_zp = get_avg_neigh(graph_iter_zp);
74 T W_zm = get_avg_neigh(graph_iter_zm);
75
76 T inv_delta_cell_sqr = 1.0 / (delta_cell * delta_cell);
77
78 T laplace_x = inv_delta_cell_sqr * (-W_xm + 2. * W_i - W_xp);
79 T laplace_y = inv_delta_cell_sqr * (-W_ym + 2. * W_i - W_yp);
80 T laplace_z = inv_delta_cell_sqr * (-W_zm + 2. * W_i - W_zp);
81 T res = (laplace_x + laplace_y + laplace_z);
82
83 return -res;
84 }
85} // namespace shammodels::basegodunov
std::uint32_t u32
32 bit unsigned integer
namespace for the basegodunov model
T laplacian_7pt(const u32 cell_global_id, const shambase::VecComponent< Tvec > delta_cell, const AMRGraphLinkiterator &graph_iter_xp, const AMRGraphLinkiterator &graph_iter_xm, const AMRGraphLinkiterator &graph_iter_yp, const AMRGraphLinkiterator &graph_iter_ym, const AMRGraphLinkiterator &graph_iter_zp, const AMRGraphLinkiterator &graph_iter_zm, ACCField &&field_access)
Get the discretized laplacian.