|
CDT++
Causal Dynamical Triangulations in C++
|
Utility functions. More...
#include <filesystem>#include <fstream>#include <gsl/gsl>#include <mutex>#include <random>#include <span>#include <stdexcept>#include <string>#include <date/tz.h>#include "pcg_random.hpp"#include <fmt/ostream.h>#include <spdlog/sinks/basic_file_sink.h>#include <spdlog/sinks/stdout_color_sinks.h>#include <spdlog/spdlog.h>#include "Settings.hpp"
Include dependency graph for Utilities.hpp:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Enumerations | |
| enum class | topology_type { TOROIDAL , SPHERICAL } |
| clang-15 does not support std::format More... | |
Functions | |
| void | utilities::create_logger () |
| Create console and file loggers. | |
| auto | utilities::current_date_time () |
| Return current date and time. | |
| auto | utilities::die_roll () noexcept |
| Roll a die with PCG. | |
| auto | utilities::expected_points_per_timeslice (Int_precision const t_dimension, Int_precision t_number_of_simplices, Int_precision t_number_of_timeslices) |
| Calculate expected # of points per simplex. | |
| auto constexpr | utilities::generate_probability () noexcept |
| Generate a probability. | |
| template<typename NumberType , class Distribution > | |
| auto | utilities::generate_random (NumberType t_min_value, NumberType t_max_value) noexcept |
| Generate random numbers. | |
| template<typename IntegerType > | |
| auto constexpr | utilities::generate_random_int (IntegerType t_min_value, IntegerType t_max_value) noexcept |
| Generate random integers by calling generate_random, preserves template argument deduction. | |
| template<typename FloatingPointType > | |
| auto constexpr | utilities::generate_random_real (FloatingPointType t_min_value, FloatingPointType t_max_value) noexcept |
| Generate random real numbers by calling generate_random, preserves template argument deduction. | |
| template<typename IntegerType > | |
| auto | utilities::generate_random_timeslice (IntegerType &&t_max_timeslice) noexcept -> decltype(auto) |
| Generate a random timeslice. | |
| auto | utilities::Gmpzf_to_double (Gmpzf const &t_value) -> double |
| Convert Gmpzf into a double. | |
| template<typename ManifoldType > | |
| auto | utilities::make_filename (ManifoldType const &manifold) |
| auto | utilities::make_filename (topology_type const &t_topology, Int_precision t_dimension, Int_precision t_number_of_simplices, Int_precision t_number_of_timeslices, double t_initial_radius, double t_foliation_spacing) noexcept -> std::filesystem::path |
| Generate useful filenames. | |
| auto | utilities::make_random_generator () noexcept |
| Make a high-quality random number generator usable by std::shuffle. | |
| auto | operator<< (std::ostream &t_os, topology_type const &t_topology) -> std::ostream & |
| Convert topology_type to string output. | |
| template<typename Point > | |
| auto | utilities::point_to_str (Point const &t_point) -> std::string |
| Covert a CGAL point to a string. | |
| template<typename TriangulationType > | |
| void | utilities::print_delaunay (TriangulationType const &t_triangulation) |
| Print triangulation statistics. | |
| template<typename TriangulationType > | |
| auto | utilities::read_file (std::filesystem::path const &filename) -> TriangulationType |
| Read triangulation from file. | |
| auto | utilities::topology_to_str (topology_type const &t_topology) -> std::string |
| Convert a topology to a string using it's << operator. | |
| template<typename ManifoldType > | |
| void | utilities::write_file (ManifoldType const &t_universe) |
| Write the runtime results to a file. | |
| template<typename TriangulationType > | |
| void | utilities::write_file (std::filesystem::path const &filename, TriangulationType triangulation) |
| Write triangulation to file. | |
Utility functions.
Definition in file Utilities.hpp.
|
strong |
clang-15 does not support std::format
Definition at line 42 of file Utilities.hpp.
|
inline |
Create console and file loggers.
Create a console and file loggers. There are six logging levels by default:
| Logging level | Description |
|---|---|
| Trace | Used to trace the internals |
| Debug | Diagnostic information |
| Info | General information |
| Warn | Errors that are handled |
| Err | Errors which cause a function to fail |
| Critical | Errors which cause the program to fail |
A logging level covers all levels beneath it, e.g. trace covers everything, critical only shows up in spdlog::level::critical.
Logging levels and formatting are set by loggers. The sink is the object that writes the log to the target.
So, this function creates 3 sinks:
If an exception is thrown, then the default global console logger is used.
Definition at line 394 of file Utilities.hpp.
References utilities::create_logger().
Referenced by utilities::create_logger().
|
inline |
Return current date and time.
Return current date and time in ISO 8601 format Use Howard Hinnant C++11/14 data and time library and Time Zone Database Parser. std::chrono::zoned_time would be a replacement if supported by current compilers.
When AppleClang fully supports std::chrono and std::format, use this:
Definition at line 73 of file Utilities.hpp.
References utilities::current_date_time().
Referenced by utilities::current_date_time(), and utilities::make_filename().
|
inlinenoexcept |
Roll a die with PCG.
Definition at line 216 of file Utilities.hpp.
References utilities::die_roll().
Referenced by utilities::die_roll().
|
inline |
Calculate expected # of points per simplex.
Usually, there are less vertices than simplices. Here, we throw away a number of simplices that aren't correctly foliated. The exact formula is given by Dwyer: http://link.springer.com/article/10.1007/BF02574694
| t_dimension | Number of dimensions |
| t_number_of_simplices | Number of desired simplices |
| t_number_of_timeslices | Number of desired timeslices |
Definition at line 313 of file Utilities.hpp.
References utilities::expected_points_per_timeslice().
Referenced by utilities::expected_points_per_timeslice().
|
constexprnoexcept |
Generate a probability.
Definition at line 293 of file Utilities.hpp.
References utilities::generate_probability(), and utilities::generate_random_real().
Referenced by utilities::generate_probability().
|
noexcept |
Generate random numbers.
Uses Melissa E. O'Neill's Permuted Congruential Generator for high-quality RNG which passes the TestU01 statistical tests. See: http://www.pcg-random.org/paper.html for more details
| NumberType | The type of number in the RNG |
| Distribution | The distribution type, usually uniform |
| t_min_value | The minimum value |
| t_max_value | The maximum value |
Definition at line 243 of file Utilities.hpp.
References utilities::generate_random().
Referenced by utilities::generate_random().
|
constexprnoexcept |
Generate random integers by calling generate_random, preserves template argument deduction.
Definition at line 265 of file Utilities.hpp.
References utilities::generate_random_int().
Referenced by utilities::generate_random_int(), and utilities::generate_random_timeslice().
|
constexprnoexcept |
Generate random real numbers by calling generate_random, preserves template argument deduction.
Definition at line 284 of file Utilities.hpp.
References utilities::generate_random_real().
Referenced by utilities::generate_probability(), and utilities::generate_random_real().
|
noexcept |
Generate a random timeslice.
Definition at line 274 of file Utilities.hpp.
References utilities::generate_random_int(), and utilities::generate_random_timeslice().
Referenced by utilities::generate_random_timeslice().
|
inline |
Convert Gmpzf into a double.
This function is mainly for testing, since to_double() seems to work. However, if something more elaborate is required this function can be expanded.
| t_value | An exact Gmpzf multiple-precision floating point number |
Definition at line 365 of file Utilities.hpp.
References utilities::Gmpzf_to_double().
Referenced by utilities::Gmpzf_to_double().
| auto utilities::make_filename | ( | ManifoldType const & | manifold | ) |
Definition at line 131 of file Utilities.hpp.
|
inlinenoexcept |
Generate useful filenames.
| t_topology | The topology type from the scoped enum topology_type |
| t_dimension | The dimensionality of the triangulation |
| t_number_of_simplices | The number of simplices in the triangulation |
| t_number_of_timeslices | The number of time foliations |
| t_initial_radius | The radius of the first foliation t=1 |
| t_foliation_spacing | The spacing between foliations |
Definition at line 93 of file Utilities.hpp.
References utilities::current_date_time(), and utilities::make_filename().
Referenced by utilities::make_filename(), and utilities::write_file().
|
inlinenoexcept |
Make a high-quality random number generator usable by std::shuffle.
Definition at line 255 of file Utilities.hpp.
References utilities::make_random_generator().
Referenced by utilities::make_random_generator().
|
inline |
Convert topology_type to string output.
| t_os | The output stream |
| t_topology | The topology |
Definition at line 52 of file Utilities.hpp.
| auto utilities::point_to_str | ( | Point const & | t_point | ) | -> std::string |
Covert a CGAL point to a string.
| t_point | The point |
Definition at line 439 of file Utilities.hpp.
References utilities::point_to_str().
Referenced by utilities::point_to_str().
| void utilities::print_delaunay | ( | TriangulationType const & | t_triangulation | ) |
Print triangulation statistics.
| TriangulationType | The triangulation type |
| t_triangulation | A triangulation (typically a Delaunay_t<3> triangulation) |
Definition at line 144 of file Utilities.hpp.
References utilities::print_delaunay().
Referenced by utilities::print_delaunay().
| auto utilities::read_file | ( | std::filesystem::path const & | filename | ) | -> TriangulationType |
Read triangulation from file.
| TriangulationType | The type of triangulation |
| filename | The file to read from |
Definition at line 198 of file Utilities.hpp.
References utilities::read_file().
Referenced by utilities::read_file().
|
inline |
Convert a topology to a string using it's << operator.
| t_topology | The topology_type to convert |
Definition at line 449 of file Utilities.hpp.
References utilities::topology_to_str().
Referenced by utilities::topology_to_str().
| void utilities::write_file | ( | ManifoldType const & | t_universe | ) |
Write the runtime results to a file.
The filename is generated by the make_filename() and writen using another write_file() function, which is currently implemented using the << operator for triangulations.
| ManifoldType | The manifold type |
| t_universe | The simplicial manifold |
Definition at line 186 of file Utilities.hpp.
References utilities::make_filename(), and utilities::write_file().
| void utilities::write_file | ( | std::filesystem::path const & | filename, |
| TriangulationType | triangulation | ||
| ) |
Write triangulation to file.
This function writes the Delaunay triangulation in the manifold to an OFF file. http://www.geomview.org/docs/html/OFF.html#OFF Provides strong exception-safety.
| TriangulationType | The type of triangulation |
| filename | The filename to write to |
| triangulation | The triangulation to write |
Definition at line 163 of file Utilities.hpp.
References utilities::write_file().
Referenced by utilities::write_file().