28namespace generic::setup::modifiers {
30 template<
class T,
class vec>
31 inline void set_value_in_box(
32 PatchScheduler &sched, T val, std::string name, std::tuple<vec, vec> box) {
37 = pdat.template get_field<vec>(sched.pdl_old().
get_field_idx<vec>(
"xyz"));
40 = pdat.template get_field<T>(sched.pdl_old().
get_field_idx<T>(name));
43 auto &buf = f.get_buf();
44 sycl::host_accessor acc{*buf};
46 auto &buf_xyz =
xyz.get_buf();
47 sycl::host_accessor acc_xyz{*buf_xyz};
49 for (
u32 i = 0; i < f.size(); i++) {
52 if (BBAA::is_coord_in_range(r, std::get<0>(box), std::get<1>(box))) {
60 template<
class T,
class vec>
61 inline void set_value_in_sphere(
66 shambase::VecComponent<vec> radius) {
68 using flt = shambase::VecComponent<vec>;
74 = pdat.template get_field<vec>(sched.pdl_old().
get_field_idx<vec>(
"xyz"));
77 = pdat.template get_field<T>(sched.pdl_old().
get_field_idx<T>(name));
79 flt r2 = radius * radius;
81 auto &buf = f.get_buf();
82 sycl::host_accessor acc{*buf};
84 auto &buf_xyz =
xyz.get_buf();
85 sycl::host_accessor acc_xyz{*buf_xyz};
87 for (
u32 i = 0; i < f.size(); i++) {
88 vec dr = acc_xyz[i] - center;
90 if (sycl::dot(dr, dr) < r2) {
99 inline void pertub_eigenmode_wave(
100 PatchScheduler &sched, std::tuple<flt, flt> ampls, sycl::vec<flt, 3> k, flt phase) {
102 using vec = sycl::vec<flt, 3>;
104 if (std::get<0>(ampls) != 0) {
106 "density perturbation not implemented");
112 = pdat.template get_field<vec>(sched.pdl_old().
get_field_idx<vec>(
"xyz"));
114 = pdat.template get_field<vec>(sched.pdl_old().
get_field_idx<vec>(
"vxyz"));
116 flt ampl = std::get<1>(ampls);
120 u32 cnt = pdat.get_obj_cnt();
122 auto &buf_xyz =
xyz.get_buf();
123 auto acc_xyz = buf_xyz.copy_to_stdvec();
125 auto &buf_vxyz =
vxyz.get_buf();
126 auto acc_vxyz = buf_vxyz.copy_to_stdvec();
128 for (
u32 i = 0; i < cnt; i++) {
130 flt rkphi = sycl::dot(r, k) + phase;
131 acc_vxyz[i] = ampl * sycl::sin(rkphi);
134 buf_xyz.copy_from_stdvec(acc_xyz);
135 buf_vxyz.copy_from_stdvec(acc_vxyz);
149 = pdat.template get_field<T>(sched.pdl_old().
get_field_idx<T>(name));
151 sum +=
xyz.compute_sum();
154 return shamalgs::collective::allreduce_sum(sum);
constexpr const char * vxyz
3-velocity field
constexpr const char * xyz
Position field (3D coordinates)
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
SchedulerPatchData patch_data
handle the data of the patches of the scheduler
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
PatchDataLayer container class, the layout is described in patchdata_layout.
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.