From 5fdeeabba5282ba6d91e2832c7c587722a34acc3 Mon Sep 17 00:00:00 2001 From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa> Date: Fri, 9 Feb 2007 21:26:58 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@279 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/MOLECULE/atom_vec_full.cpp | 888 +++++++++++++++++++++++++++++++++ src/MOLECULE/atom_vec_full.h | 68 +++ 2 files changed, 956 insertions(+) create mode 100644 src/MOLECULE/atom_vec_full.cpp create mode 100644 src/MOLECULE/atom_vec_full.h diff --git a/src/MOLECULE/atom_vec_full.cpp b/src/MOLECULE/atom_vec_full.cpp new file mode 100644 index 0000000000..7de7dfb748 --- /dev/null +++ b/src/MOLECULE/atom_vec_full.cpp @@ -0,0 +1,888 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + 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 + 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. +------------------------------------------------------------------------- */ + +#include "stdlib.h" +#include "atom_vec_full.h" +#include "atom.h" +#include "domain.h" +#include "modify.h" +#include "fix.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +#define MIN(A,B) ((A) < (B)) ? (A) : (B) +#define MAX(A,B) ((A) > (B)) ? (A) : (B) + +#define DELTA 10000 + +/* ---------------------------------------------------------------------- */ + +AtomVecFull::AtomVecFull(LAMMPS *lmp, int narg, char **arg) : + AtomVec(lmp, narg, arg) +{ + molecular = 1; + bonds_allow = 1; + angles_allow = 1; + dihedrals_allow = 1; + impropers_allow = 1; + mass_type = 1; + size_comm = 3; + size_reverse = 3; + size_border = 8; + size_data_atom = 7; + size_data_vel = 4; + xcol_data = 5; +} + +/* ---------------------------------------------------------------------- + grow atom arrays + n = 0 grows arrays by DELTA + n > 0 allocates arrays to size n +------------------------------------------------------------------------- */ + +void AtomVecFull::grow(int n) +{ + if (n == 0) nmax += DELTA; + else nmax = n; + atom->nmax = nmax; + + tag = atom->tag = (int *) + memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); + type = atom->type = (int *) + memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); + mask = atom->mask = (int *) + memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); + image = atom->image = (int *) + memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); + x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); + v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); + f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); + + q = atom->q = (double *) + memory->srealloc(atom->q,nmax*sizeof(double),"atom:q"); + molecule = atom->molecule = (int *) + memory->srealloc(atom->molecule,nmax*sizeof(int),"atom:molecule"); + + nspecial = atom->nspecial = + memory->grow_2d_int_array(atom->nspecial,nmax,3,"atom:nspecial"); + special = atom->special = + memory->grow_2d_int_array(atom->special,nmax,atom->maxspecial, + "atom:special"); + + num_bond = atom->num_bond = (int *) + memory->srealloc(atom->num_bond,nmax*sizeof(int),"atom:num_bond"); + bond_type = atom->bond_type = + memory->grow_2d_int_array(atom->bond_type,nmax,atom->bond_per_atom, + "atom:bond_type"); + bond_atom = atom->bond_atom = + memory->grow_2d_int_array(atom->bond_atom,nmax,atom->bond_per_atom, + "atom:bond_atom"); + + num_angle = atom->num_angle = (int *) + memory->srealloc(atom->num_angle,nmax*sizeof(int),"atom:num_angle"); + angle_type = atom->angle_type = + memory->grow_2d_int_array(atom->angle_type,nmax,atom->angle_per_atom, + "atom:angle_type"); + angle_atom1 = atom->angle_atom1 = + memory->grow_2d_int_array(atom->angle_atom1,nmax,atom->angle_per_atom, + "atom:angle_atom1"); + angle_atom2 = atom->angle_atom2 = + memory->grow_2d_int_array(atom->angle_atom2,nmax,atom->angle_per_atom, + "atom:angle_atom2"); + angle_atom3 = atom->angle_atom3 = + memory->grow_2d_int_array(atom->angle_atom3,nmax,atom->angle_per_atom, + "atom:angle_atom3"); + + num_dihedral = atom->num_dihedral = (int *) + memory->srealloc(atom->num_dihedral,nmax*sizeof(int),"atom:num_dihedral"); + dihedral_type = atom->dihedral_type = + memory->grow_2d_int_array(atom->dihedral_type,nmax,atom->dihedral_per_atom, + "atom:dihedral_type"); + dihedral_atom1 = atom->dihedral_atom1 = + memory->grow_2d_int_array(atom->dihedral_atom1,nmax, + atom->dihedral_per_atom,"atom:dihedral_atom1"); + dihedral_atom2 = atom->dihedral_atom2 = + memory->grow_2d_int_array(atom->dihedral_atom2,nmax, + atom->dihedral_per_atom,"atom:dihedral_atom2"); + dihedral_atom3 = atom->dihedral_atom3 = + memory->grow_2d_int_array(atom->dihedral_atom3,nmax, + atom->dihedral_per_atom,"atom:dihedral_atom3"); + dihedral_atom4 = atom->dihedral_atom4 = + memory->grow_2d_int_array(atom->dihedral_atom4,nmax, + atom->dihedral_per_atom,"atom:dihedral_atom4"); + + num_improper = atom->num_improper = (int *) + memory->srealloc(atom->num_improper,nmax*sizeof(int),"atom:num_improper"); + improper_type = atom->improper_type = + memory->grow_2d_int_array(atom->improper_type,nmax,atom->improper_per_atom, + "atom:improper_type"); + improper_atom1 = atom->improper_atom1 = + memory->grow_2d_int_array(atom->improper_atom1,nmax, + atom->improper_per_atom,"atom:improper_atom1"); + improper_atom2 = atom->improper_atom2 = + memory->grow_2d_int_array(atom->improper_atom2,nmax, + atom->improper_per_atom,"atom:improper_atom2"); + improper_atom3 = atom->improper_atom3 = + memory->grow_2d_int_array(atom->improper_atom3,nmax, + atom->improper_per_atom,"atom:improper_atom3"); + improper_atom4 = atom->improper_atom4 = + memory->grow_2d_int_array(atom->improper_atom4,nmax, + atom->improper_per_atom,"atom:improper_atom4"); + + if (atom->nextra_grow) + for (int iextra = 0; iextra < atom->nextra_grow; iextra++) + modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax); +} + +/* ---------------------------------------------------------------------- */ + +void AtomVecFull::reset_ptrs() +{ + tag = atom->tag; + type = atom->type; + mask = atom->mask; + image = atom->image; + x = atom->x; + v = atom->v; + f = atom->f; + + q = atom->q; + molecule = atom->molecule; + nspecial = atom->nspecial; + special = atom->special; + + num_bond = atom->num_bond; + bond_type = atom->bond_type; + bond_atom = atom->bond_atom; + + num_angle = atom->num_angle; + angle_type = atom->angle_type; + angle_atom1 = atom->angle_atom1; + angle_atom2 = atom->angle_atom2; + angle_atom3 = atom->angle_atom3; + + num_dihedral = atom->num_dihedral; + dihedral_type = atom->dihedral_type; + dihedral_atom1 = atom->dihedral_atom1; + dihedral_atom2 = atom->dihedral_atom2; + dihedral_atom3 = atom->dihedral_atom3; + dihedral_atom4 = atom->dihedral_atom4; + + num_improper = atom->num_improper; + improper_type = atom->improper_type; + improper_atom1 = atom->improper_atom1; + improper_atom2 = atom->improper_atom2; + improper_atom3 = atom->improper_atom3; + improper_atom4 = atom->improper_atom4; +} + +/* ---------------------------------------------------------------------- + zero auxiliary data for owned atom I + data in copy(), not including tag,type,mask,image,x,v +------------------------------------------------------------------------- */ + +void AtomVecFull::zero_owned(int i) +{ + q[i] = 0.0; + molecule[i] = 0; + num_bond[i] = 0; + num_angle[i] = 0; + num_dihedral[i] = 0; + num_improper[i] = 0; + nspecial[i][0] = 0; + nspecial[i][1] = 0; + nspecial[i][2] = 0; +} + +/* ---------------------------------------------------------------------- + zero auxiliary data for n ghost atoms + data in border(), not including x,tag,type,mask + grow() is here since zero_ghost called first in hybrid::unpack_border() +------------------------------------------------------------------------- */ + +void AtomVecFull::zero_ghost(int n, int first) +{ + int last = first + n; + for (int i = first; i < last; i++) { + if (i == nmax) atom->avec->grow(0); + q[i] = 0.0; + molecule[i] = 0; + } +} + +/* ---------------------------------------------------------------------- */ + +void AtomVecFull::copy(int i, int j) +{ + int k; + + tag[j] = tag[i]; + type[j] = type[i]; + mask[j] = mask[i]; + image[j] = image[i]; + x[j][0] = x[i][0]; + x[j][1] = x[i][1]; + x[j][2] = x[i][2]; + v[j][0] = v[i][0]; + v[j][1] = v[i][1]; + v[j][2] = v[i][2]; + + q[j] = q[i]; + molecule[j] = molecule[i]; + + num_bond[j] = num_bond[i]; + for (k = 0; k < num_bond[j]; k++) { + bond_type[j][k] = bond_type[i][k]; + bond_atom[j][k] = bond_atom[i][k]; + } + + num_angle[j] = num_angle[i]; + for (k = 0; k < num_angle[j]; k++) { + angle_type[j][k] = angle_type[i][k]; + angle_atom1[j][k] = angle_atom1[i][k]; + angle_atom2[j][k] = angle_atom2[i][k]; + angle_atom3[j][k] = angle_atom3[i][k]; + } + + num_dihedral[j] = num_dihedral[i]; + for (k = 0; k < num_dihedral[j]; k++) { + dihedral_type[j][k] = dihedral_type[i][k]; + dihedral_atom1[j][k] = dihedral_atom1[i][k]; + dihedral_atom2[j][k] = dihedral_atom2[i][k]; + dihedral_atom3[j][k] = dihedral_atom3[i][k]; + dihedral_atom4[j][k] = dihedral_atom4[i][k]; + } + + num_improper[j] = num_improper[i]; + for (k = 0; k < num_improper[j]; k++) { + improper_type[j][k] = improper_type[i][k]; + improper_atom1[j][k] = improper_atom1[i][k]; + improper_atom2[j][k] = improper_atom2[i][k]; + improper_atom3[j][k] = improper_atom3[i][k]; + improper_atom4[j][k] = improper_atom4[i][k]; + } + + nspecial[j][0] = nspecial[i][0]; + nspecial[j][1] = nspecial[i][1]; + nspecial[j][2] = nspecial[i][2]; + for (k = 0; k < nspecial[j][2]; k++) special[j][k] = special[i][k]; + + if (atom->nextra_grow) + for (int iextra = 0; iextra < atom->nextra_grow; iextra++) + modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j); +} + +/* ---------------------------------------------------------------------- */ + +int AtomVecFull::pack_comm(int n, int *list, double *buf, int *pbc_flags) +{ + int i,j,m; + + m = 0; + if (pbc_flags[0] == 0) { + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = x[j][0]; + buf[m++] = x[j][1]; + buf[m++] = x[j][2]; + } + } else { + double xprd = domain->xprd; + double yprd = domain->yprd; + double zprd = domain->zprd; + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = x[j][0] + pbc_flags[1]*xprd; + buf[m++] = x[j][1] + pbc_flags[2]*yprd; + buf[m++] = x[j][2] + pbc_flags[3]*zprd; + } + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void AtomVecFull::unpack_comm(int n, int first, double *buf) +{ + int i,m,last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { + x[i][0] = buf[m++]; + x[i][1] = buf[m++]; + x[i][2] = buf[m++]; + } +} + +/* ---------------------------------------------------------------------- */ + +int AtomVecFull::pack_reverse(int n, int first, double *buf) +{ + int i,m,last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { + buf[m++] = f[i][0]; + buf[m++] = f[i][1]; + buf[m++] = f[i][2]; + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void AtomVecFull::unpack_reverse(int n, int *list, double *buf) +{ + int i,j,m; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + f[j][0] += buf[m++]; + f[j][1] += buf[m++]; + f[j][2] += buf[m++]; + } +} + +/* ---------------------------------------------------------------------- */ + +int AtomVecFull::pack_border(int n, int *list, double *buf, + int *pbc_flags) +{ + int i,j,m; + + m = 0; + if (pbc_flags[0] == 0) { + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = x[j][0]; + buf[m++] = x[j][1]; + buf[m++] = x[j][2]; + buf[m++] = tag[j]; + buf[m++] = type[j]; + buf[m++] = mask[j]; + buf[m++] = q[j]; + buf[m++] = molecule[j]; + } + } else { + double xprd = domain->xprd; + double yprd = domain->yprd; + double zprd = domain->zprd; + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = x[j][0] + pbc_flags[1]*xprd; + buf[m++] = x[j][1] + pbc_flags[2]*yprd; + buf[m++] = x[j][2] + pbc_flags[3]*zprd; + buf[m++] = tag[j]; + buf[m++] = type[j]; + buf[m++] = mask[j]; + buf[m++] = q[j]; + buf[m++] = molecule[j]; + } + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +int AtomVecFull::pack_border_one(int i, double *buf) +{ + buf[0] = q[i]; + buf[1] = molecule[i]; + return 2; +} + +/* ---------------------------------------------------------------------- */ + +void AtomVecFull::unpack_border(int n, int first, double *buf) +{ + int i,m,last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { + if (i == nmax) grow(0); + x[i][0] = buf[m++]; + x[i][1] = buf[m++]; + x[i][2] = buf[m++]; + tag[i] = static_cast<int> (buf[m++]); + type[i] = static_cast<int> (buf[m++]); + mask[i] = static_cast<int> (buf[m++]); + q[i] = buf[m++]; + molecule[i] = static_cast<int> (buf[m++]); + } +} + +/* ---------------------------------------------------------------------- */ + +int AtomVecFull::unpack_border_one(int i, double *buf) +{ + q[i] = buf[0]; + molecule[i] = static_cast<int> (buf[1]); + return 2; +} + +/* ---------------------------------------------------------------------- + pack data for atom I for sending to another proc + xyz must be 1st 3 values, so comm::exchange() can test on them +------------------------------------------------------------------------- */ + +int AtomVecFull::pack_exchange(int i, double *buf) +{ + int k; + + int m = 1; + buf[m++] = x[i][0]; + buf[m++] = x[i][1]; + buf[m++] = x[i][2]; + buf[m++] = v[i][0]; + buf[m++] = v[i][1]; + buf[m++] = v[i][2]; + buf[m++] = tag[i]; + buf[m++] = type[i]; + buf[m++] = mask[i]; + buf[m++] = image[i]; + + buf[m++] = q[i]; + buf[m++] = molecule[i]; + + buf[m++] = num_bond[i]; + for (k = 0; k < num_bond[i]; k++) { + buf[m++] = bond_type[i][k]; + buf[m++] = bond_atom[i][k]; + } + + buf[m++] = num_angle[i]; + for (k = 0; k < num_angle[i]; k++) { + buf[m++] = angle_type[i][k]; + buf[m++] = angle_atom1[i][k]; + buf[m++] = angle_atom2[i][k]; + buf[m++] = angle_atom3[i][k]; + } + + buf[m++] = num_dihedral[i]; + for (k = 0; k < num_dihedral[i]; k++) { + buf[m++] = dihedral_type[i][k]; + buf[m++] = dihedral_atom1[i][k]; + buf[m++] = dihedral_atom2[i][k]; + buf[m++] = dihedral_atom3[i][k]; + buf[m++] = dihedral_atom4[i][k]; + } + + buf[m++] = num_improper[i]; + for (k = 0; k < num_improper[i]; k++) { + buf[m++] = improper_type[i][k]; + buf[m++] = improper_atom1[i][k]; + buf[m++] = improper_atom2[i][k]; + buf[m++] = improper_atom3[i][k]; + buf[m++] = improper_atom4[i][k]; + } + + buf[m++] = nspecial[i][0]; + buf[m++] = nspecial[i][1]; + buf[m++] = nspecial[i][2]; + for (k = 0; k < nspecial[i][2]; k++) buf[m++] = special[i][k]; + + if (atom->nextra_grow) + for (int iextra = 0; iextra < atom->nextra_grow; iextra++) + m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); + + buf[0] = m; + return m; +} + +/* ---------------------------------------------------------------------- */ + +int AtomVecFull::unpack_exchange(double *buf) +{ + int k; + + int nlocal = atom->nlocal; + if (nlocal == nmax) grow(0); + + int m = 1; + x[nlocal][0] = buf[m++]; + x[nlocal][1] = buf[m++]; + x[nlocal][2] = buf[m++]; + v[nlocal][0] = buf[m++]; + v[nlocal][1] = buf[m++]; + v[nlocal][2] = buf[m++]; + tag[nlocal] = static_cast<int> (buf[m++]); + type[nlocal] = static_cast<int> (buf[m++]); + mask[nlocal] = static_cast<int> (buf[m++]); + image[nlocal] = static_cast<int> (buf[m++]); + + q[nlocal] = buf[m++]; + molecule[nlocal] = static_cast<int> (buf[m++]); + + num_bond[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_bond[nlocal]; k++) { + bond_type[nlocal][k] = static_cast<int> (buf[m++]); + bond_atom[nlocal][k] = static_cast<int> (buf[m++]); + } + + num_angle[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_angle[nlocal]; k++) { + angle_type[nlocal][k] = static_cast<int> (buf[m++]); + angle_atom1[nlocal][k] = static_cast<int> (buf[m++]); + angle_atom2[nlocal][k] = static_cast<int> (buf[m++]); + angle_atom3[nlocal][k] = static_cast<int> (buf[m++]); + } + + num_dihedral[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_dihedral[nlocal]; k++) { + dihedral_type[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom1[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom2[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom3[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom4[nlocal][k] = static_cast<int> (buf[m++]); + } + + num_improper[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_improper[nlocal]; k++) { + improper_type[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom1[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom2[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom3[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom4[nlocal][k] = static_cast<int> (buf[m++]); + } + + nspecial[nlocal][0] = static_cast<int> (buf[m++]); + nspecial[nlocal][1] = static_cast<int> (buf[m++]); + nspecial[nlocal][2] = static_cast<int> (buf[m++]); + for (k = 0; k < nspecial[nlocal][2]; k++) + special[nlocal][k] = static_cast<int> (buf[m++]); + + if (atom->nextra_grow) + for (int iextra = 0; iextra < atom->nextra_grow; iextra++) + m += modify->fix[atom->extra_grow[iextra]]-> + unpack_exchange(nlocal,&buf[m]); + + atom->nlocal++; + return m; +} + +/* ---------------------------------------------------------------------- + size of restart data for all atoms owned by this proc + include extra data stored by fixes +------------------------------------------------------------------------- */ + +int AtomVecFull::size_restart() +{ + int i; + + int nlocal = atom->nlocal; + int n = 0; + for (i = 0; i < nlocal; i++) + n += 17 + 2*num_bond[i] + 4*num_angle[i] + + 5*num_dihedral[i] + 5*num_improper[i]; + + if (atom->nextra_restart) + for (int iextra = 0; iextra < atom->nextra_restart; iextra++) + for (i = 0; i < nlocal; i++) + n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); + + return n; +} + +/* ---------------------------------------------------------------------- + size of restart data for atom I + do not include extra data stored by fixes, included by caller +------------------------------------------------------------------------- */ + +int AtomVecFull::size_restart_one(int i) +{ + int n = 17 + 2*num_bond[i] + 4*num_angle[i] + + 5*num_dihedral[i] + 5*num_improper[i]; + return n; +} + +/* ---------------------------------------------------------------------- + pack atom I's data for restart file including extra quantities + xyz must be 1st 3 values, so that read_restart can test on them + molecular types may be negative, but write as positive +------------------------------------------------------------------------- */ + +int AtomVecFull::pack_restart(int i, double *buf) +{ + int k; + + int m = 1; + buf[m++] = x[i][0]; + buf[m++] = x[i][1]; + buf[m++] = x[i][2]; + buf[m++] = tag[i]; + buf[m++] = type[i]; + buf[m++] = mask[i]; + buf[m++] = image[i]; + buf[m++] = v[i][0]; + buf[m++] = v[i][1]; + buf[m++] = v[i][2]; + + buf[m++] = q[i]; + buf[m++] = molecule[i]; + + buf[m++] = num_bond[i]; + for (k = 0; k < num_bond[i]; k++) { + buf[m++] = MAX(bond_type[i][k],-bond_type[i][k]); + buf[m++] = bond_atom[i][k]; + } + + buf[m++] = num_angle[i]; + for (k = 0; k < num_angle[i]; k++) { + buf[m++] = MAX(angle_type[i][k],-angle_type[i][k]); + buf[m++] = angle_atom1[i][k]; + buf[m++] = angle_atom2[i][k]; + buf[m++] = angle_atom3[i][k]; + } + + buf[m++] = num_dihedral[i]; + for (k = 0; k < num_dihedral[i]; k++) { + buf[m++] = MAX(dihedral_type[i][k],-dihedral_type[i][k]); + buf[m++] = dihedral_atom1[i][k]; + buf[m++] = dihedral_atom2[i][k]; + buf[m++] = dihedral_atom3[i][k]; + buf[m++] = dihedral_atom4[i][k]; + } + + buf[m++] = num_improper[i]; + for (k = 0; k < num_improper[i]; k++) { + buf[m++] = MAX(improper_type[i][k],-improper_type[i][k]); + buf[m++] = improper_atom1[i][k]; + buf[m++] = improper_atom2[i][k]; + buf[m++] = improper_atom3[i][k]; + buf[m++] = improper_atom4[i][k]; + } + + if (atom->nextra_restart) + for (int iextra = 0; iextra < atom->nextra_restart; iextra++) + m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); + + buf[0] = m; + return m; +} + +/* ---------------------------------------------------------------------- + unpack data for one atom from restart file including extra quantities +------------------------------------------------------------------------- */ + +int AtomVecFull::unpack_restart(double *buf) +{ + int k; + + int nlocal = atom->nlocal; + if (nlocal == nmax) { + grow(0); + if (atom->nextra_store) + atom->extra = memory->grow_2d_double_array(atom->extra,nmax, + atom->nextra_store, + "atom:extra"); + } + + int m = 1; + x[nlocal][0] = buf[m++]; + x[nlocal][1] = buf[m++]; + x[nlocal][2] = buf[m++]; + tag[nlocal] = static_cast<int> (buf[m++]); + type[nlocal] = static_cast<int> (buf[m++]); + mask[nlocal] = static_cast<int> (buf[m++]); + image[nlocal] = static_cast<int> (buf[m++]); + v[nlocal][0] = buf[m++]; + v[nlocal][1] = buf[m++]; + v[nlocal][2] = buf[m++]; + + q[nlocal] = buf[m++]; + molecule[nlocal] = static_cast<int> (buf[m++]); + + num_bond[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_bond[nlocal]; k++) { + bond_type[nlocal][k] = static_cast<int> (buf[m++]); + bond_atom[nlocal][k] = static_cast<int> (buf[m++]); + } + + num_angle[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_angle[nlocal]; k++) { + angle_type[nlocal][k] = static_cast<int> (buf[m++]); + angle_atom1[nlocal][k] = static_cast<int> (buf[m++]); + angle_atom2[nlocal][k] = static_cast<int> (buf[m++]); + angle_atom3[nlocal][k] = static_cast<int> (buf[m++]); + } + + num_dihedral[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_dihedral[nlocal]; k++) { + dihedral_type[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom1[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom2[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom3[nlocal][k] = static_cast<int> (buf[m++]); + dihedral_atom4[nlocal][k] = static_cast<int> (buf[m++]); + } + + num_improper[nlocal] = static_cast<int> (buf[m++]); + for (k = 0; k < num_improper[nlocal]; k++) { + improper_type[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom1[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom2[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom3[nlocal][k] = static_cast<int> (buf[m++]); + improper_atom4[nlocal][k] = static_cast<int> (buf[m++]); + } + + double **extra = atom->extra; + if (atom->nextra_store) { + int size = static_cast<int> (buf[0]) - m; + for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; + } + + atom->nlocal++; + return m; +} + +/* ---------------------------------------------------------------------- + create one atom of type itype at x0,y0,z0 + set other values to defaults +------------------------------------------------------------------------- */ + +void AtomVecFull::create_atom(int itype, double x0, double y0, double z0, + int ihybrid) +{ + int nlocal = atom->nlocal; + if (nlocal == nmax) grow(0); + + tag[nlocal] = 0; + type[nlocal] = itype; + x[nlocal][0] = x0; + x[nlocal][1] = y0; + x[nlocal][2] = z0; + mask[nlocal] = 1; + image[nlocal] = (512 << 20) | (512 << 10) | 512; + v[nlocal][0] = 0.0; + v[nlocal][1] = 0.0; + v[nlocal][2] = 0.0; + + q[nlocal] = 0.0; + molecule[nlocal] = 0; + num_bond[nlocal] = 0; + num_angle[nlocal] = 0; + num_dihedral[nlocal] = 0; + num_improper[nlocal] = 0; + + atom->nlocal++; +} + +/* ---------------------------------------------------------------------- + unpack one line from Atoms section of data file + initialize other atom quantities +------------------------------------------------------------------------- */ + +void AtomVecFull::data_atom(double xtmp, double ytmp, double ztmp, + int imagetmp, char **values, int ihybrid) +{ + int nlocal = atom->nlocal; + if (nlocal == nmax) grow(0); + + tag[nlocal] = atoi(values[0]); + if (tag[nlocal] <= 0) + error->one("Invalid atom ID in Atoms section of data file"); + + molecule[nlocal] = atoi(values[1]); + + type[nlocal] = atoi(values[2]); + if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) + error->one("Invalid atom type in Atoms section of data file"); + + q[nlocal] = atof(values[3]); + + x[nlocal][0] = xtmp; + x[nlocal][1] = ytmp; + x[nlocal][2] = ztmp; + + image[nlocal] = imagetmp; + + mask[nlocal] = 1; + v[nlocal][0] = 0.0; + v[nlocal][1] = 0.0; + v[nlocal][2] = 0.0; + num_bond[nlocal] = 0; + num_angle[nlocal] = 0; + num_dihedral[nlocal] = 0; + num_improper[nlocal] = 0; + + atom->nlocal++; +} + +/* ---------------------------------------------------------------------- + return # of bytes of allocated memory +------------------------------------------------------------------------- */ + +int AtomVecFull::memory_usage() +{ + int bytes = 0; + + if (atom->memcheck("tag")) bytes += nmax * sizeof(int); + if (atom->memcheck("type")) bytes += nmax * sizeof(int); + if (atom->memcheck("mask")) bytes += nmax * sizeof(int); + if (atom->memcheck("image")) bytes += nmax * sizeof(int); + if (atom->memcheck("x")) bytes += nmax*3 * sizeof(double); + if (atom->memcheck("v")) bytes += nmax*3 * sizeof(double); + if (atom->memcheck("f")) bytes += nmax*3 * sizeof(double); + + if (atom->memcheck("q")) bytes += nmax * sizeof(double); + if (atom->memcheck("molecule")) bytes += nmax * sizeof(int); + if (atom->memcheck("nspecial")) bytes += nmax*3 * sizeof(int); + if (atom->memcheck("special")) bytes += nmax*atom->maxspecial * sizeof(int); + + if (atom->memcheck("num_bond")) bytes += nmax * sizeof(int); + if (atom->memcheck("bond_type")) + bytes += nmax*atom->bond_per_atom * sizeof(int); + if (atom->memcheck("bond_atom")) + bytes += nmax*atom->bond_per_atom * sizeof(int); + + if (atom->memcheck("num_angle")) bytes += nmax * sizeof(int); + if (atom->memcheck("angle_type")) + bytes += nmax*atom->angle_per_atom * sizeof(int); + if (atom->memcheck("angle_atom1")) + bytes += nmax*atom->angle_per_atom * sizeof(int); + if (atom->memcheck("angle_atom2")) + bytes += nmax*atom->angle_per_atom * sizeof(int); + if (atom->memcheck("angle_atom3")) + bytes += nmax*atom->angle_per_atom * sizeof(int); + + if (atom->memcheck("num_dihedral")) bytes += nmax * sizeof(int); + if (atom->memcheck("dihedral_type")) + bytes += nmax*atom->dihedral_per_atom * sizeof(int); + if (atom->memcheck("dihedral_atom1")) + bytes += nmax*atom->dihedral_per_atom * sizeof(int); + if (atom->memcheck("dihedral_atom2")) + bytes += nmax*atom->dihedral_per_atom * sizeof(int); + if (atom->memcheck("dihedral_atom3")) + bytes += nmax*atom->dihedral_per_atom * sizeof(int); + if (atom->memcheck("dihedral_atom4")) + bytes += nmax*atom->dihedral_per_atom * sizeof(int); + + if (atom->memcheck("num_improper")) bytes += nmax * sizeof(int); + if (atom->memcheck("improper_type")) + bytes += nmax*atom->improper_per_atom * sizeof(int); + if (atom->memcheck("improper_atom1")) + bytes += nmax*atom->improper_per_atom * sizeof(int); + if (atom->memcheck("improper_atom2")) + bytes += nmax*atom->improper_per_atom * sizeof(int); + if (atom->memcheck("improper_atom3")) + bytes += nmax*atom->improper_per_atom * sizeof(int); + if (atom->memcheck("improper_atom4")) + bytes += nmax*atom->improper_per_atom * sizeof(int); + + return bytes; +} diff --git a/src/MOLECULE/atom_vec_full.h b/src/MOLECULE/atom_vec_full.h new file mode 100644 index 0000000000..81f2a6fcca --- /dev/null +++ b/src/MOLECULE/atom_vec_full.h @@ -0,0 +1,68 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + 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 + 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. +------------------------------------------------------------------------- */ + +#ifndef ATOM_VEC_FULL_H +#define ATOM_VEC_FULL_H + +#include "atom_vec.h" + +namespace LAMMPS_NS { + +class AtomVecFull : public AtomVec { + public: + AtomVecFull(class LAMMPS *, int, char **); + void grow(int); + void reset_ptrs(); + void zero_owned(int); + void zero_ghost(int, int); + void copy(int, int); + int pack_comm(int, int *, double *, int *); + void unpack_comm(int, int, double *); + int pack_reverse(int, int, double *); + void unpack_reverse(int, int *, double *); + int pack_border(int, int *, double *, int *); + int pack_border_one(int, double *); + void unpack_border(int, int, double *); + int unpack_border_one(int, double *); + int pack_exchange(int, double *); + int unpack_exchange(double *); + int size_restart(); + int size_restart_one(int); + int pack_restart(int, double *); + int unpack_restart(double *); + void create_atom(int, double, double, double, int); + void data_atom(double, double, double, int, char **, int); + int memory_usage(); + + private: + int *tag,*type,*mask,*image; + double **x,**v,**f; + double *q; + int *molecule; + int **nspecial,**special; + int *num_bond; + int **bond_type,**bond_atom; + int *num_angle; + int **angle_type; + int **angle_atom1,**angle_atom2,**angle_atom3; + int *num_dihedral; + int **dihedral_type; + int **dihedral_atom1,**dihedral_atom2,**dihedral_atom3,**dihedral_atom4; + int *num_improper; + int **improper_type; + int **improper_atom1,**improper_atom2,**improper_atom3,**improper_atom4; +}; + +} + +#endif