From fee96bc77714a57dabde74cbe590b3ced7fa144d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 29 Jun 2025 19:10:29 -0400 Subject: [PATCH] make double to bool/int/tagint conversions explicit --- src/EXTRA-COMMAND/group2ndx.cpp | 2 +- src/KSPACE/ewald_dipole.cpp | 2 +- src/KSPACE/pppm_dipole.cpp | 2 +- src/ML-SNAP/pair_snap.cpp | 2 +- src/REAXFF/fix_reaxff_species.cpp | 10 +++++----- src/REPLICA/hyper.cpp | 4 ++-- src/RIGID/fix_shake.cpp | 2 +- src/UEF/uef_utils.cpp | 16 ++++++++-------- src/fix_box_relax.cpp | 4 ++-- src/fix_spring_chunk.cpp | 2 +- src/set.cpp | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/EXTRA-COMMAND/group2ndx.cpp b/src/EXTRA-COMMAND/group2ndx.cpp index e19d16f0f5..e48b128824 100644 --- a/src/EXTRA-COMMAND/group2ndx.cpp +++ b/src/EXTRA-COMMAND/group2ndx.cpp @@ -95,7 +95,7 @@ void Group2Ndx::write_group(FILE *fp, int gid) } else { utils::print(fp, "[ {} ]\n", group->names[gid]); } - width = log10((double) atom->natoms) + 2; + width = (int) log10((double) atom->natoms) + 2; cols = 80 / width; } diff --git a/src/KSPACE/ewald_dipole.cpp b/src/KSPACE/ewald_dipole.cpp index e4982b1d56..c9f3ca59f6 100644 --- a/src/KSPACE/ewald_dipole.cpp +++ b/src/KSPACE/ewald_dipole.cpp @@ -72,7 +72,7 @@ void EwaldDipole::init() dipoleflag = atom->mu?1:0; qsum_qsq(0); // q[i] might not be declared ? - if (dipoleflag && q2) + if (dipoleflag && (q2 != 0.0)) error->all(FLERR,"Cannot (yet) use charges with Kspace style EwaldDipole"); // no triclinic ewald dipole (yet) diff --git a/src/KSPACE/pppm_dipole.cpp b/src/KSPACE/pppm_dipole.cpp index ecf49b465f..687d495252 100644 --- a/src/KSPACE/pppm_dipole.cpp +++ b/src/KSPACE/pppm_dipole.cpp @@ -95,7 +95,7 @@ void PPPMDipole::init() dipoleflag = atom->mu?1:0; qsum_qsq(0); // q[i] might not be declared ? - if (dipoleflag && q2) + if (dipoleflag && (q2 != 0.0)) error->all(FLERR,"Cannot (yet) use charges with Kspace style PPPMDipole"); triclinic_check(); diff --git a/src/ML-SNAP/pair_snap.cpp b/src/ML-SNAP/pair_snap.cpp index 3e7d1aaa42..53734fa35c 100644 --- a/src/ML-SNAP/pair_snap.cpp +++ b/src/ML-SNAP/pair_snap.cpp @@ -399,7 +399,7 @@ void PairSNAP::coeff(int narg, char **arg) // ncoeffall should be (ncoeff+2)*(ncoeff+1)/2 // so, ncoeff = floor(sqrt(2*ncoeffall))-1 - ncoeff = sqrt(2.0*ncoeffall)-1; + ncoeff = (int) sqrt(2.0*ncoeffall) - 1; ncoeffq = (ncoeff*(ncoeff+1))/2; int ntmp = 1+ncoeff+ncoeffq; if (ntmp != ncoeffall) { diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 97c9f0a4d3..b2657ba677 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -248,8 +248,8 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR, iarg + 1, "Fix reaxff/species: Variable {} is not equal-style", delete_Nlimit_varname); } else - delete_Nlimit = utils::numeric(FLERR, arg[iarg + 1], false, lmp); - delete_Nsteps = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + delete_Nlimit = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + delete_Nsteps = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; // position of molecules } else if (strcmp(arg[iarg], "position") == 0) { @@ -956,7 +956,7 @@ void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) } ndeletions = delete_Tcount[0] - delete_Tcount[delete_Nsteps - 1]; if (delete_Nlimit_varid > -1) - delete_Nlimit = input->variable->compute_equal(delete_Nlimit_varid); + delete_Nlimit = (int) input->variable->compute_equal(delete_Nlimit_varid); headroom = MAX(0, delete_Nlimit - ndeletions); if (headroom == 0) { for (i = delete_Nsteps - 1; i > 0; i--) delete_Tcount[i] = delete_Tcount[i - 1]; @@ -1117,11 +1117,11 @@ void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) } else { int writeflag = 0; for (i = 0; i < ndelspec; i++) - if (deletecount[i]) writeflag = 1; + if (deletecount[i] != 0.0) writeflag = 1; if (writeflag) { utils::print(fdel, "{}", update->ntimestep); - for (i = 0; i < ndelspec; i++) { fprintf(fdel, "\t%g", deletecount[i]); } + for (i = 0; i < ndelspec; i++) fprintf(fdel, "\t%g", deletecount[i]); fprintf(fdel, "\n"); fflush(fdel); } diff --git a/src/REPLICA/hyper.cpp b/src/REPLICA/hyper.cpp index df853642b4..228be9fc7d 100644 --- a/src/REPLICA/hyper.cpp +++ b/src/REPLICA/hyper.cpp @@ -254,8 +254,8 @@ void Hyper::command(int narg, char **arg) if (hyperenable) { t_hyper = fix_hyper->query(1); - nevent_running = fix_hyper->query(2); - nevent_atoms_running = fix_hyper->query(3); + nevent_running = (int) fix_hyper->query(2); + nevent_atoms_running = (int) fix_hyper->query(3); avebonds = fix_hyper->query(4); maxdrift = fix_hyper->query(5); maxbondlen = fix_hyper->query(6); diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 89b8ffd942..e64ff94eb0 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -2729,7 +2729,7 @@ void FixShake::stats() // print stats only for non-zero counts if (comm->me == 0) { - const int width = log10((double)(MAX(MAX(1,nb),na)))+2; + const int width = (int) log10((double)(MAX(MAX(1,nb),na))) + 2; auto mesg = fmt::format("{} stats (type/ave/delta/count) on step {}\n", utils::uppercase(style), update->ntimestep); for (int i = 1; i < nb; i++) { diff --git a/src/UEF/uef_utils.cpp b/src/UEF/uef_utils.cpp index d33029084c..f710496f3c 100644 --- a/src/UEF/uef_utils.cpp +++ b/src/UEF/uef_utils.cpp @@ -91,10 +91,10 @@ UEFBox::UEFBox() mul_m2(l0t,t2i); for (int k=0; k<3; ++k) for (int j=0; j<3; ++j) { - a1[k][j] = round(t1[k][j]); - a1i[k][j] = round(t1i[k][j]); - a2[k][j] = round(t2[k][j]); - a2i[k][j] = round(t2i[k][j]); + a1[k][j] = (int)round(t1[k][j]); + a1i[k][j] = (int)round(t1i[k][j]); + a2[k][j] = (int)round(t2[k][j]); + a2i[k][j] = (int)round(t2i[k][j]); } // winv used to transform between @@ -173,8 +173,8 @@ bool UEFBox::reduce() // determine how many times to apply the automorphisms and find new theta // values - int f1 = round(theta[0]); - int f2 = round(theta[1]); + int f1 = (int)round(theta[0]); + int f2 = (int)round(theta[1]); theta[0] -= f1; theta[1] -= f2; @@ -351,8 +351,8 @@ void red3(double b[3][3], int r[3][3], int ri[3][3]) double min = col_prod(b,2,2); int x1v[2]; int x2v[2]; - x1v[0] = floor(y1); x1v[1] = x1v[0]+1; - x2v[0] = floor(y2); x2v[1] = x2v[0]+1; + x1v[0] = (int) floor(y1); x1v[1] = x1v[0]+1; + x2v[0] = (int) floor(y2); x2v[1] = x2v[0]+1; for (int k=0;k<2;k++) for (int j=0;j<2;j++) { double a[3]; diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index 3778847ef5..32701ead54 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -371,7 +371,7 @@ void FixBoxRelax::init() // detect if any rigid fixes exist so rigid bodies move when box is remapped rfix.clear(); - for (auto &ifix : modify->get_fix_list()) + for (const auto &ifix : modify->get_fix_list()) if (ifix->rigid_flag) rfix.push_back(ifix); // initial box dimensions @@ -911,7 +911,7 @@ void FixBoxRelax::compute_press_target() p_hydro = 0.0; for (int i = 0; i < 3; i++) if (p_flag[i]) p_hydro += p_target[i]; - if (pflagsum) p_hydro /= pflagsum; + if (pflagsum != 0.0) p_hydro /= pflagsum; for (int i = 0; i < 3; i++) { if (p_flag[i] && fabs(p_hydro - p_target[i]) > 1.0e-6) deviatoric_flag = 1; diff --git a/src/fix_spring_chunk.cpp b/src/fix_spring_chunk.cpp index f42572b190..32dbe20965 100644 --- a/src/fix_spring_chunk.cpp +++ b/src/fix_spring_chunk.cpp @@ -181,7 +181,7 @@ void FixSpringChunk::post_force(int /*vflag*/) r = sqrt(dx*dx + dy*dy + dz*dz); r = MAX(r,SMALL); - if (masstotal[m]) { + if (masstotal[m] != 0.0) { fcom[m][0] = k_spring*dx/r / masstotal[m]; fcom[m][1] = k_spring*dy/r / masstotal[m]; fcom[m][2] = k_spring*dz/r / masstotal[m]; diff --git a/src/set.cpp b/src/set.cpp index 73bc7ccbfe..e6e9c6fd81 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -1837,7 +1837,7 @@ void Set::invoke_mol(Action *action) if (!select[i]) continue; if (varflag) { - molID = vec1[i]; + molID = (tagint)vec1[i]; if (molID < 0) error->one(FLERR,"Invalid molecule ID in set command"); }