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
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
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 Tvec pos_block_max = index_block_max[block_id].template convert<Tscal>() * dxfact;
68
69 Tscal block_cell_size = ((pos_block_max - pos_block_min) * one_over_Nside).x();
70
71 std::array<u32, dim> coord_array = AMRBlock::get_coord(cell_loc_id);
72
73 Tvec offset; // offset of the lower left border of the cell from the lower left
74 // corner of the block
75 for (u32 d = 0; d < dim; d++) {
76 offset[d] = coord_array[d] * block_cell_size;
77 }
78
79 // so the coordinate of the cell center is pos_block_min + offset + half a cell
80 cell_coord[i] = pos_block_min + offset
81 + 0.5 * block_cell_size; // coordinates of the cell center
82 });
83 }
84
85 template<class Tvec, class TgridVec>
87
88 auto block_count = get_ro_edge_base(0).get_tex_symbol();
89 auto block_min = get_ro_edge_base(1).get_tex_symbol();
90 auto block_max = get_ro_edge_base(2).get_tex_symbol();
91 auto cell_coord = get_rw_edge_base(0).get_tex_symbol();
92
93 std::string tex = R"tex(
94 Compute cell coordinates:
95
96 \begin{align}
97 s_i &= \mathbf{e}_x \cdot ({block_max}_i - {block_min}_i) \chi \\
98 {cell_coord}_i &= \frac{s_i}{2} + {block_min}_i \chi + \delta_{i \mod 8} \chi
99 i &\in [0,{block_count} \cdot {block_nside}^3)\\
100 \chi &= {grid_coord_to_pos_fact} / block_{\rm nside} \\
101 \delta_{i \mod 8} &= \text{local cell offset within block} \\
102 block_{\rm nside} &= {block_nside}
103 \end{align}
104 )tex";
105
106 shambase::replace_all(tex, "{block_count}", block_count);
107 shambase::replace_all(tex, "{block_min}", block_min);
108 shambase::replace_all(tex, "{block_max}", block_max);
109 shambase::replace_all(tex, "{cell_coord}", cell_coord);
110 shambase::replace_all(tex, "{block_nside}", shambase::format("{}", block_nside));
112 tex, "{grid_coord_to_pos_fact}", shambase::format("{}", grid_coord_to_pos_fact));
113
114 return tex;
115 }
116
117} // namespace shammodels::basegodunov::modules
118
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:183
namespace for the basegodunov model modules
A variant of sham::MultiRef for distributed data.