-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_aceIO.py
119 lines (93 loc) · 4.17 KB
/
test_aceIO.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from unittest import TestCase
import unittest
import filecmp
import os
import numpy as np
from ASAPy import AceIO
class TestAceEditor(TestCase):
@classmethod
def setUpClass(cls):
cls.ace = AceIO.AceEditor('./test_data/92235.710nc')
def test_write_endf_with_sum_rule(self):
"""
Fake an adjusted xsec which should make mt rules go, write the data and it
should be exactly as the input since nothing actually changed
"""
ace = AceIO.AceEditor('./test_data/92235.710nc')
ace.adjusted_mts.add(102)
ace.apply_sum_rules()
w = AceIO.WriteAce('./test_data/92235.710nc')
base_ace = AceIO.AceEditor('./test_data/92235.710nc')
for mt_adjusted in ace.adjusted_mts:
try:
w.replace_array(base_ace.get_sigma(mt_adjusted), base_ace.get_sigma(mt_adjusted))
except ValueError:
print("MT {0} adjusted but was not present on original ace, perhaps it was redundant".format(mt_adjusted))
w.write_ace("./test_data/test_output_u235_102_no_changes")
if not filecmp.cmp("./test_data/test_output_u235_102_no_changes", './test_data/92235.710nc'):
self.fail("Created ace file not the same as original even though nothing changed.")
else:
os.remove("./test_data/test_output_u235_102_no_changes")
def test_get_nu_distro(self):
[e, v] = self.ace.get_nu_distro()
self.assertAlmostEqual(e[4], 100.0)
self.assertAlmostEqual(v[4], 2.4338)
def test_set_and_get_chi_distro(self):
"""
Checks to make sure chi is actually set by setting it to a known value and checking the getter after.
Does not test the pdf/cdf logic for update of cdf based on pdf
"""
ace = AceIO.AceEditor('./test_data/92235.710nc')
chi = ace.get_chi_distro()
gold_pdf = chi[2]
for idx in range(len(gold_pdf)):
gold_pdf[idx] = np.ones(len(gold_pdf[idx])) * 0
ace.set_chi_distro(gold_pdf)
check_chi = ace.get_chi_distro()
np.testing.assert_almost_equal(gold_pdf, check_chi[2])
def test_set_and_get_nu_distro(self):
"""
Checks to make sure nu is actually set by setting it to a known value and checking the getter after
"""
ace = AceIO.AceEditor('./test_data/92235.710nc')
gold_sigma = ace.get_sigma(452) / 2
ace.set_sigma(452, gold_sigma)
check_sigma = ace.get_sigma(452)
np.testing.assert_almost_equal(gold_sigma, check_sigma)
def test_get_sigma(self):
v = self.ace.get_sigma(2)
self.assertAlmostEqual(v[99], 18.65279)
def test_set_sigma_wrong_len(self):
self.assertRaises(IndexError, self.ace.set_sigma, *[2, [5, 10]])
def test_set_sigma_(self):
self.ace.set_sigma(2, self.ace.get_sigma(2)*2)
v = self.ace.get_sigma(2)
self.assertAlmostEqual(v[99], 18.65279*2)
self.assertEqual(self.ace.adjusted_mts, {2})
def test_non_existant_sigma(self):
self.assertRaises(KeyError, self.ace.get_sigma, -1)
def test_set_sum(self):
#TODO need to find a good test for this
pass
#self.ace.set_sigma(102, self.ace.get_sigma(2)*2)
#self.ace.apply_sum_rules()
def test_get_nu(self):
fission_chi_prompt_energy, fission_chi_prompt_energy_out, fission_chi_prompt_energy_p, fission_chi_prompt_energy_c = self.ace.get_chi_distro()
self.assertAlmostEqual(fission_chi_prompt_energy_p[4][25], 3.368962e-09)
def test__check_if_mts_present(self):
"""
Make sure all MTs are found correctly
"""
should_be_in_mts = [2, 18, 102]
mts_found = self.ace._check_if_mts_present(should_be_in_mts)
self.assertEqual(mts_found, should_be_in_mts)
def test__check_if_some_mts_present(self):
"""
Make sure if some MT in the list of MTs is not there, it is removed
"""
should_be_in_mts = [2, 18, 102]
should_not_be_in_mts = [1000]
mts_found = self.ace._check_if_mts_present(should_be_in_mts + should_not_be_in_mts)
self.assertEqual(mts_found, should_be_in_mts)
if __name__ == '__main__':
unittest.main()