Reference documentation for deal.II version GIT relicensing-136-gb80d0be4af 2024-03-18 08:20:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
Utilities Namespace Reference

Namespaces

namespace  CUDA
 
namespace  internal
 
namespace  LinearAlgebra
 
namespace  MPI
 
namespace  System
 
namespace  Trilinos
 

Classes

class  MutableBind
 

Functions

IndexSet create_evenly_distributed_partitioning (const unsigned int my_partition_id, const unsigned int n_partitions, const types::global_dof_index total_size)
 
template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > mutable_bind (ReturnType(*function)(FunctionArgs...), std_cxx20::type_identity_t< FunctionArgs > &&...arguments)
 
template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > mutable_bind (std::function< ReturnType(FunctionArgs...)>, std_cxx20::type_identity_t< FunctionArgs > &&...arguments)
 
template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > mutable_bind (ReturnType(*function)(FunctionArgs...))
 
template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > mutable_bind (std::function< ReturnType(FunctionArgs...)>)
 
std::string dealii_version_string ()
 
template<int dim, typename Number >
std::vector< std::array< std::uint64_t, dim > > inverse_Hilbert_space_filling_curve (const std::vector< Point< dim, Number > > &points, const int bits_per_dim=64)
 
template<int dim>
std::vector< std::array< std::uint64_t, dim > > inverse_Hilbert_space_filling_curve (const std::vector< std::array< std::uint64_t, dim > > &points, const int bits_per_dim=64)
 
template<int dim>
std::uint64_t pack_integers (const std::array< std::uint64_t, dim > &index, const int bits_per_dim)
 
std::string compress (const std::string &input)
 
std::string decompress (const std::string &compressed_input)
 
std::string encode_base64 (const std::vector< unsigned char > &binary_input)
 
std::vector< unsigned char > decode_base64 (const std::string &base64_input)
 
std::string int_to_string (const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
 
template<typename number >
std::string to_string (const number value, const unsigned int digits=numbers::invalid_unsigned_int)
 
unsigned int needed_digits (const unsigned int max_number)
 
template<typename Number >
Number truncate_to_n_digits (const Number number, const unsigned int n_digits)
 
int string_to_int (const std::string &s)
 
std::string dim_string (const int dim, const int spacedim)
 
std::vector< intstring_to_int (const std::vector< std::string > &s)
 
double string_to_double (const std::string &s)
 
std::vector< double > string_to_double (const std::vector< std::string > &s)
 
std::vector< std::string > split_string_list (const std::string &s, const std::string &delimiter=",")
 
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)
 
std::string replace_in_string (const std::string &input, const std::string &from, const std::string &to)
 
std::string trim (const std::string &input)
 
double generate_normal_random_number (const double a, const double sigma)
 
template<class T >
std::string type_to_string (const T &t)
 
template<int N, typename T >
constexpr T fixed_power (const T t)
 
template<typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr T pow (const T base, const int iexp)
 
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)
 
template<typename Integer >
std::vector< Integer > reverse_permutation (const std::vector< Integer > &permutation)
 
template<typename Integer >
std::vector< Integer > invert_permutation (const std::vector< Integer > &permutation)
 
