Skip to content

Commit 7421159

Browse files
committed
folder path for output files and folders
1 parent d208cf5 commit 7421159

File tree

7 files changed

+50
-29
lines changed

7 files changed

+50
-29
lines changed

docs/users_guide/execution_settings/cad2csg/python_cadtocsg_api_usage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following example shows a usage with every attributes specified.
3939
)
4040
4141
my_settings = geouned.Settings(
42+
outPath=".",
4243
matFile="",
4344
voidGen=True,
4445
debug=False,

src/geouned/GEOUNED/core.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from tqdm import tqdm
1212

1313
from .code_version import *
14+
from .utils.log_utils import setup_logger
1415
from .conversion import cell_definition as Conv
1516
from .cuboid.translate import translate
1617
from .decompose import decom_one as Decom
@@ -23,8 +24,6 @@
2324
from .write.write_files import write_geometry
2425

2526
logger = logging.getLogger("general_logger")
26-
logger.info(f"GEOUNED version {version('geouned')}")
27-
logger.info(f"FreeCAD version {'.'.join(FreeCAD.Version()[:3])}")
2827

2928

3029
class CadToCsg:
@@ -67,6 +66,14 @@ def __init__(
6766
self.filename = None
6867
self.skip_solids = []
6968

69+
log_path = Path(self.settings.outPath) / "log_files"
70+
log_path.mkdir(parents=True, exist_ok=True)
71+
setup_logger("general_logger", log_path / "geouned_general.log")
72+
setup_logger("fuzzy_logger", log_path / "geouned_fuzzy.log")
73+
setup_logger("solids_logger", log_path / "geouned_solids.log")
74+
logger.info(f"GEOUNED version {version('geouned')}")
75+
logger.info(f"FreeCAD version {'.'.join(FreeCAD.Version()[:3])}")
76+
7077
@property
7178
def options(self):
7279
return self._options
@@ -598,9 +605,9 @@ def _decompose_solids(self, meta: bool):
598605
continue
599606
logger.info(f"Decomposing solid: {i + 1}/{totsolid}")
600607
if self.settings.debug:
601-
debug_output_folder = Path("debug")
602-
logger.info(m.Comments)
608+
debug_output_folder = Path(self.settings.outPath) / "debug"
603609
debug_output_folder.mkdir(parents=True, exist_ok=True)
610+
logger.info(m.Comments)
604611
if m.IsEnclosure:
605612
m.Solids[0].exportStep(str(debug_output_folder / f"origEnclosure_{i}.stp"))
606613
else:
@@ -615,7 +622,7 @@ def _decompose_solids(self, meta: bool):
615622
)
616623

617624
if err != 0:
618-
sus_output_folder = Path("suspicious_solids")
625+
sus_output_folder = Path(self.settings.outPath) / "suspicious_solids"
619626
sus_output_folder.mkdir(parents=True, exist_ok=True)
620627
if m.IsEnclosure:
621628
Part.CompSolid(m.Solids).exportStep(str(sus_output_folder / f"Enclosure_original_{i}.stp"))

src/geouned/GEOUNED/utils/basic_functions_part2.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
import logging
55
import math
66

7-
import FreeCAD
8-
97
from .basic_functions_part1 import (
10-
is_in_line,
11-
is_in_plane,
128
is_in_tolerance,
139
is_opposite,
1410
is_parallel,

src/geouned/GEOUNED/utils/data_classes.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,11 @@ class Settings:
594594
"""Settings for changing the way the CAD to CSG conversion is done
595595
596596
Args:
597-
matFile (str, optional): _description_. Defaults to "".
597+
outPath (str, optional): Path to folder where output file will be
598+
written. If folder doesn't exist it will be created. Defaults
599+
to ".".
600+
matFile (str, optional): Name of the file in which the material
601+
information is provided. Defaults to "".
598602
voidGen (bool, optional): Generate voids of the geometry. Defaults
599603
to True.
600604
debug (bool, optional): Write step files of original and decomposed
@@ -638,6 +642,7 @@ class Settings:
638642

639643
def __init__(
640644
self,
645+
outPath: str = ".",
641646
matFile: str = "",
642647
voidGen: bool = True,
643648
debug: bool = False,
@@ -653,7 +658,7 @@ def __init__(
653658
startSurf: int = 1,
654659
sort_enclosure: bool = False,
655660
):
656-
661+
self.outPath = outPath
657662
self.matFile = matFile
658663
self.voidGen = voidGen
659664
self.debug = debug
@@ -669,6 +674,16 @@ def __init__(
669674
self.startSurf = startSurf
670675
self.sort_enclosure = sort_enclosure
671676

677+
@property
678+
def outPath(self):
679+
return self._outPath
680+
681+
@outPath.setter
682+
def outPath(self, outPath: str):
683+
if not isinstance(outPath, str):
684+
raise TypeError(f"geouned.Settings.outPath should be a str, not a {type(outPath)}")
685+
self._outPath = outPath
686+
672687
@property
673688
def matFile(self):
674689
return self._matFile

src/geouned/GEOUNED/write/additional_files.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
from pathlib import Path
22

33

4-
def comments_write(name, MetaList):
4+
def comments_write(name_path, MetaList):
55
"""Function to write in an independent file the comment strings"""
66

7-
Path(name).parent.mkdir(parents=True, exist_ok=True)
7+
Path(name_path).parent.mkdir(parents=True, exist_ok=True)
8+
name = name_path.parent.absolute() / (name_path.name + "_summary.txt")
9+
810
with open(file=name + "_comments.txt", mode="w", encoding="utf-8") as outfile:
911
for m in MetaList:
1012
outfile.write(m.Comments + "\n")
1113

1214

13-
def summary_write(name, MetaList):
15+
def summary_write(name_path, MetaList):
16+
17+
Path(name_path).parent.mkdir(parents=True, exist_ok=True)
18+
name = name_path.parent.absolute() / (name_path.name + "_summary.txt")
1419

15-
Path(name).parent.mkdir(parents=True, exist_ok=True)
16-
with open(file=name + "_summary.txt", mode="w", encoding="utf-8") as outfile:
20+
with open(file=name, mode="w", encoding="utf-8") as outfile:
1721
header = f" Cell Id{'':5s}Mat Id{'':6s}Density{'':7s}Volume{'':5s}Comments\n"
1822
outfile.write(header)
1923

src/geouned/GEOUNED/write/write_files.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from . import additional_files as OutFiles
23
from .mcnp_format import McnpInput
34
from .openmc_format import OpenmcInput
@@ -31,14 +32,17 @@ def write_geometry(
3132
msg = f"outFormat {out_format} not in supported MC codes ({supported_mc_codes})"
3233
raise ValueError(msg)
3334

35+
filePath = Path(settings.outPath)
36+
pathName = filePath / geometryName
37+
3438
# write cells comments in file
3539
if cellCommentFile:
36-
OutFiles.comments_write(geometryName, MetaList)
40+
OutFiles.comments_write(pathName, MetaList)
3741
if cellSummaryFile:
38-
OutFiles.summary_write(geometryName, MetaList)
42+
OutFiles.summary_write(pathName, MetaList)
3943

4044
if "mcnp" in outFormat:
41-
mcnpFilename = geometryName + ".mcnp"
45+
mcnpFilename = filePath / (geometryName + ".mcnp")
4246
outBox = (
4347
UniverseBox.XMin,
4448
UniverseBox.XMax,
@@ -72,15 +76,15 @@ def write_geometry(
7276
OMCFile = OpenmcInput(MetaList, Surfaces, options, tolerances, numeric_format)
7377

7478
if "openmc_xml" in outFormat:
75-
omcFilename = geometryName + ".xml"
79+
omcFilename = filePath / (geometryName + ".xml")
7680
OMCFile.write_xml(omcFilename)
7781

7882
if "openmc_py" in outFormat:
79-
omcFilename = geometryName + ".py"
83+
omcFilename = filePath / (geometryName + ".py")
8084
OMCFile.write_py(omcFilename)
8185

8286
if "serpent" in outFormat:
83-
serpentFilename = geometryName + ".serp"
87+
serpentFilename = filePath / (geometryName + ".serp")
8488
outBox = (
8589
UniverseBox.XMin,
8690
UniverseBox.XMax,
@@ -111,7 +115,7 @@ def write_geometry(
111115
Serpentfile.write_input(serpentFilename)
112116

113117
if "phits" in outFormat:
114-
phitsFilename = geometryName + ".inp"
118+
phitsFilename = filePath / (geometryName + ".inp")
115119
PHITS_outBox = (
116120
UniverseBox.XMin,
117121
UniverseBox.XMax,

src/geouned/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
from .GEOReverse import *
1313
from .GEOUNED import *
14-
from .GEOUNED.utils.log_utils import setup_logger
15-
16-
setup_logger("general_logger", "geouned_general_log.log")
17-
setup_logger("fuzzy_logger", "geouned_fuzzy_log.log")
18-
setup_logger("solids_logger", "geouned_solids_log.log")
19-
2014

2115
__version__ = version("geouned")
2216

0 commit comments

Comments
 (0)