Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AsciiSplitDump.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
19template<class T>
20void AsciiSplitDump::PatchDump::write_val(T val) {
21 if constexpr (
22 std::is_same_v<T, u32> || std::is_same_v<T, i32> || std::is_same_v<T, u64>
23 || std::is_same_v<T, i64>) {
24 file << shambase::format("{:}\n", val);
25 } else if constexpr (std::is_same_v<T, i64_3> || std::is_same_v<T, i32_3>) {
26 file << shambase::format("{:} {:} {:}\n", val.x(), val.y(), val.z());
27 } else if constexpr (std::is_same_v<T, f64> || std::is_same_v<T, f32>) {
28 file << shambase::format("{:0.9f}\n", val);
29 } else if constexpr (std::is_same_v<T, f64_3> || std::is_same_v<T, f32_3>) {
30 file << shambase::format("{:0.9f} {:0.9f} {:0.9f}\n", val.x(), val.y(), val.z());
31 } else if constexpr (std::is_same_v<T, f64_8> || std::is_same_v<T, f32_8>) {
32 file << shambase::format(
33 "{:0.9f} {:0.9f} {:0.9f} {:0.9f} {:0.9f} {:0.9f} {:0.9f} {:0.9f}\n",
34 val.s0(),
35 val.s1(),
36 val.s2(),
37 val.s3(),
38 val.s4(),
39 val.s5(),
40 val.s6(),
41 val.s7());
42 } else {
44 }
45}
46
47template<class T>
48void AsciiSplitDump::PatchDump::write_table(std::vector<T> buf, u32 len) {
49 for (u32 i = 0; i < len; i++) {
50 write_val(buf[i]);
51 }
52}
53
54template<class T>
55void AsciiSplitDump::PatchDump::write_table(sycl::buffer<T> buf, u32 len) {
56 sycl::host_accessor acc{buf, sycl::read_only};
57 for (u32 i = 0; i < len; i++) {
58 write_val(acc[i]);
59 }
60}
61
62#ifndef DOXYGEN
63 #define XMAC_TYPES \
64 X(f32) \
65 X(f32_2) \
66 X(f32_3) \
67 X(f32_4) \
68 X(f32_8) \
69 X(f32_16) \
70 X(f64) \
71 X(f64_2) \
72 X(f64_3) \
73 X(f64_4) \
74 X(f64_8) \
75 X(f64_16) \
76 X(u32) \
77 X(u64) \
78 X(u32_3) \
79 X(u64_3) \
80 X(i64_3)
81
82 #define X(_arg_) \
83 template void AsciiSplitDump::PatchDump::write_val<_arg_>(_arg_ val); \
84 template void AsciiSplitDump::PatchDump::write_table<_arg_>( \
85 std::vector<_arg_> buf, u32 len); \
86 template void AsciiSplitDump::PatchDump::write_table<_arg_>( \
87 sycl::buffer<_arg_> buf, u32 len);
88
89XMAC_TYPES
90 #undef X
91#endif
std::uint32_t u32
32 bit unsigned integer
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.