DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Defines.hpp File Reference

Core type aliases, constants, and metaprogramming utilities for the DNDS framework. More...

#include "Macros.hpp"
#include "Errors.hpp"
#include "EigenPCH.hpp"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <vector>
#include <memory>
#include <tuple>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <type_traits>
#include <filesystem>
#include <functional>
#include <locale>
#include <csignal>
#include <cstdarg>
#include <cstdlib>
#include <fmt/core.h>
Include dependency graph for Defines.hpp:

Go to the source code of this file.

Classes

struct  DNDS::is_ssp< T >
 Type trait that detects whether a type is a std::shared_ptr wrapping. More...
 
struct  DNDS::is_ssp< ssp< T > >
 
class  DNDS::ObjectNaming
 Mixin base class providing a runtime instance name for tracing/debugging. More...
 
struct  DNDS::ObjName
 Tag type for naming objects created via make_ssp. More...
 
struct  DNDS::Meta::is_std_array< T >
 Type trait that detects whether a type is a std::array. More...
 
struct  DNDS::Meta::is_std_array< std::array< T, N > >
 
struct  DNDS::Meta::is_std_vector< T >
 Type trait that detects whether a type is a std::vector. More...
 
struct  DNDS::Meta::is_std_vector< std::vector< T, Allocator > >
 
struct  DNDS::Meta::is_fixed_data_real_eigen_matrix< T >
 see if the Actual valid data is in the struct scope (memcpy copyable) More...
 
struct  DNDS::Meta::is_fixed_data_real_eigen_matrix< Eigen::Matrix< T, M, N, options, max_m, max_n > >
 
struct  DNDS::Meta::is_real_eigen_matrix< T >
 Type trait that detects whether a type is an Eigen::Matrix with real scalar type. More...
 
struct  DNDS::Meta::is_real_eigen_matrix< Eigen::Matrix< real, M, N, options, max_m, max_n > >
 
struct  DNDS::Meta::has_std_hash< T, typename >
 Type trait that detects whether std::hash is specialized for a given type. More...
 
struct  DNDS::Meta::has_std_hash< T, std::void_t< decltype(std::hash< T >{}(std::declval< T >()))> >
 
struct  DNDS::vector_hash< T >
 Hash functor for std::vector<T>, combining element hashes via XOR. More...
 
struct  DNDS::array_hash< T, s >
 Hash functor for std::array<T, s>, combining element hashes via XOR. More...
 
struct  DNDS::Empty
 Trivially-copyable empty placeholder type that accepts any assignment. More...
 
struct  DNDS::EmptyNoDefault
 Empty placeholder type without a default constructor; accepts any assignment. More...
 

Namespaces

namespace  DNDS
 the host side operators are provided as implemented
 
namespace  DNDS::Meta
 
namespace  DNDS::TermColor
 

Macros

#define DNDS_FMT_ARG(V)   fmt::arg(#V, V)
 
#define DNDS_DEVICE_CALLABLE
 
#define DNDS_DEVICE
 
#define DNDS_HOST
 
#define DNDS_GLOBAL
 
#define DNDS_CONSTANT
 
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
 
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE_NO_EMPTY_CTOR(T, T_Self)
 
#define DNDS_INDEX_MAX   INT64_MAX
 
#define DNDS_INDEX_MIN   INT64_MIN
 
#define DNDS_ROWSIZE_MAX   INT32_MAX
 
#define DNDS_ROWSIZE_MIN   INT32_MIN
 
#define DNDS_E_PI   3.1415926535897932384626433832795028841971693993751058209749445923078164062
 
#define DNDS_MAKE_SSP(ssp, ...)   (ssp = std::make_shared<typename decltype(ssp)::element_type>(__VA_ARGS__))
 
#define DNDS_RESTRICT
 
#define DNDS_FORCEINLINE
 

Typedefs

using DNDS::real = double
 Canonical floating-point scalar used throughout DNDSR (double precision).
 
using DNDS::index = int64_t
 Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
 
using DNDS::rowsize = int32_t
 Row-width / per-row element-count type (signed 32-bit).
 
