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.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2018-04-28 05:41:04 +08:00
|
|
|
#include <cmath>
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "min_sd.h"
|
|
|
|
#include "update.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "timer.h"
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
using namespace LAMMPS_NS;
|
|
|
|
|
2009-04-04 03:46:03 +08:00
|
|
|
// EPS_ENERGY = minimum normalization for energy tolerance
|
|
|
|
|
2008-04-15 06:13:25 +08:00
|
|
|
#define EPS_ENERGY 1.0e-8
|
2008-04-15 04:50:48 +08:00
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
MinSD::MinSD(LAMMPS *lmp) : MinLineSearch(lmp) {}
|
2007-01-30 08:22:05 +08:00
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
minimization via steepest descent
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2010-06-02 23:41:31 +08:00
|
|
|
int MinSD::iterate(int maxiter)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2009-08-15 04:54:10 +08:00
|
|
|
int i,m,n,fail,ntimestep;
|
|
|
|
double fdotf;
|
|
|
|
double *fatom,*hatom;
|
|
|
|
|
|
|
|
// initialize working vectors
|
|
|
|
|
2010-05-22 04:05:47 +08:00
|
|
|
for (i = 0; i < nvec; i++) h[i] = fvec[i];
|
2009-08-15 04:54:10 +08:00
|
|
|
if (nextra_atom)
|
|
|
|
for (m = 0; m < nextra_atom; m++) {
|
|
|
|
fatom = fextra_atom[m];
|
|
|
|
hatom = hextra_atom[m];
|
|
|
|
n = extra_nlen[m];
|
|
|
|
for (i = 0; i < n; i++) hatom[i] = fatom[i];
|
|
|
|
}
|
|
|
|
if (nextra_global)
|
|
|
|
for (i = 0; i < nextra_global; i++) hextra[i] = fextra[i];
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2010-06-02 23:41:31 +08:00
|
|
|
for (int iter = 0; iter < maxiter; iter++) {
|
2015-10-23 06:06:49 +08:00
|
|
|
|
2016-06-18 07:48:15 +08:00
|
|
|
if (timer->check_timeout(niter))
|
|
|
|
return TIMEOUT;
|
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
ntimestep = ++update->ntimestep;
|
2010-06-02 23:41:31 +08:00
|
|
|
niter++;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
// line minimization along h from current position x
|
|
|
|
// h = downhill gradient direction
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2007-02-22 06:21:06 +08:00
|
|
|
eprevious = ecurrent;
|
2010-06-02 23:41:31 +08:00
|
|
|
fail = (this->*linemin)(ecurrent,alpha_final);
|
2009-02-28 05:23:34 +08:00
|
|
|
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
|
|
|
|
2012-06-07 06:47:51 +08:00
|
|
|
if (fabs(ecurrent-eprevious) <
|
|
|
|
update->etol * 0.5*(fabs(ecurrent) + fabs(eprevious) + EPS_ENERGY))
|
2008-04-15 04:50:48 +08:00
|
|
|
return ETOL;
|
|
|
|
|
|
|
|
// force tolerance criterion
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-15 04:54:10 +08:00
|
|
|
fdotf = fnorm_sqr();
|
|
|
|
if (fdotf < update->ftol*update->ftol) return FTOL;
|
2008-04-15 04:50:48 +08:00
|
|
|
|
2009-02-26 07:58:04 +08:00
|
|
|
// set new search direction h to f = -Grad(x)
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2010-05-22 04:05:47 +08:00
|
|
|
for (i = 0; i < nvec; i++) h[i] = fvec[i];
|
2009-08-15 04:54:10 +08:00
|
|
|
if (nextra_atom)
|
|
|
|
for (m = 0; m < nextra_atom; m++) {
|
2012-06-07 06:47:51 +08:00
|
|
|
fatom = fextra_atom[m];
|
|
|
|
hatom = hextra_atom[m];
|
|
|
|
n = extra_nlen[m];
|
|
|
|
for (i = 0; i < n; i++) hatom[i] = fatom[i];
|
2009-08-15 04:54:10 +08:00
|
|
|
}
|
|
|
|
if (nextra_global)
|
|
|
|
for (i = 0; i < nextra_global; i++) hextra[i] = fextra[i];
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
// 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);
|
2015-08-29 04:00:56 +08:00
|
|
|
timer->stamp(Timer::OUTPUT);
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2008-04-15 04:50:48 +08:00
|
|
|
return MAXITER;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|