git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@26 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
76
src/min_sd.cpp
Normal file
76
src/min_sd.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
www.cs.sandia.gov/~sjplimp/lammps.html
|
||||
Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
|
||||
|
||||
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"
|
||||
|
||||
#define EPS 1.0e-6
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
minimization via steepest descent
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void MinSD::iterate(int n)
|
||||
{
|
||||
int i,fail;
|
||||
double alpha,dot,dotall;
|
||||
double *f;
|
||||
|
||||
f = atom->f[0];
|
||||
for (int i = 0; i < ndof; i++) h[i] = f[i];
|
||||
|
||||
neval = 0;
|
||||
|
||||
for (niter = 0; niter < n; niter++) {
|
||||
|
||||
update->ntimestep++;
|
||||
|
||||
// line minimization along direction h from current atom->x
|
||||
|
||||
eprevious = ecurrent;
|
||||
fail = (this->*linemin)(ndof,atom->x[0],h,ecurrent,dmin,dmax,alpha,neval);
|
||||
|
||||
// if max_eval exceeded, all done
|
||||
// if linemin failed or energy did not decrease sufficiently, all done
|
||||
|
||||
if (neval >= update->max_eval) break;
|
||||
|
||||
if (fail || fabs(ecurrent-eprevious) <=
|
||||
update->tolerance * 0.5*(fabs(ecurrent) + fabs(eprevious) + EPS))
|
||||
break;
|
||||
|
||||
// set h to new f = -Grad(x)
|
||||
// done if size sq of grad vector < EPS
|
||||
|
||||
f = atom->f[0];
|
||||
dot = 0.0;
|
||||
for (i = 0; i < ndof; i++) dot += f[i]*f[i];
|
||||
MPI_Allreduce(&dot,&dotall,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
if (dotall < EPS) break;
|
||||
|
||||
for (i = 0; i < ndof; i++) h[i] = f[i];
|
||||
|
||||
// output for thermo, dump, restart files
|
||||
|
||||
if (output->next == update->ntimestep) {
|
||||
timer->stamp();
|
||||
output->write(update->ntimestep);
|
||||
timer->stamp(TIME_OUTPUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user