1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC) //
// http://www.uq.edu.au/esscc //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.opensource.org/licenses/osl-3.0.php //
// //
/////////////////////////////////////////////////////////////
#include "Geometry/SimpleNTable3D.h"
/*!
Return the grid index of a position.
\param pos the position
\warning does not check if pos is within space
*/
int CSimple3DNTable::index(const Vec3& pos) const
{
int ix=int((pos.X()-m_p0.X())/m_dim);
int iy=int((pos.Y()-m_p0.Y())/m_dim);
int iz=int((pos.Z()-m_p0.Z())/m_dim);
int idx=ix+m_xsize*iy+iz*m_xsize*m_ysize;
return idx;
}
/*!
Get all indices to which a particle at a given position will be added.
\param pos the position
\warning does not check if pos is within space
*/
vector<int> CSimple3DNTable::allidx(const Vec3& pos) const
{
vector<int> res;
int ix=int((pos.X()-m_p0.X())/m_dim);
int iy=int((pos.Y()-m_p0.Y())/m_dim);
int iz=int((pos.Z()-m_p0.Z())/m_dim);
int idx=ix+m_xsize*iy+iz*m_xsize*m_ysize;
res.push_back(idx);
// iz-layer
if(ix>0){
res.push_back(idx-1);
if(iy>0){
res.push_back(idx-m_xsize-1);
}
if(iy<m_ysize-1){
res.push_back(idx+m_xsize-1);
}
}
if(ix<m_xsize-1){
res.push_back(idx+1);
if(iy>0){
res.push_back(idx-m_xsize+1);
}
if(iy<m_ysize-1){
res.push_back(idx+m_xsize+1);
}
}
if(iy>0){
res.push_back(idx-m_xsize);
}
if(iy<m_ysize-1){
res.push_back(idx+m_xsize);
}
// iz-1 layer
if(iz>0){
int idb=idx-m_xsize*m_ysize;
res.push_back(idb);
if(ix>0){
res.push_back(idb-1);
if(iy>0){
res.push_back(idb-m_xsize-1);
}
if(iy<m_ysize-1){
res.push_back(idb+m_xsize-1);
}
}
if(ix<m_xsize-1){
res.push_back(idb+1);
if(iy>0){
res.push_back(idb-m_xsize+1);
}
if(iy<m_ysize-1){
res.push_back(idb+m_xsize+1);
}
}
if(iy>0){
res.push_back(idb-m_xsize);
}
if(iy<m_ysize-1){
res.push_back(idb+m_xsize);
}
}
// iz+1 layer
if(iz<m_zsize-1){
int idb=idx+m_xsize*m_ysize;
res.push_back(idb);
if(ix>0){
res.push_back(idb-1);
if(iy>0){
res.push_back(idb-m_xsize-1);
}
if(iy<m_ysize-1){
res.push_back(idb+m_xsize-1);
}
}
if(ix<m_xsize-1){
res.push_back(idb+1);
if(iy>0){
res.push_back(idb-m_xsize+1);
}
if(iy<m_ysize-1){
res.push_back(idb+m_xsize+1);
}
}
if(iy>0){
res.push_back(idb-m_xsize);
}
if(iy<m_ysize-1){
res.push_back(idb+m_xsize);
}
}
return res;
}
/*!
insert circular images of the particle
\param cbp the particle
*/
void CSimple3DNTable::insertParticleCircular(SimpleParticle cbp)
{
if(m_xcirc){
if (int((cbp.getPos().X()-m_p0.X())/m_dim)==1) {
cbp.moveTo(cbp.getPos()+m_xshift);
const vector<int> idx=allidx(cbp.getPos());
for(vector<int>::const_iterator citer=idx.begin();citer!=idx.end();citer++){
m_data[*citer].push_back(cbp);
}
} else if (int((cbp.getPos().X()-m_p0.X())/m_dim)==m_xsize-2) {
cbp.moveTo(cbp.getPos()-m_xshift);
const vector<int> idx=allidx(cbp.getPos());
for(vector<int>::const_iterator citer=idx.begin();citer!=idx.end();citer++){
m_data[*citer].push_back(cbp);
}
}
}
}
/*!
Constructor
\param pos position of the (xmin,ymin,zmin) point
\param dim size of the space
\param r grid spacing
*/
CSimple3DNTable::CSimple3DNTable(const Vec3& pos,const Vec3& dim ,double r ,bool xcirc,bool ycirc,bool zcirc)
{
//cout << "CSimple3DNTable(" << pos << " , " << dim << " , " << r << ")" << endl;
m_xsize=int(ceil(dim.X()/r));
m_ysize=int(ceil(dim.Y()/r));
m_zsize=int(ceil(dim.Z()/r));
m_xcirc=xcirc;
m_ycirc=ycirc;
m_zcirc=zcirc;
m_p0=pos;
m_dim=r;
// pad in circular directions
if (m_xcirc) {
m_xsize+=2;
m_p0-=Vec3(r,0.0,0.0);
m_xshift=Vec3(dim.X(),0.0,0.0);
}
if (m_ycirc) {
m_ysize+=2;
m_p0-=Vec3(0.0,r,0.0);
m_yshift=Vec3(0.0,dim.Y(),0.0);
}
if (m_zcirc) {
m_zsize+=2;
m_p0-=Vec3(0.0,0.0,r);
m_yshift=Vec3(0.0,0.0,dim.Z());
}
//cout << "NT size : " << m_xsize << " , " << m_ysize << " , " << m_zsize << endl;
m_data=new vector<SimpleParticle>[m_xsize*m_ysize*m_zsize];
}
/*!
Put all interactions into a set
\param iset the set into which to put them
\param dmax max distance for the creation of an interaction
*/
void CSimple3DNTable::getInteractions(set<BasicInteraction,BILess>& iset, double dmax)
{
for(int i=0;i<m_xsize;i++){
for(int j=0;j<m_ysize;j++){
for(int k=0;k<m_zsize;k++){
int idx=i+m_xsize*j+k*m_xsize*m_ysize;
//cout << "-- " << i << " , " << j << " , " << idx << endl;
if(m_data[idx].size()>=2){
for(vector<SimpleParticle>::iterator iter=m_data[idx].begin();
iter!=m_data[idx].end()-1;
iter++)
{
for (
vector<SimpleParticle>::iterator iter2=iter+1;
iter2!=m_data[idx].end();
iter2++)
{
// cout << "Pair: " << iter->getID() << " - " << iter2 ->getID() << endl;
if((iter->getPos()-iter2->getPos()).norm() < dmax*(iter->getRad()+iter2->getRad()))
{
iset.insert(BasicInteraction(iter->getID(),iter2->getID()));
}
}
}
}
}
}
}
}
// debugging only
void CSimple3DNTable::print()
{
for(int i=0;i<m_xsize;i++){
for(int j=0;j<m_ysize;j++){
for(int k=0;k<m_zsize;k++){
int idx=i+m_xsize*j+k*m_xsize*m_ysize;
//cout << "-- " << i << " , " << j << " , " << " , " << j << " , " << idx << endl;
for(vector<SimpleParticle>::iterator iter=m_data[idx].begin();
iter!=m_data[idx].end();
iter++){
cout << iter->getPos() << " , " << iter->getRad() << endl;
}
}
}
}
}
|