Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CartesianRender.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 "shambackends/vec.hpp"
27#include <pybind11/numpy.h>
28#include <pybind11/pytypes.h>
29
31
32 template<class Tvec, class Tfield, template<class> class SPHKernel>
33 class CartesianRender {
34 public:
35 using Tscal = shambase::VecComponent<Tvec>;
36 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
37 using Kernel = SPHKernel<Tscal>;
38
39 using Config = SolverConfig<Tvec, SPHKernel>;
40 using Storage = SolverStorage<Tvec, u32>;
41
42 ShamrockCtx &context;
43 Config &solver_config;
44 Storage &storage;
45
46 CartesianRender(ShamrockCtx &context, Config &solver_config, Storage &storage)
47 : context(context), solver_config(solver_config), storage(storage) {}
48
49 using field_getter_t = const sham::DeviceBuffer<Tfield> &(
51
52 sham::DeviceBuffer<Tfield> compute_slice(
53 std::function<field_getter_t> field_getter, const sham::DeviceBuffer<Tvec> &positions);
54
55 sham::DeviceBuffer<Tfield> compute_column_integ(
56 std::function<field_getter_t> field_getter,
58
59 sham::DeviceBuffer<Tfield> compute_azymuthal_integ(
60 std::function<field_getter_t> field_getter,
62
63 sham::DeviceBuffer<Tfield> compute_slice(
65
66 sham::DeviceBuffer<Tfield> compute_column_integ(
69
70 sham::DeviceBuffer<Tfield> compute_azymuthal_integ(
73
74 sham::DeviceBuffer<Tfield> compute_slice(
75 std::string field_name,
76 const sham::DeviceBuffer<Tvec> &positions,
77 std::optional<
78 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
79 custom_getter);
80
81 sham::DeviceBuffer<Tfield> compute_column_integ(
82 std::string field_name,
84 std::optional<
85 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
86 custom_getter);
87
88 sham::DeviceBuffer<Tfield> compute_azymuthal_integ(
89 std::string field_name,
91 std::optional<
92 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
93 custom_getter);
94
95 sham::DeviceBuffer<Tfield> compute_slice(
96 std::function<field_getter_t> field_getter,
97 Tvec center,
98 Tvec delta_x,
99 Tvec delta_y,
100 u32 nx,
101 u32 ny);
102
103 sham::DeviceBuffer<Tfield> compute_column_integ(
104 std::function<field_getter_t> field_getter,
105 Tvec center,
106 Tvec delta_x,
107 Tvec delta_y,
108 u32 nx,
109 u32 ny);
110
111 sham::DeviceBuffer<Tfield> compute_slice(
113 Tvec center,
114 Tvec delta_x,
115 Tvec delta_y,
116 u32 nx,
117 u32 ny);
118
119 sham::DeviceBuffer<Tfield> compute_column_integ(
121 Tvec center,
122 Tvec delta_x,
123 Tvec delta_y,
124 u32 nx,
125 u32 ny);
126
127 sham::DeviceBuffer<Tfield> compute_slice(
128 std::string field_name,
129 Tvec center,
130 Tvec delta_x,
131 Tvec delta_y,
132 u32 nx,
133 u32 ny,
134 std::optional<
135 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
136 custom_getter);
137
138 sham::DeviceBuffer<Tfield> compute_column_integ(
139 std::string field_name,
140 Tvec center,
141 Tvec delta_x,
142 Tvec delta_y,
143 u32 nx,
144 u32 ny,
145 std::optional<
146 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
147 custom_getter);
148
149 inline sham::DeviceBuffer<Tfield> compute_slice(
150 std::string field_name,
151 const std::vector<Tvec> &positions,
152 std::optional<
153 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
154 custom_getter) {
155 sham::DeviceBuffer<Tvec> positions_buf{
156 positions.size(), shamsys::instance::get_compute_scheduler_ptr()};
157 positions_buf.copy_from_stdvec(positions);
158 return compute_slice(field_name, positions_buf, custom_getter);
159 }
160
161 inline sham::DeviceBuffer<Tfield> compute_column_integ(
162 std::string field_name,
163 const std::vector<shammath::Ray<Tvec>> &rays,
164 std::optional<
165 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
166 custom_getter) {
168 rays.size(), shamsys::instance::get_compute_scheduler_ptr()};
169 rays_buf.copy_from_stdvec(rays);
170 return compute_column_integ(field_name, rays_buf, custom_getter);
171 }
172
173 inline sham::DeviceBuffer<Tfield> compute_azymuthal_integ(
174 std::string field_name,
175 const std::vector<shammath::RingRay<Tvec>> &ring_rays,
176 std::optional<
177 std::function<pybind11::array_t<Tfield>(size_t, shamrock::PatchDataLazyGetter &)>>
178 custom_getter) {
180 ring_rays.size(), shamsys::instance::get_compute_scheduler_ptr()};
181 ring_rays_buf.copy_from_stdvec(ring_rays);
182 return compute_azymuthal_integ(field_name, ring_rays_buf, custom_getter);
183 }
184
185 inline sham::DeviceBuffer<Tfield> compute_slice(
186 shamrock::solvergraph::Field<Tfield> &field, const std::vector<Tvec> &positions) {
187 sham::DeviceBuffer<Tvec> positions_buf{
188 positions.size(), shamsys::instance::get_compute_scheduler_ptr()};
189 positions_buf.copy_from_stdvec(positions);
190 return compute_slice(field, positions_buf);
191 }
192
193 inline sham::DeviceBuffer<Tfield> compute_column_integ(
195 const std::vector<shammath::Ray<Tvec>> &rays) {
197 rays.size(), shamsys::instance::get_compute_scheduler_ptr()};
198 rays_buf.copy_from_stdvec(rays);
199 return compute_column_integ(field, rays_buf);
200 }
201
202 inline sham::DeviceBuffer<Tfield> compute_azymuthal_integ(
204 const std::vector<shammath::RingRay<Tvec>> &ring_rays) {
206 ring_rays.size(), shamsys::instance::get_compute_scheduler_ptr()};
207 ring_rays_buf.copy_from_stdvec(ring_rays);
208 return compute_azymuthal_integ(field, ring_rays_buf);
209 }
210
211 private:
212 inline PatchScheduler &scheduler() { return shambase::get_check_ref(context.sched); }
213 };
214
215} // namespace shammodels::sph::modules
std::uint32_t u32
32 bit unsigned integer
The MPI scheduler.
A buffer allocated in USM (Unified Shared Memory).
void copy_from_stdvec(const std::vector< T > &vec)
Copy the content of a std::vector into the buffer.
Lazily fetches a single named field of a patch as a numpy array, on demand.
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:112
namespace for the sph model modules
Ray representation for intersection testing.
Definition AABB.hpp:34
Ring ray representation for intersection testing.
Definition AABB.hpp:67
The configuration for a sph solver.
Patch object that contain generic patch information.
Definition Patch.hpp:33