Skip to content

Commit c65e507

Browse files
committed
change version to be an attribute
1 parent 29d8810 commit c65e507

3 files changed

Lines changed: 83 additions & 77 deletions

File tree

scripts/WMP.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import numpy as np
77

88
# Version of WMP nuclear data format
9-
WMP_VERSION = 'v1.0'
9+
WMP_VERSION_MAJOR = 1
10+
WMP_VERSION_MINOR = 1
11+
WMP_VERSION = (WMP_VERSION_MAJOR, WMP_VERSION_MINOR)
1012

1113
# The value of the Boltzman constant in units of eV / K
1214
K_BOLTZMANN = 8.6173303e-5
@@ -401,14 +403,21 @@ def from_hdf5(cls, group_or_filename):
401403
group = group_or_filename
402404
else:
403405
h5file = h5py.File(group_or_filename, 'r')
404-
try:
405-
version = h5file['version'].value.decode()
406-
except AttributeError:
407-
version = h5file['version'].value[0].decode()
408-
if version != WMP_VERSION:
409-
raise ValueError('The given WMP data uses version '
410-
+ version + ' whereas your installation of the OpenMC '
411-
'Python API expects version ' + WMP_VERSION)
406+
407+
# Make sure version matches
408+
if 'version' in h5file.attrs:
409+
major, minor = h5file.attrs['version']
410+
if major != WMP_VERSION_MAJOR:
411+
raise IOError(
412+
'WMP data format uses version {}. {} whereas your '
413+
'installation of the OpenMC Python API expects version '
414+
'{}.x.'.format(major, minor, WMP_VERSION_MAJOR))
415+
else:
416+
raise IOError(
417+
'WMP data does not indicate a version. Your installation of '
418+
'the OpenMC Python API expects version {}.x data.'
419+
.format(WMP_VERSION_MAJOR))
420+
412421
group = list(h5file.values())[0]
413422

414423
name = group.name[1:]
@@ -577,8 +586,7 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'):
577586
# Open file and write version.
578587
with h5py.File(path, mode, libver=libver) as f:
579588
f.attrs['filetype'] = np.string_('data_wmp')
580-
f.create_dataset('version', (1, ), dtype='S10')
581-
f['version'][:] = WMP_VERSION.encode('ASCII')
589+
f.attrs['version'] = np.array(WMP_VERSION)
582590

583591
g = f.create_group(self.name)
584592

scripts/validation.py

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,17 @@
7272
f = open(logfile, 'w');
7373

7474
# write info
75-
f.write("Energy range: {} {}".format(nuc_wmp.E_min, nuc_wmp.E_max))
76-
f.write("\n")
77-
f.write("Number of windows: {}".format(nuc_wmp.windows.shape[0]))
78-
f.write("\n")
79-
f.write("Fissionable: {}".format(nuc_wmp.fissionable))
80-
f.write("\n")
75+
f.write("WMP file: {}\n".format(wmp_library))
76+
f.write("Nuclide: {}\n".format(nuc_name))
77+
f.write("Energy range: [{}, {}] eV\n".format(nuc_wmp.E_min, nuc_wmp.E_max))
78+
f.write("Number of windows: {}\n".format(nuc_wmp.windows.shape[0]))
79+
f.write("Fissionable: {}\n".format(nuc_wmp.fissionable))
8180

8281
# load ace data
8382
nuc_ace = openmc.data.IncidentNeutron.from_hdf5(ace_file)
8483
assert strTemp in nuc_ace.temperatures, "ace file does not contain T={}".format(strTemp)
8584

86-
f.write("Load ace file: {}".format(ace_file))
87-
f.write("\n")
85+
f.write("Load ace file: {}\n".format(ace_file))
8886

8987
# energy grid for comparison
9088
max_e = nuc_wmp.E_max
@@ -93,10 +91,8 @@
9391
energy = np.logspace(np.log10(min_e), np.log10(max_e), N_points)
9492
energy[0] = min_e
9593
energy[-1] = max_e
96-
f.write("Test energy range: {} {} eV".format(energy[0], energy[-1]))
97-
f.write("\n")
98-
f.write("Test temperature: {} K".format(temp))
99-
f.write("\n")
94+
f.write("Test energy range: [{}, {}] eV\n".format(energy[0], energy[-1]))
95+
f.write("Test temperature: {} K\n".format(temp))
10096

10197
# reactions for comparison
10298
mts = [1, 2, 27, 18]
@@ -131,16 +127,11 @@
131127
max_error_energy = energy[max_error_idx]
132128
max_error_wmpxs = rxn_wmp[max_error_idx]
133129
max_error_acexs = rxn_ace[max_error_idx]
134-
f.write("{} Max abs error: ".format(rxn))
135-
f.write("\n")
136-
f.write(" energy: {}".format(max_error_energy))
137-
f.write("\n")
138-
f.write(" WMP xs: {}".format(max_error_wmpxs))
139-
f.write("\n")
140-
f.write(" ACE xs: {}".format(max_error_acexs))
141-
f.write("\n")
142-
f.write(" error : {}".format(max_error))
143-
f.write("\n")
130+
f.write("{} - max abs error:\n".format(rxn))
131+
f.write(" energy: {}\n".format(max_error_energy))
132+
f.write(" WMP xs: {}\n".format(max_error_wmpxs))
133+
f.write(" ACE xs: {}\n".format(max_error_acexs))
134+
f.write(" error : {}\n".format(max_error))
144135

