def makeTable(G, trunc=False): ''' ''' data = readData(G) groupMask, counts, mask, extraName = getGroupBounds(G, 3) maxOrder = max(getGroupBounds(G, 3)[1].values()) order = 2 table = np.zeros((11, 11)) # Load the reference table[0, 0] = data['k']['ref'] table[1:, 0] = data['dens']['ref'] for homog in range(5): # Get the non-energy truncated results table[0, homog + 1] = data['k']['klt_combine'][homog][maxOrder - 1] table[1:, homog + 1] = data['dens']['klt_combine'][homog][maxOrder - 1] # Get the energy truncated results table[0, homog + 6] = data['k']['klt_combine'][homog][order] table[1:, homog + 6] = data['dens']['klt_combine'][homog][order] table = table[:, [0, 6, 7, 8, 9, 10]] if trunc else table[:, [0, 2, 3, 4, 5]] label = ['$k_{\\text{eff}}$', 'Cell {}'] print '\nData table for Truncation={}'.format(trunc) for i, row in enumerate(table): head = label[0] if i == 0 else label[1].format(i) print head + '&' + ' & '.join(['{: 4.3f}'.format(r) for r in row]) + '\\\\' if i == 0: print '\\hline'
def readData(G): ''' Reads data from the data directory that has been make via Unotran Returns the % relative error for both k and pin-cell fission density ''' groupMask, counts, mask, extraName = getGroupBounds(G, 3) maxOrder = max(getGroupBounds(G, 3)[1].values()) data = {} for d in ['dens', 'k']: # Load the reference try: ref = np.load('reference/ref_{}_{}_{}.npy'.format(d, 'full', G)) if d == 'dens': # Normalize the reference ref /= np.linalg.norm(ref) # Get the density for each pin ref = np.sum(ref.reshape(10, -1), axis=1) ref /= np.mean(ref) except IOError: raise IOError('Missing reference for {} with {} groups'.format( d, G)) data[d] = {} # Add the reference to the data data[d]['ref'] = ref for basis in [ 'dlp', 'klt_full', 'klt_combine', 'klt_uo2', 'klt_mox', 'klt_pins_full' ]: data[d][basis] = {} for homog in range(5): data[d][basis][homog] = [] for o in range(maxOrder): # Load the data try: sol = np.load( 'data/dgm_{}_{}_{}_g{}_c{}_o{}_h{}.npy'.format( d, basis, 'full', G, 3, o, homog)) if d == 'dens': sol /= np.linalg.norm(sol) sol = np.sum(sol.reshape(10, -1), axis=1) sol /= np.mean(sol) except IOError as e: print('Missing data/dgm_{}_{}_{}_g{}_c{}_o{}_h{}.npy'. format(d, basis, 'full', G, 3, o, homog)) sol = np.zeros(ref.shape) # Compute the error err = (sol - ref) / ref * 100 data[d][basis][homog].append(err) return data
def plot(A, basisType, contig, bName): colors = ['b', 'g', 'm'] plt.clf() G = A.shape[1] groupMask, counts, mask, extraName = getGroupBounds(G, contig) bounds = [0] for i, a in enumerate(A): ming = 0 for CG, nGroups in counts.items(): maxg = ming + nGroups plt.plot(range(ming, maxg), a[ming:maxg], c=colors[i], label='order {}'.format(i)) bounds.append(maxg) ming += nGroups bounds = np.array(bounds) plt.vlines(bounds[1:-1] - 0.5, -1, 1) plt.xlim([0, G - 1]) plt.ylim([-1, 1]) plt.xlabel('Energy group') plt.ylabel('Normalized basis') handles, labels = plt.gca().get_legend_handles_labels() by_label = OrderedDict(zip(labels, handles)) legend = plt.legend(by_label.values(), by_label.keys(), loc='upper center', ncol=3, fancybox=True, framealpha=0.0, bbox_to_anchor=(0.5, 1.1)) plt.savefig('{}.png'.format(bName), transparent=True, additional_artists=[legend]) return
def makeBasis(G, contig): # Get the coarse group bounds groupMask, counts, mask, extraName = getGroupBounds(G, contig) eName = ('_' + extraName) if extraName is not None else '' print 'building {0}{2}_{1}g'.format('dlp', G, eName) print counts # Initialize the basis lists basis = np.zeros((G, G)) # Compute the basis for each coarse group for group, order in counts.items(): # Get the DLP basis for the given order A = DLP(order) # Get the mask for the currect group m = groupMask == group #plt.plot(A[np.argsort(mask[m]), :3]) # plt.show() # Slice into the basis with the current group basis[np.ix_(m, m)] = A[np.argsort(mask[m])] testBasis(basis) # Save the basis to file bName = 'basis/{0}{2}_{1}g'.format('dlp', G, eName) np.savetxt(bName, basis) plotBasis(G, bName)
def makePlots(G, pType='phi'): ''' ''' groupMask, counts, mask, extraName = getGroupBounds(G, 3) maxOrder = max(getGroupBounds(G, 3)[1].values()) lowOrder = 2 fm, cm, mm, bounds = setGeometry('full') dx = [] for i, c in enumerate(cm): if i == len(cm) - 1: break for x in np.linspace(c, cm[i + 1], fm[i] + 1)[:-1]: dx.append(x) dx.append(cm[-1]) dx = np.array(dx) x = 0.5 * (dx[1:] + dx[:-1]) labels = ['Case 1', 'Case 2', 'Case 3', 'Case 4'] ls = [':', '-', '-.', '--'] for order in [lowOrder, maxOrder - 1]: for group in (range(G) if pType == 'phi' else [0]): ref = np.load('reference/ref_{}_{}_{}.npy'.format( pType, 'full', G)) if pType == 'phi': ref = ref[0, group] ref /= np.linalg.norm(ref) plt.plot(x, ref, label='Reference') for homog in range(1, 5): sol = np.load('data/dgm_{}_{}_{}_g{}_c{}_o{}_h{}.npy'.format( pType, 'klt_combine', 'full', G, 3, order, homog)) if pType == 'phi': sol = sol[0, group] sol /= np.linalg.norm(sol) plt.plot(x, sol, ls=ls[homog - 1], label=labels[homog - 1]) plt.legend(fancybox=True, framealpha=0.0) plt.xlabel('length [cm]') plt.ylabel('normalized scalar flux' if pType == 'phi' else 'normalized fission density') plt.xlim([0.0, 12.8]) plt.savefig('plots/{}_g{}_o{}.png'.format(pType, group, order), transparent=True) plt.clf()
def getInfo(task): Gs = [44, 238, 1968] item = 0 for G in Gs: makeSnapPlot = True for contig in [3]: # makePlot(G) for basisType in ['uo2', 'mox', 'pins_full', 'combine', 'full', 'pins_core1', 'pins_core2', 'assay_12', 'assay_13', 'assay_all', 'core1', 'core2']: if makeSnapPlot: makePlot(G) makeSnapePlot = False if item == task: x = getGroupBounds(G, contig)[1] print x, np.cumsum(x.values()) return G, basisType, contig else: item += 1
def setGroup(G, contig, order=None, basisType='dlp'): groupBounds, counts, mask, bName = getGroupBounds(G, contig) pydgm.control.xs_name = 'XS/{}gXS.anlxs'.format(G).ljust(256) print 'using basis basis/{}_{}_{}g'.format(basisType, bName, G) pydgm.control.dgm_basis_name = 'basis/{}_{}_{}g'.format( basisType, bName, G).ljust(256) if order is not None: print basisType, G, counts.values(), order, [ min(d - 1, order) for d in counts.values() ] pydgm.control.truncation_map = [ min(d - 1, order) for d in counts.values() ] if len(groupBounds) > 0: pydgm.control.energy_group_map = np.array(groupBounds) + 1
def getInfo(task): Gs = [44, 238, 1968] geos = ['full'] contigs = [3] item = 0 for i, G in enumerate(Gs): for homogOption in [0, 1, 2, 3, 4]: for contig in contigs: maxOrder = max(getGroupBounds(G, contig)[1].values()) for geo in geos: # Select the basis based on the geometry if geo == 0: basisTypes = ['dlp'] elif geo == 'full': basisTypes = [ 'dlp', 'klt_full', 'klt_combine', 'klt_uo2', 'klt_mox', 'klt_pins_full' ] elif geo == 'core1': basisTypes = [ 'dlp', 'klt_assay_12', 'klt_assay_all', 'klt_core1', 'klt_pins_core1' ] elif geo == 'core2': basisTypes = [ 'dlp', 'klt_assay_13', 'klt_assay_all', 'klt_core2', 'klt_pins_core2' ] for j, basisType in enumerate(basisTypes): for order in range(maxOrder): if item == task: return geo, G, basisType, order, contig, homogOption else: item += 1
def makeBasis(G, basisType, contig, flat=False): if basisType == 'full': name = 'klt_full' data = getSnapshots(G, 'full') elif basisType == 'mox': name = 'klt_mox' data = getSnapshots(G, 'mox') elif basisType == 'uo2': name = 'klt_uo2' data = getSnapshots(G, 'uo2-1') elif basisType == 'pins_full': name = 'klt_pins_full' data = np.concatenate((getSnapshots(G, 'uo2-1'), getSnapshots(G, 'mox')), axis=1) elif basisType == 'pins_core1': name = 'klt_pins_core1' data = np.concatenate((getSnapshots(G, 'uo2-1'), getSnapshots(G, 'uo2-2'), getSnapshots(G, 'uo2-Gd')), axis=1) elif basisType == 'pins_core2': name = 'klt_pins_core2' data = np.concatenate((getSnapshots(G, 'uo2-1'), getSnapshots(G, 'uo2-2'), getSnapshots(G, 'mox')), axis=1) elif basisType == 'combine': name = 'klt_combine' data = np.concatenate((getSnapshots(G, 'uo2-1'), getSnapshots(G, 'mox'), getSnapshots(G, 'junction')), axis=1) elif basisType == 'core1': name = 'klt_core1' data = getSnapshots(G, 'core1') elif basisType == 'core2': name = 'klt_core2' data = getSnapshots(G, 'core2') elif basisType == 'assay_12': name = 'klt_assay_12' data = np.concatenate((getSnapshots(G, 'assay1'), getSnapshots(G, 'assay2')), axis=1) elif basisType == 'assay_13': name = 'klt_assay_13' data = np.concatenate((getSnapshots(G, 'assay1'), getSnapshots(G, 'assay3')), axis=1) elif basisType == 'assay_all': name = 'klt_assay_all' data = np.concatenate((getSnapshots(G, 'assay1'), getSnapshots(G, 'assay2'), getSnapshots(G, 'assay3')), axis=1) else: raise NotImplementedError('The type: {} has not been implemented'.format(basisType)) # Get the coarse group bounds groupMask, counts, mask, extraName = getGroupBounds(G, contig) eName = ('_' + extraName) if extraName is not None else '' # Initialize the basis lists basis = np.zeros((G, G)) # Compute the basis for each coarse group for group, order in counts.items(): # Get the mask for the currect group m = groupMask == group # Get the DLP basis for the given order A = KLT(data[m], flat) # Slice into the basis with the current group basis[np.ix_(m, m)] = A bName = 'basis/{0}{2}_{1}g'.format(name, G, eName) # Save the basis to file np.savetxt(bName, basis) plotBasis(G, basisType, contig, bName)
def run(): solver = 'eigen' geo = 'full' G = 44 basisType = 'dlp' contig = 3 order = 12 path = 'data' # Solve the DGM Problem setVariables(G, geo, solver, True, contig, basisType, order) # Setup the variable containers pydgm.dgmsolver.initialize_dgmsolver() # Give some dummy phi pydgm.state.phi = np.arange(np.product(pydgm.state.phi.shape)).reshape( pydgm.state.phi.shape) + 1 # Get the right shapes from the inputs nL, nG, nC = pydgm.state.phi.shape # Compute the flux momenst pydgm.dgmsolver.compute_flux_moments() # Get the flux moments and shape m_phi = pydgm.state.mg_phi[0].T nCG = m_phi.shape[1] # Compute the test cross sections pydgm.dgmsolver.compute_xs_moments() sig_t_test = pydgm.state.mg_sig_t # Get the group bounds groupBounds, counts, mask, bName = getGroupBounds(G, contig) nO = np.max(counts.values()) bounds = [0] for o in range(np.max(counts.keys()) + 1): bounds.append(bounds[o] + counts[o]) # Load the basis P = np.loadtxt('basis/{}_{}_{}g'.format(basisType, bName, G)) # Get the fine group flux phi = pydgm.state.phi[0, :, :] nMat = np.max(pydgm.mesh.mmap) # Create the XS containers ex_sig_t = np.zeros((nMat, nCG, nO)) m_sig_t = np.zeros((nC, nCG, nO)) # Loop over the spatial cells for m in range(nMat): # Get the fine XS sig_t = pydgm.material.sig_t[:, m] # Loop over the energy group for cg in range(nCG): P_G = P.T[bounds[cg]:bounds[cg + 1]] for gp in range(bounds[cg], bounds[cg + 1]): for o, p in enumerate(P_G): ex_sig_t[m, cg, o] += p[gp] * sig_t[gp] * P_G[0, gp] print ex_sig_t.shape print m_phi.shape for c in range(nC): pass exit() m_sig_t[j] = m_sig_t.dot(m_phi) / m_phi[0] print m_phi print m_sig_t.T print sig_t_test