From 04501e3213cc81a5fb4f68dbc0f7d78af485cad3 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 13 Jul 2020 22:53:59 -0500 Subject: [PATCH] Move calculation of normalization factor into NormalizationHelper --- openmc/deplete/abc.py | 38 +++++++++++++++++++++++++------------- openmc/deplete/operator.py | 16 +--------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index f07174a95b..2fb85a6771 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -4,16 +4,17 @@ This module contains the Operator class, which is then passed to an integrator to run a full depletion simulation. """ +from abc import ABC, abstractmethod from collections import namedtuple, defaultdict from collections.abc import Iterable, Callable +from copy import deepcopy +from inspect import signature +from numbers import Real, Integral import os from pathlib import Path -from abc import ABC, abstractmethod -from copy import deepcopy -from warnings import warn -from numbers import Real, Integral -from inspect import signature +import sys import time +from warnings import warn from numpy import nonzero, empty, asarray from uncertainties import ufloat @@ -21,6 +22,7 @@ from uncertainties import ufloat from openmc.data import DataLibrary, JOULE_PER_EV from openmc.lib import MaterialFilter, Tally from openmc.checkvalue import check_type, check_greater_than +from . import comm from .results import Results from .chain import Chain from .results_list import ResultsList @@ -317,18 +319,11 @@ class NormalizationHelper(ABC): nuclides : list of str All nuclides with desired reaction rates. Ordered to be consistent with :class:`openmc.deplete.Operator` - energy : float - Total energy [J/s/source neutron] produced in a transport simulation. - Updated in the material iteration with :meth:`update`. + """ def __init__(self): self._nuclides = None - self._energy = 0.0 - - @property - def energy(self): - return self._energy * JOULE_PER_EV def reset(self): """Reset energy produced prior to unpacking tallies""" @@ -371,6 +366,23 @@ class NormalizationHelper(ABC): check_type("nuclides", nuclides, list, str) self._nuclides = nuclides + def factor(self, power): + # Reduce energy produced from all processes + # J / s / source neutron + energy = comm.allreduce(self._energy) * JOULE_PER_EV + + # Guard against divide by zero + if energy == 0: + if comm.rank == 0: + sys.stderr.flush() + print("No energy reported from OpenMC tallies. Do your HDF5 " + "files have heating data?\n", file=sys.stderr, flush=True) + comm.barrier() + comm.Abort(1) + + # Return normalization factor for scaling reaction rates + return power / energy + class FissionYieldHelper(ABC): """Abstract class for processing energy dependent fission yields diff --git a/openmc/deplete/operator.py b/openmc/deplete/operator.py index 05c9cf5e4e..281360634f 100644 --- a/openmc/deplete/operator.py +++ b/openmc/deplete/operator.py @@ -7,7 +7,6 @@ densities is all done in-memory instead of through the filesystem. """ -import sys import copy from collections import OrderedDict import os @@ -677,21 +676,8 @@ class Operator(TransportOperator): # Divide by total number and store rates[i] = self._rate_helper.divide_by_adens(number) - # Reduce energy produced from all processes - # J / s / source neutron - energy = comm.allreduce(self._normalization_helper.energy) - - # Guard against divide by zero - if energy == 0: - if comm.rank == 0: - sys.stderr.flush() - print(" No energy reported from OpenMC tallies. Do your HDF5 " - "files have heating data?\n", file=sys.stderr, flush=True) - comm.barrier() - comm.Abort(1) - # Scale reaction rates to obtain units of reactions/sec - rates *= power / energy + rates *= self._normalization_helper.factor(power) # Store new fission yields on the chain self.chain.fission_yields = fission_yields