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
30#include <memory>
31
32namespace shamrock::solvergraph {
33
34 template<class T>
36
37 u32 field_idx;
38
39 public:
40 CopyPatchDataFieldFromLayer(u32 field_idx) : field_idx(field_idx) {}
41
43 shamrock::patch::PatchDataLayerLayout &layout, const std::string &field_name)
44 : CopyPatchDataFieldFromLayer(layout.get_field_idx<T>(field_name)) {}
45
47 const std::shared_ptr<shamrock::patch::PatchDataLayerLayout> &layout,
48 const std::string &field_name)
50
51 struct Edges {
52 const IPatchDataLayerRefs &original;
53 IFieldRefs<T> &target;
54 };
55
56 void set_edges(
57 std::shared_ptr<IPatchDataLayerRefs> original, std::shared_ptr<IFieldRefs<T>> target) {
58 __internal_set_ro_edges({original});
60 }
61
62 Edges get_edges() {
63 return Edges{get_ro_edge<IPatchDataLayerRefs>(0), get_rw_edge<IFieldRefs<T>>(0)};
64 }
65
67
69
70 auto edges = get_edges();
71
72 auto source_refs = edges.original.get_const_refs();
73
74 // Collect the sizes & resize the target field if it support resizing
76
77 source_refs.for_each([&](u64 id_patch, const patch::PatchDataLayer &pdat) {
78 sizes.add_obj(id_patch, pdat.get_obj_cnt());
79 });
80
81 edges.target.ensure_sizes(sizes);
82
83 // perform the actual copy
84 auto target_refs = edges.target.get_refs();
85
86 source_refs.for_each([&](u64 id_patch, const patch::PatchDataLayer &source) {
87 PatchDataField<T> &dest = target_refs.get(id_patch).get();
88 dest.overwrite(source.get_field<T>(field_idx), source.get_obj_cnt());
89 });
90 }
91
92 std::string _impl_get_label() const { return "CopyPatchDataFieldFromLayer"; }
93
94 std::string _impl_get_tex() const { return "TODO"; }
95 };
96
97} // namespace shamrock::solvergraph
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.
std::string _impl_get_tex() const
get the tex of the node
std::string _impl_get_label() const
get the label of the node
Interface for a solver graph edge representing a field as references to the underlying patch fields.
Inode is node between data edges, takes multiple inputs, multiple outputs.
Definition INode.hpp:30
void __internal_set_rw_edges(std::vector< std::shared_ptr< IEdge > > new_rw_edges)
Set the read write edges.
Definition INode.hpp:181
void __internal_set_ro_edges(std::vector< std::shared_ptr< IEdge > > new_ro_edges)
Set the read only edges.
Definition INode.hpp:171
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:110
#define __shamrock_stack_entry()
Macro to create a stack entry.