Utils

Parameter wrap

This class is used to facilitate parameters read.

class ParametersWrap

A tool to transform a map from string keys to variant parameters.

The input map is typically an input from the python interface.

Public Types

using VarParam = std::variant<real, std::vector<real>, std::vector<real2>, std::string, bool>

A variant that contains the possible types to represent parameters.

using MapParams = std::map<std::string, VarParam>

Represents the map from parameter names to parameter values.

Public Functions

ParametersWrap(const MapParams &params)

Construct a ParametersWrap object from a MapParams.

template <typename T>
bool exists(const std::string &key)

Check if a parameter of a given type and name exists in the map.

Return
true if T and key match, false otherwise.
Template Parameters
  • T: The type of the parameter
Parameters
  • key: The name of the parameter to check

void checkAllRead() const

Die if some keys were not read (see read())

template <typename T>
T read(const std::string &key)

Fetch a parameter value for a given key.

On success, this method will also mark internally the parameter as read. This allows to check if some parameters were never used (see

checkAllRead()).
Template Parameters
  • T: the type of the parameter to read.
Parameters
  • key: the parameter name to read.

This method dies if key does not exist or if T is the wrong type.

StepRandomGen

class StepRandomGen

A random number generator that generates a different number at every time step but returns the same number while the time step is not updated.

Used to generate independant random numbers at every time step. Several calls at the same time step will return the same random number. This is used to keep the interactionssymmetric accross ranks (pairwise particle halo interactions are computed twice, once on each rank. The random seed must therefore be the same and only depend on the time step, not the rank).

Public Functions

StepRandomGen(long seed)

construct a StepRandomGen

Parameters
  • seed: The random seed.

real generate(const MirState *state)

Generates a random number from the current state.

Return
a random number uniformly distributed on [0.001, 1].
Parameters
  • state: The currenst state that contains time step info.

Friends

std::ofstream &operator<<(std::ofstream &stream, const StepRandomGen &gen)

serialization helper

std::ifstream &operator>>(std::ifstream &stream, StepRandomGen &gen)

deserialization helper