Skip to content

Commit 6bea486

Browse files
committed
Merge branch 'develop' into pr-4188; remove CLI test
2 parents 45c7249 + 98bd86f commit 6bea486

7 files changed

Lines changed: 69 additions & 44 deletions

File tree

‎cmake/OpenMCConfig.cmake.in‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ endif()
1111
find_dependency(fmt CONFIG REQUIRED HINTS ${PACKAGE_PREFIX_DIR})
1212
find_dependency(pugixml CONFIG REQUIRED HINTS ${PACKAGE_PREFIX_DIR})
1313

14+
# libopenmc links against HDF5, which may be imported targets (e.g. hdf5-shared)
15+
# when HDF5 was found through its own CMake package
16+
if(NOT DEFINED HDF5_PREFER_PARALLEL)
17+
set(HDF5_PREFER_PARALLEL @HDF5_PREFER_PARALLEL@)
18+
endif()
19+
# Older FindHDF5 versions require C to be enabled for their compiler checks
20+
if(NOT CMAKE_C_COMPILER_LOADED)
21+
enable_language(C)
22+
endif()
23+
find_dependency(HDF5 COMPONENTS C HL)
24+
1425
if(@OPENMC_USE_DAGMC@)
1526
find_dependency(DAGMC REQUIRED HINTS @DAGMC_DIR@)
1627
endif()

‎docs/source/quickinstall.rst‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ you wish) with OpenMC installed.
3535
conda create --name openmc-env openmc
3636
conda activate openmc-env
3737
38-
If you are installing on macOS with an Apple silicon ARM-based processor, you
39-
will also need to specify the `--platform` option:
40-
41-
.. code-block:: sh
42-
43-
conda create --name openmc-env --platform osx-64 openmc
44-
4538
You are now in a conda environment called `openmc-env` that has OpenMC
4639
installed.
4740

‎docs/source/usersguide/install.rst‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ you wish) with OpenMC installed.
3535
conda create --name openmc-env openmc
3636
conda activate openmc-env
3737
38-
If you are installing on macOS with an Apple silicon ARM-based processor, you
39-
will also need to specify the `--platform` option:
40-
41-
.. code-block:: sh
42-
43-
conda create --name openmc-env --platform osx-64 openmc
44-
4538
You are now in a conda environment called `openmc-env` that has OpenMC
4639
installed.
4740

‎openmc/data/reaction.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ def _get_products(ev, mt):
192192
energy[i] = items[1]
193193
lang = items[2]
194194
if lang == 0:
195-
mu.append(Legendre(values))
195+
# Coefficients start at l = 1; a_0 = 1 is implied
196+
mu.append(Legendre(np.insert(values, 0, 1.0)))
196197
elif lang == 12:
197198
mu.append(Tabular(values[::2], values[1::2]))
198199
elif lang == 14:

