ticket-1257-vesicle-productticket_1156ticket_822_more_unit_tests
Last change
on this file since e220acc was
b297ba9,
checked in by Paul Kienzle <pkienzle@…>, 6 years ago
|
lint
|
-
Property mode set to
100755
|
File size:
1.2 KB
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | """ |
---|
3 | Generate the Gauss-Legendre integration points and save them as a C file. |
---|
4 | """ |
---|
5 | from __future__ import division, print_function |
---|
6 | |
---|
7 | import numpy as np |
---|
8 | from numpy.polynomial.legendre import leggauss |
---|
9 | |
---|
10 | def gengauss(n, path): |
---|
11 | """ |
---|
12 | Save the Gauss-Legendre integration points for length *n* into file *path*. |
---|
13 | """ |
---|
14 | z, w = leggauss(n) |
---|
15 | |
---|
16 | # Make sure array size is a multiple of 4 |
---|
17 | if n%4: |
---|
18 | array_size = n + (4 - n%4) |
---|
19 | z, w = [np.hstack((v, [0.]*(4-n%4))) for v in (z, w)] |
---|
20 | else: |
---|
21 | array_size = n |
---|
22 | |
---|
23 | with open(path, "w") as fid: |
---|
24 | fid.write("""\ |
---|
25 | // Generated by sasmodels.gengauss.gengauss(%d) |
---|
26 | |
---|
27 | #ifdef GAUSS_N |
---|
28 | # undef GAUSS_N |
---|
29 | # undef GAUSS_Z |
---|
30 | # undef GAUSS_W |
---|
31 | #endif |
---|
32 | #define GAUSS_N %d |
---|
33 | #define GAUSS_Z Gauss%dZ |
---|
34 | #define GAUSS_W Gauss%dWt |
---|
35 | |
---|
36 | """%(n, n, n, n)) |
---|
37 | |
---|
38 | if array_size != n: |
---|
39 | fid.write("// Note: using array size %d so that it is a multiple of 4\n\n"%array_size) |
---|
40 | |
---|
41 | fid.write("constant double Gauss%dWt[%d]={\n"%(n, array_size)) |
---|
42 | fid.write(",\n".join("\t% .15e"%v for v in w)) |
---|
43 | fid.write("\n};\n") |
---|
44 | |
---|
45 | fid.write("constant double Gauss%dZ[%d]={\n"%(n, array_size)) |
---|
46 | fid.write(",\n".join("\t% .15e"%v for v in z)) |
---|
47 | fid.write("\n};") |
---|
Note: See
TracBrowser
for help on using the repository browser.