def addAssignments2CompBlock(lines,compDataByMixtureID=0, mixAssignmentsGivenParentMix=0):

########################################################################
# Append the commented input in the composition block with mixture ID's 
# that are assigned in triton, and thus not in the composition block
########################################################################

  print 'Running addAssignments2CompBlock'

  if compDataByMixtureID == 0:
    compDataByMixtureID = getCompDataByMixtureID(lines)
  if mixAssignmentsGivenParentMix == 0:
    tmp_list = getMixtureAssignments(lines)
    mixAssignmentsGivenParentMix = tmp_list[1]

  start_comp = findLineNumWithComments(lines,'read comp')
  end_comp = findLineNumWithComments(lines,'end comp',start_index=start_comp)

  new_lines = []  # These are what will be appended to the composition block
  new_lines.append("'")
  new_lines.append("'" + 'Begin Making Compositions for Assigned Mixtures from the Triton Depletion Block')
  for parentMix in mixAssignmentsGivenParentMix.keys():
    assignedMixList = mixAssignmentsGivenParentMix[parentMix]
    new_lines.append("'"+'These Compositions are Assignments for Mixture ' + str(parentMix) + ' in Triton')
    for assignedMix in assignedMixList:
      for materialIndex in compDataByMixtureID[parentMix].keys():
        tmp_list = compDataByMixtureID[parentMix][materialIndex][:]  # The [:] is there to make a new copy of the list, not just a new variable that points at the same data
        tmp_list[1] = str(assignedMix)    # Replacing the parentMix with the assignedMix
        new_lines.append(' '.join(tmp_list))   # The list of strings is joined into one string (separated by ' ') and appended to new_lines
  
# Insert the new composition lines into the input
  new_input = lines[:]
  for line_num in range(len(new_lines)-1,-1,-1):
    new_input.insert(end_comp, new_lines[line_num] + '\n')
  return new_input
Пример #2
0
def getFuelMixtures(lines,
                    compDataByMixtureID=0,
                    mixAssignmentsGivenParentMix=0):

    for line_num in range(
            len(lines) - 2, -1, -1
    ):  # Stepping back through input, need -2 cuz extra empty spot at end of list assigned
        if lines[line_num][0] == "'":
            del lines[line_num]  # delete the comments

    print 'Running getFuelMixtures'

    # This determines which mixtures are fuels
    # Find where the composition block starts and ends
    fuelMixtures = []  # List that will contain mixture ID's that have fuel

    fuelNames = [
        'uo2', '92235', '92238', '92000', 'u-235', 'u-238', 'u-233', 'uranium',
        'u', 'uc', 'un', 'u3o8', 'u(.27)metal'
    ]

    if compDataByMixtureID == 0:
        compDataByMixtureID = getCompDataByMixtureID(lines)
# This is a dictionary of form {mixID:{materialIndex:[list of strings that describe the composition]}}
# Further described in module getCompDataByMixtureID
    if mixAssignmentsGivenParentMix == 0:
        assignmentData = getMixtureAssignments(lines)
        mixAssignmentsGivenParentMix = assignmentData[1]

    for mixID in compDataByMixtureID.keys():
        for materialIndex in range(len(compDataByMixtureID[mixID])):
            for fuelName in fuelNames:
                if fuelName in compDataByMixtureID[mixID][materialIndex]:
                    if mixID not in fuelMixtures:
                        fuelMixtures.append(mixID)
                        break


# Replace any mixtureIDs with their assignments if present.
# Work through fuelMixtures backwards.
    if mixAssignmentsGivenParentMix != -1:
        for index in range(len(fuelMixtures) - 1, -1, -1):
            if fuelMixtures[index] in mixAssignmentsGivenParentMix.keys():
                assignedMixs = mixAssignmentsGivenParentMix[
                    fuelMixtures[index]]
                del fuelMixtures[index]
                for assignedMix in assignedMixs:
                    fuelMixtures.insert(index, assignedMix)

    return fuelMixtures
Пример #3
0
def addAssignments2CompBlock(lines,
                             compDataByMixtureID=0,
                             mixAssignmentsGivenParentMix=0):

    ########################################################################
    # Append the commented input in the composition block with mixture ID's
    # that are assigned in triton, and thus not in the composition block
    ########################################################################

    print 'Running addAssignments2CompBlock'

    if compDataByMixtureID == 0:
        compDataByMixtureID = getCompDataByMixtureID(lines)
    if mixAssignmentsGivenParentMix == 0:
        tmp_list = getMixtureAssignments(lines)
        mixAssignmentsGivenParentMix = tmp_list[1]

    start_comp = findLineNumWithComments(lines, 'read comp')
    end_comp = findLineNumWithComments(lines,
                                       'end comp',
                                       start_index=start_comp)

    new_lines = []  # These are what will be appended to the composition block
    new_lines.append("'")
    new_lines.append(
        "'" +
        'Begin Making Compositions for Assigned Mixtures from the Triton Depletion Block'
    )
    for parentMix in mixAssignmentsGivenParentMix.keys():
        assignedMixList = mixAssignmentsGivenParentMix[parentMix]
        new_lines.append("'" +
                         'These Compositions are Assignments for Mixture ' +
                         str(parentMix) + ' in Triton')
        for assignedMix in assignedMixList:
            for materialIndex in compDataByMixtureID[parentMix].keys():
                tmp_list = compDataByMixtureID[parentMix][
                    materialIndex][:]  # The [:] is there to make a new copy of the list, not just a new variable that points at the same data
                tmp_list[1] = str(
                    assignedMix
                )  # Replacing the parentMix with the assignedMix
                new_lines.append(
                    ' '.join(tmp_list)
                )  # The list of strings is joined into one string (separated by ' ') and appended to new_lines


