forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8626 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
9b2440a0ab
commit
6304a8c9bf
|
@ -28,7 +28,7 @@ SHLIBFLAGS = -shared
|
||||||
# LAMMPS ifdef settings, OPTIONAL
|
# LAMMPS ifdef settings, OPTIONAL
|
||||||
# see possible settings in doc/Section_start.html#2_2 (step 4)
|
# see possible settings in doc/Section_start.html#2_2 (step 4)
|
||||||
|
|
||||||
LMP_INC = -DLAMMPS_GZIP -DLAMMPS_JPEG
|
LMP_INC = -DLAMMPS_GZIP #-DLAMMPS_JPEG
|
||||||
|
|
||||||
# MPI library, REQUIRED
|
# MPI library, REQUIRED
|
||||||
# see discussion in doc/Section_start.html#2_2 (step 5)
|
# see discussion in doc/Section_start.html#2_2 (step 5)
|
||||||
|
|
13
src/atom.cpp
13
src/atom.cpp
|
@ -1384,14 +1384,25 @@ void Atom::update_callback(int ifix)
|
||||||
|
|
||||||
void *Atom::extract(char *name)
|
void *Atom::extract(char *name)
|
||||||
{
|
{
|
||||||
|
if (strcmp(name,"mass") == 0) return (void *) mass;
|
||||||
|
|
||||||
if (strcmp(name,"id") == 0) return (void *) tag;
|
if (strcmp(name,"id") == 0) return (void *) tag;
|
||||||
if (strcmp(name,"type") == 0) return (void *) type;
|
if (strcmp(name,"type") == 0) return (void *) type;
|
||||||
if (strcmp(name,"mask") == 0) return (void *) mask;
|
if (strcmp(name,"mask") == 0) return (void *) mask;
|
||||||
|
if (strcmp(name,"image") == 0) return (void *) image;
|
||||||
if (strcmp(name,"x") == 0) return (void *) x;
|
if (strcmp(name,"x") == 0) return (void *) x;
|
||||||
if (strcmp(name,"v") == 0) return (void *) v;
|
if (strcmp(name,"v") == 0) return (void *) v;
|
||||||
if (strcmp(name,"f") == 0) return (void *) f;
|
if (strcmp(name,"f") == 0) return (void *) f;
|
||||||
if (strcmp(name,"mass") == 0) return (void *) mass;
|
if (strcmp(name,"molecule") == 0) return (void *) molecule;
|
||||||
|
if (strcmp(name,"q") == 0) return (void *) q;
|
||||||
|
if (strcmp(name,"mu") == 0) return (void *) mu;
|
||||||
|
if (strcmp(name,"omega") == 0) return (void *) omega;
|
||||||
|
if (strcmp(name,"amgmom") == 0) return (void *) angmom;
|
||||||
|
if (strcmp(name,"torque") == 0) return (void *) torque;
|
||||||
|
if (strcmp(name,"radius") == 0) return (void *) radius;
|
||||||
if (strcmp(name,"rmass") == 0) return (void *) rmass;
|
if (strcmp(name,"rmass") == 0) return (void *) rmass;
|
||||||
|
if (strcmp(name,"vfrac") == 0) return (void *) vfrac;
|
||||||
|
if (strcmp(name,"s0") == 0) return (void *) s0;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
181
src/library.cpp
181
src/library.cpp
|
@ -30,6 +30,7 @@
|
||||||
#include "modify.h"
|
#include "modify.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
#include "fix.h"
|
#include "fix.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
|
@ -157,6 +158,14 @@ void *lammps_extract_atom(void *ptr, char *name)
|
||||||
id = compute ID
|
id = compute ID
|
||||||
style = 0 for global data, 1 for per-atom data, 2 for local data
|
style = 0 for global data, 1 for per-atom data, 2 for local data
|
||||||
type = 0 for scalar, 1 for vector, 2 for array
|
type = 0 for scalar, 1 for vector, 2 for array
|
||||||
|
for global data, returns a pointer to the
|
||||||
|
compute's internal data structure for the entity
|
||||||
|
caller should cast it to (double *) for a scalar or vector
|
||||||
|
caller should cast it to (double **) for an array
|
||||||
|
for per-atom or local data, returns a pointer to the
|
||||||
|
compute's internal data structure for the entity
|
||||||
|
caller should cast it to (double *) for a vector
|
||||||
|
caller should cast it to (double **) for an array
|
||||||
returns a void pointer to the compute's internal data structure
|
returns a void pointer to the compute's internal data structure
|
||||||
for the entity which the caller can cast to the proper data type
|
for the entity which the caller can cast to the proper data type
|
||||||
returns a NULL if id is not recognized or style/type not supported
|
returns a NULL if id is not recognized or style/type not supported
|
||||||
|
@ -236,7 +245,8 @@ void *lammps_extract_compute(void *ptr, char *id, int style, int type)
|
||||||
which the caller can cast to a (double *) which points to the value
|
which the caller can cast to a (double *) which points to the value
|
||||||
for per-atom or local data, returns a pointer to the
|
for per-atom or local data, returns a pointer to the
|
||||||
fix's internal data structure for the entity
|
fix's internal data structure for the entity
|
||||||
which the caller can cast to the proper data type
|
caller should cast it to (double *) for a vector
|
||||||
|
caller should cast it to (double **) for an array
|
||||||
returns a NULL if id is not recognized or style/type not supported
|
returns a NULL if id is not recognized or style/type not supported
|
||||||
IMPORTANT: for global data,
|
IMPORTANT: for global data,
|
||||||
this function allocates a double to store the value in,
|
this function allocates a double to store the value in,
|
||||||
|
@ -300,7 +310,7 @@ void *lammps_extract_fix(void *ptr, char *id, int style, int type,
|
||||||
which the caller can cast to a (double *) which points to the value
|
which the caller can cast to a (double *) which points to the value
|
||||||
for atom-style variable, returns a pointer to the
|
for atom-style variable, returns a pointer to the
|
||||||
vector of per-atom values on each processor,
|
vector of per-atom values on each processor,
|
||||||
which the caller can cast to the proper data type
|
which the caller can cast to a (double *) which points to the values
|
||||||
returns a NULL if name is not recognized or not equal-style or atom-style
|
returns a NULL if name is not recognized or not equal-style or atom-style
|
||||||
IMPORTANT: for both equal-style and atom-style variables,
|
IMPORTANT: for both equal-style and atom-style variables,
|
||||||
this function allocates memory to store the variable data in
|
this function allocates memory to store the variable data in
|
||||||
|
@ -343,7 +353,10 @@ void *lammps_extract_variable(void *ptr, char *name, char *group)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------
|
||||||
|
return the total number of atoms in the system
|
||||||
|
useful before call to lammps_get_atoms() so can pre-allocate vector
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int lammps_get_natoms(void *ptr)
|
int lammps_get_natoms(void *ptr)
|
||||||
{
|
{
|
||||||
|
@ -353,9 +366,18 @@ int lammps_get_natoms(void *ptr)
|
||||||
return natoms;
|
return natoms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------
|
||||||
|
gather the named atom-based entity across all processors
|
||||||
|
name = desired quantity, e.g. x or charge
|
||||||
|
type = 0 for integer values, 1 for double values
|
||||||
|
count = # of per-atom values, e.g. 1 for type or charge, 3 for x or f
|
||||||
|
return atom-based values in data, ordered by count, then by atom ID
|
||||||
|
e.g. x[0][0],x[0][1],x[0][2],x[1][0],x[1][1],x[1][2],x[2][0],...
|
||||||
|
data must be allocated by caller to correct length
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void lammps_get_coords(void *ptr, double *coords)
|
void lammps_gather_atoms(void *ptr, char *name,
|
||||||
|
int type, int count, void *data)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||||
|
|
||||||
|
@ -365,47 +387,142 @@ void lammps_get_coords(void *ptr, double *coords)
|
||||||
if (lmp->atom->natoms > MAXSMALLINT) return;
|
if (lmp->atom->natoms > MAXSMALLINT) return;
|
||||||
|
|
||||||
int natoms = static_cast<int> (lmp->atom->natoms);
|
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 = lmp->atom->x;
|
int i,j,offset;
|
||||||
int *tag = lmp->atom->tag;
|
|
||||||
int nlocal = lmp->atom->nlocal;
|
|
||||||
|
|
||||||
int id,offset;
|
// copy = Natom length vector of per-atom values
|
||||||
for (int i = 0; i < nlocal; i++) {
|
// use atom ID to insert each atom's values into copy
|
||||||
id = tag[i];
|
// MPI_Allreduce with MPI_SUM to merge into data, ordered by atom ID
|
||||||
offset = 3*(id-1);
|
|
||||||
copy[offset+0] = x[i][0];
|
if (type == 0) {
|
||||||
copy[offset+1] = x[i][1];
|
void *vptr = lmp->atom->extract(name);
|
||||||
copy[offset+2] = x[i][2];
|
int *vector;
|
||||||
|
int **array;
|
||||||
|
if (count == 1) vector = (int *) vptr;
|
||||||
|
else array = (int **) vptr;
|
||||||
|
|
||||||
|
int *copy;
|
||||||
|
lmp->memory->create(copy,count*natoms,"lib/gather:copy");
|
||||||
|
for (i = 0; i < count*natoms; i++) copy[i] = 0;
|
||||||
|
|
||||||
|
int *tag = lmp->atom->tag;
|
||||||
|
int nlocal = lmp->atom->nlocal;
|
||||||
|
|
||||||
|
if (count == 1)
|
||||||
|
for (i = 0; i < nlocal; i++)
|
||||||
|
copy[tag[i]-1] = vector[i];
|
||||||
|
else
|
||||||
|
for (i = 0; i < nlocal; i++) {
|
||||||
|
offset = count*(tag[i]-1);
|
||||||
|
for (j = 0; j < count; j++)
|
||||||
|
copy[offset++] = array[i][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Allreduce(copy,data,count*natoms,MPI_INT,MPI_SUM,lmp->world);
|
||||||
|
lmp->memory->destroy(copy);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
void *vptr = lmp->atom->extract(name);
|
||||||
|
double *vector;
|
||||||
|
double **array;
|
||||||
|
if (count == 1) vector = (double *) vptr;
|
||||||
|
else array = (double **) vptr;
|
||||||
|
|
||||||
|
double *copy;
|
||||||
|
lmp->memory->create(copy,count*natoms,"lib/gather:copy");
|
||||||
|
for (i = 0; i < count*natoms; i++) copy[i] = 0.0;
|
||||||
|
|
||||||
|
int *tag = lmp->atom->tag;
|
||||||
|
int nlocal = lmp->atom->nlocal;
|
||||||
|
|
||||||
|
if (count == 1) {
|
||||||
|
for (i = 0; i < nlocal; i++)
|
||||||
|
copy[tag[i]-1] = vector[i];
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < nlocal; i++) {
|
||||||
|
offset = count*(tag[i]-1);
|
||||||
|
for (j = 0; j < count; j++)
|
||||||
|
copy[offset++] = array[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Allreduce(copy,data,count*natoms,MPI_DOUBLE,MPI_SUM,lmp->world);
|
||||||
|
lmp->memory->destroy(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Allreduce(copy,coords,3*natoms,MPI_DOUBLE,MPI_SUM,lmp->world);
|
|
||||||
delete [] copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void lammps_put_coords(void *ptr, double *coords)
|
/* ----------------------------------------------------------------------
|
||||||
|
gather the named atom-based entity across all processors
|
||||||
|
name = desired quantity, e.g. x or charge
|
||||||
|
type = 0 for integer values, 1 for double values
|
||||||
|
count = # of per-atom values, e.g. 1 for type or charge, 3 for x or f
|
||||||
|
return atom-based values in data, ordered by count, then by atom ID
|
||||||
|
e.g. x[0][0],x[0][1],x[0][2],x[1][0],x[1][1],x[1][2],x[2][0],...
|
||||||
|
data must be allocated by caller to correct length
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void lammps_scatter_atoms(void *ptr, char *name,
|
||||||
|
int type, int count, void *data)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||||
|
|
||||||
// error if no map defined by LAMMPS
|
// error if tags are not defined or not consecutive
|
||||||
|
|
||||||
if (lmp->atom->map_style == 0) return;
|
if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) return;
|
||||||
if (lmp->atom->natoms > MAXSMALLINT) return;
|
if (lmp->atom->natoms > MAXSMALLINT) return;
|
||||||
|
|
||||||
int natoms = static_cast<int> (lmp->atom->natoms);
|
int natoms = static_cast<int> (lmp->atom->natoms);
|
||||||
double **x = lmp->atom->x;
|
|
||||||
|
|
||||||
int m,offset;
|
int i,j,m,offset;
|
||||||
for (int i = 0; i < natoms; i++) {
|
|
||||||
if ((m = lmp->atom->map(i+1)) >= 0) {
|
// copy = Natom length vector of per-atom values
|
||||||
offset = 3*i;
|
// use atom ID to insert each atom's values into copy
|
||||||
x[m][0] = coords[offset+0];
|
// MPI_Allreduce with MPI_SUM to merge into data, ordered by atom ID
|
||||||
x[m][1] = coords[offset+1];
|
|
||||||
x[m][2] = coords[offset+2];
|
if (type == 0) {
|
||||||
|
void *vptr = lmp->atom->extract(name);
|
||||||
|
int *vector;
|
||||||
|
int **array;
|
||||||
|
if (count == 1) vector = (int *) vptr;
|
||||||
|
else array = (int **) vptr;
|
||||||
|
int *dptr = (int *) data;
|
||||||
|
|
||||||
|
if (count == 1)
|
||||||
|
for (i = 0; i < natoms; i++)
|
||||||
|
if ((m = lmp->atom->map(i+1)) >= 0)
|
||||||
|
vector[m] = dptr[i];
|
||||||
|
else
|
||||||
|
for (i = 0; i < natoms; i++)
|
||||||
|
if ((m = lmp->atom->map(i+1)) >= 0) {
|
||||||
|
offset = count*i;
|
||||||
|
for (j = 0; j < count; j++)
|
||||||
|
array[m][j] = dptr[offset++];
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
void *vptr = lmp->atom->extract(name);
|
||||||
|
double *vector;
|
||||||
|
double **array;
|
||||||
|
if (count == 1) vector = (double *) vptr;
|
||||||
|
else array = (double **) vptr;
|
||||||
|
double *dptr = (double *) data;
|
||||||
|
|
||||||
|
int *tag = lmp->atom->tag;
|
||||||
|
int nlocal = lmp->atom->nlocal;
|
||||||
|
|
||||||
|
if (count == 1) {
|
||||||
|
for (i = 0; i < natoms; i++)
|
||||||
|
if ((m = lmp->atom->map(i+1)) >= 0)
|
||||||
|
vector[m] = dptr[i];
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < natoms; i++) {
|
||||||
|
if ((m = lmp->atom->map(i+1)) >= 0) {
|
||||||
|
offset = count*i;
|
||||||
|
for (j = 0; j < count; j++)
|
||||||
|
array[m][j] = dptr[offset++];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,13 @@ void *lammps_extract_fix(void *, char *, int, int, int, int);
|
||||||
void *lammps_extract_variable(void *, char *, char *);
|
void *lammps_extract_variable(void *, char *, char *);
|
||||||
|
|
||||||
int lammps_get_natoms(void *);
|
int lammps_get_natoms(void *);
|
||||||
void lammps_get_coords(void *, double *);
|
void lammps_gather_atoms(void *, char *, int, int, void *);
|
||||||
void lammps_put_coords(void *, double *);
|
void lammps_scatter_atoms(void *, char *, int, int, void *);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ERROR/WARNING messages:
|
/* ERROR/WARNING messages:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue