27
27
from armi import runLog
28
28
from armi .nucDirectory import nuclideBases
29
29
from armi .nuclearDataIO .nuclearFileMetadata import NuclideXSMetadata , RegionXSMetadata
30
+ from armi .nuclearDataIO import xsNuclides
30
31
from armi .utils import properties
31
32
32
33
_ISOTXS_EXT = "ISO"
@@ -144,10 +145,22 @@ def getISOTXSLibrariesToMerge(xsLibrarySuffix, xsLibFileNames):
144
145
return isosToMerge
145
146
146
147
147
- def mergeXSLibrariesInWorkingDirectory (lib , xsLibrarySuffix = "" , mergeGammaLibs = False ):
148
+ def mergeXSLibrariesInWorkingDirectory (
149
+ lib ,
150
+ xsLibrarySuffix = "" ,
151
+ mergeGammaLibs = False ,
152
+ alternateDirectory = None ,
153
+ ):
148
154
"""
149
155
Merge neutron (ISOTXS) and gamma (GAMISO/PMATRX) library data into the provided library.
150
156
157
+ Notes
158
+ -----
159
+ Convention is for fuel XS id to come first alphabetically (A, B, C, etc.) and then be
160
+ followed by non-fuel. This should allow `referenceDummyNuclide` to be defined before
161
+ it is needed by a non-fuel cross section, but if the convention is not followed then
162
+ this could cause an issue.
163
+
151
164
Parameters
152
165
----------
153
166
lib : obj
@@ -161,18 +174,25 @@ def mergeXSLibrariesInWorkingDirectory(lib, xsLibrarySuffix="", mergeGammaLibs=F
161
174
mergeGammaLibs : bool, optional
162
175
If True, the GAMISO and PMATRX files that correspond to the ISOTXS library will be merged. Note: if these
163
176
files do not exist this will fail.
177
+
178
+ alternateDirectory : str, optional
179
+ An alternate directory in which to search for files other than the working directory. The main purpose
180
+ of this is for testing, but it could also be useful to users.
164
181
"""
165
182
# pylint: disable=import-outside-toplevel) ; avoid cyclic import with isotxs bringing this in for data structure
166
183
from armi .nuclearDataIO .cccc import isotxs
167
184
from armi .nuclearDataIO .cccc import gamiso
168
185
from armi .nuclearDataIO .cccc import pmatrx
169
186
from armi import nuclearDataIO
170
187
188
+ baseDir = alternateDirectory or os .getcwd ()
189
+ globPath = os .path .join (baseDir , _ISOTXS_EXT + "*" )
171
190
xsLibFiles = getISOTXSLibrariesToMerge (
172
- xsLibrarySuffix , [iso for iso in glob .glob (_ISOTXS_EXT + "*" )]
191
+ xsLibrarySuffix , [iso for iso in glob .glob (globPath )]
173
192
)
174
193
librariesToMerge = []
175
194
neutronVelocities = {} # Dictionary of neutron velocities from each ISOTXS file
195
+ referenceDummyNuclides = None
176
196
for xsLibFilePath in sorted (xsLibFiles ):
177
197
try :
178
198
xsID = re .search ("ISO([A-Z0-9]{2})" , xsLibFilePath ).group (
@@ -197,21 +217,48 @@ def mergeXSLibrariesInWorkingDirectory(lib, xsLibrarySuffix="", mergeGammaLibs=F
197
217
)
198
218
)
199
219
continue
220
+
200
221
neutronLibrary = isotxs .readBinary (xsLibFilePath )
201
222
neutronVelocities [xsID ] = neutronLibrary .neutronVelocity
202
- librariesToMerge .append (neutronLibrary )
223
+
224
+ dummyNuclidesInNeutron = [
225
+ nuc
226
+ for nuc in neutronLibrary .nuclides
227
+ if isinstance (nuc ._base , nuclideBases .DummyNuclideBase )
228
+ ]
229
+ if not dummyNuclidesInNeutron :
230
+ runLog .info (f"Adding dummy nuclides to library { xsID } " )
231
+ addedDummyData = isotxs .addDummyNuclidesToLibrary (
232
+ neutronLibrary , referenceDummyNuclides
233
+ ) # Add DUMMY nuclide data not produced by MC2-3
234
+ isotxsLibraryPath = os .path .join (
235
+ baseDir ,
236
+ nuclearDataIO .getExpectedISOTXSFileName (
237
+ suffix = xsLibrarySuffix , xsID = xsID
238
+ ),
239
+ )
240
+ isotxsDummyPath = isotxsLibraryPath
241
+ isotxs .writeBinary (neutronLibrary , isotxsDummyPath )
242
+ neutronLibraryDummyData = isotxs .readBinary (isotxsDummyPath )
243
+ librariesToMerge .append (neutronLibraryDummyData )
244
+ dummyNuclidesInNeutron = referenceDummyNuclides
245
+ else :
246
+ librariesToMerge .append (neutronLibrary )
247
+ if not referenceDummyNuclides :
248
+ referenceDummyNuclides = dummyNuclidesInNeutron
249
+
203
250
if mergeGammaLibs :
204
- dummyNuclides = [
205
- nuc
206
- for nuc in neutronLibrary .nuclides
207
- if isinstance (nuc ._base , nuclideBases .DummyNuclideBase )
208
- ]
209
-
210
- gamisoLibraryPath = nuclearDataIO .getExpectedGAMISOFileName (
211
- suffix = xsLibrarySuffix , xsID = xsID
251
+ gamisoLibraryPath = os .path .join (
252
+ baseDir ,
253
+ nuclearDataIO .getExpectedGAMISOFileName (
254
+ suffix = xsLibrarySuffix , xsID = xsID
255
+ ),
212
256
)
213
- pmatrxLibraryPath = nuclearDataIO .getExpectedPMATRXFileName (
214
- suffix = xsLibrarySuffix , xsID = xsID
257
+ pmatrxLibraryPath = os .path .join (
258
+ baseDir ,
259
+ nuclearDataIO .getExpectedPMATRXFileName (
260
+ suffix = xsLibrarySuffix , xsID = xsID
261
+ ),
215
262
)
216
263
217
264
# Check if the gamiso and pmatrx data paths exist with the xs library suffix so that
@@ -226,18 +273,20 @@ def mergeXSLibrariesInWorkingDirectory(lib, xsLibrarySuffix="", mergeGammaLibs=F
226
273
f"Attempting to find GAMISO/PMATRX data with "
227
274
f"only XS ID { xsID } instead."
228
275
)
229
- gamisoLibraryPath = nuclearDataIO .getExpectedGAMISOFileName (xsID = xsID )
230
- pmatrxLibraryPath = nuclearDataIO .getExpectedPMATRXFileName (xsID = xsID )
276
+ gamisoLibraryPath = os .path .join (
277
+ baseDir , nuclearDataIO .getExpectedGAMISOFileName (xsID = xsID )
278
+ )
279
+ pmatrxLibraryPath = os .path .join (
280
+ baseDir , nuclearDataIO .getExpectedPMATRXFileName (xsID = xsID )
281
+ )
231
282
232
283
# GAMISO data
233
284
gammaLibrary = gamiso .readBinary (gamisoLibraryPath )
234
285
addedDummyData = gamiso .addDummyNuclidesToLibrary (
235
- gammaLibrary , dummyNuclides
286
+ gammaLibrary , dummyNuclidesInNeutron
236
287
) # Add DUMMY nuclide data not produced by MC2-3
237
288
if addedDummyData :
238
- gamisoDummyPath = os .path .abspath (
239
- os .path .join (os .getcwd (), gamisoLibraryPath )
240
- )
289
+ gamisoDummyPath = gamisoLibraryPath
241
290
gamiso .writeBinary (gammaLibrary , gamisoDummyPath )
242
291
gammaLibraryDummyData = gamiso .readBinary (gamisoDummyPath )
243
292
librariesToMerge .append (gammaLibraryDummyData )
@@ -247,12 +296,10 @@ def mergeXSLibrariesInWorkingDirectory(lib, xsLibrarySuffix="", mergeGammaLibs=F
247
296
# PMATRX data
248
297
pmatrxLibrary = pmatrx .readBinary (pmatrxLibraryPath )
249
298
addedDummyData = pmatrx .addDummyNuclidesToLibrary (
250
- pmatrxLibrary , dummyNuclides
299
+ pmatrxLibrary , dummyNuclidesInNeutron
251
300
) # Add DUMMY nuclide data not produced by MC2-3
252
301
if addedDummyData :
253
- pmatrxDummyPath = os .path .abspath (
254
- os .path .join (os .getcwd (), pmatrxLibraryPath )
255
- )
302
+ pmatrxDummyPath = pmatrxLibraryPath
256
303
pmatrx .writeBinary (pmatrxLibrary , pmatrxDummyPath )
257
304
pmatrxLibraryDummyData = pmatrx .readBinary (pmatrxDummyPath )
258
305
librariesToMerge .append (pmatrxLibraryDummyData )
0 commit comments