openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
764 stars 492 forks source link

MicroXS classmethods from_csv() and to_csv() do not work properly #3121

Open MatteoZammataro opened 1 month ago

MatteoZammataro commented 1 month ago

The from_csv and to_csv methods of the MicroXS class only work properly when multiple energy groups are provided. Common methods for generating MicroXS objects, such as from_multigroup_flux or get_micros_and_fluxes, generate only 1 group cross sections. Using to_csv() on a MicroXS object created with either from_multigroup_flux or get_micros_and_fluxes will result in an error because the MicroXS object does not have a "groups" attribute. Similarly, a csv file that was created with the structure of a MicroXS object could not be exported using the from_csv method for the same reason.

paulromano commented 3 weeks ago

@MatteoZammataro I am not able to reproduce the behavior you are describing. When I generate a one-group MicroXS using openmc.deplete.get_micros_and_fluxes, I am able to call to_csv and from_csv on the resulting MicroXS object with no problems. If you have a minimal working example showing what error you are running into, that might help us figure out what's going on.

MatteoZammataro commented 1 week ago

@paulromano You're right. openmc.deplete.get_micros_and_fluxes actually works. I can confirm that I am still having the same problem with openmc.deplete.MicroXS.from_multigroup_flux.

Please see below for a minimal working example of this:

import openmc
import openmc.deplete
import numpy as np
openmc.config["chain_file"] = ''
openmc.config['cross_sections'] = ''

# Superphenix spectrum from FISPACT II reference input spectra
flux_in_each_group=[6.6916e-06, 1.5930e-05, 1.0278e-05, 4.9583e-05, 1.1865e-04, 4.4932e-04,
 1.1509e-03, 1.0233e-03, 1.3668e-03, 4.3450e-03, 6.2777e-03, 8.9414e-03,
 1.2983e-02, 7.8716e-03, 7.3546e-03, 1.6075e-02, 1.8869e-02, 9.6460e-03,
 1.0830e-02, 8.7370e-03, 8.6765e-03, 1.2679e-02, 5.9354e-02, 2.0820e-02,
 2.2604e-02, 1.9196e-02, 1.1942e-02, 5.9428e-02, 2.1465e-02, 2.4117e-02,
 6.6600e-02, 9.9250e-02, 2.3013e-02, 5.5682e-02, 4.2858e-02, 3.7873e-02,
 5.2680e-02, 1.5020e-02, 2.4404e-02, 3.0927e-03, 1.9771e-02, 4.3238e-02,
 6.9037e-03, 2.8554e-02, 1.6334e-02, 9.9194e-03, 1.5689e-02, 5.0276e-03,
 9.8235e-03, 1.0352e-03, 8.0593e-03, 3.0671e-03, 1.0712e-02, 1.8188e-03,
 4.5980e-03, 4.7832e-03, 2.1305e-03, 3.3856e-03, 1.4445e-03, 3.3809e-03,
 1.1162e-03, 7.1226e-04, 8.7168e-04, 3.7131e-04, 7.6017e-05, 1.5291e-04,
 3.5405e-05, 1.2587e-05, 9.4876e-06, 2.6135e-06, 1.8039e-06, 1.3416e-06,
 1.4864e-06, 5.5203e-07, 4.0242e-07, 4.4897e-07, 5.2181e-07, 6.9533e-07,
 6.8661e-07, 2.8834e-07, 4.7287e-07, 3.3985e-07, 7.8695e-07, 4.6730e-07,
 7.8391e-07, 1.1686e-06, 5.9794e-07, 4.0174e-07, 1.0388e-06, 5.3492e-07,
 1.8093e-06, 4.5305e-07, 2.4485e-06, 6.3356e-07, 2.3720e-06, 2.0380e-07,
 2.9716e-07, 2.4077e-07, 6.8430e-07, 8.4857e-07, 1.2475e-07, 2.8831e-07,
 3.0207e-07, 2.7637e-07, 2.5283e-07, 2.1512e-07, 1.7903e-07, 1.6596e-07,
 3.9129e-08, 4.8623e-08, 7.3567e-08, 2.4991e-08, 2.1283e-08, 2.2296e-08,
 9.9792e-09, 1.2369e-09, 7.8823e-10, 1.5931e-10, 9.2887e-11, 8.9650e-11,
 5.0372e-11, 1.8049e-11, 3.0414e-11, 9.3776e-11, 1.2764e-10, 2.6496e-10,
 6.7639e-10, 9.1311e-10, 1.1903e-09, 4.0771e-09, 1.0007e-09, 7.4217e-09,
 1.4615e-09, 1.2589e-08, 1.5295e-08, 1.5206e-08, 6.3913e-09, 2.1452e-09,
 6.0147e-09, 2.5561e-09, 5.2676e-10, 1.5831e-09, 5.7392e-10, 7.7623e-11,
 1.8322e-10, 2.3127e-10, 4.6483e-10, 6.3034e-10, 1.0365e-09, 3.6728e-10,
 9.1051e-10, 1.0061e-09, 3.1074e-10, 9.7179e-10, 7.2700e-10, 2.3550e-10,
 7.0990e-10, 1.4459e-10, 4.8869e-10, 4.4278e-10, 3.8838e-10, 3.7584e-10,
 3.1236e-10, 2.1031e-10, 1.9702e-10, 1.8112e-10, 1.6198e-10, 1.3856e-10,
 7.1110e-11, 3.6657e-11, 3.1715e-11, 3.0186e-11]
energies=openmc.mgxs.GROUP_STRUCTURES["XMAS-172"]

micro_xs = openmc.deplete.MicroXS.from_multigroup_flux(
    energies=np.ascontiguousarray(energies),
    multigroup_flux=np.ascontiguousarray(flux_in_each_group[::-1]),
    temperature=294,
    chain_file= openmc.config['chain_file'],
    nuclides=["U235","U238","Pu239","Pu241"])

micro_xs.to_csv("micros_from_mg_flux.csv")

Sorry for the inconvenience. If you have the same problem, it should be possible to solve it with a few modifications to openmc.deplete.MicroXS.from_multigroup_flux.