Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeCoordinates.cpp
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
20
24
26
27 template<class Tvec, class TgridVec>
29 using Tscal = shambase::VecComponent<Tvec>;
30
31 auto edges = get_edges();
32
33 edges.spans_block_min.check_sizes(edges.sizes.indexes);
34 edges.spans_block_max.check_sizes(edges.sizes.indexes);
35
36 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
37
39 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 block_count) {
40 return block_count * block_size; // cell count
41 });
42
43 edges.spans_coordinates.ensure_sizes(cell_counts);
44 auto &block_min_spans = edges.spans_block_min.get_spans();
45 auto &block_max_spans = edges.spans_block_max.get_spans();
46 auto &cell_coord_spans = edges.spans_coordinates.get_spans();
47
48 Tscal one_over_Nside = 1. / block_nside;
49
50 Tscal dxfact = grid_coord_to_pos_fact;
51
53 shamsys::instance::get_compute_scheduler_ptr(),
54 sham::DDMultiRef{block_min_spans, block_max_spans},
55 sham::DDMultiRef{cell_coord_spans},
56 cell_counts,
57 [one_over_Nside, dxfact](
58 u32 i,
59 const TgridVec *__restrict index_block_min,
60 const TgridVec *__restrict index_block_max,
61 Tvec *__restrict cell_coord) {
62 u32 block_id = i / AMRBlock::block_size; // index of the block to which the current
63 // cell belongs
64 u32 cell_loc_id = i % AMRBlock::block_size; // index of the cell within the block
65
66 Tvec pos_block_min = index_block_min[block_id].template convert<Tscal>() * dxfact;
67
68 // size from the int coords difference, so that it does not depend on the block
69 // position
70 Tscal block_cell_size
71 = Tscal(index_block_max[block_id].x() - index_block_min[block_id].x())
72 * (dxfact * one_over_Nside);
73
74 std::array<u32, dim> coord_array = AMRBlock::get_coord(cell_loc_id);
75
76 Tvec offset; // offset of the lower left border of the cell from the lower left
77 // corner of the block
78 for (u32 d = 0; d < dim; d++) {
79 offset[d] = coord_array[d] * block_cell_size;
80 }
81
82 // so the coordinate of the cell center is pos_block_min + offset + half a cell
83 cell_coord[i] = pos_block_min + offset
84 + 0.5 * block_cell_size; // coordinates of the cell center
85 });
86 }
87
88 template<class Tvec, class TgridVec>
90 std::string tex = R"tex(
91 Compute cell coordinates:
92
93 \begin{align}
94 s_i &= \mathbf{e}_x \cdot ({spans_block_max}_i - {spans_block_min}_i) \chi \\
95 {spans_coordinates}_i &= \frac{s_i}{2} + {spans_block_min}_i \chi + \delta_{i \mod 8} \chi
96 i &\in [0,{sizes} \cdot {block_nside}^3)\\
97 \chi &= {grid_coord_to_pos_fact} / block_{\rm nside} \\
98 \delta_{i \mod 8} &= \text{local cell offset within block} \\
99 block_{\rm nside} &= {block_nside}
100 \end{align}
101 )tex";
102
103 replace_edges_tex_symbols(tex);
104
105 shambase::replace_all(tex, "{block_nside}", sham::format("{}", block_nside));
107 tex, "{grid_coord_to_pos_fact}", sham::format("{}", grid_coord_to_pos_fact));
108
109 return tex;
110 }
111
112} // namespace shammodels::basegodunov::modules
113
Computes the coordinates of each cell.
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Represents a collection of objects distributed across patches identified by a u64 id.
virtual std::string _impl_get_tex() const
get the tex of the node
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:106
namespace for the basegodunov model modules
A variant of sham::MultiRef for distributed data.