Skip to content

Commit 5e00416

Browse files
committed
cli: added indexs to Run hooks
1 parent bc2c0af commit 5e00416

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/pymcnp/Inp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ def to_mcnp(self):
131131
# source += DELIMITER
132132

133133
return f"""
134-
{self.message or ""}
135-
{self.title}
134+
{self.message + "\n" if self.message else ""}{self.title}
136135
{'\n'.join(map(str, self.cells))}
137136
138137
{'\n'.join(map(str, self.surfaces))}

src/pymcnp/cli/run.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@ def __init__(self, inps: Inp, command='mcnp6'):
4646
self.inps = inps
4747
self.command = command
4848

49-
def prehook_file(self, path: pathlib.Path):
49+
def prehook_file(self, path: pathlib.Path, index: int):
5050
"""
5151
Runs before a file.
5252
5353
Parameters:
5454
path: Path to run directory.
55+
index: Run number.
5556
"""
5657

5758
pass
5859

59-
def posthook_file(self, path: pathlib.Path):
60+
def posthook_file(self, path: pathlib.Path, index: int):
6061
"""
6162
Runs after a file.
6263
6364
Parameters:
6465
path: Path to run directory.
66+
index: Run number.
6567
"""
6668

6769
pass
@@ -110,13 +112,13 @@ def run(self, path: str | pathlib.Path):
110112
with path_input.open('w') as file:
111113
file.write(inp.to_mcnp())
112114

113-
self.prehook_file(subdirectory)
115+
self.prehook_file(subdirectory, i)
114116
process = subprocess.Popen([f'{self.command}', f'inp={path_input} outp={path_output} ptrac={path_ptrac}'])
115117
processes.append((process, subdirectory))
116118

117-
for process, subdirectory in processes:
119+
for i, (process, subdirectory) in enumerate(processes):
118120
process.wait()
119-
self.posthook_file(subdirectory)
121+
self.posthook_file(subdirectory, i)
120122

121123
self.posthook_batch(directory)
122124

src/pymcnp/inp/Cell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def __init__(
2626
self,
2727
number: types.Integer,
2828
material: types.Integer,
29-
density: types.Integer,
3029
geometry: types.Geometry,
30+
density: types.Real = None,
3131
options: types.Tuple[cell.CellOption] = None,
3232
):
3333
"""
@@ -46,7 +46,7 @@ def __init__(
4646

4747
self.number: types.Integer = number
4848
self.material: types.Integer = material
49-
self.density: types.Integer = density
49+
self.density: types.Real = density
5050
self.geometry: types.Geometry = geometry
5151
self.options: types.Tuple[cell.CellOption] = options
5252

tests/test_pymcnp/test_cli/test_Run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class Test_Methods:
2424
def test_prehook_file(self):
2525
for example in self.EXAMPLES:
2626
element = self.element(**example)
27-
element.prehook_file(self.PATH)
27+
element.prehook_file(self.PATH, 0)
2828

2929
def test_posthook_file(self):
3030
for example in self.EXAMPLES:
3131
element = self.element(**example)
32-
element.prehook_file(self.PATH)
32+
element.posthook_file(self.PATH, 0)
3333

3434
def test_prehook_batch(self):
3535
for example in self.EXAMPLES:
@@ -39,7 +39,7 @@ def test_prehook_batch(self):
3939
def test_posthook_batch(self):
4040
for example in self.EXAMPLES:
4141
element = self.element(**example)
42-
element.prehook_batch(self.PATH)
42+
element.posthook_batch(self.PATH)
4343

4444
def test_run(self):
4545
for example in self.EXAMPLES:

0 commit comments

Comments
 (0)