template<typename T >
size_t pack (const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
 
template<typename T >
std::vector< char > pack (const T &object, const bool allow_compression=true)
 
template<typename T >
unpack (const std::vector< char > &buffer, const bool allow_compression=true)
 
template<typename T >
unpack (const std::vector< char >::const_iterator &cbegin, const std::vector< char >::const_iterator &cend, const bool allow_compression=true)
 
template<typename T , int N>
void unpack (const std::vector< char > &buffer, T(&unpacked_object)[N], const bool allow_compression=true)
 
template<typename T , int N>
void unpack (const std::vector< char >::const_iterator &cbegin, const std::vector< char >::const_iterator &cend, T(&unpacked_object)[N], const bool allow_compression=true)
 
bool get_bit (const unsigned char number, const unsigned int n)
 
void set_bit (unsigned char &number, const unsigned int n, const bool x)
 
template<typename To , typename From >
std::unique_ptr< To > dynamic_unique_cast (std::unique_ptr< From > &&p)
 
template<typename T >
T & get_underlying_value (T &p)
 
template<typename T >
T & get_underlying_value (std::shared_ptr< T > &p)
 
template<typename T >
T & get_underlying_value (const std::shared_ptr< T > &p)
 
template<typename T >
T & get_underlying_value (std::unique_ptr< T > &p)
 
template<typename T >
T & get_underlying_value (const std::unique_ptr< T > &p)
 
template<int dim, typename Number , typename VectorizedArrayType = VectorizedArray<Number>>
FERemoteEvaluationCommunicator< dim > compute_remote_communicator_faces_point_to_point_interpolation (const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const std::vector< std::pair< types::boundary_id, std::function< std::vector< bool >()> > > &non_matching_faces_marked_vertices, const unsigned int quad_no=0, const unsigned int dof_no=0, const double tolerance=1e-9)
 
template<int dim, typename Number , typename VectorizedArrayType = VectorizedArray<Number>>
FERemoteEvaluationCommunicator< dim > compute_remote_communicator_faces_nitsche_type_mortaring (const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const std::vector< std::pair< types::boundary_id, std::function< std::vector< bool >()> > > &non_matching_faces_marked_vertices, const unsigned int n_q_pnts_1D, const unsigned int dof_no=0, NonMatching::MappingInfo< dim, dim, Number > *nm_mapping_info=nullptr, const double tolerance=1e-9)
 
static ::ExceptionBaseExcInvalidNumber2StringConversersion (unsigned int arg1, unsigned int arg2)
 
static ::ExceptionBaseExcInvalidNumber (unsigned int arg1)
 
static ::ExceptionBaseExcCantConvertString (std::string arg1)
 

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.

The namespace collects convenience functions to set up FERemoteEvaluationCommunicator for typical use cases.

Function Documentation

◆ create_evenly_distributed_partitioning()

IndexSet Utilities::create_evenly_distributed_partitioning ( const unsigned int  my_partition_id,
const unsigned int  n_partitions,
const types::global_dof_index  total_size 
)

Given the total number of elements total_size, create an evenly distributed 1:1 partitioning of the elements for across n_partitions. The local sizes will be equal to the total_size divided by the number of partitions plus the remainder being divided amongst the first processes. Each process will store a contiguous subset of indices, and the index set on process p+1 starts at the index one larger than the last one stored on process p. For example, a total_size of 11 with 3 processes will result in the IndexSets { [0,4), [4,8), [8,11)] }, and this function will return the my_partition_id 's IndexSet.

Definition at line 78 of file mpi.cc.

◆ mutable_bind() [1/4]

template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > Utilities::mutable_bind ( ReturnType(*)(FunctionArgs...)  function,
std_cxx20::type_identity_t< FunctionArgs > &&...  arguments 
)

Create a MutableBind object from a function pointer and a list of arguments.

An example usage is given by:

void my_function(const int &a, const double &b);
auto bound = mutable_bind(my_function, 1, 2.0);
bound(); // will execute my_function(1, 2.0);
bound.set_arguments(2, 3.0);
bound(); // will execute my_function(2, 3.0);
bound.parse_arguments("3: 4.0");
bound(); // will execute my_function(3, 4.0);
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), std_cxx20::type_identity_t< FunctionArgs > &&...arguments)

◆ mutable_bind() [2/4]

template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > Utilities::mutable_bind ( std::function< ReturnType(FunctionArgs...)>  ,
std_cxx20::type_identity_t< FunctionArgs > &&...  arguments 
)

Same as above, using a std::function object.

◆ mutable_bind() [3/4]

template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > Utilities::mutable_bind ( ReturnType(*)(FunctionArgs...)  function)

Create a MutableBind object from a function pointer, with uninitialized arguments.

Notice that if you do not call one of the MutableBind::set_arguments() methods, or the MutableBind::parse_arguments() function on the returned object, then the arguments passed to the function object will be initialized with the values coming from each of the arguments' default constructors.

◆ mutable_bind() [4/4]

