Ejemplo n.º 1
0
    def findTMP(self, inp, designator):
        mh = McnpinpHandler()
        mcnpcontent = mh.readContent(inp, designator)

        if '$' in mcnpcontent:
            mcnpcontent = mcnpcontent[:mcnpcontent.find('$')]
        if mcnpcontent.find('tmp') > 0 or mcnpcontent.find('TMP') > 0:
            return True
        else:
            return False
Ejemplo n.º 2
0
def changeMcnpLine(inp, step, designator, section='cell'):
    mh = McnpinpHandler()
    line = mh.readContent(inp, designator, section)
    data = line.strip().split()[2]
    if float(data) > 0:
        replacedata = str(float(data) + step)
    else:
        replacedata = str(float(data) - step)
    newline = line.replace(data, replacedata)
    mh.modifyinp(inp, designator, newline, section)
Ejemplo n.º 3
0
def inital(inp, diff, surflist=None):
    mh = McnpinpHandler()

    for surf in surflist:
        line1 = mh.readContent(inp, surf, section='surface')
        oldsurf = float(line1.strip().split()[2])
        if oldsurf > 0:
            newsurf = oldsurf - diff
        else:
            newsurf = oldsurf + diff

        newline = line1.replace(line1.strip().split()[2], "{:.1f}".format(newsurf))
        mh.modifyinp(inp, surf, newline, section='surface')
Ejemplo n.º 4
0
    def readTMP(self, inp, designator):
        mh = McnpinpHandler()
        mcnpcontent = mh.readContent(inp, designator)
        if '$' in mcnpcontent:
            mcnpcontent = mcnpcontent[:mcnpcontent.find('$')]

        inplist = mcnpcontent.strip().split()
        tmp = None
        for ii, eachstr in enumerate(inplist):
            if 'tmp' in eachstr or 'TMP' in eachstr:
                tmp = float(inplist[ii][4:])

        return tmp
Ejemplo n.º 5
0
ppn = args.ppn
step = args.step

mh = McnpinpHandler()
mtr = McnpTallyReader()
end = 5.0000e-04
resultfile = mcnpinp + 'results.out'

with open(resultfile, 'w') as fid:
    fid.write("{:^10} {:^10}\n".format('Added Th', 'keff'))
mh.cleanup(mcnpinp)
resultfile = mcnpinp + 'results.out'

for ii in np.arange(0, end, step):
    #modify density
    mcnpcontent = mh.readContent(mcnpinp, '4')
    density = mcnpcontent.strip().split()[2]
    mh.modifyinp(
        mcnpinp, '4',
        mcnpcontent.replace(density, '{:.6e}'.format(float(density) + ii)))
    #modify m card
    mcnpcontent = mh.readContent(mcnpinp, 'm1', section='data')
    mcnplist = mcnpcontent.strip().split()
    indx = mcnplist.index('90232.90c')
    mcnplist[indx + 1] = '{:.6e}'.format(float(mcnplist[indx + 1]) + ii)
    mcnpline = ' '.join(mcnplist)
    mh.modifyinp(mcnpinp, 'm1', mcnpline, section='data')
    os.system('mpirun -r ssh -np ' + str(int(node * ppn)) +
              ' /home/daiye/bin/mcnp5.mpi n=' + mcnpinp)
    if os.path.isfile(mcnpinp + 'o'):
        print('MCNP5 run finished!')
Ejemplo n.º 6
0
tallydic = {
    '1004': '94240',
    '1003': '94239',
    '1005': '94241',
    '1007': '90232',
    '1016': '91233',
    '1018': '92233',
    '1020': '92235',
    '1019': '92234',
    '1023': '92238'
}
mh = McnpinpHandler()
paralists = []
newcardlist = []
for card in cardlist:
    line = mh.readContent(inp, card, section='data')
    if line:
        lists = line.strip().split()
        newcardlist.append(card)
        paralists.append(
            [int(x) if type(eval(x)) == int else float(x) for x in lists[1:]])

para = {card: para for card, para in zip(newcardlist, paralists)}

deleteNonMcnpCard(inp, cardlist)
print(para)
initalornot = True

if 'naclsets' in para.keys():
    startmolnacl = para['naclsets'][0]
    endmolnacl = para['naclsets'][1]
