Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
pyUnits.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
15
16#include "shambackends/sycl.hpp"
19#include <pybind11/cast.h>
21#include <shamunits/Names.hpp>
23#include <memory>
24
26 auto &m = root_module;
27
28 using UnitSystem = shamunits::UnitSystem<f64>;
29
30 py::class_<UnitSystem>(m, "UnitSystem")
31 .def(
32 py::init([](f64 unit_time,
33 f64 unit_length,
34 f64 unit_mass,
35 f64 unit_current,
36 f64 unit_temperature,
37 f64 unit_qte,
38 f64 unit_lumint) {
39 return std::make_unique<UnitSystem>(
40 unit_time,
41 unit_length,
42 unit_mass,
43 unit_current,
44 unit_temperature,
45 unit_qte,
46 unit_lumint);
47 }),
48 py::kw_only(),
49 py::arg("unit_time") = 1,
50 py::arg("unit_length") = 1,
51 py::arg("unit_mass") = 1,
52 py::arg("unit_current") = 1,
53 py::arg("unit_temperature") = 1,
54 py::arg("unit_qte") = 1,
55 py::arg("unit_lumint") = 1)
56 .def(
57 "get",
58 [](UnitSystem &self, std::string name, i32 power, std::string pref) {
60
61 return self.runtime_get(pref_, shamunits::units::unit_from_name(name), power);
62 },
63 // py::arg("self"),
64 py::arg("name"),
65 py::arg("power") = 1,
66 py::arg("pref") = "None")
67 .def(
68 "to",
69 [](UnitSystem &self, std::string name, i32 power, std::string pref) {
71
72 return self.runtime_to(pref_, shamunits::units::unit_from_name(name), power);
73 },
74 // py::arg("self"),
75 py::arg("name"),
76 py::arg("power") = 1,
77 py::arg("pref") = "None"
78
79 );
80
81 py::class_<shamunits::Constants<f64>>(m, "Constants")
82 .def(py::init([](UnitSystem s) {
83 return std::make_unique<shamunits::Constants<f64>>(s);
84 }))
87#define X(st, conv) \
88 .def( \
89 #st, \
90 [](shamunits::Constants<f64> &cte, i32 power) { \
91 return sycl::pown(cte.st(), power); \
92 }, \
93 py::arg("power") = 1)
97#undef X
99
100 ;
101}
#define UNITS_CONSTANTS
X macro to list all constants conversion & bindings.
Definition Constants.hpp:44
const UnitName unit_from_name(std::string p)
Get the UnitName enum value from a unit name as a string.
Definition Names.hpp:191
double f64
Alias for double.
std::int32_t i32
32 bit integer
Defines a unit system.
UnitPrefix
Enum of all prefixes.
Definition Names.hpp:89
const UnitPrefix unit_prefix_from_name(std::string p)
Get the UnitPrefix enum value from a prefix name as a string.
Definition Names.hpp:137
Pybind11 include and definitions.
#define ON_PYTHON_INIT
Register a Python module init function using static initialization.
#define X
Temp definition for the X macro call to define the log levels.
Definition logs.hpp:132
Physical constants.