Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
particleGen.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 <functional>
22#include <vector>
23
24namespace shamrock::sph {
25
26 template<class flt>
27 inline sycl::vec<flt, 3> get_box_dim(flt r_particle, u32 xcnt, u32 ycnt, u32 zcnt) {
28
29 using vec3 = sycl::vec<flt, 3>;
30
31 u32 im = xcnt;
32 u32 jm = ycnt;
33 u32 km = zcnt;
34
35 auto get_pos = [&](u32 i, u32 j, u32 k) -> vec3 {
36 vec3 r_a
37 = {2 * i + ((j + k) % 2),
38 sycl::sqrt(3.) * (j + (1. / 3.) * (k % 2)),
39 2 * sycl::sqrt(6.) * k / 3};
40
41 r_a *= r_particle;
42
43 return r_a;
44 };
45
46 return get_pos(im, jm, km);
47 }
48
49 template<class flt>
50 inline std::tuple<sycl::vec<flt, 3>, sycl::vec<flt, 3>> get_ideal_fcc_box(
51 flt r_particle, std::tuple<sycl::vec<flt, 3>, sycl::vec<flt, 3>> box) {
52
53 using vec3 = sycl::vec<flt, 3>;
54
55 vec3 box_min = std::get<0>(box);
56 vec3 box_max = std::get<1>(box);
57
58 vec3 box_dim = box_max - box_min;
59
60 vec3 iboc_dim = (box_dim / vec3({2, sycl::sqrt(3.), 2 * sycl::sqrt(6.) / 3})) / r_particle;
61
62 u32 i = iboc_dim.x();
63 u32 j = iboc_dim.y();
64 u32 k = iboc_dim.z();
65
66 // std::cout << "get_ideal_box_idim :" << i << " " << j << " " << k << std::endl;
67
68 i -= i % 2;
69 j -= j % 2;
70 k -= k % 2;
71
72 vec3 m1 = get_box_dim(r_particle, i, j, k);
73
74 return {box_min, box_min + m1};
75 }
76
77 template<class Tscal>
78 inline sycl::vec<Tscal, 3> get_fcc_pos(u32 i, u32 j, u32 k) {
79 return {
80 2 * i + ((j + k) % 2),
81 sycl::sqrt(3.) * (j + (1. / 3.) * (k % 2)),
82 2 * sycl::sqrt(6.) * k / 3};
83 }
84
85} // namespace shamrock::sph
std::uint32_t u32
32 bit unsigned integer