Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SimBox.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
21template<class... Ts>
22struct overloaded : Ts... {
23 using Ts::operator()...;
24};
26template<class... Ts>
27overloaded(Ts...) -> overloaded<Ts...>;
28
29namespace shamrock::patch {
30
31 void SimulationBoxInfo::to_json(nlohmann::json &j) {
32 auto &pcoord = patch_coord_bounding_box;
33 auto &bounding_box_var = bounding_box;
34
35 j["patchcoormin"] = pcoord.coord_min;
36 j["patchcoormax"] = pcoord.coord_max;
37
38 std::visit(
40 [&](auto arg) {
42 },
44 j["coordtype"] = "f32_3";
45 j["box_min"] = sham::sycl_vec_to_array(arg.lower);
46 j["box_max"] = sham::sycl_vec_to_array(arg.upper);
47 },
49 j["coordtype"] = "f64_3";
50 j["box_min"] = sham::sycl_vec_to_array(arg.lower);
51 j["box_max"] = sham::sycl_vec_to_array(arg.upper);
52 },
54 j["coordtype"] = "u32_3";
55 j["box_min"] = sham::sycl_vec_to_array(arg.lower);
56 j["box_max"] = sham::sycl_vec_to_array(arg.upper);
57 },
59 j["coordtype"] = "u64_3";
60 j["box_min"] = sham::sycl_vec_to_array(arg.lower);
61 j["box_max"] = sham::sycl_vec_to_array(arg.upper);
62 },
64 j["coordtype"] = "i64_3";
65 j["box_min"] = sham::sycl_vec_to_array(arg.lower);
66 j["box_max"] = sham::sycl_vec_to_array(arg.upper);
67 }},
68 bounding_box_var.value);
69 }
70
71 void SimulationBoxInfo::from_json(const nlohmann::json &j) {
72 PatchCoord<3> pcoord;
73 j.at("patchcoormin").get_to(pcoord.coord_min);
74 j.at("patchcoormax").get_to(pcoord.coord_max);
75 patch_coord_bounding_box = pcoord;
76
77 // logger::raw_ln(
78 // pdl.check_main_field_type<f64_3>(),
79 // j.at("coordtype").get<std::string>(),
80 // j.at("coordtype").get<std::string>() == "f64_3");
81 if (pdl.check_main_field_type<f32_3>()
82 && (j.at("coordtype").get<std::string>() == "f32_3")) {
84 sham::array_to_sycl_vec(j.at("box_min").get<std::array<f32, 3>>()),
85 sham::array_to_sycl_vec(j.at("box_max").get<std::array<f32, 3>>()),
86 };
87 } else if (
88 pdl.check_main_field_type<f64_3>()
89 && (j.at("coordtype").get<std::string>() == "f64_3")) {
91 sham::array_to_sycl_vec(j.at("box_min").get<std::array<f64, 3>>()),
92 sham::array_to_sycl_vec(j.at("box_max").get<std::array<f64, 3>>()),
93 };
94 } else if (
95 pdl.check_main_field_type<u32_3>()
96 && (j.at("coordtype").get<std::string>() == "u32_3")) {
98 sham::array_to_sycl_vec(j.at("box_min").get<std::array<u32, 3>>()),
99 sham::array_to_sycl_vec(j.at("box_max").get<std::array<u32, 3>>()),
100 };
101 } else if (
102 pdl.check_main_field_type<u64_3>()
103 && (j.at("coordtype").get<std::string>() == "u64_3")) {
104 bounding_box.value = shammath::CoordRange<u64_3>{
105 sham::array_to_sycl_vec(j.at("box_min").get<std::array<u64, 3>>()),
106 sham::array_to_sycl_vec(j.at("box_max").get<std::array<u64, 3>>()),
107 };
108 } else if (
109 pdl.check_main_field_type<i64_3>()
110 && (j.at("coordtype").get<std::string>() == "i64_3")) {
111 bounding_box.value = shammath::CoordRange<i64_3>{
112 sham::array_to_sycl_vec(j.at("box_min").get<std::array<i64, 3>>()),
113 sham::array_to_sycl_vec(j.at("box_max").get<std::array<i64, 3>>()),
114 };
115 } else {
116 throw shambase::make_except_with_loc<std::runtime_error>("unable to parse json type");
117 }
118 }
119
120} // namespace shamrock::patch
bool check_main_field_type()
check that main field (id=0)is of type T
void to_json(nlohmann::json &j)
Serializes a SimulationBoxInfo object to a JSON object.
Definition SimBox.cpp:31
void from_json(const nlohmann::json &j)
Deserializes a JSON object into a SimulationBoxInfo object.
Definition SimBox.cpp:71
std::array< T, n > sycl_vec_to_array(sycl::vec< T, n > v)
Converts a SYCL vector into a C++ standard library array.
sycl::vec< T, n > array_to_sycl_vec(std::array< T, n > v)
Converts a C++ standard library array into a SYCL vector.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
Contains functions for converting between SYCL vector types and C++ standard library array types.