template<typename ReturnType , class... FunctionArgs>
MutableBind< ReturnType, FunctionArgs... > Utilities::mutable_bind ( std::function< ReturnType(FunctionArgs...)>  )

Same as above, using a std::function object.

◆ dealii_version_string()

std::string Utilities::dealii_version_string ( )

Return a string of the form "deal.II version x.y.z" where "x.y.z" identifies the version of deal.II you are using. This information is also provided by the DEAL_II_PACKAGE_NAME and DEAL_II_PACKAGE_VERSION preprocessor variables.

Definition at line 94 of file utilities.cc.

◆ inverse_Hilbert_space_filling_curve() [1/2]

template<int dim, typename Number >
std::vector< std::array< std::uint64_t, dim > > Utilities::inverse_Hilbert_space_filling_curve ( const std::vector< Point< dim, Number > > &  points,
const int  bits_per_dim = 64 
)

Assign to each point in points an index using the Hilbert space filling curve. To that end, a bounding box for points will be determined, based on which their integer coordinates are calculated. The linear index is given as a dim-collection of bits, from high to low. This is done in order to keep the maximum resolution in terms of bit depth along each axis. Note that this dim-integer index can still be easily used for sorting and ordering, for example using the lexicographic ordering of tuples of integers.

The depth of the Hilbert curve (i.e. the number of bits per dimension) by default is equal to 64.

Note
This function can also handle degenerate cases, e.g. when the bounding box has zero size in one of the dimensions.

Definition at line 145 of file utilities.cc.

◆ inverse_Hilbert_space_filling_curve() [2/2]

template<int dim>
std::vector< std::array< std::uint64_t, dim > > Utilities::inverse_Hilbert_space_filling_curve ( const std::vector< std::array< std::uint64_t, dim > > &  points,
const int  bits_per_dim = 64 
)

Same as above, but for points in integer coordinates.

Definition at line 254 of file utilities.cc.

◆ pack_integers()

template<int dim>
std::uint64_t Utilities::pack_integers ( const std::array< std::uint64_t, dim > &  index,
const int  bits_per_dim 
)

Pack the least significant bits_per_dim bits from each element of index (starting from last) into a single unsigned integer. The last element of index will be used to set the first bits_per_dim bits in the resulting integer, the second to last element is used to set the next bits_per_dim bits, etc.. To fit all the data into the output, the following should hold bits_per_dim * dim <= 64.

The function is useful in debugging and visualization of indices returned by inverse_Hilbert_space_filling_curve().

Note
There is no need to use this function in order to compare indices returned by inverse_Hilbert_space_filling_curve(), as that can easily be done via std::lexicographical_compare().

Definition at line 366 of file utilities.cc.

◆ compress()

std::string Utilities::compress ( const std::string &  input)

If the library is configured with ZLIB, then this function compresses the input string and returns a non-zero terminated string containing the compressed input.

If the library was not configured with ZLIB enabled, the returned string is identical to the input string.

Parameters
[in]inputThe string to compress
Returns
A compressed version of the input string

Definition at line 389 of file utilities.cc.

◆ decompress()

std::string Utilities::decompress ( const std::string &  compressed_input)

If the library is configured with ZLIB, then this function assumes that the input string has been compressed using the compress() function, and returns the original decompressed string.

If the library was not configured with ZLIB enabled, the returned string is identical to the input string.

Parameters
[in]compressed_inputA compressed string, as returned by the function compress()
Returns
The original uncompressed string.

Definition at line 411 of file utilities.cc.

◆ encode_base64()

std::string Utilities::encode_base64 ( const std::vector< unsigned char > &  binary_input)

Encodes the binary input as a base64 string.

Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. Base64 is designed to carry data stored in binary formats across channels that only reliably support text content. It is used also to store binary formats in a machine independent way.

Parameters
binary_inputA vector of characters, representing your input as binary data.
Returns
A string containing the binary input as a base64 string.

Definition at line 433 of file utilities.cc.

◆ decode_base64()

std::vector< unsigned char > Utilities::decode_base64 ( const std::string &  base64_input)

