Penning Trap Simulation Simulate particle behavior inside a Penning Trap

Loading...
Searching...
No Matches
Functions
utils.cpp File Reference

Implementation of the utils. More...

`#include "utils.hpp"`

Go to the source code of this file.

## Functions
std::string | scientific_format (double d, int width, int prec)
| Turns a double into a string written in scientific format.
std::string | scientific_format (const std::vector< double > &v, int width, int prec)
| Turns a vector of doubles into a string written in scientific format.
void | m_assert (bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg)
| Test an expression, confirm that test is ok, or abort execution.
bool | close_to (arma::vec &a, arma::vec &b, double tol)
| Test if two armadillo vectors are close to each other.
bool | mkpath (std::string path, int mode)
| Make path given.

## Detailed Description

Implementation of the utils.

Author
  Cory Alexander Balaton (coryab)
  Janita Ovidie Sandtrøen Willumsen (janitaws)

Version
  1.0

Bug:
  No known bugs

Definition in file utils.cpp.

## Function Documentation

## ◆ close_to()

bool close_to | ( | arma::vec & | a,
|  | arma::vec & | b,
|  | double | tol = `1e-8`
| ) |  |

Test if two armadillo vectors are close to each other.

This function takes in 2 vectors and checks if they are approximately equal to each other given a tolerance.

Parameters

  a | Vector a
  b | Vector b
  tol | The tolerance

Returns
  bool

Definition at line 58 of file utils.cpp.

## ◆ m_assert()

void m_assert | ( | bool | expr,
|  | std::string | expr_str,
|  | std::string | func,
|  | std::string | file,
|  | int | line,
|  | std::string | msg
| ) |  |

Test an expression, confirm that test is ok, or abort execution.

This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails.

Parameters

  expr | The expression to be evaluated
  expr_str | The stringified version of the expression
  func | The function name of the caller
  file | The file of the caller
  line | The line number where this function is called from
  msg | The message to be displayed

Definition at line 40 of file utils.cpp.

## ◆ mkpath()

bool mkpath | ( | std::string | path,
|  | int | mode = `0777`
| ) |  |

Make path given.

This tries to be the equivalent to "mkdir -p" and creates a new directory whenever it needs to.

Parameters

  path | The path to be created
  mode | The mode/permissions for all the new directories

Returns
  bool Success/Fail

Definition at line 72 of file utils.cpp.

## ◆ scientific_format() [1/2]

std::string scientific_format | ( | const std::vector< double > & | v,
|  | int | width = `20`,
|  | int | prec = `10`
| ) |  |

Turns a vector of doubles into a string written in scientific format.

The code is stolen from https://github.com/anderkve/FYS3150.

Parameters

  v | The vector to stringify
  width | The reserved width of the string
  prec | The precision of the stringified number

Returns
  std::string

Definition at line 22 of file utils.cpp.

## ◆ scientific_format() [2/2]

std::string scientific_format | ( | double | d,
|  | int | width = `20`,
|  | int | prec = `10`
| ) |  |

Turns a double into a string written in scientific format.

The code is stolen from https://github.com/anderkve/FYS3150.

Parameters

  d | The number to stringify
  width | The reserved width of the string
  prec | The precision of the stringified number

Returns
  std::string

Definition at line 15 of file utils.cpp.