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;
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
#define EPS 1.0e-6
|
|
|
|
|
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
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void MinSD::iterate(int n)
|
|
|
|
{
|
|
|
|
int i,fail;
|
|
|
|
double alpha,dot,dotall;
|
|
|
|
|
|
|
|
for (int i = 0; i < ndof; i++) h[i] = f[i];
|
2007-02-22 04:57:31 +08:00
|
|
|
for (i = 0; i < ndof_extra; i++) hextra[i] = fextra[i];
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
neval = 0;
|
|
|
|
|
|
|
|
for (niter = 0; niter < n; niter++) {
|
|
|
|
|
|
|
|
update->ntimestep++;
|
|
|
|
|
|
|
|
// line minimization along direction h from current atom->x
|
|
|
|
|
2007-02-22 04:57:31 +08:00
|
|
|
eprevious = energy;
|
|
|
|
fail = (this->*linemin)(neval);
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
// if max_eval exceeded, all done
|
|
|
|
// if linemin failed or energy did not decrease sufficiently, all done
|
|
|
|
|
|
|
|
if (neval >= update->max_eval) break;
|
|
|
|
|
2007-02-22 04:57:31 +08:00
|
|
|
if (fail || fabs(energy-eprevious) <=
|
|
|
|
update->tolerance * 0.5*(fabs(energy) + fabs(eprevious) + EPS))
|
2006-09-28 03:51:33 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set h to new f = -Grad(x)
|
|
|
|
// done if size sq of grad vector < EPS
|
|
|
|
|
|
|
|
dot = 0.0;
|
|
|
|
for (i = 0; i < ndof; i++) dot += f[i]*f[i];
|
|
|
|
MPI_Allreduce(&dot,&dotall,1,MPI_DOUBLE,MPI_SUM,world);
|
2007-02-22 04:57:31 +08:00
|
|
|
for (i = 0; i < ndof_extra; i++) dotall += fextra[i]*fextra[i];
|
2006-09-28 03:51:33 +08:00
|
|
|
if (dotall < EPS) break;
|
|
|
|
|
|
|
|
for (i = 0; i < ndof; i++) h[i] = f[i];
|
2007-02-22 04:57:31 +08:00
|
|
|
for (i = 0; i < ndof_extra; i++) hextra[i] = fextra[i];
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
// output for thermo, dump, restart files
|
|
|
|
|
|
|
|
if (output->next == update->ntimestep) {
|
|
|
|
timer->stamp();
|
|
|
|
output->write(update->ntimestep);
|
|
|
|
timer->stamp(TIME_OUTPUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|