Ejemplo n.º 7
0
def maxPowerPeakFactorSearch(mcnpinp, node, ppn, trforrod, mode, rodstep=10):
    """
        Function: under different rod position, compute the power distribution, power peak factor and find the 
        maximum power peak factor, finally write all results to a filename of inp+'results.out'.
        Parameters: 
            inp: the name of mcnp output file.
            node: the node for parallel computing.
            ppn: the core for parallel computing.
            trforrod: dict for rod, key is 'tr' card, value is rod num.
            mode: mode for rod withdrawal accident or rod drop accident, 'w' stands for withdrawal and
            'd' stands for drop.
            rodstep: rod move step everytime.
        Return: none
    
    """
    cr = {}
    rodlists = {}
    powerfactorresults = {}
    mh = McnpinpHandler()
    # read initial rod position of burnup mcnp input
    for key, value in trforrod.items():
        rodmessage = mh.readContent(mcnpinp, key, 'data')
        lists = rodmessage.strip().split()
        rodxcoordinate = float(lists[1])
        rodycoordinate = float(lists[2])
        rodinsertpostion = float(lists[3])
        cr[value] = ControlRod(rod=value,
                               trCard=key,
                               rodRange=180.0,
                               rodXCoordinate=rodxcoordinate,
                               rodYCoordinate=rodycoordinate)
        cr[value].setInsertPosition(rodinsertpostion)
        rodlists[value] = key
        powerfactorresults[value] = []
    print(rodlists)
    print(powerfactorresults)
    mh.cleanup(mcnpinp)
    if re.match('w', mode, re.I) is not None:
        limit = 180.
        factor = 1
    elif re.match('d', mode, re.I) is not None:
        limit = 0
        factor = -1
    else:
        print("Mode set error! Should be w or d!")
        exit(0)

    for rod in rodlists:
        ii = 0
        initinsertposition = cr[rod].getInsertPosition()
        while (cr[rod].getInsertPosition() * factor < limit):
            instertposition = initinsertposition + rodstep * ii * factor
            if instertposition * factor > limit:
                instertposition = limit
            cr[rod].setInsertPosition(instertposition)
            ### modify mcnp inp
            mh.modifyinp(mcnpinp, cr[rod].getTrCardNo(),
                         cr[rod].ouputforMcnpinp(), 'data')
            ii = ii + 1
            ### run mcnp
            print('  mpirun -r ssh -np ' + str(int(node * ppn)) +
                  ' /home/daiye/bin/mcnp5.mpi n=' + mcnpinp)
            os.system('  mpirun -r ssh -np ' + str(int(node * ppn)) +
                      ' /home/daiye/bin/mcnp5.mpi n=' + mcnpinp)

            if os.path.isfile(mcnpinp + 'o'):
                print('MCNP5 run finished!')
            else:
                print('error!!!,MCNP5 run failed!')
                exit(0)
            ### read results and write to results file

            keff = readKeff(mcnpinp + 'o')
            meshfilename = mcnpinp + '_mesh_' + rod + '_' + str(
                instertposition)
            original_meshfilename = getMeshFilename(mcnpinp + 'o')
            if os.path.isfile(original_meshfilename):
                mh.deleteFiles(meshfilename)
                os.rename(original_meshfilename, meshfilename)
                print("Rename meshtal to {:}\n".format(meshfilename))

            resultsfilename = mcnpinp + rod + '_' + str(
                instertposition) + '.csv'
            uncertainty = 1.1 * 1.1
            radialPowerPeakFactor, axialPowerPeakFactor, totPowerPeakFactor = computePowerDesityDistribution(
                meshfilename, resultsfilename, uncertainty)
            powerfactorresults[rod].append(
                (instertposition, keff[0], radialPowerPeakFactor,
                 axialPowerPeakFactor, totPowerPeakFactor))
            mh.cleanup(mcnpinp)
        ## set rod insertposition to inital
        cr[rod].setInsertPosition(initinsertposition)
        mh.modifyinp(mcnpinp, cr[rod].getTrCardNo(), cr[rod].ouputforMcnpinp(),
                     'data')

    maxradialPowerPeakFactor = 0
    maxaxialPowerPeakFactor = 0
    maxtotPowerPeakFactor = 0
    maxrod1 = ''
    maxrod2 = ''
    maxrod3 = ''
    #print(powerfactorresults)
    with open(mcnpinp + 'results.out', 'w') as fid:
        fid.write('{:^5}{:^20}{:^8}{:^20}{:^20}{:^20}\n'.format\
                ('Rod', 'Insert position', 'Keff', 'Radial peak factor', 'Axial peak factor', 'Tot peak factor'))
        for rod in powerfactorresults:
            for ii in range(len(powerfactorresults[rod])):
                radialpowerfactor = powerfactorresults[rod][ii][2]
                axialpowerfactor = powerfactorresults[rod][ii][3]
                totpowerfactor = powerfactorresults[rod][ii][4]
                instertposition = powerfactorresults[rod][ii][0]
                keff = powerfactorresults[rod][ii][1]
                if maxradialPowerPeakFactor < radialpowerfactor:
                    maxrod1 = rod
                    maxradialPowerPeakFactor = radialpowerfactor
                if maxaxialPowerPeakFactor < axialpowerfactor:
                    maxrod2 = rod
                    maxaxialPowerPeakFactor = axialpowerfactor
                if maxtotPowerPeakFactor < totpowerfactor:
                    maxrod3 = rod
                    maxtotPowerPeakFactor = totpowerfactor
                fid.write('{:^5}{:^20.3f}{:^8.5f}{:^20.4f}{:^20.4f}{:^20.4f}\n'.format\
                (rod, instertposition, keff, radialpowerfactor, axialpowerfactor, totpowerfactor))

        fid.write('{:}:  {:}\n'.format('Rod', maxrod1))
        fid.write('{:}:  {:.4}\n'.format('Max radial power peak factor',
                                         maxradialPowerPeakFactor))
        fid.write('{:}:  {:}\n'.format('Rod', maxrod2))
        fid.write('{:}:  {:.4}\n'.format('Max axial power peak factor',
                                         maxaxialPowerPeakFactor))
        fid.write('{:}:  {:}\n'.format('Rod', maxrod3))
        fid.write('{:}:  {:.4}\n'.format('Max total power peak factor',
                                         maxtotPowerPeakFactor))
