Skip to content

Commit 27f4e3b

Browse files
committed
add kinetic simulation machinery
- add some missing precursor tally machinery in reaction.cpp and tally.cpp, and output.cpp - add testing harness for kinetic simulations - remove some unuesd timers - implement time stepping loop in random_ray_simulation.cpp and supporting funtions.
1 parent 9cb7b3f commit 27f4e3b

15 files changed

Lines changed: 610 additions & 73 deletions

include/openmc/random_ray/random_ray.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ class RandomRay : public Particle {
5050
static RandomRaySourceShape source_shape_; // Flag for linear source
5151
static RandomRaySampleMethod sample_method_; // Flag for sampling method
5252

53+
static double avg_miss_rate_; // Average ray miss rate per
54+
// iteration for reporting
55+
static int64_t n_source_regions_; // Total number of source regions
56+
static int64_t
57+
n_external_source_regions_; // Total number of source regions with
58+
// non-zero external source terms
59+
static uint64_t total_geometric_intersections_; // Tracks the total number of
60+
// geometric intersections by
61+
// all rays for reporting
62+
5363
// Kinetic simulation variables
5464
static int bd_order_; // Order of backwards difference approximation for
5565
// time-derivatives
@@ -60,9 +70,13 @@ class RandomRay : public Particle {
6070
//----------------------------------------------------------------------------
6171
// Public data members
6272
vector<float> angular_flux_;
63-
6473
bool ray_trace_only_ {false}; // If true, only perform geometry operations
6574

75+
//---------------------------------------------------------------------------
76+
// Public data members for kinetic simulations
77+
vector<float> angular_flux_td_;
78+
vector<float> angular_flux_td_prime_;
79+
6680
private:
6781
//----------------------------------------------------------------------------
6882
// Private data members
@@ -77,6 +91,12 @@ class RandomRay : public Particle {
7791
double distance_travelled_ {0};
7892
bool is_active_ {false};
7993
bool is_alive_ {true};
94+
95+
//---------------------------------------------------------------------------
96+
// Private data members for kinetic simulations
97+
vector<double> delta_psi_td_;
98+
vector<double> delta_psi_td_prime_;
99+
80100
}; // class RandomRay
81101

82102
} // namespace openmc

include/openmc/random_ray/random_ray_simulation.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ class RandomRaySimulation {
2626
void output_simulation_results() const;
2727
void instability_check(
2828
int64_t n_hits, double k_eff, double& avg_miss_rate) const;
29-
void print_results_random_ray(uint64_t total_geometric_intersections,
30-
double avg_miss_rate, int negroups, int64_t n_source_regions,
31-
int64_t n_external_source_regions) const;
29+
void print_results_random_ray() const;
3230

3331
//----------------------------------------------------------------------------
3432
// Accessors
3533
FlatSourceDomain* domain() const { return domain_.get(); }
3634

3735
private:
3836
//----------------------------------------------------------------------------
39-
// Data members
37+
// Data Members
4038

4139
// Contains all flat source region data
4240
unique_ptr<FlatSourceDomain> domain_;
@@ -51,6 +49,9 @@ class RandomRaySimulation {
5149
// Number of energy groups
5250
int negroups_;
5351

52+
// Number of delay groups
53+
int ndgroups_;
54+
5455
}; // class RandomRaySimulation
5556

5657
//============================================================================
@@ -61,6 +62,15 @@ void openmc_run_random_ray();
6162
void validate_random_ray_inputs();
6263
void openmc_reset_random_ray();
6364

65+
//! Write data related to randaom ray to statepoint
66+
//! \param[in] group HDF5 group
67+
void write_random_ray_hdf5(hid_t group);
68+
69+
// Functions for kinetic simulations
70+
void set_time_dependent_settings();
71+
void rename_statepoint_file(int i);
72+
void rename_tallies_file(int i);
73+
6474
} // namespace openmc
6575

66-
#endif // OPENMC_RANDOM_RAY_SIMULATION_H
76+
#endif // OPENMC_RANDOM_RAY_SIMUgATION_H

include/openmc/simulation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ extern const RegularMesh* ufs_mesh;
4949
extern vector<double> k_generation;
5050
extern vector<int64_t> work_index;
5151

52+
//-----------------------------------------------------------------------------
53+
// Global variables for kinetic simulations
54+
extern double current_time;
55+
5256
} // namespace simulation
5357

5458
//==============================================================================

include/openmc/timer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extern Timer time_event_collision;
3333
extern Timer time_event_death;
3434
extern Timer time_update_src;
3535

36-
extern Timer time_initialize_td;
3736
extern Timer time_update_bd_vectors_td;
3837
extern Timer time_update_src_td;
3938
extern Timer time_compute_precursors;

