Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion csg2csg/Input.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# /usr/env/python3

from csg2csg.UniverseCard import UniverseCard, uni_fill, mat_fill
import copy

class InputDeck:
"""InputDeck class from which other concrete examples
Expand All @@ -22,6 +23,7 @@ def __init__(self, filename, quick=False):
# TODO maybe these should be dictionaries by index
self.cell_list = []
self.surface_list = []
self.universe_list = []
self.last_free_surface_index = 0
self.importance_list = {} # dictionary of importances
self.material_list = {}
Expand Down Expand Up @@ -76,6 +78,7 @@ def from_input(self, InputDeckClass):
self.cell_list = InputDeckClass.cell_list
self.surface_list = InputDeckClass.surface_list
self.material_list = InputDeckClass.material_list
self.universe_list = InputDeckClass.universe_list
return

# step through each cell and determine if the cell can
Expand All @@ -87,3 +90,43 @@ def split_unions(self):
# match any splitable unions - this will look like (stuff):(stuff):(stuff)
# so we could make 3 cells from that
continue

# prepare universe entries given cells
def create_universes_from_cells(self):
universe_ids = set()

# count unique universe IDs
universe_ids.update(int(cell.cell_universe) for cell in self.cell_list)

# Maybe set is empty? In which case, put every cell in universe 1
#if not universe_ids:
# universe_ids.add(1)
# for cell in self.cell_list:
# cell.cell_universe = 1

for uni in universe_ids:
newUni = UniverseCard()
newUni.build_from_cell_list(uni,self.cell_list)
self.universe_list.append(newUni)

# Need to ensure there is both a root universe and, if cells,
# a cell universe to hold them. This may imply adding another
# universe to the geometry and changing the cell universe IDs.
# First need to identify whether the root universe has cells.
# If so, duplicate the universe, make the new universe a cell
# universe without being root, remove cells from the root universe,
# and make the root universe contain the new universe.
for uni in self.universe_list:
if uni.is_root:
if uni.cell_list:
newID = max(universe_ids) + 1
newUni = copy.copy(uni)
newUni.universe_id = newID
newUni.is_root = 0
newUni.border_surface = 0
uni.cell_list = []
uni.fill_type = uni_fill
uni.fill_id = newID
self.universe_list.append(newUni)

return
2 changes: 1 addition & 1 deletion csg2csg/MCNPCellCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def __interpret(self):
tokens = self.text_string.split()

tokens = string.split()

self.cell_id = int(tokens[0])
material_number = int(tokens[1])
if material_number > 0:
Expand Down
24 changes: 12 additions & 12 deletions csg2csg/MCNPInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,15 @@ def __simplify_cones(self):
# loop over the surfaces
for surf in self.surface_list:
# if we are a cone
print(
surf.surface_type,
surf.surface_type
in [
SurfaceCard.SurfaceType["CONE_X"],
SurfaceCard.SurfaceType["CONE_Y"],
SurfaceCard.SurfaceType["CONE_Z"],
],
)
#print(
# surf.surface_type,
# surf.surface_type
# in [
# SurfaceCard.SurfaceType["CONE_X"],
# SurfaceCard.SurfaceType["CONE_Y"],
# SurfaceCard.SurfaceType["CONE_Z"],
# ],
#)
if surf.surface_type in [
SurfaceCard.SurfaceType["CONE_X"],
SurfaceCard.SurfaceType["CONE_Y"],
Expand Down Expand Up @@ -1166,7 +1166,7 @@ def __get_surface_cards(self, idx):
while True:
surf_line = strip_dollar_comments(self.file_lines[idx])
if surf_line.isspace():
logging.debug("%s", "found end of cell cards at line " + str(idx))
logging.debug("%s", "found end of surface cards at line " + str(idx))
idx += 1
break

Expand Down Expand Up @@ -1343,7 +1343,7 @@ def process(self):
self.__get_material_cards(idx)
# need to flatten first to get transformed surface in the
# correct place
self.__simplify_cones()
#self.__simplify_cones()
self.__flatten_macrobodies()
self.__explode_nots()

Expand Down Expand Up @@ -1401,7 +1401,7 @@ def __write_mcnp_materials(self, filestream):
filestream, self.material_list[material], self.preserve_xsid
)

# main write MCNP method, depnds on where the geometry
# main write MCNP method, depends on where the geometry
# came from
def write_mcnp(self, filename, flat=True):
f = open(filename, "w")
Expand Down
2 changes: 0 additions & 2 deletions csg2csg/MCNPSurfaceCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def mcnp_cone_y(SurfaceCard):
# write the mcnp form of an cone aligned along the z axis
def mcnp_cone_z(SurfaceCard):
string = "k/z "
print(SurfaceCard.surface_coefficients)
string += str(SurfaceCard.surface_coefficients[0]) + " "
string += str(SurfaceCard.surface_coefficients[1]) + " "
string += str(SurfaceCard.surface_coefficients[2]) + " "
Expand Down Expand Up @@ -224,7 +223,6 @@ def write_mcnp_surface(filestream, SurfaceCard):
elif SurfaceCard.surface_type == SurfaceCard.SurfaceType["PLANE_Y"]:
string += mcnp_plane_y(SurfaceCard)
elif SurfaceCard.surface_type == SurfaceCard.SurfaceType["PLANE_Z"]:
print(SurfaceCard)
string += mcnp_plane_z(SurfaceCard)
elif SurfaceCard.surface_type == SurfaceCard.SurfaceType["CYLINDER_X"]:
string += mcnp_cylinder_x(SurfaceCard)
Expand Down
1 change: 1 addition & 0 deletions csg2csg/MaterialCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ def explode_elements(self):
for key in new_nuclides.keys():
self.composition_dictionary[key] = new_nuclides[key]
self.xsid_dictionary[key] = ""

78 changes: 78 additions & 0 deletions csg2csg/SCONECellCard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/env/python3

from csg2csg.MCNPFormatter import mcnp_line_formatter

from csg2csg.CellCard import CellCard
from enum import Enum
import re
import math

# turn the generic operation type into a scone relevant text string
def scone_op_from_generic(Operation):
# if we are not of type operator - we are string do nowt
if not isinstance(Operation, CellCard.OperationType):
if Operation == "(":
return " < "
elif Operation == ")":
return " > "
else:
return Operation
else:
# otherwise we need to do something
if Operation == CellCard.OperationType["NOT"]:
string = " # "
elif Operation == CellCard.OperationType["AND"]:
string = " "
elif Operation == CellCard.OperationType["UNION"]:
string = " : "
else:
string = "unknown operation"
# return the operation
return string


# write the cell card for a scone cell given a generic cell card
def write_scone_cell(filestream, CellCard):

# In root universe, identify .......
# Presently assumes only two cells in the root, with one surface,
# as in Serpent.
# Allow multiple cells in root. Fix this later!
#if (CellCard.cell_universe == 0 and
#CellCard.cell_surface_list[0] >= 0):
# return

# print (CellCard)
string = str(CellCard.cell_id) + " { type unionCell; id "
string += str(CellCard.cell_id) + "; "

# Need to keep track of universe definitions and return
# to write these separately
if CellCard.cell_fill != 0:
string += " filltype uni; universe " + str(int(CellCard.cell_fill) + 1) + "; "

# Doesn't have a universe - has a material
# Due to SCONE weirdness, all materials are preceded with an 'm'
if CellCard.cell_fill == 0:
# material 0 is void
string += " filltype mat; material "
if CellCard.cell_material_number == 0:
string += " void; "
else:
string += "m" + str(CellCard.cell_material_number) + "; "

string += "surfaces [ "

# build the cell description
for item in CellCard.cell_interpreted:
string += scone_op_from_generic(item)

string += " ]; }\n"

# removes any multiple spaces
string = re.sub(" +", " ", string)

string = mcnp_line_formatter(string)

filestream.write(string)

101 changes: 101 additions & 0 deletions csg2csg/SCONEInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# /usr/env/python3

from csg2csg.Input import InputDeck
from csg2csg.SCONESurfaceCard import write_scone_surface
from csg2csg.SCONECellCard import write_scone_cell
from csg2csg.SCONEMaterialCard import write_scone_material
from csg2csg.SCONEUniverseCard import write_scone_universe

import logging
import re


class SCONEInput(InputDeck):
"""SCONEInput class - does the actual processing"""

# constructor
def __init__(self, filename=""):
InputDeck.__init__(self, filename)

# open the geometry card
def __write_scone_geometry_start(self, filestream):
filestream.write("geometry { \n")
filestream.write("type geometryStd; \n")
# Surely there is a way to customise this? Am I missing a
# method somewhere? For now I will leave as vacuum - should be easy
# for the user to change
filestream.write("boundary (0 0 0 0 0 0); \n")
filestream.write("graph {type shrunk;} \n")
return

# close the geometry card
def __write_scone_geometry_end(self, filestream):
filestream.write("} \n")
return

# open the nuclear data card
def __write_scone_data_start(self, filestream):
filestream.write("nuclearData { \n")
filestream.write("handles { \n")
filestream.write("ce {type aceNeutronDatabase; ")
filestream.write("aceLibrary $SCONE_ACE; ures 0;} \n")
filestream.write("} \n")
return

# close the data card
def __write_scone_data_end(self, filestream):
filestream.write("} \n")
return

# write the SCONE surface definitions
def __write_scone_surfaces(self, filestream):
filestream.write("! --- surface definitions --- !\n")
filestream.write("surfaces { \n")
for surface in self.surface_list:
write_scone_surface(filestream, surface)
filestream.write("} \n")
return

# Write the SCONE Cell definitions
def __write_scone_cells(self, filestream):
filestream.write("! --- cell definitions --- !\n")
filestream.write("cells { \n")
for cell in self.cell_list:
write_scone_cell(filestream, cell)
filestream.write("} \n")
return

# Write the SCONE universe definitions
# Most codes have universes implicit in their cells, complicating things
# slightly.
def __write_scone_universes(self, filestream):
filestream.write("! --- universe definitions --- !\n")
filestream.write("universes { \n")
for universe in self.universe_list:
write_scone_universe(filestream, universe)
filestream.write("} \n")

# write the material compositions
def __write_scone_materials(self, filestream):
filestream.write("! --- material definitions --- !\n")
filestream.write("materials { \n")
for material in self.material_list:
write_scone_material(filestream, self.material_list[material])
filestream.write("} \n")
return


# main write scone method, depending upon where the geometry
# came from
def write_scone(self, filename, flat=True):
f = open(filename, "w")
self.__write_scone_geometry_start(f)
self.__write_scone_surfaces(f)
self.__write_scone_cells(f)
self.create_universes_from_cells()
self.__write_scone_universes(f)
self.__write_scone_geometry_end(f)
self.__write_scone_data_start(f)
self.__write_scone_materials(f)
self.__write_scone_data_end(f)
f.close()
38 changes: 38 additions & 0 deletions csg2csg/SCONEMaterialCard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/env/python3

from csg2csg.MaterialCard import MaterialCard
from csg2csg.MCNPFormatter import get_fortran_formatted_number

# write a specific scone material card
def write_scone_material(filestream, MaterialCard):

string = "! " + MaterialCard.material_name + " \n"
string += "m" + str(MaterialCard.material_number) + " { \n"
string += "composition { \n"
# Stick on .03 regardless until something to read temperature
# from MCNP is added!
# Multiply by adens because SCONE requires absolute densities
dens = MaterialCard.density
if dens > 0:
adens = dens
else:
molar_mass = 0
for nuc in MaterialCard.composition_dictionary:
molar_mass += MaterialCard.composition_dictionary[nuc] * (int(nuc) % 1000)

adens = -dens * 6.02214e-01 / molar_mass

for nuc in MaterialCard.composition_dictionary:
string += "{}.03 {:e}; \n".format(
nuc, MaterialCard.composition_dictionary[nuc] * adens
)

string += "} \n"

# set the relevant colour
if MaterialCard.material_colour:
string += "rgb (" + MaterialCard.material_colour + "); \n"

string += "} \n"
filestream.write(string)
return
Loading
Loading