Strip extra spaces from code.
[voro++.git] / branches / exact / src / pre_container.hh
blob1acd23882adb8a3fb11f4983599ae65407f5b7d5
1 // Voro++, a 3D cell-based Voronoi library
2 //
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
13 #include "c_loops.hh"
14 #include "container.hh"
16 namespace voro {
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
24 * can be transferred.
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 {
30 public:
31 /** The minimum x coordinate of the container. */
32 const double ax;
33 /** The maximum x coordinate of the container. */
34 const double bx;
35 /** The minimum y coordinate of the container. */
36 const double ay;
37 /** The maximum y coordinate of the container. */
38 const double by;
39 /** The minimum z coordinate of the container. */
40 const double az;
41 /** The maximum z coordinate of the container. */
42 const double bz;
43 /** A boolean value that determines if the x coordinate in
44 * periodic or not. */
45 const bool xperiodic;
46 /** A boolean value that determines if the y coordinate in
47 * periodic or not. */
48 const bool yperiodic;
49 /** A boolean value that determines if the z coordinate in
50 * periodic or not. */
51 const bool zperiodic;
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
56 * within the class.
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);
61 protected:
62 /** The number of doubles associated with a single particle
63 * (three for the standard container, four when radius
64 * information is stored). */
65 const int ps;
66 void new_chunk();
67 void extend_chunk_index();
68 /** The size of the chunk index. */
69 int index_sz;
70 /** A pointer to the chunk index to store the integer particle
71 * IDs. */
72 int **pre_id;
73 /** A pointer to the last allocated integer ID chunk. */
74 int **end_id;
75 /** A pointer to the end of the integer ID chunk index, used to
76 * determine when the chunk index is full. */
77 int **l_id;
78 /** A pointer to the next available slot on the current
79 * particle ID chunk. */
80 int *ch_id;
81 /** A pointer to the end of the current integer chunk. */
82 int *e_id;
83 /** A pointer to the chunk index to store the floating point
84 * information associated with particles. */
85 double **pre_p;
86 /** A pointer to the last allocated chunk of floating point
87 * information. */
88 double **end_p;
89 /** A pointer to the next available slot on the current
90 * floating point chunk. */
91 double *ch_p;
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 {
100 public:
101 /** The class constructor sets up the geometry of container,
102 * initializing the minimum and maximum coordinates in each
103 * direction.
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");
119 import(fp);
120 fclose(fp);
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 {
132 public:
133 /** The class constructor sets up the geometry of container,
134 * initializing the minimum and maximum coordinates in each
135 * direction.
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");
151 import(fp);
152 fclose(fp);
154 void setup(container_poly &con);
155 void setup(particle_order &vo,container_poly &con);
160 #endif