Skip to content

Commit b34a5c9

Browse files
committed
fast forward to use updated functions; add some missing flow control
1 parent 0f768b2 commit b34a5c9

5 files changed

Lines changed: 83 additions & 69 deletions

File tree

include/openmc/random_ray/random_ray_simulation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class RandomRaySimulation {
2121
// Methods
2222
void apply_fixed_sources_and_mesh_domains();
2323
void prepare_fixed_sources_adjoint();
24-
void kinetic_single_time_step(int i);
2524
void prepare_adjoint_simulation();
2625
void simulate();
26+
void initialize_time_step(int i);
27+
void finalize_time_step();
2728
void output_simulation_results() const;
2829
void instability_check(
2930
int64_t n_hits, double k_eff, double& avg_miss_rate) const;

include/openmc/random_ray/source_region.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ class SourceRegionContainer {
996996
bool& is_linear() { return is_linear_; }
997997
const bool is_linear() const { return is_linear_; }
998998
SourceRegionHandle get_source_region_handle(int64_t sr);
999+
void simulation_reset();
9991000
void adjoint_reset();
10001001

10011002
//---------------------------------------------------------------------------

src/random_ray/random_ray_simulation.cpp

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ void RandomRaySimulation::prepare_fixed_sources_adjoint()
438438

439439
void RandomRaySimulation::prepare_adjoint_simulation()
440440
{
441+
// Reset all simulation values
442+
domain_->source_regions_.simulation_reset();
443+
441444
// Configure the domain for adjoint simulation
442445
FlatSourceDomain::adjoint_ = true;
443446

@@ -454,59 +457,6 @@ void RandomRaySimulation::prepare_adjoint_simulation()
454457
domain_->nu_sigma_f_.swap(domain_->chi_);
455458
}
456459

457-
// TODO: Add support for time-dependent restart
458-
void RandomRaySimulation::kinetic_single_time_step(int i)
459-
{
460-
// Increment time step
461-
simulation::current_timestep = i + 1;
462-
if (i >= 0)
463-
// Increment the current time
464-
simulation::current_time += settings::dt;
465-
466-
// Set eigenvalue if needed
467-
if (settings::run_mode == RunMode::EIGENVALUE) {
468-
if (i == -1) {
469-
// Set flag for k_eff correction if initial condition
470-
simulation::k_eff_correction = true;
471-
472-
// Store average keff from initial simulation
473-
static_avg_k_eff_ = simulation::keff;
474-
}
475-
domain_->k_eff_ = static_avg_k_eff_;
476-
}
477-
domain_->source_regions_.adjoint_reset();
478-
domain_->propagate_final_quantities();
479-
domain_->source_regions_.time_step_reset();
480-
481-
if (i >= 0) {
482-
// Compute RHS backward differences
483-
domain_->compute_rhs_bd_quantities();
484-
485-
// Update time dependent cross section based on the density
486-
domain_->update_material_density(i);
487-
}
488-
489-
// Run the initial condition
490-
simulate();
491-
492-
if (i == -1) {
493-
// Initialize the BD arrays if initial condition
494-
domain_->store_time_step_quantities(false);
495-
// Reset flags for kinetic simulation if initial condition
496-
simulation::is_initial_condition = false;
497-
simulation::k_eff_correction = false;
498-
} else {
499-
// Else, store final quantities for the current time step
500-
domain_->store_time_step_quantities();
501-
}
502-
503-
// Rename statepoint and tallies file for the current time step
504-
rename_time_step_file(fmt::format("statepoint.{0}", settings::n_batches),
505-
".h5", simulation::current_timestep);
506-
if (settings::output_tallies)
507-
rename_time_step_file("tallies", ".out", simulation::current_timestep);
508-
}
509-
510460
void RandomRaySimulation::simulate()
511461
{
512462
if (!is_first_simulation_) {
@@ -580,11 +530,11 @@ void RandomRaySimulation::simulate()
580530
domain_->apply_transport_stabilization();
581531

582532
if (settings::run_mode == RunMode::EIGENVALUE) {
583-
// Compute random ray k-eff
584-
if (!settings::kinetic_simulation ||
585-
settings::kinetic_simulation && simulation::is_initial_condition) {
533+
// Compute random ray k-eff for initial condition.
534+
// This keff will be preserved
535+
if (simulation::is_initial_condition) {
586536
domain_->compute_k_eff();
587-
if (simulation::k_eff_correction) {
537+
if (settings::kinetic_simulation && simulation::k_eff_correction) {
588538
static_fission_rate_.push_back(domain_->fission_rate_);
589539
static_k_eff_.push_back(domain_->k_eff_);
590540
}
@@ -655,6 +605,51 @@ void RandomRaySimulation::simulate()
655605
is_first_simulation_ = false;
656606
}
657607

608+
void RandomRaySimulation::initialize_time_step(int i)
609+
{
610+
if (simulation::k_eff_correction)
611+
static_avg_k_eff_ = simulation::keff;
612+
domain_->k_eff_ = static_avg_k_eff_;
613+
614+
// Increment current timestep and simuation time
615+
simulation::current_timestep = i + 1;
616+
617+
// Propagate previous converted solution for kinetic simulation
618+
domain_->source_regions_.simulation_reset();
619+
domain_->propagate_final_quantities();
620+
domain_->source_regions_.time_step_reset();
621+
622+
if (!simulation::is_initial_condition) {
623+
// Compute RHS backward differences
624+
domain_->compute_rhs_bd_quantities();
625+
626+
// Update time dependent cross section based on the density
627+
domain_->update_material_density(i);
628+
629+
simulation::current_time += settings::dt;
630+
}
631+
}
632+
633+
void RandomRaySimulation::finalize_time_step()
634+
{
635+
if (simulation::is_initial_condition) {
636+
// Initialize the BD arrays if initial condition
637+
domain_->store_time_step_quantities(false);
638+
// Toggle off initial condition and source correction
639+
simulation::is_initial_condition = false;
640+
simulation::k_eff_correction = false;
641+
} else {
642+
// Else, store final quantities for the current time step
643+
domain_->store_time_step_quantities();
644+
}
645+
646+
// Rename statepoint and tallies file for the current time step
647+
rename_time_step_file(fmt::format("statepoint.{0}", settings::n_batches),
648+
".h5", simulation::current_timestep);
649+
if (settings::output_tallies)
650+
rename_time_step_file("tallies", ".out", simulation::current_timestep);
651+
}
652+
658653
void RandomRaySimulation::output_simulation_results() const
659654
{
660655
// Print random ray results
@@ -861,7 +856,6 @@ void openmc_run_random_ray()
861856
//////////////////////////////////////////////////////////
862857
// Run forward simulation
863858
//////////////////////////////////////////////////////////
864-
865859
if (openmc::mpi::master) {
866860
if (openmc::FlatSourceDomain::adjoint_) {
867861
openmc::FlatSourceDomain::adjoint_ = false;
@@ -883,14 +877,22 @@ void openmc_run_random_ray()
883877
// Initialize fixed sources, if present
884878
sim.apply_fixed_sources_and_mesh_domains();
885879

886-
// Run initial random ray simulation
880+
// Simulate single random ray simulation (static case)
881+
// OR get an initial estimate for scattering and fission
882+
// distributions (if fissile material exist),
883+
// and k-eff (if kinetic eigenvalue simulation)
887884
sim.simulate();
888885

889886
if (openmc::settings::kinetic_simulation) {
890-
// Timestepping loop, including k-eff correction initial
891-
// condition (i = -1)
892-
for (int i = -1; i < openmc::settings::n_timesteps; i++)
893-
sim.kinetic_single_time_step(i);
887+
// Toggle initial condition source correction
888+
openmc::simulation::k_eff_correction = true;
889+
int i_start = -1;
890+
// Timestepping loop,
891+
for (int i = i_start; i < openmc::settings::n_timesteps; i++) {
892+
sim.initialize_time_step(i);
893+
sim.simulate();
894+
sim.finalize_time_step();
895+
}
894896
}
895897

896898
//////////////////////////////////////////////////////////

src/random_ray/source_region.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,14 @@ SourceRegionHandle SourceRegionContainer::get_source_region_handle(int64_t sr)
364364
return handle;
365365
}
366366

367-
void SourceRegionContainer::adjoint_reset()
367+
void SourceRegionContainer::simulation_reset()
368368
{
369369
std::fill(n_hits_.begin(), n_hits_.end(), 0);
370370
std::fill(volume_.begin(), volume_.end(), 0.0);
371371
std::fill(volume_t_.begin(), volume_t_.end(), 0.0);
372372
std::fill(volume_sq_.begin(), volume_sq_.end(), 0.0);
373373
std::fill(volume_sq_t_.begin(), volume_sq_t_.end(), 0.0);
374374
std::fill(volume_naive_.begin(), volume_naive_.end(), 0.0);
375-
std::fill(
376-
external_source_present_.begin(), external_source_present_.end(), 0);
377-
std::fill(external_source_.begin(), external_source_.end(), 0.0);
378375
std::fill(centroid_.begin(), centroid_.end(), Position {0.0, 0.0, 0.0});
379376
std::fill(centroid_iteration_.begin(), centroid_iteration_.end(),
380377
Position {0.0, 0.0, 0.0});
@@ -390,7 +387,6 @@ void SourceRegionContainer::adjoint_reset()
390387
}
391388
std::fill(scalar_flux_new_.begin(), scalar_flux_new_.end(), 0.0);
392389
std::fill(source_.begin(), source_.end(), 0.0f);
393-
std::fill(external_source_.begin(), external_source_.end(), 0.0f);
394390
std::fill(source_gradients_.begin(), source_gradients_.end(),
395391
MomentArray {0.0, 0.0, 0.0});
396392
std::fill(flux_moments_old_.begin(), flux_moments_old_.end(),
@@ -424,6 +420,13 @@ void SourceRegionContainer::adjoint_reset()
424420
}
425421
}
426422

423+
void SourceRegionContainer::adjoint_reset()
424+
{
425+
std::fill(
426+
external_source_present_.begin(), external_source_present_.end(), 0);
427+
std::fill(external_source_.begin(), external_source_.end(), 0.0f);
428+
}
429+
427430
//-----------------------------------------------------------------------------
428431
// Methods for kinetic simulations
429432

src/settings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ void get_run_parameters(pugi::xml_node node_base)
381381
if (check_for_node(random_ray_node, "adjoint")) {
382382
FlatSourceDomain::adjoint_ =
383383
get_node_value_bool(random_ray_node, "adjoint");
384+
if (FlatSourceDomain::adjoint_ && kinetic_simulation) {
385+
fatal_error("Adjoint kinetic simulations are currently unsupported .");
386+
}
384387
}
385388
if (check_for_node(random_ray_node, "sample_method")) {
386389
std::string temp_str =
@@ -1343,6 +1346,10 @@ void read_settings_xml(pugi::xml_node root)
13431346

13441347
// Create weight window generator objects
13451348
if (check_for_node(root, "weight_window_generators")) {
1349+
if (kinetic_simulation) {
1350+
fatal_error("Weight window generation is currently unsupported in kinetic"
1351+
" random ray solver mode.");
1352+
}
13461353
auto wwgs_node = root.child("weight_window_generators");
13471354
for (pugi::xml_node node_wwg :
13481355
wwgs_node.children("weight_windows_generator")) {

0 commit comments

Comments
 (0)