OpenMPCD
DensityProfile.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the OpenMPCD::DensityProfile class.
4  */
5 
6 #ifndef OPENMPCD_DENSITYPROFILE_HPP
7 #define OPENMPCD_DENSITYPROFILE_HPP
8 
10 #include <OpenMPCD/Exceptions.hpp>
11 #include <OpenMPCD/Vector3D.hpp>
12 
13 #include <string>
14 #include <vector>
15 
16 namespace OpenMPCD
17 {
18  /**
19  * Represents a density profile.
20  *
21  * This class can be configured via the `instrumentation.densityProfile`
22  * configuration group. If it is not present, this class will not be active.
23  * Otherwise, the following sub-settings are allowed:
24  * - `cellSubdivision` may be a group that has three positive integer
25  * entries, `x`, `y`, and `z`, which define the resolution of the
26  * profile. If, for example, `x` has a value of `3`, this means that each
27  * collision cell is divided into three regions of equal length along the
28  * \f$ x \f$ direction, and each region is sampled individually.
29  * If `cellSubdivision` is not present, the values for
30  * `cellSubdivision.x`, `cellSubdivision.y`, and `cellSubdivision.z`
31  * default to `1`.
32  */
34  {
35  public:
36  /**
37  * The constructor.
38  *
39  * @param[in] mpcBoxSizeX
40  * The MPC simulation box size along the \f$ x \f$
41  * direction.
42  * @param[in] mpcBoxSizeY
43  * The MPC simulation box size along the \f$ y \f$
44  * direction.
45  * @param[in] mpcBoxSizeZ
46  * The MPC simulation box size along the \f$ z \f$
47  * direction.
48  * @param[in] settings
49  * The settings for this instance.
50  *
51  * @throw OpenMPCD::InvalidArgumentException
52  * If `OPENMPCD_DEBUG` is defined, throws if any of the
53  * numerical arguments is `0`.
54  *
55  * @throw OpenMPCD::InvalidConfigurationException
56  * Throws if the configuration is invalid.
57  */
59  const unsigned int mpcBoxSizeX,
60  const unsigned int mpcBoxSizeY,
61  const unsigned int mpcBoxSizeZ,
62  const Configuration::Setting& settings);
63 
64  public:
65  /**
66  * Returns the number of times collision cells are subdivided along
67  * the \f$ x \f$ direction.
68  */
69  unsigned int getCellSubdivisionsX() const
70  {
71  return cellSubdivisionsX;
72  }
73 
74  /**
75  * Returns the number of times collision cells are subdivided along
76  * the \f$ y \f$ direction.
77  */
78  unsigned int getCellSubdivisionsY() const
79  {
80  return cellSubdivisionsY;
81  }
82 
83  /**
84  * Returns the number of times collision cells are subdivided along
85  * the \f$ z \f$ direction.
86  */
87  unsigned int getCellSubdivisionsZ() const
88  {
89  return cellSubdivisionsZ;
90  }
91 
92  /**
93  * Increments the fill count.
94  */
96  {
97  ++fillCount;
98  }
99 
100  /**
101  * Adds mass to the given point.
102  * The coordinates given to this function are the index of the cell and its subdivisions.
103  * @throw OutOfBoundsException If OPENMPCD_DEBUG is defined, throws if x, y, or z are too large.
104  * @param[in] x The x coordinate of the point.
105  * @param[in] y The y coordinate of the point.
106  * @param[in] z The z coordinate of the point.
107  * @param[in] m The mass to add.
108  */
109  void add(const std::vector<std::vector<std::vector<FP> > >::size_type x,
110  const std::vector<std::vector<FP> >::size_type y,
111  const std::vector<FP>::size_type z,
112  const FP m)
113  {
114  #ifdef OPENMPCD_DEBUG
115  if(x>=points.size())
117  if(y>=points[x].size())
119  if(z>=points[x][y].size())
121  #endif
122 
123  points[x][y][z] += m;
124  }
125 
126  /**
127  * Saves the data into a file with the given path.
128  * Each line represents one point in the density profile.
129  * The first three columns are the x, y, and z coordinates of the point, respectively.
130  * The last column shows the averaged mass density at that point.
131  * @param[in] path The path to save to.
132  * @throw IOException Throws on an IO error.
133  */
134  void saveToFile(const std::string& path) const;
135 
136  private:
137  std::vector<std::vector<std::vector<FP> > > points; ///< The points in the flow profile.
138  unsigned int fillCount; ///< The number of measurements performed.
139 
140  unsigned int cellSubdivisionsX; ///< The number of times collision cells are subdivided along the x direction.
141  unsigned int cellSubdivisionsY; ///< The number of times collision cells are subdivided along the y direction.
142  unsigned int cellSubdivisionsZ; ///< The number of times collision cells are subdivided along the z direction.
143  };
144 }
145 
146 #endif
Exceptions.hpp
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::DensityProfile::saveToFile
void saveToFile(const std::string &path) const
Saves the data into a file with the given path.
Definition: DensityProfile.cpp:47
OpenMPCD::DensityProfile::getCellSubdivisionsZ
unsigned int getCellSubdivisionsZ() const
Returns the number of times collision cells are subdivided along the direction.
Definition: DensityProfile.hpp:87
OpenMPCD::DensityProfile::incrementFillCount
void incrementFillCount()
Increments the fill count.
Definition: DensityProfile.hpp:95
Vector3D.hpp
OpenMPCD::FP
double FP
Default floating point type.
Definition: Types.hpp:13
OpenMPCD::DensityProfile::getCellSubdivisionsY
unsigned int getCellSubdivisionsY() const
Returns the number of times collision cells are subdivided along the direction.
Definition: DensityProfile.hpp:78
OpenMPCD::DensityProfile::DensityProfile
DensityProfile(const unsigned int mpcBoxSizeX, const unsigned int mpcBoxSizeY, const unsigned int mpcBoxSizeZ, const Configuration::Setting &settings)
The constructor.
Definition: DensityProfile.cpp:9
OpenMPCD::DensityProfile::getCellSubdivisionsX
unsigned int getCellSubdivisionsX() const
Returns the number of times collision cells are subdivided along the direction.
Definition: DensityProfile.hpp:69
OpenMPCD::Configuration::Setting
Represents a setting in the configuration.
Definition: Configuration.hpp:36
Configuration.hpp
OpenMPCD::OutOfBoundsException
Exception for out-of-bounds access.
Definition: Exceptions.hpp:112
OpenMPCD::DensityProfile
Represents a density profile.
Definition: DensityProfile.hpp:33
OpenMPCD::DensityProfile::add
void add(const std::vector< std::vector< std::vector< FP > > >::size_type x, const std::vector< std::vector< FP > >::size_type y, const std::vector< FP >::size_type z, const FP m)
Adds mass to the given point.
Definition: DensityProfile.hpp:109