openmc/examples.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,14 @@ def slab_mg(num_regions=1, mat_names=None, mgxslib_name='2g.h5') -> openmc.Model
656656

657657
return model
658658

659-
def _generate_c5g7_materials(time_dependent) -> openmc.Materials:
659+
def _generate_c5g7_materials(kinetic) -> openmc.Materials:
660660
"""Generate materials utilizing multi-group cross sections based on the
661661
the C5G7 Benchmark.
662662
663663
Parameters
664664
----------
665-
time_dependent : bool
666-
Flag to generate cross sections for a time-dependent model or not.
665+
kinetic : bool
666+
Flag to generate cross sections for kinetic simulations.
667667
668668
Returns
669669
-------
@@ -692,7 +692,7 @@ def _generate_c5g7_materials(time_dependent) -> openmc.Materials:
692692
# come from Hou et al., "OECD/NEA benchmark for time-dependnet neutron
693693
# transport calculations without homogeniztaion"
694694
# DOI: 10.1016/j.nucengdes.2017.02.008
695-
n_dg = C5G7_N_DG if time_dependent else 0
695+
n_dg = C5G7_N_DG if kinetic else 0
696696

697697
# Instantiate the 7-group (C5G7) cross section data
698698
uo2_xsdata = openmc.XSdata('UO2', groups, num_delayed_groups=n_dg)
@@ -728,7 +728,7 @@ def _generate_c5g7_materials(time_dependent) -> openmc.Materials:
728728
0.0000e+00, 0.0000e+00])
729729

730730
# Delayed and prompt cross sections for time-dependent simulation
731-
if time_dependent:
731+
if kinetic:
732732

733733
# Table A2 in Hou et. al
734734
beta = np.array([[2.13333e-04, 2.13333e-04, 2.13333e-04, 2.13333e-04, 2.13333e-04, 2.13333e-04, 2.13333e-04],
@@ -804,7 +804,7 @@ def _generate_c5g7_materials(time_dependent) -> openmc.Materials:
804804
scatter_matrix = np.rollaxis(scatter_matrix, 0, 3)
805805
h2o_xsdata.set_scatter_matrix(scatter_matrix)
806806

807-
if time_dependent:
807+
if kinetic:
808808
# Table A4 in Hou et al.
809809
velocities = np.array([2.23517E+09, 4.98880E+08, 3.84974E+07,
810810
5.12639E+06, 1.67542E+06, 7.26031E+05, 2.81629E+05])
@@ -822,7 +822,7 @@ def _generate_c5g7_materials(time_dependent) -> openmc.Materials:
822822
uo2.set_density('macro', 1.0)
823823
uo2.add_macroscopic('UO2')
824824

825-
if time_dependent:
825+
if kinetic:
826826
densities = np.linspace(1, 0.95, 100)
827827
else:
828828
densities = None
@@ -905,14 +905,14 @@ def _generate_random_ray_pin_cell(uo2, water) -> openmc.Universe:
905905

906906
return pincell
907907

908-
def random_ray_pin_cell(time_dependent=False) -> openmc.Model:
908+
def random_ray_pin_cell(kinetic=False) -> openmc.Model:
909909
"""Create a PWR pin cell example using C5G7 cross section data.
910910
cross section data.
911911
912912
Parameters
913913
----------
914-
time_dependent : bool
915-
Flag to generate a time-dependent model or not.
914+
kinetic : bool
915+
Flag to generate kinetic simulation model or not.
916916
917917
Returns
918918
-------
@@ -924,7 +924,7 @@ def random_ray_pin_cell(time_dependent=False) -> openmc.Model:
924924

925925
###########################################################################
926926
# Create Materials for the problem
927-
materials = _generate_c5g7_materials(time_dependent)
927+
materials = _generate_c5g7_materials(kinetic)
928928
uo2 = materials[0]
929929
water = materials[1]
930930

