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
|
|
|
|
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 "math.h"
|
|
|
|
#include "mpi.h"
|
|
|
|
#include "min_sd.h"
|
|
|
|
#include "atom.h"
|
|
|
|
#include "update.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "timer.h"
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
using namespace LAMMPS_NS;
|
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
#define EPS 1.0e-8
|
|
|
|
|
|
|
|
enum{FAIL,MAXITER,MAXEVAL,ETOL,FTOL}; // same as in other min classes
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
MinSD::MinSD(LAMMPS *lmp) : MinCG(lmp) {}
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
minimization via steepest descent
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
int MinSD::iterate(int n)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2008-04-15 04:50:48 +08:00
|
|
|
int i,fail,ntimestep;
|
|
|
|
double dot,dotall;
|
2007-02-22 06:21:06 +08:00
|
|
|
double *f;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2007-02-22 06:21:06 +08:00
|
|
|
f = atom->f[0];
|
2006-09-28 03:51:33 +08:00
|
|
|
for (int i = 0; i < ndof; i++) h[i] = f[i];
|
|
|
|
|
|
|
|
neval = 0;
|
|
|
|
|
|
|
|
for (niter = 0; niter < n; niter++) {
|
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
ntimestep = ++update->ntimestep;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
// line minimization along direction h from current atom->x
|
|
|
|
|
2007-02-22 06:21:06 +08:00
|
|
|
eprevious = ecurrent;
|
2008-04-15 04:50:48 +08:00
|
|
|
fail = (this->*linemin)(ndof,atom->x[0],h,ecurrent,dmin,dmax,
|
|
|
|
alpha_final,neval);
|
|
|
|
if (fail) return FAIL;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
// function evaluation criterion
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
if (neval >= update->max_eval) return MAXEVAL;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
// energy tolerance criterion
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
if (fabs(ecurrent-eprevious) <=
|
|
|
|
update->etol * 0.5*(fabs(ecurrent) + fabs(eprevious) + EPS))
|
|
|
|
return ETOL;
|
|
|
|
|
|
|
|
// force tolerance criterion
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2007-02-22 06:21:06 +08:00
|
|
|
f = atom->f[0];
|
2006-09-28 03:51:33 +08:00
|
|
|
dot = 0.0;
|
|
|
|
for (i = 0; i < ndof; i++) dot += f[i]*f[i];
|
|
|
|
MPI_Allreduce(&dot,&dotall,1,MPI_DOUBLE,MPI_SUM,world);
|
2008-04-15 04:50:48 +08:00
|
|
|
|
|
|
|
if (dotall < update->ftol * update->ftol) return FTOL;
|
|
|
|
|
|
|
|
// set h to new f = -Grad(x)
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ndof; i++) h[i] = f[i];
|
|
|
|
|
|
|
|
// output for thermo, dump, restart files
|
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
if (output->next == ntimestep) {
|
2006-09-28 03:51:33 +08:00
|
|
|
timer->stamp();
|
2008-04-15 04:50:48 +08:00
|
|
|
output->write(ntimestep);
|
2006-09-28 03:51:33 +08:00
|
|
|
timer->stamp(TIME_OUTPUT);
|
|
|
|
}
|
|
|
|
}
|
2008-04-15 04:50:48 +08:00
|
|
|
|
|
|
|
return MAXITER;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|