1 // Voro++, a 3D cell-based Voronoi library
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 /** \file pre_container.hh
8 * \brief Header file for the pre_container and related classes. */
10 #ifndef VOROPP_PRE_CONTAINER_HH
11 #define VOROPP_PRE_CONTAINER_HH
16 #include "container.hh"
20 /** \brief A class for storing an arbitrary number of particles, prior to setting
21 * up a container geometry.
23 * The pre_container_base class can dynamically import and store an arbitrary
24 * number of particles. Once the particles have been read in, an appropriate
25 * container class can be set up with the optimal grid size, and the particles
28 * The pre_container_base class is not intended for direct use, but forms the
29 * base of the pre_container and pre_container_poly classes, that add routines
30 * depending on whether particle radii need to be tracked or not. */
31 class pre_container_base
{
33 /** The minimum x coordinate of the container. */
35 /** The maximum x coordinate of the container. */
37 /** The minimum y coordinate of the container. */
39 /** The maximum y coordinate of the container. */
41 /** The minimum z coordinate of the container. */
43 /** The maximum z coordinate of the container. */
45 /** A boolean value that determines if the x coordinate in
48 /** A boolean value that determines if the y coordinate in
51 /** A boolean value that determines if the z coordinate in
54 void guess_optimal(int &nx
,int &ny
,int &nz
);
55 pre_container_base(double ax_
,double bx_
,double ay_
,double by_
,double az_
,double bz_
,bool xperiodic_
,bool yperiodic_
,bool zperiodic_
,int ps_
);
56 ~pre_container_base();
57 /** Calculates and returns the total number of particles stored
59 * \return The number of particles. */
60 inline int total_particles() {
61 return (end_id
-pre_id
)*pre_container_chunk_size
+(ch_id
-*end_id
);
64 /** The number of doubles associated with a single particle
65 * (three for the standard container, four when radius
66 * information is stored). */
69 void extend_chunk_index();
70 /** The size of the chunk index. */
72 /** A pointer to the chunk index to store the integer particle
75 /** A pointer to the last allocated integer ID chunk. */
77 /** A pointer to the end of the integer ID chunk index, used to
78 * determine when the chunk index is full. */
80 /** A pointer to the next available slot on the current
81 * particle ID chunk. */
83 /** A pointer to the end of the current integer chunk. */
85 /** A pointer to the chunk index to store the floating point
86 * information associated with particles. */
88 /** A pointer to the last allocated chunk of floating point
91 /** A pointer to the next available slot on the current
92 * floating point chunk. */
96 /** \brief A class for storing an arbitrary number of particles without radius
97 * information, prior to setting up a container geometry.
99 * The pre_container class is an extension of the pre_container_base class for
100 * cases when no particle radius information is available. */
101 class pre_container
: public pre_container_base
{
103 /** The class constructor sets up the geometry of container,
104 * initializing the minimum and maximum coordinates in each
106 * \param[in] (ax_,bx_) the minimum and maximum x coordinates.
107 * \param[in] (ay_,by_) the minimum and maximum y coordinates.
108 * \param[in] (az_,bz_) the minimum and maximum z coordinates.
109 * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the
110 * container is periodic in
111 * each coordinate direction. */
112 pre_container(double ax_
,double bx_
,double ay_
,double by_
,double az_
,double bz_
,
113 bool xperiodic_
,bool yperiodic_
,bool zperiodic_
)
114 : pre_container_base(ax_
,bx_
,ay_
,by_
,az_
,bz_
,xperiodic_
,yperiodic_
,zperiodic_
,3) {};
115 void put(int n
,double x
,double y
,double z
);
116 void import(FILE *fp
=stdin
);
117 /** Imports particles from a file.
118 * \param[in] filename the name of the file to read from. */
119 inline void import(const char* filename
) {
120 FILE *fp
=safe_fopen(filename
,"r");
124 void setup(container
&con
);
125 void setup(particle_order
&vo
,container
&con
);
128 /** \brief A class for storing an arbitrary number of particles with radius
129 * information, prior to setting up a container geometry.
131 * The pre_container_poly class is an extension of the pre_container_base class
132 * for cases when particle radius information is available. */
133 class pre_container_poly
: public pre_container_base
{
135 /** The class constructor sets up the geometry of container,
136 * initializing the minimum and maximum coordinates in each
138 * \param[in] (ax_,bx_) the minimum and maximum x coordinates.
139 * \param[in] (ay_,by_) the minimum and maximum y coordinates.
140 * \param[in] (az_,bz_) the minimum and maximum z coordinates.
141 * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the
142 * container is periodic in
143 * each coordinate direction. */
144 pre_container_poly(double ax_
,double bx_
,double ay_
,double by_
,double az_
,double bz_
,
145 bool xperiodic_
,bool yperiodic_
,bool zperiodic_
)
146 : pre_container_base(ax_
,bx_
,ay_
,by_
,az_
,bz_
,xperiodic_
,yperiodic_
,zperiodic_
,4) {};
147 void put(int n
,double x
,double y
,double z
,double r
);
148 void import(FILE *fp
=stdin
);
149 /** Imports particles from a file.
150 * \param[in] filename the name of the file to read from. */
151 inline void import(const char* filename
) {
152 FILE *fp
=safe_fopen(filename
,"r");
156 void setup(container_poly
&con
);
157 void setup(particle_order
&vo
,container_poly
&con
);