Reset platonic code.
[voro++.git] / branches / 2d / src / v_compute_2d.hh
blob6115c1e1e48a53d64dd6c63746f5a2d7787cab12
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 v_compute.hh
8 * \brief Header file for the 2D voro_compute template and related classes. */
10 #ifndef VOROPP_V_COMPUTE_2D_HH
11 #define VOROPP_V_COMPUTE_2D_HH
13 #include <cstdio>
14 #include <cstdlib>
15 #include <cmath>
16 #include <vector>
17 using namespace std;
19 #include "config.hh"
20 #include "worklist_2d.hh"
21 #include "cell_2d.hh"
22 #include "cell_nc_2d.hh"
24 namespace voro {
26 /** \brief Structure for holding information about a particle.
28 * This small structure holds information about a single particle, and is used
29 * by several of the routines in the voro_compute template for passing
30 * information by reference between functions. */
31 struct particle_record_2d {
32 /** The index of the block that the particle is within. */
33 int ij;
34 /** The number of particle within its block. */
35 int l;
36 /** The x-index of the block. */
37 int di;
38 /** The y-index of the block. */
39 int dj;
42 /** \brief Template for carrying out Voronoi cell computations. */
43 template <class c_class_2d>
44 class voro_compute_2d {
45 public:
46 /** A reference to the container class on which to carry out*/
47 c_class_2d &con;
48 /** The size of an internal computational block in the x
49 * direction. */
50 const double boxx;
51 /** The size of an internal computational block in the y
52 * direction. */
53 const double boxy;
54 /** The inverse box length in the x direction, set to
55 * nx/(bx-ax). */
56 const double xsp;
57 /** The inverse box length in the y direction, set to
58 * ny/(by-ay). */
59 const double ysp;
60 /** The number of boxes in the x direction for the searching mask. */
61 const int hx;
62 /** The number of boxes in the y direction for the searching mask. */
63 const int hy;
64 /** A constant, set to the value of hx multiplied by hy, which
65 * is used in the routines which step through mask boxes in
66 * sequence. */
67 const int hxy;
68 /** The number of floating point entries to store for each
69 * particle. */
70 const int ps;
71 /** This array holds the numerical IDs of each particle in each
72 * computational box. */
73 int **id;
74 /** A two dimensional array holding particle positions. For the
75 * derived container_poly class, this also holds particle
76 * radii. */
77 double **p;
78 /** An array holding the number of particles within each
79 * computational box of the container. */
80 int *co;
81 voro_compute_2d(c_class_2d &con_,int hx_,int hy_);
82 /** The class destructor frees the dynamically allocated memory
83 * for the mask and queue. */
84 ~voro_compute_2d() {
85 delete [] qu;
86 delete [] mask;
88 template<class v_cell_2d>
89 bool compute_cell(v_cell_2d &c,int ij,int s,int ci,int cj);
90 void find_voronoi_cell(double x,double y,int ci,int cj,int ij,particle_record_2d &w,double &mrs);
91 private:
92 /** A constant set to boxx*boxx+boxy*boxy+boxz*boxz, which is
93 * frequently used in the computation. */
94 const double bxsq;
95 /** This sets the current value being used to mark tested blocks
96 * in the mask. */
97 unsigned int mv;
98 /** The current size of the search list. */
99 int qu_size;
100 /** A pointer to the array of worklists. */
101 const unsigned int *wl;
102 /** An pointer to the array holding the minimum distances
103 * associated with the worklists. */
104 double *mrad;
105 /** This array is used during the cell computation to determine
106 * which blocks have been considered. */
107 unsigned int *mask;
108 /** An array is used to store the queue of blocks to test
109 * during the Voronoi cell computation. */
110 int *qu;
111 /** A pointer to the end of the queue array, used to determine
112 * when the queue is full. */
113 int *qu_l;
114 template<class v_cell_2d>
115 inline bool corner_test(v_cell_2d &c,double xl,double yl,double xh,double yh);
116 template<class v_cell_2d>
117 inline bool edge_x_test(v_cell_2d &c,double xl,double y0,double y1);
118 template<class v_cell_2d>
119 inline bool edge_y_test(v_cell_2d &c,double x0,double yl,double x1);
120 bool compute_min_max_radius(int di,int dj,double fx,double fy,double gx,double gy,double& crs,double mrs);
121 bool compute_min_radius(int di,int dj,double fx,double fy,double mrs);
122 inline void add_to_mask(int ei,int ej,int *&qu_e);
123 inline void scan_bits_mask_add(unsigned int q,unsigned int *mij,int ei,int ej,int *&qu_e);
124 inline void scan_all(int ij,double x,double y,int di,int dj,particle_record_2d &w,double &mrs);
125 void add_list_memory(int*& qu_s,int*& qu_e);
126 /** Resets the mask in cases where the mask counter wraps
127 * around. */
128 inline void reset_mask() {
129 for(unsigned int *mp=mask;mp<mask+hxy;mp++) *mp=0;
135 #endif