diff --git a/notebooks/notebook_proccess_xs_with_only_MF32.ipynb b/notebooks/notebook_proccess_xs_with_only_MF32.ipynb new file mode 100644 index 00000000..0644c252 --- /dev/null +++ b/notebooks/notebook_proccess_xs_with_only_MF32.ipynb @@ -0,0 +1,96 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import sandy" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "endf6 = sandy.get_endf6_file(\"jeff_33\", \"xs\", 170350)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Process total, elastic and capture cross section with only MF = 32 section:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "out = endf6.get_errorr(verbose=True, mt_rlm=[1, 2, 102])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "xs = out.get_xs()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots(figsize=(7, 3.5), dpi=100)\n", + "xs.data.index = xs.data.index.right\n", + "xs.data.plot(logx=True, logy=True, alpha=0.8, linewidth=0.9, ax=ax)\n", + "ax.set_ylabel(\"cross section / b\")\n", + "ax.set_xlabel(\"energy / eV\")\n", + "fig.tight_layout()" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "d167b81dab4cfdd7e83bd7f0413ce20e956b35802f4873808516fc813094dcfb" + }, + "kernelspec": { + "display_name": "Python 3.7.10 ('sandy-devel')", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.10" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/sandy/core/endf6.py b/sandy/core/endf6.py index 4a3ec186..07442509 100644 --- a/sandy/core/endf6.py +++ b/sandy/core/endf6.py @@ -1673,6 +1673,11 @@ def get_errorr(self, **kwargs : `dict` keyword argument to pass to `sandy.njoy.process`. + Parameters to insert dummy MF=33 file + ------------------------------------- + mt_rlm: `int` or `list` + mt number to be reconstructed with RML methods. + Parameters for RECONR --------------------- err : `float`, optional @@ -1707,7 +1712,7 @@ def get_errorr(self, processing for resonance parameter covariances (default is 1, 1% sensitivity method) mt: `int` or iterable of `int`, optional - list of MT reactions to be processed + list of xs MT reactions to be processed .. note:: this list will be used for all covariance types, i.e., MF31, MF33, MF34, MF35. @@ -1868,7 +1873,13 @@ def get_errorr(self, 12 / 1.00000e-05 3.00000e-02 5.80000e-02 1.40000e-01 2.80000e-01 3.50000e-01 6.25000e-01 4.00000e+00 4.80520e+01 5.53000e+03 8.21000e+05 2.23100e+06 1.00000e+07 / 3/ + 3 452 'nu' / + 3 455 'nu' / + 3 456 'nu' / 3 251 'mubar' / + 3 252 'xi' / + 3 253 'gamma' / + 3 259 '1_v' / 5/ 5 18 'chi' / 0/ @@ -2046,7 +2057,7 @@ def get_errorr(self, kwds_njoy.update(cov_info) # Mandatory groupr module activation - groupr_ = True if (kwds_njoy["nubar"] or kwds_njoy["chi"] or "ek_groupr" in kwds_njoy or "spectrum_groupr" in kwds_njoy) else groupr + groupr_ = True if (kwds_njoy["nubar"] or kwds_njoy["chi"] or "ek_groupr" in kwds_njoy or "spectrum_groupr" in kwds_njoy or kwds_njoy['urr']) else groupr with TemporaryDirectory() as td: endf6file = os.path.join(td, "endf6_file") @@ -2116,7 +2127,7 @@ def get_gendf(self, mubar : `bool`, optional Proccess multigroup mubar (default is `False`) mt: `int` or iterable of `int`, optional - run groupr only for the selected MT numbers + run groupr for xs for the selected MT numbers nubar : `bool`, optional Proccess multigroup nubar (default is `False`) nuclide_production : `bool`, optional @@ -2314,7 +2325,54 @@ def get_gendf(self, 12 / 1.00000e-05 3.00000e-02 5.80000e-02 1.40000e-01 2.80000e-01 3.50000e-01 6.25000e-01 4.00000e+00 4.80520e+01 5.53000e+03 8.21000e+05 2.23100e+06 1.00000e+07 / 3/ + 3 452 'nu' / + 3 455 'nu' / + 3 456 'nu' / 3 251 'mubar' / + 3 252 'xi' / + 3 253 'gamma' / + 3 259 '1_v' / + 5/ + 5 18 'chi' / + 0/ + 0/ + moder + -24 32 / + stop + + U-238 for selected mt: + >>> out = endf6.get_gendf(mt=[18, 102], ek_groupr=sandy.energy_grids.CASMO12, verbose=True, err=1, nubar=True, mubar=True, chi=True) + moder + 20 -21 / + reconr + -21 -22 / + 'sandy runs njoy'/ + 9237 0 0 / + 1 0. / + 0/ + broadr + -21 -22 -23 / + 9237 1 0 0 0. / + 1 / + 293.6 / + 0 / + groupr + -21 -23 0 -24 / + 9237 1 0 2 0 1 1 0 / + 'sandy runs groupr' / + 293.6/ + 10000000000.0/ + 12 / + 1.00000e-05 3.00000e-02 5.80000e-02 1.40000e-01 2.80000e-01 3.50000e-01 6.25000e-01 4.00000e+00 4.80520e+01 5.53000e+03 8.21000e+05 2.23100e+06 1.00000e+07 / + 3 18 / + 3 102 / + 3 452 'nu' / + 3 455 'nu' / + 3 456 'nu' / + 3 251 'mubar' / + 3 252 'xi' / + 3 253 'gamma' / + 3 259 '1_v' / 5/ 5 18 'chi' / 0/ @@ -2382,10 +2440,11 @@ def get_gendf(self, kwds_njoy["acer"] = False kwds_njoy["keep_pendf"] = False - kwds_njoy["nubar"] = nubar - kwds_njoy["xs"] = xs - kwds_njoy["chi"] = chi - kwds_njoy["mubar"] = mubar + cov_info = self.covariance_info(nubar=nubar, xs=xs, + mubar=mubar, chi=chi) + if not np.any(list(cov_info.values())): + return # no covariance found or wanted + kwds_njoy.update(cov_info) with TemporaryDirectory() as td: endf6file = os.path.join(td, "endf6_file") @@ -2438,32 +2497,33 @@ def covariance_info(self, nubar=True, xs=True, mubar=True, chi=True): Check file contatining MF31, MF33, MF34 and MF35 >>> endf6 = sandy.get_endf6_file('jeff_33', 'xs', 922380) >>> endf6.covariance_info() - {'nubar': True, 'xs': True, 'mubar': True, 'chi': True} + {'nubar': True, 'xs': True, 'mubar': True, 'chi': True, 'urr': False} Set all values to `False` >>> endf6.covariance_info(xs=False, mubar=False, chi=False, nubar=False) - {'nubar': False, 'xs': False, 'mubar': False, 'chi': False} + {'nubar': False, 'xs': False, 'mubar': False, 'chi': False, 'urr': False} 2nd example without MF34 >>> endf6 = sandy.get_endf6_file('jeff_33', 'xs', 922350) >>> endf6.covariance_info() - {'nubar': True, 'xs': True, 'mubar': False, 'chi': True} + {'nubar': True, 'xs': True, 'mubar': False, 'chi': True, 'urr': False} If MF34 is not found, setting `mubar=True` won't change anything' >>> endf6 = sandy.get_endf6_file('jeff_33', 'xs', 922350) >>> endf6.covariance_info(mubar=True) - {'nubar': True, 'xs': True, 'mubar': False, 'chi': True} + {'nubar': True, 'xs': True, 'mubar': False, 'chi': True, 'urr': False} All infos are `False` if no covariance is found >>> endf6 = sandy.get_endf6_file('jeff_33', 'xs', 10030) >>> endf6.covariance_info() - {'nubar': False, 'xs': False, 'mubar': False, 'chi': False} + {'nubar': False, 'xs': False, 'mubar': False, 'chi': False, 'urr': False} """ - supported_mf = [31, 33, 34, 35] + supported_mf = [31, 32, 33, 34, 35] endf6_cov_mf = self.to_series().index.get_level_values("MF")\ .intersection(supported_mf) run_nubar = True if 31 in endf6_cov_mf else False + run_urr = True if 32 in endf6_cov_mf else False run_xs = True if 33 in endf6_cov_mf else False run_mubar = True if 34 in endf6_cov_mf else False run_chi = True if 35 in endf6_cov_mf else False @@ -2473,5 +2533,6 @@ def covariance_info(self, nubar=True, xs=True, mubar=True, chi=True): 'xs': run_xs if xs else False, 'mubar': run_mubar if mubar else False, 'chi': run_chi if chi else False, + 'urr': run_urr if not run_xs else False, } return cov_info diff --git a/sandy/errorr.py b/sandy/errorr.py index dbd6e23e..217af6dd 100644 --- a/sandy/errorr.py +++ b/sandy/errorr.py @@ -131,21 +131,30 @@ def get_xs(self, **kwargs): data = pd.concat(data, axis=1).fillna(0) return sandy.Xs(data) - def get_cov(self, multigroup=True): + def get_cov(self, multigroup=True, mf=None): """ Extract cross section/nubar covariance from `Errorr` instance. + Parameters + ---------- + multigroup : `bool`, optional + Option that allows to show the results in multigroup structure. The + default is True. + mf : `int` or `list`, optional + MF number. The default are the available in the `Errorr` object. + Returns ------- - data : `sandy CategoryCov` - xs/nubar covariance matrix for all cross section/nubar - MAT/MT in ERRORR file. + data : `sandy.CategoryCov` or `dict` + covariance matrix for the selected mf. If more thant one mf is + selected, it returns a `dict` with mf number as key and the + `sandy.CategoryCov` as value. Examples -------- >>> endf6 = sandy.get_endf6_file("jeff_33", "xs", 10010) >>> err = endf6.get_errorr(ek_errorr=[1e-2, 1e1, 2e7], err=1) - >>> err.get_cov().data + >>> err.get_cov(mf=33).data MAT1 125 MT1 1 2 102 E1 (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0] @@ -157,7 +166,7 @@ def get_cov(self, multigroup=True): 102 (0.01, 10.0] 1.07035e-06 7.58742e-09 0.00000e+00 0.00000e+00 6.51764e-04 3.40163e-04 (10.0, 20000000.0] 5.58627e-07 1.49541e-06 0.00000e+00 0.00000e+00 3.40163e-04 6.70431e-02 - >>> err.get_cov(multigroup=False).data + >>> err.get_cov(multigroup=False, mf=33).data MAT1 125 MT1 1 2 102 E1 1.00000e-02 1.00000e+01 2.00000e+07 1.00000e-02 1.00000e+01 2.00000e+07 1.00000e-02 1.00000e+01 2.00000e+07 @@ -170,37 +179,110 @@ def get_cov(self, multigroup=True): 2.00000e+07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 102 1.00000e-02 1.07035e-06 7.58742e-09 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 6.51764e-04 3.40163e-04 0.00000e+00 1.00000e+01 5.58627e-07 1.49541e-06 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 3.40163e-04 6.70431e-02 0.00000e+00 - 2.00000e+07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 + 2.00000e+07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 + + Selected mf: + >>> endf6 = sandy.get_endf6_file('jeff_33','xs', 922350) + >>> out = endf6.get_errorr(err=1, xs=False, mubar=False, chi=False, nubar=True, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7]) + >>> nubar = out.get_cov(mf=[31]).data + >>> nubar + MAT1 9228 + MT1 456 + E1 (0.01, 10.0] (10.0, 20000000.0] + MAT MT E + 9228 456 (0.01, 10.0] 3.15367e-05 1.41334e-05 + (10.0, 20000000.0] 1.41334e-05 1.64304e-05 + + Automatic mf selection: + >>> assert out.get_cov().data.equals(nubar) + + mf=[31, 33]: + >>> out = endf6.get_errorr(err=1, xs=True, mubar=False, chi=False, nubar=True, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7]) + >>> cov = out.get_cov() + >>> assert cov[31].data.equals(nubar) + >>> cov[33].data.loc[(9228, 2), (9228, 18)] + E1 (0.01, 10.0] (10.0, 20000000.0] + E + (0.01, 10.0] -4.49435e-05 -2.13654e-08 + (10.0, 20000000.0] -4.86857e-10 -2.68869e-05 + + + Test all the mf: + >>> endf6 = sandy.get_endf6_file('jeff_33','xs', 922380) + >>> out = endf6.get_errorr(err=1, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7]) + >>> cov = out.get_cov() + >>> cov.keys() + dict_keys([33, 34, 35, 31]) + + mt=[452, 455, 456]: + >>> endf6 = sandy.get_endf6_file("jeff_33", "xs", 942410) + >>> out = endf6.get_errorr(err=1, xs=False, mubar=False, chi=False, nubar=True, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7]) + >>> out.get_cov().data + MAT1 9443 + MT1 452 455 456 + E1 (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0] + MAT MT E + 9443 452 (0.01, 10.0] 3.14218e-05 3.23619e-06 1.35750e-05 3.39374e-06 3.15192e-05 3.23578e-06 + (10.0, 20000000.0] 3.23619e-06 2.75936e-05 1.62044e-06 3.32191e-05 3.24501e-06 2.75789e-05 + 455 (0.01, 10.0] 1.35750e-05 1.62044e-06 2.50000e-03 6.24999e-04 0.00000e+00 0.00000e+00 + (10.0, 20000000.0] 3.39374e-06 3.32191e-05 6.24999e-04 1.28125e-02 0.00000e+00 0.00000e+00 + 456 (0.01, 10.0] 3.15192e-05 3.24501e-06 0.00000e+00 0.00000e+00 3.16913e-05 3.25345e-06 + (10.0, 20000000.0] 3.23578e-06 2.75789e-05 0.00000e+00 0.00000e+00 3.25345e-06 2.76506e-05 """ eg = self.get_energy_grid() if multigroup: eg = pd.IntervalIndex.from_breaks(eg) - data = [] - for mat, mf, mt in self.filter_by(listmf=[31, 33]).data: - mf33 = sandy.errorr.read_mf33(self, mat, mt) - for mt1, cov in mf33["COVS"].items(): + + # Select the mf: + if mf is not None: + listmf_ = [mf] if isinstance(mf, int) else mf + else: + listmf_ = list(self.to_series().index.get_level_values("MF") + .intersection([33, 34, 35])) + + data = {mf_: [] for mf_ in listmf_} + # Nubar is in mf=33, so if mf=31 is in the list, mf=33 has to be there + if 31 in listmf_ and 33 not in listmf_: + listmf_.append(33) + listmf_.remove(31) + for mat_, mf_, mt_ in self.filter_by(listmf=listmf_).data: + cov_mf = sandy.errorr.read_cov_mf(self, mat_, mt_, mf_) + for mt1, cov in cov_mf["COVS"].items(): if not multigroup: # add zero row and column at the end of the matrix # (this must be done for ERRORR covariance matrices) cov = np.insert(cov, cov.shape[0], [0]*cov.shape[1], axis=0) cov = np.insert(cov, cov.shape[1], [0]*cov.shape[0], axis=1) idx = pd.MultiIndex.from_product( - [[mat], [mt], eg], + [[mat_], [mt_], eg], names=["MAT", "MT", "E"], ) idx1 = pd.MultiIndex.from_product( - [[mat], [mt1], eg], + [[mat_], [mt1], eg], names=["MAT1", "MT1", "E1"], ) df = pd.DataFrame(cov, index=idx, columns=idx1) \ .stack(level=["MAT1", "MT1", "E1"]) \ .rename("VAL") \ .reset_index() - data.append(df) - data = pd.concat(data) - return sandy.CategoryCov.from_stack(data, index=["MAT", "MT", "E"], - columns=["MAT1", "MT1", "E1"], - values='VAL') + if mt_ == 452 or mt_ == 455 or mt_ == 456: + if 31 in data: + data[31].append(df) + else: + data[31] = [df] + else: + data[mf_].append(df) + cov_dict = {key: sandy.CategoryCov.from_stack( + pd.concat(value), + index=["MAT", "MT", "E"], + columns=["MAT1", "MT1", "E1"], + values='VAL') + for key, value in data.items() if len(value) > 0} + + # If only one mf is calculated, the return is directly the `CategoryCov` object + if len(cov_dict) == 1: + [(key, cov_dict)] = cov_dict.items() + return cov_dict def read_mf1(tape, mat): @@ -277,7 +359,7 @@ def read_mf3(tape, mat, mt): return out -def read_mf33(tape, mat, mt): +def read_cov_mf(tape, mat, mt, mf): """ Parse MAT/MF=33/MT section from `sandy.Errorr` object and return structured content in nested dcitionaries. @@ -294,7 +376,6 @@ def read_mf33(tape, mat, mt): out : `dict` Content of the ENDF-6 tape structured as nested `dict`. """ - mf = 33 df = tape._get_section_df(mat, mf, mt) out = { "MAT": mat, diff --git a/sandy/njoy.py b/sandy/njoy.py index 17654eeb..3af4fc87 100644 --- a/sandy/njoy.py +++ b/sandy/njoy.py @@ -81,6 +81,7 @@ import pdb import tempfile import subprocess as sp +import pytest import pandas as pd import numpy as np @@ -187,6 +188,7 @@ NJOY_TEMPERATURES = [293.6] NJOY_SIG0 = [1e10] NJOY_THERMR_EMAX = 10 +banned_xs = [251, 252, 253, 259, 452, 455, 459] def get_njoy(): @@ -265,6 +267,47 @@ def _moder_input(nin, nout, **kwargs): return "\n".join(text) + "\n" +def _error_input(endfin, pendfin, mt_rlm): + """ + Write dummy ERRORR input. + + Parameters + ---------- + endfin : `int` + tape number for input ENDF-6 file + pendfin : `int` + tape number for input PENDF file + mt_rlm : `int` or `list` + mt in the dummy files. + + Returns + ------- + `str` + errorr input text. + + Examples + -------- + >>> print(sandy.njoy._error_input(20, 21, [1, 2, 102])) + errorr + 999/ + 20 21 / + 1/ + 2/ + 102/ + 0/ + """ + text = ["errorr"] + text += ["999/"] + text += [f"{endfin:d} {pendfin:d} /"] + if mt_rlm is None: + raise SyntaxError("Not mt_rlm introduced") + mtlist = [mt_rlm] if isinstance(mt_rlm, int) else mt_rlm + for mt_ in mtlist: + text += [f"{mt_:d}/"] + text += ["0/"] + return "\n".join(text) + "\n" + + def _reconr_input(endfin, pendfout, mat, header="sandy runs njoy", err=NJOY_TOLER, @@ -635,7 +678,7 @@ def _errorr_input(endfin, pendfin, gendfin, errorrout, mat, mfcov : `int` endf covariance file to be processed (default is 33) mt: `int` or iterable of `int`, optional - run errorr only for the selected mt numbers + run errorr for xs for the selected MT numbers (default is `None`, i.e., process all MT) spectrum_errorr : iterable, optional weight function (default is `None`) @@ -755,10 +798,20 @@ def _errorr_input(endfin, pendfin, gendfin, errorrout, mat, 0 293.6 / 1 33 1/ 1 0 / - 2 / + 2 / + + Test of wrong mt number: + >>> with pytest.raises(SyntaxError): sandy.njoy._errorr_input(20, 21, 0, 22, 9237, mt=455) """ irelco = 0 if relative is False else 1 - iread = 1 if mt is not None else 0 + if mt is not None: + mtlist = [mt] if isinstance(mt, int) else mt + for xs_ban in banned_xs: + if xs_ban in mtlist and mfcov == 33: + raise SyntaxError("Introduced mt are not appropriate for mf=33") + else: + mtlist = [] + iread = 1 if len(mtlist) != 0 and mfcov == 33 else 0 iwt_ = 1 if spectrum_errorr is not None else iwt_errorr ign_ = 1 if ek_errorr is not None else ign_errorr text = ["errorr"] @@ -767,8 +820,7 @@ def _errorr_input(endfin, pendfin, gendfin, errorrout, mat, text += [f"{mat:d} {ign_:d} {iwt_:d} {printflag:d} {irelco} /"] text += [f"{printflag:d} {temp:.1f} /"] text += [f"{iread:d} {mfcov} {irespr:d}/"] - if iread == 1: # only specific mts - mtlist = [mt] if isinstance(mt, int) else mt + if iread == 1 and mfcov == 33: # only specific mts nmt = len(mtlist) text += [f"{nmt:d} 0 /"] text += [" ".join(map(str, mtlist)) + " /"] @@ -792,7 +844,7 @@ def _groupr_input(endfin, pendfin, gendfout, mat, iwt_groupr=2, lord=0, sigz=[1e+10], temp=NJOY_TEMPERATURES[0], spectrum_groupr=None, mt=None, - iprint=False, nubar=False, mubar=False, chi=False, + iprint=False, nubar=False, mubar=False, chi=False, xs=True, nuclide_production=False, **kwargs): """ @@ -808,8 +860,6 @@ def _groupr_input(endfin, pendfin, gendfout, mat, tape number for output PENDF file mat : `int` MAT number - chi : `bool`, optional - Process chi (default is `False`) ek_groupr : iterable, optional derived cross section energy bounds (default is None) ep : iterable, optional @@ -829,12 +879,16 @@ def _groupr_input(endfin, pendfin, gendfout, mat, lord : `int`, optional Legendre order (default is 0) mt: `int` or iterable of `int`, optional - run groupr only for the selected MT numbers + run groupr for xs for the selected MT numbers (default is `None`, i.e., process all MT) + chi : `bool`, optional + Process chi (default is `False`) mubar : `bool`, optional Proccess mubar (default is `False`) nubar : `bool`, optional Proccess nubar (default is `False`) + xs : `bool`, optional + Proccess multigroup xs (default is `True`) nuclide_production : `bool`, optional process MF10 (default is `False`) sigz : iterable of `float` @@ -952,27 +1006,28 @@ def _groupr_input(endfin, pendfin, gendfout, mat, 0/ Test mubar: - >>> print(sandy.njoy._groupr_input(20, 21, 22, 9237, mubar=True)) + >>> print(sandy.njoy._groupr_input(20, 21, 22, 9237, mubar=True, xs=False)) groupr 20 21 0 22 / 9237 2 0 2 0 1 1 0 / 'sandy runs groupr' / 293.6/ 10000000000.0/ - 3/ 3 251 'mubar' / + 3 252 'xi' / + 3 253 'gamma' / + 3 259 '1_v' / 0/ 0/ Test chi: - >>> print(sandy.njoy._groupr_input(20, 21, 22, 9237, chi=True)) + >>> print(sandy.njoy._groupr_input(20, 21, 22, 9237, chi=True, xs=False)) groupr 20 21 0 22 / 9237 2 0 2 0 1 1 0 / 'sandy runs groupr' / 293.6/ 10000000000.0/ - 3/ 5/ 5 18 'chi' / 0/ @@ -1014,7 +1069,10 @@ def _groupr_input(endfin, pendfin, gendfout, mat, 10000000000.0/ 3 2 / 0/ - 0/ + 0/ + + Test the wrong mt number: + >>> with pytest.raises(SyntaxError): sandy.njoy._groupr_input(20, 21, 0, 22, 9237, mt=[102, 455]) """ iwt_ = 1 if spectrum_groupr is not None else iwt_groupr ign_ = 1 if ek_groupr is not None else ign_groupr @@ -1043,14 +1101,26 @@ def _groupr_input(endfin, pendfin, gendfout, mat, spectrum_groupr[1::2])) text += [tab1] text += ["/"] - if mt is None: - text += ["3/"] # by default process all cross sections (MF=3) - else: - mtlist = [mt] if isinstance(mt, int) else mt - for mt_ in mtlist: - text += [f"3 {mt_:d} /"] + if xs: + if mt is None: + text += ["3/"] # by default process all cross sections (MF=3) + else: + mtlist = [mt] if isinstance(mt, int) else mt + for xs_ban in banned_xs: + if xs_ban in mtlist: + raise SyntaxError("Introduced mt are not appropriate for xs") + else: + for mt_ in mtlist: + text += [f"3 {mt_:d} /"] + if nubar: + text += ["3 452 'nu' /"] + text += ["3 455 'nu' /"] + text += ["3 456 'nu' /"] if mubar: text += ["3 251 'mubar' /"] + text += ["3 252 'xi' /"] + text += ["3 253 'gamma' /"] + text += ["3 259 '1_v' /"] if chi: text += ["5/"] text += ["5 18 'chi' /"] @@ -1120,6 +1190,7 @@ def process( errorr=False, groupr=False, acer=True, + urr=False, wdir="", dryrun=False, tag="", @@ -1226,19 +1297,23 @@ def process( inputs["tape20"] = endftape e = 21 p = e + 1 - text = _moder_input(20, -e) + if urr: + text = _error_input(20, e, kwargs["mt_rlm"]) + kwargs['xs'] = True + else: + text = _moder_input(20, -e) if pendftape: inputs["tape99"] = pendftape text += _moder_input(99, -p) else: - text += _reconr_input(-e, -p, **kwargs) + text += _reconr_input(-e, -p, **kwargs) if not urr else _reconr_input(e, p, **kwargs) if broadr: o = p + 1 - text += _broadr_input(-e, -p, -o, **kwargs) + text += _broadr_input(-e, -p, -o, **kwargs) if not urr else _broadr_input(e, p, o, **kwargs) p = o if thermr: o = p + 1 - text += _thermr_input(0, -p, -o, **kwargs) + text += _thermr_input(0, -p, -o, **kwargs) p = o if unresr: o = p + 1 @@ -1270,9 +1345,9 @@ def process( kwargs["temp"] = temp kwargs["suff"] = suff = f".{suff}" g = o + 1 + i - text += _groupr_input(-e, -p, -g, **kwargs) + text += _groupr_input(-e, -p, -g, **kwargs) if not urr else _groupr_input(e, p, g, **kwargs) o = 32 + i - text += _moder_input(-g, o) + text += _moder_input(-g, o) if not urr else _moder_input(g, o, **kwargs) outputs[f"tape{o}"] = join( wdir, f"{outprefix}{tag}{suff}.gendf", @@ -1286,11 +1361,11 @@ def process( kwargs["temp"] = temp kwargs["suff"] = suff = f".{suff}" if groupr: - text += _groupr_input(-e, -p, -g_, **kwargs) + text += _groupr_input(-e, -p, -g_, **kwargs) if not urr else _groupr_input(e, p, g_,**kwargs) if kwargs['nubar']: o = 31 + i * 5 kwargs['mfcov'] = mfcov = 31 - text += _errorr_input(-e, -p_, -g_, o, **kwargs) + text += _errorr_input(-e, -p_, -g_, o, **kwargs) if not urr else _errorr_input(e, p, g_, o,**kwargs) outputs[f"tape{o}"] = join( wdir, f"{outprefix}{tag}{suff}_{mfcov}.errorr", @@ -1298,7 +1373,7 @@ def process( if kwargs['xs']: o = 33 + i * 5 kwargs['mfcov'] = mfcov = 33 - text += _errorr_input(-e, -p_, -g_, o, **kwargs) + text += _errorr_input(-e, -p_, -g_, o, **kwargs) if not urr else _errorr_input(e, p, g_, o,**kwargs) outputs[f"tape{o}"] = join( wdir, f"{outprefix}{tag}{suff}_{mfcov}.errorr", @@ -1308,7 +1383,7 @@ def process( if kwargs['chi']: o = 35 + i * 5 kwargs['mfcov'] = mfcov = 35 - text += _errorr_input(-e, -p_, -g_, o, **kwargs) + text += _errorr_input(-e, -p_, -g_, o, **kwargs) if not urr else _errorr_input(e, p, g_, o,**kwargs) outputs[f"tape{o}"] = join( wdir, f"{outprefix}{tag}{suff}_{mfcov}.errorr", @@ -1316,7 +1391,7 @@ def process( if kwargs['mubar']: o = 34 + i * 5 kwargs['mfcov'] = mfcov = 34 - text += _errorr_input(-e, -p_, -g_, o, **kwargs) + text += _errorr_input(-e, -p_, -g_, o, **kwargs) if not urr else _errorr_input(e, p, g_, o,**kwargs) outputs[f"tape{o}"] = join( wdir, f"{outprefix}{tag}{suff}_{mfcov}.errorr",