def fixUnitsWithArrays(new_input,unitGeom=0,arrayData=0):
 
  print 'Running fixUnitsWithArrays'

  if unitGeom == 0:
    unitGeom = getUnitGeom(new_input)
  if arrayData == 0:
    arrayData = getArrayData(new_input)

  start_geom = findLineNumWithComments(new_input,'read geom')
  end_geom = findLineNumWithComments(new_input,'end geom', start_index=start_geom)

  """ Start by calculating the x and y dimensions of the array. 
        A) Find nux and nuy
        B) Make a list of units which span the x and y dimensions of the array
        C) Find the size of each of these units
          1)  Find which region is the boundary for the unit
          2) Find the dimension of that region
        D) Sum up the unit dimensions to ge the array dimension """

  # Remove any redundant spaces to make parsing simpler
  for line_num in range(start_geom,end_geom):
    new_input[line_num] = re.sub('[ ]+',' ', new_input[line_num])

  for array_num in arrayData.keys():
    units_x = []
    units_y = []
    nux = arrayData[array_num]['nux']
    nuy = arrayData[array_num]['nuy']
    for position in range(nux):
      units_x.append(arrayData[array_num]['unitGivenLocation'][position])
    # this units_y part will only work for a cuboidal array
    for position in range(0,nux*nuy,nux):
      units_y.append(arrayData[array_num]['unitGivenLocation'][position])
    unit_size = []
    array_size_x = 0.0
    for unit in units_x:
      boundary_region = unitGeom[unit]['boundaryRegion']
      unit_size = abs(unitGeom[unit][boundary_region]['dimension']['x+']) + abs(unitGeom[unit][boundary_region]['dimension']['x-'])
      array_size_x = array_size_x + unit_size
#    print array_size_x
    unit_size = []
    array_size_y = 0.0
    for unit in units_y:
      boundary_region = unitGeom[unit]['boundaryRegion']
      unit_size = abs(unitGeom[unit][boundary_region]['dimension']['y+']) + abs(unitGeom[unit][boundary_region]['dimension']['y-'])
      array_size_y = array_size_y + unit_size
#    print array_size_y

    """ Now for each array:
        E) go to the unit where the array is described
        F) Read the array definition
        G) Determine which surface is being filled in the array
        H) If this surface is larger than array_size_x and array_size_y
          1) Make a new surface that has dimensions array_size_x and array_size_y
            a) If array_size_x == array_size_y
              i) Adjust the x+ and x- equally to get the correct size surface
              ii) Adjust the y+ and y- equally to get the correct size surface
            b) If array_size_x != array_size_y
              i) Adjust the x+ dimension to get the correct size surface
              ii) Adjust the y- dimension to get the correct size surface
          2) Change the array definition such that this new_surface is the one being filled
          3) Add "-" + new_suface_number to the media describing the old surface number
    """
    # This is the unit where the array is used
    unit = arrayData[array_num]['locatedInUnit']
#    print 'The Unit we want is ', unit
    # Find the start and end of the desciption for the unit
    unit_search = re.compile(r'unit\s+(\d+)')
    search_line = start_geom
    for line_num in range(start_geom, end_geom):
      tmp_line_num = findLineNumWithComments(new_input,'unit',start_index=search_line)
      tmp_unit = int(unit_search.search(new_input[tmp_line_num]).groups()[0])
      if unit == tmp_unit:
        start_unit = tmp_line_num
        break
      else:
        search_line = tmp_line_num + 1
    end_unit = findLineNumWithComments(new_input,'boundary',start_index=start_unit)


    # Find where the array is described
    array_search = re.compile(r'array\s+(\d+)')
    for line_num in range(start_unit, end_unit):
      tmp_line_num = findLineNumWithComments(new_input,'array',start_index=line_num)
      possible_array = int(array_search.search(new_input[tmp_line_num]).groups()[0])
      if array_num == possible_array:
        array_line = tmp_line_num
        break
