Skip to content

Commit

Permalink
grid_spline: simplify get_indices from c file
Browse files Browse the repository at this point in the history
  • Loading branch information
chichilalescu committed Nov 24, 2014
1 parent 48f5efa commit 139f6c4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pyJHTDB/generic_splines.py
Expand Up @@ -284,23 +284,37 @@ def beta_cformulas(node):
# end and return 0
src_txt += 'return EXIT_SUCCESS;\n}\n'
src_txt += 'int ' + cprefix + 'indices' + csuffix + '('
src_txt += 'int cell, ' # which cell are we in?
src_txt += (
' int *index)' + # array where to place the values of the beta polynomials
'int cell, ' + # which cell are we in?
'int *index)' + # array where to place the values of the beta polynomials
'\n{\n')
if self.periodic:
for i in range(self.n*2 + 2):
src_txt += 'index[{0}] = {1};\n'.format(i, i-self.n)
else:
src_txt += (
'switch (cell)\n{\n')
for cell in range(len(self.beta)):
for cell in range(self.n):
src_txt += 'case {0}:\n'.format(cell)
for i in range(len(self.neighbour_list[cell])):
src_txt += 'index[{0}] = {1};\n'.format(i, self.neighbour_list[cell][i] - cell)
if len(self.neighbour_list[cell]) < self.n*2+2:
src_txt += 'index[{0}] = {1};\n'.format(self.n*2+1, self.neighbour_list[cell][-1] - cell)
src_txt += 'break;\n'
for cell in range(len(self.beta)-self.n, len(self.beta)):
src_txt += 'case {0}:\n'.format(cell)
for i in range(len(self.neighbour_list[cell])):
src_txt += 'index[{0}] = {1};\n'.format(i, self.neighbour_list[cell][i] - cell)
if len(self.neighbour_list[cell]) < self.n*2+2:
src_txt += 'index[{0}] = {1};\n'.format(self.n*2+1, self.neighbour_list[cell][-1] - cell)
src_txt += 'break;\n'
cell = self.n+1
src_txt += 'default:\n'.format(cell)
for i in range(len(self.neighbour_list[cell])):
src_txt += 'index[{0}] = {1};\n'.format(i, self.neighbour_list[cell][i] - cell)
if len(self.neighbour_list[cell]) < self.n*2+2:
src_txt += 'index[{0}] = {1};\n'.format(self.n*2+1, self.neighbour_list[cell][-1] - cell)
src_txt += 'break;\n'
src_txt += ('\n}\n') # end cell switch
# end and return 0
src_txt += 'return EXIT_SUCCESS;\n}\n'
Expand Down

0 comments on commit 139f6c4

Please sign in to comment.