# Insert the new composition lines into the input
    new_input = lines[:]
    for line_num in range(len(new_lines) - 1, -1, -1):
        new_input.insert(end_comp, new_lines[line_num] + '\n')
    return new_input
Пример #4
0
def getFuelMixtures(lines,compDataByMixtureID=0,mixAssignmentsGivenParentMix=0):

  for line_num in range(len(lines)-2,-1,-1):    # Stepping back through input, need -2 cuz extra empty spot at end of list assigned
    if lines[line_num][0] == "'":
      del lines[line_num]         # delete the comments

  print 'Running getFuelMixtures'

# This determines which mixtures are fuels
# Find where the composition block starts and ends
  fuelMixtures = []        # List that will contain mixture ID's that have fuel

  fuelNames = ['uo2','92235','92238','92000','u-235','u-238','u-233','uranium','u','uc','un','u3o8','u(.27)metal']

  if compDataByMixtureID == 0:
    compDataByMixtureID = getCompDataByMixtureID(lines)
# This is a dictionary of form {mixID:{materialIndex:[list of strings that describe the composition]}}
# Further described in module getCompDataByMixtureID
  if mixAssignmentsGivenParentMix == 0:
    assignmentData = getMixtureAssignments(lines)
    mixAssignmentsGivenParentMix = assignmentData[1]


  for mixID in compDataByMixtureID.keys():
    for materialIndex in range(len(compDataByMixtureID[mixID])):
      for fuelName in fuelNames:
        if fuelName in compDataByMixtureID[mixID][materialIndex]:
          if mixID not in fuelMixtures:
            fuelMixtures.append(mixID)
            break

# Replace any mixtureIDs with their assignments if present.
# Work through fuelMixtures backwards.
  if mixAssignmentsGivenParentMix != -1:
    for index in range(len(fuelMixtures)-1,-1,-1):
      if fuelMixtures[index] in mixAssignmentsGivenParentMix.keys():
        assignedMixs = mixAssignmentsGivenParentMix[fuelMixtures[index]]
        del fuelMixtures[index]
        for assignedMix in assignedMixs:
          fuelMixtures.insert(index,assignedMix)

  return fuelMixtures 
Пример #5
0
def newt2keno(filename):

  """ This module converts a newt input into a keno input. Two main steps are taken:
      I.) Parse the input for information about the problem
         A) Read geometry and media information for each unit
         B) Read array definition data
         C) Determine which units have fuel in them
            1) Determine which mixture ID's have fuel in them
               i) Read composition data
               ii) Read assignments from the depletion block
      II.) Edit the input to convert from Newt to KENO style input """

# Read the input
  f = open(filename, 'r')  
  lines = f.read().split('\n')    # Read all lines
  f.close()

# Read Composition Data
  compDataByMixtureID = getCompDataByMixtureID(lines)

# Find mixture assignments if present
  mixData = getMixtureAssignments(lines)
  parentMixGivenAssignedMix = mixData[0]
  mixAssignmentsGivenParentMix = mixData[1]

# Determine which mixture ID's have fuel in them
  fuelMixtures = getFuelMixtures(lines,compDataByMixtureID,mixAssignmentsGivenParentMix)

# Read geometry and media information for each unit
  unitGeom = getUnitGeom(lines)

# Determine which units have fuel
  unitsWithFuel = getUnitsWithFuel(lines,fuelMixtures)

# Read array data
  arrayData = getArrayData(lines,unitsWithFuel)

  """ Start Making a New Input File """
# If Assigned Mixtures are Used, Add them to the Composition Block
  if mixAssignmentsGivenParentMix != -1:
    new_input = addAssignments2CompBlock(lines,compDataByMixtureID,mixAssignmentsGivenParentMix)

# Edit the computational sequence, title, and cross-section library
  new_input = editAboveCompositionBlock(new_input)

# Remove all input between the composition block and the geometry block
  end_comp = findLineNumWithComments(new_input, 'end comp')
  read_geom = findLineNumWithComments(new_input, 'read geom')
  for count in range(read_geom - end_comp - 1):
    del(new_input[end_comp+1])

# Add a parameter block after the composition block
  new_input.insert(end_comp+1,'end parm \n')
  new_input.insert(end_comp+1,'     nsk=0 \n')
  new_input.insert(end_comp+1,'     npg=500 \n')  #500 is probably too much
  new_input.insert(end_comp+1,'     gen=100 \n')  #100 probably good
  new_input.insert(end_comp+1,'     htm=no \n')
  new_input.insert(end_comp+1,'read parm \n')