#    print new_input[array_line]

    # Read the array information
    array_reader = re.compile(r'array([a-zA-Z0-9.\-+ ]+)place')
    tmp_string = array_reader.search(new_input[array_line]).groups()[0]
    tmp_list = string2list(tmp_string)
    # The bounding surface for the array is the one that is not negative
    for i in range(1, len(tmp_list)):
      if tmp_list[i].find('-') == -1:
        array_surf = int(tmp_list[i])
#    print 'array surf is ', array_surf
    
    # Find the dimensions of the array surface being used
    x_plus = unitGeom[unit][array_surf]['dimension']['x+']
    x_minus = unitGeom[unit][array_surf]['dimension']['x-']
    y_plus = unitGeom[unit][array_surf]['dimension']['y+']
    y_minus = unitGeom[unit][array_surf]['dimension']['y-']
    surf_x_length = abs(x_plus - x_minus)
    surf_y_length = abs(y_plus - y_minus)

    # See if the array surface size is the same as the sum of the length of the units filling it
    if surf_x_length == array_size_x and surf_y_length == array_size_y:
      print 'Array', array_num, 'seems OK. Continuing...'
      pass
    else:
      print 'Array', array_num, ': The surface used to define the array is larger than the sum of the length of the units filling it.'
      print 'This will cause issues in KENO/MCDancoff.'
      print 'Attempting to fix the problem'
      x_diff = surf_x_length - array_size_x
      y_diff = surf_y_length - array_size_y
      if array_size_x == array_size_y:
        new_x_plus = x_plus - x_diff/2.0
        new_x_minus = x_minus + x_diff/2.0
        new_y_plus = y_plus - y_diff/2.0
        new_y_minus = y_minus + y_diff/2.0
      else:
        new_x_plus = x_plus - x_diff
        new_x_minus = x_minus
        new_y_plus = y_plus
        new_y_minus = y_minus + y_diff

      """ Start making the new surface for the array to be filled into """

      # Pick a new surface # that is not already in use
      tmp_list = unitGeom[unit].keys()
      new_surf_num = 999
      for num in range(999,0,-1):
        if new_surf_num in tmp_list:
          new_surf_num = new_surf_num - 1
        else:
          break

      # Make the new surface by copying the old one and editing it's values
      shape = unitGeom[unit][array_surf]['shape']
      array_surf_line = findLineNumWithComments(new_input, shape + ' ' + str(array_surf), start_index=start_unit)
      new_surf_list = string2list(new_input[array_surf_line])
#      print new_input[array_surf_line]
      new_surf_list[1] = str(new_surf_num)
      new_surf_list[2] = str(new_x_plus)
      new_surf_list[3] = str(new_x_minus)
      new_surf_list[4] = str(new_y_plus)
      new_surf_list[5] = str(new_y_minus)
      new_surf_definition = ' '.join(new_surf_list)
#      print new_surf_definition

      # Change the array definition to use the new surface
      new_array_list = string2list(new_input[array_line])
      # The bounding surface for the array is the one that is not negative
      for i in range(2, len(new_array_list)):
        if new_array_list[i].find('-') == -1:
          new_array_list[i] = str(new_surf_num)
          break
      new_array_definition = ' '.join(new_array_list)
#      print new_array_definition
      
      # Write the new surface definition to the input
      new_input.insert(array_surf_line, new_surf_definition + '\n')
      new_input.insert(array_surf_line, "'The new surface is defined below \n")

      # Write the new array definition to the input
      # Check if the array definition line number changed first
      if array_line > array_surf_line:
        array_line = array_line + 2
      new_input[array_line] = "'Old: " + new_input[array_line]
      new_input.insert(array_line, new_array_definition + '\n')
      new_input.insert(array_line, "'The new array is defined below \n")

      """ Now need to change the media that describes the original 
          surface number to also exclude the new surface number """
      # Find where the array is described, then append '-' + new_surf_num
      array_search = re.compile(r'array\s+(\d+)')
      for line_num in range(start_unit, end_unit):
        tmp_line_num = findLineNumWithComments(new_input,'media',start_index=tmp_line_num)
        tmp_list = string2list(new_input[tmp_line_num])
        if str(array_surf) in tmp_list[3:]:
          media_line = tmp_line_num
          tmp_list.append(' ' + '-' + str(new_surf_num))
          new_media_line = ' '.join(tmp_list)
          break
        else:
          tmp_line_num = tmp_line_num + 1

      new_input[media_line] = "'Old: " + new_input[media_line] + '\n'
      new_input.insert(media_line, new_media_line + '\n')
      new_input.insert(media_line, "'The new media is defined below \n")
  return new_input
