From 4033293e4224e2bd899761973aa2e770a1166caa Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Fri, 20 Sep 2024 03:36:40 +0900 Subject: [PATCH] refactor (#33) - build: set cpp_std to c++11 - fix: -Wzero-as-null-pointer-constant - fix: -Wlogical-not-parentheses - fix: modernize-redundant-void-arg - fix: -Wwritable-strings - refactor: performance-type-promotion-in-math-fn - refactor: readability-avoid-const-params-in-decls --------- Co-authored-by: Eisuke Kawashima --- include/damping/dftd_atm.h | 30 ++++++++++++------------- include/damping/dftd_rational.h | 12 +++++----- include/dftd_damping.h | 2 +- include/dftd_dispersion.h | 4 ++-- include/dftd_eeq.h | 4 ++-- include/dftd_geometry.h | 2 +- include/dftd_matrix.h | 40 ++++++++++++++++----------------- include/dftd_model.h | 6 ++--- include/dftd_ncoord.h | 18 +++++++-------- meson.build | 1 + src/dftd_dispersion.cpp | 24 ++++++++++---------- src/dftd_eeq.cpp | 16 ++++++------- src/dftd_model.cpp | 4 ++-- src/dftd_ncoord.cpp | 4 ++-- test/test_disp.cpp | 14 ++++++------ test/test_disp.h | 8 +++---- test/test_disp2.cpp | 10 ++++----- test/test_disp2.h | 8 +++---- test/test_grad.cpp | 14 ++++++------ test/test_grad.h | 10 ++++----- test/test_ncoord.cpp | 8 +++---- test/test_ncoord.h | 4 ++-- test/test_param.cpp | 8 +++---- test/test_param.h | 2 +- test/util.cpp | 8 +++---- 25 files changed, 131 insertions(+), 130 deletions(-) diff --git a/include/damping/dftd_atm.h b/include/damping/dftd_atm.h index 71a004a..3c3eb6d 100644 --- a/include/damping/dftd_atm.h +++ b/include/damping/dftd_atm.h @@ -30,11 +30,11 @@ namespace dftd4 { extern int get_atm_dispersion( const TMolecule &mol, const TMatrix &dist, - const double cutoff, - const double s9, - const double a1, - const double a2, - const double alp, + double cutoff, + double s9, + double a1, + double a2, + double alp, const TMatrix &c6, const TMatrix &dc6dcn, const TMatrix &dc6dq, @@ -48,11 +48,11 @@ extern int get_atm_dispersion( extern int get_atm_dispersion_energy( const TMolecule &mol, const TMatrix &dist, - const double cutoff, - const double s9, - const double a1, - const double a2, - const double alp, + double cutoff, + double s9, + double a1, + double a2, + double alp, const TMatrix &c6, TVector &energy ); @@ -60,11 +60,11 @@ extern int get_atm_dispersion_energy( extern int get_atm_dispersion_derivs( const TMolecule &mol, const TMatrix &dist, - const double cutoff, - const double s9, - const double a1, - const double a2, - const double alp, + double cutoff, + double s9, + double a1, + double a2, + double alp, const TMatrix &c6, const TMatrix &dc6dcn, const TMatrix &dc6dq, diff --git a/include/damping/dftd_rational.h b/include/damping/dftd_rational.h index 72b576f..b342940 100644 --- a/include/damping/dftd_rational.h +++ b/include/damping/dftd_rational.h @@ -24,15 +24,15 @@ namespace dftd4 { -extern inline double fdmpr_bj(const int n, const double r, const double c); -extern inline double fdmprdr_bj(const int n, const double r, const double c); +extern inline double fdmpr_bj(int n, double r, double c); +extern inline double fdmprdr_bj(int n, double r, double c); // Generic wrappers for two- and three-body dispersion extern int get_dispersion2( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, const dparam &par, const TMatrix &c6, const TMatrix &dc6dcn, @@ -47,7 +47,7 @@ extern int get_dispersion2( extern int get_dispersion3( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, const dparam &par, const TMatrix &c6, const TMatrix &dc6dcn, @@ -64,7 +64,7 @@ extern int get_dispersion3( extern int get_dispersion2_energy( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, const dparam &par, const TMatrix &c6, TVector &energy @@ -73,7 +73,7 @@ extern int get_dispersion2_energy( extern int get_dispersion2_derivs( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, const dparam &par, const TMatrix &c6, const TMatrix &dc6dcn, diff --git a/include/dftd_damping.h b/include/dftd_damping.h index 20c2679..70be056 100644 --- a/include/dftd_damping.h +++ b/include/dftd_damping.h @@ -37,6 +37,6 @@ namespace dftd4 { * @returns Exit status. */ extern int - d4par(const std::string func, dftd4::dparam &par, const bool latm = true); + d4par(const std::string func, dftd4::dparam &par, bool latm = true); } // namespace dftd4 diff --git a/include/dftd_dispersion.h b/include/dftd_dispersion.h index 6080e36..985e3a9 100644 --- a/include/dftd_dispersion.h +++ b/include/dftd_dispersion.h @@ -52,10 +52,10 @@ class dparam { */ extern int get_dispersion( const TMolecule &mol, - const int charge, + int charge, const TD4Model &d4, const dparam &par, - const TCutoff cutoff, + TCutoff cutoff, double &energy, double *GRAD ); diff --git a/include/dftd_eeq.h b/include/dftd_eeq.h index b05d7cb..2b82958 100644 --- a/include/dftd_eeq.h +++ b/include/dftd_eeq.h @@ -30,8 +30,8 @@ namespace dftd4 { extern int get_charges( const TMolecule &mol, const TMatrix &dist, - const int charge, - const double cutoff, + int charge, + double cutoff, TVector &q, TMatrix &dqdr, bool lgrad diff --git a/include/dftd_geometry.h b/include/dftd_geometry.h index b33ac9d..4fe817e 100644 --- a/include/dftd_geometry.h +++ b/include/dftd_geometry.h @@ -38,7 +38,7 @@ class TMolecule { at.New(NAtoms); } - void FreeMemory(void) { + void FreeMemory() { xyz.Delete(); at.Delete(); } diff --git a/include/dftd_matrix.h b/include/dftd_matrix.h index 2cae2e9..a47db62 100644 --- a/include/dftd_matrix.h +++ b/include/dftd_matrix.h @@ -33,15 +33,15 @@ template class TVector { TVector() { N = 0; - p = 0; + p = nullptr; ElementSize = sizeof(T); } ~TVector() { - if (p != 0) Delete(); + if (p != nullptr) Delete(); } void NewVector(int VectorLength) { if (VectorLength < 0) { std::exit(EXIT_FAILURE); } - if (p != 0 && N == VectorLength) { + if (p != nullptr && N == VectorLength) { Init(); } else { Delete(); @@ -58,9 +58,9 @@ template class TVector { void New(int VectorLength) { return NewVector(VectorLength); } void NewVec(int VectorLength) { return NewVector(VectorLength); } - void Delete(void) { - if (p != 0 && N != 0) { delete[] p; } - p = 0; + void Delete() { + if (p != nullptr && N != 0) { delete[] p; } + p = nullptr; N = 0; } void CopyVec(const TVector &v) { @@ -73,8 +73,8 @@ template class TVector { mem = (long int)N * ElementSize; std::memcpy(p, v.p, mem); } - void Init(void) { - if (p != 0) { + void Init() { + if (p != nullptr) { long int mem = (long int)N * ElementSize; std::memset(p, 0, mem); } @@ -104,20 +104,20 @@ template class TMatrix { TMatrix() { cols = 0; rows = 0; - p = 0; + p = nullptr; ElementSize = sizeof(T); } ~TMatrix() { - if (p != 0) Delete(); + if (p != nullptr) Delete(); } void NewMatrix(int r, int c) { if (r < 0 || c < 0) std::exit(EXIT_FAILURE); - if (p != 0 && r == rows && c == cols) { + if (p != nullptr && r == rows && c == cols) { Init(); } else { long int mem = (long int)r * (long int)c; - if (p != 0) Delete(); // Eventually delete old matrix + if (p != nullptr) Delete(); // Eventually delete old matrix if (mem == 0) return; // don't touch pointer if no memory is allocated @@ -136,26 +136,26 @@ template class TMatrix { void New(int r, int c) { return NewMatrix(r, c); } void NewMat(int r, int c) { return NewMatrix(r, c); } - void Delete(void) { - if (p != 0 && rows * cols != 0) { delete[] p; } + void Delete() { + if (p != nullptr && rows * cols != 0) { delete[] p; } rows = 0; cols = 0; - p = 0; + p = nullptr; } - void Init(void) { + void Init() { long int mem; - if (p != 0) { + if (p != nullptr) { mem = (long int)cols * (long int)rows * ElementSize; std::memset(p, 0, mem); } } - void Transpose(void) { + void Transpose() { T x; int i, j; - if (p != 0) { + if (p != nullptr) { if (rows == cols) { for (i = 0; i < rows; i++) { for (j = 0; j < i; j++) { @@ -191,7 +191,7 @@ template class TMatrix { std::memcpy(p, m.p, mem); } - void Print(char name[] = "unknown") { + void Print(const char name[] = "unknown") { printf("Matrix printed: %s (%d, %d)\n", name, rows, cols); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { diff --git a/include/dftd_model.h b/include/dftd_model.h index c72ef7d..4e109c4 100644 --- a/include/dftd_model.h +++ b/include/dftd_model.h @@ -77,12 +77,12 @@ class TD4Model { extern inline double trapzd(const double a[23], const double b[23]); extern inline double - weight_cn(const double wf, const double cn, const double cnref); + weight_cn(double wf, double cn, double cnref); extern inline double - zeta(const double a, const double c, const double qref, const double qmod); + zeta(double a, double c, double qref, double qmod); extern inline double - dzeta(const double a, const double c, const double qref, const double qmod); + dzeta(double a, double c, double qref, double qmod); extern int get_max_ref(const TMolecule &mol, int &mref); diff --git a/include/dftd_ncoord.h b/include/dftd_ncoord.h index b31d403..e434076 100644 --- a/include/dftd_ncoord.h +++ b/include/dftd_ncoord.h @@ -51,7 +51,7 @@ extern int calc_distances(const TMolecule &mol, TMatrix &dist); extern int get_ncoord_erf( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, TVector &cn, TMatrix &dcndr, bool lgrad = false @@ -69,7 +69,7 @@ extern int get_ncoord_erf( extern int ncoord_erf( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, TVector &cn ); @@ -87,7 +87,7 @@ extern int ncoord_erf( extern int dncoord_erf( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, TVector &cn, TMatrix &dcndr ); @@ -104,7 +104,7 @@ extern int dncoord_erf( extern int get_ncoord_d4( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, TVector &cn, TMatrix &dcndr, bool lgrad = false @@ -122,7 +122,7 @@ extern int get_ncoord_d4( extern int ncoord_d4( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, TVector &cn ); @@ -140,7 +140,7 @@ extern int ncoord_d4( extern int dncoord_d4( const TMolecule &mol, const TMatrix &dist, - const double cutoff, + double cutoff, TVector &cn, TMatrix &dcndr ); @@ -173,14 +173,14 @@ extern double derf_count(double k, double rr); * @param lgrad Flag for gradient. */ extern int cut_coordination_number( - const double cn_max, + double cn_max, TVector &cn, TMatrix &dcndr, bool lgrad ); -extern inline double log_cn_cut(const double cn_max, const double cn); +extern inline double log_cn_cut(double cn_max, double cn); -extern inline double dlog_cn_cut(const double cn_max, const double cn); +extern inline double dlog_cn_cut(double cn_max, double cn); }; // namespace dftd4 diff --git a/meson.build b/meson.build index 8b63715..79f10e1 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ project( license: 'LGPL3-or-later', meson_version: '>=0.51', default_options: [ + 'cpp_std=c++11', 'default_library=both', 'warning_level=3', ], diff --git a/src/dftd_dispersion.cpp b/src/dftd_dispersion.cpp index cf32c30..afbfa8a 100644 --- a/src/dftd_dispersion.cpp +++ b/src/dftd_dispersion.cpp @@ -69,22 +69,22 @@ int get_dispersion( // calculate partial charges from EEQ model info = get_charges(mol, dist, charge, cutoff.cn_eeq, q, dqdr, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // get the D4 coordination number info = get_ncoord_d4(mol, dist, cutoff.cn, cn, dcndr, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // maximum number of reference systems int mref{0}; info = get_max_ref(mol, mref); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // reference charges TMatrix refq; refq.NewMat(mref, mol.NAtoms); info = d4.set_refq_eeq(mol, refq); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; TMatrix gwvec; TMatrix dgwdcn; @@ -95,7 +95,7 @@ int get_dispersion( dgwdq.NewMat(mref, mol.NAtoms); } info = d4.weight_references(mol, cn, q, refq, gwvec, dgwdcn, dgwdq, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; TMatrix c6; TMatrix dc6dcn; @@ -107,7 +107,7 @@ int get_dispersion( } info = d4.get_atomic_c6(mol, gwvec, dgwdcn, dgwdq, c6, dc6dcn, dc6dq, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // -------------------------- // Two-body dispersion energy @@ -136,11 +136,11 @@ int get_dispersion( gradient, lgrad ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; if (lgrad) { info = BLAS_Add_Mat_x_Vec(gradient, dqdr, dEdq, false, 1.0); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; } dqdr.Delete(); @@ -162,7 +162,7 @@ int get_dispersion( dgwdq.NewMat(mref, mol.NAtoms); } info = d4.weight_references(mol, cn, q, refq, gwvec, dgwdcn, dgwdq, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; cn.Delete(); q.Delete(); @@ -176,7 +176,7 @@ int get_dispersion( } info = d4.get_atomic_c6(mol, gwvec, dgwdcn, dgwdq, c6, dc6dcn, dc6dq, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; gwvec.Delete(); dgwdcn.Delete(); @@ -197,7 +197,7 @@ int get_dispersion( gradient, lgrad ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; } else { cn.Delete(); q.Delete(); @@ -214,7 +214,7 @@ int get_dispersion( if (lgrad) { info = BLAS_Add_Mat_x_Vec(gradient, dcndr, dEdcn, false, 1.0); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; } dcndr.Delete(); diff --git a/src/dftd_eeq.cpp b/src/dftd_eeq.cpp index d84f396..6a098c3 100644 --- a/src/dftd_eeq.cpp +++ b/src/dftd_eeq.cpp @@ -149,11 +149,11 @@ int get_charges( // get the EEQ coordination number info = get_ncoord_erf(mol, dist, cutoff, cn, dcndr, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // corresponds to model%solve in Fortran info = eeq_chrgeq(mol, dist, charge, cn, q, dcndr, dqdr, lgrad, lverbose); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; dcndr.Delete(); cn.Delete(); @@ -301,10 +301,10 @@ int eeq_chrgeq( if (lgrad) dxdcn.NewVec(m); info = get_vrhs(mol, charge, cn, xvec, dxdcn, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = get_amat_0d(mol, dist, Amat); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; TVector vrhs; vrhs.NewVec(m); @@ -315,9 +315,9 @@ int eeq_chrgeq( // solve: A Q = X (Eq.4) -> Q = Ainv X info = BLAS_InvertMatrix(Ainv); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = BLAS_Add_Mat_x_Vec(vrhs, Ainv, xvec, false, 1.0); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // remove charge constraint (make vector smaller by one) for (int i = 0; i != mm; i++) { @@ -360,7 +360,7 @@ int eeq_chrgeq( atrace.NewMat(m, 3); info = get_damat_0d(mol, dist, vrhs, Amat, dAmat, atrace); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; for (int i = 0; i != mol.NAtoms; i++) { dAmat(3 * i, i) += atrace(i, 0); @@ -388,7 +388,7 @@ int eeq_chrgeq( } info = BLAS_Add_Mat_x_Mat(dqdr, dAmat, A, false, false, -1.0); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; dAmat.Delete(); } diff --git a/src/dftd_model.cpp b/src/dftd_model.cpp index a5d7579..ce39f02 100644 --- a/src/dftd_model.cpp +++ b/src/dftd_model.cpp @@ -190,12 +190,12 @@ int TD4Model::get_atomic_c6( // maximum number of reference systems int mref{0}; info = get_max_ref(mol, mref); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; TMatrix alpha; alpha.NewMat(mol.NAtoms, 23 * mref); info = set_refalpha_eeq(mol, alpha); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; if (lgrad) { double dc6dcni{0.0}, dc6dcnj{0.0}, dc6dqi{0.0}, dc6dqj{0.0}; diff --git a/src/dftd_ncoord.cpp b/src/dftd_ncoord.cpp index 307c8a6..de8d49d 100644 --- a/src/dftd_ncoord.cpp +++ b/src/dftd_ncoord.cpp @@ -262,10 +262,10 @@ int get_ncoord_erf( } else { info = ncoord_erf(mol, dist, cutoff, cn); } - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = cut_coordination_number(cn_max, cn, dcndr, lgrad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return EXIT_SUCCESS; }; diff --git a/test/test_disp.cpp b/test/test_disp.cpp index 42dd768..f24abe3 100644 --- a/test/test_disp.cpp +++ b/test/test_disp.cpp @@ -44,14 +44,14 @@ int test_energy( // assemble molecule TMolecule mol; info = get_molecule(n, atoms, coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; TCutoff cutoff; TD4Model d4; // dispersion main function info = get_dispersion(mol, charge, d4, par, cutoff, energy, nullptr); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; if (check(energy, ref) == EXIT_FAILURE) { print_fail("BP86-D4-ATM", energy, ref); @@ -67,7 +67,7 @@ int test_disp() { info = test_energy( water_n, water_atoms, water_coord, water_charge, water_ref_energy ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_energy( mb16_43_01_n, @@ -76,7 +76,7 @@ int test_disp() { mb16_43_01_charge, mb16_43_01_ref_energy ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_energy( rost61_m1_n, @@ -85,11 +85,11 @@ int test_disp() { rost61_m1_charge, rost61_m1_ref_energy ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_energy(amf3_n, amf3_atoms, amf3_coord, amf3_charge, amf3_ref_energy); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_energy( actinides_n, @@ -98,7 +98,7 @@ int test_disp() { actinides_charge, actinides_ref_energy ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return EXIT_SUCCESS; } diff --git a/test/test_disp.h b/test/test_disp.h index 892d101..aac6074 100644 --- a/test/test_disp.h +++ b/test/test_disp.h @@ -29,13 +29,13 @@ static const double amf3_ref_energy{-2.9119716615478E-03}; static const double actinides_ref_energy{-2.836190476292469E-01}; extern int test_energy( - const int n, + int n, const char atoms[][4], const double coord[], - const int charge, - const double ref + int charge, + double ref ); -extern int test_disp(void); +extern int test_disp(); #endif // TEST_DISP_H diff --git a/test/test_disp2.cpp b/test/test_disp2.cpp index dd4a24e..87e806a 100644 --- a/test/test_disp2.cpp +++ b/test/test_disp2.cpp @@ -45,14 +45,14 @@ int test_energy2( // assemble molecule TMolecule mol; info = get_molecule(n, atoms, coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; TCutoff cutoff; TD4Model d4; // dispersion main function info = get_dispersion(mol, charge, d4, par, cutoff, energy, nullptr); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; if (check(energy, ref, 1e-8) == EXIT_FAILURE) { print_fail("BP86-D4", energy, ref); @@ -68,7 +68,7 @@ int test_disp2() { info = test_energy2( water_n, water_atoms, water_coord, water_charge, -2.3162150393943E-04 ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_energy2( mb16_43_01_n, @@ -77,7 +77,7 @@ int test_disp2() { mb16_43_01_charge, -2.5912431304617E-02 ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_energy2( actinides_n, @@ -86,7 +86,7 @@ int test_disp2() { actinides_charge, -2.8381803698606716E-01 ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return EXIT_SUCCESS; } diff --git a/test/test_disp2.h b/test/test_disp2.h index 5c45af5..4f7428d 100644 --- a/test/test_disp2.h +++ b/test/test_disp2.h @@ -19,13 +19,13 @@ #define TEST_DISP2_H extern int test_energy2( - const int n, + int n, const char atoms[][4], const double coord[], - const int charge, - const double ref + int charge, + double ref ); -extern int test_disp2(void); +extern int test_disp2(); #endif // TEST_DISP2_H diff --git a/test/test_grad.cpp b/test/test_grad.cpp index fe9cf4d..78d7a4a 100644 --- a/test/test_grad.cpp +++ b/test/test_grad.cpp @@ -62,7 +62,7 @@ int test_numgrad(TMolecule &mol, const int charge, const dparam &par) { d4grad[i] = 0.0; } info = get_dispersion(mol, charge, d4, par, cutoff, energy, d4grad); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // check translational invariance of analytical gradient if (is_trans_invar(mol, d4grad) != EXIT_SUCCESS) return EXIT_FAILURE; @@ -123,7 +123,7 @@ int test_pbed4_mb01() { TMolecule mol; int info = get_molecule(mb16_43_01_n, mb16_43_01_atoms, mb16_43_01_coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return test_numgrad(mol, charge, par); }; @@ -137,7 +137,7 @@ int test_bp86d4atm_water() { int charge = water_charge; TMolecule mol; int info = get_molecule(water_n, water_atoms, water_coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return test_numgrad(mol, charge, par); } @@ -151,7 +151,7 @@ int test_tpss0d4mbd_rost61m1() { int charge = rost61_m1_charge; TMolecule mol; int info = get_molecule(rost61_m1_n, rost61_m1_atoms, rost61_m1_coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return test_numgrad(mol, charge, par); } @@ -160,13 +160,13 @@ int test_grad() { int info{0}; info = test_pbed4_mb01(); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_bp86d4atm_water(); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_tpss0d4mbd_rost61m1(); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return EXIT_SUCCESS; }; diff --git a/test/test_grad.h b/test/test_grad.h index 15434ce..41f4216 100644 --- a/test/test_grad.h +++ b/test/test_grad.h @@ -23,13 +23,13 @@ using namespace dftd4; -extern int test_numgrad(TMolecule &mol, const int charge, const dparam &par); +extern int test_numgrad(TMolecule &mol, int charge, const dparam &par); extern int is_trans_invar(const TMolecule &mol, double gradient[]); -extern int test_bp86d4atm_water(void); -extern int test_pbed4_mb01(void); -extern int test_tpss0d4mbd_rost61m1(void); +extern int test_bp86d4atm_water(); +extern int test_pbed4_mb01(); +extern int test_tpss0d4mbd_rost61m1(); -extern int test_grad(void); +extern int test_grad(); #endif // TEST_GRAD_H diff --git a/test/test_ncoord.cpp b/test/test_ncoord.cpp index 22fe644..4247bdd 100644 --- a/test/test_ncoord.cpp +++ b/test/test_ncoord.cpp @@ -39,7 +39,7 @@ int test_cn( // assemble molecule TMolecule mol; info = get_molecule(n, atoms, coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // get reference TVector ref; @@ -58,7 +58,7 @@ int test_cn( TMatrix dcndr; // empty because no gradient needed cn.New(n); info = get_ncoord_d4(mol, dist, 9999.9, cn, dcndr, false); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // compare to ref for (int i = 0; i != n; i++) { @@ -76,12 +76,12 @@ int test_ncoord() { info = test_cn( mb16_43_01_n, mb16_43_01_atoms, mb16_43_01_coord, mb16_43_01_ref_cn ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; info = test_cn( rost61_m1_n, rost61_m1_atoms, rost61_m1_coord, rost61_m1_ref_cn ); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return EXIT_SUCCESS; } diff --git a/test/test_ncoord.h b/test/test_ncoord.h index 865892e..6a0fe70 100644 --- a/test/test_ncoord.h +++ b/test/test_ncoord.h @@ -39,12 +39,12 @@ static const double rost61_m1_ref_cn[22] { }; extern int test_cn( - const int n, + int n, const char atoms[][3], const double coord[], const double ref_cn[] ); -extern int test_ncoord(void); +extern int test_ncoord(); #endif // TEST_NCOORD_H diff --git a/test/test_param.cpp b/test/test_param.cpp index eaf74ba..9a1815e 100644 --- a/test/test_param.cpp +++ b/test/test_param.cpp @@ -40,7 +40,7 @@ int test_rational_damping(const double ref[], TCutoff cutoff) { int charge = upu23_0a_charge; TMolecule mol; info = get_molecule(upu23_0a_n, upu23_0a_atoms, upu23_0a_coord, mol); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // create default D4 model TD4Model d4; @@ -51,7 +51,7 @@ int test_rational_damping(const double ref[], TCutoff cutoff) { energy = 0.0; info = get_dispersion(mol, charge, d4, par, cutoff, energy, nullptr); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; if (check(energy, ref[i]) == EXIT_FAILURE) { print_fail(funcs[i], energy, ref[i]); @@ -67,13 +67,13 @@ int test_param() { TCutoff cutoff = TCutoff(disp2_default, 15.0); info = test_rational_damping(ref, cutoff); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; // do not use cutoffs double huge = std::numeric_limits::max(); TCutoff no_cutoff = TCutoff(huge, huge, huge, huge); info = test_rational_damping(ref_no_cutoff, no_cutoff); - if (!info == EXIT_SUCCESS) return info; + if (info != EXIT_SUCCESS) return info; return EXIT_SUCCESS; } diff --git a/test/test_param.h b/test/test_param.h index 37a333d..612d143 100644 --- a/test/test_param.h +++ b/test/test_param.h @@ -24,7 +24,7 @@ using namespace dftd4; -extern int test_param(void); +extern int test_param(); extern int test_rational_damping(const double ref[], TCutoff cutoff); static const int nfuncs = 97; diff --git a/test/util.cpp b/test/util.cpp index 88df121..5843622 100644 --- a/test/util.cpp +++ b/test/util.cpp @@ -50,9 +50,9 @@ bool check( double diff; if (rel) { - diff = fabs(actual - expected) / expected; + diff = std::fabs(actual - expected) / expected; } else { - diff = fabs(actual - expected); + diff = std::fabs(actual - expected); } if (diff > epsilon) { @@ -70,9 +70,9 @@ bool check( float diff; if (rel) { - diff = fabs(actual - expected) / expected; + diff = std::fabs(actual - expected) / expected; } else { - diff = fabs(actual - expected); + diff = std::fabs(actual - expected); } if (diff > epsilon) {