169
169
bool FullCircMNTable3D::insertChecked(const Sphere& S,unsigned int gid,double tol)
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;
172
179
int id=getIndex(S.Center());
173
180
int xidx=getXIndex(S.Center());
174
181
int yidx=getYIndex(S.Center());
175
182
int zidx=getZIndex(S.Center());
177
188
tol+=s_small_value;
178
if((id!=-1) && (xidx!=0) && (xidx!=m_nx-1) && (gid<m_ngroups)){
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
180
191
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(S.Center(),S.Radius()-tol,gid);
181
if(close_spheres.size()==0){
182
m_data[id].insert(S,gid);
188
SClone.shift(m_shift_x);
189
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-tol,gid);
190
if(close_spheres.size()==0){
191
int clone_id=getFullIndex(SClone.Center());
192
m_data[clone_id].insert(SClone,gid);
194
} else if (xidx==m_nx-2){
196
SClone.shift(-1.0*m_shift_x);
197
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-tol,gid);
198
if(close_spheres.size()==0){
199
int clone_id=getFullIndex(SClone.Center());
200
m_data[clone_id].insert(SClone,gid);
206
SClone.shift(m_shift_y);
207
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-tol,gid);
208
if(close_spheres.size()==0){
209
int clone_id=getFullIndex(SClone.Center());
210
m_data[clone_id].insert(SClone,gid);
212
} else if (yidx==m_ny-2){
214
SClone.shift(-1.0*m_shift_y);
215
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-tol,gid);
216
if(close_spheres.size()==0){
217
int clone_id=getFullIndex(SClone.Center());
218
m_data[clone_id].insert(SClone,gid);
224
SClone.shift(m_shift_z);
225
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-tol,gid);
226
if(close_spheres.size()==0){
227
int clone_id=getFullIndex(SClone.Center());
228
m_data[clone_id].insert(SClone,gid);
230
} else if (zidx==m_nz-2){
232
SClone.shift(-1.0*m_shift_z);
233
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(SClone.Center(),SClone.Radius()-tol,gid);
234
if(close_spheres.size()==0){
235
int clone_id=getFullIndex(SClone.Center());
236
m_data[clone_id].insert(SClone,gid);
192
orig_insertable=(close_spheres.size()==0); // insertable if there are no spheres too close
193
// check if clone is insertable
195
if (xidx==1){ // original in x-min slice of the table -> shift clone to +x
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
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);
207
if (yidx==1){ // original in y-min slice of the table -> shift clone to +y
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
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);
219
if (zidx==1){ // original in z-min slice of the table -> shift clone to +z
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
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);
231
// original not in end slices -> no cloning
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);
243
if (needs_ycloning) { // if needed, insert clone
244
int clone_id=getFullIndex(YClone.Center());
245
m_data[clone_id].insert(YClone,gid);
247
if (needs_zcloning) { // if needed, insert clone
248
int clone_id=getFullIndex(ZClone.Center());
249
m_data[clone_id].insert(ZClone,gid);
246
258
bool FullCircMNTable3D::checkInsertable(const Sphere& S,unsigned int gid)
260
bool orig_insertable=false;
261
bool clone_insertable=false;
262
bool needs_cloning=false;
250
263
int id=this->getIndex(S.Center());
251
264
int xidx=getXIndex(S.Center());
252
265
int yidx=getYIndex(S.Center());
253
266
int zidx=getZIndex(S.Center());
255
if((id!=-1) && (xidx!=0) && (xidx!=m_nx-1) && (yidx!=0) && (yidx!=m_ny-1) && (zidx!=0) && (zidx!=m_nz-1) && (gid<m_ngroups)){
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
256
271
multimap<double,const Sphere*> close_spheres=getSpheresFromGroupNear(S.Center(),S.Radius()-s_small_value,gid);
257
if(close_spheres.size()==0){
261
// for(map<double,const Sphere*>::const_iterator iter=close_spheres.begin();
262
// iter!=close_spheres.end();
264
// std::cout << iter->first << " | " << *(iter->second) << std::endl;
272
orig_insertable=(close_spheres.size()==0);
273
// check if clone is insertable
275
if (xidx==1){ // original in x-min slice of the table -> shift clone to +x
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
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);
287
if (yidx==1){ // original in y-min slice of the table -> shift clone to +y
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
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);
299
if (zidx==1){ // original in z-min slice of the table -> shift clone to +z
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
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);
310
// original not in end slices -> no cloning
313
return (orig_insertable && (clone_insertable || (!needs_cloning))); // original is insertable and clone is either insertable or not needed
274
318
Generate bonds between particles of a group. Takes cloned particles into account.