-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecay_compare.py
executable file
·94 lines (79 loc) · 2.48 KB
/
decay_compare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
from pprint import pprint
from collections import defaultdict
import numpy as np
from sympy import exp
from pyne import nucname
from pyne.material import Material
from pyne import cram
np.set_printoptions(precision=18)
#TIMES = [0.0] + sorted(TIME_STEPS.keys())
TIMES = [0.0] + np.logspace(1, 20, 39).tolist()
NTIMES = len(TIMES)
DECAY_MATS = {t: (-cram.DECAY_MATRIX*t) for t in TIMES}
emptytime = lambda: np.zeros(NTIMES, dtype=float)
def run_nuclide(nuc):
bateman = defaultdict(emptytime)
bateman[nuc][0] = 1
crammed = defaultdict(emptytime)
crammed[nuc][0] = 1
diagexp = defaultdict(emptytime)
diagexp[nuc][0] = 1
n0 = Material({nuc: 1.0}, mass=1.0, atoms_per_molecule=1.0)
for i, t in enumerate(TIMES[1:], 1):
# compute Bateman
try:
b1 = n0.decay(t).to_atom_frac()
except RuntimeError:
# decay can't handle all of the same nuclides CRAM can
b1 = {}
for key, val in b1.items():
n = nucname.name(key)
bateman[n][i] = val
# compute CRAM
c1 = n0.cram(DECAY_MATS[t], order=16).to_atom_frac()
for key, val in c1.items():
n = nucname.name(key)
crammed[n][i] = val
# compute e^x of the diagonal of the decay matrix, ie the nuc itself
nuc_idx = cram.NUCS_IDX[nuc]
mat_idx = cram.IJ[nuc_idx, nuc_idx]
diagexp[nuc][i] = exp(-DECAY_MATS[t][mat_idx]).evalf(n=30)
return bateman, crammed, diagexp
def diff_nuclide(a, b, abs=False, include_missing=True):
d = defaultdict(emptytime)
for nuc in a:
if nuc in b or include_missing:
d[nuc] = a[nuc] - b[nuc]
if include_missing:
for nuc in b:
if nuc not in a:
d[nuc] = -b[nuc]
if abs:
for nuc in d:
d[nuc] = np.abs(d[nuc])
return d
def run_nuclides(nucs=None, verbose=True):
batemans = {}
crammeds = {}
diagexps = {}
nucs = cram.NUCS if nucs is None else nucs
for nuc in nucs:
print('Running nuc ' + nuc)
b, c, d = run_nuclide(nuc)
batemans[nuc] = b
crammeds[nuc] = c
diagexps[nuc] = d
return batemans, crammeds, diagexps
if __name__ == '__main__':
print(TIMES)
nuc = 'H3'
b, c, d = run_nuclide('H3')
print('Bateman:')
pprint(b[nuc])
print('Decay Exponentional:')
pprint(d[nuc])
print('CRAM')
pprint(c[nuc])
print('Diff')
pprint(diff_nuclide(d,c)[nuc])