Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AsciiSplitDump.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
20#include "shambase/string.hpp"
21#include "shambackends/sycl.hpp"
23#include <filesystem>
24#include <fstream>
25#include <iostream>
26#include <utility>
27
33
37 struct PatchDump {
38 std::ofstream file;
39
46 void open(u64 id_patch, std::string fileprefix) {
47 const std::filesystem::path path{
48 fileprefix + "patch_" + shambase::format("{:04d}", id_patch) + ".txt"};
49 if (std::filesystem::exists(path)) {
50 std::filesystem::remove(path);
51 }
52
53 file.open(path);
54 }
55
62 void change_table_name(std::string table_name, std::string type) {
63 file << "--> " + table_name + " " + "type=" + type + "\n";
64 }
65
71 template<class T>
72 void write_val(T val);
73
80 template<class T>
81 void write_table(std::vector<T> buf, u32 len);
82
89 template<class T>
90 void write_table(sycl::buffer<T> buf, u32 len);
91
95 void close() { file.close(); }
96 };
97
106
113 std::string fileprefix;
114
115 public:
122 inline PatchDump &get_file(u64 id) { return dump_dist.get(id); }
123
129 explicit AsciiSplitDump(std::string fileprefix) : fileprefix(std::move(fileprefix)) {}
130
136 inline void create_id(u64 id) { dump_dist.add_obj(id, {})->second.open(id, fileprefix); }
137};
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A class to dump a simulation state into ASCII files.
PatchDump & get_file(u64 id)
Get a reference to a file.
AsciiSplitDump(std::string fileprefix)
Constructor.
void create_id(u64 id)
Create a new file for the given patch.
Represents a collection of objects distributed across patches identified by a u64 id.
iterator add_obj(u64 id, T &&obj)
Adds a new object to the collection.
T & get(u64 id)
Returns a reference to an object in the collection.
STL namespace.