Skip to content

Commit

Permalink
Merge branch 'dev' into testing_more_mc_codes
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Apr 30, 2024
2 parents da4394e + cf94454 commit fed99be
Show file tree
Hide file tree
Showing 28 changed files with 261 additions and 340 deletions.
2 changes: 1 addition & 1 deletion src/geouned/GEOReverse/Modules/MCNPinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ def get_hyperboloid_parameters(eVal, eVect, T, k, iaxis):
else:
if ellipsoid:
print("ellipical hyperboloid not implemented")
print("single radius from {} eigen Value will be used".format(minorRad))
print(f"single radius from {minorRad} eigen Value will be used")
return "hyperboloid", (
pos,
axis,
Expand Down
2 changes: 1 addition & 1 deletion src/geouned/GEOReverse/Modules/Objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self, Id, params, tr=None):
self.transform(tr)

def __str__(self):
return "plane : {}\nParameters : {}".format(self.id, self.params)
return f"plane : {self.id}\nParameters : {self.params}"

def copy(self):
return Plane(self.id, self.params)
Expand Down
16 changes: 7 additions & 9 deletions src/geouned/GEOReverse/Modules/Parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

# If type specifier not given, any data type can be formatted:
def fmt_gen(s):
return "{" + ":<{}".format(len(s)) + "}"
return "{" + f":<{len(s)}" + "}"


fmt_d = fmt_gen
Expand Down Expand Up @@ -204,9 +204,7 @@ def print_debug(self, comment, key="tihv"):
d = self.debug
if d:
print(
"Line {}, {} card. {}".format(
self.pos, CID.get_name(self.ctype), comment
),
f"Line {self.pos}, {CID.get_name(self.ctype)} card. {comment}",
file=d,
)
if "t" in key:
Expand Down Expand Up @@ -670,7 +668,7 @@ def card(self, wrap=False, comment=True):
# there is no proper place to wrap.
self.print_debug("Cannot wrap line " + repr(i), "")
warnings.warn(
"Cannot wrap card" " on line {}".format(self.pos)
f"Cannot wrap card on line {self.pos}"
)
break
else:
Expand Down Expand Up @@ -1226,7 +1224,7 @@ def get_cards(inp, debug=None, preservetabs=False):
from os import stat

