def _search_keff(guess, target, model_builder, model_args, print_iterations, print_output, guesses, results): """Function which will actually create our model, run the calculation, and obtain the result. This function will be passed to the root finding algorithm Parameters ---------- guess : Real Current guess for the parameter to be searched in `model_builder`. target_keff : Real Value to search for model_builder : collections.Callable Callable function which builds a model according to a passed parameter. This function must return an openmc.model.Model object. model_args : dict Keyword-based arguments to pass to the `model_builder` method. print_iterations : bool Whether or not to print the guess and the resultant keff during the iteration process. print_output : bool Whether or not to print the OpenMC output during the iterations. guesses : Iterable of Real Running list of guesses thus far, to be updated during the execution of this function. results : Iterable of Real Running list of results thus far, to be updated during the execution of this function. Returns ------- float Value of the model for the current guess compared to the target value. """ # Build the model model = model_builder(guess, **model_args) # Run the model and obtain keff sp_filepath = model.run(output=print_output) with openmc.StatePoint(sp_filepath) as sp: keff = sp.k_combined # Record the history guesses.append(guess) results.append(keff) if print_iterations: text = 'Iteration: {}; Guess of {:.2e} produced a keff of ' + \ '{:1.5f} +/- {:1.5f}' print(text.format(len(guesses), guess, keff.n, keff.s)) return keff.n - target
def _search_keff(guess, target, model_builder, model_args, print_iterations, print_output, guesses, results): """Function which will actually create our model, run the calculation, and obtain the result. This function will be passed to the root finding algorithm Parameters ---------- guess : Real Current guess for the parameter to be searched in `model_builder`. target_keff : Real Value to search for model_builder : collections.Callable Callable function which builds a model according to a passed parameter. This function must return an openmc.model.Model object. model_args : dict Keyword-based arguments to pass to the `model_builder` method. print_iterations : bool Whether or not to print the guess and the resultant keff during the iteration process. print_output : bool Whether or not to print the OpenMC output during the iterations. guesses : Iterable of Real Running list of guesses thus far, to be updated during the execution of this function. results : Iterable of Real Running list of results thus far, to be updated during the execution of this function. Returns ------- float Value of the model for the current guess compared to the target value. """ # Build the model model = model_builder(guess, **model_args) # Run the model and obtain keff keff = model.run(output=print_output) # Record the history guesses.append(guess) results.append(keff) if print_iterations: text = 'Iteration: {}; Guess of {:.2e} produced a keff of ' + \ '{:1.5f} +/- {:1.5f}' print(text.format(len(guesses), guess, keff[0], keff[1])) return (keff[0] - target)
def shield(rad, bool, outer, m_batches, m_error, neutrons): #MATERIALS# min = 1 max = outer R1 = rad[0] R2 = rad[1] mats = openmc.Materials() tungsten = openmc.Material(name='Tungsten') tungsten.set_density('g/cm3', 19.0) tungsten.add_element('W', 1.0) mats.append(tungsten) water = openmc.Material(name='Water') water.set_density('g/cm3', 1.0) water.add_element('H', 2.0) water.add_element('O', 1.0) mats.append(water) eurofer = openmc.Material(name='EUROFER97') eurofer.set_density('g/cm3', 7.75) eurofer.add_element('Fe', 89.067, percent_type='wo') eurofer.add_element('C', 0.11, percent_type='wo') eurofer.add_element('Mn', 0.4, percent_type='wo') eurofer.add_element('Cr', 9.0, percent_type='wo') eurofer.add_element('Ta', 0.12, percent_type='wo') eurofer.add_element('W', 1.1, percent_type='wo') eurofer.add_element('N', 0.003, percent_type='wo') eurofer.add_element('V', 0.2, percent_type='wo') mats.append(eurofer) boron = openmc.Material(name='Boron') boron.set_density('g/cm3', 2.37) boron.add_element('B', 1.0) mats.append(boron) #GEOMETRY# sphere1 = openmc.Sphere(R=min) sphere2 = openmc.Sphere(R=R1) sphere3 = openmc.Sphere(R=R2) sphere4 = openmc.Sphere(R=max) sphere5 = openmc.Sphere(R=15) sphere6 = openmc.Sphere(R=17, boundary_type='vacuum') vac1 = -sphere1 mat1 = +sphere1 & -sphere2 mat2 = +sphere2 & -sphere3 mat3 = +sphere3 & -sphere4 vac2 = +sphere4 & -sphere5 steel = +sphere5 & -sphere6 vac3 = +sphere6 vacuum1 = openmc.Cell(region=vac1) first = openmc.Cell(region=mat1) first.fill = tungsten second = openmc.Cell(region=mat2) second.fill = water third = openmc.Cell(region=mat3) third.fill = tungsten vacuum2 = openmc.Cell(region=vac2) vessel = openmc.Cell(region=steel) vessel.fill = boron vacuum3 = openmc.Cell(region=vac3) root = openmc.Universe(cells=(vacuum1, first, second, third, vacuum2, vessel, vacuum3)) geom = openmc.Geometry(root) #SETTINGS# batch = 2 max_batches = m_batches inactive = 1 particles = neutrons source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([14e6], [1]) sett = openmc.Settings() sett.batches = batch sett.trigger_active = True sett.trigger_max_batches = m_batches sett.inactive = inactive sett.particles = particles sett.output = {'tallies': False} sett.run_mode = 'fixed source' sett.source = source #TALLIES# tallies = openmc.Tallies() filter = openmc.SurfaceFilter(sphere6) tally = openmc.Tally(name='leakage') tally.scores = ['current'] tally.filters = [filter] trigger = openmc.Trigger('rel_err', m_error / 100) tally.triggers = [trigger] tallies.append(tally) model = openmc.model.Model(geom, mats, sett, tallies) #RUN# model.run(output=bool) #PLOT# #plots = openmc.Plots() #plot = openmc.Plot() #plot.basis = 'xz' #plot.origin = (0, 0, 0) #plot.width = (200, 200) #plot.pixels = (400, 400) #plot.color_by = 'material' #plot.colors = {tungsten: 'black', water: 'blue'} #plots.append(plot) #plots.export_to_xml() for i in reversed(range(batch, max_batches + 1)): filename = 'statepoint.' + str(i).zfill(len(str(max_batches))) + '.h5' if os.path.isfile(filename): sp = openmc.StatePoint(filename) break #print('file:',filename) leakage = sp.get_tally(name='leakage') leakage_mean = leakage.mean[0][0][0] leakage_error = leakage.std_dev[0][0][0] #print(leakage_mean) #print(leakage_error) dir = '/home/emiralle/shield_git' for zippath in glob.iglob(os.path.join(dir, '*.h5')): os.remove(zippath) return leakage_mean * 100, leakage_error * 100
def shield(rad, major, coil, bool, outer, m_batches, m_error, neutrons): #MATERIALS# min = coil max = outer+coil major_rad = major + outer R1 = rad[0] R2 = rad[1] mats = openmc.Materials() tungsten = openmc.Material(name='Tungsten carbide') tungsten.set_density('g/cm3', 15.63) tungsten.add_element('W', 1.0) tungsten.add_element('C', 1.0) mats.append(tungsten) water = openmc.Material(name='Water') water.set_density('g/cm3', 1.0) water.add_element('H', 2.0) water.add_element('O', 1.0) mats.append(water) copper = openmc.Material(name='Copper') copper.set_density('g/cm3', 8.5) copper.add_element('Cu', 1.0) mats.append(copper) eurofer = openmc.Material(name='EUROFER97') eurofer.set_density('g/cm3', 7.75) eurofer.add_element('Fe', 89.067, percent_type='wo') eurofer.add_element('C', 0.11, percent_type='wo') eurofer.add_element('Mn', 0.4, percent_type='wo') eurofer.add_element('Cr', 9.0, percent_type='wo') eurofer.add_element('Ta', 0.12, percent_type='wo') eurofer.add_element('W', 1.1, percent_type='wo') eurofer.add_element('N', 0.003, percent_type='wo') eurofer.add_element('V', 0.2, percent_type='wo') mats.append(eurofer) #GEOMETRY# cylinder = openmc.ZCylinder(R=min) shield1 = openmc.ZCylinder(R=R1) shield2 = openmc.ZCylinder(R=R2) shield3 = openmc.ZCylinder(R=max) top = major_rad-(max-min) shield_sph1 = openmc.Sphere(R=top) shield_sph2 = openmc.Sphere(R=major_rad-(max-min)+(max-R2)) shield_sph3 = openmc.Sphere(R=major_rad-(max-min)+(max-R2)+(R2-R1)) pit = sqrt(top**2+top**2) max_shield = sqrt(top**2+pit**2)+1 vessel_in = openmc.Sphere(R=major_rad) vessel_out = openmc.Sphere(R=max_shield, boundary_type='vacuum') magnet = -cylinder & -vessel_in mat1 = -shield1 & +cylinder & -shield_sph3 #work on this mat2 = -shield2 & +shield1 & -shield_sph2 #work on this mat3 = -shield3 & +shield2 & -shield_sph1 #work on this plasma = +shield3 & -shield_sph1 a = +shield_sph1 & -shield_sph2 & +shield2 #work on this b = +shield_sph2 & -shield_sph3 & +shield1 #work on this c = +shield_sph3 & -vessel_in & +cylinder #work on this vessel = +vessel_in & -vessel_out plasma_cell = openmc.Cell(region=plasma) #1 cop_mag = openmc.Cell(region=magnet) #2 cop_mag.fill = copper tung1 = openmc.Cell(region=mat1) #3 tung1.fill = tungsten wat = openmc.Cell(region=mat2) #4 wat.fill = water tung2 = openmc.Cell(region=mat3) #5 tung2.fill = tungsten ste_ves = openmc.Cell(region=vessel) #6 ste_ves.fill = eurofer tung_sph1 = openmc.Cell(region=a) #7 tung_sph1.fill = tungsten wat_sph = openmc.Cell(region=b) #8 wat_sph.fill = water tung_sph2 = openmc.Cell(region=c) #9 tung_sph2.fill = tungsten root = openmc.Universe(cells=(plasma_cell, cop_mag, tung1, wat, tung2, ste_ves, tung_sph1, wat_sph, tung_sph2)) geom = openmc.Geometry(root) root.plot(width=(600.0, 600.0), basis='xz') #SETTINGS# batch = 2 max_batches = m_batches inactive = 0 particles = neutrons source = openmc.Source() source.space = openmc.stats.Box((-top,-top,-top),(top,top,top)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([14e6], [1]) sett = openmc.Settings() sett.batches = batch sett.trigger_active = True sett.trigger_max_batches = m_batches sett.inactive = inactive sett.particles = particles sett.output = {'tallies': True} sett.run_mode = 'fixed source' sett.source = source #PLOT# plots = openmc.Plots() plot = openmc.Plot() #plot.type = 'voxel' plot.basis = 'xz' plot.origin = (0, 0, 0) plot.width = (600, 600) plot.pixels = (1000, 1000) plot.color_by = 'material' plot.colors = {tungsten: 'black', water: 'blue', eurofer: 'grey', copper: 'brown'} plots.append(plot) plots.export_to_xml() #TALLIES# tallies = openmc.Tallies() filter = openmc.CellFilter(cop_mag) tally = openmc.Tally(name='total') tally.scores = ['total'] tally.filters = [filter] trigger = openmc.Trigger('rel_err', m_error/100) tally.triggers = [trigger] tallies.append(tally) model = openmc.model.Model(geom, mats, sett, tallies) #RUN# model.run(output=bool) for i in reversed(range(batch,max_batches+1)): filename = 'statepoint.' +str(i).zfill(len(str(max_batches)))+ '.h5' if os.path.isfile(filename): sp = openmc.StatePoint(filename) break #print('file:',filename) leakage = sp.get_tally(name='total') leakage_mean = leakage.mean[0][0][0] leakage_error = leakage.std_dev[0][0][0] #print(leakage_mean) #print(leakage_error) dir = '/home/emiralle/shield_git' for zippath in glob.iglob(os.path.join(dir, '*.h5')): os.remove(zippath) return leakage_mean, leakage_error