using DNDS::real_sized_index = int64_t
 Integer type with the same width as real (used for type-punning / packing).
 
using DNDS::real_half_sized_index = int32_t
 Integer type with half the width of real.
 
template<typename T >
using DNDS::ssp = std::shared_ptr< T >
 Shortened alias for std::shared_ptr used pervasively in DNDSR.
 
template<typename T >
using DNDS::remove_cvref_t = std::remove_cv_t< std::remove_reference_t< T > >
 Convenience remove_cv + remove_reference composition (C++17 port of C++20's std::remove_cvref_t).
 
using DNDS::t_RowsizeVec = std::vector< rowsize >
 Vector of row widths (one rowsize per row).
 
using DNDS::t_IndexVec = std::vector< index >
 Vector of index values (global offsets, local ids, etc.).
 
using DNDS::t_pIndexVec = ssp< t_IndexVec >
 Shared pointer alias to t_IndexVec (used by mapping tables shared between arrays, see IndexMapping.hpp).
 
using DNDS::t_indexerPair = std::tuple< index, index >
 Paired indices, typically (start, size) or (first, last).
 
using DNDS::tDiFj = Eigen::Matrix< real, -1, -1, Eigen::RowMajor >
 Row-major dynamic Eigen matrix used by quadrature / basis tables.
 
using DNDS::MatrixXR = Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic >
 Column-major dynamic Eigen matrix of reals (default layout).
 
using DNDS::VectorXR = Eigen::Vector< real, Eigen::Dynamic >
 Dynamic Eigen vector of reals.
 
using DNDS::RowVectorXR = Eigen::RowVector< real, Eigen::Dynamic >
 Dynamic row-vector of reals.
 

Functions

void DNDS_signal_handler (int signal)
 
void DNDS::RegisterSignalHandler ()
 Install SEGV / ABRT handlers that print a backtrace via DNDS_signal_handler.
 
std::pair< index, indexDNDS::EvenSplitRange (int rank, int nRanks, index nGlobal)
 Split a global range [0, nGlobal) evenly among nRanks workers.
 
bool DNDS::IsUnInitReal (real v)
 Whether v equals the NaN sentinel UnInitReal (tested via isnan).
 
template<typename T , typename... Args>
ssp< T > DNDS::make_ssp (Args &&...args)
 Type-safe replacement for DNDS_MAKE_SSP. Creates ssp<T> with forwarded args.
 
template<typename T , typename... Args>
ssp< T > DNDS::make_ssp (ObjName objName, Args &&...args)
 Named variant of make_ssp. If T inherits ObjectNaming, sets the name.
 
constexpr int DNDS::RowSize_To_EigenSize (rowsize rs)
 Convert a rowsize constant to the corresponding Eigen compile-time size. Fixed >= 0 -> the value; DynamicSize / NonUniformSize -> Eigen::Dynamic.
 
std::string DNDS::RowSize_To_PySnippet (rowsize rs)
 Encode a rowsize constant as a short Python-binding snippet: "<number>" for fixed, "D" for DynamicSize, "I" for NonUniformSize. Used when generating pybind11 class names.
 
std::string DNDS::Align_To_PySnippet (rowsize al)
 Encode an alignment value as a Python-binding snippet: "N" for NoAlign, the number otherwise.
 
std::ostream & DNDS::log ()
 Return the current DNDSR log stream (either std::cout or the installed file).
 
bool DNDS::ostreamIsTTY (std::ostream &ostream)
 Heuristic detection of whether ostream is attached to a terminal.
 
bool DNDS::logIsTTY ()
 Convenience: ostreamIsTTY applied to the current log() stream.
 
void DNDS::setLogStream (ssp< std::ostream > nstream)
 Redirect log() output to a user-supplied stream. Ownership is shared.
 
void DNDS::setLogStreamCout ()
 Restore the default std::cout routing for log().
 
int DNDS::get_terminal_width ()
 Terminal width in columns (falls back to a fixed default when not a TTY).
 
void DNDS::print_progress (std::ostream &os, double progress)
 Render a textual progress bar to os for progress in [0, 1].
 
int DNDS::get_env_OMP_NUM_THREADS ()
 Read OMP_NUM_THREADS env var, returning 1 if unset / invalid.
 
int DNDS::get_env_DNDS_DIST_OMP_NUM_THREADS ()
 Read the DNDSR-specific DNDS_DIST_OMP_NUM_THREADS override, falling back to get_env_OMP_NUM_THREADS.
 
template<typename T >
bool DNDS::signedIntWillAddOverflow (T value, T increment)
 Overflow-detecting test for value + increment on signed integers.
 
template<typename T >
DNDS::signedIntSafeAdd (T value, T increment)
 Add two signed integers, asserting on overflow instead of silently wrapping.
 
template<typename T >
DNDS::size_t_to_signed (size_t v)
 Narrowing size_t -> T conversion with range check.
 
index DNDS::size_to_index (size_t v)
 Range-checked conversion from size_t to DNDS::index.
 
rowsize DNDS::size_to_rowsize (size_t v)
 Range-checked conversion from size_t to DNDS::rowsize.
 
template<class TtRowsizeVec , class TtIndexVec >
void DNDS::AccumulateRowSize (const TtRowsizeVec &rowsizes, TtIndexVec &rowstarts)
 Build a prefix-sum table from a row-size vector.
 
template<class T >
bool DNDS::checkUniformVector (const std::vector< T > &dat, T &value)
 Whether all elements of dat are equal; if so, stores the value into value.
 
template<class T , class TP = T>
void DNDS::PrintVec (const std::vector< T > &dat, std::ostream &out)
 Print a vector to out with outputDelim between elements.
 
template<class TL , class TR >
constexpr auto DNDS::divCeil (TL l, TR r)
 Integer ceiling division. l must be non-negative, r positive.
 
template<typename T >
constexpr T DNDS::sqr (const T &a)
 a * a, constexpr. Works for all arithmetic types.
 
template<typename T >
constexpr T DNDS::cube (const T &a)
 a * a * a, constexpr.
 
constexpr real DNDS::sign (real a)
 Signum function: +1, 0, or -1.
 
constexpr real DNDS::signTol (real a, real tol)
 Tolerant signum: returns 0 inside [-tol, tol].
 
constexpr real DNDS::signP (real a)
 "Signum, biased toward +1": treats 0 as positive.
 
constexpr real DNDS::signM (real a)
 "Signum, biased toward -1": treats 0 as negative.
 
template<typename T >
constexpr T DNDS::mod (T a, T b)
 Mathematical modulo that always returns a non-negative result. Unlike % in C++ where (-1) % 3 == -1, mod(-1, 3) == 2.
 
template<typename T >
constexpr T DNDS::divide_ceil (T a, T b)
 Integer ceiling division ceil(a / b). Correct for all signs.
 
real DNDS::float_mod (real a, real b)
 Floating-point modulo matching Python's % (result has sign of b).
 
template<class tIt1 , class tIt1end , class tIt2 , class tIt2end , class tF >
bool DNDS::iterateIdentical (tIt1 it1, tIt1end it1end, tIt2 it2, tIt2end it2end, tF F)
 Walk two ordered ranges in lockstep, calling F on each match.
 
int32_t DNDS::checkedIndexTo32 (index v)
 Narrow index to int32_t with range check; dies on overflow.
 
std::string DNDS::getStringForceWString (const std::wstring &v)
 Convert a wstring to string (UTF-8 on Windows, byte-cast elsewhere).
 
std::string DNDS::getStringForcePath (const std::filesystem::path::string_type &v)
 Portable conversion of a platform-native path string to std::string.
 
std::vector< std::string > DNDS::splitSString (const std::string &str, char delim)
 
std::vector< std::string > DNDS::splitSStringClean (const std::string &str, char delim)
 
bool DNDS::sstringHasSuffix (const std::string &str, const std::string &suffix)
 
std::string DNDS::GetSetVersionName (const std::string &ver="")
 Read/set the build version string accessible from code.
 

Variables

template<typename T >
constexpr bool DNDS::is_ssp_v = is_ssp<T>::value
 
DNDS_CONSTANT const index DNDS::indexMin = INT64_MIN
 Minimum representable index value (= INT64_MIN).
 
DNDS_CONSTANT const real DNDS::UnInitReal = NAN
 Sentinel "not initialised" real value (NaN). Cheap to detect with std::isnan or IsUnInitReal; survives MPI transport unchanged.
 
DNDS_CONSTANT const index DNDS::UnInitIndex = INT64_MIN
 Sentinel "not initialised" index value (= INT64_MIN).
 
DNDS_CONSTANT const rowsize DNDS::UnInitRowsize = INT32_MIN
 Sentinel "not initialised" rowsize value (= INT32_MIN).
 
DNDS_CONSTANT const real DNDS::veryLargeReal = 3e200
 Catch-all upper bound ("practically infinity") for physical scalars.
 
DNDS_CONSTANT const real DNDS::largeReal = 3e10
 Loose upper bound (e.g., for non-dimensional limits).
 
DNDS_CONSTANT const real DNDS::verySmallReal = 1e-200
 Catch-all lower bound ("effectively zero").
 
DNDS_CONSTANT const real DNDS::smallReal = 1e-10
 Loose lower bound (for iterative-solver tolerances etc.).
 
DNDS_CONSTANT const real DNDS::pi = DNDS_E_PI
 π in double precision (matches DNDS_E_PI macro).
 
DNDS_CONSTANT const rowsize DNDS::DynamicSize = -1
 Template parameter flag: "row width is set at runtime but uniform".
 
DNDS_CONSTANT const rowsize DNDS::NonUniformSize = -2
 Template parameter flag: "each row has an independent width".
 
DNDS_CONSTANT const rowsize DNDS::NoAlign = -1024
 Alignment flag: no padding applied to rows (the only currently-supported value).
 
template<typename T >
constexpr bool DNDS::Meta::always_false = false
 
template<typename _Tp >
constexpr bool DNDS::Meta::is_std_array_v = is_std_array<_Tp>::value
 
template<typename _Tp >
constexpr bool DNDS::Meta::is_fixed_data_real_eigen_matrix_v = is_fixed_data_real_eigen_matrix<_Tp>::value
 
template<typename T >
constexpr bool DNDS::Meta::is_eigen_dense_v = std::is_base_of_v<Eigen::DenseBase<T>, T>
 
template<class T >
constexpr bool DNDS::Meta::is_real_eigen_matrix_v = is_real_eigen_matrix<T>::value
 
constexpr std::string_view DNDS::TermColor::Red = "\033[91m"
 ANSI escape: bright red foreground.
 
constexpr std::string_view DNDS::TermColor::Green = "\033[92m"
 ANSI escape: bright green foreground.
 
constexpr std::string_view DNDS::TermColor::Yellow = "\033[93m"
 ANSI escape: bright yellow foreground.
 
constexpr std::string_view DNDS::TermColor::Blue = "\033[94m"
 ANSI escape: bright blue foreground.
 
constexpr std::string_view DNDS::TermColor::Magenta = "\033[95m"
 ANSI escape: bright magenta foreground.
 
constexpr std::string_view DNDS::TermColor::Cyan = "\033[96m"
 ANSI escape: bright cyan foreground.
 
constexpr std::string_view DNDS::TermColor::White = "\033[97m"
 ANSI escape: bright white foreground.
 
constexpr std::string_view DNDS::TermColor::Reset = "\033[0m"
 ANSI escape: reset all attributes.
 
constexpr std::string_view DNDS::TermColor::Bold = "\033[1m"
 ANSI escape: bold.
 
constexpr std::string_view DNDS::TermColor::Underline = "\033[4m"
 ANSI escape: underline.
 
constexpr std::string_view DNDS::TermColor::Blink = "\033[5m"
 ANSI escape: blinking text.
 
constexpr std::string_view DNDS::TermColor::Reverse = "\033[7m"
 ANSI escape: reverse (swap fg/bg).
 
constexpr std::string_view DNDS::TermColor::Hidden = "\033[8m"
 ANSI escape: hidden text.
 

Detailed Description

Core type aliases, constants, and metaprogramming utilities for the DNDS framework.

Definition in file Defines.hpp.

Macro Definition Documentation

◆ DNDS_CONSTANT

#define DNDS_CONSTANT

Definition at line 80 of file Defines.hpp.

◆ DNDS_DEVICE

#define DNDS_DEVICE

Definition at line 77 of file Defines.hpp.

◆ DNDS_DEVICE_CALLABLE

#define DNDS_DEVICE_CALLABLE

Definition at line 76 of file Defines.hpp.

◆ DNDS_DEVICE_TRIVIAL_COPY_DEFINE

#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE (   T,
  T_Self 
)
Value:
DNDS_DEVICE_CALLABLE T() = default; \
DNDS_DEVICE_CALLABLE T(const T_Self &) = default; \
DNDS_DEVICE_CALLABLE T(T_Self &&) = default; \
DNDS_DEVICE_CALLABLE T &operator=(const T_Self &) = default; \
DNDS_DEVICE_CALLABLE T &operator=(T_Self &&) = default; \
DNDS_DEVICE_CALLABLE ~T() = default;
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76

