Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Namespaces | Classes | Functions
Utilities Namespace Reference

Namespaces

 MPI
 
 System
 
 Trilinos
 

Classes

struct  fixed_int_power
 
struct  fixed_int_power< a, 0 >
 

Functions

std::string int_to_string (const unsigned int i, const unsigned int digits=numbers::invalid_unsigned_int)
 
unsigned int needed_digits (const unsigned int max_number)
 
int string_to_int (const std::string &s)
 
std::vector< intstring_to_int (const std::vector< std::string > &s)
 
double string_to_double (const std::string &s)
 
std::vector< doublestring_to_double (const std::vector< std::string > &s)
 
std::vector< std::string > split_string_list (const std::string &s, const char delimiter= ',')
 
std::vector< std::string > break_text_into_lines (const std::string &original_text, const unsigned int width, const char delimiter= ' ')
 
bool match_at_string_start (const std::string &name, const std::string &pattern)
 
std::pair< int, unsigned intget_integer_at_position (const std::string &name, const unsigned int position)
 
double generate_normal_random_number (const double a, const double sigma)
 
template<int N, typename T >
fixed_power (const T t)
 
template<typename Iterator , typename T >
Iterator lower_bound (Iterator first, Iterator last, const T &val)
 
template<typename Iterator , typename T , typename Comp >
Iterator lower_bound (Iterator first, Iterator last, const T &val, const Comp comp)
 
std::vector< unsigned intreverse_permutation (const std::vector< unsigned int > &permutation)
 
std::vector< unsigned intinvert_permutation (const std::vector< unsigned int > &permutation)
 
std::vector< unsigned long
long int
reverse_permutation (const std::vector< unsigned long long int > &permutation)
 
std::vector< unsigned long
long int
invert_permutation (const std::vector< unsigned long long int > &permutation)
 

Detailed Description

A namespace for utility functions that are not particularly specific to finite element computing or numerical programs, but nevertheless are needed in various contexts when writing applications.

Author
Wolfgang Bangerth, 2005

Function Documentation

std::string Utilities::int_to_string ( const unsigned int  i,
const unsigned int  digits = numbers::invalid_unsigned_int 
)

Convert a number i to a string, with as many digits as given to fill with leading zeros.

If the second parameter is left at its default value, the number is not padded with leading zeros. The result is then the same as of the standard C function itoa() had been called.

unsigned int Utilities::needed_digits ( const unsigned int  max_number)

Determine how many digits are needed to represent numbers at most as large as the given number.

int Utilities::string_to_int ( const std::string &  s)

Given a string, convert it to an integer. Throw an assertion if that is not possible.

std::vector<int> Utilities::string_to_int ( const std::vector< std::string > &  s)

Given a list of strings, convert it to a list of integers. Throw an assertion if that is not possible.

double Utilities::string_to_double ( const std::string &  s)

Given a string, convert it to an double. Throw an assertion if that is not possible.

std::vector<double> Utilities::string_to_double ( const std::vector< std::string > &  s)

Given a list of strings, convert it to a list of doubles. Throw an assertion if that is not possible.

std::vector<std::string> Utilities::split_string_list ( const std::string &  s,
const char  delimiter = ',' 
)

Given a string that contains text separated by a delimiter, split it into its components; for each component, remove leading and trailing spaces.

The default value of the delimiter is a comma, so that the function splits comma separated lists of strings.

std::vector<std::string> Utilities::break_text_into_lines ( const std::string &  original_text,
const unsigned int  width,
const char  delimiter = ' ' 
)

Take a text, usually a documentation or something, and try to break it into individual lines of text at most width characters wide, by breaking at positions marked by delimiter in the text. If this is not possible, return the shortest lines that are longer than width. The default value of the delimiter is a space character. If original_text contains newline characters (
), the string is split at these locations, too.

bool Utilities::match_at_string_start ( const std::string &  name,
const std::string &  pattern 
)

Return true if the given pattern string appears in the first position of the string.

std::pair<int, unsigned int> Utilities::get_integer_at_position ( const std::string &  name,
const unsigned int  position 
)

Read a (signed) integer starting at the position in name indicated by the second argument, and retun this integer as a pair together with how many characters it takes up in the string.

