Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
GetFieldRefFromLayer.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
20#include "shambase/memory.hpp"
24#include <memory>
25
26namespace shamrock::solvergraph {
27
28 template<class T>
29 class GetFieldRefFromLayer : public INode {
30
31 u32 field_idx;
32
33 public:
34 GetFieldRefFromLayer(u32 field_idx) : field_idx(field_idx) {}
35
37 shamrock::patch::PatchDataLayerLayout &layout, const std::string &field_name)
38 : GetFieldRefFromLayer(layout.get_field_idx<T>(field_name)) {}
39
41 const std::shared_ptr<shamrock::patch::PatchDataLayerLayout> &layout,
42 const std::string &field_name)
43 : GetFieldRefFromLayer(shambase::get_check_ref(layout), field_name) {}
44
45 struct Edges {
46 const IPatchDataLayerRefs &source;
48 };
49
50 void set_edges(
51 std::shared_ptr<IPatchDataLayerRefs> source,
52 std::shared_ptr<shamrock::solvergraph::FieldRefs<T>> out_ref) {
54 __internal_set_rw_edges({out_ref});
55 }
56
57 Edges get_edges() {
58 return Edges{
59 get_ro_edge<IPatchDataLayerRefs>(0),
60 get_rw_edge<shamrock::solvergraph::FieldRefs<T>>(0)};
61 }
62
64 auto edges = get_edges();
65
66 edges.out_ref.set_refs(
67 edges.source.get_const_refs()
68 .template map<std::reference_wrapper<PatchDataField<T>>>(
69 [&](u64 id_patch, shamrock::patch::PatchDataLayer &pdat) {
70 return std::ref(pdat.get_field<T>(field_idx));
71 }));
72 }
73
74 std::string _impl_get_label() const { return "GetFieldRefFromLayer"; }
75
76 std::string _impl_get_tex() const { return "TODO"; }
77 };
78} // namespace shamrock::solvergraph
Defines the PatchDataLayerRefs class for managing distributed references to patch data layers.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
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_label() const
get the label of the node
std::string _impl_get_tex() const
get the tex of the node
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
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