git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@3009 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2009-08-06 22:21:38 +00:00
parent f3ddb773fd
commit 6fbcee59ee
9 changed files with 134 additions and 28 deletions

View File

@ -1369,6 +1369,27 @@ void Atom::update_callback(int ifix)
if (extra_restart[i] > ifix) extra_restart[i]--;
}
/* ----------------------------------------------------------------------
return a pointer to a named internal variable
if don't recognize name, return NULL
------------------------------------------------------------------------- */
void *Atom::extract(char *name)
{
if (strcmp(name,"natoms") == 0) return (void *) &natoms;
if (strcmp(name,"nlocal") == 0) return (void *) &nlocal;
if (strcmp(name,"id") == 0) return (void *) tag;
if (strcmp(name,"type") == 0) return (void *) type;
if (strcmp(name,"x") == 0) return (void *) x;
if (strcmp(name,"v") == 0) return (void *) v;
if (strcmp(name,"f") == 0) return (void *) f;
if (strcmp(name,"mass") == 0) return (void *) mass;
if (strcmp(name,"rmass") == 0) return (void *) rmass;
return NULL;
}
/* ----------------------------------------------------------------------
return # of bytes of allocated memory
call to avec sums per-atom vectors

View File

@ -146,6 +146,8 @@ class Atom : protected Pointers {
void delete_callback(const char *, int);
void update_callback(int);
void *extract(char *);
double memory_usage();
int memcheck(const char *);

View File

@ -90,6 +90,7 @@ class Compute : protected Pointers {
int matchstep(int);
void clearstep();
virtual void *extract(char *) {return NULL;}
virtual double memory_usage() {return 0.0;}
protected:

View File

@ -126,6 +126,7 @@ class Fix : protected Pointers {
virtual int modify_param(int, char **) {return 0;}
virtual void *extract(char *) {return NULL;}
virtual double memory_usage() {return 0.0;}
protected:

View File

@ -15,10 +15,14 @@
// new LAMMPS-specific functions can be added
#include "mpi.h"
#include "string.h"
#include "library.h"
#include "lammps.h"
#include "input.h"
#include "atom.h"
#include "update.h"
#include "domain.h"
#include "modify.h"
using namespace LAMMPS_NS;
@ -29,8 +33,8 @@ using namespace LAMMPS_NS;
void lammps_open(int argc, char **argv, MPI_Comm communicator, void **ptr)
{
LAMMPS *lammps = new LAMMPS(argc,argv,communicator);
*ptr = (void *) lammps;
LAMMPS *lmp = new LAMMPS(argc,argv,communicator);
*ptr = (void *) lmp;
}
/* ----------------------------------------------------------------------
@ -39,8 +43,8 @@ void lammps_open(int argc, char **argv, MPI_Comm communicator, void **ptr)
void lammps_close(void *ptr)
{
LAMMPS *lammps = (LAMMPS *) ptr;
delete lammps;
LAMMPS *lmp = (LAMMPS *) ptr;
delete lmp;
}
/* ----------------------------------------------------------------------
@ -49,8 +53,8 @@ void lammps_close(void *ptr)
void lammps_file(void *ptr, char *str)
{
LAMMPS *lammps = (LAMMPS *) ptr;
lammps->input->file(str);
LAMMPS *lmp = (LAMMPS *) ptr;
lmp->input->file(str);
}
/* ----------------------------------------------------------------------
@ -59,8 +63,8 @@ void lammps_file(void *ptr, char *str)
char *lammps_command(void *ptr, char *str)
{
LAMMPS *lammps = (LAMMPS *) ptr;
return lammps->input->one(str);
LAMMPS *lmp = (LAMMPS *) ptr;
return lmp->input->one(str);
}
/* ----------------------------------------------------------------------
@ -68,12 +72,43 @@ char *lammps_command(void *ptr, char *str)
all must receive LAMMPS pointer as argument
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
extract a pointer to an internal LAMMPS value or data structure
category: 0 = general, 1 = fix, 2 = compute
id = ID of fix or compute (else not used)
name = desired quantity, e.g. x or dt
returns a void pointer which the caller can cast to the desired data type
returns a NULL if LAMMPS does not recognize the name
------------------------------------------------------------------------- */
void *lammps_extract(void *ptr, int category, char *id, char *name)
{
LAMMPS *lmp = (LAMMPS *) ptr;
if (category == 0) {
if (strcmp(name,"dt") == 0) return (void *) &lmp->update->dt;
if (strcmp(name,"boxxlo") == 0) return (void *) &lmp->domain->boxlo[0];
if (strcmp(name,"boxxhi") == 0) return (void *) &lmp->domain->boxhi[0];
if (strcmp(name,"boxylo") == 0) return (void *) &lmp->domain->boxlo[1];
if (strcmp(name,"boxyhi") == 0) return (void *) &lmp->domain->boxhi[1];
if (strcmp(name,"boxzlo") == 0) return (void *) &lmp->domain->boxlo[2];
if (strcmp(name,"boxzhi") == 0) return (void *) &lmp->domain->boxhi[2];
return NULL;
}
if (category == 1) return lmp->atom->extract(name);
if (category == 2) return lmp->modify->extract_fix(id,name);
if (category == 3) return lmp->modify->extract_compute(id,name);
return NULL;
}
/* ---------------------------------------------------------------------- */
int lammps_get_natoms(void *ptr)
{
LAMMPS *lammps = (LAMMPS *) ptr;
int natoms = static_cast<int> (lammps->atom->natoms);
LAMMPS *lmp = (LAMMPS *) ptr;
int natoms = static_cast<int> (lmp->atom->natoms);
return natoms;
}
@ -81,14 +116,14 @@ int lammps_get_natoms(void *ptr)
void lammps_get_coords(void *ptr, double *coords)
{
LAMMPS *lammps = (LAMMPS *) ptr;
int natoms = static_cast<int> (lammps->atom->natoms);
LAMMPS *lmp = (LAMMPS *) ptr;
int natoms = static_cast<int> (lmp->atom->natoms);
double *copy = new double[3*natoms];
for (int i = 0; i < 3*natoms; i++) copy[i] = 0.0;
double **x = lammps->atom->x;
int *tag = lammps->atom->tag;
int nlocal = lammps->atom->nlocal;
double **x = lmp->atom->x;
int *tag = lmp->atom->tag;
int nlocal = lmp->atom->nlocal;
int id,offset;
for (int i = 0; i < nlocal; i++) {
@ -99,7 +134,7 @@ void lammps_get_coords(void *ptr, double *coords)
copy[offset+2] = x[i][2];
}
MPI_Allreduce(copy,coords,3*natoms,MPI_DOUBLE,MPI_SUM,lammps->world);
MPI_Allreduce(copy,coords,3*natoms,MPI_DOUBLE,MPI_SUM,lmp->world);
delete [] copy;
}
@ -107,14 +142,14 @@ void lammps_get_coords(void *ptr, double *coords)
void lammps_put_coords(void *ptr, double *coords)
{
LAMMPS *lammps = (LAMMPS *) ptr;
int natoms = static_cast<int> (lammps->atom->natoms);
LAMMPS *lmp = (LAMMPS *) ptr;
int natoms = static_cast<int> (lmp->atom->natoms);
double **x = lammps->atom->x;
double **x = lmp->atom->x;
int m,offset;
for (int i = 0; i < natoms; i++) {
if ((m = lammps->atom->map(i+1)) >= 0) {
if ((m = lmp->atom->map(i+1)) >= 0) {
offset = 3*i;
x[m][0] = coords[offset+0];
x[m][1] = coords[offset+1];

View File

@ -24,14 +24,15 @@
extern "C" {
#endif
void lammps_open(int, char **, MPI_Comm, void **); /* start-up LAMMPS */
void lammps_close(void *); /* shut-down LAMMPS */
void lammps_file(void *, char *); /* run an input script */
char *lammps_command(void *, char *); /* execute a command */
void lammps_open(int, char **, MPI_Comm, void **);
void lammps_close(void *);
void lammps_file(void *, char *);
char *lammps_command(void *, char *);
int lammps_get_natoms(void *); /* return # of atoms */
void lammps_get_coords(void *, double *); /* get atom x from all procs */
void lammps_put_coords(void *, double *); /* put atom x on all procs */
void *lammps_extract(void *, int, char *, char *);
int lammps_get_natoms(void *);
void lammps_get_coords(void *, double *);
void lammps_put_coords(void *, double *);
#ifdef __cplusplus
}

View File

@ -56,7 +56,11 @@ void Memory::sfree(void *ptr)
void *Memory::srealloc(void *ptr, int n, const char *name)
{
if (n == 0) return NULL;
if (n == 0) {
sfree(ptr);
return NULL;
}
ptr = realloc(ptr,n);
if (ptr == NULL) {
char str[128];

View File

@ -996,6 +996,42 @@ void Modify::list_init_compute()
if (compute[i]->timeflag) list_timeflag[n_timeflag++] = i;
}
/* ----------------------------------------------------------------------
return a pointer to a named internal variable owned by fix ID
if don't recognize ID, return NULL
------------------------------------------------------------------------- */
void *Modify::extract_fix(char *id, char *name)
{
int ifix = find_fix(id);
if (ifix < 0) return NULL;
if (strcmp(name,"index") == 0) {
index_permanent = ifix;
return (void *) &index_permanent;
}
return fix[ifix]->extract(name);
}
/* ----------------------------------------------------------------------
return a pointer to a named internal variable owned by compute ID
if don't recognize ID, return NULL
------------------------------------------------------------------------- */
void *Modify::extract_compute(char *id, char *name)
{
int icompute = find_compute(id);
if (icompute < 0) return NULL;
if (strcmp(name,"index") == 0) {
index_permanent = icompute;
return (void *) &index_permanent;
}
return compute[icompute]->extract(name);
}
/* ----------------------------------------------------------------------
return # of bytes of allocated memory from all fixes
------------------------------------------------------------------------- */

View File

@ -83,6 +83,9 @@ class Modify : protected Pointers {
int read_restart(FILE *);
void restart_deallocate();
void *extract_fix(char *, char *);
void *extract_compute(char *, char *);
double memory_usage();
private:
@ -111,6 +114,8 @@ class Modify : protected Pointers {
char **style_restart_peratom;
int *index_restart_peratom;
int index_permanent; // fix/compute index returned to library call
void list_init(int, int &, int *&);
void list_init_end_of_step(int, int &, int *&);
void list_init_thermo_energy(int, int &, int *&);