@@ -56,44 +56,45 @@ class SensitivityReader(BaseReader):
5656
5757 Parameters
5858 ----------
59- filePath: str
59+ filePath : str
6060 Path to sensitivity file
6161
6262 Attributes
6363 ----------
64- nMat: None or int
64+ nMat : None or int
6565 Number of materials
66- nZai: None or int
66+ nZai : None or int
6767 Number of perturbed isotopes
68- nPert: None or int
68+ nPert : None or int
6969 Number of perturbations
70- nEne: None or int
70+ nEne : None or int
7171 Number of energy groups
72- nMu: None or int
72+ nMu : None or int
7373 Number of perturbed materials
74- materials: :py :class:`~collections.OrderedDict`
74+ materials : :class:`~collections.OrderedDict`
7575 Ordered dictionary of materials that have
7676 been perturbed.
77- zais: :py :class:`~collections.OrderedDict`
77+ zais : :class:`~collections.OrderedDict`
7878 Ordered dictionary of nuclides that
7979 have been perturbed
80- perts: :py :class:`~collections.OrderedDict`
80+ perts : :class:`~collections.OrderedDict`
8181 Ordered dictionary of reactions that
8282 have been perturbed, e.g `'total xs'`
83- latGen: int
83+ latGen : int
8484 Number of latent generations used to generate
8585 these sensitivities
86- energies: None or :py :class:`numpy.array`
86+ energies : None or :class:`numpy.array`
8787 Array of energy bounds for the sensitivities, from
8888 lowest to highest
89- lethargyWidths: None or :py :class:`numpy.array`
89+ lethargyWidths : None or :class:`numpy.array`
9090 Array of lethargy widths of each energy group.
91- sensitivities: dict
91+ sensitivities : dict
9292 Dictionary of names of sensitivities and their corresponding
9393 arrays.
94- energyIntegratedSens: dict
94+ energyIntegratedSens : dict
9595 Dictionary of names of the sensitivities that have been integrated
9696 against energy, and their corresponding arrays
97+
9798 """
9899
99100 _RECONVERT_ATTR_MAP = {
@@ -143,18 +144,18 @@ def _read(self):
143144 if not throughParams :
144145 chunk0 = chunk [0 ]
145146 if 'Number' in chunk0 :
146- self .__processNumChunk (chunk )
147+ self ._processNumChunk (chunk )
147148 elif 'included' in chunk0 :
148149 what = chunk0 .split ()[1 ]
149- self .__processIndexChunk (what , chunk )
150+ self ._processIndexChunk (what , chunk )
150151 elif 'energy' in chunk0 :
151- self .__processEnergyChunk (chunk )
152+ self ._processEnergyChunk (chunk )
152153 elif 'latent' in chunk0 :
153154 split = chunk0 .split ()
154155 self .latGen = int (split [split .index ('latent' ) - 1 ])
155156 throughParams = True
156157 continue
157- self .__processSensChunk (chunk )
158+ self ._processSensChunk (chunk )
158159 if self .zais :
159160 old = self .zais
160161 self .zais = OrderedDict ()
@@ -164,7 +165,7 @@ def _read(self):
164165 continue
165166 self .zais [int (key )] = value
166167
167- def __processNumChunk (self , chunk ):
168+ def _processNumChunk (self , chunk ):
168169 chunk = [line for line in chunk if 'SENS' in line ]
169170 for line in chunk :
170171 split = line .split ()
@@ -176,7 +177,7 @@ def __processNumChunk(self, chunk):
176177 'Attempted to set attribute {} from number block' .format (
177178 attrN ))
178179
179- def __processIndexChunk (self , what , chunk ):
180+ def _processIndexChunk (self , what , chunk ):
180181 key = what .lower ()
181182 if key not in self ._indxMap :
182183 raise SerpentToolsException (
@@ -203,7 +204,7 @@ def __processIndexChunk(self, what, chunk):
203204 raise SerpentToolsException (
204205 "Unexpected index chunk {}" .format (chunk ))
205206
206- def __processEnergyChunk (self , chunk ):
207+ def _processEnergyChunk (self , chunk ):
207208 for line in chunk :
208209 if 'SENS' == line [:4 ]:
209210 break
@@ -221,7 +222,7 @@ def __processEnergyChunk(self, chunk):
221222 warning ("Unanticipated energy setting {}"
222223 .format (splitLine [0 ]))
223224
224- def __processSensChunk (self , chunk ):
225+ def _processSensChunk (self , chunk ):
225226 varName = None
226227 isEnergyIntegrated = False
227228 varName = None
@@ -230,16 +231,44 @@ def __processSensChunk(self, chunk):
230231 continue
231232 if line [:3 ] == 'ADJ' :
232233 fullVarName = line .split ()[0 ]
233- split = fullVarName .split ('_' )
234- pertIndx = split .index ('PERT' )
235- sensIndx = split .index ('SENS' )
236- varName = '_' .join (split [pertIndx + 1 : sensIndx ])
237- isEnergyIntegrated = split [- 2 :] == ['E' , 'INT' ]
234+ nameProps = self ._getAdjVarProps (fullVarName .split ("_" ))
235+ varName = nameProps .get ("name" )
236+
237+ if varName is None :
238+ raise ValueError (
239+ "Cannot get response name from {}" .format (fullVarName ))
240+
241+ isEnergyIntegrated = nameProps .get ("energyFlag" , False )
242+ latentGen = nameProps .get ("latent" )
243+
238244 elif varName is not None :
239- self .__addSens (varName , str2vec (line ), isEnergyIntegrated )
245+ self ._addSens (
246+ varName , str2vec (line ), isEnergyIntegrated , latentGen )
240247 varName = None
241248
242- def __addSens (self , varName , vec , isEnergyIntegrated ):
249+ @staticmethod
250+ def _getAdjVarProps (parts ):
251+ props = {}
252+ nameStart = None
253+
254+ for ix , word in enumerate (parts ):
255+ if word == "PERT" :
256+ nameStart = ix + 1
257+ elif word == "SENS" :
258+ if nameStart is None :
259+ raise ValueError (
260+ "Cannot get response name from {}" .format (parts ))
261+ props ["name" ] = "_" .join (parts [nameStart :ix ])
262+ elif word == "INT" :
263+ props ["energyFlag" ] = (parts [ix - 1 ] == "E" )
264+ elif word == "GEN" :
265+ props ["latent" ] = int (parts [ix - 1 ])
266+
267+ return props
268+
269+ def _addSens (self , varName , vec , isEnergyIntegrated , latentGen ):
270+ if latentGen is not None :
271+ return
243272 dest = (self .energyIntegratedSens if isEnergyIntegrated
244273 else self .sensitivities )
245274 newShape = [2 , self .nPert , self .nZai , self .nMat ]
0 commit comments