MoReFEM
Loading...
Searching...
No Matches
Namespaces | Data Structures | Typedefs | Enumerations | Functions
MoReFEM::Utilities Namespace Reference

Namespace that enclose most of the Utilities (some aren't for conveniency, such as NumericNS or FilesystemNS). More...

Namespaces

namespace  ExceptionNS
 Placeholder namespace description needed for it to appear in Doxygen namespace list.
 
namespace  PointerComparison
 Placeholder namespace description needed for it to appear in Doxygen namespace list.
 
namespace  PrintPolicyNS
 Placeholder namespace description needed for it to appear in Doxygen namespace list.
 
namespace  String
 Placeholder namespace description needed for it to appear in Doxygen namespace list.
 
namespace  Tuple
 Placeholder namespace description needed for it to appear in Doxygen namespace list.
 

Data Structures

struct  ArraySize
 Helper struct to return statically the size of an array. More...
 
class  AsciiOrBinary
 Provides a way to specify the output format of the solution vectors corresponding to each unknown. More...
 
class  BoolArray
 A class to handle a dynamic array of bool with some safety. More...
 
struct  ConstRefOrValue
 Yields most adapted return type: by value or by const reference. More...
 
struct  ContainerHash
 Struct used to generate a hash key for a container with a direct accessor. More...
 
class  CSRPattern
 Objects that store information about the CSR pattern of a sparse matrix. More...
 
class  Environment
 Provides access to shell environment variables and also some internal data that act likewise. More...
 
struct  IsSharedPtr
 Determines whether an object is a shared_ptr or not. More...
 
struct  IsSpecializationOf
 Yields true_type if T is a specialization of Template. More...
 
struct  IsSpecializationOf< Template, Template< Args... > >
 
struct  IsSpecializationOfInt
 
struct  IsSpecializationOfInt< Template, Template< N > >
 
struct  IsUniquePtr
 Determines whether an object is a unique_ptr or not. More...
 
struct  PrintContainer
 Print the content of a container (that might be associative or not - see PrintPolicyT). More...
 
class  Singleton
 Provides part of the singleton interface to T through a CRTP. More...
 
struct  StaticCast
 A slightly extended static_cast. More...
 
struct  Type2Type
 Create an hollow object that might be useful to mimic template function overloading. More...
 

Typedefs

template<class T >
using const_ref_or_nullopt = std::optional<std::reference_wrapper<const T>>
 Convenient alias when an argument is either (almost) const T& or std::nullopt.
 
template<class T >
using ref_or_nullopt = std::optional<std::reference_wrapper<T>>
 Convenient alias when an argument is either (almost) T& or std::nullopt.
 

Enumerations

enum class  Access { read_only , read_and_write }
 Enum used to enforce constness in third party libraries that didn't do it natively. More...
 

Functions

template<class ItemPtrT , std::size_t N>
std::array< ItemPtrT, N > NullptrArray ()
 Function to set to nullptr all the content of a defined array.
 
template<class T , std::size_t N>
std::array< T, N > FilledWithUninitializedIndex ()
 Init an array with NumericNS::UninitializedIndex for all of its elements.
 
std::vector< bool > VectorFromBoolArray (const BoolArray &array)
 Create a std::vector<bool> with the same content as array object.
 
template<::MoReFEM::Concept::Tuple TupleT, typename StreamT = std::ostream>
void PrintTuple (const TupleT &tuple, StreamT &stream=std::cout, PrintNS::Delimiter::separator separator=PrintNS::Delimiter::separator(", "), PrintNS::Delimiter::opener opener=PrintNS::Delimiter::opener("["), PrintNS::Delimiter::closer closer=PrintNS::Delimiter::closer("]\n"))
 Print the content of a tuple or a pair.
 
template<class T , class FirstCriterionT , typename... OtherCriteriaT>
bool Sort (const T &lhs, const T &rhs)
 Defines the ordering of two different objects.
 
constexpr float DefaultMaxLoadFactor () noexcept
 Value of std::unordered_map::max_load_factor() that is recommended in "The C++ Standard Library" by N. Josuttis.
 
template<class T >
std::size_t HashCombine (std::size_t &seed, const T &value)
 Function lifted from Boost (http://www.boost.org) to combine several hash keys together.
 
template<class T >
void EliminateDuplicate (std::vector< T > &vector)
 Sort a std::vector and delete the possible duplicates.
 
template<class T , class ComparePredicateT , class EqualPredicateT >
void EliminateDuplicate (std::vector< T > &vector, ComparePredicateT comp, EqualPredicateT equal)
 Sort a std::vector and delete the possible duplicates.
 
std::string Now (const Wrappers::Mpi &mpi)
 Write the current date in format 'YYYY-MM-DD_HH:MM:SS'.
 
template<class PointerT >
IGNORE_BLOCK_IN_DOXYGEN bool IsNullptr (const PointerT &pointer)
 A trivial function to check whether a pointer is nullptr or not.
 
const std::string & EmptyString ()
 Returns a reference to a static empty string.
 

Detailed Description

Namespace that enclose most of the Utilities (some aren't for conveniency, such as NumericNS or FilesystemNS).

Enumeration Type Documentation

◆ Access

enum class MoReFEM::Utilities::Access
strong

Enum used to enforce constness in third party libraries that didn't do it natively.

It is currently used in Petsc::AccessVectorContent for instance.

Function Documentation

◆ NullptrArray()

template<class ItemPtrT , std::size_t N>
std::array< ItemPtrT, N > MoReFEM::Utilities::NullptrArray ( )

Function to set to nullptr all the content of a defined array.

e.g.

std::array<GlobalVector::unique_ptr, 5> = Utilities::NullptrArray<GlobalVector::unique_ptr, 5>();

in a class declaration of data attribute will init it with 5 nullptr.

Returns
Array which includes N nullptr terms.

◆ FilledWithUninitializedIndex()

template<class T , std::size_t N>
std::array< T, N > MoReFEM::Utilities::FilledWithUninitializedIndex ( )

Init an array with NumericNS::UninitializedIndex for all of its elements.

Template Parameters
TAn integral type.
NSize of the array.

◆ VectorFromBoolArray()

std::vector< bool > MoReFEM::Utilities::VectorFromBoolArray ( const BoolArray & array)

Create a std::vector<bool> with the same content as array object.

Parameters
[in]arrayThe BoolArray object.
Returns
The newly-minter std::vector.

◆ PrintTuple()

template<::MoReFEM::Concept::Tuple TupleT, typename StreamT = std::ostream>
void MoReFEM::Utilities::PrintTuple ( const TupleT & tuple,
StreamT & stream = std::cout,
PrintNS::Delimiter::separator separator = PrintNS::Delimiter::separator(", "),
PrintNS::Delimiter::opener opener = PrintNS::Delimiter::opener("["),
PrintNS::Delimiter::closer closer = PrintNS::Delimiter::closer("]\n") )

Print the content of a tuple or a pair.

Inspired by Nicolai M. Josuttis "The C++ standard library" page 74.

Template Parameters
StreamTType of output stream considered
Parameters
[in,out]streamOutput stream in which tuple content will be displayed. All tuple elements must define operator<<.
[in]tupleTuple which content is displayed.
[in]separatorSeparator between two entries of the tuple.
[in]openerPrefix used while displaying the tuple.
[in]closerSuffix used while displaying the tuple.

◆ Sort()

template<class T , class FirstCriterionT , typename... OtherCriteriaT>
bool MoReFEM::Utilities::Sort ( const T & lhs,
const T & rhs )

Defines the ordering of two different objects.

Template Parameters
TType of the objects.
FirstCriterionTFirst criterion to be considered to sort both objects. If the criterion is enough to make a difference between both objects, result is returned. A criterion object must provide:
  • A static method Value() which returns something (let's name this type U) and take as argument a T::shared_ptr.
  • A binary comparison operator StrictOrderingOperator which acts upon two U types object.
OtherCriteriaTIf first criterion isn't enough, iterate through OtherCriteriaT until one criterion is able to separate both objects, or until all criteria have been tried.

An example is probably the best way to explain the purpose of sort.

class ClassToSort
{
[...]
public:
int FirstMethod() const;
std::string SecondMethod() const;
};
template<class ComparisonT = std::less<int>>
struct SortCriterion1
{
static int Value(const ClassToSort& elem)
{
return elem.Method1();
}
*using StrictOrderingOperator = ComparisonT;
};
template<class ComparisonT = std::less<std::string>>
struct SortCriterion2
{
static std::string Value(const ClassToSort& elem)
{
return elem.Method2();
}
using StrictOrderingOperator = ComparisonT;
};
std::vector<ClassToSort> list_of_objects;
[... fill list of objects ...]
// Sort the objects with criterion1 as primary criterion and criterion2 as secondary criterion.
std::stable_sort(list_of_objects.begin(), list_of_objects.end(), Sort<ClassToSort, SortCriterion1<>,
SortCriterion2<>);
// Sort the objects with criterion2 as primary criterion and criterion1 as secondary criterion.
. // Consider decreasing order for criterion 1.
std::stable_sort(list_of_objects.begin(), list_of_objects.end(), Sort<ClassToSort, SortCriterion2<>,
SortCriterion1<std::greater<int>>);
bool Sort(const T &lhs, const T &rhs)
Defines the ordering of two different objects.
Definition Sort.hpp:102

As variadic template is used, more than 2 criteria might be used (as many as you like in fact).

Parameters
[in]lhsLeft-hand side.
[in]rhsRight-hand side.
Returns
True if lhs is before rhs with respect to all sort criteria.

◆ DefaultMaxLoadFactor()

constexpr float MoReFEM::Utilities::DefaultMaxLoadFactor ( )
constexprnoexcept

Value of std::unordered_map::max_load_factor() that is recommended in "The C++ Standard Library" by N. Josuttis.

Returns
0.7 (either that or .8 was suggested).

◆ HashCombine()

template<class T >
std::size_t MoReFEM::Utilities::HashCombine ( std::size_t & seed,
const T & value )

Function lifted from Boost (http://www.boost.org) to combine several hash keys together.

Apparently this formula stems from Knuth's work.

For instance to yield a hash key for a std::pair<std::size_t, std::size_t>:

std::pair<std::size_t, std::size_t> pair;
...
std::size_t key = std::hash<std::size_t>()(pair.first);
Utilities::HashCombine(key, pair.second);
std::size_t HashCombine(std::size_t &seed, const T &value)
Function lifted from Boost (http://www.boost.org) to combine several hash keys together.
Template Parameters
TType for which a std::hash specialization already exists.
Parameters
[in,out]seedIn input current value of the hash; in output modified value.
[in]valueNew element which hash key is combined to the seed to provide a new has key.
Returns
seed after the modification.

◆ EliminateDuplicate() [1/2]

template<class T >
void MoReFEM::Utilities::EliminateDuplicate ( std::vector< T > & vector)

Sort a std::vector and delete the possible duplicates.

Template Parameters
TType of the data stored within the std::vector.
Parameters
[in,out]vectorVector which should be sort and from which duplicates should be removed.

This version uses default comparison (less) and equality (==) predicates.

◆ EliminateDuplicate() [2/2]

template<class T , class ComparePredicateT , class EqualPredicateT >
void MoReFEM::Utilities::EliminateDuplicate ( std::vector< T > & vector,
ComparePredicateT comp,
EqualPredicateT equal )

Sort a std::vector and delete the possible duplicates.

Template Parameters
TType of the data stored within the std::vector.
Parameters
[in,out]vectorVector which should be sort and from which duplicates should be removed.
Template Parameters
ComparePredicateTFunctor used to compare two values of the vector.
EqualPredicateTPredicate used to determine two quantities are equal.
Parameters
[in]compBinary functor used to sort two values.
[in]equalPredicate to use to determine whether two values are equal.

◆ Now()

std::string MoReFEM::Utilities::Now ( const Wrappers::Mpi & mpi)

Write the current date in format 'YYYY-MM-DD_HH:MM:SS'.

Parameters
[in]mpiThe mpi facility. Current function is there to tag output directories, so we do not want a mismatcch among ranks due to slightly different time. So root processor transmits its time to all ranks.
Returns
The string at the format specified above.

I could probably have used std::chrono library, but I'm not very familiar with it and lots of features (including some that I think would do in a breeze what this function does) are set to appear in C++20.

◆ IsNullptr()

template<class PointerT >
IGNORE_BLOCK_IN_DOXYGEN bool MoReFEM::Utilities::IsNullptr ( const PointerT & pointer)
inline

A trivial function to check whether a pointer is nullptr or not.

[internal] The point is just to avoid a lambda in algorithms... [internal] Argument is a const reference to make it work also for unique_ptr...

Template Parameters
PointerTType of the variable being scrutinized; it must be a pointer or a pointer-like type (currently only pointer or shared/unique smart pointers may be used in this function).
Parameters
[in]pointerPointer or pointer-like variable being under investigation.
Returns
True if pointer is equal to nullptr.

◆ EmptyString()

const std::string & MoReFEM::Utilities::EmptyString ( )

Returns a reference to a static empty string.

Returns
""