145136
# max rel. error
146137
relerr = abs(rxn_wmp/rxn_ace - 1)
@@ -152,16 +143,11 @@
152143
max_error_energy = energy[max_error_idx]
153144
max_error_wmpxs = rxn_wmp[max_error_idx]
154145
max_error_acexs = rxn_ace[max_error_idx]
155-
f.write("{} Max rel error: ".format(rxn))
156-
f.write("\n")
157-
f.write(" energy: {}".format(max_error_energy))
158-
f.write("\n")
159-
f.write(" WMP xs: {}".format(max_error_wmpxs))
160-
f.write("\n")
161-
f.write(" ACE xs: {}".format(max_error_acexs))
162-
f.write("\n")
163-
f.write(" error : {:.2f}%".format(max_error*100))
164-
f.write("\n")
146+
f.write("{} - max rel error:\n".format(rxn))
147+
f.write(" energy: {}\n".format(max_error_energy))
148+
f.write(" WMP xs: {}\n".format(max_error_wmpxs))
149+
f.write(" ACE xs: {}\n".format(max_error_acexs))
150+
f.write(" error : {:.2f}%\n".format(max_error*100))
165151

166152
# plot
167153
plt.clf()

wmp_format.md

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,71 @@
11
# Windowed Multipole Library Format
22

3-
**/version** (*char[]*)
3+
The current version of the statepoint file format is 1.1.
44

5-
The format version of the file. The current version is "v1.0"
5+
+ **/**
66

7-
**/nuclide/**
7+
- *Attributes* :
88

9-
- **broaden_poly** (*int[]*)
9+
- **filetype** (*char[]*)
1010

11-
If 1, Doppler broaden curve fit for window with corresponding index.
12-
If 0, do not.
11+
String indicating the type of file.
1312

14-
- **curvefit** (*double[][][]*)
13+
- **version** (*int[2]*)
1514

16-
Curve fit coefficients. Indexed by (reaction type, coefficient index,
17-
window index).
15+
Major and minor version of the data.
1816

19-
- **data** (*complex[][]*)
17+
+ **/\<nuclide name\>/**
2018

21-
Complex poles and residues. Each pole has a corresponding set of
22-
residues. For example, the i-th pole and corresponding residues
23-
are stored as
19+
- *Datasets* :
2420

25-
![data](https://latex.codecogs.com/gif.latex?\text{data}[:,i]&space;=&space;[\text{pole}_i,&space;~\text{residue}_{i1},&space;~\text{residue}_{i2},&space;~\text{residue}_{i3}])
21+
- **broaden_poly** (*int[]*)
2622

27-
The residues are in the order: scattering, absorption, fission. Complex
28-
numbers are stored by forming a type with "r" and "i" identifiers,
29-
similar to how [h5py] does it.
23+
If 1, Doppler broaden curve fit for window with corresponding index.
24+
If 0, do not.
3025

31-
- **E_max** (*double*)
26+
- **curvefit** (*double[][][]*)
3227

33-
Highest energy the windowed multipole part of the library is valid for.
28+
Curve fit coefficients. Indexed by (reaction type, coefficient index,
29+
window index).
3430

35-
- **E_min** (*double*)
31+
- **data** (*complex[][]*)
3632

37-
Lowest energy the windowed multipole part of the library is valid for.
33+
Complex poles and residues. Each pole has a corresponding set of
34+
residues. For example, the i-th pole and corresponding residues
35+
are stored as
3836

39-
- **spacing** (*double*)
37+
![data](https://latex.codecogs.com/gif.latex?\text{data}[:,i]&space;=&space;[\text{pole}_i,&space;~\text{residue}_{i1},&space;~\text{residue}_{i2},&space;~\text{residue}_{i3}])
4038

41-
![spacing](https://latex.codecogs.com/gif.latex?\frac{\sqrt{E_{max}}-&space;\sqrt{E_{min}}}{n_w})
39+
The residues are in the order: scattering, absorption, fission. Complex
40+
numbers are stored by forming a type with "r" and "i" identifiers,
41+
similar to how [h5py] does it.
4242

43-
Where ![data](https://latex.codecogs.com/gif.latex?E_{max}) is the
44-
maximum energy the windows go up to.
45-
![data](https://latex.codecogs.com/gif.latex?E_{min}) is the minimum
46-
energy and equivalent to ``E_min``, and ![data](https://latex.codecogs.com/gif.latex?n_w)
47-
is the number of windows, given by ``windows``.
43+
- **E_max** (*double*)
4844

49-
- **sqrtAWR** (*double*)
45+
Highest energy the windowed multipole part of the library is valid for.
5046

51-
Square root of the atomic weight ratio.
47+
- **E_min** (*double*)
5248

53-
- **windows** (*int[][]*)
49+
Lowest energy the windowed multipole part of the library is valid for.
5450

55-
The poles to start from and end at for each window. windows[i, 0] and
56-
windows[i, 1] are, respectively, the indexes (1-based) of the first and last
57-
pole in window i.
51+
- **spacing** (*double*)
52+
53+
![spacing](https://latex.codecogs.com/gif.latex?\frac{\sqrt{E_{max}}-&space;\sqrt{E_{min}}}{n_w})
54+
55+
Where ![data](https://latex.codecogs.com/gif.latex?E_{max}) is the
56+
maximum energy the windows go up to.
57+
![data](https://latex.codecogs.com/gif.latex?E_{min}) is the minimum
58+
energy and equivalent to ``E_min``, and ![data](https://latex.codecogs.com/gif.latex?n_w)
59+
is the number of windows, given by ``windows``.
60+
61+
- **sqrtAWR** (*double*)
62+
63+
Square root of the atomic weight ratio.
64+
65+
- **windows** (*int[][]*)
66+
67+
The poles to start from and end at for each window. windows[i, 0] and
68+
windows[i, 1] are, respectively, the indexes (1-based) of the first and last
69+
pole in window i.
5870

5971
[h5py]: http://docs.h5py.org/en/latest/

0 commit comments

Comments
 (0)