/
test_globalFluxInterface.py
323 lines (253 loc) · 10.7 KB
/
test_globalFluxInterface.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Copyright 2019 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for generic global flux interface"""
# pylint: disable=missing-function-docstring,missing-class-docstring,protected-access,invalid-name,no-self-use,no-method-argument,import-outside-toplevel
import unittest
import numpy
from armi import settings
from armi.nuclearDataIO.cccc import isotxs
from armi.physics.neutronics.globalFlux import globalFluxInterface
from armi.reactor import geometry
from armi.reactor.blocks import HexBlock
from armi.reactor.flags import Flags
from armi.reactor.tests import test_blocks
from armi.reactor.tests import test_reactors
from armi.tests import ISOAA_PATH
# pylint: disable=abstract-method
class MockReactorParams:
def __init__(self):
self.cycle = 1
self.timeNode = 2
class MockCoreParams:
pass
class MockCore:
def __init__(self):
# just pick a random geomType
self.geomType = geometry.GeomType.CARTESIAN
self.symmetry = "full"
self.p = MockCoreParams()
class MockReactor:
def __init__(self):
self.core = MockCore()
self.o = None
self.p = MockReactorParams()
class MockGlobalFluxInterface(globalFluxInterface.GlobalFluxInterface):
"""
Add fake keff calc to a the general gf interface.
This simulates a 1000 pcm keff increase over 1 step.
"""
def interactBOC(self, cycle=None):
globalFluxInterface.GlobalFluxInterface.interactBOC(self, cycle=cycle)
self.r.core.p.keff = 1.00
def interactEveryNode(self, cycle, node):
globalFluxInterface.GlobalFluxInterface.interactEveryNode(self, cycle, node)
self.r.core.p.keff = 1.01
class MockGlobalFluxWithExecuters(
globalFluxInterface.GlobalFluxInterfaceUsingExecuters
):
def getExecuterCls(self):
return MockGlobalFluxExecuter
class MockGlobalFluxWithExecutersNonUniform(MockGlobalFluxWithExecuters):
def getExecuterOptions(self, label=None):
"""
Return modified executerOptions
"""
opts = globalFluxInterface.GlobalFluxInterfaceUsingExecuters.getExecuterOptions(
self, label=label
)
opts.hasNonUniformAssems = True # to increase test coverage
return opts
class MockGlobalFluxExecuter(globalFluxInterface.GlobalFluxExecuter):
"""Tests for code that uses Executers, which rely on OutputReaders to update state."""
def _readOutput(self):
class MockOutputReader:
def apply(self, r): # pylint: disable=no-self-use
r.core.p.keff += 0.01
def getKeff(self):
return 1.05
return MockOutputReader()
class TestGlobalFluxOptions(unittest.TestCase):
def test_readFromSettings(self):
cs = settings.Settings()
opts = globalFluxInterface.GlobalFluxOptions("neutronics-run")
opts.fromUserSettings(cs)
self.assertFalse(opts.adjoint)
def test_readFromReactors(self):
reactor = MockReactor()
opts = globalFluxInterface.GlobalFluxOptions("neutronics-run")
opts.fromReactor(reactor)
self.assertEqual(opts.geomType, geometry.GeomType.CARTESIAN)
self.assertFalse(opts.savePhysicsFiles)
def test_savePhysicsFiles(self):
reactor = MockReactor()
opts = globalFluxInterface.GlobalFluxOptions("neutronics-run")
# savePhysicsFilesList matches MockReactor parameters
opts.savePhysicsFilesList = ["001002"]
opts.fromReactor(reactor)
self.assertTrue(opts.savePhysicsFiles)
# savePhysicsFilesList does not match MockReactor parameters
opts.savePhysicsFilesList = ["001000"]
opts.fromReactor(reactor)
self.assertFalse(opts.savePhysicsFiles)
class TestGlobalFluxInterface(unittest.TestCase):
def test_interaction(self):
"""
Ensure the basic interaction hooks work
Check that a 1000 pcm rx swing is observed due to the mock.
"""
cs = settings.Settings()
_o, r = test_reactors.loadTestReactor()
gfi = MockGlobalFluxInterface(r, cs)
gfi.interactBOC()
gfi.interactEveryNode(0, 0)
gfi.interactEOC()
self.assertAlmostEqual(r.core.p.rxSwing, 1000)
def test_getIOFileNames(self):
cs = settings.Settings()
gfi = MockGlobalFluxInterface(MockReactor(), cs)
inf, _outf, _stdname = gfi.getIOFileNames(1, 2, 1)
self.assertEqual(inf, "armi001_2_001.GlobalFlux.inp")
def test_getHistoryParams(self):
params = globalFluxInterface.GlobalFluxInterface.getHistoryParams()
self.assertEqual(len(params), 3)
self.assertIn("detailedDpa", params)
def test_checkEnergyBalance(self):
cs = settings.Settings()
_o, r = test_reactors.loadTestReactor()
gfi = MockGlobalFluxInterface(r, cs)
gfi._checkEnergyBalance()
class TestGlobalFluxInterfaceWithExecuters(unittest.TestCase):
"""Tests for the default global flux execution."""
@classmethod
def setUpClass(cls):
cs = settings.Settings()
_o, cls.r = test_reactors.loadTestReactor()
cls.r.core.p.keff = 1.0
cls.gfi = MockGlobalFluxWithExecuters(cls.r, cs)
def test_executerInteraction(self):
gfi, r = self.gfi, self.r
gfi.interactBOC()
gfi.interactEveryNode(0, 0)
r.p.timeNode += 1
gfi.interactEveryNode(0, 1)
gfi.interactEOC()
self.assertAlmostEqual(r.core.p.rxSwing, (1.02 - 1.01) / 1.01 * 1e5)
def test_calculateKeff(self):
self.assertEqual(self.gfi.calculateKeff(), 1.05) # set in mock
def test_getExecuterCls(self):
class0 = globalFluxInterface.GlobalFluxInterfaceUsingExecuters.getExecuterCls()
self.assertEqual(class0, globalFluxInterface.GlobalFluxExecuter)
class TestGlobalFluxInterfaceWithExecutersNonUniform(unittest.TestCase):
"""Tests for global flux execution with non-uniform assemblies."""
@classmethod
def setUpClass(cls):
cs = settings.Settings()
_o, cls.r = test_reactors.loadTestReactor()
cls.r.core.p.keff = 1.0
cls.gfi = MockGlobalFluxWithExecutersNonUniform(cls.r, cs)
def test_executerInteractionNonUniformAssems(self):
gfi, r = self.gfi, self.r
gfi.interactBOC()
gfi.interactEveryNode(0, 0)
r.p.timeNode += 1
gfi.interactEveryNode(0, 1)
gfi.interactEOC()
self.assertAlmostEqual(r.core.p.rxSwing, (1.02 - 1.01) / 1.01 * 1e5)
def test_calculateKeff(self):
self.assertEqual(self.gfi.calculateKeff(), 1.05) # set in mock
def test_getExecuterCls(self):
class0 = globalFluxInterface.GlobalFluxInterfaceUsingExecuters.getExecuterCls()
self.assertEqual(class0, globalFluxInterface.GlobalFluxExecuter)
class TestGlobalFluxResultMapper(unittest.TestCase):
"""
Test that global flux result mappings run.
Notes
-----
This does not test that the flux mapping is correct. That has to be done
at another level.
"""
def test_mapper(self):
# Switch to MC2v2 setting to make sure the isotopic/elemental expansions are compatible
# with actually doing some math using the ISOAA test microscopic library
o, r = test_reactors.loadTestReactor(customSettings={"xsKernel": "MC2v2"})
applyDummyFlux(r)
r.core.lib = isotxs.readBinary(ISOAA_PATH)
mapper = globalFluxInterface.GlobalFluxResultMapper()
mapper.r = r
mapper._renormalizeNeutronFluxByBlock(100)
self.assertAlmostEqual(r.core.calcTotalParam("power", generationNum=2), 100)
mapper._updateDerivedParams()
self.assertGreater(r.core.p.maxPD, 0.0)
self.assertGreater(r.core.p.maxFlux, 0.0)
mapper.updateDpaRate()
block = r.core.getFirstBlock()
self.assertGreater(block.p.detailedDpaRate, 0)
self.assertEqual(block.p.detailedDpa, 0)
# Test DoseResultsMapper. Pass in full list of blocks to apply() in order
# to exercise blockList option (does not change behavior, since this is what
# apply() does anyway)
opts = globalFluxInterface.GlobalFluxOptions("test")
opts.fromUserSettings(o.cs)
dosemapper = globalFluxInterface.DoseResultsMapper(1000, opts)
dosemapper.apply(r, blockList=r.core.getBlocks())
self.assertGreater(block.p.detailedDpa, 0)
mapper.clearFlux()
self.assertEqual(len(block.p.mgFlux), 0)
def test_getDpaXs(self):
mapper = globalFluxInterface.GlobalFluxResultMapper()
# test fuel block
b = HexBlock("fuel", height=10.0)
vals = mapper.getDpaXs(b)
self.assertEqual(len(vals), 33)
self.assertAlmostEqual(vals[0], 2345.69, 1)
# build a grid plate block
b = HexBlock("grid_plate", height=10.0)
b.p.flags = Flags.GRID_PLATE
self.assertTrue(b.hasFlags(Flags.GRID_PLATE))
# test grid plate block
mapper.cs["gridPlateDpaXsSet"] = "dpa_EBRII_PE16"
vals = mapper.getDpaXs(b)
self.assertEqual(len(vals), 33)
self.assertAlmostEqual(vals[0], 2478.95, 1)
# test null case
mapper.cs["gridPlateDpaXsSet"] = "fake"
with self.assertRaises(KeyError):
mapper.getDpaXs(b)
def test_getBurnupPeakingFactor(self):
mapper = globalFluxInterface.GlobalFluxResultMapper()
# test fuel block
mapper.cs["burnupPeakingFactor"] = 0.0
b = HexBlock("fuel", height=10.0)
b.p.flux = 100.0
b.p.fluxPeak = 250.0
factor = mapper.getBurnupPeakingFactor(b)
self.assertEqual(factor, 2.5)
class TestGlobalFluxUtils(unittest.TestCase):
def test_calcReactionRates(self):
"""
Test that the reaction rate code executes and sets a param > 0.0.
.. warning: This does not validate the reaction rate calculation.
"""
b = test_blocks.loadTestBlock()
test_blocks.applyDummyData(b)
self.assertAlmostEqual(b.p.rateAbs, 0.0)
globalFluxInterface.calcReactionRates(b, 1.01, b.r.core.lib)
self.assertGreater(b.p.rateAbs, 0.0)
def applyDummyFlux(r, ng=33):
"""Set arbitrary flux distribution on reactor."""
for b in r.core.getBlocks():
b.p.power = 1.0
b.p.mgFlux = numpy.arange(ng, dtype=numpy.float64)
if __name__ == "__main__":
unittest.main()