Only write threshold to file if used.

This commit is contained in:
Patrick Shriwise 2019-10-05 10:50:32 -05:00
parent 507bc0d933
commit 48fab6dcac
3 changed files with 34 additions and 31 deletions

View file

@ -87,7 +87,7 @@ public:
// Data members
int domain_type_; //!< Type of domain (cell, material, etc.)
size_t n_samples_; //!< Number of samples to use
double trigger_ {-1.0}; //!< Error threshold for domain volumes
double threshold_ {-1.0}; //!< Error threshold for domain volumes
Position lower_left_; //!< Lower-left position of bounding box
Position upper_right_; //!< Upper-right position of bounding box
std::vector<int> domain_ids_; //!< IDs of domains to find volumes of

View file

@ -12,7 +12,7 @@ from uncertainties import ufloat
import openmc
import openmc.checkvalue as cv
_VERSION_VOLUME = 2
_VERSION_VOLUME = 1
class VolumeCalculation(object):
@ -32,7 +32,7 @@ class VolumeCalculation(object):
Upper-right coordinates of bounding box used to sample points. If this
argument is not supplied, an attempt is made to automatically determine
a bounding box.
trigger : float
threshold : float
Threshold for the maxmimum standard deviation of volumes
Attributes
@ -47,7 +47,7 @@ class VolumeCalculation(object):
Lower-left coordinates of bounding box used to sample points
upper_right : Iterable of float
Upper-right coordinates of bounding box used to sample points
trigger : float
threshold : float
Threshold for the maximum standard deviation of volume in the calculation
atoms : dict
Dictionary mapping unique IDs of domains to a mapping of nuclides to
@ -61,10 +61,10 @@ class VolumeCalculation(object):
"""
def __init__(self, domains, samples, lower_left=None,
upper_right=None, trigger=None):
upper_right=None, threshold=None):
self._atoms = {}
self._volumes = {}
self._trigger = None
self._threshold = None
cv.check_type('domains', domains, Iterable,
(openmc.Cell, openmc.Material, openmc.Universe))
@ -78,8 +78,8 @@ class VolumeCalculation(object):
self.samples = samples
if trigger is not None:
self.trigger = trigger
if threshold is not None:
self.threshold = threshold
if lower_left is not None:
if upper_right is None:
@ -132,8 +132,8 @@ class VolumeCalculation(object):
return self._upper_right
@property
def trigger(self):
return self._trigger
def threshold(self):
return self._threshold
@property
def domain_type(self):
@ -182,11 +182,11 @@ class VolumeCalculation(object):
cv.check_length(name, upper_right, 3)
self._upper_right = upper_right
@trigger.setter
def trigger(self, trigger):
name = 'Volume std. dev. trigger'
cv.check_type(name, trigger, Real)
self._trigger = trigger
@threshold.setter
def threshold(self, threshold):
name = 'volume std. dev. threshold'
cv.check_type(name, threshold, Real)
self._threshold = threshold
@volumes.setter
def volumes(self, volumes):
@ -220,11 +220,11 @@ class VolumeCalculation(object):
samples = f.attrs['samples']
lower_left = f.attrs['lower_left']
upper_right = f.attrs['upper_right']
trigger = f.attrs['trigger']
if trigger == -1.0:
trigger = None
try:
threshold = f.attrs['threshold']
except KeyError:
threshold = None
volumes = {}
atoms = {}
ids = []
@ -254,7 +254,7 @@ class VolumeCalculation(object):
domains = [openmc.Universe(uid) for uid in ids]
# Instantiate the class and assign results
vol = cls(domains, samples, lower_left, upper_right, trigger)
vol = cls(domains, samples, lower_left, upper_right, threshold)
vol.volumes = volumes
vol.atoms = atoms
return vol
@ -299,7 +299,7 @@ class VolumeCalculation(object):
ll_elem.text = ' '.join(str(x) for x in self.lower_left)
ur_elem = ET.SubElement(element, "upper_right")
ur_elem.text = ' '.join(str(x) for x in self.upper_right)
if self.trigger:
trigger_elem = ET.SubElement(element, "trigger")
trigger_elem.text = str(self.trigger)
if self.threshold:
threshold_elem = ET.SubElement(element, "threshold")
threshold_elem.text = str(self.threshold)
return element

View file

@ -68,11 +68,11 @@ VolumeCalculation::VolumeCalculation(pugi::xml_node node)
fatal_error(msg);
}
if (check_for_node(node, "trigger")) {
trigger_ = std::stod(get_node_value(node, "trigger"));
if (trigger_ <= 0.0) {
if (check_for_node(node, "threshold")) {
threshold_ = std::stod(get_node_value(node, "threshold"));
if (threshold_ <= 0.0) {
std::stringstream msg;
msg << "Invalid error threshold " << trigger_ << " provided for a volume calculation.";
msg << "Invalid error threshold " << threshold_ << " provided for a volume calculation.";
fatal_error(msg);
}
}
@ -93,7 +93,7 @@ std::vector<VolumeCalculation::Result> VolumeCalculation::execute() const {
std::vector<VolumeCalculation::Result> results = _execute();
// if no std. dev. threshold is set, return these resuls
if (trigger_ == -1.0) { return results; }
if (threshold_ == -1.0) { return results; }
size_t offset = n_samples_;
double max_err;
@ -104,7 +104,7 @@ std::vector<VolumeCalculation::Result> VolumeCalculation::execute() const {
for (const auto& result : results) { max_err = std::max(max_err, result.volume[1]); }
// exit once we're below our error limit
if (max_err <= trigger_) { break; }
if (max_err <= threshold_) { break; }
// perform the calculation
std::vector<VolumeCalculation::Result> tmp = _execute(offset);
@ -336,7 +336,10 @@ void VolumeCalculation::to_hdf5(const std::string& filename,
write_attribute(file_id, "samples", n_samples_);
write_attribute(file_id, "lower_left", lower_left_);
write_attribute(file_id, "upper_right", upper_right_);
write_attribute(file_id, "trigger", trigger_);
if (threshold_ != -1.0) {
write_attribute(file_id, "threshold", threshold_);
}
if (domain_type_ == FILTER_CELL) {
write_attribute(file_id, "domain_type", "cell");
}