From 4614fe51c07890e06ec4f7d25f2b3395c4500a5e Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Wed, 8 Apr 2020 13:10:03 +0200 Subject: [PATCH] No more warnings (#124) * No more warnings * Shut up, clang * Silence Clang also in Release mode --- cmake/custom/compilers/CXXFlags.cmake | 11 +++++-- src/XCFunctional.cpp | 4 +-- src/XCFunctional.hpp | 2 +- src/config.hpp | 2 ++ src/densvars.hpp | 38 +++++++++++++++---------- src/functionals/apbec.cpp | 2 +- src/functionals/constants.hpp | 22 +++++++------- src/functionals/list_of_functionals.hpp | 2 +- src/functionals/lypc.cpp | 2 +- src/functionals/m0xy_fun.hpp | 11 +++---- src/functionals/optx.cpp | 8 +++--- src/functionals/pbec.cpp | 8 +++--- src/functionals/pbec_eps.hpp | 8 +++--- src/functionals/pbeintc.cpp | 2 +- src/functionals/pbelocc.cpp | 2 +- src/functionals/pw9xx.hpp | 2 +- src/functionals/revtpssc_eps.hpp | 6 ++-- src/functionals/slater.hpp | 2 +- src/functionals/tfk.cpp | 2 +- src/functionals/tpsslocc.cpp | 4 +-- src/functionals/tw.cpp | 2 -- src/functionals/zvpbeint.cpp | 2 +- src/functionals/zvpbesolc.cpp | 2 +- src/xcint.cpp | 4 +-- src/xcint.hpp | 14 ++++----- 25 files changed, 88 insertions(+), 76 deletions(-) diff --git a/cmake/custom/compilers/CXXFlags.cmake b/cmake/custom/compilers/CXXFlags.cmake index 94db3849..530f1834 100644 --- a/cmake/custom/compilers/CXXFlags.cmake +++ b/cmake/custom/compilers/CXXFlags.cmake @@ -24,8 +24,9 @@ if(CMAKE_CXX_COMPILER_ID MATCHES GNU) "-Wuninitialized" "-Wmissing-declarations" "-Wwrite-strings" - "-Weffc++" "-Wno-sign-compare" + "-Wno-implicit-fallthrough" + "-Wno-missing-field-initializers" ) list(APPEND XCFun_CXX_FLAGS_RELEASE "-O3" @@ -54,9 +55,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES Clang) "-Wuninitialized" "-Wmissing-declarations" "-Wwrite-strings" - "-Weffc++" - "-Wdocumentation" "-Wno-sign-compare" + "-Wno-implicit-fallthrough" + "-Wno-missing-field-initializers" + "-Wno-undefined-var-template" ) list(APPEND XCFun_CXX_FLAGS_RELEASE "-O3" @@ -64,6 +66,9 @@ if(CMAKE_CXX_COMPILER_ID MATCHES Clang) "-funroll-loops" "-ftree-vectorize" "-Wno-unused" + "-Wno-implicit-fallthrough" + "-Wno-missing-field-initializers" + "-Wno-undefined-var-template" ) endif() diff --git a/src/XCFunctional.cpp b/src/XCFunctional.cpp index 2848253c..3ca1c625 100644 --- a/src/XCFunctional.cpp +++ b/src/XCFunctional.cpp @@ -80,9 +80,9 @@ int xcfun_test() { fun, fd->test_vars, fd->test_mode, fd->test_order)) == 0) { int n = xcfun_output_length(fun); auto out = new double[n]; - if (!fd->test_in) + if (fd->test_in.empty()) xcfun::die("Functional has no test input!", f); - xcfun_eval(fun, fd->test_in, out); + xcfun_eval(fun, fd->test_in.data(), out); int nerr = 0; for (auto i = 0; i < n; ++i) if (std::abs(out[i] - fd->test_out[i]) > diff --git a/src/XCFunctional.hpp b/src/XCFunctional.hpp index 29721709..5606740c 100644 --- a/src/XCFunctional.hpp +++ b/src/XCFunctional.hpp @@ -32,7 +32,7 @@ struct XCFunctional { xcfun_mode mode{XC_MODE_UNSET}; xcfun_vars vars{XC_VARS_UNSET}; std::array active_functionals{{nullptr}}; - std::array settings; + std::array settings{{0.0}}; }; namespace xcfun { diff --git a/src/config.hpp b/src/config.hpp index 8141cedc..12d8573d 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -49,3 +49,5 @@ typedef qd_real ireal_t; #define XCFUN_NUM_CONVERT // Must convert real types at i/o #define INNER_TO_OUTER(INNER) to_double(INNER) #endif + +typedef ireal_t parameter; diff --git a/src/densvars.hpp b/src/densvars.hpp index d5b52dbc..7013dad9 100644 --- a/src/densvars.hpp +++ b/src/densvars.hpp @@ -217,21 +217,29 @@ template struct densvars { b_43 = pow(b, 4.0 / 3.0); } - const XCFunctional * parent; + const XCFunctional * parent{nullptr}; double get_param(enum xc_parameter p) const { return parent->settings[p]; } - T a, b, gaa, gab, gbb; - /* na+nb, na-nb, (grad n)^2, (grad n).(grad s), (grad s)^2 */ - T n, s, gnn, gns, gss; - - T tau, taua, taub; // Kinetic energy densities. - - T lapa, lapb; // Density Laplacians - - T zeta; // s/n - T r_s; // (3/4pi)^1/3*n^(-1/3) - T n_m13; // pow(n,-1.0/3.0) - T a_43, b_43; // pow(a,4.0/3.0), pow(b,4.0/3.0) - - T jpaa, jpbb; // square of the alpha and beta paramagnetic current vectors. + T a{static_cast(0)}; + T b{static_cast(0)}; + T gaa{static_cast(0)}; + T gab{static_cast(0)}; + T gbb{static_cast(0)}; + T n{static_cast(0)}; /// na+nb + T s{static_cast(0)}; /// na - nb + T gnn{static_cast(0)}; /// (grad n) ^ 2 + T gns{static_cast(0)}; /// (grad n).(grad s) + T gss{static_cast(0)}; /// (grad s) ^ 2 + T tau{static_cast(0)}; /// Kinetic energy density. + T taua{static_cast(0)}; /// Alpha kinetic energy density. + T taub{static_cast(0)}; /// Beta kinetic energy density. + T lapa{static_cast(0)}; /// Alpha Laplacian density. + T lapb{static_cast(0)}; /// Beta Laplacian density. + T zeta{static_cast(0)}; /// s/n + T r_s{static_cast(0)}; /// (3/4pi)^1/3*n^(-1/3) + T n_m13{static_cast(0)}; /// pow(n,-1.0/3.0) + T a_43{static_cast(0)}; + T b_43{static_cast(0)}; /// pow(a,4.0/3.0), pow(b,4.0/3.0) + T jpaa{static_cast(0)}; /// square of the alpha paramagnetic current vector. + T jpbb{static_cast(0)}; /// square of the beta paramagnetic current vector. }; diff --git a/src/functionals/apbec.cpp b/src/functionals/apbec.cpp index 0f5c2967..17180038 100644 --- a/src/functionals/apbec.cpp +++ b/src/functionals/apbec.cpp @@ -22,7 +22,7 @@ template static num phi(const densvars & d) { } template static num energy(const densvars & d) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta = 0.079030523241; num bg = beta / param_gamma; num eps = pw92eps::pw92eps(d); diff --git a/src/functionals/constants.hpp b/src/functionals/constants.hpp index 263a6c2b..cbdf0e1b 100644 --- a/src/functionals/constants.hpp +++ b/src/functionals/constants.hpp @@ -14,27 +14,25 @@ #pragma once -#include "functional.hpp" +#include -#ifndef M_PI // M_PI is not standard for some reason -#define M_PI 3.14159265358979323846 -#endif +#include "config.hpp" #ifndef PI -#define PI 3.14159265358979323846 +constexpr auto PI = M_PI; #endif #ifndef PI2 -#define PI2 (M_PI * M_PI) +constexpr auto PI2 = (M_PI * M_PI); #endif -namespace xc_constants { +namespace xcfun_constants { const parameter c_slater = pow(81 / (32 * M_PI), 1.0 / 3.0); // Typically called C_x -const parameter CF = 0.3 * pow(3 * M_PI * M_PI, 2.0 / 3.0); +const parameter CF = 0.3 * pow(3 * PI2, 2.0 / 3.0); // PBE constants. -const parameter param_gamma = (1 - log(2.0)) / (M_PI * M_PI); -const parameter param_beta_pbe_paper = 0.066725; -const parameter param_beta_accurate = 0.06672455060314922; +const parameter param_gamma = (1 - log(2.0)) / (PI2); +constexpr parameter param_beta_pbe_paper = 0.066725; +constexpr parameter param_beta_accurate = 0.06672455060314922; const parameter param_beta_gamma = param_beta_accurate / param_gamma; -} // namespace xc_constants +} // namespace xcfun_constants diff --git a/src/functionals/list_of_functionals.hpp b/src/functionals/list_of_functionals.hpp index fcb760a4..e7b2c5b6 100644 --- a/src/functionals/list_of_functionals.hpp +++ b/src/functionals/list_of_functionals.hpp @@ -14,7 +14,7 @@ #pragma once -enum xc_functional_id { +enum xcfun_functional_id { XC_SLATERX, XC_PW86X, XC_VWN3C, diff --git a/src/functionals/lypc.cpp b/src/functionals/lypc.cpp index 45953e75..f70e7996 100644 --- a/src/functionals/lypc.cpp +++ b/src/functionals/lypc.cpp @@ -20,7 +20,7 @@ template static num lypc(const densvars & d) { const parameter B = 0.132; const parameter C = 0.2533; const parameter Dd = 0.349; - using xc_constants::CF; + using xcfun_constants::CF; num icbrtn = pow(d.n, -1.0 / 3.0); num P = 1 / (1 + Dd * icbrtn); num omega = exp(-C * icbrtn) * P * pow(d.n, -11.0 / 3.0); diff --git a/src/functionals/m0xy_fun.hpp b/src/functionals/m0xy_fun.hpp index e93627b2..668c09cd 100644 --- a/src/functionals/m0xy_fun.hpp +++ b/src/functionals/m0xy_fun.hpp @@ -14,11 +14,12 @@ #pragma once +#include + #include "pw92eps.hpp" #include "pw9xx.hpp" -#include -// common functions for MO5 and M06 family of (hybrid) meta-gga functionals +// common functions for M05 and M06 family of (hybrid) meta-gga functionals namespace m0xy_metagga_xc_internal { @@ -61,7 +62,7 @@ const parameter scalefactorTFconst = 3.17480210393640; // which was used as benchmark here for energy and first derivatives. template static num zet(const num & rho, const num & tau) { - using xc_constants::CF; + using xcfun_constants::CF; return 2 * tau / pow(rho, 5.0 / 3.0) - CF * scalefactorTFconst; } @@ -140,7 +141,7 @@ template static num Dsigma(const num & na, const num & gaa, const num & taua) // static num Dsigma(const num &chi2, const num &zet) { - // using xc_constants::CF; + // using xcfun_constants::CF; // return (1.0 - 0.25*chi2/(zet + CF*scalefactorTFconst)); // Idiotic to subtract the constant (inside zet) and then add it back again @@ -233,7 +234,7 @@ static num m05_c_anti(const parameter param_c[5], template static num m05_c_para(const parameter param_c[5], const num & chi2, - const num & zet, + const num & /* zet */, const num & Dsigma) { // this is an "universal" constant for all M05/M06 functionals const parameter gamma_c_parallel = 0.06; diff --git a/src/functionals/optx.cpp b/src/functionals/optx.cpp index 7abd31a8..278589e1 100644 --- a/src/functionals/optx.cpp +++ b/src/functionals/optx.cpp @@ -19,10 +19,10 @@ template static num optx(const densvars & d) { const parameter a1 = 1.05151, a2 = 1.43169, gamma = 0.006; num g_xa2 = gamma * d.gaa * pow(d.a, -8.0 / 3.0); num g_xb2 = gamma * d.gbb * pow(d.b, -8.0 / 3.0); - return -(d.a_43 * - (a1 * xc_constants::c_slater + a2 * pow(g_xa2, 2) * pow(1 + g_xa2, -2))) - - (d.b_43 * - (a1 * xc_constants::c_slater + a2 * pow(g_xb2, 2) * pow(1 + g_xb2, -2))); + return -(d.a_43 * (a1 * xcfun_constants::c_slater + + a2 * pow(g_xa2, 2) * pow(1 + g_xa2, -2))) - + (d.b_43 * (a1 * xcfun_constants::c_slater + + a2 * pow(g_xb2, 2) * pow(1 + g_xb2, -2))); } FUNCTIONAL(XC_OPTX) = {"OPTX Handy & Cohen exchange", diff --git a/src/functionals/pbec.cpp b/src/functionals/pbec.cpp index d74c8e18..0e2c61bd 100644 --- a/src/functionals/pbec.cpp +++ b/src/functionals/pbec.cpp @@ -18,16 +18,16 @@ #include "vwn.hpp" template static num A(const num & eps, const num & u3) { - using xc_constants::param_beta_gamma; - using xc_constants::param_gamma; + using xcfun_constants::param_beta_gamma; + using xcfun_constants::param_gamma; return param_beta_gamma / expm1(-eps / (param_gamma * u3)); } template static num H(const num & d2, const num & eps, const num & u3) { num d2A = d2 * A(eps, u3); - using xc_constants::param_beta_gamma; - using xc_constants::param_gamma; + using xcfun_constants::param_beta_gamma; + using xcfun_constants::param_gamma; return param_gamma * u3 * log(1 + param_beta_gamma * d2 * (1 + d2A) / (1 + d2A * (1 + d2A))); } diff --git a/src/functionals/pbec_eps.hpp b/src/functionals/pbec_eps.hpp index a1513fc1..7029ad39 100644 --- a/src/functionals/pbec_eps.hpp +++ b/src/functionals/pbec_eps.hpp @@ -21,16 +21,16 @@ namespace pbec_eps { template static num A(const num & eps, const T & u3) { - using xc_constants::param_beta_gamma; - using xc_constants::param_gamma; + using xcfun_constants::param_beta_gamma; + using xcfun_constants::param_gamma; return param_beta_gamma / expm1(-eps / (param_gamma * u3)); } template static num H(const num & d2, const num & eps, const T & u3) { num d2A = d2 * A(eps, u3); - using xc_constants::param_beta_gamma; - using xc_constants::param_gamma; + using xcfun_constants::param_beta_gamma; + using xcfun_constants::param_gamma; return param_gamma * u3 * log(1 + param_beta_gamma * d2 * (1 + d2A) / (1 + d2A * (1 + d2A))); } diff --git a/src/functionals/pbeintc.cpp b/src/functionals/pbeintc.cpp index bc0c7f62..3aa49e6e 100644 --- a/src/functionals/pbeintc.cpp +++ b/src/functionals/pbeintc.cpp @@ -22,7 +22,7 @@ template static num phi(const densvars & d) { } template static num energy(const densvars & d) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta = 0.052; num bg = beta / param_gamma; num eps = pw92eps::pw92eps(d); diff --git a/src/functionals/pbelocc.cpp b/src/functionals/pbelocc.cpp index b0e095b7..98ff42f9 100644 --- a/src/functionals/pbelocc.cpp +++ b/src/functionals/pbelocc.cpp @@ -22,7 +22,7 @@ template static num phi(const densvars & d) { } template static num energy(const densvars & d) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta0 = 0.0375; const parameter aa = 0.08; num u = phi(d); diff --git a/src/functionals/pw9xx.hpp b/src/functionals/pw9xx.hpp index 75e90c00..e9a8d9fd 100644 --- a/src/functionals/pw9xx.hpp +++ b/src/functionals/pw9xx.hpp @@ -64,7 +64,7 @@ template static num prefactor(const num & rho) { // prefactor for the pw91k functional template static num pw91k_prefactor(const num & rho) { - using xc_constants::CF; + using xcfun_constants::CF; return CF * pow(2.0, 2.0 / 3.0) * pow(rho, 5.0 / 3.0); } diff --git a/src/functionals/revtpssc_eps.hpp b/src/functionals/revtpssc_eps.hpp index 6638e8f1..c3f2bb0c 100644 --- a/src/functionals/revtpssc_eps.hpp +++ b/src/functionals/revtpssc_eps.hpp @@ -23,7 +23,7 @@ using namespace pbec_eps; template static num revtpssA(const num & eps, const T & u3, const num & beta_tpss) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; num beta_gamma = beta_tpss / param_gamma; return beta_gamma / expm1(-eps / (param_gamma * u3)); } @@ -34,7 +34,7 @@ static num revtpssH(const num & d2, const T & u3, const num & beta_tpss) { num d2A = d2 * revtpssA(eps, u3, beta_tpss); - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; num beta_gamma = beta_tpss / param_gamma; return param_gamma * u3 * log(1 + beta_gamma * d2 * (1 + d2A) / (1 + d2A * (1 + d2A))); @@ -42,7 +42,7 @@ static num revtpssH(const num & d2, template static num revtpss_beta(const num & dens) { num r_s = cbrt(3 / (4 * PI * dens)); - using xc_constants::param_beta_pbe_paper; + using xcfun_constants::param_beta_pbe_paper; return param_beta_pbe_paper * (1 + 0.1 * r_s) / (1 + 0.1778 * r_s); } diff --git a/src/functionals/slater.hpp b/src/functionals/slater.hpp index 7457f4f6..ac83cd8f 100644 --- a/src/functionals/slater.hpp +++ b/src/functionals/slater.hpp @@ -17,5 +17,5 @@ #include "constants.hpp" template static num slaterx(const densvars & d) { - return (-xc_constants::c_slater) * (d.a_43 + d.b_43); + return (-xcfun_constants::c_slater) * (d.a_43 + d.b_43); } diff --git a/src/functionals/tfk.cpp b/src/functionals/tfk.cpp index 3f673a98..9ad74735 100644 --- a/src/functionals/tfk.cpp +++ b/src/functionals/tfk.cpp @@ -18,7 +18,7 @@ // Thomas-Fermi kinetic energy functional template static num tfk(const densvars & d) { - using xc_constants::CF; + using xcfun_constants::CF; return CF * pow(d.n, 5.0 / 3.0); } diff --git a/src/functionals/tpsslocc.cpp b/src/functionals/tpsslocc.cpp index 5e72a4ee..ebc3cca2 100644 --- a/src/functionals/tpsslocc.cpp +++ b/src/functionals/tpsslocc.cpp @@ -22,7 +22,7 @@ template static num phi(const densvars & d) { } template static num pbeloc_eps(const densvars & d) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta0 = 0.0375; const parameter aa = 0.08; num u = phi(d); @@ -41,7 +41,7 @@ template static num pbeloc_eps(const densvars & d) { } template static num pbeloc_eps_pola(const num & a, const num & gaa) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta0 = 0.0375; const parameter aa = 0.08; num u = pow(2.0, -1.0 / 3.0); // phi for fully polarized systems diff --git a/src/functionals/tw.cpp b/src/functionals/tw.cpp index fae25bc1..e7f3e57d 100644 --- a/src/functionals/tw.cpp +++ b/src/functionals/tw.cpp @@ -18,8 +18,6 @@ // von Weizsacker kinetic energy functional template static num tw(const densvars & d) { - using xc_constants::CF; - return 1. / 8. * pow(d.gaa + d.gbb, 2.0) / d.n; } diff --git a/src/functionals/zvpbeint.cpp b/src/functionals/zvpbeint.cpp index 9064483b..a1b3067a 100644 --- a/src/functionals/zvpbeint.cpp +++ b/src/functionals/zvpbeint.cpp @@ -22,7 +22,7 @@ template static num phi(const densvars & d) { } template static num energy(const densvars & d) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta = 0.052; const parameter alpha = 1.0; num bg = beta / param_gamma; diff --git a/src/functionals/zvpbesolc.cpp b/src/functionals/zvpbesolc.cpp index cd8b47be..0496fb42 100644 --- a/src/functionals/zvpbesolc.cpp +++ b/src/functionals/zvpbesolc.cpp @@ -22,7 +22,7 @@ template static num phi(const densvars & d) { } template static num energy(const densvars & d) { - using xc_constants::param_gamma; + using xcfun_constants::param_gamma; const parameter beta = 0.046; const parameter alpha = 1.8; // const parameter omega = 4.5; // not needed if you use the fit diff --git a/src/xcint.cpp b/src/xcint.cpp index bd07b927..10f2699d 100644 --- a/src/xcint.cpp +++ b/src/xcint.cpp @@ -47,7 +47,7 @@ template void xcint_functional_setup_helper() { fundat_db::symbol[2] == '_')) xcfun::die("Functional symbol does not start with XC_", FUN); fundat_db::d.name = fundat_db::symbol + 3; - fundat_db::d.id = (enum xc_functional_id)FUN; + fundat_db::d.id = static_cast(FUN); xcint_funs[FUN] = fundat_db::d; xcint_functional_setup_helper(); } @@ -67,7 +67,7 @@ template struct retarded_helper { fundat_db::symbol[2] == '_')) xcfun::die("Functional symbol does not start with XC_", FUN); fundat_db::d.name = fundat_db::symbol + 3; - fundat_db::d.id = (enum xc_functional_id)FUN; + fundat_db::d.id = static_cast(FUN); xcint_funs[FUN] = fundat_db::d; } }; diff --git a/src/xcint.hpp b/src/xcint.hpp index 455d9c9a..601fcafe 100644 --- a/src/xcint.hpp +++ b/src/xcint.hpp @@ -14,7 +14,9 @@ #pragma once +#include #include +#include #include "config.hpp" #include "ctaylor.hpp" @@ -49,21 +51,19 @@ struct functional_data { const char * short_description; const char * long_description; int depends; // XC_DENSITY | XC_GRADIENT etc -#define FP(N, E) ctaylor (*fp##N)(const densvars> &); +#define FP(N, E) \ + std::function(const densvars> &)> fp##N; FOR_EACH(XCFUN_MAX_ORDER, FP, ) xcfun_vars test_vars; xcfun_mode test_mode; int test_order; double test_threshold; - double test_in[16]; // Increase dimensions if future tests require it - double test_out[128]; - - enum xc_functional_id id; + std::array test_in; // Increase dimensions if future tests require it + std::array test_out; + xcfun_functional_id id; const char * name; // Set up automatically from the symbol }; -typedef ireal_t parameter; - struct parameter_data { const char * description; parameter default_value;