Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
GeneratorLatticeCubic.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
18
21#include "shammath/AABB.hpp"
25
27
28 template<class Tvec>
29 class GeneratorLatticeCubic : public ISPHSetupNode {
30 using Tscal = shambase::VecComponent<Tvec>;
31 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
32 using Lattice = shammath::LatticeCubic<Tvec>;
33 using LatticeIter = typename shammath::LatticeCubic<Tvec>::IteratorDiscontinuous;
34
35 ShamrockCtx &context;
36 Tscal dr;
38
39 LatticeIter generator;
40
41 static auto init_gen(Tscal dr, std::pair<Tvec, Tvec> box) {
42
43 auto [idxs_min, idxs_max] = Lattice::get_box_index_bounds(dr, box.first, box.second);
44 u32 idx_gen = 0;
45 return LatticeIter(dr, idxs_min, idxs_max);
46 };
47
48 public:
49 GeneratorLatticeCubic(ShamrockCtx &context, Tscal dr, std::pair<Tvec, Tvec> box)
50 : context(context), dr(dr), box(box), generator(init_gen(dr, box)) {}
51
52 bool is_done() { return generator.is_done(); }
53
55 StackEntry stack_loc{};
56
57 using namespace shamrock::patch;
58 PatchScheduler &sched = shambase::get_check_ref(context.sched);
59
60 std::vector<Tvec> pos_data;
61
62 // Fill pos_data if the scheduler has some patchdata in this rank
63 if (!is_done()) {
64 u64 loc_gen_count = nmax;
65
66 auto gen_info = shamalgs::collective::fetch_view(loc_gen_count);
67
68 u64 skip_start = gen_info.head_offset;
69 u64 gen_cnt = loc_gen_count;
70 u64 skip_end = gen_info.total_byte_count - loc_gen_count - gen_info.head_offset;
71
72 shamlog_debug_ln(
73 "GeneratorLatticeCubic",
74 "generate : ",
75 skip_start,
76 gen_cnt,
77 skip_end,
78 "total",
79 skip_start + gen_cnt + skip_end);
80
81 generator.skip(skip_start);
82 auto tmp = generator.next_n(gen_cnt);
83 generator.skip(skip_end);
84
85 for (Tvec r : tmp) {
86 if (Patch::is_in_patch_converted(r, box.lower, box.upper)) {
87 pos_data.push_back(r);
88 }
89 }
90 }
91
92 // Make a patchdata from pos_data
93 PatchDataLayer tmp(sched.get_layout_ptr_old());
94 if (!pos_data.empty()) {
95 tmp.resize(pos_data.size());
96 tmp.fields_raz();
97
98 {
99 u32 len = pos_data.size();
101 = tmp.get_field<Tvec>(sched.pdl_old().get_field_idx<Tvec>("xyz"));
102 // sycl::buffer<Tvec> buf(pos_data.data(), len);
103 f.override(pos_data, len);
104 }
105
106 {
108 = tmp.get_field<Tscal>(sched.pdl_old().get_field_idx<Tscal>("hpart"));
109 f.override(dr);
110 }
111 }
112 return tmp;
113 }
114
115 std::string get_name() { return "GeneratorLatticeCubic"; }
117 };
118
119} // namespace shammodels::sph::modules
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
The MPI scheduler.
Iterator utility to generate the lattice.
utility for generating Cubic crystal lattices
bool is_done()
This function return true if the setup is done.
std::string get_name()
Get the name of the node.
ISPHSetupNode_Dot get_dot_subgraph()
Get a dot subgraph describing the node and its childrens (recursively).
shamrock::patch::PatchDataLayer next_n(u32 nmax)
This function generate patchdata with at most nmax per MPI ranks This function is always assumed as c...
This class is an interface that all SPH setup nodes must implement. It describe an operation associat...
PatchDataLayer container class, the layout is described in patchdata_layout.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
namespace for the sph model modules
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
Axis-Aligned bounding box.
Definition AABB.hpp:99
This struct is used to generate a dot graph of the setup tree.
static bool is_in_patch_converted(sycl::vec< T, 3 > val, sycl::vec< T, 3 > min_val, sycl::vec< T, 3 > max_val)
check if particle is in the asked range, given the output of @convert_coord
Definition Patch.hpp:210