Definition at line 83 of file Defines.hpp.

◆ DNDS_DEVICE_TRIVIAL_COPY_DEFINE_NO_EMPTY_CTOR

#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE_NO_EMPTY_CTOR (   T,
  T_Self 
)
Value:
DNDS_DEVICE_CALLABLE T(const T_Self &) = default; \
DNDS_DEVICE_CALLABLE T(T_Self &&) = default; \
DNDS_DEVICE_CALLABLE T &operator=(const T_Self &) = default; \
DNDS_DEVICE_CALLABLE T &operator=(T_Self &&) = default; \
DNDS_DEVICE_CALLABLE ~T() = default;

Definition at line 91 of file Defines.hpp.

◆ DNDS_E_PI

#define DNDS_E_PI   3.1415926535897932384626433832795028841971693993751058209749445923078164062

Definition at line 197 of file Defines.hpp.

◆ DNDS_FMT_ARG

#define DNDS_FMT_ARG (   V)    fmt::arg(#V, V)

Definition at line 43 of file Defines.hpp.

◆ DNDS_FORCEINLINE

#define DNDS_FORCEINLINE

Definition at line 978 of file Defines.hpp.

◆ DNDS_GLOBAL

#define DNDS_GLOBAL

Definition at line 79 of file Defines.hpp.