Ejemplo n.º 8
0
class Preprocesser(object):
    def __init__(self):
        self._cardlist = [
            'Naclsets', 'Pucl3sets', 'coresizesets', 'reflectorsets',
            'Thcl4sets', 'Ucl3sets', 'Ucl4sets', 'Na', 'Cl', 'U', 'Th'
        ]
        self.mcnpinphandler = McnpinpHandler()

    def getParameter(self, mcnpinp, materialcard):

        paralists = []
        newcardlist = []
        for card in self._cardlist:
            line = self.mcnpinphandler.readContent(mcnpinp,
                                                   card,
                                                   section='data')
            if line:
                lists = line.strip().split()
                newcardlist.append(card)
                paralists.append([
                    int(x) if type(eval(x)) == int else float(x)
                    for x in lists[1:]
                ])

        parameter = {card: para for card, para in zip(newcardlist, paralists)}
        line = self.mcnpinphandler.readContent(mcnpinp,
                                               materialcard,
                                               section='data')
        linelist = line.strip().split()
        parameter['mcardcontent'] = linelist
        return parameter

    def copyInitalMcnpinp(self, initalinp, mcnpinp):
        with open(initalinp, 'r') as fid1, open(mcnpinp, 'w') as fid2:
            for line in fid1:
                fid2.write(line)

    def deleteNonMcnpCard(self, mcnpinp):
        shadow = False
        with open(mcnpinp, 'r') as fid, open(mcnpinp + 'bp', 'w') as fid2:
            for line in fid:
                shadow = False
                lists = line.strip().split()
                if bool(lists):
                    for card in self._cardlist:
                        if re.fullmatch(card, lists[0], re.I) is not None:
                            shadow = True
                            break
                if not shadow:
                    fid2.write(line)
        os.remove(mcnpinp)
        os.rename(mcnpinp + 'bp', mcnpinp)

    def cleanupFolder(self, mcnpinp):
        self.mcnpinphandler.cleanup(mcnpinp)

    def modfiyMaterial(self, mcnpinp, cellnum, newdensity, mcard,
                       newmcardcontent):
        line = self.mcnpinphandler.readContent(mcnpinp, cellnum)
        newline = line.replace(line.strip().split()[2],
                               '-{:.5f}'.format(newdensity))
        self.mcnpinphandler.modifyinp(mcnpinp, cellnum, newline)
        self.mcnpinphandler.modifyinp(mcnpinp, mcard, newmcardcontent, 'data')

    def changeMode(self, mcnpinp, mode, test=False):
        with open(mcnpinp, 'r', encoding="utf-8") as fid:
            content = fid.readlines()
        if test:
            fixedSource = 'sdef  axs=0 0 1 pos=0 0 0 ext=d1 rad=d2  erg=d3 par=1\
                \nsi1    -10 10\nsp1   0   1\nsi2    0  10\nsp2    -21 1\nSI3   L  \
                0.151 0.248 0.410 0.675 1.11 1.84 3.03 4.99 19.64\nSP3      \
            0.0 5.45e-2 5.0e-2 8.0e-2 0.122 0.165 0.178 0.157 0.1985\nnps 50\n'

            kcodeSource = 'kcode    200 1.0 5 50\nksrc   50. 0. 0. -50 0 0  -0 \
                    0 0  0 0 20\n'

        else:
            fixedSource = 'sdef  axs=0 0 1 pos=0 0 0 ext=d1 rad=d2  erg=d3 par=1\
                    \nsi1    -10 10\nsp1   0   1\nsi2    0  10\nsp2    -21 1\nSI3   L  \
                    0.151 0.248 0.410 0.675 1.11 1.84 3.03 4.99 19.64\nSP3      \
                0.0 5.45e-2 5.0e-2 8.0e-2 0.122 0.165 0.178 0.157 0.1985\nnps 50000\n'

            kcodeSource = 'kcode    20000 1.0 30 250\nksrc   50. 0. 0. -50 0 0  -0 \
                    0 0  0 0 20\n'

        if re.fullmatch('fixed', mode, re.I):

            with open(mcnpinp, 'w', encoding="utf-8") as f:
                for line in content:
                    lists = line.strip().split()
                    if lists and re.fullmatch('kcode', lists[0],
                                              re.I) is not None:
                        f.write(fixedSource)
                    elif lists and re.fullmatch('ksrc', lists[0],
                                                re.I) is not None:
                        pass
                    else:
                        f.write(line)
        elif re.fullmatch('kcode', mode, re.I):
            with open(mcnpinp, 'w', encoding="utf-8") as f:
                for line in content:
                    lists = line.strip().split()
                    if lists and re.fullmatch('sdef', lists[0],
                                              re.I) is not None:
                        f.write(kcodeSource)
                    elif lists and re.fullmatch('si|sp|sc|ds[0-9]{1,3}', lists[0], \
                                            re.I) is not None:
                        pass
                    elif lists and re.fullmatch('nps', lists[0],
                                                re.I) is not None:
                        pass
                    else:
                        f.write(line)
        else:
            raise NameError('No such mode!')

    def changeMcnpLine(self, inp, increment, designator, section='cell'):
        line = self.mcnpinphandler.readContent(inp, designator, section)
        data = line.strip().split()[2]
        if float(data) > 0:
            replacedata = str(float(data) + increment)
        else:
            replacedata = str(float(data) - increment)
        newline = line.replace(data, replacedata)
        self.mcnpinphandler.modifyinp(inp, designator, newline, section)
