ESyS-Particle  2.3.4
nt_block.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-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 // //
12 
16 template<typename T>
18  : m_table(NULL),
19  m_xmin(0),
20  m_xmax(0),
21  m_ymin(0),
22  m_ymax(0),
23  m_zmin(0),
24  m_zmax(0)
25 {
26 }
27 
40 template<typename T>
41 NTBlock<T>::NTBlock(NeighborTable<T>* t,int xmin,int xmax,int ymin,int ymax,int zmin,int zmax)
42  : m_table(t),
43  m_xmin(xmin),
44  m_xmax(xmax),
45  m_ymin(ymin),
46  m_ymax(ymax),
47  m_zmin(zmin),
48  m_zmax(zmax)
49 {
50 }
51 
55 template<typename T>
56 unsigned int NTBlock<T>::size()
57 {
58  unsigned int np=0;
59  for (iterator it = begin(); it != end(); it++, np++)
60  {
61  // keep going
62  }
63 
64  return np;
65 }
66 
67 
72 template<typename T>
74 {
75  // find the first occupied site in the search array
76  int ix=m_xmin;
77  int iy=m_ymin;
78  int iz=m_zmin;
79  bool end=false;
80  while(!end && m_table->nparts_at_gridpoint(m_table->index(ix,iy,iz))==0){
81  if(ix<m_xmax){
82  ix++;
83  } else {
84  ix=m_xmin;
85  if(iy<m_ymax){
86  iy++;
87  } else {
88  iy=m_ymin;
89  if(iz<m_zmax){
90  iz++;
91  } else {
92  ix=m_xmax+1;// end iter
93  iy=m_ymax+1;
94  iz=m_zmax+1;
95  end=true;
96  }
97  }
98  }
99  }
100  return iterator(this,ix,iy,iz,0);
101 }
102 
106 template<typename T>
108 {
109  return iterator(this,m_xmax+1,m_ymax+1,m_zmax+1,0);
110 }
111 
116 // template<typename T>
117 // iterator NTBlock<T>::rbegin()
118 // {
119 
120 // }
121 
125 // template<typename T>
126 // iterator NTBlock<T>::rend()
127 // {}
128 
132 template<typename T>
133 T* NTBlock<T>::ptr(int ix,int iy,int iz,int j)
134 {
135  typename NeighborTable<T>::indextype a_idx;
136  a_idx.first=m_table->index(ix,iy,iz);
137  a_idx.second=j;
138 
139  return m_table->ptr(a_idx);
140 }
141 
145 template<typename T>
146 T& NTBlock<T>::ref(int ix,int iy,int iz,int j)
147 {
148  typename NeighborTable<T>::indextype a_idx;
149  a_idx.first=m_table->index(ix,iy,iz);
150  a_idx.second=j;
151 
152  return m_table->ref(a_idx);
153 }
154 
158 template <typename T>
159 bool operator== (const NTBlock<T>& b1,const NTBlock<T>& b2)
160 {
161  return (b1.m_table==b2.m_table &&
162  b1.m_xmin==b2.m_xmin &&
163  b1.m_xmax==b2.m_xmax &&
164  b1.m_ymin==b2.m_ymin &&
165  b1.m_ymax==b2.m_ymax &&
166  b1.m_zmin==b2.m_zmin &&
167  b1.m_zmax==b2.m_zmax);
168 }
169 
173 template <typename T>
174 bool operator!=(const NTBlock<T>& b1,const NTBlock<T>& b2)
175 {
176  return (b1.m_table!=b2.m_table ||
177  b1.m_xmin!=b2.m_xmin ||
178  b1.m_xmax!=b2.m_xmax ||
179  b1.m_ymin!=b2.m_ymin ||
180  b1.m_ymax!=b2.m_ymax ||
181  b1.m_zmin!=b2.m_zmin ||
182  b1.m_zmax!=b2.m_zmax);
183 }
184 
185 
192 template <typename T>
193 ostream& operator<<(ostream& ost,const NTBlock<T>& NTB)
194 {
195  ost << "---NTBlock---"<< endl;
196  ost << "range: " << endl;
197  ost << "x: " << NTB.m_xmin << "-" << NTB.m_xmax << endl;
198  ost << "y: " << NTB.m_ymin << "-" << NTB.m_ymax << endl;
199  ost << "z: " << NTB.m_zmin << "-" << NTB.m_zmax << endl;
200  ost << "indices:" << endl;
201  for (int ix=NTB.m_xmin;ix<=NTB.m_xmax;ix++){
202  for (int iy=NTB.m_ymin;iy<=NTB.m_ymax;iy++){
203  for (int iz=NTB.m_zmin;iz<=NTB.m_zmax;iz++){
204  ost << NTB.m_table->index(ix,iy,iz) << " ";
205  }
206  }
207  }
208  ost << endl;
209 
210  return ost;
211 }
NTBlock
representation of a slab of the search array of a NeigborTable
Definition: nt_block.h:33
NTBlock::m_ymin
int m_ymin
Definition: nt_block.h:41
NTBlock::m_xmin
int m_xmin
Definition: nt_block.h:41
NTBlock::ref
T & ref(int, int, int, int)
Definition: nt_block.hpp:146
NeighborTable::index
int index(const Vec3 &)
Definition: ntable.hpp:109
NeighborTable::ref
T & ref(NeighborTable< T >::indextype)
Definition: ntable.hpp:225
NTBlock::m_zmax
int m_zmax
Definition: nt_block.h:41
NeighborTable::ptr
T * ptr(NeighborTable< T >::indextype)
Definition: ntable.hpp:216
operator<<
ostream & operator<<(ostream &ost, const NTBlock< T > &NTB)
Definition: nt_block.hpp:193
operator!=
bool operator!=(const NTBlock< T > &b1, const NTBlock< T > &b2)
Definition: nt_block.hpp:174
NeighborTable::indextype
pair< int, int > indextype
Definition: ntable.h:72
NTBlock::m_zmin
int m_zmin
Definition: nt_block.h:41
NULL
#define NULL
Definition: t_list.h:17
NTBlock_iter
iterator for a NTBlock
Definition: ntb_iter.h:39
NTBlock::begin
iterator begin()
Definition: nt_block.hpp:73
NTBlock::size
unsigned int size()
Definition: nt_block.hpp:56
NTBlock::m_xmax
int m_xmax
Definition: nt_block.h:41
NeighborTable
class for neighbor search
Definition: ntable.h:68
NTBlock::m_ymax
int m_ymax
Definition: nt_block.h:41
operator==
bool operator==(const NTBlock< T > &b1, const NTBlock< T > &b2)
Definition: nt_block.hpp:159
NTBlock::ptr
T * ptr(int, int, int, int)
Definition: nt_block.hpp:133
NTBlock::NTBlock
NTBlock()
Definition: nt_block.hpp:17
NTBlock::end
iterator end()
Definition: nt_block.hpp:107
NTBlock::m_table
NeighborTable< T > * m_table
Definition: nt_block.h:40