Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CopyPatchDataLayerFields.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
18
19namespace shamrock::solvergraph {
20
22 StackEntry stack_loc{};
23
24 auto edges = get_edges();
25
26 edges.target.set_patchdatas({});
27
28 // Ensures that the layout are all matching sources and targets
29 edges.original.get_const_refs().for_each(
30 [&](u64 id_patch, const patch::PatchDataLayer &pdat) {
31 if (pdat.get_layout_ptr().get() != layout_source.get()) {
32 throw shambase::make_except_with_loc<std::invalid_argument>("layout mismatch");
33 }
34 });
35
36 if (edges.target.get_layout_ptr().get() != layout_target.get()) {
38 }
39
40 // Copy the fields from the original to the target
41 edges.target.set_patchdatas(edges.original.get_const_refs().map<patch::PatchDataLayer>(
42 [&](u64 id_patch, const patch::PatchDataLayer &pdat) {
43 patch::PatchDataLayer pdat_new(layout_target);
44
45 pdat_new.for_each_field_any([&](auto &field) {
46 using T = typename std::remove_reference<decltype(field)>::type::Field_type;
47 field.insert(pdat.get_field<T>(field.get_name()));
48 });
49
50 pdat_new.check_field_obj_cnt_match();
51 return pdat_new;
52 }));
53 }
54
55} // namespace shamrock::solvergraph
Defines the CopyPatchDataLayerFields class for copying fields between patch data layers.
std::uint64_t u64
64 bit unsigned integer
PatchDataLayer container class, the layout is described in patchdata_layout.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.