ESyS-Particle  2.3.4
nt_slab.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>
17 NTSlab<T>::NTSlab():m_sl(0,0,0,0,0)
18 {
19  m_table=NULL;
20 }
21 
29 template<typename T>
30 NTSlab<T>::NTSlab(NeighborTable<T>* t,DSlice s):m_table(t),m_sl(s)
31 {
32 }
33 
37 template<typename T>
38 unsigned int NTSlab<T>::size()const
39 {
40  unsigned int np=0;
41 
42  for(unsigned int i=0;i<m_sl.size();i++){
43  np+=m_table->nparts_at_gridpoint(m_sl[i]);
44  }
45 
46  return np;
47 }
48 
53 template<typename T>
55 {
56  // find the first occupied site in the search array
57  unsigned int i=0;
58  while(
59  (i<m_sl.size())
60  &&
61  (m_table->nparts_at_gridpoint(m_sl[i]) == 0)
62  ){
63  i++;
64  }
65  return
66  typename NTSlab<T>::iterator(
67  this,
68  typename NeighborTable<T>::indextype(i,0)
69  );
70 }
71 
75 template<typename T>
77 {
78  return
79  typename NTSlab<T>::iterator(
80  this,
81  typename NeighborTable<T>::indextype(m_sl.size(),0)
82  );
83 }
84 
89 template<typename T>
91 {
92  int j;
93 
94  // find the last occupied site in the search array
95  int i=m_sl.size()-1;
96  while((i>-1)&&
97  nparts_at_gridpoint(i)==0){
98  i--;
99  }
100  j=nparts_at_gridpoint(i)-1;
101  if(i==-1) j=0; // rend
102 
103  return
104  typename NTSlab<T>::iterator(
105  this,
106  typename NeighborTable<T>::indextype(i,j)
107  );
108 }
109 
113 template<typename T>
115 {
116  return
117  typename NTSlab<T>::iterator(
118  this,
119  typename NeighborTable<T>::indextype(-1,0)
120  );
121 }
122 
129 template<typename T>
131 {
132  typename NeighborTable<T>::indextype a_idx;
133  a_idx.first=m_sl[idx.first];
134  a_idx.second=idx.second;
135 
136  return m_table->ptr(a_idx);
137 }
138 
145 template<typename T>
147 {
148  typename NeighborTable<T>::indextype a_idx;
149  a_idx.first=m_sl[idx.first];
150  a_idx.second=idx.second;
151 
152  return m_table->ref(a_idx);
153 }
154 
155 
162 template<typename T>
163 void NTSlab<T>::insert(typename NTSlab<T>::iterator,const T& data)
164 {
165  m_table->insert(data);
166 }
167 
168 
174 template<typename T>
175 void NTSlab<T>::erase(typename NTSlab<T>::iterator pos)
176 {
177  // check if iter points into this slab ?
178  // erase item
179  typename NeighborTable<T>::indextype a_idx;
180  a_idx.first=m_sl[pos.index().first];
181  a_idx.second=pos.index().second;
182  m_table->erase(a_idx);
183 }
184 
191 template<typename T>
192 void NTSlab<T>::erase(typename NTSlab<T>::iterator begin,typename NTSlab<T>::iterator end)
193 {
194  // do it backwards, because erase invalidates all iterators behind
195  begin--;
196  end--;
197 
198  for(typename NTSlab<T>::iterator iter=end;
199  iter!=begin;
200  iter--){
201 
202  erase(iter);
203  }
204 }
205 
206 template <typename T>
207 bool operator== (const NTSlab<T>& s1,const NTSlab<T>& s2)
208 {
209  return(s1.m_table==s2.m_table && s1.m_sl==s2.m_sl);
210 }
211 
212 template <typename T>
213 bool operator!= (const NTSlab<T>& s1,const NTSlab<T>& s2)
214 {
215  return (s1.m_table!=s2.m_table || s1.m_sl!=s2.m_sl);
216 }
217 
224 template<typename T>
225 ostream& operator<< (ostream& ost,const NTSlab<T>& NTS)
226 {
227  ost << "---NTSlab---" << endl;
228  ost << "indices:" << endl;
229  for(unsigned int i=0;i<NTS.slab_size();i++){
230  ost << NTS.m_sl[i] << " ";
231  }
232  ost << endl;
233 
234  return ost;
235 }
operator==
bool operator==(const NTSlab< T > &s1, const NTSlab< T > &s2)
Definition: nt_slab.hpp:207
NTSlab::m_table
NeighborTable< T > * m_table
Definition: nt_slab.h:42
NTSlab::rbegin
iterator rbegin()
Definition: nt_slab.hpp:90
NeighborTable::ref
T & ref(NeighborTable< T >::indextype)
Definition: ntable.hpp:225
NTSlab::insert
void insert(iterator, const T &)
Definition: nt_slab.hpp:163
NeighborTable::ptr
T * ptr(NeighborTable< T >::indextype)
Definition: ntable.hpp:216
NTSlab::iterator
NTSlab_iter< T > iterator
Definition: nt_slab.h:37
operator!=
bool operator!=(const NTSlab< T > &s1, const NTSlab< T > &s2)
Definition: nt_slab.hpp:213
NTSlab::ptr
T * ptr(typename NeighborTable< T >::indextype)
Definition: nt_slab.hpp:130
NTSlab::rend
iterator rend()
number of particles at a given gridpoint
Definition: nt_slab.hpp:114
NTSlab::slab_size
unsigned int slab_size() const
Definition: nt_slab.h:50
NTSlab::erase
void erase(iterator)
NeighborTable::indextype
pair< int, int > indextype
Definition: ntable.h:72
NTSlab
representation of a slab of the search array of a NeigborTable
Definition: nt_slab.h:35
NTSlab::NTSlab
NTSlab()
Definition: nt_slab.hpp:17
NULL
#define NULL
Definition: t_list.h:17
NTSlab::ref
T & ref(typename NeighborTable< T >::indextype)
Definition: nt_slab.hpp:146
NeighborTable
class for neighbor search
Definition: ntable.h:68
esys::lsm::bpu::iter
boost::python::object iter(const boost::python::object &pyOb)
Definition: Util.h:25
operator<<
ostream & operator<<(ostream &ost, const NTSlab< T > &NTS)
Definition: nt_slab.hpp:225
NTSlab::size
unsigned int size() const
Definition: nt_slab.hpp:38
NTSlab_iter
iterator for a NTSlab
Definition: nts_iter.h:39
NTSlab::begin
iterator begin()
Definition: nt_slab.hpp:54
NTSlab_iter::index
NeighborTable< T >::indextype index() const
Definition: nts_iter.hpp:118
DSlice
Definition: dslice.h:22
NTSlab::m_sl
DSlice m_sl
Definition: nt_slab.h:43
NTSlab::end
iterator end()
Definition: nt_slab.hpp:76