def main(): halfwidth = 0.5 iterations = 100 xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) print "Cross Section: %s" %xs Chart = Gnuplot.Gnuplot() title = "100 iterations max" Chart.title(title) Chart.xlabel("Number of Bins (length of vectors)") Chart.ylabel("Dominant eigenvalue") Chart("set yrange[0.35:]") Histories = [500, 1000, 5000, 10000] Zones = [5, 10, 20, 30, 50, 75, 100, 200, 500] for h in Histories: eValues = [] for z in Zones: geo = Geometry.Geometry(z, [[-halfwidth, halfwidth]]) print "geoL %s\nHistories per iteration = %i" %(geo, h) uni = scipy.ones(geo.bins) uSource = fissionSource.histogramSource(uni, geo) mark = Markov.Markov(geo, xs, h) amc = arnoldiMC.arnoldiMC(mark) amc.arnoldi(uSource, iterations) eValues.append(amc.eValue) eData = Gnuplot.Data(Zones, eValues, with="lines", title="# histories: %i" %h) Chart.replot(eData)
def __init__(self, usage=None, version=None): """ __init__ will create all the necessary information you need to run the code. It parses the command line to understand all your options. """ if not usage: usage = 'usage: %prog [options] args' optparse.OptionParser.__init__(self, usage=usage, version=version) self.add_option("-f", "--file", dest="filename", type='string', default=None, help="gnuplot data filename") self.add_option("-b", "--bins", dest="bins", type="int", default="50", help="Number of spatial bins.") self.add_option("-w", "--width", dest="width", type="float", default="20", help="Width of slab.") self.add_option("-I", "--iterations", dest="I", type="string", default='[3, 5, 7, 10, 15, 20]', help="How many Arnoldi Iterations per trial.") self.add_option("-T", "--trials", dest="Trials", type="float", default=100, help="How many independent trials.") self.add_option("-r", "--run", dest="run", action="store_true", default=False, help="Perform calculation.") self.add_option("-s", "--source", dest="source", type="string", default='uniform', help="""Defines source distribution. Available sources: 'uniform' --- uniform distrbution 'pleft' --- point source in left most bin 'pright' --- point source in right most bin 'pcenter' --- point source in center bin""") self.options, self.args = self.parse_args() self.geo = Geometry.Geometry(self.options.bins, [[0,self.options.width]]) self.xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) if self.options.source == 'uniform': s = scipy.ones(self.options.bins) elif self.options.source == 'pleft': s = scipy.zeros(self.options.bins) s[0] = 1 elif self.options.source == 'pright': s = scipy.zeros(self.options.bins) s[-1] = 1 elif self.options.source == 'pcenter': mid = int(self.options.bins/2.0) s = scipy.zeros(self.options.bins) s[mid] = 1 else: s = eval(self.options.source) try: self.source = fissionSource.histogramSource(s, self.geo) except: raise ValueError, "Unsupported source distribution: %s" %self.options.source self.options.I = eval(self.options.I)
def main(): N = int(1E6) geo = Geometry.Geometry(10, [[-0.5, 0, 5]]) uni = scipy.ones(10) uSource = fissionSource.histogramSource(uni, geo) start = time.time() uSource.sample(N) end = time.time() elapsedTime = end - start print "Elapsedtime to sample %i neutrons: %s" % (N, elapsedTime)
def main(): xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) halfWidth = [0.5, 1.0, 5.0, 10.0, 30.0] # xs = CrossSection.CrossSection(xS=0) # halfWidth=[300] c = [1.615379, 1.277102, 1.024879, 1.007135, 1.0] histories = 1000 in_cycles = 5 a_cycles = 50 # n = particle.neutron() # bank = fissionBank.fissionBank() # bank.append(n,histories) # for part in bank: # part.setRandDirection() chart = Gnuplot.Gnuplot() chart.xlabel("Cycles") chart.ylabel("k-effective") chart.title("Histories = %i, Inactive Cycles = %i, Active Cycles = %i" %(histories, in_cycles, a_cycles)) chart("set key right bottom") chart("set yrange [0:*]") for i in xrange(len(halfWidth)): geo = Geometry.Geometry(10,[[-halfWidth[i], halfWidth[i]]]) print "xs: %s" %xs print "geo: %s" %geo print "Histories = %i" %histories source = makeFBank(histories) source = makeFSource(geo) pmc = powerMC.powerMC(geo, xs, in_cycles, a_cycles, histories) pmc.power(source) kbench = 1/(2*c[i] - 1) print "halfWidth: %s, k-benchmark: %8.6f" %(halfWidth[i], kbench) print "k-estimate = %8.6f, std.dev-est = %8.6E" %(pmc.k, math.sqrt(pmc.vark)) print "left-leakage: %i, right-leakage: %i, weight-killed: %i" %( pmc.minLeakage, pmc.maxLeakage, pmc.wgtKilled) data = Gnuplot.Data((pmc.k_inactive+pmc.convergence), with="lines", title="kest=%.6f, kvarest=%.2E, kcalc=%.6f" %(pmc.k, pmc.vark, kbench)) cycleData = Gnuplot.Data((pmc.k_inactive+pmc.cycle_k), with="points", title="cycle estimates") chart.replot(data, cycleData) srcChart = Gnuplot.Gnuplot() hs = fissionSource.histogramSource(pmc.source, pmc.geo) sourceData = Gnuplot.Data(hs, with='lines')
def __init__(self, gui): super(QWidget, self).__init__() self.title = "Coverage Test Visualizer" # For slider self.gui = gui # Window size param self.top = 150 self.left = 150 self.width = 1000 self.height = 1000 reset = QPushButton("Reset", self) reset.move(10, 20) run_test = QPushButton("Run Test", self) run_test.move(10, 50) reset.clicked.connect(self.show_reset) run_test.clicked.connect(self.show_test) # To get sprayer properties self.my_sprayer = Sprayer() # Call geometry class self.my_geometry = Geometry() self.sprayer_width = self.my_sprayer.sprayer_width self.sprayer_range = self.my_sprayer.sprayer_range self.spread_angle = self.my_sprayer.spread_angle # Get the made up surface for testing # self.surface = self.my_geometry.test_surface self.robot_base = self.my_geometry.robot_base # Get the grid size self.grid_size = self.my_geometry.grid_size '''We will get the pose from the Sprayer class. This is the default starting pose for now. We will update this variable to change sprayer pose''' self.pose = [0.5, 0.5, 0] # Should be 6D. 3D for now # Change this to change table height self.table_height = 0.15 # self.new_voxel = self.my_geometry.my_compute_mesh_to_voxel() self.InitWindow()
def testtrackHistory(): """ """ geo = Geometry.Geometry(10, [[-1, 1]]) xs = CrossSection.CrossSection() mark = Markov.Markov(geo, xs, histories=1000) n = particle.neutron() bank = fissionBank.fissionBank() bank.append(n, 5) newbank = fissionBank.fissionBank() print "xs: %s" % xs for neut in bank[:1]: neut.setRandDirection() mark.trackHistory(neut, newbank, 1.0)
def main(self): bins = 50 halfwidth=0.5 histories = 10000 iterations = 50 restarts = 5 geo = Geometry.Geometry(bins, [[-halfwidth,halfwidth]]) xs = CrossSection.CrossSection(xS=0.5,nu=1.0,xF=0.5,xG=0) self.mark = Markov.Markov(geo, xs, histories) self.mark.score = self.score self.Q = scipy.zeros((bins,0)) for i in xrange(bins): print "I am at %i" %i point = scipy.zeros((bins)) point[i] = 1 pSource = fissionSource.histogramSource(point,geo) self.response = fissionBank.fissionBank() self.mark.transport(pSource) q = fissionSource.histogramSource(self.response,geo) q = q*(1.0/self.mark.histories) self.printVector(q) self.Q = scipy.column_stack((self.Q,q)) q = scipy.ones(bins) q = q/scipy.linalg.norm(q,2) print "Calling Deterministic Arnoldi" adtm = ArnoldiDtm.Arnoldi(self.Q, iterations, restarts) eValues, eVectors = adtm.Arnoldi(q) print "Eigenvalues: " self.printVector(eValues) print "Dominant eigenvector: " self.printVector(eVectors[:,-1]) print "\nAll eigenvectors: " self.printM(eVectors) Chart = Gnuplot.Gnuplot() Chart.title("Histories per 'vector': %i, bins = %i" %(histories, bins)) length = len(eValues)-1 for i in xrange(5): data = Gnuplot.Data(eVectors[:,length-i],with='lines', title='vector %i' %i) Chart.replot(data)
def main(): histories = 10000 iterations = 10 xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) geo = Geometry.Geometry(10, [[-0.5, 0.5]]) uni = scipy.ones(geo.bins) point = scipy.zeros(geo.bins) point[0] = 1 uSource = fissionSource.histogramSource(uni, geo) pSource = fissionSource.histogramSource(point, geo) uSource = uSource / scipy.linalg.norm(uSource, 2) mark = Markov.Markov(geo, xs, histories) amc = arnoldiMC.arnoldiMC(mark) # calc_eVector(amc) EigenPairs(amc)
def testtransport(): """ """ geo = Geometry.Geometry(10, [[-1, 1]]) xs = CrossSection.CrossSection() mark = Markov.Markov(geo, xs, histories=1000) bank = fissionBank.fissionBank() n = particle.neutron() bank.append(n, 10) for neut in bank: neut.setRandDirection() newbank = mark.transport(bank, 1) print "leak-left: %.4f, leak-right: %.4f, weight-killed: %.4f" % ( mark.minLeakage, mark.maxLeakage, mark.wgtKilled)
def testRoulette(): """ """ geo = Geometry.Geometry(10, [[-1, 1]]) xs = CrossSection.CrossSection() mark = Markov.Markov(geo, xs, histories=1000) n = particle.neutron() bank = fissionBank.fissionBank() bank.append(n, 1000000) print "weight-in: %s" % (len(bank)) for i in xrange(len(bank)): bank[i] = mark.russianRoulette(bank[i]) print "\nweight-out: %s, +- %.4f" % (bankWeight(bank), math.sqrt( len(bank)))
def dummy(self, hw, Chart, title='None'): """ hw: Halfwidth of geometry Chart: Gnuplot object where plotting occurs. title: Title of plot, if None, title will be eigenvalue """ valuesvsBins = [] for bin in self.Bins: print "Bins = %i" %bin geo = Geometry.Geometry(bin, [[-hw,hw]]) mark = Markov.Markov(geo, self.xs, self.histories) amc = arnoldiMC.arnoldiMC(mark) uSource = fissionSource.histogramSource(scipy.ones(bin)) Values, Vectors = amc.arnoldi(uSource, self.iterations) valuesvsBins.append(Values[-1]) title = 'hw = %.2f' %hw kData = Gnuplot.Data(self.Bins, valuesvsBins, with='lines', title=title) Chart.replot(kData) return Chart
def Orthogonal(self, hw, bins): """ Orthogonal will run Arnoldi's method and determine if the basis vectors are orthogonal. hw: halfwidth of geometry bins: number of spatial bins """ geo = Geometry.Geometry(bins, [[-hw, hw]]) mark = Markov.Markov(geo, self.xs, self.histories) amc = arnoldiMC.arnoldiMC(mark) uSource = fissionSource.histogramSource(scipy.ones(bins)) Values, Vectors = amc.ERAM(uSource, 5, self.iterations) # Values, Vectors = amc.arnoldi(uSource, self.iterations) n = len(amc.Q) O = scipy.zeros((n, n)) for i in xrange(n): for j in xrange(n): O[i, j] = scipy.dot(amc.Q[i], amc.Q[j]) print "Orthogonality:" amc.printM(O)
def sampleTest(): geo = Geometry.Geometry(10,[[0,1]]) histories = 100000 HSX = [] HSErrors = [] source = scipy.ones(10) source[3:7] = source[3:7]*-1 source[2] = 3 source[5] = -3 HS = fissionSource.histogramSource(source, geo) HS = HS/scipy.linalg.norm(HS,2) for i in xrange(len(HS)): HSX.append(i) HSErrors.append(math.sqrt(abs(HS[i]))/math.sqrt(histories/geo.bins)) F1 = HS.sample(histories) F2 = HS.sample(histories) F3 = HS.sample(histories) F4 = HS.sample(histories) F5 = HS.sample(histories) H1 = fissionSource.histogramSource(F1, geo) H2 = fissionSource.histogramSource(F2, geo) H3 = fissionSource.histogramSource(F3, geo) H4 = fissionSource.histogramSource(F4, geo) H5 = fissionSource.histogramSource(F5, geo) H1 = H1/scipy.linalg.norm(H1,2) H2 = H2/scipy.linalg.norm(H2,2) H3 = H3/scipy.linalg.norm(H3,2) H4 = H4/scipy.linalg.norm(H4,2) H5 = H5/scipy.linalg.norm(H5,2) Chart = prinths(HS,HSX) printsample(H1, Chart) printsample(H2, Chart) printsample(H3, Chart) printsample(H4, Chart) printsample(H5, Chart) printErrors(HS, HSX, HSErrors, Chart)
def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title('qmcPACK Input Builder') manager = MainManager() self.window.add_accel_group(manager.get_accel_group()) manager.Setup() mainMenu = manager.get_widget("/MenuBar") mainBox = gtk.VBox() mainBox.pack_start(mainMenu, False, False) # Connect menu callbacks manager.SaveAsAction.connect("activate", self.save_as_callback) manager.SaveAction.connect("activate", self.save_callback) self.About = GUIAboutDialog() manager.AboutAction.connect("activate", self.about_callback) self.window.connect("delete_event", self.delete) notebook = gtk.Notebook() notebook.set_tab_pos(gtk.POS_LEFT) self.GeometryFrame = Geometry() self.WavefunctionFrame = Wavefunction() self.RunFrame = Run() notebook.append_page(self.GeometryFrame, gtk.Label("Geometry")) notebook.append_page(self.WavefunctionFrame, gtk.Label("Wave function")) notebook.append_page(self.RunFrame, gtk.Label("Run")) if (viewerOkay): self.Viewer = StructureViewer() notebook.append_page(self.Viewer, gtk.Label("Viewer")) mainBox.pack_start(notebook, False, False, 5) self.window.add(mainBox) # Setup dialogs buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK) self.SaveAsDialog = gtk.FileChooserDialog("Save qmcPACK input as", \ self.window, gtk.FILE_CHOOSER_ACTION_SAVE, buttons) self.SaveAsDialog.hide() self.Filename = None self.window.show_all()
def main(): histories = 1000 iterations = 50 trials = 50 halfWidth = 0.5 xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) print "Cross Section: %s" %xs geo = Geometry.Geometry(100, [[-halfWidth, halfWidth]]) mark = Markov.Markov(geo,xs, histories) uni = scipy.ones(geo.bins) uSource = fissionSource.histogramSource(uni, geo) Chart = Gnuplot.Gnuplot() Chart.xlabel('Iteration') Chart.ylabel('Eigenvalue estimate') Chart.title('histories per Arnoldi iteration: %i' %histories) for j in xrange(5): eValues = [] for i in xrange(trials): amc = arnoldiMC.arnoldiMC(mark) amc.arnoldi(uSource, iterations) print "eValue = %s" %amc.eValue eValues.append(amc.eValue) average_eValue = sum(eValues)/trials # Calculate Variance var_eValue = 0 for value in eValues: var_eValue += math.pow((value - average_eValue),2) var_eValue = var_eValue/(trials - 1) eData = Gnuplot.Data(eValues, with='lines', title="%6.4f, %6.4f" %(average_eValue, math.sqrt(var_eValue))) Chart.replot(eData)
import gnuplotFile if __name__ == "__main__": bins = 50 hw = 0.5 histories = [1000, 5000, 10000] amciterations = 3 amcrestarts = 20 pmcactive = amciterations*amcrestarts pmcinactive = 3 Chart = Gnuplot.Gnuplot() Chart.xlabel("Histories") Chart.ylabel("Standard Deviation") geo = Geometry.Geometry(bins, [[0, 2*hw]]) xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) uSource = fissionSource.histogramSource(scipy.ones(bins), geo) if len(sys.argv) < 2: raise IndexError gnuData = {} for h in histories: print "\nHistories = ------------ %i\n" %h amc = arnoldiMC.arnoldiMC(geo, xs, h, storeVectors=True) Values, Vectors = amc.ERAM(uSource, amcrestarts, amciterations) y = scipy.array(amc.eValues) yMeans = [scipy.mean(y[:i,-1]) for i in xrange(1,len(y))] yVar = [scipy.var(y[:i,-1]) for i in xrange(1,len(y))] yStd = scipy.sqrt(yVar)
parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbosity of ArnoldiMC output.") parser.add_option("-M", "--movie", dest="movie", type="string", default=None, help="Directory for convergence of eigenvector.") options, args = parser.parse_args() geo = Geometry.Geometry(options.bins, [[0, options.width]]) xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) if options.source == 'uniform': s = scipy.ones(options.bins) elif options.source == 'random': s = scipy.rand(options.bin) elif options.source == 'pleft': s = scipy.zeros(options.bins) s[0] = 1 elif options.source == 'pright': s = scipy.zeros(options.bins) s[-1] = 1 elif options.source == 'pcenter': mid = int(options.bins / 2.0) s = scipy.zeros(options.bins) s[mid] = 1
def main(): a = Geometry.Geometry() b = HeatMap(a) print(type(b)) print("Successfully completed \a")
def extract_data_from(input_ini_file): input_file = open(input_ini_file, 'r') temp_file = open("temp_file.txt", 'w') line = input_file.readline() while line: if (line.count('\n') == len(line)): pass else: i = 0 while i < len(line): if line[i] != ' ': i = i + 1 else: break temp_file.write(line[:i] + '\n') line = input_file.readline() input_file.close() temp_file.close() S4_Object = S4() read_mode = 0 file = open("temp_file.txt", 'r') line = file.readline() material_num = -1 geometry_num = -1 while line: if line.count('\n') == len(line): line = file.readline() continue elif re.match(r'\[GENERAL\]', line): read_mode = 0 elif re.match(r'\[OPTICAL\]', line): read_mode = 1 elif re.match(r'\[MATERIAL', line): material_num = material_num + 1 temp_material = Material.Material() S4_Object.optical_grating.add_material(temp_material) read_mode = 2 elif re.match(r'\[GEOMETRY', line): geometry_num = geometry_num + 1 temp_geometry = Geometry.Geometry() S4_Object.optical_grating.add_geometry(temp_geometry) read_mode = 3 else: if read_mode == 0: lattice_vector = [[1, 0], [0, 1]] height_min = -1.0 height_max = 1.0 if re.match(r'dimension', line): temp = int(re.findall(r'\d+.?\d*', line)[0]) print("temp: ", temp) S4_Object.optical_grating.set_dimension(temp) elif re.match(r'background_index', line): S4_Object.set_background_index( float(re.findall(r'\d+.?\d*', line)[0])) elif re.match(r'pitch_x', line): lattice_vector[0][0] = float( re.findall(r'\d+.?\d*', line)[0]) line = file.readline() if re.match(r'pitch_y', line): lattice_vector[1][1] = float( re.findall(r'\d+.?\d*', line)[0]) S4_Object.set_lattice_vector(lattice_vector) elif re.match(r'domain_max', line): height_max = float(re.findall(r'\d+.?\d*', line)[0]) line = file.readline() if re.match(r'domain_min', line): height_min = float(re.findall(r'\d+.?\d*', line)[0]) #S4_Object.set_height(height_max - height_min) elif re.match(r'rcwa_harmonics', line): fourier_series_num = float( re.findall(r'\d+.?\d*', line)[0]) line = file.readline() if re.match(r'rcwa_harmonics', line): if float(re.findall(r'\d+.?\d*', line)[0]) > fourier_series_num: fourier_series_num = float( re.findall(r'\d+.?\d*', line)[0]) S4_Object.set_fourier_series_num(fourier_series_num) elif re.match(r'depth', line): S4_Object.set_depth_array([ float(elem) for elem in re.findall(r'\d+.?\d*', line) ]) #elif re.match(r'slice_num', line): # S4_Object.optical_grating.set_layer_num(float(re.findall(r'\d+.?\d*', line)[0] + 2)) else: pass elif read_mode == 1: if re.match(r'free_space_wavelength', line): S4_Object.optic.set_free_space_wavelength( float(re.findall(r'\d+.?\d*', line)[0])) elif re.match(r'incidence_angle', line): S4_Object.optic.set_incidence_angle( float(re.findall(r'\d+.?\d*', line)[0])) elif re.match(r'azimuth_angle', line): S4_Object.optic.set_azimuth_angle( float(re.findall(r'\d+.?\d*', line)[0])) elif re.match(r'polarization_angle', line): S4_Object.optic.set_polarization_angle( float(re.findall(r'\d+.?\d*', line)[0])) elif re.match(r'polarization_phase_diff', line): S4_Object.optic.set_polarization_phase_diff( float(re.findall(r'\d+.?\d*', line)[0])) elif read_mode == 2: if re.match(r'name=', line): S4_Object.optical_grating.material_array[ material_num].set_name(line[5:len(line) - 1]) elif re.match(r'n=', line): S4_Object.optical_grating.material_array[ material_num].set_n( float(re.findall(r'\d+.?\d*', line)[0])) elif re.match(r'k=', line): S4_Object.optical_grating.material_array[ material_num].set_k( float(re.findall(r'\d+.?\d*', line)[0])) elif read_mode == 3: if re.match(r'poly_file=', line): vertex_array = [] if (line[10] == '\n'): vertex_array = [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]] else: poly_file_name = (line[10:])[:-1] poly_file = open(poly_file_name, 'r') line_poly = poly_file.readline() while line_poly: vertex = [ float(re.findall(r'\d+.?\d*', line)[0]), float(re.findall(r'\d+.?\d*', line)[1]) ] line_poly = poly_file.readline() vertex_array.append(vertex) S4_Object.optical_grating.geometry_array[ geometry_num].set_polygon_array(vertex_array) elif re.match(r'begin_x', line): x = float(re.findall(r'\d+.?\d*', line)[0]) line = file.readline() while line.count('\n') == len(line): line = file.readline() y = float(re.findall(r'\d+.?\d*', line)[0]) line = file.readline() while line.count('\n') == len(line): line = file.readline() #z = float(re.findall(r'\d+.?\d*', line)[0]) S4_Object.optical_grating.geometry_array[ geometry_num].set_begin_coordinate([x, y]) elif re.match(r'end_x', line): print("x: ", line) x = float(re.findall(r'\d+.?\d*', line)[0]) line = file.readline() while line.count('\n') == len(line): line = file.readline() print("y: ", line) y = float(re.findall(r'\d+.?\d*', line)[0]) line = file.readline() while line.count('\n') == len(line): line = file.readline() print("z: ", line) #z = float(re.findall(r'\d+.?\d*', line)[0]) S4_Object.optical_grating.geometry_array[ geometry_num].set_end_coordinate([x, y]) elif re.match(r'mat_name=', line): material_name = (line[9:])[:-1] S4_Object.optical_grating.geometry_array[ geometry_num].set_material_name(material_name) elif re.match(r'end_scaling', line): value = float(re.findall(r'\d+.?\d*', line)[0]) S4_Object.optical_grating.geometry_array[ geometry_num].set_scaling_size(value) else: pass line = file.readline() file.close() return S4_Object
fuel_rad = 0.4 rad = np.array([0.4, 0.3, 0.2, 0.1]) nCells = len(rad) + 1 nGrps = 2 NEWk = 1.0 k = 2.0 m = 2.0 iteration = 0 tmp = 1. / 4. / np.pi idx = range(rays) myidx = idx[rank:rays:size] print("Hello World! I am process %d of %d on %s.\n" % (rank, size, name)) #Initial functions G = Geometry(pitch, rays) #Initialize cross sections, source, etc F = Flux(fuel_rad, pitch, nCells, nGrps, NEWk, rad, rays) #Iterations while abs(k - NEWk) > 1e-5 or m > 1e-5: # for i in range(0,1): #Updates for this iteration iteration = iteration + 1 # random.seed(1) k = NEWk F.deltapsi_storage = np.zeros([rays, nCells, nGrps]) F.phibar = np.zeros([nCells, nGrps]) G.vol_storage = np.zeros([rays, nCells]) # G.vol = np.zeros(nCells)
def main(): # Step 1: Initialize ParticleManager PM = ParticleManager() PM.setIterationLimit(20) # Step 2: Generate Data # This step will hopefully not be explicityly needed in the future totalXS, scatterXS = DataGenerators.generateElasticElectronData(10) ionXS = DataGenerators.generateFakeInelasticElectronXS() xsec = XSections.XSection(totalXS[1], totalXS[0]) diffXS = Distribution.Distribution() diffXS.setDomain([-np.pi, np.pi]) diffXS.setPdfData(partial(Distribution.diffElasticElectronXS, 10)) ionXSec = XSections.XSection(ionXS[1], ionXS[0]) ionDist = Distribution.Distribution() ionDist.setDomain([0., 300. * TC._eV_Erg]) ionDist.setPdfData(Distribution.fakeIonizationElectron) # Step 3: Add Materials matMan = Material.MaterialManager() mat = Material.Material(14) mat.setZNumber(10) mat.setAtomicDensity(1.0 * (1 / 18.01) * TC._nAvogad) mat.setElectronScatterDistribution(diffXS.sample) mat.setElectronElasticXSHandle(xsec.getXSection) mat.setElectronEnergyLossHandle(ionDist.sample) mat.setElectronIonizationXSHandle(ionXSec.getXSection) mat.setElectronPhysics('inelastic') matMan.addMaterial(mat) PM.addMaterials(matMan) # Step 4: Add Geometry geoMan = Geometry.GeometryManager() geo = Geometry.Geometry(dim=3, coordSys='cartesian', iLimits=(-1e-5, 1e-5), jLimits=(-1e-5, 1e-5), kLimits=(0, 1e-5), coarseMesh=(1, 1, 1), fineI=[100], fineJ=[100], fineK=[100]) geo.setMaterial(14) geoMan.addGeometry(geo) PM.addGeometry(geoMan) # print(PM.matManager.matDict[14].zNumber) # Step 5: Add Source Particles soMan = Source.SourceManager() so = Source.Source() so.setLocation() so.setEnergy(1000) so.setDirection(np.array([0., 0., 1.])) so.setParticleType() so.setPopulation(10000) soMan.addSource(so) PM.addParticles(source=soMan) # Step 6: Create and add Tally tal = Tally.HeatMap(geo) # tal = Tally.PathTrack(geo) PM.addTally(tal) timerStart = time.process_time() PM.transportParticles() timerStop = time.process_time() # tal.createGraphic() tal.createGraphic(projection='xy') tal.createGraphic(projection='yz') tal.createGraphic(projection='xz') rms = tal.rmsVariance(10000) print("Root Mean Square variance: ", rms) elapsedTime = timerStop - timerStart print("Elapsed Time: ", elapsedTime) print("FOM: ", 1 / (rms * elapsedTime)) # tal.printEdgesToFile() # tal.printHeatMapToFile() return
import gnuplotFile if __name__ == "__main__": Chart = Gnuplot.Gnuplot() Chart.xlabel("iteration") Chart.ylabel("RMS Error") Chart("set logscale y") Chart.title("3 Restarts, 10 Iterations each") histories = [1000, 5000, 10000, 50000, 100000] bins = 50 halfwidth = 0.5 iterations = 3 restarts = 10 geo = Geometry.Geometry(bins, [[0, 2*halfwidth]]) xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) uSource = fissionSource.histogramSource(scipy.ones(bins), geo) # Deterministic sn3 = procOUTSN.procOutsn(sys.argv[1]) csHeight, csCenters = sn3.coursenSNFS(geo) snSource = fissionSource.histogramSource(csHeight, geo) gnuData = {} for h in histories: print "\nHistories %i" %h amc = arnoldiMC.arnoldiMC(geo, xs, h, storeVectors=True) # Values, Vectors = amc.arnoldi(uSource, iterations) Values, Vectors = amc.ERAM(uSource, restarts, iterations) # Values, Vectors = amc.ERAM(snSource, restarts, iterations)
if len(sys.argv) > 1: gFile = gnuplotFile.gnuplotFile(sys.argv[1], data) return Chart if __name__ == "__main__": # histories = [1000, 10000, 100000] histories = 10000 iterations = 11 halfWidth = [0.5, 1.0, 5.0, 10.0, 30.0] c = [1.615379, 1.277102, 1.024879, 1.007135, 1.0] xs = CrossSection.CrossSection(xS=0.5, nu=1.0, xF=0.5, xG=0) print "Cross Section: %s" %xs Chart = Gnuplot.Gnuplot() # Chart.title("histories = %i" %histories) # xs = CrossSection.CrossSection(xS=0.0) # geo = Geometry.Geometry(10,[[-300.0, 300.0]]) # print "geo: %s" %geo # Chart = arnoldiMCGeneral(geo, xs, histories, iterations, Chart) for i in xrange(len(halfWidth[:1])): geo = Geometry.Geometry(50,[[-halfWidth[i], halfWidth[i]]]) print "geo: %s" %geo print "Histories = %i" %histories Chart = arnoldiMCGeneral(geo, xs, histories, iterations, Chart)