2006-09-28 03:51:33 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
2007-01-30 08:22:05 +08:00
|
|
|
http://lammps.sandia.gov, Sandia National Laboratories
|
|
|
|
Steve Plimpton, sjplimp@sandia.gov
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
|
|
|
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
2012-06-07 06:47:51 +08:00
|
|
|
certain rights in this software. This software is distributed under
|
2006-09-28 03:51:33 +08:00
|
|
|
the GNU General Public License.
|
|
|
|
|
|
|
|
See the README file in the top-level LAMMPS directory.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
#include "stdlib.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "fix_minimize.h"
|
|
|
|
#include "atom.h"
|
2009-08-15 04:54:10 +08:00
|
|
|
#include "domain.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "memory.h"
|
|
|
|
#include "error.h"
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
using namespace LAMMPS_NS;
|
2012-02-02 00:27:41 +08:00
|
|
|
using namespace FixConst;
|
2007-01-30 08:22:05 +08:00
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
FixMinimize::FixMinimize(LAMMPS *lmp, int narg, char **arg) :
|
|
|
|
Fix(lmp, narg, arg)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
nvector = 0;
|
|
|
|
peratom = NULL;
|
|
|
|
vectors = NULL;
|
|
|
|
|
|
|
|
// register callback to this fix from Atom class
|
|
|
|
// don't perform initial allocation here, must wait until add_vector()
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
atom->add_callback(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
FixMinimize::~FixMinimize()
|
|
|
|
{
|
2007-01-30 08:22:05 +08:00
|
|
|
// unregister callbacks to this fix from Atom class
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
atom->delete_callback(id,0);
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
// delete locally stored data
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->destroy(peratom);
|
|
|
|
for (int m = 0; m < nvector; m++) memory->destroy(vectors[m]);
|
2009-08-15 04:54:10 +08:00
|
|
|
memory->sfree(vectors);
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixMinimize::setmask()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
allocate/initialize memory for a new vector with N elements per atom
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixMinimize::add_vector(int n)
|
|
|
|
{
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->grow(peratom,nvector+1,"minimize:peratom");
|
2009-08-15 04:54:10 +08:00
|
|
|
peratom[nvector] = n;
|
|
|
|
|
|
|
|
vectors = (double **)
|
|
|
|
memory->srealloc(vectors,(nvector+1)*sizeof(double *),"minimize:vectors");
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->create(vectors[nvector],atom->nmax*n,"minimize:vector");
|
2009-08-15 04:54:10 +08:00
|
|
|
|
|
|
|
int ntotal = n*atom->nlocal;
|
|
|
|
for (int i = 0; i < ntotal; i++) vectors[nvector][i] = 0.0;
|
|
|
|
nvector++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
return a pointer to the Mth vector
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double *FixMinimize::request_vector(int m)
|
|
|
|
{
|
|
|
|
return vectors[m];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
store box size at beginning of line search
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixMinimize::store_box()
|
|
|
|
{
|
|
|
|
boxlo[0] = domain->boxlo[0];
|
|
|
|
boxlo[1] = domain->boxlo[1];
|
|
|
|
boxlo[2] = domain->boxlo[2];
|
|
|
|
boxhi[0] = domain->boxhi[0];
|
|
|
|
boxhi[1] = domain->boxhi[1];
|
|
|
|
boxhi[2] = domain->boxhi[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
reset x0 for atoms that moved across PBC via reneighboring in line search
|
|
|
|
x0 = 1st vector
|
|
|
|
must do minimum_image using original box stored at beginning of line search
|
|
|
|
swap & set_global_box() change to original box, then restore current box
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixMinimize::reset_coords()
|
|
|
|
{
|
|
|
|
box_swap();
|
|
|
|
domain->set_global_box();
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
double **x = atom->x;
|
|
|
|
double *x0 = vectors[0];
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
double dx,dy,dz,dx0,dy0,dz0;
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
dx = dx0 = x[i][0] - x0[n];
|
|
|
|
dy = dy0 = x[i][1] - x0[n+1];
|
|
|
|
dz = dz0 = x[i][2] - x0[n+2];
|
|
|
|
domain->minimum_image(dx,dy,dz);
|
|
|
|
if (dx != dx0) x0[n] = x[i][0] - dx;
|
|
|
|
if (dy != dy0) x0[n+1] = x[i][1] - dy;
|
|
|
|
if (dz != dz0) x0[n+2] = x[i][2] - dz;
|
|
|
|
n += 3;
|
|
|
|
}
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
box_swap();
|
|
|
|
domain->set_global_box();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
swap current box size with stored box size
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixMinimize::box_swap()
|
|
|
|
{
|
|
|
|
double tmp;
|
|
|
|
|
|
|
|
tmp = boxlo[0];
|
|
|
|
boxlo[0] = domain->boxlo[0];
|
|
|
|
domain->boxlo[0] = tmp;
|
|
|
|
tmp = boxlo[1];
|
|
|
|
boxlo[1] = domain->boxlo[1];
|
|
|
|
domain->boxlo[1] = tmp;
|
|
|
|
tmp = boxlo[2];
|
|
|
|
boxlo[2] = domain->boxlo[2];
|
|
|
|
domain->boxlo[2] = tmp;
|
|
|
|
|
|
|
|
tmp = boxhi[0];
|
|
|
|
boxhi[0] = domain->boxhi[0];
|
|
|
|
domain->boxhi[0] = tmp;
|
|
|
|
tmp = boxhi[1];
|
|
|
|
boxhi[1] = domain->boxhi[1];
|
|
|
|
domain->boxhi[1] = tmp;
|
|
|
|
tmp = boxhi[2];
|
|
|
|
boxhi[2] = domain->boxhi[2];
|
|
|
|
domain->boxhi[2] = tmp;
|
|
|
|
}
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
2012-06-07 06:47:51 +08:00
|
|
|
memory usage of local atom-based arrays
|
2006-09-28 03:51:33 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2007-10-05 01:57:04 +08:00
|
|
|
double FixMinimize::memory_usage()
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
double bytes = 0.0;
|
|
|
|
for (int m = 0; m < nvector; m++)
|
|
|
|
bytes += atom->nmax*peratom[m]*sizeof(double);
|
2006-09-28 03:51:33 +08:00
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
2012-06-07 06:47:51 +08:00
|
|
|
allocate local atom-based arrays
|
2006-09-28 03:51:33 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixMinimize::grow_arrays(int nmax)
|
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
for (int m = 0; m < nvector; m++)
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->grow(vectors[m],peratom[m]*nmax,"minimize:vector");
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
2012-06-07 06:47:51 +08:00
|
|
|
copy values within local atom-based arrays
|
2006-09-28 03:51:33 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2013-02-09 00:44:04 +08:00
|
|
|
void FixMinimize::copy_arrays(int i, int j, int delflag)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
int m,iper,nper,ni,nj;
|
|
|
|
|
|
|
|
for (m = 0; m < nvector; m++) {
|
|
|
|
nper = peratom[m];
|
|
|
|
ni = nper*i;
|
|
|
|
nj = nper*j;
|
|
|
|
for (iper = 0; iper < nper; iper++) vectors[m][nj++] = vectors[m][ni++];
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
2012-06-07 06:47:51 +08:00
|
|
|
pack values in local atom-based arrays for exchange with another proc
|
2006-09-28 03:51:33 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixMinimize::pack_exchange(int i, double *buf)
|
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
int m,iper,nper,ni;
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
for (m = 0; m < nvector; m++) {
|
|
|
|
nper = peratom[m];
|
|
|
|
ni = nper*i;
|
|
|
|
for (iper = 0; iper < nper; iper++) buf[n++] = vectors[m][ni++];
|
|
|
|
}
|
|
|
|
return n;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
2012-06-07 06:47:51 +08:00
|
|
|
unpack values in local atom-based arrays from exchange with another proc
|
2006-09-28 03:51:33 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixMinimize::unpack_exchange(int nlocal, double *buf)
|
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
int m,iper,nper,ni;
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
for (m = 0; m < nvector; m++) {
|
2011-07-01 04:10:18 +08:00
|
|
|
nper = peratom[m];
|
2009-08-15 04:54:10 +08:00
|
|
|
ni = nper*nlocal;
|
|
|
|
for (iper = 0; iper < nper; iper++) vectors[m][ni++] = buf[n++];
|
|
|
|
}
|
|
|
|
return n;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|