diff --git a/include/openmc/constants.h b/include/openmc/constants.h index 9c8c391e18..5a099f9562 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -360,7 +360,7 @@ enum class GeometryType { CSG, DAG }; //============================================================================== // Variance Reduction constants -constexpr double WEIGHT_CUTOFF {1.0e-38}; // default low weight cutoff +constexpr double DEFAULT_WEIGHT_CUTOFF {1.0e-38}; // default low weight cutoff } // namespace openmc diff --git a/include/openmc/weight_windows.h b/include/openmc/weight_windows.h index 12059f1cb2..12113d528f 100644 --- a/include/openmc/weight_windows.h +++ b/include/openmc/weight_windows.h @@ -44,14 +44,14 @@ extern vector> weight_windows; //============================================================================== struct WeightWindow { - double lower_weight {-1}; // -1 indicates not valid state + double lower_weight {-1}; // -1 indicates invalid state double upper_weight {1}; double survival_weight {0.5}; - double weight_cutoff {WEIGHT_CUTOFF}; + double weight_cutoff {DEFAULT_WEIGHT_CUTOFF}; int max_split {1}; //! Whether the weight window is in a valid state - operator bool() const { return lower_weight >= 0.0; } + bool is_valid() const { return lower_weight >= 0.0; } }; //============================================================================== @@ -74,7 +74,7 @@ public: //! \param[in] group HDF5 group to write to void to_hdf5(hid_t group) const; - //! Return a weight window at the specified index + //! Retrieve the weight window for a particle //! \param[in] p Particle to get weight window for WeightWindow get_weight_window(const Particle& p) const; @@ -90,7 +90,7 @@ private: vector lower_ww_; //!< Lower weight window bounds vector upper_ww_; //!< Upper weight window bounds double survival_ratio_ {3.0}; //!< Survival weight ratio - double weight_cutoff_ {1.0e-38}; //!< Weight cutoff + double weight_cutoff_ {DEFAULT_WEIGHT_CUTOFF}; //!< Weight cutoff int max_split_ {10}; //!< Maximum value for particle splitting int32_t mesh_idx_; //!< index in meshes vector }; diff --git a/src/weight_windows.cpp b/src/weight_windows.cpp index 885e2733bd..ebdc2d32e4 100644 --- a/src/weight_windows.cpp +++ b/src/weight_windows.cpp @@ -39,11 +39,11 @@ void apply_weight_windows(Particle& p) WeightWindow weight_window; for (const auto& ww : variance_reduction::weight_windows) { weight_window = ww->get_weight_window(p); - if (weight_window) + if (weight_window.is_valid()) break; } // particle is not in any of the ww domains, do nothing - if (!weight_window) + if (!weight_window.is_valid()) return; // get the paramters @@ -74,7 +74,7 @@ void apply_weight_windows(Particle& p) for (int l = 0; l < i_split - 1; l++) { p.create_secondary(weight / n_split, p.u(), p.E(), p.type()); } - // TODO: maybe weight should be weight - sum of child weight + // remaining weight is applied to current particle p.wgt() = weight / n_split; } else if (weight <= weight_window.lower_weight) { @@ -104,7 +104,7 @@ void free_memory_weight_windows() WeightWindows::WeightWindows(pugi::xml_node node) { // Make sure required elements are present - vector required_elems { + const vector required_elems { "id", "particle_type", "energy_bins", "lower_ww_bounds", "upper_ww_bounds"}; for (const auto& elem : required_elems) { if (!check_for_node(node, elem.c_str())) {