Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
units_json.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
24namespace shamunits {
25
32 template<class Tscal>
33 inline void to_json(nlohmann::json &j, const ::shamunits::UnitSystem<Tscal> &p) {
34 j = nlohmann::json{
35 {"unit_time", p.s_inv},
36 {"unit_length", p.m_inv},
37 {"unit_mass", p.kg_inv},
38 {"unit_current", p.A_inv},
39 {"unit_temperature", p.K_inv},
40 {"unit_qte", p.mol_inv},
41 {"unit_lumint", p.cd_inv}};
42 }
43
50 template<class Tscal>
51 inline void from_json(const nlohmann::json &j, ::shamunits::UnitSystem<Tscal> &p) {
53 j.at("unit_time").get<Tscal>(),
54 j.at("unit_length").get<Tscal>(),
55 j.at("unit_mass").get<Tscal>(),
56 j.at("unit_current").get<Tscal>(),
57 j.at("unit_temperature").get<Tscal>(),
58 j.at("unit_qte").get<Tscal>(),
59 j.at("unit_lumint").get<Tscal>());
60 }
61
62} // namespace shamunits
Defines a unit system.
namespace containing the units library
void from_json(const nlohmann::json &j, ::shamunits::UnitSystem< Tscal > &p)
Deserializes a UnitSystem object from a JSON object.
void to_json(nlohmann::json &j, const ::shamunits::UnitSystem< Tscal > &p)
Converts a UnitSystem object to a JSON object.