Skip to content

Commit

Permalink
adding reg tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed May 23, 2024
1 parent bb17d1b commit 119fb5f
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,49 @@
step_files.remove(Path("testing/inputSTEP/large/Triangle.stp"))
suffixes = (".mcnp", ".xml", ".inp", ".py", ".serp")


@pytest.mark.parametrize("input_step_file", step_files)
def compare_files_line_by_line(filename_new: Path, filename_original: Path):

with open(filename_new, 'r') as f:
file_new = f.readlines()
with open(filename_original, 'r') as f:
file_original = f.readlines()

for line_counter, line_new in enumerate(file_new, start=1):
for line_original in file_original:
if line_new != line_original:
print(f"{filename_new} does not match {filename_original}")
print(f"Line {line_counter} different in files")
# else print that line from both files
print(f"\tFile 1: {line_new}", end='')
print(f"\tFile 2: {line_original}", end='')
assert False

# @pytest.mark.parametrize("input_step_file", step_files[:2])
# @pytest.mark.parametrize("suffix", suffixes)
# def test_new_mc_files_match_original(suffix, input_step_file):
"""Test that the text files produced for each MC code match the original files.
If this test fails it might be due to an improved MC code output instead of
a mistake in the PR. You might want to update the MC text file in the regression
test folder with the 'tests/update_regression_test_files.py' script."""

suffix='.serp'
input_step_file=step_files[0]
# sets up an output folder for the results
regression_test_file = Path("tests/regression_test") / input_step_file.stem/ input_step_file.with_suffix(suffix)
output_dir = Path("tests_outputs") / input_step_file.with_suffix("")
output_filename_stem = output_dir / input_step_file.stem
output_filename = output_filename_stem.with_suffix(suffix)
print(output_dir) #'tests_outputs/testing/inputSTEP/tuboshueco'
print(input_step_file.stem)
print(Path(input_step_file.stem).with_suffix(suffix))

compare_files_line_by_line(output_filename, regression_test_file)

print(output_dir)
assert False
# test_new_mc_files_match_original('.serp', step_files[0])

@pytest.mark.parametrize("input_step_file", step_files[:2])
def test_conversion(input_step_file):
"""Test that step files can be converted to openmc and mcnp files"""

Expand Down
118 changes: 118 additions & 0 deletions tests/update_regression_test_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from pathlib import Path


import geouned

suffixes = (".mcnp", ".xml", ".inp", ".py", ".serp")

path_to_cad = Path("testing/inputSTEP")
step_files = list(path_to_cad.rglob("*.stp")) + list(path_to_cad.rglob("*.step"))

for input_step_file in step_files:

# sets up an output folder for the results
output_dir = Path("tests/regression_test") / input_step_file.with_suffix("")
output_dir.mkdir(parents=True, exist_ok=True)
output_filename_stem = output_dir / input_step_file.stem

# deletes the output MC files if they already exists
for suffix in suffixes:
output_filename_stem.with_suffix(suffix).unlink(missing_ok=True)

my_options = geouned.Options(
forceCylinder=False,
newSplitPlane=True,
delLastNumber=False,
enlargeBox=2,
nPlaneReverse=0,
splitTolerance=0,
scaleUp=True,
quadricPY=False,
Facets=False,
prnt3PPlane=False,
forceNoOverlap=False,
)

my_tolerances = geouned.Tolerances(
relativeTol=False,
relativePrecision=0.000001,
value=0.000001,
distance=0.0001,
angle=0.0001,
pln_distance=0.0001,
pln_angle=0.0001,
cyl_distance=0.0001,
cyl_angle=0.0001,
sph_distance=0.0001,
kne_distance=0.0001,
kne_angle=0.0001,
tor_distance=0.0001,
tor_angle=0.0001,
min_area=0.01,
)

my_numeric_format = geouned.NumericFormat(
P_abc="14.7e",
P_d="14.7e",
P_xyz="14.7e",
S_r="14.7e",
S_xyz="14.7e",
C_r="12f",
C_xyz="12f",
K_xyz="13.6e",
K_tan2="12f",
T_r="14.7e",
T_xyz="14.7e",
GQ_1to6="18.15f",
GQ_7to9="18.15f",
GQ_10="18.15f",
)

my_settings = geouned.Settings(
matFile="",
voidGen=True,
debug=False,
compSolids=True,
simplify="no",
cellRange=[],
exportSolids="",
minVoidSize=200.0, # units mm
maxSurf=50,
maxBracket=30,
voidMat=[],
voidExclude=[],
startCell=1,
startSurf=1,
sort_enclosure=False,
)

geo = geouned.CadToCsg(
stepFile=f"{input_step_file.resolve()}",
options=my_options,
settings=my_settings,
tolerances=my_tolerances,
numeric_format=my_numeric_format,
)

geo.start()

geo.export_csg(
title="Converted with GEOUNED",
geometryName=f"{output_filename_stem.resolve()}",
outFormat=(
"openmc_xml",
"openmc_py",
"serpent",
"phits",
"mcnp",
),
volSDEF=True, # changed from the default
volCARD=False, # changed from the default
UCARD=None,
dummyMat=True, # changed from the default
cellCommentFile=False,
cellSummaryFile=False, # changed from the default
)

for suffix in suffixes:
assert output_filename_stem.with_suffix(suffix).exists()

0 comments on commit 119fb5f

Please sign in to comment.