diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed170253e4..4c5e3c1e837 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,10 +385,17 @@ endif() add_library(cxx_interface INTERFACE) target_compile_options( cxx_interface - INTERFACE -Wall -Wextra $<$:-Werror> + INTERFACE -Wall + -Wextra + $<$:-Werror> + # add extra warnings + $<$:-Wextern-initializer> # disable warnings from -Wextra - -Wno-sign-compare -Wno-unused-function -Wno-unused-variable - -Wno-unused-parameter -Wno-missing-braces + -Wno-sign-compare + -Wno-unused-function + -Wno-unused-variable + -Wno-unused-parameter + -Wno-missing-braces $<$:-Wno-clobbered;-Wno-cast-function-type> $<$:-wd592>) diff --git a/samples/chamber_game.py b/samples/chamber_game.py index 4bef2cb486c..2cf634d550d 100644 --- a/samples/chamber_game.py +++ b/samples/chamber_game.py @@ -49,7 +49,7 @@ "\nMOVE: (JOYSTICK AXIS), (KEYBOARD i/j/k/l)" "\nACTION BUTTON: (JOYSTICK A), (KEYBOARD p)" "\nRESTART: (JOYSTICK START), (KEYBOARD b)") -except BaseException: +except ImportError: has_pygame = False print("\nCONTROLS:" "\nMOVE: (KEYBOARD i/j/k/l)" @@ -294,15 +294,9 @@ fix=[True, True, True]) # MINIMIZE ENERGY - -energy = system.analysis.energy() -#print("Before Minimization: E_total = {}".format(energy['total'])) espressomd.minimize_energy.steepest_descent(system, f_max=100, gamma=30.0, max_steps=10000, max_displacement=0.01) -energy = system.analysis.energy() -#print("After Minimization: E_total = {}".format(energy['total'])) - p_startpos = system.part[:].pos # THERMOSTAT @@ -413,7 +407,6 @@ def T_to_g(temp): zoom_eq = 5.0 zoom_v = 0.0 - zoom_a = 0.0 zoom = zoom_eq zoom_dt = 0.01 diff --git a/samples/lj-demo.py b/samples/lj-demo.py index f0e2010dd80..efa23ab4ea4 100644 --- a/samples/lj-demo.py +++ b/samples/lj-demo.py @@ -52,10 +52,10 @@ try: import midi -except BaseException: +except ImportError: try: from pygame import midi - except BaseException: + except ImportError: from portmidi import midi midi.init() @@ -528,7 +528,7 @@ def midi_thread(): # rotate clockwise mayavi_rotation_angle += mayavi_rotation_angle_step * \ data2 - elif data2 >= 65: + else: # rotate counterclockwise mayavi_rotation_angle -= mayavi_rotation_angle_step * \ (data2 - 64) diff --git a/src/config/featuredefs.py b/src/config/featuredefs.py index b7ea3dbfd80..70da71a5824 100644 --- a/src/config/featuredefs.py +++ b/src/config/featuredefs.py @@ -50,8 +50,6 @@ class defs: def __init__(self, filename): # complete set of all defined features allfeatures = set() - # allfeatures minus externals and derived - features = set() # list of implications (pairs of feature -> implied feature) implications = list() # list of requirements (pairs of feature -> requirement expr) @@ -131,8 +129,10 @@ def __init__(self, filename): raise SyntaxError(" requires ", line) requirements.append((feature, rest, toCPPExpr(rest))) + # allfeatures minus externals and derived features = allfeatures.difference(derived) features = features.difference(externals) + self.allfeatures = allfeatures self.features = features self.requirements = requirements diff --git a/src/core/debug.hpp b/src/core/debug.hpp index f8e80ed02f8..2d48d12852c 100644 --- a/src/core/debug.hpp +++ b/src/core/debug.hpp @@ -23,6 +23,8 @@ * * Implementation in debug.cpp. */ +#ifndef DEBUG_HPP +#define DEBUG_HPP /** this performs a lot of tests which will very likely detect corruptions of * the cell structure. @@ -36,3 +38,5 @@ void check_particle_consistency(); * they should be. */ void check_particle_sorting(); + +#endif diff --git a/src/core/electrostatics_magnetostatics/elc.cpp b/src/core/electrostatics_magnetostatics/elc.cpp index 06b2b432cc4..1ba3783009e 100644 --- a/src/core/electrostatics_magnetostatics/elc.cpp +++ b/src/core/electrostatics_magnetostatics/elc.cpp @@ -217,15 +217,14 @@ void distribute(int size) { * See @cite yeh99a. */ static void add_dipole_force(const ParticleRange &particles) { - double pref = coulomb.prefactor * 4 * M_PI * ux * uy * uz; - int size = 3; + double const pref = coulomb.prefactor * 4 * M_PI * ux * uy * uz; + int const size = 3; auto local_particles = particles; /* for nonneutral systems, this shift gives the background contribution (rsp. for this shift, the DM of the background is zero) */ - double shift = 0.5 * box_geo.length()[2]; - double field_tot = 0; + double const shift = 0.5 * box_geo.length()[2]; // collect moments @@ -258,7 +257,7 @@ static void add_dipole_force(const ParticleRange &particles) { distribute(size); // Yeh + Berkowitz dipole term @cite yeh99a - field_tot = gblcblk[0]; + double field_tot = gblcblk[0]; // Const. potential contribution if (elc_params.const_pot) { @@ -281,11 +280,11 @@ static void add_dipole_force(const ParticleRange &particles) { * See @cite yeh99a. */ static double dipole_energy(const ParticleRange &particles) { - double pref = coulomb.prefactor * 2 * M_PI * ux * uy * uz; - int size = 7; + double const pref = coulomb.prefactor * 2 * M_PI * ux * uy * uz; + int const size = 7; /* for nonneutral systems, this shift gives the background contribution (rsp. for this shift, the DM of the background is zero) */ - double shift = 0.5 * box_geo.length()[2]; + double const shift = 0.5 * box_geo.length()[2]; // collect moments @@ -354,18 +353,18 @@ static double dipole_energy(const ParticleRange &particles) { /*****************************************************************/ inline double image_sum_b(double q, double z) { - double shift = 0.5 * box_geo.length()[2]; - double fac = elc_params.delta_mid_top * elc_params.delta_mid_bot; - double image_sum = + double const shift = 0.5 * box_geo.length()[2]; + double const fac = elc_params.delta_mid_top * elc_params.delta_mid_bot; + double const image_sum = (q / (1.0 - fac) * (z - 2.0 * fac * box_geo.length()[2] / (1.0 - fac))) - q * shift / (1 - fac); return image_sum; } inline double image_sum_t(double q, double z) { - double shift = 0.5 * box_geo.length()[2]; - double fac = elc_params.delta_mid_top * elc_params.delta_mid_bot; - double image_sum = + double const shift = 0.5 * box_geo.length()[2]; + double const fac = elc_params.delta_mid_top * elc_params.delta_mid_bot; + double const image_sum = (q / (1.0 - fac) * (z + 2.0 * fac * box_geo.length()[2] / (1.0 - fac))) - q * shift / (1 - fac); return image_sum; @@ -373,13 +372,12 @@ inline double image_sum_t(double q, double z) { /*****************************************************************/ static double z_energy(const ParticleRange &particles) { - double pref = coulomb.prefactor * 2 * M_PI * ux * uy; - int size = 4; + double const pref = coulomb.prefactor * 2 * M_PI * ux * uy; + int const size = 4; - double eng = 0; /* for nonneutral systems, this shift gives the background contribution (rsp. for this shift, the DM of the background is zero) */ - double shift = 0.5 * box_geo.length()[2]; + double const shift = 0.5 * box_geo.length()[2]; if (elc_params.dielectric_contrast_on) { if (elc_params.const_pot) { @@ -398,10 +396,10 @@ static double z_energy(const ParticleRange &particles) { } } } else { - double delta = elc_params.delta_mid_top * elc_params.delta_mid_bot; - double fac_delta_mid_bot = elc_params.delta_mid_bot / (1 - delta); - double fac_delta_mid_top = elc_params.delta_mid_top / (1 - delta); - double fac_delta = delta / (1 - delta); + double const delta = elc_params.delta_mid_top * elc_params.delta_mid_bot; + double const fac_delta_mid_bot = elc_params.delta_mid_bot / (1 - delta); + double const fac_delta_mid_top = elc_params.delta_mid_top / (1 - delta); + double const fac_delta = delta / (1 - delta); clear_vec(gblcblk, size); for (auto &p : particles) { @@ -443,6 +441,7 @@ static double z_energy(const ParticleRange &particles) { } distribute(size); + double eng = 0; if (this_node == 0) eng -= pref * (gblcblk[1] * gblcblk[2] - gblcblk[0] * gblcblk[3]); @@ -451,11 +450,11 @@ static double z_energy(const ParticleRange &particles) { /*****************************************************************/ static void add_z_force(const ParticleRange &particles) { - double pref = coulomb.prefactor * 2 * M_PI * ux * uy; + double const pref = coulomb.prefactor * 2 * M_PI * ux * uy; if (elc_params.dielectric_contrast_on) { auto local_particles = particles; - int size = 1; + int const size = 1; if (elc_params.const_pot) { clear_vec(gblcblk, size); /* just counter the 2 pi |z| contribution stemming from P3M */ @@ -466,10 +465,10 @@ static void add_z_force(const ParticleRange &particles) { gblcblk[0] += elc_params.delta_mid_top * p.p.q; } } else { - double delta = elc_params.delta_mid_top * elc_params.delta_mid_bot; - double fac_delta_mid_bot = elc_params.delta_mid_bot / (1 - delta); - double fac_delta_mid_top = elc_params.delta_mid_top / (1 - delta); - double fac_delta = delta / (1 - delta); + double const delta = elc_params.delta_mid_top * elc_params.delta_mid_bot; + double const fac_delta_mid_bot = elc_params.delta_mid_bot / (1 - delta); + double const fac_delta_mid_top = elc_params.delta_mid_top / (1 - delta); + double const fac_delta = delta / (1 - delta); clear_vec(gblcblk, size); for (auto &p : local_particles) { @@ -717,10 +716,9 @@ static void setup_Q(int q, double omega, const ParticleRange &particles) { } static void add_P_force(const ParticleRange &particles) { - int ic; - int size = 4; + int const size = 4; - ic = 0; + int ic = 0; for (auto &p : particles) { p.f.f[0] += partblk[size * ic + POQESM] * gblcblk[POQECP] - partblk[size * ic + POQECM] * gblcblk[POQESP] + @@ -735,11 +733,11 @@ static void add_P_force(const ParticleRange &particles) { } static double P_energy(double omega, int n_part) { - int size = 4; + int const size = 4; double eng = 0; - double pref = 1 / omega; + double const pref = 1 / omega; - for (unsigned ic = 0; ic < n_part; ic++) { + for (int ic = 0; ic < n_part; ic++) { eng += pref * (partblk[size * ic + POQECM] * gblcblk[POQECP] + partblk[size * ic + POQESM] * gblcblk[POQESP] + partblk[size * ic + POQECP] * gblcblk[POQECM] + @@ -750,10 +748,9 @@ static double P_energy(double omega, int n_part) { } static void add_Q_force(const ParticleRange &particles) { - int ic; - int size = 4; + int const size = 4; - ic = 0; + int ic = 0; for (auto &p : particles) { p.f.f[1] += partblk[size * ic + POQESM] * gblcblk[POQECP] - partblk[size * ic + POQECM] * gblcblk[POQESP] + @@ -768,11 +765,11 @@ static void add_Q_force(const ParticleRange &particles) { } static double Q_energy(double omega, int n_part) { - int size = 4; + int const size = 4; double eng = 0; - double pref = 1 / omega; + double const pref = 1 / omega; - for (unsigned ic = 0; ic < n_part; ic++) { + for (int ic = 0; ic < n_part; ic++) { eng += pref * (partblk[size * ic + POQECM] * gblcblk[POQECP] + partblk[size * ic + POQESM] * gblcblk[POQESP] + partblk[size * ic + POQECP] * gblcblk[POQECM] + @@ -917,13 +914,11 @@ static void setup_PQ(int p, int q, double omega, static void add_PQ_force(int p, int q, double omega, const ParticleRange &particles) { - int ic; - - double pref_x = C_2PI * ux * p / omega; - double pref_y = C_2PI * uy * q / omega; - int size = 8; + double const pref_x = C_2PI * ux * p / omega; + double const pref_y = C_2PI * uy * q / omega; + int const size = 8; - ic = 0; + int ic = 0; for (auto &p : particles) { p.f.f[0] += pref_x * (partblk[size * ic + PQESCM] * gblcblk[PQECCP] + partblk[size * ic + PQESSM] * gblcblk[PQECSP] - @@ -954,11 +949,11 @@ static void add_PQ_force(int p, int q, double omega, } static double PQ_energy(double omega, int n_part) { - int size = 8; + int const size = 8; double eng = 0; - double pref = 1 / omega; + double const pref = 1 / omega; - for (unsigned ic = 0; ic < n_part; ic++) { + for (int ic = 0; ic < n_part; ic++) { eng += pref * (partblk[size * ic + PQECCM] * gblcblk[PQECCP] + partblk[size * ic + PQECSM] * gblcblk[PQECSP] + partblk[size * ic + PQESCM] * gblcblk[PQESCP] + @@ -1053,9 +1048,9 @@ double ELC_energy(const ParticleRange &particles) { } int ELC_tune(double error) { - double err; - double h = elc_params.h, lz = box_geo.length()[2]; - double min_inv_boxl = std::min(ux, uy); + double const h = elc_params.h; + double lz = box_geo.length()[2]; + double const min_inv_boxl = std::min(ux, uy); if (elc_params.dielectric_contrast_on) { // adjust lz according to dielectric layer method @@ -1067,6 +1062,7 @@ int ELC_tune(double error) { elc_params.far_cut = min_inv_boxl; + double err; do { const auto prefactor = 2 * Utils::pi() * elc_params.far_cut; @@ -1277,7 +1273,7 @@ void ELC_p3m_charge_assign_both(const ParticleRange &particles) { for (int i = 0; i < p3m.local_mesh.size; i++) p3m.rs_mesh[i] = 0.0; - for (auto &p : particles) { + for (auto const &p : particles) { if (p.p.q != 0.0) { p3m_assign_charge(p.p.q, p.r.p, p3m.inter_weights); assign_image_charge(p); @@ -1290,7 +1286,7 @@ void ELC_p3m_charge_assign_image(const ParticleRange &particles) { for (int i = 0; i < p3m.local_mesh.size; i++) p3m.rs_mesh[i] = 0.0; - for (auto &p : particles) { + for (auto const &p : particles) { if (p.p.q != 0.0) { assign_image_charge(p); } @@ -1325,7 +1321,7 @@ Utils::Vector3d ELC_P3M_dielectric_layers_force_contribution( double ELC_P3M_dielectric_layers_energy_contribution( Utils::Vector3d const &pos1, Utils::Vector3d const &pos2, double q1q2) { - double eng = {}; + double eng = 0.0; if (pos1[2] < elc_params.space_layer) { auto const q = elc_params.delta_mid_bot * q1q2; diff --git a/src/core/electrostatics_magnetostatics/fft.cpp b/src/core/electrostatics_magnetostatics/fft.cpp index 0337e7f0ece..5a94ffee928 100644 --- a/src/core/electrostatics_magnetostatics/fft.cpp +++ b/src/core/electrostatics_magnetostatics/fft.cpp @@ -277,25 +277,21 @@ int calc_send_block(const int *pos1, const int *grid1, const int *pos2, void pack_block_permute1(double const *const in, double *const out, const int *start, const int *size, const int *dim, int element) { - /* slow, mid and fast changing indices for input grid */ - int s, m, f, e; - /* linear index of in grid, linear index of out grid */ - int li_in, li_out = 0; + /* offsets for indices in input grid */ - int m_in_offset, s_in_offset; + auto const m_in_offset = element * (dim[2] - size[2]); + auto const s_in_offset = element * (dim[2] * (dim[1] - size[1])); /* offset for mid changing indices of output grid */ - int m_out_offset; - - m_in_offset = element * (dim[2] - size[2]); - s_in_offset = element * (dim[2] * (dim[1] - size[1])); - m_out_offset = (element * size[0]) - element; - li_in = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); - - for (s = 0; s < size[0]; s++) { /* fast changing out */ - li_out = element * s; - for (m = 0; m < size[1]; m++) { /* slow changing out */ - for (f = 0; f < size[2]; f++) { /* mid changing out */ - for (e = 0; e < element; e++) + auto const m_out_offset = (element * size[0]) - element; + /* linear index of in grid */ + int li_in = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); + + for (int s = 0; s < size[0]; s++) { /* fast changing out */ + /* linear index of out grid */ + int li_out = element * s; + for (int m = 0; m < size[1]; m++) { /* slow changing out */ + for (int f = 0; f < size[2]; f++) { /* mid changing out */ + for (int e = 0; e < element; e++) out[li_out++] = in[li_in++]; li_out += m_out_offset; } @@ -329,28 +325,22 @@ void pack_block_permute1(double const *const in, double *const out, void pack_block_permute2(double const *const in, double *const out, const int *start, const int *size, const int *dim, int element) { - /* slow, mid and fast changing indices for input grid */ - int s, m, f, e; - /* linear index of in grid, linear index of out grid */ - int li_in, li_out = 0; + /* offsets for indices in input grid */ - int m_in_offset, s_in_offset; + auto const m_in_offset = element * (dim[2] - size[2]); + auto const s_in_offset = element * (dim[2] * (dim[1] - size[1])); /* offset for slow changing index of output grid */ - int s_out_offset; - /* start index for mid changing index of output grid */ - int m_out_start; - - m_in_offset = element * (dim[2] - size[2]); - s_in_offset = element * (dim[2] * (dim[1] - size[1])); - s_out_offset = (element * size[0] * size[1]) - element; - li_in = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); - - for (s = 0; s < size[0]; s++) { /* mid changing out */ - m_out_start = element * (s * size[1]); - for (m = 0; m < size[1]; m++) { /* fast changing out */ - li_out = m_out_start + element * m; - for (f = 0; f < size[2]; f++) { /* slow changing out */ - for (e = 0; e < element; e++) + auto const s_out_offset = (element * size[0] * size[1]) - element; + /* linear index of in grid */ + int li_in = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); + + for (int s = 0; s < size[0]; s++) { /* mid changing out */ + auto const m_out_start = element * (s * size[1]); + for (int m = 0; m < size[1]; m++) { /* fast changing out */ + /* linear index of out grid */ + int li_out = m_out_start + element * m; + for (int f = 0; f < size[2]; f++) { /* slow changing out */ + for (int e = 0; e < element; e++) out[li_out++] = in[li_in++]; li_out += s_out_offset; } @@ -767,20 +757,16 @@ void fft_perform_back(double *data, bool check_complex, fft_data_struct &fft, void fft_pack_block(double const *const in, double *const out, int const start[3], int const size[3], int const dim[3], int element) { - /* linear index of in grid, linear index of out grid */ - int li_in, li_out = 0; - /* copy size */ - int copy_size; + + auto const copy_size = element * size[2] * static_cast(sizeof(double)); /* offsets for indices in input grid */ - int m_in_offset, s_in_offset; + auto const m_in_offset = element * dim[2]; + auto const s_in_offset = element * (dim[2] * (dim[1] - size[1])); /* offsets for indices in output grid */ - int m_out_offset; - - copy_size = element * size[2] * static_cast(sizeof(double)); - m_in_offset = element * dim[2]; - s_in_offset = element * (dim[2] * (dim[1] - size[1])); - m_out_offset = element * size[2]; - li_in = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); + auto const m_out_offset = element * size[2]; + /* linear index of in grid, linear index of out grid */ + int li_in = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); + int li_out = 0; for (int s = 0; s < size[0]; s++) { for (int m = 0; m < size[1]; m++) { @@ -795,25 +781,19 @@ void fft_pack_block(double const *const in, double *const out, void fft_unpack_block(double const *const in, double *const out, int const start[3], int const size[3], int const dim[3], int element) { - /* mid and slow changing indices */ - int m, s; - /* linear index of in grid, linear index of out grid */ - int li_in = 0, li_out; - /* copy size */ - int copy_size; - /* offset for indices in input grid */ - int m_in_offset; - /* offsets for indices in output grid */ - int m_out_offset, s_out_offset; - copy_size = element * size[2] * static_cast(sizeof(double)); - m_out_offset = element * dim[2]; - s_out_offset = element * (dim[2] * (dim[1] - size[1])); - m_in_offset = element * size[2]; - li_out = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); + auto const copy_size = element * size[2] * static_cast(sizeof(double)); + /* offsets for indices in output grid */ + auto const m_out_offset = element * dim[2]; + auto const s_out_offset = element * (dim[2] * (dim[1] - size[1])); + /* offset for indices in input grid */ + auto const m_in_offset = element * size[2]; + /* linear index of in grid, linear index of out grid */ + int li_in = 0; + int li_out = element * (start[2] + dim[2] * (start[1] + dim[1] * start[0])); - for (s = 0; s < size[0]; s++) { - for (m = 0; m < size[1]; m++) { + for (int s = 0; s < size[0]; s++) { + for (int m = 0; m < size[1]; m++) { memmove(&(out[li_out]), &(in[li_in]), copy_size); li_in += m_in_offset; li_out += m_out_offset; diff --git a/src/core/electrostatics_magnetostatics/specfunc.hpp b/src/core/electrostatics_magnetostatics/specfunc.hpp index 8512a18b009..dbc5b244b25 100644 --- a/src/core/electrostatics_magnetostatics/specfunc.hpp +++ b/src/core/electrostatics_magnetostatics/specfunc.hpp @@ -105,7 +105,7 @@ inline double evaluateAsChebychevSeriesAt(Utils::Span series, assert(series.size() >= 3); const double *c = series.data(); - double x2 = 2.0 * x; + double const x2 = 2.0 * x; double dd = c[series.size() - 1]; double d = x2 * dd + c[series.size() - 2]; for (auto j = static_cast(series.size()) - 3; j >= 1; j--) { diff --git a/src/core/forcecap.hpp b/src/core/forcecap.hpp index 13158d70ebd..7a0d940d1af 100644 --- a/src/core/forcecap.hpp +++ b/src/core/forcecap.hpp @@ -18,6 +18,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#ifndef FORCECAP_HPP +#define FORCECAP_HPP #include "ParticleRange.hpp" @@ -25,3 +27,5 @@ void forcecap_set(double forcecap); double forcecap_get(); void forcecap_cap(ParticleRange particles); + +#endif diff --git a/src/core/global.cpp b/src/core/global.cpp index 21c8f8585ed..907ac71bb7c 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -186,21 +187,24 @@ std::size_t hash_value(Datafield const &field) { void common_bcast_parameter(int i) { switch (fields.at(i).type) { case Datafield::Type::INT: - MPI_Bcast((int *)fields.at(i).data, fields.at(i).dimension, MPI_INT, 0, - comm_cart); + boost::mpi::broadcast(comm_cart, reinterpret_cast(fields.at(i).data), + fields.at(i).dimension, 0); break; case Datafield::Type::UNSIGNED_LONG: - MPI_Bcast((unsigned long *)fields.at(i).data, fields.at(i).dimension, - MPI_UNSIGNED_LONG, 0, comm_cart); + boost::mpi::broadcast(comm_cart, + reinterpret_cast(fields.at(i).data), + fields.at(i).dimension, 0); break; case Datafield::Type::BOOL: static_assert(sizeof(bool) == sizeof(char), "bool datatype does not have the expected size"); - MPI_Bcast((char *)fields.at(i).data, 1, MPI_CHAR, 0, comm_cart); + boost::mpi::broadcast(comm_cart, + reinterpret_cast(fields.at(i).data), 1, 0); break; case Datafield::Type::DOUBLE: - MPI_Bcast((double *)fields.at(i).data, fields.at(i).dimension, MPI_DOUBLE, - 0, comm_cart); + boost::mpi::broadcast(comm_cart, + reinterpret_cast(fields.at(i).data), + fields.at(i).dimension, 0); break; default: throw std::runtime_error("Unknown type."); diff --git a/src/core/io/mpiio/mpiio.cpp b/src/core/io/mpiio/mpiio.cpp index c6b09072075..572835e3661 100644 --- a/src/core/io/mpiio/mpiio.cpp +++ b/src/core/io/mpiio/mpiio.cpp @@ -91,9 +91,9 @@ static void mpiio_dump_array(const std::string &fn, T *arr, size_t len, MPI_INFO_NULL, &f); if (ret) { char buf[MPI_MAX_ERROR_STRING]; - int len; - MPI_Error_string(ret, buf, &len); - buf[len] = '\0'; + int buf_len; + MPI_Error_string(ret, buf, &buf_len); + buf[buf_len] = '\0'; fprintf(stderr, "MPI-IO Error: Could not open file \"%s\": %s\n", fn.c_str(), buf); errexit(); @@ -116,15 +116,14 @@ static void mpiio_dump_array(const std::string &fn, T *arr, size_t len, * \param fields The dumped fields */ static void dump_info(const std::string &fn, unsigned fields) { - static std::vector npartners; - int success; FILE *f = fopen(fn.c_str(), "wb"); if (!f) { fprintf(stderr, "MPI-IO Error: Could not open %s for writing.\n", fn.c_str()); errexit(); } - success = (fwrite(&fields, sizeof(fields), 1, f) == 1); + static std::vector npartners; + int success = (fwrite(&fields, sizeof(fields), 1, f) == 1); // Pack the necessary information of bonded_ia_params: // The number of partners. This is needed to interpret the bond IntList. if (bonded_ia_params.size() > npartners.size()) @@ -151,8 +150,7 @@ static void dump_info(const std::string &fn, unsigned fields) { void mpi_mpiio_common_write(const char *filename, unsigned fields, const ParticleRange &particles) { std::string fnam(filename); - int nlocalpart = particles.size(), pref = 0, bpref = 0; - int rank; + int const nlocalpart = static_cast(particles.size()); // Keep static buffers in order not having to allocate them on every // function call static std::vector pos, vel; @@ -160,6 +158,7 @@ void mpi_mpiio_common_write(const char *filename, unsigned fields, // Nlocalpart prefixes // Prefixes based for arrays: 3 * pref for vel, pos. + int pref = 0, bpref = 0; MPI_Exscan(&nlocalpart, &pref, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); // Realloc static buffers if necessary @@ -194,6 +193,7 @@ void mpi_mpiio_common_write(const char *filename, unsigned fields, i3 += 3; } + int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) dump_info(fnam + ".head", fields); @@ -225,7 +225,7 @@ void mpi_mpiio_common_write(const char *filename, unsigned fields, } // Determine the prefixes in the bond file - int bonds_size = bonds.size(); + int bonds_size = static_cast(bonds.size()); MPI_Exscan(&bonds_size, &bpref, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); mpiio_dump_array(fnam + ".boff", &bonds_size, 1, rank, MPI_INT); @@ -270,9 +270,9 @@ static void mpiio_read_array(const std::string &fn, T *arr, size_t len, if (ret) { char buf[MPI_MAX_ERROR_STRING]; - int len; - MPI_Error_string(ret, buf, &len); - buf[len] = '\0'; + int buf_len; + MPI_Error_string(ret, buf, &buf_len); + buf[buf_len] = '\0'; fprintf(stderr, "MPI-IO Error: Could not open file \"%s\": %s\n", fn.c_str(), buf); errexit(); diff --git a/src/python/espressomd/reaction_ensemble.pyx b/src/python/espressomd/reaction_ensemble.pyx index 9fd3b9b6aaf..4f6f0698919 100644 --- a/src/python/espressomd/reaction_ensemble.pyx +++ b/src/python/espressomd/reaction_ensemble.pyx @@ -200,10 +200,8 @@ cdef class ReactionAlgorithm: self._params[k] = kwargs[k] for k in self._valid_keys_add(): - try: + if k in kwargs: self._params[k] = kwargs[k] - except BaseException: - pass self._check_lengths_of_arrays() self._validate_params_default_charge() self._set_params_in_es_core_add() diff --git a/src/python/espressomd/script_interface.pyx b/src/python/espressomd/script_interface.pyx index 23565dec80f..593fb1f7d02 100644 --- a/src/python/espressomd/script_interface.pyx +++ b/src/python/espressomd/script_interface.pyx @@ -100,7 +100,7 @@ cdef class PScriptInterface: try: ptr = get_instance(oid).lock() self.set_sip(ptr) - except BaseException: + except Exception: raise Exception("Could not get sip for given_id") def id(self): diff --git a/src/python/espressomd/visualization.pyx b/src/python/espressomd/visualization.pyx index 93b53307f36..1f787db6ec5 100644 --- a/src/python/espressomd/visualization.pyx +++ b/src/python/espressomd/visualization.pyx @@ -22,7 +22,7 @@ try: from .visualization_mayavi import mayaviLive else: raise ImportError("Cannot connect to X server") -except BaseException as e: +except Exception as e: if isinstance(e, ImportError) or isinstance(e, RuntimeError) and \ e.args[0] == 'No pyface.toolkits plugin could be loaded for wx': class mayaviLive: diff --git a/src/python/espressomd/visualization_mayavi.pyx b/src/python/espressomd/visualization_mayavi.pyx index 050365c5a4c..08396a16aaa 100644 --- a/src/python/espressomd/visualization_mayavi.pyx +++ b/src/python/espressomd/visualization_mayavi.pyx @@ -110,13 +110,13 @@ cdef class mayaviLive: IF LENNARD_JONES: try: radius = 0.5 * get_ia_param(t, t).lj.sig - except BaseException: + except Exception: radius = 0. IF WCA: if radius == 0: try: radius = 0.5 * get_ia_param(t, t).wca.sig - except BaseException: + except Exception: radius = 0. if radius == 0: @@ -131,7 +131,7 @@ cdef class mayaviLive: else: try: radius = self.particle_sizes[t] - except BaseException: + except Exception: radius = radius_from_lj(t) return radius diff --git a/src/python/espressomd/visualization_opengl.py b/src/python/espressomd/visualization_opengl.py index 8530f2c1de0..b827fbc70c5 100644 --- a/src/python/espressomd/visualization_opengl.py +++ b/src/python/espressomd/visualization_opengl.py @@ -971,7 +971,7 @@ def radius_by_lj(part_type): if radius == 0: radius = self.system.non_bonded_inter[part_type, part_type].wca.get_params()[ 'sigma'] * 0.5 - except BaseException: + except Exception: radius = 0.5 if radius == 0: radius = 0.5 diff --git a/src/python/object_in_fluid/oif_classes.py b/src/python/object_in_fluid/oif_classes.py index 3867a8bb241..883639e7087 100644 --- a/src/python/object_in_fluid/oif_classes.py +++ b/src/python/object_in_fluid/oif_classes.py @@ -460,9 +460,6 @@ def copy(self, origin=None, particle_type=-1, particle_mass=1.0, rotate=None): mesh = Mesh(system=self.system) mesh.ids_extremal_points = self.ids_extremal_points - rotation = np.array([[1.0, 0.0, 0.0], - [0.0, 1.0, 0.0], - [0.0, 0.0, 1.0]]) if rotate is not None: # variables for rotation @@ -474,8 +471,7 @@ def copy(self, origin=None, particle_type=-1, particle_mass=1.0, sc = np.sin(rotate[2]) rotation = np.array( [[cb * cc, sa * sb * cc - ca * sc, sc * sa + cc * sb * ca], - [cb * sc, ca * cc + sa * sb * - sc, sc * sb * ca - cc * sa], + [cb * sc, ca * cc + sa * sb * sc, sc * sb * ca - cc * sa], [-sb, cb * sa, ca * cb]]) for point in self.points: diff --git a/testsuite/python/rotation.py b/testsuite/python/rotation.py index ccd6cc9ac9a..fe8e035df9e 100644 --- a/testsuite/python/rotation.py +++ b/testsuite/python/rotation.py @@ -3,7 +3,7 @@ try: import scipy.spatial.transform as sst -except BaseException: +except ImportError: pass import espressomd.rotation