deal2lkit: A ToolKit library for Deal.II
utilities.h File Reference
#include <deal2lkit/config.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/smartpointer.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/timer.h>
#include <deal.II/fe/fe.h>
#include <deal.II/base/std_cxx11/shared_ptr.h>
#include <typeinfo>
#include <cxxabi.h>
#include <sstream>
#include <sys/ioctl.h>
#include <chrono>
#include <stdio.h>
#include <deal.II/lac/block_vector.h>
#include <nvector/nvector_serial.h>
#include <deal.II/base/index_set.h>

Go to the source code of this file.

Classes

class  TimeUtilities
 This function collects some time utilities. More...
 
class  OverWriteStream< Stream >
 This class uses n_lines lines of stream_out to show the output. More...
 
class  OverWriteStream< Stream >
 This class uses n_lines lines of stream_out to show the output. More...
 

Functions

std::string demangle (const char *name)
 Demangle c++ names. More...
 
void append_to_file (const std::string &in_file, const std::string &out_file)
 This function copy the text contained in in_file to the file out_file . More...
 
unsigned int get_next_available_index_directory_name (const std::string &base, int n_digits=3, unsigned int start=0, unsigned int index_max=1000)
 A function that return the index of the first non existing folder matching a pattern make by base and n_digits number. More...
 
std::string get_next_available_directory_name (const std::string &base, int n_digits=3, unsigned int start=0, unsigned int index_max=1000)
 A function that return the name of the first non existing folder matching a pattern make by base and n_digits number. More...
 
bool dir_exists (const std::string &dir)
 A function to check the existence of dir directory. More...
 
bool file_exists (const std::string &file)
 A function to check the existence of file file. More...
 
bool create_directory (const std::string &name)
 A function to create directory. More...
 
bool copy_files (const std::string &files, const std::string &destination)
 A function to copy a list of file ( "file1 file2 file3" ) in the destination folder (destination) More...
 
bool copy_file (const std::string &files, const std::string &destination)
 A function to make a copy of file with the name destination. More...
 
bool rename_file (const std::string &file, const std::string &new_file)
 A function to rename a file with a new name new_file. More...
 
 DeclException1 (ExcCannottExecuteCommand, std::string,<< "Cannot execute command "<< arg1<< "\Please verify you have "<< "the needed permissions.")
 Cannot execute std::system(command) More...
 
template<typename S , typename T >
OverWriteStream< S > & operator<< (OverWriteStream< S > &output_stream, const T &t)
 
template<class T >
std::vector< T > unique (const std::vector< T > &myvector)
 A simple function that accepts a vector as an input and returns a second vector containing only the unique value among consecutive entries of the original vector. More...
 
template<class Type >
std::string print (const std::vector< Type > &list, const std::string sep=",")
 Return a string containing the content of the vector, with elements separated by the @ sep parameter. More...
 
template<int dim>
std::string print (const Point< dim > &point, const std::string sep=",")
 Return a string containing the content of the Point, with elements separated by the @ sep parameter. More...
 
template<class T >
std::string type (const T &t)
 Return a human readable name of the type passed as argument. More...
 
template<class T >
shared_ptr< T > SP (T *t)
 Construct a shared pointer to a non const class T. More...
 
template<class T >
shared_ptr< const T > SP (const T *t)
 Construct a shared pointer to a const class T. More...
 
template<typename VEC >
void vector_shift (VEC &in_vec, double a_scalar)
 A simple class to shift a vector by a scalar. More...
 
void copy (BlockVector< double > &dst, const N_Vector &src)
 
void copy (N_Vector &dst, const BlockVector< double > &src)
 

Function Documentation

§ append_to_file()

void append_to_file ( const std::string &  in_file,
const std::string &  out_file 
)

This function copy the text contained in in_file to the file out_file .

Definition at line 67 of file utilities.cc.

§ copy() [1/2]

void copy ( BlockVector< double > &  dst,
const N_Vector &  src 
)

Definition at line 258 of file utilities.cc.

§ copy() [2/2]

void copy ( N_Vector &  dst,
const BlockVector< double > &  src 
)

Definition at line 275 of file utilities.cc.

§ copy_file()

bool copy_file ( const std::string &  files,
const std::string &  destination 
)

