From 055842b5cbb2a2d9b7763311c5ce74af29f20e26 Mon Sep 17 00:00:00 2001 From: Shikhar Kumar Date: Thu, 11 Apr 2019 12:38:36 -0400 Subject: [PATCH] Only call statepoint_write from C API if cmfd_run --- include/openmc/settings.h | 1 + openmc/capi/settings.py | 1 + openmc/cmfd.py | 26 +++++++++++++++----------- src/settings.cpp | 1 + src/simulation.cpp | 6 ++++-- src/state_point.cpp | 1 - 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/openmc/settings.h b/include/openmc/settings.h index fc6fea6e7..9dff8f0ea 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -27,6 +27,7 @@ extern bool assume_separate; //!< assume tallies are spatially separate extern bool check_overlaps; //!< check overlaps in geometry? extern bool confidence_intervals; //!< use confidence intervals for results? extern bool create_fission_neutrons; //!< create fission neutrons (fixed source)? +extern "C" bool cmfd_run; //!< is a CMFD run? extern "C" bool dagmc; //!< indicator of DAGMC geometry extern "C" bool entropy_on; //!< calculate Shannon entropy? extern bool legendre_to_tabular; //!< convert Legendre distributions to tabular? diff --git a/openmc/capi/settings.py b/openmc/capi/settings.py index 3dd672354..78794d856 100644 --- a/openmc/capi/settings.py +++ b/openmc/capi/settings.py @@ -18,6 +18,7 @@ _dll.openmc_get_seed.restype = c_int64 class _Settings(object): # Attributes that are accessed through a descriptor batches = _DLLGlobal(c_int32, 'n_batches') + cmfd_run = _DLLGlobal(c_bool, 'cmfd_run') entropy_on = _DLLGlobal(c_bool, 'entropy_on') generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch') inactive = _DLLGlobal(c_int32, 'n_inactive') diff --git a/openmc/cmfd.py b/openmc/cmfd.py index 4fa9c9e8f..bd74341c0 100644 --- a/openmc/cmfd.py +++ b/openmc/cmfd.py @@ -753,6 +753,8 @@ class CMFDRun(object): # Initialize simulation openmc.capi.simulation_init() + openmc.capi.settings.cmfd_run = True + def next_batch(self): # TODO add function description # Initialize CMFD batch @@ -790,7 +792,6 @@ class CMFDRun(object): # Call C API statepoint_write to save source distribution with CMFD # feedback - # TODO don't call statepoint_write in openmc if settings::cmfd_run openmc.capi.statepoint_write(filename=filename) # Append CMFD data to statepoint file using h5py @@ -1119,7 +1120,8 @@ class CMFDRun(object): self._cmfd_on = True # Check to reset tallies - if (self._n_resets > 0 and current_batch in self._reset) or self._reset_every: + if ((self._n_resets > 0 and current_batch in self._reset) + or self._reset_every): self._cmfd_tally_reset() def _execute_cmfd(self): @@ -1417,9 +1419,11 @@ class CMFDRun(object): with np.errstate(divide='ignore', invalid='ignore'): self._weightfactors = (np.divide(self._cmfd_src * norm, sourcecounts, where=div_condition, - out=np.ones_like(self._cmfd_src), dtype=np.float32)) + out=np.ones_like(self._cmfd_src), + dtype=np.float32)) - if not self._feedback or openmc.capi.current_batch() < self._feedback_begin: + if (not self._feedback + or openmc.capi.current_batch() < self._feedback_begin): return # Broadcast weight factors to all procs @@ -1972,9 +1976,9 @@ class CMFDRun(object): self._scatt_rate = np.append(self._scatt_rate, reshape_scattrr, axis=5) - # Compute scattering xs as aggregate of banked scatt_rate over tally window - # divided by flux. Flux dimensionality increased to account for extra - # dimensionality of scattering xs + # Compute scattering xs as aggregate of banked scatt_rate over tally + # window divided by flux. Flux dimensionality increased to account for + # extra dimensionality of scattering xs extended_flux = self._flux[:,:,:,:,np.newaxis] with np.errstate(divide='ignore', invalid='ignore'): self._scattxs = np.divide(np.sum(self._scatt_rate, axis=5), @@ -1999,9 +2003,9 @@ class CMFDRun(object): self._nfiss_rate = np.append(self._nfiss_rate, reshape_nfissrr, axis=5) - # Compute nu-fission xs as aggregate of banked nfiss_rate over tally window - # divided by flux. Flux dimensionality increased to account for extra - # dimensionality of nu-fission xs + # Compute nu-fission xs as aggregate of banked nfiss_rate over tally + # window divided by flux. Flux dimensionality increased to account for + # extra dimensionality of nu-fission xs with np.errstate(divide='ignore', invalid='ignore'): self._nfissxs = np.divide(np.sum(self._nfiss_rate, axis=5), extended_flux, where=extended_flux > 0, @@ -2062,7 +2066,7 @@ class CMFDRun(object): # Reshape and extract only p1 data from tally results as there is # no need for p0 data reshape_p1scattrr = np.swapaxes(p1scattrr.reshape(target_tally_shape), - 0, 2)[:,:,:,1,:,:] + 0, 2)[:,:,:,1,:,:] # p1-scatter rr is flipped in energy axis as tally results are given in # reverse order of energy group diff --git a/src/settings.cpp b/src/settings.cpp index 4c041a080..947fbc90e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -40,6 +40,7 @@ namespace settings { // Default values for boolean flags bool assume_separate {false}; bool check_overlaps {false}; +bool cmfd_run {false}; bool confidence_intervals {false}; bool create_fission_neutrons {true}; bool dagmc {false}; diff --git a/src/simulation.cpp b/src/simulation.cpp index fa565b575..6e375fe9b 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -364,8 +364,10 @@ void finalize_batch() settings::statepoint_batch.insert(simulation::current_batch); } - // Write out state point if it's been specified for this batch - if (contains(settings::statepoint_batch, simulation::current_batch)) { + // Write out state point if it's been specified for this batch and is not + // a CMFD run instance + if (contains(settings::statepoint_batch, simulation::current_batch) + && !settings::cmfd_run) { if (contains(settings::sourcepoint_batch, simulation::current_batch) && settings::source_write && !settings::source_separate) { bool b = true; diff --git a/src/state_point.cpp b/src/state_point.cpp index 66eaf7ffd..9d5a385dc 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -312,7 +312,6 @@ openmc_load_cmfd_tallies(const int* tally_ids, const int* sp_tally_ids) hid_t tallies_group = open_group(file_id, "tallies"); - // TODO pass this in as argument? int n_tallies = 4; for (int i =0; i < n_tallies; i++) { std::string name = "tally " + std::to_string(sp_tally_ids[i]);