handle invalid lookup for bond/angle tabulation
This commit is contained in:
@ -609,18 +609,18 @@ double AngleTable::splint(double *xa, double *ya, double *y2a, int n, double x)
|
|||||||
|
|
||||||
void AngleTable::uf_lookup(int type, double x, double &u, double &f)
|
void AngleTable::uf_lookup(int type, double x, double &u, double &f)
|
||||||
{
|
{
|
||||||
int itable;
|
|
||||||
double fraction,a,b;
|
double fraction,a,b;
|
||||||
|
|
||||||
Table *tb = &tables[tabindex[type]];
|
const Table *tb = &tables[tabindex[type]];
|
||||||
|
const int itable = static_cast<int> (x * tb->invdelta);
|
||||||
|
|
||||||
if (tabstyle == LINEAR) {
|
if ((itable < 0) || (itable >= tablength) || (!ISFINITE(itable))) {
|
||||||
itable = static_cast<int> ( x * tb->invdelta);
|
error->one(FLERR,"Illegal angle in angle style table");
|
||||||
|
} else if (tabstyle == LINEAR) {
|
||||||
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
||||||
u = tb->e[itable] + fraction*tb->de[itable];
|
u = tb->e[itable] + fraction*tb->de[itable];
|
||||||
f = tb->f[itable] + fraction*tb->df[itable];
|
f = tb->f[itable] + fraction*tb->df[itable];
|
||||||
} else if (tabstyle == SPLINE) {
|
} else if (tabstyle == SPLINE) {
|
||||||
itable = static_cast<int> ( x * tb->invdelta);
|
|
||||||
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
||||||
|
|
||||||
b = (x - tb->ang[itable]) * tb->invdelta;
|
b = (x - tb->ang[itable]) * tb->invdelta;
|
||||||
@ -640,17 +640,15 @@ void AngleTable::uf_lookup(int type, double x, double &u, double &f)
|
|||||||
|
|
||||||
void AngleTable::u_lookup(int type, double x, double &u)
|
void AngleTable::u_lookup(int type, double x, double &u)
|
||||||
{
|
{
|
||||||
int itable;
|
|
||||||
double fraction,a,b;
|
double fraction,a,b;
|
||||||
|
|
||||||
Table *tb = &tables[tabindex[type]];
|
const Table *tb = &tables[tabindex[type]];
|
||||||
|
const int itable = static_cast<int> ( x * tb->invdelta);
|
||||||
|
|
||||||
if (tabstyle == LINEAR) {
|
if (tabstyle == LINEAR) {
|
||||||
itable = static_cast<int> ( x * tb->invdelta);
|
|
||||||
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
||||||
u = tb->e[itable] + fraction*tb->de[itable];
|
u = tb->e[itable] + fraction*tb->de[itable];
|
||||||
} else if (tabstyle == SPLINE) {
|
} else if (tabstyle == SPLINE) {
|
||||||
itable = static_cast<int> ( x * tb->invdelta);
|
|
||||||
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
fraction = (x - tb->ang[itable]) * tb->invdelta;
|
||||||
|
|
||||||
b = (x - tb->ang[itable]) * tb->invdelta;
|
b = (x - tb->ang[itable]) * tb->invdelta;
|
||||||
|
|||||||
@ -590,29 +590,28 @@ double BondTable::splint(double *xa, double *ya, double *y2a, int n, double x)
|
|||||||
|
|
||||||
void BondTable::uf_lookup(int type, double x, double &u, double &f)
|
void BondTable::uf_lookup(int type, double x, double &u, double &f)
|
||||||
{
|
{
|
||||||
int itable;
|
|
||||||
double fraction,a,b;
|
double fraction,a,b;
|
||||||
char estr[128];
|
char estr[128];
|
||||||
|
|
||||||
Table *tb = &tables[tabindex[type]];
|
const Table *tb = &tables[tabindex[type]];
|
||||||
if (x < tb->lo) {
|
const int itable = static_cast<int> ((x - tb->lo) * tb->invdelta);
|
||||||
|
if (itable < 0) {
|
||||||
sprintf(estr,"Bond length < table inner cutoff: "
|
sprintf(estr,"Bond length < table inner cutoff: "
|
||||||
"type %d length %g",type,x);
|
"type %d length %g",type,x);
|
||||||
error->one(FLERR,estr);
|
error->one(FLERR,estr);
|
||||||
}
|
} else if (itable >= tablength) {
|
||||||
if (x > tb->hi) {
|
|
||||||
sprintf(estr,"Bond length > table outer cutoff: "
|
sprintf(estr,"Bond length > table outer cutoff: "
|
||||||
"type %d length %g",type,x);
|
"type %d length %g",type,x);
|
||||||
error->one(FLERR,estr);
|
error->one(FLERR,estr);
|
||||||
|
} else if (!ISFINITE(itable)) {
|
||||||
|
error->one(FLERR,"Illegal bond length in bond style table");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabstyle == LINEAR) {
|
if (tabstyle == LINEAR) {
|
||||||
itable = static_cast<int> ((x - tb->lo) * tb->invdelta);
|
|
||||||
fraction = (x - tb->r[itable]) * tb->invdelta;
|
fraction = (x - tb->r[itable]) * tb->invdelta;
|
||||||
u = tb->e[itable] + fraction*tb->de[itable];
|
u = tb->e[itable] + fraction*tb->de[itable];
|
||||||
f = tb->f[itable] + fraction*tb->df[itable];
|
f = tb->f[itable] + fraction*tb->df[itable];
|
||||||
} else if (tabstyle == SPLINE) {
|
} else if (tabstyle == SPLINE) {
|
||||||
itable = static_cast<int> ((x - tb->lo) * tb->invdelta);
|
|
||||||
fraction = (x - tb->r[itable]) * tb->invdelta;
|
fraction = (x - tb->r[itable]) * tb->invdelta;
|
||||||
|
|
||||||
b = (x - tb->r[itable]) * tb->invdelta;
|
b = (x - tb->r[itable]) * tb->invdelta;
|
||||||
@ -633,19 +632,22 @@ void BondTable::uf_lookup(int type, double x, double &u, double &f)
|
|||||||
|
|
||||||
void BondTable::u_lookup(int type, double x, double &u)
|
void BondTable::u_lookup(int type, double x, double &u)
|
||||||
{
|
{
|
||||||
int itable;
|
|
||||||
double fraction,a,b;
|
double fraction,a,b;
|
||||||
|
|
||||||
Table *tb = &tables[tabindex[type]];
|
if (!ISFINITE(x)) {
|
||||||
|
u = 0.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Table *tb = &tables[tabindex[type]];
|
||||||
x = MAX(x,tb->lo);
|
x = MAX(x,tb->lo);
|
||||||
x = MIN(x,tb->hi);
|
x = MIN(x,tb->hi);
|
||||||
|
const int itable = static_cast<int> ((x - tb->lo) * tb->invdelta);
|
||||||
|
|
||||||
if (tabstyle == LINEAR) {
|
if (tabstyle == LINEAR) {
|
||||||
itable = static_cast<int> ((x - tb->lo) * tb->invdelta);
|
|
||||||
fraction = (x - tb->r[itable]) * tb->invdelta;
|
fraction = (x - tb->r[itable]) * tb->invdelta;
|
||||||
u = tb->e[itable] + fraction*tb->de[itable];
|
u = tb->e[itable] + fraction*tb->de[itable];
|
||||||
} else if (tabstyle == SPLINE) {
|
} else if (tabstyle == SPLINE) {
|
||||||
itable = static_cast<int> ((x - tb->lo) * tb->invdelta);
|
|
||||||
fraction = (x - tb->r[itable]) * tb->invdelta;
|
fraction = (x - tb->r[itable]) * tb->invdelta;
|
||||||
|
|
||||||
b = (x - tb->r[itable]) * tb->invdelta;
|
b = (x - tb->r[itable]) * tb->invdelta;
|
||||||
|
|||||||
Reference in New Issue
Block a user