def graph(nuc): """Returns a graphviz Digraph object for the decay chain starting from nuc.""" i = nucname.name(nuc) name = nucname.name(nuc) dot = Digraph(comment='Decay chain for ' + nuc) dot.node(name) nodes_seen = {name} kids = data.decay_children(i) from_to = {(i, j) for j in kids} edges_seen = set() while len(from_to) != 0: new_from_to = set() for ft in from_to: i, j = ft jname = nucname.name(j) if jname not in nodes_seen: dot.node(jname) nodes_seen.add(jname) if ft not in edges_seen: iname = nucname.name(i) try: label = rxname.name(i, j, 'decay') except RuntimeError: label = 'sf' label = PRETTY_RX.get(label, label) br = data.branch_ratio(i, j) if br < 1.0: label += ', br={0:.3}'.format(br) dot.edge(iname, jname, label=label) edges_seen.add(ft) kids = data.decay_children(j) new_from_to |= {(j, k) for k in kids} from_to = new_from_to return dot
def _generate_xs(self, e_g, phi_g): """Grab xs data from cache depending on group flux. Parameters ---------- e_g : list of floats Group structure. phi_g : list of floats Group flux. Returns ------- data : list of tuples A list of tuples of the format (nuc, rx, xs). """ rc = self.rc verbose = rc.verbose xscache = self.xscache xscache['E_g'] = e_g xscache['phi_g'] = phi_g G = len(phi_g) temp = rc.temperature rxs = self.reactions nucs = rc.track_nucs dt = np.dtype([('nuc', 'i4'), ('rx', np.uint32), ('xs', 'f8', G)]) data = np.empty(len(nucs)*len(rxs), dtype=dt) i = 0 for nuc in nucs: for rx in rxs: xs = xscache[nuc, rx, temp] if verbose: print("OpenMC XS:", nucname.name(nuc), rxname.name(rx), xs, temp) data[i] = nuc, rx, xs i += 1 return data
def test_name_mts(): assert_equal(rxname.name(107), "a") assert_equal(rxname.name(1), "total") assert_equal(rxname.name(long(107)), "a") assert_equal(rxname.name(long(1)), "total") assert_equal(rxname.name("107"), "a") assert_equal(rxname.name("1"), "total")
def test_name_ids(): assert_equal(rxname.name(_hash("a")), "a") assert_equal(rxname.name(_hash("total")), "total") assert_equal(rxname.name(long(_hash("a"))), "a") assert_equal(rxname.name(long(_hash("total"))), "total") assert_equal(rxname.name(str(_hash("a"))), "a") assert_equal(rxname.name(str(_hash("total"))), "total")
def _generate_xs(self, phi_g): rc = self.rc verbose = rc.verbose xscache = self.xscache xscache['E_g'] = rc.group_structure xscache['phi_g'] = phi_g G = len(phi_g) temp = rc.temperature rxs = self.reactions nucs = rc.core_transmute dt = np.dtype([('nuc', 'i4'), ('rx', np.uint32), ('xs', 'f8', G)]) data = np.empty(len(nucs)*len(rxs), dtype=dt) i = 0 for nuc in nucs: for rx in rxs: xs = xscache[nuc, rx, temp] if verbose: print("OpenMC XS:", nucname.name(nuc), rxname.name(rx), xs) data[i] = nuc, rx, xs i += 1 return data
def test_name_nucdelta(): assert_equal(rxname.name("U235", "U236"), "absorption") assert_equal(rxname.name("U235", "Np236", "p"), "absorption") assert_equal(rxname.name(922350, 912350), "p")
def test_name_alts(): assert_equal(rxname.name("alpha"), "a") assert_equal(rxname.name("tot"), "total")
def test_name_names(): assert_equal(rxname.name("a"), "a") assert_equal(rxname.name("total"), "total")
tw = TextWrapper(initial_indent=" ", subsequent_indent=" ", break_long_words=False) style = {"style": "margin-left:auto;margin-right:auto;"} rxtab = PrettyTable(['reaction', 'id', 'description']) rxtab.align['reaction'] = 'l' rxtab.align['id'] = 'r' rxtab.align['description'] = 'l' for name in sorted(rxname.names): rxtab.add_row(["'" + name + "'", rxname.id(name), rxname.doc(name)]) rxtab = "\n".join(tw.wrap(rxtab.get_html_string(attributes=style))) aliastab = PrettyTable(['alias', 'reaction']) aliastab.align['alias'] = 'l' aliastab.align['reaction'] = 'l' for alias, rxid in sorted(rxname.altnames.items()): aliastab.add_row(["'" + alias + "'", "'" + rxname.name(rxid) + "'"]) aliastab = "\n".join(tw.wrap(aliastab.get_html_string(attributes=style))) _rxname_rst = """**Reactions:** .. raw:: html <div> {0} </div> **Reaction Aliases:** .. raw:: html <div>
def write(self, libs, dirname): """Write out libraries to a directory. Parameters ---------- libs : dict The reactor libraries gleaned from buk. dirname : str The output directory. """ if not os.path.isdir(dirname): os.makedirs(dirname) rownames = ["TIME", "NEUT_PROD", "NEUT_DEST", "BUd"] for mat, matlib in libs.items(): if isinstance(mat, int): fname = str(nucname.zzaaam(mat)) elif mat == 'fuel': fname = mat else: continue lines = [row + " " + " ".join(map(str, matlib[row])) for row in rownames] nucs = matlib["tracked_nucs"] lines.extend(sorted([n + " " + " ". join(["{:.4g}".format(f) for f in nucs[n]]) for n in nucs])) with open(os.path.join(dirname, fname + ".txt"), "w") as f: f.write("\n".join(lines)) track_actinides = [n for n in nucs if nucname.znum(n) in nucname.act] with open(os.path.join(dirname, "manifest.txt"), "w") as f: f.write("\n".join([str(nucname.zzaaam(act)) for act in track_actinides])) f.write("\n") with open(os.path.join(dirname, "params.txt"), "w") as f: if self.rc.get("enrichment") is None: enrichment = self.rc.initial_heavy_metal.get(922350) else: enrichment = self.rc.enrichment if enrichment is not None: f.write("ENRICHMENT {}\n".format(enrichment)) if self.rc.get("batches") is not None: f.write("BATCHES {}\n".format(self.rc.batches)) if self.rc.get("pnl") is not None: f.write("PNL {}\n".format(self.rc.pnl)) f.write("BURNUP {}\n".format(sum(libs["fuel"]["BUd"]))) f.write("FLUX {:.0E}\n".format(np.mean(libs["fuel"]["phi_tot"][1:]))) with open(os.path.join(dirname, "structural.txt"), "w") as f: clad_linear_density = pi * self.rc.clad_density * \ (self.rc.clad_cell_radius ** 2 - self.rc.void_cell_radius ** 2) fuel_linear_density = pi * self.rc.fuel_density * \ self.rc.fuel_cell_radius ** 2 clad_frac = float(clad_linear_density / fuel_linear_density) cladrows = ["{} {:.8f}".format(nucname.zzaaam(n), f*clad_frac) for n, f in self.rc.clad_material.comp.items()] f.write("\n".join(cladrows)) f.write("\n") shutil.copyfile("TAPE9.INP", os.path.join(dirname, "TAPE9.INP")) # write cross section json file xsdata = [[[nucname.name(int(n)), rxname.name(int(r)), float(x)] for n, r, x in lib] for lib in libs['xs']] with open(os.path.join(dirname, 'xs.json'), 'w') as f: json.dump(xsdata, f, sort_keys=True, indent=1, separators=(', ', ': ')) # write flux json file with open(os.path.join(dirname, 'phi_g.json'), 'w') as f: json.dump(libs['phi_g'], f, sort_keys=True, indent=1, separators=(', ', ': '))