Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5b8db46
initial implementation complete. Now for debugging.
jtramm Sep 18, 2025
8719e23
seems to be working
jtramm Sep 18, 2025
e702bbe
finished deleting all references to base source regions
jtramm Sep 19, 2025
2990038
fixed issue with mesh map for point source locator
jtramm Sep 19, 2025
c7df7eb
moved source updates into single SR function, to allow for calling at…
jtramm Sep 19, 2025
d3fd941
moved volume src before pt source to be consistent with original orde…
jtramm Sep 19, 2025
81d3516
fixed bug with adjoints, caused by update_neutron_source not being ca…
jtramm Sep 19, 2025
615e319
removed debug prints
jtramm Sep 19, 2025
e3aa71f
fixed final bug. Issue was with adjoint and meshes, the mesh_map was …
jtramm Sep 19, 2025
1125eb8
removal of forward vs. adjoint top level simulation objects. Now only…
jtramm Sep 19, 2025
9862252
Moving all source region indexing logic into functions to avoid repro…
jtramm Sep 19, 2025
fb037a2
cleanup of comments on source region handle finder
jtramm Sep 19, 2025
5a6f2f2
ran clang format
jtramm Sep 19, 2025
f664451
removed unneeded distance argument, and corrected bug in locking of p…
jtramm Sep 22, 2025
14adca4
ran clang format
jtramm Sep 22, 2025
a2e2adf
removed unneded SourceRegion constructor
jtramm Sep 22, 2025
4a02d16
added check to convert low XS materials to void materials
jtramm Sep 25, 2025
423e106
fixed issue with ray using particle material vs. source region material
jtramm Sep 26, 2025
19d7046
added test for random ray low density flux conversion
jtramm Sep 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/openmc/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ constexpr double MIN_HITS_PER_BATCH {1.5};
// prevent extremely large adjoint source terms from being generated.
constexpr double ZERO_FLUX_CUTOFF {1e-22};

// The minimum macroscopic cross section value considered non-void for the
// random ray solver. Materials with any group with a cross section below this
// value will be converted to pure void.
constexpr double MINIMUM_MACRO_XS {1e-6};

// ============================================================================
// MATH AND PHYSICAL CONSTANTS

