forked from lijiext/lammps
try to fix code processing norms for minimizers that looked incorrect
This commit is contained in:
parent
29f2569ee2
commit
661238f627
18
src/min.cpp
18
src/min.cpp
|
@ -852,20 +852,22 @@ double Min::fnorm_max()
|
||||||
for (int m = 0; m < nextra_atom; m++) {
|
for (int m = 0; m < nextra_atom; m++) {
|
||||||
fatom = fextra_atom[m];
|
fatom = fextra_atom[m];
|
||||||
n = extra_nlen[m];
|
n = extra_nlen[m];
|
||||||
for (i = 0; i < n; i+=3)
|
for (i = 0; i < n; i+=3) {
|
||||||
fdotf = fvec[i]*fvec[i]+fvec[i+1]*fvec[i+1]+fvec[i+2]*fvec[i+2];
|
fdotf = fatom[i]*fatom[i]+fatom[i+1]*fatom[i+1]+fatom[i+2]*fatom[i+2];
|
||||||
local_norm_max = MAX(fdotf,local_norm_max);
|
local_norm_max = MAX(fdotf,local_norm_max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double norm_max = 0.0;
|
double norm_max = 0.0;
|
||||||
MPI_Allreduce(&local_norm_max,&norm_max,1,MPI_DOUBLE,MPI_MAX,world);
|
MPI_Allreduce(&local_norm_max,&norm_max,1,MPI_DOUBLE,MPI_MAX,world);
|
||||||
|
|
||||||
if (nextra_global)
|
if (nextra_global) {
|
||||||
for (i = 0; i < n; i+=3)
|
for (i = 0; i < nextra_global; i+=3) {
|
||||||
fdotf = fvec[i]*fvec[i]+fvec[i+1]*fvec[i+1]+fvec[i+2]*fvec[i+2];
|
fdotf = fextra[i]*fextra[i];
|
||||||
norm_max = MAX(fdotf,norm_max);
|
norm_max = MAX(fdotf,norm_max);
|
||||||
|
}
|
||||||
|
}
|
||||||
return norm_max;
|
return norm_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -906,14 +908,14 @@ double Min::total_torque()
|
||||||
|
|
||||||
double Min::inf_torque()
|
double Min::inf_torque()
|
||||||
{
|
{
|
||||||
double fmsq,fmaxsqone,fmaxsqall;
|
double fmaxsqone,fmaxsqall;
|
||||||
int nlocal = atom->nlocal;
|
int nlocal = atom->nlocal;
|
||||||
double hbar = force->hplanck/MY_2PI;
|
double hbar = force->hplanck/MY_2PI;
|
||||||
double tx,ty,tz;
|
double tx,ty,tz;
|
||||||
double **sp = atom->sp;
|
double **sp = atom->sp;
|
||||||
double **fm = atom->fm;
|
double **fm = atom->fm;
|
||||||
|
|
||||||
fmsq = fmaxsqone = fmaxsqall = 0.0;
|
fmaxsqone = fmaxsqall = 0.0;
|
||||||
for (int i = 0; i < nlocal; i++) {
|
for (int i = 0; i < nlocal; i++) {
|
||||||
tx = fm[i][1]*sp[i][2] - fm[i][2]*sp[i][1];
|
tx = fm[i][1]*sp[i][2] - fm[i][2]*sp[i][1];
|
||||||
ty = fm[i][2]*sp[i][0] - fm[i][0]*sp[i][2];
|
ty = fm[i][2]*sp[i][0] - fm[i][0]*sp[i][2];
|
||||||
|
|
|
@ -251,10 +251,16 @@ int MinFire::iterate(int maxiter)
|
||||||
// sync across replicas if running multi-replica minimization
|
// sync across replicas if running multi-replica minimization
|
||||||
|
|
||||||
if (update->ftol > 0.0) {
|
if (update->ftol > 0.0) {
|
||||||
if (normstyle == MAX) fdotf = fnorm_max(); // max force norm
|
if (normstyle == MAX) {
|
||||||
else if (normstyle == INF) fdotf = fnorm_inf(); // inf force norm
|
fdotfloc = fnorm_max(); // max force norm
|
||||||
else if (normstyle == TWO) fdotf = fnorm_sqr(); // Euclidean force 2-norm
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
else error->all(FLERR,"Illegal min_modify command");
|
} else if (normstyle == INF) {
|
||||||
|
fdotfloc = fnorm_inf(); // inf force norm
|
||||||
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
|
} else if (normstyle == TWO) {
|
||||||
|
fdotf = fnorm_sqr(); // Euclidean force 2-norm
|
||||||
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||||
|
} else error->all(FLERR,"Illegal min_modify command");
|
||||||
if (update->multireplica == 0) {
|
if (update->multireplica == 0) {
|
||||||
if (fdotf < update->ftol*update->ftol) return FTOL;
|
if (fdotf < update->ftol*update->ftol) return FTOL;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -216,10 +216,16 @@ int MinQuickMin::iterate(int maxiter)
|
||||||
// sync across replicas if running multi-replica minimization
|
// sync across replicas if running multi-replica minimization
|
||||||
|
|
||||||
if (update->ftol > 0.0) {
|
if (update->ftol > 0.0) {
|
||||||
if (normstyle == MAX) fdotfloc = fnorm_max(); // max force norm
|
if (normstyle == MAX) {
|
||||||
else if (normstyle == INF) fdotfloc = fnorm_inf(); // inf force norm
|
fdotfloc = fnorm_max(); // max force norm
|
||||||
else if (normstyle == TWO) fdotfloc = fnorm_sqr(); // Euclidean force 2-norm
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
else error->all(FLERR,"Illegal min_modify command");
|
} else if (normstyle == INF) {
|
||||||
|
fdotfloc = fnorm_inf(); // inf force norm
|
||||||
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
|
} else if (normstyle == TWO) {
|
||||||
|
fdotfloc = fnorm_sqr(); // Euclidean force 2-norm
|
||||||
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||||
|
} else error->all(FLERR,"Illegal min_modify command");
|
||||||
if (update->multireplica == 0) {
|
if (update->multireplica == 0) {
|
||||||
if (fdotf < update->ftol*update->ftol) return FTOL;
|
if (fdotf < update->ftol*update->ftol) return FTOL;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
#include "universe.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
|
@ -77,11 +78,18 @@ int MinSD::iterate(int maxiter)
|
||||||
return ETOL;
|
return ETOL;
|
||||||
|
|
||||||
// force tolerance criterion
|
// force tolerance criterion
|
||||||
|
// sync across replicas if running multi-replica minimization
|
||||||
|
|
||||||
if (normstyle == MAX) fdotf = fnorm_max(); // max force norm
|
if (normstyle == MAX) {
|
||||||
else if (normstyle == INF) fdotf = fnorm_inf(); // infinite force norm
|
fdotfloc = fnorm_max(); // max force norm
|
||||||
else if (normstyle == TWO) fdotf = fnorm_sqr(); // Euclidean force 2-norm
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
else error->all(FLERR,"Illegal min_modify command");
|
} else if (normstyle == INF) {
|
||||||
|
fdotfloc = fnorm_inf(); // infinite force norm
|
||||||
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
|
} else if (normstyle == TWO) {
|
||||||
|
fdotfloc = fnorm_sqr(); // Euclidean force 2-norm
|
||||||
|
MPI_Allreduce(&fdotfloc,&fdotf,1,MPI_DOUBLE,MPI_MAX,universe->uworld);
|
||||||
|
} else error->all(FLERR,"Illegal min_modify command");
|
||||||
if (fdotf < update->ftol*update->ftol) return FTOL;
|
if (fdotf < update->ftol*update->ftol) return FTOL;
|
||||||
|
|
||||||
// set new search direction h to f = -Grad(x)
|
// set new search direction h to f = -Grad(x)
|
||||||
|
|
Loading…
Reference in New Issue