diff --git a/src/core/BondList.hpp b/src/core/BondList.hpp index fd78127b6c2..e3b0eb00aa2 100644 --- a/src/core/BondList.hpp +++ b/src/core/BondList.hpp @@ -139,9 +139,9 @@ class BondList { auto const id_pos = find_end(m_it); auto const partners_begin = m_it; auto const partners_end = id_pos; - return {-(*id_pos) - 1, - Utils::make_span(std::addressof(*partners_begin), - std::distance(partners_begin, partners_end))}; + auto const dist = std::distance(partners_begin, partners_end); + return {-(*id_pos) - 1, Utils::make_span(std::addressof(*partners_begin), + static_cast(dist))}; } }; @@ -206,7 +206,9 @@ class BondList { * @brief Number of bonds. * @return The number of bonds in the list. */ - size_type size() const { return std::distance(begin(), end()); } + auto size() const { + return static_cast(std::distance(begin(), end())); + } /** * @brief Erase all bonds from the list. diff --git a/src/core/BoxGeometry.hpp b/src/core/BoxGeometry.hpp index 81503f9976d..7224ec4a2b7 100644 --- a/src/core/BoxGeometry.hpp +++ b/src/core/BoxGeometry.hpp @@ -187,7 +187,8 @@ class BoxGeometry { Utils::Vector get_mi_vector(const Utils::Vector &a, const Utils::Vector &b) const { if (type() == BoxType::LEES_EDWARDS) { - auto const shear_plane_normal = lees_edwards_bc().shear_plane_normal; + auto const shear_plane_normal = + static_cast(lees_edwards_bc().shear_plane_normal); auto a_tmp = a; auto b_tmp = b; a_tmp[shear_plane_normal] = Algorithm::periodic_fold( @@ -226,9 +227,13 @@ class BoxGeometry { auto ret = u - v; if (type() == BoxType::LEES_EDWARDS) { auto const &le = m_lees_edwards_bc; - auto const dy = x[le.shear_plane_normal] - y[le.shear_plane_normal]; - if (fabs(dy) > 0.5 * length_half()[le.shear_plane_normal]) { - ret[le.shear_direction] -= Utils::sgn(dy) * le.shear_velocity; + auto const shear_plane_normal = + static_cast(le.shear_plane_normal); + auto const shear_direction = + static_cast(le.shear_direction); + auto const dy = x[shear_plane_normal] - y[shear_plane_normal]; + if (fabs(dy) > 0.5 * length_half()[shear_plane_normal]) { + ret[shear_direction] -= Utils::sgn(dy) * le.shear_velocity; } } return ret; @@ -263,7 +268,7 @@ inline std::pair fold_coordinate(double pos, int image_box, */ inline void fold_position(Utils::Vector3d &pos, Utils::Vector3i &image_box, const BoxGeometry &box) { - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { if (box.periodic(i)) { std::tie(pos[i], image_box[i]) = fold_coordinate(pos[i], image_box[i], box.length()[i]); @@ -279,7 +284,7 @@ inline void fold_position(Utils::Vector3d &pos, Utils::Vector3i &image_box, inline Utils::Vector3d folded_position(const Utils::Vector3d &p, const BoxGeometry &box) { Utils::Vector3d p_folded; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { if (box.periodic(i)) { p_folded[i] = Algorithm::periodic_fold(p[i], box.length()[i]); } else { diff --git a/src/core/Observable_stat.cpp b/src/core/Observable_stat.cpp index 527bad5da96..252296760c4 100644 --- a/src/core/Observable_stat.cpp +++ b/src/core/Observable_stat.cpp @@ -37,7 +37,7 @@ #include #include -inline std::size_t max_non_bonded_pairs() { +static auto max_non_bonded_pairs() { auto const n = static_cast(max_seen_particle_type); return (n * (n + 1)) / 2; } @@ -52,7 +52,8 @@ Observable_stat::Observable_stat(std::size_t chunk_size) #else constexpr std::size_t n_vs = 0; #endif - auto const n_bonded = bonded_ia_params.get_next_key(); + auto const n_bonded = + static_cast(bonded_ia_params.get_next_key()); auto const n_non_bonded = max_non_bonded_pairs(); constexpr std::size_t n_ext_fields = 1; // reduction over all fields constexpr std::size_t n_kinetic = 1; // linear+angular kinetic contributions diff --git a/src/core/Particle.hpp b/src/core/Particle.hpp index 7b0520a65b1..0be5ae40b15 100644 --- a/src/core/Particle.hpp +++ b/src/core/Particle.hpp @@ -38,11 +38,9 @@ #include namespace detail { -inline void check_axis_idx_valid(int const axis) { - assert(axis >= 0 and axis <= 2); -} +inline void check_axis_idx_valid(unsigned int const axis) { assert(axis <= 2); } -inline bool get_nth_bit(uint8_t const bitfield, int const bit_idx) { +inline bool get_nth_bit(uint8_t const bitfield, unsigned int const bit_idx) { return bitfield & (1u << bit_idx); } } // namespace detail @@ -463,11 +461,11 @@ struct Particle { // NOLINT(bugprone-exception-escape) auto const &rotation() const { return p.rotation; } auto &rotation() { return p.rotation; } bool can_rotate() const { return static_cast(p.rotation); } - bool can_rotate_around(int const axis) const { + bool can_rotate_around(unsigned int const axis) const { detail::check_axis_idx_valid(axis); return detail::get_nth_bit(p.rotation, axis); } - void set_can_rotate_around(int const axis, bool const rot_flag) { + void set_can_rotate_around(unsigned int const axis, bool const rot_flag) { detail::check_axis_idx_valid(axis); if (rot_flag) { p.rotation |= static_cast(1u << axis); @@ -492,7 +490,7 @@ struct Particle { // NOLINT(bugprone-exception-escape) auto calc_director() const { return r.calc_director(); } #else // ROTATION auto can_rotate() const { return false; } - auto can_rotate_around(int const axis) const { return false; } + auto can_rotate_around(unsigned int const axis) const { return false; } #endif // ROTATION #ifdef DIPOLES auto const &dipm() const { return p.dipm; } @@ -539,7 +537,7 @@ struct Particle { // NOLINT(bugprone-exception-escape) auto const &fixed() const { return p.ext_flag; } auto &fixed() { return p.ext_flag; } bool has_fixed_coordinates() const { return static_cast(p.ext_flag); } - bool is_fixed_along(int const axis) const { + bool is_fixed_along(unsigned int const axis) const { detail::check_axis_idx_valid(axis); return detail::get_nth_bit(p.ext_flag, axis); } @@ -555,7 +553,7 @@ struct Particle { // NOLINT(bugprone-exception-escape) auto &ext_force() { return p.ext_force; } #else // EXTERNAL_FORCES constexpr bool has_fixed_coordinates() const { return false; } - constexpr bool is_fixed_along(int const) const { return false; } + constexpr bool is_fixed_along(unsigned int const) const { return false; } #endif // EXTERNAL_FORCES #ifdef ENGINE auto const &swimming() const { return p.swim; } diff --git a/src/core/bond_breakage/bond_breakage.cpp b/src/core/bond_breakage/bond_breakage.cpp index c8ec9babf2a..42632731682 100644 --- a/src/core/bond_breakage/bond_breakage.cpp +++ b/src/core/bond_breakage/bond_breakage.cpp @@ -173,7 +173,7 @@ static void remove_pair_bonds_to(Particle &p, int other_pid) { std::vector> to_delete; for (auto b : p.bonds()) { if (b.partner_ids().size() == 1 and b.partner_ids()[0] == other_pid) - to_delete.emplace_back(std::pair{b.bond_id(), other_pid}); + to_delete.emplace_back(b.bond_id(), other_pid); } for (auto const &b : to_delete) { remove_bond(p, BondView(b.first, {&b.second, 1})); diff --git a/src/core/cell_system/AtomDecomposition.hpp b/src/core/cell_system/AtomDecomposition.hpp index 934a91bccfb..207ec4f0ed0 100644 --- a/src/core/cell_system/AtomDecomposition.hpp +++ b/src/core/cell_system/AtomDecomposition.hpp @@ -124,7 +124,7 @@ class AtomDecomposition : public ParticleDecomposition { /** * @brief Get the local cell. */ - Cell &local() { return cells.at(m_comm.rank()); } + Cell &local() { return cells.at(static_cast(m_comm.rank())); } void configure_neighbors(); GhostCommunicator prepare_comm(); diff --git a/src/core/cell_system/CellStructure.hpp b/src/core/cell_system/CellStructure.hpp index 8cf45b6d7c6..27c487e9b3d 100644 --- a/src/core/cell_system/CellStructure.hpp +++ b/src/core/cell_system/CellStructure.hpp @@ -166,10 +166,10 @@ struct CellStructure { // cppcheck-suppress assertWithSideEffect assert(not p or p->id() == id); - if (id >= m_particle_index.size()) - m_particle_index.resize(id + 1); + if (static_cast(id) >= m_particle_index.size()) + m_particle_index.resize(static_cast(id + 1)); - m_particle_index[id] = p; + m_particle_index[static_cast(id)] = p; } /** @@ -234,20 +234,20 @@ struct CellStructure { Particle *get_local_particle(int id) { assert(id >= 0); - if (id >= m_particle_index.size()) + if (static_cast(id) >= m_particle_index.size()) return nullptr; - return m_particle_index[id]; + return m_particle_index[static_cast(id)]; } /** @overload */ const Particle *get_local_particle(int id) const { assert(id >= 0); - if (id >= m_particle_index.size()) + if (static_cast(id) >= m_particle_index.size()) return nullptr; - return m_particle_index[id]; + return m_particle_index[static_cast(id)]; } template diff --git a/src/core/cell_system/RegularDecomposition.cpp b/src/core/cell_system/RegularDecomposition.cpp index 6bb4ec142bc..6500a57a829 100644 --- a/src/core/cell_system/RegularDecomposition.cpp +++ b/src/core/cell_system/RegularDecomposition.cpp @@ -53,7 +53,7 @@ Cell *RegularDecomposition::position_to_cell(const Utils::Vector3d &pos) { Utils::Vector3i cpos; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { cpos[i] = static_cast(std::floor(pos[i] * inv_cell_size[i])) + 1 - cell_offset[i]; @@ -266,8 +266,9 @@ void RegularDecomposition::fill_comm_cell_lists(ParticleList **part_lists, *part_lists++ = &(cells.at(i).particles()); } } + Utils::Vector3d RegularDecomposition::max_cutoff() const { - auto dir_max_range = [this](int i) { + auto dir_max_range = [this](unsigned int i) { return std::min(0.5 * m_box.length()[i], m_local_box.length()[i]); }; @@ -307,7 +308,7 @@ void RegularDecomposition::create_cell_grid(double range) { auto const volume = Utils::product(local_box_l); auto const scale = std::cbrt(RegularDecomposition::max_num_cells / volume); - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { /* this is at least 1 */ cell_grid[i] = static_cast(std::ceil(local_box_l[i] * scale)); cell_range[i] = local_box_l[i] / static_cast(cell_grid[i]); @@ -370,7 +371,7 @@ void RegularDecomposition::create_cell_grid(double range) { /* now set all dependent variables */ int new_cells = 1; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { ghost_cell_grid[i] = cell_grid[i] + 2; new_cells *= ghost_cell_grid[i]; cell_size[i] = m_local_box.length()[i] / static_cast(cell_grid[i]); @@ -380,7 +381,7 @@ void RegularDecomposition::create_cell_grid(double range) { /* allocate cell array and cell pointer arrays */ cells.clear(); - cells.resize(new_cells); + cells.resize(static_cast(new_cells)); m_local_cells.resize(n_local_cells); m_ghost_cells.resize(new_cells - n_local_cells); } diff --git a/src/core/collision.cpp b/src/core/collision.cpp index 981d5c191c0..a32dec37243 100644 --- a/src/core/collision.cpp +++ b/src/core/collision.cpp @@ -93,7 +93,7 @@ static bool bind_centers() { // but does so later in the process. This is needed to guarantee that // a particle can only be glued once, even if queued twice in a single // time step - return collision_params.mode != CollisionModeType::OFF && + return collision_params.mode != CollisionModeType::OFF and collision_params.mode != CollisionModeType::GLUE_TO_SURF; } @@ -130,7 +130,7 @@ void Collision_parameters::initialize() { #ifdef VIRTUAL_SITES // Check vs placement parameter if (collision_params.mode == CollisionModeType::BIND_VS) { - if ((collision_params.vs_placement < 0.) || + if ((collision_params.vs_placement < 0.) or (collision_params.vs_placement > 1.)) { throw std::domain_error( "Parameter 'vs_placement' must be between 0 and 1"); @@ -139,13 +139,13 @@ void Collision_parameters::initialize() { #endif // Check if bonded ia exist - if ((collision_params.mode == CollisionModeType::BIND_CENTERS) && + if ((collision_params.mode == CollisionModeType::BIND_CENTERS) and !bonded_ia_params.contains(collision_params.bond_centers)) { throw std::runtime_error( "Bond in parameter 'bond_centers' was not added to the system"); } - if ((collision_params.mode == CollisionModeType::BIND_VS) && + if ((collision_params.mode == CollisionModeType::BIND_VS) and !bonded_ia_params.contains(collision_params.bond_vs)) { throw std::runtime_error( "Bond in parameter 'bond_vs' was not added to the system"); @@ -153,16 +153,16 @@ void Collision_parameters::initialize() { // If the bond type to bind particle centers is not a pair bond... // Check that the bonds have the right number of partners - if ((collision_params.mode == CollisionModeType::BIND_CENTERS) && + if ((collision_params.mode == CollisionModeType::BIND_CENTERS) and (get_bond_num_partners(collision_params.bond_centers) != 1)) { throw std::runtime_error("The bond type to be used for binding particle " "centers needs to be a pair bond"); } // The bond between the virtual sites can be pair or triple - if ((collision_params.mode == CollisionModeType::BIND_VS) && - !(get_bond_num_partners(collision_params.bond_vs) == 1 || - get_bond_num_partners(collision_params.bond_vs) == 2)) { + if ((collision_params.mode == CollisionModeType::BIND_VS) and + (get_bond_num_partners(collision_params.bond_vs) != 1 and + get_bond_num_partners(collision_params.bond_vs) != 2)) { throw std::runtime_error("The bond type to be used for binding virtual " "sites needs to be a pair or three-particle bond"); } @@ -242,10 +242,10 @@ const Particle &glue_to_surface_calc_vs_pos(const Particle &p1, const double dist_betw_part = vec21.norm(); // Find out, which is the particle to be glued. - if ((p1.type() == collision_params.part_type_to_be_glued) && + if ((p1.type() == collision_params.part_type_to_be_glued) and (p2.type() == collision_params.part_type_to_attach_vs_to)) { c = 1 - collision_params.dist_glued_part_to_vs / dist_betw_part; - } else if ((p2.type() == collision_params.part_type_to_be_glued) && + } else if ((p2.type() == collision_params.part_type_to_be_glued) and (p1.type() == collision_params.part_type_to_attach_vs_to)) { c = collision_params.dist_glued_part_to_vs / dist_betw_part; } else { @@ -299,8 +299,8 @@ void coldet_do_three_particle_bond(Particle &p, Particle const &p1, id2 = p2.id()](BondView const &bond) { auto const partner_ids = bond.partner_ids(); - return ((partner_ids[0] == id1) && (partner_ids[1] == id2)) || - ((partner_ids[0] == id2) && (partner_ids[1] == id1)); + return ((partner_ids[0] == id1) and (partner_ids[1] == id2)) or + ((partner_ids[0] == id2) and (partner_ids[1] == id1)); }; auto const &bonds = p.bonds(); @@ -450,7 +450,7 @@ void three_particle_binding_domain_decomposition( for (auto &c : gathered_queue) { // If we have both particles, at least as ghosts, Get the corresponding cell // indices - if (cell_structure.get_local_particle(c.pp1) && + if (cell_structure.get_local_particle(c.pp1) and cell_structure.get_local_particle(c.pp2)) { Particle &p1 = *cell_structure.get_local_particle(c.pp1); Particle &p2 = *cell_structure.get_local_particle(c.pp2); @@ -459,7 +459,7 @@ void three_particle_binding_domain_decomposition( if (cell1) three_particle_binding_do_search(cell1, p1, p2); - if (cell2 && cell1 != cell2) + if (cell2 and cell1 != cell2) three_particle_binding_do_search(cell2, p1, p2); } // If local particles exist diff --git a/src/core/cuda_init.cpp b/src/core/cuda_init.cpp index 49fbeb1f023..ff472ad04d8 100644 --- a/src/core/cuda_init.cpp +++ b/src/core/cuda_init.cpp @@ -89,7 +89,7 @@ std::vector cuda_gather_gpus() { if (this_node == 0) { std::set device_set; - int *n_gpu_array = new int[n_nodes]; + int *n_gpu_array = new int[static_cast(n_nodes)]; MPI_Gather(&n_gpus, 1, MPI_INT, n_gpu_array, 1, MPI_INT, 0, MPI_COMM_WORLD); /* insert local devices */ diff --git a/src/core/cuda_interface.cpp b/src/core/cuda_interface.cpp index 9fb68dc90bb..9fe7ae4ec38 100644 --- a/src/core/cuda_interface.cpp +++ b/src/core/cuda_interface.cpp @@ -115,9 +115,9 @@ void cuda_mpi_get_particles( static void add_forces_and_torques(ParticleRange particles, Utils::Span forces, Utils::Span torques) { - int i = 0; + unsigned int i = 0; for (auto &p : particles) { - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { p.force()[j] += static_cast(forces[3 * i + j]); #ifdef ROTATION p.torque()[j] += static_cast(torques[3 * i + j]); diff --git a/src/core/electrostatics/p3m.cpp b/src/core/electrostatics/p3m.cpp index df878133a18..c954125b5ee 100644 --- a/src/core/electrostatics/p3m.cpp +++ b/src/core/electrostatics/p3m.cpp @@ -285,7 +285,7 @@ CoulombP3M::CoulombP3M(P3MParameters &¶meters, double prefactor, } namespace { -template struct AssignCharge { +template struct AssignCharge { void operator()(p3m_data_struct &p3m, double q, Utils::Vector3d const &real_pos, p3m_interpolation_cache &inter_weights) { @@ -325,22 +325,23 @@ void CoulombP3M::charge_assign(ParticleRange const &particles) { for (int i = 0; i < p3m.local_mesh.size; i++) p3m.rs_mesh[i] = 0.0; - Utils::integral_parameter(p3m.params.cao, p3m, particles); + Utils::integral_parameter(p3m.params.cao, p3m, + particles); } void CoulombP3M::assign_charge(double q, Utils::Vector3d const &real_pos, p3m_interpolation_cache &inter_weights) { - Utils::integral_parameter(p3m.params.cao, p3m, q, - real_pos, inter_weights); + Utils::integral_parameter(p3m.params.cao, p3m, q, + real_pos, inter_weights); } void CoulombP3M::assign_charge(double q, Utils::Vector3d const &real_pos) { - Utils::integral_parameter(p3m.params.cao, p3m, q, - real_pos); + Utils::integral_parameter(p3m.params.cao, p3m, q, + real_pos); } namespace { -template struct AssignForces { +template struct AssignForces { void operator()(p3m_data_struct &p3m, double force_prefac, ParticleRange const &particles) const { using Utils::make_const_span; @@ -507,8 +508,8 @@ double CoulombP3M::long_range_kernel(bool force_flag, bool energy_flag, p3m.local_mesh.dim); auto const force_prefac = prefactor / volume; - Utils::integral_parameter(p3m.params.cao, p3m, - force_prefac, particles); + Utils::integral_parameter(p3m.params.cao, p3m, + force_prefac, particles); // add dipole forces if (p3m.params.epsilon != P3M_EPSILON_METALLIC) { @@ -733,7 +734,7 @@ void CoulombP3M::tune() { } void CoulombP3M::sanity_checks_boxl() const { - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { /* check k-space cutoff */ if (p3m.params.cao_cut[i] >= box_geo.length_half()[i]) { std::stringstream msg; @@ -750,10 +751,10 @@ void CoulombP3M::sanity_checks_boxl() const { } if (p3m.params.epsilon != P3M_EPSILON_METALLIC) { - if (!((box_geo.length()[0] == box_geo.length()[1]) and - (box_geo.length()[1] == box_geo.length()[2])) or - !((p3m.params.mesh[0] == p3m.params.mesh[1]) and - (p3m.params.mesh[1] == p3m.params.mesh[2]))) { + if ((box_geo.length()[0] != box_geo.length()[1]) or + (box_geo.length()[1] != box_geo.length()[2]) or + (p3m.params.mesh[0] != p3m.params.mesh[1]) or + (p3m.params.mesh[1] != p3m.params.mesh[2])) { throw std::runtime_error( "CoulombP3M: non-metallic epsilon requires cubic box"); } diff --git a/src/core/galilei/ComFixed.hpp b/src/core/galilei/ComFixed.hpp index 6eee9135c57..940626904ed 100644 --- a/src/core/galilei/ComFixed.hpp +++ b/src/core/galilei/ComFixed.hpp @@ -103,7 +103,7 @@ class ComFixed { if (it != m_type_index.end()) { auto const mass_frac = p.mass() / masses[it->second]; auto const &type_force = forces[it->second]; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { p.force()[i] -= mass_frac * type_force[i]; } } diff --git a/src/core/ghosts.cpp b/src/core/ghosts.cpp index 900f59b7759..6a22941130b 100644 --- a/src/core/ghosts.cpp +++ b/src/core/ghosts.cpp @@ -236,10 +236,10 @@ static std::size_t calc_transmit_size(unsigned data_parts) { static std::size_t calc_transmit_size(const GhostCommunication &ghost_comm, unsigned int data_parts) { if (data_parts & GHOSTTRANS_PARTNUM) - return sizeof(int) * ghost_comm.part_lists.size(); + return sizeof(unsigned int) * ghost_comm.part_lists.size(); auto const n_part = boost::accumulate( - ghost_comm.part_lists, 0ul, + ghost_comm.part_lists, std::size_t{0}, [](std::size_t sum, auto part_list) { return sum + part_list->size(); }); return n_part * calc_transmit_size(data_parts); @@ -263,7 +263,8 @@ static void prepare_send_buffer(CommBuf &send_buffer, /* put in data */ for (auto part_list : ghost_comm.part_lists) { if (data_parts & GHOSTTRANS_PARTNUM) { - int np = static_cast(part_list->size()); + assert(part_list->size() <= std::numeric_limits::max()); + auto np = static_cast(part_list->size()); archiver << np; } else { for (auto &p : *part_list) { @@ -279,7 +280,7 @@ static void prepare_send_buffer(CommBuf &send_buffer, assert(archiver.bytes_written() == send_buffer.size()); } -static void prepare_ghost_cell(ParticleList *cell, int size) { +static void prepare_ghost_cell(ParticleList *cell, std::size_t size) { /* Adapt size */ cell->resize(size); @@ -306,7 +307,7 @@ static void put_recv_buffer(CommBuf &recv_buffer, if (data_parts & GHOSTTRANS_PARTNUM) { for (auto part_list : ghost_comm.part_lists) { - int np; + unsigned int np; archiver >> np; prepare_ghost_cell(part_list, np); } @@ -378,7 +379,7 @@ static void cell_cell_transfer(const GhostCommunication &ghost_comm, auto *dst_list = ghost_comm.part_lists[pl + offset]; if (data_parts & GHOSTTRANS_PARTNUM) { - prepare_ghost_cell(dst_list, static_cast(src_list->size())); + prepare_ghost_cell(dst_list, src_list->size()); } else { auto &src_part = *src_list; auto &dst_part = *dst_list; diff --git a/src/core/grid.cpp b/src/core/grid.cpp index db541fb5a34..17ef5a4df28 100644 --- a/src/core/grid.cpp +++ b/src/core/grid.cpp @@ -36,7 +36,6 @@ #include #include -#include BoxGeometry box_geo; LocalBox local_geo; @@ -49,7 +48,7 @@ int map_position_node_array(const Utils::Vector3d &pos) { auto const f_pos = folded_position(pos, box_geo); Utils::Vector3i im; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { im[i] = static_cast(std::floor(f_pos[i] / local_geo.length()[i])); im[i] = std::clamp(im[i], 0, node_grid[i] - 1); } @@ -72,13 +71,13 @@ LocalBox regular_decomposition(const BoxGeometry &box, Utils::Vector3d local_length; Utils::Vector3d my_left; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { local_length[i] = box.length()[i] / node_grid_par[i]; my_left[i] = node_pos[i] * local_length[i]; } Utils::Array boundaries; - for (std::size_t dir = 0; dir < 3; dir++) { + for (unsigned int dir = 0; dir < 3; dir++) { /* left boundary ? */ boundaries[2 * dir] = (node_pos[dir] == 0); /* right boundary ? */ diff --git a/src/core/immersed_boundary/ImmersedBoundaries.cpp b/src/core/immersed_boundary/ImmersedBoundaries.cpp index 7798710cc13..c90cf431e21 100644 --- a/src/core/immersed_boundary/ImmersedBoundaries.cpp +++ b/src/core/immersed_boundary/ImmersedBoundaries.cpp @@ -71,7 +71,7 @@ void ImmersedBoundaries::init_volume_conservation(CellStructure &cs) { // reference BoundariesFound = true; if (v->volRef == 0.) { - v->volRef = VolumesCurrent[v->softID]; + v->volRef = VolumesCurrent[static_cast(v->softID)]; } } } @@ -104,7 +104,7 @@ void ImmersedBoundaries::calc_volumes(CellStructure &cs) { // Loop over all particles on local node cs.bond_loop([&tempVol](Particle &p1, int bond_id, Utils::Span partners) { - auto vol_cons_params = vol_cons_parameters(p1); + auto const vol_cons_params = vol_cons_parameters(p1); if (vol_cons_params && boost::get(bonded_ia_params.at(bond_id).get()) != nullptr) { @@ -138,7 +138,7 @@ void ImmersedBoundaries::calc_volumes(CellStructure &cs) { const double v213 = x2[0] * x1[1] * x3[2]; const double v123 = x1[0] * x2[1] * x3[2]; - tempVol[vol_cons_params->softID] += + tempVol[static_cast(vol_cons_params->softID)] += 1.0 / 6.0 * (-v321 + v231 + v312 - v132 - v213 + v123); } return false; @@ -162,11 +162,12 @@ void ImmersedBoundaries::calc_volume_force(CellStructure &cs) { // IBM VolCons bonded interaction. Basically this loops over all // triangles, not all particles. First round to check for volume // conservation. - const IBMVolCons *ibmVolConsParameters = vol_cons_parameters(p1); - if (not ibmVolConsParameters) + auto const vol_cons_params = vol_cons_parameters(p1); + if (not vol_cons_params) return false; - auto current_volume = VolumesCurrent[ibmVolConsParameters->softID]; + auto const current_volume = + VolumesCurrent[static_cast(vol_cons_params->softID)]; // Our particle is the leading particle of a triel // Get second and third particle of the triangle @@ -189,8 +190,8 @@ void ImmersedBoundaries::calc_volume_force(CellStructure &cs) { auto const n = vector_product(a12, a13); const double ln = n.norm(); const double A = 0.5 * ln; - const double fact = ibmVolConsParameters->kappaV * - (current_volume - ibmVolConsParameters->volRef) / + const double fact = vol_cons_params->kappaV * + (current_volume - vol_cons_params->volRef) / current_volume; auto const nHat = n / ln; diff --git a/src/core/immersed_boundary/ImmersedBoundaries.hpp b/src/core/immersed_boundary/ImmersedBoundaries.hpp index 93d5d5923c5..2cc7d7e8fd4 100644 --- a/src/core/immersed_boundary/ImmersedBoundaries.hpp +++ b/src/core/immersed_boundary/ImmersedBoundaries.hpp @@ -44,7 +44,7 @@ class ImmersedBoundaries { double get_current_volume(int softID) const { assert(softID >= 0); assert(softID < VolumesCurrent.size()); - return VolumesCurrent[softID]; + return VolumesCurrent[static_cast(softID)]; } private: diff --git a/src/core/integrators/steepest_descent.cpp b/src/core/integrators/steepest_descent.cpp index ed332407167..fa5e1e4e9dd 100644 --- a/src/core/integrators/steepest_descent.cpp +++ b/src/core/integrators/steepest_descent.cpp @@ -51,7 +51,7 @@ bool steepest_descent_step(const ParticleRange &particles) { auto f = 0.0; // For all Cartesian coordinates - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { // Skip, if coordinate is fixed if (!p.is_fixed_along(j)) { // Skip positional increments of virtual particles diff --git a/src/core/integrators/velocity_verlet_inline.hpp b/src/core/integrators/velocity_verlet_inline.hpp index fce60cf017e..7ae712fc53b 100644 --- a/src/core/integrators/velocity_verlet_inline.hpp +++ b/src/core/integrators/velocity_verlet_inline.hpp @@ -43,7 +43,7 @@ inline void velocity_verlet_propagate_vel_pos(const ParticleRange &particles, // Don't propagate translational degrees of freedom of vs if (p.is_virtual()) continue; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5 * dt * a(t) */ p.v()[j] += 0.5 * time_step * p.force()[j] / p.mass(); @@ -67,7 +67,7 @@ inline void velocity_verlet_propagate_vel_final(const ParticleRange &particles, if (p.is_virtual()) continue; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { /* Propagate velocity: v(t+dt) = v(t+0.5*dt) + 0.5*dt * a(t+dt) */ p.v()[j] += 0.5 * time_step * p.force()[j] / p.mass(); diff --git a/src/core/integrators/velocity_verlet_npt.cpp b/src/core/integrators/velocity_verlet_npt.cpp index 38264cafe1c..1d37b62c978 100644 --- a/src/core/integrators/velocity_verlet_npt.cpp +++ b/src/core/integrators/velocity_verlet_npt.cpp @@ -54,7 +54,7 @@ void velocity_verlet_npt_propagate_vel_final(const ParticleRange &particles, if (p.is_virtual()) continue; auto const noise = friction_therm0_nptiso<2>(npt_iso, p.v(), p.id()); - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { if (nptiso.geometry & ::nptgeom_dir[j]) { nptiso.p_vel[j] += Utils::sqr(p.v()[j] * time_step) * p.mass(); @@ -72,7 +72,7 @@ void velocity_verlet_npt_propagate_vel_final(const ParticleRange &particles, void velocity_verlet_npt_finalize_p_inst(double time_step) { /* finalize derivation of p_inst */ nptiso.p_inst = 0.0; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { if (nptiso.geometry & ::nptgeom_dir[i]) { nptiso.p_vel[i] /= Utils::sqr(time_step); nptiso.p_inst += nptiso.p_vir[i] + nptiso.p_vel[i]; @@ -124,7 +124,7 @@ void velocity_verlet_npt_propagate_pos(const ParticleRange &particles, for (auto &p : particles) { if (p.is_virtual()) continue; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { if (nptiso.geometry & ::nptgeom_dir[j]) { p.pos()[j] = scal[1] * (p.pos()[j] + scal[2] * p.v()[j] * time_step); @@ -146,7 +146,7 @@ void velocity_verlet_npt_propagate_pos(const ParticleRange &particles, if (this_node == 0) { new_box = box_geo.length(); - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { if (nptiso.cubic_box || nptiso.geometry & ::nptgeom_dir[i]) { new_box[i] = L_new; } @@ -172,7 +172,7 @@ void velocity_verlet_npt_propagate_vel(const ParticleRange &particles, // Don't propagate translational degrees of freedom of vs if (p.is_virtual()) continue; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { auto const noise = friction_therm0_nptiso<1>(npt_iso, p.v(), p.id()); if (nptiso.geometry & ::nptgeom_dir[j]) { diff --git a/src/core/lees_edwards/LeesEdwardsBC.hpp b/src/core/lees_edwards/LeesEdwardsBC.hpp index e78d2059857..2b450fd5074 100644 --- a/src/core/lees_edwards/LeesEdwardsBC.hpp +++ b/src/core/lees_edwards/LeesEdwardsBC.hpp @@ -23,6 +23,7 @@ #include #include +#include struct LeesEdwardsBC { double pos_offset = 0.; @@ -37,14 +38,16 @@ struct LeesEdwardsBC { Utils::Vector3d n_jumps{}; Utils::Vector3d res = d; - double n_le_crossings = - std::round(res[shear_plane_normal] * l_inv[shear_plane_normal]); - if (n_le_crossings >= 1) - res[shear_direction] += pos_offset; - if (n_le_crossings <= -1) - res[shear_direction] -= pos_offset; + auto const le_plane_normal = static_cast(shear_plane_normal); + auto const le_direction = static_cast(shear_direction); + auto const n_le_crossings = + std::round(res[le_plane_normal] * l_inv[le_plane_normal]); + if (n_le_crossings >= 1.) + res[le_direction] += pos_offset; + if (n_le_crossings <= -1.) + res[le_direction] -= pos_offset; - for (int i : {0, 1, 2}) { + for (auto const i : {0u, 1u, 2u}) { if (periodic[i]) { n_jumps[i] = std::round(res[i] * l_inv[i]); res[i] -= n_jumps[i] * l[i]; diff --git a/src/core/magnetostatics/dp3m.cpp b/src/core/magnetostatics/dp3m.cpp index d36460a1544..2b714c12461 100644 --- a/src/core/magnetostatics/dp3m.cpp +++ b/src/core/magnetostatics/dp3m.cpp @@ -164,7 +164,7 @@ DipolarP3M::DipolarP3M(P3MParameters &¶meters, double prefactor, } namespace { -template struct AssignDipole { +template struct AssignDipole { void operator()(dp3m_data_struct &dp3m, Utils::Vector3d const &real_pos, Utils::Vector3d const &dip) const { auto const weights = p3m_calculate_interpolation_weights( @@ -191,14 +191,14 @@ void DipolarP3M::dipole_assign(ParticleRange const &particles) { for (auto const &p : particles) { if (p.dipm() != 0.) { - Utils::integral_parameter(dp3m.params.cao, dp3m, - p.pos(), p.calc_dip()); + Utils::integral_parameter(dp3m.params.cao, dp3m, + p.pos(), p.calc_dip()); } } } namespace { -template struct AssignTorques { +template struct AssignTorques { void operator()(dp3m_data_struct const &dp3m, double prefac, int d_rs, ParticleRange const &particles) const { @@ -222,7 +222,7 @@ template struct AssignTorques { } }; -template struct AssignForces { +template struct AssignForces { void operator()(dp3m_data_struct const &dp3m, double prefac, int d_rs, ParticleRange const &particles) const { @@ -397,7 +397,7 @@ double DipolarP3M::kernel(bool force_flag, bool energy_flag, dp3m.sm.spread_grid(dp3m.rs_mesh.data(), comm_cart, dp3m.local_mesh.dim); /* Assign force component from mesh to particle */ - Utils::integral_parameter( + Utils::integral_parameter( dp3m.params.cao, dp3m, dipole_prefac * two_pi_L_i, d_rs, particles); } @@ -484,7 +484,7 @@ double DipolarP3M::kernel(bool force_flag, bool energy_flag, dp3m.sm.spread_grid(Utils::make_span(meshes), comm_cart, dp3m.local_mesh.dim); /* Assign force component from mesh to particle */ - Utils::integral_parameter( + Utils::integral_parameter( dp3m.params.cao, dp3m, dipole_prefac * Utils::sqr(two_pi_L_i), d_rs, particles); } @@ -858,7 +858,7 @@ double dp3m_rtbisection(double box_size, double r_cut_iL, int n_c_part, } void DipolarP3M::sanity_checks_boxl() const { - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { /* check k-space cutoff */ if (dp3m.params.cao_cut[i] >= box_geo.length_half()[i]) { std::stringstream msg; @@ -874,14 +874,14 @@ void DipolarP3M::sanity_checks_boxl() const { } } - if ((box_geo.length()[0] != box_geo.length()[1]) || + if ((box_geo.length()[0] != box_geo.length()[1]) or (box_geo.length()[1] != box_geo.length()[2])) { throw std::runtime_error("DipolarP3M: requires a cubic box"); } } void DipolarP3M::sanity_checks_periodicity() const { - if (!box_geo.periodic(0) || !box_geo.periodic(1) || !box_geo.periodic(2)) { + if (!box_geo.periodic(0) or !box_geo.periodic(1) or !box_geo.periodic(2)) { throw std::runtime_error( "DipolarP3M: requires periodicity (True, True, True)"); } diff --git a/src/core/nonbonded_interactions/nonbonded_interaction_data.hpp b/src/core/nonbonded_interactions/nonbonded_interaction_data.hpp index 2fd5ad27f67..280ad33481a 100644 --- a/src/core/nonbonded_interactions/nonbonded_interaction_data.hpp +++ b/src/core/nonbonded_interactions/nonbonded_interaction_data.hpp @@ -365,11 +365,11 @@ extern int max_seen_particle_type; */ double maximal_cutoff_nonbonded(); -inline int get_ia_param_key(int i, int j) { +inline auto get_ia_param_key(int i, int j) { assert(i >= 0 && i < ::max_seen_particle_type); assert(j >= 0 && j < ::max_seen_particle_type); - return Utils::upper_triangular(std::min(i, j), std::max(i, j), - ::max_seen_particle_type); + return static_cast(Utils::upper_triangular( + std::min(i, j), std::max(i, j), ::max_seen_particle_type)); } /** diff --git a/src/core/p3m/common.hpp b/src/core/p3m/common.hpp index e912f8d75b9..247a23c1bfe 100644 --- a/src/core/p3m/common.hpp +++ b/src/core/p3m/common.hpp @@ -49,8 +49,9 @@ auto constexpr P3M_EPSILON_METALLIC = 0.0; #include "LocalBox.hpp" -#include +#include #include +#include namespace detail { /** @brief Index helpers for direct and reciprocal space. @@ -135,9 +136,8 @@ struct P3MParameters { } if (not(mesh >= Utils::Vector3i::broadcast(1) or - ((mesh[0] >= 1) and - (mesh == Utils::Vector3i{{mesh[0], -1, -1}}))) and - not(tuning and mesh == Utils::Vector3i::broadcast(-1))) { + ((mesh[0] >= 1) and (mesh == Utils::Vector3i{{mesh[0], -1, -1}})) or + (tuning and mesh == Utils::Vector3i::broadcast(-1)))) { throw std::domain_error("Parameter 'mesh' must be > 0"); } @@ -150,7 +150,7 @@ struct P3MParameters { } } - if ((cao < 1 or cao > 7) and not(tuning and cao == -1)) { + if ((cao < 1 or cao > 7) and (not tuning or cao != -1)) { throw std::domain_error("Parameter 'cao' must be >= 1 and <= 7"); } @@ -205,7 +205,7 @@ struct P3MLocalMesh { */ void recalc_ld_pos(P3MParameters const ¶ms) { // spatial position of left down mesh point - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { ld_pos[i] = (ld_ind[i] + params.mesh_off[i]) * params.a[i]; } } @@ -243,7 +243,7 @@ std::array, 3> inline calc_meshift( Utils::Vector3i const &mesh_size, bool zero_out_midpoint = false) { std::array, 3> ret{}; - for (std::size_t i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { ret[i] = std::vector(mesh_size[i]); for (int j = 1; j <= mesh_size[i] / 2; j++) { diff --git a/src/core/p3m/interpolation.hpp b/src/core/p3m/interpolation.hpp index a25b0d8f66b..ebbf89d5b7c 100644 --- a/src/core/p3m/interpolation.hpp +++ b/src/core/p3m/interpolation.hpp @@ -53,7 +53,7 @@ template struct InterpolationWeights { * type InterpolationWeights. */ class p3m_interpolation_cache { - std::size_t m_cao = 0; + int m_cao = 0; /** Charge fractions for mesh assignment. */ std::vector ca_frac; /** index of first mesh point for charge assignment. */ @@ -109,10 +109,10 @@ class p3m_interpolation_cache { InterpolationWeights ret; ret.ind = ca_fmp[i]; - auto const offset = ca_frac.data() + 3 * i * m_cao; - boost::copy(make_const_span(offset + 0 * m_cao, m_cao), ret.w_x.begin()); - boost::copy(make_const_span(offset + 1 * m_cao, m_cao), ret.w_y.begin()); - boost::copy(make_const_span(offset + 2 * m_cao, m_cao), ret.w_z.begin()); + auto const offset = ca_frac.data() + 3 * i * cao; + boost::copy(make_const_span(offset + 0 * cao, cao), ret.w_x.begin()); + boost::copy(make_const_span(offset + 1 * cao, cao), ret.w_y.begin()); + boost::copy(make_const_span(offset + 2 * cao, cao), ret.w_z.begin()); return ret; } @@ -149,7 +149,7 @@ p3m_calculate_interpolation_weights(const Utils::Vector3d &position, /* nearest mesh point */ Utils::Vector3i nmp; - for (int d = 0; d < 3; d++) { + for (unsigned int d = 0; d < 3; d++) { /* particle position in mesh coordinates */ auto const pos = ((position[d] - local_mesh.ld_pos[d]) * ai[d]) - pos_shift; diff --git a/src/core/particle_node.cpp b/src/core/particle_node.cpp index 31360907adc..8c8d46d37a6 100644 --- a/src/core/particle_node.cpp +++ b/src/core/particle_node.cpp @@ -477,7 +477,7 @@ void remove_particle(int p_id) { } else if (this_node == 0) { ::comm_cart.recv(boost::mpi::any_source, 42, p_type); } - assert(not(this_node == 0 and p_type == -1)); + assert(this_node != 0 or p_type != -1); boost::mpi::broadcast(::comm_cart, p_type, 0); remove_id_from_map(p_id, p_type); } diff --git a/src/core/thermostats/brownian_inline.hpp b/src/core/thermostats/brownian_inline.hpp index 162f7c209b6..bc2ee7675f1 100644 --- a/src/core/thermostats/brownian_inline.hpp +++ b/src/core/thermostats/brownian_inline.hpp @@ -65,7 +65,7 @@ inline Utils::Vector3d bd_drag(Thermostat::GammaType const &brownian_gamma, #endif Utils::Vector3d position = {}; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { // Second (deterministic) term of the Eq. (14.39) of schlick10a. // Only a conservative part of the force is used here #ifdef PARTICLE_ANISOTROPY @@ -118,7 +118,7 @@ inline Utils::Vector3d bd_drag_vel(Thermostat::GammaType const &brownian_gamma, #endif Utils::Vector3d velocity = {}; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { // First (deterministic) term of the eq. (14.34) of schlick10a taking // into account eq. (14.35). Only conservative part of the force is used // here. @@ -171,7 +171,7 @@ inline Utils::Vector3d bd_random_walk(BrownianThermostat const &brownian, Utils::Vector3d delta_pos_body{}; auto const noise = Random::noise_gaussian( brownian.rng_counter(), brownian.rng_seed(), p.id()); - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { #ifndef PARTICLE_ANISOTROPY if (sigma_pos > 0.0) { @@ -200,7 +200,7 @@ inline Utils::Vector3d bd_random_walk(BrownianThermostat const &brownian, #endif Utils::Vector3d position = {}; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { #ifdef PARTICLE_ANISOTROPY position[j] += aniso_flag ? delta_pos_lab[j] : delta_pos_body[j]; @@ -226,7 +226,7 @@ inline Utils::Vector3d bd_random_walk_vel(BrownianThermostat const &brownian, auto const noise = Random::noise_gaussian( brownian.rng_counter(), brownian.rng_seed(), p.id()); Utils::Vector3d velocity = {}; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (!p.is_fixed_along(j)) { // Random (heat) velocity. See eq. (10.2.16) taking into account eq. // (10.2.18) and (10.2.29), pottier10a. Note, that the pottier10a units @@ -264,7 +264,7 @@ bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, Particle &p, } Utils::Vector3d dphi = {}; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (p.can_rotate_around(j)) { // only a conservative part of the torque is used here #ifndef PARTICLE_ANISOTROPY @@ -303,7 +303,7 @@ bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation, } Utils::Vector3d omega = {}; - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (p.can_rotate_around(j)) { #ifdef PARTICLE_ANISOTROPY omega[j] = p.torque()[j] / gamma[j]; @@ -341,7 +341,7 @@ bd_random_walk_rot(BrownianThermostat const &brownian, Particle const &p, Utils::Vector3d dphi = {}; auto const noise = Random::noise_gaussian( brownian.rng_counter(), brownian.rng_seed(), p.id()); - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (p.can_rotate_around(j)) { #ifndef PARTICLE_ANISOTROPY if (sigma_pos > 0.0) { @@ -376,7 +376,7 @@ bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle const &p) { Utils::Vector3d domega{}; auto const noise = Random::noise_gaussian( brownian.rng_counter(), brownian.rng_seed(), p.id()); - for (int j = 0; j < 3; j++) { + for (unsigned int j = 0; j < 3; j++) { if (p.can_rotate_around(j)) { domega[j] = sigma_vel * noise[j] / sqrt(p.rinertia()[j]); } diff --git a/src/core/unit_tests/rotation_test.cpp b/src/core/unit_tests/rotation_test.cpp index 4fd298f9be3..278a5232118 100644 --- a/src/core/unit_tests/rotation_test.cpp +++ b/src/core/unit_tests/rotation_test.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -41,13 +42,13 @@ auto constexpr tol = 5. * 100. * std::numeric_limits::epsilon(); namespace Testing { std::tuple, Utils::Vector3d> -setup_trivial_quat(int i, Utils::Vector3d const &v_in) { +setup_trivial_quat(unsigned int i, Utils::Vector3d const &v_in) { auto quat = Utils::Quaternion{{0., 0., 0., 0.}}; quat[i] = 1.; auto v_ref = v_in; - if (i) { + if (i >= 1) { v_ref *= -1.; - v_ref[i - 1] *= -1.; + v_ref[static_cast(i - 1)] *= -1.; } return std::make_tuple(quat, v_ref); } @@ -55,12 +56,12 @@ setup_trivial_quat(int i, Utils::Vector3d const &v_in) { BOOST_AUTO_TEST_CASE(convert_vector_space_to_body_test) { auto const t_in = Utils::Vector3d{{1., 2., 3.}}; - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { auto p = Particle(); Utils::Vector3d t_ref; std::tie(p.quat(), t_ref) = Testing::setup_trivial_quat(i, t_in); auto const t_out = convert_vector_space_to_body(p, t_in); - for (int j : {0, 1, 2}) { + for (unsigned int j : {0u, 1u, 2u}) { BOOST_CHECK_CLOSE(t_out[j], t_ref[j], tol); } } @@ -70,7 +71,7 @@ BOOST_AUTO_TEST_CASE(convert_torque_to_body_frame_apply_fix_test) { auto const t_in = Utils::Vector3d{{1., 2., 3.}}; { // test particle torque conversion - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { auto p = Particle(); p.set_can_rotate_all_axes(); Utils::Vector3d t_ref; @@ -78,14 +79,14 @@ BOOST_AUTO_TEST_CASE(convert_torque_to_body_frame_apply_fix_test) { p.torque() = t_in; convert_torque_to_body_frame_apply_fix(p); auto const t_out = p.torque(); - for (int j : {0, 1, 2}) { + for (unsigned int j : {0u, 1u, 2u}) { BOOST_CHECK_CLOSE(t_out[j], t_ref[j], tol); } } } { // torque is set to zero for axes without rotation - for (int j : {0, 1, 2}) { + for (unsigned int j : {0u, 1u, 2u}) { auto p = Particle(); p.set_can_rotate_all_axes(); p.set_can_rotate_around(j, false); @@ -139,7 +140,7 @@ BOOST_AUTO_TEST_CASE(rotate_particle_body_test) { auto const phi = Utils::pi(); auto const quat = local_rotate_particle_body(p, {0., 0., 1.}, phi); auto const quat_ref = Utils::Vector4d{{-4., 3., -2., 1.}}; - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { BOOST_CHECK_CLOSE(quat[i], quat_ref[i], tol); } } @@ -149,7 +150,7 @@ BOOST_AUTO_TEST_CASE(rotate_particle_body_test) { auto const phi = 2. * Utils::pi(); auto const quat = local_rotate_particle_body(p, {0., 0., 1.}, phi); auto const quat_ref = Utils::Vector4d{{-1., -2., -3., -4.}}; - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { BOOST_CHECK_CLOSE(quat[i], quat_ref[i], tol); } } @@ -165,7 +166,7 @@ BOOST_AUTO_TEST_CASE(propagate_omega_quat_particle_test) { propagate_omega_quat_particle(p, 0.01); auto const quat = p.quat(); auto const quat_ref = Utils::Quaternion::identity(); - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { BOOST_CHECK_CLOSE(quat[i], quat_ref[i], tol); } } @@ -173,7 +174,7 @@ BOOST_AUTO_TEST_CASE(propagate_omega_quat_particle_test) { // test trivial cases with parameters extremely close to the limit: // time step almost 1.0 and product of time step with omega almost 2.0 auto const time_step = 0.99; - for (int j : {0, 1, 2}) { + for (unsigned int j : {0u, 1u, 2u}) { p.quat() = Utils::Quaternion::identity(); p.omega() = {0., 0., 0.}; p.omega()[j] = 2.; @@ -182,7 +183,7 @@ BOOST_AUTO_TEST_CASE(propagate_omega_quat_particle_test) { auto quat_ref = Utils::Quaternion::identity(); quat_ref[1 + j] = time_step; quat_ref[0] = std::sqrt(1. - time_step * time_step); - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { BOOST_CHECK_CLOSE(quat[i], quat_ref[i], tol); } } @@ -207,8 +208,8 @@ BOOST_AUTO_TEST_CASE(convert_operator_body_to_space_test) { auto const linear_transf_space = convert_body_to_space(quat, linear_transf_body); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { + for (unsigned int i = 0; i < 3; i++) { + for (unsigned int j = 0; j < 3; j++) { if (linear_transf_space_ref(i, j) == 0.0) { BOOST_CHECK_SMALL( std::abs(linear_transf_space(i, j) - linear_transf_space_ref(i, j)), @@ -233,7 +234,7 @@ BOOST_AUTO_TEST_CASE(convert_dip_to_quat_test) { auto const pair = convert_dip_to_quat({0., 0., dipm}); auto const quat = quat_to_vector4d(pair.first); auto const quat_ref = Utils::Vector4d{{1., 0., 0., 0.}}; - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { BOOST_CHECK_CLOSE(quat[i], quat_ref[i], tol); } BOOST_CHECK_CLOSE(pair.second, dipm, tol); @@ -243,7 +244,7 @@ BOOST_AUTO_TEST_CASE(convert_dip_to_quat_test) { auto const pair = convert_dip_to_quat({dipm, 0., 0.}); auto const quat = quat_to_vector4d(pair.first); auto const quat_ref = Utils::Vector4d{{0.5, -0.5, 0.5, -0.5}}; - for (int i : {0, 1, 2, 3}) { + for (unsigned int i : {0u, 1u, 2u, 3u}) { BOOST_CHECK_CLOSE(quat[i], quat_ref[i], tol); } BOOST_CHECK_CLOSE(pair.second, dipm, tol); diff --git a/src/core/virtual_sites.cpp b/src/core/virtual_sites.cpp index 2c66a768e6f..cb973e5a7fb 100644 --- a/src/core/virtual_sites.cpp +++ b/src/core/virtual_sites.cpp @@ -118,9 +118,9 @@ calculate_vs_relate_to_params(Particle const &p_vs, // Verify result Utils::Quaternion qtemp = relate_to_quat * quat; - for (int i = 0; i < 4; i++) { + for (unsigned int i = 0; i < 4; i++) { if (fabs(qtemp[i] - quat_director[i]) > 1E-9) { - fprintf(stderr, "vs_relate_to: component %d: %f instead of %f\n", i, + fprintf(stderr, "vs_relate_to: component %u: %f instead of %f\n", i, qtemp[i], quat_director[i]); } } diff --git a/src/core/virtual_sites/lb_inertialess_tracers.cpp b/src/core/virtual_sites/lb_inertialess_tracers.cpp index b87b2d42327..2fd0015a73c 100644 --- a/src/core/virtual_sites/lb_inertialess_tracers.cpp +++ b/src/core/virtual_sites/lb_inertialess_tracers.cpp @@ -92,7 +92,7 @@ void IBM_UpdateParticlePositions(ParticleRange const &particles, // Euler integrator for (auto &p : particles) { if (p.is_virtual()) { - for (int axis = 0; axis < 3; axis++) { + for (unsigned int axis = 0; axis < 3; axis++) { #ifdef EXTERNAL_FORCES if (not p.is_fixed_along(axis)) #endif diff --git a/src/script_interface/auto_parameters/AutoParameters.hpp b/src/script_interface/auto_parameters/AutoParameters.hpp index 4fec3064859..f770398c05d 100644 --- a/src/script_interface/auto_parameters/AutoParameters.hpp +++ b/src/script_interface/auto_parameters/AutoParameters.hpp @@ -115,7 +115,7 @@ class AutoParameters : public Base { if (m_parameters.count(p.name)) { m_parameters.erase(p.name); } - m_parameters.emplace(std::make_pair(p.name, std::move(p))); + m_parameters.emplace(p.name, std::move(p)); } } diff --git a/src/script_interface/integrators/IntegratorHandle.cpp b/src/script_interface/integrators/IntegratorHandle.cpp index 2a485360572..9668a3b0c5b 100644 --- a/src/script_interface/integrators/IntegratorHandle.cpp +++ b/src/script_interface/integrators/IntegratorHandle.cpp @@ -86,15 +86,15 @@ static bool checkpoint_filter(typename VariantMap::value_type const &kv) { /* When loading from a checkpoint file, defer the integrator object to last, * and skip the time_step if it is -1 to avoid triggering sanity checks. */ - return kv.first != "integrator" and - not(kv.first == "time_step" and ::integ_switch == INTEG_METHOD_NVT and - get_time_step() == -1. and is_type(kv.second) and - get_value(kv.second) == -1.); + return kv.first == "integrator" or + (kv.first == "time_step" and ::integ_switch == INTEG_METHOD_NVT and + get_time_step() == -1. and is_type(kv.second) and + get_value(kv.second) == -1.); } void IntegratorHandle::do_construct(VariantMap const ¶ms) { for (auto const &kv : params) { - if (checkpoint_filter(kv)) { + if (not checkpoint_filter(kv)) { do_set_parameter(kv.first, kv.second); } } diff --git a/src/script_interface/interactions/NonBondedInteractions.hpp b/src/script_interface/interactions/NonBondedInteractions.hpp index 99182b573e2..30a0e224c5f 100644 --- a/src/script_interface/interactions/NonBondedInteractions.hpp +++ b/src/script_interface/interactions/NonBondedInteractions.hpp @@ -41,7 +41,8 @@ namespace Interactions { class NonBondedInteractions : public ObjectHandle { using container_type = - std::unordered_map>; + std::unordered_map>; auto make_interaction(int i, int j) { assert(i <= j); @@ -59,7 +60,7 @@ class NonBondedInteractions : public ObjectHandle { auto const size = ::max_seen_particle_type; for (int i = 0; i < size; i++) { for (int j = i; j < size; j++) { - auto const key = Utils::upper_triangular(i, j, size); + auto const key = get_ia_param_key(i, j); ::nonbonded_ia_params[i] = std::make_shared<::IA_parameters>(); m_nonbonded_ia_params[key] = make_interaction(i, j); } @@ -72,7 +73,7 @@ class NonBondedInteractions : public ObjectHandle { make_particle_type_exist(size); for (int i = 0; i < size; i++) { for (int j = i; j < size; j++) { - auto const key = Utils::upper_triangular(i, j, size); + auto const key = get_ia_param_key(i, j); m_nonbonded_ia_params[key] = make_interaction(i, j); } } diff --git a/src/script_interface/particle_data/ParticleList.cpp b/src/script_interface/particle_data/ParticleList.cpp index 900c3bbd8c6..e2f2c7ab961 100644 --- a/src/script_interface/particle_data/ParticleList.cpp +++ b/src/script_interface/particle_data/ParticleList.cpp @@ -76,15 +76,12 @@ std::string ParticleList::get_internal_state() const { auto state = Utils::unpack(packed_state); state.name = "Particles::ParticleHandle"; auto const bonds_view = p_handle.call_method("get_bonds_view", {}); - state.params.emplace_back( - std::pair{"bonds", pack(bonds_view)}); + state.params.emplace_back(std::string{"bonds"}, pack(bonds_view)); #ifdef EXCLUSIONS auto const exclusions = p_handle.call_method("get_exclusions", {}); - state.params.emplace_back( - std::pair{"exclusions", pack(exclusions)}); + state.params.emplace_back(std::string{"exclusions"}, pack(exclusions)); #endif // EXCLUSIONS - state.params.emplace_back( - std::pair{"__cpt_sentinel", pack(None{})}); + state.params.emplace_back(std::string{"__cpt_sentinel"}, pack(None{})); return Utils::pack(state); }); @@ -157,7 +154,7 @@ static void auto_exclusions(boost::mpi::communicator const &comm, for (auto const &partner : partners[pid1]) if (partner.first == pid2) return; - partners[pid1].emplace_back(std::pair{pid2, n_bonds}); + partners[pid1].emplace_back(pid2, n_bonds); }; for (auto it = bonded_pairs.begin(); it != bonded_pairs.end(); it += 2) { diff --git a/src/shapes/src/Ellipsoid.cpp b/src/shapes/src/Ellipsoid.cpp index dbad6617f1b..128f0fd85f2 100644 --- a/src/shapes/src/Ellipsoid.cpp +++ b/src/shapes/src/Ellipsoid.cpp @@ -52,9 +52,9 @@ void Ellipsoid::calculate_dist(const Utils::Vector3d &pos, double &dist, } /* calculate dist and vec */ - for (int i = 0; i < 3; i++) { - vec[i] = (ppos_e[i] - Utils::sqr(m_semiaxes[i]) * ppos_e[i] / - (l + Utils::sqr(m_semiaxes[i]))); + for (unsigned int i = 0; i < 3; i++) { + auto const semi_sq = Utils::sqr(m_semiaxes[i]); + vec[i] = (ppos_e[i] - semi_sq * ppos_e[i] / (l + semi_sq)); } dist = distance_prefactor * m_direction * vec.norm(); @@ -67,7 +67,7 @@ bool Ellipsoid::inside_ellipsoid(const Utils::Vector3d &ppos) const { double Ellipsoid::newton_term(const Utils::Vector3d &ppos, const double &l) const { Utils::Vector3d axpos, lax, lax2; - for (int i = 0; i < 3; i++) { + for (unsigned int i = 0; i < 3; i++) { axpos[i] = Utils::sqr(m_semiaxes[i]) * Utils::sqr(ppos[i]); lax[i] = l + Utils::sqr(m_semiaxes[i]); lax2[i] = Utils::sqr(lax[i]); diff --git a/src/utils/include/utils/Vector.hpp b/src/utils/include/utils/Vector.hpp index 41c51d07226..5ddd0f1cc43 100644 --- a/src/utils/include/utils/Vector.hpp +++ b/src/utils/include/utils/Vector.hpp @@ -140,7 +140,7 @@ template class Vector : public Array { Vector &normalize() { auto const l = norm(); if (l > T(0)) { - for (int i = 0; i < N; i++) + for (std::size_t i = 0; i < N; i++) this->operator[](i) /= l; } @@ -188,7 +188,7 @@ Vector &binary_op_assign(Vector &a, Vector const &b, Op op) { template constexpr bool all_of(Vector const &a, Vector const &b, Op op) { - for (int i = 0; i < a.size(); i++) { + for (unsigned int i = 0; i < N; i++) { /* Short circuit */ if (!static_cast(op(a[i], b[i]))) { return false; diff --git a/src/utils/include/utils/integral_parameter.hpp b/src/utils/include/utils/integral_parameter.hpp index 3467526f7b2..9bb5b405bb6 100644 --- a/src/utils/include/utils/integral_parameter.hpp +++ b/src/utils/include/utils/integral_parameter.hpp @@ -27,22 +27,20 @@ namespace Utils { namespace detail { -template