Skip to content

Commit c790560

Browse files
authored
Merge pull request #129 from njzjz/relative
fix relative bug
2 parents 8c4c6e6 + 814a225 commit c790560

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

source/lib/include/NNPInter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ class NNPInterModelDevi
200200
void compute_std_f (vector<VALUETYPE> & std,
201201
const vector<VALUETYPE> & avg,
202202
const vector<vector<VALUETYPE> >& xx);
203+
void compute_relative_std_f (vector<VALUETYPE> & std,
204+
const vector<VALUETYPE> & avg,
205+
const VALUETYPE eps);
203206
private:
204207
unsigned numb_models;
205208
vector<Session*> sessions;

source/lib/src/NNPInter.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,3 +1690,22 @@ compute_std_f (vector<VALUETYPE> & std,
16901690
}
16911691
}
16921692

1693+
void
1694+
NNPInterModelDevi::
1695+
compute_relative_std_f (vector<VALUETYPE> &std,
1696+
const vector<VALUETYPE> &avg,
1697+
const VALUETYPE eps)
1698+
{
1699+
unsigned nloc = std.size();
1700+
for (unsigned ii = 0; ii < nloc; ++ii){
1701+
const VALUETYPE * tmp_avg = &(avg[ii*3]);
1702+
VALUETYPE vdiff[3];
1703+
vdiff[0] = tmp_avg[0];
1704+
vdiff[1] = tmp_avg[1];
1705+
vdiff[2] = tmp_avg[2];
1706+
VALUETYPE f_norm = sqrt(MathUtilities::dot(vdiff, vdiff));
1707+
// relative std = std/(abs(f)+eps)
1708+
std[ii] /= f_norm + eps;
1709+
}
1710+
}
1711+

source/lmp/pair_nnp.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ void PairNNP::compute(int eflag, int vflag)
450450
vector<double> tmp_avg_f;
451451
nnp_inter_model_devi.compute_avg (tmp_avg_f, all_force);
452452
nnp_inter_model_devi.compute_std_f (std_f, tmp_avg_f, all_force);
453+
if (out_rel == 1){
454+
nnp_inter_model_devi.compute_relative_std_f (std_f, tmp_avg_f, eps);
455+
}
453456
#else
454457
vector<float> tmp_avg_f_, std_f_;
455458
for (unsigned ii = 0; ii < all_force_.size(); ++ii){
@@ -461,6 +464,9 @@ void PairNNP::compute(int eflag, int vflag)
461464
nnp_inter_model_devi.compute_std_f (std_f_, tmp_avg_f_, all_force_);
462465
std_f.resize(std_f_.size());
463466
for (int dd = 0; dd < std_f_.size(); ++dd) std_f[dd] = std_f_[dd];
467+
if (out_rel == 1){
468+
nnp_inter_model_devi.compute_relative_std_f (std_f, tmp_avg_f_, eps);
469+
}
464470
#endif
465471
double min = numeric_limits<double>::max(), max = 0, avg = 0;
466472
ana_st(max, min, avg, std_f, nlocal);
@@ -514,16 +520,7 @@ void PairNNP::compute(int eflag, int vflag)
514520
// 1. If the atom_style is not atomic (e.g. charge), the order of std_f is different from that of atom ids.
515521
// 2. std_f is not gathered by MPI.
516522
for (int dd = 0; dd < all_nlocal; ++dd) {
517-
if (out_rel == 1){
518-
// relative std = std/(abs(f)+1)
519-
#ifdef HIGH_PREC
520-
fp << " " << setw(18) << std_f[dd] / (fabs(tmp_avg_f[dd]) + eps);
521-
#else
522-
fp << " " << setw(18) << std_f[dd] / (fabsf(tmp_avg_f_[dd]) + eps);
523-
#endif
524-
} else {
525523
fp << " " << setw(18) << std_f[dd];
526-
}
527524
}
528525
}
529526
fp << endl;

0 commit comments

Comments
 (0)