preCICE v3.1.1
Loading...
Searching...
No Matches
Namespaces | Classes | Functions | Variables
precice::utils Namespace Reference

contains precice-related utilities. More...

Namespaces

namespace  eigenio
 
namespace  networking
 
namespace  petsc
 PETSc related utilities.
 
namespace  statistics
 

Classes

struct  ComponentWiseLess
 
struct  conjunction
 
struct  conjunction< B1 >
 
struct  conjunction< B1, Bn... >
 
class  DoubleAggregator
 An accurate aggregator for doubles with usability in mind. More...
 
struct  IndexMaps
 Provides mappings of indices for dimensions 2 and 3. More...
 
struct  IndexMaps< 2 >
 
struct  IndexMaps< 3 >
 
class  IntraComm
 Utility class for managing intra-participant communication operations. More...
 
class  LockNotFoundException
 
class  ManageUniqueIDs
 Manages a set of unique IDs. More...
 
struct  MPIResult
 
class  MultiLock
 Class handling multiple locks allowing global lock and unlock operations. More...
 
class  MultiLockException
 
class  Parallel
 Utility class for managing MPI operations. More...
 
class  Petsc
 Utility class for managing PETSc operations. More...
 
struct  RangePreview
 The RangePreview object used as a lazy proxy struct for proviewing the content of a Range. More...
 
class  StringMaker
 Utility class to build a string from C functions with output pointers and static maximum length. More...
 
struct  StringMatch
 
struct  transform
 
struct  type_transform
 

Functions

template<class InputIt1 , class InputIt2 , class OutputIt >
void set_intersection_indices (InputIt1 ref1, InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first)
 This function is by and large the same as std::set_intersection(). The only difference is that we don't return the intersection set itself, but we return the indices of elements in InputIt1, which appear in both sets ( InputIt1 and InputIt2 ) The implementation was taken from https://en.cppreference.com/w/cpp/algorithm/set_intersection#Version_1 with the only difference that we compute and store std::distance() (i.e. the indices) in the output iterator. Similar to the std function, this function operates on sorted ranges.
 
template<typename... Elements>
auto make_array (Elements &&... elements) -> std::array< typename std::common_type< Elements... >::type, sizeof...(Elements)>
 Function that generates an array from given elements.
 
template<typename Container , typename BinaryPredicate = std::equal_to<typename Container::value_type>>
bool unique_elements (const Container &c, BinaryPredicate p={})
 
template<class InputIter , class ElementType >
void intersperse (InputIter first, InputIter last, const ElementType &elem, std::ostream &out)
 
