Skip to content

Commit ae35403

Browse files
committed
First comment of OpenMC importing of geometry
1 parent dc6585a commit ae35403

File tree

8 files changed

+67
-24
lines changed

8 files changed

+67
-24
lines changed

csg2csg/CellCard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self,card_string):
2828
self.cell_importance = 1 # note any importance - we assume everything else is 0
2929
self.cell_text_description = ""
3030
self.cell_interpreted = "" #this it the generalised form of the cell
31-
self.cell_fill = 0
31+
self.cell_fill = 0 # note fill could corresepond to a universe or a lattice fill
3232
self.cell_universe = 0
3333
self.cell_universe_offset = 0
3434
self.cell_universe_rotation = 0

csg2csg/Input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class InputDeck:
1414
# TODO maybe these should be dictionaries by index
1515
cell_list = []
1616
surface_list = []
17+
lattice_list = []
1718
last_free_surface_index = 0
1819
importance_list = {} # dictionary of importances
1920
material_list = {}

csg2csg/MCNPCellCard.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ def generalise(self):
171171
if idx == len(cell_description): break
172172

173173
self.cell_interpreted = cell_description
174-
#print(self.cell_id)
175-
#print(self.cell_interpreted)
176-
#logging.debug("%s\n", "Generalised cell card " + ''.join([str(i) for i in self.cell_interpreted]))
177-
174+
178175
return
179176

180177
# generally spaceify the text so that between each item
@@ -186,7 +183,6 @@ def __sanitise(self):
186183
# given a valid keyword and string return the value of the
187184
# keyword
188185
def __get_keyword_value(self,keyword,string):
189-
#regex = re.regex=re.compile("("+keyword+") ?= ?[1-9][0-9]*")
190186
regex = re.regex=re.compile("("+keyword+") ?= ?(?=.)([+-]?([0-9]*)(\.([0-9]+))?)")
191187
result = regex.search(string)[0]
192188
return result.split(" ")[2] #string[offset:end]

csg2csg/MCNPInput.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,15 +829,19 @@ def __get_cell_cards(self):
829829

830830
# set the boundary conditions
831831
def __apply_boundary_conditions(self):
832-
832+
833+
for particle in self.importance_list:
834+
importances = self.importance_list[particle].split()
835+
for idx,value in enumerate(importances):
836+
# TODO this needs to be multi particle
837+
self.cell_list[idx].cell_importance = float(value)
833838
# apply the importances to cells
834-
if len(self.importance_list) != 0:
839+
#if len(self.importance_list) != 0:
835840
# TODO make this loop apply to multiple particle
836841
# types but for now just do neutrons
837-
if len(self.importance_list[ParticleNames["NEUTRON"]]) != 0:
838-
importances = self.importance_list[ParticleNames["NEUTRON"]].split()
839-
for idx,value in enumerate(importances):
840-
self.cell_list[idx].cell_importance = float(value)
842+
# if len(self.importance_list[ParticleNames["NEUTRON"]]) != 0:
843+
# importances = self.importance_list[ParticleNames["NEUTRON"]].split()
844+
841845

842846
# loop over the cells and if the cell has
843847
# importance 0, all the sufaces get boundary

csg2csg/OpenMCCell.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,20 @@ def cell_from_attribute(xml_attribute):
115115

116116
# todo if name based materials are used will need
117117
# a helper function
118-
if xml_attribute["material"] == "void":
119-
cell.cell_material_number = 0
118+
119+
if "material" in xml_attribute:
120+
if xml_attribute["material"] == "void":
121+
cell.cell_material_number = 0
122+
else:
123+
cell.cell_material_number = xml_attribute["material"]
120124
else:
121-
cell.cell_material_number = xml_attribute["material"]
125+
cell.cell_material_number = 0
122126

123127
cell.cell_text_description = xml_attribute["region"]
124-
cell.cell_universe = xml_attribute["universe"]
125-
cell.cell_fill = xml_attribute["fill"]
128+
if "universe" in xml_attribute:
129+
cell.cell_universe = xml_attribute["universe"]
130+
if "fill" in xml_attribute:
131+
cell.cell_fill = xml_attribute["fill"]
126132

127133
cell.generalise()
128134
return cell

