From 25edd2fe1137e6b607e4dd98d38335bd63990adf Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 13 Apr 2016 16:05:36 -0500 Subject: [PATCH] Add coinsolver support to input files and regression tests * some more comments to help with enrichment debugging * break out second reactor transaction tests * adding all sqlite to gitigore * slightly better error message in test regression * dynamic capacitated works with default preference == 1 * growth.xml now works with coin * sources file updated to use positive preference values * physor enr now works * increment i after stmt * update recycle to use coin, remove mps calls * adding greedy versions for files that were using coin as a solver * added test cases explicitly for cbc and greedy --- .gitignore | 1 + input/greedy_recycle.xml | 215 ++++++++++++++++++ input/physor/1_Enrichment_2_Reactor.xml | 2 +- input/physor/2_Sources_3_Reactors.xml | 2 +- .../physor/greedy_1_Enrichment_2_Reactor.xml | 138 +++++++++++ input/physor/greedy_2_Sources_3_Reactors.xml | 198 ++++++++++++++++ input/recycle.xml | 2 +- src/enrichment.cc | 6 + tests/input/dynamic_capacitated.xml | 2 +- tests/input/growth.xml | 2 +- tests/test_regression.py | 60 +++-- 11 files changed, 609 insertions(+), 19 deletions(-) create mode 100644 input/greedy_recycle.xml create mode 100644 input/physor/greedy_1_Enrichment_2_Reactor.xml create mode 100644 input/physor/greedy_2_Sources_3_Reactors.xml diff --git a/.gitignore b/.gitignore index 7c9abaa258..12d20994d1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ rs.cred tests/run_inputs.py cyclus.sqlite cycamore_version.h +*.sqlite diff --git a/input/greedy_recycle.xml b/input/greedy_recycle.xml new file mode 100644 index 0000000000..cadd8ea3f1 --- /dev/null +++ b/input/greedy_recycle.xml @@ -0,0 +1,215 @@ + + + 600 + 1 + 2000 + + + + + agents NullInst + agents NullRegion + cycamore Source + cycamore Sink + cycamore Enrichment + cycamore Reactor + cycamore FuelFab + cycamore Separations + + + + enrichment + + + natl_u + natl_u + uox + 0.003 + waste + 1e100 + 1e100 + + + + + + separations + + + + + sep_stream + + 1e100 + + Pu .99 + + + + + + waste + 30001 + 30001 + spent_uox + 2.0 + + + + + + fuelfab + + + depleted_u + depleted_u + 30001 + + sep_stream + 15000 + + thermal + mox + 30001 + + + + + + reactor + + + fresh_uox fresh_mox + spent_uox spent_mox + uox mox + spent_uox waste + 1.0 2.0 + + 17 + 2 + 30000 + 3 + 1 + + + + + + repo + + + waste + 1e100 + + + + + + depleted_src + + + depleted_u + depleted_u + + + + + + SingleRegion + + + SingleInstitution + + + repo + 1 + + + reactor + 1 + + + depleted_src + 1 + + + fuelfab + 1 + + + separations + 1 + + + enrichment + 1 + + + + + + + + natl_u + mass + U235 0.711 + U238 99.289 + + + + fresh_uox + mass + U2350.04 + U2380.96 + + + + depleted_u + mass + U2350.003 + U2380.997 + + + + fresh_mox + mass + U235 0.0027381 + U238 0.9099619 + Pu238 0.001746 + Pu239 0.045396 + Pu240 0.020952 + Pu241 0.013095 + Pu242 0.005238 + + + + spent_mox + mass + U235 0.0017381 + U238 0.90 + Pu238 0.001746 + Pu239 0.0134 + Pu240 0.020952 + Pu241 0.013095 + Pu242 0.005238 + + + + spent_uox + mass + U235 156.729 + U236 102.103 + U238 18280.324 + Np237 13.656 + Pu238 5.043 + Pu239 106.343 + Pu240 41.357 + Pu241 36.477 + Pu242 15.387 + Am241 1.234 + Am243 3.607 + Cm244 0.431 + Cm245 1.263 + + + diff --git a/input/physor/1_Enrichment_2_Reactor.xml b/input/physor/1_Enrichment_2_Reactor.xml index 371b9b057e..96ba12fa8d 100755 --- a/input/physor/1_Enrichment_2_Reactor.xml +++ b/input/physor/1_Enrichment_2_Reactor.xml @@ -5,7 +5,7 @@ 4 1 2000 - + 1001 cycamore Enrichment diff --git a/input/physor/2_Sources_3_Reactors.xml b/input/physor/2_Sources_3_Reactors.xml index e9a45b6810..439de80d53 100755 --- a/input/physor/2_Sources_3_Reactors.xml +++ b/input/physor/2_Sources_3_Reactors.xml @@ -5,7 +5,7 @@ 5 1 2000 - + 1001 cycamore Source diff --git a/input/physor/greedy_1_Enrichment_2_Reactor.xml b/input/physor/greedy_1_Enrichment_2_Reactor.xml new file mode 100644 index 0000000000..d8a295eea3 --- /dev/null +++ b/input/physor/greedy_1_Enrichment_2_Reactor.xml @@ -0,0 +1,138 @@ + + + + + 4 + 1 + 2000 + + + + + cycamore Enrichment + cycamore Reactor + agents NullRegion + agents NullInst + + + + Enrichment + + + natl_u + natl_u + enriched_u + ef_tails + 10.01 + 1e5 + + + + + + Reactor1 + + + lwr_fuel_recipe + lwr_used_fuel_recipe + enriched_u + waste + 1.0 + + 1 + 0 + 0.1 + 10 + 10 + + 1 2 + enriched_u enriched_u + lwr_fuel_recipe2 lwr_fuel_recipe + lwr_used_fuel_recipe lwr_used_fuel_recipe + + + + + + Reactor2 + + + lwr_fuel_recipe + lwr_used_fuel_recipe + enriched_u + waste + 0.5 + + 1 + 0 + 0.1 + 10 + 10 + + + + + + SingleRegion + + + SingleInstitution + + + Enrichment + 1 + + + Reactor1 + 1 + + + Reactor2 + 1 + + + + + + + + natl_u + mass + 922350000 0.711 + 922380000 99.289 + + + + lwr_fuel_recipe + mass + 922350000 3.0 + 922380000 97.0 + + + + lwr_fuel_recipe2 + mass + 922350000 5.0 + 922380000 95.0 + + + + lwr_used_fuel_recipe + mass + 922350000 156.729 + 922360000 102.103 + 922380000 18280.324 + 932370000 13.656 + 942380000 5.043 + 942390000 106.343 + 942400000 41.357 + 942410000 36.477 + 942420000 15.387 + 952410000 1.234 + + 952430000 3.607 + 962440000 0.431 + 962450000 1.263 + + + diff --git a/input/physor/greedy_2_Sources_3_Reactors.xml b/input/physor/greedy_2_Sources_3_Reactors.xml new file mode 100644 index 0000000000..a7cd443d36 --- /dev/null +++ b/input/physor/greedy_2_Sources_3_Reactors.xml @@ -0,0 +1,198 @@ + + + + + 5 + 1 + 2000 + + + + + cycamore Source + cycamore Reactor + agents NullRegion + cycamore DeployInst + + + + UOX_Source + + + uox + uox_fuel_recipe + 2.500000001 + + + + + + MOX_Source + + + mox + mox_fuel_recipe + 2.500000001 + + + + + + Reactor1 + + + + uox_fuel_recipe mox_fuel_recipe + uox_used_fuel_recipe mox_used_fuel_recipe + uox mox + waste waste + 0.1 1.0 + + 1 + 0 + 0.1 + 10 + 10 + + 4 + uox + 2.0 + + + + + + + Reactor2 + + + uox_fuel_recipe mox_fuel_recipe + uox_used_fuel_recipe mox_used_fuel_recipe + uox mox + waste waste + 0.1 1.0 + + 1 + 0 + 0.1 + 10 + 10 + + + + + + Reactor3 + + + uox_fuel_recipe mox_fuel_recipe + uox_used_fuel_recipe mox_used_fuel_recipe + uox mox + waste waste + 0.1 0.5 + + 1 + 0 + 0.1 + 10 + 10 + + + + + + SingleRegion + + + + + SingleInstitution + + + + UOX_Source + MOX_Source + Reactor1 + Reactor2 + Reactor3 + + + + 1 + 1 + 1 + 2 + 3 + + + + 1 + 1 + 1 + 1 + 1 + + + + + + + + natl_u + mass + 922350000 0.711 + 922380000 99.289 + + + + uox_fuel_recipe + mass + 922350000 4.0 + 922380000 96.0 + + + + uox_used_fuel_recipe + mass + 922350000 156.729 + 922360000 102.103 + 922380000 18280.324 + 932370000 13.656 + 942380000 5.043 + 942390000 106.343 + 942400000 41.357 + 942410000 36.477 + 942420000 15.387 + 952410000 1.234 + + 952430000 3.607 + 962440000 0.431 + 962450000 1.263 + + + + mox_fuel_recipe + mass + 922340000 0.0002 + 922350000 0.0018 + 922360000 0.01 + 9223800000.8973 + 942380000 0.0032 + 942390000 0.0507 + 942400000 0.0247 + 942410000 0.0134 + 942420000 0.0085 + 080160000 0.13 + + + + mox_used_fuel_recipe + mass + 922350000 0.01 + 922380000 0.94 + 922360000 0.03 + 080160000 0.13 + 942390000 0.02 + + + diff --git a/input/recycle.xml b/input/recycle.xml index 5917ef6d31..70c426c3b7 100644 --- a/input/recycle.xml +++ b/input/recycle.xml @@ -3,7 +3,7 @@ 600 1 2000 - + 1001 agents NullInst diff --git a/src/enrichment.cc b/src/enrichment.cc index ae69c9804c..c9d7205a2b 100644 --- a/src/enrichment.cc +++ b/src/enrichment.cc @@ -64,7 +64,13 @@ void Enrichment::Tick() { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Enrichment::Tock() { using cyclus::toolkit::RecordTimeSeries; + LOG(cyclus::LEV_INFO4, "EnrFac") << prototype() + << " used " << intra_timestep_swu_ + << " SWU"; RecordTimeSeries(this, intra_timestep_swu_); + LOG(cyclus::LEV_INFO4, "EnrFac") << prototype() + << " used " << intra_timestep_feed_ + << " feed"; RecordTimeSeries(this, intra_timestep_feed_); } diff --git a/tests/input/dynamic_capacitated.xml b/tests/input/dynamic_capacitated.xml index ccc69f1747..a9ff264902 100644 --- a/tests/input/dynamic_capacitated.xml +++ b/tests/input/dynamic_capacitated.xml @@ -5,7 +5,7 @@ 4 1 2000 - + 1001 cycamoreSink diff --git a/tests/input/growth.xml b/tests/input/growth.xml index 7bc3fd874b..63034f02c3 100644 --- a/tests/input/growth.xml +++ b/tests/input/growth.xml @@ -5,7 +5,7 @@ 4 1 2000 - + 1001 diff --git a/tests/test_regression.py b/tests/test_regression.py index 9c70bff2cc..1b4e24677e 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -97,17 +97,16 @@ def tearDown(self): print("removing {0}".format(self.outf)) os.remove(self.outf) -class TestPhysorEnrichment(TestRegression): +class _PhysorEnrichment(TestRegression): """This class tests the 1_Enrichment_2_Reactor.xml file related to the Cyclus Physor 2014 publication. The number of key facilities, the enrichment values, and the transactions to each reactor are tested. """ def __init__(self, *args, **kwargs): - super(TestPhysorEnrichment, self).__init__(*args, **kwargs) - self.inf = "../input/physor/1_Enrichment_2_Reactor.xml" + super(_PhysorEnrichment, self).__init__(*args, **kwargs) def setUp(self): - super(TestPhysorEnrichment, self).setUp() + super(_PhysorEnrichment, self).setUp() tbl = self.agent_entry self.rx_id = self.find_ids(":cycamore:Reactor", tbl) self.enr_id = self.find_ids(":cycamore:Enrichment", tbl) @@ -137,7 +136,7 @@ def test_nu(self): self.to_ary(enr, "Time") == t]) for t in range(4)] assert_array_almost_equal(exp, obs, decimal=2) - def test_xactions(self): + def test_xactions1(self): # reactor 1 transactions exp = [1, 1, 1, 1] txs = [0, 0, 0, 0] @@ -148,6 +147,7 @@ def test_xactions(self): msg = "Testing that first reactor gets less than it wants." assert_array_almost_equal(exp, txs, decimal=2, err_msg=msg) + def test_xactions2(self): # reactor 2 transactions exp = [1, 0.8, 0.2, 1] txs = [0, 0, 0, 0] @@ -157,18 +157,27 @@ def test_xactions(self): msg = "Testing that second reactor gets what it wants." assert_array_almost_equal(exp, txs, decimal=2, err_msg=msg) + +class TestCBCPhysorEnrichment(_PhysorEnrichment): + def __init__(self, *args, **kwargs): + super(TestCBCPhysorEnrichment, self).__init__(*args, **kwargs) + self.inf = "../input/physor/1_Enrichment_2_Reactor.xml" + +class TestGreedyPhysorEnrichment(_PhysorEnrichment): + def __init__(self, *args, **kwargs): + super(TestGreedyPhysorEnrichment, self).__init__(*args, **kwargs) + self.inf = "../input/physor/greedy_1_Enrichment_2_Reactor.xml" -class TestPhysorSources(TestRegression): +class _PhysorSources(TestRegression): """This class tests the 2_Sources_3_Reactor.xml file related to the Cyclus Physor 2014 publication. Reactor deployment and transactions between suppliers and reactors are tested. """ def __init__(self, *args, **kwargs): - super(TestPhysorSources, self).__init__(*args, **kwargs) - self.inf = "../input/physor/2_Sources_3_Reactors.xml" + super(_PhysorSources, self).__init__(*args, **kwargs) def setUp(self): - super(TestPhysorSources, self).setUp() + super(_PhysorSources, self).setUp() # identify each reactor and supplier by id tbl = self.agent_entry @@ -231,6 +240,16 @@ def test_rxtr3_xactions(self): txs[tx['Time']] += self.rsrc_qtys[tx['ResourceId']] assert_array_almost_equal(uox_exp, txs) +class TestCBCPhysorSources(_PhysorSources): + def __init__(self, *args, **kwargs): + super(TestCBCPhysorSources, self).__init__(*args, **kwargs) + self.inf = "../input/physor/2_Sources_3_Reactors.xml" + +class TestGreedyPhysorSources(_PhysorSources): + def __init__(self, *args, **kwargs): + super(TestGreedyPhysorSources, self).__init__(*args, **kwargs) + self.inf = "../input/physor/greedy_2_Sources_3_Reactors.xml" + class TestDynamicCapacitated(TestRegression): """Tests dynamic capacity restraints involving changes in the number of source and sink facilities. @@ -383,18 +402,17 @@ def test_deployment(self): for x in source3_id: yield assert_equal, enter_time[np.where(agent_ids == x)], 2 -class TestRecycle(TestRegression): +class _Recycle(TestRegression): """This class tests the input/recycle.xml file. """ def __init__(self, *args, **kwargs): - super(TestRecycle, self).__init__(*args, **kwargs) + super(_Recycle, self).__init__(*args, **kwargs) # this test requires separations which isn't supported by hdf5 # so we force sqlite: base, _ = os.path.splitext(self.outf) self.ext = '.sqlite' self.outf = base + self.ext - self.inf = "../input/recycle.xml" self.sql = """ SELECT t.time as time,SUM(c.massfrac*r.quantity) as qty FROM transactions as t JOIN resources as r ON t.resourceid=r.resourceid AND r.simid=t.simid @@ -426,9 +444,10 @@ def do_compare(self, fromfac, tofac, nuclide, exp_invs): i = 0 for exp, obs in zip(invs, exp_invs): + self.assertAlmostEquals( + exp, obs, msg='mismatch at t={}, {} != {}'.format(i, exp, obs)) i += 1 - self.assertAlmostEquals(exp, obs, msg='mismatch at t={0}'.format(i)) - + os.remove(expfname) os.remove(obsfname) @@ -474,3 +493,16 @@ def test_pu239_reactor_repo(self): exp[549] = 420.42772559790944 self.do_compare('reactor', 'repo', 942390000, exp) +class TestGreedyRecycle(_Recycle): + """This class tests the input/recycle.xml file. + """ + def __init__(self, *args, **kwargs): + super(TestGreedyRecycle, self).__init__(*args, **kwargs) + self.inf = "../input/greedy_recycle.xml" + +class TestCbcRecycle(_Recycle): + """This class tests the input/recycle.xml file. + """ + def __init__(self, *args, **kwargs): + super(TestCbcRecycle, self).__init__(*args, **kwargs) + self.inf = "../input/recycle.xml"