Skip to content

Commit

Permalink
No more warnings (#124)
Browse files Browse the repository at this point in the history
* No more warnings

* Shut up, clang

* Silence Clang also in Release mode
  • Loading branch information
robertodr authored Apr 8, 2020
1 parent 6f59311 commit 4614fe5
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 76 deletions.
11 changes: 8 additions & 3 deletions cmake/custom/compilers/CXXFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -54,16 +55,20 @@ 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"
"-ffast-math"
"-funroll-loops"
"-ftree-vectorize"
"-Wno-unused"
"-Wno-implicit-fallthrough"
"-Wno-missing-field-initializers"
"-Wno-undefined-var-template"
)
endif()

Expand Down
4 changes: 2 additions & 2 deletions src/XCFunctional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) >
Expand Down
2 changes: 1 addition & 1 deletion src/XCFunctional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct XCFunctional {
xcfun_mode mode{XC_MODE_UNSET};
xcfun_vars vars{XC_VARS_UNSET};
std::array<functional_data *, XC_NR_FUNCTIONALS> active_functionals{{nullptr}};
std::array<double, XC_NR_PARAMETERS_AND_FUNCTIONALS> settings;
std::array<double, XC_NR_PARAMETERS_AND_FUNCTIONALS> settings{{0.0}};
};

namespace xcfun {
Expand Down
2 changes: 2 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
38 changes: 23 additions & 15 deletions src/densvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,29 @@ template <typename T> 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<T>(0)};
T b{static_cast<T>(0)};
T gaa{static_cast<T>(0)};
T gab{static_cast<T>(0)};
T gbb{static_cast<T>(0)};
T n{static_cast<T>(0)}; /// na+nb
T s{static_cast<T>(0)}; /// na - nb
T gnn{static_cast<T>(0)}; /// (grad n) ^ 2
T gns{static_cast<T>(0)}; /// (grad n).(grad s)
T gss{static_cast<T>(0)}; /// (grad s) ^ 2
T tau{static_cast<T>(0)}; /// Kinetic energy density.
T taua{static_cast<T>(0)}; /// Alpha kinetic energy density.
T taub{static_cast<T>(0)}; /// Beta kinetic energy density.
T lapa{static_cast<T>(0)}; /// Alpha Laplacian density.
T lapb{static_cast<T>(0)}; /// Beta Laplacian density.
T zeta{static_cast<T>(0)}; /// s/n
T r_s{static_cast<T>(0)}; /// (3/4pi)^1/3*n^(-1/3)
T n_m13{static_cast<T>(0)}; /// pow(n,-1.0/3.0)
T a_43{static_cast<T>(0)};
T b_43{static_cast<T>(0)}; /// pow(a,4.0/3.0), pow(b,4.0/3.0)
T jpaa{static_cast<T>(0)}; /// square of the alpha paramagnetic current vector.
T jpbb{static_cast<T>(0)}; /// square of the beta paramagnetic current vector.
};
2 changes: 1 addition & 1 deletion src/functionals/apbec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename num> static num phi(const densvars<num> & d) {
}

template <typename num> static num energy(const densvars<num> & 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);
Expand Down
22 changes: 10 additions & 12 deletions src/functionals/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,25 @@

#pragma once

#include "functional.hpp"
#include <cmath>

#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
2 changes: 1 addition & 1 deletion src/functionals/list_of_functionals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

enum xc_functional_id {
enum xcfun_functional_id {
XC_SLATERX,
XC_PW86X,
XC_VWN3C,
Expand Down
2 changes: 1 addition & 1 deletion src/functionals/lypc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template <typename num> static num lypc(const densvars<num> & 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);
Expand Down
11 changes: 6 additions & 5 deletions src/functionals/m0xy_fun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

#pragma once

#include <cstdio>

#include "pw92eps.hpp"
#include "pw9xx.hpp"
#include <stdio.h>

// 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 {

Expand Down Expand Up @@ -61,7 +62,7 @@ const parameter scalefactorTFconst = 3.17480210393640;
// which was used as benchmark here for energy and first derivatives.

template <typename num> 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;
}
Expand Down Expand Up @@ -140,7 +141,7 @@ template <typename num>
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
Expand Down Expand Up @@ -233,7 +234,7 @@ static num m05_c_anti(const parameter param_c[5],
template <typename num>
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;
Expand Down
8 changes: 4 additions & 4 deletions src/functionals/optx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ template <typename num> static num optx(const densvars<num> & 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",
Expand Down
8 changes: 4 additions & 4 deletions src/functionals/pbec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
#include "vwn.hpp"

template <typename num> 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 <typename num>
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)));
}
Expand Down
8 changes: 4 additions & 4 deletions src/functionals/pbec_eps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

namespace pbec_eps {
template <typename num, class T> 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 <typename num, class T>
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)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/functionals/pbeintc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename num> static num phi(const densvars<num> & d) {
}

template <typename num> static num energy(const densvars<num> & 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);
Expand Down
2 changes: 1 addition & 1 deletion src/functionals/pbelocc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename num> static num phi(const densvars<num> & d) {
}

template <typename num> static num energy(const densvars<num> & 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);
Expand Down
2 changes: 1 addition & 1 deletion src/functionals/pw9xx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ template <typename num> static num prefactor(const num & rho) {

// prefactor for the pw91k functional
template <typename num> 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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/functionals/revtpssc_eps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace pbec_eps;

template <typename num, class T>
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));
}
Expand All @@ -34,15 +34,15 @@ 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)));
}

template <typename num> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/functionals/slater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
#include "constants.hpp"

template <typename num> static num slaterx(const densvars<num> & d) {
return (-xc_constants::c_slater) * (d.a_43 + d.b_43);
return (-xcfun_constants::c_slater) * (d.a_43 + d.b_43);
}
2 changes: 1 addition & 1 deletion src/functionals/tfk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Thomas-Fermi kinetic energy functional

template <typename num> static num tfk(const densvars<num> & d) {
using xc_constants::CF;
using xcfun_constants::CF;

return CF * pow(d.n, 5.0 / 3.0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/functionals/tpsslocc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename num> static num phi(const densvars<num> & d) {
}

template <typename num> static num pbeloc_eps(const densvars<num> & 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);
Expand All @@ -41,7 +41,7 @@ template <typename num> static num pbeloc_eps(const densvars<num> & d) {
}

template <typename num> 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
Expand Down
2 changes: 0 additions & 2 deletions src/functionals/tw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
// von Weizsacker kinetic energy functional

template <typename num> static num tw(const densvars<num> & d) {
using xc_constants::CF;

return 1. / 8. * pow(d.gaa + d.gbb, 2.0) / d.n;
}

Expand Down
2 changes: 1 addition & 1 deletion src/functionals/zvpbeint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename num> static num phi(const densvars<num> & d) {
}

template <typename num> static num energy(const densvars<num> & 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;
Expand Down
2 changes: 1 addition & 1 deletion src/functionals/zvpbesolc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename num> static num phi(const densvars<num> & d) {
}

template <typename num> static num energy(const densvars<num> & 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
Expand Down
Loading

0 comments on commit 4614fe5

Please sign in to comment.