| 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 "MNTCell.h" |
| 14 |
|
| 15 |
// --- STL includes --- |
| 16 |
#include <utility> |
| 17 |
|
| 18 |
using std::make_pair; |
| 19 |
using std::endl; |
| 20 |
|
| 21 |
// --- System includes --- |
| 22 |
#include <cmath> |
| 23 |
|
| 24 |
using std::fabs; |
| 25 |
|
| 26 |
int MNTCell::s_output_style=0; |
| 27 |
|
| 28 |
/*! |
| 29 |
construct MNTCell |
| 30 |
|
| 31 |
\param ngroups initial number of particle groups, can be extended later |
| 32 |
*/ |
| 33 |
MNTCell::MNTCell(unsigned int ngroups) |
| 34 |
{ |
| 35 |
m_data=vector<vector<Sphere> >(ngroups); |
| 36 |
} |
| 37 |
|
| 38 |
/*! |
| 39 |
increase the number of groups. If the number of groups is already greater |
| 40 |
then the given number, do nothing. |
| 41 |
|
| 42 |
\param ngroups the new number of groups |
| 43 |
*/ |
| 44 |
void MNTCell::SetNGroups(unsigned int ngroups) |
| 45 |
{ |
| 46 |
if(ngroups>m_data.size()) m_data.resize(ngroups); |
| 47 |
} |
| 48 |
|
| 49 |
/*! |
| 50 |
insert sphere into cell |
| 51 |
|
| 52 |
\param S the sphere |
| 53 |
\param gid the group id |
| 54 |
|
| 55 |
\warning no check for validity of gid |
| 56 |
*/ |
| 57 |
void MNTCell::insert(const Sphere& S, int gid) |
| 58 |
{ |
| 59 |
m_data[gid].push_back(S); |
| 60 |
} |
| 61 |
|
| 62 |
int MNTCell::NParts() const |
| 63 |
{ |
| 64 |
int np=0; |
| 65 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 66 |
group_iter!=m_data.end(); |
| 67 |
group_iter++){ |
| 68 |
np+=group_iter->size(); |
| 69 |
} |
| 70 |
|
| 71 |
return np; |
| 72 |
} |
| 73 |
|
| 74 |
/*! |
| 75 |
get all spheres within a given distance to a point, irrespective of group |
| 76 |
|
| 77 |
\param P the point |
| 78 |
\param d max. distance between the point and the surface of the sphere |
| 79 |
*/ |
| 80 |
const multimap<double,const Sphere*> MNTCell::getSpheresNear(const Vector3& P,double d) const |
| 81 |
{ |
| 82 |
multimap<double, const Sphere*> res; |
| 83 |
|
| 84 |
// for all groups |
| 85 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 86 |
group_iter!=m_data.end(); |
| 87 |
group_iter++){ |
| 88 |
// for all particles in the group |
| 89 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 90 |
iter!=group_iter->end(); |
| 91 |
iter++){ |
| 92 |
double dist=iter->getDist(P); |
| 93 |
if(dist<=d){ |
| 94 |
res.insert(make_pair(dist,&(*iter))); |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return res; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
/*! |
| 104 |
get all spheres from one group within a given distance to a point |
| 105 |
|
| 106 |
\param P the point |
| 107 |
\param d max. distance between the point and the surface of the sphere |
| 108 |
\param gid the group id |
| 109 |
|
| 110 |
\warning no check for validity of gid |
| 111 |
*/ |
| 112 |
const multimap<double,const Sphere*> MNTCell::getSpheresFromGroupNear(const Vector3& P,double d,int gid) const |
| 113 |
{ |
| 114 |
multimap<double,const Sphere*> res; |
| 115 |
|
| 116 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 117 |
iter!=m_data[gid].end(); |
| 118 |
iter++){ |
| 119 |
double dist=iter->getDist(P); |
| 120 |
if(dist<=d){ |
| 121 |
res.insert(make_pair(dist,&(*iter))); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
return res; |
| 126 |
} |
| 127 |
|
| 128 |
/*! |
| 129 |
get all spheres from one group within a given distance to a point |
| 130 |
|
| 131 |
\param P the point |
| 132 |
\param d max. distance between the point and the surface of the sphere |
| 133 |
\param gid the group id |
| 134 |
|
| 135 |
\warning no check for validity of gid |
| 136 |
*/ |
| 137 |
multimap<double,Sphere*> MNTCell::getSpheresFromGroupNearNC(const Vector3& P,double d,int gid) |
| 138 |
{ |
| 139 |
multimap<double,Sphere*> res; |
| 140 |
|
| 141 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 142 |
iter!=m_data[gid].end(); |
| 143 |
iter++){ |
| 144 |
double dist=iter->getDist(P); |
| 145 |
if(dist<=d){ |
| 146 |
res.insert(make_pair(dist,&(*iter))); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
return res; |
| 151 |
} |
| 152 |
|
| 153 |
/*! |
| 154 |
get the closest spheres to a given point |
| 155 |
|
| 156 |
\param p the point |
| 157 |
\param nmax the maximum number of spheres returned |
| 158 |
*/ |
| 159 |
const multimap<double,const Sphere*> MNTCell::getSpheresClosestTo(const Vector3& p,unsigned int nmax) const |
| 160 |
{ |
| 161 |
multimap<double,const Sphere*> pmap; |
| 162 |
double max_dist; |
| 163 |
|
| 164 |
// for all groups |
| 165 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 166 |
group_iter!=m_data.end(); |
| 167 |
group_iter++){ |
| 168 |
// for all particles in the group |
| 169 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 170 |
iter!=group_iter->end(); |
| 171 |
iter++){ |
| 172 |
double dist=iter->getDist(p); |
| 173 |
if(pmap.size()<nmax){ // less then nmax found -> insert |
| 174 |
pmap.insert(make_pair(dist,&(*iter))); |
| 175 |
max_dist=(pmap.rbegin())->first; |
| 176 |
} else if(dist<max_dist){ // closer than nmax-th -> insert |
| 177 |
pmap.erase(max_dist); |
| 178 |
pmap.insert(make_pair(dist,&(*iter))); |
| 179 |
max_dist=(pmap.rbegin())->first; |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
return pmap; |
| 185 |
} |
| 186 |
|
| 187 |
/*! |
| 188 |
tag the closest spheres to a given point |
| 189 |
|
| 190 |
\param p the point |
| 191 |
\param dist max. distance to which particles are tagged |
| 192 |
\param gid the group Id |
| 193 |
\param tag the tag |
| 194 |
*/ |
| 195 |
void MNTCell::tagSpheresNear(const Vector3& p,double dist,int gid, int tag) |
| 196 |
{ |
| 197 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 198 |
iter!=m_data[gid].end(); |
| 199 |
iter++){ |
| 200 |
double d=(iter->getDist(p)); |
| 201 |
if(d<=dist){ |
| 202 |
iter->setTag(tag); |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
/*! |
| 208 |
tag the closest sphere to a given point |
| 209 |
|
| 210 |
\param p the point |
| 211 |
\param gid the group Id |
| 212 |
\param tag the tag |
| 213 |
*/ |
| 214 |
void MNTCell::tagClosestParticle(const Vector3& p,int gid,int tag) |
| 215 |
{ |
| 216 |
if(m_data[gid].size()>0){ |
| 217 |
vector<Sphere>::iterator closest=m_data[gid].begin(); |
| 218 |
double min_dist=(closest->getDist(p)); |
| 219 |
|
| 220 |
for(vector<Sphere>::iterator iter=m_data[gid].begin() ; |
| 221 |
iter!=m_data[gid].end(); |
| 222 |
iter++){ |
| 223 |
double d=(iter->getDist(p)); |
| 224 |
if(d<min_dist){ |
| 225 |
closest=iter; |
| 226 |
min_dist=d; |
| 227 |
} |
| 228 |
} |
| 229 |
closest->setTag(tag); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
/*! |
| 234 |
get the sphere within a given group closest to given sphere |
| 235 |
|
| 236 |
\param s the sphere |
| 237 |
\param gid the group |
| 238 |
\param maximum distance |
| 239 |
*/ |
| 240 |
const Sphere* MNTCell::getClosestSphereFromGroup(const Sphere& s,int gid, double md) const |
| 241 |
{ |
| 242 |
const Sphere* res=NULL; |
| 243 |
double d=md; |
| 244 |
|
| 245 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 246 |
iter!=m_data[gid].end(); |
| 247 |
iter++){ |
| 248 |
double dist=iter->getDist(s.Center())-s.Radius(); |
| 249 |
if(dist<=d){ |
| 250 |
res=&(*iter); |
| 251 |
d=dist; |
| 252 |
} |
| 253 |
} |
| 254 |
return res; |
| 255 |
} |
| 256 |
|
| 257 |
/*! |
| 258 |
Get the sphere within a given group closest to given sphere, using anisotropic weighted distance. |
| 259 |
|
| 260 |
\param s the sphere |
| 261 |
\param gid the group |
| 262 |
\param md distance |
| 263 |
*/ |
| 264 |
const Sphere* MNTCell::getClosestSphereFromGroup(const Sphere& s,int gid, double md, |
| 265 |
double wx, double wy, double wz) const |
| 266 |
{ |
| 267 |
const Sphere* res=NULL; |
| 268 |
double d=md; |
| 269 |
|
| 270 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 271 |
iter!=m_data[gid].end(); |
| 272 |
iter++){ |
| 273 |
double dist=(iter->Center()-s.Center()).wnorm2(wx,wy,wz); |
| 274 |
if(dist<=d){ |
| 275 |
res=&(*iter); |
| 276 |
d=dist; |
| 277 |
} |
| 278 |
} |
| 279 |
return res; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
/*! |
| 284 |
get the sphere within a given group closest to given sphere |
| 285 |
|
| 286 |
\param s the sphere |
| 287 |
\param gid the group |
| 288 |
\param maximum distance |
| 289 |
*/ |
| 290 |
Sphere* MNTCell::getClosestSphereFromGroup(const Vector3& p,int gid, double md) |
| 291 |
{ |
| 292 |
Sphere* res=NULL; |
| 293 |
double d=md; |
| 294 |
|
| 295 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 296 |
iter!=m_data[gid].end(); |
| 297 |
iter++){ |
| 298 |
double dist=(iter->Center()-p).norm(); |
| 299 |
if(dist<=d){ |
| 300 |
res=&(*iter); |
| 301 |
d=dist; |
| 302 |
} |
| 303 |
} |
| 304 |
return res; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
/* |
| 309 |
tag all particles within a group |
| 310 |
|
| 311 |
\param gid the group Id |
| 312 |
\param tag the tag |
| 313 |
\param mask the tag mask (i.e. new_tag = new_tag=(old_tag & (~mask)) | (tag & mask)) |
| 314 |
*/ |
| 315 |
void MNTCell::tagSpheresInGroup(int gid,int tag,int mask) |
| 316 |
{ |
| 317 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 318 |
iter!=m_data[gid].end(); |
| 319 |
iter++){ |
| 320 |
int old_tag=iter->Tag(); |
| 321 |
int new_tag = (old_tag & (~mask)) | (tag & mask); |
| 322 |
iter->setTag(new_tag); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
/*! |
| 328 |
get all spheres from a group |
| 329 |
|
| 330 |
\param gid the goup Id |
| 331 |
*/ |
| 332 |
const vector<const Sphere*> MNTCell::getAllSpheresFromGroup(int gid) const |
| 333 |
{ |
| 334 |
vector<const Sphere*> res; |
| 335 |
|
| 336 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 337 |
iter!=m_data[gid].end(); |
| 338 |
iter++){ |
| 339 |
res.push_back(&(*iter)); |
| 340 |
} |
| 341 |
|
| 342 |
return res; |
| 343 |
} |
| 344 |
|
| 345 |
/*! |
| 346 |
get all spheres from a group |
| 347 |
|
| 348 |
\param gid the goup Id |
| 349 |
*/ |
| 350 |
vector<Sphere*> MNTCell::getAllSpheresFromGroupNC(int gid) |
| 351 |
{ |
| 352 |
vector<Sphere*> res; |
| 353 |
|
| 354 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 355 |
iter!=m_data[gid].end(); |
| 356 |
iter++){ |
| 357 |
res.push_back(&(*iter)); |
| 358 |
} |
| 359 |
|
| 360 |
return res; |
| 361 |
} |
| 362 |
|
| 363 |
/*! |
| 364 |
get particles close to geometric object |
| 365 |
|
| 366 |
\param G the geometric object |
| 367 |
\param dist the maximum distance |
| 368 |
\param gid the group Id |
| 369 |
*/ |
| 370 |
const vector<Sphere*> MNTCell::getSpheresNearObject(const AGeometricObject* G,double dist,unsigned int gid) |
| 371 |
{ |
| 372 |
vector<Sphere*> res; |
| 373 |
|
| 374 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 375 |
iter!=m_data[gid].end(); |
| 376 |
iter++){ |
| 377 |
double d=G->getDist(iter->Center())-iter->Radius(); |
| 378 |
if(d<=dist){ |
| 379 |
res.push_back(&(*iter)); |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
return res; |
| 384 |
} |
| 385 |
|
| 386 |
/*! |
| 387 |
get particles inside a volume |
| 388 |
|
| 389 |
\param V the volume |
| 390 |
\param gid the group Id |
| 391 |
*/ |
| 392 |
const vector<Sphere*> MNTCell::getSpheresInVolume(const AVolume* V,unsigned int gid) |
| 393 |
{ |
| 394 |
vector<Sphere*> res; |
| 395 |
|
| 396 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 397 |
iter!=m_data[gid].end(); |
| 398 |
iter++){ |
| 399 |
bool isin=V->isIn(iter->Center()); |
| 400 |
if(isin){ |
| 401 |
res.push_back(&(*iter)); |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
return res; |
| 406 |
} |
| 407 |
|
| 408 |
/*! |
| 409 |
get the sum of the area/volume of all particles in a group, assuming 2D |
| 410 |
|
| 411 |
\param gid the group id |
| 412 |
*/ |
| 413 |
double MNTCell::getSumVolume2D(unsigned int gid) |
| 414 |
{ |
| 415 |
double res=0.0; |
| 416 |
|
| 417 |
// check if gid is valid |
| 418 |
if(gid<m_data.size()){ |
| 419 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 420 |
iter!=m_data[gid].end(); |
| 421 |
iter++){ |
| 422 |
double rad=iter->Radius(); |
| 423 |
res+=3.1415926*rad*rad; // A=pi*r^2 |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
return res; |
| 428 |
} |
| 429 |
|
| 430 |
/*! |
| 431 |
get the number of particles in a group |
| 432 |
|
| 433 |
\param gid the group id |
| 434 |
*/ |
| 435 |
int MNTCell::getNrParticles(int gid) |
| 436 |
{ |
| 437 |
return m_data[gid].size(); |
| 438 |
} |
| 439 |
|
| 440 |
/*! |
| 441 |
remove particle with given id |
| 442 |
|
| 443 |
\param id the particle id |
| 444 |
\param gid the group Id |
| 445 |
*/ |
| 446 |
void MNTCell::remove(int id, int gid) |
| 447 |
{ |
| 448 |
|
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
/*! |
| 453 |
remove particles inside a volume |
| 454 |
|
| 455 |
\param Vol the volume |
| 456 |
\param full remove particles fully inside volume or center inside |
| 457 |
*/ |
| 458 |
void MNTCell::removeInVolume(const AVolume* Vol,int gid,bool full) |
| 459 |
{ |
| 460 |
vector<Sphere> tmp; |
| 461 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 462 |
iter!=m_data[gid].end(); |
| 463 |
iter++){ |
| 464 |
if(!Vol->isIn(iter->Center())){ |
| 465 |
tmp.push_back(*iter); |
| 466 |
} |
| 467 |
} |
| 468 |
m_data[gid].swap(tmp); |
| 469 |
} |
| 470 |
|
| 471 |
/*! |
| 472 |
remove particles with a given tag |
| 473 |
|
| 474 |
\param tag the particle tag |
| 475 |
\param mask the tag mask |
| 476 |
\param gid the group Id |
| 477 |
*/ |
| 478 |
void MNTCell::removeTagged(int gid,int tag, int mask) |
| 479 |
{ |
| 480 |
vector<Sphere> tmp; |
| 481 |
for(vector<Sphere>::iterator iter=m_data[gid].begin(); |
| 482 |
iter!=m_data[gid].end(); |
| 483 |
iter++){ |
| 484 |
if((iter->Tag() & mask) != (tag & mask)){ |
| 485 |
tmp.push_back(*iter); |
| 486 |
} |
| 487 |
} |
| 488 |
m_data[gid]=tmp; |
| 489 |
} |
| 490 |
|
| 491 |
/*! |
| 492 |
change particle IDs so that they are continous |
| 493 |
|
| 494 |
\param id0 lowest ID to be used |
| 495 |
\return lowest free ID, i.e. highest used ID+1 |
| 496 |
*/ |
| 497 |
int MNTCell::renumberParticlesContinuous(int id0) |
| 498 |
{ |
| 499 |
int id=id0; |
| 500 |
|
| 501 |
for(vector<vector<Sphere> >::iterator giter=m_data.begin(); |
| 502 |
giter!=m_data.end(); |
| 503 |
giter++){ |
| 504 |
for(vector<Sphere>::iterator iter=giter->begin(); |
| 505 |
iter!=giter->end(); |
| 506 |
iter++){ |
| 507 |
iter->setId(id); |
| 508 |
id++; |
| 509 |
} |
| 510 |
} |
| 511 |
return id; |
| 512 |
} |
| 513 |
|
| 514 |
/*! |
| 515 |
get the sum of the area/volume of all particles in a group, assuming 3D |
| 516 |
|
| 517 |
\param gid the group id |
| 518 |
*/ |
| 519 |
double MNTCell::getSumVolume3D(unsigned int gid) |
| 520 |
{ |
| 521 |
double res=0.0; |
| 522 |
|
| 523 |
// check if gid is valid |
| 524 |
if(gid<m_data.size()){ |
| 525 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 526 |
iter!=m_data[gid].end(); |
| 527 |
iter++){ |
| 528 |
double rad=iter->Radius(); |
| 529 |
res+=(4.0/3.0)*3.1415926*rad*rad*rad; // V=4/3*pi*r^3 |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
return res; |
| 534 |
} |
| 535 |
|
| 536 |
/*! |
| 537 |
get Ids of particles in cell |
| 538 |
*/ |
| 539 |
vector<int> MNTCell::getIdList() |
| 540 |
{ |
| 541 |
vector<int> res; |
| 542 |
|
| 543 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 544 |
group_iter!=m_data.end(); |
| 545 |
group_iter++){ |
| 546 |
// for all particles in the group |
| 547 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 548 |
iter!=group_iter->end(); |
| 549 |
iter++){ |
| 550 |
res.push_back(iter->Id()); |
| 551 |
} |
| 552 |
} |
| 553 |
return res; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
/*! |
| 558 |
intra-cell bonds |
| 559 |
|
| 560 |
\param gid group ID |
| 561 |
\param tol max. difference between bond length and equilibrium dist. |
| 562 |
*/ |
| 563 |
vector<pair<int,int> > MNTCell::getBonds(int gid,double tol) |
| 564 |
{ |
| 565 |
vector<pair<int,int> > res; |
| 566 |
|
| 567 |
// check if gid is valid |
| 568 |
if(gid<m_data.size()){ |
| 569 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 570 |
iter!=m_data[gid].end(); |
| 571 |
iter++){ |
| 572 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 573 |
iter2!=m_data[gid].end(); |
| 574 |
iter2++){ |
| 575 |
if(iter!=iter2){ |
| 576 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 577 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 578 |
if(fabs(d-r0)<(r0*tol)){ |
| 579 |
if(iter->Id()<iter2->Id()){ |
| 580 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 581 |
} else { |
| 582 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
return res; |
| 591 |
} |
| 592 |
|
| 593 |
/*! |
| 594 |
intra-cell bonds between particles with the same (arbitrary) tag |
| 595 |
|
| 596 |
\param gid group ID |
| 597 |
\param tol max. difference between bond length and equilibrium dist. |
| 598 |
*/ |
| 599 |
vector<pair<int,int> > MNTCell::getBondsSame(int gid,double tol) |
| 600 |
{ |
| 601 |
vector<pair<int,int> > res; |
| 602 |
|
| 603 |
// check if gid is valid |
| 604 |
if(gid<m_data.size()){ |
| 605 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 606 |
iter!=m_data[gid].end(); |
| 607 |
iter++){ |
| 608 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 609 |
iter2!=m_data[gid].end(); |
| 610 |
iter2++){ |
| 611 |
if(iter!=iter2){ |
| 612 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 613 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 614 |
if((fabs(d-r0)<(r0*tol)) && (iter->Tag()==iter2->Tag())){ |
| 615 |
if(iter->Id()<iter2->Id()){ |
| 616 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 617 |
} else { |
| 618 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
return res; |
| 627 |
} |
| 628 |
|
| 629 |
/*! |
| 630 |
intra-cell bonds with positions |
| 631 |
|
| 632 |
\param gid group ID |
| 633 |
\param tol max. difference between bond length and equilibrium dist. |
| 634 |
*/ |
| 635 |
vector<BondWithPos> MNTCell::getBondsWithPos(int gid,double tol) |
| 636 |
{ |
| 637 |
vector<BondWithPos> res; |
| 638 |
|
| 639 |
// check if gid is valid |
| 640 |
if(gid<m_data.size()){ |
| 641 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 642 |
iter!=m_data[gid].end(); |
| 643 |
iter++){ |
| 644 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 645 |
iter2!=m_data[gid].end(); |
| 646 |
iter2++){ |
| 647 |
if(iter!=iter2){ |
| 648 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 649 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 650 |
if(d-r0<(r0*tol)){ |
| 651 |
if(iter->Id()<iter2->Id()){ |
| 652 |
BondWithPos bwp; |
| 653 |
bwp.first=iter->Id(); |
| 654 |
bwp.second=iter2->Id(); |
| 655 |
bwp.firstPos=iter->Center(); |
| 656 |
bwp.secondPos=iter2->Center(); |
| 657 |
res.push_back(bwp); |
| 658 |
} else { |
| 659 |
BondWithPos bwp; |
| 660 |
bwp.first=iter2->Id(); |
| 661 |
bwp.second=iter->Id(); |
| 662 |
bwp.firstPos=iter2->Center(); |
| 663 |
bwp.secondPos=iter->Center(); |
| 664 |
res.push_back(bwp); |
| 665 |
} |
| 666 |
} |
| 667 |
} |
| 668 |
} |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
return res; |
| 673 |
} |
| 674 |
|
| 675 |
/*! |
| 676 |
intra-cell bonds between particles with the same (arbitrary) tag |
| 677 |
|
| 678 |
\param gid group ID |
| 679 |
\param tol max. difference between bond length and equilibrium dist. |
| 680 |
*/ |
| 681 |
vector<BondWithPos> MNTCell::getBondsWithPos(int gid,double tol ,const MNTCell& C) |
| 682 |
{ |
| 683 |
vector<BondWithPos> res; |
| 684 |
// check if gid is valid |
| 685 |
if(gid<m_data.size()){ |
| 686 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 687 |
iter!=m_data[gid].end(); |
| 688 |
iter++){ |
| 689 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 690 |
iter2!=C.m_data[gid].end(); |
| 691 |
iter2++){ |
| 692 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 693 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 694 |
if(d-r0<(r0*tol)){ |
| 695 |
if(iter->Id()<iter2->Id()){ |
| 696 |
BondWithPos bwp; |
| 697 |
bwp.first=iter->Id(); |
| 698 |
bwp.second=iter2->Id(); |
| 699 |
bwp.firstPos=iter->Center(); |
| 700 |
bwp.secondPos=iter2->Center(); |
| 701 |
res.push_back(bwp); |
| 702 |
} else { |
| 703 |
BondWithPos bwp; |
| 704 |
bwp.first=iter2->Id(); |
| 705 |
bwp.second=iter->Id(); |
| 706 |
bwp.firstPos=iter2->Center(); |
| 707 |
bwp.secondPos=iter->Center(); |
| 708 |
res.push_back(bwp); |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
return res; |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
/*! |
| 721 |
intra-cell bonds between particles with a different (arbitrary) tag |
| 722 |
|
| 723 |
\param gid group ID |
| 724 |
\param tol max. difference between bond length and equilibrium dist. |
| 725 |
*/ |
| 726 |
vector<pair<int,int> > MNTCell::getBondsDiff(int gid,double tol) |
| 727 |
{ |
| 728 |
vector<pair<int,int> > res; |
| 729 |
|
| 730 |
// check if gid is valid |
| 731 |
if(gid<m_data.size()){ |
| 732 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 733 |
iter!=m_data[gid].end(); |
| 734 |
iter++){ |
| 735 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 736 |
iter2!=m_data[gid].end(); |
| 737 |
iter2++){ |
| 738 |
if(iter!=iter2){ |
| 739 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 740 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 741 |
if((fabs(d-r0)<(r0*tol)) && (iter->Tag()!=iter2->Tag())){ |
| 742 |
if(iter->Id()<iter2->Id()){ |
| 743 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 744 |
} else { |
| 745 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
} |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
return res; |
| 754 |
} |
| 755 |
|
| 756 |
/*! |
| 757 |
intra-cell bonds between particles with 2 defined tags |
| 758 |
|
| 759 |
\param gid group ID |
| 760 |
\param tol max. difference between bond length and equilibrium dist. |
| 761 |
\param tag1 1st particle tag |
| 762 |
\param tag2 2nd particle tag |
| 763 |
*/ |
| 764 |
vector<pair<int,int> > MNTCell::getBondsTagged(int gid,double tol, int tag1, int tag2) |
| 765 |
{ |
| 766 |
vector<pair<int,int> > res; |
| 767 |
|
| 768 |
// check if gid is valid |
| 769 |
if(gid<m_data.size()){ |
| 770 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 771 |
iter!=m_data[gid].end(); |
| 772 |
iter++){ |
| 773 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 774 |
iter2!=m_data[gid].end(); |
| 775 |
iter2++){ |
| 776 |
if(iter!=iter2){ |
| 777 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 778 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 779 |
if((fabs(d-r0)<(r0*tol)) && |
| 780 |
(((iter->Tag()==tag1) && (iter2->Tag()==tag2)) || |
| 781 |
((iter->Tag()==tag2)&&(iter2->Tag()==tag1)))) |
| 782 |
{ |
| 783 |
if(iter->Id()<iter2->Id()){ |
| 784 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 785 |
} else { |
| 786 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 787 |
} |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
return res; |
| 795 |
} |
| 796 |
|
| 797 |
/*! |
| 798 |
intra-cell bonds between particles with the same, defined tag |
| 799 |
|
| 800 |
\param gid group ID |
| 801 |
\param tol max. difference between bond length and equilibrium dist. |
| 802 |
\param ptag the particle tag |
| 803 |
\param mask the mask for the particle tag |
| 804 |
*/ |
| 805 |
vector<pair<int,int> > MNTCell::getBonds(int gid,double tol, int ptag, int mask) |
| 806 |
{ |
| 807 |
vector<pair<int,int> > res; |
| 808 |
|
| 809 |
// check if gid is valid |
| 810 |
if(gid<m_data.size()){ |
| 811 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 812 |
iter!=m_data[gid].end(); |
| 813 |
iter++){ |
| 814 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 815 |
iter2!=m_data[gid].end(); |
| 816 |
iter2++){ |
| 817 |
if(iter!=iter2){ |
| 818 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 819 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 820 |
if((fabs(d-r0)<(r0*tol)) && |
| 821 |
(iter->Tag()==ptag) && |
| 822 |
(iter2->Tag()==ptag)) |
| 823 |
{ |
| 824 |
if(iter->Id()<iter2->Id()){ |
| 825 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 826 |
} else { |
| 827 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
} |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
return res; |
| 836 |
} |
| 837 |
|
| 838 |
/*! |
| 839 |
inter-cell bonds |
| 840 |
|
| 841 |
\param gid group ID |
| 842 |
\param tol max. difference between bond length and equilibrium dist. |
| 843 |
\param C the other cell |
| 844 |
*/ |
| 845 |
vector<pair<int,int> > MNTCell::getBonds(int gid,double tol,const MNTCell& C) |
| 846 |
{ |
| 847 |
vector<pair<int,int> > res; |
| 848 |
|
| 849 |
// check if gid is valid |
| 850 |
if(gid<m_data.size()){ |
| 851 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 852 |
iter!=m_data[gid].end(); |
| 853 |
iter++){ |
| 854 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 855 |
iter2!=C.m_data[gid].end(); |
| 856 |
iter2++){ |
| 857 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 858 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 859 |
if(fabs(d-r0)<(r0*tol)){ |
| 860 |
if(iter->Id()<iter2->Id()){ |
| 861 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 862 |
} else { |
| 863 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 864 |
} |
| 865 |
} |
| 866 |
} |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
return res; |
| 871 |
} |
| 872 |
|
| 873 |
|
| 874 |
/*! |
| 875 |
inter-cell bonds between particles with the same (arbitrary) tag |
| 876 |
|
| 877 |
\param gid group ID |
| 878 |
\param tol max. difference between bond length and equilibrium dist. |
| 879 |
\param C the other cell |
| 880 |
*/ |
| 881 |
vector<pair<int,int> > MNTCell::getBondsSame(int gid,double tol,const MNTCell& C) |
| 882 |
{ |
| 883 |
vector<pair<int,int> > res; |
| 884 |
|
| 885 |
// check if gid is valid |
| 886 |
if(gid<m_data.size()){ |
| 887 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 888 |
iter!=m_data[gid].end(); |
| 889 |
iter++){ |
| 890 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 891 |
iter2!=C.m_data[gid].end(); |
| 892 |
iter2++){ |
| 893 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 894 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 895 |
if((fabs(d-r0)<(r0*tol)) && (iter->Tag()==iter2->Tag())){ |
| 896 |
if(iter->Id()<iter2->Id()){ |
| 897 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 898 |
} else { |
| 899 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 900 |
} |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
return res; |
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
/*! |
| 911 |
inter-cell bonds between particles with a different (arbitrary) tag |
| 912 |
|
| 913 |
\param gid group ID |
| 914 |
\param tol max. difference between bond length and equilibrium dist. |
| 915 |
\param C the other cell |
| 916 |
*/ |
| 917 |
vector<pair<int,int> > MNTCell::getBondsDiff(int gid,double tol,const MNTCell& C) |
| 918 |
{ |
| 919 |
vector<pair<int,int> > res; |
| 920 |
|
| 921 |
// check if gid is valid |
| 922 |
if(gid<m_data.size()){ |
| 923 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 924 |
iter!=m_data[gid].end(); |
| 925 |
iter++){ |
| 926 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 927 |
iter2!=C.m_data[gid].end(); |
| 928 |
iter2++){ |
| 929 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 930 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 931 |
if((fabs(d-r0)<(r0*tol)) && (iter->Tag()!=iter2->Tag())){ |
| 932 |
if(iter->Id()<iter2->Id()){ |
| 933 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 934 |
} else { |
| 935 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 936 |
} |
| 937 |
} |
| 938 |
} |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
return res; |
| 943 |
} |
| 944 |
|
| 945 |
|
| 946 |
/*! |
| 947 |
inter-cell bonds between particles with the same, defined tag |
| 948 |
|
| 949 |
\param gid group ID |
| 950 |
\param tol max. difference between bond length and equilibrium dist. |
| 951 |
\param C the other cell |
| 952 |
\param ptag the particle tag |
| 953 |
\param mask the mask for the particle tag |
| 954 |
*/ |
| 955 |
vector<pair<int,int> > MNTCell::getBonds(int gid,double tol,const MNTCell& C, int ptag, int mask) |
| 956 |
{ |
| 957 |
vector<pair<int,int> > res; |
| 958 |
|
| 959 |
// check if gid is valid |
| 960 |
if(gid<m_data.size()){ |
| 961 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 962 |
iter!=m_data[gid].end(); |
| 963 |
iter++){ |
| 964 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 965 |
iter2!=C.m_data[gid].end(); |
| 966 |
iter2++){ |
| 967 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 968 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 969 |
if((fabs(d-r0)<(r0*tol)) && |
| 970 |
(iter->Tag()==ptag) && |
| 971 |
(iter2->Tag()==ptag)) |
| 972 |
{ |
| 973 |
if(iter->Id()<iter2->Id()){ |
| 974 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 975 |
} else { |
| 976 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 977 |
} |
| 978 |
} |
| 979 |
} |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
return res; |
| 984 |
} |
| 985 |
|
| 986 |
/*! |
| 987 |
inter-cell bonds between particles with 2 defined tags |
| 988 |
|
| 989 |
\param gid group ID |
| 990 |
\param tol max. difference between bond length and equilibrium dist. |
| 991 |
\param C the other cell |
| 992 |
\param tag1 1st particle tag |
| 993 |
\param tag2 2nd particle tag |
| 994 |
*/ |
| 995 |
vector<pair<int,int> > MNTCell::getBondsTagged(int gid,double tol,const MNTCell& C, int tag1, int tag2) |
| 996 |
{ |
| 997 |
vector<pair<int,int> > res; |
| 998 |
|
| 999 |
// check if gid is valid |
| 1000 |
if(gid<m_data.size()){ |
| 1001 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 1002 |
iter!=m_data[gid].end(); |
| 1003 |
iter++){ |
| 1004 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 1005 |
iter2!=C.m_data[gid].end(); |
| 1006 |
iter2++){ |
| 1007 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 1008 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 1009 |
if((fabs(d-r0)<(r0*tol)) && |
| 1010 |
(((iter->Tag()==tag1) && (iter2->Tag()==tag2)) || |
| 1011 |
((iter->Tag()==tag2)&&(iter2->Tag()==tag1)))) |
| 1012 |
{ |
| 1013 |
if(iter->Id()<iter2->Id()){ |
| 1014 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 1015 |
} else { |
| 1016 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 1017 |
} |
| 1018 |
} |
| 1019 |
} |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
return res; |
| 1024 |
} |
| 1025 |
|
| 1026 |
/*! |
| 1027 |
intra-cell bonds between particles with 2 defined tags |
| 1028 |
|
| 1029 |
\param gid group ID |
| 1030 |
\param tol max. difference between bond length and equilibrium dist. |
| 1031 |
\param tag1 1st particle tag |
| 1032 |
\param tag2 2nd particle tag |
| 1033 |
*/ |
| 1034 |
vector<pair<int,int> > MNTCell::getBondsTaggedMasked(int gid,double tol ,int tag1 ,int mask1,int tag2 ,int mask2) |
| 1035 |
{ |
| 1036 |
vector<pair<int,int> > res; |
| 1037 |
|
| 1038 |
// check if gid is valid |
| 1039 |
if(gid<m_data.size()){ |
| 1040 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 1041 |
iter!=m_data[gid].end(); |
| 1042 |
iter++){ |
| 1043 |
for(vector<Sphere>::const_iterator iter2=iter; |
| 1044 |
iter2!=m_data[gid].end(); |
| 1045 |
iter2++){ |
| 1046 |
if(iter!=iter2){ |
| 1047 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 1048 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 1049 |
if((fabs(d-r0)<(r0*tol)) && |
| 1050 |
((((iter->Tag() & mask1)== (tag1 & mask1)) && ((iter2->Tag() & mask2) == (tag2 & mask2))) || |
| 1051 |
(((iter->Tag() & mask2)== (tag2 & mask2)) && ((iter2->Tag() & mask1) == (tag1 & mask1))))) |
| 1052 |
{ |
| 1053 |
if(iter->Id()<iter2->Id()){ |
| 1054 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 1055 |
} else { |
| 1056 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 1057 |
} |
| 1058 |
} |
| 1059 |
} |
| 1060 |
} |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
return res; |
| 1065 |
} |
| 1066 |
|
| 1067 |
/*! |
| 1068 |
inter-cell bonds between particles with 2 defined tags |
| 1069 |
|
| 1070 |
\param gid group ID |
| 1071 |
\param tol max. difference between bond length and equilibrium dist. |
| 1072 |
\param C the other cell |
| 1073 |
\param tag1 1st particle tag |
| 1074 |
\param tag2 2nd particle tag |
| 1075 |
*/ |
| 1076 |
vector<pair<int,int> > MNTCell::getBondsTaggedMasked(int gid,double tol,const MNTCell& C,int tag1,int mask1,int tag2,int mask2) |
| 1077 |
{ |
| 1078 |
vector<pair<int,int> > res; |
| 1079 |
|
| 1080 |
// check if gid is valid |
| 1081 |
if(gid<m_data.size()){ |
| 1082 |
for(vector<Sphere>::const_iterator iter=m_data[gid].begin(); |
| 1083 |
iter!=m_data[gid].end(); |
| 1084 |
iter++){ |
| 1085 |
for(vector<Sphere>::const_iterator iter2=C.m_data[gid].begin(); |
| 1086 |
iter2!=C.m_data[gid].end(); |
| 1087 |
iter2++){ |
| 1088 |
double d=(iter->Center()-iter2->Center()).norm(); // dist between centers |
| 1089 |
double r0=iter->Radius()+iter2->Radius(); // sum of radii -> equilibrium distance |
| 1090 |
if((fabs(d-r0)<(r0*tol)) && |
| 1091 |
((((iter->Tag() & mask1)== (tag1 & mask1)) && ((iter2->Tag() & mask2) == (tag2 & mask2))) || |
| 1092 |
(((iter->Tag() & mask2)== (tag2 & mask2)) && ((iter2->Tag() & mask1) == (tag1 & mask1))))) |
| 1093 |
{ |
| 1094 |
if(iter->Id()<iter2->Id()){ |
| 1095 |
res.push_back(make_pair(iter->Id(),iter2->Id())); |
| 1096 |
} else { |
| 1097 |
res.push_back(make_pair(iter2->Id(),iter->Id())); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
} |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
return res; |
| 1105 |
} |
| 1106 |
|
| 1107 |
/*! |
| 1108 |
Set output style |
| 1109 |
|
| 1110 |
\param style the output style: 0 = debug, 1 = .geo |
| 1111 |
*/ |
| 1112 |
void MNTCell::SetOutputStyle(int style) |
| 1113 |
{ |
| 1114 |
MNTCell::s_output_style=style; |
| 1115 |
} |
| 1116 |
|
| 1117 |
ostream& operator << (ostream& ost ,const MNTCell& C) |
| 1118 |
{ |
| 1119 |
if(MNTCell::s_output_style==0){ |
| 1120 |
Sphere::SetOutputStyle(0); |
| 1121 |
int gcount=0; |
| 1122 |
// for all groups |
| 1123 |
for(vector<vector<Sphere> >::const_iterator group_iter=C.m_data.begin(); |
| 1124 |
group_iter!=C.m_data.end(); |
| 1125 |
group_iter++){ |
| 1126 |
ost << "-- Group " << gcount << " -- " << endl; |
| 1127 |
gcount++; |
| 1128 |
// for all particles in the group |
| 1129 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1130 |
iter!=group_iter->end(); |
| 1131 |
iter++){ |
| 1132 |
ost << " [ " << *iter << " ] "; |
| 1133 |
} |
| 1134 |
ost << endl; |
| 1135 |
} |
| 1136 |
} else if(MNTCell::s_output_style==1){ |
| 1137 |
Sphere::SetOutputStyle(1); |
| 1138 |
// for all groups |
| 1139 |
for(vector<vector<Sphere> >::const_iterator group_iter=C.m_data.begin(); |
| 1140 |
group_iter!=C.m_data.end(); |
| 1141 |
group_iter++){ |
| 1142 |
// for all particles in the group |
| 1143 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1144 |
iter!=group_iter->end(); |
| 1145 |
iter++){ |
| 1146 |
ost << *iter << endl; |
| 1147 |
} |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
return ost; |
| 1152 |
} |
| 1153 |
|
| 1154 |
void MNTCell::writePositions(ostream& ost) |
| 1155 |
{ |
| 1156 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 1157 |
group_iter!=m_data.end(); |
| 1158 |
group_iter++){ |
| 1159 |
// for all particles in the group |
| 1160 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1161 |
iter!=group_iter->end(); |
| 1162 |
iter++){ |
| 1163 |
ost << iter->Center() << " "; |
| 1164 |
} |
| 1165 |
} |
| 1166 |
} |
| 1167 |
|
| 1168 |
void MNTCell::writeRadii(ostream& ost) |
| 1169 |
{ |
| 1170 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 1171 |
group_iter!=m_data.end(); |
| 1172 |
group_iter++){ |
| 1173 |
// for all particles in the group |
| 1174 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1175 |
iter!=group_iter->end(); |
| 1176 |
iter++){ |
| 1177 |
ost << iter->Radius() << " "; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
void MNTCell::writeIDs(ostream& ost) |
| 1183 |
{ |
| 1184 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 1185 |
group_iter!=m_data.end(); |
| 1186 |
group_iter++){ |
| 1187 |
// for all particles in the group |
| 1188 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1189 |
iter!=group_iter->end(); |
| 1190 |
iter++){ |
| 1191 |
ost << iter->Id() << " "; |
| 1192 |
} |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
void MNTCell::writeTags(ostream& ost) |
| 1197 |
{ |
| 1198 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 1199 |
group_iter!=m_data.end(); |
| 1200 |
group_iter++){ |
| 1201 |
// for all particles in the group |
| 1202 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1203 |
iter!=group_iter->end(); |
| 1204 |
iter++){ |
| 1205 |
ost << iter->Tag() << " "; |
| 1206 |
} |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
unsigned int MNTCell::writeParticlesInBlock(ostream& ost, const Vector3& min_pt, const Vector3& max_pt) |
| 1211 |
{ |
| 1212 |
Sphere::SetOutputStyle(1); |
| 1213 |
unsigned int count=0; |
| 1214 |
// for all groups |
| 1215 |
for(vector<vector<Sphere> >::const_iterator group_iter=m_data.begin(); |
| 1216 |
group_iter!=m_data.end(); |
| 1217 |
group_iter++){ |
| 1218 |
// for all particles in the group |
| 1219 |
for(vector<Sphere>::const_iterator iter=group_iter->begin(); |
| 1220 |
iter!=group_iter->end(); |
| 1221 |
iter++){ |
| 1222 |
Vector3 pos=iter->Center(); |
| 1223 |
if((pos.X()>=min_pt.x()) && (pos.X()<max_pt.x()) && |
| 1224 |
(pos.Y()>=min_pt.y()) && (pos.Y()<max_pt.y()) && |
| 1225 |
(pos.Z()>=min_pt.z()) && (pos.Z()<max_pt.z())){ |
| 1226 |
ost << *iter << endl; |
| 1227 |
count++; |
| 1228 |
} |
| 1229 |
} |
| 1230 |
} |
| 1231 |
return count; |
| 1232 |
} |
| 1233 |
|