def poltCR(foldname, ndict): path = foldname + '\\MOBATADS.OUT' mtr = McnpTallyReader() with open(path, 'r') as fid: for eachline in fid: title = eachline break namelists = re.split("\s{2,}", title.strip()) timetag = namelists[1] namelists.insert(1, 'dummy') results = pd.read_csv(path, sep='\s+', usecols=lambda x: x not in ['dummy'], skiprows=1, header=None, names=namelists) inpname = foldname[:-3] print(inpname) # print(results['Time(d)']) crlists = [] for ii in ndict.keys(): for jj in range(ndict[ii]): path = foldname + '\\' + inpname + 'o-' + str(ii) + '-' + str(jj + 1) crlists.append(mtr.getCR(path)) plt.plot(results['Time(d)'], crlists, '-o') # plt.xlim(0,1500) plt.xlabel('Time (days)') plt.ylabel('CR') plt.show()
mh.modifyinp(inp, 'm1', 'm1 ' + line, 'data') line = mh.readContent(inp, '4') print(line) # print(line.strip().split()[2]) newline = line.replace(line.strip().split()[2], '-{:.4f}'.format(density)) print(newline) mh.modifyinp(inp, '4', newline) changeMode(inp, mode='kcode') # os.system('mcnp5'+ ' n=' + inp) os.system('mpirun -r ssh -np ' + str(int(node * ppn)) + ' /home/daiye/bin/mcnp5.mpi n=' + inp) if os.path.isfile(inp + 'o'): print('MCNP5 run finished!') results['keff'] = mtr.readKeff(inp + 'o')['keff'] results['kCR'] = mtr.getCR(inp + 'o') k_totrate = mtr.readNeutronActivity(inp + 'o') results['kescape'] = k_totrate['escape']/(k_totrate['escape']\ +k_totrate['lossfission']+k_totrate['capture']) # escape of kcode mode if os.path.isfile(inp + 'o'): oldfilename = inp + 'o' newfilename = inp+'ko_'+str(mm)+'_'+str(kk)+'_'+'{:.4f}'.format(matdict[nacl])\ +'_'+'{:.4f}'.format(matdict[ucl3])+'_'+'{:.4f}'.format(matdict[thcl4]) mh.deleteFiles(newfilename) os.rename(oldfilename, newfilename) mh.cleanup(inp) else: print('error!!!,MCNP5 run failed!') exit(0) if results['keff'] < 0.998: changeMode(inp, mode='fixed')
mh.modifyinp(inp, 'm1', 'm1 ' + line, 'data') line = mh.readContent(inp, '4') print(line) # print(line.strip().split()[2]) newline = line.replace(line.strip().split()[2], '-{:.4f}'.format(density)) print(newline) mh.modifyinp(inp, '4', newline) changeMode(inp, mode='kcode') # os.system('mcnp5'+ ' n=' + inp) os.system('mpirun -r ssh -np ' + str(int(node * ppn)) + ' /home/daiye/bin/mcnp5.mpi n=' + inp) if os.path.isfile(inp + 'o'): print('MCNP5 run finished!') results['keff'] = mtr.readKeff(inp + 'o')['keff'] results['kCR'] = mtr.getCR(inp + 'o') k_totrate = mtr.readNeutronActivity(inp + 'o') results['kescape'] = k_totrate['escape']/(k_totrate['escape']\ +k_totrate['lossfission']+k_totrate['capture']) # escape of kcode mode if os.path.isfile(inp + 'o'): oldfilename = inp + 'o' newfilename = inp+'ko_'+str(mm)+'_'+str(kk)+'_'+str(matdict[nacl])\ +'_'+str(matdict[pucl3])+'_'+str(matdict[thcl4]) mh.deleteFiles(newfilename) os.rename(oldfilename, newfilename) mh.cleanup(inp) else: print('error!!!,MCNP5 run failed!') exit(0) if results['keff'] < 0.998: changeMode(inp, mode='fixed')
class Postprocesser(object): def __init__(self): self.mcnptallyreader = McnpTallyReader() self.mcnpinphandler = McnpinpHandler() def outputResults(self, filename, content, writeingmode='a'): with open(filename, writeingmode) as fid: fid.write(content) def renameFile(self, oldfilename, newfilename): self.mcnpinphandler.deleteFiles(newfilename) os.rename(oldfilename, newfilename) def readVolume(self, filename): volume = None with open(filename, 'r') as fid: context = fid.readlines() context = [line for line in context if len(line.strip().split()) == 1] line = re.findall(" \d\.\d{5}E[+-]\d{2}", ''.join(context))[0] volume = float(line) return volume def getKeff(self, mcnpout): if os.path.isfile(mcnpout): print('MCNP5 run finished!') return self.mcnptallyreader.readKeff(mcnpout)['keff'] else: raise FileNotFoundError('No such file: {:}!'.format(mcnpout)) def getEscape(self, mcnpout, mode='fixed'): if os.path.isfile(mcnpout): print('MCNP5 run finished!') if re.fullmatch('kcode', mode, re.I): k_totrate = self.mcnptallyreader.readNeutronActivity(mcnpout) escaperate = k_totrate['escape']/(k_totrate['escape']\ +k_totrate['lossfission']+k_totrate['capture']) elif re.fullmatch('fixed', mode, re.I): f_totrate = self.mcnptallyreader.readNeutronActivity(mcnpout) escaperate = f_totrate['escape'] / (f_totrate['escape'] + f_totrate['lossfission'] + f_totrate['capture']) else: raise NameError('No such mode: {:}'.format(mode)) return escaperate # escape of kcode mode else: raise FileNotFoundError('No such file: {:}'.format(mcnpout)) def getCR(self, mcnpout, mode='kcode', tallydic=None, cell=None, matnum=None): if os.path.isfile(mcnpout): print('MCNP5 run finished!') if re.fullmatch('kcode', mode, re.I): cr = self.mcnptallyreader.getCR(mcnpout) elif re.fullmatch('fixed', mode, re.I): cr = self.mcnptallyreader.getCR( PurePath.joinpath(Path(os.getcwd()), mcnpout), mode='fixed', tallydic=tallydic, cell=cell, matnum=matnum, volume=self.readVolume(mcnpout)) else: raise NameError('No such mode: {:}'.format(mode)) return cr # escape of kcode mode else: raise FileNotFoundError('No such file: {:}'.format(mcnpout))