Skip to content

Invalid MF32 section accepted by C++ parser #58

@gschnabel

Description

@gschnabel

The following MF32/MT151 generated and wrongly formatted section by ChatGPT is accepted by the C++ but not the Python parser:

 2.350439+2 0.000000+0          2          0          1          0 12532151    1
 5.000000-1 0.000000+0          0          0          2          2 12532151    2
 1.000000-4 0.000000+0 0.000000+0 0.000000+0 4.000000-6 0.000000+0 12532151    3
 0.000000+0 0.000000+0 1.000000-4                                  12532151    4
 4.000000-4 0.000000+0 0.000000+0 0.000000+0 2.500000-5 0.000000+0 12532151    5
 0.000000+0 0.000000+0 1.000000-4                                  12532151    6
                                                                   12532  0    0

This command fails:

endf-cli show --no-cpp --ignore_send_records --ignore_missing_tpid /32/151/isotope/1 mf32_test.endf

while this one succeeds:

endf-cli show --ignore_send_records --ignore_missing_tpid /32/151/isotope/1 mf32_test.endf

The following code generated by ChatGPT was used to create the section:

import pandas as pd


def format_endf_float(x: float) -> str:
    if x == 0.0:
        return " 0.000000+0"
    s = f"{x:.6E}"
    mantissa, exp = s.split("E")
    return f"{mantissa}{int(exp):+d}".replace("E", "").rjust(11)

def make_mf32_mlbw(
    df: pd.DataFrame,
    mat: int,
    mt: int,
    awri: float,
    spin: float
) -> str:
    """
    Create MF=32 covariance section for MLBW resonances
    with diagonal covariance only.
    """

    required = {"Er", "Gn", "Gg", "dEr", "dGn", "dGg"}
    if not required.issubset(df.columns):
        raise ValueError(f"DataFrame must contain {required}")

    nres = len(df)
    lines = []

    # -------------------------------
    # HEAD record
    # -------------------------------
    # C1 = AWRI, C2 = 0.0
    # L1 = 2 (MLBW), L2 = 0
    # N1 = NJS (spin groups) = 1
    # N2 = 0
    head = (
        format_endf_float(awri)
        + format_endf_float(0.0)
        + f"{2:11d}{0:11d}{1:11d}{0:11d}"
        + f"{mat:4d}32{mt:3d}    1"
    )
    lines.append(head)

    # -------------------------------
    # Spin group header
    # -------------------------------
    # C1 = spin, C2 = 0
    # L1 = 0, L2 = 0
    # N1 = number of resonances
    # N2 = number of covariance matrices (= Nres)
    sg = (
        format_endf_float(spin)
        + format_endf_float(0.0)
        + f"{0:11d}{0:11d}{nres:11d}{nres:11d}"
        + f"{mat:4d}32{mt:3d}    2"
    )
    lines.append(sg)

    record = 3

    # -------------------------------
    # Covariance matrices
    # -------------------------------
    # Each resonance has a 3x3 diagonal covariance matrix
    # Order: Er, Gn, Gg
    for _, r in df.iterrows():
        cov = [
            r.dEr ** 2, 0.0, 0.0,
            0.0, r.dGn ** 2, 0.0,
            0.0, 0.0, r.dGg ** 2,
        ]

        buf = ""
        for v in cov:
            buf += format_endf_float(v)
            if len(buf) == 66:
                lines.append(
                    buf + f"{mat:4d}32{mt:3d}{record:5d}"
                )
                record += 1
                buf = ""

        if buf.strip():
            lines.append(
                buf.ljust(66) + f"{mat:4d}32{mt:3d}{record:5d}"
            )
            record += 1

    # -------------------------------
    # SEND record
    # -------------------------------
    lines.append(" " * 66 + f"{mat:4d}32  0    0")

    return "\n".join(lines)


df = pd.DataFrame({
    "Er":  [1.0, 10.0],
    "Gn":  [0.02, 0.05],
    "Gg":  [0.10, 0.12],
    "dEr": [0.01, 0.02],
    "dGn": [0.002, 0.005],
    "dGg": [0.01, 0.01],
})

mf32 = make_mf32_mlbw(
    df=df,
    mat=125,
    mt=151,
    awri=235.0439,
    spin=0.5
)

print(mf32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions