Debian Codegraph @

src/FullCircMNTable3D.cc

raw
1 /////////////////////////////////////////////////////////////
2 // //
3 // Copyright (c) 2007-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
11 /////////////////////////////////////////////////////////////
12
13 #include "FullCircMNTable3D.h"
14
15 // --- System includes ---
16 #include <cmath>
17
18 // --- IO includes ---
19 #include <iostream>
20
21 using std::endl;
22
23 using std::floor;
24
25
26 FullCircMNTable3D::FullCircMNTable3D()
27 {}
28
29 /*!
30 Construct FullCircMNTable3D.
31
32 \param MinPt minimum point
33 \param MaxPt maximum point
34 \param cd cell dimension
35 \param ngroups initial number of particle groups
36 */
37 FullCircMNTable3D::FullCircMNTable3D(const Vector3& MinPt,const Vector3& MaxPt,double cd,unsigned int ngroups):
38 CircMNTable3D(MinPt, MaxPt, cd, ngroups)
39 {
40 m_shift_y=Vector3(0.0,(m_max_pt-m_min_pt).Y(),0.0);
41 m_shift_z=Vector3(0.0,0.0,(m_max_pt-m_min_pt).Z());
42
43 // check if grid spacing fits size in circular directions:
44 double ny=(MaxPt-MinPt).Y()/m_celldim;
45 double nz=(MaxPt-MinPt).Z()/m_celldim;
46 // error message if not
47 if(ny!=floor(ny)){
48 std::cout << "WARNING! grid spacing " << m_celldim << " doesn't fit periodic y-dimension " << (MaxPt-MinPt).Y() << std::endl;
49 }
50 if(nz!=floor(nz)){
51 std::cout << "WARNING! grid spacing " << m_celldim << " doesn't fit periodic z-dimension " << (MaxPt-MinPt).Z() << std::endl;
52 }
53 }
54
55 /*!
56 Destruct FullCircMNTable3D.
57 */
58 FullCircMNTable3D::~FullCircMNTable3D()
59 {}
60
61 /*!
62 set circularity of y-dimension to 1
63 */
64 void FullCircMNTable3D::set_y_circ()
65 {
66 m_y_periodic=1;
67 }
68
69 /*!
70 set circularity of z-dimension to 1
71 */
72 void FullCircMNTable3D::set_z_circ()
73 {
74 m_z_periodic=1;
75 }
76
77
78 /*!
79 get the cell index for a given position
80
81 \param Pos the position
82 \return the cell index if Pos is inside the table, -1 otherwise
83 */
84 int FullCircMNTable3D::getIndex(const Vector3& Pos) const
85 {
86 int ret;
87
88 int ix=int(floor((Pos.x()-m_origin.x())/m_celldim));
89 int iy=int(floor((Pos.y()-m_origin.y())/m_celldim));
90 int iz=int(floor((Pos.z()-m_origin.z())/m_celldim));
91
92 // check if pos is in table excl. padding
93 if((ix>=0) && (ix<=m_nx-1) && (iy>=0) && (iy<=m_ny-1) && (iz>=0) && (iz<=m_nz-1)){
94 ret=idx(ix,iy,iz);
95 } else {
96 ret=-1;
97 }
98
99 return ret;
100 }
101
102 /*!
103 Insert sphere. Insert clone into other side of Table.
104
105 \param S the Sphere
106 \param gid the group id
107 */
108 bool FullCircMNTable3D::insert(const Sphere& S,unsigned int gid)
109 { bool res;
110
111 int id=getIndex(S.Center());
112 int xidx=getXIndex(S.Center());
113 int yidx=getYIndex(S.Center());
114 int zidx=getZIndex(S.Center());
115
116 if((id!=-1) && (xidx!=0) && (xidx!=m_nx-1) && (yidx!=0) && (yidx!=m_ny-1) && (zidx!=0) && (zidx!=m_nz-1) && (gid<m_ngroups)){ // valid index
117 // insert sphere
118 m_data[id].insert(S,gid);
119 res=true;
120 // insert x-clone
121 if (xidx==1){
122 Sphere SClone=S;
123 SClone.shift(m_shift_x);
124 int clone_id=getFullIndex(SClone.Center());
125 m_data[clone_id].insert(SClone,gid);
126 } else if (xidx==m_nx-2){
127 Sphere SClone=S;
128 SClone.shift(-1.0*m_shift_x);
129 int clone_id=getFullIndex(SClone.Center());
130 m_data[clone_id].insert(SClone,gid);
131 }
132 // insert y-clone
133 if (yidx==1){
134 Sphere SClone=S;
135 SClone.shift(m_shift_y);
136 int clone_id=getFullIndex(SClone.Center());
137 m_data[clone_id].insert(SClone,gid);
138 } else if (yidx==m_ny-2){
139 Sphere SClone=S;
140 SClone.shift(-1.0*m_shift_y);
141 int clone_id=getFullIndex(SClone.Center());
142 m_data[clone_id].insert(SClone,gid);
143 }
144 // insert z-clone
145 if (zidx==1){
146 Sphere SClone=S;
147 SClone.shift(m_shift_z);
148 int clone_id=getFullIndex(SClone.Center());
149 m_data[clone_id].insert(SClone,gid);
150 } else if (zidx==m_nz-2){
151 Sphere SClone=S;
152 SClone.shift(-1.0*m_shift_z);
153 int clone_id=getFullIndex(SClone.Center());
154 m_data[clone_id].insert(SClone,gid);
155 }
156 } else {
157 res=false;
158 }
159
160 return res;
161 }
162
163 /*!
164 Insert sphere if it doesn't collide with other spheres. Insert clone into other side of Table.
165
166 \param S the Sphere
167 \param gid the group id
168 */
169 bool FullCircMNTable3D::insertChecked(const Sphere& S,unsigned int gid,double tol)
170 {
171 bool res;
172 bool orig_insertable=false;
173 bool xclone_insertable=false;
174 bool yclone_insertable=false;
175 bool zclone_insertable=false;
176 bool needs_xcloning=false;
177 bool needs_ycloning=false;
178 bool needs_zcloning=false;
179 int id=getIndex(S.Center());
180 int xidx=getXIndex(S.Center());
181 int yidx=getYIndex(S.Center());
182 int zidx=getZIndex(S.Center());
183
184 Sphere XClone=S;
185 Sphere YClone=S;
186 Sphere ZClone=S;
187
188 tol+=s_small_value;
189 if((id!=-1) && (xidx!=0) && (xidx!=m_nx-1) && (yidx!=0) && (yidx!=m_ny-1) && (zidx!=0) && (zidx!=m_nz-1) && (gid<m_ngroups)){ // original position is inside "core" of the table
190 // check if original is insertable
191 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(S.Center(),S.Radius()-tol,gid);
192 orig_insertable=(close_spheres.size()==0); // insertable if there are no spheres too close
193 // check if clone is insertable
194 // -- x --
195 if (xidx==1){ // original in x-min slice of the table -> shift clone to +x
196 needs_xcloning=true;
197 XClone.shift(m_shift_x);
198 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(XClone.Center(),XClone.Radius()-tol,gid);
199 xclone_insertable=(close_spheres.size()==0);
200 } else if (xidx==m_nx-2){ // original in x-max slice of the table -> shift clone to -x
201 needs_xcloning=true;
202 XClone.shift(-1.0*m_shift_x);
203 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(XClone.Center(),XClone.Radius()-tol,gid);
204 xclone_insertable=(close_spheres.size()==0);
205 }
206 // -- y --
207 if (yidx==1){ // original in y-min slice of the table -> shift clone to +y
208 needs_ycloning=true;
209 YClone.shift(m_shift_y);
210 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(YClone.Center(),YClone.Radius()-tol,gid);
211 yclone_insertable=(close_spheres.size()==0);
212 } else if (yidx==m_ny-2){ // original in y-max slice of the table -> shift clone to -y
213 needs_ycloning=true;
214 YClone.shift(-1.0*m_shift_y);
215 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(YClone.Center(),YClone.Radius()-tol,gid);
216 yclone_insertable=(close_spheres.size()==0);
217 }
218 // -- z --
219 if (zidx==1){ // original in z-min slice of the table -> shift clone to +z
220 needs_zcloning=true;
221 ZClone.shift(m_shift_z);
222 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(ZClone.Center(),ZClone.Radius()-tol,gid);
223 zclone_insertable=(close_spheres.size()==0);
224 } else if (zidx==m_nz-2){ // original in z-max slice of the table -> shift clone to -z
225 needs_zcloning=true;
226 ZClone.shift(-1.0*m_shift_z);
227 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(ZClone.Center(),ZClone.Radius()-tol,gid);
228 zclone_insertable=(close_spheres.size()==0);
229 }
230
231 // original not in end slices -> no cloning
232 }
233
234 if(orig_insertable &&
235 (xclone_insertable || (!needs_xcloning)) &&
236 (yclone_insertable || (!needs_ycloning)) &&
237 (zclone_insertable || (!needs_zcloning))){ // if origin is insertable and all clones are either insertable or not needed
238 m_data[id].insert(S,gid); // insert original
239 if (needs_xcloning) { // if needed, insert xclone
240 int clone_id=getFullIndex(XClone.Center());
241 m_data[clone_id].insert(XClone,gid);
242 }
243 if (needs_ycloning) { // if needed, insert clone
244 int clone_id=getFullIndex(YClone.Center());
245 m_data[clone_id].insert(YClone,gid);
246 }
247 if (needs_zcloning) { // if needed, insert clone
248 int clone_id=getFullIndex(ZClone.Center());
249 m_data[clone_id].insert(ZClone,gid);
250 }
251 res=true;
252 } else {
253 res=false;
254 }
255 return res;
256 }
257
258 bool FullCircMNTable3D::checkInsertable(const Sphere& S,unsigned int gid)
259 {
260 bool orig_insertable=false;
261 bool clone_insertable=false;
262 bool needs_cloning=false;
263 int id=this->getIndex(S.Center());
264 int xidx=getXIndex(S.Center());
265 int yidx=getYIndex(S.Center());
266 int zidx=getZIndex(S.Center());
267 Sphere SClone=S;
268
269 if((id!=-1) && (xidx!=0) && (xidx!=m_nx-1) && (yidx!=0) && (yidx!=m_ny-1) && (zidx!=0) && (zidx!=m_nz-1) && (gid<m_ngroups)){ // original position is inside "core" of the table
270 // check if original is insertable
271 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(S.Center(),S.Radius()-s_small_value,gid);
272 orig_insertable=(close_spheres.size()==0);
273 // check if clone is insertable
274 // -- x --
275 if (xidx==1){ // original in x-min slice of the table -> shift clone to +x
276 needs_cloning=true;
277 SClone.shift(m_shift_x);
278 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-s_small_value,gid);
279 clone_insertable=(close_spheres.size()==0);
280 } else if (xidx==m_nx-2){ // original in x-max slice of the table -> shift clone to -x
281 needs_cloning=true;
282 SClone.shift(-1.0*m_shift_x);
283 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-s_small_value,gid);
284 clone_insertable=(close_spheres.size()==0);
285 }
286 // -- y --
287 if (yidx==1){ // original in y-min slice of the table -> shift clone to +y
288 needs_cloning=true;
289 SClone.shift(m_shift_y);
290 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-s_small_value,gid);
291 clone_insertable=(close_spheres.size()==0);
292 } else if (yidx==m_ny-2){ // original in y-max slice of the table -> shift clone to -y
293 needs_cloning=true;
294 SClone.shift(-1.0*m_shift_y);
295 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-s_small_value,gid);
296 clone_insertable=(close_spheres.size()==0);
297 }
298 // -- z --
299 if (zidx==1){ // original in z-min slice of the table -> shift clone to +z
300 needs_cloning=true;
301 SClone.shift(m_shift_z);
302 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-s_small_value,gid);
303 clone_insertable=(close_spheres.size()==0);
304 } else if (zidx==m_nz-2){ // original in z-max slice of the table -> shift clone to -z
305 needs_cloning=true;
306 SClone.shift(-1.0*m_shift_z);
307 multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-s_small_value,gid);
308 clone_insertable=(close_spheres.size()==0);
309 }
310 // original not in end slices -> no cloning
311 }
312
313 return (orig_insertable && (clone_insertable || (!needs_cloning))); // original is insertable and clone is either insertable or not needed
314 }
315
316
317 /*!
318 Generate bonds between particles of a group. Takes cloned particles into account.
319
320 \param gid the group ID
321 \param tol max. difference between bond length and equilibrium dist.
322 \param btag bond tag
323 */
324 void FullCircMNTable3D::generateBonds(int gid,double tol,int btag)
325 {
326 std::cout << "FullCircMNTable3D::generateBonds( " << gid << " , " << tol << " , " << btag << " )" << std::endl;
327 // loop over all inner cells
328 for(int i=0;i<m_nx-1;i++){
329 for(int j=0;j<m_ny-1;j++){
330 for(int k=0;k<m_nz-1;k++){
331 int id=idx(i,j,k);
332 // loop over "upper" neighbors of each cell
333 for(int ii=-1;ii<=1;ii++){
334 for(int jj=-1;jj<=1;jj++){
335 for(int kk=-1;kk<=1;kk++){
336 int id2=idx(i+ii,j+jj,k+kk);
337 vector<pair<int,int> > bonds;
338 if((ii+jj+kk)==0){ // intra-cell, not for boundary
339 // std::cout << id << " - " << id << std::endl;
340 bonds=m_data[id].getBonds(gid,tol);
341 } else if(id2>id){ // inter-cell
342 //std::cout << id << " - " << id2 << std::endl;
343 bonds=m_data[id].getBonds(gid,tol,m_data[id2]);
344 }
345 for(vector<pair<int,int> >::iterator iter=bonds.begin();
346 iter!=bonds.end();
347 iter++){
348 //std::cout << iter->first << " | " << iter->second << " ";
349 if(iter->second > iter->first){
350 m_bonds[btag].insert(*iter);
351 }
352 }
353 //std::cout << std::endl;
354 }
355 }
356 }
357 //std::cout << std::endl;
358 }
359 }
360 }
361 }
362
363 // ostream& FullCircMNTable3D::operator << (ostream&,const FullCircMNTable3D&)
364 // {}