Decodes a base64 string into a binary output.

This is the inverse of the encode_base64() function above.

Parameters
base64_inputA string that contains the input in base64 format.
Returns
A vector of characters that represents your input as binary data.

Definition at line 446 of file utilities.cc.

◆ int_to_string()

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

Convert a number value 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 if the standard C++ std::to_string (or the older C function itoa()) had been called.

This function takes an unsigned int as argument. As a consequence, if you call it with a signed int (which is of course the same type as int), the argument is implicitly converted to unsigned integers and negative numbers may not be printed as you had hoped. Similarly, if you call the function with a long int, the printed result might show the effects of an overflow upon conversion to unsigned int.

Note
The use of this function is discouraged and users should use Utilities::to_string() instead. In its current implementation the function simply calls to_string<unsigned int>().

Definition at line 470 of file utilities.cc.

◆ to_string()

template<typename number >
std::string Utilities::to_string ( const number  value,
const unsigned int  digits = numbers::invalid_unsigned_int 
)

Convert a number value to a string, with digits characters. The string is padded with leading zeros, after a possible minus sign. Therefore the total number of padding zeros is digits minus any signs, decimal points and digits of value.

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 if the C++ function std::to_string() had been called (for integral types), or if boost::lexical_cast() had been called (for all other types).

Definition at line 479 of file utilities.cc.

◆ needed_digits()

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.

Definition at line 565 of file utilities.cc.

◆ truncate_to_n_digits()

template<typename Number >
Number Utilities::truncate_to_n_digits ( const Number  number,
const unsigned int  n_digits 
)

This function allows to cut off a floating point number number after n_digits of accuracy, i.e., after n_digits decimal places in scientific floating point notation. When interpreted as rounding operation, this function reduces the absolute value of a floating point number and always rounds towards zero, since decimal places are simply cut off.

Definition at line 578 of file utilities.cc.

◆ string_to_int() [1/2]

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.

Definition at line 605 of file utilities.cc.

◆ dim_string()

std::string Utilities::dim_string ( const int  dim,
const int  spacedim 
)

Return a string describing the dimensions of the object. Often, functions in the deal.II library as well as in user codes need to define a string containing the template dimensions of some objects defined using two template parameters: dim (the topological dimension of the object) and spacedim (the dimension of the embedding Euclidean space). Since in all deal.II classes, by default spacedim is equal to dimension, the above string is usually contracted to "<dim>", instead of "<dim,spacedim>". This function returns a string containing "dim" if dim is equal to spacedim, otherwise it returns "dim,spacedim".

Definition at line 555 of file utilities.cc.

◆ string_to_int() [2/2]

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.

Definition at line 642 of file utilities.cc.

◆ string_to_double() [1/2]

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.

Definition at line 653 of file utilities.cc.

◆ string_to_double() [2/2]

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.

Definition at line 690 of file utilities.cc.

◆ split_string_list() [1/2]

std::vector< std::string > Utilities::split_string_list ( const std::string &  s,
const std::string &  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.

To make data input from tables simpler, if the input string ends in a delimiter (possibly followed by an arbitrary amount of whitespace), then this last delimiter is ignored. For example,

Utilities::split_string_list("abc; def; ghi; ", ';');
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition utilities.cc:701

yields the same 3-element list of output {"abc","def","ghi"} as you would get if the input had been

Utilities::split_string_list("abc; def; ghi", ';');

or

Utilities::split_string_list("abc; def; ghi;", ';');

As a consequence of this rule, a call like

yields a one-element list. Because of the trimming of whitespace, the single element is the empty string.

This function can digest the case that the delimiter is a space. In this case, it returns all words in the string. Combined with the rules above, this implies that

Utilities::split_string_list("abc def ghi ", ' ');

yields again the 3-element list of output {"abc","def","ghi"} from above despite the presence of space at the end of the string. Furthermore,

yields an empty list regardless of the number of spaces in the string.

Definition at line 701 of file utilities.cc.

◆ split_string_list() [2/2]

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

Specialization of split_string_list() for the case where the delimiter is a single char.

Definition at line 746 of file utilities.cc.

◆ break_text_into_lines()

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.

Definition at line 755 of file utilities.cc.

◆ match_at_string_start()

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.

Definition at line 832 of file utilities.cc.

◆ get_integer_at_position()

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 return 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)

