Voro++
pre_container.hh
Go to the documentation of this file.
00001 // Voro++, a 3D cell-based Voronoi library
00002 //
00003 // Author   : Chris H. Rycroft (LBL / UC Berkeley)
00004 // Email    : chr@alum.mit.edu
00005 // Date     : August 30th 2011
00006 
00007 /** \file pre_container.hh
00008  * \brief Header file for the pre_container and related classes. */
00009 
00010 #ifndef VOROPP_PRE_CONTAINER_HH
00011 #define VOROPP_PRE_CONTAINER_HH
00012 
00013 #include "c_loops.hh"
00014 #include "container.hh"
00015 
00016 namespace voro {
00017 
00018 /** \brief A class for storing an arbitrary number of particles, prior to setting
00019  * up a container geometry.
00020  *
00021  * The pre_container_base class can dynamically import and store an arbitrary
00022  * number of particles. Once the particles have been read in, an appropriate
00023  * container class can be set up with the optimal grid size, and the particles
00024  * can be transferred.
00025  *
00026  * The pre_container_base class is not intended for direct use, but forms the
00027  * base of the pre_container and pre_container_poly classes, that add routines
00028  * depending on whether particle radii need to be tracked or not. */
00029 class pre_container_base {
00030         public:
00031                 /** The minimum x coordinate of the container. */
00032                 const double ax;
00033                 /** The maximum x coordinate of the container. */
00034                 const double bx;
00035                 /** The minimum y coordinate of the container. */
00036                 const double ay;
00037                 /** The maximum y coordinate of the container. */
00038                 const double by;
00039                 /** The minimum z coordinate of the container. */
00040                 const double az;
00041                 /** The maximum z coordinate of the container. */
00042                 const double bz;
00043                 /** A boolean value that determines if the x coordinate in
00044                  * periodic or not. */
00045                 const bool xperiodic;
00046                 /** A boolean value that determines if the y coordinate in
00047                  * periodic or not. */
00048                 const bool yperiodic;
00049                 /** A boolean value that determines if the z coordinate in
00050                  * periodic or not. */
00051                 const bool zperiodic;
00052                 void guess_optimal(int &nx,int &ny,int &nz);
00053                 pre_container_base(double ax_,double bx_,double ay_,double by_,double az_,double bz_,bool xperiodic_,bool yperiodic_,bool zperiodic_,int ps_);
00054                 ~pre_container_base();
00055                 /** Calculates and returns the total number of particles stored
00056                  * within the class.
00057                  * \return The number of particles. */
00058                 inline int total_particles() {
00059                         return (end_id-pre_id)*pre_container_chunk_size+(ch_id-*end_id);
00060                 }
00061         protected:
00062                 /** The number of doubles associated with a single particle
00063                  * (three for the standard container, four when radius
00064                  * information is stored). */
00065                 const int ps;
00066                 void new_chunk();
00067                 void extend_chunk_index();
00068                 /** The size of the chunk index. */
00069                 int index_sz;
00070                 /** A pointer to the chunk index to store the integer particle
00071                  * IDs. */
00072                 int **pre_id;
00073                 /** A pointer to the last allocated integer ID chunk. */
00074                 int **end_id;
00075                 /** A pointer to the end of the integer ID chunk index, used to
00076                  * determine when the chunk index is full. */
00077                 int **l_id;
00078                 /** A pointer to the next available slot on the current
00079                  * particle ID chunk. */
00080                 int *ch_id;
00081                 /** A pointer to the end of the current integer chunk. */
00082                 int *e_id;
00083                 /** A pointer to the chunk index to store the floating point
00084                  * information associated with particles. */
00085                 double **pre_p;
00086                 /** A pointer to the last allocated chunk of floating point
00087                  * information. */
00088                 double **end_p;
00089                 /** A pointer to the next available slot on the current
00090                  * floating point chunk. */
00091                 double *ch_p;
00092 };
00093 
00094 /** \brief A class for storing an arbitrary number of particles without radius
00095  * information, prior to setting up a container geometry.
00096  *
00097  * The pre_container class is an extension of the pre_container_base class for
00098  * cases when no particle radius information is available. */
00099 class pre_container : public pre_container_base {
00100         public:
00101                 /** The class constructor sets up the geometry of container,
00102                  * initializing the minimum and maximum coordinates in each
00103                  * direction.
00104                  * \param[in] (ax_,bx_) the minimum and maximum x coordinates.
00105                  * \param[in] (ay_,by_) the minimum and maximum y coordinates.
00106                  * \param[in] (az_,bz_) the minimum and maximum z coordinates.
00107                  * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the
00108                  *                                                container is periodic in
00109                  *                                                each coordinate direction. */
00110                 pre_container(double ax_,double bx_,double ay_,double by_,double az_,double bz_,
00111                                 bool xperiodic_,bool yperiodic_,bool zperiodic_)
00112                         : pre_container_base(ax_,bx_,ay_,by_,az_,bz_,xperiodic_,yperiodic_,zperiodic_,3) {};
00113                 void put(int n,double x,double y,double z);
00114                 void import(FILE *fp=stdin);
00115                 /** Imports particles from a file.
00116                  * \param[in] filename the name of the file to read from. */
00117                 inline void import(const char* filename) {
00118                         FILE *fp=safe_fopen(filename,"r");
00119                         import(fp);
00120                         fclose(fp);
00121                 }
00122                 void setup(container &con);
00123                 void setup(particle_order &vo,container &con);
00124 };
00125 
00126 /** \brief A class for storing an arbitrary number of particles with radius
00127  * information, prior to setting up a container geometry.
00128  *
00129  * The pre_container_poly class is an extension of the pre_container_base class
00130  * for cases when particle radius information is available. */
00131 class pre_container_poly : public pre_container_base {
00132         public:
00133                 /** The class constructor sets up the geometry of container,
00134                  * initializing the minimum and maximum coordinates in each
00135                  * direction.
00136                  * \param[in] (ax_,bx_) the minimum and maximum x coordinates.
00137                  * \param[in] (ay_,by_) the minimum and maximum y coordinates.
00138                  * \param[in] (az_,bz_) the minimum and maximum z coordinates.
00139                  * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the
00140                  *                                                container is periodic in
00141                  *                                                each coordinate direction. */
00142                 pre_container_poly(double ax_,double bx_,double ay_,double by_,double az_,double bz_,
00143                                 bool xperiodic_,bool yperiodic_,bool zperiodic_)
00144                         : pre_container_base(ax_,bx_,ay_,by_,az_,bz_,xperiodic_,yperiodic_,zperiodic_,4) {};
00145                 void put(int n,double x,double y,double z,double r);
00146                 void import(FILE *fp=stdin);
00147                 /** Imports particles from a file.
00148                  * \param[in] filename the name of the file to read from. */
00149                 inline void import(const char* filename) {
00150                         FILE *fp=safe_fopen(filename,"r");
00151                         import(fp);
00152                         fclose(fp);
00153                 }
00154                 void setup(container_poly &con);
00155                 void setup(particle_order &vo,container_poly &con);
00156 };
00157 
00158 }
00159 
00160 #endif