Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo 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')
Exemplo 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
Exemplo n.º 5
0
    def hasMtnumIninp(self, inpfile, matnum):
        mh = McnpinpHandler()
        cellcards = mh.readCellCards(inpfile)

        matincellcard = []
        for line in cellcards:
            lists = line.strip().split()
            matincellcard.append(lists[1])
        for mat in matnum:
            if mat not in matincellcard:
                mh.errorMessage(' material number {:} do not exists!\n'.format(mat))
                return False

        return True
Exemplo n.º 6
0
    def isTMPIdentical(self, filename, workpath=None):
        inpfile = filename
        tmpdic = {}
        if workpath:
            inpfile = os.path.join(workpath, filename)
        mh = McnpinpHandler()
        cellcards = mh.readCellCards(inpfile)
        for line in cellcards:
            lists = line.strip().split()
            mat = lists[1]
            if mat not in tmpdic.keys():
                tmpdic[mat] = []
            for ii, eachstr in enumerate(lists):
                if 'tmp' in eachstr or 'TMP' in eachstr:
                    tmp = lists[ii][4:]
                    tmpdic[mat].append(tmp)

        for key, tmps in tmpdic.items():
            if len(set(tmps)) > 1:
                mh.errorMessage('The TMP card of material {:} is inconsistent!\n'.format(key))
                return False

        return True
Exemplo n.º 7
0
    def isTemEqMtnum(self, filename, workpath=None):

        inpfile = filename
        if workpath:
            inpfile = os.path.join(workpath, filename)
        mh = McnpinpHandler()
        cellcards = mh.readCellCards(inpfile)
        tmpnum = 0
        matnum = 0

        for cellcard in cellcards:
            if '$' in cellcard:
                cellcard = cellcard[:cellcard.find('$')]
            if cellcard.find('tmp')>0 or cellcard.find('TMP')>0:
                tmpnum += 1
            if cellcard.strip().split()[1] != '0':
                matnum += 1
        if tmpnum == matnum:
            print ('matnum is ', matnum, ' tmpnum is ', tmpnum)
            return True
        else:
            print ('matnum is ', matnum, ' tmpnum is ', tmpnum)
            print ('The number of tmp and the number of  material are not  identical !')
            return False
Exemplo n.º 8
0
                    required=True,
                    type=str)
parser.add_argument('--step',
                    '-s',
                    help='step lenth for calculation',
                    metavar="",
                    default=1e-5,
                    type=float)
args = parser.parse_args()
print("input file is {:}, step lenth is {:}".format(args.input, args.step))
mcnpinp = args.input
node = args.node
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',
 def __init__(self):
     self.mh = McnpinpHandler()
     self.mtr = McnpTallyReader()
Exemplo n.º 10
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))
Exemplo n.º 11
0
 def __init__(self):
     self.mcnptallyreader = McnpTallyReader()
     self.mcnpinphandler = McnpinpHandler()
Exemplo n.º 12
0
 def __init__(self):
     self._cardlist = [
         'Naclsets', 'Pucl3sets', 'coresizesets', 'reflectorsets',
         'Thcl4sets', 'Ucl3sets', 'Ucl4sets', 'Na', 'Cl', 'U', 'Th'
     ]
     self.mcnpinphandler = McnpinpHandler()