@@ -962,9 +962,10 @@ def random_ray_pin_cell(time_dependent=False) -> openmc.Model:
962962
settings.random_ray['distance_inactive'] = 20.0
963963
settings.random_ray['ray_source'] = rr_source
964964
settings.random_ray['volume_normalized_flux_tallies'] = True
965-
if time_dependent:
966-
settings.run_mode = "time dependent"
967-
settings.time_dependent = {
965+
if kinetic:
966+
settings.random_ray['bd_order'] = 3
967+
settings.kinetic_simulation = True
968+
settings.timestep_parameters = {
968969
"dt": 0.01,
969970
"n_timesteps": 20,
970971
"timestep_units": "s",
@@ -980,7 +981,7 @@ def random_ray_pin_cell(time_dependent=False) -> openmc.Model:
980981
# Instantiate a Tallies collection and export to XML
981982
tallies = openmc.Tallies([tally])
982983

983-
if time_dependent:
984+
if kinetic:
984985
delay_filter = openmc.DelayedGroupFilter(np.arange(1, C5G7_N_DG+1, 1))
985986
tally = openmc.Tally(name="Delayed tally")
986987
tally.filters = [delay_filter]
@@ -997,7 +998,7 @@ def random_ray_pin_cell(time_dependent=False) -> openmc.Model:
997998
model.tallies = tallies
998999
return model
9991000

1000-
def random_ray_lattice(time_dependent=False) -> openmc.Model:
1001+
def random_ray_lattice(kinetic=False) -> openmc.Model:
10011002
"""Create a 2x2 PWR pin cell asymmetrical lattice example.
10021003
10031004
This model is a 2x2 reflective lattice of fuel pins with one of the lattice
@@ -1006,8 +1007,8 @@ def random_ray_lattice(time_dependent=False) -> openmc.Model:
10061007
10071008
Parameters
10081009
----------
1009-
time_dependent : bool
1010-
Flag to generate a time-dependent model or not.
1010+
kinetic : bool
1011+
Flag to generate a kinetic simulation model or not.
10111012
10121013
Returns
10131014
-------
@@ -1019,7 +1020,7 @@ def random_ray_lattice(time_dependent=False) -> openmc.Model:
10191020

10201021
###########################################################################
10211022
# Create Materials for the problem
1022-
materials = _generate_c5g7_materials(time_dependent)
1023+
materials = _generate_c5g7_materials(kinetic)
10231024
uo2 = materials[0]
10241025
water = materials[1]
10251026

@@ -1031,7 +1032,7 @@ def random_ray_lattice(time_dependent=False) -> openmc.Model:
10311032
# Define a moderator lattice universe
10321033

10331034
moderator_infinite = openmc.Cell(name='moderator infinite')
1034-
if time_dependent:
1035+
if kinetic:
10351036
water_reflector = water.clone()
10361037
water_reflector.name='Water Reflector'
10371038
water_reflector.set_density('macro', 1.0)
@@ -1094,9 +1095,10 @@ def random_ray_lattice(time_dependent=False) -> openmc.Model:
10941095
settings.random_ray['distance_inactive'] = 20.0
10951096
settings.random_ray['ray_source'] = rr_source
10961097
settings.random_ray['volume_normalized_flux_tallies'] = True
1097-
if time_dependent:
1098-
settings.run_mode = "time dependent"
1099-
settings.time_dependent = {
1098+
if kinetic:
1099+
settings.random_ray['bd_order'] = 3
1100+
settings.kinetic_simulation = True
1101+
settings.timestep_parameters = {
11001102
"dt": 0.01,
11011103
"n_timesteps": 2,
11021104
"timestep_units": "s",
@@ -1127,7 +1129,7 @@ def random_ray_lattice(time_dependent=False) -> openmc.Model:
11271129
# Instantiate a Tallies collection and export to XML
11281130
tallies = openmc.Tallies([tally])
11291131

1130-
if time_dependent:
1132+
if kinetic:
11311133
delay_filter = openmc.DelayedGroupFilter(np.arange(1, C5G7_N_DG+1, 1))
11321134
tally = openmc.Tally(name="Mesh delayed tally")
11331135
tally.filters = [mesh_filter, delay_filter]

src/output.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ const std::unordered_map<int, const char*> score_names = {
598598
{SCORE_IFP_TIME_NUM, "IFP lifetime numerator"},
599599
{SCORE_IFP_BETA_NUM, "IFP delayed fraction numerator"},
600600
{SCORE_IFP_DENOM, "IFP common denominator"},
601+
{SCORE_PRECURSORS, "Precursor Population"},
601602
};
602603

603604
//! Create an ASCII output file showing all tally results.

src/random_ray/flat_source_domain.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ void FlatSourceDomain::batch_reset()
9696
source_regions_.scalar_flux_new(se) = 0.0;
9797
}
9898

99-
if (settings::kinetic_simulation && !settings::is_initial_condition) {
99+
if (settings::kinetic_simulation) {
100100
#pragma omp parallel for
101101
for (int64_t se = 0; se < n_source_elements(); se++) {
102-
source_regions_.scalar_flux_td_new(se) = 0.0;
102+
source_regions_.precursors_new(se) = 0.0;
103+
if (!settings::is_initial_condition)
104+
source_regions_.scalar_flux_td_new(se) = 0.0;
103105
}
104106
}
105107
}

0 commit comments

Comments
 (0)