If no integer can be read at the indicated position, return (-1,numbers::invalid_unsigned_int)

double Utilities::generate_normal_random_number ( const double  a,
const double  sigma 
)

Generate a random number from a normalized Gaussian probability distribution centered around a and with standard deviation sigma.

This function is reentrant, i.e., it can safely be called from multiple threads at the same time. However, if so done, then there is no guarantee that each thread will get the same sequence of numbers every time. Rather, the produced sequence of random numbers will be apportioned to the different threads in non-deterministic ways. If this is a problem, for example for exactly reproducibility, then you need to use separate random number facilities for separate threads, rather than this global function. For example, the C++11 standard offers such objects, as does BOOST.

Note
Like the system function rand(), this function produces the same sequence of random numbers every time a program is started. This is an important property for debugging codes, but it makes it impossible to really verify statistics properties of a code. For rand(), you can call srand() to "seed" the random number generator to get different sequences of random numbers every time a program is called. However, this function does not allow seeding the random number generator. If you need this, as above, use one of the C++ or BOOST facilities.
template<int N, typename T >
T Utilities::fixed_power ( const T  t)
inline

Calculate a fixed power, provided as a template argument, of a number.

This function provides an efficient way to calculate things like t^N where N is a known number at compile time.

Use this function as in fixed_power<dim> (n).

Definition at line 705 of file utilities.h.

template<typename Iterator , typename T >
Iterator Utilities::lower_bound ( Iterator  first,
Iterator  last,
const T &  val 
)
inline

Optimized replacement for std::lower_bound for searching within the range of column indices. Slashes execution time by approximately one half for the present application, partly because because the binary search is replaced by a linear search for small loop lengths.

Another reason for this function is rather obscure: when using the GCC libstdc++ function std::lower_bound, complexity is O(log(N)) as required. However, when using the debug version of the GCC libstdc++ as we do when running the testsuite, then std::lower_bound tests whether the sequence is in fact partitioned with respect to the pivot 'value' (i.e. in essence that the sequence is sorted as required for binary search to work). However, verifying this means that the complexity of std::lower_bound jumps to O(N); we call this function O(N) times below, making the overall complexity O(N**2). The consequence is that a few tests with big meshes completely run off the wall time limit for tests and fail with the libstdc++ debug mode

This function simply makes the assumption that the sequence is sorted, and we simply don't do the additional check.

Definition at line 731 of file utilities.h.

template<typename Iterator , typename T , typename Comp >
Iterator Utilities::lower_bound ( Iterator  first,
Iterator  last,
const T &  val,
const Comp  comp 
)
inline

The same function as above, but taking an argument that is used to compare individual elements of the sequence of objects pointed to by the iterators.

Definition at line 744 of file utilities.h.

std::vector<unsigned int> Utilities::reverse_permutation ( const std::vector< unsigned int > &  permutation)

Given a permutation vector (i.e. a vector $p_0\ldots p_{N-1}$ where each $p_i\in [0,N)$ and $p_i\neq p_j$ for $i\neq j$), produce the reverse permutation $q_i=N-1-p_i$.

std::vector<unsigned int> Utilities::invert_permutation ( const std::vector< unsigned int > &  permutation)

Given a permutation vector (i.e. a vector $p_0\ldots p_{N-1}$ where each $p_i\in [0,N)$ and $p_i\neq p_j$ for $i\neq j$), produce the inverse permutation $q_0\ldots q_{N-1}$ so that $q_{p_i}=p_{q_i}=i$.

std::vector<unsigned long long int> Utilities::reverse_permutation ( const std::vector< unsigned long long int > &  permutation)

Given a permutation vector (i.e. a vector $p_0\ldots p_{N-1}$ where each $p_i\in [0,N)$ and $p_i\neq p_j$ for $i\neq j$), produce the reverse permutation $q_i=N-1-p_i$.

std::vector<unsigned long long int> Utilities::invert_permutation ( const std::vector< unsigned long long int > &  permutation)

Given a permutation vector (i.e. a vector $p_0\ldots p_{N-1}$ where each $p_i\in [0,N)$ and $p_i\neq p_j$ for $i\neq j$), produce the inverse permutation $q_0\ldots q_{N-1}$ so that $q_{p_i}=p_{q_i}=i$.