Skip to content

Commit 3ac64d9

Browse files
authored
Random Ray Base Source Region Refactor (#3576)
1 parent feefcc6 commit 3ac64d9

File tree

17 files changed

+690
-436
lines changed

17 files changed

+690
-436
lines changed

include/openmc/constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ constexpr double MIN_HITS_PER_BATCH {1.5};
6868
// prevent extremely large adjoint source terms from being generated.
6969
constexpr double ZERO_FLUX_CUTOFF {1e-22};
7070

71+
// The minimum macroscopic cross section value considered non-void for the
72+
// random ray solver. Materials with any group with a cross section below this
73+
// value will be converted to pure void.
74+
constexpr double MINIMUM_MACRO_XS {1e-6};
75+
7176
// ============================================================================
7277
// MATH AND PHYSICAL CONSTANTS
7378

include/openmc/random_ray/flat_source_domain.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class FlatSourceDomain {
2727

2828
//----------------------------------------------------------------------------
2929
// Methods
30-
virtual void update_neutron_source(double k_eff);
31-
double compute_k_eff(double k_eff_old) const;
30+
virtual void update_single_neutron_source(SourceRegionHandle& srh);
31+
virtual void update_all_neutron_sources();
32+
void compute_k_eff();
3233
virtual void normalize_scalar_flux_and_volumes(
3334
double total_active_distance_per_iteration);
3435

@@ -41,7 +42,7 @@ class FlatSourceDomain {
4142
void output_to_vtk() const;
4243
void convert_external_sources();
4344
void count_external_source_regions();
44-
void set_adjoint_sources(const vector<double>& forward_flux);
45+
void set_adjoint_sources();
4546
void flux_swap();
4647
virtual double evaluate_flux_at_point(Position r, int64_t sr, int g) const;
4748
double compute_fixed_source_normalization_factor() const;
@@ -54,9 +55,8 @@ class FlatSourceDomain {
5455
bool is_target_void);
5556
void apply_mesh_to_cell_and_children(int32_t i_cell, int32_t mesh_idx,
5657
int32_t target_material_id, bool is_target_void);
57-
void prepare_base_source_regions();
5858
SourceRegionHandle get_subdivided_source_region_handle(
59-
int64_t sr, int mesh_bin, Position r, double dist, Direction u);
59+
SourceRegionKey sr_key, Position r, Direction u);
6060
void finalize_discovered_source_regions();
6161
void apply_transport_stabilization();
6262
int64_t n_source_regions() const
@@ -67,6 +67,10 @@ class FlatSourceDomain {
6767
{
6868
return source_regions_.n_source_regions() * negroups_;
6969
}
70+
int64_t lookup_base_source_region_idx(const GeometryState& p) const;
71+
SourceRegionKey lookup_source_region_key(const GeometryState& p) const;
72+
int64_t lookup_mesh_bin(int64_t sr, Position r) const;
73+
int lookup_mesh_idx(int64_t sr) const;
7074

7175
//----------------------------------------------------------------------------
7276
// Static Data members
@@ -86,6 +90,7 @@ class FlatSourceDomain {
8690

8791
//----------------------------------------------------------------------------
8892
// Public Data members
93+
double k_eff_ {1.0}; // Eigenvalue
8994
bool mapped_all_tallies_ {false}; // If all source regions have been visited
9095

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

113-
// Base source region container. When source region subdivision via mesh
114-
// is in use, this container holds the original (non-subdivided) material
115-
// filled cell instance source regions. These are useful as they can be
116-
// initialized with external source and mesh domain information ahead of time.
117-
// Then, dynamically discovered source regions can be initialized by cloning
118-
// their base region.
119-
SourceRegionContainer base_source_regions_;
120-
121118
// Parallel hash map holding all source regions discovered during
122119
// a single iteration. This is a threadsafe data structure that is cleaned
123120
// out after each iteration and stored in the "source_regions_" container.
@@ -134,8 +131,17 @@ class FlatSourceDomain {
134131
// Map that relates a SourceRegionKey to the external source index. This map
135132
// is used to check if there are any point sources within a subdivided source
136133
// region at the time it is discovered.
137-
std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>
138-
point_source_map_;
134+
std::unordered_map<SourceRegionKey, vector<int>, SourceRegionKey::HashFunctor>
135+
external_point_source_map_;
136+
137+
// Map that relates a base source region index to the external source index.
138+
// This map is used to check if there are any volumetric sources within a
139+
// subdivided source region at the time it is discovered.
140+
std::unordered_map<int64_t, vector<int>> external_volumetric_source_map_;
141+
142+
// Map that relates a base source region index to a mesh index. This map
143+
// is used to check which subdivision mesh is present in a source region.
144+
std::unordered_map<int64_t, int> mesh_map_;
139145

140146
// If transport corrected MGXS data is being used, there may be negative
141147
// in-group scattering cross sections that can result in instability in MOC
@@ -147,12 +153,11 @@ class FlatSourceDomain {
147153
//----------------------------------------------------------------------------
148154
// Methods
149155
void apply_external_source_to_source_region(
150-
Discrete* discrete, double strength_factor, SourceRegionHandle& srh);
151-
void apply_external_source_to_cell_instances(int32_t i_cell,
152-
Discrete* discrete, double strength_factor, int target_material_id,
153-
const vector<int32_t>& instances);
154-
void apply_external_source_to_cell_and_children(int32_t i_cell,
155-
Discrete* discrete, double strength_factor, int32_t target_material_id);
156+
int src_idx, SourceRegionHandle& srh);
157+
void apply_external_source_to_cell_instances(int32_t i_cell, int src_idx,
158+
int target_material_id, const vector<int32_t>& instances);
159+
void apply_external_source_to_cell_and_children(
160+
int32_t i_cell, int src_idx, int32_t target_material_id);
156161
virtual void set_flux_to_flux_plus_source(int64_t sr, double volume, int g);
157162
void set_flux_to_source(int64_t sr, int g);
158163
virtual void set_flux_to_old_flux(int64_t sr, int g);

include/openmc/random_ray/linear_source_domain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LinearSourceDomain : public FlatSourceDomain {
2020
public:
2121
//----------------------------------------------------------------------------
2222
// Methods
23-
void update_neutron_source(double k_eff) override;
23+
void update_single_neutron_source(SourceRegionHandle& srh) override;
2424
void normalize_scalar_flux_and_volumes(
2525
double total_active_distance_per_iteration) override;
2626

include/openmc/random_ray/random_ray.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class RandomRay : public Particle {
4848
static double distance_active_; // Active ray length
4949
static unique_ptr<Source> ray_source_; // Starting source for ray sampling
5050
static RandomRaySourceShape source_shape_; // Flag for linear source
51-
static bool mesh_subdivision_enabled_; // Flag for mesh subdivision
5251
static RandomRaySampleMethod sample_method_; // Flag for sampling method
5352

5453
//----------------------------------------------------------------------------

include/openmc/random_ray/random_ray_simulation.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ class RandomRaySimulation {
2121
// Methods
2222
void compute_segment_correction_factors();
2323
void apply_fixed_sources_and_mesh_domains();
24-
void prepare_fixed_sources_adjoint(vector<double>& forward_flux,
25-
SourceRegionContainer& forward_source_regions,
26-
SourceRegionContainer& forward_base_source_regions,
27-
std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>&
28-
forward_source_region_map);
24+
void prepare_fixed_sources_adjoint();
2925
void simulate();
3026
void output_simulation_results() const;
3127
void instability_check(
@@ -45,9 +41,6 @@ class RandomRaySimulation {
4541
// Contains all flat source region data
4642
unique_ptr<FlatSourceDomain> domain_;
4743

48-
// Random ray eigenvalue
49-
double k_eff_ {1.0};
50-
5144
// Tracks the average FSR miss rate for analysis and reporting
5245
double avg_miss_rate_ {0.0};
5346

include/openmc/random_ray/source_region.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ class SourceRegion {
308308
//----------------------------------------------------------------------------
309309
// Constructors
310310
SourceRegion(int negroups, bool is_linear);
311-
SourceRegion(const SourceRegionHandle& handle, int64_t parent_sr);
312311
SourceRegion() = default;
313312

314313
//----------------------------------------------------------------------------

0 commit comments

Comments
 (0)