Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
GetParticlesOutsideSphere.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
19#include "shambase/string.hpp"
21
23
24 template<typename Tvec>
26 StackEntry stack_loc{};
27 auto edges = get_edges();
28
29 const shamrock::solvergraph::DDPatchDataFieldRef<Tvec> &pos_refs = edges.pos.get_refs();
30
31 edges.part_ids_outside_sphere.ensure_allocated(pos_refs.get_ids());
32
33 pos_refs.for_each([&](u64 id_patch, const PatchDataField<Tvec> &pos) {
34 auto tmp = pos.get_ids_where(
35 [](const Tvec *__restrict pos, u32 i, Tvec sphere_center, Tscal sphere_radius) {
36 return sycl::length(pos[i] - sphere_center) > sphere_radius;
37 },
38 sphere_center,
39 sphere_radius);
40
41 edges.part_ids_outside_sphere.buffers.get(id_patch).append(tmp);
42 });
43 }
44
45 template<typename Tvec>
47 auto pos = get_ro_edge_base(0).get_tex_symbol();
48 auto part_ids_outside_sphere = get_rw_edge_base(0).get_tex_symbol();
49
50 std::string tex = R"tex(
51 Get particles outside of the sphere
52
53 \begin{align}
54 {part_ids_outside_sphere} &= \{i \text{ where } \vert\vert{pos}_i - c\vert\vert > r\}\\
55 c &= {center}\\
56 r &= {radius}
57 \end{align}
58 )tex";
59
60 shambase::replace_all(tex, "{pos}", pos);
61 shambase::replace_all(tex, "{part_ids_outside_sphere}", part_ids_outside_sphere);
62 shambase::replace_all(tex, "{center}", shambase::format("{}", sphere_center));
63 shambase::replace_all(tex, "{radius}", shambase::format("{}", sphere_radius));
64
65 return tex;
66 }
67
68} // namespace shammodels::sph::modules
69
Declares the GetParticlesOutsideSphere module for removing particles.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
sham::DeviceBuffer< u32 > get_ids_where(Lambdacd &&cd_true, Args... args) const
Same function as.
void append(const DeviceBuffer &other)
Append the content of another buffer to this one.
Represents a collection of objects distributed across patches identified by a u64 id.
std::vector< u64 > get_ids() const
Returns a vector of all the ids of the objects in the collection.
void for_each(std::function< void(u64, T &)> &&f)
Applies a function to each object in the collection.
virtual std::string _impl_get_tex() const
get the tex of the node
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 sph model modules
This file contains the definition for the stacktrace related functionality.