refactor how properties computed by the fix are accessed

lambda is no an (intensive) scalar property
and the vector property only has the potential energies.
pressure is accessed via compute pressure/alchemy.
This commit is contained in:
Axel Kohlmeyer
2023-02-25 12:47:49 -05:00
parent d691d1db78
commit 60129958c8
5 changed files with 52 additions and 42 deletions

View File

@ -86,8 +86,8 @@ fix_modify integrate press pressure
# "dump 1 all atom 100 ${name}.lammpstrj" & # "dump 1 all atom 100 ${name}.lammpstrj" &
# "dump_modify 1 sort id" # "dump_modify 1 sort id"
thermo_style custom step temp press etotal density pe ke f_transform[1] f_transform[4] thermo_style custom step temp press etotal density pe ke f_transform f_transform[3]
thermo_modify colname f_transform[1] lambda colname f_transform[4] EPot_mixed thermo_modify colname f_transform lambda colname f_transform[3] EPot_mixed
thermo_modify press pressure thermo_modify press pressure
thermo 100 thermo 100

View File

@ -167,8 +167,8 @@ fix_modify integrate press pressure
# only need to output a dump file from one partition # only need to output a dump file from one partition
# if "${name} == twowater" then # "dump 1 all atom 100 ${name}.lammpstrj" # "dump_modify 1 sort id" # if "${name} == twowater" then # "dump 1 all atom 100 ${name}.lammpstrj" # "dump_modify 1 sort id"
thermo_style custom step temp press etotal density pe ke f_transform[1] f_transform[4] thermo_style custom step temp press etotal density pe ke f_transform f_transform[3]
thermo_modify colname f_transform[1] lambda colname f_transform[4] EPot_mixed thermo_modify colname f_transform lambda colname f_transform[3] EPot_mixed
thermo_modify press pressure thermo_modify press pressure
thermo 100 thermo 100
@ -377,21 +377,21 @@ Per MPI rank memory allocation (min/avg/max) = 7.535 | 7.535 | 7.535 Mbytes
19800 295.68946 81474.342 2308.3249 1.0240743 2219.3041 89.020804 0.01 1910.5545 19800 295.68946 81474.342 2308.3249 1.0240743 2219.3041 89.020804 0.01 1910.5545
19900 306.4947 43488.052 2330.4958 1.0222707 2238.222 92.27385 0.005 1957.4368 19900 306.4947 43488.052 2330.4958 1.0222707 2238.222 92.27385 0.005 1957.4368
20000 313.31679 -25133.284 -1161.6979 1.0163289 -1256.0256 94.327722 0 -1649.7551 20000 313.31679 -25133.284 -1161.6979 1.0163289 -1256.0256 94.327722 0 -1649.7551
Loop time of 11.8252 on 2 procs for 20000 steps with 102 atoms Loop time of 11.7903 on 2 procs for 20000 steps with 102 atoms
Performance: 29.226 ns/day, 0.821 hours/ns, 1691.296 timesteps/s, 172.512 katom-step/s Performance: 29.312 ns/day, 0.819 hours/ns, 1696.311 timesteps/s, 173.024 katom-step/s
99.3% CPU use with 2 MPI tasks x 1 OpenMP threads 99.3% CPU use with 2 MPI tasks x 1 OpenMP threads
MPI task timing breakdown: MPI task timing breakdown:
Section | min time | avg time | max time |%varavg| %total Section | min time | avg time | max time |%varavg| %total
--------------------------------------------------------------- ---------------------------------------------------------------
Pair | 6.8298 | 8.6298 | 10.43 | 61.3 | 72.98 Pair | 6.8605 | 8.6071 | 10.354 | 59.5 | 73.00
Bond | 0.045072 | 0.045296 | 0.045519 | 0.1 | 0.38 Bond | 0.044148 | 0.044761 | 0.045375 | 0.3 | 0.38
Neigh | 0.10567 | 0.10572 | 0.10577 | 0.0 | 0.89 Neigh | 0.10568 | 0.10573 | 0.10578 | 0.0 | 0.90
Comm | 0.73714 | 2.5381 | 4.3392 | 113.0 | 21.46 Comm | 0.74919 | 2.4939 | 4.2386 | 110.5 | 21.15
Output | 0.0032977 | 0.0035468 | 0.003796 | 0.4 | 0.03 Output | 0.0033838 | 0.0036358 | 0.0038879 | 0.4 | 0.03
Modify | 0.43872 | 0.44155 | 0.44438 | 0.4 | 3.73 Modify | 0.46825 | 0.47526 | 0.48227 | 1.0 | 4.03
Other | | 0.06121 | | | 0.52 Other | | 0.05993 | | | 0.51
Nlocal: 51 ave 51 max 51 min Nlocal: 51 ave 51 max 51 min
Histogram: 2 0 0 0 0 0 0 0 0 0 Histogram: 2 0 0 0 0 0 0 0 0 0

