diff --git a/src/geouned/GEOUNED/core.py b/src/geouned/GEOUNED/core.py index bf67bb55..0125f4d5 100644 --- a/src/geouned/GEOUNED/core.py +++ b/src/geouned/GEOUNED/core.py @@ -1,4 +1,3 @@ -import configparser import json import logging import typing @@ -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]],