def changeArray2KenoType(new_input,arrayData=0,unitGeom=0):
  """

  """
  print 'Running changeArray2KenoType'

  # Check if the dictionaries were given, if not then get them
  if arrayData == 0:
    arrayData = getArrayData(new_input)
  if unitGeom ==0:
    unitGeom = getUnitGeom

  # Find the lines describing the array block
  read_array = findLineNumWithComments(new_input,'read arr')
  end_array = findLineNumWithComments(new_input,'end arr',start_index=read_array)

  # This will be used to read the array number
  read_ara_num = re.compile(r'^ara\D*(\d*)\b')
  read_before_fill = re.compile(r'([a-zA-Z0-9,= ]*)fill')
  read_after_fill = re.compile(r'fill([a-zA-Z0-9,= ]*)')
  read_before_end = re.compile(r'([a-zA-Z0-9,= ]*)end')
  read_after_end = re.compile(r'end([a-zA-Z0-9,= ]*)')

  for line_num in range(read_array,end_array):
    if 'ara' in new_input[line_num]:
      array_num = int(read_ara_num.search(new_input[line_num]).groups()[0])
      if arrayData[array_num]['fuel_present'] == 'yes':
        nux = arrayData[array_num]['nux']
        nuy = arrayData[array_num]['nuy']

        # Isolate the part of the array definition that contains unit numbers
        # Make sure no numbers are on the same line as where 'fill' or 'end' are found
        start_fill = findLineNumWithComments(new_input,'fill',start_index=line_num)
        end_fill = findLineNumWithComments(new_input,'end',start_index=start_fill)
        start_fill_loc = new_input[start_fill].find('fill')
        end_fill_loc = new_input[end_fill].find('end')
        start_fill_text = new_input[start_fill]
        end_fill_text = new_input[end_fill]

        for line in new_input[start_fill:end_fill+6]:
          print line
        # Delete the lines that contain units
        del(new_input[start_fill:end_fill+1])

        # Insert a new line that contains everything including and after the word 'end' (preserve the 'end' keyword)
        new_input.insert(start_fill, read_after_end.search(end_fill_text).group() + '\n')
        # Replace the the where 'end' was found with all text before the word 'end' (isolate the unit numbers)
        new_input.insert(start_fill, read_before_fill.search(start_fill_text).group() + '\n')

        tmp_list = []
        for y in range(nuy):
          tmp_string = ''
          for x in range(nux):
            location = y*nux + x
            tmp_string = tmp_string + str(arrayData[array_num]['unitGivenLocation'][location]) + ' '
          tmp_string = tmp_string + '\n'
          tmp_list.append(tmp_string)

        for tmp_string in tmp_list:
          new_input.insert(start_fill+1,tmp_string)
        """ delete the lines that contain units
            make new string of units nux long, with nuy number of rows
            can use unitsByLocation (not these are newt location numbers)
            insert the new lines into new_input and add /n to each line
            """
#        for line in new_input[start_fill:end_fill+6]:
#          print line

  return new_input
