2018-08-23 21:38:23 -05:00
|
|
|
//! \file simulation.h
|
|
|
|
|
//! \brief Variables/functions related to a running simulation
|
|
|
|
|
|
2018-08-20 14:40:32 -05:00
|
|
|
#ifndef OPENMC_SIMULATION_H
|
|
|
|
|
#define OPENMC_SIMULATION_H
|
2018-07-06 06:36:05 -05:00
|
|
|
|
2019-05-28 19:57:52 -04:00
|
|
|
#include "openmc/mesh.h"
|
2018-10-17 06:34:12 -05:00
|
|
|
#include "openmc/particle.h"
|
2021-04-22 16:46:23 -04:00
|
|
|
#include "openmc/vector.h"
|
2018-10-17 06:34:12 -05:00
|
|
|
|
2018-07-06 06:36:05 -05:00
|
|
|
#include <cstdint>
|
2018-07-17 06:43:35 -05:00
|
|
|
|
|
|
|
|
namespace openmc {
|
2018-07-06 06:36:05 -05:00
|
|
|
|
2018-10-17 16:14:13 -05:00
|
|
|
constexpr int STATUS_EXIT_NORMAL {0};
|
|
|
|
|
constexpr int STATUS_EXIT_MAX_BATCH {1};
|
|
|
|
|
constexpr int STATUS_EXIT_ON_TRIGGER {2};
|
|
|
|
|
|
2018-08-23 21:38:23 -05:00
|
|
|
//==============================================================================
|
2018-10-09 22:34:08 -05:00
|
|
|
// Global variable declarations
|
2018-08-23 21:38:23 -05:00
|
|
|
//==============================================================================
|
2018-07-06 06:36:05 -05:00
|
|
|
|
2018-10-09 22:34:08 -05:00
|
|
|
namespace simulation {
|
|
|
|
|
|
2025-11-13 21:35:33 +01:00
|
|
|
extern int ct_current_file; //!< current collision track file index
|
2018-10-10 07:02:07 -05:00
|
|
|
extern "C" int current_batch; //!< current batch
|
|
|
|
|
extern "C" int current_gen; //!< current fission generation
|
2018-10-16 20:28:00 -05:00
|
|
|
extern "C" bool initialized; //!< has simulation been initialized?
|
2018-10-10 07:02:07 -05:00
|
|
|
extern "C" double keff; //!< average k over batches
|
|
|
|
|
extern "C" double keff_std; //!< standard deviation of average k
|
|
|
|
|
extern "C" double k_col_abs; //!< sum over batches of k_collision * k_absorption
|
|
|
|
|
extern "C" double
|
|
|
|
|
k_col_tra; //!< sum over batches of k_collision * k_tracklength
|
|
|
|
|
extern "C" double
|
|
|
|
|
k_abs_tra; //!< sum over batches of k_absorption * k_tracklength
|
2019-01-22 16:11:39 -06:00
|
|
|
extern double log_spacing; //!< lethargy spacing for energy grid searches
|
2018-10-10 07:02:07 -05:00
|
|
|
extern "C" int n_lost_particles; //!< cumulative number of lost particles
|
|
|
|
|
extern "C" bool need_depletion_rx; //!< need to calculate depletion rx?
|
2018-10-10 07:17:52 -05:00
|
|
|
extern "C" int restart_batch; //!< batch at which a restart job resumed
|
2018-10-10 07:02:07 -05:00
|
|
|
extern "C" bool satisfy_triggers; //!< have tally triggers been satisfied?
|
2024-10-03 19:32:03 -03:00
|
|
|
extern int ssw_current_file; //!< current surface source file
|
2018-10-10 07:02:07 -05:00
|
|
|
extern "C" int total_gen; //!< total number of generations simulated
|
2019-02-20 07:33:06 -06:00
|
|
|
extern double total_weight; //!< Total source weight in a batch
|
2019-03-20 13:26:04 -05:00
|
|
|
extern int64_t work_per_rank; //!< number of particles per MPI rank
|
2018-10-09 22:34:08 -05:00
|
|
|
|
2019-05-28 19:57:52 -04:00
|
|
|
extern const RegularMesh* entropy_mesh;
|
|
|
|
|
extern const RegularMesh* ufs_mesh;
|
|
|
|
|
|
2021-04-22 16:46:23 -04:00
|
|
|
extern vector<double> k_generation;
|
|
|
|
|
extern vector<int64_t> work_index;
|
2018-10-10 07:02:07 -05:00
|
|
|
|
2026-05-19 23:23:10 -05:00
|
|
|
extern int64_t
|
|
|
|
|
simulation_tracks_completed; //!< Number of tracks completed on this rank
|
|
|
|
|
|
2018-10-09 22:34:08 -05:00
|
|
|
} // namespace simulation
|
2018-07-06 06:36:05 -05:00
|
|
|
|
2018-08-23 21:38:23 -05:00
|
|
|
//==============================================================================
|
|
|
|
|
// Functions
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2018-11-15 08:13:14 -06:00
|
|
|
//! Allocate space for source and fission banks
|
|
|
|
|
void allocate_banks();
|
|
|
|
|
|
2018-04-26 22:26:29 -05:00
|
|
|
//! Determine number of particles to transport per process
|
2026-05-19 23:23:10 -05:00
|
|
|
void calculate_work(int64_t n_particles);
|
2018-04-26 22:26:29 -05:00
|
|
|
|
2020-06-17 22:22:01 -05:00
|
|
|
//! Initialize nuclear data before a simulation
|
|
|
|
|
void initialize_data();
|
2020-06-17 15:49:20 -05:00
|
|
|
|
2018-10-16 19:24:37 -05:00
|
|
|
//! Initialize a batch
|
2018-10-17 16:14:13 -05:00
|
|
|
void initialize_batch();
|
2018-10-16 19:24:37 -05:00
|
|
|
|
2018-10-12 08:01:23 -05:00
|
|
|
//! Initialize a fission generation
|
2018-10-17 16:14:13 -05:00
|
|
|
void initialize_generation();
|
2018-10-12 08:01:23 -05:00
|
|
|
|
2026-05-19 23:23:10 -05:00
|
|
|
//! Full initialization of a particle track
|
|
|
|
|
void initialize_particle_track(
|
|
|
|
|
Particle& p, int64_t index_source, bool is_secondary);
|
2018-10-17 06:34:12 -05:00
|
|
|
|
2018-10-17 10:06:16 -05:00
|
|
|
//! Finalize a batch
|
|
|
|
|
//!
|
|
|
|
|
//! Handles synchronization and accumulation of tallies, calculation of Shannon
|
|
|
|
|
//! entropy, getting single-batch estimate of keff, and turning on tallies when
|
|
|
|
|
//! appropriate
|
2018-10-17 16:14:13 -05:00
|
|
|
void finalize_batch();
|
2018-10-17 10:06:16 -05:00
|
|
|
|
2018-10-16 19:48:26 -05:00
|
|
|
//! Finalize a fission generation
|
2018-10-17 16:14:13 -05:00
|
|
|
void finalize_generation();
|
2018-10-16 19:48:26 -05:00
|
|
|
|
2018-10-10 07:17:52 -05:00
|
|
|
//! Determine overall generation number
|
|
|
|
|
extern "C" int overall_generation();
|
|
|
|
|
|
2018-04-26 22:26:29 -05:00
|
|
|
#ifdef OPENMC_MPI
|
2018-10-17 16:14:13 -05:00
|
|
|
void broadcast_results();
|
2018-04-26 22:26:29 -05:00
|
|
|
#endif
|
2018-07-17 06:43:35 -05:00
|
|
|
|
2019-02-21 08:32:32 -06:00
|
|
|
void free_memory_simulation();
|
|
|
|
|
|
2026-05-19 23:23:10 -05:00
|
|
|
//! Compute unique particle ID from a 1-based source index
|
|
|
|
|
//! \param index_source 1-based source index within this rank's work
|
|
|
|
|
//! \return globally unique particle ID
|
|
|
|
|
int64_t compute_particle_id(int64_t index_source);
|
|
|
|
|
|
|
|
|
|
//! Compute the transport RNG seed from a particle ID
|
|
|
|
|
//! \param particle_id the particle's globally unique ID
|
|
|
|
|
//! \return seed value passed to init_particle_seeds()
|
|
|
|
|
int64_t compute_transport_seed(int64_t particle_id);
|
|
|
|
|
|
|
|
|
|
//! Simulate a single particle history from birth to death, inclusive of any
|
|
|
|
|
//! secondary particles. In shared secondary mode, only a single track is
|
|
|
|
|
//! transported and secondaries are deposited into a shared bank instead.
|
2020-01-14 02:48:27 +00:00
|
|
|
void transport_history_based_single_particle(Particle& p);
|
|
|
|
|
|
|
|
|
|
//! Simulate all particle histories using history-based parallelism
|
|
|
|
|
void transport_history_based();
|
|
|
|
|
|
2026-05-19 23:23:10 -05:00
|
|
|
//! Simulate all particles using history-based parallelism, with a shared
|
|
|
|
|
//! secondary bank
|
|
|
|
|
void transport_history_based_shared_secondary();
|
|
|
|
|
|
2020-01-19 19:12:32 +00:00
|
|
|
//! Simulate all particle histories using event-based parallelism
|
|
|
|
|
void transport_event_based();
|
|
|
|
|
|
2026-05-19 23:23:10 -05:00
|
|
|
//! Simulate all particles using event-based parallelism, with a shared
|
|
|
|
|
//! secondary bank
|
|
|
|
|
void transport_event_based_shared_secondary();
|
|
|
|
|
|
2018-07-17 06:43:35 -05:00
|
|
|
} // namespace openmc
|
|
|
|
|
|
2018-08-20 14:40:32 -05:00
|
|
|
#endif // OPENMC_SIMULATION_H
|