Merge pull request #1947 from pshriwise/ww-final-tests

Weight windows final push
This commit is contained in:
Paul Romano 2022-01-19 09:13:07 -06:00 committed by GitHub
commit 72af700ffd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 2244 additions and 18 deletions

View file

@ -358,6 +358,10 @@ constexpr int CMFD_NOACCEL {-1};
enum class GeometryType { CSG, DAG };
//==============================================================================
// Variance Reduction constants
constexpr double DEFAULT_WEIGHT_CUTOFF {1.0e-38}; // default low weight cutoff
} // namespace openmc
#endif // OPENMC_CONSTANTS_H

View file

@ -305,6 +305,9 @@ private:
int n_event_ {0}; // number of events executed in this particle's history
// Weight window information
int n_split_ {0}; // Number of splits this particle has undergone
// DagMC state variables
#ifdef DAGMC
moab::DagMC::RayHistory history_;
@ -426,6 +429,9 @@ public:
double& collision_distance() { return collision_distance_; }
int& n_event() { return n_event_; }
int n_split() const { return n_split_; }
int& n_split() { return n_split_; }
#ifdef DAGMC
moab::DagMC::RayHistory& history() { return history_; }
Direction& last_dir() { return last_dir_; }

View file

@ -89,6 +89,11 @@ void inelastic_scatter(const Nuclide& nuc, const Reaction& rx, Particle& p);
void sample_secondary_photons(Particle& p, int i_nuclide);
//Split or Roulette particles based their weight and the lower weight window
// bound.
//! \param[in] p, particle to be split or rouletted with the weight window.
void split_particle(Particle& p);
} // namespace openmc
#endif // OPENMC_PHYSICS_H

View file

@ -55,6 +55,7 @@ extern "C" bool trigger_on; //!< tally triggers enabled?
extern bool trigger_predict; //!< predict batches for triggers?
extern bool ufs_on; //!< uniform fission site method on?
extern bool urr_ptables_on; //!< use unresolved resonance prob. tables?
extern bool weight_windows_on; //!< are weight windows are enabled?
extern bool write_all_tracks; //!< write track files for every particle?
extern bool write_initial_source; //!< write out initial source file?
@ -99,6 +100,7 @@ extern std::unordered_set<int>
statepoint_batch; //!< Batches when state should be written
extern std::unordered_set<int>
source_write_surf_id; //!< Surface ids where sources will be written
extern int max_splits; //!< maximum number of particle splits for weight windows
extern int64_t max_surface_particles; //!< maximum number of particles to be
//!< banked on surfaces per process
extern TemperatureMethod

View file

@ -0,0 +1,99 @@
#ifndef OPENMC_WEIGHT_WINDOWS_H
#define OPENMC_WEIGHT_WINDOWS_H
#include <cstdint>
#include <unordered_map>
#include <hdf5.h>
#include <pugixml.hpp>
#include "openmc/constants.h"
#include "openmc/memory.h"
#include "openmc/mesh.h"
#include "openmc/particle.h"
#include "openmc/vector.h"
namespace openmc {
//==============================================================================
// Non-member functions
//==============================================================================
//! Apply weight windows to a particle
//! \param[in] p Particle to apply weight windows to
void apply_weight_windows(Particle& p);
//! Free memory associated with weight windows
void free_memory_weight_windows();
//==============================================================================
// Global variables
//==============================================================================
class WeightWindows;
namespace variance_reduction {
extern std::unordered_map<int32_t, int32_t> ww_map;
extern vector<unique_ptr<WeightWindows>> weight_windows;
} // namespace variance_reduction
//==============================================================================
//! Individual weight window information
//==============================================================================
struct WeightWindow {
double lower_weight {-1}; // -1 indicates invalid state
double upper_weight {1};
double survival_weight {0.5};
double weight_cutoff {DEFAULT_WEIGHT_CUTOFF};
int max_split {1};
//! Whether the weight window is in a valid state
bool is_valid() const { return lower_weight >= 0.0; }
};
//==============================================================================
//! Weight window settings
//==============================================================================
class WeightWindows {
public:
// Constructors
WeightWindows();
WeightWindows(pugi::xml_node node);
// Methods
//! Set the weight window ID
void set_id(int32_t id = -1);
// NOTE: This is unused for now but may be used in the future
//! Write weight window settings to an HDF5 file
//! \param[in] group HDF5 group to write to
void to_hdf5(hid_t group) const;
//! Retrieve the weight window for a particle
//! \param[in] p Particle to get weight window for
WeightWindow get_weight_window(const Particle& p) const;
// Accessors
int32_t id() const { return id_; }
const Mesh& mesh() const { return *model::meshes[mesh_idx_]; }
private:
// Data members
int32_t id_; //!< Unique ID
ParticleType particle_type_; //!< Particle type to apply weight windows to
vector<double> energy_bins_; //!< Energy bins [eV]
vector<double> lower_ww_; //!< Lower weight window bounds
vector<double> upper_ww_; //!< Upper weight window bounds
double survival_ratio_ {3.0}; //!< Survival weight ratio
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
};
} // namespace openmc
#endif // OPENMC_WEIGHT_WINDOWS_H