Beispiel #3
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
Beispiel #4
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
def fixUnitsWithArrays(new_input, unitGeom=0, arrayData=0):

    print 'Running fixUnitsWithArrays'

    if unitGeom == 0:
        unitGeom = getUnitGeom(new_input)
    if arrayData == 0:
        arrayData = getArrayData(new_input)

    start_geom = findLineNumWithComments(new_input, 'read geom')
    end_geom = findLineNumWithComments(new_input,
                                       'end geom',
                                       start_index=start_geom)
    """ Start by calculating the x and y dimensions of the array. 
        A) Find nux and nuy
        B) Make a list of units which span the x and y dimensions of the array
        C) Find the size of each of these units
          1)  Find which region is the boundary for the unit
          2) Find the dimension of that region
        D) Sum up the unit dimensions to ge the array dimension """

    # Remove any redundant spaces to make parsing simpler
    for line_num in range(start_geom, end_geom):
        new_input[line_num] = re.sub('[ ]+', ' ', new_input[line_num])

    for array_num in arrayData.keys():
        units_x = []
        units_y = []
        nux = arrayData[array_num]['nux']
        nuy = arrayData[array_num]['nuy']
        for position in range(nux):
            units_x.append(arrayData[array_num]['unitGivenLocation'][position])
        # this units_y part will only work for a cuboidal array
        for position in range(0, nux * nuy, nux):
            units_y.append(arrayData[array_num]['unitGivenLocation'][position])
        unit_size = []
        array_size_x = 0.0
        for unit in units_x:
            boundary_region = unitGeom[unit]['boundaryRegion']
            unit_size = abs(
                unitGeom[unit][boundary_region]['dimension']['x+']) + abs(
                    unitGeom[unit][boundary_region]['dimension']['x-'])
            array_size_x = array_size_x + unit_size
#    print array_size_x
        unit_size = []
        array_size_y = 0.0
        for unit in units_y:
            boundary_region = unitGeom[unit]['boundaryRegion']
            unit_size = abs(
                unitGeom[unit][boundary_region]['dimension']['y+']) + abs(
                    unitGeom[unit][boundary_region]['dimension']['y-'])
            array_size_y = array_size_y + unit_size
#    print array_size_y
        """ Now for each array:
        E) go to the unit where the array is described
        F) Read the array definition
        G) Determine which surface is being filled in the array
        H) If this surface is larger than array_size_x and array_size_y
          1) Make a new surface that has dimensions array_size_x and array_size_y
            a) If array_size_x == array_size_y
              i) Adjust the x+ and x- equally to get the correct size surface
              ii) Adjust the y+ and y- equally to get the correct size surface
            b) If array_size_x != array_size_y
              i) Adjust the x+ dimension to get the correct size surface
              ii) Adjust the y- dimension to get the correct size surface
          2) Change the array definition such that this new_surface is the one being filled
          3) Add "-" + new_suface_number to the media describing the old surface number
    """
        # This is the unit where the array is used
        unit = arrayData[array_num]['locatedInUnit']
        #    print 'The Unit we want is ', unit
        # Find the start and end of the desciption for the unit
        unit_search = re.compile(r'unit\s+(\d+)')
        search_line = start_geom
        for line_num in range(start_geom, end_geom):
            tmp_line_num = findLineNumWithComments(new_input,
                                                   'unit',
                                                   start_index=search_line)
            tmp_unit = int(
                unit_search.search(new_input[tmp_line_num]).groups()[0])
            if unit == tmp_unit:
                start_unit = tmp_line_num
                break
            else:
                search_line = tmp_line_num + 1
        end_unit = findLineNumWithComments(new_input,
                                           'boundary',
                                           start_index=start_unit)

        # Find where the array is described
        array_search = re.compile(r'array\s+(\d+)')
        for line_num in range(start_unit, end_unit):
            tmp_line_num = findLineNumWithComments(new_input,
                                                   'array',
                                                   start_index=line_num)
            possible_array = int(
                array_search.search(new_input[tmp_line_num]).groups()[0])
            if array_num == possible_array:
                array_line = tmp_line_num
                break
#    print new_input[array_line]

# Read the array information
        array_reader = re.compile(r'array([a-zA-Z0-9.\-+ ]+)place')
        tmp_string = array_reader.search(new_input[array_line]).groups()[0]
        tmp_list = string2list(tmp_string)
        # The bounding surface for the array is the one that is not negative
        for i in range(1, len(tmp_list)):
            if tmp_list[i].find('-') == -1:
                array_surf = int(tmp_list[i])


#    print 'array surf is ', array_surf

