From 2147331fcd1c3c6ccb4213cc3a10e8cf7bf9f474 Mon Sep 17 00:00:00 2001 From: Adam Nelson Date: Fri, 27 Apr 2018 09:33:05 -0400 Subject: [PATCH 1/4] Updating c5g7 model --- mg-criticality/make_library.py | 4 ++-- mg-criticality/repo.py | 7 ++++--- mg-criticality/run_cases.py | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mg-criticality/make_library.py b/mg-criticality/make_library.py index 2c61700..f6bcb0c 100755 --- a/mg-criticality/make_library.py +++ b/mg-criticality/make_library.py @@ -552,10 +552,10 @@ def create_6g(): [0.000, 0.000, 2.000, 0.00, 0.00, 0.00], [0.000, 0.000, 0.000, 2.00, 0.00, 0.00], [0.000, 0.000, 0.000, 0.275, 0.60, 0.00], - [0.000, 0.000, 2.000, 0.033, 0.171, 0.024]]]) + [0.000, 0.000, 0.000, 0.033, 0.171, 0.024]]]) scatter = np.rollaxis(scatter, 0, 3) total = [0.240, 0.975, 3.10, 3.10, 0.975, 0.240] - chi = [0.48, 0.02, 0.0, 0.0, 0.02, 0.048] + chi = [0.48, 0.02, 0.0, 0.0, 0.02, 0.48] URR = set_it('URR', groups, 0, fiss, nu, absorption, scatter, total, chi) mg_cross_sections_file.add_xsdata(URR) diff --git a/mg-criticality/repo.py b/mg-criticality/repo.py index 7dc2230..5339bcf 100644 --- a/mg-criticality/repo.py +++ b/mg-criticality/repo.py @@ -3,10 +3,11 @@ from make_model import Case # GLOBAL DATA -batches = 5000 -inactive = 500 -particles = 10000 +batches = 600 +inactive = 100 +particles = 100000 tab_leg = {'enable': True, 'num_points': 33} +# tab_leg = {'enable': False, 'num_points': 33} def build_cases(): diff --git a/mg-criticality/run_cases.py b/mg-criticality/run_cases.py index d228d46..eec1e27 100755 --- a/mg-criticality/run_cases.py +++ b/mg-criticality/run_cases.py @@ -2,6 +2,7 @@ from __future__ import print_function from optparse import OptionParser +import pickle import matplotlib.pyplot as plt import numpy as np @@ -32,6 +33,7 @@ if options.list_cases: print('Case Name: {0}'.format(key)) exit() +results = [] # Run specific case, if requested if options.case_name: if options.case_name in repo.names: @@ -48,6 +50,7 @@ if options.case_name: print(case.name + ' Failed Execution!') else: print_case(case) + results.append(case) else: print('Invalid Case Name: ' + options.case) @@ -66,3 +69,6 @@ else: print(case.name + ' Failed Execution!') else: print_case(case) + results.append(case) + +pickle.dump(results, open("save.pkl", "wb")) From 77d705342136d87469c25b9b2bc37369e851ee5f Mon Sep 17 00:00:00 2001 From: Adam G Nelson Date: Sat, 19 Oct 2019 08:44:52 -0500 Subject: [PATCH 2/4] Storing Sood changes --- mg-criticality/make_library.py | 37 ++++++++++++++++++++++------ mg-criticality/make_model.py | 8 ++++--- mg-criticality/repo.py | 26 ++++---------------- mg-criticality/run_cases.py | 44 +++++++++++++++++++++++++--------- 4 files changed, 73 insertions(+), 42 deletions(-) diff --git a/mg-criticality/make_library.py b/mg-criticality/make_library.py index 2c61700..ad3d25b 100755 --- a/mg-criticality/make_library.py +++ b/mg-criticality/make_library.py @@ -16,6 +16,27 @@ GROUP_STRUCT = {1: openmc.mgxs.EnergyGroups(group_edges=[0.0, 20.0e6]), ############################################################################### +def check_it(scatter_matrix): + import scipy.special as ss + groups = scatter_matrix.shape[0] + orders = scatter_matrix.shape[2] + Nmu = 50 + mu = np.linspace(-1, 1, Nmu) + f = np.zeros(shape=(groups, groups, Nmu)) + neg = False + for gin in range(groups): + for gout in range(groups): + data = np.array(scatter_matrix[gin, gout, :], copy=True) + if np.sum(data) > 0: + data /= data[0] + for l in range(orders): + f[gin, gout, :] += ((float(l) + 0.5) * + ss.eval_legendre(l, mu) * data[l]) + if np.any(f[gin, gout, :] < 0): + neg = True + return neg + + def plot_it(scatter_matrix): import matplotlib.pyplot as plt import scipy.special as ss @@ -44,6 +65,9 @@ def plot_it(scatter_matrix): def set_it(name, groups, order, fission, nu, absorption, scatt, total, chi): + neg = check_it(scatt) + if neg: + print(name + ' is negative!') xsd = openmc.XSdata(name, groups) xsd.order = order if fission is not None: @@ -305,7 +329,6 @@ def create_2g(): scatter = np.rollaxis(scatter, 0, 3) total = [0.2208, 0.3360] chi = [0.575, 0.425] - Pu = set_it('Pu', groups, 0, fiss, nu, absorption, scatter, total, chi) mg_cross_sections_file.add_xsdata(Pu) @@ -462,7 +485,7 @@ def create_2g(): capture = [0.0087078, 0.02518] absorption = np.add(capture, fiss) scatter = np.array( - [[[0.31980, 0.0045552], + [[[0.31980, 0.004555], [0.000000, 0.42410]]]) scatter = np.rollaxis(scatter, 0, 3) total = [0.33588, 0.54628] @@ -491,8 +514,8 @@ def create_2g(): ########################################################################### # 5.2.2 UD2O-1 nu = [2.50, 2.50] - fiss = np.array([0.0028172, 0.097]) - capture = [0.0087078, 0.02518] + fiss = np.array([0.002817, 0.097]) + capture = [0.008708, 0.02518] absorption = np.add(capture, fiss) scatter = np.array( [[[0.31980, 0.06694], [0.004555, -0.0003972]], @@ -526,7 +549,7 @@ def create_3g(): [0.000, 0.000, 2.000]]]) scatter = np.rollaxis(scatter, 0, 3) total = [0.240, 0.975, 3.10] - chi = [0.96, 0.05, 0.0] + chi = [0.96, 0.04, 0.0] URR = set_it('URR', groups, 0, fiss, nu, absorption, scatter, total, chi) mg_cross_sections_file.add_xsdata(URR) @@ -552,10 +575,10 @@ def create_6g(): [0.000, 0.000, 2.000, 0.00, 0.00, 0.00], [0.000, 0.000, 0.000, 2.00, 0.00, 0.00], [0.000, 0.000, 0.000, 0.275, 0.60, 0.00], - [0.000, 0.000, 2.000, 0.033, 0.171, 0.024]]]) + [0.000, 0.000, 0.000, 0.033, 0.171, 0.024]]]) scatter = np.rollaxis(scatter, 0, 3) total = [0.240, 0.975, 3.10, 3.10, 0.975, 0.240] - chi = [0.48, 0.02, 0.0, 0.0, 0.02, 0.048] + chi = [0.48, 0.02, 0.0, 0.0, 0.02, 0.48] URR = set_it('URR', groups, 0, fiss, nu, absorption, scatter, total, chi) mg_cross_sections_file.add_xsdata(URR) diff --git a/mg-criticality/make_model.py b/mg-criticality/make_model.py index a80ebd7..fab41bb 100644 --- a/mg-criticality/make_model.py +++ b/mg-criticality/make_model.py @@ -55,7 +55,7 @@ class Case(object): mats.append(openmc.Material(name=self.mat_names[i])) mats[-1].set_density('macro', 1.0) mats[-1].add_macroscopic(macros[-1]) - materials_file.add_material(mats[-1]) + materials_file += [mats[-1]] materials_file.cross_sections = GROUP_FILES[self.groups] @@ -101,6 +101,8 @@ class Case(object): settings_file.source = openmc.source.Source(space=uniform_dist) + settings_file.output = {'summary': False} + return settings_file def make_tallies(self, r=None): @@ -303,7 +305,7 @@ class Case(object): def execute(self, quiet=True): returncode = openmc.run(output=(not quiet)) spfile = 'statepoint.' + str(self.batches) + '.h5' - sp = openmc.StatePoint(spfile) - self.keff = sp.k_combined[:] + sp = openmc.StatePoint(spfile, autolink=False) + self.keff = sp.k_combined return returncode diff --git a/mg-criticality/repo.py b/mg-criticality/repo.py index 7dc2230..b8bbe08 100644 --- a/mg-criticality/repo.py +++ b/mg-criticality/repo.py @@ -2,11 +2,11 @@ from make_model import Case -# GLOBAL DATA -batches = 5000 -inactive = 500 -particles = 10000 -tab_leg = {'enable': True, 'num_points': 33} +# GLOBAL OPTIONS +batches = 1000 +inactive = 50 +particles = 2000 +tab_leg = {'enable': True} def build_cases(): @@ -574,22 +574,6 @@ def build_cases(): params)) names[name] = len(cases) - 1 - # # CASE -11 - # case = -11 - # name = 'Ua-1-1-IN' - # mat_names = ['Ua1'] - # groups = 1 - # order = 1 - # geom = 'IN' - # rad = [1.] - # ref_k = 2.25 - # mesh_dim = [20, 1, 1] - # params = {'mesh_dim': mesh_dim, 'tab_leg': tab_leg, 'batches': batches, - # 'inactive': inactive, 'particles': particles} - # cases.append(Case(case, name, mat_names, groups, order, geom, rad, ref_k, - # params)) - # names[name] = len(cases) - 1 - # CASE 36 case = 36 name = 'Ua-1-1-CY' diff --git a/mg-criticality/run_cases.py b/mg-criticality/run_cases.py index d228d46..361207b 100755 --- a/mg-criticality/run_cases.py +++ b/mg-criticality/run_cases.py @@ -1,20 +1,18 @@ #!/usr/bin/env python -from __future__ import print_function from optparse import OptionParser - -import matplotlib.pyplot as plt -import numpy as np +import csv import repo import make_library def print_case(case): - bias = np.abs(1.0E5 * (case.keff[0] - case.ref_k)) - print('\tCalculated keff = {0:1.6f}'.format(case.keff[0])) + bias = 1.0E5 * (case.keff - case.ref_k) + print('\tCalculated keff = {0:1.6f}'.format(case.keff)) print('\tReference keff = {0:1.6f}'.format(case.ref_k)) print('\tBias [pcm] = {0:1.1f}'.format(bias)) + return bias # Command line parsing @@ -33,6 +31,10 @@ if options.list_cases: exit() # Run specific case, if requested +case_nums = [] +case_names = [] +biases = [] +codes = [] if options.case_name: if options.case_name in repo.names: case_num = repo.names[options.case_name] @@ -46,8 +48,12 @@ if options.case_name: code = case.execute(False) if code != 0: print(case.name + ' Failed Execution!') + bias = 0. else: - print_case(case) + bias = print_case(case) + biases.append(bias) + case_names.append(case.name) + case_nums.append(case_num) else: print('Invalid Case Name: ' + options.case) @@ -62,7 +68,23 @@ else: print(case.number, case.name) case.make_model() code = case.execute(True) - if code != 0: - print(case.name + ' Failed Execution!') - else: - print_case(case) + bias = print_case(case) + + biases.append(bias) + case_names.append(case.name) + codes.append(code) + case_nums.append(case.number) + + +# Write to a CSV +with open("results.csv", mode="w") as csv_file: + writer = csv.writer(csv_file, delimiter=",", quotechar='"', + quoting=csv.QUOTE_NONNUMERIC) + + # write the header + writer.writerow(['Case ID', 'Case Name', 'Eigenvalue Bias [pcm]', + 'Error Code']) + + # Now run each case + for i in range(len(case_nums)): + writer.writerow([case_nums[i], case_names[i], biases[i], codes[i]]) From 448e2ffd12bd533a1b662cb54f1b5dac752e8137 Mon Sep 17 00:00:00 2001 From: Adam Nelson Date: Sat, 19 Oct 2019 19:15:58 -0500 Subject: [PATCH 3/4] fixed c5g7 --- mg-criticality/make_model.py | 10 ++++------ mg-criticality/repo.py | 2 -- mg-criticality/run_cases.py | 5 +++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mg-criticality/make_model.py b/mg-criticality/make_model.py index fab41bb..b941fbf 100644 --- a/mg-criticality/make_model.py +++ b/mg-criticality/make_model.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import numpy as np import openmc @@ -225,10 +223,10 @@ class Case(object): surfs = [] for r, rad in enumerate(self.rad): if r == len(self.rad) - 1: - surfs.append(openmc.ZCylinder(R=rad, + surfs.append(openmc.ZCylinder(r=rad, boundary_type='vacuum')) else: - surfs.append(openmc.ZCylinder(R=rad)) + surfs.append(openmc.ZCylinder(r=rad)) # Instantiate Cells cells = [] @@ -244,9 +242,9 @@ class Case(object): surfs = [] for r, rad in enumerate(self.rad): if r == len(self.rad) - 1: - surfs.append(openmc.Sphere(R=rad, boundary_type='vacuum')) + surfs.append(openmc.Sphere(r=rad, boundary_type='vacuum')) else: - surfs.append(openmc.Sphere(R=rad)) + surfs.append(openmc.Sphere(r=rad)) # Instantiate Cells cells = [] diff --git a/mg-criticality/repo.py b/mg-criticality/repo.py index b8bbe08..4dca3ec 100644 --- a/mg-criticality/repo.py +++ b/mg-criticality/repo.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - from make_model import Case # GLOBAL OPTIONS diff --git a/mg-criticality/run_cases.py b/mg-criticality/run_cases.py index 361207b..98d02cd 100755 --- a/mg-criticality/run_cases.py +++ b/mg-criticality/run_cases.py @@ -83,8 +83,9 @@ with open("results.csv", mode="w") as csv_file: # write the header writer.writerow(['Case ID', 'Case Name', 'Eigenvalue Bias [pcm]', - 'Error Code']) + 'Eigenvalue Bias Std. Dev. [pcm]', 'Error Code']) # Now run each case for i in range(len(case_nums)): - writer.writerow([case_nums[i], case_names[i], biases[i], codes[i]]) + writer.writerow([case_nums[i], case_names[i], biases[i].n, + biases[i].s, codes[i]]) From 2dfea8514f0fa3f355e62a269f3fb208977184f5 Mon Sep 17 00:00:00 2001 From: Adam G Nelson Date: Sat, 2 Nov 2019 11:18:18 -0500 Subject: [PATCH 4/4] Fixing changes requested by @paulromano: appending material list and fixing error handling. --- mg-criticality/make_model.py | 19 +++++++++++++------ mg-criticality/run_cases.py | 17 ++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/mg-criticality/make_model.py b/mg-criticality/make_model.py index fab41bb..83998ba 100644 --- a/mg-criticality/make_model.py +++ b/mg-criticality/make_model.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import numpy as np +from subprocess import CalledProcessError import openmc import openmc.checkvalue as cv @@ -55,7 +56,7 @@ class Case(object): mats.append(openmc.Material(name=self.mat_names[i])) mats[-1].set_density('macro', 1.0) mats[-1].add_macroscopic(macros[-1]) - materials_file += [mats[-1]] + materials_file.append(mats[-1]) materials_file.cross_sections = GROUP_FILES[self.groups] @@ -303,9 +304,15 @@ class Case(object): geometry.export_to_xml() def execute(self, quiet=True): - returncode = openmc.run(output=(not quiet)) - spfile = 'statepoint.' + str(self.batches) + '.h5' - sp = openmc.StatePoint(spfile, autolink=False) - self.keff = sp.k_combined + success = True + try: + openmc.run(output=(not quiet)) + except CalledProcessError: + success = False - return returncode + if success: + spfile = 'statepoint.' + str(self.batches) + '.h5' + sp = openmc.StatePoint(spfile, autolink=False) + self.keff = sp.k_combined + + return success diff --git a/mg-criticality/run_cases.py b/mg-criticality/run_cases.py index 361207b..def9690 100755 --- a/mg-criticality/run_cases.py +++ b/mg-criticality/run_cases.py @@ -46,14 +46,15 @@ if options.case_name: print('Running Case\n') case.make_model() code = case.execute(False) - if code != 0: + if code: + bias = print_case(case) + else: print(case.name + ' Failed Execution!') bias = 0. - else: - bias = print_case(case) biases.append(bias) case_names.append(case.name) case_nums.append(case_num) + codes.append(code) else: print('Invalid Case Name: ' + options.case) @@ -68,14 +69,16 @@ else: print(case.number, case.name) case.make_model() code = case.execute(True) - bias = print_case(case) - + if code: + bias = print_case(case) + else: + print(case.name + ' Failed Execution!') + bias = 0. biases.append(bias) case_names.append(case.name) codes.append(code) case_nums.append(case.number) - # Write to a CSV with open("results.csv", mode="w") as csv_file: writer = csv.writer(csv_file, delimiter=",", quotechar='"', @@ -83,7 +86,7 @@ with open("results.csv", mode="w") as csv_file: # write the header writer.writerow(['Case ID', 'Case Name', 'Eigenvalue Bias [pcm]', - 'Error Code']) + 'Successful Execution']) # Now run each case for i in range(len(case_nums)):