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
def editArrayBlock(new_input): # This module addresses changes needed for the array block in order to convert # from Newt to Keno. The adjusted input is then returned. # # Adds 'nuz=1' for any arrays and removes any pinpow statements if present # NOTE: if many exceptions in the input begin breaking this code. It may be more # robust to read only the things wanted (nux=9, fill, end fill, etc) # r'^nux\D*(\d*)\b' for example to get nux, then insert nuz=1 print 'Running editArrayBlock' read_array = findLineNumWithComments(new_input, 'read arra') end_array = findLineNumWithComments(new_input, 'end arra',start_index=read_array) # This adds 'nuz=1' to any arrays for line_num in range(read_array + 1, end_array): if 'ara' in new_input[line_num]: for new_line in range(line_num, end_array): if 'nuy' in new_input[new_line] and 'nuz' not in new_input[new_line]: tmp_list = string2list(new_input[new_line]) for index in range(len(tmp_list)): if 'nuy' in tmp_list[index]: tmp_list.insert(index,'nuz=1') new_input[new_line] = ' '.join(tmp_list) + '\n' break # This removes a pinpow statement if present for line_num in range(read_array + 1, end_array): if 'ara' in new_input[line_num]: for new_line in range(line_num, end_array): if 'pinpow' in new_input[new_line]: tmp_list = string2list(new_input[new_line]) for index in range(len(tmp_list)): if 'pinpow' in tmp_list[index]: del(tmp_list[index]) if '=' in tmp_list[index] or 'yes' in tmp_list[index] or 'no' in tmp_list[index]: del(tmp_list[index]) if 'yes' in tmp_list[index] or 'no' in tmp_list[index]: del(tmp_list[index]) new_input[new_line] = ' '.join(tmp_list[:]) + '\n' break else: new_input[new_line] = ' '.join(tmp_list[:]) + '\n' break return new_input
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
def editGeomBlock(new_input): """ This module addresses changes needed for the geometry block in order to convert from Newt to Keno. The adjusted input is then returned. This module adds a z-dimension to the shapes that are described It removes any grid information from the "boundary" statement It adds an index and a position for the z-dimension for arrays Shorthand notation is identified if present for cuboids Note that ' '.join(tmp_list[0:x]) joins together elements 0 to x-1, with ' ' in between each element """ print 'Running editGeomBlock' read_geom = findLineNumWithComments(new_input, 'read geom') end_geom = findLineNumWithComments(new_input, 'end geom',start_index=read_geom) # In case some shorthand notation is used 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'] for line_num in range(read_geom + 1, end_geom): ########### Cylinder if 'cylinder' in new_input[line_num]: tmp_list = string2list(new_input[line_num]) new_input[line_num] = ' '.join(tmp_list[0:3]) + ' 20.0 -20.0 '+ ' '.join(tmp_list[3:]) + '\n' ########### Cuboid elif 'cuboid' in new_input[line_num]: tmp_list = string2list(new_input[line_num]) try: short = read_shorthand.search(tmp_list[2]).groups() except AttributeError: # No shorthand used new_input[line_num] = ' '.join(tmp_list[0:6]) + ' 20.0 -20.0 '+ ' '.join(tmp_list[6:]) + '\n' else: # There was shorthand new_input[line_num] = ' '.join(tmp_list[0:3]) + ' 20.0 -20.0 '+ ' '.join(tmp_list[3:]) + '\n' ############ Boundary elif 'boundary' in new_input[line_num]: tmp_list = string2list(new_input[line_num]) new_input[line_num] = 'boundary ' + tmp_list[1] + '\n' ############ Array elif 'array' in new_input[line_num]: tmp_list = string2list(new_input[line_num]) new_input[line_num] = ' '.join(tmp_list[0:6]) + ' 1 ' + ' '.join(tmp_list[6:8]) + ' 0.0 ' + ' '.join(tmp_list[8:]) + '\n' return new_input
def editBoundsBlock(new_input): # This module checks to see if boundary conditions are set to all reflective. # If they are not, then "all=refl" is inserted and a message is printed print 'Running editBoundsBlock' read_bounds = findLineNumWithComments(new_input, 'read bou') end_bounds = findLineNumWithComments(new_input, 'end bou') all_refl = 0 for line_num in range(read_bounds + 1, end_bounds): if 'all' in new_input[line_num]: all_refl = 1 if all_refl == 0: del(new_input[read_bounds + 1: end_bounds]) new_input.insert(read_bounds+1, 'all=refl') print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' print 'BOUNDARIES SET TO ALL REFLECTIVE' print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' return new_input
def editBottomOfNewtInput(new_input): """ editBottomOfNewtInput(new_input): This module addresses changes needed below the bounds block in order to convert from Newt to Keno. The adjusted input is then returned. Remove "end model" and add "end data". Also delete anything between "end bounds" and "end data" except for a plot block """ print 'Running edit BottomOfNewtInput' end_bounds = findLineNumWithComments(new_input, 'end bounds') end_model = findLineNumWithComments(new_input, 'end mod',start_index=end_bounds) # insert "end data" and delete "end model" new_input.insert(end_model+1,'end data\n') del(new_input[end_model:end_model+1]) # Delete everything BETWEEN "end bounds" and "end data" del(new_input[end_bounds+1:end_model]) return new_input
def editAboveCompositionBlock(new_input): print 'Running editAboveCompositionBlock' read_comp = findLineNumWithComments(new_input,'read comp') for line_num in range(read_comp): new_input[line_num] = "'/" + new_input[line_num] new_input.insert(0, "'batch_args \-m \n") new_input.insert(0, 'ce_v7_endf \n') new_input.insert(0, 'KENO input converted from NEWT \n') new_input.insert(0, '=csas6 parm=check \n') return new_input
def editBottomOfNewtInput(new_input): """ editBottomOfNewtInput(new_input): This module addresses changes needed below the bounds block in order to convert from Newt to Keno. The adjusted input is then returned. Remove "end model" and add "end data". Also delete anything between "end bounds" and "end data" except for a plot block """ print 'Running edit BottomOfNewtInput' end_bounds = findLineNumWithComments(new_input, 'end bounds') end_model = findLineNumWithComments(new_input, 'end mod', start_index=end_bounds) # insert "end data" and delete "end model" new_input.insert(end_model + 1, 'end data\n') del (new_input[end_model:end_model + 1]) # Delete everything BETWEEN "end bounds" and "end data" del (new_input[end_bounds + 1:end_model]) return new_input
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
def autoDan(filename): # Remove Excessive spaces blanks = re.compile(r'[ ]{4,}') for line_num in range(len(lines)): lines[line_num] = re.sub('[ ]{4,}',' ', lines[line_num]) # Edit the input so that parm=check read_comp = findLineNumWithComments(lines,'read comp') get_sequence = re.compile(r'=\s*(\S+)\b') tmp_line_num = 0 for line_num in range(read_comp): sequence_line = findLineNumWithComments(lines,'=',start_index=tmp_line_num) sequence = get_sequence.search(lines[sequence_line]).groups()[0] if 'shell' in sequence: tmp_line_num = sequence_line continue else: break print sequence # Check for parm, then add check if not there. if lines[sequence_line].find('parm') == -1: lines[sequence_line] = lines[sequence_line] + ' parm=check \n' else: # for line_num in range(read_comp): # new_input[line_num] = "'/" + new_input[line_num] # new_input.insert(0, "'batch_args \-m \n") # new_input.insert(0, 'ce_v7_endf \n') # new_input.insert(0, 'KENO input converted from NEWT \n') # new_input.insert(0, '=csas6 parm=check \n') return new_input # Find the scale_path and version scale_path = get_scale_root() find_version = re.compile(r'scale(\d+.\d+)') version = find_version.search(scale_path).groups()[0] # Setup the arguments needed to run Scale args = [] if '/' in scale_path: machine = posix args.append(scale_path + '/cmds/batch' + version) else: machine = windows args.append(scale_path + '\cmds\batch' + version + '.bat') args.append(' -m ') args.append(new_filename) Popen(args) if __name__ == '__main__': f = open(sys.argv[1], 'r') lines = f.read().split('\n') # Read all lines f.close() autoDan(lines)
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 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 keno2mcdancoff(data, filename): print 'Entering keno2mcdancoff' # Passed in all the accumulated data from the newt2keno routine new_input = data[0] compDataByMixtureID = data[1] mixAssignmentsGivenParentMix = data[2] parentMixGivenAssignedMix = data[3] unitGeom = data[4] unitsWithFuel = data[5] arrayData = data[6] fuelMixtures = data[7] # delete all lines below 'end bounds' and above 'end_data' end_bounds = findLineNumWithComments(new_input, 'end boun') end_data = findLineNumWithComments(new_input, 'end data', start_index=end_bounds) for i in range(end_bounds + 1, end_data): new_input.remove(i) # Add the new block needed for MCDancoff new_input.insert(end_bounds + 1, 'end start \n') new_input.insert(end_bounds + 1, 'read start \n') print arrayData[1].keys() print arrayData[1]['unitGivenLocation'].keys() print arrayData[1]['unitGivenLocation'][48] print unitsWithFuel print unitGeom[36].keys() print unitGeom[36][14].keys() print unitGeom[36][14]['shape'] print unitGeom[36][14]['dimension']['x+'] print unitGeom[36][13].keys() print unitGeom[36][13]['shape'] # Go through each array, check if fuel is present counter = 0 # Used to keep track of which lattice elements don't have fuel skipped_lat_loc = [ ] # Used to keep track of which lattice elements don't have fuel for array_num in arrayData.keys(): if arrayData[array_num]['fuel_present'] == 'yes': nux = arrayData[array_num]['nux'] nuy = arrayData[array_num]['nuy'] # Go through each unit inside the array, from last (bottom right) to first (top left) for newt_loc in range( len(arrayData[array_num]['unitGivenLocation'].keys()) - 1, -1, -1): keno_loc = len(arrayData[array_num] ['unitGivenLocation'].keys()) - 1 - newt_loc unit = arrayData[array_num]['unitGivenLocation'][newt_loc] if unit not in unitsWithFuel: new_input.insert(end_bounds + 2, "'This unit has no fuel \n") skipped_lat_loc.append(counter) # skipped_lat_loc.append(loc) # Change here, added this counter + 1 at 4:47 PM 12/19/11 counter += 1 continue ### Note this part will only work for square lattices currently else: counter = counter + 1 # Determine x,y coordinates in array num = float(keno_loc + 1) / nux diff = num - int((keno_loc + 1) / nux) if diff == 0: y = int(num) x = nux else: y = int(num) + 1 x = int(round(nux * diff)) # Determine the outermost region containing fuel in the unit max_size = 0.0 for surface in unitGeom[unit].keys(): if surface == 'boundaryRegion': continue else: # Check if the region has fuel in it if unitGeom[unit][surface][ 'mixtureID'] not in fuelMixtures: continue else: if unitGeom[unit][surface][ 'shape'] == 'cylinder': size = unitGeom[unit][surface]['radius'] elif unitGeom[unit][surface][ 'shape'] == 'cuboid': size = unitGeom[unit][surface][ 'dimension']['x+'] else: print 'SHAPE THAT IS NOT SUPPORTED IN keno2mcdancoff with unit = ', unit, ' surface = ', surface # Check size if size > max_size: max_size = size region = unitGeom[unit][surface][ 'mediaOrder'] # print region new_input.insert(end_bounds+2,'dancoff array '+ str(array_num) + ' ' + str(x) + ' ' + str(y) + \ ' 1 ' + ' unit ' + str(unit) + ' region ' + str(region) + '\n') """ Reverse the order of the MCDancoff Start Data. This will account for the difference between NEWT and KENO array definitions when the Dancoff output files are read. Also, change the skipped_lat_loc list. """ # Locate lines that have start data in them # read_start = findLineNumWithComments(new_input,'read start') # end_start = findLineNumWithComments(new_input,'end start') # tmp_list = new_input[read_start+1:end_start] # tmp_list.reverse() # new_input[read_start+1:end_start] = tmp_list # # size = nux*nuy # print skipped_lat_loc # for num in range(len(skipped_lat_loc)): # skipped_lat_loc[num] = size - skipped_lat_loc[num] # print skipped_lat_loc # Change the sequence to mcdancoff and the library to xn01 csas_line = findLineNumWithComments(new_input, '=csas') new_input.insert(csas_line, '=mcdancoff \n') del (new_input[csas_line + 1]) library_line = findLineNumWithComments(new_input, 'ce_v') new_input.insert(library_line, 'xn01 \n') del (new_input[library_line + 1]) # Write the mcdancoff input file new_filename = filename + '.mcdan.inp' g = open(new_filename, 'w') for line in new_input: g.write(line) g.close() # run_it(new_filename) return skipped_lat_loc
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 keno2mcdancoff(data,filename): print 'Entering keno2mcdancoff' # Passed in all the accumulated data from the newt2keno routine new_input = data[0] compDataByMixtureID = data[1] mixAssignmentsGivenParentMix = data[2] parentMixGivenAssignedMix = data[3] unitGeom = data[4] unitsWithFuel = data[5] arrayData = data[6] fuelMixtures = data[7] # delete all lines below 'end bounds' and above 'end_data' end_bounds = findLineNumWithComments(new_input,'end boun') end_data = findLineNumWithComments(new_input,'end data',start_index=end_bounds) for i in range(end_bounds+1,end_data): new_input.remove(i) # Add the new block needed for MCDancoff new_input.insert(end_bounds+1,'end start \n') new_input.insert(end_bounds+1,'read start \n') print arrayData[1].keys() print arrayData[1]['unitGivenLocation'].keys() print arrayData[1]['unitGivenLocation'][48] print unitsWithFuel print unitGeom[36].keys() print unitGeom[36][14].keys() print unitGeom[36][14]['shape'] print unitGeom[36][14]['dimension']['x+'] print unitGeom[36][13].keys() print unitGeom[36][13]['shape'] # Go through each array, check if fuel is present counter = 0 # Used to keep track of which lattice elements don't have fuel skipped_lat_loc = [] # Used to keep track of which lattice elements don't have fuel for array_num in arrayData.keys(): if arrayData[array_num]['fuel_present'] == 'yes': nux = arrayData[array_num]['nux'] nuy = arrayData[array_num]['nuy'] # Go through each unit inside the array, from last (bottom right) to first (top left) for newt_loc in range(len(arrayData[array_num]['unitGivenLocation'].keys())-1 , -1, -1): keno_loc = len(arrayData[array_num]['unitGivenLocation'].keys()) - 1 - newt_loc unit = arrayData[array_num]['unitGivenLocation'][newt_loc] if unit not in unitsWithFuel: new_input.insert(end_bounds+2,"'This unit has no fuel \n") skipped_lat_loc.append(counter) # skipped_lat_loc.append(loc) # Change here, added this counter + 1 at 4:47 PM 12/19/11 counter += 1 continue ### Note this part will only work for square lattices currently else: counter = counter + 1 # Determine x,y coordinates in array num = float(keno_loc+1)/nux diff = num - int((keno_loc+1)/nux) if diff == 0: y = int(num) x = nux else: y = int(num) + 1 x = int(round(nux*diff)) # Determine the outermost region containing fuel in the unit max_size = 0.0 for surface in unitGeom[unit].keys(): if surface == 'boundaryRegion': continue else: # Check if the region has fuel in it if unitGeom[unit][surface]['mixtureID'] not in fuelMixtures: continue else: if unitGeom[unit][surface]['shape'] == 'cylinder': size = unitGeom[unit][surface]['radius'] elif unitGeom[unit][surface]['shape'] == 'cuboid': size = unitGeom[unit][surface]['dimension']['x+'] else: print 'SHAPE THAT IS NOT SUPPORTED IN keno2mcdancoff with unit = ', unit, ' surface = ', surface # Check size if size > max_size: max_size = size region = unitGeom[unit][surface]['mediaOrder'] # print region new_input.insert(end_bounds+2,'dancoff array '+ str(array_num) + ' ' + str(x) + ' ' + str(y) + \ ' 1 ' + ' unit ' + str(unit) + ' region ' + str(region) + '\n') """ Reverse the order of the MCDancoff Start Data. This will account for the difference between NEWT and KENO array definitions when the Dancoff output files are read. Also, change the skipped_lat_loc list. """ # Locate lines that have start data in them # read_start = findLineNumWithComments(new_input,'read start') # end_start = findLineNumWithComments(new_input,'end start') # tmp_list = new_input[read_start+1:end_start] # tmp_list.reverse() # new_input[read_start+1:end_start] = tmp_list # # size = nux*nuy # print skipped_lat_loc # for num in range(len(skipped_lat_loc)): # skipped_lat_loc[num] = size - skipped_lat_loc[num] # print skipped_lat_loc # Change the sequence to mcdancoff and the library to xn01 csas_line = findLineNumWithComments(new_input,'=csas') new_input.insert(csas_line, '=mcdancoff \n') del(new_input[csas_line + 1]) library_line = findLineNumWithComments(new_input,'ce_v') new_input.insert(library_line, 'xn01 \n') del(new_input[library_line + 1]) # Write the mcdancoff input file new_filename = filename + '.mcdan.inp' g = open(new_filename, 'w') for line in new_input: g.write(line) g.close() # run_it(new_filename) return skipped_lat_loc