# Make adjustments to Geometry Block 
  new_input = editGeomBlock(new_input)

# Make adjustments to Array Block
  new_input = editArrayBlock(new_input)

# Make sure bounds are correct
  new_input = editBoundsBlock(new_input)

# Remove "end model" and add "end data". 
# Also delete anything between "end bounds" and "end data" except for a plot block
  new_input = editBottomOfNewtInput(new_input)

# Attempt to fix how arrays are placed in the newt model geometry
  new_input = fixUnitsWithArrays(new_input,unitGeom,arrayData)

# Have to add back \n to lines that don't have them
  for line_num in range(len(new_input)):
    if '\n' not in new_input[line_num]:
      new_input[line_num] = new_input[line_num] + '\n'

# Write the keno input file
  new_filename = filename + '.keno.inp'
  g = open(new_filename, 'w')
  for line in new_input:
    g.write(line)
    
  g.close()

#  run_it(new_input,new_filename)

  print arrayData[1].keys()
  print arrayData[1]['unitGivenLocation'].keys()
# Return Information
  data = [new_input,compDataByMixtureID,mixAssignmentsGivenParentMix,
          parentMixGivenAssignedMix,unitGeom,unitsWithFuel,arrayData,fuelMixtures]
  return data
Пример #6
0
def newt2keno(filename):
    """ This module converts a newt input into a keno input. Two main steps are taken:
      I.) Parse the input for information about the problem
         A) Read geometry and media information for each unit
         B) Read array definition data
         C) Determine which units have fuel in them
            1) Determine which mixture ID's have fuel in them
               i) Read composition data
               ii) Read assignments from the depletion block
      II.) Edit the input to convert from Newt to KENO style input """

    # Read the input
    f = open(filename, 'r')
    lines = f.read().split('\n')  # Read all lines
    f.close()

    # Read Composition Data
    compDataByMixtureID = getCompDataByMixtureID(lines)

    # Find mixture assignments if present
    mixData = getMixtureAssignments(lines)
    parentMixGivenAssignedMix = mixData[0]
    mixAssignmentsGivenParentMix = mixData[1]

    # Determine which mixture ID's have fuel in them
    fuelMixtures = getFuelMixtures(lines, compDataByMixtureID,
                                   mixAssignmentsGivenParentMix)

    # Read geometry and media information for each unit
    unitGeom = getUnitGeom(lines)

    # Determine which units have fuel
    unitsWithFuel = getUnitsWithFuel(lines, fuelMixtures)

    # Read array data
    arrayData = getArrayData(lines, unitsWithFuel)
    """ Start Making a New Input File """
    # If Assigned Mixtures are Used, Add them to the Composition Block
    if mixAssignmentsGivenParentMix != -1:
        new_input = addAssignments2CompBlock(lines, compDataByMixtureID,
                                             mixAssignmentsGivenParentMix)

# Edit the computational sequence, title, and cross-section library
    new_input = editAboveCompositionBlock(new_input)

    # Remove all input between the composition block and the geometry block
    end_comp = findLineNumWithComments(new_input, 'end comp')
    read_geom = findLineNumWithComments(new_input, 'read geom')
    for count in range(read_geom - end_comp - 1):
        del (new_input[end_comp + 1])

# Add a parameter block after the composition block
    new_input.insert(end_comp + 1, 'end parm \n')
    new_input.insert(end_comp + 1, '     nsk=0 \n')
    new_input.insert(end_comp + 1,
                     '     npg=500 \n')  #500 is probably too much
    new_input.insert(end_comp + 1, '     gen=100 \n')  #100 probably good
    new_input.insert(end_comp + 1, '     htm=no \n')
    new_input.insert(end_comp + 1, 'read parm \n')

    # Make adjustments to Geometry Block
    new_input = editGeomBlock(new_input)

    # Make adjustments to Array Block
    new_input = editArrayBlock(new_input)

    # Make sure bounds are correct
    new_input = editBoundsBlock(new_input)

    # Remove "end model" and add "end data".
    # Also delete anything between "end bounds" and "end data" except for a plot block
    new_input = editBottomOfNewtInput(new_input)

    # Attempt to fix how arrays are placed in the newt model geometry
    new_input = fixUnitsWithArrays(new_input, unitGeom, arrayData)

    # Have to add back \n to lines that don't have them
    for line_num in range(len(new_input)):
        if '\n' not in new_input[line_num]:
            new_input[line_num] = new_input[line_num] + '\n'


# Write the keno input file
    new_filename = filename + '.keno.inp'
    g = open(new_filename, 'w')
    for line in new_input:
        g.write(line)

    g.close()

    #  run_it(new_input,new_filename)

    print arrayData[1].keys()
    print arrayData[1]['unitGivenLocation'].keys()
    # Return Information
    data = [
        new_input, compDataByMixtureID, mixAssignmentsGivenParentMix,
        parentMixGivenAssignedMix, unitGeom, unitsWithFuel, arrayData,
        fuelMixtures
    ]
    return data