Skip to content

Commit

Permalink
added get_keff and get_table140
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiorito Luca committed Aug 19, 2022
1 parent ffb8795 commit 4bd7ef3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions sandy/mcnp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .mctal import *
from .meshtal import *
from .output_file import *
47 changes: 47 additions & 0 deletions sandy/mcnp/output_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import re
from io import StringIO

import pandas as pd


__author__ = "Luca Fiorito"

__all__ = [
"get_keff",
"get_table140",
]


def get_keff(file):
with open(file, 'r') as f:
text = f.read()
PATTERN = "final estimate.*= (?P<keff>[\.0-9]+).*?(?P<stdev>[\.0-9]+)"
match = re.search(PATTERN, text)
keff = float(match.group("keff"))
std = float(match.group("stdev"))
return {"KEFF": keff, "ERR": std}


def get_table140(file):
print(f"reading file '{file}'...")
with open(file, 'r') as f:
text = f.read()
PATTERN = "(?:^1neutron.*table 140\n)(?P<table>(?:.*\n)+?)(?P<end>^\s+total\s{20})"
match = re.search(PATTERN, text, re.MULTILINE).group("table")
widths=[10, 9, 11, 9,] + [12] * 6
dtypes = [int, int, str, float, int, float, float, float, float, int]
names = pd.read_fwf(
StringIO(match),
widths=widths,
skip_blank_lines=True,
nrows=2,
header=None,
).fillna("").apply(lambda col: " ".join(col).strip())
df = pd.read_fwf(
StringIO(match),
widths=widths,
skip_blank_lines=True,
skiprows=3,
names=names,
).ffill()
return df.astype(dict(zip(names, dtypes)))

0 comments on commit 4bd7ef3

Please sign in to comment.