Skip to content

Commit ca5e7f3

Browse files
committed
patch mg_cross_sections only when needed
1 parent 8474d05 commit ca5e7f3

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

openmc/model/model.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import Path
77
import math
88
from numbers import Integral, Real
9+
import os
910
import random
1011
import re
1112
from tempfile import NamedTemporaryFile, TemporaryDirectory
@@ -1159,26 +1160,29 @@ def plot(
11591160
x_max = (origin[x] + 0.5*width[0]) * axis_scaling_factor[axis_units]
11601161
y_min = (origin[y] - 0.5*width[1]) * axis_scaling_factor[axis_units]
11611162
y_max = (origin[y] + 0.5*width[1]) * axis_scaling_factor[axis_units]
1163+
1164+
mg_cross_sections = os.devnull
11621165

11631166
# Determine whether any materials contains macroscopic data and if so,
11641167
# set energy mode accordingly and check that mg cross sections path is accessible
11651168
for mat in self.geometry.get_all_materials().values():
11661169
if mat._macroscopic is not None:
11671170
self.settings.energy_mode = 'multi-group'
11681171
try:
1169-
openmc.config['mg_cross_sections'] = Path(openmc.config['mg_cross_sections']).resolve()
1172+
mg_cross_sections = Path(openmc.config['mg_cross_sections']).resolve()
11701173
except KeyError:
11711174
raise RuntimeError("'mg_cross_sections' path must be set before plotting.")
11721175
break
1173-
1174-
# Get ID map from the C API
1175-
id_map = self.id_map(
1176-
origin=origin,
1177-
width=width,
1178-
pixels=pixels,
1179-
basis=basis,
1180-
color_overlaps=show_overlaps
1181-
)
1176+
1177+
with openmc.config.patch('mg_cross_sections', mg_cross_sections):
1178+
# Get ID map from the C API
1179+
id_map = self.id_map(
1180+
origin=origin,
1181+
width=width,
1182+
pixels=pixels,
1183+
basis=basis,
1184+
color_overlaps=show_overlaps
1185+
)
11821186

11831187
# Generate colors if not provided
11841188
if colors is None and seed is not None:

0 commit comments

Comments
 (0)