diff --git a/doc/src/compute_pressure.rst b/doc/src/compute_pressure.rst index f69f70daba..3c98208261 100644 --- a/doc/src/compute_pressure.rst +++ b/doc/src/compute_pressure.rst @@ -46,13 +46,14 @@ system volume (or area in 2d). The second term is the virial, equal to -dU/dV, computed for all pairwise as well as 2-body, 3-body, 4-body, many-body, and long-range interactions, where :math:`r_i` and :math:`f_i` are the position and force vector of atom *i*, and the black -dot indicates a dot product. When periodic boundary conditions are -used, N' necessarily includes periodic image (ghost) atoms outside the -central box, and the position and force vectors of ghost atoms are thus -included in the summation. When periodic boundary conditions are not -used, N' = N = the number of atoms in the system. :doc:`Fixes ` -that impose constraints (e.g. the :doc:`fix shake ` command) -also contribute to the virial term. +dot indicates a dot product. This is computed in parallel for each +sub-domain and then summed over all parallel processes. Thus N' +necessarily includes atoms from neighboring sub-domains (so-called ghost +atoms) and the position and force vectors of ghost atoms are thus +included in the summation. Only when running in serial and without +periodic boundary conditions is N' = N = the number of atoms in the +system. :doc:`Fixes ` that impose constraints (e.g. the :doc:`fix +shake ` command) may also contribute to the virial term. A symmetric pressure tensor, stored as a 6-element vector, is also calculated by this compute. The 6 components of the vector are diff --git a/examples/melt/in.melt b/examples/melt/in.melt index 8431a4344e..f169dc2ffc 100644 --- a/examples/melt/in.melt +++ b/examples/melt/in.melt @@ -9,7 +9,7 @@ create_box 1 box create_atoms 1 box mass 1 1.0 -velocity all create 3.0 87287 +velocity all create 3.0 87287 loop geom pair_style lj/cut 2.5 pair_coeff 1 1 1.0 1.0 2.5 diff --git a/examples/melt/log.27Nov18.melt.g++.4 b/examples/melt/log.27Nov18.melt.g++.4 deleted file mode 100644 index 927895b1cd..0000000000 --- a/examples/melt/log.27Nov18.melt.g++.4 +++ /dev/null @@ -1,85 +0,0 @@ -LAMMPS (27 Nov 2018) - using 1 OpenMP thread(s) per MPI task -# 3d Lennard-Jones melt - -units lj -atom_style atomic - -lattice fcc 0.8442 -Lattice spacing in x,y,z = 1.6796 1.6796 1.6796 -region box block 0 10 0 10 0 10 -create_box 1 box -Created orthogonal box = (0 0 0) to (16.796 16.796 16.796) - 1 by 2 by 2 MPI processor grid -create_atoms 1 box -Created 4000 atoms - Time spent = 0.00041604 secs -mass 1 1.0 - -velocity all create 3.0 87287 - -pair_style lj/cut 2.5 -pair_coeff 1 1 1.0 1.0 2.5 - -neighbor 0.3 bin -neigh_modify every 20 delay 0 check no - -fix 1 all nve - -#dump id all atom 50 dump.melt - -#dump 2 all image 25 image.*.jpg type type # axes yes 0.8 0.02 view 60 -30 -#dump_modify 2 pad 3 - -#dump 3 all movie 25 movie.mpg type type # axes yes 0.8 0.02 view 60 -30 -#dump_modify 3 pad 3 - -thermo 50 -run 250 -Neighbor list info ... - update every 20 steps, delay 0 steps, check no - max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 2.8 - ghost atom cutoff = 2.8 - binsize = 1.4, bins = 12 12 12 - 1 neighbor lists, perpetual/occasional/extra = 1 0 0 - (1) pair lj/cut, perpetual - attributes: half, newton on - pair build: half/bin/atomonly/newton - stencil: half/bin/3d/newton - bin: standard -Per MPI rank memory allocation (min/avg/max) = 2.705 | 2.705 | 2.705 Mbytes -Step Temp E_pair E_mol TotEng Press - 0 3 -6.7733681 0 -2.2744931 -3.7033504 - 50 1.6754119 -4.7947589 0 -2.2822693 5.6615925 - 100 1.6503357 -4.756014 0 -2.2811293 5.8050524 - 150 1.6596605 -4.7699432 0 -2.2810749 5.7830138 - 200 1.6371874 -4.7365462 0 -2.2813789 5.9246674 - 250 1.6323462 -4.7292021 0 -2.2812949 5.9762238 -Loop time of 0.223329 on 4 procs for 250 steps with 4000 atoms - -Performance: 483592.231 tau/day, 1119.426 timesteps/s -97.3% CPU use with 4 MPI tasks x 1 OpenMP threads - -MPI task timing breakdown: -Section | min time | avg time | max time |%varavg| %total ---------------------------------------------------------------- -Pair | 0.15881 | 0.16314 | 0.16859 | 0.9 | 73.05 -Neigh | 0.02472 | 0.025218 | 0.025828 | 0.3 | 11.29 -Comm | 0.025185 | 0.030091 | 0.034351 | 1.9 | 13.47 -Output | 0.00015163 | 0.00019169 | 0.00030899 | 0.0 | 0.09 -Modify | 0.0037532 | 0.0038366 | 0.0040054 | 0.2 | 1.72 -Other | | 0.00085 | | | 0.38 - -Nlocal: 1000 ave 1010 max 982 min -Histogram: 1 0 0 0 0 0 1 0 0 2 -Nghost: 2703.75 ave 2713 max 2689 min -Histogram: 1 0 0 0 0 0 0 2 0 1 -Neighs: 37915.5 ave 39239 max 36193 min -Histogram: 1 0 0 0 0 1 1 0 0 1 - -Total # of neighbors = 151662 -Ave neighs/atom = 37.9155 -Neighbor list builds = 12 -Dangerous builds not checked -Total wall time: 0:00:00 diff --git a/examples/melt/log.27Nov18.melt.g++.1 b/examples/melt/log.8Apr21.melt.g++.1 similarity index 51% rename from examples/melt/log.27Nov18.melt.g++.1 rename to examples/melt/log.8Apr21.melt.g++.1 index 69b39e6011..a3b6d003db 100644 --- a/examples/melt/log.27Nov18.melt.g++.1 +++ b/examples/melt/log.8Apr21.melt.g++.1 @@ -1,4 +1,4 @@ -LAMMPS (27 Nov 2018) +LAMMPS (8 Apr 2021) using 1 OpenMP thread(s) per MPI task # 3d Lennard-Jones melt @@ -6,17 +6,17 @@ units lj atom_style atomic lattice fcc 0.8442 -Lattice spacing in x,y,z = 1.6796 1.6796 1.6796 +Lattice spacing in x,y,z = 1.6795962 1.6795962 1.6795962 region box block 0 10 0 10 0 10 create_box 1 box -Created orthogonal box = (0 0 0) to (16.796 16.796 16.796) +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (16.795962 16.795962 16.795962) 1 by 1 by 1 MPI processor grid create_atoms 1 box Created 4000 atoms - Time spent = 0.000645638 secs + create_atoms CPU = 0.002 seconds mass 1 1.0 -velocity all create 3.0 87287 +velocity all create 3.0 87287 loop geom pair_style lj/cut 2.5 pair_coeff 1 1 1.0 1.0 2.5 @@ -48,38 +48,38 @@ Neighbor list info ... pair build: half/bin/atomonly/newton stencil: half/bin/3d/newton bin: standard -Per MPI rank memory allocation (min/avg/max) = 3.221 | 3.221 | 3.221 Mbytes +Per MPI rank memory allocation (min/avg/max) = 3.222 | 3.222 | 3.222 Mbytes Step Temp E_pair E_mol TotEng Press 0 3 -6.7733681 0 -2.2744931 -3.7033504 - 50 1.6758903 -4.7955425 0 -2.2823355 5.670064 - 100 1.6458363 -4.7492704 0 -2.2811332 5.8691042 - 150 1.6324555 -4.7286791 0 -2.280608 5.9589514 - 200 1.6630725 -4.7750988 0 -2.2811136 5.7364886 - 250 1.6275257 -4.7224992 0 -2.281821 5.9567365 -Loop time of 0.729809 on 1 procs for 250 steps with 4000 atoms + 50 1.6842865 -4.8082494 0 -2.2824513 5.5666131 + 100 1.6712577 -4.7875609 0 -2.281301 5.6613913 + 150 1.6444751 -4.7471034 0 -2.2810074 5.8614211 + 200 1.6471542 -4.7509053 0 -2.2807916 5.8805431 + 250 1.6645597 -4.7774327 0 -2.2812174 5.7526089 +Loop time of 1.61045 on 1 procs for 250 steps with 4000 atoms -Performance: 147983.915 tau/day, 342.555 timesteps/s +Performance: 67062.020 tau/day, 155.236 timesteps/s 99.9% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 0.60661 | 0.60661 | 0.60661 | 0.0 | 83.12 -Neigh | 0.092198 | 0.092198 | 0.092198 | 0.0 | 12.63 -Comm | 0.013581 | 0.013581 | 0.013581 | 0.0 | 1.86 -Output | 0.0001452 | 0.0001452 | 0.0001452 | 0.0 | 0.02 -Modify | 0.014395 | 0.014395 | 0.014395 | 0.0 | 1.97 -Other | | 0.002878 | | | 0.39 +Pair | 1.3961 | 1.3961 | 1.3961 | 0.0 | 86.69 +Neigh | 0.13555 | 0.13555 | 0.13555 | 0.0 | 8.42 +Comm | 0.037732 | 0.037732 | 0.037732 | 0.0 | 2.34 +Output | 0.0003345 | 0.0003345 | 0.0003345 | 0.0 | 0.02 +Modify | 0.038016 | 0.038016 | 0.038016 | 0.0 | 2.36 +Other | | 0.002731 | | | 0.17 -Nlocal: 4000 ave 4000 max 4000 min +Nlocal: 4000.00 ave 4000 max 4000 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 5499 ave 5499 max 5499 min +Nghost: 5506.00 ave 5506 max 5506 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 151513 ave 151513 max 151513 min +Neighs: 151788.0 ave 151788 max 151788 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 151513 -Ave neighs/atom = 37.8783 +Total # of neighbors = 151788 +Ave neighs/atom = 37.947000 Neighbor list builds = 12 Dangerous builds not checked -Total wall time: 0:00:00 +Total wall time: 0:00:01 diff --git a/examples/melt/log.8Apr21.melt.g++.4 b/examples/melt/log.8Apr21.melt.g++.4 new file mode 100644 index 0000000000..1edbeac7aa --- /dev/null +++ b/examples/melt/log.8Apr21.melt.g++.4 @@ -0,0 +1,85 @@ +LAMMPS (8 Apr 2021) + using 1 OpenMP thread(s) per MPI task +# 3d Lennard-Jones melt + +units lj +atom_style atomic + +lattice fcc 0.8442 +Lattice spacing in x,y,z = 1.6795962 1.6795962 1.6795962 +region box block 0 10 0 10 0 10 +create_box 1 box +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (16.795962 16.795962 16.795962) + 1 by 2 by 2 MPI processor grid +create_atoms 1 box +Created 4000 atoms + create_atoms CPU = 0.001 seconds +mass 1 1.0 + +velocity all create 3.0 87287 loop geom + +pair_style lj/cut 2.5 +pair_coeff 1 1 1.0 1.0 2.5 + +neighbor 0.3 bin +neigh_modify every 20 delay 0 check no + +fix 1 all nve + +#dump id all atom 50 dump.melt + +#dump 2 all image 25 image.*.jpg type type # axes yes 0.8 0.02 view 60 -30 +#dump_modify 2 pad 3 + +#dump 3 all movie 25 movie.mpg type type # axes yes 0.8 0.02 view 60 -30 +#dump_modify 3 pad 3 + +thermo 50 +run 250 +Neighbor list info ... + update every 20 steps, delay 0 steps, check no + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 2.8 + ghost atom cutoff = 2.8 + binsize = 1.4, bins = 12 12 12 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard +Per MPI rank memory allocation (min/avg/max) = 2.706 | 2.706 | 2.706 Mbytes +Step Temp E_pair E_mol TotEng Press + 0 3 -6.7733681 0 -2.2744931 -3.7033504 + 50 1.6842865 -4.8082494 0 -2.2824513 5.5666131 + 100 1.6712577 -4.7875609 0 -2.281301 5.6613913 + 150 1.6444751 -4.7471034 0 -2.2810074 5.8614211 + 200 1.6471542 -4.7509053 0 -2.2807916 5.8805431 + 250 1.6645597 -4.7774327 0 -2.2812174 5.7526089 +Loop time of 0.490832 on 4 procs for 250 steps with 4000 atoms + +Performance: 220034.754 tau/day, 509.340 timesteps/s +96.7% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.35932 | 0.37256 | 0.38746 | 1.9 | 75.90 +Neigh | 0.035928 | 0.038449 | 0.042344 | 1.3 | 7.83 +Comm | 0.053452 | 0.068917 | 0.08485 | 5.3 | 14.04 +Output | 0.00015545 | 0.00023746 | 0.00047684 | 0.0 | 0.05 +Modify | 0.0096958 | 0.0097951 | 0.0098989 | 0.1 | 2.00 +Other | | 0.0008721 | | | 0.18 + +Nlocal: 1000.00 ave 1008 max 987 min +Histogram: 1 0 0 0 0 0 1 0 1 1 +Nghost: 2711.25 ave 2728 max 2693 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Neighs: 37947.0 ave 38966 max 37338 min +Histogram: 1 1 0 1 0 0 0 0 0 1 + +Total # of neighbors = 151788 +Ave neighs/atom = 37.947000 +Neighbor list builds = 12 +Dangerous builds not checked +Total wall time: 0:00:00 diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index 51dca15e7b..136472f1cd 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -1261,6 +1261,7 @@ void FixWallGran::granular(double rsq, double dx, double dy, double dz, k_tangential = tangential_coeffs[0]; damp_tangential = tangential_coeffs[1]*damp_normal_prefactor; + Fscrit = tangential_coeffs[2] * Fncrit; int thist0 = tangential_history_index; int thist1 = thist0 + 1; @@ -1346,7 +1347,6 @@ void FixWallGran::granular(double rsq, double dx, double dy, double dz, } // rescale frictional displacements and forces if needed - Fscrit = tangential_coeffs[2] * Fncrit; fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); if (fs > Fscrit) { shrmag = sqrt(history[thist0]*history[thist0] + diff --git a/src/MOLECULE/angle_cosine_periodic.cpp b/src/MOLECULE/angle_cosine_periodic.cpp index 0df103c333..6d4252e8b3 100644 --- a/src/MOLECULE/angle_cosine_periodic.cpp +++ b/src/MOLECULE/angle_cosine_periodic.cpp @@ -17,17 +17,17 @@ #include "angle_cosine_periodic.h" -#include #include "atom.h" -#include "neighbor.h" -#include "domain.h" #include "comm.h" +#include "domain.h" +#include "error.h" #include "force.h" #include "math_const.h" #include "math_special.h" #include "memory.h" -#include "error.h" +#include "neighbor.h" +#include using namespace LAMMPS_NS; using namespace MathConst; @@ -224,7 +224,7 @@ void AngleCosinePeriodic::coeff(int narg, char **arg) double AngleCosinePeriodic::equilibrium_angle(int i) { - return MY_PI*(1.0 - (b[i]>0)?0.0:1.0/static_cast(multiplicity[i])); + return MY_PI*(1.0 - ((b[i]>0) ? 0.0 : (1.0/static_cast(multiplicity[i])))); } /* ---------------------------------------------------------------------- diff --git a/src/RIGID/fix_rattle.cpp b/src/RIGID/fix_rattle.cpp index aef3cb3964..90aa6d487a 100644 --- a/src/RIGID/fix_rattle.cpp +++ b/src/RIGID/fix_rattle.cpp @@ -17,17 +17,18 @@ #include "fix_rattle.h" -#include -#include #include "atom.h" -#include "update.h" -#include "modify.h" -#include "domain.h" -#include "force.h" #include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" #include "math_extra.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 26bbb9477f..3cd4f5dbc8 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -13,29 +13,29 @@ #include "fix_rigid.h" -#include - -#include -#include "math_extra.h" -#include "math_eigen.h" #include "atom.h" #include "atom_vec_ellipsoid.h" #include "atom_vec_line.h" #include "atom_vec_tri.h" -#include "domain.h" -#include "update.h" -#include "respa.h" -#include "modify.h" -#include "group.h" #include "comm.h" -#include "random_mars.h" -#include "force.h" -#include "input.h" -#include "variable.h" -#include "math_const.h" -#include "memory.h" +#include "domain.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "input.h" +#include "math_const.h" +#include "math_eigen.h" +#include "math_extra.h" +#include "memory.h" +#include "modify.h" +#include "random_mars.h" +#include "respa.h" #include "rigid_const.h" +#include "update.h" +#include "variable.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index 4dec04370e..3c4e332fd2 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -18,22 +18,24 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nh.h" -#include -#include -#include "math_extra.h" + #include "atom.h" +#include "comm.h" #include "compute.h" #include "domain.h" -#include "update.h" -#include "modify.h" -#include "fix_deform.h" -#include "group.h" -#include "comm.h" -#include "force.h" -#include "kspace.h" -#include "memory.h" #include "error.h" +#include "fix_deform.h" +#include "force.h" +#include "group.h" +#include "kspace.h" +#include "math_extra.h" +#include "memory.h" +#include "modify.h" #include "rigid_const.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/RIGID/fix_rigid_nvt_small.cpp b/src/RIGID/fix_rigid_nvt_small.cpp index 0bcebd866d..0392f9c881 100644 --- a/src/RIGID/fix_rigid_nvt_small.cpp +++ b/src/RIGID/fix_rigid_nvt_small.cpp @@ -18,6 +18,7 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nvt_small.h" + #include "error.h" using namespace LAMMPS_NS; diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 390fe88309..5662e63c88 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -13,25 +13,26 @@ #include "fix_shake.h" +#include "angle.h" +#include "atom.h" +#include "atom_vec.h" +#include "bond.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "fix_respa.h" +#include "force.h" +#include "group.h" +#include "math_const.h" +#include "memory.h" +#include "modify.h" +#include "molecule.h" +#include "respa.h" +#include "update.h" + #include #include #include -#include "atom.h" -#include "atom_vec.h" -#include "molecule.h" -#include "update.h" -#include "respa.h" -#include "modify.h" -#include "domain.h" -#include "force.h" -#include "bond.h" -#include "angle.h" -#include "comm.h" -#include "group.h" -#include "fix_respa.h" -#include "math_const.h" -#include "memory.h" -#include "error.h" using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp index 2247a9467c..72fa4ff064 100644 --- a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp @@ -581,14 +581,14 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, { double r2inv,r6inv,r,grij,expm2,t,erfc1,prefactor,prefactor2; double fraction,table,forcecoul,forcecoul2,forcelj; - double rrij,expn2,erfc2,expb,ecoul,evdwl,trx,tr,ftr; + double rrij,expn2,erfc2,ecoul,evdwl,trx,tr,ftr; int itable; r2inv = 1.0/rsq; + r = sqrt(rsq); if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { - r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); @@ -621,7 +621,6 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, forcecoul2 = 0.0; prefactor2 = 0.0; } else { - r = sqrt(rsq); rrij = lj2[itype][jtype]*r; expn2 = exp(-rrij*rrij); erfc2 = erfc(rrij); diff --git a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp index c7fcac855a..4e52226eaf 100644 --- a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp @@ -586,9 +586,9 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, int itable; r2inv = 1.0/rsq; + r = sqrt(rsq); if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { - r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); @@ -613,7 +613,6 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - r = sqrt(rsq); expb = lj3[itype][jtype]*exp(-lj1[itype][jtype]*r); forcelj = expb*lj1[itype][jtype]*r; r6inv = r2inv*r2inv*r2inv; diff --git a/src/dump.cpp b/src/dump.cpp index 031364dada..c483d90fc3 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -14,16 +14,16 @@ #include "dump.h" #include "atom.h" -#include "irregular.h" -#include "update.h" -#include "domain.h" -#include "group.h" -#include "output.h" -#include "modify.h" -#include "fix.h" #include "compute.h" -#include "memory.h" +#include "domain.h" #include "error.h" +#include "fix.h" +#include "group.h" +#include "irregular.h" +#include "memory.h" +#include "modify.h" +#include "output.h" +#include "update.h" #include @@ -141,12 +141,9 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) if (strchr(filename,'*')) multifile = 1; - char *suffix = filename + strlen(filename) - strlen(".bin"); - if (suffix > filename && strcmp(suffix,".bin") == 0) binary = 1; - suffix = filename + strlen(filename) - strlen(".gz"); - if (suffix > filename && strcmp(suffix,".gz") == 0) compressed = 1; - suffix = filename + strlen(filename) - strlen(".zst"); - if (suffix > filename && strcmp(suffix,".zst") == 0) compressed = 1; + if (utils::strmatch(filename, "\\.bin$")) binary = 1; + if (utils::strmatch(filename, "\\.gz$") + || utils::strmatch(filename, "\\.zst$")) compressed = 1; } /* ---------------------------------------------------------------------- */ @@ -582,12 +579,11 @@ void Dump::openfile() if (filewriter) { if (compressed) { #ifdef LAMMPS_GZIP - char gzip[128]; - sprintf(gzip,"gzip -6 > %s",filecurrent); + auto gzip = fmt::format("gzip -6 > {}",filecurrent); #ifdef _WIN32 - fp = _popen(gzip,"wb"); + fp = _popen(gzip.c_str(),"wb"); #else - fp = popen(gzip,"w"); + fp = popen(gzip.c_str(),"w"); #endif #else error->one(FLERR,"Cannot open gzipped file"); diff --git a/src/finish.cpp b/src/finish.cpp index 810155f1b0..28596e3a72 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -401,7 +401,7 @@ void Finish::end(int flag) } #endif - if (lmp->kokkos && lmp->kokkos->ngpus > 0) + if ((comm->me == 0) && lmp->kokkos && (lmp->kokkos->ngpus > 0)) if (const char* env_clb = getenv("CUDA_LAUNCH_BLOCKING")) if (!(strcmp(env_clb,"1") == 0)) { error->warning(FLERR,"Timing breakdown may not be accurate " diff --git a/src/fix_tmd.cpp b/src/fix_tmd.cpp index 8cff132c63..f462b0633b 100644 --- a/src/fix_tmd.cpp +++ b/src/fix_tmd.cpp @@ -18,19 +18,18 @@ #include "fix_tmd.h" +#include "atom.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "respa.h" +#include "update.h" + #include #include -#include "atom.h" -#include "update.h" -#include "modify.h" -#include "domain.h" -#include "group.h" -#include "respa.h" -#include "force.h" -#include "memory.h" -#include "error.h" - - using namespace LAMMPS_NS; using namespace FixConst; @@ -520,31 +519,29 @@ void FixTMD::readfile(char *file) void FixTMD::open(char *file) { - compressed = 0; - char *suffix = file + strlen(file) - 3; - if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1; - if (!compressed) fp = fopen(file,"r"); - else { + if (utils::strmatch(file,"\\.gz$")) { + compressed = 1; + #ifdef LAMMPS_GZIP - char gunzip[128]; - snprintf(gunzip,128,"gzip -c -d %s",file); + auto gunzip = fmt::format("gzip -c -d {}",file); #ifdef _WIN32 - fp = _popen(gunzip,"rb"); + fp = _popen(gunzip.c_str(),"rb"); #else - fp = popen(gunzip,"r"); + fp = popen(gunzip.c_str(),"r"); #endif #else - error->one(FLERR,"Cannot open gzipped file"); + error->one(FLERR,"Cannot open gzipped file without gzip support"); #endif + } else { + compressed = 0; + fp = fopen(file,"r"); } - if (fp == nullptr) { - char str[128]; - snprintf(str,128,"Cannot open file %s",file); - error->one(FLERR,str); - } + if (fp == nullptr) + error->one(FLERR,fmt::format("Cannot open file {}: {}", + file, utils::getsyserror())); } /* ---------------------------------------------------------------------- */ diff --git a/src/input.cpp b/src/input.cpp index f96cf8c75c..9079cdd76c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1250,9 +1250,18 @@ void Input::shell() for (int i = 1; i < narg; i++) { rv = 0; #ifdef _WIN32 - if (arg[i]) rv = _putenv(arg[i]); + if (arg[i]) rv = _putenv(utils::strdup(arg[i])); #else - if (arg[i]) rv = putenv(arg[i]); + if (arg[i]) { + std::string vardef(arg[i]); + auto found = vardef.find_first_of("="); + if (found == std::string::npos) { + rv = setenv(vardef.c_str(),"",1); + } else { + rv = setenv(vardef.substr(0,found).c_str(), + vardef.substr(found+1).c_str(),1); + } + } #endif rv = (rv < 0) ? errno : 0; MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world); diff --git a/src/library.cpp b/src/library.cpp index b72c8d7220..300aafc293 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4734,19 +4734,14 @@ void lammps_set_fix_external_callback(void *handle, char *id, FixExternalFnPtr c BEGIN_CAPTURE { int ifix = lmp->modify->find_fix(id); - if (ifix < 0) { - char str[128]; - snprintf(str, 128, "Can not find fix with ID '%s'!", id); - lmp->error->all(FLERR,str); - } + if (ifix < 0) + lmp->error->all(FLERR,fmt::format("Cannot find fix with ID '{}'!", id)); Fix *fix = lmp->modify->fix[ifix]; - if (strcmp("external",fix->style) != 0) { - char str[128]; - snprintf(str, 128, "Fix '%s' is not of style external!", id); - lmp->error->all(FLERR,str); - } + if (strcmp("external",fix->style) != 0) + lmp->error->all(FLERR,fmt::format("Fix '{}' is not of style " + "external!", id)); FixExternal * fext = (FixExternal*) fix; fext->set_callback(callback, caller); diff --git a/src/pair.cpp b/src/pair.cpp index 767fa638cf..0d90b0ce39 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -204,7 +204,6 @@ void Pair::modify_params(int narg, char **arg) else error->all(FLERR,"Illegal pair_modify command"); iarg += 2; } else if (strcmp(arg[iarg],"nofdotr") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); no_virial_fdotr_compute = 1; ++iarg; } else error->all(FLERR,"Illegal pair_modify command"); diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index c7b6048139..c12ec67351 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -468,10 +468,7 @@ void PairHybrid::coeff(int narg, char **arg) if (multiple[m]) { multflag = 1; if (narg < 4) error->all(FLERR,"Incorrect args for pair coefficients"); - if (!isdigit(arg[3][0])) - error->all(FLERR,"Incorrect args for pair coefficients"); - int index = utils::inumeric(FLERR,arg[3],false,lmp); - if (index == multiple[m]) break; + if (multiple[m] == utils::inumeric(FLERR,arg[3],false,lmp)) break; else continue; } else break; } @@ -492,7 +489,7 @@ void PairHybrid::coeff(int narg, char **arg) // invoke sub-style coeff() starting with 1st remaining arg - if (!none) styles[m]->coeff(narg-1-multflag,&arg[1+multflag]); + if (!none) styles[m]->coeff(narg-1-multflag,arg+1+multflag); // if sub-style only allows one pair coeff call (with * * and type mapping) // then unset setflag/map assigned to that style before setting it below diff --git a/src/pair_hybrid_overlay.cpp b/src/pair_hybrid_overlay.cpp index fc78a8aef7..814b3b2f20 100644 --- a/src/pair_hybrid_overlay.cpp +++ b/src/pair_hybrid_overlay.cpp @@ -17,7 +17,6 @@ #include "error.h" #include -#include using namespace LAMMPS_NS; @@ -51,10 +50,7 @@ void PairHybridOverlay::coeff(int narg, char **arg) if (multiple[m]) { multflag = 1; if (narg < 4) error->all(FLERR,"Incorrect args for pair coefficients"); - if (!isdigit(arg[3][0])) - error->all(FLERR,"Incorrect args for pair coefficients"); - int index = utils::inumeric(FLERR,arg[3],false,lmp); - if (index == multiple[m]) break; + if (multiple[m] == utils::inumeric(FLERR,arg[3],false,lmp)) break; else continue; } else break; } @@ -75,7 +71,7 @@ void PairHybridOverlay::coeff(int narg, char **arg) // invoke sub-style coeff() starting with 1st remaining arg - if (!none) styles[m]->coeff(narg-1-multflag,&arg[1+multflag]); + if (!none) styles[m]->coeff(narg-1-multflag,arg+1+multflag); // set setflag and which type pairs map to which sub-style // if sub-style is none: set hybrid subflag, wipe out map diff --git a/src/read_data.cpp b/src/read_data.cpp index 09fb8f3eae..cc3b2e5965 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1954,13 +1954,12 @@ int ReadData::reallocate(int **pcount, int cmax, int amax) void ReadData::open(char *file) { - compressed = 0; - char *suffix = file + strlen(file) - 3; - if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1; - if (!compressed) fp = fopen(file,"r"); - else { + if (utils::strmatch(file,"\\.gz$")) { + compressed = 1; + #ifdef LAMMPS_GZIP - std::string gunzip = fmt::format("gzip -c -d {}",file); + auto gunzip = fmt::format("gzip -c -d {}",file); + #ifdef _WIN32 fp = _popen(gunzip.c_str(),"rb"); #else @@ -1968,8 +1967,11 @@ void ReadData::open(char *file) #endif #else - error->one(FLERR,"Cannot open gzipped file: " + utils::getsyserror()); + error->one(FLERR,"Cannot open gzipped file without gzip support"); #endif + } else { + compressed = 0; + fp = fopen(file,"r"); } if (fp == nullptr) diff --git a/src/reader.cpp b/src/reader.cpp index a4bc8d816f..c22a9f7e5d 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -37,13 +37,12 @@ void Reader::open_file(const char *file) { if (fp != nullptr) close_file(); - compressed = 0; - const char *suffix = file + strlen(file) - 3; - if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1; - if (!compressed) fp = fopen(file,"r"); - else { + if (utils::strmatch(file,"\\.gz$")) { + compressed = 1; + #ifdef LAMMPS_GZIP - std::string gunzip = fmt::format("gzip -c -d {}",file); + auto gunzip = fmt::format("gzip -c -d {}",file); + #ifdef _WIN32 fp = _popen(gunzip.c_str(),"rb"); #else @@ -51,8 +50,11 @@ void Reader::open_file(const char *file) #endif #else - error->one(FLERR,"Cannot open gzipped file: " + utils::getsyserror()); + error->one(FLERR,"Cannot open gzipped file without gzip support"); #endif + } else { + compressed = 0; + fp = fopen(file,"r"); } if (fp == nullptr) diff --git a/src/variable.cpp b/src/variable.cpp index 1a4feb3573..d903490219 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -337,11 +337,11 @@ void Variable::set(int narg, char **arg) } if (nvar == maxvar) grow(); style[nvar] = GETENV; - num[nvar] = 1; + num[nvar] = 2; which[nvar] = 0; pad[nvar] = 0; data[nvar] = new char*[num[nvar]]; - copy(1,&arg[2],data[nvar]); + data[nvar][0] = utils::strdup(arg[2]); data[nvar][1] = utils::strdup("(undefined)"); // SCALARFILE for strings or numbers @@ -1252,7 +1252,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) print_var_error(FLERR,"Invalid syntax in variable formula",ivar); expect = OP; - char *contents; + char *contents = nullptr; i = find_matching_paren(str,i,contents,ivar); i++; @@ -2068,7 +2068,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) // ---------------- if (str[i] == '(') { - char *contents; + char *contents = nullptr; i = find_matching_paren(str,i,contents,ivar); i++; @@ -3286,6 +3286,7 @@ int Variable::find_matching_paren(char *str, int i, char *&contents, int ivar) int istop = i; int n = istop - istart - 1; + delete[] contents; contents = new char[n+1]; strncpy(contents,&str[istart+1],n); contents[n] = '\0'; @@ -4827,7 +4828,7 @@ double Variable::evaluate_boolean(char *str) error->all(FLERR,"Invalid Boolean syntax in if command"); expect = OP; - char *contents; + char *contents = nullptr; i = find_matching_paren(str,i,contents,-1); i++; diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 9bd6e74c9b..e8cebe98e2 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -20,8 +20,8 @@ #include "output.h" #include "update.h" #include "utils.h" +#include "variable.h" -#include "fmt/format.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "../testing/core.h" @@ -400,23 +400,26 @@ TEST_F(SimpleCommandsTest, Shell) command("shell putenv TEST_VARIABLE=simpletest"); END_HIDE_OUTPUT(); - char *test_var = getenv("TEST_VARIABLE"); + const char *test_var = getenv("TEST_VARIABLE"); ASSERT_NE(test_var, nullptr); ASSERT_THAT(test_var, StrEq("simpletest")); BEGIN_HIDE_OUTPUT(); - command("shell putenv TEST_VARIABLE=simpletest"); - command("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2"); + command("shell putenv TEST_VARIABLE"); + command("shell putenv TEST_VARIABLE2=simpletest OTHER_VARIABLE=2"); END_HIDE_OUTPUT(); - char *test_var2 = getenv("TEST_VARIABLE2"); - char *other_var = getenv("OTHER_VARIABLE"); + test_var = getenv("TEST_VARIABLE2"); + ASSERT_NE(test_var, nullptr); + ASSERT_THAT(test_var, StrEq("simpletest")); - ASSERT_NE(test_var2, nullptr); - ASSERT_THAT(test_var2, StrEq("simpletest2")); + test_var = getenv("OTHER_VARIABLE"); + ASSERT_NE(test_var, nullptr); + ASSERT_THAT(test_var, StrEq("2")); - ASSERT_NE(other_var, nullptr); - ASSERT_THAT(other_var, StrEq("2")); + test_var = getenv("TEST_VARIABLE"); + ASSERT_NE(test_var, nullptr); + ASSERT_THAT(test_var, StrEq("")); } TEST_F(SimpleCommandsTest, CiteMe) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 97f874a856..f31959c3ff 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -122,6 +122,8 @@ TEST_F(VariableTest, CreateDelete) file_vars(); ASSERT_EQ(variable->nvar, 1); BEGIN_HIDE_OUTPUT(); + command("shell putenv TEST_VARIABLE=simpletest2"); + command("shell putenv TEST_VARIABLE2=simpletest OTHER_VARIABLE=2"); command("variable one index 1 2 3 4"); command("variable two equal 1"); command("variable two equal 2"); @@ -133,8 +135,8 @@ TEST_F(VariableTest, CreateDelete) command("variable five2 loop 10 200 pad"); command("variable six world one"); command("variable seven format two \"%5.2f\""); - command("variable eight getenv PWD"); - command("variable eight getenv XXXXX"); + command("variable eight getenv TEST_VARIABLE2"); + command("variable eight getenv XXX"); command("variable nine file test_variable.file"); command("variable ten internal 1.0"); command("variable ten internal 10.0"); @@ -167,6 +169,14 @@ TEST_F(VariableTest, CreateDelete) unlink("MYFILE"); ASSERT_THAT(variable->retrieve("file"), StrEq("0")); + BEGIN_HIDE_OUTPUT(); + command("variable seven delete"); + command("variable seven getenv TEST_VARIABLE"); + command("variable eight getenv OTHER_VARIABLE"); + END_HIDE_OUTPUT(); + ASSERT_THAT(variable->retrieve("seven"), StrEq("simpletest2")); + ASSERT_THAT(variable->retrieve("eight"), StrEq("2")); + ASSERT_EQ(variable->equalstyle(variable->find("one")), 0); ASSERT_EQ(variable->equalstyle(variable->find("two")), 1); ASSERT_EQ(variable->equalstyle(variable->find("ten")), 1); diff --git a/unittest/force-styles/tests/angle-cosine_periodic.yaml b/unittest/force-styles/tests/angle-cosine_periodic.yaml index 1c6cb7158d..84d8ff1194 100644 --- a/unittest/force-styles/tests/angle-cosine_periodic.yaml +++ b/unittest/force-styles/tests/angle-cosine_periodic.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 10 Mar 2021 -date_generated: Tue Apr 6 18:38:56 2021 +lammps_version: 8 Apr 2021 +date_generated: Thu Apr 8 09:28:11 2021 epsilon: 2.5e-13 prerequisites: ! | atom full @@ -11,32 +11,32 @@ input_file: in.fourmol angle_style: cosine/periodic angle_coeff: ! | 1 75.0 1 2 - 2 45.0 1 2 + 2 45.0 -1 2 3 50.0 -1 3 4 100.0 -1 4 -equilibrium: 4 1.5707963267948966 1.5707963267948966 0 0 +equilibrium: 4 3.141592653589793 1.5707963267948966 2.0943951023931957 2.356194490192345 extract: ! "" natoms: 29 -init_energy: 946.676664091363 -init_stress: ! |2- - 3.8581448829084906e+00 -6.3926599144452858e+01 6.0068454261544439e+01 1.4347370855129017e+02 1.0109551149053127e+02 4.9470344115369670e+01 +init_energy: 605.3643061001458 +init_stress: ! |- + -1.7082420754402889e+01 -7.3281097507808681e+00 2.4410530505183818e+01 8.5827033671406951e+01 1.4260977966148616e+02 4.1579557432232576e+01 init_forces: ! |2 1 7.9609486050127529e+00 -3.9274211736421961e+01 -3.8917410871887981e+01 2 4.6997439470662350e+00 3.8052682089524090e+01 3.0599010994189470e+01 - 3 -4.4330179925982058e+01 -1.6514501437366098e+00 1.9894582317318523e+01 - 4 1.1465928779203908e+01 -7.1462736556935234e+00 -1.8983545733370338e+01 - 5 2.7634466780141157e+01 1.5504150132065057e+01 1.0078115065618357e+01 - 6 2.2512674572611367e+01 -5.4260358088923418e+01 -6.0646506351853276e+01 + 3 -7.1532072701475698e+01 9.6873528247272844e+01 7.3410935137796983e+01 + 4 3.1784763224659116e+01 -4.4133218046130608e+01 -6.2234613362865147e+01 + 5 5.8817481848549889e+01 -2.5112568523390145e+01 3.9611729278121981e+00 + 6 -8.7258065964885336e+00 -4.2663580774228997e+01 -1.6819642012415606e+01 7 -1.5578858996464229e+01 1.3895348629116569e+01 -3.3939856789628062e+00 - 8 -2.6028225001107934e+00 4.7418887884887312e+01 1.2659217319984802e+02 - 9 9.4419020144376677e+00 -1.3812152922900303e+01 1.2280697239365450e+00 - 10 3.7181742871134183e+01 -2.6592777970320334e+01 -1.0034832175946605e+02 - 11 1.1888648487599809e+01 -1.7288532453781471e+00 -1.8714004234488471e+00 - 12 1.3452345752647041e+01 3.9195153629390539e+01 -3.9429673136141247e+01 - 13 -4.6656310032990458e+00 -1.2502935413462930e+01 1.4918864440944628e+01 - 14 -2.1383527724886850e+01 -9.3422692044635554e+00 7.5125645645164223e+00 - 15 -8.0644375221897171e+00 -2.6783296801963008e+00 6.9267625241565547e+00 - 16 -7.0395776185793807e+01 4.3227686209287491e+01 3.0567216126495769e+01 + 8 -1.6678237064738614e+01 -2.6557373913973738e+01 8.7708427797183326e+00 + 9 -9.4419020144376677e+00 1.3812152922900303e+01 -1.2280697239365450e+00 + 10 1.0844630504236606e+02 1.9274264686364820e+01 1.2594098114786526e+01 + 11 -1.1888648487599809e+01 1.7288532453781471e+00 1.8714004234488471e+00 + 12 9.7432958614920665e+01 1.1284647087939499e+02 -1.3445218835244805e+02 + 13 -2.2887258478933525e+01 -5.9815335453575649e+01 4.1237962971772127e+01 + 14 -4.6498844054867675e+01 -3.0251289808967520e+01 1.5556535565006259e+01 + 15 -5.3477741242848616e+01 -1.7885978453267143e+01 4.6284681424489207e+01 + 16 -7.3215663693592745e+01 1.7514552522777997e+01 7.4857846653898914e+00 17 2.0782832048872386e+01 -2.8304296512773977e+01 1.5273484998106287e+01 18 1.6481336531704756e+00 1.7222946144801426e+01 -6.9896289164966490e+01 19 -2.0180190840279820e+01 -2.5140421523544326e+01 2.9933594625645306e+01 @@ -50,27 +50,27 @@ init_forces: ! |2 27 -8.7971258084923178e+00 7.2217511410368814e+01 -2.4599681382405976e+01 28 -1.9235439225569891e+01 -4.3179911322776611e+01 1.0030656861974458e+00 29 2.8032565034062209e+01 -2.9037600087592210e+01 2.3596615696208531e+01 -run_energy: 945.667120914027 -run_stress: ! |2- - 4.9007195370705645e+00 -6.4584848054201885e+01 5.9684128517131313e+01 1.4440631784196160e+02 1.0147779649040916e+02 5.0605123164347972e+01 +run_energy: 603.8182365368202 +run_stress: ! |- + -1.6098625319219664e+01 -7.7961962067566510e+00 2.3894821525976329e+01 8.7036156470651477e+01 1.4262918929621054e+02 4.2523803236880880e+01 run_forces: ! |2 - 1 8.0595707378962782e+00 -3.9275884216073550e+01 -3.8921834622274609e+01 - 2 4.6450877231394490e+00 3.7989319504376653e+01 3.0709930231636147e+01 - 3 -4.4174062041610540e+01 -1.3116774304574319e+00 1.9852389406583850e+01 - 4 1.1432955350908090e+01 -7.3978491536336328e+00 -1.8963452260213845e+01 - 5 2.7565769765719310e+01 1.5533965769082254e+01 1.0064393083030197e+01 - 6 2.2437947870916961e+01 -5.4321180615060769e+01 -6.0748488446866872e+01 - 7 -1.5585343433722571e+01 1.3904433399215314e+01 -3.4020204287915634e+00 - 8 -2.7173598979194153e+00 4.7428178462168347e+01 1.2654691883960646e+02 - 9 9.4915406599908749e+00 -1.3885257714808199e+01 1.2160209239091246e+00 - 10 3.7036130179485966e+01 -2.6384482125884212e+01 -1.0013051660330657e+02 - 11 1.1913327728618880e+01 -1.7105485662994653e+00 -1.8898750666441195e+00 - 12 1.3449580650332301e+01 3.9344535800585398e+01 -3.9552691785632291e+01 - 13 -4.6002052262583266e+00 -1.2370495939576998e+01 1.4765847794019894e+01 - 14 -2.1313398317698834e+01 -9.6666833306404527e+00 7.4826992840481967e+00 - 15 -8.0459573339780484e+00 -2.8098768831377434e+00 7.2021609989661499e+00 - 16 -7.0394187900784956e+01 4.3284348202675552e+01 3.0478355256814506e+01 - 17 2.0798603484964556e+01 -2.8350845162531051e+01 1.5290163395115368e+01 + 1 8.1036664069391833e+00 -3.9279459516104339e+01 -3.8959949625007155e+01 + 2 4.6488532958171156e+00 3.7987813821226069e+01 3.0712083303318757e+01 + 3 -7.1419656269516480e+01 9.7015207052323333e+01 7.3123837986656483e+01 + 4 3.1774739774255771e+01 -4.4324760214341296e+01 -6.1918121921961003e+01 + 5 5.8630133295649813e+01 -2.5003101567718115e+01 3.8957656941403842e+00 + 6 -8.6686835699933500e+00 -4.2717543793109854e+01 -1.6944132920021204e+01 + 7 -1.5605967450730276e+01 1.3924972058096937e+01 -3.4081311693274161e+00 + 8 -1.6735469954990947e+01 -2.6654949908594496e+01 8.9412902423392993e+00 + 9 -9.4705763934675620e+00 1.3861186924074314e+01 -1.2218212802251793e+00 + 10 1.0864309846473817e+02 1.9311615651482960e+01 1.2534898619395602e+01 + 11 -1.1889594908454491e+01 1.6849924892427488e+00 1.9039966312260486e+00 + 12 9.6643785665770423e+01 1.1329932305772147e+02 -1.3435213826206018e+02 + 13 -2.2815824864999897e+01 -5.9701629573330088e+01 4.1148977584672039e+01 + 14 -4.6226658006998740e+01 -3.0469540424436548e+01 1.5534272011399247e+01 + 15 -5.3141801628038777e+01 -1.8156497866651446e+01 4.6272398149175629e+01 + 16 -7.3254211788300807e+01 1.7569251761827239e+01 7.4522974142679850e+00 + 17 2.0784167932320894e+01 -2.8346879951708846e+01 1.5284477542010659e+01 18 1.7456021018344252e+00 1.7528557172698406e+01 -7.0852460721917453e+01 19 -2.0389936120749365e+01 -2.5462340563923114e+01 3.0421727677614534e+01 20 1.8644334018914940e+01 7.9337833912247095e+00 4.0430733044302912e+01 diff --git a/unittest/force-styles/yaml_writer.cpp b/unittest/force-styles/yaml_writer.cpp index b5082c361f..d299b7a879 100644 --- a/unittest/force-styles/yaml_writer.cpp +++ b/unittest/force-styles/yaml_writer.cpp @@ -13,6 +13,7 @@ #include "yaml_writer.h" #include "yaml.h" +#include "fmt/format.h" #include #include @@ -51,41 +52,17 @@ YamlWriter::~YamlWriter() void YamlWriter::emit(const std::string &key, const double value) { - yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)key.c_str(), key.size(), 1, 0, - YAML_PLAIN_SCALAR_STYLE); - yaml_emitter_emit(&emitter, &event); - char buf[256]; - snprintf(buf, 256, "%.15g", value); - yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf, - strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE); - yaml_emitter_emit(&emitter, &event); + emit(key,fmt::format("{}",value)); } void YamlWriter::emit(const std::string &key, const long value) { - yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)key.c_str(), key.size(), 1, 0, - YAML_PLAIN_SCALAR_STYLE); - yaml_emitter_emit(&emitter, &event); - char buf[256]; - snprintf(buf, 256, "%ld", value); - yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf, - strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE); - yaml_emitter_emit(&emitter, &event); + emit(key,fmt::format("{}",value)); } void YamlWriter::emit(const std::string &key, const int value) { - yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)key.c_str(), key.size(), 1, 0, - YAML_PLAIN_SCALAR_STYLE); - yaml_emitter_emit(&emitter, &event); - char buf[256]; - snprintf(buf, 256, "%d", value); - yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf, - strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE); - yaml_emitter_emit(&emitter, &event); + emit(key,fmt::format("{}",value)); } void YamlWriter::emit(const std::string &key, const std::string &value) diff --git a/unittest/python/python-formats.py b/unittest/python/python-formats.py index c093e9bebb..ca877b8305 100644 --- a/unittest/python/python-formats.py +++ b/unittest/python/python-formats.py @@ -4,7 +4,7 @@ from lammps.formats import LogFile, AvgChunkFile EXAMPLES_DIR=os.path.abspath(os.path.join(__file__, '..', '..', '..', 'examples')) -DEFAULT_STYLE_EXAMPLE_LOG="melt/log.27Nov18.melt.g++.1" +DEFAULT_STYLE_EXAMPLE_LOG="melt/log.8Apr21.melt.g++.1" MULTI_STYLE_EXAMPLE_LOG="peptide/log.27Nov18.peptide.g++.1" AVG_CHUNK_FILE="VISCOSITY/profile.13Oct16.nemd.2d.g++.1"