csg2csg/OpenMCInput.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from csg2csg.OpenMCSurface import SurfaceCard,surface_from_attribute, write_openmc_surface
1010
from csg2csg.OpenMCCell import cell_from_attribute, write_openmc_cell
1111
from csg2csg.OpenMCMaterial import material_from_attribute, write_openmc_material
12+
from csg2csg.OpenMCLattice import lattice_from_attribute, write_openmc_lattice
13+
1214
'''
1315
copy and paste from http://effbot.org/zone/element-lib.htm#prettyprint
1416
it basically walks your tree and adds spaces and newlines so the tree is
@@ -69,13 +71,21 @@ def process(self):
6971

7072
# process the geometry
7173
def __process_geometry(self):
74+
7275
for child in self.xml_geom:
7376
if child.tag == "surface":
7477
surface = surface_from_attribute(child.attrib)
7578
InputDeck.surface_list.append(surface)
7679
elif child.tag == "cell":
7780
cell = cell_from_attribute(child.attrib)
7881
InputDeck.cell_list.append(cell)
82+
elif child.tag == "lattice":
83+
lattice = lattice_from_attribute('lattice', child.attrib, child.getchildren())
84+
InputDeck.lattice_list.append(lattice)
85+
elif child.tag == "hex_lattice":
86+
lattice = lattice_from_attribute('hex_latice', child.attrib, child.getchildren())
87+
InputDeck.lattice_list.append(lattice)
88+
7989

8090
# loop over the cells and set the material
8191
# density for each cell
@@ -114,7 +124,13 @@ def __write_openmc_surfaces(self, geometry_tree):
114124
def __write_openmc_cells(self, geometry_tree):
115125
for cell in self.cell_list:
116126
write_openmc_cell(cell, geometry_tree)
117-
127+
128+
# write the collection of OpenMC lattice definitions
129+
def __write_openmc_lattices(self, geometry_tree):
130+
for lattice in self.lattice_list:
131+
write_openmc_lattice(lattice, geometry_tree)
132+
133+
118134
# write the collection of Material
119135
def __write_openmc_materials(self, material_tree):
120136
for mat in self.material_list:
@@ -167,6 +183,7 @@ def write_openmc(self, filename, flat = True):
167183

168184
self.__write_openmc_surfaces(geometry)
169185
self.__write_openmc_cells(geometry)
186+
self.__write_openmc_lattices(geometry)
170187
self.__check_unused_universes(geometry)
171188

172189
tree = ET.ElementTree(geometry)

csg2csg/OpenMCMaterial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ def get_zaid(name):
4141
nucleon_number = "00" + str(nucleon_number)
4242
elif nucleon_number > 10 and nucleon_number < 100:
4343
nucleon_number = "0" + str(nucleon_number)
44-
4544

46-
return str(zz)+nucleon_number
45+
return str(zz)+str(nucleon_number)
4746

4847
# convert zaid to a name for openmc
4948
def zaid_to_name(zaid_string):
@@ -60,6 +59,7 @@ def zaid_to_name(zaid_string):
6059
# turn zz into a name
6160

6261
name = name_zaid[zz]
62+
6363
return name+str(aa)
6464

6565
################## input functions #########################
@@ -83,10 +83,10 @@ def material_from_attribute(xml_element, children):
8383
zaid = get_zaid(nucid)
8484
if "wo" in child.attrib:
8585
# mass fractions are -ve
86-
nucs[zaid] = -1*float(child.attrib["wo"])
86+
nucs[zaid] = float(-1*float(child.attrib["wo"]))
8787
if "ao" in child.attrib:
8888
atom_fraction = True
89-
nucs[zaid] = child.attrib["ao"]
89+
nucs[zaid] = float(child.attrib["ao"])
9090

9191
if not atom_fraction: density = density*-1.0
9292

csg2csg/OpenMCSurface.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,29 @@ def write_openmc_surface(SurfaceCard, geometry_tree):
119119
def surface_from_attribute(xml_attribute):
120120
surface = SurfaceCard("")
121121
# loop over the surface attributes and build the generic description
122-
surface.boundary_condition = boundarystring_to_type(xml_attribute['boundary'])
123-
surface.surface_coefficients = xml_attribute['coeffs'].split()
122+
if "boundary" in xml_attribute:
123+
surface.boundary_condition = boundarystring_to_type(xml_attribute['boundary'])
124+
else:
125+
# if no boundary parameter then is automatically transmission
126+
surface.boundary_condition = SurfaceCard.BoundaryCondition.TRANSMISSION
127+
124128
surface.surface_id = xml_attribute['id']
125129
surface.surface_type = type_to_generictype(xml_attribute['type'])
130+
131+
# special cases where we need to instanciate as a general plane
132+
# TODO this expansion should likely be done somwhere else in a genaric
133+
# way
134+
if surface.surface_type == SurfaceCard.SurfaceType.PLANE_X:
135+
surface_coefficients = "1.0 0.0 0.0 " + xml_attribute['coeffs']
136+
elif surface.surface_type == SurfaceCard.SurfaceType.PLANE_Y:
137+
surface_coefficients = "0.0 1.0 0.0 " + xml_attribute['coeffs']
138+
elif surface.surface_type == SurfaceCard.SurfaceType.PLANE_Z:
139+
surface_coefficients = "0.0 0.0 1.0 " + xml_attribute['coeffs']
140+
else:
141+
surface_coefficients = xml_attribute['coeffs']
142+
143+
surface.surface_coefficients = surface_coefficients.split()
144+
126145
return surface
127146

128147
class OpenMCSurfaceCard(SurfaceCard):

0 commit comments

Comments
 (0)