‎openmc/executor.py‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,36 @@ def _process_CLI_arguments(volume=False, geometry_debug=False, particles=None,
9292
return args
9393

9494

95+
def _get_error_message(output):
96+
"""Truncate a raised exception message from C++ to be applied as a Python exception message
97+
98+
Parameters
99+
----------
100+
output : str
101+
Standard output and standard error of the OpenMC executable
102+
103+
Returns
104+
-------
105+
str
106+
Error message to be applied as Exception text
107+
108+
"""
109+
if 'ERROR: ' in output:
110+
_, _, error_msg = output.partition('ERROR: ')
111+
elif 'what()' in output:
112+
_, _, error_msg = output.partition('what(): ')
113+
elif 'terminating due to uncaught exception of type ' in output:
114+
# libc++ (e.g. macOS) reports "...of type std::runtime_error: msg"
115+
_, _, error_msg = output.partition(
116+
'terminating due to uncaught exception of type ')
117+
_, sep, error_msg = error_msg.partition(': ')
118+
if not sep or not error_msg.strip():
119+
error_msg = 'OpenMC aborted unexpectedly.'
120+
else:
121+
error_msg = 'OpenMC aborted unexpectedly.'
122+
return ' '.join(error_msg.split())
123+
124+
95125
def _run(args, output, cwd):
96126
# Launch a subprocess
97127
p = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE,
@@ -113,17 +143,7 @@ def _run(args, output, cwd):
113143

114144
# Raise an exception if return status is non-zero
115145
if p.returncode != 0:
116-
# Get error message from output and simplify whitespace
117-
output = ''.join(lines)
118-
if 'ERROR: ' in output:
119-
_, _, error_msg = output.partition('ERROR: ')
120-
elif 'what()' in output:
121-
_, _, error_msg = output.partition('what(): ')
122-
else:
123-
error_msg = 'OpenMC aborted unexpectedly.'
124-
error_msg = ' '.join(error_msg.split())
125-
126-
raise RuntimeError(error_msg)
146+
raise RuntimeError(_get_error_message(''.join(lines)))
127147

128148

129149
def plot_geometry(output=True, openmc_exec='openmc', cwd='.', path_input=None):

‎openmc/model/model.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,10 +1472,8 @@ def plot(
14721472
**contour_kwargs
14731473
)
14741474

1475-
# If only showing outline, set the axis limits and aspect explicitly
1475+
# If only showing outline, set the aspect explicitly
14761476
if outline == 'only':
1477-
axes.set_xlim(x_min, x_max)
1478-
axes.set_ylim(y_min, y_max)
14791477
axes.set_aspect('equal')
14801478

14811479
# Add legend showing which colors represent which material or cell
@@ -1532,6 +1530,10 @@ def plot(
15321530
ys.append(particle.r[y] * axis_scaling_factor[axis_units])
15331531
axes.scatter(xs, ys, **source_kwargs)
15341532

1533+
# Keep the requested view even when source points lie outside it.
1534+
axes.set_xlim(x_min, x_max)
1535+
axes.set_ylim(y_min, y_max)
1536+
15351537
return axes
15361538

15371539
def sample_external_source(

‎tests/unit_tests/test_executor.py‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
from pathlib import Path
1+
from openmc.executor import _get_error_message
2+
import pytest
23

3-
from openmc.executor import _process_CLI_arguments
44

5-
6-
def test_process_cli_arguments_path_input_str(tmp_path):
7-
# _process_CLI_arguments must return a list of str: openmc.lib.init
8-
# calls .encode() on each argument (#4185)
9-
args = list(_process_CLI_arguments(path_input=str(tmp_path)))
10-
assert args[-1] == str(tmp_path)
11-
assert all(isinstance(arg, str) for arg in args)
12-
13-
14-
def test_process_cli_arguments_path_input_pathlike(tmp_path):
15-
args = list(_process_CLI_arguments(path_input=Path(tmp_path)))
16-
assert args[-1] == str(tmp_path)
17-
assert all(isinstance(arg, str) for arg in args)
5+
@pytest.mark.parametrize('output, message', [
6+
# OpenMC's own error messages
7+
(' ERROR: Could not add nuclide', 'Could not add nuclide'),
8+
# libstdc++ (e.g. Linux)
9+
("terminate called after throwing an instance of 'std::runtime_error'\n"
10+
" what(): Could not add nuclide", 'Could not add nuclide'),
11+
# libc++ (e.g. macOS)
12+
('libc++abi: terminating due to uncaught exception of type '
13+
'std::runtime_error: Could not add nuclide', 'Could not add nuclide'),
14+
# libc++ with an exception that has no message
15+
('libc++abi: terminating due to uncaught exception of type int',
16+
'OpenMC aborted unexpectedly.'),
17+
# Any other failure
18+
('Segmentation fault', 'OpenMC aborted unexpectedly.'),
19+
])
20+
def test_error_message_from_output(output, message):
21+
"""The error message is recovered from each way OpenMC can fail."""
22+
assert _get_error_message(output) == message

0 commit comments

Comments
 (0)