From 6c29c394434e2f5acfb78d7080aca73b9c62c66a Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 15 Aug 2016 17:50:03 -0500 Subject: [PATCH] Add check on user-specified bounding boxes for volume calculations --- openmc/volume.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/openmc/volume.py b/openmc/volume.py index e9b1dac1d3..2a2a92f61e 100644 --- a/openmc/volume.py +++ b/openmc/volume.py @@ -1,6 +1,7 @@ from collections import Iterable, Mapping from numbers import Real, Integral from xml.etree import ElementTree as ET +from warnings import warn import numpy as np import pandas as pd @@ -68,10 +69,26 @@ class VolumeCalculation(object): self.samples = samples if lower_left is not None: - self.lower_left = lower_left if upper_right is None: raise ValueError('Both lower-left and upper-right coordinates ' 'should be specified') + + # For cell domains, try to compute bounding box and make sure + # user-specified one is valid + if self.domain_type == 'cell': + for c in domains: + if c.region is None: + continue + ll, ur = c.region.bounding_box + if np.any(np.isinf(ll)) or np.any(np.isinf(ur)): + continue + if (np.any(np.asarray(lower_left) > ll) or + np.any(np.asarray(upper_right) < ur)): + warn("Specified bounding box is smaller than computed " + "bounding box for cell {}. Volume calculation may " + "be incorrect!".format(c.id)) + + self.lower_left = lower_left self.upper_right = upper_right else: if self.domain_type == 'cell':