# Find the dimensions of the array surface being used
        x_plus = unitGeom[unit][array_surf]['dimension']['x+']
        x_minus = unitGeom[unit][array_surf]['dimension']['x-']
        y_plus = unitGeom[unit][array_surf]['dimension']['y+']
        y_minus = unitGeom[unit][array_surf]['dimension']['y-']
        surf_x_length = abs(x_plus - x_minus)
        surf_y_length = abs(y_plus - y_minus)

        # See if the array surface size is the same as the sum of the length of the units filling it
        if surf_x_length == array_size_x and surf_y_length == array_size_y:
            print 'Array', array_num, 'seems OK. Continuing...'
            pass
        else:
            print 'Array', array_num, ': The surface used to define the array is larger than the sum of the length of the units filling it.'
            print 'This will cause issues in KENO/MCDancoff.'
            print 'Attempting to fix the problem'
            x_diff = surf_x_length - array_size_x
            y_diff = surf_y_length - array_size_y
            if array_size_x == array_size_y:
                new_x_plus = x_plus - x_diff / 2.0
                new_x_minus = x_minus + x_diff / 2.0
                new_y_plus = y_plus - y_diff / 2.0
                new_y_minus = y_minus + y_diff / 2.0
            else:
                new_x_plus = x_plus - x_diff
                new_x_minus = x_minus
                new_y_plus = y_plus
                new_y_minus = y_minus + y_diff
            """ Start making the new surface for the array to be filled into """

            # Pick a new surface # that is not already in use
            tmp_list = unitGeom[unit].keys()
            new_surf_num = 999
            for num in range(999, 0, -1):
                if new_surf_num in tmp_list:
                    new_surf_num = new_surf_num - 1
                else:
                    break

            # Make the new surface by copying the old one and editing it's values
            shape = unitGeom[unit][array_surf]['shape']
            array_surf_line = findLineNumWithComments(new_input,
                                                      shape + ' ' +
                                                      str(array_surf),
                                                      start_index=start_unit)
            new_surf_list = string2list(new_input[array_surf_line])
            #      print new_input[array_surf_line]
            new_surf_list[1] = str(new_surf_num)
            new_surf_list[2] = str(new_x_plus)
            new_surf_list[3] = str(new_x_minus)
            new_surf_list[4] = str(new_y_plus)
            new_surf_list[5] = str(new_y_minus)
            new_surf_definition = ' '.join(new_surf_list)
            #      print new_surf_definition

            # Change the array definition to use the new surface
            new_array_list = string2list(new_input[array_line])
            # The bounding surface for the array is the one that is not negative
            for i in range(2, len(new_array_list)):
                if new_array_list[i].find('-') == -1:
                    new_array_list[i] = str(new_surf_num)
                    break
            new_array_definition = ' '.join(new_array_list)
            #      print new_array_definition

            # Write the new surface definition to the input
            new_input.insert(array_surf_line, new_surf_definition + '\n')
            new_input.insert(array_surf_line,
                             "'The new surface is defined below \n")

            # Write the new array definition to the input
            # Check if the array definition line number changed first
            if array_line > array_surf_line:
                array_line = array_line + 2
            new_input[array_line] = "'Old: " + new_input[array_line]
            new_input.insert(array_line, new_array_definition + '\n')
            new_input.insert(array_line, "'The new array is defined below \n")
            """ Now need to change the media that describes the original 
          surface number to also exclude the new surface number """
            # Find where the array is described, then append '-' + new_surf_num
            array_search = re.compile(r'array\s+(\d+)')
            for line_num in range(start_unit, end_unit):
                tmp_line_num = findLineNumWithComments(
                    new_input, 'media', start_index=tmp_line_num)
                tmp_list = string2list(new_input[tmp_line_num])
                if str(array_surf) in tmp_list[3:]:
                    media_line = tmp_line_num
                    tmp_list.append(' ' + '-' + str(new_surf_num))
                    new_media_line = ' '.join(tmp_list)
                    break
                else:
                    tmp_line_num = tmp_line_num + 1

            new_input[media_line] = "'Old: " + new_input[media_line] + '\n'
            new_input.insert(media_line, new_media_line + '\n')
            new_input.insert(media_line, "'The new media is defined below \n")
    return new_input