Definition at line 847 of file utilities.cc.

◆ replace_in_string()

std::string Utilities::replace_in_string ( const std::string &  input,
const std::string &  from,
const std::string &  to 
)

Return a string with all occurrences of from in input replaced by to.

Definition at line 509 of file utilities.cc.

◆ trim()

std::string Utilities::trim ( const std::string &  input)

Return a string with all standard whitespace characters (including '\t', '\n', and '\r') at the beginning and end of input removed.

Definition at line 528 of file utilities.cc.

◆ generate_normal_random_number()

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. The returned number will be different every time the function is called.

This function is reentrant, i.e., it can safely be called from multiple threads at the same time. In addition, each thread will get the same sequence of numbers every time. On the other hand, if you run Threads::Task objects via the Threading Building Blocks, then tasks will be assigned to mostly random threads, and may get a different sequence of random numbers in different runs of the program, since a previous task may already have consumed the first few random numbers generated for the thread you're on. If this is a problem, you need to create your own random number generator objects every time you want to start from a defined point.

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 statistical 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.

Definition at line 889 of file utilities.cc.

◆ type_to_string()

template<class T >
std::string Utilities::type_to_string ( const T &  t)
inline

Return a string description of the type of the variable t.

In general, C++ uses mangled names to identify types. This function uses boost::core::demangle to return a human readable string describing the type of the variable passed as argument.

Definition at line 1020 of file utilities.h.

◆ fixed_power()

template<int N, typename T >
constexpr T Utilities::fixed_power ( const T  t)
inlineconstexpr

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. The function computes the power of \(t\) via the "recursive doubling" approach in which, for example, \(t^7\) is computed as

\begin{align*} t^7 = (tttt)(tt)(t) \end{align*}

where computing \(tt\) requires one product, computing \(tttt\) is achieved by multiplying the previously computed \(tt\) by itself (requiring another multiplication), and then the product is computed via two more multiplications for a total of 4 multiplications instead of the naively necessary 6.

The major savings this function generates result, however, from the fact that it exploits that we have an integer power of the argument \(t\). The alternative to computing such powers, std::pow(t,7) uses the std::pow function that takes the exponent as a floating point number and, because it has to cater to the complexities of the general situation, is vastly slower.

Use this function as in fixed_power<dim> (t) or fixed_power<7> (t).

Definition at line 939 of file utilities.h.

◆ pow()

template<typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr T Utilities::pow ( const T  base,
const int  iexp 
)
constexpr

A replacement for std::pow that allows compile-time calculations for constant expression arguments and if the exponent is a positive integer. The base must be an arithmetic type (i.e., an integer or floating point type), and the exponent iexp must not be negative.

Definition at line 963 of file utilities.h.

◆ lower_bound() [1/2]

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 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 1029 of file utilities.h.

◆ lower_bound() [2/2]

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 1038 of file utilities.h.

◆ reverse_permutation()

template<typename Integer >
std::vector< Integer > Utilities::reverse_permutation ( const std::vector< Integer > &  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\).

Definition at line 1667 of file utilities.h.

◆ invert_permutation()

template<typename Integer >
std::vector< Integer > Utilities::invert_permutation ( const std::vector< Integer > &  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\).

Definition at line 1682 of file utilities.h.

◆ pack() [1/2]

template<typename T >
size_t Utilities::pack ( const T &  object,
std::vector< char > &  dest_buffer,
const bool  allow_compression = true 
)

Given an arbitrary object of type T, use boost::serialization utilities to pack the object into a vector of characters and append it to the given buffer. The number of elements that have been added to the buffer will be returned. The object can be unpacked using the Utilities::unpack function below.

If the library has been compiled with ZLIB enabled, then the output buffer can be compressed. This can be triggered with the parameter allow_compression, and is only of effect if ZLIB is enabled.

