From 1d5242ede19f379e99a43ad2c6f5c07497b54281 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 15 Mar 2019 15:36:45 -0500 Subject: [PATCH] Fix a whole bunch of -Wall warnings --- include/openmc/error.h | 4 ++-- include/openmc/plot.h | 5 ++++- src/bremsstrahlung.cpp | 2 +- src/cross_sections.cpp | 1 - src/dagmc.cpp | 6 +++--- src/distribution_energy.cpp | 3 +++ src/endf.cpp | 3 +-- src/geometry.cpp | 3 +-- src/hdf5_interface.cpp | 5 +++++ src/initialize.cpp | 1 - src/lattice.cpp | 1 - src/material.cpp | 3 +-- src/mgxs.cpp | 2 -- src/nuclide.cpp | 2 +- src/output.cpp | 9 ++++----- src/particle_restart.cpp | 4 ++++ src/photon.cpp | 5 ----- src/physics.cpp | 21 +++++++-------------- src/plot.cpp | 7 ++++--- src/secondary_kalbach.cpp | 2 +- src/secondary_nbody.cpp | 2 ++ src/tallies/tally.cpp | 1 - src/tallies/trigger.cpp | 2 +- 23 files changed, 45 insertions(+), 49 deletions(-) diff --git a/include/openmc/error.h b/include/openmc/error.h index 206c9b5b2d..062368f17a 100644 --- a/include/openmc/error.h +++ b/include/openmc/error.h @@ -29,13 +29,13 @@ set_errmsg(const std::stringstream& message) [[noreturn]] void fatal_error(const std::string& message, int err=-1); -inline +[[noreturn]] inline void fatal_error(const std::stringstream& message) { fatal_error(message.str()); } -inline +[[noreturn]] inline void fatal_error(const char* message) { fatal_error({message, std::strlen(message)}); diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 2752add9cf..8e5aa02a6d 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -138,6 +138,10 @@ T PlotBase::get_map() const { in_i = 1; out_i = 2; break; +#ifdef __GNUC__ + default: + __builtin_unreachable(); +#endif } // set initial position @@ -168,7 +172,6 @@ T PlotBase::get_map() const { if (level >=0) {j = level + 1;} if (found_cell) { data.set_value(y, x, p, j); - Cell* c = model::cells[p.coord_[j].cell].get(); } } // inner for } // outer for diff --git a/src/bremsstrahlung.cpp b/src/bremsstrahlung.cpp index 3b9d8b591b..e6b76d19d5 100644 --- a/src/bremsstrahlung.cpp +++ b/src/bremsstrahlung.cpp @@ -45,7 +45,7 @@ void thick_target_bremsstrahlung(Particle& p, double* E_lost) auto n_e = data::ttb_e_grid.size(); // Find the lower bounding index of the incident electron energy - int j = lower_bound_index(data::ttb_e_grid.cbegin(), + size_t j = lower_bound_index(data::ttb_e_grid.cbegin(), data::ttb_e_grid.cend(), e); if (j == n_e - 1) --j; diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index e91cfc8756..2216b37daf 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -247,7 +247,6 @@ read_ce_cross_sections(const std::vector>& nuc_temps, LibraryKey key {Library::Type::photon, element}; int idx = data::library_map[key]; std::string& filename = data::libraries[idx].path_; - int i_element = data::element_map[element]; write_message("Reading " + element + " from " + filename, 6); // Open file and make sure version is sufficient diff --git a/src/dagmc.cpp b/src/dagmc.cpp index b50d65d88a..8add1f4f37 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -142,7 +142,7 @@ void load_dagmc_geometry() model::DAG = new moab::DagMC(); } - /// Materials \\\ + // --- Materials --- // create uwuw instance UWUW uwuw(DAGMC_FILENAME.c_str()); @@ -176,7 +176,7 @@ void load_dagmc_geometry() rval = model::DAG->parse_properties(keywords, dum, delimiters.c_str()); MB_CHK_ERR_CONT(rval); - /// Cells (Volumes) \\\ + // --- Cells (Volumes) --- // initialize cell objects int n_cells = model::DAG->num_entities(3); @@ -298,7 +298,7 @@ void load_dagmc_geometry() "This may result in lost particles and rapid simulation failure."); } - /// Surfaces \\\ + // --- Surfaces --- // initialize surface objects int n_surfaces = model::DAG->num_entities(2); diff --git a/src/distribution_energy.cpp b/src/distribution_energy.cpp index e311e322d2..1b9be7346b 100644 --- a/src/distribution_energy.cpp +++ b/src/distribution_energy.cpp @@ -245,6 +245,9 @@ double ContinuousTabular::sample(double E) const E_out = E_l_k + (std::sqrt(std::max(0.0, p_l_k*p_l_k + 2.0*frac*(r1 - c_k))) - p_l_k)/frac; } + } else { + throw std::runtime_error{"Unexpected interpolation for continuous energy " + "distribution."}; } // Now interpolate between incident energy bins i and i + 1 diff --git a/src/endf.cpp b/src/endf.cpp index 86f08b8a86..464bc974c2 100644 --- a/src/endf.cpp +++ b/src/endf.cpp @@ -164,9 +164,8 @@ double Tabulated1D::operator()(double x) const Interpolation interp; if (n_regions_ == 0) { interp = Interpolation::lin_lin; - } else if (n_regions_ == 1) { + } else { interp = int_[0]; - } else if (n_regions_ > 1) { for (int j = 0; j < n_regions_; ++j) { if (i < nbt_[j]) { interp = int_[j]; diff --git a/src/geometry.cpp b/src/geometry.cpp index 6eaa61fe24..8791dd9573 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -39,7 +39,6 @@ bool check_cell_overlap(Particle* p) // Loop through each coordinate level for (int j = 0; j < n_coord; j++) { Universe& univ = *model::universes[p->coord_[j].universe]; - int n = univ.cells_.size(); // Loop through each cell on this level for (auto index_cell : univ.cells_) { @@ -351,7 +350,7 @@ BoundaryInfo distance_to_boundary(Particle* p) double d_lat = INFINITY; double d_surf = INFINITY; int32_t level_surf_cross; - std::array level_lat_trans; + std::array level_lat_trans {}; // Loop over each coordinate level. for (int i = 0; i < p->n_coord_; i++) { diff --git a/src/hdf5_interface.cpp b/src/hdf5_interface.cpp index d85a4cc9e9..1fb10b7066 100644 --- a/src/hdf5_interface.cpp +++ b/src/hdf5_interface.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "xtensor/xtensor.hpp" @@ -47,6 +48,8 @@ get_shape(hid_t obj_id, hsize_t* dims) dspace = H5Dget_space(obj_id); } else if (type == H5I_ATTR) { dspace = H5Aget_space(obj_id); + } else { + throw std::runtime_error{"Expected dataset or attribute in call to get_shape."}; } H5Sget_simple_extent_dims(dspace, dims, nullptr); H5Sclose(dspace); @@ -70,6 +73,8 @@ std::vector object_shape(hid_t obj_id) dspace = H5Dget_space(obj_id); } else if (type == H5I_ATTR) { dspace = H5Aget_space(obj_id); + } else { + throw std::runtime_error{"Expected dataset or attribute in call to object_shape."}; } int n = H5Sget_simple_extent_ndims(dspace); diff --git a/src/initialize.cpp b/src/initialize.cpp index 61390651f5..f8a4f4a39a 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -121,7 +121,6 @@ void initialize_mpi(MPI_Comm intracomm) int parse_command_line(int argc, char* argv[]) { - char buffer[256]; // buffer for reading attribute int last_flag = 0; for (int i=1; i < argc; ++i) { std::string arg {argv[i]}; diff --git a/src/lattice.cpp b/src/lattice.cpp index 6e0f2331f0..eb6282bacb 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -800,7 +800,6 @@ HexLattice::is_valid_index(int indx) const { int nx {2*n_rings_ - 1}; int ny {2*n_rings_ - 1}; - int nz {n_axial_}; int iz = indx / (nx * ny); int iy = (indx - nx*ny*iz) / nx; int ix = indx - nx*ny*iz - nx*iy; diff --git a/src/material.cpp b/src/material.cpp index 94a6214836..de0d7e5de5 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -1283,12 +1283,11 @@ openmc_material_set_densities(int32_t index, int n, const char** name, const dou } // Set total density to the sum of the vector - int err = mat->set_density(sum_density, "atom/b-cm"); // Assign S(a,b) tables mat->init_thermal(); - return 0; + return err; } else { set_errmsg("Index in materials array is out of bounds."); return OPENMC_E_OUT_OF_BOUNDS; diff --git a/src/mgxs.cpp b/src/mgxs.cpp index d345cdb22d..efe562fa28 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -329,8 +329,6 @@ Mgxs::Mgxs(const std::string& in_name, const std::vector& mat_kTs, // Force all of the following data to be the same; these will be verified // to be true later int in_scatter_format = micros[0]->scatter_format; - int in_num_groups = micros[0]->num_groups; - int in_num_delayed_groups = micros[0]->num_delayed_groups; bool in_is_isotropic = micros[0]->is_isotropic; std::vector in_polar = micros[0]->polar; std::vector in_azimuthal = micros[0]->azimuthal; diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 8a6f1aa57b..7f034fd41f 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -97,7 +97,7 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature, int i_nucl // Determine closest temperature double min_delta_T = INFTY; - double T_actual; + double T_actual = 0.0; for (auto T : temps_available) { double delta_T = std::abs(T - T_desired); if (delta_T < min_delta_T) { diff --git a/src/output.cpp b/src/output.cpp index df0976d94a..ee74a27e15 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -283,9 +283,9 @@ print_overlap_check() { #ifdef OPENMC_MPI std::vector temp(model::overlap_check_count); - int err = MPI_Reduce(temp.data(), model::overlap_check_count.data(), - model::overlap_check_count.size(), MPI_INT64_T, - MPI_SUM, 0, mpi::intracomm); + MPI_Reduce(temp.data(), model::overlap_check_count.data(), + model::overlap_check_count.size(), MPI_INT64_T, + MPI_SUM, 0, mpi::intracomm); #endif if (mpi::master) { @@ -482,7 +482,7 @@ void print_runtime() // Calculate particle rate in active/inactive batches int n_active = simulation::current_batch - settings::n_inactive; - double speed_inactive; + double speed_inactive = 0.0; double speed_active; if (settings::restart_run) { if (simulation::restart_batch < settings::n_inactive) { @@ -492,7 +492,6 @@ void print_runtime() speed_active = (settings::n_particles * n_active * settings::gen_per_batch) / time_active.elapsed(); } else { - speed_inactive = 0.0; speed_active = (settings::n_particles * (settings::n_batches - simulation::restart_batch) * settings::gen_per_batch) / time_active.elapsed(); diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index 0bc677cfd8..b2017bbebe 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -14,6 +14,7 @@ #include // for copy #include +#include #include namespace openmc { @@ -90,6 +91,9 @@ void run_particle_restart() case RUN_MODE_FIXEDSOURCE: particle_seed = p.id_; break; + default: + throw std::runtime_error{"Unexpected run mode: " + + std::to_string(previous_run_mode)}; } set_particle_seed(particle_seed); diff --git a/src/photon.cpp b/src/photon.cpp index 79345b90e0..8a0ddf9aa9 100644 --- a/src/photon.cpp +++ b/src/photon.cpp @@ -550,11 +550,6 @@ void PhotonInteraction::pair_production(double alpha, double* E_electron, // "PENELOPE-2011: A Code System for Monte Carlo Simulation of Electron and // Photon Transport," OECD-NEA, Issy-les-Moulineaux, France (2011). - // Compute the minimum and maximum values of the electron reduced energy, - // i.e. the fraction of the photon energy that is given to the electron - double e_min = 1.0/alpha; - double e_max = 1.0 - 1.0/alpha; - // Compute the high-energy Coulomb correction double a = Z_ / FINE_STRUCTURE; double c = a*a*(1.0/(1.0 + a*a) + 0.202059 + a*a*(-0.03693 + a*a*(0.00835 + diff --git a/src/physics.cpp b/src/physics.cpp index 1cfd316580..e28c5a00ed 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -421,20 +421,11 @@ int sample_element(Particle* p) // Get pointers to elements, densities const auto& mat {model::materials[p->material_]}; - int n = mat->nuclide_.size(); - int i = 0; double prob = 0.0; - int i_element; - while (prob < cutoff) { - // Check to make sure that a nuclide was sampled - if (i >= n) { - p->write_restart(); - fatal_error("Did not sample any element during collision."); - } - + for (int i = 0; i < mat->element_.size(); ++i) { // Find atom density - i_element = mat->element_[i]; + int i_element = mat->element_[i]; double atom_density = mat->atom_density_[i]; // Determine microscopic cross section @@ -442,10 +433,12 @@ int sample_element(Particle* p) // Increment probability to compare to cutoff prob += sigma; - ++i; + if (prob > cutoff) return i_element; } - return i_element; + // If we made it here, no element was sampled + p->write_restart(); + fatal_error("Did not sample any element during collision."); } Reaction* sample_fission(int i_nuclide, const Particle* p) @@ -614,7 +607,7 @@ void scatter(Particle* p, int i_nuclide) // INELASTIC SCATTERING int j = 0; - int i; + int i = 0; while (prob < cutoff) { i = nuc->index_inelastic_scatter_[j]; ++j; diff --git a/src/plot.cpp b/src/plot.cpp index 02fb42d76b..74279cad51 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -80,8 +80,6 @@ std::unordered_map plot_map; extern "C" int openmc_plot_geometry() { - int err; - for (auto pl : model::plots) { std::stringstream ss; ss << "Processing plot " << pl.id_ << ": " @@ -695,6 +693,10 @@ void draw_mesh_lines(Plot pl, ImageData& data) outer = 1; inner = 2; break; +#ifdef __GNUC__ + default: + __builtin_unreachable(); +#endif } Position ll_plot {pl.origin_}; @@ -806,7 +808,6 @@ void create_voxel(Plot pl) // Write current date and time write_attribute(file_id, "date_and_time", time_stamp().c_str()); - hsize_t three = 3; std::array pixels; std::copy(pl.pixels_.begin(), pl.pixels_.end(), pixels.begin()); write_attribute(file_id, "num_voxels", pixels); diff --git a/src/secondary_kalbach.cpp b/src/secondary_kalbach.cpp index cec5344def..e3974f357e 100644 --- a/src/secondary_kalbach.cpp +++ b/src/secondary_kalbach.cpp @@ -199,7 +199,7 @@ void KalbachMann::sample(double E_in, double& E_out, double& mu) const km_r = distribution_[l].r[k]; km_a = distribution_[l].a[k]; - } else if (distribution_[l].interpolation == Interpolation::lin_lin) { + } else { // Linear-linear interpolation double E_l_k1 = distribution_[l].e_out[k+1]; double p_l_k1 = distribution_[l].p[k+1]; diff --git a/src/secondary_nbody.cpp b/src/secondary_nbody.cpp index dabd9de3a8..564fca73d8 100644 --- a/src/secondary_nbody.cpp +++ b/src/secondary_nbody.cpp @@ -55,6 +55,8 @@ void NBodyPhaseSpace::sample(double E_in, double& E_out, double& mu) const r6 = prn(); y = -std::log(r1*r2*r3*r4) - std::log(r5) * std::pow(std::cos(PI/2.0*r6), 2); break; + default: + throw std::runtime_error{"N-body phase space with >5 bodies."}; } // Now determine v and E_out diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 682db35405..fe1953b26e 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -328,7 +328,6 @@ Tally::set_scores(std::vector scores) // Iterate over the given scores. for (auto score_str : scores) { // Make sure a delayed group filter wasn't used with an incompatible score. - bool has_delayedgroup = delayedgroup_filter_ != C_NONE; if (delayedgroup_filter_ != C_NONE) { if (score_str != "delayed-nu-fission" && score_str != "decay-rate") fatal_error("Cannot tally " + score_str + "with a delayedgroup filter"); diff --git a/src/tallies/trigger.cpp b/src/tallies/trigger.cpp index c1b0a93649..d43be8b9ce 100644 --- a/src/tallies/trigger.cpp +++ b/src/tallies/trigger.cpp @@ -114,7 +114,7 @@ check_keff_trigger() if (settings::run_mode != RUN_MODE_EIGENVALUE) return 0.; double k_combined[2]; - int err = openmc_get_keff(k_combined); + openmc_get_keff(k_combined); double uncertainty = 0.; switch (settings::keff_trigger.metric) {