#include "atom_vec_wavepacket.h"
#include <cstring>
#include "atom.h"
#include "comm.h"
#include "domain.h"
#include "modify.h"
#include "fix.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
AtomVecWavepacket::AtomVecWavepacket(LAMMPS *lmp) : AtomVec(lmp)
{
comm_x_only = comm_f_only = 0;
mass_type = 1;
molecular = 0;
forceclearflag = 1;
size_forward = 4; size_reverse = 10; size_border = 10; size_velocity = 6; size_data_atom = 11; size_data_vel = 5; xcol_data = 9;
atom->wavepacket_flag = 1;
atom->electron_flag = 1; atom->q_flag = atom->spin_flag = atom->eradius_flag =
atom->ervel_flag = atom->erforce_flag = 1;
atom->cs_flag = atom->csforce_flag = atom->vforce_flag = atom->ervelforce_flag = atom->etag_flag = 1;
}
void AtomVecWavepacket::grow(int n)
{
if (n == 0) grow_nmax();
else nmax = n;
atom->nmax = nmax;
tag = memory->grow(atom->tag,nmax,"atom:tag");
type = memory->grow(atom->type,nmax,"atom:type");
mask = memory->grow(atom->mask,nmax,"atom:mask");
image = memory->grow(atom->image,nmax,"atom:image");
x = memory->grow(atom->x,nmax,3,"atom:x");
v = memory->grow(atom->v,nmax,3,"atom:v");
f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
q = memory->grow(atom->q,nmax,"atom:q");
spin = memory->grow(atom->spin,nmax,"atom:spin");
eradius = memory->grow(atom->eradius,nmax,"atom:eradius");
ervel = memory->grow(atom->ervel,nmax,"atom:ervel");
erforce = memory->grow(atom->erforce,nmax*comm->nthreads,"atom:erforce");
cs = memory->grow(atom->cs,2*nmax,"atom:cs");
csforce = memory->grow(atom->csforce,2*nmax,"atom:csforce");
vforce = memory->grow(atom->vforce,3*nmax,"atom:vforce");
ervelforce = memory->grow(atom->ervelforce,nmax,"atom:ervelforce");
etag = memory->grow(atom->etag,nmax,"atom:etag");
if (atom->nextra_grow)
for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
}
void AtomVecWavepacket::grow_reset()
{
tag = atom->tag; type = atom->type;
mask = atom->mask; image = atom->image;
x = atom->x; v = atom->v; f = atom->f;
q = atom->q;
eradius = atom->eradius; ervel = atom->ervel; erforce = atom->erforce;
cs = atom->cs;
csforce = atom->csforce;
vforce = atom->vforce;
ervelforce = atom->ervelforce;
etag = atom->etag;
}
void AtomVecWavepacket::copy(int i, int j, int delflag)
{
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];
spin[j] = spin[i];
eradius[j] = eradius[i];
ervel[j] = ervel[i];
cs[2*j] = cs[2*i];
cs[2*j+1] = cs[2*i+1];
etag[j] = etag[i];
if (atom->nextra_grow)
for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag);
}
void AtomVecWavepacket::force_clear(int n, size_t nbytes)
{
memset(&erforce[n],0,nbytes);
}
int AtomVecWavepacket::pack_comm(int n, int *list, double *buf,
int pbc_flag, int *pbc)
{
int i,j,m;
double dx,dy,dz;
m = 0;
if (pbc_flag == 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++] = eradius[j];
}
} else {
if (domain->triclinic == 0) {
dx = pbc[0]*domain->xprd;
dy = pbc[1]*domain->yprd;
dz = pbc[2]*domain->zprd;
} else {
dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
dz = pbc[2]*domain->zprd;
}
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = x[j][0] + dx;
buf[m++] = x[j][1] + dy;
buf[m++] = x[j][2] + dz;
buf[m++] = eradius[j];
}
}
return m;
}
int AtomVecWavepacket::pack_comm_vel(int n, int *list, double *buf,
int pbc_flag, int *pbc)
{
int i,j,m;
double dx,dy,dz,dvx,dvy,dvz;
m = 0;
if (pbc_flag == 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++] = eradius[j];
buf[m++] = v[j][0];
buf[m++] = v[j][1];
buf[m++] = v[j][2];
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
} else {
if (domain->triclinic == 0) {
dx = pbc[0]*domain->xprd;
dy = pbc[1]*domain->yprd;
dz = pbc[2]*domain->zprd;
} else {
dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
dz = pbc[2]*domain->zprd;
}
if (!deform_vremap) {
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = x[j][0] + dx;
buf[m++] = x[j][1] + dy;
buf[m++] = x[j][2] + dz;
buf[m++] = eradius[j];
buf[m++] = v[j][0];
buf[m++] = v[j][1];
buf[m++] = v[j][2];
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
} else {
dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
dvz = pbc[2]*h_rate[2];
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = x[j][0] + dx;
buf[m++] = x[j][1] + dy;
buf[m++] = x[j][2] + dz;
buf[m++] = eradius[j];
if (mask[i] & deform_groupbit) {
buf[m++] = v[j][0] + dvx;
buf[m++] = v[j][1] + dvy;
buf[m++] = v[j][2] + dvz;
} else {
buf[m++] = v[j][0];
buf[m++] = v[j][1];
buf[m++] = v[j][2];
}
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
}
}
return m;
}
int AtomVecWavepacket::pack_comm_hybrid(int n, int *list, double *buf)
{
int i,j,m;
m = 0;
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = eradius[j];
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
return m;
}
void AtomVecWavepacket::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++];
eradius[i] = buf[m++];
}
}
void AtomVecWavepacket::unpack_comm_vel(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++];
eradius[i] = buf[m++];
v[i][0] = buf[m++];
v[i][1] = buf[m++];
v[i][2] = buf[m++];
ervel[i] = buf[m++];
cs[2*i] = buf[m++];
cs[2*i+1] = buf[m++];
}
}
int AtomVecWavepacket::unpack_comm_hybrid(int n, int first, double *buf)
{
int i,m,last;
m = 0;
last = first + n;
for (i = first; i < last; i++){
eradius[i] = buf[m++];
ervel[i] = buf[m++];
cs[2*i] = buf[m++];
cs[2*i+1] = buf[m++];
}
return m;
}
int AtomVecWavepacket::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];
buf[m++] = erforce[i];
buf[m++] = ervelforce[i];
buf[m++] = vforce[3*i];
buf[m++] = vforce[3*i+1];
buf[m++] = vforce[3*i+2];
buf[m++] = csforce[2*i];
buf[m++] = csforce[2*i+1];
}
return m;
}
int AtomVecWavepacket::pack_reverse_hybrid(int n, int first, double *buf)
{
int i,m,last;
m = 0;
last = first + n;
for (i = first; i < last; i++){
buf[m++] = erforce[i];
buf[m++] = ervelforce[i];
buf[m++] = vforce[3*i];
buf[m++] = vforce[3*i+1];
buf[m++] = vforce[3*i+2];
buf[m++] = csforce[2*i];
buf[m++] = csforce[2*i+1];
}
return m;
}
void AtomVecWavepacket::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++];
erforce[j] += buf[m++];
ervelforce[j] += buf[m++];
vforce[3*j] += buf[m++];
vforce[3*j+1] += buf[m++];
vforce[3*j+2] += buf[m++];
csforce[2*j] += buf[m++];
csforce[2*j+1] += buf[m++];
}
}
int AtomVecWavepacket::unpack_reverse_hybrid(int n, int *list, double *buf)
{
int i,j,m;
m = 0;
for (i = 0; i < n; i++) {
j = list[i];
erforce[j] += buf[m++];
ervelforce[j] += buf[m++];
vforce[3*j] += buf[m++];
vforce[3*j+1] += buf[m++];
vforce[3*j+2] += buf[m++];
csforce[2*j] += buf[m++];
csforce[2*j+1] += buf[m++];
}
return m;
}
int AtomVecWavepacket::pack_border(int n, int *list, double *buf,
int pbc_flag, int *pbc)
{
int i,j,m;
double dx,dy,dz;
m = 0;
if (pbc_flag == 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++] = ubuf(tag[j]).d;
buf[m++] = ubuf(type[j]).d;
buf[m++] = ubuf(mask[j]).d;
buf[m++] = q[j];
buf[m++] = ubuf(spin[j]).d;
buf[m++] = eradius[j];
buf[m++] = ubuf(etag[j]).d;
}
} else {
if (domain->triclinic == 0) {
dx = pbc[0]*domain->xprd;
dy = pbc[1]*domain->yprd;
dz = pbc[2]*domain->zprd;
} else {
dx = pbc[0];
dy = pbc[1];
dz = pbc[2];
}
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = x[j][0] + dx;
buf[m++] = x[j][1] + dy;
buf[m++] = x[j][2] + dz;
buf[m++] = ubuf(tag[j]).d;
buf[m++] = ubuf(type[j]).d;
buf[m++] = ubuf(mask[j]).d;
buf[m++] = q[j];
buf[m++] = ubuf(spin[j]).d;
buf[m++] = eradius[j];
buf[m++] = ubuf(etag[j]).d;
}
}
if (atom->nextra_border)
for (int iextra = 0; iextra < atom->nextra_border; iextra++)
m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]);
return m;
}
int AtomVecWavepacket::pack_border_vel(int n, int *list, double *buf,
int pbc_flag, int *pbc)
{
int i,j,m;
double dx,dy,dz,dvx,dvy,dvz;
m = 0;
if (pbc_flag == 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++] = ubuf(tag[j]).d;
buf[m++] = ubuf(type[j]).d;
buf[m++] = ubuf(mask[j]).d;
buf[m++] = q[j];
buf[m++] = ubuf(spin[j]).d;
buf[m++] = eradius[j];
buf[m++] = ubuf(etag[j]).d;
buf[m++] = v[j][0];
buf[m++] = v[j][1];
buf[m++] = v[j][2];
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
} else {
if (domain->triclinic == 0) {
dx = pbc[0]*domain->xprd;
dy = pbc[1]*domain->yprd;
dz = pbc[2]*domain->zprd;
} else {
dx = pbc[0];
dy = pbc[1];
dz = pbc[2];
}
if (domain->triclinic == 0) {
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = x[j][0] + dx;
buf[m++] = x[j][1] + dy;
buf[m++] = x[j][2] + dz;
buf[m++] = ubuf(tag[j]).d;
buf[m++] = ubuf(type[j]).d;
buf[m++] = ubuf(mask[j]).d;
buf[m++] = q[j];
buf[m++] = ubuf(spin[j]).d;
buf[m++] = eradius[j];
buf[m++] = ubuf(etag[j]).d;
buf[m++] = v[j][0];
buf[m++] = v[j][1];
buf[m++] = v[j][2];
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
} else {
dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
dvz = pbc[2]*h_rate[2];
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = x[j][0] + dx;
buf[m++] = x[j][1] + dy;
buf[m++] = x[j][2] + dz;
buf[m++] = ubuf(tag[j]).d;
buf[m++] = ubuf(type[j]).d;
buf[m++] = ubuf(mask[j]).d;
buf[m++] = q[j];
buf[m++] = ubuf(spin[j]).d;
buf[m++] = eradius[j];
buf[m++] = ubuf(etag[j]).d;
if (mask[i] & deform_groupbit) {
buf[m++] = v[j][0] + dvx;
buf[m++] = v[j][1] + dvy;
buf[m++] = v[j][2] + dvz;
} else {
buf[m++] = v[j][0];
buf[m++] = v[j][1];
buf[m++] = v[j][2];
}
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
}
}
if (atom->nextra_border)
for (int iextra = 0; iextra < atom->nextra_border; iextra++)
m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]);
return m;
}
int AtomVecWavepacket::pack_border_hybrid(int n, int *list, double *buf)
{
int i,j,m;
m = 0;
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = q[j];
buf[m++] = ubuf(spin[j]).d;
buf[m++] = eradius[j];
buf[m++] = ubuf(etag[j]).d;
buf[m++] = ervel[j];
buf[m++] = cs[2*j];
buf[m++] = cs[2*j+1];
}
return m;
}
void AtomVecWavepacket::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] = (tagint) ubuf(buf[m++]).i;
type[i] = (int) ubuf(buf[m++]).i;
mask[i] = (int) ubuf(buf[m++]).i;
q[i] = buf[m++];
spin[i] = (int) ubuf(buf[m++]).i;
eradius[i] = buf[m++];
etag[i] = (int) ubuf(buf[m++]).i;
}
if (atom->nextra_border)
for (int iextra = 0; iextra < atom->nextra_border; iextra++)
m += modify->fix[atom->extra_border[iextra]]->
unpack_border(n,first,&buf[m]);
}
void AtomVecWavepacket::unpack_border_vel(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] = (tagint) ubuf(buf[m++]).i;
type[i] = (int) ubuf(buf[m++]).i;
mask[i] = (int) ubuf(buf[m++]).i;
q[i] = buf[m++];
spin[i] = (int) ubuf(buf[m++]).i;
eradius[i] = buf[m++];
etag[i] = (int) ubuf(buf[m++]).i;
v[i][0] = buf[m++];
v[i][1] = buf[m++];
v[i][2] = buf[m++];
ervel[i] = buf[m++];
cs[2*i] = buf[m++];
cs[2*i+1] = buf[m++];
}
if (atom->nextra_border)
for (int iextra = 0; iextra < atom->nextra_border; iextra++)
m += modify->fix[atom->extra_border[iextra]]->
unpack_border(n,first,&buf[m]);
}
int AtomVecWavepacket::unpack_border_hybrid(int n, int first, double *buf)
{
int i,m,last;
m = 0;
last = first + n;
for (i = first; i < last; i++) {
q[i] = buf[m++];
spin[i] = (int) ubuf(buf[m++]).i;
eradius[i] = buf[m++];
etag[i] = (int) ubuf(buf[m++]).i;
ervel[i] = buf[m++];
cs[2*i] = buf[m++];
cs[2*i+1] = buf[m++];
}
return m;
}
int AtomVecWavepacket::pack_exchange(int i, double *buf)
{
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++] = ubuf(tag[i]).d;
buf[m++] = ubuf(type[i]).d;
buf[m++] = ubuf(mask[i]).d;
buf[m++] = ubuf(image[i]).d;
buf[m++] = q[i];
buf[m++] = ubuf(spin[i]).d;
buf[m++] = eradius[i];
buf[m++] = ervel[i];
buf[m++] = ubuf(etag[i]).d;
buf[m++] = cs[2*i];
buf[m++] = cs[2*i+1];
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 AtomVecWavepacket::unpack_exchange(double *buf)
{
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] = (tagint) ubuf(buf[m++]).i;
type[nlocal] = (int) ubuf(buf[m++]).i;
mask[nlocal] = (int) ubuf(buf[m++]).i;
image[nlocal] = (imageint) ubuf(buf[m++]).i;
q[nlocal] = buf[m++];
spin[nlocal] = (int) ubuf(buf[m++]).i;
eradius[nlocal] = buf[m++];
ervel[nlocal] = buf[m++];
etag[nlocal] = (int) ubuf(buf[m++]).i;
cs[2*nlocal] = buf[m++];
cs[2*nlocal+1] = 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;
}
int AtomVecWavepacket::size_restart()
{
int i;
int nlocal = atom->nlocal;
int n = 18 * nlocal;
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;
}
int AtomVecWavepacket::pack_restart(int i, double *buf)
{
int m = 1;
buf[m++] = x[i][0];
buf[m++] = x[i][1];
buf[m++] = x[i][2];
buf[m++] = ubuf(tag[i]).d;
buf[m++] = ubuf(type[i]).d;
buf[m++] = ubuf(mask[i]).d;
buf[m++] = ubuf(image[i]).d;
buf[m++] = v[i][0];
buf[m++] = v[i][1];
buf[m++] = v[i][2];
buf[m++] = q[i];
buf[m++] = ubuf(spin[i]).d;
buf[m++] = eradius[i];
buf[m++] = ervel[i];
buf[m++] = ubuf(etag[i]).d;
buf[m++] = cs[2*i];
buf[m++] = cs[2*i+1];
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;
}
int AtomVecWavepacket::unpack_restart(double *buf)
{
int nlocal = atom->nlocal;
if (nlocal == nmax) {
grow(0);
if (atom->nextra_store)
memory->grow(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] = (tagint) ubuf(buf[m++]).i;
type[nlocal] = (int) ubuf(buf[m++]).i;
mask[nlocal] = (int) ubuf(buf[m++]).i;
image[nlocal] = (imageint) ubuf(buf[m++]).i;
v[nlocal][0] = buf[m++];
v[nlocal][1] = buf[m++];
v[nlocal][2] = buf[m++];
q[nlocal] = buf[m++];
spin[nlocal] = (int) ubuf(buf[m++]).i;
eradius[nlocal] = buf[m++];
ervel[nlocal] = buf[m++];
etag[nlocal] = (int) ubuf(buf[m++]).i;
cs[2*nlocal] = buf[m++];
cs[2*nlocal+1] = 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;
}
void AtomVecWavepacket::create_atom(int itype, double *coord)
{
int nlocal = atom->nlocal;
if (nlocal == nmax) grow(0);
tag[nlocal] = 0;
type[nlocal] = itype;
x[nlocal][0] = coord[0];
x[nlocal][1] = coord[1];
x[nlocal][2] = coord[2];
mask[nlocal] = 1;
image[nlocal] = ((imageint) IMGMAX << IMG2BITS) |
((imageint) IMGMAX << IMGBITS) | IMGMAX;
v[nlocal][0] = 0.0;
v[nlocal][1] = 0.0;
v[nlocal][2] = 0.0;
q[nlocal] = 1.;
spin[nlocal] = 0;
eradius[nlocal] = 0.0;
ervel[nlocal] = 0.0;
etag[nlocal] = 0;
cs[2*nlocal] = 0.;
cs[2*nlocal+1] = 0.;
atom->nlocal++;
}
void AtomVecWavepacket::data_atom(double *coord, imageint imagetmp,
char **values)
{
int nlocal = atom->nlocal;
if (nlocal == nmax) grow(0);
tag[nlocal] = utils::tnumeric(FLERR,values[0],true,lmp);
type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp);
if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
error->one(FLERR,"Invalid atom type in Atoms section of data file");
q[nlocal] = utils::numeric(FLERR,values[2],true,lmp);
spin[nlocal] = utils::inumeric(FLERR,values[3],true,lmp);
eradius[nlocal] = utils::numeric(FLERR,values[4],true,lmp);
if (eradius[nlocal] < 0.0)
error->one(FLERR,"Invalid eradius in Atoms section of data file");
etag[nlocal] = utils::inumeric(FLERR,values[5],true,lmp);
cs[2*nlocal] = utils::numeric(FLERR,values[6],true,lmp);
cs[2*nlocal+1] = utils::numeric(FLERR,values[7],true,lmp);
x[nlocal][0] = coord[0];
x[nlocal][1] = coord[1];
x[nlocal][2] = coord[2];
image[nlocal] = imagetmp;
mask[nlocal] = 1;
v[nlocal][0] = 0.0;
v[nlocal][1] = 0.0;
v[nlocal][2] = 0.0;
ervel[nlocal] = 0.0;
atom->nlocal++;
}
int AtomVecWavepacket::data_atom_hybrid(int nlocal, char **values)
{
q[nlocal] = utils::numeric(FLERR,values[0],true,lmp);
spin[nlocal] = utils::inumeric(FLERR,values[1],true,lmp);
eradius[nlocal] = utils::numeric(FLERR,values[2],true,lmp);
if (eradius[nlocal] < 0.0)
error->one(FLERR,"Invalid eradius in Atoms section of data file");
etag[nlocal] = utils::inumeric(FLERR,values[3],true,lmp);
cs[2*nlocal] = utils::inumeric(FLERR,values[4],true,lmp);
cs[2*nlocal+1] = utils::numeric(FLERR,values[5],true,lmp);
v[nlocal][0] = 0.0;
v[nlocal][1] = 0.0;
v[nlocal][2] = 0.0;
ervel[nlocal] = 0.0;
return 3;
}
void AtomVecWavepacket::data_vel(int m, char **values)
{
v[m][0] = utils::numeric(FLERR,values[0],true,lmp);
v[m][1] = utils::numeric(FLERR,values[1],true,lmp);
v[m][2] = utils::numeric(FLERR,values[2],true,lmp);
ervel[m] = utils::numeric(FLERR,values[3],true,lmp);
}
int AtomVecWavepacket::data_vel_hybrid(int m, char **values)
{
ervel[m] = utils::numeric(FLERR,values[0],true,lmp);
return 1;
}
void AtomVecWavepacket::pack_data(double **buf)
{
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++) {
buf[i][0] = ubuf(tag[i]).d;
buf[i][1] = ubuf(type[i]).d;
buf[i][2] = q[i];
buf[i][3] = ubuf(spin[i]).d;
buf[i][4] = eradius[i];
buf[i][5] = ubuf(etag[i]).d;
buf[i][6] = cs[2*i];
buf[i][7] = cs[2*i+1];
buf[i][8] = x[i][0];
buf[i][9] = x[i][1];
buf[i][10] = x[i][2];
buf[i][11] = ubuf((image[i] & IMGMASK) - IMGMAX).d;
buf[i][12] = ubuf((image[i] >> IMGBITS & IMGMASK) - IMGMAX).d;
buf[i][13] = ubuf((image[i] >> IMG2BITS) - IMGMAX).d;
}
}
int AtomVecWavepacket::pack_data_hybrid(int i, double *buf)
{
buf[0] = q[i];
buf[1] = ubuf(spin[i]).d;
buf[2] = eradius[i];
buf[3] = ubuf(etag[i]).d;
buf[4] = cs[2*i];
buf[5] = cs[2*i+1];
return 6;
}
void AtomVecWavepacket::write_data(FILE *fp, int n, double **buf)
{
for (int i = 0; i < n; i++)
fprintf(fp,TAGINT_FORMAT
" %d %-1.16e %d %-1.16e %d %-1.16e %-1.16e %-1.16e "
"%-1.16e %-1.16e %d %d %d\n",
(tagint) ubuf(buf[i][0]).i,(int) ubuf(buf[i][1]).i,
buf[i][2],(int) ubuf(buf[i][3]).i,buf[i][4],
(int) ubuf(buf[i][5]).i,buf[i][6],buf[i][8],
buf[i][8],buf[i][9],buf[i][10],
(int) ubuf(buf[i][11]).i,(int) ubuf(buf[i][12]).i,
(int) ubuf(buf[i][13]).i);
}
int AtomVecWavepacket::write_data_hybrid(FILE *fp, double *buf)
{
fprintf(fp," %-1.16e %d %-1.16e %d %-1.16e %-1.16e",
buf[0],(int) ubuf(buf[1]).i,buf[2],(int) ubuf(buf[3]).i,
buf[4],buf[5]);
return 6;
}
void AtomVecWavepacket::pack_vel(double **buf)
{
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++) {
buf[i][0] = ubuf(tag[i]).d;
buf[i][1] = v[i][0];
buf[i][2] = v[i][1];
buf[i][3] = v[i][2];
buf[i][4] = ervel[i];
}
}
int AtomVecWavepacket::pack_vel_hybrid(int i, double *buf)
{
buf[0] = ervel[i];
return 1;
}
void AtomVecWavepacket::write_vel(FILE *fp, int n, double **buf)
{
for (int i = 0; i < n; i++)
fprintf(fp,TAGINT_FORMAT " %-1.16e %-1.16e %-1.16e %-1.16e\n",
(tagint) ubuf(buf[i][0]).i,buf[i][1],buf[i][2],buf[i][3],buf[i][4]);
}
int AtomVecWavepacket::write_vel_hybrid(FILE *fp, double *buf)
{
fprintf(fp," %-1.16e",buf[0]);
return 1;
}
int AtomVecWavepacket::property_atom(char *name)
{
if (strcmp(name,"spin") == 0) return 0;
if (strcmp(name,"eradius") == 0) return 1;
if (strcmp(name,"ervel") == 0) return 2;
if (strcmp(name,"erforce") == 0) return 3;
return -1;
}
void AtomVecWavepacket::pack_property_atom(int index, double *buf,
int nvalues, int groupbit)
{
int *mask = atom->mask;
int nlocal = atom->nlocal;
int n = 0;
if (index == 0) {
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) buf[n] = spin[i];
else buf[n] = 0.0;
n += nvalues;
}
} else if (index == 1) {
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) buf[n] = eradius[i];
else buf[n] = 0.0;
n += nvalues;
}
} else if (index == 2) {
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) buf[n] = ervel[i];
else buf[n] = 0.0;
n += nvalues;
}
} else if (index == 3) {
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) buf[n] = erforce[i];
else buf[n] = 0.0;
n += nvalues;
}
}
}
bigint AtomVecWavepacket::memory_usage()
{
bigint bytes = 0;
if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
if (atom->memcheck("q")) bytes += memory->usage(q,nmax);
if (atom->memcheck("spin")) bytes += memory->usage(spin,nmax);
if (atom->memcheck("eradius")) bytes += memory->usage(eradius,nmax);
if (atom->memcheck("ervel")) bytes += memory->usage(ervel,nmax);
if (atom->memcheck("erforce"))
bytes += memory->usage(erforce,nmax*comm->nthreads);
if (atom->memcheck("ervelforce")) bytes += memory->usage(ervelforce,nmax);
if (atom->memcheck("cs")) bytes += memory->usage(cs,2*nmax);
if (atom->memcheck("csforce")) bytes += memory->usage(csforce,2*nmax);
if (atom->memcheck("vforce")) bytes += memory->usage(vforce,3*nmax);
if (atom->memcheck("etag")) bytes += memory->usage(etag,nmax);
return bytes;
}