diff --git a/src/geouned/GEOUNED/utils/geometry_gu.py b/src/geouned/GEOUNED/utils/geometry_gu.py index 8892c94d..4011cbe5 100644 --- a/src/geouned/GEOUNED/utils/geometry_gu.py +++ b/src/geouned/GEOUNED/utils/geometry_gu.py @@ -117,15 +117,15 @@ def __init__(self, solid, tolerances, plane3Pts=False): toroidIndex.append(i) if len(toroidIndex) != 0: - tFaces = self.__same_torus_surf__(toroidIndex) + tFaces = self.same_torus_surf(toroidIndex) for i, tSet in enumerate(tFaces): - URange = self.__merge_periodic_uv__("U", tSet) - VRange = self.__merge_periodic_uv__("V", tSet) + URange = self.merge_periodic_uv("U", tSet) + VRange = self.merge_periodic_uv("V", tSet) for t in tSet: self.TorusVParams[t] = (i, VRange) self.TorusUParams[t] = (i, URange) - def __same_torus_surf__(self, torusList): + def same_torus_surf(self, torusList): """group as a single face all the neighbour faces of the same torus""" sameTorusFace = [] temp = torusList[:] @@ -145,9 +145,9 @@ def __same_torus_surf__(self, torusList): temp.remove(c) sameTorusFace.append(current) - return self.__separate_surfaces__(sameTorusFace) + return self.separate_surfaces(sameTorusFace) - def __separate_surfaces__(self, faceList): + def separate_surfaces(self, faceList): """group all faces in faceList forming a continuous surface""" sameSurfaces = [] for tset in faceList: @@ -171,7 +171,7 @@ def __separate_surfaces__(self, faceList): return sameSurfaces # TODO check if this function is used as it appears to be nut used in the code - def __merge_no_periodic_uv__(self, parameter, faceList): + def merge_no_periodic_uv(self, parameter, faceList): if parameter == "U": i1 = 0 i2 = 2 @@ -188,7 +188,7 @@ def __merge_no_periodic_uv__(self, parameter, faceList): return mergedParams - def __merge_periodic_uv__(self, parameter, faceList): + def merge_periodic_uv(self, parameter, faceList): two_pi = 2.0 * math.pi if parameter == "U": i1 = 0 diff --git a/src/geouned/GEOUNED/void/void_box_class.py b/src/geouned/GEOUNED/void/void_box_class.py index a5564f59..b3d3ae9f 100644 --- a/src/geouned/GEOUNED/void/void_box_class.py +++ b/src/geouned/GEOUNED/void/void_box_class.py @@ -31,8 +31,8 @@ def __init__(self, MetaSolids, Enclosure): continue if m.BoundBox.isValid(): if self.BoundBox.intersect(m.BoundBox): - Obj = self.__copy_meta__(m) - self.__remove_extra_comp__(Obj, self.BoundBox) + Obj = self.copy_meta(m) + self.remove_extra_comp(Obj, self.BoundBox) self.Objects.append(Obj) return @@ -161,7 +161,7 @@ def refine(self): ) for m in self.Objects: - self.__remove_extra_comp__(m, Cube, mode="dist") + self.remove_extra_comp(m, Cube, mode="dist") return def get_void_complementary(self, Surfaces, options, tolerances, numeric_format, simplify="no"): @@ -450,7 +450,7 @@ def get_bound_planes(self): return (PXMin, PXMax, PYMin, PYMax, PZMin, PZMax) - def __remove_extra_comp__(self, Obj, Box, mode="box"): + def remove_extra_comp(self, Obj, Box, mode="box"): reducedSol = [] reducedDef = BoolSequence(operator="OR") if not Obj.Solids: @@ -476,7 +476,7 @@ def __remove_extra_comp__(self, Obj, Box, mode="box"): Obj.set_definition(reducedDef) return - def __copy_meta__(self, m): + def copy_meta(self, m): solidsCopy = m.Solids[:] facesCopy = m.Faces[:] Meta = GeounedSolid(m.__id__, solidsCopy) diff --git a/src/geouned/GEOUNED/write/mcnp_format.py b/src/geouned/GEOUNED/write/mcnp_format.py index 240026f0..5d8ef81c 100644 --- a/src/geouned/GEOUNED/write/mcnp_format.py +++ b/src/geouned/GEOUNED/write/mcnp_format.py @@ -52,10 +52,10 @@ def __init__( if isinstance(self.StepFile, (tuple, list)): self.StepFile = "; ".join(self.StepFile) - self.__get_surface_table__() - self.__simplify_planes__(Surfaces) + self.get_surface_table() + self.simplify_planes(Surfaces) - self.Surfaces = self.__sorted_surfaces__(Surfaces) + self.Surfaces = self.sorted_surfaces(Surfaces) self.Materials = set() return @@ -87,8 +87,8 @@ def write_input(self, filename): Path(filename).parent.mkdir(parents=True, exist_ok=True) logger.info(f"write MCNP file {filename}") self.inpfile = open(filename, "w", encoding="utf-8") - self.__write_header__() - self.__write_cell_block__() + self.write_header() + self.write_cell_block() self.inpfile.write(" \n") surfaceHeader = """\ @@ -97,15 +97,15 @@ def write_input(self, filename): C ########################################################## """ self.inpfile.write(surfaceHeader) - self.__write_surface_block__() + self.write_surface_block() self.inpfile.write(" \n") - self.__write_source_block__() + self.write_source_block() self.inpfile.close() return - def __write_header__(self): + def write_header(self): freeCAD_Version = "{V[0]:}.{V[1]:}.{V[2]:}".format(V=FreeCAD.Version()) @@ -133,25 +133,25 @@ def __write_header__(self): self.inpfile.write(Information) return - def __write_cell_block__(self): + def write_cell_block(self): for i, cell in enumerate(self.Cells): - self.__write_cells__(cell) + self.write_cells(cell) return - def __write_surface_block__(self): + def write_surface_block(self): for surf in self.Surfaces: - self.__write_surfaces__(surf) + self.write_surfaces(surf) - def __write_cells__(self, cell): + def write_cells(self, cell): index = cell.label # if index is None objet not contain cell definition # but a comment to insert between cells if cell.__id__ is None: - comment = self.__comment_line__(cell.Comments) + comment = self.comment_line(cell.Comments) self.inpfile.write(comment) return @@ -166,14 +166,14 @@ def __write_cells__(self, cell): mcnpcell = "{}{}\n{}{}".format( cellHeader, - self.__cell_format__(cell.Definition, offset=len(cellHeader)), - self.__option_format__(cell), - self.__comment_format__(cell.Comments, cell.MatInfo), + self.cell_format(cell.Definition, offset=len(cellHeader)), + self.option_format(cell), + self.comment_format(cell.Comments, cell.MatInfo), ) self.inpfile.write(mcnpcell) return - def __write_surfaces__(self, surface): + def write_surfaces(self, surface): """Write the surfaces in MCNP format""" MCNP_def = mcnp_surface( @@ -191,7 +191,7 @@ def __write_surfaces__(self, surface): logger.info(f"Surface {surface.Type} cannot be written in MCNP input") return - def __write_source_block__(self): + def write_source_block(self): if self.SDEF_sphere is None: return @@ -214,7 +214,7 @@ def __write_source_block__(self): for line in self.SDEF_sphere: Block += line - celList, volList = self.__get_solid_cell_volume__() + celList, volList = self.get_solid_cell_volume() F4Tally = CardLine(f"F4:{self.part} ") F4Tally.extend(celList) @@ -234,10 +234,10 @@ def __write_source_block__(self): self.inpfile.write(Block) - def __cell_format__(self, Definition, offset=11): + def cell_format(self, Definition, offset=11): return write_mcnp_cell_def(Definition, tabspace=11, offset=offset) - def __option_format__(self, cell): + def option_format(self, cell): option = "" if self.Options["Volume"]: @@ -259,7 +259,7 @@ def __option_format__(self, cell): return option - def __comment_format__(self, cComment, mComment=None): + def comment_format(self, cComment, mComment=None): comment = "" if mComment: @@ -275,7 +275,7 @@ def __comment_format__(self, cComment, mComment=None): comment += f"{'':11s}${c}\n" return comment - def __comment_line__(self, lineComment): + def comment_line(self, lineComment): lineComment = lineComment.strip().split("\n") comment = "" if lineComment: @@ -286,7 +286,7 @@ def __comment_line__(self, lineComment): comment += "C \n" return comment - def __get_surface_table__(self): + def get_surface_table(self): self.surfaceTable = {} self.__solidCells__ = 0 self.__cells__ = 0 @@ -309,33 +309,33 @@ def __get_surface_table__(self): self.surfaceTable[index] = {i} return - def __simplify_planes__(self, Surfaces): + def simplify_planes(self, Surfaces): for p in Surfaces["PX"]: if p.Surf.Axis[0] < 0: p.Surf.Axis = FreeCAD.Vector(1, 0, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PY"]: if p.Surf.Axis[1] < 0: p.Surf.Axis = FreeCAD.Vector(0, 1, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PZ"]: if p.Surf.Axis[2] < 0: p.Surf.Axis = FreeCAD.Vector(0, 0, 1) - self.__change_surf_sign__(p) + self.change_surf_sign(p) if self.options.prnt3PPlane: for p in Surfaces["P"]: if p.Surf.pointDef: axis, d = points_to_coeffs(p.Surf.Points) if is_opposite(axis, p.Surf.Axis): - self.__change_surf_sign__(p) + self.change_surf_sign(p) return - def __sorted_surfaces__(self, Surfaces): + def sorted_surfaces(self, Surfaces): temp = SurfacesDict(Surfaces) surfList = [] for ind in range(Surfaces.IndexOffset, Surfaces.surfaceNumber + Surfaces.IndexOffset): @@ -345,7 +345,7 @@ def __sorted_surfaces__(self, Surfaces): temp.del_surface(ind + 1) return surfList - def __change_surf_sign__(self, p): + def change_surf_sign(self, p): if p.Index not in self.surfaceTable.keys(): logger.info(f"{p.Type} Surface {p.Index} not used in cell definition) {p.Surf.Axis} {p.Surf.Position}") @@ -357,7 +357,7 @@ def __change_surf_sign__(self, p): if s == p.Index: change_surf_sign(s, self.Cells[ic].Definition) - def __get_solid_cell_volume__(self): + def get_solid_cell_volume(self): solidList = [] volumeList = [] diff --git a/src/geouned/GEOUNED/write/openmc_format.py b/src/geouned/GEOUNED/write/openmc_format.py index af19d458..45a3eadf 100644 --- a/src/geouned/GEOUNED/write/openmc_format.py +++ b/src/geouned/GEOUNED/write/openmc_format.py @@ -22,42 +22,42 @@ def __init__(self, Meta, Surfaces, options, tolerances, numeric_format): self.tolerances = tolerances self.numeric_format = numeric_format - self.__get_surface_table__() - self.__simplify_planes__(Surfaces) + self.get_surface_table() + self.simplify_planes(Surfaces) - self.Surfaces = self.__sorted_surfaces__(Surfaces) + self.Surfaces = self.sorted_surfaces(Surfaces) self.Materials = set() def write_xml(self, filename): logger.info(f"write OpenMC xml file {filename}") Path(filename).parent.mkdir(parents=True, exist_ok=True) with open(file=filename, mode="w", encoding="utf-8") as self.inpfile: - self.__write_xml_header__() + self.write_xml_header() self.inpfile.write("\n") - self.__write_xml_cell_block__() + self.write_xml_cell_block() self.inpfile.write(" \n") - self.__write_xml_surface_block__() + self.write_xml_surface_block() self.inpfile.write("\n") return - def __write_xml_header__(self): + def write_xml_header(self): Header = "\n" self.inpfile.write(Header) return - def __write_xml_cell_block__(self): + def write_xml_cell_block(self): for _, cell in enumerate(self.Cells): if cell.MatInfo == "Graveyard": continue - self.__write_xml_cells__(cell) + self.write_xml_cells(cell) return - def __write_xml_surface_block__(self): + def write_xml_surface_block(self): for surf in self.Surfaces[:-1]: - self.__write_xml_surfaces__(surf) - self.__write_xml_surfaces__(self.Surfaces[-1], boundary=True) + self.write_xml_surfaces(surf) + self.write_xml_surfaces(self.Surfaces[-1], boundary=True) - def __write_xml_cells__(self, cell): + def write_xml_cells(self, cell): """Write the cell in xml OpenMC format""" index = cell.label cellName = ". ".join(cell.Comments.splitlines()) @@ -78,7 +78,7 @@ def __write_xml_cells__(self, cell): self.inpfile.write(OMCcell) return - def __write_xml_surfaces__(self, surface, boundary=False): + def write_xml_surfaces(self, surface, boundary=False): """Write the surfaces in xml OpenMC format""" surfType, coeffs = open_mc_surface(surface.Type, surface.Surf, self.tolerances, self.numeric_format) @@ -101,22 +101,22 @@ def write_py(self, filename): Path(filename).parent.mkdir(parents=True, exist_ok=True) with open(file=filename, mode="w", encoding="utf-8") as self.inpfile: - self.__write_py_header__() + self.write_py_header() if len(self.Materials) > 0: self.inpfile.write("# Materials setup\n") - self.__write_py_materials__() + self.write_py_materials() self.inpfile.write("\n") self.inpfile.write("# Surface setup\n") - self.__write_py_surface_block__() + self.write_py_surface_block() self.inpfile.write("\n") self.inpfile.write("# Cell definition \n") - self.__write_py_cell_block__() + self.write_py_cell_block() return - def __write_py_header__(self): + def write_py_header(self): Header = """\ # openMC geometry script generated by GEOUNED @@ -130,7 +130,7 @@ def __write_py_header__(self): self.inpfile.write(Header) return - def __write_py_materials__(self): + def write_py_materials(self): matList = tuple(sorted(self.Materials)) strMat = [] for m in matList: @@ -142,13 +142,13 @@ def __write_py_materials__(self): self.inpfile.write(collect) self.inpfile.write("materials.export_to_xml()\n") - def __write_py_surface_block__(self): + def write_py_surface_block(self): for surf in self.Surfaces[:-1]: - self.__write_py_surfaces__(surf) - self.__write_py_surfaces__(self.Surfaces[-1], boundary=True) + self.write_py_surfaces(surf) + self.write_py_surfaces(self.Surfaces[-1], boundary=True) - def __write_py_surfaces__(self, surface, boundary=False): + def write_py_surfaces(self, surface, boundary=False): """Write the surfaces in python OpenMC format""" surfType, coeffs = open_mc_surface( @@ -168,13 +168,13 @@ def __write_py_surfaces__(self, surface, boundary=False): self.inpfile.write(OMCsurf) return - def __write_py_cell_block__(self): + def write_py_cell_block(self): cellNames = [] for i, cell in enumerate(self.Cells): if cell.MatInfo == "Graveyard": continue - self.__write_py_cells__(cell) + self.write_py_cells(cell) if cell.__id__ is None: continue cellNames.append(f"C{cell.label}") @@ -184,7 +184,7 @@ def __write_py_cell_block__(self): self.inpfile.write(geometry) return - def __write_py_cells__(self, cell): + def write_py_cells(self, cell): """Write the cell in python OpenMC format""" index = cell.label cellName = ". ".join(cell.Comments.splitlines()) @@ -208,7 +208,7 @@ def __write_py_cells__(self, cell): self.inpfile.write(OMCcell) return - def __get_surface_table__(self): + def get_surface_table(self): self.surfaceTable = {} self.__solidCells__ = 0 self.__cells__ = 0 @@ -231,25 +231,25 @@ def __get_surface_table__(self): self.surfaceTable[index] = {i} return - def __simplify_planes__(self, Surfaces): + def simplify_planes(self, Surfaces): for p in Surfaces["PX"]: if p.Surf.Axis[0] < 0: p.Surf.Axis = FreeCAD.Vector(1, 0, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PY"]: if p.Surf.Axis[1] < 0: p.Surf.Axis = FreeCAD.Vector(0, 1, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PZ"]: if p.Surf.Axis[2] < 0: p.Surf.Axis = FreeCAD.Vector(0, 0, 1) - self.__change_surf_sign__(p) + self.change_surf_sign(p) return - def __sorted_surfaces__(self, Surfaces): + def sorted_surfaces(self, Surfaces): temp = SurfacesDict(Surfaces) surfList = [] for ind in range(Surfaces.IndexOffset, Surfaces.surfaceNumber + Surfaces.IndexOffset): @@ -259,7 +259,7 @@ def __sorted_surfaces__(self, Surfaces): temp.del_surface(ind + 1) return surfList - def __change_surf_sign__(self, p): + def change_surf_sign(self, p): if p.Index not in self.surfaceTable.keys(): logger.info(f"{p.Type} Surface {p.Index} not used in cell definition {p.Surf.Axis} {p.Surf.Position}") diff --git a/src/geouned/GEOUNED/write/phits_format.py b/src/geouned/GEOUNED/write/phits_format.py index 98352137..08a25ee9 100644 --- a/src/geouned/GEOUNED/write/phits_format.py +++ b/src/geouned/GEOUNED/write/phits_format.py @@ -70,10 +70,10 @@ def __init__( if self.Title == "": self.Title = self.StepFile - self.__get_surface_table__() - self.__simplify_planes__(Surfaces) + self.get_surface_table() + self.simplify_planes(Surfaces) - self.Surfaces = self.__sorted_surfaces__(Surfaces) + self.Surfaces = self.sorted_surfaces(Surfaces) self.Materials = set() return @@ -82,7 +82,7 @@ def write_phits(self, filename): logger.info(f"write PHITS file {filename}") Path(filename).parent.mkdir(parents=True, exist_ok=True) with open(file=filename, mode="w", encoding="utf-8") as self.inpfile: - self.__write_phits_header__() + self.write_phits_header() cHeader = """\ $ @@ -93,7 +93,7 @@ def write_phits(self, filename): [CELL]\n""" self.inpfile.write(cHeader) - self.__write_phits_cell_block__() + self.write_phits_cell_block() self.inpfile.write(" \n") surfaceHeader = """\ @@ -105,7 +105,7 @@ def write_phits(self, filename): [SURFACE]\n""" self.inpfile.write(surfaceHeader) - self.__write_phits_surface_block__() + self.write_phits_surface_block() self.inpfile.write(" \n") materialHeader = """\ @@ -120,7 +120,7 @@ def write_phits(self, filename): if self.DummyMat: self.inpfile.write(materialHeader) - self.__write_phits_source_block__() + self.write_phits_source_block() self.inpfile.write(" \n") volHeader = """\ @@ -136,12 +136,12 @@ def write_phits(self, filename): if self.Options["Volume"]: self.inpfile.write(volHeader) - self.__write_phits_volume_block__() + self.write_phits_volume_block() self.inpfile.write(" \n") return - def __write_phits_header__(self): + def write_phits_header(self): freeCAD_Version = "{V[0]:}.{V[1]:}.{V[2]:}".format(V=FreeCAD.Version()) @@ -177,22 +177,22 @@ def __write_phits_header__(self): self.inpfile.write(Information) return - def __write_phits_cell_block__(self): + def write_phits_cell_block(self): enclenvChk = [] - enclenvChk = self.__stepfile_label_chk__(self.StepFile) + enclenvChk = self.stepfile_label_chk(self.StepFile) if enclenvChk: logger.info("Unified the inner void cell(s) definition") for i, cell in enumerate(self.Cells): - self.__write_phits_cells_uni_void_def__(cell) + self.write_phits_cells_uni_void_def(cell) return else: for i, cell in enumerate(self.Cells): - self.__write_phits_cells__(cell) + self.write_phits_cells(cell) return - def __stepfile_label_chk__(self, filename): + def stepfile_label_chk(self, filename): enclenvList = [] with open(filename) as f: @@ -203,19 +203,19 @@ def __stepfile_label_chk__(self, filename): cond2 = envelLabel == None return cond1 and cond2 - def __write_phits_surface_block__(self): + def write_phits_surface_block(self): for surf in self.Surfaces: - self.__write_phits_surfaces__(surf) + self.write_phits_surfaces(surf) - def __write_phits_cells__(self, cell): + def write_phits_cells(self, cell): index = cell.label # if index is None objet not contain cell definition # but a comment to insert between cells if cell.__id__ is None: - comment = self.__comment_line__(cell.Comments) + comment = self.comment_line(cell.Comments) self.inpfile.write(comment) return @@ -250,21 +250,21 @@ def __write_phits_cells__(self, cell): phitscell = "{}{}\n{}{}".format( cellHeader, - self.__cell_format__(cell.Definition, offset=len(cellHeader)), - self.__option_format__(cell), - self.__comment_format__(cell.Comments, cell.MatInfo), + self.cell_format(cell.Definition, offset=len(cellHeader)), + self.option_format(cell), + self.comment_format(cell.Comments, cell.MatInfo), ) self.inpfile.write(phitscell) return - def __write_phits_cells_uni_void_def__(self, cell): + def write_phits_cells_uni_void_def(self, cell): index = cell.label # if index is None objet not contain cell definition # but a comment to insert between cells if cell.__id__ is None: - comment = self.__comment_line__(cell.Comments) + comment = self.comment_line(cell.Comments) self.inpfile.write(comment) return """ @@ -275,7 +275,7 @@ def __write_phits_cells_uni_void_def__(self, cell): # To exclude solid cell(s) from the inner void's defenition, # a string of '#(Solid Cell No.)', or inclsolidCells, # is appended to the new inner void cell definition - # after self.__cell_format__(cell.Definition) process. + # after self.cell_format(cell.Definition) process. """ if cell.Void: @@ -313,9 +313,9 @@ def __write_phits_cells_uni_void_def__(self, cell): phitscell = "{}{}\n{}{}\n".format( cellHeader, - self.__new_inner_void_def__(inclSolidCells, cell.Definition, offset=len(cellHeader)), - self.__option_format__(cell), - self.__comment_format__(cell.Comments, cell.MatInfo), + self.inner_void_def(inclSolidCells, cell.Definition, offset=len(cellHeader)), + self.option_format(cell), + self.comment_format(cell.Comments, cell.MatInfo), ) self.inpfile.write(phitscell) return @@ -331,7 +331,7 @@ def __write_phits_cells_uni_void_def__(self, cell): # To check auto-generated voids, apply this commented out section instead # and comment out above from "if cell.Void:..." to "... else: return" # In addition, if you set volCARD = True and want for all void regions to come apperes in [VOLUME], - # comment out some part in the def __write_phits_volume_block__() section also. + # comment out some part in the def write_phits_volume_block() section also. if cell.Material == 0: logger.info(cell.IsEnclosure) if cell.MatInfo == 'Graveyard': @@ -352,14 +352,14 @@ def __write_phits_cells_uni_void_def__(self, cell): phitscell = "{}{}\n{}{}".format( cellHeader, - self.__cell_format__(cell.Definition, offset=len(cellHeader)), - self.__option_format__(cell), - self.__comment_format__(cell.Comments, cell.MatInfo), + self.cell_format(cell.Definition, offset=len(cellHeader)), + self.option_format(cell), + self.comment_format(cell.Comments, cell.MatInfo), ) self.inpfile.write(phitscell) return - def __write_phits_surfaces__(self, surface): + def write_phits_surfaces(self, surface): """Write the surfaces in PHITS format""" PHITS_def = phits_surface( @@ -377,7 +377,7 @@ def __write_phits_surfaces__(self, surface): logger.info(f"Surface {surface.Type} cannot be written in PHITS input") return - def __write_phits_source_block__(self): + def write_phits_source_block(self): if self.DummyMat: mat = list(self.Materials) @@ -402,7 +402,7 @@ def __write_phits_source_block__(self): self.inpfile.write(Block) - def __write_phits_volume_block__(self): + def write_phits_volume_block(self): vol = f"{'':5s}reg{'':5s}vol\n" @@ -410,7 +410,7 @@ def __write_phits_volume_block__(self): eliminated_endVoidIndex = self.__cells__ + self.startCell - 3 enclenvChk = [] - enclenvChk = self.__stepfile_label_chk__(self.StepFile) + enclenvChk = self.stepfile_label_chk(self.StepFile) if enclenvChk and self.Options["Volume"]: for i, cell in enumerate(self.Cells): @@ -453,17 +453,17 @@ def __write_phits_volume_block__(self): self.inpfile.write(vol) """ - def __cell_format__(self, Definition, offset=11): + def cell_format(self, Definition, offset=11): return write_phits_cell_def(Definition, tabspace=11, offset=offset) - def __new_inner_void_def__(self, innerSolidCells, Definition, offset=11): - newInnerVoidDef = self.__cell_format__(Definition, offset) + def inner_void_def(self, innerSolidCells, Definition, offset=11): + newInnerVoidDef = self.cell_format(Definition, offset) strdef = CellString(tabspace=11) strdef.add(newInnerVoidDef + innerSolidCells) strdef.wrap_line(offset) return strdef.str - def __option_format__(self, cell): + def option_format(self, cell): option = "" if self.Options["Volume"]: @@ -477,7 +477,7 @@ def __option_format__(self, cell): return option - def __comment_format__(self, cComment, mComment=None): + def comment_format(self, cComment, mComment=None): comment = "" if mComment: @@ -493,7 +493,7 @@ def __comment_format__(self, cComment, mComment=None): comment += f"{'':11s}${c}\n" return comment - def __comment_line__(self, lineComment): + def comment_line(self, lineComment): lineComment = lineComment.strip().split("\n") comment = "" if lineComment: @@ -504,7 +504,7 @@ def __comment_line__(self, lineComment): comment += "$ \n" return comment - def __get_surface_table__(self): + def get_surface_table(self): self.surfaceTable = {} self.__solidCells__ = 0 self.__cells__ = 0 @@ -527,32 +527,32 @@ def __get_surface_table__(self): self.surfaceTable[index] = {i} return - def __simplify_planes__(self, Surfaces): + def simplify_planes(self, Surfaces): for p in Surfaces["PX"]: if p.Surf.Axis[0] < 0: p.Surf.Axis = FreeCAD.Vector(1, 0, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PY"]: if p.Surf.Axis[1] < 0: p.Surf.Axis = FreeCAD.Vector(0, 1, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PZ"]: if p.Surf.Axis[2] < 0: p.Surf.Axis = FreeCAD.Vector(0, 0, 1) - self.__change_surf_sign__(p) + self.change_surf_sign(p) if self.options.prnt3PPlane: for p in Surfaces["P"]: if p.Surf.pointDef: axis, d = points_to_coeffs(p.Surf.Points) if is_opposite(axis, p.Surf.Axis): - self.__change_surf_sign__(p) + self.change_surf_sign(p) return - def __sorted_surfaces__(self, Surfaces): + def sorted_surfaces(self, Surfaces): temp = SurfacesDict(Surfaces) surfList = [] for ind in range(Surfaces.IndexOffset, Surfaces.surfaceNumber + Surfaces.IndexOffset): @@ -562,7 +562,7 @@ def __sorted_surfaces__(self, Surfaces): temp.del_surface(ind + 1) return surfList - def __change_surf_sign__(self, p): + def change_surf_sign(self, p): if p.Index not in self.surfaceTable.keys(): logger.info(f"{p.Type} Surface {p.Index} not used in cell definition) {p.Surf.Axis} {p.Surf.Position}") @@ -574,7 +574,7 @@ def __change_surf_sign__(self, p): if s == p.Index: change_surf_sign(s, self.Cells[ic].Definition) - def __get_solid_cell_volume__(self): + def get_solid_cell_volume(self): solidList = [] volumeList = [] diff --git a/src/geouned/GEOUNED/write/serpent_format.py b/src/geouned/GEOUNED/write/serpent_format.py index bb5b1eb2..f58f5741 100644 --- a/src/geouned/GEOUNED/write/serpent_format.py +++ b/src/geouned/GEOUNED/write/serpent_format.py @@ -50,10 +50,10 @@ def __init__( if isinstance(self.StepFile, (tuple, list)): self.StepFile = "; ".join(self.StepFile) - self.__get_surface_table__() - self.__simplify_planes__(Surfaces) + self.get_surface_table() + self.simplify_planes(Surfaces) - self.Surfaces = self.__sorted_surfaces__(Surfaces) + self.Surfaces = self.sorted_surfaces(Surfaces) self.Materials = set() return @@ -80,26 +80,26 @@ def write_input(self, filename): logger.info(f"write Serpent file {filename}") Path(filename).parent.mkdir(parents=True, exist_ok=True) with open(file=filename, mode="w", encoding="utf-8") as self.inpfile: - self.__write_header__() + self.write_header() cellblockHeader = """\ % --- CELL DEFINITIONS """ self.inpfile.write(cellblockHeader) - self.__write_cell_block__() + self.write_cell_block() self.inpfile.write(" \n") surfaceHeader = """\ % --- SURFACE DEFINITIONS """ self.inpfile.write(surfaceHeader) - self.__write_surface_block__() + self.write_surface_block() self.inpfile.write(" \n") - self.__write_source_block__() + self.write_source_block() return - def __write_header__(self): + def write_header(self): freeCAD_Version = "{V[0]:}.{V[1]:}.{V[2]:}".format(V=FreeCAD.Version()) @@ -127,19 +127,19 @@ def __write_header__(self): self.inpfile.write(Information) return - def __write_surface_block__(self): + def write_surface_block(self): for surf in self.Surfaces: - self.__write_surfaces__(surf) + self.write_surfaces(surf) - def __write_cell_block__(self): + def write_cell_block(self): for i, cell in enumerate(self.Cells): - self.__write_cells__(cell) + self.write_cells(cell) return # to_mod - def __write_cells__(self, cell): + def write_cells(self, cell): index = cell.label # If index is None, the object does not contain cell definition @@ -161,7 +161,7 @@ def __write_cells__(self, cell): cellHeader = f'cell {index:<5d} {self.Options["Universe"]} {cell.Material:<5d} ' serpent_cell = ( - f"{cellHeader}{self.__cell_format__(cell.Definition, offset=len(cellHeader))}" + f"{cellHeader}{self.cell_format(cell.Definition, offset=len(cellHeader))}" f"{self.comment_format(cell.Comments, cell.MatInfo)}" ) self.inpfile.write(serpent_cell) @@ -175,14 +175,14 @@ def __write_cells__(self, cell): cellHeader = f"cell {index:<5d} 0 {cell.Material:<5d} " serpent_cell = ( - f"{cellHeader}{self.__cell_format__(cell.Definition, offset=len(cellHeader))}" + f"{cellHeader}{self.cell_format(cell.Definition, offset=len(cellHeader))}" f"{self.comment_format(cell.Comments, cell.MatInfo)}" ) self.inpfile.write(serpent_cell) return - def __write_surfaces__(self, surface): + def write_surfaces(self, surface): """Write the surfaces in Serpent format""" Serpent_def = serpent_surface( @@ -202,7 +202,7 @@ def __write_surfaces__(self, surface): # No void all option in Serpent. For now remove addition of source. - def __write_source_block__(self): + def write_source_block(self): # if self.SDEF_sphere is None: return MODE = f"\nset nps 1e6\nset bc 1" @@ -224,7 +224,7 @@ def __write_source_block__(self): # for line in self.SDEF_sphere: # Block += line - # celList,volList = self.__get_solid_cell_volume__() + # celList,volList = self.get_solid_cell_volume() # F4Tally = CardLine('F4:{} '.format(self.part)) # F4Tally.extend(celList) @@ -244,12 +244,12 @@ def __write_source_block__(self): self.inpfile.write(Block) - def __cell_format__(self, Definition, offset=11): + def cell_format(self, Definition, offset=11): return write_serpent_cell_def(Definition, tabspace=11, offset=offset) # Function not relevant for Serpent : No importance setting, universes assigned elsewhere. # Volumes only defined on tally cards. - # def __option_format__(self,cell): + # def option_format(self,cell): # option = '' # if self.Options['Volume']: @@ -297,7 +297,7 @@ def comment_line(self, lineComment): comment += "% \n" return comment - def __get_surface_table__(self): + def get_surface_table(self): self.surfaceTable = {} self.__solidCells__ = 0 self.__cells__ = 0 @@ -320,33 +320,33 @@ def __get_surface_table__(self): self.surfaceTable[index] = {i} return - def __simplify_planes__(self, Surfaces): + def simplify_planes(self, Surfaces): for p in Surfaces["PX"]: if p.Surf.Axis[0] < 0: p.Surf.Axis = FreeCAD.Vector(1, 0, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PY"]: if p.Surf.Axis[1] < 0: p.Surf.Axis = FreeCAD.Vector(0, 1, 0) - self.__change_surf_sign__(p) + self.change_surf_sign(p) for p in Surfaces["PZ"]: if p.Surf.Axis[2] < 0: p.Surf.Axis = FreeCAD.Vector(0, 0, 1) - self.__change_surf_sign__(p) + self.change_surf_sign(p) if self.options.prnt3PPlane: for p in Surfaces["P"]: if p.Surf.pointDef: axis, d = points_to_coeffs(p.Surf.Points) if is_opposite(axis, p.Surf.Axis): - self.__change_surf_sign__(p) + self.change_surf_sign(p) return - def __sorted_surfaces__(self, Surfaces): + def sorted_surfaces(self, Surfaces): temp = SurfacesDict(Surfaces) surfList = [] for ind in range(Surfaces.IndexOffset, Surfaces.surfaceNumber + Surfaces.IndexOffset): @@ -356,7 +356,7 @@ def __sorted_surfaces__(self, Surfaces): temp.del_surface(ind + 1) return surfList - def __change_surf_sign__(self, p): + def change_surf_sign(self, p): if p.Index not in self.surfaceTable.keys(): logger.info(f"{p.Type} Surface {p.Index} not used in cell definition) {p.Surf.Axis} {p.Surf.Position}") @@ -368,7 +368,7 @@ def __change_surf_sign__(self, p): if s == p.Index: change_surf_sign(s, self.Cells[ic].Definition) - def __get_solid_cell_volume__(self): + def get_solid_cell_volume(self): solidList = [] volumeList = []