Unverified Commit 9a70f2d1 authored by Steve Plimpton's avatar Steve Plimpton Committed by GitHub
Browse files

Merge pull request #773 from lammps/couple-simple

update of COUPLE/simple examples
parents e798cdf3 b95cf658
Loading
Loading
Loading
Loading
+22 −19
Original line number Diff line number Diff line
@@ -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:
+1 −1
Original line number Diff line number Diff line
@@ -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");
  }

+9 −8
Original line number Diff line number Diff line
@@ -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
+6 −3
Original line number Diff line number Diff line
@@ -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)

+3 −7
Original line number Diff line number Diff line
@@ -306,10 +306,6 @@ 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.
  neighbor->init();
}

/* ---------------------------------------------------------------------- */
@@ -342,7 +338,7 @@ void CreateBonds::single_bond()
    bond_atom[m][num_bond[m]] = batom2;
    num_bond[m]++;
  }
  ++atom->nbonds;
  atom->nbonds++;

  if (force->newton_bond) return;

@@ -390,7 +386,7 @@ void CreateBonds::single_angle()
    angle_atom3[m][num_angle[m]] = aatom3;
    num_angle[m]++;
  }
  ++atom->nangles;
  atom->nangles++;

  if (force->newton_bond) return;

@@ -454,7 +450,7 @@ void CreateBonds::single_dihedral()
    dihedral_atom4[m][num_dihedral[m]] = datom4;
    num_dihedral[m]++;
  }
  ++atom->ndihedrals;
  atom->ndihedrals++;

  if (force->newton_bond) return;

Loading