Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
FieldSpan.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
23
24namespace shamrock::solvergraph {
25
26 template<class T>
27 class FieldSpan : public IFieldSpan<T> {
28
30
31 public:
32 using IFieldSpan<T>::IFieldSpan;
33
34 virtual DDPatchDataFieldSpanPointer<T> &get_spans() { return spans; }
35
36 virtual const DDPatchDataFieldSpanPointer<T> &get_spans() const { return spans; }
37
38 inline virtual void check_sizes(const shambase::DistributedData<u32> &sizes) const {
39 on_distributeddata_diff(
40 spans,
41 sizes,
42 [&](u64 id) {
43 std::vector<u64> ids;
44 spans.for_each([&](u64 id, const PatchDataFieldSpan<T> &span) {
45 ids.push_back(id);
46 });
48 "Missing field span in distributed data at id {}\n"
49 "Field name: {}\n"
50 "Field texsymbol: {}",
51 id,
52 this->get_label(),
53 this->get_tex_symbol()));
54 },
55 [](u64 id) {
56 // TODO
57 },
58 [&](u64 id) {
60 "Extra field span in distributed data at id {}\n"
61 "Field name: {}\n"
62 "Field texsymbol: {}",
63 id,
64 this->get_label(),
65 this->get_tex_symbol()));
66 });
67 }
68
69 inline virtual void ensure_sizes(const shambase::DistributedData<u32> &sizes) {
70 check_sizes(sizes);
71 }
72
73 void set_spans(DDPatchDataFieldSpanPointer<T> spans) { this->spans = spans; }
74
75 DDPatchDataFieldSpanPointer<T> extract() {
76 DDPatchDataFieldSpanPointer<T> spans = std::exchange(this->spans, {});
77 return spans;
78 }
79
80 inline virtual void free_alloc() { spans = {}; }
81 };
82} // namespace shamrock::solvergraph
std::uint64_t u64
64 bit unsigned integer
Represents a collection of objects distributed across patches identified by a u64 id.
void for_each(std::function< void(u64, T &)> &&f)
Applies a function to each object in the collection.
Represents a span of data within a PatchDataField.
virtual void free_alloc()
Free allocated memory.
Definition FieldSpan.hpp:80
virtual const DDPatchDataFieldSpanPointer< T > & get_spans() const
Const variant of get_spans.
Definition FieldSpan.hpp:36
virtual void ensure_sizes(const shambase::DistributedData< u32 > &sizes)
Ensure that the sizes of the patches in the field match the given sizes (Can resize the underlying fi...
Definition FieldSpan.hpp:69
virtual DDPatchDataFieldSpanPointer< T > & get_spans()
Get the DistributedData of spans attached to the underlying field.
Definition FieldSpan.hpp:34
virtual void check_sizes(const shambase::DistributedData< u32 > &sizes) const
Check that the sizes of the patches in the field match the given sizes.
Definition FieldSpan.hpp:38
Interface for a solver graph edge representing a field as spans.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.