Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ModifierFilter.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
21#include "shamcomm/logs.hpp"
28#include <vector>
29
30template<class Tvec, template<class> class SPHKernel>
32 u32 nmax) {
33
35 Config solver_config;
36 ShamrockCtx &ctx = context;
37 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
38 shamrock::patch::PatchDataLayer tmp = parent->next_n(nmax);
39
42 = tmp.get_field_buf_ref<Tvec>(sched.pdl_old().get_field_idx<Tvec>("xyz"));
44 = tmp.get_field_buf_ref<Tvec>(sched.pdl_old().get_field_idx<Tvec>("vxyz"));
45
46 std::vector<Tvec> pos = buf_xyz.copy_to_stdvec();
47
48 std::vector<u32> idx_keep = {};
49 for (u32 i = 0; i < pos.size(); i++) {
50 if (this->filter(pos[i])) {
51 idx_keep.push_back(i);
52 }
53 }
54
55 if (idx_keep.empty()) {
56 tmp.resize(0);
57 } else {
58 sham::DeviceBuffer<u32> filter_idx_buf(
59 idx_keep.size(), shamsys::instance::get_compute_scheduler_ptr());
60
61 filter_idx_buf.copy_from_stdvec(idx_keep);
62
63 tmp.keep_ids(filter_idx_buf, idx_keep.size());
64 }
65
66 return tmp;
67}
68
69using namespace shammath;
73
Header file describing a Node Instance.
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.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
shamrock::patch::PatchDataLayer next_n(u32 nmax)
This function generate patchdata with at most nmax per MPI ranks This function is always assumed as c...
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.
Class holding the value of numerous constants generated from the following source.
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:110
namespace for math utility
Definition AABB.hpp:26
The configuration for a sph solver.