Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CopyPatchDataFieldFromLayer.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
19
30#include <memory>
31
32#define NODE_EDGES(X_RO, X_RW) \
33 X_RO(shamrock::solvergraph::IPatchDataLayerRefs, original) \
34 X_RW(shamrock::solvergraph::IFieldRefs<T>, target)
35
36namespace shamrock::solvergraph {
37
38 template<class T>
39 class CopyPatchDataFieldFromLayer : public INode {
40
41 u32 field_idx;
42
43 public:
44 CopyPatchDataFieldFromLayer(u32 field_idx) : field_idx(field_idx) {}
45
46 CopyPatchDataFieldFromLayer(
47 shamrock::patch::PatchDataLayerLayout &layout, const std::string &field_name)
48 : CopyPatchDataFieldFromLayer(layout.get_field_idx<T>(field_name)) {}
49
50 CopyPatchDataFieldFromLayer(
51 const std::shared_ptr<shamrock::patch::PatchDataLayerLayout> &layout,
52 const std::string &field_name)
53 : CopyPatchDataFieldFromLayer(shambase::get_check_ref(layout), field_name) {}
54
55 EXPAND_NODE_EDGES(NODE_EDGES)
56
58
60
61 auto edges = get_edges();
62
63 auto source_refs = edges.original.get_const_refs();
64
65 // Collect the sizes & resize the target field if it support resizing
67
68 source_refs.for_each([&](u64 id_patch, const patch::PatchDataLayer &pdat) {
69 sizes.add_obj(id_patch, pdat.get_obj_cnt());
70 });
71
72 edges.target.ensure_sizes(sizes);
73
74 // perform the actual copy
75 auto target_refs = edges.target.get_refs();
76
77 source_refs.for_each([&](u64 id_patch, const patch::PatchDataLayer &source) {
78 PatchDataField<T> &dest = target_refs.get(id_patch).get();
79 dest.overwrite(source.get_field<T>(field_idx), source.get_obj_cnt());
80 });
81 }
82
83 std::string _impl_get_label() const { return "CopyPatchDataFieldFromLayer"; }
84
85 std::string _impl_get_tex() const { return "TODO"; }
86 };
87
88} // namespace shamrock::solvergraph
89
90#undef NODE_EDGES
Defines the PatchDataLayerRefs class for managing distributed references to patch data layers.
Defines the PatchDataLayerEdge class for managing patch data layer edges.
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.
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.
u32 get_obj_cnt() const
get the number of objects (particles) stored in this layer
std::string _impl_get_tex() const
get the tex of the node
std::string _impl_get_label() const
get the label of the node
This header file contains utility functions related to exception handling in the code.
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
#define __shamrock_stack_entry()
Macro to create a stack entry.