View File

@ -45,7 +45,7 @@ Read molecule template water:
create_atoms 0 single -2.0 0.0 0.0 mol water 453624 create_atoms 0 single -2.0 0.0 0.0 mol water 453624
Created 3 atoms Created 3 atoms
using lattice units in orthogonal box = (-5 -5 -5) to (5 5 5) using lattice units in orthogonal box = (-5 -5 -5) to (5 5 5)
create_atoms CPU = 0.004 seconds create_atoms CPU = 0.003 seconds
create_atoms 0 single 2.0 0.0 0.0 mol water 767353 create_atoms 0 single 2.0 0.0 0.0 mol water 767353
Created 3 atoms Created 3 atoms
using lattice units in orthogonal box = (-5 -5 -5) to (5 5 5) using lattice units in orthogonal box = (-5 -5 -5) to (5 5 5)
@ -191,8 +191,8 @@ fix_modify integrate press pressure
# only need to output a dump file from one partition # only need to output a dump file from one partition
# if "${name} == twowater" then # "dump 1 all atom 100 ${name}.lammpstrj" # "dump_modify 1 sort id" # if "${name} == twowater" then # "dump 1 all atom 100 ${name}.lammpstrj" # "dump_modify 1 sort id"
thermo_style custom step temp press etotal density pe ke f_transform[1] f_transform[4] thermo_style custom step temp press etotal density pe ke f_transform f_transform[3]
thermo_modify colname f_transform[1] lambda colname f_transform[4] EPot_mixed thermo_modify colname f_transform lambda colname f_transform[3] EPot_mixed
thermo_modify press pressure thermo_modify press pressure
thermo 100 thermo 100
@ -402,21 +402,21 @@ Per MPI rank memory allocation (min/avg/max) = 7.535 | 7.535 | 7.535 Mbytes
19800 295.68946 81474.342 1996.4567 1.0240743 1907.4359 89.020804 0.99 1910.5545 19800 295.68946 81474.342 1996.4567 1.0240743 1907.4359 89.020804 0.99 1910.5545
19900 306.4947 43488.052 2048.2997 1.0222707 1956.0258 92.27385 0.995 1957.4368 19900 306.4947 43488.052 2048.2997 1.0222707 1956.0258 92.27385 0.995 1957.4368
20000 313.31679 -25133.284 -1555.4274 1.0163289 -1649.7551 94.327722 1 -1649.7551 20000 313.31679 -25133.284 -1555.4274 1.0163289 -1649.7551 94.327722 1 -1649.7551
Loop time of 11.8253 on 2 procs for 20000 steps with 102 atoms Loop time of 11.7903 on 2 procs for 20000 steps with 102 atoms
Performance: 29.226 ns/day, 0.821 hours/ns, 1691.295 timesteps/s, 172.512 katom-step/s Performance: 29.312 ns/day, 0.819 hours/ns, 1696.310 timesteps/s, 173.024 katom-step/s
99.3% CPU use with 2 MPI tasks x 1 OpenMP threads 99.3% CPU use with 2 MPI tasks x 1 OpenMP threads
MPI task timing breakdown: MPI task timing breakdown:
Section | min time | avg time | max time |%varavg| %total Section | min time | avg time | max time |%varavg| %total
--------------------------------------------------------------- ---------------------------------------------------------------
Pair | 6.8508 | 8.6272 | 10.404 | 60.5 | 72.96 Pair | 6.8748 | 8.631 | 10.387 | 59.8 | 73.20
Bond | 0.045829 | 0.046542 | 0.047256 | 0.3 | 0.39 Bond | 0.04667 | 0.047105 | 0.04754 | 0.2 | 0.40
Neigh | 0.10781 | 0.10791 | 0.108 | 0.0 | 0.91 Neigh | 0.10858 | 0.10862 | 0.10866 | 0.0 | 0.92
Comm | 0.75178 | 2.5281 | 4.3045 | 111.7 | 21.38 Comm | 0.74367 | 2.4997 | 4.2558 | 111.1 | 21.20
Output | 0.0032916 | 0.0035722 | 0.0038527 | 0.5 | 0.03 Output | 0.0034405 | 0.0037033 | 0.003966 | 0.4 | 0.03
Modify | 0.44867 | 0.45212 | 0.45556 | 0.5 | 3.82 Modify | 0.4338 | 0.4388 | 0.4438 | 0.8 | 3.72
Other | | 0.05976 | | | 0.51 Other | | 0.06136 | | | 0.52
Nlocal: 51 ave 51 max 51 min Nlocal: 51 ave 51 max 51 min
Histogram: 2 0 0 0 0 0 0 0 0 0 Histogram: 2 0 0 0 0 0 0 0 0 0

