OpenMPCD
LogicalEntityMeanSquareDisplacement.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the
4  * `OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement`
5  * class.
6  */
7 
8 #ifndef OPENMPCD_CUDA_MPCFLUID_INSTRUMENTATION_LOGICALENTITYMEANSQUAREDISPLACEMENT_HPP
9 #define OPENMPCD_CUDA_MPCFLUID_INSTRUMENTATION_LOGICALENTITYMEANSQUAREDISPLACEMENT_HPP
10 
11 
14 #include <OpenMPCD/Types.hpp>
15 
16 #include <ostream>
17 #include <vector>
18 
19 namespace OpenMPCD
20 {
21 namespace CUDA
22 {
23 namespace MPCFluid
24 {
25 
26 class Base;
27 
28 namespace Instrumentation
29 {
30 
31 /**
32  * Measures the mean square displacement of logical entities in an MPC fluid.
33  *
34  * This class can only be used if
35  * `OpenMPCD::CUDA::MPCFluid::Base::numberOfParticlesPerLogicalEntityIsConstant`
36  * is true.
37  *
38  * Let \f$ \vec{R}_i \f$ be the center of mass for the logical entity \f$ i \f$,
39  * with \f$ i \in \left[0, N_L - 1 \right]\f$, where \f$ N_L \f$ is the return
40  * value of `OpenMPCD::CUDA::MPCFluid::Base::getNumberOfLogicalEntities`.
41  *
42  * Then, this class samples, for configurable times \f$ \Delta t \f$,
43  * the quantity
44  * \f[
45  * C \left( t, t + \Delta t \right)
46  * =
47  * \frac{1}{N_L}
48  * \sum_{i=1}^{N_L}
49  * \left(
50  * \vec{R}_i \left( t + \Delta t \right)
51  * -
52  * \vec{R}_i \left( t \right)
53  * \right)^2
54  * \f]
55  *
56  * In order to avoid floating-point arithmetic in specifying times, and in order
57  * to decouple this class from the `CUDA::Simulation` class, time is measured
58  * in this class as the number of times `measure` has completed, not counting
59  * those calls that have no effect because of the `measureEveryNthSweep`
60  * configuration option (see below).
61  * As an example, take `measureEveryNthSweep` to be `3`. Then, the first
62  * execution of `measure` will perform a measurement, and that point in
63  * simulation time will be referred to as `measurement time 0`. The next two
64  * calls to `measure` will again have no effect, while the following (i.e. the
65  * fourth) call will be at `measurement time 1`. The fifth and sixth calls
66  * will again have no effect, and so forth.
67  *
68  * This class is configured via the
69  * `instrumentation.logicalEntityMeanSquareDisplacement`
70  * configuration group. Within that group, `measureEveryNthSweep` defines
71  * \f$ \tau \f$, and `measurementArgumentCount` defines \f$ N_A \f$; given
72  * those, the mean square displacement is measured at (simulation) times
73  * \f[
74  * \Delta t \in
75  * \left\{
76  * \tau \Delta T, 2 \tau \Delta T, \ldots, N_A \tau \Delta T
77  * \right\}
78  * \f]
79  * where \f$ \Delta T \f$ is the simulation time between consecutive sweeps.
80  * Consequently, in `measurement time`,
81  * \f$ \Delta t \in \left\{ 1, 2, \ldots, N_A \right\} \f$.
82  *
83  * For analysis of the produced results, see
84  * `MPCDAnalysis.LogicalEntityMeanSquareDisplacement`.
85  */
87 {
88 public:
89  /**
90  * The constructor.
91  *
92  * @throw OpenMPCD::NULLPointerException
93  * If `OPENMPCD_DEBUG` is defined, throws if `mpcFluid_ == nullptr`.
94  * @throw OpenMPCD::InvalidConfigurationException
95  * Throws if
96  * `!isValidConfiguration(
97  * configuration.getSetting(
98  * "instrumentation.logicalEntityMeanSquareDisplacement"))`.
99  * @throw OpenMPCD::InvalidArgumentException
100  * If `OPENMPCD_DEBUG` is defined, throws if
101  * `!mpcFluid_->numberOfParticlesPerLogicalEntityIsConstant()`.
102  *
103  * @param[in] configuration
104  * The simulation configuration.
105  * @param[in] mpcFluid_
106  * The fluid to measure. Must not be `nullptr`, and it must
107  * return `true` when its
108  * `numberOfParticlesPerLogicalEntityIsConstant` member is
109  * called.
110  */
112  const OpenMPCD::Configuration& configuration,
113  const OpenMPCD::CUDA::MPCFluid::Base* const mpcFluid_);
114 
115 private:
118  ///< The copy constructor.
119 
120 public:
121  /**
122  * The destructor.
123  */
125 
126 public:
127  /**
128  * Returns whether the an attempt has been made to configure this class,
129  * i.e. whether the `instrumentation.logicalEntityMeanSquareDisplacement`
130  * configuration group exists.
131  *
132  * @param[in] config
133  * The configuration to query.
134  */
135  static bool isConfigured(const Configuration& config);
136 
137  /**
138  * Returns whether the given configuration group is a valid configuration.
139  *
140  * For a configuration group to be valid, it must
141  * - contain the key `measureEveryNthSweep`, which must be a positive
142  * integer
143  * - contain the key `measurementArgumentCount`, which must be a
144  * positive integer.
145  *
146  * @param[in] group
147  * The configuration group to query.
148  */
149  static bool isValidConfiguration(const Configuration::Setting& group);
150 
151 
152 public:
153  /**
154  * Takes measurement data.
155  *
156  * This function is to be called by the `OpenMPCD::CUDA::Simulation` instance
157  * after every sweep.
158  */
159  void measure();
160 
161  /**
162  * Returns, in units of `measurement time`, the maximum measurement time
163  * that is configured to be measured, i.e. \f$ N_A \f$.
164  */
165  unsigned int getMaximumMeasurementTime() const;
166 
167  /**
168  * Returns `1` plus the maximum number `t` may take in
169  * `getMeanSquareDisplacement`.
170  */
171  unsigned int getMeasurementCount() const;
172 
173  /**
174  * Returns the measured mean square displacement
175  * \f$ C \left( t, t + \Delta t \right) \f$ between measurement times
176  * \f$ t \f$ and \f$ T \f$.
177  *
178  * @note
179  * The times are given in units of the `measurement time`, which is
180  * described in the documentation of this class.
181  *
182  * @throw OpenMPCD::InvalidArgumentException
183  * If `OPENMPCD_DEBUG` is defined, throws if
184  * `t >= getMeasurementCount()`.
185  * @throw OpenMPCD::InvalidArgumentException
186  * If `OPENMPCD_DEBUG` is defined, throws if
187  * `T >= getMeasurementCount()` or `T <= t` or
188  * `T - t > getMaximumMeasurementTime()`.
189  *
190  * @param[in] t
191  * The first measurement time \f$ t \f$. This value must be
192  * smaller than `getMeasurementCount()`.
193  * @param[in] T
194  * The second measurement time \f$ T \f$. This value must be
195  * smaller than `getMeasurementCount()` and larger than `t`.
196  * Also, `T - t` must not be larger than
197  * `getMaximumMeasurementTime()`.
198  */
200  const unsigned int t,
201  const unsigned int T) const;
202 
203  /**
204  * Saves the result to the given stream.
205  *
206  * For each value `t` in the range `[0, getMeasurementCount())`, and for
207  * each value `T` in the range `[t + 1, t + getMaximumMeasurementTime()]`
208  * (except for those where `T >= getMeasurementCount()`),
209  * a line will be written to the output stream, with the following fields,
210  * separated by tab characters:
211  * First, the current value of `t`, followed by the value of `T - t`,
212  * followed by the value of `getMeanSquareDisplacement(t, T)`.
213  *
214  * The numeric values will be written with precision
215  * <c>std::numeric_limits<OpenMPCD::FP>::digits10 + 2</c>.
216  *
217  * @param[out] stream
218  * The stream to write to.
219  */
220  void save(std::ostream& stream);
221 
222  /**
223  * Saves the result to the given run directory.
224  *
225  * The file within the given directory will be named
226  * `logicalEntityMeanSquareDisplacement.data`, and will be created if it
227  * does not exist, or truncated if it does. Parent directories will be
228  * created as needed.
229  * The file's contents will correspond to the output of
230  * `save(std::ostream&)`.
231  *
232  * @param[in] rundir
233  * Path to the directory, into which the result file will be
234  * written.
235  */
236  void save(const std::string& rundir);
237 
238 private:
239  const LogicalEntityMeanSquareDisplacement& operator=(
241  ///< The assignment operator.
242 
243 private:
244  const OpenMPCD::CUDA::MPCFluid::Base* const mpcFluid;
245  ///< The fluid measured.
246 
247  unsigned int measureEveryNthSweep;
248  ///< Specifies the snapshot interval.
249  unsigned int measurementArgumentCount;
250  ///< Specifies the snapshot count.
251 
252 
253  unsigned int sweepsSinceLastMeasurement;
254  ///< Counts the sweeps since the last measurement.
255 
256  std::vector<MPCParticlePositionType*> snapshots;
257  ///< The stored center of mass position snapshots.
258 
259  std::vector<std::vector<MPCParticlePositionType> >
260  meanSquareDisplacements;
261  /**< The measured mean square displacements. The first index specifies
262  the later measurement time, and the second index the difference
263  between later and prior measurement time.*/
264 
266  ///< A buffer on the Device, used to store centers of mass.
267 
268 }; //class LogicalEntityMeanSquareDisplacement
269 } //namespace Instrumentation
270 } //namespace MPCFluid
271 } //namespace CUDA
272 } //namespace OpenMPCD
273 
274 #endif //OPENMPCD_CUDA_MPCFLUID_INSTRUMENTATION_LOGICALENTITYMEANSQUAREDISPLACEMENT_HPP
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::LogicalEntityMeanSquareDisplacement
LogicalEntityMeanSquareDisplacement(const OpenMPCD::Configuration &configuration, const OpenMPCD::CUDA::MPCFluid::Base *const mpcFluid_)
The constructor.
OpenMPCD::CUDA::MPCFluid::Base
Base class for MPC fluids.
Definition: CUDA/MPCFluid/Base.hpp:40
OpenMPCD::Configuration
Represents the configuration of the simulation.
Definition: Configuration.hpp:28
OpenMPCD::MPCParticlePositionType
FP MPCParticlePositionType
The data type for the positions of MPC particles.
Definition: Types.hpp:15
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::isConfigured
static bool isConfigured(const Configuration &config)
Returns whether the an attempt has been made to configure this class, i.e.
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::measure
void measure()
Takes measurement data.
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::getMaximumMeasurementTime
unsigned int getMaximumMeasurementTime() const
Returns, in units of measurement time, the maximum measurement time that is configured to be measured...
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::~LogicalEntityMeanSquareDisplacement
~LogicalEntityMeanSquareDisplacement()
The destructor.
DeviceBuffer.hpp
Types.hpp
OpenMPCD::CUDA::DeviceBuffer< MPCParticlePositionType >
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::getMeasurementCount
unsigned int getMeasurementCount() const
Returns 1 plus the maximum number t may take in getMeanSquareDisplacement.
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::isValidConfiguration
static bool isValidConfiguration(const Configuration::Setting &group)
Returns whether the given configuration group is a valid configuration.
OpenMPCD::Configuration::Setting
Represents a setting in the configuration.
Definition: Configuration.hpp:36
Configuration.hpp
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement
Measures the mean square displacement of logical entities in an MPC fluid.
Definition: LogicalEntityMeanSquareDisplacement.hpp:86
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::getMeanSquareDisplacement
MPCParticlePositionType getMeanSquareDisplacement(const unsigned int t, const unsigned int T) const
Returns the measured mean square displacement between measurement times and .
OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement::save
void save(std::ostream &stream)
Saves the result to the given stream.