def getUnitGeom(lines): print 'Running getUnitGeom' unitGeom = {} # This is the dictionary which will contain Geometry and Mixture info for the lattice # Delete comments 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 # Find where the geometry block starts and ends start_geom = findLineNum(lines,'read geo') end_geom = findLineNum(lines,'end geo') # Start interrogating each unit read_geom_unit = re.compile(r'(\d+)') for line_num in range(start_geom + 1, end_geom): if 'unit' not in lines[line_num]: continue else: unit = read_geom_unit.search(lines[line_num]).groups() unit = int(unit[0]) end_of_unit = findLineNum(lines,'bound',start_index=line_num + 1) """ Now a unit which is in the lattice has been found and the lines describing the unit are known section reads keywords(ie. cylinder, media) and makes a dictionary regionDict that stores info for each region. When all data for all regions is assembled, regionDict is added to dictionary unitGeom for the appropriate unit. - To process the unit geometry, the lines are split such that each word/number is an element in the list geomData""" unitGeom[unit] = parseGeometryKeywords(lines[line_num + 1: end_of_unit + 1], unit) # print unitGeom[100] return unitGeom
def getUnitsWithFuel(lines,fuelMixtures=0): print 'Running getUnitsWithFuel' if fuelMixtures == 0: fuelMixtures = getFuelMixtures(lines) unitsWithFuel = [] # List of units that contain fuel material 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] read_geom = findLineNum(lines,'read geom') end_geom = findLineNum(lines,'end geom',start_index=read_geom) read_unit = re.compile(r'unit\D+(\d+)') read_media = re.compile(r'media\D+(\d+)') for line in lines[read_geom + 1 : end_geom]: if line.find('unit') != -1: unit_num = int(read_unit.search(line).groups()[0]) elif line.find('media') != -1: mixtureID = int(read_media.search(line).groups()[0]) # print mixtureID if mixtureID in fuelMixtures: # print 'mixtureID = ', mixtureID if unit_num not in unitsWithFuel: # print 'unit = ', unit_num unitsWithFuel.append(unit_num) else: continue # print unitsWithFuel return unitsWithFuel
def getMixtureAssignments(lines): ############################################################################ # If the 'assign' keyword is used in the Depletion Block, this routine # determines which mixture ID's are assigned so that they can be added # to the composition block for the MCDancoff Input. # If no assignments are present, set mixAssignmentsGivenParentMix = -1 print 'Running getMixtureAssignments in getDepletionData' # mixAssignmentsGivenParentMix = {} # This is the dictionary which will hold {mixtureID : [Assigned MixtureIDs]} # parentMixGivenAssignedMix = {} # This dictionary holds {Assigned mixture ID : Parent mixture ID} mixAssignmentsGivenParentMix = -1 parentMixGivenAssignedMix = -1 # Make sure comments are removed 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 # Check if depletion block exists start_depl = findLineNum(lines,'read dep') if start_depl == -1: print 'No Depletion Block Found: There are no mixtureID assignments' else: end_depl = findLineNum(lines,'end dep', start_index=start_depl) # Make into one long string all_lines = ' ' for line_num in range(start_depl,end_depl+1): all_lines = all_lines + lines[line_num] + ' ' # If assignments are present in the depletion block, then fill the dictionaries if 'assign' in all_lines: mixAssignmentsGivenParentMix = {} parentMixGivenAssignedMix = {} # Separate each word/number into a list depl_block = string2list(all_lines) # Now look for the keyword 'assign' to determine which mixtures aren't in the composition block for i in range(len(depl_block)): if depl_block[i] == 'assign': tmp_list = [] for j in range(i+2, len(depl_block)): if depl_block[j] == 'end': mixAssignmentsGivenParentMix[int(depl_block[i+1])] = tmp_list for assignedMix in tmp_list: parentMixGivenAssignedMix[assignedMix] = int(depl_block[i+1]) break else: tmp_list.append(int(depl_block[j])) # Return the dictionaries data = [parentMixGivenAssignedMix, mixAssignmentsGivenParentMix] return data
def getCompDataByMixtureID(lines): compDataByMixtureID = {} """ dictionary compDataByMixtureID will contain {mixID : {materialIndex : [list of strings for the composition data]}} where mixID and materialIndex are integers. An example is below: uo2 500 den=10.19 0.97 948.45 92235 2.93 92234 0.0261 92236 0.0135 92238 97.0304 end gd2o3 500 den=10.19 0.03 948.45 end This would be stored as follows: {500 :{0 :['uo2', '500', 'den=10.19', '0.97', ... , 'end']}, {1 :['gd2o3', '500', 'den=10.19', '0.03', '948.45', 'end']}} """ print 'Running getCompDataByMixtureID in getCompositionData' linesNoComm = lines[:] for line_num in range( len(linesNoComm) - 2, -1, -1 ): # Stepping back through input, need -2 cuz extra empty spot at end of list assigned if linesNoComm[line_num][0] == "'": del linesNoComm[line_num] # delete the comments start_compNoComm = findLineNum(linesNoComm, 'read comp') end_compNoComm = findLineNum(linesNoComm, 'end comp', start_index=start_compNoComm) # Need to add materials to the composition block that were "assigned" in the depletion block of the Newt input compString = '' for line_num in range(start_compNoComm + 1, end_compNoComm): if 'end' not in linesNoComm[line_num]: compString = compString + linesNoComm[line_num] + ' ' continue else: compString = compString + linesNoComm[line_num] compData_list = string2list(compString) compString = '' # A mixture ID may be made of several materials, account for that here # If the mixture ID already exists then add a new material (index for materials counts up from 0) mixID = int(compData_list[1]) if int(compData_list[1]) not in compDataByMixtureID.keys(): compDataByMixtureID[mixID] = {0: compData_list} else: materialIndex = len( compDataByMixtureID[mixID].keys() ) # If 0 is already taken, then len will return 1, which is used for the materialIndex compDataByMixtureID[mixID][materialIndex] = compData_list return compDataByMixtureID
def getCompDataByMixtureID(lines): compDataByMixtureID = {} """ dictionary compDataByMixtureID will contain {mixID : {materialIndex : [list of strings for the composition data]}} where mixID and materialIndex are integers. An example is below: uo2 500 den=10.19 0.97 948.45 92235 2.93 92234 0.0261 92236 0.0135 92238 97.0304 end gd2o3 500 den=10.19 0.03 948.45 end This would be stored as follows: {500 :{0 :['uo2', '500', 'den=10.19', '0.97', ... , 'end']}, {1 :['gd2o3', '500', 'den=10.19', '0.03', '948.45', 'end']}} """ print 'Running getCompDataByMixtureID in getCompositionData' linesNoComm = lines[:] for line_num in range(len(linesNoComm)-2,-1,-1): # Stepping back through input, need -2 cuz extra empty spot at end of list assigned if linesNoComm[line_num][0] == "'": del linesNoComm[line_num] # delete the comments start_compNoComm = findLineNum(linesNoComm,'read comp') end_compNoComm = findLineNum(linesNoComm,'end comp',start_index=start_compNoComm) # Need to add materials to the composition block that were "assigned" in the depletion block of the Newt input compString = '' for line_num in range(start_compNoComm+1, end_compNoComm): if 'end' not in linesNoComm[line_num]: compString = compString + linesNoComm[line_num] + ' ' continue else: compString = compString + linesNoComm[line_num] compData_list = string2list(compString) compString = '' # A mixture ID may be made of several materials, account for that here # If the mixture ID already exists then add a new material (index for materials counts up from 0) mixID = int(compData_list[1]) if int(compData_list[1]) not in compDataByMixtureID.keys(): compDataByMixtureID[mixID] = {0:compData_list} else: materialIndex = len(compDataByMixtureID[mixID].keys()) # If 0 is already taken, then len will return 1, which is used for the materialIndex compDataByMixtureID[mixID][materialIndex] = compData_list return compDataByMixtureID
def getUnitGeom(lines): print 'Running getUnitGeom' unitGeom = { } # This is the dictionary which will contain Geometry and Mixture info for the lattice # Delete comments 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 # Find where the geometry block starts and ends start_geom = findLineNum(lines, 'read geo') end_geom = findLineNum(lines, 'end geo') # Start interrogating each unit read_geom_unit = re.compile(r'(\d+)') for line_num in range(start_geom + 1, end_geom): if 'unit' not in lines[line_num]: continue else: unit = read_geom_unit.search(lines[line_num]).groups() unit = int(unit[0]) end_of_unit = findLineNum(lines, 'bound', start_index=line_num + 1) """ Now a unit which is in the lattice has been found and the lines describing the unit are known section reads keywords(ie. cylinder, media) and makes a dictionary regionDict that stores info for each region. When all data for all regions is assembled, regionDict is added to dictionary unitGeom for the appropriate unit. - To process the unit geometry, the lines are split such that each word/number is an element in the list geomData""" unitGeom[unit] = parseGeometryKeywords( lines[line_num + 1:end_of_unit + 1], unit) # print unitGeom[100] return unitGeom
def getUnitsWithFuel(lines, fuelMixtures=0): print 'Running getUnitsWithFuel' if fuelMixtures == 0: fuelMixtures = getFuelMixtures(lines) unitsWithFuel = [] # List of units that contain fuel material 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] read_geom = findLineNum(lines, 'read geom') end_geom = findLineNum(lines, 'end geom', start_index=read_geom) read_unit = re.compile(r'unit\D+(\d+)') read_media = re.compile(r'media\D+(\d+)') for line in lines[read_geom + 1:end_geom]: if line.find('unit') != -1: unit_num = int(read_unit.search(line).groups()[0]) elif line.find('media') != -1: mixtureID = int(read_media.search(line).groups()[0]) # print mixtureID if mixtureID in fuelMixtures: # print 'mixtureID = ', mixtureID if unit_num not in unitsWithFuel: # print 'unit = ', unit_num unitsWithFuel.append(unit_num) else: continue # print unitsWithFuel return unitsWithFuel
def getArrayData(lines, unitsWithFuel=0): print 'Running getArrayData' 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 if unitsWithFuel == 0: unitsWithFuel = getUnitsWithFuel(lines) arrayData = {} unitGivenLocation = {} locationsGivenUnit = {} # Find where the array block starts and ends start_array = findLineNum(lines, 'read arr') end_array = findLineNum(lines, 'end arr', start_index=start_array) # Merge the Array block into 1 line, remove excess spaces array_block = ' '.join(lines[start_array:end_array + 1]) array_block = re.sub('\s+', ' ', array_block) # Expand any FIDO style input that may be present # Need an exception for the error this will cause. If FIDO input found, expand it. read_fido = re.compile( r'((\d+)([rp])([a-zA-Z0-9.\-+]*))' ) # ie for 4p5.43e-5 the returned list will contain ['4p5.43e-5', '4', 'p', '5.43e-5'] for i in range(100): try: fido = read_fido.search(array_block).groups() except AttributeError: # No FIDO found, exit loop break else: num_r_or_p = int(fido[1]) tmp_list = array_block.split(fido[0]) new_string = '' if fido[2] == 'r': for num in range(int(fido[1])): new_string = new_string + fido[3] + ' ' array_block = tmp_list[0] + new_string + tmp_list[1] """ For each array, read the array #, nux, nuy, and type. Then from keywords 'fill' to 'end' read in the units for the array """ read_ara = re.compile(r'ara\D+(\d+)\b') read_nux = re.compile(r'nux\D+(\d+)\b') read_nuy = re.compile(r'nuy\D+(\d+)\b') read_typ = re.compile(r'typ[ =]*(\w*)\b') read_fill = re.compile(r'fill\s+\d+') """ 1) Determine how many arrays there are. 2) Use keyword 'ara' to navigate the array definitions. a) Split the array_block at 'ara' so that each array definition is isolated b) Read 'nux', 'nuy' and 'typ' into dictionary arrayData for each array 3) Store the unit numbers that belong to each array in a dictionary a) Begin reading unit numbers after keyword 'fill' b) Dictionaries unitGivenLocation and locationsGivenUnit will be populated and then added to the dictionary arrayData. """ array_numbers = [] ara_indices = [] fill_indices = [] arrays = [] for array in read_ara.finditer(array_block): array_numbers.append(int(array.groups()[0])) # Split each array definition into a spearate string arrays = array_block.split('ara') del (arrays[0]) for num in range(len(array_numbers)): ara = array_numbers[num] nux = int(read_nux.search(arrays[num]).groups()[0]) nuy = int(read_nuy.search(arrays[num]).groups()[0]) test4type = -1 test4type = arrays[num].find('typ') if test4type != -1: typ = read_typ.search(arrays[num]).groups()[0] else: typ = 'cuboidal' # This is the default in Scale arrayData[ara] = {'nux': nux, 'nuy': nuy, 'typ': typ} """ Now that the size and shape of each array is known, read in all the units for each array. These units will be stored in three different ways: 1) In a list called unitsList 2) In a dictionary called unitGivenLocation 3) In a dictionary called locationsGivenUnit These three data structures will be convenient for other modules to rely on. Begin reading unit numbers after the fill_index for each array. The number of units will be nux*nuy """ read_units = re.compile(r'(\d+)[ ,]*') for num in range(len(array_numbers)): units_list = [] unitGivenLocation = {} locationsGivenUnit = {} fill_index = arrays[num].find('fill') units_list = read_units.findall(arrays[num][fill_index:]) size = arrayData[array_numbers[num]]['nux'] * arrayData[ array_numbers[num]]['nuy'] if size != len(units_list): print 'Error - nux*nuy is not equal to the number of units entered in array ', ara exit for position in range(size): units_list[position] = int(units_list[position]) unitGivenLocation[position] = units_list[position] tmp_list = [] for position in range(size): tmp_list = [] if units_list[position] in locationsGivenUnit: continue else: tmp_list.append(position) for num2 in range(position + 1, size): if units_list[position] == units_list[num2]: tmp_list.append(num2) locationsGivenUnit[units_list[position]] = tmp_list arrayData[array_numbers[num]]['units_list'] = units_list arrayData[array_numbers[num]]['unitGivenLocation'] = unitGivenLocation arrayData[ array_numbers[num]]['locationsGivenUnit'] = locationsGivenUnit """ Now use unitsWithFuel so that it can be determined if an array has fuel in it. Add {'fuel_present' : zzz} to each array in arrayData. zzz is 'yes' or 'no'. """ for num in array_numbers: arrayData[num]['fuel_present'] = 'no' for unit in arrayData[num]['units_list']: if unit in unitsWithFuel: arrayData[num]['fuel_present'] = 'yes' break """ Now determine in what units the arrays are used in. Add this information to the dictionary arrayData. """ # Find where the array block starts and ends start_geom = findLineNum(lines, 'read geom') end_geom = findLineNum(lines, 'end geom', start_index=start_geom) array_search = re.compile(r'array\s+(\d+)') unit_search = re.compile(r'unit\s+(\d+)') for line in lines[start_geom:end_geom]: if line.find('unit') != -1: unit = int(unit_search.search(line).groups()[0]) if line.find('array') != -1: array_num = int(array_search.search(line).groups()[0]) arrayData[array_num]['locatedInUnit'] = unit print arrayData[200]['locatedInUnit'] return arrayData
def getLatticeUnits(lines): # Find where the array block starts and ends start_array = findLineNum(lines,'read arr') end_array = findLineNum(lines,'end arr',start_index=start_array) # Find nux and nuy to determine size of lattice # There may be arrays for control blades, etc so loop # through until nux = nuy (square array) read_nux = re.compile(r'^nux\D*(\d*)\b') read_nuy = re.compile(r'^nuy\D*(\d*)\b') nux = 0 # Initializing nux and nuy s.t. nux != nuy nuy = 1 while nux != nuy: for line_num in range(start_array,end_array): loc = lines[line_num].find('nux') if loc != -1: nux = read_nux.search(lines[line_num][loc:]).groups() new_start = line_num # will start searching for nuy here loc = -1 break # print nux for line_num in range(start_array,end_array): loc = lines[line_num].find('nuy') if loc != -1: nuy = read_nuy.search(lines[new_start][loc:]).groups() new_start = line_num # will start searching here next loop break # Now the size of the lattice is known # Read the units in. They are between keywords 'fill' and 'end' nux = int(nux[0]) nuy = int(nuy[0]) size = nux*nuy loc = -1 unitByLocation = {} locationsByUnit = {} for line_num in range(new_start,end_array): loc = lines[line_num].find('fill') if loc != -1: new_start = line_num # Will start looking at this line start_loc = loc + 4 # Will start looking after 'fill' loc = -1 break for line_num in range(new_start,end_array): loc = lines[line_num].find('end') if loc != -1: new_end = line_num # Will stop looking at this line end_loc = loc - 1 # Will stop looking before 'end' break all_lines = ' ' for line_num in range(new_start,new_end + 1): if line_num == new_start: all_lines = lines[line_num][start_loc:] elif line_num == new_end + 1: all_lines = all_lines + ' ' + lines[line_num][:end_loc] else: all_lines = all_lines + ' ' + lines[line_num] # Whole array is now one string. Parse for the unit numbers now. read_units = re.compile(r'\d+') units_list = read_units.findall(all_lines) for pos in range(size): units_list[pos] = int(units_list[pos]) unitByLocation[pos] = units_list[pos] #!! print units_list #!! print unitByLocation # Make a dictionary that lists all locations where a given unit is located tmp_list = [] # print 'len of units_list is ', len(units_list) for pos in range(size): tmp_list = [] if units_list[pos] in locationsByUnit: continue else: tmp_list.append(pos) for num in range(pos + 1,size): if units_list[pos] == units_list[num]: tmp_list.append(num) locationsByUnit[units_list[pos]] = tmp_list #!! print locationsByUnit latticeList = [units_list,unitByLocation,locationsByUnit] return latticeList
def getUnitGeom(filename): latticeInfo = { } # This is the dictionary which will contain Geometry and Mixture info for the lattice # 1) should be able to read from an object, which units are in the array??? # if so then next is: # 2) Know which mixtures numbers are fuels, get from some object # 3) Read Media to determine what the geometry is, and which is outermost fuel # if dealing with a legacy input which must be parsed, try this # Delete comments f = open(filename, 'r') lines = f.read().split('\n') # Read all lines 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 # Find where the array block starts and ends start_array = findLineNum(lines, 'read arr') end_array = findLineNum(lines, 'end arr') print start_array print end_array # Find nux and nuy to determine size of lattice # There may be arrays for control blades, etc so loop # through until nux = nuy (square array) read_nux = re.compile(r'^nux\D*(\d*)\b') read_nuy = re.compile(r'^nuy\D*(\d*)\b') nux = 0 # Initializing nux and nuy s.t. nux != nuy nuy = 1 while nux != nuy: for line_num in range(start_array, end_array): loc = lines[line_num].find('nux') if loc != -1: nux = read_nux.search(lines[line_num][loc:]).groups() new_start = line_num # will start searching for nuy here loc = -1 break # print nux for line_num in range(start_array, end_array): loc = lines[line_num].find('nuy') if loc != -1: nuy = read_nuy.search(lines[new_start][loc:]).groups() new_start = line_num # will start searching here next loop break # Now the size of the lattice is known # Read the units in. They are between keywords 'fill' and 'end' nux = int(nux[0]) nuy = int(nuy[0]) size = nux * nuy loc = -1 unitByLocation = {} locationsByUnit = {} for line_num in range(new_start, end_array): loc = lines[line_num].find('fill') if loc != -1: new_start = line_num # Will start looking at this line start_loc = loc + 4 # Will start looking after 'fill' loc = -1 break for line_num in range(new_start, end_array): loc = lines[line_num].find('end') if loc != -1: new_end = line_num # Will stop looking at this line end_loc = loc - 1 # Will stop looking before 'end' break all_lines = ' ' for line_num in range(new_start, new_end + 1): if line_num == new_start: all_lines = lines[line_num][start_loc:] elif line_num == new_end + 1: all_lines = all_lines + ' ' + lines[line_num][:end_loc] else: all_lines = all_lines + ' ' + lines[line_num] # Whole array is now one string. Parse for the unit numbers now. read_units = re.compile(r'\d+') units_list = read_units.findall(all_lines) for pos in range(size): units_list[pos] = int(units_list[pos]) unitByLocation[pos] = units_list[pos] #!! print units_list #!! print unitByLocation # Make a dictionary that lists all locations where a given unit is located tmp_list = [] # print 'len of units_list is ', len(units_list) for pos in range(size): tmp_list = [] if units_list[pos] in locationsByUnit: continue else: tmp_list.append(pos) for num in range(pos + 1, size): if units_list[pos] == units_list[num]: tmp_list.append(num) locationsByUnit[units_list[pos]] = tmp_list #!! print locationsByUnit ############################# # Maybe make a new file now # ############################# # Find where the geometry block starts and ends start_geom = findLineNum(lines, 'read g') end_geom = findLineNum(lines, 'end g') # Start interrogating each unit that is part of the lattice (in units_list) read_geom_unit = re.compile(r'(\d+)') for line_num in range(start_geom + 1, end_geom): if 'unit' not in lines[line_num]: continue else: unit = read_geom_unit.search(lines[line_num]).groups() unit = int(unit[0]) if unit not in units_list: continue else: # print unit for new_line in range(line_num + 1, end_geom): j = -1 j = lines[new_line].find('bound') if j != -1: end_of_unit = new_line # print end_of_unit break # Now a unit which is in the lattice has been found and the lines describing the unit are known # This section reads keywords(ie. cylinder, media) and makes a dictionary regionDict that # Stores info for each region. # When all data for all regions is assembled, regionDict is added to dictionary unitGeom # for the appropriate unit regionDict = {} read_shorthand = re.compile( r'^(\d+)([sp])([a-zA-Z0-9.\-+]*)' ) # ie for 4p5.43e-5 the returned list will contain ['4', 'p', '5.43e-5'] media_counter = 1 # Initialize to 1 each time a new unit is parsed for new_line in range(line_num + 1, end_of_unit + 1): geomData_tuple = re.split(',\s*|\s*', lines[new_line]) geomData = list( geomData_tuple) # convert the tuple into a list for i in range( len(geomData) - 1, -1, -1 ): # This loop removes any empty strings from geomData if geomData[i] == '': del geomData[i] # Check for shorthand notation, if no shorthand is used then none will be returned. # Need an exception for the error this will cause. If shorthand found, expand it. for i in range(len(geomData) - 1, -1, -1): try: short = read_shorthand.search(geomData[i]).groups() except AttributeError: # No shorthand, read it into dictionary continue else: num_r_or_p = int(short[0]) geomData[i] = short[2] x = 0 for z in range(i + 1, i + num_r_or_p): if short[1] == 'p' and x % 2 == 0: geomData.insert(z, '-' + short[2]) x = x + 1 else: geomData.insert(z, short[2]) x = x + 1 # Now that the geometry data has been parsed and shorthand has been expanded, read the values in a dictionary if geomData[0] == 'cylinder': regionDict[int(geomData[1])] = { 'shape': geomData[0], 'radius': float(geomData[2]) } elif geomData[0] == 'cuboid': regionDict[int(geomData[1])] = { 'shape': geomData[0], 'dimension': { 'x+': float(geomData[2]), 'x-': float(geomData[3]), 'y+': float(geomData[4]), 'y-': float(geomData[5]) } } # For 'media', we want to assign a mixtureID to a regionID. Select the regionID by whichever one is not negative. elif geomData[0] == 'media': for z in range(3, len(geomData)): j = geomData[z].find('-') if j == -1: regionID = geomData[z] break regionDict[int(regionID)]['mixtureID'] = int( geomData[1]) regionDict[int( regionID )]['mediaOrder'] = media_counter # This is needed for MCDancoff Inputs media_counter += 1 if float(geomData[2]) != 1.0: print 'Non-unity Density Multiplier in Unit ', unit, 'in region ', regionID print 'Value given is ', geomData[2] print 'WARNING - This is not accounted for yet when creating in Centrm Inputs ' elif geomData[0] == 'boundary': latticeInfo[unit] = regionDict # print unitGeom else: continue print 'WARNING - Presently Unsupported Keyword In Unit ', unit # print regionDict print latticeInfo[11] fuelMixtures = getFuelMixtures(lines) print fuelMixtures mixtureAssignments = parseDepletionBlock(lines)
def getArrayData(lines,unitsWithFuel=0): print 'Running getArrayData' 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 if unitsWithFuel == 0: unitsWithFuel = getUnitsWithFuel(lines) arrayData = {} unitGivenLocation = {} locationsGivenUnit = {} # Find where the array block starts and ends start_array = findLineNum(lines,'read arr') end_array = findLineNum(lines,'end arr',start_index=start_array) # Merge the Array block into 1 line, remove excess spaces array_block = ' '.join(lines[start_array:end_array + 1]) array_block = re.sub('\s+',' ', array_block) # Expand any FIDO style input that may be present # Need an exception for the error this will cause. If FIDO input found, expand it. read_fido = re.compile(r'((\d+)([rp])([a-zA-Z0-9.\-+]*))') # ie for 4p5.43e-5 the returned list will contain ['4p5.43e-5', '4', 'p', '5.43e-5'] for i in range(100): try: fido = read_fido.search(array_block).groups() except AttributeError: # No FIDO found, exit loop break else: num_r_or_p = int(fido[1]) tmp_list = array_block.split(fido[0]) new_string = '' if fido[2] == 'r': for num in range(int(fido[1])): new_string = new_string + fido[3] + ' ' array_block = tmp_list[0] + new_string + tmp_list[1] """ For each array, read the array #, nux, nuy, and type. Then from keywords 'fill' to 'end' read in the units for the array """ read_ara = re.compile(r'ara\D+(\d+)\b') read_nux = re.compile(r'nux\D+(\d+)\b') read_nuy = re.compile(r'nuy\D+(\d+)\b') read_typ = re.compile(r'typ[ =]*(\w*)\b') read_fill = re.compile(r'fill\s+\d+') """ 1) Determine how many arrays there are. 2) Use keyword 'ara' to navigate the array definitions. a) Split the array_block at 'ara' so that each array definition is isolated b) Read 'nux', 'nuy' and 'typ' into dictionary arrayData for each array 3) Store the unit numbers that belong to each array in a dictionary a) Begin reading unit numbers after keyword 'fill' b) Dictionaries unitGivenLocation and locationsGivenUnit will be populated and then added to the dictionary arrayData. """ array_numbers = [] ara_indices = [] fill_indices = [] arrays = [] for array in read_ara.finditer(array_block): array_numbers.append(int(array.groups()[0])) # Split each array definition into a spearate string arrays = array_block.split('ara') del(arrays[0]) for num in range(len(array_numbers)): ara = array_numbers[num] nux = int(read_nux.search(arrays[num]).groups()[0]) nuy = int(read_nuy.search(arrays[num]).groups()[0]) test4type = -1 test4type = arrays[num].find('typ') if test4type != -1: typ = read_typ.search(arrays[num]).groups()[0] else: typ = 'cuboidal' # This is the default in Scale arrayData[ara] = {'nux':nux, 'nuy':nuy, 'typ':typ} """ Now that the size and shape of each array is known, read in all the units for each array. These units will be stored in three different ways: 1) In a list called unitsList 2) In a dictionary called unitGivenLocation 3) In a dictionary called locationsGivenUnit These three data structures will be convenient for other modules to rely on. Begin reading unit numbers after the fill_index for each array. The number of units will be nux*nuy """ read_units = re.compile(r'(\d+)[ ,]*') for num in range(len(array_numbers)): units_list = [] unitGivenLocation = {} locationsGivenUnit = {} fill_index = arrays[num].find('fill') units_list = read_units.findall(arrays[num][fill_index:]) size = arrayData[array_numbers[num]]['nux']*arrayData[array_numbers[num]]['nuy'] if size != len(units_list): print 'Error - nux*nuy is not equal to the number of units entered in array ', ara exit for position in range(size): units_list[position] = int(units_list[position]) unitGivenLocation[position] = units_list[position] tmp_list = [] for position in range(size): tmp_list = [] if units_list[position] in locationsGivenUnit: continue else: tmp_list.append(position) for num2 in range(position + 1,size): if units_list[position] == units_list[num2]: tmp_list.append(num2) locationsGivenUnit[units_list[position]] = tmp_list arrayData[array_numbers[num]]['units_list'] = units_list arrayData[array_numbers[num]]['unitGivenLocation'] = unitGivenLocation arrayData[array_numbers[num]]['locationsGivenUnit'] = locationsGivenUnit """ Now use unitsWithFuel so that it can be determined if an array has fuel in it. Add {'fuel_present' : zzz} to each array in arrayData. zzz is 'yes' or 'no'. """ for num in array_numbers: arrayData[num]['fuel_present'] = 'no' for unit in arrayData[num]['units_list']: if unit in unitsWithFuel: arrayData[num]['fuel_present'] = 'yes' break """ Now determine in what units the arrays are used in. Add this information to the dictionary arrayData. """ # Find where the array block starts and ends start_geom = findLineNum(lines,'read geom') end_geom = findLineNum(lines,'end geom',start_index=start_geom) array_search = re.compile(r'array\s+(\d+)') unit_search = re.compile(r'unit\s+(\d+)') for line in lines[start_geom : end_geom]: if line.find('unit') != -1: unit = int(unit_search.search(line).groups()[0]) if line.find('array') != -1: array_num = int(array_search.search(line).groups()[0]) arrayData[array_num]['locatedInUnit'] = unit print arrayData[200]['locatedInUnit'] return arrayData