int main(int, char **argv) { const double myT = water_prop.kT; // room temperature in Hartree const double R = 2.7; Functional x(Identity()); Grid n(gd); n = 0.001*VectorXd::Ones(gd.NxNyNz) + 0.001*(-10*r2(gd)).cwise().exp(); compare_functionals(Sum(), x + kT, myT, n, 2e-13); compare_functionals(Quadratic(), sqr(x + kT) - x + 2*kT, myT, n, 2e-12); compare_functionals(Sqrt(), sqrt(x), myT, n, 1e-12); compare_functionals(SqrtAndMore(), sqrt(x) - x + 2*kT, myT, n, 1e-12); compare_functionals(Log(), log(x), myT, n, 3e-14); compare_functionals(LogAndSqr(), log(x) + sqr(x), myT, n, 3e-14); compare_functionals(LogAndSqrAndInverse(), log(x) + (sqr(x)-Pow(3)) + Functional(1)/x, myT, n, 3e-10); compare_functionals(LogOneMinusX(), log(1-x), myT, n, 1e-12); compare_functionals(LogOneMinusNbar(R), log(1-StepConvolve(R)), myT, n, 1e-13); compare_functionals(SquareXshell(R), sqr(xShellConvolve(R)), myT, n); Functional n2 = ShellConvolve(R); Functional n3 = StepConvolve(R); compare_functionals(n2_and_n3(R), sqr(n2) + sqr(n3), myT, n, 1e-14); const double four_pi_r2 = 4*M_PI*R*R; Functional one_minus_n3 = 1 - n3; Functional phi1 = (-1/four_pi_r2)*n2*log(one_minus_n3); compare_functionals(Phi1(R), phi1, myT, n, 1e-13); const double four_pi_r = 4*M_PI*R; Functional n2x = xShellConvolve(R); Functional n2y = yShellConvolve(R); Functional n2z = zShellConvolve(R); Functional phi2 = (sqr(n2) - sqr(n2x) - sqr(n2y) - sqr(n2z))/(four_pi_r*one_minus_n3); compare_functionals(Phi2(R), phi2, myT, n, 1e-14); Functional phi3rf = n2*(sqr(n2) - 3*(sqr(n2x) + sqr(n2y) + sqr(n2z)))/(24*M_PI*sqr(one_minus_n3)); compare_functionals(Phi3rf(R), phi3rf, myT, n, 1e-13); compare_functionals(AlmostRF(R), myT*(phi1 + phi2 + phi3rf), myT, n, 2e-14); Functional veff = EffectivePotentialToDensity(); compare_functionals(SquareVeff(R), sqr(veff), myT, Grid(gd, -myT*n.cwise().log()), 1e-12); compare_functionals(AlmostRFnokT(R), phi1 + phi2 + phi3rf, myT, n, 3e-14); compare_functionals(AlmostRF(R), (myT*phi1).set_name("phi1") + (myT*phi2).set_name("phi2") + (myT*phi3rf).set_name("phi3"), myT, n, 4e-14); compare_functionals(Phi1Veff(R), phi1(veff), myT, Grid(gd, -myT*n.cwise().log()), 1e-13); compare_functionals(Phi2Veff(R), phi2(veff), myT, Grid(gd, -myT*n.cwise().log()), 1e-14); compare_functionals(Phi3rfVeff(R), phi3rf(veff), myT, Grid(gd, -myT*n.cwise().log()), 1e-13); compare_functionals(IdealGasFast(), IdealGasOfVeff, myT, Grid(gd, -myT*n.cwise().log()), 1e-12); double mu = -1; compare_functionals(Phi1plus(R, mu), phi1(veff) + IdealGasOfVeff + ChemicalPotential(mu)(veff), myT, Grid(gd, -myT*n.cwise().log()), 1e-12); if (errors == 0) printf("\n%s passes!\n", argv[0]); else printf("\n%s fails %d tests!\n", argv[0], errors); return errors; }
double Phi(double x){ if(x<0)return Phi1(-x); if(x<3.4)return Phi_0(x); return 1-exp(-x*x/2)/sqrt(2*pi)/Phi_1(x); }