git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1751 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -25,7 +25,7 @@ class Min : protected Pointers {
|
|||||||
double alpha_final;
|
double alpha_final;
|
||||||
int niter,neval;
|
int niter,neval;
|
||||||
char *stopstr;
|
char *stopstr;
|
||||||
double dmin,dmax;
|
double dmax;
|
||||||
int linestyle,lineiter;
|
int linestyle,lineiter;
|
||||||
|
|
||||||
Min(class LAMMPS *);
|
Min(class LAMMPS *);
|
||||||
|
|||||||
@ -294,8 +294,7 @@ int MinCG::iterate(int n)
|
|||||||
// line minimization along direction h from current atom->x
|
// line minimization along direction h from current atom->x
|
||||||
|
|
||||||
eprevious = ecurrent;
|
eprevious = ecurrent;
|
||||||
fail = (this->*linemin)(ndof,atom->x[0],h,ecurrent,dmin,dmax,
|
fail = (this->*linemin)(ndof,atom->x[0],h,ecurrent,dmax,alpha_final,neval);
|
||||||
alpha_final,neval);
|
|
||||||
if (fail) return FAIL;
|
if (fail) return FAIL;
|
||||||
|
|
||||||
// function evaluation criterion
|
// function evaluation criterion
|
||||||
@ -479,7 +478,7 @@ void MinCG::force_clear()
|
|||||||
x = ptr to atom->x[0] as vector
|
x = ptr to atom->x[0] as vector
|
||||||
dir = search direction as vector
|
dir = search direction as vector
|
||||||
eng = current energy at initial x
|
eng = current energy at initial x
|
||||||
min/max dist = min/max distance to move any atom coord
|
maxdist = max distance to move any atom coord
|
||||||
output: return 0 if successful move, non-zero alpha alpha
|
output: return 0 if successful move, non-zero alpha alpha
|
||||||
return 1 if failed, alpha = 0.0
|
return 1 if failed, alpha = 0.0
|
||||||
alpha = distance moved along dir to set x to minimun eng config
|
alpha = distance moved along dir to set x to minimun eng config
|
||||||
@ -502,45 +501,48 @@ void MinCG::force_clear()
|
|||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int MinCG::linemin_backtrack(int n, double *x, double *dir, double eng,
|
int MinCG::linemin_backtrack(int n, double *x, double *dir, double eng,
|
||||||
double mindist, double maxdist,
|
double maxdist, double &alpha, int &nfunc)
|
||||||
double &alpha, int &nfunc)
|
|
||||||
{
|
{
|
||||||
int i,ilist,m;
|
int i,m;
|
||||||
double fdotdirme,fdotdirall,fme,fmax,eoriginal,alphamax;
|
|
||||||
|
|
||||||
// stopping criterion, must be scaled by normflag
|
// stopping criterion, must be scaled by normflag
|
||||||
|
|
||||||
double *f = atom->f[0];
|
double *f = atom->f[0];
|
||||||
fdotdirme = 0.0;
|
double fdotdirme = 0.0;
|
||||||
for (i = 0; i < n; i++) fdotdirme += f[i]*dir[i];
|
for (i = 0; i < n; i++) fdotdirme += f[i]*dir[i];
|
||||||
|
double fdotdirall;
|
||||||
MPI_Allreduce(&fdotdirme,&fdotdirall,1,MPI_DOUBLE,MPI_SUM,world);
|
MPI_Allreduce(&fdotdirme,&fdotdirall,1,MPI_DOUBLE,MPI_SUM,world);
|
||||||
if (output->thermo->normflag) fdotdirall /= atom->natoms;
|
if (output->thermo->normflag) fdotdirall /= atom->natoms;
|
||||||
|
|
||||||
// alphamax = step that moves some atom coord by maxdist
|
// alphamax = step that moves some atom coord by maxdist
|
||||||
|
|
||||||
fme = 0.0;
|
double fme = 0.0;
|
||||||
for (i = 0; i < n; i++) fme = MAX(fme,fabs(dir[i]));
|
for (i = 0; i < n; i++) fme = MAX(fme,fabs(dir[i]));
|
||||||
|
double fmax;
|
||||||
MPI_Allreduce(&fme,&fmax,1,MPI_DOUBLE,MPI_MAX,world);
|
MPI_Allreduce(&fme,&fmax,1,MPI_DOUBLE,MPI_MAX,world);
|
||||||
if (fmax == 0.0) return 1;
|
if (fmax == 0.0) return 1;
|
||||||
|
|
||||||
alphamax = maxdist/fmax;
|
double alphamax = maxdist/fmax;
|
||||||
|
|
||||||
// reduce alpha by factor of ALPHA_REDUCE until energy decrease is sufficient
|
// reduce alpha by ALPHA_REDUCE until energy decrease is sufficient
|
||||||
|
|
||||||
eoriginal = eng;
|
double eoriginal = eng;
|
||||||
alpha = alphamax;
|
alpha = alphamax;
|
||||||
|
double alpha_previous = 0.0;
|
||||||
|
double delta;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
for (i = 0; i < n; i++) x[i] += alpha*dir[i];
|
delta = alpha - alpha_previous;
|
||||||
|
for (i = 0; i < n; i++) x[i] += delta*dir[i];
|
||||||
eng_force(&n,&x,&dir,&eng);
|
eng_force(&n,&x,&dir,&eng);
|
||||||
nfunc++;
|
nfunc++;
|
||||||
|
|
||||||
if (eng <= eoriginal - BACKTRACK_SLOPE*alpha*fdotdirall) return 0;
|
if (eng <= eoriginal - BACKTRACK_SLOPE*alpha*fdotdirall) return 0;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) x[i] -= alpha*dir[i];
|
alpha_previous = alpha;
|
||||||
|
|
||||||
alpha *= ALPHA_REDUCE;
|
alpha *= ALPHA_REDUCE;
|
||||||
if (alpha == 0.0) {
|
if (alpha == 0.0) {
|
||||||
|
for (i = 0; i < n; i++) x[i] -= alpha_previous*dir[i];
|
||||||
eng_force(&n,&x,&dir,&eng);
|
eng_force(&n,&x,&dir,&eng);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/min_cg.h
12
src/min_cg.h
@ -32,18 +32,20 @@ class MinCG : public Min {
|
|||||||
int triclinic; // 0 if domain is orthog, 1 if triclinic
|
int triclinic; // 0 if domain is orthog, 1 if triclinic
|
||||||
|
|
||||||
class FixMinimize *fix_minimize; // fix that stores gradient vecs
|
class FixMinimize *fix_minimize; // fix that stores gradient vecs
|
||||||
class Compute *pe_compute; // compute for potential energy
|
class Compute *pe_compute; // compute for potential energy
|
||||||
double ecurrent; // current potential energy
|
double ecurrent; // current potential energy
|
||||||
double mindist,maxdist; // min/max dist for coord delta in line search
|
double mindist,maxdist; // min/max dist for coord delta in line search
|
||||||
|
|
||||||
int ndof; // # of degrees-of-freedom on this proc
|
int ndof; // # of degrees-of-freedom on this proc
|
||||||
double *g,*h; // local portion of gradient, searchdir vectors
|
double *g,*h; // local portion of gradient, searchdir vectors
|
||||||
|
|
||||||
|
// ptr to linemin functions
|
||||||
|
|
||||||
typedef int (MinCG::*FnPtr)(int, double *, double *, double,
|
typedef int (MinCG::*FnPtr)(int, double *, double *, double,
|
||||||
double, double, double &, int &);
|
double, double &, int &);
|
||||||
FnPtr linemin; // ptr to linemin functions
|
FnPtr linemin;
|
||||||
int linemin_backtrack(int, double *, double *, double,
|
int linemin_backtrack(int, double *, double *, double,
|
||||||
double, double, double &, int &);
|
double, double &, int &);
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void setup_vectors();
|
void setup_vectors();
|
||||||
|
|||||||
@ -51,8 +51,7 @@ int MinSD::iterate(int n)
|
|||||||
// line minimization along direction h from current atom->x
|
// line minimization along direction h from current atom->x
|
||||||
|
|
||||||
eprevious = ecurrent;
|
eprevious = ecurrent;
|
||||||
fail = (this->*linemin)(ndof,atom->x[0],h,ecurrent,dmin,dmax,
|
fail = (this->*linemin)(ndof,atom->x[0],h,ecurrent,dmax,alpha_final,neval);
|
||||||
alpha_final,neval);
|
|
||||||
if (fail) return FAIL;
|
if (fail) return FAIL;
|
||||||
|
|
||||||
// function evaluation criterion
|
// function evaluation criterion
|
||||||
|
|||||||
Reference in New Issue
Block a user