Loading...
Searching...
No Matches
terra::util Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  Ok
 
class  Result
 
class  Table
 Table class for storing and manipulating tabular data. More...
 
class  Timer
 Timer supporting RAII scope or manual stop. More...
 
class  TimerNode
 Node representing a timed region in the hierarchy. More...
 
class  TimerTree
 Singleton tree managing all timer nodes per MPI rank. More...
 
class  XML
 

Concepts

concept  FlagLike
 Concept for types that behave like bitmask flags.
 

Functions

template<FlagLike E>
constexpr E operator| (E a, E b)
 
template<FlagLike E>
constexpr E operator& (E a, E b)
 
template<FlagLike E>
constexpr bool has_flag (E mask_value, E flag) noexcept
 Checks if a bitmask value contains a specific flag.
 
CLI::Option * add_option_with_default (CLI::App &app, const std::string &name, auto &field, std::string desc="")
 Just a small wrapper to set the default of the option to the value of the variable where it shall be stored.
 
CLI::Option * add_flag_with_default (CLI::App &app, const std::string &name, bool &field, std::string desc="")
 Just a small wrapper to set the default of the flag to the value of the variable where it shall be stored.
 
void print_cli_summary (const CLI::App &app, std::ostream &os=std::cout)
 Prints an overview of the available flags, the passed arguments, defaults, etc.
 
bool prepare_empty_directory (const std::string &path_str, bool root_only=true)
 Prepares an empty directory with the passed path.
 
void prepare_empty_directory_or_abort (const std::string &path_str, bool root_only=true)
 Like prepare_empty_directory() but aborts if empty directory could not be prepared successfully.
 
void print_general_info (int argc, char **argv, std::ostream &out=logroot)
 Prints some general information for this run to out.
 
void terra_initialize (int *argc, char ***argv)
 RAII approach to safely initialize MPI and Kokkos.
 
double interpolate_linear_1D (const double pos_a, const double pos_b, const double val_a, const double val_b, const double pos, const bool clamp)
 Computes the linearly interpolated value at a specified point using two surrounding data points.
 
Result< Tableread_table_from_csv (const std::string &filename)
 Attempts to read a csv file and converts that into a Table instance.
 
std::string current_timestamp ()
 Get the current timestamp as a string.
 

Variables

detail::PrefixCout logroot ([]() { return detail::log_prefix();})
 std::ostream subclass that just logs on root and adds a timestamp for each line.
 
detail::PrefixCout logall ([]() { return detail::log_prefix();}, false)
 std::ostream subclass that just logs on any process and adds a timestamp for each line.
 

Function Documentation

◆ add_flag_with_default()

CLI::Option * terra::util::add_flag_with_default ( CLI::App &  app,
const std::string &  name,
bool &  field,
std::string  desc = "" 
)
inline

Just a small wrapper to set the default of the flag to the value of the variable where it shall be stored.

Equivalent to

app.add_flag( name, field, std::move( desc ) )->default_val( field );

but with this you do not have to pass 'field' twice :)

◆ add_option_with_default()

CLI::Option * terra::util::add_option_with_default ( CLI::App &  app,
const std::string &  name,
auto &  field,
std::string  desc = "" 
)

Just a small wrapper to set the default of the option to the value of the variable where it shall be stored.

Equivalent to

app.add_option( name, field, std::move( desc ) )->default_val( field );

but with this you do not have to pass 'field' twice :)

◆ current_timestamp()

std::string terra::util::current_timestamp ( )
inline

Get the current timestamp as a string.

Returns
Timestamp string.

◆ has_flag()

template<FlagLike E>
constexpr bool terra::util::has_flag ( mask_value,
flag 
)
constexprnoexcept

Checks if a bitmask value contains a specific flag.

This function checks if the bitmask value mask_value has the flag flag set. If flag is E::NO_FLAG, it checks if mask_value is exactly E::NO_FLAG.

Template Parameters
EThe enum type representing the bitmask.
Parameters
mask_valueThe bitmask value to check.
flagThe flag to check for in mask_value.
Returns
true if mask_value contains flag or whether mask_value == flag if flag == E::NO_FLAG, otherwise false.

◆ interpolate_linear_1D()

double terra::util::interpolate_linear_1D ( const double  pos_a,
const double  pos_b,
const double  val_a,
const double  val_b,
const double  pos,
const bool  clamp 
)

Computes the linearly interpolated value at a specified point using two surrounding data points.

Parameters
pos_acoordinate of the first data point
pos_bcoordinate of the first data point
val_avalue at pos_a
val_bvalue at pos_b
poswhere to evaluate
clampif true, clamps to [val_a, val_b]
Returns
The interpolated value at the specified x-coordinate.

◆ operator&()

template<FlagLike E>
constexpr E terra::util::operator& ( a,
b 
)
constexpr

◆ operator|()

template<FlagLike E>
constexpr E terra::util::operator| ( a,
b 
)
constexpr

◆ prepare_empty_directory()

bool terra::util::prepare_empty_directory ( const std::string &  path_str,
bool  root_only = true 
)
inline

Prepares an empty directory with the passed path.

If the directory does not exist: will create a directory

  • if possible => returns true
  • if creation fails => returns false If the directory does exist and is empty: will do nothing => returns true If the directory does exist and is not empty: will do nothing => returns false

Returns true for all non-zero ranks if root_only == true.

◆ prepare_empty_directory_or_abort()

void terra::util::prepare_empty_directory_or_abort ( const std::string &  path_str,
bool  root_only = true 
)
inline

Like prepare_empty_directory() but aborts if empty directory could not be prepared successfully.

◆ print_cli_summary()

void terra::util::print_cli_summary ( const CLI::App &  app,
std::ostream &  os = std::cout 
)
inline

Prints an overview of the available flags, the passed arguments, defaults, etc.

◆ print_general_info()

void terra::util::print_general_info ( int  argc,
char **  argv,
std::ostream &  out = logroot 
)
inline

Prints some general information for this run to out.

◆ read_table_from_csv()

Result< Table > terra::util::read_table_from_csv ( const std::string &  filename)
inline

Attempts to read a csv file and converts that into a Table instance.

Recognizes commas as a separator.

Parameters
filenameCSV file path
Returns
Result object either containing a Table on success or an error string.

◆ terra_initialize()

void terra::util::terra_initialize ( int *  argc,
char ***  argv 
)
inline

RAII approach to safely initialize MPI and Kokkos.

At the start of your main(), create this object to run MPI_Init/Finalize and to start the Kokkos scope.

Like this:

 int main( int argc, char** argv)
 {
     // Make sure to not destroy it right away!
     //     TerraScopeGuard( &argc, &argv );
     // will not work! Name the thing!

     TerraScopeGuard terra_scope_guard( &argc, &argv );

     // Here goes your cool app/test. MPI and Kokkos are finalized automatically (even if you throw an
     // exception).

     // ...
 } // Destructor handles stuff here. 

Variable Documentation

◆ logall

detail::PrefixCout terra::util::logall([]() { return detail::log_prefix();}, false) ( [] () { return detail::log_prefix();}  ,
false   
)
inline

std::ostream subclass that just logs on any process and adds a timestamp for each line.

You should be able to use this as a plugin replacement for std::cout.

◆ logroot

detail::PrefixCout terra::util::logroot([]() { return detail::log_prefix();}) ( [] () { return detail::log_prefix();}  )
inline

std::ostream subclass that just logs on root and adds a timestamp for each line.

You should be able to use this as a plugin replacement for std::cout.