From 8c7735d187bf3ee25b4ab4d04072c814695162b4 Mon Sep 17 00:00:00 2001 From: Steve Bradnam Date: Fri, 18 Feb 2022 16:32:00 +0000 Subject: [PATCH 1/2] Added preserve_xsid capability --- csg2csg/Input.py | 4 +++- csg2csg/MCNPInput.py | 6 +++--- csg2csg/SerpentInput.py | 6 +++--- csg2csg/SerpentMaterialCard.py | 8 ++++++-- csg2csg/__main__.py | 8 ++++++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/csg2csg/Input.py b/csg2csg/Input.py index 3e6f90a..877aea5 100644 --- a/csg2csg/Input.py +++ b/csg2csg/Input.py @@ -8,9 +8,10 @@ class InputDeck: """ Constructor """ - def __init__(self, filename, quick = False): + def __init__(self, filename, quick = False, preserve_xsid = False): self.filename = filename self.quick_process = quick + self.preserve_xsid = preserve_xsid self.file_lines = "" self.title = "" @@ -70,6 +71,7 @@ def get_cell_with_id(self, id): # instanciate from input def from_input(self,InputDeckClass): self.filename = InputDeckClass.filename + self.preserve_xsid = InputDeckClass.preserve_xsid self.title = InputDeckClass.title self.cell_list = InputDeckClass.cell_list self.surface_list = InputDeckClass.surface_list diff --git a/csg2csg/MCNPInput.py b/csg2csg/MCNPInput.py index 95dd267..959f133 100644 --- a/csg2csg/MCNPInput.py +++ b/csg2csg/MCNPInput.py @@ -29,11 +29,11 @@ class MCNPInput(InputDeck): """ MCNPInputDeck class - does the actuall processing """ - preserve_xsid = False + #preserve_xsid = False # constructor - def __init__(self, filename ="", quick = False): - InputDeck.__init__(self,filename, quick) + def __init__(self, filename ="", quick = False, preserve_xsid = False): + InputDeck.__init__(self,filename, quick, preserve_xsid) # self.process() # TODO - maybe make a function that aribitrarily extract text diff --git a/csg2csg/SerpentInput.py b/csg2csg/SerpentInput.py index 0e95717..3220709 100644 --- a/csg2csg/SerpentInput.py +++ b/csg2csg/SerpentInput.py @@ -13,8 +13,8 @@ class SerpentInput(InputDeck): """ # constructor - def __init__(self,filename = ""): - InputDeck.__init__(self,filename) + def __init__(self,filename = "",preserve_xsid=False): + InputDeck.__init__(self,filename,preserve_xsid) # extract a material card from the start line until def __get_material_card(self, start_line, mat_num): @@ -120,7 +120,7 @@ def __write_serpent_surfaces(self, filestream): def __write_serpent_materials(self, filestream): filestream.write("% --- material definitions --- %\n") for material in self.material_list: - write_serpent_material(filestream, self.material_list[material]) + write_serpent_material(filestream, self.material_list[material], self.preserve_xsid) return # main write serpent method, depending upon where the geometry diff --git a/csg2csg/SerpentMaterialCard.py b/csg2csg/SerpentMaterialCard.py index 265623a..a2c2218 100644 --- a/csg2csg/SerpentMaterialCard.py +++ b/csg2csg/SerpentMaterialCard.py @@ -4,7 +4,7 @@ from csg2csg.MCNPFormatter import get_fortran_formatted_number # write a specific serpent material card -def write_serpent_material(filestream, material): +def write_serpent_material(filestream, material, preserve_xs): string = "% " + material.material_name +"\n" string += "mat " + str(material.material_number) + " " @@ -17,7 +17,11 @@ def write_serpent_material(filestream, material): string += "\n" for nuc in material.composition_dictionary: - string += '{} {:e} \n'.format(nuc, material.composition_dictionary[nuc]) + if preserve_xs: + string += '{}.{} {:e} \n'.format(nuc, material.xsid_dictionary[nuc], material.composition_dictionary[nuc]) + else: + string += '{} {:e} \n'.format(nuc, material.composition_dictionary[nuc]) + filestream.write(string) return diff --git a/csg2csg/__main__.py b/csg2csg/__main__.py index 169e36d..aa6c4a9 100755 --- a/csg2csg/__main__.py +++ b/csg2csg/__main__.py @@ -52,6 +52,10 @@ def main(): help = 'Perform quick translation, skip surface comparison - model may not transport', action = "store_true") + parser.add_argument('-xs','--preserve_xsid', + help = 'Retain xs library for materials', + action = "store_true") + # parse the arguments args = parser.parse_args(argv) @@ -71,12 +75,12 @@ def main(): if args.format == 'mcnp': # read the mcnp input - input = MCNPInput(filename,args.quick) + input = MCNPInput(filename,args.quick,args.preserve_xsid) input.read() input.process() elif args.format == 'serpent': # read the serpent input - input = SerpentInput(filename) + input = SerpentInput(filename,args.preserve_xsid) input.read() input.process() elif args.format == 'openmc': From 1858c70aea113647a398e5fe7bb9da41358fb5b4 Mon Sep 17 00:00:00 2001 From: shimwell Date: Tue, 22 Feb 2022 14:51:02 +0000 Subject: [PATCH 2/2] [skip ci] Apply pep8 formatting changes --- csg2csg/Input.py | 2 +- csg2csg/MCNPInput.py | 13 +++++++------ csg2csg/SerpentInput.py | 8 +++++--- csg2csg/SerpentMaterialCard.py | 8 +++++--- csg2csg/__main__.py | 13 ++++++++----- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/csg2csg/Input.py b/csg2csg/Input.py index 925fccd..620642b 100644 --- a/csg2csg/Input.py +++ b/csg2csg/Input.py @@ -10,7 +10,7 @@ class InputDeck: """ Constructor """ - def __init__(self, filename, quick = False, preserve_xsid = False): + def __init__(self, filename, quick=False, preserve_xsid=False): self.filename = filename self.quick_process = quick self.preserve_xsid = preserve_xsid diff --git a/csg2csg/MCNPInput.py b/csg2csg/MCNPInput.py index a83a37b..49329ec 100644 --- a/csg2csg/MCNPInput.py +++ b/csg2csg/MCNPInput.py @@ -28,14 +28,15 @@ class MCNPInput(InputDeck): - """ MCNPInputDeck class - does the actuall processing - """ - #preserve_xsid = False + """MCNPInputDeck class - does the actuall processing""" + + # preserve_xsid = False # constructor - def __init__(self, filename ="", quick = False, preserve_xsid = False): - InputDeck.__init__(self,filename, quick, preserve_xsid) -# self.process() + def __init__(self, filename="", quick=False, preserve_xsid=False): + InputDeck.__init__(self, filename, quick, preserve_xsid) + + # self.process() # TODO - maybe make a function that aribitrarily extract text # between one keyword until another keyword is found diff --git a/csg2csg/SerpentInput.py b/csg2csg/SerpentInput.py index 582d94f..4f58035 100644 --- a/csg2csg/SerpentInput.py +++ b/csg2csg/SerpentInput.py @@ -13,8 +13,8 @@ class SerpentInput(InputDeck): """SerpentInput class - does the actual processing""" # constructor - def __init__(self,filename = "",preserve_xsid=False): - InputDeck.__init__(self,filename,preserve_xsid) + def __init__(self, filename="", preserve_xsid=False): + InputDeck.__init__(self, filename, preserve_xsid) # extract a material card from the start line until def __get_material_card(self, start_line, mat_num): @@ -118,7 +118,9 @@ def __write_serpent_surfaces(self, filestream): def __write_serpent_materials(self, filestream): filestream.write("% --- material definitions --- %\n") for material in self.material_list: - write_serpent_material(filestream, self.material_list[material], self.preserve_xsid) + write_serpent_material( + filestream, self.material_list[material], self.preserve_xsid + ) return # main write serpent method, depending upon where the geometry diff --git a/csg2csg/SerpentMaterialCard.py b/csg2csg/SerpentMaterialCard.py index 2f79f1b..a7cb075 100644 --- a/csg2csg/SerpentMaterialCard.py +++ b/csg2csg/SerpentMaterialCard.py @@ -18,9 +18,11 @@ def write_serpent_material(filestream, material, preserve_xs): for nuc in material.composition_dictionary: if preserve_xs: - string += '{}.{} {:e} \n'.format(nuc, material.xsid_dictionary[nuc], material.composition_dictionary[nuc]) - else: - string += '{} {:e} \n'.format(nuc, material.composition_dictionary[nuc]) + string += "{}.{} {:e} \n".format( + nuc, material.xsid_dictionary[nuc], material.composition_dictionary[nuc] + ) + else: + string += "{} {:e} \n".format(nuc, material.composition_dictionary[nuc]) filestream.write(string) return diff --git a/csg2csg/__main__.py b/csg2csg/__main__.py index 2895cfd..7dcafa9 100755 --- a/csg2csg/__main__.py +++ b/csg2csg/__main__.py @@ -59,9 +59,12 @@ def main(): action="store_true", ) - parser.add_argument('-xs','--preserve_xsid', - help = 'Retain xs library for materials', - action = "store_true") + parser.add_argument( + "-xs", + "--preserve_xsid", + help="Retain xs library for materials", + action="store_true", + ) # parse the arguments args = parser.parse_args(argv) @@ -81,12 +84,12 @@ def main(): if args.format == "mcnp": # read the mcnp input - input = MCNPInput(filename,args.quick,args.preserve_xsid) + input = MCNPInput(filename, args.quick, args.preserve_xsid) input.read() input.process() elif args.format == "serpent": # read the serpent input - input = SerpentInput(filename,args.preserve_xsid) + input = SerpentInput(filename, args.preserve_xsid) input.read() input.process() elif args.format == "openmc":