4 Compile the C++ Woods-Saxon generator, run it, pipe the results into this
11 import matplotlib.pyplot
as plt
13 from scipy
import integrate
17 return r*r/(1. + np.exp((r-R)/a))
21 basename =
'generate-woods-saxon'
22 cxxname =
'{}.cxx'.
format(basename)
23 if not os.path.exists(basename)
or (
24 os.path.getmtime(cxxname) > os.path.getmtime(basename)):
25 print(
'compiling C++ Woods-Saxon generator')
26 subprocess.check_call(
27 [
'g++',
'-std=c++11',
'-Wall',
'-Wextra',
'-O3',
'-march=native',
28 cxxname,
'-o'+basename])
34 print(
'generating Woods-Saxon numbers')
35 with subprocess.Popen([
'./'+basename,
str(R),
str(a),
str(N)],
36 stdout=subprocess.PIPE)
as proc:
37 samples = np.fromiter(proc.stdout, dtype=float, count=N)
40 plt.hist(samples, bins=200, histtype=
'step', normed=
True)
43 r = np.linspace(0, rmax, 1000)
44 norm = integrate.quad(woods_saxon, 0, rmax, args=(R, a))[0]
51 if __name__ ==
"__main__":