A function to make a copy of file with the name destination.

Definition at line 139 of file utilities.cc.

§ copy_files()

bool copy_files ( const std::string &  files,
const std::string &  destination 
)

A function to copy a list of file ( "file1 file2 file3" ) in the destination folder (destination)

Definition at line 119 of file utilities.cc.

§ create_directory()

bool create_directory ( const std::string &  name)

A function to create directory.

It creates all directories needed.

Definition at line 108 of file utilities.cc.

§ DeclException1()

DeclException1 ( ExcCannottExecuteCommand  ,
std::string  ,
<< "Cannot execute command "<< arg1<< "\ease verify you have "<< "the needed permissions."   
)

Cannot execute std::system(command)

§ demangle()

std::string demangle ( const char *  name)

Demangle c++ names.

Definition at line 28 of file utilities.cc.

§ dir_exists()

bool dir_exists ( const std::string &  dir)

A function to check the existence of dir directory.

Definition at line 83 of file utilities.cc.

§ file_exists()

bool file_exists ( const std::string &  file)

A function to check the existence of file file.

Definition at line 77 of file utilities.cc.

§ get_next_available_directory_name()

std::string get_next_available_directory_name ( const std::string &  base,
int  n_digits = 3,
unsigned int  start = 0,
unsigned int  index_max = 1000 
)

A function that return the name of the first non existing folder matching a pattern make by base and n_digits number.

(base000, base001, base002, ...) The research of the index starts from the value start and ends when index_max is reached.

Definition at line 102 of file utilities.cc.

§ get_next_available_index_directory_name()

unsigned int get_next_available_index_directory_name ( const std::string &  base,
int  n_digits = 3,
unsigned int  start = 0,
unsigned int  index_max = 1000 
)

A function that return the index of the first non existing folder matching a pattern make by base and n_digits number.

(base000, base001, base002, ...) The research of the index starts from the value start and ends when index_max is reached.

Definition at line 89 of file utilities.cc.

§ operator<<()

template<typename S , typename T >
OverWriteStream<S>& operator<< ( OverWriteStream< S > &  output_stream,
const T &  t 
)
inline

Definition at line 395 of file utilities.h.

§ print() [1/2]

template<class Type >
std::string print ( const std::vector< Type > &  list,
const std::string  sep = "," 
)

Return a string containing the content of the vector, with elements separated by the @ sep parameter.

Definition at line 425 of file utilities.h.

§ print() [2/2]

template<int dim>
std::string print ( const Point< dim > &  point,
const std::string  sep = "," 
)

Return a string containing the content of the Point, with elements separated by the @ sep parameter.

Definition at line 443 of file utilities.h.

§ rename_file()

bool rename_file ( const std::string &  file,
const std::string &  new_file 
)

A function to rename a file with a new name new_file.

Definition at line 149 of file utilities.cc.

§ SP() [1/2]

template<class T >
shared_ptr<T> SP ( T *  t)
inline

Construct a shared pointer to a non const class T.

This is a convenience function to simplify the construction of shared pointers:

code

std_cxx11::shared_ptr<MyClass> my_ptr;

...

my_ptr = SP(new MyClass);

Definition at line 483 of file utilities.h.

§ SP() [2/2]

template<class T >
shared_ptr<const T> SP ( const T *  t)
inline

Construct a shared pointer to a const class T.

This is a convenience function to simplify the construction of shared pointers (which should replace dealii::SmartPointers):

code

std_cxx11::shared_ptr<const MyClass> my_ptr;

... const MyClass * p = new MyClass; my_ptr = SP(p);

Definition at line 505 of file utilities.h.

§ type()

template<class T >
std::string type ( const T &  t)

Return a human readable name of the type passed as argument.

Definition at line 461 of file utilities.h.

§ unique()

template<class T >
std::vector<T> unique ( const std::vector< T > &  myvector)

A simple function that accepts a vector as an input and returns a second vector containing only the unique value among consecutive entries of the original vector.

Definition at line 412 of file utilities.h.

§ vector_shift()

template<typename VEC >
void vector_shift ( VEC &  in_vec,
double  a_scalar 
)

A simple class to shift a vector by a scalar.

This function is deprecated in deal but needed in many codes

Definition at line 516 of file utilities.h.