From d90c2ceced1d51355fd4ae5ea23d0ca3bb417067 Mon Sep 17 00:00:00 2001 From: ilhamv Date: Sun, 3 Sep 2023 22:38:38 -0700 Subject: [PATCH 1/3] refactor loops --- examples/fixed_source/slab_absorbium/input.py | 2 +- mcdc/__init__.py | 2 +- mcdc/card.py | 32 +++--- mcdc/constant.py | 14 +-- mcdc/input_.py | 67 ++++++----- mcdc/kernel.py | 26 ++--- mcdc/loop.py | 106 +++++++++--------- mcdc/main.py | 26 ++--- mcdc/print_.py | 20 ++-- mcdc/type_.py | 63 ++++++----- 10 files changed, 187 insertions(+), 171 deletions(-) diff --git a/examples/fixed_source/slab_absorbium/input.py b/examples/fixed_source/slab_absorbium/input.py index cc69cfb2..e189df7d 100644 --- a/examples/fixed_source/slab_absorbium/input.py +++ b/examples/fixed_source/slab_absorbium/input.py @@ -42,7 +42,7 @@ ) # Setting -mcdc.setting(N_particle=1e3) +mcdc.setting(N_particle=1e4) # Run mcdc.run() diff --git a/mcdc/__init__.py b/mcdc/__init__.py index ab1d2b14..5b6384e3 100644 --- a/mcdc/__init__.py +++ b/mcdc/__init__.py @@ -14,7 +14,7 @@ weighted_emission, population_control, branchless_collision, - census, + time_census, weight_window, iQMC, weight_roulette, diff --git a/mcdc/card.py b/mcdc/card.py index 8ced9933..1de85107 100644 --- a/mcdc/card.py +++ b/mcdc/card.py @@ -1,6 +1,6 @@ import numpy as np -from mcdc.constant import INF, GR_ALL, PCT_NONE, PI, SHIFT +from mcdc.constant import INF, GYRATION_RADIUS_ALL, PCT_NONE, PI, SHIFT class InputDeck: @@ -66,27 +66,31 @@ def reset(self): self.setting = { "tag": "Setting", "N_particle": 0, + "rng_seed": 1, + "time_boundary": INF, + "progress_bar": True, + "output_name": "output", + "save_input_deck": True, + "track_particle": False, + "mode_eigenvalue": False, + "k_init": 1.0, "N_inactive": 0, "N_active": 0, "N_cycle": 0, - "mode_eigenvalue": False, - "time_boundary": INF, - "rng_seed": 1, - "bank_active_buff": 100, - "bank_census_buff": 1.0, - "k_init": 1.0, - "output": "output", - "progress_bar": True, + "save_particle": False, "gyration_radius": False, - "gyration_radius_type": GR_ALL, + "gyration_radius_type": GYRATION_RADIUS_ALL, + "N_census": 1, + "census_time": np.array([INF]), "source_file": False, "source_file_name": "", - "track_particle": False, - "save_particle": False, - "save_input_deck": True, "IC_file": False, "IC_file_name": "", "N_precursor": 0, + # Below are parameters not copied to mcdc.setting + "bank_active_buff": 100, + "bank_census_buff": 1.0, + # TODO: Move to technique "N_sensitivity": 0, } @@ -138,8 +142,6 @@ def reset(self): "IC_neutron_density_max": 0.0, "IC_precursor_density_max": 0.0, "IC_cycle_stretch": 1.0, - "time_census": False, - "census_time": np.array([INF]), "branchless_collision": False, "dsm_order": 1, } diff --git a/mcdc/constant.py b/mcdc/constant.py index cd8d1c67..c3d2306e 100644 --- a/mcdc/constant.py +++ b/mcdc/constant.py @@ -22,13 +22,13 @@ MESH_T = 3 # Gyration raius type -GR_ALL = 0 -GR_INFINITE_X = 1 -GR_INFINITE_Y = 2 -GR_INFINITE_Z = 3 -GR_ONLY_X = 4 -GR_ONLY_Y = 5 -GR_ONLY_Z = 6 +GYRATION_RADIUS_ALL = 0 +GYRATION_RADIUS_INFINITE_X = 1 +GYRATION_RADIUS_INFINITE_Y = 2 +GYRATION_RADIUS_INFINITE_Z = 3 +GYRATION_RADIUS_ONLY_X = 4 +GYRATION_RADIUS_ONLY_Y = 5 +GYRATION_RADIUS_ONLY_Z = 6 # Population control PCT_NONE = 0 diff --git a/mcdc/input_.py b/mcdc/input_.py index 246430a1..6be3394c 100644 --- a/mcdc/input_.py +++ b/mcdc/input_.py @@ -19,13 +19,13 @@ make_card_source, ) from mcdc.constant import ( - GR_ALL, - GR_INFINITE_X, - GR_INFINITE_Y, - GR_INFINITE_Z, - GR_ONLY_X, - GR_ONLY_Y, - GR_ONLY_Z, + GYRATION_RADIUS_ALL, + GYRATION_RADIUS_INFINITE_X, + GYRATION_RADIUS_INFINITE_Y, + GYRATION_RADIUS_INFINITE_Z, + GYRATION_RADIUS_ONLY_X, + GYRATION_RADIUS_ONLY_Y, + GYRATION_RADIUS_ONLY_Z, PCT_NONE, PCT_COMBING, PCT_COMBING_WEIGHT, @@ -900,21 +900,21 @@ def setting(**kw): # Check the suplied keyword arguments for key in kw.keys(): check_support( - "source parameter", + "setting parameter", key, [ + "progress_bar", "N_particle", - "time_boundary", "rng_seed", - "output", - "progress_bar", - "k_eff", - "active_bank_buff", - "census_bank_buff", - "source_file", + "time_boundary", "particle_tracker", "save_input_deck", + "output_name", + "source_file", "IC_file", + "active_bank_buff", + "census_bank_buff", + "k_eff", ], False, ) @@ -923,7 +923,7 @@ def setting(**kw): N_particle = kw.get("N_particle") time_boundary = kw.get("time_boundary") rng_seed = kw.get("rng_seed") - output = kw.get("output") + output = kw.get("output_name") progress_bar = kw.get("progress_bar") k_eff = kw.get("k_eff") bank_active_buff = kw.get("active_bank_buff") @@ -950,7 +950,7 @@ def setting(**kw): # Output .h5 file name if output is not None: - card["output"] = output + card["output_name"] = output # Progress bar if progress_bar is not None: @@ -1020,19 +1020,19 @@ def eigenmode( if gyration_radius is not None: card["gyration_radius"] = True if gyration_radius == "all": - card["gyration_radius_type"] = GR_ALL + card["gyration_radius_type"] = GYRATION_RADIUS_ALL elif gyration_radius == "infinite-x": - card["gyration_radius_type"] = GR_INFINITE_X + card["gyration_radius_type"] = GYRATION_RADIUS_INFINITE_X elif gyration_radius == "infinite-y": - card["gyration_radius_type"] = GR_INFINITE_Y + card["gyration_radius_type"] = GYRATION_RADIUS_INFINITE_Y elif gyration_radius == "infinite-z": - card["gyration_radius_type"] = GR_INFINITE_Z + card["gyration_radius_type"] = GYRATION_RADIUS_INFINITE_Z elif gyration_radius == "only-x": - card["gyration_radius_type"] = GR_ONLY_X + card["gyration_radius_type"] = GYRATION_RADIUS_ONLY_X elif gyration_radius == "only-y": - card["gyration_radius_type"] = GR_ONLY_Y + card["gyration_radius_type"] = GYRATION_RADIUS_ONLY_Y elif gyration_radius == "only-z": - card["gyration_radius_type"] = GR_ONLY_Z + card["gyration_radius_type"] = GYRATION_RADIUS_ONLY_Z else: print_error("Unknown gyration radius type") @@ -1075,12 +1075,21 @@ def branchless_collision(): card["weighted_emission"] = False -def census(t, pct="none"): - card = mcdc.input_deck.technique - card["time_census"] = True +def time_census(t): + # Remove census beyond the final tally time grid point + while True: + if t[-1] >= mcdc.input_deck.tally["mesh"]["t"][-1]: + t = t[:-1] + else: + break + + # Add the default, final census-at-infinity + t = np.append(t, INF) + + # Set the time census parameters + card = mcdc.input_deck.setting card["census_time"] = t - if pct != "none": - population_control(pct) + card["N_census"] = len(t) def weight_window(x=None, y=None, z=None, t=None, window=None, width=None): diff --git a/mcdc/kernel.py b/mcdc/kernel.py index f109d61f..41f0f56d 100644 --- a/mcdc/kernel.py +++ b/mcdc/kernel.py @@ -1561,7 +1561,7 @@ def eigenvalue_tally(P, distance, mcdc): def eigenvalue_tally_closeout_history(mcdc): N_particle = mcdc["setting"]["N_particle"] - i_cycle = mcdc["i_cycle"] + idx_cycle = mcdc["idx_cycle"] # MPI Allreduce buff_nuSigmaF = np.zeros(1, np.float64) @@ -1592,7 +1592,7 @@ def eigenvalue_tally_closeout_history(mcdc): # Update and store k_eff mcdc["k_eff"] = buff_nuSigmaF[0] / N_particle - mcdc["k_cycle"][i_cycle] = mcdc["k_eff"] + mcdc["k_cycle"][idx_cycle] = mcdc["k_eff"] # Normalize other eigenvalue/global tallies tally_n = buff_n[0] / N_particle @@ -1612,7 +1612,7 @@ def eigenvalue_tally_closeout_history(mcdc): mcdc["C_avg"] += tally_C mcdc["C_sdv"] += tally_C * tally_C - N = 1 + mcdc["i_cycle"] - mcdc["setting"]["N_inactive"] + N = 1 + mcdc["idx_cycle"] - mcdc["setting"]["N_inactive"] mcdc["k_avg_running"] = mcdc["k_avg"] / N if N == 1: mcdc["k_sdv_running"] = 0.0 @@ -1658,7 +1658,7 @@ def eigenvalue_tally_closeout_history(mcdc): rms_local = np.zeros(1, np.float64) rms = np.zeros(1, np.float64) gr_type = mcdc["setting"]["gyration_radius_type"] - if gr_type == GR_ALL: + if gr_type == GYRATION_RADIUS_ALL: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ( @@ -1666,27 +1666,27 @@ def eigenvalue_tally_closeout_history(mcdc): + (P["y"] - com_y) ** 2 + (P["z"] - com_z) ** 2 ) * P["w"] - elif gr_type == GR_INFINITE_X: + elif gr_type == GYRATION_RADIUS_INFINITE_X: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ((P["y"] - com_y) ** 2 + (P["z"] - com_z) ** 2) * P["w"] - elif gr_type == GR_INFINITE_Y: + elif gr_type == GYRATION_RADIUS_INFINITE_Y: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ((P["x"] - com_x) ** 2 + (P["z"] - com_z) ** 2) * P["w"] - elif gr_type == GR_INFINITE_Z: + elif gr_type == GYRATION_RADIUS_INFINITE_Z: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ((P["x"] - com_x) ** 2 + (P["y"] - com_y) ** 2) * P["w"] - elif gr_type == GR_ONLY_X: + elif gr_type == GYRATION_RADIUS_ONLY_X: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ((P["x"] - com_x) ** 2) * P["w"] - elif gr_type == GR_ONLY_Y: + elif gr_type == GYRATION_RADIUS_ONLY_Y: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ((P["y"] - com_y) ** 2) * P["w"] - elif gr_type == GR_ONLY_Z: + elif gr_type == GYRATION_RADIUS_ONLY_Z: for i in range(N_local): P = mcdc["bank_census"]["particles"][i] rms_local[0] += ((P["z"] - com_z) ** 2) * P["w"] @@ -1697,7 +1697,7 @@ def eigenvalue_tally_closeout_history(mcdc): rms = math.sqrt(rms[0] / W) # Gyration radius - mcdc["gyration_radius"][i_cycle] = rms + mcdc["gyration_radius"][idx_cycle] = rms @njit @@ -1743,8 +1743,8 @@ def move_to_event(P, mcdc): d_time_boundary = speed * (mcdc["setting"]["time_boundary"] - P["t"]) # Distance to census time - idx = mcdc["technique"]["census_idx"] - d_time_census = speed * (mcdc["technique"]["census_time"][idx] - P["t"]) + idx = mcdc["idx_census"] + d_time_census = speed * (mcdc["setting"]["census_time"][idx] - P["t"]) # Distance to collision if mcdc["technique"]["iQMC"]: diff --git a/mcdc/loop.py b/mcdc/loop.py index 8300e718..7727a411 100644 --- a/mcdc/loop.py +++ b/mcdc/loop.py @@ -19,75 +19,81 @@ # ========================================================================= -# Main loop +# Fixed-source loop # ========================================================================= @njit -def loop_main(mcdc): - simulation_end = False - - idx_cycle = 0 - while not simulation_end: - seed_cycle = kernel.split_seed(idx_cycle, mcdc["setting"]["rng_seed"]) +def loop_fixed_source(mcdc): + # Loop over time censuses + for idx_census in range(mcdc["setting"]["N_census"]): + mcdc["idx_census"] = idx_census + seed_census = kernel.split_seed(idx_census, mcdc["setting"]["rng_seed"]) # Loop over source particles - seed_source = kernel.split_seed(seed_cycle, SEED_SPLIT_SOURCE) + seed_source = kernel.split_seed(seed_census, SEED_SPLIT_SOURCE) loop_source(seed_source, mcdc) # Loop over source precursors if mcdc["bank_precursor"]["size"] > 0: seed_source_precursor = kernel.split_seed( - seed_cycle, SEED_SPLIT_SOURCE_PRECURSOR + seed_census, SEED_SPLIT_SOURCE_PRECURSOR ) loop_source_precursor(seed_source_precursor, mcdc) - # Eigenvalue cycle closeout - if mcdc["setting"]["mode_eigenvalue"]: - # Tally history closeout - kernel.eigenvalue_tally_closeout_history(mcdc) - if mcdc["cycle_active"]: - kernel.tally_reduce_bin(mcdc) - kernel.tally_closeout_history(mcdc) + # Time census closeout + if idx_census < mcdc["setting"]["N_census"] - 1: + # TODO: Make census actions optional - # Print progress - with objmode(): - print_progress_eigenvalue(mcdc) + # Output tally - # Manage particle banks - seed_bank = kernel.split_seed(seed_cycle, SEED_SPLIT_BANK) + # Manage particle banks: population control and wor rebalance + seed_bank = kernel.split_seed(seed_census, SEED_SPLIT_BANK) kernel.manage_particle_banks(seed_bank, mcdc) - # Cycle management - mcdc["i_cycle"] += 1 - if mcdc["i_cycle"] == mcdc["setting"]["N_cycle"]: - simulation_end = True - elif mcdc["i_cycle"] >= mcdc["setting"]["N_inactive"]: - mcdc["cycle_active"] = True + # Tally closeout + kernel.tally_closeout(mcdc) - # Time census closeout - elif ( - mcdc["technique"]["time_census"] - and mcdc["technique"]["census_idx"] - < len(mcdc["technique"]["census_time"]) - 1 - ): - # Manage particle banks - seed_bank = kernel.split_seed(seed_cycle, SEED_SPLIT_BANK) - kernel.manage_particle_banks(seed_bank, mcdc) - # Increment census index - mcdc["technique"]["census_idx"] += 1 +# ========================================================================= +# Eigenvalue loop +# ========================================================================= - # Fixed-source closeout - else: - simulation_end = True - idx_cycle += 1 +@njit +def loop_eigenvalue(mcdc): + simulation_end = False + + # Loop over power iteration cycles + for idx_cycle in range(mcdc["setting"]["N_cycle"]): + seed_cycle = kernel.split_seed(idx_cycle, mcdc["setting"]["rng_seed"]) + + # Loop over source particles + seed_source = kernel.split_seed(seed_cycle, SEED_SPLIT_SOURCE) + loop_source(seed_source, mcdc) + + # Tally "history" closeout + kernel.eigenvalue_tally_closeout_history(mcdc) + if mcdc["cycle_active"]: + kernel.tally_reduce_bin(mcdc) + kernel.tally_closeout_history(mcdc) + + # Print progress + with objmode(): + print_progress_eigenvalue(mcdc) + + # Manage particle banks + seed_bank = kernel.split_seed(seed_cycle, SEED_SPLIT_BANK) + kernel.manage_particle_banks(seed_bank, mcdc) + + # Entering active cycle? + mcdc["idx_cycle"] += 1 + if mcdc["idx_cycle"] >= mcdc["setting"]["N_inactive"]: + mcdc["cycle_active"] = True # Tally closeout kernel.tally_closeout(mcdc) - if mcdc["setting"]["mode_eigenvalue"]: - kernel.eigenvalue_tally_closeout(mcdc) + kernel.eigenvalue_tally_closeout(mcdc) # ============================================================================= @@ -125,8 +131,8 @@ def loop_source(seed, mcdc): P = mcdc["bank_source"]["particles"][idx_work] # Check if it is beyond current census index - census_idx = mcdc["technique"]["census_idx"] - if P["t"] > mcdc["technique"]["census_time"][census_idx]: + idx_census = mcdc["idx_census"] + if P["t"] > mcdc["setting"]["census_time"][idx_census]: P["t"] += SHIFT kernel.add_particle(P, mcdc["bank_census"]) else: @@ -757,12 +763,12 @@ def loop_source_precursor(seed, mcdc): # Sample emission time P_new["t"] = -math.log(kernel.rng(P_new)) / decay - census_idx = mcdc["technique"]["census_idx"] - if census_idx > 0: - P_new["t"] += mcdc["technique"]["census_time"][census_idx - 1] + idx_census = mcdc["idx_census"] + if idx_census > 0: + P_new["t"] += mcdc["setting"]["census_time"][idx_census - 1] # Accept if it is inside current census index - if P_new["t"] < mcdc["technique"]["census_time"][census_idx]: + if P_new["t"] < mcdc["setting"]["census_time"][idx_census]: # Reduce precursor weight DNP["w"] -= 1.0 diff --git a/mcdc/main.py b/mcdc/main.py index 5055dac3..e888951f 100644 --- a/mcdc/main.py +++ b/mcdc/main.py @@ -29,7 +29,7 @@ import mcdc.type_ as type_ from mcdc.constant import * -from mcdc.loop import loop_main, loop_iqmc +from mcdc.loop import loop_fixed_source, loop_eigenvalue, loop_iqmc from mcdc.print_ import print_banner, print_msg, print_runtime, print_header_eigenvalue # Get input_deck @@ -63,10 +63,12 @@ def run(): # Run simulation simulation_start = MPI.Wtime() - if not mcdc["technique"]["iQMC"]: - loop_main(mcdc) - else: + if mcdc["technique"]["iQMC"]: loop_iqmc(mcdc) + elif mcdc["setting"]["mode_eigenvalue"]: + loop_eigenvalue(mcdc) + else: + loop_fixed_source(mcdc) mcdc["runtime_simulation"] = MPI.Wtime() - simulation_start # Output: generate hdf5 output files @@ -166,6 +168,7 @@ def prepare(): type_.make_type_lattice(input_deck.lattices) type_.make_type_source(G) type_.make_type_tally(N_tally_scores, input_deck.tally) + type_.make_type_setting(input_deck) type_.make_type_technique(N_particle, G, input_deck.technique) type_.make_type_global(input_deck) kernel.adapt_rng(nb.config.DISABLE_JIT) @@ -302,7 +305,6 @@ def prepare(): "weight_roulette", "iQMC", "IC_generator", - "time_census", "branchless_collision", ]: mcdc["technique"][name] = input_deck.technique[name] @@ -391,16 +393,6 @@ def prepare(): np.random.seed(seed) mcdc["technique"]["iqmc_lds"] = np.random.random((N, N_dim)) - # ========================================================================= - # Time census - # ========================================================================= - - # Census time - mcdc["technique"]["census_time"] = input_deck.technique["census_time"] - - # Census index - mcdc["technique"]["census_idx"] = 0 - # ========================================================================= # Derivative Source Method # ========================================================================= @@ -542,7 +534,7 @@ def generate_hdf5(mcdc): print_msg("") print_msg(" Generating output HDF5 files...") - with h5py.File(mcdc["setting"]["output"] + ".h5", "w") as f: + with h5py.File(mcdc["setting"]["output_name"] + ".h5", "w") as f: # Input deck if mcdc["setting"]["save_input_deck"]: input_group = f.create_group("input_deck") @@ -670,7 +662,7 @@ def generate_hdf5(mcdc): def closeout(mcdc): # Runtime if mcdc["mpi_master"]: - with h5py.File(mcdc["setting"]["output"] + ".h5", "a") as f: + with h5py.File(mcdc["setting"]["output_name"] + ".h5", "a") as f: for name in [ "total", "preparation", diff --git a/mcdc/print_.py b/mcdc/print_.py index e6cb8b69..70ac1f91 100644 --- a/mcdc/print_.py +++ b/mcdc/print_.py @@ -67,13 +67,13 @@ def print_progress(percent, mcdc): if master: sys.stdout.write("\r") if not mcdc["setting"]["mode_eigenvalue"]: - if not mcdc["technique"]["time_census"]: + if mcdc["setting"]["N_census"] == 1: sys.stdout.write( " [%-28s] %d%%" % ("=" * int(percent * 28), percent * 100.0) ) else: - idx = mcdc["technique"]["census_idx"] + 1 - N = len(mcdc["technique"]["census_time"]) + idx = mcdc["idx_census"] + 1 + N = len(mcdc["setting"]["census_time"]) sys.stdout.write( " Census %i/%i: [%-28s] %d%%" % (idx, N, "=" * int(percent * 28), percent * 100.0) @@ -105,27 +105,29 @@ def print_header_eigenvalue(mcdc): def print_progress_eigenvalue(mcdc): if master: - i_cycle = mcdc["i_cycle"] + idx_cycle = mcdc["idx_cycle"] k_eff = mcdc["k_eff"] k_avg = mcdc["k_avg_running"] k_sdv = mcdc["k_sdv_running"] - gr = mcdc["gyration_radius"][i_cycle] + gr = mcdc["gyration_radius"][idx_cycle] if mcdc["setting"]["progress_bar"]: sys.stdout.write("\r") sys.stdout.write("\033[K") if mcdc["setting"]["gyration_radius"]: if not mcdc["cycle_active"]: - print(" %-4i %.5f %6.2f" % (i_cycle + 1, k_eff, gr)) + print(" %-4i %.5f %6.2f" % (idx_cycle + 1, k_eff, gr)) else: print( " %-4i %.5f %6.2f %.5f +/- %.5f" - % (i_cycle + 1, k_eff, gr, k_avg, k_sdv) + % (idx_cycle + 1, k_eff, gr, k_avg, k_sdv) ) else: if not mcdc["cycle_active"]: - print(" %-4i %.5f" % (i_cycle + 1, k_eff)) + print(" %-4i %.5f" % (idx_cycle + 1, k_eff)) else: - print(" %-4i %.5f %.5f +/- %.5f" % (i_cycle + 1, k_eff, k_avg, k_sdv)) + print( + " %-4i %.5f %.5f +/- %.5f" % (idx_cycle + 1, k_eff, k_avg, k_sdv) + ) def print_iqmc_eigenvalue_progress(mcdc): diff --git a/mcdc/type_.py b/mcdc/type_.py index e9d415cb..08fa5089 100644 --- a/mcdc/type_.py +++ b/mcdc/type_.py @@ -11,7 +11,7 @@ bool_ = np.bool_ str_ = "U30" -# MC/DC types, will be defined by input deck +# MC/DC types, will be defined based on input deck particle = None particle_record = None nuclide = None @@ -21,6 +21,7 @@ universe = None lattice = None source = None +setting = None tally = None technique = None global_ = None @@ -447,32 +448,45 @@ def make_type_score(shape): # ============================================================================== -setting = np.dtype( - [ - ("N_particle", int64), - ("N_inactive", int64), - ("N_active", int64), - ("N_cycle", int64), +def make_type_setting(deck): + global setting + + card = deck.setting + struct = [ + # Basic MC simulation parameters + ("N_particle", uint64), ("rng_seed", uint64), ("time_boundary", float64), - ("bank_active_buff", int64), + # Misc. + ("progress_bar", bool_), + ("output_name", "U30"), + ("save_input_deck", bool_), + ("track_particle", bool_), + # Eigenvalue mode ("mode_eigenvalue", bool_), ("k_init", float64), + ("N_inactive", uint64), + ("N_active", uint64), + ("N_cycle", uint64), + ("save_particle", bool_), ("gyration_radius", bool_), - ("gyration_radius_type", int64), - ("output", "U30"), - ("progress_bar", bool_), + ("gyration_radius_type", uint64), + # Time census + ("N_census", uint64), + ("census_time", float64, (card["N_census"],)), + # Particle source file ("source_file", bool_), ("source_file_name", "U30"), - ("track_particle", bool_), - ("save_particle", bool_), - ("save_input_deck", bool_), + # Initial condition source file ("IC_file", bool_), ("IC_file_name", "U30"), - ("N_precursor", int64), - ("N_sensitivity", int64), + ("N_precursor", uint64), + # TODO: Move to technique + ("N_sensitivity", uint64), ] -) + + # Finalize setting type + setting = np.dtype(struct) # ============================================================================== @@ -492,7 +506,6 @@ def make_type_technique(N_particle, G, card): ("weight_roulette", bool_), ("iQMC", bool_), ("IC_generator", bool_), - ("time_census", bool_), ("branchless_collision", bool_), ] @@ -571,15 +584,6 @@ def make_type_technique(N_particle, G, card): ("iqmc_sweep_counter", int64), ] - # ========================================================================= - # Time census - # ========================================================================= - - struct += [ - ("census_time", float64, (len(card["census_time"]),)), - ("census_idx", int64), - ] - # ========================================================================= # IC generator # ========================================================================= @@ -659,7 +663,7 @@ def make_type_global(card): # Particle bank types bank_active = particle_bank(1 + bank_active_buff) - if card.setting["mode_eigenvalue"] or card.technique["time_census"]: + if card.setting["mode_eigenvalue"] or card.setting["N_census"] > 1: bank_census = particle_bank(int((1 + bank_census_buff) * N_work)) bank_source = particle_bank(int((1 + bank_census_buff) * N_work)) else: @@ -721,11 +725,12 @@ def make_type_global(card): ("k_avg_running", float64), ("k_sdv_running", float64), ("gyration_radius", float64, (N_cycle,)), - ("i_cycle", int64), + ("idx_cycle", int64), ("cycle_active", bool_), ("eigenvalue_tally_nuSigmaF", float64), ("eigenvalue_tally_n", float64), ("eigenvalue_tally_C", float64), + ("idx_census", int64), ("mpi_size", int64), ("mpi_rank", int64), ("mpi_master", bool_), From 16bf829de7f1d069e944a4c81ed2eb2dbe565976 Mon Sep 17 00:00:00 2001 From: ilhamv Date: Sun, 3 Sep 2023 22:49:17 -0700 Subject: [PATCH 2/3] replace output with output_name --- examples/eigenvalue/2d_c5g7_iqmc/input.py | 2 +- .../eigenvalue/slab_2gu_iqmc/test.py | 4 +- .../eigenvalue/slab_kornreich_iqmc/test.py | 4 +- .../fixed_source/cooper2_iqmc/test.py | 4 +- .../regression/fixed_source/reed_iqmc/test.py | 4 +- test/unit/test_loop.py | 41 ------------------- .../fixed_source/azurv1_pl_super/input.py | 2 +- .../fixed_source/inf_shem361/input.py | 2 +- .../fixed_source/inf_shem361_td/input.py | 2 +- .../analytic/fixed_source/reed/input.py | 2 +- .../fixed_source/slab_absorbium/input.py | 2 +- .../fixed_source/slab_isobeam_td/input.py | 2 +- 12 files changed, 15 insertions(+), 56 deletions(-) delete mode 100644 test/unit/test_loop.py diff --git a/examples/eigenvalue/2d_c5g7_iqmc/input.py b/examples/eigenvalue/2d_c5g7_iqmc/input.py index 7258a50b..b062f322 100644 --- a/examples/eigenvalue/2d_c5g7_iqmc/input.py +++ b/examples/eigenvalue/2d_c5g7_iqmc/input.py @@ -205,7 +205,7 @@ def set_mat(mat): # Setting -mcdc.setting(N_particle=N, output="davidson_output") +mcdc.setting(N_particle=N, output_name="davidson_output") mcdc.eigenmode() # Run diff --git a/test/regression/eigenvalue/slab_2gu_iqmc/test.py b/test/regression/eigenvalue/slab_2gu_iqmc/test.py index d345d1c5..26010bac 100644 --- a/test/regression/eigenvalue/slab_2gu_iqmc/test.py +++ b/test/regression/eigenvalue/slab_2gu_iqmc/test.py @@ -65,7 +65,7 @@ def pi_test(): eigenmode_solver=solver, ) # Setting - mcdc.setting(N_particle=N, output="pi_output") + mcdc.setting(N_particle=N, output_name="pi_output") mcdc.eigenmode() # Run @@ -152,7 +152,7 @@ def davidson_test(): eigenmode_solver=solver, ) # Setting - mcdc.setting(N_particle=N, output="davidson_output") + mcdc.setting(N_particle=N, output_name="davidson_output") mcdc.eigenmode() # Run diff --git a/test/regression/eigenvalue/slab_kornreich_iqmc/test.py b/test/regression/eigenvalue/slab_kornreich_iqmc/test.py index e78cb4ad..a4070a5f 100644 --- a/test/regression/eigenvalue/slab_kornreich_iqmc/test.py +++ b/test/regression/eigenvalue/slab_kornreich_iqmc/test.py @@ -64,7 +64,7 @@ def pi_test(): eigenmode_solver=solver, ) # Setting - mcdc.setting(N_particle=N, output="pi_output") + mcdc.setting(N_particle=N, output_name="pi_output") mcdc.eigenmode() # Run @@ -146,7 +146,7 @@ def davidson_test(): eigenmode_solver=solver, ) # Setting - mcdc.setting(N_particle=N, output="davidson_output") + mcdc.setting(N_particle=N, output_name="davidson_output") mcdc.eigenmode() # Run diff --git a/test/regression/fixed_source/cooper2_iqmc/test.py b/test/regression/fixed_source/cooper2_iqmc/test.py index f98fc9aa..7d96b7cd 100644 --- a/test/regression/fixed_source/cooper2_iqmc/test.py +++ b/test/regression/fixed_source/cooper2_iqmc/test.py @@ -67,7 +67,7 @@ def si_test(): # Set tally, setting, and run mcdc # ============================================================================= # Setting - mcdc.setting(N_particle=N, progress_bar=False, output="si_output") + mcdc.setting(N_particle=N, progress_bar=False, output_name="si_output") # Run mcdc.run() # ========================================================================= @@ -147,7 +147,7 @@ def gmres_test(): # Set tally, setting, and run mcdc # ============================================================================= # Setting - mcdc.setting(N_particle=N, progress_bar=False, output="gmres_output") + mcdc.setting(N_particle=N, progress_bar=False, output_name="gmres_output") # Run mcdc.run() # ========================================================================= diff --git a/test/regression/fixed_source/reed_iqmc/test.py b/test/regression/fixed_source/reed_iqmc/test.py index bfb15e75..4fe9ca66 100644 --- a/test/regression/fixed_source/reed_iqmc/test.py +++ b/test/regression/fixed_source/reed_iqmc/test.py @@ -65,7 +65,7 @@ def si_test(): ) # Setting - mcdc.setting(N_particle=N, progress_bar=False, output="si_output") + mcdc.setting(N_particle=N, progress_bar=False, output_name="si_output") # Run mcdc.run() @@ -144,7 +144,7 @@ def gmres_test(): ) # Setting - mcdc.setting(N_particle=N, progress_bar=False, output="gmres_output") + mcdc.setting(N_particle=N, progress_bar=False, output_name="gmres_output") # Run mcdc.run() diff --git a/test/unit/test_loop.py b/test/unit/test_loop.py deleted file mode 100644 index 4c1258d1..00000000 --- a/test/unit/test_loop.py +++ /dev/null @@ -1,41 +0,0 @@ -import numpy as np -from mcdc.loop import loop_particle, loop_main, loop_source -import mcdc.type_ as type_ -import mcdc.card -from mcdc.constant import INF - - -def loop_setup_test(): - type_.make_type_surface(1) - type_.make_type_particle(False, 0) - P = np.zeros(1, dtype=type_.particle)[0] - S = np.zeros(1, dtype=type_.surface)[0] - - x = 5.0 - trans = np.array([0.0, 0.0, 0.0]) - - S["G"] = 1.0 - S["linear"] = True - S["J"] = np.array([-x, -x]) - S["t"] = np.array([0.0, INF]) - - # Surface on the left - P["x"] = 4.0 - - # setup_card = card.InputCard() - - # mcdc = - - assert 0 == 0 - - -def test_loop_main(): - # [P, S] = loop_setup_test() - - print("This worked") - assert 0 == 0 - - -def test_loop_particle(): - print("This worked") - assert 0 == 0 diff --git a/test/verification/analytic/fixed_source/azurv1_pl_super/input.py b/test/verification/analytic/fixed_source/azurv1_pl_super/input.py index ab5aa8cc..0173747d 100644 --- a/test/verification/analytic/fixed_source/azurv1_pl_super/input.py +++ b/test/verification/analytic/fixed_source/azurv1_pl_super/input.py @@ -47,7 +47,7 @@ # Setting mcdc.setting( - N_particle=N_particle, output="output_" + str(N_particle), progress_bar=False + N_particle=N_particle, output_name="output_" + str(N_particle), progress_bar=False ) # Run diff --git a/test/verification/analytic/fixed_source/inf_shem361/input.py b/test/verification/analytic/fixed_source/inf_shem361/input.py index cafbdfdc..1b77cc26 100644 --- a/test/verification/analytic/fixed_source/inf_shem361/input.py +++ b/test/verification/analytic/fixed_source/inf_shem361/input.py @@ -59,7 +59,7 @@ # Setting mcdc.setting( N_particle=N_particle, - output="output_" + str(N_particle), + output_name="output_" + str(N_particle), active_bank_buff=1000, progress_bar=False, ) diff --git a/test/verification/analytic/fixed_source/inf_shem361_td/input.py b/test/verification/analytic/fixed_source/inf_shem361_td/input.py index d79dfc53..4f2f2026 100644 --- a/test/verification/analytic/fixed_source/inf_shem361_td/input.py +++ b/test/verification/analytic/fixed_source/inf_shem361_td/input.py @@ -61,7 +61,7 @@ # Setting mcdc.setting( N_particle=N_particle, - output="output_" + str(N_particle), + output_name="output_" + str(N_particle), active_bank_buff=10000, progress_bar=False, ) diff --git a/test/verification/analytic/fixed_source/reed/input.py b/test/verification/analytic/fixed_source/reed/input.py index 279c9008..495a0b61 100644 --- a/test/verification/analytic/fixed_source/reed/input.py +++ b/test/verification/analytic/fixed_source/reed/input.py @@ -49,7 +49,7 @@ # Setting mcdc.setting( - N_particle=N_particle, output="output_" + str(N_particle), progress_bar=False + N_particle=N_particle, output_name="output_" + str(N_particle), progress_bar=False ) # Run diff --git a/test/verification/analytic/fixed_source/slab_absorbium/input.py b/test/verification/analytic/fixed_source/slab_absorbium/input.py index 05675ee2..9e585c9b 100644 --- a/test/verification/analytic/fixed_source/slab_absorbium/input.py +++ b/test/verification/analytic/fixed_source/slab_absorbium/input.py @@ -46,7 +46,7 @@ # Setting mcdc.setting( - N_particle=N_particle, output="output_" + str(N_particle), progress_bar=False + N_particle=N_particle, output_name="output_" + str(N_particle), progress_bar=False ) # Run diff --git a/test/verification/analytic/fixed_source/slab_isobeam_td/input.py b/test/verification/analytic/fixed_source/slab_isobeam_td/input.py index 76dc0389..f9e55eb4 100644 --- a/test/verification/analytic/fixed_source/slab_isobeam_td/input.py +++ b/test/verification/analytic/fixed_source/slab_isobeam_td/input.py @@ -40,7 +40,7 @@ # Setting mcdc.setting( - N_particle=N_particle, output="output_" + str(N_particle), progress_bar=False + N_particle=N_particle, output_name="output_" + str(N_particle), progress_bar=False ) # Run From 6af9c314d6732a5a2c9ccfcecd526119a159b613 Mon Sep 17 00:00:00 2001 From: ilhamv Date: Sun, 3 Sep 2023 23:06:27 -0700 Subject: [PATCH 3/3] minor comment change --- mcdc/loop.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mcdc/loop.py b/mcdc/loop.py index 7727a411..c54fc8d2 100644 --- a/mcdc/loop.py +++ b/mcdc/loop.py @@ -43,11 +43,9 @@ def loop_fixed_source(mcdc): # Time census closeout if idx_census < mcdc["setting"]["N_census"] - 1: - # TODO: Make census actions optional + # TODO: Output tally (optional) - # Output tally - - # Manage particle banks: population control and wor rebalance + # Manage particle banks: population control and work rebalance seed_bank = kernel.split_seed(seed_census, SEED_SPLIT_BANK) kernel.manage_particle_banks(seed_bank, mcdc)