Voro++
|
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 wall.cc 00008 * \brief Function implementations for the derived wall classes. */ 00009 00010 #include "wall.hh" 00011 00012 namespace voro { 00013 00014 /** Tests to see whether a point is inside the sphere wall object. 00015 * \param[in,out] (x,y,z) the vector to test. 00016 * \return True if the point is inside, false if the point is outside. */ 00017 bool wall_sphere::point_inside(double x,double y,double z) { 00018 return (x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc)*(z-zc)<rc*rc; 00019 } 00020 00021 /** Cuts a cell by the sphere wall object. The spherical wall is approximated by 00022 * a single plane applied at the point on the sphere which is closest to the center 00023 * of the cell. This works well for particle arrangements that are packed against 00024 * the wall, but loses accuracy for sparse particle distributions. 00025 * \param[in,out] c the Voronoi cell to be cut. 00026 * \param[in] (x,y,z) the location of the Voronoi cell. 00027 * \return True if the cell still exists, false if the cell is deleted. */ 00028 template<class v_cell> 00029 bool wall_sphere::cut_cell_base(v_cell &c,double x,double y,double z) { 00030 double xd=x-xc,yd=y-yc,zd=z-zc,dq; 00031 dq=xd*xd+yd*yd+zd*zd; 00032 if (dq>1e-5) { 00033 dq=2*(sqrt(dq)*rc-dq); 00034 return c.nplane(xd,yd,zd,dq,w_id); 00035 } 00036 return true; 00037 } 00038 00039 /** Tests to see whether a point is inside the plane wall object. 00040 * \param[in] (x,y,z) the vector to test. 00041 * \return True if the point is inside, false if the point is outside. */ 00042 bool wall_plane::point_inside(double x,double y,double z) { 00043 return x*xc+y*yc+z*zc<ac; 00044 } 00045 00046 /** Cuts a cell by the plane wall object. 00047 * \param[in,out] c the Voronoi cell to be cut. 00048 * \param[in] (x,y,z) the location of the Voronoi cell. 00049 * \return True if the cell still exists, false if the cell is deleted. */ 00050 template<class v_cell> 00051 bool wall_plane::cut_cell_base(v_cell &c,double x,double y,double z) { 00052 double dq=2*(ac-x*xc-y*yc-z*zc); 00053 return c.nplane(xc,yc,zc,dq,w_id); 00054 } 00055 00056 /** Tests to see whether a point is inside the cylindrical wall object. 00057 * \param[in] (x,y,z) the vector to test. 00058 * \return True if the point is inside, false if the point is outside. */ 00059 bool wall_cylinder::point_inside(double x,double y,double z) { 00060 double xd=x-xc,yd=y-yc,zd=z-zc; 00061 double pa=(xd*xa+yd*ya+zd*za)*asi; 00062 xd-=xa*pa;yd-=ya*pa;zd-=za*pa; 00063 return xd*xd+yd*yd+zd*zd<rc*rc; 00064 } 00065 00066 /** Cuts a cell by the cylindrical wall object. The cylindrical wall is 00067 * approximated by a single plane applied at the point on the cylinder which is 00068 * closest to the center of the cell. This works well for particle arrangements 00069 * that are packed against the wall, but loses accuracy for sparse particle 00070 * distributions. 00071 * \param[in,out] c the Voronoi cell to be cut. 00072 * \param[in] (x,y,z) the location of the Voronoi cell. 00073 * \return True if the cell still exists, false if the cell is deleted. */ 00074 template<class v_cell> 00075 bool wall_cylinder::cut_cell_base(v_cell &c,double x,double y,double z) { 00076 double xd=x-xc,yd=y-yc,zd=z-zc; 00077 double pa=(xd*xa+yd*ya+zd*za)*asi; 00078 xd-=xa*pa;yd-=ya*pa;zd-=za*pa; 00079 pa=xd*xd+yd*yd+zd*zd; 00080 if(pa>1e-5) { 00081 pa=2*(sqrt(pa)*rc-pa); 00082 return c.nplane(xd,yd,zd,pa,w_id); 00083 } 00084 return true; 00085 } 00086 00087 /** Tests to see whether a point is inside the cone wall object. 00088 * \param[in] (x,y,z) the vector to test. 00089 * \return True if the point is inside, false if the point is outside. */ 00090 bool wall_cone::point_inside(double x,double y,double z) { 00091 double xd=x-xc,yd=y-yc,zd=z-zc; 00092 double pa=(xd*xa+yd*ya+zd*za)*asi; 00093 xd-=xa*pa;yd-=ya*pa;zd-=za*pa; 00094 pa*=gra; 00095 if (pa<0) return false; 00096 pa*=pa; 00097 return xd*xd+yd*yd+zd*zd<pa; 00098 } 00099 00100 /** Cuts a cell by the cone wall object. The conical wall is 00101 * approximated by a single plane applied at the point on the cone which is 00102 * closest to the center of the cell. This works well for particle arrangements 00103 * that are packed against the wall, but loses accuracy for sparse particle 00104 * distributions. 00105 * \param[in,out] c the Voronoi cell to be cut. 00106 * \param[in] (x,y,z) the location of the Voronoi cell. 00107 * \return True if the cell still exists, false if the cell is deleted. */ 00108 template<class v_cell> 00109 bool wall_cone::cut_cell_base(v_cell &c,double x,double y,double z) { 00110 double xd=x-xc,yd=y-yc,zd=z-zc; 00111 double xf,yf,zf,imoda; 00112 double pa=(xd*xa+yd*ya+zd*za)*asi; 00113 xd-=xa*pa;yd-=ya*pa;zd-=za*pa; 00114 pa=xd*xd+yd*yd+zd*zd; 00115 if(pa>1e-5) { 00116 pa=1/sqrt(pa); 00117 imoda=sqrt(asi); 00118 xf=-sang*imoda*xa+cang*pa*xd; 00119 yf=-sang*imoda*ya+cang*pa*yd; 00120 zf=-sang*imoda*za+cang*pa*zd; 00121 pa=2*(xf*(xc-x)+yf*(yc-y)+zf*(zc-z)); 00122 return c.nplane(xf,yf,zf,pa,w_id); 00123 } 00124 return true; 00125 } 00126 00127 }