View File

@ -31,33 +31,27 @@ using namespace FixConst;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
static double get_lambda(const bigint &step, const bigint &begin, const bigint &end, int iworld)
{
double lambda = step - begin;
if (lambda != 0.0) lambda /= end - begin;
if (iworld == 0) lambda = 1.0 - lambda;
return lambda;
}
/* ---------------------------------------------------------------------- */
FixAlchemy::FixAlchemy(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), commbuf(nullptr) FixAlchemy::FixAlchemy(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), commbuf(nullptr)
{ {
if (narg != 3) error->all(FLERR, "Incorrect number of arguments for fix alchemy"); if (narg != 3) error->all(FLERR, "Incorrect number of arguments for fix alchemy");
if (universe->nworlds != 2) error->all(FLERR, "Must use exactly two partitions");
lambda = epot[0] = epot[1] = 0.0; lambda = epot[0] = epot[1] = epot[2] = 0.0;
progress = 0; progress = 0;
for (int i = 0; i < 6; ++i) pressure[i] = 0.0; for (int i = 0; i < 6; ++i) pressure[i] = 0.0;
no_change_box = 1; no_change_box = 1;
time_depend = 1;
scalar_flag = 1;
extscalar = 0;
vector_flag = 1; vector_flag = 1;
size_vector = 10; size_vector = 3;
extvector = 0; extvector = 1;
ilevel_respa = 0; ilevel_respa = 0;
nmax = 6; nmax = 6;
sync_box = 0;
// set up rank-to-rank communicator // set up rank-to-rank communicator
if (universe->nworlds != 2) error->all(FLERR, "Must use exactly two partitions");
int color = comm->me; int color = comm->me;
int key = universe->iworld; int key = universe->iworld;
MPI_Comm_split(universe->uworld, color, key, &samerank); MPI_Comm_split(universe->uworld, color, key, &samerank);
@ -163,12 +157,22 @@ void FixAlchemy::setup(int vflag)
void FixAlchemy::post_integrate() void FixAlchemy::post_integrate()
{ {
// synchronize atom positions
const int nall = atom->nlocal + atom->nghost; const int nall = atom->nlocal + atom->nghost;
MPI_Bcast(&atom->x[0][0], 3 * nall, MPI_DOUBLE, 0, samerank); MPI_Bcast(&atom->x[0][0], 3 * nall, MPI_DOUBLE, 0, samerank);
// synchronize box dimensions, if needed // synchronize box dimensions, if needed
if (sync_box) synchronize_box(domain, samerank); if (sync_box) synchronize_box(domain, samerank);
} }
/* ---------------------------------------------------------------------- */
static double get_lambda(const bigint &step, const bigint &begin, const bigint &end, int iworld)
{
double lambda = step - begin;
if (lambda != 0.0) lambda /= end - begin;
if (iworld == 0) lambda = 1.0 - lambda;
return lambda;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -215,11 +219,16 @@ void FixAlchemy::post_force(int /*vflag*/)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
double FixAlchemy::compute_scalar()
{
return lambda;
}
/* ---------------------------------------------------------------------- */
double FixAlchemy::compute_vector(int n) double FixAlchemy::compute_vector(int n)
{ {
if (n == 0) return lambda; return epot[n];
if ((n > 0) && (n < 4)) return epot[n - 1];
return pressure[n - 4];
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -34,6 +34,7 @@ class FixAlchemy : public Fix {
void setup(int) override; void setup(int) override;
void post_integrate() override; void post_integrate() override;
void post_force(int) override; void post_force(int) override;
double compute_scalar() override;
double compute_vector(int) override; double compute_vector(int) override;
void *extract(const char *, int &) override; void *extract(const char *, int &) override;