source: sasmodels/sasmodels/gengauss.py @ c64a68e

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since c64a68e was ff31782, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

add -ngauss option to compare in order to set the number of integration points

  • Property mode set to 100755
File size: 1.1 KB
Line 
1#!/usr/bin/env python
2from __future__ import division, print_function
3
4import sys
5
6import numpy as np
7from numpy.polynomial.legendre import leggauss
8
9def gengauss(n, path):
10    z, w = leggauss(n)
11
12    # Make sure array size is a multiple of 4
13    if n%4:
14        array_size = n + (4 - n%4)
15        z, w = [np.hstack((v, [0.]*(4-n%4))) for v in (z, w)]
16    else:
17        array_size = n
18
19    with open(path, "w") as fid:
20        fid.write("""\
21// Generated by sasmodels.gengauss.gengauss(%d)
22
23#ifdef GAUSS_N
24# undef GAUSS_N
25# undef GAUSS_Z
26# undef GAUSS_W
27#endif
28#define GAUSS_N %d
29#define GAUSS_Z Gauss%dZ
30#define GAUSS_W Gauss%dWt
31
32"""%(n, n, n, n))
33
34        if array_size != n:
35            fid.write("// Note: using array size %d so that it is a multiple of 4\n\n"%array_size)
36
37        fid.write("constant double Gauss%dWt[%d]={\n"%(n, array_size))
38        fid.write(",\n".join("\t% .15e"%v for v in w))
39        fid.write("\n};\n")
40
41        fid.write("constant double Gauss%dZ[%d]={\n"%(n, array_size))
42        fid.write(",\n".join("\t% .15e"%v for v in z))
43        fid.write("\n};")
Note: See TracBrowser for help on using the repository browser.