iname = inp
dname = ".{}.~".format(os.path.basename(inp))
dname = f".{os.path.basename(inp)}.~"
try:
it = stat(iname).st_mtime
except OSError as e:
Expand Down Expand Up @@ -1272,7 +1270,7 @@ def index_(line, chars="$&"):
"""
Find the first index of one of the chars in line.
"""
r = re.compile("[{}]".format(chars))
r = re.compile(f"[{chars}]")
m = r.search(line)
if m:
i = m.end() - 1
Expand Down Expand Up @@ -1303,7 +1301,7 @@ def replace_tab(l, cln, preserve=False, ts=8):
while "\t" in l:
i = l.index("\t")
ii = (i // ts + 1) * ts - i
print("c Line {}: tab replaced with {} spaces".format(cln + 1, ii))
print(f"c Line {cln + 1}: tab replaced with {ii} spaces")
l = l[:i] + " " * ii + l[i + 1 :]
return l[:]

Expand Down Expand Up @@ -1505,7 +1503,7 @@ def are_close_lists(x, y, re=1e-6, pci=[]):
for xx, yy in zip(xl, yl):
r = are_close_vals(xx, yy, re)
if not r:
m = "diff at {}".format(n)
m = f"diff at {n}"
break
else:
m = "all elements are close or equal"
Expand Down
16 changes: 8 additions & 8 deletions src/geouned/GEOReverse/Modules/Utils/BooleanSolids.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,25 @@ def __str__(self):
line = ""
for name in varName:
element = self[name][name]
line += " {:4d} : {}\n".format(name, element.val)
line += f" {name:4d} : {element.val}\n"
return line

outstr = " "
for name in varName:
outstr = outstr + " {:3d}".format(name)
outstr = outstr + f" {name:3d}"
outstr = outstr + "\n"

for name1 in varName:
line = " {:3d} ".format(name1)
linenot = "~{:3d} ".format(name1)
line = f" {name1:3d} "
linenot = f"~{name1:3d} "
for name2 in varName:
elmt = self[name1][name2]
if elmt.diagonal:
line += " {:>2d} ".format(elmt.val)
line += f" {elmt.val:>2d} "
linenot += " "
else:
line += " {}{} ".format(elmt.val[0], elmt.val[1])
linenot += " {}{} ".format(elmt.val[3], elmt.val[2])
line += f" {elmt.val[0]}{elmt.val[1]} "
linenot += f" {elmt.val[3]}{elmt.val[2]} "
outstr += line + "\n"
outstr += linenot + "\n"
return outstr
Expand Down Expand Up @@ -457,7 +457,7 @@ def point_inside(solid):
n = n + 1

if n == cut_box:
print("Solid not found in bounding Box (Volume : {})".format(solid.Volume))
print(f"Solid not found in bounding Box (Volume : {solid.Volume})")
return None


Expand Down
4 changes: 2 additions & 2 deletions src/geouned/GEOReverse/Modules/Utils/booleanFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def __init__(self, definition=None, operator=None):
self.level = 0

def __str__(self):
out = "{}[".format(self.operator)
out = f"{self.operator}["
if type(self.elements) is bool:
return " True " if self.elements else " False "
for e in self.elements:
if type(e) is int or type(e) is bool or type(e) is str:
out += " {} ".format(e)
out += f" {e} "
else:
out += e.__str__()

Expand Down
14 changes: 6 additions & 8 deletions src/geouned/GEOReverse/Modules/buildCAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def BuildUniverse(
Universe = AllUniverses[Ustart]

print(
"Build Universe {} in container cell {}".format(
ContainerCell.FILL, ContainerCell.name
)
f"Build Universe {ContainerCell.FILL} in container cell {ContainerCell.name}"
)
fails = []
for NTcell in Universe.values():
Expand All @@ -136,7 +134,7 @@ def BuildUniverse(
NTcell = NTcell.copy()

if buildShape:
print("Level :{} build Cell {} ".format(CC.level + 1, NTcell.name))
print(f"Level :{CC.level + 1} build Cell {NTcell.name} ")
if type(NTcell.definition) is not BoolSequence:
NTcell.definition = BoolSequence(NTcell.definition.str)

Expand Down Expand Up @@ -187,15 +185,15 @@ def makeTree(CADdoc, CADCells):
label, universeCADCells = CADCells
groupObj = CADdoc.addObject("App::Part", "Materials")

groupObj.Label = "Universe_{}_Container_{}".format(label[1], label[0])
groupObj.Label = f"Universe_{label[1]}_Container_{label[0]}"

CADObj = {}
for i, c in enumerate(universeCADCells):
if type(c) is tuple:
groupObj.addObject(makeTree(CADdoc, c))
else:
featObj = CADdoc.addObject("Part::FeaturePython", "solid{}".format(i))
featObj.Label = "Cell_{}_{}".format(c.name, c.MAT)
featObj = CADdoc.addObject("Part::FeaturePython", f"solid{i}")
featObj.Label = f"Cell_{c.name}_{c.MAT}"
featObj.Shape = c.shape
if c.MAT not in CADObj.keys():
CADObj[c.MAT] = [featObj]
Expand All @@ -204,7 +202,7 @@ def makeTree(CADdoc, CADCells):

for mat, matGroup in CADObj.items():
groupMatObj = CADdoc.addObject("App::Part", "Materials")
groupMatObj.Label = "Material_{}".format(mat)
groupMatObj.Label = f"Material_{mat}"
groupMatObj.addObjects(matGroup)
groupObj.addObject(groupMatObj)

Expand Down
10 changes: 5 additions & 5 deletions src/geouned/GEOReverse/Modules/processInp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def getSetting(config):
elif key == "inFormat":
inFormat = config.get("Setting", key)
else:
print("{} bad keyword. Ignored".format(key))
print(f"{key} bad keyword. Ignored")

return fileIn, fileOut, outBox, inFormat

Expand All @@ -108,7 +108,7 @@ def getLevel(config):
elif key == "UStart":
UStart = config.getint("Levels", key)
else:
print("{} bad keyword. Ignored".format(key))
print(f"{key} bad keyword. Ignored")

return UStart, levMax

Expand All @@ -122,7 +122,7 @@ def getRange(section, config):
elif key == "range":
rawRange = config.get(section, key)
else:
print("{} bad keyword. Ignored".format(key))
print(f"{key} bad keyword. Ignored")

if rType is None:
return None
Expand All @@ -132,7 +132,7 @@ def getRange(section, config):
elif rType.lower() == "exclude" or rType.lower() == "include":
ctRange = getRangeData(rawRange)
if ctRange is None:
print("bad range in section {}".format(section))
print(f"bad range in section {section}")
return None
else:
return (rType.lower(), ctRange)
Expand Down Expand Up @@ -198,7 +198,7 @@ def setSecOptions(config):
tolerance = config.getfloat("Options", key)
setattr(Options, key, tolerance)
else:
print("{} bad keyword. Ignored".format(key))
print(f"{key} bad keyword. Ignored")

return

Expand Down
2 changes: 1 addition & 1 deletion src/geouned/GEOReverse/Modules/remh.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def replace(self, surf, new, pos=0):
self.str = self.str[0 : m.start()] + s2 + self.str[m.end() :]
return m.start() + len(s2)
else:
print("number {} not found".format(surf))
print(f"number {surf} not found")
return -1

def countP(self):
Expand Down
4 changes: 2 additions & 2 deletions src/geouned/GEOReverse/Modules/splitFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def point_inside(solid):
n = n + 1

if n == cut_box:
print("Solid not found in bounding Box (Volume : {})".format(solid.Volume))
print(f"Solid not found in bounding Box (Volume : {solid.Volume})")
print("Valid Solid : ", solid.isValid())
return None

Expand Down Expand Up @@ -371,7 +371,7 @@ def surface_side(p, surf):
break

else:
print("surface type {} not considered".format(surf[0]))
print(f"surface type {surf[0]} not considered")
return

return inout > 0
Expand Down
6 changes: 3 additions & 3 deletions src/geouned/GEOUNED/Conversion/CellDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def GenPlaneCylinder_old(face, solid):

U_val_str_cl = []
for i, elem1 in enumerate(U_val):
num_str1 = "%11.4E" % elem1
num_str1 = f"{elem1:11.4E}"
if abs(elem1) < 1.0e-5:
num_str1 = "%11.4E" % 0.0
if not (BF.isDuplicateInList(num_str1, i, U_val)):
Expand Down Expand Up @@ -522,7 +522,7 @@ def GenPlaneCone_old(face, solid):
u_val_str_cl = []

for i, elem1 in enumerate(u_val):
num_str1 = "%11.4E" % elem1
num_str1 = f"{elem1:11.4E}"
if abs(elem1) < 1.0e-5:
num_str1 = "%11.4E" % 0.0
if not (BF.isDuplicateInList(num_str1, i, u_val)):
Expand Down Expand Up @@ -993,7 +993,7 @@ def cellDef(meta_obj, surfaces, universe_box):
if extra[0] not in surf_piece:
surf_piece.append(extra[0])
else:
surf_piece.append("({})".format(":".join(extra)))
surf_piece.append(f"({':'.join(extra)})")

surf_piece_bool = BoolSequence(" ".join(surf_piece))
# possible expresion for e
Expand Down
6 changes: 3 additions & 3 deletions src/geouned/GEOUNED/Cuboid/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ def translate(meta_list, surfaces, universe_box, setting):
for i, m in enumerate(meta_list):
if m.IsEnclosure:
continue
print("Decomposing solid: {}/{} ".format(i, tot_solid))
print(f"Decomposing solid: {i}/{tot_solid} ")
if setting["debug"]:
print(m.Comments)
if m.IsEnclosure:
m.Solids[0].exportStep("origEnclosure_{}.stp".format(i))
m.Solids[0].exportStep(f"origEnclosure_{i}.stp")
else:
m.Solids[0].exportStep("origSolid_{}.stp".format(i))
m.Solids[0].exportStep(f"origSolid_{i}.stp")

surfaces.extend(
Decom.ExtractSurfaces(
Expand Down
6 changes: 3 additions & 3 deletions src/geouned/GEOUNED/Decompose/Decom_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def GenPlaneCylinder(face, solid):
Uval_str_cl = []

for i, elem1 in enumerate(Uval):
num_str1 = "%11.4E" % elem1
num_str1 = f"{elem1:11.4E}"
if abs(elem1) < 1.0e-5:
num_str1 = "%11.4E" % 0.0

Expand Down Expand Up @@ -597,7 +597,7 @@ def GenPlaneCone(face, solid):
Uval_str_cl = []

for i, elem1 in enumerate(Uval):
num_str1 = "%11.4E" % elem1
num_str1 = f"{elem1:11.4E}"
if abs(elem1) < 1.0e-5:
num_str1 = "%11.4E" % 0.0
if not (isDuplicateInList(num_str1, i, Uval)):
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def splitComponent(solidShape, universe_box):

if abs(Volch) > 1e-2: # 1% of Volume change
if opt.verbose:
print("Warning: Volume has changed after decomposition: %11.4E" % Volch)
print(f"Warning: Volume has changed after decomposition: {Volch:11.4E}")
err += 4

return comsolid, err
Expand Down
2 changes: 1 addition & 1 deletion src/geouned/GEOUNED/LoadFile/LoadFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def checkEnclosure(freecad_doc, enclosure_list):
print("Following enclosure produce loop")
for p in encl_dict.keys():
for s in encl_dict[p]:
print("{}_{}".format(s, p))
print(f"{s}_{p}")
raise ValueError("GEOUNED.LoadFunctions.checkEnclosure failed")

# check enclosures solids are correctly nested and don't overlap each other
Expand Down
4 changes: 2 additions & 2 deletions src/geouned/GEOUNED/LoadFile/LoadSTEP.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def LoadCAD(filename, mat_filename, default_mat=[], comp_solids=True):
if os.path.exists(mat_filename):
m_dict = extractMaterials(mat_filename)
else:
print("Material definition file {} does not exist.".format(mat_filename))
print(f"Material definition file {mat_filename} does not exist.")
m_dict = {}
else:
m_dict = {}
Expand Down Expand Up @@ -135,7 +135,7 @@ def LoadCAD(filename, mat_filename, default_mat=[], comp_solids=True):
n_solids = len(elem.Shape.Solids)

for i in range(n_solids):
meta_list[i_solid].setComments("{}{}".format(comment, (i + 1)))
meta_list[i_solid].setComments(f"{comment}{i + 1}")
meta_list[i_solid].setCADSolid()

if tempre_mat:
Expand Down
Loading

0 comments on commit fed99be

Please sign in to comment.