forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8133 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
10507a091e
commit
34f7a93712
|
@ -32,5 +32,7 @@ lammps_spparks grain-growth Monte Carlo with strain via MD,
|
|||
coupling to SPPARKS kinetic MC code
|
||||
library collection of useful inter-code communication routines
|
||||
simple simple example of driver code calling LAMMPS as library
|
||||
fortran a wrapper on the LAMMPS library API that
|
||||
can be called from Fortran
|
||||
|
||||
Each sub-directory has its own README.
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
libfwrapper.c is a C file that wraps the LAMMPS library API
|
||||
in src/library.h so that it can be called from Fortran.
|
||||
|
||||
See the couple/simple/simple.f90 program for an example
|
||||
of a Fortran code that does this.
|
||||
|
||||
See the README file in that dir for instructions
|
||||
on how to build a Fortran code that uses this
|
||||
wrapper and links to the LAMMPS library.
|
|
@ -0,0 +1,129 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
www.cs.sandia.gov/~sjplimp/lammps.html
|
||||
Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* libwrapper = fortran wrappers for LAMMPS library functions.
|
||||
See README for compilation instructions */
|
||||
|
||||
#include "mpi.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "stdint.h"
|
||||
#include "library.h" /* this is a LAMMPS include file */
|
||||
|
||||
/* wrapper for creating a lammps instance from fortran.
|
||||
since fortran has no simple way to emit a c-compatible
|
||||
argument array, we don't support it. for simplicity,
|
||||
the address of the pointer to the lammps object is
|
||||
stored in a 64-bit integer on all platforms. */
|
||||
|
||||
void lammps_open_(MPI_Fint *comm, int64_t *ptr)
|
||||
{
|
||||
void *obj;
|
||||
MPI_Comm ccomm;
|
||||
|
||||
/* convert MPI communicator from fortran to c */
|
||||
ccomm = MPI_Comm_f2c(*comm);
|
||||
|
||||
lammps_open(0,NULL,ccomm,&obj);
|
||||
*ptr = (int64_t) obj;
|
||||
}
|
||||
|
||||
/* no-MPI version of the wrapper from above. */
|
||||
|
||||
void lammps_open_no_mpi_(int64_t *ptr)
|
||||
{
|
||||
void *obj;
|
||||
|
||||
lammps_open_no_mpi(0,NULL,&obj);
|
||||
*ptr = (int64_t) obj;
|
||||
}
|
||||
|
||||
/* wrapper for shutting down a lammps instance from fortran. */
|
||||
|
||||
void lammps_close_(int64_t *ptr)
|
||||
{
|
||||
void *obj;
|
||||
obj = (void *) *ptr;
|
||||
|
||||
lammps_close(obj);
|
||||
}
|
||||
|
||||
/* wrapper for passing an input file to lammps from fortran.
|
||||
since fortran strings are not zero terminated, we have
|
||||
to pass the length explicitly and make a copy that is. */
|
||||
|
||||
void lammps_file_(int64_t *ptr, char *fname, MPI_Fint *len)
|
||||
{
|
||||
void *obj;
|
||||
char *cpy;
|
||||
|
||||
obj = (void *) *ptr;
|
||||
|
||||
cpy = (char *)calloc(*len + 1,sizeof(char));
|
||||
memcpy(cpy,fname,*len);
|
||||
|
||||
lammps_file(obj,cpy);
|
||||
free(cpy);
|
||||
}
|
||||
|
||||
/* wrapper for passing a line input to lammps from fortran.
|
||||
since fortran strings are not zero terminated, we have
|
||||
to pass the length explicitly and make a copy that is. */
|
||||
|
||||
void lammps_command_(int64_t *ptr, char *line, MPI_Fint *len)
|
||||
{
|
||||
void *obj;
|
||||
char *cpy;
|
||||
|
||||
obj = (void *) *ptr;
|
||||
|
||||
cpy = (char *)calloc(*len + 1,sizeof(char));
|
||||
memcpy(cpy,line,*len);
|
||||
|
||||
lammps_command(obj,cpy);
|
||||
free(cpy);
|
||||
}
|
||||
|
||||
/* fortran wrapper to get the number of atoms from lammps.
|
||||
return values require an interface in fortran, so we
|
||||
make the wrapper into a procedure. */
|
||||
|
||||
void lammps_get_natoms_(int64_t *ptr, MPI_Fint *natoms)
|
||||
{
|
||||
void *obj;
|
||||
obj = (void *) *ptr;
|
||||
|
||||
*natoms = lammps_get_natoms(obj);
|
||||
}
|
||||
|
||||
/* wrapper to copy coordinates from lammps to fortran */
|
||||
|
||||
void lammps_get_coords_(int64_t *ptr, double *coords)
|
||||
{
|
||||
void *obj;
|
||||
obj = (void *) *ptr;
|
||||
|
||||
lammps_get_coords(obj,coords);
|
||||
}
|
||||
|
||||
/* wrapper to copy coordinates from fortran to lammps */
|
||||
|
||||
void lammps_put_coords_(int64_t *ptr, double *coords)
|
||||
{
|
||||
void *obj;
|
||||
obj = (void *) *ptr;
|
||||
|
||||
lammps_put_coords(obj,coords);
|
||||
}
|
||||
|
Loading…
Reference in New Issue