Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed config ini code #218

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 0 additions & 179 deletions src/geouned/GEOUNED/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import configparser
import json
import logging
import typing
Expand Down Expand Up @@ -262,184 +261,6 @@ def from_json(cls, filename: str):
cad_to_csg.export_csg()
return cad_to_csg

# TODO add tests as set_configuration is not currently tested
def set_configuration(self, configFile=None):

if configFile is None:
return

config = configparser.ConfigParser()
config.optionxform = str
config.read(configFile)
for section in config.sections():
if section == "Files":
for key in config["Files"].keys():
if key in ("geometryName", "matFile", "title"):
self.set(key, config.get("Files", key))

elif key == "stepFile":
value = config.get("Files", key).strip()
lst = value.split()
if value[0] in ("(", "[") and value[-1] in ("]", ")"):
data = value[1:-1].split(",")
data = [x.strip() for x in data]
self.set(key, data)
elif len(lst) > 1:
self.set(key, lst)
else:
self.set(key, value)

elif key == "outFormat":
raw = config.get("Files", key).strip()
values = tuple(x.strip() for x in raw.split(","))
outFormat = []
for v in values:
if v.lower() == "mcnp":
outFormat.append("mcnp")
elif v.lower() == "openmc_xml":
outFormat.append("openmc_xml")
elif v.lower() == "openmc_py":
outFormat.append("openmc_py")
elif v.lower() == "serpent":
outFormat.append("serpent")
elif v.lower() == "phits":
outFormat.append("phits")
self.set(key, tuple(outFormat))

elif section == "Parameters":
for key in config["Parameters"].keys():
if key in (
"voidGen",
"debug",
"compSolids",
"volSDEF",
"volCARD",
"dummyMat",
"cellSummaryFile",
"cellCommentFile",
"sort_enclosure",
):
self.set(key, config.getboolean("Parameters", key))
elif key in (
"minVoidSize",
"maxSurf",
"maxBracket",
"startCell",
"startSurf",
):
self.set(key, config.getint("Parameters", key))
elif key in ("exportSolids", "UCARD", "simplify"):
self.set(key, config.get("Parameters", key))
elif key == "voidMat":
value = config.get("Parameters", key).strip()
data = value[1:-1].split(",")
self.set(key, (int(data[0]), float(data[1]), data[2]))
else:
value = config.get("Parameters", key).strip()
data = value[1:-1].split(",")
self.set(key, tuple(map(int, data)))

elif section == "Options":
attributes_and_types = get_type_hints(Options())
for key in config["Options"].keys():
if key in attributes_and_types.keys():
if attributes_and_types[key] is bool:
value = config.getboolean("Options", key)
elif attributes_and_types[key] is float or attributes_and_types[key] is int:
value = config.getfloat("Options", key)
setattr(self.options, key, value)

elif section == "Tolerances":
attributes_and_types = get_type_hints(Tolerances())
for key in config["Tolerances"].keys():
if key in attributes_and_types.keys():
if attributes_and_types[key] is bool:
value = config.getboolean("Tolerances", key)
elif attributes_and_types[key] is float:
value = config.getfloat("Tolerances", key)
setattr(self.tolerances, key, value)

elif section == "MCNP_Numeric_Format":
attributes_and_types = get_type_hints(NumericFormat())
PdEntry = False
for key in config["MCNP_Numeric_Format"].keys():
if key in attributes_and_types.keys():
value = config.get("MCNP_Numeric_Format", key)
setattr(self.numeric_format, key, value)
if key == "P_d":
PdEntry = True

else:
logger.info(f"bad section name : {section}")

if self.__dict__["geometryName"] == "":
self.__dict__["geometryName"] = self.__dict__["stepFile"][:-4]

# TODO see if we can find another way to do this
if self.options.prnt3PPlane and not PdEntry:
self.NumericFormat.P_d = "22.15e"

logger.info(self.__dict__)

# TODO add tests as set is not currently tested
def set(self, kwrd, value):

if kwrd == "stepFile":
if isinstance(value, (list, tuple)):
for v in value:
if not isinstance(v, str):
logger.info(f"elemt in {kwrd} list should be string")
return
elif not isinstance(value, str):
logger.info(f"{kwrd} should be string or tuple of strings")
return

elif kwrd == "UCARD":
if value == "None":
value = None
elif value.isdigit():
value = int(value)
else:
logger.info(f"{kwrd} value should be None or integer")
return
elif kwrd == "outFormat":
if len(value) == 0:
return
elif kwrd in ("geometryName", "matFile", "exportSolids"):
if not isinstance(value, str):
logger.info(f"{kwrd} value should be str instance")
return
elif kwrd in ("cellRange", "voidMat", "voidExclude"):
if not isinstance(value, (list, tuple)):
logger.info(f"{kwrd} value should be list or tuple")
return
elif kwrd in ("minVoidSize", "maxSurf", "maxBracket", "startCell", "startSurf"):
if not isinstance(value, int):
logger.info(f"{kwrd} value should be integer")
return
elif kwrd in (
"voidGen",
"debug",
"compSolids",
"simplifyCTable",
"volSDEF",
"volCARD",
"dummyMat",
"cellSummaryFile",
"cellCommentFile",
"sort_enclosure",
):
if not isinstance(value, bool):
logger.info(f"{kwrd} value should be boolean")
return

self.__dict__[kwrd] = value
if kwrd == "stepFile" and self.__dict__["geometryName"] == "":
if isinstance(value, (tuple, list)):
self.__dict__["geometryName"] == "joined_step_files"
else:
self.__dict__["geometryName"] == value[:-4]

def load_step_file(
self,
filename: typing.Union[str, typing.Sequence[str]],
Expand Down