CDT++
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Enumerations | Functions
Utilities.hpp File Reference

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.
 

Detailed Description

Utility functions.

Author
Adam Getchell

Definition in file Utilities.hpp.

Enumeration Type Documentation

◆ topology_type

enum class topology_type
strong

clang-15 does not support std::format

Definition at line 42 of file Utilities.hpp.

Function Documentation

◆ create_logger()

void utilities::create_logger ( )
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:

  1. Console, which logs Info and below to the terminal
  2. Debug, which logs Debug and below to logs/debug-log.txt
  3. Trace, which logs everything to logs/trace-log.txt

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().

◆ current_date_time()

auto utilities::current_date_time ( )
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.

Returns
A formatted string with the system local time
See also
https://github.com/HowardHinnant/date
https://en.cppreference.com/w/cpp/chrono/zoned_time

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().

◆ die_roll()

auto utilities::die_roll ( )
inlinenoexcept

Roll a die with PCG.

Definition at line 216 of file Utilities.hpp.

References utilities::die_roll().

Referenced by utilities::die_roll().

◆ expected_points_per_timeslice()

auto utilities::expected_points_per_timeslice ( Int_precision const  t_dimension,
Int_precision  t_number_of_simplices,
Int_precision  t_number_of_timeslices 
)
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

Parameters
t_dimensionNumber of dimensions
t_number_of_simplicesNumber of desired simplices
t_number_of_timeslicesNumber of desired timeslices
Returns
The number of points per timeslice to obtain the desired number of simplices

Definition at line 313 of file Utilities.hpp.

References utilities::expected_points_per_timeslice().

Referenced by utilities::expected_points_per_timeslice().

◆ generate_probability()

auto constexpr utilities::generate_probability ( )
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().

◆ generate_random()

template<typename NumberType , class Distribution >
auto utilities::generate_random ( NumberType  t_min_value,
NumberType  t_max_value 
)
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

Template Parameters
NumberTypeThe type of number in the RNG
DistributionThe distribution type, usually uniform
Parameters
t_min_valueThe minimum value
t_max_valueThe maximum value
Returns
A random value in the distribution between min_value and max_value

Definition at line 243 of file Utilities.hpp.

References utilities::generate_random().

Referenced by utilities::generate_random().

◆ generate_random_int()

template<typename IntegerType >
auto constexpr utilities::generate_random_int ( IntegerType  t_min_value,
IntegerType  t_max_value 
)
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().

◆ generate_random_real()

template<typename FloatingPointType >
auto constexpr utilities::generate_random_real ( FloatingPointType  t_min_value,
FloatingPointType  t_max_value 
)
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().

◆ generate_random_timeslice()

template<typename IntegerType >
auto utilities::generate_random_timeslice ( IntegerType &&  t_max_timeslice) -> decltype(auto)
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().

◆ Gmpzf_to_double()

auto utilities::Gmpzf_to_double ( Gmpzf const &  t_value) -> double
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.

Parameters
t_valueAn exact Gmpzf multiple-precision floating point number
Returns
The double conversion

Definition at line 365 of file Utilities.hpp.

References utilities::Gmpzf_to_double().

Referenced by utilities::Gmpzf_to_double().

◆ make_filename() [1/2]

template<typename ManifoldType >
auto utilities::make_filename ( ManifoldType const &  manifold)

Definition at line 131 of file Utilities.hpp.

◆ make_filename() [2/2]

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 
) -> std::filesystem::path
inlinenoexcept

Generate useful filenames.

Parameters
t_topologyThe topology type from the scoped enum topology_type
t_dimensionThe dimensionality of the triangulation
t_number_of_simplicesThe number of simplices in the triangulation
t_number_of_timeslicesThe number of time foliations
t_initial_radiusThe radius of the first foliation t=1
t_foliation_spacingThe spacing between foliations
Returns
A filename

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().

◆ make_random_generator()

auto utilities::make_random_generator ( )
inlinenoexcept

Make a high-quality random number generator usable by std::shuffle.

Returns
A RNG

Definition at line 255 of file Utilities.hpp.

References utilities::make_random_generator().

Referenced by utilities::make_random_generator().

◆ operator<<()

auto operator<< ( std::ostream &  t_os,
topology_type const &  t_topology 
) -> std::ostream&
inline

Convert topology_type to string output.

Parameters
t_osThe output stream
t_topologyThe topology
Returns
An output string of the topology

Definition at line 52 of file Utilities.hpp.

◆ point_to_str()

template<typename Point >
auto utilities::point_to_str ( Point const &  t_point) -> std::string

Covert a CGAL point to a string.

Template Parameters
PointThe type of point (e.g. 3D, 4D)
Parameters
t_pointThe point
Returns
A string representation of the point

Definition at line 439 of file Utilities.hpp.

References utilities::point_to_str().

Referenced by utilities::point_to_str().

◆ print_delaunay()

template<typename TriangulationType >
void utilities::print_delaunay ( TriangulationType const &  t_triangulation)

Print triangulation statistics.

Template Parameters
TriangulationTypeThe triangulation type
Parameters
t_triangulationA triangulation (typically a Delaunay_t<3> triangulation)

Definition at line 144 of file Utilities.hpp.

References utilities::print_delaunay().

Referenced by utilities::print_delaunay().

◆ read_file()

template<typename TriangulationType >
auto utilities::read_file ( std::filesystem::path const &  filename) -> TriangulationType

Read triangulation from file.

Template Parameters
TriangulationTypeThe type of triangulation
Parameters
filenameThe file to read from
Returns
A Delaunay triangulation

Definition at line 198 of file Utilities.hpp.

References utilities::read_file().

Referenced by utilities::read_file().

◆ topology_to_str()

auto utilities::topology_to_str ( topology_type const &  t_topology) -> std::string
inline

Convert a topology to a string using it's << operator.

Parameters
t_topologyThe topology_type to convert
Returns
A string representation of the topology_type

Definition at line 449 of file Utilities.hpp.

References utilities::topology_to_str().

Referenced by utilities::topology_to_str().

◆ write_file() [1/2]

template<typename ManifoldType >
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.

Template Parameters
ManifoldTypeThe manifold type
Parameters
t_universeThe simplicial manifold

Definition at line 186 of file Utilities.hpp.

References utilities::make_filename(), and utilities::write_file().

◆ write_file() [2/2]

template<typename TriangulationType >
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.

Template Parameters
TriangulationTypeThe type of triangulation
Parameters
filenameThe filename to write to
triangulationThe triangulation to write

Definition at line 163 of file Utilities.hpp.

References utilities::write_file().

Referenced by utilities::write_file().