f.write("// Bardell's hierarchical functions\n\n") f.write('// Number of terms: {0}\n\n'.format(len(u))) f.write('#include <stdlib.h>\n') f.write('#include <math.h>\n\n') f.write('#if defined(_WIN32) || defined(__WIN32__)\n') f.write(' #define EXPORTIT __declspec(dllexport)\n') f.write('#else\n') f.write(' #define EXPORTIT\n') f.write('#endif\n\n') f.write('EXPORTIT void calc_vec_f(double *f, double xi,\n' + ' double xi1t, double xi1r, double xi2t, double xi2r) {\n') consts = {0:'xi1t', 1:'xi1r', 2:'xi2t', 3:'xi2r'} for i in range(len(u)): const = consts.get(i) if const is None: f.write(' f[%d] = %s;\n' % (i, star2Cpow(str(u[i])))) else: f.write(' f[%d] = %s*(%s);\n' % (i, const, star2Cpow(str(u[i])))) f.write('}\n') f.write('\n\n') f.write('EXPORTIT void calc_vec_fxi(double *fxi, double xi,\n' + ' double xi1t, double xi1r, double xi2t, double xi2r) {\n') for i in range(len(u)): const = consts.get(i) if const is None: f.write(' fxi[%d] = %s;\n' % (i, star2Cpow(str(diff(u[i], xi))))) else: f.write(' fxi[%d] = %s*(%s);\n' % (i, const, star2Cpow(str(diff(u[i], xi))))) f.write('}\n')
activerow = False for j in range(matrix.shape[1]): if matrix[i, j] == 0: continue if not activerow: activerow = True if i == 0: printstr += ' switch(i) {\n' else: printstr += ' default:\n' printstr += ' return 0.;\n' printstr += ' }\n' printstr += ' case %d:\n' % i printstr += ' switch(j) {\n' printstr += ' case %d:\n' % j printstr += ' return %s;\n' % star2Cpow(str(matrix[i, j].evalf())) printstr += ' default:\n' printstr += ' return 0.;\n' printstr += ' }\n' printstr += ' default:\n' printstr += ' return 0.;\n' printstr += ' }\n' printstr += '}\n' if '_12' in filepath: printstr_12_h += printstr_h filepath = r'..\..\..\C\src\bardell_12_%s.c' % name[:-3] with open(filepath, 'w') as g: g.write(printstr_12 + printstr) else: printstr_full += printstr