OpenMPCD
FlowProfile.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the FlowProfile class.
4  */
5 
6 #ifndef OPENMPCD_FLOWPROFILE_HPP
7 #define OPENMPCD_FLOWPROFILE_HPP
8 
10 #include <OpenMPCD/Exceptions.hpp>
13 #include <OpenMPCD/Vector3D.hpp>
14 
15 #include <boost/multi_array.hpp>
16 #include <boost/shared_ptr.hpp>
17 
18 #include <string>
19 
20 namespace OpenMPCD
21 {
22  /**
23  * Represents a flow profile.
24  *
25  * This class can be configured via the `instrumentation.flowProfile`
26  * configuration group. If it is not present, this class will not be active.
27  * Otherwise, the following sub-settings are allowed:
28  * - `cellSubdivision` may be a group that has three positive integer
29  * entries, `x`, `y`, and `z`, which define the resolution of the
30  * profile. If, for example, `x` has a value of `3`, this means that each
31  * collision cell is divided into three regions of equal length along the
32  * \f$ x \f$ direction, and each region is sampled individually.
33  * If `cellSubdivision` is not present, the values for
34  * `cellSubdivision.x`, `cellSubdivision.y`, and `cellSubdivision.z`
35  * default to `1`.
36  * - `sweepCountPerOutput` may be set to a non-negative integer. If the
37  * value is greater than `0`, this instance measures the flow field for
38  * `sweepCountPerOutput` successive sweeps, then computes statistical
39  * data (averages, standard deviations) of the flow field as measured
40  * during these sweeps, and finally starts a new measurement,
41  * disregarding old data. If `sweepCountPerOutput` is `0` (the default),
42  * all sweeps are measured, and the data taken contributes to the only
43  * set of output data.
44  *
45  * @tparam T The data type.
46  */
47  template<typename T> class FlowProfile
48  {
49  public:
50  /**
51  * The constructor.
52  *
53  * @param[in] mpcBoxSizeX
54  * The MPC simulation box size along the \f$ x \f$
55  * direction.
56  * @param[in] mpcBoxSizeY
57  * The MPC simulation box size along the \f$ y \f$
58  * direction.
59  * @param[in] mpcBoxSizeZ
60  * The MPC simulation box size along the \f$ z \f$
61  * direction.
62  * @param[in] settings
63  * The settings for this instance.
64  *
65  * @throw OpenMPCD::InvalidArgumentException
66  * If `OPENMPCD_DEBUG` is defined, throws if any of the
67  * numerical arguments is `0`.
68  *
69  * @throw OpenMPCD::InvalidConfigurationException
70  * Throws if the configuration is invalid.
71  */
73  const unsigned int mpcBoxSizeX,
74  const unsigned int mpcBoxSizeY,
75  const unsigned int mpcBoxSizeZ,
76  const Configuration::Setting& settings);
77 
78  public:
79  /**
80  * Returns the number of times collision cells are subdivided along
81  * the \f$ x \f$ direction.
82  */
83  unsigned int getCellSubdivisionsX() const
84  {
85  return cellSubdivisionsX;
86  }
87 
88  /**
89  * Returns the number of times collision cells are subdivided along
90  * the \f$ y \f$ direction.
91  */
92  unsigned int getCellSubdivisionsY() const
93  {
94  return cellSubdivisionsY;
95  }
96 
97  /**
98  * Returns the number of times collision cells are subdivided along
99  * the \f$ z \f$ direction.
100  */
101  unsigned int getCellSubdivisionsZ() const
102  {
103  return cellSubdivisionsZ;
104  }
105 
106  /**
107  * Adds data to the given point.
108  *
109  * The coordinates given to this function are the index of the cell
110  * and its subdivisions.
111  *
112  *
113  * @throw OpenMPCD::InvalidCallException
114  * If `OPENMPCD_DEBUG` is defined, throws if `newSweep` has
115  * not been called before.
116  * @throw OpenMPCD::OutOfBoundsException
117  * If `OPENMPCD_DEBUG` is defined, throws if `x`, `y`, or `z`
118  * are too large, that is, if
119  * `x >= mpcBoxSizeX * getCellSubdivisionsX()`, where
120  * `mpcBoxSizeX` is the size of the simulation box along the
121  * \f$ x \f$ direction, and analogously for the other
122  * coordinates.
123  *
124  * @param[in] x The x coordinate of the point.
125  * @param[in] y The y coordinate of the point.
126  * @param[in] z The z coordinate of the point.
127  * @param[in] v The vector to add.
128  */
129  void add(const std::size_t x, const std::size_t y,
130  const std::size_t z, const Vector3D<T>& v)
131  {
133  !outputBlocks.empty(), InvalidCallException);
134 
136  x < outputBlocks.back()->shape()[0], OutOfBoundsException);
138  y < outputBlocks.back()->shape()[1], OutOfBoundsException);
140  z < outputBlocks.back()->shape()[2], OutOfBoundsException);
141 
142  (*outputBlocks.back())[x][y][z][0].addDatum(v.getX());
143  (*outputBlocks.back())[x][y][z][1].addDatum(v.getY());
144  (*outputBlocks.back())[x][y][z][2].addDatum(v.getZ());
145  }
146 
147  /**
148  * Signals that a new sweep has begun.
149  */
150  void newSweep();
151 
152  /**
153  * Saves the data into a file with the given path.
154  *
155  * The first line is a comment header that starts with a `#`
156  * character and contains labels for each of the columns, which are
157  * described below.
158  *
159  * What follows after this first line is a number of output blocks,
160  * where the blocks are separated from one another by blank lines
161  * (but there is neither a blank line between the header and the
162  * first block, nor between the last block and the end of the file.)
163  *
164  * Each block represents a number of sweeps that have been measured
165  * in succession. What the block contains are statistical data
166  * about this series of sweeps, as described below. The number of
167  * sweeps per block is configured in the `sweepCountPerOutput`
168  * configuration option. The last block of an output file may
169  * contain fewer sweeps, if the simulation terminates before an
170  * integer multiple of `sweepCountPerOutput` could be reached.
171  *
172  * Each line in a block represents one point in the flow field.
173  * The first three columns are the x, y, and z coordinates of the
174  * point, respectively.
175  * The next three columns are the means of the x, y, and z
176  * coordinates of the velocity.
177  * The next three columns are the standard deviations of the x, y,
178  * and z coordinates of the velocity.
179  * The last column contains the sample sizes.
180  *
181  * @throw OpenMPCD::IOException Throws on an IO error.
182  *
183  * @param[in] path The path to save to.
184  */
185  void saveToFile(const std::string& path) const;
186 
187  private:
188  /**
189  * Creates a new output block.
190  */
191  void createOutputBlock();
192 
193  /**
194  * Prints the given output block to the given stream.
195  *
196  * @param[in] outputBlock
197  * The output block to print.
198  * @param[out] stream
199  * The stream to print to.
200  */
201  void printOutputBlockToStream(
202  const boost::multi_array<OnTheFlyStatistics<T>, 4 >& outputBlock,
203  std::ostream& stream) const;
204 
205  private:
206  const unsigned int simulationBoxSizeX;
207  /**< The size of the simulation box along the \f$ x \f$
208  direction.*/
209  const unsigned int simulationBoxSizeY;
210  /**< The size of the simulation box along the \f$ y \f$
211  direction.*/
212  const unsigned int simulationBoxSizeZ;
213  /**< The size of the simulation box along the \f$ z \f$
214  direction.*/
215 
216  unsigned int cellSubdivisionsX;
217  /**< The number of times collision cells are subdivided along
218  the \f$ x \f$ direction.*/
219  unsigned int cellSubdivisionsY;
220  /**< The number of times collision cells are subdivided along
221  the \f$ y \f$ direction.*/
222  unsigned int cellSubdivisionsZ;
223  /**< The number of times collision cells are subdivided along
224  the \f$ z \f$ direction.*/
225 
226  unsigned int sweepCountPerOutput;
227  ///< How many sweeps should enter into one output.
228  unsigned int currentBlockSweepCount;
229  ///< The number of sweeps in the current output block.
230 
231  std::deque<
232  boost::shared_ptr<boost::multi_array<OnTheFlyStatistics<T>, 4>
233  > >
234  outputBlocks; ///< Pointers to output blocks.
235  };
236 }
237 
238 #endif
OpenMPCD::FlowProfile::newSweep
void newSweep()
Signals that a new sweep has begun.
Definition: FlowProfile.cpp:51
OpenMPCD::InvalidCallException
Exception for a forbidden function call.
Definition: Exceptions.hpp:144
Exceptions.hpp
OpenMPCD::Vector3D::getZ
OPENMPCD_CUDA_HOST_AND_DEVICE T getZ() const
Returns the z coordinate.
Definition: Vector3D.hpp:119
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::FlowProfile::FlowProfile
FlowProfile(const unsigned int mpcBoxSizeX, const unsigned int mpcBoxSizeY, const unsigned int mpcBoxSizeZ, const Configuration::Setting &settings)
The constructor.
Definition: FlowProfile.cpp:13
OpenMPCD::Vector3D::getX
OPENMPCD_CUDA_HOST_AND_DEVICE T getX() const
Returns the x coordinate.
Definition: Vector3D.hpp:61
OpenMPCD::Vector3D::getY
OPENMPCD_CUDA_HOST_AND_DEVICE T getY() const
Returns the y coordinate.
Definition: Vector3D.hpp:90
OpenMPCD::FlowProfile::getCellSubdivisionsZ
unsigned int getCellSubdivisionsZ() const
Returns the number of times collision cells are subdivided along the direction.
Definition: FlowProfile.hpp:101
OpenMPCD::FlowProfile::getCellSubdivisionsY
unsigned int getCellSubdivisionsY() const
Returns the number of times collision cells are subdivided along the direction.
Definition: FlowProfile.hpp:92
OpenMPCD::FlowProfile::getCellSubdivisionsX
unsigned int getCellSubdivisionsX() const
Returns the number of times collision cells are subdivided along the direction.
Definition: FlowProfile.hpp:83
Vector3D.hpp
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::FlowProfile::saveToFile
void saveToFile(const std::string &path) const
Saves the data into a file with the given path.
Definition: FlowProfile.cpp:76
OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE
#define OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE(assertion, ExceptionType)
Definition: OPENMPCD_DEBUG_ASSERT.hpp:76
OnTheFlyStatistics.hpp
OpenMPCD::FlowProfile
Represents a flow profile.
Definition: FlowProfile.hpp:47
OpenMPCD::Configuration::Setting
Represents a setting in the configuration.
Definition: Configuration.hpp:36
Configuration.hpp
OpenMPCD::OnTheFlyStatistics
Computes sample means and variances "on-the-fly" or "online", i.e.
Definition: OnTheFlyStatistics.hpp:34
OpenMPCD::OutOfBoundsException
Exception for out-of-bounds access.
Definition: Exceptions.hpp:112
OpenMPCD::FlowProfile::add
void add(const std::size_t x, const std::size_t y, const std::size_t z, const Vector3D< T > &v)
Adds data to the given point.
Definition: FlowProfile.hpp:129