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

This commit is contained in:
sjplimp
2007-01-30 00:22:05 +00:00
parent 9cdbeaf9f2
commit 209f169cbc
414 changed files with 6935 additions and 10462 deletions

View File

@ -1,7 +1,7 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
www.cs.sandia.gov/~sjplimp/lammps.html
Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
@ -15,7 +15,8 @@
#include "string.h"
#include "replicate.h"
#include "atom.h"
#include "atom_atomic.h"
#include "atom_vec.h"
#include "atom_vec_hybrid.h"
#include "force.h"
#include "domain.h"
#include "comm.h"
@ -23,9 +24,7 @@
#include "memory.h"
#include "error.h"
#define AtomInclude
#include "style.h"
#undef AtomInclude
using namespace LAMMPS_NS;
#define LB_FACTOR 1.1
#define MAXATOMS 0x7FFFFFFF
@ -35,6 +34,10 @@
/* ---------------------------------------------------------------------- */
Replicate::Replicate(LAMMPS *lmp) : Pointers(lmp) {}
/* ---------------------------------------------------------------------- */
void Replicate::command(int narg, char **arg)
{
int i,j,m,n;
@ -90,28 +93,34 @@ void Replicate::command(int narg, char **arg)
for (i = 0; i < atom->nlocal; i++)
domain->unmap(atom->x[i][0],atom->x[i][1],atom->x[i][2],atom->image[i]);
// nwords, words = list of atom style keywords
// communication buffer for all my atom's info
// max_size = largest buffer needed by any proc
// must do before new Atom class created,
// since size_restart() uses atom->nlocal
int max_size;
int send_size = atom->avec->size_restart();
MPI_Allreduce(&send_size,&max_size,1,MPI_INT,MPI_MAX,world);
double *buf =
(double *) memory->smalloc(max_size*sizeof(double),"replicate:buf");
// old = original atom class
// atom = new replicated atom class
char **words;
int nwords = atom->style2arg(words);
// if old atom style was hybrid, pass sub-style names to create_avec
Atom *old = atom;
if (0) return; // dummy line to enable else-if macro expansion
atom = new Atom(lmp);
#define AtomClass
#define AtomStyle(key,Class) \
else if (strcmp(old->style,#key) == 0) atom = new Class(nwords,words);
#include "style.h"
#undef AtomClass
atom->settings(old);
for (i = 0; i < nwords; i++) delete [] words[i];
delete [] words;
int nstyles = 0;
char **keywords = NULL;
if (strcmp(old->atom_style,"hybrid") == 0) {
AtomVecHybrid *avec_hybrid = (AtomVecHybrid *) old->avec;
nstyles = avec_hybrid->nstyles;
keywords = avec_hybrid->keywords;
}
atom->create_avec(old->atom_style,nstyles,keywords);
// check that new problem size will not be too large
// if N > 2^31, turn off tags
@ -148,15 +157,15 @@ void Replicate::command(int narg, char **arg)
// store old simulation box
double oldxprd = domain->xprd;
double oldyprd = domain->yprd;
double oldzprd = domain->zprd;
double old_xprd = domain->xprd;
double old_yprd = domain->yprd;
double old_zprd = domain->zprd;
// setup new simulation box
domain->boxxhi = domain->boxxlo + nx*oldxprd;
domain->boxyhi = domain->boxylo + ny*oldyprd;
domain->boxzhi = domain->boxzlo + nz*oldzprd;
domain->boxxhi = domain->boxxlo + nx*old_xprd;
domain->boxyhi = domain->boxylo + ny*old_yprd;
domain->boxzhi = domain->boxzlo + nz*old_zprd;
// new problem setup using new box boundaries
@ -164,7 +173,7 @@ void Replicate::command(int narg, char **arg)
else n = static_cast<int> (LB_FACTOR * atom->natoms / nprocs);
atom->allocate_type_arrays();
atom->grow(n);
atom->avec->grow(n);
domain->set_initial_box();
domain->set_global_box();
@ -182,14 +191,14 @@ void Replicate::command(int narg, char **arg)
// copy type arrays to new atom class
if (atom->mass_require) {
if (atom->mass) {
for (int itype = 1; itype <= atom->ntypes; itype++) {
atom->mass_setflag[itype] = old->mass_setflag[itype];
if (atom->mass_setflag[itype]) atom->mass[itype] = old->mass[itype];
}
}
if (atom->dipole_require) {
if (atom->dipole) {
for (int itype = 1; itype <= atom->ntypes; itype++) {
atom->dipole_setflag[itype] = old->dipole_setflag[itype];
if (atom->dipole_setflag[itype])
@ -197,16 +206,6 @@ void Replicate::command(int narg, char **arg)
}
}
// communication buffer for all my atom's info
// max_size = largest buffer needed by any proc
int max_size;
int send_size = old->size_restart();
MPI_Allreduce(&send_size,&max_size,1,MPI_INT,MPI_MAX,world);
double *buf;
buf = (double *) memory->smalloc(max_size*sizeof(double),"replicate:buf");
// loop over all procs
// if this iteration of loop is me:
// pack my unmapped atom data into buf
@ -216,6 +215,9 @@ void Replicate::command(int narg, char **arg)
// unpack atom into new atom class from buf if I own it
// adjust tag, mol #, coord, topology info as needed
AtomVec *old_avec = old->avec;
AtomVec *avec = atom->avec;
int ix,iy,iz,image,atom_offset,mol_offset;
double xnew,ynew,znew;
int tag_enable = atom->tag_enable;
@ -223,7 +225,7 @@ void Replicate::command(int narg, char **arg)
for (int iproc = 0; iproc < nprocs; iproc++) {
if (me == iproc) {
n = 0;
for (i = 0; i < old->nlocal; i++) n += old->pack_restart(i,&buf[n]);
for (i = 0; i < old->nlocal; i++) n += old_avec->pack_restart(i,&buf[n]);
}
MPI_Bcast(&n,1,MPI_INT,iproc,world);
MPI_Bcast(buf,n,MPI_DOUBLE,iproc,world);
@ -234,9 +236,9 @@ void Replicate::command(int narg, char **arg)
m = 0;
while (m < n) {
xnew = buf[m+1] + ix*oldxprd;
ynew = buf[m+2] + iy*oldyprd;
znew = buf[m+3] + iz*oldzprd;
xnew = buf[m+1] + ix*old_xprd;
ynew = buf[m+2] + iy*old_yprd;
znew = buf[m+3] + iz*old_zprd;
image = (512 << 20) | (512 << 10) | 512;
domain->remap(xnew,ynew,znew,image);
@ -244,7 +246,7 @@ void Replicate::command(int narg, char **arg)
ynew >= subylo && ynew < subyhi &&
znew >= subzlo && znew < subzhi) {
m += atom->unpack_restart(&buf[m]);
m += avec->unpack_restart(&buf[m]);
i = atom->nlocal - 1;
if (tag_enable)
@ -262,23 +264,23 @@ void Replicate::command(int narg, char **arg)
if (atom->molecular) {
if (atom->molecule[i] > 0)
atom->molecule[i] += mol_offset;
if (atom->bonds_allow)
if (atom->avec->bonds_allow)
for (j = 0; j < atom->num_bond[i]; j++)
atom->bond_atom[i][j] += atom_offset;
if (atom->angles_allow)
if (atom->avec->angles_allow)
for (j = 0; j < atom->num_angle[i]; j++) {
atom->angle_atom1[i][j] += atom_offset;
atom->angle_atom2[i][j] += atom_offset;
atom->angle_atom3[i][j] += atom_offset;
}
if (atom->dihedrals_allow)
if (atom->avec->dihedrals_allow)
for (j = 0; j < atom->num_dihedral[i]; j++) {
atom->dihedral_atom1[i][j] += atom_offset;
atom->dihedral_atom2[i][j] += atom_offset;
atom->dihedral_atom3[i][j] += atom_offset;
atom->dihedral_atom4[i][j] += atom_offset;
}
if (atom->impropers_allow)
if (atom->avec->impropers_allow)
for (j = 0; j < atom->num_improper[i]; j++) {
atom->improper_atom1[i][j] += atom_offset;
atom->improper_atom2[i][j] += atom_offset;
@ -339,7 +341,7 @@ void Replicate::command(int narg, char **arg)
atom->map_set();
}
if (atom->molecular) {
Special special;
Special special(lmp);
special.build();
}
}