#include "fix_reaxc.h"
#include "atom.h"
#include "memory.h"
using namespace LAMMPS_NS;
using namespace FixConst;
#define MAX_REAX_BONDS 30
#define MIN_REAX_BONDS 15
#define MIN_REAX_HBONDS 25
FixReaxC::FixReaxC(LAMMPS *lmp,int narg, char **arg) :
Fix(lmp, narg, arg)
{
oldnmax = 0;
num_bonds = NULL;
num_hbonds = NULL;
grow_arrays(atom->nmax);
atom->add_callback(0);
comm_forward = 1;
}
FixReaxC::~FixReaxC()
{
atom->delete_callback(id,0);
memory->destroy(num_bonds);
memory->destroy(num_hbonds);
}
int FixReaxC::setmask()
{
int mask = 0;
return mask;
}
double FixReaxC::memory_usage()
{
int nmax = atom->nmax;
double bytes = nmax * 2 * sizeof(int);
return bytes;
}
void FixReaxC::grow_arrays(int nmax)
{
memory->grow(num_bonds,nmax,"reaxc:num_bonds");
memory->grow(num_hbonds,nmax,"reaxc:num_hbonds");
for (int i = oldnmax; i < nmax; i++) {
num_hbonds[i] = MIN_REAX_HBONDS;
num_bonds[i] = MIN_REAX_BONDS;
}
oldnmax = nmax;
}
void FixReaxC::copy_arrays(int i, int j, int )
{
num_bonds[j] = num_bonds[i];
num_hbonds[j] = num_hbonds[i];
}
int FixReaxC::pack_exchange(int i, double *buf)
{
buf[0] = num_bonds[i];
buf[1] = num_hbonds[i];
return 2;
}
int FixReaxC::unpack_exchange(int nlocal, double *buf)
{
num_bonds[nlocal] = static_cast<int> (buf[0]);
num_hbonds[nlocal] = static_cast<int> (buf[1]);
return 2;
}
int FixReaxC::pack_forward_comm(int n, int *list, double *buf,
int , int * )
{
int i,j,m;
m = 0;
for (i = 0; i < n; i++) {
j = list[i];
buf[m++] = num_bonds[j];
}
return m;
}
void FixReaxC::unpack_forward_comm(int n, int first, double *buf)
{
int i,m,last;
m = 0;
last = first + n;
for (i = first; i < last; i++)
num_bonds[i] = static_cast<int> (buf[m++]);
}