If many consecutive calls with the same buffer are considered, it is recommended for reasons of performance to ensure that its capacity is sufficient.

This function considers a number of special cases for which packing (and unpacking) can be simplified. These are:

  • If the object of type T is relatively small (less than 256 bytes) and if T satisfies std::is_trivially_copyable, then it is copied bit by bit into the output buffer.
  • If no compression is requested, and if the object is a vector of objects whose type T satisfies std::is_trivially_copyable, then packing implies copying the length of the vector into the destination buffer followed by a bit-by-bit copy of the contents of the vector. A similar process is used for vectors of vectors of objects whose type T satisfies std::is_trivially_copyable.
  • Finally, if the type T of the object to be packed is std::tuple<> (i.e., a tuple without any elements as indicated by the empty argument list) and if no compression is requested, then this type is considered an "empty" type and it is packed into a zero byte buffer. Using empty types is occasionally useful when sending messages to other processes if the important part about the message is that it is sent, not what it contains – in other words, it puts the receiver on notice of something, without having to provide any details. In such cases, it is helpful if the message body can be empty – that is, have length zero – and using std::tuple<> facilitates this by providing a type which the present function packs into an empty output buffer, given that many deal.II functions send objects only after calling pack() to serialize them.

In several of the special cases above, the std::is_trivially_copyable property is important, see https://en.cppreference.com/w/cpp/types/is_trivially_copyable . For a type T to satisfy this property essentially means that an object t2 of this type can be initialized by copying another object t1 bit-by-bit into the memory space of t2. In particular, this is the case for built-in types such as int, double, or char, as well as structures and classes that only consist of such types and that have neither user-defined constructors nor virtual functions. In practice, and together with the fact that vectors and vector-of-vectors of these types are also special-cased, this covers many of the most common kinds of messages one sends around with MPI or one wants to serialize (the two most common use cases for this function).

Definition at line 1364 of file utilities.h.

◆ pack() [2/2]

template<typename T >
std::vector< char > Utilities::pack ( const T &  object,
const bool  allow_compression = true 
)

Creates and returns a buffer solely for the given object, using the above mentioned pack function (including all of its special cases).

If the library has been compiled with ZLIB enabled, then the output buffer can be compressed. This can be triggered with the parameter allow_compression, and is only of effect if ZLIB is enabled.

Definition at line 1439 of file utilities.h.

◆ unpack() [1/4]

template<typename T >
T Utilities::unpack ( const std::vector< char > &  buffer,
const bool  allow_compression = true 
)

Given a vector of characters, obtained through a call to the function Utilities::pack, restore its content in an object of type T.

This function uses boost::serialization utilities to unpack the object from a vector of characters, and it is the inverse of the function Utilities::pack(). It considers the same set of special cases as documented with the pack() function.

The allow_compression parameter denotes if the buffer to read from could have been previously compressed with ZLIB, and is only of effect if ZLIB is enabled.

Note
Since no arguments to this function depend on the template type T, you must manually specify the template argument when calling this function.
If you want to pack() or unpack() arrays of objects, then the following works:
double array[3] = {1,2,3};
std::vector<char> buffer = Utilities::pack(array);
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
Definition utilities.h:1364
However, the converse does not:
array = Utilities::unpack<double[3]>(buffer);
This is because C++ does not allow functions to return arrays. Consequently, there is a separate unpack() function for arrays, see below.

Definition at line 1521 of file utilities.h.

◆ unpack() [2/4]

template<typename T >
T Utilities::unpack ( const std::vector< char >::const_iterator &  cbegin,
const std::vector< char >::const_iterator &  cend,
const bool  allow_compression = true 
)

Same unpack function as above, but takes constant iterators on (a fraction of) a given packed buffer of type std::vector<char> instead.

The allow_compression parameter denotes if the buffer to read from could have been previously compressed with ZLIB, and is only of effect if ZLIB is enabled.

Definition at line 1450 of file utilities.h.

◆ unpack() [3/4]

template<typename T , int N>
void Utilities::unpack ( const std::vector< char > &  buffer,
T(&)  unpacked_object[N],
const bool  allow_compression = true 
)

