From 23c146905bf15ed3e33a3c973d0bbb661677ff98 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:50:24 -0500 Subject: [PATCH 01/66] Add files via upload --- OpenMC_PhotonTransport.py | 202 ++++++++++++++++++++++++++++++++++++++ Photon_TallytoVtk.py | 35 +++++++ Source_Mesh_Reader.py | 41 ++++++++ 3 files changed, 278 insertions(+) create mode 100644 OpenMC_PhotonTransport.py create mode 100644 Photon_TallytoVtk.py create mode 100644 Source_Mesh_Reader.py diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py new file mode 100644 index 0000000..52b4c64 --- /dev/null +++ b/OpenMC_PhotonTransport.py @@ -0,0 +1,202 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Aug 7 10:07:33 2024 + +@author: Anupama Rajendra +""" + +import openmc +import argparse +import numpy as np + +Mesh_File = 'OpenMC_Mesh.h5m' +Strengths = [] +#Performing simulation for the first decay time +with open('Sum_1.txt', 'r') as Sum_1: + Lines = Sum_1.readlines() + Split = Lines[0].split() + for sums in Split: + Strengths.append(float(sums)) + +parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") + +#Required user inputs: +parser.add_argument('--filepath', type=str, required=True) +parser.add_argument('--element_1', type=str, required=True) +parser.add_argument('--element_2', type=str, required=True) +#Shell radii are left as user inputs, but the mesh is specific to W_inner_radius = 1000, W_outer_radius = 1005, C_inner_radius = 995 +parser.add_argument('--W_inner_radius', type=float, required=True) +parser.add_argument('--W_outer_radius', type=float, required=True) +parser.add_argument('--C_inner_radius', type=float, required=True) + +args = parser.parse_args() + +fp = args.filepath +E_1 = args.element_1 +E_2 = args.element_2 +R_W_1 = args.W_inner_radius +R_W_2 = args.W_outer_radius +R_C_1 = args.C_inner_radius + +# fp = '../../ALARA/data/elelib.std' +# E_1 = 'W' +# E_2 = 'C' +# R_W_1 = 1000 +# R_W_2 = 1005 +# R_C_1 = 995 +bounds = [0, + 1.00e+4, + 2.00e+4, + 5.00e+4, + 1.00e+5, + 2.00e+5, + 3.00e+5, + 4.00e+5, + 6.00e+5, + 8.00e+5, + 1.00e+6, + 1.22e+6, + 1.44e+6, + 1.66e+6, + 2.00e+6, + 2.50e+6, + 3.00e+6, + 4.00e+6, + 5.00e+6, + 6.50e+6, + 8.00e+6, + 1.00e+7, + 1.20e+7, + 1.40e+7, + 2.00e+7] + +#ALARA Element Library to read density for specified element: +# with open(""+fp+"") as ALARA_Lib: +with open("elelib.std") as ALARA_Lib: + Lib_Lines = ALARA_Lib.readlines() + +# Create materials & export to XML: +#Simulating tungsten shell: + +def make_W(element_1): + M_1 = openmc.Material(material_id=1, name=element_1) + for line in Lib_Lines: + if line.split()[0].lower() == element_1.lower(): + Density_M_1 = float(line.strip().split()[3]) + M_1.set_density('g/cm3', Density_M_1) + M_1.add_element(element_1, 1.00) + return M_1 + +def make_C(element_2): + M_2 = openmc.Material(material_id=2, name=element_2) + for line in Lib_Lines: + if line.split()[0].lower() == element_2.lower(): + #if line.startswith(element_2.lower()): + Density_M_2 = float(line.strip().split()[3]) + M_2.set_density('g/cm3', Density_M_2) + M_2.add_element(element_2, 1.00) + return M_2 + +def all_mat(M_1, M_2): + all_materials = openmc.Materials([M_1, M_2]) + all_materials.cross_sections = '../fendl-3.2-hdf5/cross_sections.xml' + all_materials.export_to_xml() + +# Create geometry +#Spherical shell: +def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_2): + S_W_1= openmc.Sphere(r=inner_radius_W) #sphere of radius 1000cm + inside_W_sphere_1 = -S_W_1 + outside_W_sphere_1 = +S_W_1 + S_W_2 = openmc.Sphere(r=outer_radius_W, boundary_type='vacuum') + inside_W_sphere_2 = -S_W_2 + outside_W_sphere_2 = +S_W_2 + S_W_3 = outside_W_sphere_1 & inside_W_sphere_2 #filled with specified material + + S_C_1= openmc.Sphere(r=inner_radius_C) #sphere of radius 995cm + inside_C_sphere_1 = -S_C_1 + outside_C_sphere_1 = +S_C_1 + S_C_3 = outside_C_sphere_1 & inside_W_sphere_1 #filled with specified material + + # Mapping materials to geometry: + Void = openmc.Cell(fill=None, region = inside_C_sphere_1) + W_Shell = openmc.Cell(fill=M_1, region=S_W_3) + C_Shell = openmc.Cell(fill=M_2, region=S_C_3) + Cells = [Void, W_Shell, C_Shell] + geometry = openmc.Geometry(Cells) + geometry.export_to_xml() + return geometry, Void, W_Shell, C_Shell, Cells + +#Define source: +def make_source(W_Shell, C_Shell, Cells): + Energy_List = [] + Source_List = [] + Particle_Filter = openmc.ParticleFilter('photon') + Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') + Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, volume_normalized=False) + for index, bound in enumerate(bounds[:-1]): + Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) + Energy_List.append(Energy_Dist) + Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=Strengths[index], particle='photon', domains=Cells)) + np.savetxt('Energy_List.txt', Energy_List, fmt='%s') + return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist + +# Define tallies +def tallies(W_Shell, C_Shell, Particle_Filter, Total_Mesh): + # global Total_Mesh + # global Total_Filter + Total_Filter = openmc.MeshFilter(Total_Mesh) + + neutron_tally = openmc.Tally(tally_id=1, name="Neutron tally") + neutron_tally.scores = ['flux', 'elastic', 'absorption'] + + # Implementing filter for neutron tally through W shell + global cell_filter + cell_filter = openmc.CellFilter([W_Shell, C_Shell]) + neutron_tally.filters = [cell_filter, Total_Filter] + + # Creating a tally to get the flux energy spectrum. + # An energy filter is created to assign to the flux tally. + energy_filter_flux = openmc.EnergyFilter.from_group_structure("VITAMIN-J-42") + + spectrum_tally = openmc.Tally(tally_id=2, name="Flux spectrum") + # Implementing energy and cell filters for flux spectrum tally + spectrum_tally.filters = [cell_filter, Total_Filter, energy_filter_flux, Particle_Filter] + spectrum_tally.scores = ['flux'] + + tall = openmc.Tallies([neutron_tally, spectrum_tally]) + tall.export_to_xml() + return tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter + +# Assign simulation settings +def settings(Source_List): + sets = openmc.Settings() + sets.batches = 10 + sets.inactive = 1 + sets.particles = 100000 + sets.source = Source_List + sets.run_mode = 'fixed source' + sets.export_to_xml() + return sets + +def plot_universe(Void, W_Shell, C_Shell, Cells): + universe_ss = openmc.Universe(cells=Cells) + Plot = universe_ss.plot(width=(2500.0, 2500.0), basis='xz', + colors={Void: 'blue', W_Shell: 'red', C_Shell: 'green'}, legend=True) + Plot.figure.savefig('Universe') + return universe_ss + +# Exporting materials, geometry, and tallies to .xml +def export_to_xml(element_1, element_2, inner_radius_W, outer_radius_W, inner_radius_C): + OpenMC_W = make_W(element_1) + OpenMC_C = make_C(element_2) + OpenMC_Mat = all_mat(OpenMC_W, OpenMC_C) + OpenMC_Geometry = make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, OpenMC_W, OpenMC_C) + OpenMC_Source = make_source(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) + OpenMC_Settings = settings(OpenMC_Source[0]) + OpenMC_Tallies = tallies(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Source[1], OpenMC_Source[2]) + OpenMC_Universe = plot_universe(OpenMC_Geometry[1], OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) + #return OpenMC_Materials, OpenMC_Geometry, OpenMC_Source, OpenMC_Settings, OpenMC_Tallies, OpenMC_Universe + return OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies + +M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, Mesh_Dist, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(E_1, E_2, R_W_1, R_W_2, R_C_1) \ No newline at end of file diff --git a/Photon_TallytoVtk.py b/Photon_TallytoVtk.py new file mode 100644 index 0000000..a167f42 --- /dev/null +++ b/Photon_TallytoVtk.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Oct 3 23:18:20 2024 + +@author: Anupama Rajendra +""" +import openmc +import matplotlib.pyplot as plt + +with openmc.StatePoint("statepoint.10.h5") as sp: + flux_spectrum = sp.get_tally(id=2) + mesh=sp.meshes[1] + # Get the reshaped tally data + tally_data_reshaped = flux_spectrum.get_reshaped_data(value='mean') + + # Print the shape of the tally data + print("Tally data shape:", tally_data_reshaped.shape) + + flux_sum_en = tally_data_reshaped.sum(axis=(0,1,3,4,5)) + #Vitamin-J energy filter: + e_filter = flux_spectrum.filters[2] + #Lower bounds of the energy bins + e_filter_lower = e_filter.bins[:, 0] + + # Plot flux spectrum + fix, ax = plt.subplots() + ax.loglog(e_filter_lower, flux_sum_en, drawstyle='steps-post') + ax.set_xlabel('Energy [eV]') + ax.set_ylabel('Flux [photon-cm/source]') + ax.grid(True, which='both') + plt.savefig('Photon_flux_vs_energy.png') + plt.show() + + mesh_data = tally_data_reshaped.sum(axis=(0,2,3,4,5)) + vtk = mesh.write_data_to_vtk(filename="Photon_Flux.vtk", datasets={"mean":mesh_data.flatten()}) \ No newline at end of file diff --git a/Source_Mesh_Reader.py b/Source_Mesh_Reader.py new file mode 100644 index 0000000..f991163 --- /dev/null +++ b/Source_Mesh_Reader.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Sep 30 15:16:44 2024 + +@author: Anupama Rajendra +""" + +import h5py +import numpy as np + +# Open the HDF5 files +File_1 = h5py.File("source_mesh_1.h5m", 'r') +File_2 = h5py.File("source_mesh_2.h5m", 'r') +Files = [File_1, File_2] + +# Number of photon groups +photon_groups = 24 + +# Process each file +for file_index, file in enumerate(Files): + # Extract data from the current file + tstt = file['tstt'] + elements = tstt['elements'] + tet_four = elements['Tet4'] + tags = tet_four['tags'] + sd = tags['source_density'][:] + + # Write source density to a separate file for each mesh + with open(f'source_density_{file_index + 1}.txt', 'w') as source: + for tet_element in sd: + source.write(' '.join(map(str, tet_element)) + '\n') + + # Calculate summed strengths for each photon group + summed_strengths = [] + for group in range(photon_groups): + strengths = np.sum(sd[:, group]) # Sum over all mesh elements + summed_strengths.append(strengths) + + # Write summed strengths to a separate file for each mesh + with open(f'summed_photon_strengths_{file_index + 1}.txt', 'w') as sums: + sums.write(' '.join(map(str, summed_strengths)) + '\n') \ No newline at end of file From 8d1f88b3a75c742aa767661ee2633ad167ed3a90 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:05:38 -0500 Subject: [PATCH 02/66] Deleted unused Energy_List lines --- OpenMC_PhotonTransport.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index 52b4c64..6f9b49a 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -129,14 +129,13 @@ def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_ #Define source: def make_source(W_Shell, C_Shell, Cells): - Energy_List = [] Source_List = [] Particle_Filter = openmc.ParticleFilter('photon') Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, volume_normalized=False) for index, bound in enumerate(bounds[:-1]): Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) - Energy_List.append(Energy_Dist) + #Source strengths given by Strengths list at the top Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=Strengths[index], particle='photon', domains=Cells)) np.savetxt('Energy_List.txt', Energy_List, fmt='%s') return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist @@ -199,4 +198,4 @@ def export_to_xml(element_1, element_2, inner_radius_W, outer_radius_W, inner_ra #return OpenMC_Materials, OpenMC_Geometry, OpenMC_Source, OpenMC_Settings, OpenMC_Tallies, OpenMC_Universe return OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies -M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, Mesh_Dist, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(E_1, E_2, R_W_1, R_W_2, R_C_1) \ No newline at end of file +M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, Mesh_Dist, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(E_1, E_2, R_W_1, R_W_2, R_C_1) From d7e58a3418a45e4801a43a371b00696cf38c36ec Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:19:29 -0500 Subject: [PATCH 03/66] Update OpenMC_PhotonTransport.py Co-authored-by: Paul Wilson --- OpenMC_PhotonTransport.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index 6f9b49a..b5a9675 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -14,9 +14,7 @@ #Performing simulation for the first decay time with open('Sum_1.txt', 'r') as Sum_1: Lines = Sum_1.readlines() - Split = Lines[0].split() - for sums in Split: - Strengths.append(float(sums)) + strengths = [float(strength) for strength in Lines[0].split()] parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") From 39e2d4bb6ef969c469b43c680cafb97d70a1806c Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:22:33 -0500 Subject: [PATCH 04/66] Delete unused 'Energy_List.txt' line --- OpenMC_PhotonTransport.py | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index b5a9675..1e47e40 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -135,7 +135,6 @@ def make_source(W_Shell, C_Shell, Cells): Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) #Source strengths given by Strengths list at the top Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=Strengths[index], particle='photon', domains=Cells)) - np.savetxt('Energy_List.txt', Energy_List, fmt='%s') return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist # Define tallies From 3dfb567f5a9d379a22c2b2ab482ad78ae4bec739 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:51:54 -0500 Subject: [PATCH 05/66] Delete print statement --- Photon_TallytoVtk.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Photon_TallytoVtk.py b/Photon_TallytoVtk.py index a167f42..ef03742 100644 --- a/Photon_TallytoVtk.py +++ b/Photon_TallytoVtk.py @@ -13,9 +13,6 @@ # Get the reshaped tally data tally_data_reshaped = flux_spectrum.get_reshaped_data(value='mean') - # Print the shape of the tally data - print("Tally data shape:", tally_data_reshaped.shape) - flux_sum_en = tally_data_reshaped.sum(axis=(0,1,3,4,5)) #Vitamin-J energy filter: e_filter = flux_spectrum.filters[2] @@ -32,4 +29,4 @@ plt.show() mesh_data = tally_data_reshaped.sum(axis=(0,2,3,4,5)) - vtk = mesh.write_data_to_vtk(filename="Photon_Flux.vtk", datasets={"mean":mesh_data.flatten()}) \ No newline at end of file + vtk = mesh.write_data_to_vtk(filename="Photon_Flux.vtk", datasets={"mean":mesh_data.flatten()}) From 5bb02ff3a777254354364aca0065e951483b3457 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:57:17 -0500 Subject: [PATCH 06/66] Remove summed strengths text file as output --- Source_Mesh_Reader.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source_Mesh_Reader.py b/Source_Mesh_Reader.py index f991163..91c2d3f 100644 --- a/Source_Mesh_Reader.py +++ b/Source_Mesh_Reader.py @@ -30,12 +30,12 @@ for tet_element in sd: source.write(' '.join(map(str, tet_element)) + '\n') - # Calculate summed strengths for each photon group + # Calculate summed (and individual mesh) strengths for each photon group summed_strengths = [] + strengths_list = [] for group in range(photon_groups): - strengths = np.sum(sd[:, group]) # Sum over all mesh elements - summed_strengths.append(strengths) - - # Write summed strengths to a separate file for each mesh - with open(f'summed_photon_strengths_{file_index + 1}.txt', 'w') as sums: - sums.write(' '.join(map(str, summed_strengths)) + '\n') \ No newline at end of file + total_strengths = np.sum(sd[:, group]) # Sum over all mesh elements + summed_strengths.append(total_strengths) + strengths = sd[:,group] + strengths_list.append(strengths) + From 1fdb1b18f0abb83012d63e44c019119f7471c87b Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:58:55 -0500 Subject: [PATCH 07/66] Read summed photon strengths from Source_Mesh_Reader - Reading total strengths directly from Source_Mesh_Reader instead of writing a new list in this script --- OpenMC_PhotonTransport.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index 1e47e40..2c0a9c0 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -8,13 +8,9 @@ import openmc import argparse import numpy as np +from Source_Mesh_Reader import summed_strengths Mesh_File = 'OpenMC_Mesh.h5m' -Strengths = [] -#Performing simulation for the first decay time -with open('Sum_1.txt', 'r') as Sum_1: - Lines = Sum_1.readlines() - strengths = [float(strength) for strength in Lines[0].split()] parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") @@ -134,7 +130,7 @@ def make_source(W_Shell, C_Shell, Cells): for index, bound in enumerate(bounds[:-1]): Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) #Source strengths given by Strengths list at the top - Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=Strengths[index], particle='photon', domains=Cells)) + Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=summed_strengths[index], particle='photon', domains=Cells)) return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist # Define tallies From 569eb280573278377c53663379eadd93d2418941 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:25:35 -0500 Subject: [PATCH 08/66] Add source strengths for each individual mesh element - Brought the MeshBase object inside the loop over the energy bounds --- OpenMC_PhotonTransport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index 2c0a9c0..12116c2 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -8,7 +8,7 @@ import openmc import argparse import numpy as np -from Source_Mesh_Reader import summed_strengths +from Source_Mesh_Reader import summed_strengths, strengths_list Mesh_File = 'OpenMC_Mesh.h5m' @@ -126,10 +126,10 @@ def make_source(W_Shell, C_Shell, Cells): Source_List = [] Particle_Filter = openmc.ParticleFilter('photon') Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') - Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, volume_normalized=False) for index, bound in enumerate(bounds[:-1]): + Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=strengths_list[index], volume_normalized=False) Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) - #Source strengths given by Strengths list at the top + #Source strengths given by strengths_list created by Source_Mesh_Reader Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=summed_strengths[index], particle='photon', domains=Cells)) return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist From 1008270848ee62a88f3139ea5853453e02baaa45 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:29:44 -0500 Subject: [PATCH 09/66] Update OpenMC_PhotonTransport.py Assign material library path to new function and delete unused lines --- OpenMC_PhotonTransport.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index 12116c2..33196ff 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -65,14 +65,16 @@ 2.00e+7] #ALARA Element Library to read density for specified element: -# with open(""+fp+"") as ALARA_Lib: -with open("elelib.std") as ALARA_Lib: - Lib_Lines = ALARA_Lib.readlines() +def mat_lib(filepath): + with open(""+filepath+"") as ALARA_Lib: + #with open("elelib.std") as ALARA_Lib: + Lib_Lines = ALARA_Lib.readlines() + return Lib_Lines # Create materials & export to XML: #Simulating tungsten shell: -def make_W(element_1): +def make_W(element_1, Lib_Lines): M_1 = openmc.Material(material_id=1, name=element_1) for line in Lib_Lines: if line.split()[0].lower() == element_1.lower(): @@ -81,7 +83,7 @@ def make_W(element_1): M_1.add_element(element_1, 1.00) return M_1 -def make_C(element_2): +def make_C(element_2, Lib_Lines): M_2 = openmc.Material(material_id=2, name=element_2) for line in Lib_Lines: if line.split()[0].lower() == element_2.lower(): @@ -135,15 +137,12 @@ def make_source(W_Shell, C_Shell, Cells): # Define tallies def tallies(W_Shell, C_Shell, Particle_Filter, Total_Mesh): - # global Total_Mesh - # global Total_Filter Total_Filter = openmc.MeshFilter(Total_Mesh) neutron_tally = openmc.Tally(tally_id=1, name="Neutron tally") neutron_tally.scores = ['flux', 'elastic', 'absorption'] # Implementing filter for neutron tally through W shell - global cell_filter cell_filter = openmc.CellFilter([W_Shell, C_Shell]) neutron_tally.filters = [cell_filter, Total_Filter] @@ -179,9 +178,10 @@ def plot_universe(Void, W_Shell, C_Shell, Cells): return universe_ss # Exporting materials, geometry, and tallies to .xml -def export_to_xml(element_1, element_2, inner_radius_W, outer_radius_W, inner_radius_C): - OpenMC_W = make_W(element_1) - OpenMC_C = make_C(element_2) +def export_to_xml(filepath, element_1, element_2, inner_radius_W, outer_radius_W, inner_radius_C): + OpenMC_SF = mat_lib(filepath) + OpenMC_W = make_W(element_1, OpenMC_SF) + OpenMC_C = make_C(element_2, OpenMC_SF) OpenMC_Mat = all_mat(OpenMC_W, OpenMC_C) OpenMC_Geometry = make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, OpenMC_W, OpenMC_C) OpenMC_Source = make_source(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) @@ -189,6 +189,6 @@ def export_to_xml(element_1, element_2, inner_radius_W, outer_radius_W, inner_ra OpenMC_Tallies = tallies(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Source[1], OpenMC_Source[2]) OpenMC_Universe = plot_universe(OpenMC_Geometry[1], OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) #return OpenMC_Materials, OpenMC_Geometry, OpenMC_Source, OpenMC_Settings, OpenMC_Tallies, OpenMC_Universe - return OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies - -M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, Mesh_Dist, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(E_1, E_2, R_W_1, R_W_2, R_C_1) + return OpenMC_SF, OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies + +Lib_Lines, M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, Mesh_Dist, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(fp, E_1, E_2, R_W_1, R_W_2, R_C_1) From 19e86efbeccb862e6ac57deaf09349bf0d7d0928 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:31:14 -0500 Subject: [PATCH 10/66] Adding materials/geometry files These two files can be imported into a neutron or photon transport problem --- TwoLayers_Geometry.py | 33 +++++++++++++++++++++++++++++++++ TwoLayers_Materials.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 TwoLayers_Geometry.py create mode 100644 TwoLayers_Materials.py diff --git a/TwoLayers_Geometry.py b/TwoLayers_Geometry.py new file mode 100644 index 0000000..6cdf1a7 --- /dev/null +++ b/TwoLayers_Geometry.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Oct 11 15:56:57 2024 + +@author: Anupama Rajendra +""" + +import openmc + +# Create geometry +#Spherical shell: +def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_2): + S_W_1= openmc.Sphere(r=inner_radius_W) #sphere of radius 1000cm + inside_W_sphere_1 = -S_W_1 + outside_W_sphere_1 = +S_W_1 + S_W_2 = openmc.Sphere(r=outer_radius_W, boundary_type='vacuum') + inside_W_sphere_2 = -S_W_2 + outside_W_sphere_2 = +S_W_2 + S_W_3 = outside_W_sphere_1 & inside_W_sphere_2 #filled with specified material + + S_C_1= openmc.Sphere(r=inner_radius_C) #sphere of radius 995cm + inside_C_sphere_1 = -S_C_1 + outside_C_sphere_1 = +S_C_1 + S_C_3 = outside_C_sphere_1 & inside_W_sphere_1 #filled with specified material + + # Mapping materials to geometry: + Void = openmc.Cell(fill=None, region = inside_C_sphere_1) + W_Shell = openmc.Cell(fill=M_1, region=S_W_3) + C_Shell = openmc.Cell(fill=M_2, region=S_C_3) + Cells = [Void, W_Shell, C_Shell] + geometry = openmc.Geometry(Cells) + geometry.export_to_xml() + return geometry, Void, W_Shell, C_Shell, Cells \ No newline at end of file diff --git a/TwoLayers_Materials.py b/TwoLayers_Materials.py new file mode 100644 index 0000000..238cdc4 --- /dev/null +++ b/TwoLayers_Materials.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Oct 11 13:49:23 2024 + +@author: Anupama Rajendra +""" +import openmc + +#ALARA Element Library to read density for specified element: +def mat_lib(filepath): + with open(""+filepath+"") as ALARA_Lib: + #with open("elelib.std") as ALARA_Lib: + Lib_Lines = ALARA_Lib.readlines() + return Lib_Lines + +# Create materials & export to XML: +#Simulating tungsten shell: + +def make_W(element_1, Lib_Lines): + M_1 = openmc.Material(material_id=1, name=element_1) + for line in Lib_Lines: + if line.split()[0].lower() == element_1.lower(): + Density_M_1 = float(line.strip().split()[3]) + M_1.set_density('g/cm3', Density_M_1) + M_1.add_element(element_1, 1.00) + return M_1 + +def make_C(element_2, Lib_Lines): + M_2 = openmc.Material(material_id=2, name=element_2) + for line in Lib_Lines: + if line.split()[0].lower() == element_2.lower(): + #if line.startswith(element_2.lower()): + Density_M_2 = float(line.strip().split()[3]) + M_2.set_density('g/cm3', Density_M_2) + M_2.add_element(element_2, 1.00) + return M_2 + +def all_mat(M_1, M_2): + all_materials = openmc.Materials([M_1, M_2]) + all_materials.cross_sections = '../fendl-3.2-hdf5/cross_sections.xml' + all_materials.export_to_xml() \ No newline at end of file From 6fa1367007d86cb0ec8e4ec6a9617b1011f9b7ca Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:32:56 -0500 Subject: [PATCH 11/66] Import materials/geometry from TwoLayers_Materials & TwoLayers_Geometry --- OpenMC_PhotonTransport.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index 33196ff..d1f43f4 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -9,6 +9,8 @@ import argparse import numpy as np from Source_Mesh_Reader import summed_strengths, strengths_list +from TwoLayers_Materials import * +from TwoLayers_Geometry import * Mesh_File = 'OpenMC_Mesh.h5m' From c3cf5db818bfdfd36737dfa63c0e9b3e6213a8f8 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:35:17 -0500 Subject: [PATCH 12/66] Delete materials and geometry functions from current script --- OpenMC_PhotonTransport.py | 59 --------------------------------------- 1 file changed, 59 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index d1f43f4..f66a3e0 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -66,65 +66,6 @@ 1.40e+7, 2.00e+7] -#ALARA Element Library to read density for specified element: -def mat_lib(filepath): - with open(""+filepath+"") as ALARA_Lib: - #with open("elelib.std") as ALARA_Lib: - Lib_Lines = ALARA_Lib.readlines() - return Lib_Lines - -# Create materials & export to XML: -#Simulating tungsten shell: - -def make_W(element_1, Lib_Lines): - M_1 = openmc.Material(material_id=1, name=element_1) - for line in Lib_Lines: - if line.split()[0].lower() == element_1.lower(): - Density_M_1 = float(line.strip().split()[3]) - M_1.set_density('g/cm3', Density_M_1) - M_1.add_element(element_1, 1.00) - return M_1 - -def make_C(element_2, Lib_Lines): - M_2 = openmc.Material(material_id=2, name=element_2) - for line in Lib_Lines: - if line.split()[0].lower() == element_2.lower(): - #if line.startswith(element_2.lower()): - Density_M_2 = float(line.strip().split()[3]) - M_2.set_density('g/cm3', Density_M_2) - M_2.add_element(element_2, 1.00) - return M_2 - -def all_mat(M_1, M_2): - all_materials = openmc.Materials([M_1, M_2]) - all_materials.cross_sections = '../fendl-3.2-hdf5/cross_sections.xml' - all_materials.export_to_xml() - -# Create geometry -#Spherical shell: -def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_2): - S_W_1= openmc.Sphere(r=inner_radius_W) #sphere of radius 1000cm - inside_W_sphere_1 = -S_W_1 - outside_W_sphere_1 = +S_W_1 - S_W_2 = openmc.Sphere(r=outer_radius_W, boundary_type='vacuum') - inside_W_sphere_2 = -S_W_2 - outside_W_sphere_2 = +S_W_2 - S_W_3 = outside_W_sphere_1 & inside_W_sphere_2 #filled with specified material - - S_C_1= openmc.Sphere(r=inner_radius_C) #sphere of radius 995cm - inside_C_sphere_1 = -S_C_1 - outside_C_sphere_1 = +S_C_1 - S_C_3 = outside_C_sphere_1 & inside_W_sphere_1 #filled with specified material - - # Mapping materials to geometry: - Void = openmc.Cell(fill=None, region = inside_C_sphere_1) - W_Shell = openmc.Cell(fill=M_1, region=S_W_3) - C_Shell = openmc.Cell(fill=M_2, region=S_C_3) - Cells = [Void, W_Shell, C_Shell] - geometry = openmc.Geometry(Cells) - geometry.export_to_xml() - return geometry, Void, W_Shell, C_Shell, Cells - #Define source: def make_source(W_Shell, C_Shell, Cells): Source_List = [] From e217e000d3207699de9e7c0c6465033d23275b4c Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:41:17 -0500 Subject: [PATCH 13/66] Update OpenMC_PhotonTransport.py Co-authored-by: Paul Wilson --- OpenMC_PhotonTransport.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenMC_PhotonTransport.py b/OpenMC_PhotonTransport.py index f66a3e0..6af4ca4 100644 --- a/OpenMC_PhotonTransport.py +++ b/OpenMC_PhotonTransport.py @@ -123,8 +123,9 @@ def plot_universe(Void, W_Shell, C_Shell, Cells): # Exporting materials, geometry, and tallies to .xml def export_to_xml(filepath, element_1, element_2, inner_radius_W, outer_radius_W, inner_radius_C): OpenMC_SF = mat_lib(filepath) - OpenMC_W = make_W(element_1, OpenMC_SF) - OpenMC_C = make_C(element_2, OpenMC_SF) + materials = [] + for material_id, element in enumerate(elements): + materials.append(make_element(element, material_id+1, OpenMC_SF)) OpenMC_Mat = all_mat(OpenMC_W, OpenMC_C) OpenMC_Geometry = make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, OpenMC_W, OpenMC_C) OpenMC_Source = make_source(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) From 94519f9e1d1001c10cf2a8211ccd08a2b7ed2bb8 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:15:40 -0600 Subject: [PATCH 14/66] Update TwoLayers_Materials.py - Created dictionary with material densities - Created OpenMC Material and Materials objects with separate function --- TwoLayers_Materials.py | 43 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/TwoLayers_Materials.py b/TwoLayers_Materials.py index 238cdc4..caf63eb 100644 --- a/TwoLayers_Materials.py +++ b/TwoLayers_Materials.py @@ -9,33 +9,24 @@ #ALARA Element Library to read density for specified element: def mat_lib(filepath): with open(""+filepath+"") as ALARA_Lib: - #with open("elelib.std") as ALARA_Lib: Lib_Lines = ALARA_Lib.readlines() return Lib_Lines - + +def create_densities(elements, Lib_Lines): + density_dict = {} + for element in elements: + for line in Lib_Lines: + if line.split()[0].lower() == element.lower(): + density_dict[element] = float(line.strip().split()[3]) + return density_dict + # Create materials & export to XML: #Simulating tungsten shell: - -def make_W(element_1, Lib_Lines): - M_1 = openmc.Material(material_id=1, name=element_1) - for line in Lib_Lines: - if line.split()[0].lower() == element_1.lower(): - Density_M_1 = float(line.strip().split()[3]) - M_1.set_density('g/cm3', Density_M_1) - M_1.add_element(element_1, 1.00) - return M_1 - -def make_C(element_2, Lib_Lines): - M_2 = openmc.Material(material_id=2, name=element_2) - for line in Lib_Lines: - if line.split()[0].lower() == element_2.lower(): - #if line.startswith(element_2.lower()): - Density_M_2 = float(line.strip().split()[3]) - M_2.set_density('g/cm3', Density_M_2) - M_2.add_element(element_2, 1.00) - return M_2 - -def all_mat(M_1, M_2): - all_materials = openmc.Materials([M_1, M_2]) - all_materials.cross_sections = '../fendl-3.2-hdf5/cross_sections.xml' - all_materials.export_to_xml() \ No newline at end of file +def make_element(elements, density_dict): + mats = openmc.Materials([]) + for element_id, element in enumerate(elements): + mat = openmc.Material(material_id=element_id+1, name=element) + mat.add_element(element, 1.00) + mat.set_density('g/cm3', density_dict.get(f'{element}')) + mats.append(mat) + return mats From 38546604e370d852b409d48db5bac595cffd3222 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:04:02 -0600 Subject: [PATCH 15/66] Update TwoLayers_Materials.py Make dictionary of densities with ALARA element library Co-authored-by: Paul Wilson --- TwoLayers_Materials.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/TwoLayers_Materials.py b/TwoLayers_Materials.py index caf63eb..55bb951 100644 --- a/TwoLayers_Materials.py +++ b/TwoLayers_Materials.py @@ -7,18 +7,18 @@ import openmc #ALARA Element Library to read density for specified element: -def mat_lib(filepath): +def alara_element_densities(filepath): with open(""+filepath+"") as ALARA_Lib: - Lib_Lines = ALARA_Lib.readlines() - return Lib_Lines - -def create_densities(elements, Lib_Lines): + libLines = ALARA_lib.readlines() + num_lines = len(libLines) density_dict = {} - for element in elements: - for line in Lib_Lines: - if line.split()[0].lower() == element.lower(): - density_dict[element] = float(line.strip().split()[3]) - return density_dict + line_num = 0 + while line_num < num_lines: + element_data = line[line_num].strip().split() + element_name = element_data[0].lower + density_dict[element_name] = float(element_data[3]) + line_num += int(element_data[4]) + 1 + return density_dict # Create materials & export to XML: #Simulating tungsten shell: @@ -27,6 +27,7 @@ def make_element(elements, density_dict): for element_id, element in enumerate(elements): mat = openmc.Material(material_id=element_id+1, name=element) mat.add_element(element, 1.00) - mat.set_density('g/cm3', density_dict.get(f'{element}')) + mat.set_density('g/cm3', density_dict.get(element)) mats.append(mat) return mats + From a3db10238dc2f6cf615c3f0325f9e69343be8c4e Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:08:45 -0600 Subject: [PATCH 16/66] Update references to some variables --- TwoLayers_Materials.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TwoLayers_Materials.py b/TwoLayers_Materials.py index 55bb951..8017c27 100644 --- a/TwoLayers_Materials.py +++ b/TwoLayers_Materials.py @@ -9,13 +9,13 @@ #ALARA Element Library to read density for specified element: def alara_element_densities(filepath): with open(""+filepath+"") as ALARA_Lib: - libLines = ALARA_lib.readlines() + libLines = ALARA_Lib.readlines() num_lines = len(libLines) density_dict = {} line_num = 0 while line_num < num_lines: - element_data = line[line_num].strip().split() - element_name = element_data[0].lower + element_data = libLines[line_num].strip().split() + element_name = element_data[0].lower() density_dict[element_name] = float(element_data[3]) line_num += int(element_data[4]) + 1 return density_dict @@ -27,7 +27,7 @@ def make_element(elements, density_dict): for element_id, element in enumerate(elements): mat = openmc.Material(material_id=element_id+1, name=element) mat.add_element(element, 1.00) - mat.set_density('g/cm3', density_dict.get(element)) + mat.set_density('g/cm3', density_dict.get(element.lower())) mats.append(mat) return mats From 4199c1bdba393e800dc728c01802bd8880e1f11d Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:31:17 -0600 Subject: [PATCH 17/66] Update TwoLayers_Geometry.py Redefine inner and outer W spheres Co-authored-by: Paul Wilson --- TwoLayers_Geometry.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/TwoLayers_Geometry.py b/TwoLayers_Geometry.py index 6cdf1a7..95661c6 100644 --- a/TwoLayers_Geometry.py +++ b/TwoLayers_Geometry.py @@ -10,13 +10,9 @@ # Create geometry #Spherical shell: def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_2): - S_W_1= openmc.Sphere(r=inner_radius_W) #sphere of radius 1000cm - inside_W_sphere_1 = -S_W_1 - outside_W_sphere_1 = +S_W_1 - S_W_2 = openmc.Sphere(r=outer_radius_W, boundary_type='vacuum') - inside_W_sphere_2 = -S_W_2 - outside_W_sphere_2 = +S_W_2 - S_W_3 = outside_W_sphere_1 & inside_W_sphere_2 #filled with specified material + inner_W_sphere= openmc.Sphere(r=inner_radius_W) #sphere of radius 1000cm + outer_W_sphere = openmc.Sphere(r=outer_radius_W, boundary_type='vacuum') + W_region = +inner_W_sphere & -outer_W_sphere S_C_1= openmc.Sphere(r=inner_radius_C) #sphere of radius 995cm inside_C_sphere_1 = -S_C_1 From fdcb11f56cc832519e3dfab55bc947e0ecca775b Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:37:12 -0600 Subject: [PATCH 18/66] Import variables from TwoLayers_Materials --- TwoLayers_Geometry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TwoLayers_Geometry.py b/TwoLayers_Geometry.py index 95661c6..953d2b9 100644 --- a/TwoLayers_Geometry.py +++ b/TwoLayers_Geometry.py @@ -6,6 +6,7 @@ """ import openmc +from TwoLayers_Materials import * # Create geometry #Spherical shell: @@ -26,4 +27,4 @@ def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_ Cells = [Void, W_Shell, C_Shell] geometry = openmc.Geometry(Cells) geometry.export_to_xml() - return geometry, Void, W_Shell, C_Shell, Cells \ No newline at end of file + return geometry, Void, W_Shell, C_Shell, Cells From 2e209a6304ac3f000867d6de93b4b0c63b024704 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:50:07 -0600 Subject: [PATCH 19/66] Update directory of OpenMC_PhotonTransport --- OpenMC_PhotonTransport.py => WC_Layers/OpenMC_PhotonTransport.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename OpenMC_PhotonTransport.py => WC_Layers/OpenMC_PhotonTransport.py (100%) diff --git a/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py similarity index 100% rename from OpenMC_PhotonTransport.py rename to WC_Layers/OpenMC_PhotonTransport.py From e8a305a98d5fd7c5568aebc51a5c243d1e8cead1 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:50:40 -0600 Subject: [PATCH 20/66] Update directory of Photon_Tallytovtk --- Photon_TallytoVtk.py => WC_Layers/Photon_TallytoVtk.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Photon_TallytoVtk.py => WC_Layers/Photon_TallytoVtk.py (100%) diff --git a/Photon_TallytoVtk.py b/WC_Layers/Photon_TallytoVtk.py similarity index 100% rename from Photon_TallytoVtk.py rename to WC_Layers/Photon_TallytoVtk.py From 3aa85b304ee556633d221309041604ab599d24bd Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:51:12 -0600 Subject: [PATCH 21/66] Update directory of TwoLayers_Geometry --- TwoLayers_Geometry.py => WC_Layers/TwoLayers_Geometry.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TwoLayers_Geometry.py => WC_Layers/TwoLayers_Geometry.py (100%) diff --git a/TwoLayers_Geometry.py b/WC_Layers/TwoLayers_Geometry.py similarity index 100% rename from TwoLayers_Geometry.py rename to WC_Layers/TwoLayers_Geometry.py From 1cff395f6e9f562fa75ab91b87405f240a462e50 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:51:51 -0600 Subject: [PATCH 22/66] Update directory of TwoLayers_Materials --- TwoLayers_Materials.py => WC_Layers/TwoLayers_Materials.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TwoLayers_Materials.py => WC_Layers/TwoLayers_Materials.py (100%) diff --git a/TwoLayers_Materials.py b/WC_Layers/TwoLayers_Materials.py similarity index 100% rename from TwoLayers_Materials.py rename to WC_Layers/TwoLayers_Materials.py From 64d14d5b1fbc72a6242534ea463f891406210151 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:52:14 -0600 Subject: [PATCH 23/66] Update directory of Source_Mesh_Reader --- Source_Mesh_Reader.py => WC_Layers/Source_Mesh_Reader.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Source_Mesh_Reader.py => WC_Layers/Source_Mesh_Reader.py (100%) diff --git a/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py similarity index 100% rename from Source_Mesh_Reader.py rename to WC_Layers/Source_Mesh_Reader.py From 88a9e83fadadb0798088fc63a91d6a62f6c5f251 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:19:36 -0600 Subject: [PATCH 24/66] Update TwoLayers_Geometry.py - Redefined make_spherical_shells to take layers and inner_radius as input - Deleted reference to TwoLayers_Materials to maintain generality --- WC_Layers/TwoLayers_Geometry.py | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/WC_Layers/TwoLayers_Geometry.py b/WC_Layers/TwoLayers_Geometry.py index 953d2b9..0a87ef1 100644 --- a/WC_Layers/TwoLayers_Geometry.py +++ b/WC_Layers/TwoLayers_Geometry.py @@ -6,25 +6,25 @@ """ import openmc -from TwoLayers_Materials import * # Create geometry #Spherical shell: -def make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, M_1, M_2): - inner_W_sphere= openmc.Sphere(r=inner_radius_W) #sphere of radius 1000cm - outer_W_sphere = openmc.Sphere(r=outer_radius_W, boundary_type='vacuum') - W_region = +inner_W_sphere & -outer_W_sphere - - S_C_1= openmc.Sphere(r=inner_radius_C) #sphere of radius 995cm - inside_C_sphere_1 = -S_C_1 - outside_C_sphere_1 = +S_C_1 - S_C_3 = outside_C_sphere_1 & inside_W_sphere_1 #filled with specified material - - # Mapping materials to geometry: - Void = openmc.Cell(fill=None, region = inside_C_sphere_1) - W_Shell = openmc.Cell(fill=M_1, region=S_W_3) - C_Shell = openmc.Cell(fill=M_2, region=S_C_3) - Cells = [Void, W_Shell, C_Shell] - geometry = openmc.Geometry(Cells) - geometry.export_to_xml() - return geometry, Void, W_Shell, C_Shell, Cells +def make_spherical_shells(layers, inner_radius): + ''' + Creates a set of concentric spherical shells, each with its own material & inner/outer radius. + + layers: list of tuples with OpenMC Material name and thickness: (material, thickness) + inner_radius: the radius of the innermost spherical shell + ''' + inner_sphere = openmc.Sphere(r = inner_radius) + cells = [openmc.Cell(fill = None, region = -inner_sphere)] + for (material, thickness) in layers: + outer_radius = inner_radius + thickness + outer_sphere = openmc.Sphere(r = outer_radius) + cells.append(openmc.Cell(fill = material, region = +inner_sphere & -outer_sphere)) + outer_radius = inner_radius + outer_sphere = inner_sphere + outer_sphere.boundary_type = 'vacuum' + cells.append(openmc.Cell(fill = None, region = +outer_sphere)) + geometry = openmc.Geometry(cells) + return geometry From 2259f7910a55a5d5779f79be85c7af748e4ddfc7 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:14:10 -0600 Subject: [PATCH 25/66] Add functions to read, plot, and save data --- WC_Layers/Photon_TallytoVtk.py | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/WC_Layers/Photon_TallytoVtk.py b/WC_Layers/Photon_TallytoVtk.py index ef03742..fa9b72a 100644 --- a/WC_Layers/Photon_TallytoVtk.py +++ b/WC_Layers/Photon_TallytoVtk.py @@ -7,26 +7,29 @@ import openmc import matplotlib.pyplot as plt -with openmc.StatePoint("statepoint.10.h5") as sp: - flux_spectrum = sp.get_tally(id=2) - mesh=sp.meshes[1] - # Get the reshaped tally data - tally_data_reshaped = flux_spectrum.get_reshaped_data(value='mean') - - flux_sum_en = tally_data_reshaped.sum(axis=(0,1,3,4,5)) - #Vitamin-J energy filter: - e_filter = flux_spectrum.filters[2] - #Lower bounds of the energy bins - e_filter_lower = e_filter.bins[:, 0] +def read_statepoint(sp_filename, flux_spectrum_tally_id, mesh_number, summed_axes_energy_filter, energy_filter_index): + with openmc.StatePoint(sp_filename) as sp: + flux_spectrum = sp.get_tally(id=flux_spectrum_tally_id) + mesh=sp.meshes[mesh_number] + # Return tally data condensed into 1 dimension per filter + tally_data_reshaped = flux_spectrum.get_reshaped_data(value='mean') + flux_sum_energy = tally_data_reshaped.sum(axis=summed_axes_energy_filter) + #Vitamin-J energy filter: + e_filter = flux_spectrum.filters[energy_filter_index] + #Lower bounds of the energy bins + e_filter_lower = e_filter.bins[:, 0] + return e_filter_lower, flux_sum_energy, tally_data_reshaped, mesh +def plot_flux_data(e_filter_lower, flux_sum_energy, figure_filename): # Plot flux spectrum fix, ax = plt.subplots() - ax.loglog(e_filter_lower, flux_sum_en, drawstyle='steps-post') + ax.loglog(e_filter_lower, flux_sum_energy, drawstyle='steps-post') ax.set_xlabel('Energy [eV]') ax.set_ylabel('Flux [photon-cm/source]') ax.grid(True, which='both') - plt.savefig('Photon_flux_vs_energy.png') + plt.savefig(figure_filename) plt.show() - - mesh_data = tally_data_reshaped.sum(axis=(0,2,3,4,5)) - vtk = mesh.write_data_to_vtk(filename="Photon_Flux.vtk", datasets={"mean":mesh_data.flatten()}) + +def write_to_vtk(tally_data_reshaped, summed_axes_mesh_filter, vtk_filename, mesh): + mesh_data = tally_data_reshaped.sum(axis=summed_axes_mesh_filter) + mesh.write_data_to_vtk(filename=vtk_filename, datasets={"mean":mesh_data.flatten()}) From 84bac072af0e0cf5d3fa51798d38741285d99bc9 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:31:08 -0600 Subject: [PATCH 26/66] Fix indentation of return statement --- WC_Layers/Photon_TallytoVtk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WC_Layers/Photon_TallytoVtk.py b/WC_Layers/Photon_TallytoVtk.py index fa9b72a..8a77639 100644 --- a/WC_Layers/Photon_TallytoVtk.py +++ b/WC_Layers/Photon_TallytoVtk.py @@ -18,7 +18,7 @@ def read_statepoint(sp_filename, flux_spectrum_tally_id, mesh_number, summed_axe e_filter = flux_spectrum.filters[energy_filter_index] #Lower bounds of the energy bins e_filter_lower = e_filter.bins[:, 0] - return e_filter_lower, flux_sum_energy, tally_data_reshaped, mesh + return e_filter_lower, flux_sum_energy, tally_data_reshaped, mesh def plot_flux_data(e_filter_lower, flux_sum_energy, figure_filename): # Plot flux spectrum From 0713d7343dbcb9cf73da739c70c053b7891561b0 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 02:44:42 -0600 Subject: [PATCH 27/66] Created functions to extract and write relevant data --- WC_Layers/Source_Mesh_Reader.py | 54 +++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index 91c2d3f..bc45dfa 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -16,26 +16,40 @@ # Number of photon groups photon_groups = 24 -# Process each file -for file_index, file in enumerate(Files): - # Extract data from the current file - tstt = file['tstt'] - elements = tstt['elements'] - tet_four = elements['Tet4'] - tags = tet_four['tags'] - sd = tags['source_density'][:] +def extract_source_data(Files): + ''' + Identifies the location of the source density dataset within each mesh file. + ''' + sd_list = [] + for file in Files: + # Extract data from the current file + tstt = file['tstt'] + elements = tstt['elements'] + tet_four = elements['Tet4'] + tags = tet_four['tags'] + sd = tags['source_density'][:] + sd_list.append(sd) + return sd_list - # Write source density to a separate file for each mesh - with open(f'source_density_{file_index + 1}.txt', 'w') as source: - for tet_element in sd: - source.write(' '.join(map(str, tet_element)) + '\n') +def write_source_density(sd_list, sd_filename): + ''' + Writes each of the specified source density datasets to a text file. + + sd_list: list of source density datasets from h5m files + sd_filename: user-provided filename that appears as a prefix for the text files + ''' + for sd_index, source_density in enumerate(sd_list): + # Write source density to a separate file for each mesh + with open(f'{sd_filename}_{sd_index + 1}.txt', 'w') as source: + for tet_element in source_density: + source.write(' '.join(map(str, tet_element)) + '\n') - # Calculate summed (and individual mesh) strengths for each photon group - summed_strengths = [] - strengths_list = [] - for group in range(photon_groups): - total_strengths = np.sum(sd[:, group]) # Sum over all mesh elements - summed_strengths.append(total_strengths) - strengths = sd[:,group] - strengths_list.append(strengths) +# Calculate summed (and individual mesh) strengths for each photon group +summed_strengths = [] +strengths_list = [] +for group in range(photon_groups): + total_strengths = np.sum(sd[:, group]) # Sum over all mesh elements + summed_strengths.append(total_strengths) + strengths = sd[:,group] + strengths_list.append(strengths) From 5c03a219c56b6f04521fa939505be32a5307b54b Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:27:53 -0600 Subject: [PATCH 28/66] Define arrange_source_strengths function - The previous version was not storing source strengths correctly. The data from the last entry in sd_list was overwriting the data from the previous entries. This has been fixed in this commit. --- WC_Layers/Source_Mesh_Reader.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index bc45dfa..ecbde8c 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -31,6 +31,21 @@ def extract_source_data(Files): sd_list.append(sd) return sd_list +def arrange_source_strengths(sd_list, photon_groups): + ''' + Writes individual mesh element strengths (separated by energy group) to density_list, + then writes density_list to all_strengths_list for each set of source densities. + ''' + all_strengths_list = [] + for density in sd_list: + density_list = [] + # Calculate (individual mesh) strengths for each photon group + for group in range(photon_groups): + strengths = density[:,group] + density_list.append(strengths) + all_strengths_list.append(density_list) + return all_strengths_list + def write_source_density(sd_list, sd_filename): ''' Writes each of the specified source density datasets to a text file. @@ -43,13 +58,3 @@ def write_source_density(sd_list, sd_filename): with open(f'{sd_filename}_{sd_index + 1}.txt', 'w') as source: for tet_element in source_density: source.write(' '.join(map(str, tet_element)) + '\n') - -# Calculate summed (and individual mesh) strengths for each photon group -summed_strengths = [] -strengths_list = [] -for group in range(photon_groups): - total_strengths = np.sum(sd[:, group]) # Sum over all mesh elements - summed_strengths.append(total_strengths) - strengths = sd[:,group] - strengths_list.append(strengths) - From d761b1c3475e52545d10c925687ed09956e5f50f Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:09:37 -0600 Subject: [PATCH 29/66] Add main function that calls all helper functions --- WC_Layers/Source_Mesh_Reader.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index ecbde8c..43dac92 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -58,3 +58,9 @@ def write_source_density(sd_list, sd_filename): with open(f'{sd_filename}_{sd_index + 1}.txt', 'w') as source: for tet_element in source_density: source.write(' '.join(map(str, tet_element)) + '\n') + +def extract_arrange_write_sd(Files, photon_groups, sd_filename): + data_extractor = extract_source_data(Files) + strength_arranger = arrange_source_strengths(data_extractor, photon_groups) + write_source_density(data_extractor, sd_filename) + return data_extractor, strength_arranger From fd3cb83cfef476b5bba4c6686140daf26170a8ee Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:11:24 -0600 Subject: [PATCH 30/66] Rewrite make_source in terms of data_extractor from Source_Mesh_Reader --- WC_Layers/OpenMC_PhotonTransport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 6af4ca4..2944a6e 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -8,7 +8,7 @@ import openmc import argparse import numpy as np -from Source_Mesh_Reader import summed_strengths, strengths_list +from Source_Mesh_Reader import data_extractor from TwoLayers_Materials import * from TwoLayers_Geometry import * @@ -72,10 +72,10 @@ def make_source(W_Shell, C_Shell, Cells): Particle_Filter = openmc.ParticleFilter('photon') Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') for index, bound in enumerate(bounds[:-1]): - Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=strengths_list[index], volume_normalized=False) + Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=data_extractor[mesh_index][:,index], volume_normalized=False) Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) #Source strengths given by strengths_list created by Source_Mesh_Reader - Source = Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=summed_strengths[index], particle='photon', domains=Cells)) + Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(data_extractor[mesh_index][:, index]), particle='photon', domains=Cells)) return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist # Define tallies From ed0e05db932c8d2ad48946e83dcf2bb516a4af7e Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:41:26 -0600 Subject: [PATCH 31/66] Fix summation in make_source loop --- WC_Layers/OpenMC_PhotonTransport.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 2944a6e..1d4f813 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -8,11 +8,13 @@ import openmc import argparse import numpy as np -from Source_Mesh_Reader import data_extractor +from Source_Mesh_Reader import extract_source_data, Files from TwoLayers_Materials import * from TwoLayers_Geometry import * Mesh_File = 'OpenMC_Mesh.h5m' +mesh_index = 0 +esd = extract_source_data(Files) parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") @@ -72,10 +74,10 @@ def make_source(W_Shell, C_Shell, Cells): Particle_Filter = openmc.ParticleFilter('photon') Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') for index, bound in enumerate(bounds[:-1]): - Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=data_extractor[mesh_index][:,index], volume_normalized=False) + Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) #Source strengths given by strengths_list created by Source_Mesh_Reader - Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(data_extractor[mesh_index][:, index]), particle='photon', domains=Cells)) + Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=Cells)) return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist # Define tallies From c7a0c036812ae6640339b2e2cc5dcc9a53faec43 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:17:15 -0600 Subject: [PATCH 32/66] Changed variable name in function definition --- WC_Layers/Source_Mesh_Reader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index 43dac92..b7dd1cc 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -16,12 +16,12 @@ # Number of photon groups photon_groups = 24 -def extract_source_data(Files): +def extract_source_data(file_list): ''' Identifies the location of the source density dataset within each mesh file. ''' sd_list = [] - for file in Files: + for file in file_list: # Extract data from the current file tstt = file['tstt'] elements = tstt['elements'] @@ -59,7 +59,7 @@ def write_source_density(sd_list, sd_filename): for tet_element in source_density: source.write(' '.join(map(str, tet_element)) + '\n') -def extract_arrange_write_sd(Files, photon_groups, sd_filename): +def extract_arrange_write_sd(file_list, photon_groups, sd_filename): data_extractor = extract_source_data(Files) strength_arranger = arrange_source_strengths(data_extractor, photon_groups) write_source_density(data_extractor, sd_filename) From 4568353a737395842726d868a3c6ecb5bae86e09 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Fri, 15 Nov 2024 16:26:27 -0600 Subject: [PATCH 33/66] Updated main function that calls helper functions --- WC_Layers/Source_Mesh_Reader.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index b7dd1cc..692e0a8 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -8,14 +8,13 @@ import h5py import numpy as np +source_density_name = 'source_density' + # Open the HDF5 files File_1 = h5py.File("source_mesh_1.h5m", 'r') File_2 = h5py.File("source_mesh_2.h5m", 'r') Files = [File_1, File_2] -# Number of photon groups -photon_groups = 24 - def extract_source_data(file_list): ''' Identifies the location of the source density dataset within each mesh file. @@ -59,8 +58,7 @@ def write_source_density(sd_list, sd_filename): for tet_element in source_density: source.write(' '.join(map(str, tet_element)) + '\n') -def extract_arrange_write_sd(file_list, photon_groups, sd_filename): - data_extractor = extract_source_data(Files) - strength_arranger = arrange_source_strengths(data_extractor, photon_groups) +def extract_write_sd(file_list, sd_filename): + data_extractor = extract_source_data(file_list) write_source_density(data_extractor, sd_filename) - return data_extractor, strength_arranger + return data_extractor From f91820fa79eaa63f78993b2c44afe6b47e406799 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:30:10 -0600 Subject: [PATCH 34/66] Rename write_source_density --- WC_Layers/Source_Mesh_Reader.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index 692e0a8..36b923b 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -28,37 +28,21 @@ def extract_source_data(file_list): tags = tet_four['tags'] sd = tags['source_density'][:] sd_list.append(sd) - return sd_list - -def arrange_source_strengths(sd_list, photon_groups): - ''' - Writes individual mesh element strengths (separated by energy group) to density_list, - then writes density_list to all_strengths_list for each set of source densities. - ''' - all_strengths_list = [] - for density in sd_list: - density_list = [] - # Calculate (individual mesh) strengths for each photon group - for group in range(photon_groups): - strengths = density[:,group] - density_list.append(strengths) - all_strengths_list.append(density_list) - return all_strengths_list + return sd_list -def write_source_density(sd_list, sd_filename): +def save_source_density(sd_list, sd_filename): ''' - Writes each of the specified source density datasets to a text file. + Saves source density data as a text file. sd_list: list of source density datasets from h5m files sd_filename: user-provided filename that appears as a prefix for the text files ''' for sd_index, source_density in enumerate(sd_list): - # Write source density to a separate file for each mesh with open(f'{sd_filename}_{sd_index + 1}.txt', 'w') as source: for tet_element in source_density: source.write(' '.join(map(str, tet_element)) + '\n') -def extract_write_sd(file_list, sd_filename): +def extract_save_sd(file_list, sd_filename): data_extractor = extract_source_data(file_list) - write_source_density(data_extractor, sd_filename) + save_source_density(data_extractor, sd_filename) return data_extractor From 23473328877337b346c3d7b2bbce05864958033a Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:25:15 -0600 Subject: [PATCH 35/66] Rewrite extract_source_data --- WC_Layers/Source_Mesh_Reader.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index 36b923b..fe25f3c 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -19,15 +19,10 @@ def extract_source_data(file_list): ''' Identifies the location of the source density dataset within each mesh file. ''' - sd_list = [] - for file in file_list: - # Extract data from the current file - tstt = file['tstt'] - elements = tstt['elements'] - tet_four = elements['Tet4'] - tags = tet_four['tags'] - sd = tags['source_density'][:] - sd_list.append(sd) + sd_list = np.ndarray((len(file_list), num_elements, photon_groups)) + + for file_num, file in enumerate(file_list): + sd_list[file_num,:] = file['tstt']['elements']['Tet4']['tags']['source_density'][:] return sd_list def save_source_density(sd_list, sd_filename): From d3b612ece6ed0a50a26ace65f57c91662bcfb1d2 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:40:43 -0600 Subject: [PATCH 36/66] Change extract_source_data docstring --- WC_Layers/Source_Mesh_Reader.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index fe25f3c..48ae056 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -18,6 +18,10 @@ def extract_source_data(file_list): ''' Identifies the location of the source density dataset within each mesh file. + + input: list of .h5m mesh files (opened by h5py) containing photon source information + output: numpy array of source density data with rows = # of mesh elements and + columns = # number of photon groups, with one array per source mesh ''' sd_list = np.ndarray((len(file_list), num_elements, photon_groups)) From 99af15ad5a36fa7f071b7db85c2f43735b280026 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:56:38 -0600 Subject: [PATCH 37/66] Moved Particle_Filter to tallies --- WC_Layers/OpenMC_PhotonTransport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 1d4f813..69f2a0d 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -71,17 +71,17 @@ #Define source: def make_source(W_Shell, C_Shell, Cells): Source_List = [] - Particle_Filter = openmc.ParticleFilter('photon') Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') for index, bound in enumerate(bounds[:-1]): Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) #Source strengths given by strengths_list created by Source_Mesh_Reader Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=Cells)) - return Source_List, Particle_Filter, Total_Mesh, Mesh_Dist + return Source_List, Total_Mesh, Mesh_Dist # Define tallies def tallies(W_Shell, C_Shell, Particle_Filter, Total_Mesh): + Particle_Filter = openmc.ParticleFilter('photon') Total_Filter = openmc.MeshFilter(Total_Mesh) neutron_tally = openmc.Tally(tally_id=1, name="Neutron tally") @@ -102,7 +102,7 @@ def tallies(W_Shell, C_Shell, Particle_Filter, Total_Mesh): tall = openmc.Tallies([neutron_tally, spectrum_tally]) tall.export_to_xml() - return tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter + return tall, neutron_tally, spectrum_tally, Particle_Filter, Total_Filter, cell_filter # Assign simulation settings def settings(Source_List): From bc4e8d34b07aea19dce68bbc67817ba5baa17690 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:16:08 -0600 Subject: [PATCH 38/66] Add inner_radius as input --- WC_Layers/OpenMC_PhotonTransport.py | 1 + 1 file changed, 1 insertion(+) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 69f2a0d..20852b4 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -15,6 +15,7 @@ Mesh_File = 'OpenMC_Mesh.h5m' mesh_index = 0 esd = extract_source_data(Files) +inner_radius = 995 parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") From e06fba50372d864cde4edde06cb4ba91a8c5329f Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:27:52 -0600 Subject: [PATCH 39/66] Change inputs required for make_source --- WC_Layers/OpenMC_PhotonTransport.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 20852b4..44c255d 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -12,6 +12,7 @@ from TwoLayers_Materials import * from TwoLayers_Geometry import * +# These will be moved to a yaml file Mesh_File = 'OpenMC_Mesh.h5m' mesh_index = 0 esd = extract_source_data(Files) @@ -70,14 +71,14 @@ 2.00e+7] #Define source: -def make_source(W_Shell, C_Shell, Cells): +def make_source(cells): Source_List = [] Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') for index, bound in enumerate(bounds[:-1]): Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) #Source strengths given by strengths_list created by Source_Mesh_Reader - Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=Cells)) + Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) return Source_List, Total_Mesh, Mesh_Dist # Define tallies From 7afd5684c9944764125463e8cf48acb586c690ea Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:39:34 -0600 Subject: [PATCH 40/66] Remove Mesh_Dist as output of make_source --- WC_Layers/OpenMC_PhotonTransport.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 44c255d..b783142 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -77,9 +77,8 @@ def make_source(cells): for index, bound in enumerate(bounds[:-1]): Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) - #Source strengths given by strengths_list created by Source_Mesh_Reader Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) - return Source_List, Total_Mesh, Mesh_Dist + return Source_List, Total_Mesh # Define tallies def tallies(W_Shell, C_Shell, Particle_Filter, Total_Mesh): @@ -139,4 +138,4 @@ def export_to_xml(filepath, element_1, element_2, inner_radius_W, outer_radius_W #return OpenMC_Materials, OpenMC_Geometry, OpenMC_Source, OpenMC_Settings, OpenMC_Tallies, OpenMC_Universe return OpenMC_SF, OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies -Lib_Lines, M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, Mesh_Dist, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(fp, E_1, E_2, R_W_1, R_W_2, R_C_1) +Lib_Lines, M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(fp, E_1, E_2, R_W_1, R_W_2, R_C_1) From 2b5e67b5b40873eea0e1220ff5ead4b6bca300c4 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 23:36:28 -0600 Subject: [PATCH 41/66] Change inputs required for tallies & fix capitalization --- WC_Layers/OpenMC_PhotonTransport.py | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index b783142..91357f1 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -72,41 +72,39 @@ #Define source: def make_source(cells): - Source_List = [] - Total_Mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') + source_list = [] + total_mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') for index, bound in enumerate(bounds[:-1]): - Mesh_Dist = openmc.stats.MeshSpatial(Total_Mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) - Energy_Dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) - Source_List.append(openmc.IndependentSource(space=Mesh_Dist, energy=Energy_Dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) - return Source_List, Total_Mesh + mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) + energy_dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) + source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) + return source_list, total_mesh # Define tallies -def tallies(W_Shell, C_Shell, Particle_Filter, Total_Mesh): - Particle_Filter = openmc.ParticleFilter('photon') - Total_Filter = openmc.MeshFilter(Total_Mesh) +def tallies(total_mesh): + particle_filter = openmc.ParticleFilter('photon') + total_filter = openmc.MeshFilter(total_mesh) neutron_tally = openmc.Tally(tally_id=1, name="Neutron tally") neutron_tally.scores = ['flux', 'elastic', 'absorption'] - # Implementing filter for neutron tally through W shell - cell_filter = openmc.CellFilter([W_Shell, C_Shell]) + # Implementing filter for neutron tally through shells with material + cell_filter = openmc.CellFilter(cells_w_mats) neutron_tally.filters = [cell_filter, Total_Filter] - # Creating a tally to get the flux energy spectrum. - # An energy filter is created to assign to the flux tally. + # Vitamin-J energy filter created to assign to the flux tally. energy_filter_flux = openmc.EnergyFilter.from_group_structure("VITAMIN-J-42") spectrum_tally = openmc.Tally(tally_id=2, name="Flux spectrum") # Implementing energy and cell filters for flux spectrum tally - spectrum_tally.filters = [cell_filter, Total_Filter, energy_filter_flux, Particle_Filter] + spectrum_tally.filters = [cell_filter, total_filter, energy_filter_flux, particle_filter] spectrum_tally.scores = ['flux'] tall = openmc.Tallies([neutron_tally, spectrum_tally]) tall.export_to_xml() - return tall, neutron_tally, spectrum_tally, Particle_Filter, Total_Filter, cell_filter + return tall, neutron_tally, spectrum_tally, particle_filter, total_filter, cell_filter -# Assign simulation settings -def settings(Source_List): +def settings(source_list): sets = openmc.Settings() sets.batches = 10 sets.inactive = 1 From 4fb3156791a8046e5b8af6b3e1e96cc167839087 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 19 Nov 2024 23:37:40 -0600 Subject: [PATCH 42/66] Change variable names from uppercase to lowercase --- WC_Layers/OpenMC_PhotonTransport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 91357f1..67fde1e 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -90,7 +90,7 @@ def tallies(total_mesh): # Implementing filter for neutron tally through shells with material cell_filter = openmc.CellFilter(cells_w_mats) - neutron_tally.filters = [cell_filter, Total_Filter] + neutron_tally.filters = [cell_filter, total_filter] # Vitamin-J energy filter created to assign to the flux tally. energy_filter_flux = openmc.EnergyFilter.from_group_structure("VITAMIN-J-42") @@ -136,4 +136,4 @@ def export_to_xml(filepath, element_1, element_2, inner_radius_W, outer_radius_W #return OpenMC_Materials, OpenMC_Geometry, OpenMC_Source, OpenMC_Settings, OpenMC_Tallies, OpenMC_Universe return OpenMC_SF, OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies -Lib_Lines, M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, Source_List, Particle_Filter, Total_Mesh, tall, neutron_tally, spectrum_tally, Total_Filter, cell_filter, sets = export_to_xml(fp, E_1, E_2, R_W_1, R_W_2, R_C_1) +Lib_Lines, M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, source_list, particle_filter, total_mesh, tall, neutron_tally, spectrum_tally, total_filter, cell_filter, sets = export_to_xml(fp, E_1, E_2, R_W_1, R_W_2, R_C_1) From c81e21f4a9e18782cfb2ccc5246c28e6df098db3 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Wed, 20 Nov 2024 01:09:30 -0600 Subject: [PATCH 43/66] Rewrite export_to_xml as create_openmc_model - create_openmc_model creates a model object using all other OpenMC objects - deleted plot_universe for now as this function cannot create an OpenMC plots object - deleted .export_to_xml calls --- WC_Layers/OpenMC_PhotonTransport.py | 39 ++++++----------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 67fde1e..2b7ac02 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -16,7 +16,6 @@ Mesh_File = 'OpenMC_Mesh.h5m' mesh_index = 0 esd = extract_source_data(Files) -inner_radius = 995 parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") @@ -81,7 +80,7 @@ def make_source(cells): return source_list, total_mesh # Define tallies -def tallies(total_mesh): +def tallies(total_mesh, cells_w_mats): particle_filter = openmc.ParticleFilter('photon') total_filter = openmc.MeshFilter(total_mesh) @@ -100,40 +99,18 @@ def tallies(total_mesh): spectrum_tally.filters = [cell_filter, total_filter, energy_filter_flux, particle_filter] spectrum_tally.scores = ['flux'] - tall = openmc.Tallies([neutron_tally, spectrum_tally]) - tall.export_to_xml() - return tall, neutron_tally, spectrum_tally, particle_filter, total_filter, cell_filter - + talls = openmc.Tallies([neutron_tally, spectrum_tally]) + return talls + def settings(source_list): sets = openmc.Settings() sets.batches = 10 sets.inactive = 1 sets.particles = 100000 - sets.source = Source_List + sets.source = source_list sets.run_mode = 'fixed source' - sets.export_to_xml() return sets -def plot_universe(Void, W_Shell, C_Shell, Cells): - universe_ss = openmc.Universe(cells=Cells) - Plot = universe_ss.plot(width=(2500.0, 2500.0), basis='xz', - colors={Void: 'blue', W_Shell: 'red', C_Shell: 'green'}, legend=True) - Plot.figure.savefig('Universe') - return universe_ss - -# Exporting materials, geometry, and tallies to .xml -def export_to_xml(filepath, element_1, element_2, inner_radius_W, outer_radius_W, inner_radius_C): - OpenMC_SF = mat_lib(filepath) - materials = [] - for material_id, element in enumerate(elements): - materials.append(make_element(element, material_id+1, OpenMC_SF)) - OpenMC_Mat = all_mat(OpenMC_W, OpenMC_C) - OpenMC_Geometry = make_spherical_shell(inner_radius_W, outer_radius_W, inner_radius_C, OpenMC_W, OpenMC_C) - OpenMC_Source = make_source(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) - OpenMC_Settings = settings(OpenMC_Source[0]) - OpenMC_Tallies = tallies(OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Source[1], OpenMC_Source[2]) - OpenMC_Universe = plot_universe(OpenMC_Geometry[1], OpenMC_Geometry[2], OpenMC_Geometry[3], OpenMC_Geometry[4]) - #return OpenMC_Materials, OpenMC_Geometry, OpenMC_Source, OpenMC_Settings, OpenMC_Tallies, OpenMC_Universe - return OpenMC_SF, OpenMC_W, OpenMC_C, *OpenMC_Geometry, *OpenMC_Source, OpenMC_Settings, *OpenMC_Tallies - -Lib_Lines, M_1, M_2, geometry, Void, W_Shell, C_Shell, Cells, source_list, particle_filter, total_mesh, tall, neutron_tally, spectrum_tally, total_filter, cell_filter, sets = export_to_xml(fp, E_1, E_2, R_W_1, R_W_2, R_C_1) +def create_openmc_model(geom_object, mats_object, sets_object, talls_object): + model = openmc.model.Model(geometry = geom_object, materials = mats_object, settings = sets_object, tallies = talls_object) + return model From 1ae47ce2d70ad3c26bd5fa637d64c5ab94edb052 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Wed, 20 Nov 2024 01:12:41 -0600 Subject: [PATCH 44/66] Deleted comments describing self-explanatory code --- WC_Layers/OpenMC_PhotonTransport.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 2b7ac02..c10fc48 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -69,7 +69,6 @@ 1.40e+7, 2.00e+7] -#Define source: def make_source(cells): source_list = [] total_mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') @@ -79,7 +78,6 @@ def make_source(cells): source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) return source_list, total_mesh -# Define tallies def tallies(total_mesh, cells_w_mats): particle_filter = openmc.ParticleFilter('photon') total_filter = openmc.MeshFilter(total_mesh) @@ -95,7 +93,6 @@ def tallies(total_mesh, cells_w_mats): energy_filter_flux = openmc.EnergyFilter.from_group_structure("VITAMIN-J-42") spectrum_tally = openmc.Tally(tally_id=2, name="Flux spectrum") - # Implementing energy and cell filters for flux spectrum tally spectrum_tally.filters = [cell_filter, total_filter, energy_filter_flux, particle_filter] spectrum_tally.scores = ['flux'] From c3509d63657b5243eac21fde64914a934daa50f4 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:26:17 -0600 Subject: [PATCH 45/66] Add docstrings to functions --- WC_Layers/OpenMC_PhotonTransport.py | 37 +++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index c10fc48..a4818d0 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -13,7 +13,7 @@ from TwoLayers_Geometry import * # These will be moved to a yaml file -Mesh_File = 'OpenMC_Mesh.h5m' +openmc_mesh_file = 'OpenMC_Mesh.h5m' mesh_index = 0 esd = extract_source_data(Files) @@ -69,16 +69,36 @@ 1.40e+7, 2.00e+7] -def make_source(cells): +def make_source(cells, mesh_file): + ''' + Creates a list of OpenMC sources, complete with the relevant space and energy distributions + + inputs: + cells: list of OpenMC Cell objects + mesh_file: .h5/.h5m mesh onto which photon source will be distributed + + output: + source_list: list of OpenMC independent sources + total_mesh: OpenMC Unstructured Mesh object + ''' source_list = [] - total_mesh = openmc.UnstructuredMesh(Mesh_File, library='moab') + total_mesh = openmc.UnstructuredMesh(mesh_file, library='moab') for index, bound in enumerate(bounds[:-1]): mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) energy_dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) return source_list, total_mesh -def tallies(total_mesh, cells_w_mats): +def tallies(total_mesh): + ''' + Creates tallies and assigns energy, spatial, and particle filters. + + inputs: + total_mesh: OpenMC unstructured mesh object + + outputs: + talls: OpenMC Tallies object + ''' particle_filter = openmc.ParticleFilter('photon') total_filter = openmc.MeshFilter(total_mesh) @@ -86,6 +106,7 @@ def tallies(total_mesh, cells_w_mats): neutron_tally.scores = ['flux', 'elastic', 'absorption'] # Implementing filter for neutron tally through shells with material + # cells_w_mats has yet to be defined cell_filter = openmc.CellFilter(cells_w_mats) neutron_tally.filters = [cell_filter, total_filter] @@ -100,6 +121,14 @@ def tallies(total_mesh, cells_w_mats): return talls def settings(source_list): + ''' + Creates an OpenMC Settings object + + inputs: + source_list: iterable of OpenMC SourceBase objects + outputs: + sets: OpenMC Settings object + ''' sets = openmc.Settings() sets.batches = 10 sets.inactive = 1 From 66761913e239876fac936e7c7d9c9c2794b10c37 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:11:21 -0600 Subject: [PATCH 46/66] Add input to tallies function --- WC_Layers/OpenMC_PhotonTransport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index a4818d0..260a110 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -89,12 +89,13 @@ def make_source(cells, mesh_file): source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) return source_list, total_mesh -def tallies(total_mesh): +def tallies(total_mesh, tallied_cells): ''' Creates tallies and assigns energy, spatial, and particle filters. inputs: total_mesh: OpenMC unstructured mesh object + tallied_cells: OpenMC Cell/iterable of OpenMC Cell objects/iterable of Cell ID # outputs: talls: OpenMC Tallies object @@ -106,8 +107,7 @@ def tallies(total_mesh): neutron_tally.scores = ['flux', 'elastic', 'absorption'] # Implementing filter for neutron tally through shells with material - # cells_w_mats has yet to be defined - cell_filter = openmc.CellFilter(cells_w_mats) + cell_filter = openmc.CellFilter(tallied_cells) neutron_tally.filters = [cell_filter, total_filter] # Vitamin-J energy filter created to assign to the flux tally. From e6c9518794bd33323965abda1777b3cdaaa4f609 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:13:49 -0600 Subject: [PATCH 47/66] Changed bounds to numpy array - Modified loop over bounds in make_source (no longer uses enumerate) --- WC_Layers/OpenMC_PhotonTransport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 260a110..c31837e 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -43,7 +43,7 @@ # R_W_1 = 1000 # R_W_2 = 1005 # R_C_1 = 995 -bounds = [0, +bounds = np.array([0, 1.00e+4, 2.00e+4, 5.00e+4, @@ -67,7 +67,7 @@ 1.00e+7, 1.20e+7, 1.40e+7, - 2.00e+7] + 2.00e+7]) def make_source(cells, mesh_file): ''' @@ -83,7 +83,7 @@ def make_source(cells, mesh_file): ''' source_list = [] total_mesh = openmc.UnstructuredMesh(mesh_file, library='moab') - for index, bound in enumerate(bounds[:-1]): + for index in range(len(bounds) - 1): mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) energy_dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) From 3a09bf81cd3a21dde70dfbbcc68926c737ef04f4 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:40:40 -0600 Subject: [PATCH 48/66] Change the way upper & lower energy bounds are accessed Co-authored-by: Paul Wilson --- WC_Layers/OpenMC_PhotonTransport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index c31837e..0fff55c 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -83,9 +83,9 @@ def make_source(cells, mesh_file): ''' source_list = [] total_mesh = openmc.UnstructuredMesh(mesh_file, library='moab') - for index in range(len(bounds) - 1): + for index, (lower_bound, upper_bound) in enumerate(zip(bounds[:-1],bounds[1:[)): mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) - energy_dist = openmc.stats.Uniform(a=bounds[index], b=bounds[index + 1]) + energy_dist = openmc.stats.Uniform(a=lower_bound, b=upper_bound) source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) return source_list, total_mesh From 0d0418b6bf827a85ff1c5124b2d7a9e2598c5d10 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:10:15 -0600 Subject: [PATCH 49/66] Fixed typo in make_source --- WC_Layers/OpenMC_PhotonTransport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 0fff55c..f4a9c0e 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -83,7 +83,7 @@ def make_source(cells, mesh_file): ''' source_list = [] total_mesh = openmc.UnstructuredMesh(mesh_file, library='moab') - for index, (lower_bound, upper_bound) in enumerate(zip(bounds[:-1],bounds[1:[)): + for index, (lower_bound, upper_bound) in enumerate(zip(bounds[:-1],bounds[1:])): mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) energy_dist = openmc.stats.Uniform(a=lower_bound, b=upper_bound) source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) From 93d5b56dccc6e272f317aae1e9caf1bc8500b9a7 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:47:27 -0600 Subject: [PATCH 50/66] Add inputs to yaml file --- PhotonTransport_Inputs.yaml | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 PhotonTransport_Inputs.yaml diff --git a/PhotonTransport_Inputs.yaml b/PhotonTransport_Inputs.yaml new file mode 100644 index 0000000..a2c6663 --- /dev/null +++ b/PhotonTransport_Inputs.yaml @@ -0,0 +1,57 @@ +filename_dict : + alara_el_lib : elelib.std + mesh_file_openmc : OpenMC_Mesh.h5m + +file_indices: + source_mesh_index : 0 + +source_info : + phtn_e_bounds : + - 0 + - 1.00e+4 + - 2.00e+4 + - 5.00e+4 + - 1.00e+5 + - 2.00e+5 + - 3.00e+5 + - 4.00e+5 + - 6.00e+5 + - 8.00e+5 + - 1.00e+6 + - 1.22e+6 + - 1.44e+6 + - 1.66e+6 + - 2.00e+6 + - 2.50e+6 + - 3.00e+6 + - 4.00e+6 + - 5.00e+6 + - 6.50e+6 + - 8.00e+6 + - 1.00e+7 + - 1.20e+7 + - 1.40e+7 + - 2.00e+7 + +mat_info : + element_list : #add in order of radially innermost to outermost + - W + - C + +geom_info : + inner_radius : 995, + thicknesses : #corresponds to each of the elements in element_list + - 5 + - 5 + outer_boundary : vacuum + +tally_info : + tallied_elements : #change according to desired tally region/material + - W + - C + +settings_info : + particles : 100000 + batches : 10 + inactive_batches : 1 + run_mode : fixed_source \ No newline at end of file From 80382a4a87c65f2bb7771dbdea266273f06ad12f Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:48:22 -0600 Subject: [PATCH 51/66] Update and rename PhotonTransport_Inputs.yaml to WC_Layers/PhotonTransport_Inputs.yaml --- .../PhotonTransport_Inputs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename PhotonTransport_Inputs.yaml => WC_Layers/PhotonTransport_Inputs.yaml (92%) diff --git a/PhotonTransport_Inputs.yaml b/WC_Layers/PhotonTransport_Inputs.yaml similarity index 92% rename from PhotonTransport_Inputs.yaml rename to WC_Layers/PhotonTransport_Inputs.yaml index a2c6663..67a904d 100644 --- a/PhotonTransport_Inputs.yaml +++ b/WC_Layers/PhotonTransport_Inputs.yaml @@ -54,4 +54,4 @@ settings_info : particles : 100000 batches : 10 inactive_batches : 1 - run_mode : fixed_source \ No newline at end of file + run_mode : fixed_source From ab1b09b61259a987748fe711069d1068de97fd87 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:58:35 -0600 Subject: [PATCH 52/66] Remove hard-coded inputs that have been moved to yaml --- WC_Layers/OpenMC_PhotonTransport.py | 76 +++-------------------------- 1 file changed, 6 insertions(+), 70 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index f4a9c0e..ce5bc5d 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -1,74 +1,10 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Aug 7 10:07:33 2024 - -@author: Anupama Rajendra -""" - import openmc -import argparse import numpy as np from Source_Mesh_Reader import extract_source_data, Files -from TwoLayers_Materials import * -from TwoLayers_Geometry import * -# These will be moved to a yaml file -openmc_mesh_file = 'OpenMC_Mesh.h5m' -mesh_index = 0 +# Photon source densities from ALARA output esd = extract_source_data(Files) -parser = argparse.ArgumentParser(description="Specify required inputs: file path to ALARA Element Library, element name, inner radius [cm], outer_radius [cm]") - -#Required user inputs: -parser.add_argument('--filepath', type=str, required=True) -parser.add_argument('--element_1', type=str, required=True) -parser.add_argument('--element_2', type=str, required=True) -#Shell radii are left as user inputs, but the mesh is specific to W_inner_radius = 1000, W_outer_radius = 1005, C_inner_radius = 995 -parser.add_argument('--W_inner_radius', type=float, required=True) -parser.add_argument('--W_outer_radius', type=float, required=True) -parser.add_argument('--C_inner_radius', type=float, required=True) - -args = parser.parse_args() - -fp = args.filepath -E_1 = args.element_1 -E_2 = args.element_2 -R_W_1 = args.W_inner_radius -R_W_2 = args.W_outer_radius -R_C_1 = args.C_inner_radius - -# fp = '../../ALARA/data/elelib.std' -# E_1 = 'W' -# E_2 = 'C' -# R_W_1 = 1000 -# R_W_2 = 1005 -# R_C_1 = 995 -bounds = np.array([0, - 1.00e+4, - 2.00e+4, - 5.00e+4, - 1.00e+5, - 2.00e+5, - 3.00e+5, - 4.00e+5, - 6.00e+5, - 8.00e+5, - 1.00e+6, - 1.22e+6, - 1.44e+6, - 1.66e+6, - 2.00e+6, - 2.50e+6, - 3.00e+6, - 4.00e+6, - 5.00e+6, - 6.50e+6, - 8.00e+6, - 1.00e+7, - 1.20e+7, - 1.40e+7, - 2.00e+7]) - def make_source(cells, mesh_file): ''' Creates a list of OpenMC sources, complete with the relevant space and energy distributions @@ -120,7 +56,7 @@ def tallies(total_mesh, tallied_cells): talls = openmc.Tallies([neutron_tally, spectrum_tally]) return talls -def settings(source_list): +def settings(source_list, total_batches, inactive_batches, num_particles, run_mode): ''' Creates an OpenMC Settings object @@ -130,11 +66,11 @@ def settings(source_list): sets: OpenMC Settings object ''' sets = openmc.Settings() - sets.batches = 10 - sets.inactive = 1 - sets.particles = 100000 + sets.batches = total_batches + sets.inactive = inactive_batches + sets.particles = num_particles sets.source = source_list - sets.run_mode = 'fixed source' + sets.run_mode = run_mode return sets def create_openmc_model(geom_object, mats_object, sets_object, talls_object): From 8aff672d0f739ca56a1f464f973bd9a36c38956f Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:32:16 -0600 Subject: [PATCH 53/66] Add information to calculate effective dose --- WC_Layers/OpenMC_PhotonTransport.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index ce5bc5d..7970260 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -39,18 +39,22 @@ def tallies(total_mesh, tallied_cells): particle_filter = openmc.ParticleFilter('photon') total_filter = openmc.MeshFilter(total_mesh) - neutron_tally = openmc.Tally(tally_id=1, name="Neutron tally") - neutron_tally.scores = ['flux', 'elastic', 'absorption'] + photon_tally = openmc.Tally(tally_id=1, name="Photon tally") + photon_tally.scores = ['flux', 'elastic', 'absorption'] # Implementing filter for neutron tally through shells with material cell_filter = openmc.CellFilter(tallied_cells) - neutron_tally.filters = [cell_filter, total_filter] + photon_tally.filters = [cell_filter, total_filter] + + # Obtain coefficients to calculate effective dose + dose_energy, dose = openmc.data.dose_coefficients('photon', 'AP') + dose_filter = openmc.EnergyFunctionFilter(dose_energy, dose) # Vitamin-J energy filter created to assign to the flux tally. energy_filter_flux = openmc.EnergyFilter.from_group_structure("VITAMIN-J-42") spectrum_tally = openmc.Tally(tally_id=2, name="Flux spectrum") - spectrum_tally.filters = [cell_filter, total_filter, energy_filter_flux, particle_filter] + spectrum_tally.filters = [cell_filter, total_filter, energy_filter_flux, particle_filter, dose_filter] spectrum_tally.scores = ['flux'] talls = openmc.Tallies([neutron_tally, spectrum_tally]) From 0679a6892a0c1c787189a5c2fc1335ff60aeb184 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:54:51 -0600 Subject: [PATCH 54/66] Redefine inputs for make_spherical_shells --- WC_Layers/TwoLayers_Geometry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WC_Layers/TwoLayers_Geometry.py b/WC_Layers/TwoLayers_Geometry.py index 0a87ef1..2ea4570 100644 --- a/WC_Layers/TwoLayers_Geometry.py +++ b/WC_Layers/TwoLayers_Geometry.py @@ -9,13 +9,14 @@ # Create geometry #Spherical shell: -def make_spherical_shells(layers, inner_radius): +def make_spherical_shells(materials, thicknesses, inner_radius): ''' Creates a set of concentric spherical shells, each with its own material & inner/outer radius. layers: list of tuples with OpenMC Material name and thickness: (material, thickness) inner_radius: the radius of the innermost spherical shell ''' + layers = zip(materials, thicknesses) inner_sphere = openmc.Sphere(r = inner_radius) cells = [openmc.Cell(fill = None, region = -inner_sphere)] for (material, thickness) in layers: From fc583b17dfdf0216c7f7770a0eff535d532d6906 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:56:07 -0600 Subject: [PATCH 55/66] Edit function docstring --- WC_Layers/TwoLayers_Geometry.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/WC_Layers/TwoLayers_Geometry.py b/WC_Layers/TwoLayers_Geometry.py index 2ea4570..871d175 100644 --- a/WC_Layers/TwoLayers_Geometry.py +++ b/WC_Layers/TwoLayers_Geometry.py @@ -1,20 +1,12 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Oct 11 15:56:57 2024 - -@author: Anupama Rajendra -""" - import openmc -# Create geometry -#Spherical shell: def make_spherical_shells(materials, thicknesses, inner_radius): ''' Creates a set of concentric spherical shells, each with its own material & inner/outer radius. - - layers: list of tuples with OpenMC Material name and thickness: (material, thickness) - inner_radius: the radius of the innermost spherical shell + inputs: + materials : iterable of OpenMC Material objects + thicknesses: thickness of each OpenMC Material + inner_radius: the radius of the innermost spherical shell ''' layers = zip(materials, thicknesses) inner_sphere = openmc.Sphere(r = inner_radius) From 785511edf8282db19177e7c3749da0b56d548f9c Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:04:31 -0600 Subject: [PATCH 56/66] Changed inputs for extract_source_data --- WC_Layers/Source_Mesh_Reader.py | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index 48ae056..f41ff77 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -1,40 +1,27 @@ -# -*- coding: utf-8 -*- -""" -Created on Mon Sep 30 15:16:44 2024 - -@author: Anupama Rajendra -""" - import h5py import numpy as np -source_density_name = 'source_density' - -# Open the HDF5 files -File_1 = h5py.File("source_mesh_1.h5m", 'r') -File_2 = h5py.File("source_mesh_2.h5m", 'r') -Files = [File_1, File_2] - -def extract_source_data(file_list): +def extract_source_data(source_mesh_list): ''' Identifies the location of the source density dataset within each mesh file. - input: list of .h5m mesh files (opened by h5py) containing photon source information + input: iterable of .h5m filenames (str), whose files contain photon source information output: numpy array of source density data with rows = # of mesh elements and columns = # number of photon groups, with one array per source mesh ''' - sd_list = np.ndarray((len(file_list), num_elements, photon_groups)) - - for file_num, file in enumerate(file_list): - sd_list[file_num,:] = file['tstt']['elements']['Tet4']['tags']['source_density'][:] - return sd_list + + sd_list = np.ndarray((len(source_mesh_list), num_elements, photon_groups)) + for source_index, source_name in enumerate(source_mesh_list): + file = h5py.File(source_name, 'r') + sd_list[source_index,:] = file['tstt']['elements']['Tet4']['tags']['source_density'][:] + return sd_list def save_source_density(sd_list, sd_filename): ''' Saves source density data as a text file. sd_list: list of source density datasets from h5m files - sd_filename: user-provided filename that appears as a prefix for the text files + sd_filename: user-provided filename that appears as a prefix for the text files (str) ''' for sd_index, source_density in enumerate(sd_list): with open(f'{sd_filename}_{sd_index + 1}.txt', 'w') as source: From ee8df5b5d230390f0367dd391f6931fba667df23 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:23:41 -0600 Subject: [PATCH 57/66] Add main function to Source_Mesh_Reader --- WC_Layers/Source_Mesh_Reader.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index f41ff77..5280e6c 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -1,7 +1,9 @@ import h5py import numpy as np +import yaml +import argparse -def extract_source_data(source_mesh_list): +def extract_source_data(source_mesh_list, num_elements, photon_groups): ''' Identifies the location of the source density dataset within each mesh file. @@ -28,7 +30,22 @@ def save_source_density(sd_list, sd_filename): for tet_element in source_density: source.write(' '.join(map(str, tet_element)) + '\n') -def extract_save_sd(file_list, sd_filename): - data_extractor = extract_source_data(file_list) - save_source_density(data_extractor, sd_filename) - return data_extractor +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--Mesh_Reader_YAML', required = True, help="Path (str) to YAML file containing required inputs for Source_Mesh_Reader") + args = parser.parse_args() + smr_yaml = args.Mesh_Reader_YAML + + with open(smr_yaml, 'r') as yaml_file: + inputs = yaml.safe_load(yaml_file) + + source_mesh_list = inputs['source_meshes'] + num_elements = inputs['num_elements'] + photon_groups = inputs['photon_groups'] + sd_filename = inputs['sd_filename'] + + esd = extract_source_data(source_mesh_list, num_elements, photon_groups) + ssd = save_source_density(esd, sd_filename) + +if __name__ == "__main__": + main() From 790db582e22f005ac3cc26c3cc048828dcbe97cb Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:26:35 -0600 Subject: [PATCH 58/66] Add default to argparse input --- WC_Layers/Source_Mesh_Reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WC_Layers/Source_Mesh_Reader.py b/WC_Layers/Source_Mesh_Reader.py index 5280e6c..5b3d612 100644 --- a/WC_Layers/Source_Mesh_Reader.py +++ b/WC_Layers/Source_Mesh_Reader.py @@ -32,7 +32,7 @@ def save_source_density(sd_list, sd_filename): def main(): parser = argparse.ArgumentParser() - parser.add_argument('--Mesh_Reader_YAML', required = True, help="Path (str) to YAML file containing required inputs for Source_Mesh_Reader") + parser.add_argument('--Mesh_Reader_YAML', default = 'Source_Mesh_Reader_Inputs.yaml', help="Path (str) to YAML file containing required inputs for Source_Mesh_Reader") args = parser.parse_args() smr_yaml = args.Mesh_Reader_YAML From 3b808c1b97553b275ce76aedc77fd3df7c96531d Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:34:12 -0600 Subject: [PATCH 59/66] Add files via upload --- Source_Mesh_Reader_Inputs.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Source_Mesh_Reader_Inputs.yaml diff --git a/Source_Mesh_Reader_Inputs.yaml b/Source_Mesh_Reader_Inputs.yaml new file mode 100644 index 0000000..ebb5463 --- /dev/null +++ b/Source_Mesh_Reader_Inputs.yaml @@ -0,0 +1,6 @@ +num_elements : 6168 +photon_groups : 24 +source_meshes : + - source_mesh_1.h5m + - source_mesh_2.h5m +sd_filename : source_density \ No newline at end of file From 771b147a704ae2da420f1738fa944f37b2eaca9f Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:40:54 -0600 Subject: [PATCH 60/66] Add input to function --- WC_Layers/TwoLayers_Geometry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WC_Layers/TwoLayers_Geometry.py b/WC_Layers/TwoLayers_Geometry.py index 871d175..295fe85 100644 --- a/WC_Layers/TwoLayers_Geometry.py +++ b/WC_Layers/TwoLayers_Geometry.py @@ -1,6 +1,6 @@ import openmc -def make_spherical_shells(materials, thicknesses, inner_radius): +def make_spherical_shells(materials, thicknesses, inner_radius, outer_boundary_type): ''' Creates a set of concentric spherical shells, each with its own material & inner/outer radius. inputs: @@ -17,7 +17,7 @@ def make_spherical_shells(materials, thicknesses, inner_radius): cells.append(openmc.Cell(fill = material, region = +inner_sphere & -outer_sphere)) outer_radius = inner_radius outer_sphere = inner_sphere - outer_sphere.boundary_type = 'vacuum' + outer_sphere.boundary_type = outer_boundary_type cells.append(openmc.Cell(fill = None, region = +outer_sphere)) geometry = openmc.Geometry(cells) return geometry From 7f76500784cc359741e16aaee652193c0736f391 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:10:01 -0600 Subject: [PATCH 61/66] Add docstrings to functions --- WC_Layers/TwoLayers_Materials.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/WC_Layers/TwoLayers_Materials.py b/WC_Layers/TwoLayers_Materials.py index 8017c27..cc151dc 100644 --- a/WC_Layers/TwoLayers_Materials.py +++ b/WC_Layers/TwoLayers_Materials.py @@ -1,14 +1,12 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Oct 11 13:49:23 2024 - -@author: Anupama Rajendra -""" import openmc -#ALARA Element Library to read density for specified element: -def alara_element_densities(filepath): - with open(""+filepath+"") as ALARA_Lib: +def alara_element_densities(alara_fp): + ''' + Creates a dictionary where keys = element names (str) and values = element density (float) + inputs: + alara_filepath : path to ALARA element library + ''' + with open(alara_fp) as ALARA_Lib: libLines = ALARA_Lib.readlines() num_lines = len(libLines) density_dict = {} @@ -20,9 +18,13 @@ def alara_element_densities(filepath): line_num += int(element_data[4]) + 1 return density_dict -# Create materials & export to XML: -#Simulating tungsten shell: -def make_element(elements, density_dict): +def make_materials(elements, density_dict): + ''' + Creates an OpenMC Materials object using user-specified elements + inputs: + elements: iterable of element names (str) + density_dict: dictionary with keys = element names (str) and values = element density (float) + ''' mats = openmc.Materials([]) for element_id, element in enumerate(elements): mat = openmc.Material(material_id=element_id+1, name=element) From 2a7d52c429bbbe6709d87b52d2d602c10ba37874 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:52:05 -0600 Subject: [PATCH 62/66] Change variable names and inputs --- WC_Layers/OpenMC_PhotonTransport.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/WC_Layers/OpenMC_PhotonTransport.py b/WC_Layers/OpenMC_PhotonTransport.py index 7970260..a1bdab4 100644 --- a/WC_Layers/OpenMC_PhotonTransport.py +++ b/WC_Layers/OpenMC_PhotonTransport.py @@ -1,17 +1,19 @@ import openmc import numpy as np -from Source_Mesh_Reader import extract_source_data, Files +import yaml +import argparse +from Source_Mesh_Reader import extract_source_data +from TwoLayers_Materials import alara_element_densities, make_materials -# Photon source densities from ALARA output -esd = extract_source_data(Files) - -def make_source(cells, mesh_file): +def make_source(bounds, cells, mesh_file, source_mesh_index): ''' Creates a list of OpenMC sources, complete with the relevant space and energy distributions inputs: + bounds : iterable of photon energy bounds (float) cells: list of OpenMC Cell objects mesh_file: .h5/.h5m mesh onto which photon source will be distributed + source_mesh_index: index specifying the photon source from which data is extracted output: source_list: list of OpenMC independent sources @@ -20,12 +22,12 @@ def make_source(cells, mesh_file): source_list = [] total_mesh = openmc.UnstructuredMesh(mesh_file, library='moab') for index, (lower_bound, upper_bound) in enumerate(zip(bounds[:-1],bounds[1:])): - mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[mesh_index][:,index], volume_normalized=False) + mesh_dist = openmc.stats.MeshSpatial(total_mesh, strengths=esd[source_mesh_index][:,index], volume_normalized=False) energy_dist = openmc.stats.Uniform(a=lower_bound, b=upper_bound) - source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[mesh_index][:, index]), particle='photon', domains=cells)) + source_list.append(openmc.IndependentSource(space=mesh_dist, energy=energy_dist, strength=np.sum(esd[source_mesh_index][:, index]), particle='photon', domains=cells)) return source_list, total_mesh -def tallies(total_mesh, tallied_cells): +def make_tallies(total_mesh, tallied_cells): ''' Creates tallies and assigns energy, spatial, and particle filters. @@ -57,10 +59,10 @@ def tallies(total_mesh, tallied_cells): spectrum_tally.filters = [cell_filter, total_filter, energy_filter_flux, particle_filter, dose_filter] spectrum_tally.scores = ['flux'] - talls = openmc.Tallies([neutron_tally, spectrum_tally]) + talls = openmc.Tallies([photon_tally, spectrum_tally]) return talls -def settings(source_list, total_batches, inactive_batches, num_particles, run_mode): +def make_settings(source_list, total_batches, inactive_batches, num_particles, run_mode): ''' Creates an OpenMC Settings object From 6b18246a12c6e0198dd75ff673886054209b6e50 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:55:58 -0600 Subject: [PATCH 63/66] Change variable key --- WC_Layers/PhotonTransport_Inputs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WC_Layers/PhotonTransport_Inputs.yaml b/WC_Layers/PhotonTransport_Inputs.yaml index 67a904d..ea18841 100644 --- a/WC_Layers/PhotonTransport_Inputs.yaml +++ b/WC_Layers/PhotonTransport_Inputs.yaml @@ -43,7 +43,7 @@ geom_info : thicknesses : #corresponds to each of the elements in element_list - 5 - 5 - outer_boundary : vacuum + outer_boundary_type : vacuum tally_info : tallied_elements : #change according to desired tally region/material From a3a99211f228923a2ed23fce2e1d989a436c450d Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:57:14 -0600 Subject: [PATCH 64/66] Update PhotonTransport_Inputs.yaml --- WC_Layers/PhotonTransport_Inputs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WC_Layers/PhotonTransport_Inputs.yaml b/WC_Layers/PhotonTransport_Inputs.yaml index ea18841..40ec28e 100644 --- a/WC_Layers/PhotonTransport_Inputs.yaml +++ b/WC_Layers/PhotonTransport_Inputs.yaml @@ -39,7 +39,7 @@ mat_info : - C geom_info : - inner_radius : 995, + inner_radius : 995 thicknesses : #corresponds to each of the elements in element_list - 5 - 5 From 608adba6daaa6ab88b2d3512f197a1ca256742f8 Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:59:47 -0600 Subject: [PATCH 65/66] Fix typo in run mode --- WC_Layers/PhotonTransport_Inputs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WC_Layers/PhotonTransport_Inputs.yaml b/WC_Layers/PhotonTransport_Inputs.yaml index 40ec28e..40ac0fa 100644 --- a/WC_Layers/PhotonTransport_Inputs.yaml +++ b/WC_Layers/PhotonTransport_Inputs.yaml @@ -54,4 +54,4 @@ settings_info : particles : 100000 batches : 10 inactive_batches : 1 - run_mode : fixed_source + run_mode : fixed source From 15f64efb88de452c83084bbbd77ba6221cedf05d Mon Sep 17 00:00:00 2001 From: Anupama Rajendra <113371601+anu1217@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:23:12 -0600 Subject: [PATCH 66/66] Update and rename Source_Mesh_Reader_Inputs.yaml to WC_Layers/Source_Mesh_Reader_Inputs.yaml --- .../Source_Mesh_Reader_Inputs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Source_Mesh_Reader_Inputs.yaml => WC_Layers/Source_Mesh_Reader_Inputs.yaml (72%) diff --git a/Source_Mesh_Reader_Inputs.yaml b/WC_Layers/Source_Mesh_Reader_Inputs.yaml similarity index 72% rename from Source_Mesh_Reader_Inputs.yaml rename to WC_Layers/Source_Mesh_Reader_Inputs.yaml index ebb5463..b4780b1 100644 --- a/Source_Mesh_Reader_Inputs.yaml +++ b/WC_Layers/Source_Mesh_Reader_Inputs.yaml @@ -3,4 +3,4 @@ photon_groups : 24 source_meshes : - source_mesh_1.h5m - source_mesh_2.h5m -sd_filename : source_density \ No newline at end of file +sd_filename : source_density