Ejemplo n.º 9
0
parser = argparse.ArgumentParser(description='input file name, node and ppn')
parser.add_argument('-n', action="store", dest="node", type=int, default=1)
parser.add_argument('-p', action="store", dest="ppn", type=int, default=1)
parser.add_argument('inp', action="store", type=str)
args = parser.parse_args()
print('inputfile=%s' % args.inp, 'ppn=%s' % args.ppn)
inp = args.inp
node = args.node
ppn = args.ppn

cardlist = ['naclsets', 'puclsets']

mh = McnpinpHandler()
paralists = []
for card in cardlist:
    line = mh.readContent(inp, card, section='data')
    if line:
        lists = line.strip().split()
        paralists.append([float(x) for x in lists[1:]])
    para = {card: para for card, para in zip(cardlist, paralists)}

deleteNonMcnpCard(inp, cardlist)

if 'naclsets' in para.keys():
    startmolnacl = para['naclsets'][0]
    endmolnacl = para['naclsets'][1]
    stepmolnacl = para['naclsets'][2]

else:
    startmolnacl = 0
    stepmolnacl = 1
Ejemplo n.º 10
0
            results['kCR'] = 0  # CR of kcode mode
            results['fCR'] = 0  # CR of fixed mode
            results['kescape'] = 0  # escape of kcode mode
            results['fescape'] = 0  # escape of fixed mode

            matdict[pucl3] = jj
            matdict[thcl4] = 100 - ii - jj
            mat = Material('mat1', matdict, 900)
            # print(uf4.getActomicMass())
            # print(thf4.getActomicMass())
            density = mat.getDensity()
            print(density)
            # print(mat.toMcnpCard().strip())
            line = mat.toMcnpCard().strip()
            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')