◆ DNDS_HOST

#define DNDS_HOST

Definition at line 78 of file Defines.hpp.

◆ DNDS_INDEX_MAX

#define DNDS_INDEX_MAX   INT64_MAX

Definition at line 116 of file Defines.hpp.

◆ DNDS_INDEX_MIN

#define DNDS_INDEX_MIN   INT64_MIN

Definition at line 117 of file Defines.hpp.

◆ DNDS_MAKE_SSP

#define DNDS_MAKE_SSP (   ssp,
  ... 
)    (ssp = std::make_shared<typename decltype(ssp)::element_type>(__VA_ARGS__))
Deprecated:
Use make_ssp<T>() or make_ssp<T>(ObjName{...}, ...) instead.

Definition at line 212 of file Defines.hpp.

◆ DNDS_RESTRICT

#define DNDS_RESTRICT

Definition at line 977 of file Defines.hpp.

◆ DNDS_ROWSIZE_MAX

#define DNDS_ROWSIZE_MAX   INT32_MAX

Definition at line 118 of file Defines.hpp.

◆ DNDS_ROWSIZE_MIN

#define DNDS_ROWSIZE_MIN   INT32_MIN

Definition at line 119 of file Defines.hpp.

Function Documentation

◆ DNDS_signal_handler()

void DNDS_signal_handler ( int  signal)

Definition at line 26 of file Defines.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: