@@ -137,36 +137,44 @@ def init_neighbours(self):
137137 for i in range (self .nz ):
138138 for j in range (self .ny ):
139139 for k in range (self .nx ):
140+ # Unique index for the current lattice site
140141 cell = self ._index (k , j , i )
141- ngbs = [ other for other in [
142+ neighbours = [
142143 self .index (k - 1 , j , i ), # left
143144 self .index (k + 1 , j , i ), # right
144145 self .index (k , j - 1 , i ), # behind
145146 self .index (k , j + 1 , i ), # in front
146147 self .index (k , j , i - 1 ), # under
147148 self .index (k , j , i + 1 ), # over
148- ]]
149+ ]
149150
150- nngbs = [other for other in [
151+ # If one of the neighbours is the cell itself, we
152+ # set its index to -1
153+ # neighbours = [other if other != cell
154+ # else -1 for other in neighbours]
155+
156+ next_neighbours = [
151157 self .index (k - 2 , j , i ), # left
152158 self .index (k + 2 , j , i ), # right
153159 self .index (k , j - 2 , i ), # behind
154160 self .index (k , j + 2 , i ), # in front
155161 self .index (k , j , i - 2 ), # under
156162 self .index (k , j , i + 2 ), # over
157- ]]
158-
159- # July 1st, 2016 Weiwei: I think it's okay for a cell with its neighbour is itself
160- # if periodic boundary conditions are used. For example, if we only have cell and enable
161- # periodic boundary condition in x-direction, then we got a rod.
162- # therefore, I commented two lines below.
163+ ]
164+
165+ # July 1st, 2016 Weiwei: I think it's okay for a cell with
166+ # its neighbour is itself if periodic boundary conditions
167+ # are used. For example, if we only have one cell and
168+ # enable periodic boundary condition in x-direction, then
169+ # we got a rod. therefore, I commented two lines below.
163170 # no cell should be its own neighbour
164- # neighbours = [other if other != cell
165- # else -1 for other in ngbs]
166- connectivity .append (ngbs )
167- connectivity_next .append (nngbs )
168-
169- return np .array (connectivity , dtype = np .int32 ), np .array (connectivity_next , dtype = np .int32 )
171+
172+ connectivity .append (neighbours )
173+ connectivity_next .append (next_neighbours )
174+
175+ return (np .array (connectivity , dtype = np .int32 ),
176+ np .array (connectivity_next , dtype = np .int32 )
177+ )
170178
171179 def index (self , i , j , k ):
172180 """
@@ -176,30 +184,30 @@ def index(self, i, j, k):
176184 i, j, k are the positions in the x, y and z directions, respectively
177185
178186 """
179- if self .periodicity [0 ]: # if mesh is periodic in x-direction
180- if i < 0 : # then wrap the left side
181- i += self .nx # to the right
182- elif i >= self .nx : # and wrap the right side
183- i -= self .nx # to the left
184-
185- if self .periodicity [1 ]:
186- if j < 0 :
187- j += self .ny
188- elif j >= self .ny :
189- j -= self .ny
190-
191- if self .periodicity [2 ]:
192- if k < 0 :
193- k += self .nz
194- elif k >= self .nz :
187+ if self .periodicity [0 ]: # if mesh is periodic in x-direction
188+ if i < 0 : # then wrap the left side
189+ i += self .nx # to the right
190+ elif i >= self .nx : # and wrap the right side
191+ i -= self .nx # to the left
192+
193+ if self .periodicity [1 ]:
194+ if j < 0 :
195+ j += self .ny
196+ elif j >= self .ny :
197+ j -= self .ny
198+
199+ if self .periodicity [2 ]:
200+ if k < 0 :
201+ k += self .nz
202+ elif k >= self .nz :
195203 k -= self .nz
196204
197205 return self ._index (i , j , k )
198206
199207 def _index (self , i , j , k ):
200208 """
201209 Returns the index for the cell with ordinals i, j, k
202- or False if that cell would be out of bounds.
210+ or -1 if that cell would be out of bounds.
203211
204212 """
205213 if i < 0 or j < 0 or k < 0 or k >= self .nz or j >= self .ny or i >= self .nx :
0 commit comments