new library functions
This commit is contained in:
@ -20,4 +20,6 @@ neigh_modify delay 0 every 20 check no
|
||||
|
||||
fix 1 all nve
|
||||
|
||||
variable fx atom fx
|
||||
|
||||
run 10
|
||||
|
||||
@ -71,8 +71,8 @@ int main(int narg, char **arg)
|
||||
(could just send it to proc 0 of comm_lammps and let it Bcast)
|
||||
all LAMMPS procs call lammps_command() on the line */
|
||||
|
||||
void *ptr;
|
||||
if (lammps == 1) lammps_open(0,NULL,comm_lammps,&ptr);
|
||||
void *lmp = NULL;
|
||||
if (lammps == 1) lammps_open(0,NULL,comm_lammps,&lmp);
|
||||
|
||||
int n;
|
||||
char line[1024];
|
||||
@ -85,7 +85,7 @@ int main(int narg, char **arg)
|
||||
MPI_Bcast(&n,1,MPI_INT,0,MPI_COMM_WORLD);
|
||||
if (n == 0) break;
|
||||
MPI_Bcast(line,n,MPI_CHAR,0,MPI_COMM_WORLD);
|
||||
if (lammps == 1) lammps_command(ptr,line);
|
||||
if (lammps == 1) lammps_command(lmp,line);
|
||||
}
|
||||
|
||||
/* run 10 more steps
|
||||
@ -94,23 +94,72 @@ int main(int narg, char **arg)
|
||||
put coords back into LAMMPS
|
||||
run a single step with changed coords */
|
||||
|
||||
if (lammps == 1) {
|
||||
lammps_command(ptr,"run 10");
|
||||
double *x = NULL;
|
||||
double *v = NULL;
|
||||
|
||||
int natoms = lammps_get_natoms(ptr);
|
||||
double *x = (double *) malloc(3*natoms*sizeof(double));
|
||||
lammps_gather_atoms(ptr,"x",1,3,x);
|
||||
if (lammps == 1) {
|
||||
lammps_command(lmp,"run 10");
|
||||
|
||||
int natoms = lammps_get_natoms(lmp);
|
||||
x = (double *) malloc(3*natoms*sizeof(double));
|
||||
lammps_gather_atoms(lmp,"x",1,3,x);
|
||||
v = (double *) malloc(3*natoms*sizeof(double));
|
||||
lammps_gather_atoms(lmp,"v",1,3,v);
|
||||
double epsilon = 0.1;
|
||||
x[0] += epsilon;
|
||||
lammps_scatter_atoms(ptr,"x",1,3,x);
|
||||
free(x);
|
||||
lammps_scatter_atoms(lmp,"x",1,3,x);
|
||||
|
||||
lammps_command(ptr,"run 1");
|
||||
lammps_command(lmp,"run 1");
|
||||
}
|
||||
|
||||
if (lammps == 1) lammps_close(ptr);
|
||||
// extract force on single atom two different ways
|
||||
|
||||
if (lammps == 1) {
|
||||
double **f = (double **) lammps_extract_atom(lmp,"f");
|
||||
printf("Force on 1 atom via extract_atom: %g\n",f[0][0]);
|
||||
|
||||
double *fx = (double *) lammps_extract_variable(lmp,"fx","all");
|
||||
printf("Force on 1 atom via extract_variable: %g\n",fx[0]);
|
||||
}
|
||||
|
||||
/* use commands_string() and commands_list() to invoke more commands */
|
||||
|
||||
char *strtwo = "run 10\nrun 20";
|
||||
if (lammps == 1) lammps_commands_string(lmp,strtwo);
|
||||
|
||||
char *cmds[2];
|
||||
cmds[0] = "run 10";
|
||||
cmds[1] = "run 20";
|
||||
if (lammps == 1) lammps_commands_list(lmp,2,cmds);
|
||||
|
||||
/* delete all atoms
|
||||
create_atoms() to create new ones with old coords, vels
|
||||
initial thermo should be same as step 20 */
|
||||
|
||||
int *type = NULL;
|
||||
|
||||
if (lammps == 1) {
|
||||
int natoms = lammps_get_natoms(lmp);
|
||||
type = (int *) malloc(natoms*sizeof(double));
|
||||
int i;
|
||||
for (i = 0; i < natoms; i++) type[i] = 1;
|
||||
|
||||
lammps_command(lmp,"delete_atoms group all");
|
||||
lammps_create_atoms(lmp,natoms,NULL,type,x,v);
|
||||
lammps_command(lmp,"run 10");
|
||||
}
|
||||
|
||||
if (x) free(x);
|
||||
if (v) free(v);
|
||||
if (type) free(type);
|
||||
|
||||
// close down LAMMPS
|
||||
|
||||
lammps_close(lmp);
|
||||
|
||||
/* close down MPI */
|
||||
|
||||
if (lammps == 1) MPI_Comm_free(&comm_lammps);
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
MPI_Finalize();
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ int main(int narg, char **arg)
|
||||
// (could just send it to proc 0 of comm_lammps and let it Bcast)
|
||||
// all LAMMPS procs call input->one() on the line
|
||||
|
||||
LAMMPS *lmp;
|
||||
LAMMPS *lmp = NULL;
|
||||
if (lammps == 1) lmp = new LAMMPS(0,NULL,comm_lammps);
|
||||
|
||||
int n;
|
||||
@ -91,7 +91,7 @@ int main(int narg, char **arg)
|
||||
MPI_Bcast(&n,1,MPI_INT,0,MPI_COMM_WORLD);
|
||||
if (n == 0) break;
|
||||
MPI_Bcast(line,n,MPI_CHAR,0,MPI_COMM_WORLD);
|
||||
if (lammps == 1) lmp->input->one(line);
|
||||
if (lammps == 1) lammps_command(lmp,line);
|
||||
}
|
||||
|
||||
// run 10 more steps
|
||||
@ -100,23 +100,74 @@ int main(int narg, char **arg)
|
||||
// put coords back into LAMMPS
|
||||
// run a single step with changed coords
|
||||
|
||||
double *x = NULL;
|
||||
double *v = NULL;
|
||||
|
||||
if (lammps == 1) {
|
||||
lmp->input->one("run 10");
|
||||
|
||||
int natoms = static_cast<int> (lmp->atom->natoms);
|
||||
double *x = new double[3*natoms];
|
||||
x = new double[3*natoms];
|
||||
v = new double[3*natoms];
|
||||
lammps_gather_atoms(lmp,"x",1,3,x);
|
||||
lammps_gather_atoms(lmp,"v",1,3,v);
|
||||
double epsilon = 0.1;
|
||||
x[0] += epsilon;
|
||||
lammps_scatter_atoms(lmp,"x",1,3,x);
|
||||
delete [] x;
|
||||
|
||||
// these 2 lines are the same
|
||||
|
||||
// lammps_command(lmp,"run 1");
|
||||
lmp->input->one("run 1");
|
||||
}
|
||||
|
||||
if (lammps == 1) delete lmp;
|
||||
// extract force on single atom two different ways
|
||||
|
||||
if (lammps == 1) {
|
||||
double **f = (double **) lammps_extract_atom(lmp,"f");
|
||||
printf("Force on 1 atom via extract_atom: %g\n",f[0][0]);
|
||||
|
||||
double *fx = (double *) lammps_extract_variable(lmp,"fx","all");
|
||||
printf("Force on 1 atom via extract_variable: %g\n",fx[0]);
|
||||
}
|
||||
|
||||
// use commands_string() and commands_list() to invoke more commands
|
||||
|
||||
char *strtwo = "run 10\nrun 20";
|
||||
if (lammps == 1) lammps_commands_string(lmp,strtwo);
|
||||
|
||||
char *cmds[2];
|
||||
cmds[0] = "run 10";
|
||||
cmds[1] = "run 20";
|
||||
if (lammps == 1) lammps_commands_list(lmp,2,cmds);
|
||||
|
||||
// delete all atoms
|
||||
// create_atoms() to create new ones with old coords, vels
|
||||
// initial thermo should be same as step 20
|
||||
|
||||
int *type = NULL;
|
||||
|
||||
if (lammps == 1) {
|
||||
int natoms = static_cast<int> (lmp->atom->natoms);
|
||||
type = new int[natoms];
|
||||
for (int i = 0; i < natoms; i++) type[i] = 1;
|
||||
|
||||
lmp->input->one("delete_atoms group all");
|
||||
lammps_create_atoms(lmp,natoms,NULL,type,x,v);
|
||||
lmp->input->one("run 10");
|
||||
}
|
||||
|
||||
delete [] x;
|
||||
delete [] v;
|
||||
delete [] type;
|
||||
|
||||
// close down LAMMPS
|
||||
|
||||
delete lmp;
|
||||
|
||||
// close down MPI
|
||||
|
||||
if (lammps == 1) MPI_Comm_free(&comm_lammps);
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
MPI_Finalize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user