|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import lxml.etree as ET |
2 | 4 | import numpy as np |
3 | 5 | import openmc |
@@ -104,6 +106,43 @@ def test_plot(run_in_tmpdir, sphere_model): |
104 | 106 | plt.close('all') |
105 | 107 |
|
106 | 108 |
|
| 109 | +def test_mg_plot(run_in_tmpdir): |
| 110 | + # Create a simple universe with macroscopic data |
| 111 | + h2o_data = openmc.Macroscopic('LWTR') |
| 112 | + water = openmc.Material(name='Water') |
| 113 | + water.set_density('macro', 1.0) |
| 114 | + water.add_macroscopic(h2o_data) |
| 115 | + sph = openmc.Sphere(r=10, boundary_type="vacuum") |
| 116 | + cell = openmc.Cell(region=-sph, fill=water) |
| 117 | + univ = openmc.Universe(cells=[cell]) |
| 118 | + |
| 119 | + # Create MGXS library and export to HDF5 |
| 120 | + groups = openmc.mgxs.EnergyGroups([1e-5, 20.0e6]) |
| 121 | + h2o_xsdata = openmc.XSdata('LWTR', groups) |
| 122 | + h2o_xsdata.order = 0 |
| 123 | + h2o_xsdata.set_total([1.0]) |
| 124 | + h2o_xsdata.set_absorption([0.5]) |
| 125 | + scatter_matrix = np.array([[[0.5]]]) |
| 126 | + scatter_matrix = np.rollaxis(scatter_matrix, 0, 3) |
| 127 | + h2o_xsdata.set_scatter_matrix(scatter_matrix) |
| 128 | + mg_library = openmc.MGXSLibrary(groups) |
| 129 | + mg_library.add_xsdatas([h2o_xsdata]) |
| 130 | + mgxs_path = Path.cwd() / 'mgxs.h5' |
| 131 | + mg_library.export_to_hdf5(mgxs_path) |
| 132 | + |
| 133 | + # Set MG cross sections in config and plot |
| 134 | + with openmc.config.patch('mg_cross_sections', mgxs_path): |
| 135 | + univ.plot(width=(200, 200), basis='yz', color_by='cell') |
| 136 | + univ.plot(width=(200, 200), basis='yz', color_by='material') |
| 137 | + |
| 138 | + with pytest.raises(RuntimeError): |
| 139 | + univ.plot(width=(200, 200), basis='yz', color_by='cell') |
| 140 | + |
| 141 | + # Close plots to avoid warning |
| 142 | + import matplotlib.pyplot as plt |
| 143 | + plt.close('all') |
| 144 | + |
| 145 | + |
107 | 146 | def test_get_nuclides(uo2): |
108 | 147 | c = openmc.Cell(fill=uo2) |
109 | 148 | univ = openmc.Universe(cells=[c]) |
|
0 commit comments