Utils

Common helper classes and functions used by plugins.

template <typename ControlType>
class PidControl

PID controller class.

Template Parameters
  • ControlType: The Datatype of the scalar to control.

Public Functions

PidControl(ControlType initError, real Kp, real Ki, real Kd)

Initialize the PID.

Parameters
  • initError: The initial difference between the current state and the target.
  • Kp: The proportional coefficient.
  • Ki: The integral coefficient.
  • Kd: The derivative coefficient.

ControlType update(ControlType error)

Update the internal state of the PID controller.

Return
The control variable value.
Parameters
  • error: The difference between the current state and the target.

Friends

std::ofstream &operator<<(std::ofstream &stream, const PidControl<ControlType> &pid)

Serialize a controller into a stream.

Return
The stream.
Parameters
  • stream: The stream that will contain the serialized data.
  • pid: The current state to serialize.

std::ifstream &operator>>(std::ifstream &stream, PidControl<ControlType> &pid)

Deserialize a controller from a stream.

Return
The stream.
Parameters
  • stream: The stream that contains the serialized data.
  • pid: The deserialized state.

void mirheo::writeXYZ(MPI_Comm comm, std::string fname, const real4 *positions, int np)

Dump positions to a file in xyz format using MPI IO.

Parameters
  • comm: The MPI communicator.
  • fname: The name of the target file.
  • positions: Array of positions xyz_.
  • np: Local number of particles.

bool mirheo::isTimeEvery(const MirState *state, int dumpEvery)

Check if a dump should occur at the current time step.

Return
true if the current step is a dump time; false otherwise.
Parameters
  • state: The current state of the simulation.
  • dumpEvery: The number of steps between two dumps.

MirState::StepType mirheo::getTimeStamp(const MirState *state, int dumpEvery)

Get the dump stamp from current time and dump frequency.

Return
The dump stamp.
Parameters
  • state: The current state of the simulation.
  • dumpEvery: The number of steps between two dumps.

class SimpleSerializer

Helper class To serialize and deserialize data.

This is used to communicate data between simulation and postprocess plugins.

Only POD types and std::vectors/HostBuffers/PinnedBuffers of POD and std::strings are supported.

Public Static Functions

static int totSize()

Return
The default total size of one element.

template <typename Arg>
static int totSize(const Arg &arg)

The total size of one element.

Return
The size in bytes of the element.
Template Parameters
  • Arg: The type of the element
Parameters
  • arg: The element instance.

template <typename Arg, typename... OthArgs>
static int totSize(const Arg &arg, const OthArgs&... othArgs)

The total size of one element.

Return
The size in bytes of all elements.
Template Parameters
  • Arg: The type of the element
  • OthArgs: The types of the element other elements
Parameters
  • arg: The element instance.
  • othArgs: The other element instances.

template <typename... Args>
static void serialize(std::vector<char> &buf, const Args&... args)

Serialize multiple elements into a buffer.

The buffer will be allocated to the correct size.

Template Parameters
  • Args: The types the elements to serialize.
Parameters
  • args: The elements to serialize.
  • buf: The buffer that will contain the serialized data.

template <typename... Args>
static void deserialize(const std::vector<char> &buf, Args&... args)

Deserialize multiple elements from a buffer.

Template Parameters
  • Args: The types the elements to deserialize.
Parameters
  • args: The deserialized elements.
  • buf: The buffer that contains the serialized data.

template <typename... Args>
static void serialize(char *to, const Args&... args)

Serialize multiple elements into a buffer.

The buffer will NOT be allocated to the correct size.

Template Parameters
  • Args: The types the elements to serialize.
Parameters
  • args: The elements to serialize.
  • to: The buffer that will contain the serialized data. Must be sufficiently large.

template <typename... Args>
static void deserialize(const char *from, Args&... args)

Deserialize multiple elements from a buffer.

Template Parameters
  • Args: The types the elements to deserialize.
Parameters
  • args: The deserialized elements.
  • from: The buffer that contains the serialized data.