Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
exemple.cpp
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
12#include <iostream>
13
14// g++ -std=c++17 -Iinclude exemple.cpp
15
16int main(void) {
17
18 using namespace shamunits;
19
20 // create si units
22
23 // get the value of au^2 in the unit system
24 // but it is quite big :)
25 std::cout << si.get<units::astronomical_unit, 2>() << std::endl;
26
27 double sol_mass = Constants<double>(si).sol_mass();
28
29 /*
30 * create a unit system with time in Myr, length in au, mass in solar masses
31 */
32 UnitSystem<double> astro_units{
33 si.get<mega, units::years>(),
34 si.get<units::astronomical_unit>(),
35 si.get<units::kilogram>() * sol_mass,
36 };
37
38 // this time it returns 1 because the base length is the astronomical unit
39 std::cout << astro_units.get<units::astronomical_unit, 2>() << std::endl;
40
41 Constants<double> astro_cte{astro_units};
42
43 // in those units G is 3.94781e+25
44 std::cout << astro_cte.G() << std::endl;
45}
Defines a unit system.
constexpr T get() const noexcept
get the value of a units in the current system
namespace containing the units library
Physical constants.
constexpr T sol_mass()
get the value of a sol_mass in the mass unit of the current unit system units
constexpr T G()
get the value of G in the current unit system units