Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91894230
libfwrapper.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 15, 13:10
Size
3 KB
Mime Type
text/x-c
Expires
Sun, Nov 17, 13:10 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22338509
Attached To
rLAMMPS lammps
libfwrapper.c
View Options
/* ----------------------------------------------------------------------
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 "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "stdint.h"
#include "mpi.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);
}
Event Timeline
Log In to Comment