remove EVAL command

This commit is contained in:
Steve Plimpton
2022-03-15 17:13:15 -06:00
parent 99fa769800
commit 8d341e0714
5 changed files with 106 additions and 72 deletions

View File

@ -185,12 +185,8 @@ void FixMDIAimd::post_force(int vflag)
ierr = MDI_Send(buf3all,3*atom->natoms,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: >COORDS data");
// trigger engine to evaluate forces,energy,pressure for current system
ierr = MDI_Send_command("EVAL",mdicomm);
if (ierr) error->all(FLERR,"MDI: EVAL command");
// request forces from MDI engine
// this triggers engine to evaluate forces,energy,stress for current system
ierr = MDI_Send_command("<FORCES",mdicomm);
if (ierr) error->all(FLERR,"MDI: <FORCES command");
@ -214,10 +210,10 @@ void FixMDIAimd::post_force(int vflag)
// divide by nprocs so each proc stores a portion
if (eflag_global) {
ierr = MDI_Send_command("<PE",mdicomm);
if (ierr) error->all(FLERR,"MDI: <PE command");
ierr = MDI_Send_command("<ENERGY",mdicomm);
if (ierr) error->all(FLERR,"MDI: <ENERGY command");
ierr = MDI_Recv(&engine_energy,1,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: <PE data");
if (ierr) error->all(FLERR,"MDI: <ENERGY data");
MPI_Bcast(&engine_energy,1,MPI_DOUBLE,0,world);
engine_energy *= mdi2lmp_energy / nprocs;
}
@ -227,10 +223,10 @@ void FixMDIAimd::post_force(int vflag)
if (vflag_global) {
double ptensor[6];
ierr = MDI_Send_command("<PTENSOR",mdicomm);
if (ierr) error->all(FLERR,"MDI: <PTENSOR command");
ierr = MDI_Send_command("<STRESS",mdicomm);
if (ierr) error->all(FLERR,"MDI: <STRESS command");
ierr = MDI_Recv(ptensor,6,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: <PTENSOR data");
if (ierr) error->all(FLERR,"MDI: <STRESS data");
MPI_Bcast(ptensor,6,MPI_DOUBLE,0,world);
double volume = domain->xprd * domain->yprd * domain->zprd;
@ -283,11 +279,12 @@ void FixMDIAimd::reallocate()
void FixMDIAimd::unit_conversions()
{
double angstrom_to_bohr,kelvin_to_hartree,ev_to_hartree;
double angstrom_to_bohr,kelvin_to_hartree,ev_to_hartree,second_to_aut;
MDI_Conversion_factor("angstrom","bohr",&angstrom_to_bohr);
MDI_Conversion_factor("kelvin_energy","hartree",&kelvin_to_hartree);
MDI_Conversion_factor("electron_volt","hartree",&ev_to_hartree);
MDI_Conversion_Factor("second","atomic_unit_of_time",&second_to_aut);
// length units
@ -312,7 +309,7 @@ void FixMDIAimd::unit_conversions()
mdi2lmp_energy = 1.0 / ev_to_hartree;
}
// force units
// force units = energy/length
mdi2lmp_force = 1.0;
lmp2mdi_force = 1.0;
@ -325,8 +322,31 @@ void FixMDIAimd::unit_conversions()
mdi2lmp_force = angstrom_to_bohr / ev_to_hartree;
}
// pressure units
// pressure or stress units = force/area = energy/volume
mdi2lmp_pressure = 1.0;
lmp2mdi_pressure = 1.0;
if (lmpunits == REAL) {
lmp2mdi_pressure = (kelvin_to_hartree / force->boltz) /
(angstrom_to_bohr * angstrom_to_bohr * angstrom_to_bohr) / force->nktv2p;
mdi2lmp_pressure = 1.0 / lmp2mdi_pressure;
} else if (lmpunits == METAL) {
lmp2mdi_pressure = ev_to_hartree /
(angstrom_to_bohr * angstrom_to_bohr * angstrom_to_bohr) / force->nktv2p;
mdi2lmp_pressure = 1.0 / lmp2mdi_pressure;
}
// velocity units = distance/time
mdi2lmp_velocity = 1.0;
lmp2mdi_velocity = 1.0;
if (lmpunits == REAL) {
lmp2mdi_velocity = angstrom_to_bohr / (1.0e-15 * second_to_aut);
mdi2lmp_velocity = 1.0 / lmp2mdi_velocity;
} else if (lmpunits == METAL) {
lmp2mdi_velocity = angstrom_to_bohr / (1.0e-12 * second_to_aut);
mdi2lmp_velocity = 1.0 / lmp2mdi_velocity;
}
}

View File

@ -54,7 +54,7 @@ class FixMDIAimd : public Fix {
double lmp2mdi_energy,mdi2lmp_energy;
double lmp2mdi_force,mdi2lmp_force;
double lmp2mdi_pressure,mdi2lmp_pressure;
double lmp2mdi_virial,mdi2lmp_virial;
double lmp2mdi_velocity,mdi2lmp_velocity;
// buffers for MDI comm

View File

@ -150,6 +150,7 @@ void MDIEngine::mdi_engine(int narg, char **arg)
ibuf1 = ibuf1all = nullptr;
maxbuf = 0;
need_evaluation = 1;
nbytes = -1;
create_atoms_flag = 0;
@ -300,6 +301,7 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
} else if (strcmp(command,">COORDS") == 0) {
receive_double3(COORD,0);
need_evaluation = 1;
} else if (strcmp(command,">FORCES") == 0) {
receive_double3(FORCE,0);
@ -328,11 +330,17 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
send_double3(COORD);
} else if (strcmp(command,"<ENERGY") == 0) {
evaluate();
if (need_evaluation) {
evaluate();
need_evaluation = 0;
}
send_energy();
} else if (strcmp(command,"<FORCES") == 0) {
evaluate();
if (need_evaluation) {
evaluate();
need_evaluation = 0;
}
send_double3(FORCE);
} else if (strcmp(command,"<KE") == 0) {
@ -351,7 +359,10 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
send_ntypes();
} else if (strcmp(command,"<STRESS") == 0) {
evaluate();
if (need_evaluation) {
evaluate();
need_evaluation = 0;
}
send_stress();
} else if (strcmp(command,"<TYPES") == 0) {
@ -754,6 +765,57 @@ void MDIEngine::mdi_optg()
"with invalid command: {}",mdicmd));
}
/* ----------------------------------------------------------------------
evaluate() = compute forces, energy, pressure of current system
usage modes:
(1) called many times by a driver for system that is continuously evolving
(2) called once per system by a driver that is passing in many systems
distinguishes between:
(a) first-time call
(b) system needs reneighboring
(c) system does not need reneighboring
for (b) and (c), timestep is advanced
---------------------------------------------------------------------- */
void MDIEngine::evaluate()
{
// NOTE: ago is not a good test
// caller should decide which verion of evaluate() is needed?
// currently cannot call it interspersed with "delete atoms" calls
// b/c whichflag stays set
// separate issue, need to unset whichflag when done
if (neighbor->ago < 0) {
update->whichflag = 1;
lmp->init();
update->integrate->setup(1);
update->whichflag = 0;
} else {
// insure potential energy and virial are tallied on this step
update->ntimestep++;
pe->addstep(update->ntimestep);
press->addstep(update->ntimestep);
int nflag = neighbor->decide();
if (nflag == 0) {
comm->forward_comm();
update->integrate->setup_minimal(0);
modify->clearstep_compute();
output->thermo->compute(1);
modify->addstep_compute(update->ntimestep+1);
} else {
update->integrate->setup_minimal(1);
modify->clearstep_compute();
output->thermo->compute(1);
modify->addstep_compute(update->ntimestep+1);
}
}
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// responses to standard MDI driver commands
@ -1356,57 +1418,6 @@ void MDIEngine::infile()
delete [] infile;
}
/* ----------------------------------------------------------------------
EVAL command
compute forces, energy, pressure of current system
can be called multiple times by driver
for a system that is continuously evolving
distinguishes between:
(1) first-time call
(2) system needs reneighboring
(3) system does not need reneighboring
this method does NOT increment timestep
---------------------------------------------------------------------- */
void MDIEngine::evaluate()
{
// NOTE: ago is not a good test
// caller needs to distinguish
// currently cannot call it interspersed with "delete atoms" calls
// b/c whichflag stays set
// separate issue, need to unset whichflag when done
if (neighbor->ago < 0) {
update->whichflag = 1;
lmp->init();
update->integrate->setup(1);
update->whichflag = 0;
} else {
// insure potential energy and virial are tallied on this step
update->ntimestep++;
pe->addstep(update->ntimestep);
press->addstep(update->ntimestep);
int nflag = neighbor->decide();
if (nflag == 0) {
comm->forward_comm();
update->integrate->setup_minimal(0);
modify->clearstep_compute();
output->thermo->compute(1);
modify->addstep_compute(update->ntimestep+1);
} else {
update->integrate->setup_minimal(1);
modify->clearstep_compute();
output->thermo->compute(1);
modify->addstep_compute(update->ntimestep+1);
}
}
}
/* ----------------------------------------------------------------------
RESET_BOX command
wrapper on library reset_box() method

View File

@ -55,6 +55,8 @@ class MDIEngine : public Command {
class Minimize *minimizer;
class Compute *ke,*pe,*press;
int need_evaluation; // 1 if system has changed, else 0
int nbytes; // NBYTES command value used by other commands
// create_atoms state
@ -90,6 +92,8 @@ class MDIEngine : public Command {
void mdi_md();
void mdi_optg();
void evaluate();
void receive_natoms();
void send_natoms();
void send_ntypes();
@ -115,7 +119,6 @@ class MDIEngine : public Command {
void single_command();
void many_commands();
void infile();
void evaluate();
void reset_box();
void create_atoms(int);
void send_stress();