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
14 #include "container.hh"
18 /** \brief A class for storing an arbitrary number of particles, prior to setting
19 * up a container geometry.
21 * The pre_container_base class can dynamically import and store an arbitrary
22 * number of particles. Once the particles have been read in, an appropriate
23 * container class can be set up with the optimal grid size, and the particles
26 * The pre_container_base class is not intended for direct use, but forms the
27 * base of the pre_container and pre_container_poly classes, that add routines
28 * depending on whether particle radii need to be tracked or not. */
29 class pre_container_base
{
31 /** The minimum x coordinate of the container. */
33 /** The maximum x coordinate of the container. */
35 /** The minimum y coordinate of the container. */
37 /** The maximum y coordinate of the container. */
39 /** The minimum z coordinate of the container. */
41 /** The maximum z coordinate of the container. */
43 /** A boolean value that determines if the x coordinate in
46 /** A boolean value that determines if the y coordinate in
49 /** A boolean value that determines if the z coordinate in
52 void guess_optimal(int &nx
,int &ny
,int &nz
);
53 pre_container_base(double ax_
,double bx_
,double ay_
,double by_
,double az_
,double bz_
,bool xperiodic_
,bool yperiodic_
,bool zperiodic_
,int ps_
);
54 ~pre_container_base();
55 /** Calculates and returns the total number of particles stored
57 * \return The number of particles. */
58 inline int total_particles() {
59 return (end_id
-pre_id
)*pre_container_chunk_size
+(ch_id
-*end_id
);
62 /** The number of doubles associated with a single particle
63 * (three for the standard container, four when radius
64 * information is stored). */
67 void extend_chunk_index();
68 /** The size of the chunk index. */
70 /** A pointer to the chunk index to store the integer particle
73 /** A pointer to the last allocated integer ID chunk. */
75 /** A pointer to the end of the integer ID chunk index, used to
76 * determine when the chunk index is full. */
78 /** A pointer to the next available slot on the current
79 * particle ID chunk. */
81 /** A pointer to the end of the current integer chunk. */
83 /** A pointer to the chunk index to store the floating point
84 * information associated with particles. */
86 /** A pointer to the last allocated chunk of floating point
89 /** A pointer to the next available slot on the current
90 * floating point chunk. */
94 /** \brief A class for storing an arbitrary number of particles without radius
95 * information, prior to setting up a container geometry.
97 * The pre_container class is an extension of the pre_container_base class for
98 * cases when no particle radius information is available. */
99 class pre_container
: public pre_container_base
{
101 /** The class constructor sets up the geometry of container,
102 * initializing the minimum and maximum coordinates in each
104 * \param[in] (ax_,bx_) the minimum and maximum x coordinates.
105 * \param[in] (ay_,by_) the minimum and maximum y coordinates.
106 * \param[in] (az_,bz_) the minimum and maximum z coordinates.
107 * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the
108 * container is periodic in
109 * each coordinate direction. */
110 pre_container(double ax_
,double bx_
,double ay_
,double by_
,double az_
,double bz_
,
111 bool xperiodic_
,bool yperiodic_
,bool zperiodic_
)
112 : pre_container_base(ax_
,bx_
,ay_
,by_
,az_
,bz_
,xperiodic_
,yperiodic_
,zperiodic_
,3) {};
113 void put(int n
,double x
,double y
,double z
);
114 void import(FILE *fp
=stdin
);
115 /** Imports particles from a file.
116 * \param[in] filename the name of the file to read from. */
117 inline void import(const char* filename
) {
118 FILE *fp
=safe_fopen(filename
,"r");
122 void setup(container
&con
);
123 void setup(particle_order
&vo
,container
&con
);
126 /** \brief A class for storing an arbitrary number of particles with radius
127 * information, prior to setting up a container geometry.
129 * The pre_container_poly class is an extension of the pre_container_base class
130 * for cases when particle radius information is available. */
131 class pre_container_poly
: public pre_container_base
{
133 /** The class constructor sets up the geometry of container,
134 * initializing the minimum and maximum coordinates in each
136 * \param[in] (ax_,bx_) the minimum and maximum x coordinates.
137 * \param[in] (ay_,by_) the minimum and maximum y coordinates.
138 * \param[in] (az_,bz_) the minimum and maximum z coordinates.
139 * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the
140 * container is periodic in
141 * each coordinate direction. */
142 pre_container_poly(double ax_
,double bx_
,double ay_
,double by_
,double az_
,double bz_
,
143 bool xperiodic_
,bool yperiodic_
,bool zperiodic_
)
144 : pre_container_base(ax_
,bx_
,ay_
,by_
,az_
,bz_
,xperiodic_
,yperiodic_
,zperiodic_
,4) {};
145 void put(int n
,double x
,double y
,double z
,double r
);
146 void import(FILE *fp
=stdin
);
147 /** Imports particles from a file.
148 * \param[in] filename the name of the file to read from. */
149 inline void import(const char* filename
) {
150 FILE *fp
=safe_fopen(filename
,"r");
154 void setup(container_poly
&con
);
155 void setup(particle_order
&vo
,container_poly
&con
);