Skip to content

Commit

Permalink
passing specific args
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed May 2, 2024
1 parent 1970ce7 commit 974144a
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/geouned/GEOUNED/Cuboid/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
65 changes: 49 additions & 16 deletions src/geouned/GEOUNED/Void/Void.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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

Expand Down
16 changes: 9 additions & 7 deletions src/geouned/GEOUNED/Write/MCNPFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
33 changes: 23 additions & 10 deletions src/geouned/GEOUNED/Write/PHITSFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 9 additions & 7 deletions src/geouned/GEOUNED/Write/SerpentFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
85 changes: 57 additions & 28 deletions src/geouned/GEOUNED/Write/WriteFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -86,14 +103,26 @@ 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,
)
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)
Loading

0 comments on commit 974144a

Please sign in to comment.