mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 13:15:39 -04:00
Apply clang-format on entire source
This commit is contained in:
parent
4c17061a1d
commit
1bc2bd8460
181 changed files with 7372 additions and 6952 deletions
|
|
@ -17,11 +17,11 @@
|
|||
#include "openmc/settings.h"
|
||||
#include "openmc/source.h"
|
||||
#include "openmc/state_point.h"
|
||||
#include "openmc/timer.h"
|
||||
#include "openmc/tallies/derivative.h"
|
||||
#include "openmc/tallies/filter.h"
|
||||
#include "openmc/tallies/tally.h"
|
||||
#include "openmc/tallies/trigger.h"
|
||||
#include "openmc/timer.h"
|
||||
#include "openmc/track_output.h"
|
||||
|
||||
#ifdef _OPENMP
|
||||
|
|
@ -39,14 +39,13 @@
|
|||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
|
||||
//==============================================================================
|
||||
// C API functions
|
||||
//==============================================================================
|
||||
|
||||
// OPENMC_RUN encompasses all the main logic where iterations are performed
|
||||
// over the batches, generations, and histories in a fixed source or k-eigenvalue
|
||||
// calculation.
|
||||
// over the batches, generations, and histories in a fixed source or
|
||||
// k-eigenvalue calculation.
|
||||
|
||||
int openmc_run()
|
||||
{
|
||||
|
|
@ -69,7 +68,8 @@ int openmc_simulation_init()
|
|||
using namespace openmc;
|
||||
|
||||
// Skip if simulation has already been initialized
|
||||
if (simulation::initialized) return 0;
|
||||
if (simulation::initialized)
|
||||
return 0;
|
||||
|
||||
// Initialize nuclear data (energy limits, log grid)
|
||||
if (settings::run_CE) {
|
||||
|
|
@ -85,8 +85,8 @@ int openmc_simulation_init()
|
|||
// If doing an event-based simulation, intialize the particle buffer
|
||||
// and event queues
|
||||
if (settings::event_based) {
|
||||
int64_t event_buffer_length = std::min(simulation::work_per_rank,
|
||||
settings::max_particles_in_flight);
|
||||
int64_t event_buffer_length =
|
||||
std::min(simulation::work_per_rank, settings::max_particles_in_flight);
|
||||
init_event_queues(event_buffer_length);
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +125,8 @@ int openmc_simulation_init()
|
|||
header("FIXED SOURCE TRANSPORT SIMULATION", 3);
|
||||
} else if (settings::run_mode == RunMode::EIGENVALUE) {
|
||||
header("K EIGENVALUE SIMULATION", 3);
|
||||
if (settings::verbosity >= 7) print_columns();
|
||||
if (settings::verbosity >= 7)
|
||||
print_columns();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +140,8 @@ int openmc_simulation_finalize()
|
|||
using namespace openmc;
|
||||
|
||||
// Skip if simulation was never run
|
||||
if (!simulation::initialized) return 0;
|
||||
if (!simulation::initialized)
|
||||
return 0;
|
||||
|
||||
// Stop active batch timer and start finalization timer
|
||||
simulation::time_active.stop();
|
||||
|
|
@ -151,14 +153,15 @@ int openmc_simulation_finalize()
|
|||
}
|
||||
|
||||
// Increment total number of generations
|
||||
simulation::total_gen += simulation::current_batch*settings::gen_per_batch;
|
||||
simulation::total_gen += simulation::current_batch * settings::gen_per_batch;
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
broadcast_results();
|
||||
#endif
|
||||
|
||||
// Write tally results to tallies.out
|
||||
if (settings::output_tallies && mpi::master) write_tallies();
|
||||
if (settings::output_tallies && mpi::master)
|
||||
write_tallies();
|
||||
|
||||
// Deactivate all tallies
|
||||
for (auto& t : model::tallies) {
|
||||
|
|
@ -169,10 +172,13 @@ int openmc_simulation_finalize()
|
|||
simulation::time_finalize.stop();
|
||||
simulation::time_total.stop();
|
||||
if (mpi::master) {
|
||||
if (settings::verbosity >= 6) print_runtime();
|
||||
if (settings::verbosity >= 4) print_results();
|
||||
if (settings::verbosity >= 6)
|
||||
print_runtime();
|
||||
if (settings::verbosity >= 4)
|
||||
print_results();
|
||||
}
|
||||
if (settings::check_overlaps) print_overlap_check();
|
||||
if (settings::check_overlaps)
|
||||
print_overlap_check();
|
||||
|
||||
// Reset flags
|
||||
simulation::initialized = false;
|
||||
|
|
@ -229,7 +235,8 @@ int openmc_next_batch(int* status)
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool openmc_is_statepoint_batch() {
|
||||
bool openmc_is_statepoint_batch()
|
||||
{
|
||||
using namespace openmc;
|
||||
using openmc::simulation::current_gen;
|
||||
|
||||
|
|
@ -283,14 +290,13 @@ void allocate_banks()
|
|||
simulation::source_bank.resize(simulation::work_per_rank);
|
||||
|
||||
// Allocate fission bank
|
||||
init_fission_bank(3*simulation::work_per_rank);
|
||||
init_fission_bank(3 * simulation::work_per_rank);
|
||||
}
|
||||
|
||||
if (settings::surf_source_write) {
|
||||
// Allocate surface source bank
|
||||
simulation::surf_source_bank.reserve(settings::max_surface_particles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void initialize_batch()
|
||||
|
|
@ -311,7 +317,7 @@ void initialize_batch()
|
|||
if (!settings::restart_run) {
|
||||
first_inactive = settings::n_inactive > 0 && simulation::current_batch == 1;
|
||||
first_active = simulation::current_batch == settings::n_inactive + 1;
|
||||
} else if (simulation::current_batch == simulation::restart_batch + 1){
|
||||
} else if (simulation::current_batch == simulation::restart_batch + 1) {
|
||||
first_inactive = simulation::restart_batch < settings::n_inactive;
|
||||
first_active = !first_inactive;
|
||||
}
|
||||
|
|
@ -345,21 +351,23 @@ void finalize_batch()
|
|||
}
|
||||
|
||||
// Check_triggers
|
||||
if (mpi::master) check_triggers();
|
||||
if (mpi::master)
|
||||
check_triggers();
|
||||
#ifdef OPENMC_MPI
|
||||
MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
|
||||
#endif
|
||||
if (simulation::satisfy_triggers || (settings::trigger_on &&
|
||||
simulation::current_batch == settings::n_max_batches)) {
|
||||
if (simulation::satisfy_triggers ||
|
||||
(settings::trigger_on &&
|
||||
simulation::current_batch == settings::n_max_batches)) {
|
||||
settings::statepoint_batch.insert(simulation::current_batch);
|
||||
}
|
||||
|
||||
// Write out state point if it's been specified for this batch and is not
|
||||
// a CMFD run instance
|
||||
if (contains(settings::statepoint_batch, simulation::current_batch)
|
||||
&& !settings::cmfd_run) {
|
||||
if (contains(settings::sourcepoint_batch, simulation::current_batch)
|
||||
&& settings::source_write && !settings::source_separate) {
|
||||
if (contains(settings::statepoint_batch, simulation::current_batch) &&
|
||||
!settings::cmfd_run) {
|
||||
if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
|
||||
settings::source_write && !settings::source_separate) {
|
||||
bool b = (settings::run_mode == RunMode::EIGENVALUE);
|
||||
openmc_statepoint_write(nullptr, &b);
|
||||
} else {
|
||||
|
|
@ -370,8 +378,8 @@ void finalize_batch()
|
|||
|
||||
if (settings::run_mode == RunMode::EIGENVALUE) {
|
||||
// Write out a separate source point if it's been specified for this batch
|
||||
if (contains(settings::sourcepoint_batch, simulation::current_batch)
|
||||
&& settings::source_write && settings::source_separate) {
|
||||
if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
|
||||
settings::source_write && settings::source_separate) {
|
||||
write_source_point(nullptr);
|
||||
}
|
||||
|
||||
|
|
@ -383,7 +391,8 @@ void finalize_batch()
|
|||
}
|
||||
|
||||
// Write out surface source if requested.
|
||||
if (settings::surf_source_write && simulation::current_batch == settings::n_batches) {
|
||||
if (settings::surf_source_write &&
|
||||
simulation::current_batch == settings::n_batches) {
|
||||
auto filename = settings::path_output + "surface_source.h5";
|
||||
write_source_point(filename.c_str(), true);
|
||||
}
|
||||
|
|
@ -396,7 +405,8 @@ void initialize_generation()
|
|||
simulation::fission_bank.resize(0);
|
||||
|
||||
// Count source sites if using uniform fission source weighting
|
||||
if (settings::ufs_on) ufs_count_sites();
|
||||
if (settings::ufs_on)
|
||||
ufs_count_sites();
|
||||
|
||||
// Store current value of tracklength k
|
||||
simulation::keff_generation = simulation::global_tallies(
|
||||
|
|
@ -411,8 +421,10 @@ void finalize_generation()
|
|||
// Update global tallies with the accumulation variables
|
||||
if (settings::run_mode == RunMode::EIGENVALUE) {
|
||||
gt(GlobalTally::K_COLLISION, TallyResult::VALUE) += global_tally_collision;
|
||||
gt(GlobalTally::K_ABSORPTION, TallyResult::VALUE) += global_tally_absorption;
|
||||
gt(GlobalTally::K_TRACKLENGTH, TallyResult::VALUE) += global_tally_tracklength;
|
||||
gt(GlobalTally::K_ABSORPTION, TallyResult::VALUE) +=
|
||||
global_tally_absorption;
|
||||
gt(GlobalTally::K_TRACKLENGTH, TallyResult::VALUE) +=
|
||||
global_tally_tracklength;
|
||||
}
|
||||
gt(GlobalTally::LEAKAGE, TallyResult::VALUE) += global_tally_leakage;
|
||||
|
||||
|
|
@ -434,7 +446,8 @@ void finalize_generation()
|
|||
synchronize_bank();
|
||||
|
||||
// Calculate shannon entropy
|
||||
if (settings::entropy_on) shannon_entropy();
|
||||
if (settings::entropy_on)
|
||||
shannon_entropy();
|
||||
|
||||
// Collect results and statistics
|
||||
calculate_generation_keff();
|
||||
|
|
@ -444,7 +457,6 @@ void finalize_generation()
|
|||
if (mpi::master && settings::verbosity >= 7) {
|
||||
print_generation();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -456,8 +468,9 @@ void initialize_history(Particle& p, int64_t index_source)
|
|||
p.from_source(&simulation::source_bank[index_source - 1]);
|
||||
} else if (settings::run_mode == RunMode::FIXED_SOURCE) {
|
||||
// initialize random number seed
|
||||
int64_t id = (simulation::total_gen + overall_generation() - 1)*settings::n_particles +
|
||||
simulation::work_index[mpi::rank] + index_source;
|
||||
int64_t id = (simulation::total_gen + overall_generation() - 1) *
|
||||
settings::n_particles +
|
||||
simulation::work_index[mpi::rank] + index_source;
|
||||
uint64_t seed = init_seed(id, STREAM_SOURCE);
|
||||
// sample from external source distribution or custom library then set
|
||||
auto site = sample_external_source(&seed);
|
||||
|
|
@ -506,8 +519,8 @@ void initialize_history(Particle& p, int64_t index_source)
|
|||
write_message("Simulating Particle {}", p.id());
|
||||
}
|
||||
|
||||
// Add paricle's starting weight to count for normalizing tallies later
|
||||
#pragma omp atomic
|
||||
// Add paricle's starting weight to count for normalizing tallies later
|
||||
#pragma omp atomic
|
||||
simulation::total_weight += p.wgt();
|
||||
|
||||
// Force calculation of cross-sections by setting last energy to zero
|
||||
|
|
@ -523,7 +536,7 @@ void initialize_history(Particle& p, int64_t index_source)
|
|||
int overall_generation()
|
||||
{
|
||||
using namespace simulation;
|
||||
return settings::gen_per_batch*(current_batch - 1) + current_gen;
|
||||
return settings::gen_per_batch * (current_batch - 1) + current_gen;
|
||||
}
|
||||
|
||||
void calculate_work()
|
||||
|
|
@ -542,7 +555,8 @@ void calculate_work()
|
|||
int64_t work_i = i < remainder ? min_work + 1 : min_work;
|
||||
|
||||
// Set number of particles
|
||||
if (mpi::rank == i) simulation::work_per_rank = work_i;
|
||||
if (mpi::rank == i)
|
||||
simulation::work_per_rank = work_i;
|
||||
|
||||
// Set index into source bank for rank i
|
||||
i_bank += work_i;
|
||||
|
|
@ -558,10 +572,10 @@ void initialize_data()
|
|||
for (const auto& nuc : data::nuclides) {
|
||||
if (nuc->grid_.size() >= 1) {
|
||||
int neutron = static_cast<int>(ParticleType::neutron);
|
||||
data::energy_min[neutron] = std::max(data::energy_min[neutron],
|
||||
nuc->grid_[0].energy.front());
|
||||
data::energy_max[neutron] = std::min(data::energy_max[neutron],
|
||||
nuc->grid_[0].energy.back());
|
||||
data::energy_min[neutron] =
|
||||
std::max(data::energy_min[neutron], nuc->grid_[0].energy.front());
|
||||
data::energy_max[neutron] =
|
||||
std::min(data::energy_max[neutron], nuc->grid_[0].energy.back());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -570,10 +584,10 @@ void initialize_data()
|
|||
if (elem->energy_.size() >= 1) {
|
||||
int photon = static_cast<int>(ParticleType::photon);
|
||||
int n = elem->energy_.size();
|
||||
data::energy_min[photon] = std::max(data::energy_min[photon],
|
||||
std::exp(elem->energy_(1)));
|
||||
data::energy_max[photon] = std::min(data::energy_max[photon],
|
||||
std::exp(elem->energy_(n - 1)));
|
||||
data::energy_min[photon] =
|
||||
std::max(data::energy_min[photon], std::exp(elem->energy_(1)));
|
||||
data::energy_max[photon] =
|
||||
std::min(data::energy_max[photon], std::exp(elem->energy_(n - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -583,10 +597,10 @@ void initialize_data()
|
|||
if (data::ttb_e_grid.size() >= 1) {
|
||||
int photon = static_cast<int>(ParticleType::photon);
|
||||
int n_e = data::ttb_e_grid.size();
|
||||
data::energy_min[photon] = std::max(data::energy_min[photon],
|
||||
std::exp(data::ttb_e_grid(1)));
|
||||
data::energy_max[photon] = std::min(data::energy_max[photon],
|
||||
std::exp(data::ttb_e_grid(n_e - 1)));
|
||||
data::energy_min[photon] =
|
||||
std::max(data::energy_min[photon], std::exp(data::ttb_e_grid(1)));
|
||||
data::energy_max[photon] = std::min(
|
||||
data::energy_max[photon], std::exp(data::ttb_e_grid(n_e - 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -603,7 +617,7 @@ void initialize_data()
|
|||
data::energy_max[neutron], nuc->name_);
|
||||
if (mpi::master && data::energy_max[neutron] < 20.0e6) {
|
||||
warning("Maximum neutron energy is below 20 MeV. This may bias "
|
||||
"the results.");
|
||||
"the results.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -615,12 +629,14 @@ void initialize_data()
|
|||
nuc->init_grid();
|
||||
}
|
||||
int neutron = static_cast<int>(ParticleType::neutron);
|
||||
simulation::log_spacing = std::log(data::energy_max[neutron] /
|
||||
data::energy_min[neutron]) / settings::n_log_bins;
|
||||
simulation::log_spacing =
|
||||
std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
|
||||
settings::n_log_bins;
|
||||
}
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
void broadcast_results() {
|
||||
void broadcast_results()
|
||||
{
|
||||
// Broadcast tally results so that each process has access to results
|
||||
for (auto& t : model::tallies) {
|
||||
// Create a new datatype that consists of all values for a given filter
|
||||
|
|
@ -643,8 +659,8 @@ void broadcast_results() {
|
|||
|
||||
// These guys are needed so that non-master processes can calculate the
|
||||
// combined estimate of k-effective
|
||||
double temp[] {simulation::k_col_abs, simulation::k_col_tra,
|
||||
simulation::k_abs_tra};
|
||||
double temp[] {
|
||||
simulation::k_col_abs, simulation::k_col_tra, simulation::k_abs_tra};
|
||||
MPI_Bcast(temp, 3, MPI_DOUBLE, 0, mpi::intracomm);
|
||||
simulation::k_col_abs = temp[0];
|
||||
simulation::k_col_tra = temp[1];
|
||||
|
|
@ -678,7 +694,7 @@ void transport_history_based_single_particle(Particle& p)
|
|||
|
||||
void transport_history_based()
|
||||
{
|
||||
#pragma omp parallel for schedule(runtime)
|
||||
#pragma omp parallel for schedule(runtime)
|
||||
for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
|
||||
Particle p;
|
||||
initialize_history(p, i_work);
|
||||
|
|
@ -698,7 +714,8 @@ void transport_event_based()
|
|||
// loop is executed multiple times until all particles have been completed.
|
||||
while (remaining_work > 0) {
|
||||
// Figure out # of particles to run for this subiteration
|
||||
int64_t n_particles = std::min(remaining_work, settings::max_particles_in_flight);
|
||||
int64_t n_particles =
|
||||
std::min(remaining_work, settings::max_particles_in_flight);
|
||||
|
||||
// Initialize all particle histories for this subiteration
|
||||
process_init_events(n_particles, source_offset);
|
||||
|
|
@ -706,8 +723,7 @@ void transport_event_based()
|
|||
// Event-based transport loop
|
||||
while (true) {
|
||||
// Determine which event kernel has the longest queue
|
||||
int64_t max = std::max({
|
||||
simulation::calculate_fuel_xs_queue.size(),
|
||||
int64_t max = std::max({simulation::calculate_fuel_xs_queue.size(),
|
||||
simulation::calculate_nonfuel_xs_queue.size(),
|
||||
simulation::advance_particle_queue.size(),
|
||||
simulation::surface_crossing_queue.size(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue