<ahref="voro_09_09_8hh.html">Go to the documentation of this file.</a><divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="comment">// Voro++, a 3D cell-based Voronoi library</span></div>
<divclass="line"><aname="l00008"></a><spanclass="lineno"> 8</span> <spanclass="comment"> * \brief A file that loads all of the Voro++ header files. */</span></div>
<divclass="line"><aname="l00012"></a><spanclass="lineno"> 12</span> <spanclass="comment"> * Voro++ is a software library for carrying out three-dimensional computations</span></div>
<divclass="line"><aname="l00013"></a><spanclass="lineno"> 13</span> <spanclass="comment"> * of the Voronoi tessellation. A distinguishing feature of the Voro++ library</span></div>
<divclass="line"><aname="l00014"></a><spanclass="lineno"> 14</span> <spanclass="comment"> * is that it carries out cell-based calculations, computing the Voronoi cell</span></div>
<divclass="line"><aname="l00015"></a><spanclass="lineno"> 15</span> <spanclass="comment"> * for each particle individually, rather than computing the Voronoi</span></div>
<divclass="line"><aname="l00016"></a><spanclass="lineno"> 16</span> <spanclass="comment"> * tessellation as a global network of vertices and edges. It is particularly</span></div>
<divclass="line"><aname="l00017"></a><spanclass="lineno"> 17</span> <spanclass="comment"> * well-suited for applications that rely on cell-based statistics, where</span></div>
<divclass="line"><aname="l00018"></a><spanclass="lineno"> 18</span> <spanclass="comment"> * features of Voronoi cells (eg. volume, centroid, number of faces) can be</span></div>
<divclass="line"><aname="l00019"></a><spanclass="lineno"> 19</span> <spanclass="comment"> * used to analyze a system of particles.</span></div>
<divclass="line"><aname="l00021"></a><spanclass="lineno"> 21</span> <spanclass="comment"> * Voro++ is written in C++ and can be built as a static library that can be</span></div>
<divclass="line"><aname="l00022"></a><spanclass="lineno"> 22</span> <spanclass="comment"> * linked to. This manual provides a reference for every function in the class</span></div>
<divclass="line"><aname="l00023"></a><spanclass="lineno"> 23</span> <spanclass="comment"> * structure. For a general overview of the program, see the Voro++ website at</span></div>
<divclass="line"><aname="l00024"></a><spanclass="lineno"> 24</span> <spanclass="comment"> * http://math.lbl.gov/voro++/ and in particular the example programs at</span></div>
<divclass="line"><aname="l00025"></a><spanclass="lineno"> 25</span> <spanclass="comment"> * http://math.lbl.gov/voro++/examples/ that demonstrate many of the library's</span></div>
<divclass="line"><aname="l00028"></a><spanclass="lineno"> 28</span> <spanclass="comment"> * \section class C++ class structure</span></div>
<divclass="line"><aname="l00029"></a><spanclass="lineno"> 29</span> <spanclass="comment"> * The code is structured around several C++ classes. The voronoicell_base</span></div>
<divclass="line"><aname="l00030"></a><spanclass="lineno"> 30</span> <spanclass="comment"> * class contains all of the routines for constructing a single Voronoi cell.</span></div>
<divclass="line"><aname="l00031"></a><spanclass="lineno"> 31</span> <spanclass="comment"> * It represents the cell as a collection of vertices that are connected by</span></div>
<divclass="line"><aname="l00032"></a><spanclass="lineno"> 32</span> <spanclass="comment"> * edges, and there are routines for initializing, making, and outputting the</span></div>
<divclass="line"><aname="l00033"></a><spanclass="lineno"> 33</span> <spanclass="comment"> * cell. The voronoicell_base class form the base of the voronoicell and</span></div>
<divclass="line"><aname="l00035"></a><spanclass="lineno"> 35</span> <spanclass="comment"> * whether neighboring particle ID information for each face must be tracked or</span></div>
<divclass="line"><aname="l00036"></a><spanclass="lineno"> 36</span> <spanclass="comment"> * not. Collectively, these classes are referred to as "voronoicell classes"</span></div>
<divclass="line"><aname="l00037"></a><spanclass="lineno"> 37</span> <spanclass="comment"> * within the documentation.</span></div>
<divclass="line"><aname="l00039"></a><spanclass="lineno"> 39</span> <spanclass="comment"> * There is a hierarchy of classes that represent three-dimensional particle</span></div>
<divclass="line"><aname="l00040"></a><spanclass="lineno"> 40</span> <spanclass="comment"> * systems. All of these are derived from the voro_base class, which contains</span></div>
<divclass="line"><aname="l00041"></a><spanclass="lineno"> 41</span> <spanclass="comment"> * constants that divide a three-dimensional system into a rectangular grid of</span></div>
<divclass="line"><aname="l00042"></a><spanclass="lineno"> 42</span> <spanclass="comment"> * equally-sized rectangular blocks; this grid is used for computational</span></div>
<divclass="line"><aname="l00043"></a><spanclass="lineno"> 43</span> <spanclass="comment"> * efficiency during the Voronoi calculations.</span></div>
<divclass="line"><aname="l00045"></a><spanclass="lineno"> 45</span> <spanclass="comment"> * The container_base, container, and container_poly are then derived from the</span></div>
<divclass="line"><aname="l00046"></a><spanclass="lineno"> 46</span> <spanclass="comment"> * voro_base class to represent a particle system in a specific</span></div>
<divclass="line"><aname="l00047"></a><spanclass="lineno"> 47</span> <spanclass="comment"> * three-dimensional rectangular box using both periodic and non-periodic</span></div>
<divclass="line"><aname="l00048"></a><spanclass="lineno"> 48</span> <spanclass="comment"> * boundary conditions. In addition, the container_periodic_base,</span></div>
<divclass="line"><aname="l00049"></a><spanclass="lineno"> 49</span> <spanclass="comment"> * container_periodic, and container_periodic_poly classes represent</span></div>
<divclass="line"><aname="l00050"></a><spanclass="lineno"> 50</span> <spanclass="comment"> * a particle system in a three-dimensional non-orthogonal periodic domain,</span></div>
<divclass="line"><aname="l00051"></a><spanclass="lineno"> 51</span> <spanclass="comment"> * defined by three periodicity vectors that represent a parallelepiped.</span></div>
<divclass="line"><aname="l00052"></a><spanclass="lineno"> 52</span> <spanclass="comment"> * Collectively, these classes are referred to as "container classes" within</span></div>
<divclass="line"><aname="l00053"></a><spanclass="lineno"> 53</span> <spanclass="comment"> * the documentation.</span></div>
<divclass="line"><aname="l00055"></a><spanclass="lineno"> 55</span> <spanclass="comment"> * The voro_compute template encapsulates all of the routines for computing</span></div>
<divclass="line"><aname="l00056"></a><spanclass="lineno"> 56</span> <spanclass="comment"> * Voronoi cells. Each container class has a voro_compute template within</span></div>
<divclass="line"><aname="l00057"></a><spanclass="lineno"> 57</span> <spanclass="comment"> * it, that accesses the container's particle system, and computes the Voronoi</span></div>
<divclass="line"><aname="l00060"></a><spanclass="lineno"> 60</span> <spanclass="comment"> * There are several wall classes that can be used to apply certain boundary</span></div>
<divclass="line"><aname="l00061"></a><spanclass="lineno"> 61</span> <spanclass="comment"> * conditions using additional plane cuts during the Voronoi cell compution.</span></div>
<divclass="line"><aname="l00062"></a><spanclass="lineno"> 62</span> <spanclass="comment"> * The code also contains a number of small loop classes, c_loop_all,</span></div>
<divclass="line"><aname="l00063"></a><spanclass="lineno"> 63</span> <spanclass="comment"> * c_loop_subset, c_loop_all_periodic, and c_loop_order that can be used to</span></div>
<divclass="line"><aname="l00064"></a><spanclass="lineno"> 64</span> <spanclass="comment"> * iterate over a certain subset of particles in a container. The latter class</span></div>
<divclass="line"><aname="l00065"></a><spanclass="lineno"> 65</span> <spanclass="comment"> * makes use of a special particle_order class that stores a specific order of</span></div>
<divclass="line"><aname="l00066"></a><spanclass="lineno"> 66</span> <spanclass="comment"> * particles within the container. The library also contains the classes</span></div>
<divclass="line"><aname="l00067"></a><spanclass="lineno"> 67</span> <spanclass="comment"> * pre_container_base, pre_container, and pre_container_poly, that can be used</span></div>
<divclass="line"><aname="l00068"></a><spanclass="lineno"> 68</span> <spanclass="comment"> * as temporary storage when importing data of unknown size.</span></div>
<divclass="line"><aname="l00070"></a><spanclass="lineno"> 70</span> <spanclass="comment"> * \section voronoicell The voronoicell classes</span></div>
<divclass="line"><aname="l00071"></a><spanclass="lineno"> 71</span> <spanclass="comment"> * The voronoicell class represents a single Voronoi cell as a convex</span></div>
<divclass="line"><aname="l00072"></a><spanclass="lineno"> 72</span> <spanclass="comment"> * polyhedron, with a set of vertices that are connected by edges. The class</span></div>
<divclass="line"><aname="l00073"></a><spanclass="lineno"> 73</span> <spanclass="comment"> * contains a variety of functions that can be used to compute and output the</span></div>
<divclass="line"><aname="l00074"></a><spanclass="lineno"> 74</span> <spanclass="comment"> * Voronoi cell corresponding to a particular particle. The command init()</span></div>
<divclass="line"><aname="l00075"></a><spanclass="lineno"> 75</span> <spanclass="comment"> * can be used to initialize a cell as a large rectangular box. The Voronoi cell</span></div>
<divclass="line"><aname="l00076"></a><spanclass="lineno"> 76</span> <spanclass="comment"> * can then be computed by repeatedly cutting it with planes that correspond to</span></div>
<divclass="line"><aname="l00077"></a><spanclass="lineno"> 77</span> <spanclass="comment"> * the perpendicular bisectors between that particle and its neighbors.</span></div>
<divclass="line"><aname="l00079"></a><spanclass="lineno"> 79</span> <spanclass="comment"> * This is achieved by using the plane() routine, which will recompute the</span></div>
<divclass="line"><aname="l00080"></a><spanclass="lineno"> 80</span> <spanclass="comment"> * cell's vertices and edges after cutting it with a single plane. This is the</span></div>
<divclass="line"><aname="l00081"></a><spanclass="lineno"> 81</span> <spanclass="comment"> * key routine in voronoicell class. It begins by exploiting the convexity</span></div>
<divclass="line"><aname="l00082"></a><spanclass="lineno"> 82</span> <spanclass="comment"> * of the underlying cell, tracing between edges to work out if the cell</span></div>
<divclass="line"><aname="l00083"></a><spanclass="lineno"> 83</span> <spanclass="comment"> * intersects the cutting plane. If it does not intersect, then the routine</span></div>
<divclass="line"><aname="l00084"></a><spanclass="lineno"> 84</span> <spanclass="comment"> * immediately exits. Otherwise, it finds an edge or vertex that intersects</span></div>
<divclass="line"><aname="l00085"></a><spanclass="lineno"> 85</span> <spanclass="comment"> * the plane, and from there, traces out a new face on the cell, recomputing</span></div>
<divclass="line"><aname="l00086"></a><spanclass="lineno"> 86</span> <spanclass="comment"> * the edge and vertex structure accordingly.</span></div>
<divclass="line"><aname="l00088"></a><spanclass="lineno"> 88</span> <spanclass="comment"> * Once the cell is computed, there are many routines for computing features of</span></div>
<divclass="line"><aname="l00089"></a><spanclass="lineno"> 89</span> <spanclass="comment"> * the the Voronoi cell, such as its volume, surface area, or centroid. There</span></div>
<divclass="line"><aname="l00090"></a><spanclass="lineno"> 90</span> <spanclass="comment"> * are also many routines for outputting features of the Voronoi cell, or</span></div>
<divclass="line"><aname="l00091"></a><spanclass="lineno"> 91</span> <spanclass="comment"> * writing its shape in formats that can be read by Gnuplot or POV-Ray.</span></div>
<divclass="line"><aname="l00093"></a><spanclass="lineno"> 93</span> <spanclass="comment"> * \subsection internal Internal data representation</span></div>
<divclass="line"><aname="l00094"></a><spanclass="lineno"> 94</span> <spanclass="comment"> * The voronoicell class has a public member p representing the</span></div>
<divclass="line"><aname="l00095"></a><spanclass="lineno"> 95</span> <spanclass="comment"> * number of vertices. The polyhedral structure of the cell is stored</span></div>
<divclass="line"><aname="l00096"></a><spanclass="lineno"> 96</span> <spanclass="comment"> * in the following arrays:</span></div>
<divclass="line"><aname="l00098"></a><spanclass="lineno"> 98</span> <spanclass="comment"> * - pts: a one-dimensional array of floating point numbers, that represent the</span></div>
<divclass="line"><aname="l00099"></a><spanclass="lineno"> 99</span> <spanclass="comment"> * position vectors x_0, x_1, ..., x_{p-1} of the polyhedron vertices.</span></div>
<divclass="line"><aname="l00100"></a><spanclass="lineno"> 100</span> <spanclass="comment"> * - nu: the order of each vertex n_0, n_1, ..., n_{p-1}, corresponding to</span></div>
<divclass="line"><aname="l00101"></a><spanclass="lineno"> 101</span> <spanclass="comment"> * the number of other vertices to which each is connected.</span></div>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="comment"> * - ed: a two-dimensional table of edges and relations. For the ith vertex,</span></div>
<divclass="line"><aname="l00103"></a><spanclass="lineno"> 103</span> <spanclass="comment"> * ed[i] has 2n_i+1 elements. The first n_i elements are the edges e(j,i),</span></div>
<divclass="line"><aname="l00104"></a><spanclass="lineno"> 104</span> <spanclass="comment"> * where e(j,i) is the jth neighbor of vertex i. The edges are ordered</span></div>
<divclass="line"><aname="l00105"></a><spanclass="lineno"> 105</span> <spanclass="comment"> * according to a right-hand rule with respect to an outward-pointing normal.</span></div>
<divclass="line"><aname="l00106"></a><spanclass="lineno"> 106</span> <spanclass="comment"> * The next n_i elements are the relations l(j,i) which satisfy the property</span></div>
<divclass="line"><aname="l00107"></a><spanclass="lineno"> 107</span> <spanclass="comment"> * e(l(j,i),e(j,i)) = i. The final element of the ed[i] list is a back</span></div>
<divclass="line"><aname="l00108"></a><spanclass="lineno"> 108</span> <spanclass="comment"> * pointer used in memory allocation.</span></div>
<divclass="line"><aname="l00110"></a><spanclass="lineno"> 110</span> <spanclass="comment"> * In a very large number of cases, the values of n_i will be 3. This is because</span></div>
<divclass="line"><aname="l00111"></a><spanclass="lineno"> 111</span> <spanclass="comment"> * the only way that a higher-order vertex can be created in the plane()</span></div>
<divclass="line"><aname="l00112"></a><spanclass="lineno"> 112</span> <spanclass="comment"> * routine is if the cutting plane perfectly intersects an existing vertex. For</span></div>
<divclass="line"><aname="l00113"></a><spanclass="lineno"> 113</span> <spanclass="comment"> * random particle arrangements with position vectors specified to double</span></div>
<divclass="line"><aname="l00114"></a><spanclass="lineno"> 114</span> <spanclass="comment"> * precision this should happen very rarely. A preliminary version of this code</span></div>
<divclass="line"><aname="l00115"></a><spanclass="lineno"> 115</span> <spanclass="comment"> * was quite successful with only making use of vertices of order 3. However,</span></div>
<divclass="line"><aname="l00116"></a><spanclass="lineno"> 116</span> <spanclass="comment"> * when calculating millions of cells, it was found that this approach is not</span></div>
<divclass="line"><aname="l00117"></a><spanclass="lineno"> 117</span> <spanclass="comment"> * robust, since a single floating point error can invalidate the computation.</span></div>
<divclass="line"><aname="l00118"></a><spanclass="lineno"> 118</span> <spanclass="comment"> * This can also be a problem for cases featuring crystalline arrangements of</span></div>
<divclass="line"><aname="l00119"></a><spanclass="lineno"> 119</span> <spanclass="comment"> * particles where the corresponding Voronoi cells may have high-order vertices</span></div>
<divclass="line"><aname="l00120"></a><spanclass="lineno"> 120</span> <spanclass="comment"> * by construction.</span></div>
<divclass="line"><aname="l00122"></a><spanclass="lineno"> 122</span> <spanclass="comment"> * Because of this, Voro++ takes the approach that it if an existing vertex is</span></div>
<divclass="line"><aname="l00123"></a><spanclass="lineno"> 123</span> <spanclass="comment"> * within a small numerical tolerance of the cutting plane, it is treated as</span></div>
<divclass="line"><aname="l00124"></a><spanclass="lineno"> 124</span> <spanclass="comment"> * being exactly on the plane, and the polyhedral topology is recomputed</span></div>
<divclass="line"><aname="l00125"></a><spanclass="lineno"> 125</span> <spanclass="comment"> * accordingly. However, while this improves robustness, it also adds the</span></div>
<divclass="line"><aname="l00126"></a><spanclass="lineno"> 126</span> <spanclass="comment"> * complexity that n_i may no longer always be 3. This causes memory management</span></div>
<divclass="line"><aname="l00127"></a><spanclass="lineno"> 127</span> <spanclass="comment"> * to be significantly more complicated, as different vertices require a</span></div>
<divclass="line"><aname="l00128"></a><spanclass="lineno"> 128</span> <spanclass="comment"> * different number of elements in the ed[][] array. To accommodate this, the</span></div>
<divclass="line"><aname="l00129"></a><spanclass="lineno"> 129</span> <spanclass="comment"> * voronoicell class allocated edge memory in a different array called mep[][],</span></div>
<divclass="line"><aname="l00130"></a><spanclass="lineno"> 130</span> <spanclass="comment"> * in such a way that all vertices of order k are held in mep[k]. If vertex</span></div>
<divclass="line"><aname="l00131"></a><spanclass="lineno"> 131</span> <spanclass="comment"> * i has order k, then ed[i] points to memory within mep[k]. The array ed[][]</span></div>
<divclass="line"><aname="l00132"></a><spanclass="lineno"> 132</span> <spanclass="comment"> * is never directly initialized as a two-dimensional array itself, but points</span></div>
<divclass="line"><aname="l00133"></a><spanclass="lineno"> 133</span> <spanclass="comment"> * at allocations within mep[][]. To the user, it appears as though each row of</span></div>
<divclass="line"><aname="l00134"></a><spanclass="lineno"> 134</span> <spanclass="comment"> * ed[][] has a different number of elements. When vertices are added or</span></div>
<divclass="line"><aname="l00135"></a><spanclass="lineno"> 135</span> <spanclass="comment"> * deleted, care must be taken to reorder and reassign elements in these</span></div>
<divclass="line"><aname="l00138"></a><spanclass="lineno"> 138</span> <spanclass="comment"> * During the plane() routine, the code traces around the vertices of the cell,</span></div>
<divclass="line"><aname="l00139"></a><spanclass="lineno"> 139</span> <spanclass="comment"> * and adds new vertices along edges which intersect the cutting plane to</span></div>
<divclass="line"><aname="l00140"></a><spanclass="lineno"> 140</span> <spanclass="comment"> * create a new face. The values of l(j,i) are used in this computation, as</span></div>
<divclass="line"><aname="l00141"></a><spanclass="lineno"> 141</span> <spanclass="comment"> * when the code is traversing from one vertex on the cell to another, this</span></div>
<divclass="line"><aname="l00142"></a><spanclass="lineno"> 142</span> <spanclass="comment"> * information allows the code to immediately work out which edge of a vertex</span></div>
<divclass="line"><aname="l00143"></a><spanclass="lineno"> 143</span> <spanclass="comment"> * points back to the one it came from. As new vertices are created, the l(j,i)</span></div>
<divclass="line"><aname="l00144"></a><spanclass="lineno"> 144</span> <spanclass="comment"> * are also updated to ensure consistency. To ensure robustness, the plane</span></div>
<divclass="line"><aname="l00145"></a><spanclass="lineno"> 145</span> <spanclass="comment"> * cutting algorithm should work with any possible combination of vertices</span></div>
<divclass="line"><aname="l00146"></a><spanclass="lineno"> 146</span> <spanclass="comment"> * which are inside, outside, or exactly on the cutting plane.</span></div>
<divclass="line"><aname="l00148"></a><spanclass="lineno"> 148</span> <spanclass="comment"> * Vertices exactly on the cutting plane create some additional computational</span></div>
<divclass="line"><aname="l00149"></a><spanclass="lineno"> 149</span> <spanclass="comment"> * difficulties. If there are two marginal vertices connected by an existing</span></div>
<divclass="line"><aname="l00150"></a><spanclass="lineno"> 150</span> <spanclass="comment"> * edge, then it would be possible for duplicate edges to be created between</span></div>
<divclass="line"><aname="l00151"></a><spanclass="lineno"> 151</span> <spanclass="comment"> * those two vertices, if the plane routine traces along both sides of this</span></div>
<divclass="line"><aname="l00152"></a><spanclass="lineno"> 152</span> <spanclass="comment"> * edge while constructing the new face. The code recognizes these cases and</span></div>
<divclass="line"><aname="l00153"></a><spanclass="lineno"> 153</span> <spanclass="comment"> * prevents the double edge from being formed. Another possibility is the</span></div>
<divclass="line"><aname="l00154"></a><spanclass="lineno"> 154</span> <spanclass="comment"> * formation of vertices of order two or one. At the end of the plane cutting</span></div>
<divclass="line"><aname="l00155"></a><spanclass="lineno"> 155</span> <spanclass="comment"> * routine, the code checks to see if any of these are present, removing the</span></div>
<divclass="line"><aname="l00156"></a><spanclass="lineno"> 156</span> <spanclass="comment"> * order one vertices by just deleting them, and removing the order two</span></div>
<divclass="line"><aname="l00157"></a><spanclass="lineno"> 157</span> <spanclass="comment"> * vertices by connecting the two neighbors of each vertex together. It is</span></div>
<divclass="line"><aname="l00158"></a><spanclass="lineno"> 158</span> <spanclass="comment"> * possible that the removal of a single low-order vertex could result in the</span></div>
<divclass="line"><aname="l00159"></a><spanclass="lineno"> 159</span> <spanclass="comment"> * creation of additional low-order vertices, so the process is applied</span></div>
<divclass="line"><aname="l00160"></a><spanclass="lineno"> 160</span> <spanclass="comment"> * recursively until no more are left.</span></div>
<divclass="line"><aname="l00162"></a><spanclass="lineno"> 162</span> <spanclass="comment"> * \section container The container classes</span></div>
<divclass="line"><aname="l00163"></a><spanclass="lineno"> 163</span> <spanclass="comment"> * There are four container classes available for general usage: container,</span></div>
<divclass="line"><aname="l00164"></a><spanclass="lineno"> 164</span> <spanclass="comment"> * container_poly, container_periodic, and container_periodic_poly. Each of</span></div>
<divclass="line"><aname="l00165"></a><spanclass="lineno"> 165</span> <spanclass="comment"> * these represent a system of particles in a specific three-dimensional</span></div>
<divclass="line"><aname="l00166"></a><spanclass="lineno"> 166</span> <spanclass="comment"> * geometry. They contain routines for importing particles from a text file,</span></div>
<divclass="line"><aname="l00167"></a><spanclass="lineno"> 167</span> <spanclass="comment"> * and adding particles individually. They also contain a large number of</span></div>
<divclass="line"><aname="l00168"></a><spanclass="lineno"> 168</span> <spanclass="comment"> * analyzing and outputting the particle system. Internally, the routines that</span></div>
<divclass="line"><aname="l00169"></a><spanclass="lineno"> 169</span> <spanclass="comment"> * compute Voronoi cells do so by making use of the voro_compute template.</span></div>
<divclass="line"><aname="l00170"></a><spanclass="lineno"> 170</span> <spanclass="comment"> * Each container class contains routines that tell the voro_compute template</span></div>
<divclass="line"><aname="l00171"></a><spanclass="lineno"> 171</span> <spanclass="comment"> * about the specific geometry of this container.</span></div>
<divclass="line"><aname="l00173"></a><spanclass="lineno"> 173</span> <spanclass="comment"> * \section voro_compute The voro_compute template</span></div>
<divclass="line"><aname="l00174"></a><spanclass="lineno"> 174</span> <spanclass="comment"> * The voro_compute template encapsulates the routines for carrying out the</span></div>
<divclass="line"><aname="l00175"></a><spanclass="lineno"> 175</span> <spanclass="comment"> * Voronoi cell computations. It contains data structures suchs as a mask and a</span></div>
<divclass="line"><aname="l00176"></a><spanclass="lineno"> 176</span> <spanclass="comment"> * queue that are used in the computations. The voro_compute template is</span></div>
<divclass="line"><aname="l00177"></a><spanclass="lineno"> 177</span> <spanclass="comment"> * associated with a specific container class, and during the computation, it</span></div>
<divclass="line"><aname="l00178"></a><spanclass="lineno"> 178</span> <spanclass="comment"> * calls routines in the container class to access the particle positions that</span></div>
<divclass="line"><aname="l00179"></a><spanclass="lineno"> 179</span> <spanclass="comment"> * are stored there.</span></div>
<divclass="line"><aname="l00181"></a><spanclass="lineno"> 181</span> <spanclass="comment"> * The key routine in this class is compute_cell(), which makes use of a</span></div>
<divclass="line"><aname="l00182"></a><spanclass="lineno"> 182</span> <spanclass="comment"> * voronoicell class to construct a Voronoi cell for a specific particle in the</span></div>
<divclass="line"><aname="l00183"></a><spanclass="lineno"> 183</span> <spanclass="comment"> * container. The basic approach that this function takes is to repeatedly cut</span></div>
<divclass="line"><aname="l00184"></a><spanclass="lineno"> 184</span> <spanclass="comment"> * the Voronoi cell by planes corresponding neighboring particles, and stop</span></div>
<divclass="line"><aname="l00185"></a><spanclass="lineno"> 185</span> <spanclass="comment"> * when it recognizes that all the remaining particles in the container are too</span></div>
<divclass="line"><aname="l00186"></a><spanclass="lineno"> 186</span> <spanclass="comment"> * far away to possibly influence cell's shape. The code makes use of two</span></div>
<divclass="line"><aname="l00187"></a><spanclass="lineno"> 187</span> <spanclass="comment"> * possible methods for working out when a cell computation is complete:</span></div>
<divclass="line"><aname="l00189"></a><spanclass="lineno"> 189</span> <spanclass="comment"> * - Radius test: if the maximum distance of a Voronoi cell</span></div>
<divclass="line"><aname="l00190"></a><spanclass="lineno"> 190</span> <spanclass="comment"> * vertex from the cell center is R, then no particles more than a distance</span></div>
<divclass="line"><aname="l00191"></a><spanclass="lineno"> 191</span> <spanclass="comment"> * 2R away can possibly influence the cell. This a very fast computation to</span></div>
<divclass="line"><aname="l00192"></a><spanclass="lineno"> 192</span> <spanclass="comment"> * do, but it has no directionality: if the cell extends a long way in one</span></div>
<divclass="line"><aname="l00193"></a><spanclass="lineno"> 193</span> <spanclass="comment"> * direction then particles a long distance in other directions will still</span></div>
<divclass="line"><aname="l00194"></a><spanclass="lineno"> 194</span> <spanclass="comment"> * need to be tested.</span></div>
<divclass="line"><aname="l00195"></a><spanclass="lineno"> 195</span> <spanclass="comment"> * - Region test: it is possible to test whether a specific region can</span></div>
<divclass="line"><aname="l00196"></a><spanclass="lineno"> 196</span> <spanclass="comment"> * possibly influence the cell by applying a series of plane tests at the</span></div>
<divclass="line"><aname="l00197"></a><spanclass="lineno"> 197</span> <spanclass="comment"> * point on the region which is closest to the Voronoi cell center. This is a</span></div>
<divclass="line"><aname="l00198"></a><spanclass="lineno"> 198</span> <spanclass="comment"> * slower computation to do, but it has directionality.</span></div>
<divclass="line"><aname="l00200"></a><spanclass="lineno"> 200</span> <spanclass="comment"> * Another useful observation is that the regions that need to be tested are</span></div>
<divclass="line"><aname="l00201"></a><spanclass="lineno"> 201</span> <spanclass="comment"> * simply connected, meaning that if a particular region does not need to be</span></div>
<divclass="line"><aname="l00202"></a><spanclass="lineno"> 202</span> <spanclass="comment"> * tested, then neighboring regions which are further away do not need to be</span></div>
<divclass="line"><aname="l00205"></a><spanclass="lineno"> 205</span> <spanclass="comment"> * For maximum efficiency, it was found that a hybrid approach making use of</span></div>
<divclass="line"><aname="l00206"></a><spanclass="lineno"> 206</span> <spanclass="comment"> * both of the above tests worked well in practice. Radius tests work well for</span></div>
<divclass="line"><aname="l00207"></a><spanclass="lineno"> 207</span> <spanclass="comment"> * the first few blocks, but switching to region tests after then prevent the</span></div>
<divclass="line"><aname="l00208"></a><spanclass="lineno"> 208</span> <spanclass="comment"> * code from becoming extremely slow, due to testing over very large spherical</span></div>
<divclass="line"><aname="l00209"></a><spanclass="lineno"> 209</span> <spanclass="comment"> * shells of particles. The compute_cell() routine therefore takes the</span></div>
<divclass="line"><aname="l00210"></a><spanclass="lineno"> 210</span> <spanclass="comment"> * following approach:</span></div>
<divclass="line"><aname="l00212"></a><spanclass="lineno"> 212</span> <spanclass="comment"> * - Initialize the voronoicell class to fill the entire computational domain.</span></div>
<divclass="line"><aname="l00213"></a><spanclass="lineno"> 213</span> <spanclass="comment"> * - Cut the cell by any wall objects that have been added to the container.</span></div>
<divclass="line"><aname="l00214"></a><spanclass="lineno"> 214</span> <spanclass="comment"> * - Apply plane cuts to the cell corresponding to the other particles which</span></div>
<divclass="line"><aname="l00215"></a><spanclass="lineno"> 215</span> <spanclass="comment"> * are within the current particle's region.</span></div>
<divclass="line"><aname="l00216"></a><spanclass="lineno"> 216</span> <spanclass="comment"> * - Test over a pre-computed worklist of neighboring regions, that have been</span></div>
<divclass="line"><aname="l00217"></a><spanclass="lineno"> 217</span> <spanclass="comment"> * ordered according to the minimum distance away from the particle's</span></div>
<divclass="line"><aname="l00218"></a><spanclass="lineno"> 218</span> <spanclass="comment"> * position. Apply radius tests after every few regions to see if the</span></div>
<divclass="line"><aname="l00219"></a><spanclass="lineno"> 219</span> <spanclass="comment"> * calculation can terminate.</span></div>
<divclass="line"><aname="l00220"></a><spanclass="lineno"> 220</span> <spanclass="comment"> * - If the code reaches the end of the worklist, add all the neighboring</span></div>
<divclass="line"><aname="l00221"></a><spanclass="lineno"> 221</span> <spanclass="comment"> * regions to a new list.</span></div>
<divclass="line"><aname="l00222"></a><spanclass="lineno"> 222</span> <spanclass="comment"> * - Carry out a region test on the first item of the list. If the region needs</span></div>
<divclass="line"><aname="l00223"></a><spanclass="lineno"> 223</span> <spanclass="comment"> * to be tested, apply the plane() routine for all of its particles, and then</span></div>
<divclass="line"><aname="l00224"></a><spanclass="lineno"> 224</span> <spanclass="comment"> * add any neighboring regions to the end of the list that need to be tested.</span></div>
<divclass="line"><aname="l00225"></a><spanclass="lineno"> 225</span> <spanclass="comment"> * Continue until the list has no elements left.</span></div>
<divclass="line"><aname="l00227"></a><spanclass="lineno"> 227</span> <spanclass="comment"> * The compute_cell() routine forms the basis of many other routines, such as</span></div>
<divclass="line"><aname="l00228"></a><spanclass="lineno"> 228</span> <spanclass="comment"> * store_cell_volumes() and draw_cells_gnuplot() that can be used to calculate</span></div>
<divclass="line"><aname="l00229"></a><spanclass="lineno"> 229</span> <spanclass="comment"> * and draw the cells in a container.</span></div>
<divclass="line"><aname="l00232"></a><spanclass="lineno"> 232</span> <spanclass="comment"> * Wall computations are handled by making use of a pure virtual wall class.</span></div>
<divclass="line"><aname="l00233"></a><spanclass="lineno"> 233</span> <spanclass="comment"> * Specific wall types are derived from this class, and require the</span></div>
<divclass="line"><aname="l00234"></a><spanclass="lineno"> 234</span> <spanclass="comment"> * specification of two routines: point_inside() that tests to see if a point</span></div>
<divclass="line"><aname="l00235"></a><spanclass="lineno"> 235</span> <spanclass="comment"> * is inside a wall or not, and cut_cell() that cuts a cell according to the</span></div>
<divclass="line"><aname="l00236"></a><spanclass="lineno"> 236</span> <spanclass="comment"> * wall's position. The walls can be added to the container using the</span></div>
<divclass="line"><aname="l00237"></a><spanclass="lineno"> 237</span> <spanclass="comment"> * add_wall() command, and these are called each time a compute_cell() command</span></div>
<divclass="line"><aname="l00238"></a><spanclass="lineno"> 238</span> <spanclass="comment"> * is carried out. At present, wall types for planes, spheres, cylinders, and</span></div>
<divclass="line"><aname="l00239"></a><spanclass="lineno"> 239</span> <spanclass="comment"> * cones are provided, although custom walls can be added by creating new</span></div>
<divclass="line"><aname="l00240"></a><spanclass="lineno"> 240</span> <spanclass="comment"> * classes derived from the pure virtual class. Currently all wall types</span></div>
<divclass="line"><aname="l00241"></a><spanclass="lineno"> 241</span> <spanclass="comment"> * approximate the wall surface with a single plane, which produces some small</span></div>
<divclass="line"><aname="l00242"></a><spanclass="lineno"> 242</span> <spanclass="comment"> * errors, but generally gives good results for dense particle packings in</span></div>
<divclass="line"><aname="l00243"></a><spanclass="lineno"> 243</span> <spanclass="comment"> * direct contact with a wall surface. It would be possible to create more</span></div>
<divclass="line"><aname="l00244"></a><spanclass="lineno"> 244</span> <spanclass="comment"> * accurate walls by making cut_cell() routines that approximate the curved</span></div>
<divclass="line"><aname="l00245"></a><spanclass="lineno"> 245</span> <spanclass="comment"> * surface with multiple plane cuts.</span></div>
<divclass="line"><aname="l00247"></a><spanclass="lineno"> 247</span> <spanclass="comment"> * The wall objects can used for periodic calculations, although to obtain</span></div>
<divclass="line"><aname="l00248"></a><spanclass="lineno"> 248</span> <spanclass="comment"> * valid results, the walls should also be periodic as well. For example, in a</span></div>
<divclass="line"><aname="l00249"></a><spanclass="lineno"> 249</span> <spanclass="comment"> * domain that is periodic in the x direction, a cylinder aligned along the x</span></div>
<divclass="line"><aname="l00250"></a><spanclass="lineno"> 250</span> <spanclass="comment"> * axis could be added. At present, the interior of all wall objects are convex</span></div>
<divclass="line"><aname="l00251"></a><spanclass="lineno"> 251</span> <spanclass="comment"> * domains, and consequently any superposition of them will be a convex domain</span></div>
<divclass="line"><aname="l00252"></a><spanclass="lineno"> 252</span> <spanclass="comment"> * also. Carrying out computations in non-convex domains poses some problems,</span></div>
<divclass="line"><aname="l00253"></a><spanclass="lineno"> 253</span> <spanclass="comment"> * since this could theoretically lead to non-convex Voronoi cells, which the</span></div>
<divclass="line"><aname="l00254"></a><spanclass="lineno"> 254</span> <spanclass="comment"> * internal data representation of the voronoicell class does not support. For</span></div>
<divclass="line"><aname="l00255"></a><spanclass="lineno"> 255</span> <spanclass="comment"> * non-convex cases where the wall surfaces feature just a small amount of</span></div>
<divclass="line"><aname="l00256"></a><spanclass="lineno"> 256</span> <spanclass="comment"> * negative curvature (eg. a torus) approximating the curved surface with a</span></div>
<divclass="line"><aname="l00257"></a><spanclass="lineno"> 257</span> <spanclass="comment"> * single plane cut may give an acceptable level of accuracy. For non-convex</span></div>
<divclass="line"><aname="l00258"></a><spanclass="lineno"> 258</span> <spanclass="comment"> * cases that feature internal angles, the best strategy may be to decompose</span></div>
<divclass="line"><aname="l00259"></a><spanclass="lineno"> 259</span> <spanclass="comment"> * the domain into several convex subdomains, carry out a calculation in each,</span></div>
<divclass="line"><aname="l00260"></a><spanclass="lineno"> 260</span> <spanclass="comment"> * and then add the results together. The voronoicell class cannot be easily</span></div>
<divclass="line"><aname="l00261"></a><spanclass="lineno"> 261</span> <spanclass="comment"> * modified to handle non-convex cells as this would fundamentally alter the</span></div>
<divclass="line"><aname="l00262"></a><spanclass="lineno"> 262</span> <spanclass="comment"> * algorithms that it uses, and cases could arise where a single plane cut</span></div>
<divclass="line"><aname="l00263"></a><spanclass="lineno"> 263</span> <spanclass="comment"> * could create several new faces as opposed to just one.</span></div>
<divclass="line"><aname="l00266"></a><spanclass="lineno"> 266</span> <spanclass="comment"> * The container classes have a number of simple routines for calculating</span></div>
<divclass="line"><aname="l00267"></a><spanclass="lineno"> 267</span> <spanclass="comment"> * Voronoi cells for all particles within them. However, in some situations it</span></div>
<divclass="line"><aname="l00268"></a><spanclass="lineno"> 268</span> <spanclass="comment"> * is desirable to iterate over a specific subset of particles. This can be</span></div>
<divclass="line"><aname="l00269"></a><spanclass="lineno"> 269</span> <spanclass="comment"> * achieved with the c_loop classes that are all derived from the c_loop_base</span></div>
<divclass="line"><aname="l00270"></a><spanclass="lineno"> 270</span> <spanclass="comment"> * class. Each class can iterate over a specific subset of particles in a</span></div>
<divclass="line"><aname="l00271"></a><spanclass="lineno"> 271</span> <spanclass="comment"> * container. There are three loop classes for use with the container and</span></div>
<divclass="line"><aname="l00274"></a><spanclass="lineno"> 274</span> <spanclass="comment"> * - c_loop_all will loop over all of the particles in a container.</span></div>
<divclass="line"><aname="l00275"></a><spanclass="lineno"> 275</span> <spanclass="comment"> * - c_loop_subset will loop over a subset of particles in a container that lie</span></div>
<divclass="line"><aname="l00276"></a><spanclass="lineno"> 276</span> <spanclass="comment"> * within some geometrical region. It can loop over particles in a</span></div>
<divclass="line"><aname="l00277"></a><spanclass="lineno"> 277</span> <spanclass="comment"> * rectangular box, particles in a sphere, or particles that lie within</span></div>
<divclass="line"><aname="l00278"></a><spanclass="lineno"> 278</span> <spanclass="comment"> * specific internal computational blocks.</span></div>
<divclass="line"><aname="l00279"></a><spanclass="lineno"> 279</span> <spanclass="comment"> * - c_loop_order will loop over a specific list of particles that were</span></div>
<divclass="line"><aname="l00280"></a><spanclass="lineno"> 280</span> <spanclass="comment"> * previously stored in a particle_order class.</span></div>
<divclass="line"><aname="l00282"></a><spanclass="lineno"> 282</span> <spanclass="comment"> * Several of the key routines within the container classes (such as</span></div>
<divclass="line"><aname="l00283"></a><spanclass="lineno"> 283</span> <spanclass="comment"> * draw_cells_gnuplot and print_custom) have versions where they can be passed</span></div>
<divclass="line"><aname="l00284"></a><spanclass="lineno"> 284</span> <spanclass="comment"> * a loop class to use. Loop classes can also be used directly and there are</span></div>
<divclass="line"><aname="l00285"></a><spanclass="lineno"> 285</span> <spanclass="comment"> * some examples on the library website that demonstrate this. It is also</span></div>
<divclass="line"><aname="l00286"></a><spanclass="lineno"> 286</span> <spanclass="comment"> * possible to write custom loop classes.</span></div>
<divclass="line"><aname="l00288"></a><spanclass="lineno"> 288</span> <spanclass="comment"> * In addition to the loop classes mentioned above, there is also a</span></div>
<divclass="line"><aname="l00289"></a><spanclass="lineno"> 289</span> <spanclass="comment"> * c_loop_all_periodic class, that is specifically for use with the</span></div>
<divclass="line"><aname="l00290"></a><spanclass="lineno"> 290</span> <spanclass="comment"> * container_periodic and container_periodic_poly classes. Since the data</span></div>
<divclass="line"><aname="l00291"></a><spanclass="lineno"> 291</span> <spanclass="comment"> * structures of these containers differ considerably, it requires a different</span></div>
<divclass="line"><aname="l00292"></a><spanclass="lineno"> 292</span> <spanclass="comment"> * loop class that is not interoperable with the others.</span></div>
<divclass="line"><aname="l00294"></a><spanclass="lineno"> 294</span> <spanclass="comment"> * \section pre_container The pre_container classes</span></div>
<divclass="line"><aname="l00295"></a><spanclass="lineno"> 295</span> <spanclass="comment"> * Voro++ makes use of internal computational grid of blocks that are used to</span></div>
<divclass="line"><aname="l00296"></a><spanclass="lineno"> 296</span> <spanclass="comment"> * configure the code for maximum efficiency. As discussed on the library</span></div>
<divclass="line"><aname="l00297"></a><spanclass="lineno"> 297</span> <spanclass="comment"> * website, the best performance is achieved for around 5 particles per block,</span></div>
<divclass="line"><aname="l00298"></a><spanclass="lineno"> 298</span> <spanclass="comment"> * with anything in the range from 3 to 12 giving good performance. Usually</span></div>
<divclass="line"><aname="l00299"></a><spanclass="lineno"> 299</span> <spanclass="comment"> * the size of the grid can be chosen by ensuring that the number of blocks is</span></div>
<divclass="line"><aname="l00300"></a><spanclass="lineno"> 300</span> <spanclass="comment"> * equal to the number of particles divided by 5.</span></div>
<divclass="line"><aname="l00302"></a><spanclass="lineno"> 302</span> <spanclass="comment"> * However, this can be difficult to choose in cases when the number of</span></div>
<divclass="line"><aname="l00303"></a><spanclass="lineno"> 303</span> <spanclass="comment"> * particles is not known a priori, and in thes cases the pre_container classes</span></div>
<divclass="line"><aname="l00304"></a><spanclass="lineno"> 304</span> <spanclass="comment"> * can be used. They can import an arbitrary number of particle positions from</span></div>
<divclass="line"><aname="l00305"></a><spanclass="lineno"> 305</span> <spanclass="comment"> * a file, dynamically allocating memory in chunks as necessary. Once particles</span></div>
<divclass="line"><aname="l00306"></a><spanclass="lineno"> 306</span> <spanclass="comment"> * are imported, they can guess an optimal block arrangement to use for the</span></div>
<divclass="line"><aname="l00307"></a><spanclass="lineno"> 307</span> <spanclass="comment"> * container class, and then transfer the particles to the container. By</span></div>
<divclass="line"><aname="l00308"></a><spanclass="lineno"> 308</span> <spanclass="comment"> * default, this procedure is used by the command-line utility to enable it to</span></div>
<divclass="line"><aname="l00309"></a><spanclass="lineno"> 309</span> <spanclass="comment"> * work well with arbitrary sizes of input data.</span></div>
<divclass="line"><aname="l00311"></a><spanclass="lineno"> 311</span> <spanclass="comment"> * The pre_container class can be used when no particle radius information is</span></div>
<divclass="line"><aname="l00312"></a><spanclass="lineno"> 312</span> <spanclass="comment"> * available, and the pre_container_poly class can be used when radius</span></div>
<divclass="line"><aname="l00313"></a><spanclass="lineno"> 313</span> <spanclass="comment"> * information is available. At present, the pre_container classes can only be</span></div>
<divclass="line"><aname="l00314"></a><spanclass="lineno"> 314</span> <spanclass="comment"> * used with the container and container_poly classes. They do not support</span></div>
<divclass="line"><aname="l00315"></a><spanclass="lineno"> 315</span> <spanclass="comment"> * the container_periodic and container_periodic_poly classes. */</span></div>
<divclass="line"><aname="l00320"></a><spanclass="lineno"> 320</span> <spanclass="preprocessor">#include "<aclass="code"href="config_8hh.html"title="Master configuration file for setting various compile-time options.">config.hh</a>"</span></div>
<divclass="line"><aname="l00321"></a><spanclass="lineno"> 321</span> <spanclass="preprocessor">#include "<aclass="code"href="common_8hh.html"title="Header file for the small helper functions.">common.hh</a>"</span></div>
<divclass="line"><aname="l00322"></a><spanclass="lineno"> 322</span> <spanclass="preprocessor">#include "<aclass="code"href="cell_8hh.html"title="Header file for the voronoicell and related classes.">cell.hh</a>"</span></div>
<divclass="line"><aname="l00323"></a><spanclass="lineno"> 323</span> <spanclass="preprocessor">#include "<aclass="code"href="v__base_8hh.html"title="Header file for the base Voronoi container class.">v_base.hh</a>"</span></div>
<divclass="line"><aname="l00324"></a><spanclass="lineno"> 324</span> <spanclass="preprocessor">#include "<aclass="code"href="rad__option_8hh.html"title="Header file for the classes encapsulating functionality for the regular and radical Voronoi tessellat...">rad_option.hh</a>"</span></div>
<divclass="line"><aname="l00325"></a><spanclass="lineno"> 325</span> <spanclass="preprocessor">#include "<aclass="code"href="container_8hh.html"title="Header file for the container_base and related classes.">container.hh</a>"</span></div>
<divclass="line"><aname="l00326"></a><spanclass="lineno"> 326</span> <spanclass="preprocessor">#include "<aclass="code"href="unitcell_8hh.html"title="Header file for the unitcell class.">unitcell.hh</a>"</span></div>
<divclass="line"><aname="l00327"></a><spanclass="lineno"> 327</span> <spanclass="preprocessor">#include "<aclass="code"href="container__prd_8hh.html"title="Header file for the container_periodic_base and related classes.">container_prd.hh</a>"</span></div>
<divclass="line"><aname="l00328"></a><spanclass="lineno"> 328</span> <spanclass="preprocessor">#include "<aclass="code"href="pre__container_8hh.html"title="Header file for the pre_container and related classes.">pre_container.hh</a>"</span></div>
<divclass="line"><aname="l00329"></a><spanclass="lineno"> 329</span> <spanclass="preprocessor">#include "<aclass="code"href="v__compute_8hh.html"title="Header file for the voro_compute template and related classes.">v_compute.hh</a>"</span></div>
<divclass="line"><aname="l00330"></a><spanclass="lineno"> 330</span> <spanclass="preprocessor">#include "<aclass="code"href="c__loops_8hh.html"title="Header file for the loop classes.">c_loops.hh</a>"</span></div>
<divclass="line"><aname="l00331"></a><spanclass="lineno"> 331</span> <spanclass="preprocessor">#include "<aclass="code"href="wall_8hh.html"title="Header file for the derived wall classes.">wall.hh</a>"</span></div>