forked from lijiext/lammps
update of COUPLE/simple examples
This commit is contained in:
parent
e798cdf31f
commit
21ff4407ab
|
@ -17,33 +17,36 @@ additional wrapper library that interfaces the C interface of the
|
|||
LAMMPS library to Fortran and also translates the MPI communicator
|
||||
from Fortran to C.
|
||||
|
||||
Once you have built LAMMPS as a library (see examples/COUPLE/README),
|
||||
you can then build any of the driver codes with compile lines like
|
||||
these, which include paths to the LAMMPS library interface, MPI (an
|
||||
installed MPICH in this case), and FFTW (assuming you built LAMMPS as
|
||||
a library with its PPPM solver).
|
||||
First build LAMMPS as a library (see examples/COUPLE/README), e.g.
|
||||
|
||||
This builds the C++ driver with the LAMMPS library using a C++ compiler:
|
||||
make mode=shlib mpi
|
||||
|
||||
g++ -I/home/sjplimp/lammps/src -c simple.cpp
|
||||
g++ -L/home/sjplimp/lammps/src simple.o \
|
||||
-llammps -lfftw -lmpich -lmpl -lpthread -o simpleCC
|
||||
You can then build any of the driver codes with compile lines like
|
||||
these, which include paths to the LAMMPS library interface, and
|
||||
linking with FFTW (only needed if you built LAMMPS as a library with
|
||||
its PPPM solver).
|
||||
|
||||
This builds the C driver with the LAMMPS library using a C compiler:
|
||||
This builds the C++ driver with the LAMMPS library using the mpiCC
|
||||
(C++) compiler:
|
||||
|
||||
gcc -I/home/sjplimp/lammps/src -c simple.c
|
||||
gcc -L/home/sjplimp/lammps/src simple.o \
|
||||
-llammps -lfftw -lmpich -lmpl -lpthread -lstdc++ -o simpleC
|
||||
mpiCC -I/home/sjplimp/lammps/src -c simple.cpp
|
||||
mpiCC -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -o simpleCC
|
||||
|
||||
This builds the C driver with the LAMMPS library using the mpicc (C)
|
||||
compiler:
|
||||
|
||||
mpicc -I/home/sjplimp/lammps/src -c simple.c
|
||||
mpicc -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -o simpleC
|
||||
|
||||
This builds the Fortran wrapper and driver with the LAMMPS library
|
||||
using a Fortran and C compiler, using the wrapper in the fortran
|
||||
directory:
|
||||
using the mpicc (C) and mpifort (Fortran) compilers, using the wrapper
|
||||
in the fortran directory:
|
||||
|
||||
cp ../fortran/libfwrapper.c .
|
||||
gcc -I/home/sjplimp/lammps/src -c libfwrapper.c
|
||||
gfortran -I/home/sjplimp/lammps/src -c simple.f90
|
||||
gfortran -L/home/sjplimp/lammps/src simple.o libfwrapper.o \
|
||||
-llammps -lfftw -lfmpich -lmpich -lpthread -lstdc++ -o simpleF
|
||||
mpicc -I/home/sjplimp/lammps/src -c libfwrapper.c
|
||||
mpifort -c simple.f90
|
||||
mpifort -L/home/sjplimp/lammps/src simple.o libfwrapper.o \
|
||||
-llammps -lfftw -o simpleF
|
||||
|
||||
You then run simpleCC, simpleC, or simpleF on a parallel machine
|
||||
on some number of processors Q with 2 arguments:
|
||||
|
|
|
@ -145,7 +145,7 @@ int main(int narg, char **arg)
|
|||
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_create_atoms(lmp,natoms,NULL,type,x,v,NULL,0);
|
||||
lammps_command(lmp,"run 10");
|
||||
}
|
||||
|
||||
|
|
|
@ -109,11 +109,11 @@ int main(int narg, char **arg)
|
|||
int natoms = static_cast<int> (lmp->atom->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);
|
||||
lammps_gather_atoms(lmp,(char *) "x",1,3,x);
|
||||
lammps_gather_atoms(lmp,(char *) "v",1,3,v);
|
||||
double epsilon = 0.1;
|
||||
x[0] += epsilon;
|
||||
lammps_scatter_atoms(lmp,"x",1,3,x);
|
||||
lammps_scatter_atoms(lmp,(char *) "x",1,3,x);
|
||||
|
||||
// these 2 lines are the same
|
||||
|
||||
|
@ -124,21 +124,22 @@ int main(int narg, char **arg)
|
|||
// extract force on single atom two different ways
|
||||
|
||||
if (lammps == 1) {
|
||||
double **f = (double **) lammps_extract_atom(lmp,"f");
|
||||
double **f = (double **) lammps_extract_atom(lmp,(char *) "f");
|
||||
printf("Force on 1 atom via extract_atom: %g\n",f[0][0]);
|
||||
|
||||
double *fx = (double *) lammps_extract_variable(lmp,"fx","all");
|
||||
double *fx = (double *)
|
||||
lammps_extract_variable(lmp,(char *) "fx",(char *) "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";
|
||||
char *strtwo = (char *) "run 10\nrun 20";
|
||||
if (lammps == 1) lammps_commands_string(lmp,strtwo);
|
||||
|
||||
char *cmds[2];
|
||||
cmds[0] = "run 10";
|
||||
cmds[1] = "run 20";
|
||||
cmds[0] = (char *) "run 10";
|
||||
cmds[1] = (char *) "run 20";
|
||||
if (lammps == 1) lammps_commands_list(lmp,2,cmds);
|
||||
|
||||
// delete all atoms
|
||||
|
|
|
@ -115,9 +115,12 @@ PROGRAM f_driver
|
|||
CALL lammps_get_natoms(ptr,natoms)
|
||||
ALLOCATE(x(3*natoms))
|
||||
|
||||
CALL lammps_gather_atoms(ptr,'x',1,3,x);
|
||||
x(1) = x(1) + epsilon
|
||||
CALL lammps_scatter_atoms(ptr,'x',1,3,x);
|
||||
! these calls are commented out, b/c libfwrapper.c
|
||||
! needs to be updated to use gather_atoms and scatter_atoms
|
||||
|
||||
!CALL lammps_gather_atoms(ptr,'x',1,3,x);
|
||||
!x(1) = x(1) + epsilon
|
||||
!CALL lammps_scatter_atoms(ptr,'x',1,3,x);
|
||||
|
||||
DEALLOCATE(x)
|
||||
|
||||
|
|
|
@ -306,9 +306,11 @@ void CreateBonds::many()
|
|||
nadd_bonds,atom->nbonds);
|
||||
}
|
||||
}
|
||||
|
||||
// trigger clearing the list of available neighbor list requests
|
||||
// and a full rebuild of them during the next run setup.
|
||||
// otherwise the request from this command may linger around.
|
||||
// and a full rebuild of them during the next run setup
|
||||
// otherwise the request from this command may linger around
|
||||
|
||||
neighbor->init();
|
||||
}
|
||||
|
||||
|
|
|
@ -407,9 +407,11 @@ void DeleteAtoms::delete_overlap(int narg, char **arg)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// trigger clearing the list of available neighbor list requests
|
||||
// and a full rebuild of them during the next run setup.
|
||||
// otherwise the request from this command may linger around.
|
||||
// and a full rebuild of them during the next run setup
|
||||
// otherwise the request from this command may linger around
|
||||
|
||||
neighbor->init();
|
||||
}
|
||||
|
||||
|
|
|
@ -715,12 +715,13 @@ void FixNeighHistory::set_arrays(int i)
|
|||
int FixNeighHistory::pack_reverse_comm_size(int n, int first)
|
||||
{
|
||||
int i,last;
|
||||
int dnump1 = dnum + 1;
|
||||
|
||||
int m = 0;
|
||||
last = first + n;
|
||||
|
||||
for (i = first; i < last; i++)
|
||||
m += 1 + (dnum+1)*npartner[i];
|
||||
m += 1 + dnump1*npartner[i];
|
||||
|
||||
return m;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue