Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edistr to endf #193

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions sandy/pfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,49 @@ def from_endf6(cls, endf6):
if not data:
raise sandy.Error("no tabulated energy distribution was found")
return cls(data)

def to_endf6(self, endf6):
"""
Update cross sections in `Endf6` instance with those available in a
`Fy` instance.

Parameters
----------
`endf6` : `sandy.Endf6`
`Endf6` instance

Returns
-------
`sandy.Endf6`
`Endf6` instance with updated IFY and CFY

Examples
--------
>>> endf6 = sandy.get_endf6_file("jeff_33", "xs", 922380)
>>> edistr = sandy.Edistr.from_endf6(endf6)
>>> out_endf = edistr.to_endf6(endf6)
>>> assert type(out_endf) == sandy.core.endf6.Endf6

>>> out_df = out_endf._get_section_df(9237, 5, 18).apply(pd.to_numeric, errors='coerce').fillna(0)
>>> input_df = endf6._get_section_df(9237, 5, 18).apply(pd.to_numeric, errors='coerce').fillna(0)
>>> assert out_df.equals(input_df)
"""
data = endf6.data.copy()
for (mat, mt, k), data_edistr in self.data.groupby(['MAT', 'MT', 'K']):
sec = endf6.read_section(mat, 5, mt)
new_values = {}
mask = f"MAT == {mat} & MT == {mt} & K == {k}"
data_ein = data_edistr.query(mask)
for ein in data_ein["EIN"].unique():
mask = f"EIN == {ein}"
new_data = data_ein.query(mask)
NBT = len(new_data["EOUT"].values)
new_values[ein] = {
"EOUT": new_data["EOUT"].values,
"EDISTR": new_data["VALUE"].values,
"NBT": [NBT],
"INT": [2],
}
sec["PDISTR"][k]['EIN'] = new_values
data[(mat, 5, mt)] = sandy.sections.mf5.write_mf5(sec)
return sandy.Endf6(data)
121 changes: 121 additions & 0 deletions sandy/sections/mf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,124 @@ def read_mf5(tape, mat, mt):
if pdistr:
out["PDISTR"] = pdistr
return out


def write_mf5(sec):
"""
Given the content of MF5 for energy distributions of secondary particles
as nested dictionaries, write it to string.

Parameters
----------
sec : 'dict'
Multiline string reproducing the content of a ENDF-6 section.

Returns
-------
`str`
Multiline string reproducing the content of a ENDF-6 section.

Examples
--------
>>> endf6 = sandy.get_endf6_file("jeff_33", "xs", 922380)
>>> sec = sandy.sections.read_mf5(endf6, 9237, 18)
>>> print(write_mf5(sec)[:1000])
92238.0000 236.005800 0 0 1 09237 5 18 1
0.00000000 0.00000000 0 1 1 29237 5 18 2
2 2 9237 5 18 3
1.000000-5 1.00000000 30000000.0 1.00000000 9237 5 18 4
0.00000000 0.00000000 0 0 1 969237 5 18 5
96 2 9237 5 18 6
0.00000000 1.000000-5 0 0 1 3039237 5 18 7
303 2 9237 5 18 8
1.000000-5 1.95793-12 2.000000-5 2.76893-12 4.000000-5 3.91586-129237 5 18 9
6.000000-5 4.79593-12 8.000000-5 5.53787-12 1.000000-4 6.19152-129237 5 18 10
2.000000-4 8.75614-12 4.000000-4 1.23831-11 6.000000-4 1.51661-119237 5 18 11
8.000000-4 1.75123-11 1.000000-3 1.95793-11 2.000000-3 2.76893-119237 5 18 12
4.000000-3 3.91586-11 6.000

"""
NK = len(sec["PDISTR"])
lines = sandy.write_cont(sec["ZA"], sec["AWR"], 0, 0, NK, 0)
for k, sub_info in sec["PDISTR"].items():
LF = sub_info['LF']
if LF not in [5, 7, 9, 11, 12]:
lines += sandy.write_tab1(0,
0,
0,
LF,
sub_info["NBT_P"],
sub_info["INT_P"],
sub_info["E_P"],
sub_info["P"])
else:
lines += sandy.write_tab1(sub_info['U'], # C1
0, # C2
0, # L1
LF, # L2
sub_info["NBT_P"], # NBT
sub_info["INT_P"], # INT
sub_info["E_P"], # X
sub_info["P"]) # Y
if LF == 5:
lines += sandy.write_tab1(0, # C1
0, # C2
0, # L1
0, # L2
sub_info["NBT_THETA"], # NBT
sub_info["INT_THETA"], # INT
sub_info["E_THETA"], # X
sub_info["THETA"]) # Y
lines += sandy.write_tab1(0, # C1
0, # C2
0, # L1
0, # L2
sub_info["NBT_G"], # NBT
sub_info["INT_G"], # INT
sub_info["E_G"], # X
sub_info["G"]) # Y
elif LF in (7, 9):
lines += sandy.write_tab1(0, # C1
0, # C2
0, # L1
0, # L2
sub_info["NBT_THETA"], # NBT
sub_info["INT_THETA"], # INT
sub_info["E_THETA"], # X
sub_info["THETA"]) # Y
elif LF == 11:
lines += sandy.write_tab1(0, # C1
0, # C2
0, # L1
0, # L2
sub_info["NBT_A"], # NBT
sub_info["INT_A"], # INT
sub_info["E_A"], # X
sub_info["A"]) # Y
lines += sandy.write_tab1(0, # C1
0, # C2
0, # L1
0, # L2
sub_info["NBT_B"], # NBT
sub_info["INT_B"], # INT
sub_info["E_B"], # X
sub_info["B"]) # Y
elif LF == 1:
NZ = len(sub_info['EIN'])
lines += sandy.write_tab2(0, # C1
0, # C2
0, # L1
0, # L2
NZ, # NZ
sub_info["NBT_EIN"], # NBT
sub_info["INT_EIN"]) # INT
for EIN, edistr in sub_info['EIN'].items():
lines += sandy.write_tab1(0, # C1
EIN, # C2
0, # L1
0, # L2
edistr["NBT"], # NBT
edistr["INT"], # INT
edistr["EOUT"], # X
edistr["EDISTR"]) # Y
return "\n".join(sandy.write_eol(lines, sec["MAT"], 5, sec["MT"]))