Given a vector of characters, obtained through a call to the function Utilities::pack, restore its content in an array of type T.

This function uses boost::serialization utilities to unpack the object from a vector of characters, and it is the inverse of the function Utilities::pack().

The allow_compression parameter denotes if the buffer to read from could have been previously compressed with ZLIB, and is only of effect if ZLIB is enabled.

Note
This function exists due to a quirk of C++. Specifically, if you want to pack() or unpack() arrays of objects, then the following works:
double array[3] = {1,2,3};
std::vector<char> buffer = Utilities::pack(array);
However, the converse does not:
array = Utilities::unpack<double[3]>(buffer);
This is because C++ does not allow functions to return arrays. The current function therefore allows to write
Utilities::unpack(buffer, array);
T unpack(const std::vector< char > &buffer, const bool allow_compression=true)
Definition utilities.h:1521
Note that unlike the other unpack() function, it is not necessary to explicitly specify the template arguments since they can be deduced from the second argument.

Definition at line 1563 of file utilities.h.

◆ unpack() [4/4]

template<typename T , int N>
void Utilities::unpack ( const std::vector< char >::const_iterator &  cbegin,
const std::vector< char >::const_iterator &  cend,
T(&)  unpacked_object[N],
const bool  allow_compression = true 
)

Same unpack function as above, but takes constant iterators on (a fraction of) a given packed buffer of type std::vector<char> instead.

The allow_compression parameter denotes if the buffer to read from could have been previously compressed with ZLIB, and is only of effect if ZLIB is enabled.

Definition at line 1529 of file utilities.h.

◆ get_bit()

bool Utilities::get_bit ( const unsigned char  number,
const unsigned int  n 
)
inline

Check if the bit at position n in number is set.

Definition at line 1576 of file utilities.h.

◆ set_bit()

void Utilities::set_bit ( unsigned char &  number,
const unsigned int  n,
const bool  x 
)
inline

Set the bit at position n in number to value x.

Definition at line 1589 of file utilities.h.

◆ dynamic_unique_cast()

template<typename To , typename From >
std::unique_ptr< To > Utilities::dynamic_unique_cast ( std::unique_ptr< From > &&  p)
inline

Convert an object of type std::unique_ptr<From> to an object of type std::unique_ptr<To>, where it is assumed that we can cast the pointer to From to a pointer to To using a dynamic_cast – in other words, we assume that From and To are connected through a class hierarchy, and that the object pointed to is in fact of a type that contains both a From and a To. An example is if either To is derived from From or the other way around.

The function throws an exception of type std::bad_cast if the dynamic_cast does not succeed. This is the same exception you would get if a regular dynamic_cast between object types (but not pointer types) does not succeed.

An example of how this function works is as follows:

