From be2b5212a61b4b8deb3695718529d038fb375290 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 11 Apr 2023 15:21:14 -0500 Subject: [PATCH 01/14] change loops to push material to push_many --- openmcyclus/DepleteReactor.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index b81d574..a60443b 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -436,9 +436,8 @@ def discharge(self): #self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) - core_pop = self.core.pop_n(npop) - for ii in range(len(core_pop)): - self.spent_fuel.push(core_pop[ii]) + self.spent_fuel.push_many(self.core.pop_n(npop)) + tot_spent = 0 for ii in range(len(self.fuel_outcommods)): @@ -467,9 +466,7 @@ def load(self): return ss = str(n) + " assemblies" #self.record("LOAD", ss) - assemblies = self.fresh_fuel.pop_n(n) - for ii in range(len(assemblies)): - self.core.push(assemblies[ii]) + self.core.push_many(self.fresh_fuel.pop_n(n)) return def transmute(self, n_assem): @@ -489,8 +486,7 @@ def transmute(self, n_assem): There seem to be two Transmute functions in the cycamore reactor? ''' old = self.core.pop_n(min(n_assem, self.core.count)) - for ii in range(len(old)): - self.core.push(old[ii]) + self.core.push_many(old) ss = str(len(old)) + " assemblies" #self.record("TRANSMUTE", ss) print("time:", self.context.time, "transmute", ss) @@ -576,8 +572,8 @@ def peek_spent(self): mapped = {} if self.spent_fuel.count > 0: mats = self.spent_fuel.pop_n(self.spent_fuel.count) + self.spent_fuel.push_many(mats) for ii in range(len(mats)): - self.spent_fuel.push(mats[ii]) commod = self.get_commod(mats[ii], 'out') mapped[commod] = mats[ii] return mapped From d4fe39028531eb7f7e6c420594ab33387b7f48f0 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 11 Apr 2023 15:37:41 -0500 Subject: [PATCH 02/14] change transmute to actually change the recipe from fresh to spent fuel --- openmcyclus/DepleteReactor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index a60443b..0d352ee 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -435,9 +435,10 @@ def discharge(self): ss = str(npop) + " assemblies" #self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) - + print(self.spent_fuel.count, self.core.count) self.spent_fuel.push_many(self.core.pop_n(npop)) - + print(self.spent_fuel.count, self.core.count) + print(self.spent_fuel.peek().comp()) tot_spent = 0 for ii in range(len(self.fuel_outcommods)): @@ -487,11 +488,15 @@ def transmute(self, n_assem): ''' old = self.core.pop_n(min(n_assem, self.core.count)) self.core.push_many(old) + if self.core.count > len(old): + self.core.push_many(self.core.pop_n(self.core.count - len(old))) + ss = str(len(old)) + " assemblies" #self.record("TRANSMUTE", ss) print("time:", self.context.time, "transmute", ss) for ii in range(len(old)): print("call OpenMC") + old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) return def record(self, event, val): From 0ff0111a488e6727a4393fc184272fe86da8c02f Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 11 Apr 2023 15:51:03 -0500 Subject: [PATCH 03/14] add function decription, print statements --- openmcyclus/DepleteReactor.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index 0d352ee..eac0670 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -572,15 +572,23 @@ def push_spent(self, leftover): def peek_spent(self): ''' - + Get the material in the spent fuel inventory. Then for each material, + get the index of its out commodity, and append that index to the + end of a list that is a value in a dictionary, the keys are + the names of each commodity ''' + print("peek_spent") mapped = {} + #for commod in self.fuel_outcommods: + # mapped[commod] = [] if self.spent_fuel.count > 0: mats = self.spent_fuel.pop_n(self.spent_fuel.count) self.spent_fuel.push_many(mats) for ii in range(len(mats)): commod = self.get_commod(mats[ii], 'out') - mapped[commod] = mats[ii] + print("get_commod", commod, mats[ii]) + mapped[commod].append(mats[ii]) + print(mapped) return mapped def get_commod(self, material, flow): From 0d0aa91e98bb45034987f7b54b87a7fc47fc2512 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 30 May 2023 15:09:28 -0500 Subject: [PATCH 04/14] resolve conflicts with preferences branch --- openmcyclus/DepleteReactor.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index ca097c6..45474c3 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -598,17 +598,9 @@ def load(self): if n == 0: return ss = str(n) + " assemblies" -<<<<<<< HEAD #self.record("LOAD", ss) self.core.push_many(self.fresh_fuel.pop_n(n)) return -======= - # self.record("LOAD", ss) - assemblies = self.fresh_fuel.pop_n(n) - for ii in range(len(assemblies)): - self.core.push(assemblies[ii]) - return ->>>>>>> preferences def transmute(self, n_assem): ''' @@ -630,15 +622,10 @@ def transmute(self, n_assem): Number of assemblies to be transmuted ''' old = self.core.pop_n(min(n_assem, self.core.count)) -<<<<<<< HEAD self.core.push_many(old) if self.core.count > len(old): self.core.push_many(self.core.pop_n(self.core.count - len(old))) -======= - for ii in range(len(old)): - self.core.push(old[ii]) ->>>>>>> preferences ss = str(len(old)) + " assemblies" # self.record("TRANSMUTE", ss) print("time:", self.context.time, "transmute", ss) @@ -738,12 +725,6 @@ def push_spent(self, leftover): def peek_spent(self): ''' -<<<<<<< HEAD - Get the material in the spent fuel inventory. Then for each material, - get the index of its out commodity, and append that index to the - end of a list that is a value in a dictionary, the keys are - the names of each commodity -======= Creates a dictionary of the materials in the spent fuel inventory based on their commodity name. @@ -753,7 +734,6 @@ def peek_spent(self): Keys are the commodity names of the spent fuel. Values are the Materials with the given commodity names. ->>>>>>> preferences ''' print("peek_spent") mapped = {} @@ -764,13 +744,9 @@ def peek_spent(self): self.spent_fuel.push_many(mats) for ii in range(len(mats)): commod = self.get_commod(mats[ii], 'out') -<<<<<<< HEAD print("get_commod", commod, mats[ii]) mapped[commod].append(mats[ii]) print(mapped) -======= - mapped[commod] = mats[ii] ->>>>>>> preferences return mapped def get_commod(self, material, flow): From a7c1865d55a0fcc09490d406a661b094dcc37e7f Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 30 May 2023 15:58:42 -0500 Subject: [PATCH 05/14] adjust format for dict from peek_spent --- openmcyclus/DepleteReactor.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index 45474c3..172a711 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -391,6 +391,7 @@ def get_material_bids(self, requests): # phase 2 got_mats = False bids = [] port = [] + all_mats = {} for commod_index, commod in enumerate(self.fuel_outcommods): reqs = requests[commod] print("time:", self.context.time, "reqs:", reqs) @@ -398,22 +399,25 @@ def get_material_bids(self, requests): # phase 2 continue elif (got_mats == False): all_mats = self.peek_spent() + print(all_mats, len(all_mats)) if len(all_mats) == 0: tot_qty = 0 continue if commod in all_mats: - mats = [all_mats[commod]] + mats = all_mats[commod] else: mats = [] + print( "time:", self.context.time, "mats to trade matching request commod:", - mats) + mats, len(mats)) if len(mats) == 0: + print("no materials") continue - + print("not skipping end of function") recipe_comp = self.context.get_recipe( self.fuel_outrecipes[commod_index]) @@ -574,9 +578,11 @@ def discharge(self): for ii in range(len(self.fuel_outcommods)): spent_mats = self.peek_spent() tot_spent = 0 + print(spent_mats) if self.fuel_outcommods[ii] in spent_mats: mats = spent_mats[self.fuel_outcommods[ii]] - tot_spent += mats.quantity + for mat in mats: + tot_spent += mat.quantity lib.record_time_series( "supply" + self.fuel_outcommods[ii], self, tot_spent) @@ -737,14 +743,15 @@ def peek_spent(self): ''' print("peek_spent") mapped = {} - #for commod in self.fuel_outcommods: - # mapped[commod] = [] + for commod in self.fuel_outcommods: + mapped[commod] = [] if self.spent_fuel.count > 0: mats = self.spent_fuel.pop_n(self.spent_fuel.count) self.spent_fuel.push_many(mats) for ii in range(len(mats)): commod = self.get_commod(mats[ii], 'out') print("get_commod", commod, mats[ii]) + # mapped[commod] = mats[ii] mapped[commod].append(mats[ii]) print(mapped) return mapped From e12ce9f4b5a55e410dc55726324cc8e186bd62cf Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 30 May 2023 16:24:24 -0500 Subject: [PATCH 06/14] remove some print statements for clarity --- openmcyclus/DepleteReactor.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index 172a711..e152e09 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -170,7 +170,6 @@ def tick(self): if self.check_decommission_condition(): self.decommission() - print("time:", self.context.time, "end retired loop") if self.cycle_step == self.cycle_time: print( "time:", @@ -184,9 +183,9 @@ def tick(self): self.discharged = self.discharge() if self.cycle_step >= self.cycle_time: - print("time:", self.context.time, "load") - print("time:", self.context.time, self.core.count) - print("time:", self.context.time, self.fresh_fuel.count) + #print("time:", self.context.time, "load") + #print("time:", self.context.time, self.core.count) + #print("time:", self.context.time, self.fresh_fuel.count) self.load() # lib.Logger('5', str("DepleteReactor" + str(self.power_cap) + "is ticking")) @@ -348,7 +347,6 @@ def get_material_requests(self): # phase 1 "demand" + commod, self, self.assem_size) ports.append({"commodities": port, "constraints": self.assem_size}) print("time:", self.context.time, "finish get_material_requests") - print("request portfolio:", ports, len(ports)) return ports def get_material_bids(self, requests): # phase 2 @@ -395,11 +393,11 @@ def get_material_bids(self, requests): # phase 2 for commod_index, commod in enumerate(self.fuel_outcommods): reqs = requests[commod] print("time:", self.context.time, "reqs:", reqs) + #print(reqs[0].commodity) if len(reqs) == 0: continue elif (got_mats == False): all_mats = self.peek_spent() - print(all_mats, len(all_mats)) if len(all_mats) == 0: tot_qty = 0 continue @@ -415,9 +413,7 @@ def get_material_bids(self, requests): # phase 2 "mats to trade matching request commod:", mats, len(mats)) if len(mats) == 0: - print("no materials") continue - print("not skipping end of function") recipe_comp = self.context.get_recipe( self.fuel_outrecipes[commod_index]) @@ -438,7 +434,7 @@ def get_material_bids(self, requests): # phase 2 return port = {'bids': bids} - print("time:", self.context.time, "portfolio:", port) + print("time:", self.context.time, "bid portfolio:", port) print("time:", self.context.time, "respond", len(bids), "assemblies") return port @@ -473,10 +469,7 @@ def get_material_trades(self, trades): # phase 5.1 "trade away", len(trades), "assemblies") - print(trades) for ii in range(len(trades)): - print("time:", self.context.time, "number of trades:", len(trades)) - print(trades[ii]) commodity = trades[ii].request.commodity mat = mats[commodity].pop(-1) responses[trades[ii]] = mat @@ -520,7 +513,6 @@ def accept_material_trades(self, responses): # phase 5.2 ss = str(n_load) + " assemblies" # self.record("LOAD", ss) for trade in responses: - print(trade.request.commodity, trade.request.preference, trade.amt) commodity = trade.request.commodity material = trade.request.target self.index_res(material, commodity) @@ -529,7 +521,7 @@ def accept_material_trades(self, responses): # phase 5.2 else: self.fresh_fuel.push(material) - print("core:", self.core.count, "fresh:", self.fresh_fuel.count) + print("core:", self.core.count, "fresh:", self.fresh_fuel.count, "spent:", self.spent_fuel.count) return def retired(self): @@ -570,15 +562,14 @@ def discharge(self): ss = str(npop) + " assemblies" # self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) - print(self.spent_fuel.count, self.core.count) + #print(self.spent_fuel.count, self.core.count) self.spent_fuel.push_many(self.core.pop_n(npop)) - print(self.spent_fuel.count, self.core.count) - print(self.spent_fuel.peek().comp()) + #print(self.spent_fuel.count, self.core.count) + #print(self.spent_fuel.peek().comp()) for ii in range(len(self.fuel_outcommods)): spent_mats = self.peek_spent() tot_spent = 0 - print(spent_mats) if self.fuel_outcommods[ii] in spent_mats: mats = spent_mats[self.fuel_outcommods[ii]] for mat in mats: @@ -638,6 +629,7 @@ def transmute(self, n_assem): for ii in range(len(old)): print("call OpenMC") old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) + return def record(self, event, val): @@ -750,8 +742,6 @@ def peek_spent(self): self.spent_fuel.push_many(mats) for ii in range(len(mats)): commod = self.get_commod(mats[ii], 'out') - print("get_commod", commod, mats[ii]) - # mapped[commod] = mats[ii] mapped[commod].append(mats[ii]) print(mapped) return mapped From 5bb8c537c296deae7181eff6d17193156b60ffa7 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Wed, 31 May 2023 09:57:53 -0500 Subject: [PATCH 07/14] change to push_many, change peek_spent output format --- openmcyclus/DepleteReactor.py | 45 +++++++++-------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index ca097c6..ca019ab 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -402,7 +402,7 @@ def get_material_bids(self, requests): # phase 2 tot_qty = 0 continue if commod in all_mats: - mats = [all_mats[commod]] + mats = all_mats[commod] else: mats = [] @@ -423,8 +423,8 @@ def get_material_bids(self, requests): # phase 2 tot_bid += mats[jj].quantity qty = min(req.target.quantity, self.assem_size) mat = ts.Material.create_untracked(qty, recipe_comp) - for kk in range(self.spent_fuel.count): - bids.append({'request': req, 'offer': mat}) + #for kk in range(self.spent_fuel.count): + bids.append({'request': req, 'offer': mat}) if tot_bid >= req.target.quantity: break tot_qty = 0 @@ -576,7 +576,8 @@ def discharge(self): tot_spent = 0 if self.fuel_outcommods[ii] in spent_mats: mats = spent_mats[self.fuel_outcommods[ii]] - tot_spent += mats.quantity + for mat in mats: + tot_spent += mat.quantity lib.record_time_series( "supply" + self.fuel_outcommods[ii], self, tot_spent) @@ -598,17 +599,10 @@ def load(self): if n == 0: return ss = str(n) + " assemblies" -<<<<<<< HEAD - #self.record("LOAD", ss) - self.core.push_many(self.fresh_fuel.pop_n(n)) - return -======= # self.record("LOAD", ss) - assemblies = self.fresh_fuel.pop_n(n) - for ii in range(len(assemblies)): - self.core.push(assemblies[ii]) + + self.core.push_many(self.fresh_fuel.pop_n(n)) return ->>>>>>> preferences def transmute(self, n_assem): ''' @@ -630,15 +624,11 @@ def transmute(self, n_assem): Number of assemblies to be transmuted ''' old = self.core.pop_n(min(n_assem, self.core.count)) -<<<<<<< HEAD + #for ii in range(len(old)): + # self.core.push(old[ii]) self.core.push_many(old) if self.core.count > len(old): self.core.push_many(self.core.pop_n(self.core.count - len(old))) - -======= - for ii in range(len(old)): - self.core.push(old[ii]) ->>>>>>> preferences ss = str(len(old)) + " assemblies" # self.record("TRANSMUTE", ss) print("time:", self.context.time, "transmute", ss) @@ -738,12 +728,6 @@ def push_spent(self, leftover): def peek_spent(self): ''' -<<<<<<< HEAD - Get the material in the spent fuel inventory. Then for each material, - get the index of its out commodity, and append that index to the - end of a list that is a value in a dictionary, the keys are - the names of each commodity -======= Creates a dictionary of the materials in the spent fuel inventory based on their commodity name. @@ -753,24 +737,17 @@ def peek_spent(self): Keys are the commodity names of the spent fuel. Values are the Materials with the given commodity names. ->>>>>>> preferences ''' print("peek_spent") mapped = {} - #for commod in self.fuel_outcommods: - # mapped[commod] = [] + for commod in self.fuel_outcommods: + mapped[commod] = [] if self.spent_fuel.count > 0: mats = self.spent_fuel.pop_n(self.spent_fuel.count) self.spent_fuel.push_many(mats) for ii in range(len(mats)): commod = self.get_commod(mats[ii], 'out') -<<<<<<< HEAD - print("get_commod", commod, mats[ii]) mapped[commod].append(mats[ii]) - print(mapped) -======= - mapped[commod] = mats[ii] ->>>>>>> preferences return mapped def get_commod(self, material, flow): From 328529ccddfdf46e2e15af89aada725d2c903646 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Wed, 31 May 2023 15:16:34 -0500 Subject: [PATCH 08/14] adjust print statements, attempt to get Record working, it's not --- openmcyclus/DepleteReactor.py | 95 ++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index ca019ab..48ba653 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -148,18 +148,21 @@ def tick(self): print("time:", self.context.time, "retired") # self.record("RETIRED", "") if self.context.time == self.exit_time + 1: + print("transmuting fuel for retirement") if self.decom_transmute_all == 1: self.transmute(math.ceil(self.n_assem_core)) else: self.transmute(math.ceil(self.n_assem_core / 2)) while self.core.count > 0: + print("discharging remaining fuel") if self.discharge() == False: break print("time:", self.context.time, "end discharge loop") while ( self.fresh_fuel.count > 0) and ( self.spent_fuel.space >= self.assem_size): + print("pushing to spent fuel") self.spent_fuel.push(self.fresh_fuel.pop()) print( @@ -168,10 +171,12 @@ def tick(self): "decommission?", self.check_decommission_condition()) if self.check_decommission_condition(): + print("decommissioning facility") self.decommission() print("time:", self.context.time, "end retired loop") if self.cycle_step == self.cycle_time: + print("core:", self.core.count, "spent:", self.spent_fuel.count) print( "time:", self.context.time, @@ -179,9 +184,12 @@ def tick(self): math.ceil( self.n_assem_batch)) self.transmute(math.ceil(self.n_assem_batch)) + print("core:", self.core.count, "spent:", self.spent_fuel.count) if (self.cycle_step >= self.cycle_time) and (self.discharged == False): + print("core:", self.core.count, "spent:", self.spent_fuel.count) self.discharged = self.discharge() + print("core:", self.core.count, "spent:", self.spent_fuel.count) if self.cycle_step >= self.cycle_time: print("time:", self.context.time, "load") @@ -217,6 +225,7 @@ def tock(self): ''' print("time:", self.context.time, "tock") if self.retired(): + print("tock retired") return if ( @@ -224,11 +233,12 @@ def tock(self): self.refuel_time) and ( self.core.count == self.n_assem_core) and ( self.discharged): + print("restarting cycle counter") self.discharged = False self.cycle_step = 0 if (self.cycle_step == 0) and (self.core.count == self.n_assem_core): - # self.record("CYCLE_START", "") + #self.record("CYCLE_START", "") print("Cycle start") if (self.cycle_step >= 0) and (self.cycle_step < self.cycle_time) and ( @@ -271,8 +281,10 @@ def check_decommission_condition(self): ''' print("time:", self.context.time, "core count:", self.core.count) if (self.core.count == 0) and (self.spent_fuel.count == 0): + print("decommissioned") return True else: + print("not decommissioned") return False def get_material_requests(self): # phase 1 @@ -348,7 +360,7 @@ def get_material_requests(self): # phase 1 "demand" + commod, self, self.assem_size) ports.append({"commodities": port, "constraints": self.assem_size}) print("time:", self.context.time, "finish get_material_requests") - print("request portfolio:", ports, len(ports)) + #print("request portfolio:", ports, len(ports)) return ports def get_material_bids(self, requests): # phase 2 @@ -393,7 +405,7 @@ def get_material_bids(self, requests): # phase 2 port = [] for commod_index, commod in enumerate(self.fuel_outcommods): reqs = requests[commod] - print("time:", self.context.time, "reqs:", reqs) + #print("time:", self.context.time, "reqs:", reqs) if len(reqs) == 0: continue elif (got_mats == False): @@ -402,15 +414,15 @@ def get_material_bids(self, requests): # phase 2 tot_qty = 0 continue if commod in all_mats: - mats = all_mats[commod] + mats = [all_mats[commod]] else: mats = [] - print( - "time:", - self.context.time, - "mats to trade matching request commod:", - mats) + #print( + # "time:", + # self.context.time, + # "mats to trade matching request commod:", + # mats) if len(mats) == 0: continue @@ -423,8 +435,8 @@ def get_material_bids(self, requests): # phase 2 tot_bid += mats[jj].quantity qty = min(req.target.quantity, self.assem_size) mat = ts.Material.create_untracked(qty, recipe_comp) - #for kk in range(self.spent_fuel.count): - bids.append({'request': req, 'offer': mat}) + for kk in range(self.spent_fuel.count): + bids.append({'request': req, 'offer': mat}) if tot_bid >= req.target.quantity: break tot_qty = 0 @@ -434,7 +446,7 @@ def get_material_bids(self, requests): # phase 2 return port = {'bids': bids} - print("time:", self.context.time, "portfolio:", port) + #print("time:", self.context.time, "portfolio:", port) print("time:", self.context.time, "respond", len(bids), "assemblies") return port @@ -469,16 +481,16 @@ def get_material_trades(self, trades): # phase 5.1 "trade away", len(trades), "assemblies") - print(trades) + #print(trades) for ii in range(len(trades)): - print("time:", self.context.time, "number of trades:", len(trades)) - print(trades[ii]) + #print("time:", self.context.time, "number of trades:", len(trades)) + #print(trades[ii]) commodity = trades[ii].request.commodity mat = mats[commodity].pop(-1) responses[trades[ii]] = mat self.resource_indexes.pop(mat.obj_id) self.push_spent(mats) - print(responses) + #print(responses) return responses @@ -508,7 +520,7 @@ def accept_material_trades(self, responses): # phase 5.2 ''' - print("time:", self.context.time, "responses:", responses) + #print("time:", self.context.time, "responses:", responses) # min(len(responses), self.n_assem_core - self.core.count) n_load = len(responses) print("time:", self.context.time, "accept", n_load, "assemblies") @@ -516,7 +528,7 @@ def accept_material_trades(self, responses): # phase 5.2 ss = str(n_load) + " assemblies" # self.record("LOAD", ss) for trade in responses: - print(trade.request.commodity, trade.request.preference, trade.amt) + #print(trade.request.commodity, trade.request.preference, trade.amt) commodity = trade.request.commodity material = trade.request.target self.index_res(material, commodity) @@ -537,8 +549,10 @@ def retired(self): Bool: true if the conditions are met, False if they aren't met ''' if (self.exit_time != -1) and (self.context.time > self.exit_time): + print("retired, yes") return 1 else: + print("retired, no") return 0 def discharge(self): @@ -566,18 +580,18 @@ def discharge(self): ss = str(npop) + " assemblies" # self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) - print(self.spent_fuel.count, self.core.count) + #print(self.spent_fuel.count, self.core.count) self.spent_fuel.push_many(self.core.pop_n(npop)) - print(self.spent_fuel.count, self.core.count) - print(self.spent_fuel.peek().comp()) + #print(self.spent_fuel.count, self.core.count) + #print(self.spent_fuel.peek().comp()) for ii in range(len(self.fuel_outcommods)): spent_mats = self.peek_spent() tot_spent = 0 if self.fuel_outcommods[ii] in spent_mats: mats = spent_mats[self.fuel_outcommods[ii]] - for mat in mats: - tot_spent += mat.quantity + #for mat in mats: + tot_spent += mats.quantity lib.record_time_series( "supply" + self.fuel_outcommods[ii], self, tot_spent) @@ -624,8 +638,6 @@ def transmute(self, n_assem): Number of assemblies to be transmuted ''' old = self.core.pop_n(min(n_assem, self.core.count)) - #for ii in range(len(old)): - # self.core.push(old[ii]) self.core.push_many(old) if self.core.count > len(old): self.core.push_many(self.core.pop_n(self.core.count - len(old))) @@ -634,7 +646,14 @@ def transmute(self, n_assem): print("time:", self.context.time, "transmute", ss) for ii in range(len(old)): print("call OpenMC") + print("comp before transmuting:", old[ii].comp()) + print("obj_id before transmuting:", old[ii].obj_id) + print("state_id before transmuting:", old[ii].state_id) old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) + old[ii].bump_state_id() + print("comp after transmuting:", old[ii].comp()) + print("obj_id after transmuting:", old[ii].obj_id) + print("state_id after transmuting:", old[ii].state_id) return def record(self, event, val): @@ -649,12 +668,18 @@ def record(self, event, val): val: str value of event to be recorded ''' - events = self.context.new_datum( - "ReactorEvents") # creates tables with name ReactorEvents - datum = lib.Datum("Event") - lib.Datum.add_val(datum, "Event", event) - events.add_val("Value", val) - events.record() + # creates tables with name ReactorEvents + #self.context.new_datum("ReactorEvents") + #datum = lib.Datum() + #datum.add_val(event,val, [1], ts.Double) + #self.context.add_val("Value", val) + #self.context.record(self.context) + + datum = self.context.new_datum("ReactorEvents") + #datum = di.new_datum("ReactorEvents") + # di = cpp_cyclusDbInit ?? + datum.add_val(event, val) + datum.record() return def index_res(self, material, incommod): @@ -738,16 +763,14 @@ def peek_spent(self): Values are the Materials with the given commodity names. ''' - print("peek_spent") + #print("peek_spent") mapped = {} - for commod in self.fuel_outcommods: - mapped[commod] = [] if self.spent_fuel.count > 0: mats = self.spent_fuel.pop_n(self.spent_fuel.count) self.spent_fuel.push_many(mats) for ii in range(len(mats)): commod = self.get_commod(mats[ii], 'out') - mapped[commod].append(mats[ii]) + mapped[commod] = mats[ii] return mapped def get_commod(self, material, flow): @@ -793,9 +816,11 @@ def get_recipe(self, material, flow): name of recipe for the queried material ''' ii = self.resource_indexes[material.obj_id] + print("resource index:", ii) if flow == 'in': return self.fuel_inrecipes[ii] elif flow == 'out': + print(self.fuel_outrecipes[ii]) return self.fuel_outrecipes[ii] def get_pref(self, material): From 1711204222b39afe165044b753a362f8a3535b2f Mon Sep 17 00:00:00 2001 From: abachma2 Date: Wed, 7 Jun 2023 14:28:35 -0500 Subject: [PATCH 09/14] play around with getting datum.add_val to work --- openmcyclus/DepleteReactor.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index fc1a963..d0cae43 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -405,7 +405,7 @@ def get_material_bids(self, requests): # phase 2 all_mats = {} for commod_index, commod in enumerate(self.fuel_outcommods): reqs = requests[commod] - #print("time:", self.context.time, "reqs:", reqs) + print("time:", self.context.time, "reqs:", reqs) if len(reqs) == 0: continue elif (got_mats == False): @@ -414,20 +414,22 @@ def get_material_bids(self, requests): # phase 2 tot_qty = 0 continue if commod in all_mats: - mats = all_mats[commod] + mats = [all_mats[commod]] else: mats = [] - #print( - # "time:", - # self.context.time, - # "mats to trade matching request commod:", - # mats) + print( + "time:", + self.context.time, + "mats to trade matching request commod:", + mats) + print(len(mats)) if len(mats) == 0: continue recipe_comp = self.context.get_recipe( self.fuel_outrecipes[commod_index]) + print(recipe_comp) for req in reqs: tot_bid = 0 for jj in range(len(mats)): @@ -650,6 +652,13 @@ def transmute(self, n_assem): print("state_id before transmuting:", old[ii].state_id) old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) old[ii].bump_state_id() + print("new state id:", old[ii].state_id) + resources_table = self.context.new_datum("Resources") + resources_table.add_val("ResourceId", old[ii].state_id, [1], int) + resources_table.record() + print(type(old[ii].state_id)) + print(resources_table.title) + #self.context.add_val("ResourceId", old[ii].state_id) print("comp after transmuting:", old[ii].comp()) print("obj_id after transmuting:", old[ii].obj_id) print("state_id after transmuting:", old[ii].state_id) @@ -815,11 +824,11 @@ def get_recipe(self, material, flow): name of recipe for the queried material ''' ii = self.resource_indexes[material.obj_id] - print("resource index:", ii) + #print("resource index:", ii) if flow == 'in': return self.fuel_inrecipes[ii] elif flow == 'out': - print(self.fuel_outrecipes[ii]) + #print(self.fuel_outrecipes[ii]) return self.fuel_outrecipes[ii] def get_pref(self, material): From 351749adfda7a4e8dcedcb4a53372ca4af295594 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Thu, 8 Jun 2023 16:20:54 -0500 Subject: [PATCH 10/14] recording resources and reactor events The ReactorEvents table is created and some of the columns can be written to it, but the column names are wrong. The spent fuel resources are partially written to the Resources table, but only up through the TimeCreated column. Not sure why the other columns can't be written. --- openmcyclus/DepleteReactor.py | 56 ++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index d0cae43..56f7477 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -146,7 +146,7 @@ def tick(self): print("time:", self.context.time, "tick") if self.retired(): print("time:", self.context.time, "retired") - # self.record("RETIRED", "") + self.record("RETIRED", "") if self.context.time == self.exit_time + 1: print("transmuting fuel for retirement") if self.decom_transmute_all == 1: @@ -183,6 +183,7 @@ def tick(self): math.ceil( self.n_assem_batch)) self.transmute(math.ceil(self.n_assem_batch)) + self.record("CYCLE_END", "") print("core:", self.core.count, "spent:", self.spent_fuel.count) if (self.cycle_step >= self.cycle_time) and (self.discharged == False): @@ -237,7 +238,7 @@ def tock(self): self.cycle_step = 0 if (self.cycle_step == 0) and (self.core.count == self.n_assem_core): - #self.record("CYCLE_START", "") + self.record("CYCLE_START", "") print("Cycle start") if (self.cycle_step >= 0) and (self.cycle_step < self.cycle_time) and ( @@ -527,7 +528,7 @@ def accept_material_trades(self, responses): # phase 5.2 print("time:", self.context.time, "accept", n_load, "assemblies") if n_load > 0: ss = str(n_load) + " assemblies" - # self.record("LOAD", ss) + self.record("LOAD", ss) for trade in responses: #print(trade.request.commodity, trade.request.preference, trade.amt) commodity = trade.request.commodity @@ -575,11 +576,11 @@ def discharge(self): ''' npop = min(self.n_assem_batch, self.core.count) if (self.n_assem_spent - self.spent_fuel.count) < npop: - # self.record("DISCHARGE", "failed") + self.record("DISCHARGE", "failed") return False ss = str(npop) + " assemblies" - # self.record("DISCHARGE", ss) + self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) #print(self.spent_fuel.count, self.core.count) self.spent_fuel.push_many(self.core.pop_n(npop)) @@ -614,7 +615,7 @@ def load(self): if n == 0: return ss = str(n) + " assemblies" - # self.record("LOAD", ss) + self.record("LOAD", ss) self.core.push_many(self.fresh_fuel.pop_n(n)) return @@ -643,25 +644,30 @@ def transmute(self, n_assem): if self.core.count > len(old): self.core.push_many(self.core.pop_n(self.core.count - len(old))) ss = str(len(old)) + " assemblies" - # self.record("TRANSMUTE", ss) + self.record("TRANSMUTE", ss) print("time:", self.context.time, "transmute", ss) for ii in range(len(old)): print("call OpenMC") - print("comp before transmuting:", old[ii].comp()) - print("obj_id before transmuting:", old[ii].obj_id) - print("state_id before transmuting:", old[ii].state_id) + parent_1 = old[ii].state_id + print("new recipe:", self.context.get_recipe(self.get_recipe(old[ii],'out'))) old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) old[ii].bump_state_id() - print("new state id:", old[ii].state_id) + print(old[ii].quantity, type(old[ii].quantity)) + print(old[ii].units, type(old[ii].units)) + print(old[ii].qual_id, type(old[ii].qual_id)) + print(parent_1, type(parent_1)) resources_table = self.context.new_datum("Resources") - resources_table.add_val("ResourceId", old[ii].state_id, [1], int) + resources_table.add_val("ResourceId", old[ii].state_id, None, 'int') + resources_table.add_val("ObjId", old[ii].obj_id, None, 'int') + resources_table.add_val("Type", old[ii].type, None, "std::string") + resources_table.add_val("TimeCreated", self.context.time, None, 'int') + #resources_table.add_val("Quantity", old[ii].quantity, None, 'float') + #resources_table.add_val("Units", old[ii].units, None, 'std::string') + #resources_table.add_val("QualId", old[ii].qual_id, None, 'int') + #resources_table.add_val("Parent1", parent_1, None, 'int') + #resources_table.add_val("Parent2", 0, None, 'int') resources_table.record() - print(type(old[ii].state_id)) - print(resources_table.title) - #self.context.add_val("ResourceId", old[ii].state_id) print("comp after transmuting:", old[ii].comp()) - print("obj_id after transmuting:", old[ii].obj_id) - print("state_id after transmuting:", old[ii].state_id) return def record(self, event, val): @@ -676,18 +682,14 @@ def record(self, event, val): val: str value of event to be recorded ''' - # creates tables with name ReactorEvents - #self.context.new_datum("ReactorEvents") - #datum = lib.Datum() - #datum.add_val(event,val, [1], ts.Double) - #self.context.add_val("Value", val) - #self.context.record(self.context) - + print("Recording to ReactorEvents") datum = self.context.new_datum("ReactorEvents") - #datum = di.new_datum("ReactorEvents") - # di = cpp_cyclusDbInit ?? - datum.add_val(event, val) + datum.add_val("AgentId", self.id, None, 'int') + datum.add_val("Time", self.context.time, None, 'int') + #datum.add_val("Event", event, None, 'std::string') + datum.add_val("Value", val, None, 'std::string') datum.record() + print("done recording") return def index_res(self, material, incommod): From 67e2eb7811bea74260ac188dc846111d016a3740 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Mon, 19 Jun 2023 14:24:25 -0500 Subject: [PATCH 11/14] figure out correct datatype, resources table mostly correct Needed to adjust the Quantity to a double. The table is full now. The Parent 1 isn't correct, but I'm not sure how to get it to be correct and match the state_id of the parent (i.e. before the state id is bumped) --- openmcyclus/DepleteReactor.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index 56f7477..61df5f3 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -649,23 +649,18 @@ def transmute(self, n_assem): for ii in range(len(old)): print("call OpenMC") parent_1 = old[ii].state_id - print("new recipe:", self.context.get_recipe(self.get_recipe(old[ii],'out'))) old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) old[ii].bump_state_id() - print(old[ii].quantity, type(old[ii].quantity)) - print(old[ii].units, type(old[ii].units)) - print(old[ii].qual_id, type(old[ii].qual_id)) - print(parent_1, type(parent_1)) resources_table = self.context.new_datum("Resources") resources_table.add_val("ResourceId", old[ii].state_id, None, 'int') resources_table.add_val("ObjId", old[ii].obj_id, None, 'int') resources_table.add_val("Type", old[ii].type, None, "std::string") resources_table.add_val("TimeCreated", self.context.time, None, 'int') - #resources_table.add_val("Quantity", old[ii].quantity, None, 'float') - #resources_table.add_val("Units", old[ii].units, None, 'std::string') - #resources_table.add_val("QualId", old[ii].qual_id, None, 'int') - #resources_table.add_val("Parent1", parent_1, None, 'int') - #resources_table.add_val("Parent2", 0, None, 'int') + resources_table.add_val("Quantity", old[ii].quantity, None, 'double') + resources_table.add_val("Units", old[ii].units, None, 'std::string') + resources_table.add_val("QualId", old[ii].qual_id, None, 'int') + resources_table.add_val("Parent1", parent_1, None, 'int') + resources_table.add_val("Parent2", 0, None, 'int') resources_table.record() print("comp after transmuting:", old[ii].comp()) return @@ -687,8 +682,8 @@ def record(self, event, val): datum.add_val("AgentId", self.id, None, 'int') datum.add_val("Time", self.context.time, None, 'int') #datum.add_val("Event", event, None, 'std::string') - datum.add_val("Value", val, None, 'std::string') - datum.record() + #datum.add_val("Value", val, None, 'std::string') + #datum.record() print("done recording") return From 2a671d63e2c1d336455363393947693597d7b579 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Mon, 19 Jun 2023 14:39:17 -0500 Subject: [PATCH 12/14] comment out self.record uses --- openmcyclus/DepleteReactor.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index 61df5f3..920cca7 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -146,7 +146,7 @@ def tick(self): print("time:", self.context.time, "tick") if self.retired(): print("time:", self.context.time, "retired") - self.record("RETIRED", "") + #self.record("RETIRED", "") if self.context.time == self.exit_time + 1: print("transmuting fuel for retirement") if self.decom_transmute_all == 1: @@ -183,7 +183,7 @@ def tick(self): math.ceil( self.n_assem_batch)) self.transmute(math.ceil(self.n_assem_batch)) - self.record("CYCLE_END", "") + #self.record("CYCLE_END", "") print("core:", self.core.count, "spent:", self.spent_fuel.count) if (self.cycle_step >= self.cycle_time) and (self.discharged == False): @@ -238,7 +238,7 @@ def tock(self): self.cycle_step = 0 if (self.cycle_step == 0) and (self.core.count == self.n_assem_core): - self.record("CYCLE_START", "") + #self.record("CYCLE_START", "") print("Cycle start") if (self.cycle_step >= 0) and (self.cycle_step < self.cycle_time) and ( @@ -528,7 +528,7 @@ def accept_material_trades(self, responses): # phase 5.2 print("time:", self.context.time, "accept", n_load, "assemblies") if n_load > 0: ss = str(n_load) + " assemblies" - self.record("LOAD", ss) + #self.record("LOAD", ss) for trade in responses: #print(trade.request.commodity, trade.request.preference, trade.amt) commodity = trade.request.commodity @@ -576,11 +576,11 @@ def discharge(self): ''' npop = min(self.n_assem_batch, self.core.count) if (self.n_assem_spent - self.spent_fuel.count) < npop: - self.record("DISCHARGE", "failed") + #self.record("DISCHARGE", "failed") return False ss = str(npop) + " assemblies" - self.record("DISCHARGE", ss) + #self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) #print(self.spent_fuel.count, self.core.count) self.spent_fuel.push_many(self.core.pop_n(npop)) @@ -615,7 +615,7 @@ def load(self): if n == 0: return ss = str(n) + " assemblies" - self.record("LOAD", ss) + #self.record("LOAD", ss) self.core.push_many(self.fresh_fuel.pop_n(n)) return @@ -644,7 +644,7 @@ def transmute(self, n_assem): if self.core.count > len(old): self.core.push_many(self.core.pop_n(self.core.count - len(old))) ss = str(len(old)) + " assemblies" - self.record("TRANSMUTE", ss) + #self.record("TRANSMUTE", ss) print("time:", self.context.time, "transmute", ss) for ii in range(len(old)): print("call OpenMC") From e75d4e64dd4e1c94cc290b92371d417e51cdc85f Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 20 Jun 2023 10:32:42 -0500 Subject: [PATCH 13/14] move spent fuel recording to discharge If fuel is to be transmuted at each cycle end, then the spent fuel resources don't need to be recording each time fuel is transmuted. This also captures all of the fuel that is dischraged from a reactor, not just the transmuted fuel. This only has an impact when a facility is decommissioned during a simulation --- openmcyclus/DepleteReactor.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/openmcyclus/DepleteReactor.py b/openmcyclus/DepleteReactor.py index 920cca7..b2ef79c 100644 --- a/openmcyclus/DepleteReactor.py +++ b/openmcyclus/DepleteReactor.py @@ -583,7 +583,22 @@ def discharge(self): #self.record("DISCHARGE", ss) print("time:", self.context.time, "discharge", ss) #print(self.spent_fuel.count, self.core.count) - self.spent_fuel.push_many(self.core.pop_n(npop)) + discharge_assemblies = self.core.pop_n(npop) + for ii in range(len(discharge_assemblies)): + parent_1 = discharge_assemblies[ii].state_id + discharge_assemblies[ii].bump_state_id() + resources_table = self.context.new_datum("Resources") + resources_table.add_val("ResourceId", discharge_assemblies[ii].state_id, None, 'int') + resources_table.add_val("ObjId", discharge_assemblies[ii].obj_id, None, 'int') + resources_table.add_val("Type", discharge_assemblies[ii].type, None, "std::string") + resources_table.add_val("TimeCreated", self.context.time, None, 'int') + resources_table.add_val("Quantity", discharge_assemblies[ii].quantity, None, 'double') + resources_table.add_val("Units", discharge_assemblies[ii].units, None, 'std::string') + resources_table.add_val("QualId", discharge_assemblies[ii].qual_id, None, 'int') + resources_table.add_val("Parent1", parent_1, None, 'int') + resources_table.add_val("Parent2", 0, None, 'int') + resources_table.record() + self.spent_fuel.push_many(discharge_assemblies) #print(self.spent_fuel.count, self.core.count) #print(self.spent_fuel.peek().comp()) @@ -648,20 +663,7 @@ def transmute(self, n_assem): print("time:", self.context.time, "transmute", ss) for ii in range(len(old)): print("call OpenMC") - parent_1 = old[ii].state_id old[ii].transmute(self.context.get_recipe(self.get_recipe(old[ii],'out'))) - old[ii].bump_state_id() - resources_table = self.context.new_datum("Resources") - resources_table.add_val("ResourceId", old[ii].state_id, None, 'int') - resources_table.add_val("ObjId", old[ii].obj_id, None, 'int') - resources_table.add_val("Type", old[ii].type, None, "std::string") - resources_table.add_val("TimeCreated", self.context.time, None, 'int') - resources_table.add_val("Quantity", old[ii].quantity, None, 'double') - resources_table.add_val("Units", old[ii].units, None, 'std::string') - resources_table.add_val("QualId", old[ii].qual_id, None, 'int') - resources_table.add_val("Parent1", parent_1, None, 'int') - resources_table.add_val("Parent2", 0, None, 'int') - resources_table.record() print("comp after transmuting:", old[ii].comp()) return From c1145be28f9415dc563d642343ebfac9fa07bb31 Mon Sep 17 00:00:00 2001 From: abachma2 Date: Tue, 20 Jun 2023 10:35:29 -0500 Subject: [PATCH 14/14] update test results for decom_transmute_all in Cycamore Specifying the decom_transmute_all in Cycamore means that all of the fuel discharged from the reactor at decommissioning gets transmuted, and thus recorded in the Resources database --- tests/integration_tests/test_depletereactor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests/test_depletereactor.py b/tests/integration_tests/test_depletereactor.py index f9b8d64..47866ef 100644 --- a/tests/integration_tests/test_depletereactor.py +++ b/tests/integration_tests/test_depletereactor.py @@ -168,6 +168,6 @@ def test_resources(self): tbl = self.resources times = self.to_array(tbl, "TimeCreated") quantities = self.to_array(tbl, "Quantity") - assert len(tbl) == 11 - assert all(times == [3,3,3,5,5,8,8,11,11,13,13]) - assert all(quantities == [10]*11) + assert len(tbl) == 12 + assert all(times == [3,3,3,5,5,8,8,11,11,13,13,13]) + assert all(quantities == [10]*12)