template<class InputIt1 , class InputIt2 >
std::pair< InputIt1, InputIt2 > mismatch (InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
 
template<typename Iter >
std::ostreamoperator<< (std::ostream &out, const RangePreview< Iter > &rp)
 Allows streaming of RangePreview objects.
 
template<typename Range , typename Iter = typename Range::const_iterator, typename Size = typename std::iterator_traits<Iter>::difference_type>
const RangePreview< Iter > previewRange (Size n, const Range &range)
 
template<typename T , typename Index , size_t n>
auto reorder_array (const std::array< Index, n > &order, const std::array< T, n > &elements) -> std::array< T, n >
 Reorders an array given an array of unique indices.
 
template<class InputIt , class Size , class InOutIt >
void add_n (InputIt first, Size count, InOutIt result)
 
template<class InputIt , class Unary >
void for_each_unique (InputIt first, InputIt last, Unary func)
 Calls each value in the range of [first, last[ exactly once.
 
template<class InputIt , class Predicate >
std::pair< InputIt, InputIt > find_first_range (InputIt first, InputIt last, Predicate p)
 Finds the first range in [first, last[ that fulfills a predicate.
 
const Eigen::VectorXd & delinearize (int toDelinearize, int dimensions)
 
template<typename VECTOR_T >
int linearize (const VECTOR_T &toLinearize)
 
DoubleAggregator operator+ (double lhs, DoubleAggregator rhs)
 
DoubleAggregator operator+ (DoubleAggregator lhs, double rhs)
 
DoubleAggregator operator- (DoubleAggregator lhs, double rhs)
 
void shiftSetFirst (Eigen::MatrixXd &A, const Eigen::VectorXd &v)
 
void appendFront (Eigen::MatrixXd &A, Eigen::VectorXd &v)
 
void removeColumnFromMatrix (Eigen::MatrixXd &A, int col)
 
void append (Eigen::VectorXd &v, double value)
 
template<typename Derived1 >
void append (Eigen::MatrixXd &A, const Eigen::PlainObjectBase< Derived1 > &B)
 
template<typename Derived1 >
void append (Eigen::VectorXd &v, const Eigen::PlainObjectBase< Derived1 > &app)
 
template<typename Derived >
auto firstN (const Eigen::PlainObjectBase< Derived > &val, unsigned n) -> const Eigen::Map< const Eigen::Matrix< typename Derived::Scalar, 1, Eigen::Dynamic > >
 
template<typename Derived , typename Iter = const typename Derived::Scalar *, typename Size = typename std::iterator_traits<Iter>::difference_type>
const RangePreview< Iter > previewRange (Size n, const Eigen::PlainObjectBase< Derived > &eigen)
 
template<typename DerivedLHS , typename DerivedRHS >
bool componentWiseLess (const Eigen::PlainObjectBase< DerivedLHS > &lhs, const Eigen::PlainObjectBase< DerivedRHS > &rhs)
 
std::string format_or_error (std::string_view str)
 
template<class... A>
std::string format_or_error (std::string_view fmt, A &&... args)
 
bool isMachineBigEndian ()
 Returns true if machine is big-endian needed for parallel vtk output.
 
template<class Out , class In >
bool isTruncated (In in)
 Returns true, if numerical truncation happens in case of type conversion.
 
bool isValidPort (int port)
 Returns true if the argument represents a valid port.
 
bool xOR (bool lhs, bool rhs)
 Exclusive "or" logical operation. Returns true, if either lhs or rhs are true.
 
template<typename ELEMENT_T >
bool contained (const ELEMENT_T &element, const std::vector< ELEMENT_T > &vec)
 Returns true, if given element is in vector, otherwise false.
 
template<typename KEY_T , typename ELEMENT_T >
bool contained (const KEY_T &key, const std::map< KEY_T, ELEMENT_T > &map)
 
template<typename KEY_T >
bool contained (const KEY_T &key, const std::set< KEY_T > &set)
 
template<class... Arguments>
void ignore (Arguments &&...)
 
std::ostreamoperator<< (std::ostream &out, const Parallel::CommState &value)
 pretty printer for CommState
 
std::string wrapText (const std::string &text, int linewidth, int indentation)
 
std::stringcheckAppendExtension (std::string &filename, const std::string &extension)
 Checks if filename has the given extension, if not appends it.
 
bool convertStringToBool (std::string const &value)
 Evaluates a string to find out if it represents a bool.
 
std::string truncate_wstring_to_string (std::wstring wstr, char fill)
 
std::size_t editDistance (std::string_view s1, std::string_view s2)
 
template<class Container >
std::vector< StringMatchcomputeMatches (std::string_view given, const Container &expected)
 
std::string getTypeName (const double &var)
 
std::string getTypeName (const std::string &var)
 
std::string getTypeName (const bool &var)
 
std::string getTypeName (const int &var)
 
std::string getTypeName (Eigen::VectorXd const &var)
 

Variables

static constexpr std::string_view ASSERT_FMT
 
const Eigen::VectorXd DELINEARIZE_2D [8]
 
const Eigen::VectorXd DELINEARIZE_3D [8]
 

Detailed Description

contains precice-related utilities.

Function Documentation

◆ add_n()

template<class InputIt , class Size , class InOutIt >
void precice::utils::add_n ( InputIt first,
Size count,
InOutIt result )

Definition at line 191 of file algorithm.hpp.

Here is the call graph for this function:

◆ append() [1/3]

template<typename Derived1 >
void precice::utils::append ( Eigen::MatrixXd & A,
const Eigen::PlainObjectBase< Derived1 > & B )

Definition at line 21 of file EigenHelperFunctions.hpp.

◆ append() [2/3]

template<typename Derived1 >
void precice::utils::append ( Eigen::VectorXd & v,
const Eigen::PlainObjectBase< Derived1 > & app )

Definition at line 37 of file EigenHelperFunctions.hpp.

◆ append() [3/3]

void precice::utils::append ( Eigen::VectorXd & v,
double value )

Definition at line 48 of file EigenHelperFunctions.cpp.

◆ appendFront()

void precice::utils::appendFront ( Eigen::MatrixXd & A,
Eigen::VectorXd & v )

Definition at line 22 of file EigenHelperFunctions.cpp.

◆ checkAppendExtension()

std::string & precice::utils::checkAppendExtension ( std::string & filename,
const std::string & extension )

Checks if filename has the given extension, if not appends it.

Returns
filename with extension.

Definition at line 44 of file String.cpp.

Here is the call graph for this function:

◆ componentWiseLess()

template<typename DerivedLHS , typename DerivedRHS >
bool precice::utils::componentWiseLess ( const Eigen::PlainObjectBase< DerivedLHS > & lhs,
const Eigen::PlainObjectBase< DerivedRHS > & rhs )

Definition at line 73 of file EigenHelperFunctions.hpp.

◆ computeMatches()

template<class Container >
std::vector< StringMatch > precice::utils::computeMatches ( std::string_view given,
const Container & expected )

Definition at line 95 of file String.hpp.

Here is the call graph for this function:

◆ contained() [1/3]

template<typename ELEMENT_T >
bool precice::utils::contained ( const ELEMENT_T & element,
const std::vector< ELEMENT_T > & vec )

Returns true, if given element is in vector, otherwise false.

Requirements:

  • ELEMENT_T must be comparable by ==

Definition at line 39 of file Helpers.hpp.

Here is the call graph for this function:

◆ contained() [2/3]

template<typename KEY_T , typename ELEMENT_T >
bool precice::utils::contained ( const KEY_T & key,
const std::map< KEY_T, ELEMENT_T > & map )

Definition at line 45 of file Helpers.hpp.

Here is the call graph for this function:

◆ contained() [3/3]

template<typename KEY_T >
bool precice::utils::contained ( const KEY_T & key,
const std::set< KEY_T > & set )

Definition at line 53 of file Helpers.hpp.

Here is the call graph for this function:

◆ convertStringToBool()

bool precice::utils::convertStringToBool ( std::string const & value)

Evaluates a string to find out if it represents a bool.

Returns True if string is yes, true, 1 or on. Otherwise False. This function is case-insensitive.

Definition at line 55 of file String.cpp.

◆ delinearize()

const Eigen::VectorXd & precice::utils::delinearize ( int toDelinearize,
int dimensions )

Definition at line 24 of file Dimensions.cpp.

◆ editDistance()

std::size_t precice::utils::editDistance ( std::string_view s1,
std::string_view s2 )

Definition at line 78 of file String.cpp.

Here is the call graph for this function:

◆ find_first_range()

template<class InputIt , class Predicate >
std::pair< InputIt, InputIt > precice::utils::find_first_range ( InputIt first,
InputIt last,
Predicate p )

Finds the first range in [first, last[ that fulfills a predicate.

Definition at line 212 of file algorithm.hpp.

Here is the call graph for this function:

◆ firstN()

template<typename Derived >
auto precice::utils::firstN ( const Eigen::PlainObjectBase< Derived > & val,
unsigned n ) -> const Eigen::Map<const Eigen::Matrix<typename Derived::Scalar, 1, Eigen::Dynamic>>

Maps the first at most n values of an Eigen object to a row vector

Parameters
[in]valthe Eigen object to map from
Returns
the mapped const row vector

Definition at line 58 of file EigenHelperFunctions.hpp.

◆ for_each_unique()

template<class InputIt , class Unary >
void precice::utils::for_each_unique ( InputIt first,
InputIt last,
Unary func )

Calls each value in the range of [first, last[ exactly once.

Definition at line 198 of file algorithm.hpp.

Here is the call graph for this function:

◆ format_or_error() [1/2]

template<class... A>
std::string precice::utils::format_or_error ( std::string_view fmt,
A &&... args )

Definition at line 25 of file fmt.hpp.

◆ format_or_error() [2/2]

std::string precice::utils::format_or_error ( std::string_view str)
inline

Definition at line 19 of file fmt.hpp.

◆ getTypeName() [1/5]

std::string precice::utils::getTypeName ( const bool & var)
inline

Definition at line 25 of file TypeNames.hpp.

◆ getTypeName() [2/5]

std::string precice::utils::getTypeName ( const double & var)
inline

Definition at line 15 of file TypeNames.hpp.

◆ getTypeName() [3/5]

std::string precice::utils::getTypeName ( const int & var)
inline

Definition at line 30 of file TypeNames.hpp.

◆ getTypeName() [4/5]

std::string precice::utils::getTypeName ( const std::string & var)
inline

Definition at line 20 of file TypeNames.hpp.

◆ getTypeName() [5/5]

std::string precice::utils::getTypeName ( Eigen::VectorXd const & var)
inline

Definition at line 35 of file TypeNames.hpp.

◆ ignore()

template<class... Arguments>
void precice::utils::ignore ( Arguments && ...)

Ignores all inputs to prevent warnings about unused variables

Don't worry compiers will optimize this and unneeded arguments away even at -O1.

Definition at line 10 of file ignore.hpp.

◆ intersperse()

template<class InputIter , class ElementType >
void precice::utils::intersperse ( InputIter first,
InputIter last,
const ElementType & elem,
std::ostream & out )

intersperse a the range [first, last[ with a given element.

This results in a range [first, elem, first+1, elem, ... , elem, last[

Template Parameters
InputIterthe type of the input iterators
ElementTypethe type of the element to intersperse

Definition at line 93 of file algorithm.hpp.

◆ isMachineBigEndian()

bool precice::utils::isMachineBigEndian ( )

Returns true if machine is big-endian needed for parallel vtk output.

Definition at line 5 of file Helpers.cpp.

◆ isTruncated()

template<class Out , class In >
bool precice::utils::isTruncated ( In in)
inline

Returns true, if numerical truncation happens in case of type conversion.

Definition at line 14 of file Helpers.hpp.

◆ isValidPort()

bool precice::utils::isValidPort ( int port)
inline

Returns true if the argument represents a valid port.

Definition at line 21 of file Helpers.hpp.

◆ linearize()

template<typename VECTOR_T >
int precice::utils::linearize ( const VECTOR_T & toLinearize)

Definition at line 13 of file Dimensions.hpp.

Here is the call graph for this function:

◆ make_array()

template<typename... Elements>
auto precice::utils::make_array ( Elements &&... elements) -> std::array<typename std::common_type<Elements...>::type, sizeof...(Elements)>

Function that generates an array from given elements.

Definition at line 51 of file algorithm.hpp.

◆ mismatch()

template<class InputIt1 , class InputIt2 >
std::pair< InputIt1, InputIt2 > precice::utils::mismatch ( InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
InputIt2 last2 )

std::mismatch

Todo

Definition at line 109 of file algorithm.hpp.

Here is the call graph for this function:

◆ operator+() [1/2]

DoubleAggregator precice::utils::operator+ ( double lhs,
DoubleAggregator rhs )
inline

Definition at line 55 of file DoubleAggregator.hpp.

Here is the call graph for this function:

◆ operator+() [2/2]

DoubleAggregator precice::utils::operator+ ( DoubleAggregator lhs,
double rhs )
inline

Definition at line 61 of file DoubleAggregator.hpp.

Here is the call graph for this function:

◆ operator-()

DoubleAggregator precice::utils::operator- ( DoubleAggregator lhs,
double rhs )
inline

Definition at line 67 of file DoubleAggregator.hpp.

Here is the call graph for this function:

◆ operator<<() [1/2]

std::ostream & precice::utils::operator<< ( std::ostream & out,
const Parallel::CommState & value )

pretty printer for CommState

Definition at line 310 of file Parallel.cpp.

Here is the call graph for this function:

◆ operator<<() [2/2]

template<typename Iter >
std::ostream & precice::utils::operator<< ( std::ostream & out,
const RangePreview< Iter > & rp )

Allows streaming of RangePreview objects.

Definition at line 162 of file algorithm.hpp.

Here is the call graph for this function:

◆ previewRange() [1/2]

template<typename Derived , typename Iter = const typename Derived::Scalar *, typename Size = typename std::iterator_traits<Iter>::difference_type>
const RangePreview< Iter > precice::utils::previewRange ( Size n,
const Eigen::PlainObjectBase< Derived > & eigen )

Definition at line 64 of file EigenHelperFunctions.hpp.

Here is the call graph for this function:

◆ previewRange() [2/2]

template<typename Range , typename Iter = typename Range::const_iterator, typename Size = typename std::iterator_traits<Iter>::difference_type>
const RangePreview< Iter > precice::utils::previewRange ( Size n,
const Range & range )

returns a display object which previews a range

The preview contains the first and last n elements and the minmax-elements.

Definition at line 173 of file algorithm.hpp.

Here is the call graph for this function:

◆ removeColumnFromMatrix()

void precice::utils::removeColumnFromMatrix ( Eigen::MatrixXd & A,
int col )

Definition at line 38 of file EigenHelperFunctions.cpp.

◆ reorder_array()

template<typename T , typename Index , size_t n>
auto precice::utils::reorder_array ( const std::array< Index, n > & order,
const std::array< T, n > & elements ) -> std::array<T, n>

Reorders an array given an array of unique indices.

Definition at line 180 of file algorithm.hpp.

◆ set_intersection_indices()

template<class InputIt1 , class InputIt2 , class OutputIt >
void precice::utils::set_intersection_indices ( InputIt1 ref1,
InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
InputIt2 last2,
OutputIt d_first )

This function is by and large the same as std::set_intersection(). The only difference is that we don't return the intersection set itself, but we return the indices of elements in InputIt1, which appear in both sets ( InputIt1 and InputIt2 ) The implementation was taken from https://en.cppreference.com/w/cpp/algorithm/set_intersection#Version_1 with the only difference that we compute and store std::distance() (i.e. the indices) in the output iterator. Similar to the std function, this function operates on sorted ranges.

Parameters
ref1The reference iterator, to which we compute the distance/indices.
first1The begin of the first range we want to compute the intersection with
last1The end of the first range we want to compute the intersection with
first1The begin of the second range we want to compute the intersection with
last1The end of the second range we want to compute the intersection with
d_firstBeginning of the output range

Definition at line 34 of file algorithm.hpp.

Here is the call graph for this function:

◆ shiftSetFirst()

void precice::utils::shiftSetFirst ( Eigen::MatrixXd & A,
const Eigen::VectorXd & v )

Definition at line 12 of file EigenHelperFunctions.cpp.

◆ truncate_wstring_to_string()

std::string precice::utils::truncate_wstring_to_string ( std::wstring wstr,
char fill = '#' )

Converts a wstring to a string by truncating non-extended ascii characters.

Parameters
[in]wstrthe wide string to convert
[in]fillthe fill char to replace multibyte characters with
Returns
the converted string

Definition at line 65 of file String.cpp.

Here is the call graph for this function:

◆ unique_elements()

template<typename Container , typename BinaryPredicate = std::equal_to<typename Container::value_type>>
bool precice::utils::unique_elements ( const Container & c,
BinaryPredicate p = {} )

Checks weather the given elements contains no duplicates.

Template Parameters
Containertype of the passed container.
BinaryPredicatethe predicate used to compare two elements for equality.
Parameters
cthe container to check for unique elements.
Returns
weather all elements in c are unique.

Definition at line 64 of file algorithm.hpp.

◆ wrapText()

std::string precice::utils::wrapText ( const std::string & text,
int linewidth,
int indentation )

Definition at line 12 of file String.cpp.

Here is the call graph for this function:

◆ xOR()

bool precice::utils::xOR ( bool lhs,
bool rhs )
inline

Exclusive "or" logical operation. Returns true, if either lhs or rhs are true.

Definition at line 27 of file Helpers.hpp.

Variable Documentation

◆ ASSERT_FMT

constexpr std::string_view precice::utils::ASSERT_FMT
staticconstexpr
Initial value:
=
"ASSERTION FAILED\n"
"Location: {}\n"
"File: {}:{}\n"
"Expression: {}\n"
"Rank: {}\n"
"Arguments: {}\n"
"Stacktrace:\n{}\n"

Definition at line 38 of file assertion.hpp.

◆ DELINEARIZE_2D

const Eigen::VectorXd precice::utils::DELINEARIZE_2D[8]
Initial value:
=
{
Eigen::VectorXd(Eigen::Vector2d(-1.0, -1.0)),
Eigen::VectorXd(Eigen::Vector2d(1.0, -1.0)),
Eigen::VectorXd(Eigen::Vector2d(-1.0, 1.0)),
Eigen::VectorXd(Eigen::Vector2d(1.0, 1.0))}

Definition at line 6 of file Dimensions.cpp.

◆ DELINEARIZE_3D

const Eigen::VectorXd precice::utils::DELINEARIZE_3D[8]
Initial value:
=
{
Eigen::VectorXd(Eigen::Vector3d(-1.0, -1.0, -1.0)),
Eigen::VectorXd(Eigen::Vector3d(1.0, -1.0, -1.0)),
Eigen::VectorXd(Eigen::Vector3d(-1.0, 1.0, -1.0)),
Eigen::VectorXd(Eigen::Vector3d(1.0, 1.0, -1.0)),
Eigen::VectorXd(Eigen::Vector3d(-1.0, -1.0, 1.0)),
Eigen::VectorXd(Eigen::Vector3d(1.0, -1.0, 1.0)),
Eigen::VectorXd(Eigen::Vector3d(-1.0, 1.0, 1.0)),
Eigen::VectorXd(Eigen::Vector3d(1.0, 1.0, 1.0))}

Definition at line 13 of file Dimensions.cpp.