@@ -438,6 +438,9 @@ void RandomRaySimulation::prepare_fixed_sources_adjoint()
438438
439439void 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-
510460void 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+
658653void 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 // ////////////////////////////////////////////////////////
0 commit comments