Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
VTKDumpUtils.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#include "shamalgs/memory.hpp"
24#include "shamcomm/logs.hpp"
30
31namespace shammodels::common::io {
32
41 template<class Tvec>
43 PatchScheduler &sched, const std::string &dump_name) {
44 StackEntry stack_loc{};
45 shamrock::LegacyVtkWriter writer(dump_name, true, shamrock::UnstructuredGrid);
46
47 using namespace shamrock::patch;
48
49 u64 num_obj = sched.get_rank_count();
50
51 shamlog_debug_mpi_ln("VTKDump", "rank count =", num_obj);
52
53 std::unique_ptr<sycl::buffer<Tvec>> pos = sched.rankgather_field<Tvec>(0);
54
55 writer.write_points(pos, num_obj);
56
57 return writer;
58 }
59
67 StackEntry stack_loc{};
68
69 u64 num_obj = sched.get_rank_count();
70
71 using namespace shamrock::patch;
72
73 if (num_obj > 0) {
74 sycl::buffer<u64> idp(num_obj);
75
76 u64 ptr = 0;
77 sched.for_each_patchdata_nonempty([&](Patch cur_p, PatchDataLayer &pdat) {
78 using namespace shamalgs::memory;
79 using namespace shambase;
80
81 write_with_offset_into(
82 shamsys::instance::get_compute_queue(),
83 idp,
84 cur_p.id_patch,
85 ptr,
86 pdat.get_obj_cnt());
87
88 ptr += pdat.get_obj_cnt();
89 });
90
91 writer.write_field("patchid", idp, num_obj);
92 } else {
93 writer.write_field_no_buf<u64>("patchid");
94 }
95 }
96
104 StackEntry stack_loc{};
105
106 using namespace shamrock::patch;
107 u64 num_obj = sched.get_rank_count();
108
109 if (num_obj > 0) {
110 sycl::buffer<u32> idp(num_obj);
111
112 u64 ptr = 0;
113 sched.for_each_patchdata_nonempty([&](Patch cur_p, PatchDataLayer &pdat) {
114 using namespace shamalgs::memory;
115 using namespace shambase;
116
117 write_with_offset_into<u32>(
118 shamsys::instance::get_compute_queue(),
119 idp,
121 ptr,
122 pdat.get_obj_cnt());
123
124 ptr += pdat.get_obj_cnt();
125 });
126
127 writer.write_field("world_rank", idp, num_obj);
128 } else {
129 writer.write_field_no_buf<u32>("world_rank");
130 }
131 }
132
142 template<class T>
144 PatchScheduler &sched,
147 const std::string &field_dump_name) {
148 StackEntry stack_loc{};
149
150 using namespace shamrock::patch;
151 u64 num_obj = sched.get_rank_count();
152
153 if (num_obj > 0) {
154 std::unique_ptr<sycl::buffer<T>> field_vals = field.rankgather_computefield(sched);
155
156 writer.write_field(field_dump_name, field_vals, num_obj);
157 } else {
158 writer.write_field_no_buf<T>(field_dump_name);
159 }
160 }
161
171 template<class T>
173 PatchScheduler &sched,
175 u32 field_idx,
176 const std::string &field_dump_name) {
177 StackEntry stack_loc{};
178
179 using namespace shamrock::patch;
180 u64 num_obj = sched.get_rank_count();
181
182 if (num_obj > 0) {
183 std::unique_ptr<sycl::buffer<T>> field_vals = sched.rankgather_field<T>(field_idx);
184
185 writer.write_field(field_dump_name, field_vals, num_obj);
186 } else {
187 writer.write_field_no_buf<T>(field_dump_name);
188 }
189 }
190
191} // namespace shammodels::common::io
Header file describing a Node Instance.
MPI scheduler.
void vtk_dump_add_compute_field(PatchScheduler &sched, shamrock::LegacyVtkWriter &writer, shamrock::ComputeField< T > &field, const std::string &field_dump_name)
Add a compute field to VTK dump.
void vtk_dump_add_field(PatchScheduler &sched, shamrock::LegacyVtkWriter &writer, u32 field_idx, const std::string &field_dump_name)
Add a data field to VTK dump.
shamrock::LegacyVtkWriter start_dump(PatchScheduler &sched, const std::string &dump_name)
Start a VTK dump by writing particle positions.
void vtk_dump_add_patch_id(PatchScheduler &sched, shamrock::LegacyVtkWriter &writer)
Add patch ID field to VTK dump.
void vtk_dump_add_worldrank(PatchScheduler &sched, shamrock::LegacyVtkWriter &writer)
Add world rank field to VTK dump.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
The MPI scheduler.
PatchDataLayer container class, the layout is described in patchdata_layout.
memory manipulation algorithms
namespace for basic c++ utilities
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
main include file for memory algorithms
This file contains the definition for the stacktrace related functionality.
Patch object that contain generic patch information.
Definition Patch.hpp:33
u64 id_patch
unique key that identify the patch
Definition Patch.hpp:86
Functions related to the MPI communicator.