diff --git a/src/geouned/GEOUNED/Cuboid/translate.py b/src/geouned/GEOUNED/Cuboid/translate.py index 3e850986..4f284538 100644 --- a/src/geouned/GEOUNED/Cuboid/translate.py +++ b/src/geouned/GEOUNED/Cuboid/translate.py @@ -84,13 +84,13 @@ def get_id(face_in, Surfaces): return 0 -def translate(meta_list, surfaces, universe_box, setting): +def translate(meta_list, surfaces, universe_box, debug): tot_solid = len(meta_list) for i, m in enumerate(meta_list): if m.IsEnclosure: continue print(f"Decomposing solid: {i}/{tot_solid} ") - if setting["debug"]: + if debug: print(m.Comments) if m.IsEnclosure: m.Solids[0].exportStep(f"origEnclosure_{i}.stp") diff --git a/src/geouned/GEOUNED/Void/Void.py b/src/geouned/GEOUNED/Void/Void.py index 01cfcafc..f4aedce3 100644 --- a/src/geouned/GEOUNED/Void/Void.py +++ b/src/geouned/GEOUNED/Void/Void.py @@ -10,7 +10,19 @@ from .VoidBoxClass import VoidBox -def void_generation(MetaList, EnclosureList, Surfaces, UniverseBox, setting, init): +def void_generation( + MetaList, + EnclosureList, + Surfaces, + UniverseBox, + voidMat, + maxsurf, + maxbracket, + minVoidSize, + simplify, + sort_enclosure, + init, +): voidList = [] if EnclosureList: @@ -32,15 +44,23 @@ def void_generation(MetaList, EnclosureList, Surfaces, UniverseBox, setting, ini ) EnclosureBox = GeounedSolid(None, Box) - if setting["voidMat"]: - voidMat = setting["voidMat"] + if voidMat: EnclosureBox.set_material(voidMat[0], voidMat[1], voidMat[2]) # get voids in 0 Level Enclosure (original Universe) # if exist Level 1 enclosures are considered as material cells print("Build Void highest enclosure") - voids = get_void_def(newMetaList, Surfaces, EnclosureBox, setting, Lev0=True) + voids = get_void_def( + newMetaList, + Surfaces, + EnclosureBox, + maxsurf, + maxbracket, + minVoidSize, + simplify, + Lev0=True, + ) voidList.append(voids) # Perform enclosure void @@ -55,25 +75,38 @@ def void_generation(MetaList, EnclosureList, Surfaces, UniverseBox, setting, ini newMetaList = VF.select_solids(MetaList, encl.SonEnclosures, encl) print(f"Build Void enclosure {j} in enclosure level {i + 1}") # select solids overlapping current enclosure "encl", and lower level enclosures - voids = get_void_def(newMetaList, Surfaces, encl, setting) + voids = get_void_def( + newMetaList, + Surfaces, + encl, + maxsurf, + maxbracket, + minVoidSize, + simplify, + False, + ) voidList.append(voids) voidList.append(set_graveyard_cell(Surfaces, UniverseBox)) - return VF.update_void_list( - init, voidList, NestedEnclosure, setting["sort_enclosure"] - ) - + return VF.update_void_list(init, voidList, NestedEnclosure, sort_enclosure) -def get_void_def(MetaList, Surfaces, Enclosure, setting, Lev0=False): - maxsurf = setting["maxSurf"] - maxbracket = setting["maxBracket"] - minSize = setting["minVoidSize"] +def get_void_def( + MetaList, + Surfaces, + Enclosure, + maxsurf, + maxbracket, + minVoidSize, + simplify, + Lev0=False, +): - if "full" in setting["simplify"].lower(): + # TODO on another PR this can be removed with an attribute setter on the CadToCsg class + if "full" in simplify.lower(): simplifyVoid = "full" - elif "void" in setting["simplify"].lower(): + elif "void" in simplify.lower(): simplifyVoid = "diag" else: simplifyVoid = "no" @@ -98,7 +131,7 @@ def get_void_def(MetaList, Surfaces, Enclosure, setting, Lev0=False): print(f"{iloop} {iz + 1}/{nvoid} {nsurfaces} {nbrackets}") if nsurfaces > maxsurf and nbrackets > maxbracket: - newspace = z.split(minSize) + newspace = z.split(minVoidSize) else: newspace = None diff --git a/src/geouned/GEOUNED/Write/MCNPFormat.py b/src/geouned/GEOUNED/Write/MCNPFormat.py index bc6d4514..49201d2d 100644 --- a/src/geouned/GEOUNED/Write/MCNPFormat.py +++ b/src/geouned/GEOUNED/Write/MCNPFormat.py @@ -14,12 +14,14 @@ class McnpInput: - def __init__(self, Meta, Surfaces, setting): - self.Title = setting["title"] - self.VolSDEF = setting["volSDEF"] - self.VolCARD = setting["volCARD"] - self.U0CARD = setting["UCARD"] - self.dummyMat = setting["dummyMat"] + def __init__( + self, Meta, Surfaces, stepFile, title, volSDEF, volCARD, UCARD, dummyMat + ): + self.Title = title + self.VolSDEF = volSDEF + self.VolCARD = volCARD + self.U0CARD = UCARD + self.dummyMat = dummyMat self.Cells = Meta self.Options = { "Volume": self.VolCARD, @@ -28,7 +30,7 @@ def __init__(self, Meta, Surfaces, setting): } self.part = "P" - self.StepFile = setting["stepFile"] + self.StepFile = stepFile if isinstance(self.StepFile, (tuple, list)): self.StepFile = "; ".join(self.StepFile) diff --git a/src/geouned/GEOUNED/Write/PHITSFormat.py b/src/geouned/GEOUNED/Write/PHITSFormat.py index 3a3cf0fd..b4eabe7a 100644 --- a/src/geouned/GEOUNED/Write/PHITSFormat.py +++ b/src/geouned/GEOUNED/Write/PHITSFormat.py @@ -29,19 +29,32 @@ class PhitsInput: - def __init__(self, Meta, Surfaces, setting): - self.Title = setting["title"] - self.VolSDEF = setting["volSDEF"] - self.VolCARD = setting["volCARD"] - self.U0CARD = setting["UCARD"] - self.DummyMat = setting["dummyMat"] - self.Matfile = setting["matFile"] - self.voidMat = setting["voidMat"] - self.startCell = setting["startCell"] + def __init__( + self, + Meta, + Surfaces, + title, + volSDEF, + volCARD, + UCARD, + dummyMat, + matFile, + voidMat, + startCell, + stepFile, + ): + self.Title = title + self.VolSDEF = volSDEF + self.VolCARD = volCARD + self.U0CARD = UCARD + self.DummyMat = dummyMat + self.Matfile = matFile + self.voidMat = voidMat + self.startCell = startCell self.Cells = Meta self.Options = {"Volume": self.VolCARD, "Universe": self.U0CARD} - self.StepFile = setting["stepFile"] + self.StepFile = stepFile if isinstance(self.StepFile, (tuple, list)): self.StepFile = "; ".join(self.StepFile) diff --git a/src/geouned/GEOUNED/Write/SerpentFormat.py b/src/geouned/GEOUNED/Write/SerpentFormat.py index f350da9c..3980a12e 100644 --- a/src/geouned/GEOUNED/Write/SerpentFormat.py +++ b/src/geouned/GEOUNED/Write/SerpentFormat.py @@ -13,12 +13,14 @@ class SerpentInput: - def __init__(self, Meta, Surfaces, setting): - self.Title = setting["title"] - self.VolSDEF = setting["volSDEF"] - self.VolCARD = setting["volCARD"] - self.U0CARD = setting["UCARD"] - self.dummyMat = setting["dummyMat"] + def __init__( + self, Meta, Surfaces, title, volSDEF, volCARD, UCARD, dummyMat, stepFile + ): + self.Title = title + self.VolSDEF = volSDEF + self.VolCARD = volCARD + self.U0CARD = UCARD + self.dummyMat = dummyMat self.Cells = Meta self.Options = { "Volume": self.VolCARD, @@ -27,7 +29,7 @@ def __init__(self, Meta, Surfaces, setting): } self.part = "p" - self.StepFile = setting["stepFile"] + self.StepFile = stepFile if isinstance(self.StepFile, (tuple, list)): self.StepFile = "; ".join(self.StepFile) diff --git a/src/geouned/GEOUNED/Write/WriteFiles.py b/src/geouned/GEOUNED/Write/WriteFiles.py index 15a61682..f02d5794 100644 --- a/src/geouned/GEOUNED/Write/WriteFiles.py +++ b/src/geouned/GEOUNED/Write/WriteFiles.py @@ -5,27 +5,43 @@ from .SerpentFormat import SerpentInput -def write_geometry(UniverseBox, MetaList, Surfaces, code_setting): - - baseName = code_setting["geometryName"] +def write_geometry( + UniverseBox, + MetaList, + Surfaces, + stepFile, + title, + volSDEF, + volCARD, + UCARD, + dummyMat, + geometryName, + outFormat, + cellCommentFile, + cellSummaryFile, + voidGen, + matFile, + voidMat, + startCell, +): # Currently there are two was of setting outFormat (via a .set method and # a class attribute. Once we have a single method then move this validating # input code to the attribute @setter supported_mc_codes = ("mcnp", "openMC_XML", "openMC_PY", "serpent", "phits") - for out_format in code_setting["outFormat"]: + for out_format in outFormat: if out_format not in supported_mc_codes: msg = f"outFormat {out_format} not in supported MC codes ({supported_mc_codes})" raise ValueError(msg) # write cells comments in file - if code_setting["cellCommentFile"]: - OutFiles.comments_write(baseName, MetaList) - if code_setting["cellSummaryFile"]: - OutFiles.summary_write(baseName, MetaList) + if cellCommentFile: + OutFiles.comments_write(geometryName, MetaList) + if cellSummaryFile: + OutFiles.summary_write(geometryName, MetaList) - if "mcnp" in code_setting["outFormat"]: - mcnpFilename = baseName + ".mcnp" + if "mcnp" in outFormat: + mcnpFilename = geometryName + ".mcnp" outBox = ( UniverseBox.XMin, UniverseBox.XMax, @@ -34,31 +50,30 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting): UniverseBox.ZMin, UniverseBox.ZMax, ) - if code_setting["voidGen"]: + if voidGen: outSphere = (Surfaces["Sph"][-1].Index, Surfaces["Sph"][-1].Surf.Radius) else: outSphere = None - MCNPfile = McnpInput(MetaList, Surfaces, code_setting) + MCNPfile = McnpInput( + MetaList, Surfaces, stepFile, title, volSDEF, volCARD, UCARD, dummyMat + ) MCNPfile.set_sdef((outSphere, outBox)) MCNPfile.write_input(mcnpFilename) - if ( - "openMC_XML" in code_setting["outFormat"] - or "openMC_PY" in code_setting["outFormat"] - ): + if "openMC_XML" in outFormat or "openMC_PY" in outFormat: OMCFile = OpenmcInput(MetaList, Surfaces) - if "openMC_XML" in code_setting["outFormat"]: - omcFilename = baseName + ".xml" + if "openMC_XML" in outFormat: + omcFilename = geometryName + ".xml" OMCFile.write_xml(omcFilename) - if "openMC_PY" in code_setting["outFormat"]: - omcFilename = baseName + ".py" + if "openMC_PY" in outFormat: + omcFilename = geometryName + ".py" OMCFile.write_py(omcFilename) - if "serpent" in code_setting["outFormat"]: - serpentFilename = baseName + ".serp" + if "serpent" in outFormat: + serpentFilename = geometryName + ".serp" outBox = ( UniverseBox.XMin, UniverseBox.XMax, @@ -67,17 +82,19 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting): UniverseBox.ZMin, UniverseBox.ZMax, ) - if code_setting["voidGen"]: + if voidGen: outSphere = (Surfaces["Sph"][-1].Index, Surfaces["Sph"][-1].Surf.Radius) else: outSphere = None - Serpentfile = SerpentInput(MetaList, Surfaces, code_setting) + Serpentfile = SerpentInput( + MetaList, Surfaces, title, volSDEF, volCARD, UCARD, dummyMat, stepFile + ) # Serpentfile.set_sdef((outSphere,outBox)) Serpentfile.write_input(serpentFilename) - if "phits" in code_setting["outFormat"]: - phitsFilename = baseName + ".inp" + if "phits" in outFormat: + phitsFilename = geometryName + ".inp" PHITS_outBox = ( UniverseBox.XMin, UniverseBox.XMax, @@ -86,7 +103,7 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting): UniverseBox.ZMin, UniverseBox.ZMax, ) - if code_setting["voidGen"]: + if voidGen: PHITS_outSphere = ( Surfaces["Sph"][-1].Index, Surfaces["Sph"][-1].Surf.Radius, @@ -94,6 +111,18 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting): else: PHITS_outSphere = None - PHITSfile = PhitsInput(MetaList, Surfaces, code_setting) + PHITSfile = PhitsInput( + MetaList, + Surfaces, + title, + volSDEF, + volCARD, + UCARD, + dummyMat, + matFile, + voidMat, + startCell, + stepFile, + ) # PHITSfile.setSDEF_PHITS((PHITS_outSphere,PHITS_outBox)) PHITSfile.write_phits(phitsFilename) diff --git a/src/geouned/GEOUNED/__init__.py b/src/geouned/GEOUNED/__init__.py index 0edd6c0f..b3d3aadc 100644 --- a/src/geouned/GEOUNED/__init__.py +++ b/src/geouned/GEOUNED/__init__.py @@ -361,8 +361,7 @@ def start(self): ) ) - code_setting = self.__dict__ - if code_setting is None: + if self.__dict__ is None: raise ValueError("Cannot run the code. Input are missing") if self.stepFile == "": raise ValueError("Cannot run the code. Step file name is missing") @@ -433,13 +432,13 @@ def start(self): # decompose all solids in elementary solids (convex ones) warningSolidList = decompose_solids( - MetaList, Surfaces, UniverseBox, code_setting, True + MetaList, Surfaces, UniverseBox, self.debug, True ) # decompose Enclosure solids if self.voidGen and EnclosureList: warningEnclosureList = decompose_solids( - EnclosureList, Surfaces, UniverseBox, code_setting, False + EnclosureList, Surfaces, UniverseBox, self.debug, False ) print("End of decomposition phase") @@ -463,11 +462,11 @@ def start(self): Conv.no_overlapping_cell(MetaList, Surfaces) else: - translate(MetaList, Surfaces, UniverseBox, code_setting) + translate(MetaList, Surfaces, UniverseBox, self.debug) # decompose Enclosure solids if self.voidGen and EnclosureList: warningEnclosureList = decompose_solids( - EnclosureList, Surfaces, UniverseBox, code_setting, False + EnclosureList, Surfaces, UniverseBox, self.debug, False ) tempstr2 = str(datetime.now() - tempTime) @@ -500,11 +499,22 @@ def start(self): init = MetaList[-1].__id__ - len(EnclosureList) else: init = 0 + # TODO perhaps this method should be moved into the CsgToCsg class to avoid passing in so many args MetaVoid = Void.void_generation( - MetaReduced, EnclosureList, Surfaces, UniverseBox, code_setting, init + MetaReduced, + EnclosureList, + Surfaces, + UniverseBox, + self.voidMat, + self.maxSurf, + self.maxBracket, + self.minVoidSize, + self.simplify, + self.sort_enclosure, + init, ) - # if code_setting['simplify'] == 'full' and not Options.forceNoOverlap: + # if self.simplify == 'full' and not Options.forceNoOverlap: if self.simplify == "full": Surfs = {} for lst in Surfaces.values(): @@ -580,7 +590,25 @@ def start(self): process_cones(MetaList, coneInfo, Surfaces, UniverseBox) # write outputformat input - write_geometry(UniverseBox, MetaList, Surfaces, code_setting) + write_geometry( + UniverseBox, + MetaList, + Surfaces, + self.stepFile, + self.title, + self.volSDEF, + self.volCARD, + self.UCARD, + self.dummyMat, + self.geometryName, + self.outFormat, + self.cellCommentFile, + self.cellSummaryFile, + self.voidGen, + self.matFile, + self.voidMat, + self.startCell, + ) print("End of MCNP, OpenMC, Serpent and PHITS translation phase") @@ -591,14 +619,14 @@ def start(self): print("Translation time of void cells", tempTime2 - tempTime1) -def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta): +def decompose_solids(MetaList, Surfaces, UniverseBox, debug, meta): totsolid = len(MetaList) warningSolids = [] for i, m in enumerate(MetaList): if meta and m.IsEnclosure: continue print(f"Decomposing solid: {i + 1}/{totsolid} ") - if setting["debug"]: + if debug: print(m.Comments) if not path.exists("debug"): mkdir("debug") @@ -625,7 +653,7 @@ def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta): warningSolids.append(i) - if setting["debug"]: + if debug: if m.IsEnclosure: comsolid.exportStep(f"debug/compEnclosure_{i}.stp") else: