Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NeighGraphLinkFieldEdge.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
26#include <functional>
27
28namespace shammodels::basegodunov::solvergraph {
29
30 template<class T>
32 public:
33 using IEdgeNamed::IEdgeNamed;
34
35 u32 nvar;
37
38 NeighGraphLinkFieldEdge(std::string name, std::string texsymbol, u32 nvar)
39 : IEdgeNamed(name, texsymbol), nvar(nvar) {}
40
41 inline void check_size(
42 const shambase::DistributedData<std::reference_wrapper<modules::AMRGraph>> &graph)
43 const {
44
45 on_distributeddata_diff(
46 link_fields,
47 graph,
48 [&](u64 id) {
50 "Missing link field in distributed data at id " + std::to_string(id));
51 },
52 [&](u64 id) {
53 if (link_fields.get(id).link_count != graph.get(id).get().link_count) {
55 "Wrong size for link field in distributed data at id "
56 + std::to_string(id));
57 }
58 },
59 [&](u64 id) {
61 "Extra link field in distributed data at id " + std::to_string(id));
62 });
63 }
64
65 inline void resize_according_to(
66 const shambase::DistributedData<std::reference_wrapper<modules::AMRGraph>> &graph) {
67
68 on_distributeddata_diff(
69 link_fields,
70 graph,
71 [&](u64 id) {
72 link_fields.add_obj(
73 id, modules::NeighGraphLinkField<T>{graph.get(id).get(), nvar});
74 },
75 [&](u64 id) {
76 link_fields.get(id).resize(graph.get(id).get());
77 },
78 [&](u64 id) {
79 link_fields.erase(id);
80 });
81 }
82
83 inline void check_size(const shamrock::solvergraph::Indexes<u32> &link_counts) const {
84
85 on_distributeddata_diff(
86 link_fields,
87 link_counts.indexes,
88 [&](u64 id) {
89 shambase::throw_with_loc<std::runtime_error>(
90 "Missing link field in distributed data at id " + std::to_string(id));
91 },
92 [&](u64 id) {
93 if (link_fields.get(id).link_count != link_counts.indexes.get(id)) {
94 shambase::throw_with_loc<std::runtime_error>(
95 "Wrong size for link field in distributed data at id "
96 + std::to_string(id));
97 }
98 },
99 [&](u64 id) {
101 "Extra link field in distributed data at id " + std::to_string(id));
102 });
103 }
104
105 inline void resize_according_to(const shamrock::solvergraph::Indexes<u32> &link_counts) {
106
107 on_distributeddata_diff(
108 link_fields,
109 link_counts.indexes,
110 [&](u64 id) {
111 link_fields.add_obj(
112 id, modules::NeighGraphLinkField<T>{link_counts.indexes.get(id), nvar});
113 },
114 [&](u64 id) {
115 link_fields.get(id).resize(link_counts.indexes.get(id));
116 },
117 [&](u64 id) {
118 link_fields.erase(id);
119 });
120 }
121
122 inline virtual void free_alloc() { link_fields = {}; }
123 };
124
125} // namespace shammodels::basegodunov::solvergraph
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.
iterator add_obj(u64 id, T &&obj)
Adds a new object to the collection.
void erase(u64 id)
Removes an object from the collection.
T & get(u64 id)
Returns a reference to an object in the collection.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.