// A base class. Assume that it has virtual
// functions so that dynamic_cast can work.
class B
{
...
};
// A derived class
class D : public B
{
...
};
// A factory function
std::unique_ptr<B> create_object (...)
{
...
}
void foo (...)
{
std::unique_ptr<B> b = create_object (...);
// Assume that we know for some reason that the object above must
// have created a D object but returned it as a std::unique_ptr<B>.
// In order to access the D functionality, we need to cast the
// pointer. Use the equivalent to dynamic_cast:
std::unique_ptr<D> d = dynamic_unique_cast<D>(std::move(b));
// If the object really was a D, then 'd' now points to it. Note
// also that in accordance with the semantics of std::unique_ptr,
// it was necessary to std::move the 'b' object, and indeed 'b'
// now no longer points to anything -- ownership has been
// transferred to 'd'!
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
Note
This function does not try to convert the Deleter objects stored by std::unique_ptr objects. The function therefore only works if the deleter objects are at their defaults, i.e., if they are of type std::default_delete<To> and std::default_delete<From>.

Definition at line 1603 of file utilities.h.

◆ get_underlying_value() [1/5]

template<typename T >
T & Utilities::get_underlying_value ( T &  p)
inline

Return underlying value. Default: return input.

Definition at line 1622 of file utilities.h.

◆ get_underlying_value() [2/5]

template<typename T >
T & Utilities::get_underlying_value ( std::shared_ptr< T > &  p)
inline

Return underlying value. Specialization for std::shared_ptr<T>.

Definition at line 1631 of file utilities.h.

◆ get_underlying_value() [3/5]

template<typename T >
T & Utilities::get_underlying_value ( const std::shared_ptr< T > &  p)
inline

Return underlying value. Specialization for const std::shared_ptr<T>.

Definition at line 1640 of file utilities.h.

◆ get_underlying_value() [4/5]

template<typename T >
T & Utilities::get_underlying_value ( std::unique_ptr< T > &  p)
inline

Return underlying value. Specialization for std::unique_ptr<T>.

Definition at line 1649 of file utilities.h.

◆ get_underlying_value() [5/5]

template<typename T >
T & Utilities::get_underlying_value ( const std::unique_ptr< T > &  p)
inline

Return underlying value. Specialization for const std::unique_ptr<T>.

Definition at line 1658 of file utilities.h.

◆ compute_remote_communicator_faces_point_to_point_interpolation()

template<int dim, typename Number , typename VectorizedArrayType = VectorizedArray<Number>>
FERemoteEvaluationCommunicator< dim > Utilities::compute_remote_communicator_faces_point_to_point_interpolation ( const MatrixFree< dim, Number, VectorizedArrayType > &  matrix_free,
const std::vector< std::pair< types::boundary_id, std::function< std::vector< bool >()> > > &  non_matching_faces_marked_vertices,
const unsigned int  quad_no = 0,
const unsigned int  dof_no = 0,
const double  tolerance = 1e-9 
)
private

A factory function for the FERemoteEvaluationCommunicator in the case of point-to-point interpolation.

Parameters
[in]matrix_freeMatrixFree object that is used to distribute quadrature points at non-matching faces. In case of point-to-point interpolation standard quadrature rules are used on faces that are connected to non-matching interfaces.
[in]non_matching_faces_marked_verticesA vector of boundary face IDs that relate to non-matching interfaces. Each boundary face ID is accompanied by a lambda function that marks the vertices of cells to be considered during the search of remote points (quadrature points of faces with given boundary face ID).
[in]quad_noQuadrature number in matrix_free.
[in]dof_noDoFHandler number in matrix_free.
[in]toleranceTolerance to find remote points.

Definition at line 1082 of file fe_remote_evaluation.h.

◆ compute_remote_communicator_faces_nitsche_type_mortaring()

template<int dim, typename Number , typename VectorizedArrayType = VectorizedArray<Number>>
FERemoteEvaluationCommunicator< dim > Utilities::compute_remote_communicator_faces_nitsche_type_mortaring ( const MatrixFree< dim, Number, VectorizedArrayType > &  matrix_free,
const std::vector< std::pair< types::boundary_id, std::function< std::vector< bool >()> > > &  non_matching_faces_marked_vertices,
const unsigned int  n_q_pnts_1D,
const unsigned int  dof_no = 0,
NonMatching::MappingInfo< dim, dim, Number > *  nm_mapping_info = nullptr,
const double  tolerance = 1e-9 
)
private

A factory function for the FERemoteEvaluationCommunicator in the case of Nitsche-type mortaring.

Parameters
[in]matrix_freeMatrixFree object that holds the DoFHandler, associated with the non-matching grid.
[in]non_matching_faces_marked_verticesA vector of boundary face IDs that relate to non-matching interfaces. Each boundary face ID is accompanied by a lambda function that marks the vertices of cells to be considered during the process of computing intersections.
[in]n_q_pnts_1DThe number of 1D quadrature points per intersection.
[in]dof_noDoFHandler number in matrix_free. distributed to each intersection (given for one coordinate direction).
[in]nm_mapping_infoIn case nm_mapping_info is not a nullptr it is set up for cell based loops, such that it can be used in combination with FERemoteEvaluation.
[in]toleranceTolerance to find intersections.

Definition at line 1222 of file fe_remote_evaluation.h.