Expand Down
47 changes: 26 additions & 21 deletions include/openmc/random_ray/flat_source_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class FlatSourceDomain {

//----------------------------------------------------------------------------
// Methods
virtual void update_neutron_source(double k_eff);
double compute_k_eff(double k_eff_old) const;
virtual void update_single_neutron_source(SourceRegionHandle& srh);
virtual void update_all_neutron_sources();
void compute_k_eff();
virtual void normalize_scalar_flux_and_volumes(
double total_active_distance_per_iteration);

Expand All @@ -41,7 +42,7 @@ class FlatSourceDomain {
void output_to_vtk() const;
void convert_external_sources();
void count_external_source_regions();
void set_adjoint_sources(const vector<double>& forward_flux);
void set_adjoint_sources();
void flux_swap();
virtual double evaluate_flux_at_point(Position r, int64_t sr, int g) const;
double compute_fixed_source_normalization_factor() const;
Expand All @@ -54,9 +55,8 @@ class FlatSourceDomain {
bool is_target_void);
void apply_mesh_to_cell_and_children(int32_t i_cell, int32_t mesh_idx,
int32_t target_material_id, bool is_target_void);
void prepare_base_source_regions();
SourceRegionHandle get_subdivided_source_region_handle(
int64_t sr, int mesh_bin, Position r, double dist, Direction u);
SourceRegionKey sr_key, Position r, Direction u);
void finalize_discovered_source_regions();
void apply_transport_stabilization();
int64_t n_source_regions() const
Expand All @@ -67,6 +67,10 @@ class FlatSourceDomain {
{
return source_regions_.n_source_regions() * negroups_;
}
int64_t lookup_base_source_region_idx(const GeometryState& p) const;
SourceRegionKey lookup_source_region_key(const GeometryState& p) const;
int64_t lookup_mesh_bin(int64_t sr, Position r) const;
int lookup_mesh_idx(int64_t sr) const;

//----------------------------------------------------------------------------
// Static Data members
Expand All @@ -86,6 +90,7 @@ class FlatSourceDomain {

//----------------------------------------------------------------------------
// Public Data members
double k_eff_ {1.0}; // Eigenvalue
bool mapped_all_tallies_ {false}; // If all source regions have been visited

int64_t n_external_source_regions_ {0}; // Total number of source regions with
Expand All @@ -110,14 +115,6 @@ class FlatSourceDomain {
// The abstract container holding all source region-specific data
SourceRegionContainer source_regions_;

// Base source region container. When source region subdivision via mesh
// is in use, this container holds the original (non-subdivided) material
// filled cell instance source regions. These are useful as they can be
// initialized with external source and mesh domain information ahead of time.
// Then, dynamically discovered source regions can be initialized by cloning
// their base region.
SourceRegionContainer base_source_regions_;

// Parallel hash map holding all source regions discovered during
// a single iteration. This is a threadsafe data structure that is cleaned
// out after each iteration and stored in the "source_regions_" container.
Expand All @@ -134,8 +131,17 @@ class FlatSourceDomain {
// Map that relates a SourceRegionKey to the external source index. This map
// is used to check if there are any point sources within a subdivided source
// region at the time it is discovered.
std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>
point_source_map_;
std::unordered_map<SourceRegionKey, vector<int>, SourceRegionKey::HashFunctor>
external_point_source_map_;

// Map that relates a base source region index to the external source index.
// This map is used to check if there are any volumetric sources within a
// subdivided source region at the time it is discovered.
std::unordered_map<int64_t, vector<int>> external_volumetric_source_map_;

// Map that relates a base source region index to a mesh index. This map
// is used to check which subdivision mesh is present in a source region.
std::unordered_map<int64_t, int> mesh_map_;

// If transport corrected MGXS data is being used, there may be negative
// in-group scattering cross sections that can result in instability in MOC
Expand All @@ -147,12 +153,11 @@ class FlatSourceDomain {
//----------------------------------------------------------------------------
// Methods
void apply_external_source_to_source_region(
Discrete* discrete, double strength_factor, SourceRegionHandle& srh);
void apply_external_source_to_cell_instances(int32_t i_cell,
Discrete* discrete, double strength_factor, int target_material_id,
const vector<int32_t>& instances);
void apply_external_source_to_cell_and_children(int32_t i_cell,
Discrete* discrete, double strength_factor, int32_t target_material_id);
int src_idx, SourceRegionHandle& srh);
void apply_external_source_to_cell_instances(int32_t i_cell, int src_idx,
int target_material_id, const vector<int32_t>& instances);
void apply_external_source_to_cell_and_children(
int32_t i_cell, int src_idx, int32_t target_material_id);
virtual void set_flux_to_flux_plus_source(int64_t sr, double volume, int g);
void set_flux_to_source(int64_t sr, int g);
virtual void set_flux_to_old_flux(int64_t sr, int g);
Expand Down
2 changes: 1 addition & 1 deletion include/openmc/random_ray/linear_source_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LinearSourceDomain : public FlatSourceDomain {
public:
//----------------------------------------------------------------------------
// Methods
void update_neutron_source(double k_eff) override;
void update_single_neutron_source(SourceRegionHandle& srh) override;
void normalize_scalar_flux_and_volumes(
double total_active_distance_per_iteration) override;

Expand Down
1 change: 0 additions & 1 deletion include/openmc/random_ray/random_ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class RandomRay : public Particle {
static double distance_active_; // Active ray length
static unique_ptr<Source> ray_source_; // Starting source for ray sampling
static RandomRaySourceShape source_shape_; // Flag for linear source
static bool mesh_subdivision_enabled_; // Flag for mesh subdivision
static RandomRaySampleMethod sample_method_; // Flag for sampling method

//----------------------------------------------------------------------------
Expand Down
9 changes: 1 addition & 8 deletions include/openmc/random_ray/random_ray_simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ class RandomRaySimulation {
// Methods
void compute_segment_correction_factors();
void apply_fixed_sources_and_mesh_domains();
void prepare_fixed_sources_adjoint(vector<double>& forward_flux,
SourceRegionContainer& forward_source_regions,
SourceRegionContainer& forward_base_source_regions,
std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>&
forward_source_region_map);
void prepare_fixed_sources_adjoint();
void simulate();
void output_simulation_results() const;
void instability_check(
Expand All @@ -45,9 +41,6 @@ class RandomRaySimulation {
// Contains all flat source region data
unique_ptr<FlatSourceDomain> domain_;

// Random ray eigenvalue
double k_eff_ {1.0};

// Tracks the average FSR miss rate for analysis and reporting
double avg_miss_rate_ {0.0};

Expand Down
1 change: 0 additions & 1 deletion include/openmc/random_ray/source_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ class SourceRegion {
//----------------------------------------------------------------------------
// Constructors
SourceRegion(int negroups, bool is_linear);
SourceRegion(const SourceRegionHandle& handle, int64_t parent_sr);
SourceRegion() = default;

//----------------------------------------------------------------------------
Expand Down
Loading