Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CopyPatchDataField.cpp
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
19
20namespace shamrock::solvergraph {
21
22 template<class T>
24 StackEntry stack_loc{};
25
26 auto edges = get_edges();
27
28 // Collect size information from source fields
30
31 edges.original.get_refs().for_each([&](u64 id_patch, const PatchDataField<T> &field) {
32 sizes.add_obj(id_patch, u32(field.get_obj_cnt()));
33 });
34
35 // Ensure target field has correct size for each patch
36 edges.target.ensure_sizes(sizes);
37
38 // Copy the fields from the original to the target
39 edges.target.get_refs().for_each([&](u64 id_patch, PatchDataField<T> &field) {
40 auto &source_field = edges.original.get_field(id_patch);
41 if (field.get_nvar() != source_field.get_nvar()) {
43 "nvar mismatch between source and target fields for patch "
44 + std::to_string(id_patch)
45 + ". Source nvar: " + std::to_string(source_field.get_nvar())
46 + ", Target nvar: " + std::to_string(field.get_nvar()));
47 }
48 field.overwrite(source_field, field.get_obj_cnt());
49 });
50 }
51
52 template<class T>
54 std::string tmp = "Copy field ${original} to ${target}";
55 shambase::replace_all(tmp, "{original}", get_ro_edge_base(0).get_tex_symbol());
56 shambase::replace_all(tmp, "{target}", get_rw_edge_base(0).get_tex_symbol());
57 return tmp;
58 }
59
60 template class CopyPatchDataField<f64>;
61 template class CopyPatchDataField<f64_3>;
62
63} // namespace shamrock::solvergraph
Defines the CopyPatchDataField class for copying fields between patch data field references.
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.
A solver graph node that copies field data from source field references to target fields.
void _impl_evaluate_internal()
Internal implementation of the field copying operation.
std::string _impl_get_tex() const
Returns the LaTeX representation of this node for documentation.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:183
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.