From 139f6c4d252b7af2ca9c3e23cc0b925721d490a6 Mon Sep 17 00:00:00 2001 From: Chichi Lalescu Date: Sun, 23 Nov 2014 21:11:40 -0500 Subject: [PATCH] grid_spline: simplify get_indices from c file --- pyJHTDB/generic_splines.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pyJHTDB/generic_splines.py b/pyJHTDB/generic_splines.py index 10e2922..519f8bf 100644 --- a/pyJHTDB/generic_splines.py +++ b/pyJHTDB/generic_splines.py @@ -284,9 +284,9 @@ 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): @@ -294,13 +294,27 @@ def beta_cformulas(node): 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'