diff --git a/.gitignore b/.gitignore index 1ebd5bd69..a29cbad25 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,7 @@ # Autocmake stuff cmake/lib/*.pyc + +# Emacs backup files +*~ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 3141b92d7..c966ced1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ ### Added +- Double logarithmic scale for the integration of spherical diffuse + interfaces: much more stable than the previous version, allowing for + Runge-Kutta 4 integrator. + +### Fixed + +- Bug in the diffuse interface Green's function. Contrary to the sharp + interface case, it is wrong to remove the monopole, which becomes + identically zero when the corresponding differential equation is + solved in extreme cases (e.g. charge far away from the sphere). + +### Added + - A new CMake module `options_wrappers.cmake` that adds new wrapper macros for the CMake `option` command. @@ -125,6 +138,8 @@ - The uppercased contents of the `.pcm` input file are written to a temporary file, instead of overwriting the user provided file. The temporary file is removed after it has been parsed. Fixes #91 as noted by @ilfreddy. +- Use Runge-Kutta-Fehlberg 7(8) ODE solver to integrate the radial equation + in the spherical diffuse Green's function class. ### Fixed diff --git a/doc/code-reference/greens-functions.rst b/doc/code-reference/greens-functions.rst index b94ee8cd4..9ee6f3eff 100644 --- a/doc/code-reference/greens-functions.rst +++ b/doc/code-reference/greens-functions.rst @@ -7,19 +7,12 @@ Green's functions objects relies on the Factory Method pattern :cite:`Gamma1994,Alexandrescu2001`, implemented through the generic Factory class. -The top-level header, _i.e._ to be included in client code, is `Green.hpp`. -The common interface to all Green's function classes is specified by the `IGreensFunction` class, +The top-level header, _i.e._ to be included in client code, is ``Green.hpp``. +The common interface to all Green's function classes is specified by the ``IGreensFunction`` class, this is non-templated. -All other classes are templated. TODO: explain template parameters. +All other classes are templated. The Green's functions are registered to the factory based on a label encoding: type, derivative, and dielectric profile. -The only allowed labels are: -- `VACUUM_NUMERICAL` -- `VACUUM_DERIVATIVE` -- `VACUMM_GRADIENT` -- `VACUUM_HESSIAN` - -- `SPHERICALDIFFUSE_TANH` -- `SPHERICALDIFFUSE_ERF` +The only allowed labels must be listed in ``src/green/Green.hpp``. If they are not, they can not be selected at run time. .. image:: ../gfx/green.png :scale: 70 % diff --git a/doc/pcmsolver.bib b/doc/pcmsolver.bib index 69c7b982c..5c600c16a 100644 --- a/doc/pcmsolver.bib +++ b/doc/pcmsolver.bib @@ -329,3 +329,13 @@ @ARTICLE{Allinger1994-tx doi = "10.1016/S0166-1280(09)80008-0" } +@article{Fosso-Tande2013, +title = "Implicit solvation models in a multiresolution multiwavelet basis", +journal = "Chemical Physics Letters", +volume = "561-562", +pages = "179--184", +year = "2013", +issn = "0009-2614", +doi = "https://doi.org/10.1016/j.cplett.2013.01.065", +author = "Jacob Fosso-Tande and Robert J. Harrison" +} \ No newline at end of file diff --git a/doc/users/input.rst b/doc/users/input.rst index cac3d1001..e20ee3980 100644 --- a/doc/users/input.rst +++ b/doc/users/input.rst @@ -363,13 +363,13 @@ while the Green's function outside might vary. * **Valid values**: :math:`\varepsilon \geq 1.0` * **Default**: 1.0 - Profile + Profile Functional form of the dielectric profile * **Type**: string - * **Valid values**: Tanh | Erf + * **Valid values**: Tanh | Erf | Log * **Valid for**: SphericalDiffuse - * **Default**: Tanh + * **Default**: Log Eps1 Static dielectric permittivity inside the interface diff --git a/src/green/Green.hpp b/src/green/Green.hpp index c719d8d45..3fbbbb8f5 100644 --- a/src/green/Green.hpp +++ b/src/green/Green.hpp @@ -33,7 +33,6 @@ #include "SphericalDiffuse.hpp" #include "UniformDielectric.hpp" #include "Vacuum.hpp" -#include "dielectric_profile/MembraneTanh.hpp" #include "dielectric_profile/OneLayerErf.hpp" #include "dielectric_profile/OneLayerTanh.hpp" #include "utils/Factory.hpp" @@ -89,6 +88,8 @@ inline Factory bootstrapFactory() { createSphericalDiffuse); factory_.subscribe("SPHERICALDIFFUSE_NUMERICAL_ERF", createSphericalDiffuse); + factory_.subscribe("SPHERICALDIFFUSE_NUMERICAL_LOG", + createSphericalDiffuse); return factory_; } diff --git a/src/green/GreensFunction.hpp b/src/green/GreensFunction.hpp index c4d9eee0a..c52fcaacb 100644 --- a/src/green/GreensFunction.hpp +++ b/src/green/GreensFunction.hpp @@ -149,6 +149,7 @@ class GreensFunction : public IGreensFunction { */ virtual DerivativeTraits operator()(DerivativeTraits * source, DerivativeTraits * probe) const = 0; + /*! Returns value of the kernel of the \f$\mathcal{S}\f$ integral operator, i.e. * the value of the Greens's function for the pair of points p1, p2: * \f$ G(\mathbf{p}_1, \mathbf{p}_2)\f$ @@ -169,6 +170,7 @@ class GreensFunction : public IGreensFunction { pp[2] = p2(2); return this->operator()(sp, pp)[0]; } + virtual std::ostream & printObject(std::ostream & os) __override { os << "Green's Function" << std::endl; return os; diff --git a/src/green/InterfacesImpl.hpp b/src/green/InterfacesImpl.hpp index e0337bda2..75bc56e51 100644 --- a/src/green/InterfacesImpl.hpp +++ b/src/green/InterfacesImpl.hpp @@ -57,34 +57,14 @@ typedef pcm::function(const double)> ProfileEvaluator * \brief holds parameters for the integrator */ struct IntegratorParameters { - /*! Absolute tolerance level */ - double eps_abs_; - /*! Relative tolerance level */ - double eps_rel_; - /*! Weight of the state */ - double factor_x_; - /*! Weight of the state derivative */ - double factor_dxdt_; /*! Lower bound of the integration interval */ double r_0_; /*! Upper bound of the integration interval */ double r_infinity_; /*! Time step between observer calls */ double observer_step_; - IntegratorParameters(double e_abs, - double e_rel, - double f_x, - double f_dxdt, - double r0, - double rinf, - double step) - : eps_abs_(e_abs), - eps_rel_(e_rel), - factor_x_(f_x), - factor_dxdt_(f_dxdt), - r_0_(r0), - r_infinity_(rinf), - observer_step_(step) {} + IntegratorParameters(double r0, double rinf, double step) + : r_0_(r0), r_infinity_(rinf), observer_step_(step) {} }; /*! \class LnTransformedRadial @@ -111,19 +91,18 @@ class LnTransformedRadial { * are reported in the manuscript. * \param[in] rho state vector holding the function and its first derivative * \param[out] drhodr state vector holding the first and second derivative - * \param[in] r position on the integration grid + * \param[in] y logarithmic position on the integration grid */ - void operator()(const StateType & rho, StateType & drhodr, const double r) { + void operator()(const StateType & rho, StateType & drhodr, const double y) { // Evaluate the dielectric profile double eps = 0.0, epsPrime = 0.0; - pcm::tie(eps, epsPrime) = eval_(r); + pcm::tie(eps, epsPrime) = eval_(std::exp(y)); if (utils::numericalZero(eps)) - throw std::domain_error("Division by zero!"); - double gamma_epsilon = epsPrime / eps; + PCMSOLVER_ERROR("Division by zero!"); + double gamma_epsilon = std::exp(y) * epsPrime / eps; // System of equations is defined here drhodr[0] = rho[1]; - drhodr[1] = -rho[1] * (rho[1] + 2.0 / r + gamma_epsilon) + - l_ * (l_ + 1) / std::pow(r, 2); + drhodr[1] = -rho[1] * (rho[1] + 1.0 + gamma_epsilon) + l_ * (l_ + 1); } }; } // namespace detail @@ -147,13 +126,13 @@ class RadialFunction __final { public: RadialFunction() : solution_(IndependentSolution()) {} RadialFunction(int l, - double r0, - double rinf, + double y0, + double yinf, const ProfileEvaluator & eval, const IntegratorParameters & parms) : solution_(IndependentSolution(l, - r0, - rinf, + y0, + yinf, eval, parms)) {} ~RadialFunction() {} @@ -184,13 +163,13 @@ class RadialFunction __final { */ template class Zeta __final { public: - Zeta() : L_(0), r_0_(0.0), r_infinity_(0.0) {} + Zeta() : L_(0), y_0_(0.0), y_infinity_(0.0) {} Zeta(int l, - double r0, - double rinf, + double y0, + double yinf, const ProfileEvaluator & eval, const IntegratorParameters & parms) - : L_(l), r_0_(r0), r_infinity_(rinf) { + : L_(l), y_0_(y0), y_infinity_(yinf) { compute(eval, parms); } ~Zeta() {} @@ -210,14 +189,14 @@ template class Zeta __final { /// Angular momentum of the solution int L_; /// Lower bound of the integration interval - double r_0_; + double y_0_; /// Upper bound of the integration interval - double r_infinity_; + double y_infinity_; /// The actual data: grid, function value and first derivative values RadialSolution function_; /*! Reports progress of differential equation integrator */ - void push_back(const StateVariable & x, double r) { - function_[0].push_back(r); + void push_back(const StateVariable & x, double y) { + function_[0].push_back(y); function_[1].push_back(x[0]); function_[2].push_back(x[1]); } @@ -227,20 +206,20 @@ template class Zeta __final { */ void compute(const ProfileEvaluator & eval, const IntegratorParameters & parms) { namespace odeint = boost::numeric::odeint; - odeint::bulirsch_stoer_dense_out stepper( - parms.eps_abs_, parms.eps_rel_, parms.factor_x_, parms.factor_dxdt_); + odeint::runge_kutta4 stepper; + ODESystem system(eval, L_); // Holds the initial conditions StateVariable init_zeta(2); // Set initial conditions - init_zeta[0] = L_ * std::log(r_0_); - init_zeta[1] = L_ / r_0_; - odeint::integrate_adaptive( + init_zeta[0] = L_ * y_0_; + init_zeta[1] = L_; + odeint::integrate_const( stepper, system, init_zeta, - r_0_, - r_infinity_, + y_0_, + y_infinity_, parms.observer_step_, pcm::bind( &Zeta::push_back, this, pcm::_1, pcm::_2)); @@ -248,13 +227,13 @@ template class Zeta __final { /*! \brief Returns value of function at given point * \param[in] point evaluation point * - * We first check if point is below r_0_, if yes we use - * the asymptotic form L*log(r) in point. + * We first check if point is below y_0_, if yes we use + * the asymptotic form L*y in point. */ double function_impl(double point) const { double zeta = 0.0; - if (point <= r_0_) { - zeta = L_ * std::log(point); + if (point <= y_0_) { + zeta = L_ * point; } else { zeta = utils::splineInterpolation(point, function_[0], function_[1]); } @@ -263,13 +242,12 @@ template class Zeta __final { /*! \brief Returns value of 1st derivative of function at given point * \param[in] point evaluation point * - * We first check if point is below r_0_, if yes we use - * the asymptotic form L / r in point. + * Below y_0_, the as asymptotic form L is used. Otherwise we interpolate. */ double derivative_impl(double point) const { double zeta = 0.0; - if (point <= r_0_) { - zeta = L_ / point; + if (point <= y_0_) { + zeta = L_; } else { zeta = utils::splineInterpolation(point, function_[0], function_[2]); } @@ -288,13 +266,13 @@ template class Zeta __final { */ template class Omega __final { public: - Omega() : L_(0), r_0_(0.0), r_infinity_(0.0) {} + Omega() : L_(0), y_0_(0.0), y_infinity_(0.0) {} Omega(int l, - double r0, - double rinf, + double y0, + double yinf, const ProfileEvaluator & eval, const IntegratorParameters & parms) - : L_(l), r_0_(r0), r_infinity_(rinf) { + : L_(l), y_0_(y0), y_infinity_(yinf) { compute(eval, parms); } ~Omega() {} @@ -314,14 +292,14 @@ template class Omega __final { /// Angular momentum of the solution int L_; /// Lower bound of the integration interval - double r_0_; + double y_0_; /// Upper bound of the integration interval - double r_infinity_; + double y_infinity_; /// The actual data: grid, function value and first derivative values RadialSolution function_; /*! Reports progress of differential equation integrator */ - void push_back(const StateVariable & x, double r) { - function_[0].push_back(r); + void push_back(const StateVariable & x, double y) { + function_[0].push_back(y); function_[1].push_back(x[0]); function_[2].push_back(x[1]); } @@ -331,21 +309,21 @@ template class Omega __final { */ void compute(const ProfileEvaluator & eval, const IntegratorParameters & parms) { namespace odeint = boost::numeric::odeint; - odeint::bulirsch_stoer_dense_out stepper( - parms.eps_abs_, parms.eps_rel_, parms.factor_x_, parms.factor_dxdt_); + odeint::runge_kutta4 stepper; + ODESystem system(eval, L_); // Holds the initial conditions StateVariable init_omega(2); // Set initial conditions - init_omega[0] = -(L_ + 1) * std::log(r_infinity_); - init_omega[1] = -(L_ + 1) / r_infinity_; + init_omega[0] = -(L_ + 1) * y_infinity_; + init_omega[1] = -(L_ + 1); // Notice that we integrate BACKWARDS, so we pass -step to integrate_adaptive - boost::numeric::odeint::integrate_adaptive( + odeint::integrate_const( stepper, system, init_omega, - r_infinity_, - r_0_, + y_infinity_, + y_0_, -parms.observer_step_, pcm::bind( &Omega::push_back, this, pcm::_1, pcm::_2)); @@ -364,12 +342,12 @@ template class Omega __final { * \param[in] point evaluation point * * We first check if point is above r_infinity_, if yes we use - * the asymptotic form -(L+1)*log(r) in point. + * the asymptotic form -(L+1)*y in point. */ double function_impl(double point) const { double omega = 0.0; - if (point >= r_infinity_) { - omega = -(L_ + 1) * std::log(point); + if (point >= y_infinity_) { + omega = -(L_ + 1) * point; } else { omega = utils::splineInterpolation(point, function_[0], function_[1]); } @@ -379,12 +357,12 @@ template class Omega __final { * \param[in] point evaluation point * * We first check if point is above r_infinity_, if yes we use - * the asymptotic form -(L+1)/r in point. + * the asymptotic form -(L+1) in point. */ double derivative_impl(double point) const { double omega = 0.0; - if (point >= r_infinity_) { - omega = -(L_ + 1) / point; + if (point >= y_infinity_) { + omega = -(L_ + 1); } else { omega = utils::splineInterpolation(point, function_[0], function_[2]); } diff --git a/src/green/SphericalDiffuse.cpp b/src/green/SphericalDiffuse.cpp index a2c823148..9480eded2 100644 --- a/src/green/SphericalDiffuse.cpp +++ b/src/green/SphericalDiffuse.cpp @@ -144,12 +144,13 @@ Stencil SphericalDiffuse::operator()(Stencil * sp, double Cr12 = this->coefficient_impl(source, probe); double gr12 = 0.0; - for (int L = 1; L <= maxLGreen_; ++L) { + for (int L = 0; L <= maxLGreen_; ++L) { gr12 += this->imagePotentialComponent_impl(L, source, probe, Cr12); } double r12 = (source - probe).norm(); - return (1.0 / (Cr12 * r12) + gr12); + double gf = (1.0 / (Cr12 * r12) + gr12); + return gf; } template @@ -238,69 +239,37 @@ template void SphericalDiffuse::initSphericalDiffuse() { using namespace detail; - LOG("SphericalDiffuse::initSphericalDiffuse"); // Parameters for the numerical solution of the radial differential equation - double eps_abs_ = 1.0e-10; /*! Absolute tolerance level */ - double eps_rel_ = 1.0e-06; /*! Relative tolerance level */ - double factor_x_ = 0.0; /*! Weight of the state */ - double factor_dxdt_ = 0.0; /*! Weight of the state derivative */ - double r_0_ = 0.5; /*! Lower bound of the integration interval */ + double r_0_ = 0.1; /*! Lower bound of the integration interval */ double r_infinity_ = this->profile_.upperLimit() + - 200.0; /*! Upper bound of the integration interval */ - double observer_step_ = 1.0e-03; /*! Time step between observer calls */ - IntegratorParameters params_(eps_abs_, - eps_rel_, - factor_x_, - factor_dxdt_, - r_0_, - r_infinity_, - observer_step_); + 30.0; /*! Upper bound of the integration interval */ + + double y_0_ = std::log(r_0_); + double y_infinity_ = std::log(r_infinity_); + double relative_width = this->profile_.relativeWidth(); + double observer_step_ = + 1.0e-2 * relative_width; /*! Time step between observer calls */ + + IntegratorParameters params_(y_0_, y_infinity_, observer_step_); ProfileEvaluator eval_ = pcm::bind(&ProfilePolicy::operator(), this->profile_, pcm::_1); - LOG("Computing coefficient for the separation of the Coulomb singularity"); - LOG("Computing first radial solution L = " + pcm::to_string(maxLC_)); - TIMER_ON("computeZeta for coefficient"); zetaC_ = RadialFunction( - maxLC_, r_0_, r_infinity_, eval_, params_); - TIMER_OFF("computeZeta for coefficient"); - LOG("DONE: Computing first radial solution L = " + pcm::to_string(maxLC_)); - - LOG("Computing second radial solution L = " + pcm::to_string(maxLC_)); - TIMER_ON("computeOmega for coefficient"); + maxLC_, y_0_, y_infinity_, eval_, params_); omegaC_ = RadialFunction( - maxLC_, r_0_, r_infinity_, eval_, params_); - TIMER_OFF("computeOmega for coefficient"); - LOG("Computing second radial solution L = " + pcm::to_string(maxLC_)); - LOG("DONE: Computing coefficient for the separation of the Coulomb singularity"); - - LOG("Computing radial solutions for Green's function"); - TIMER_ON("SphericalDiffuse: Looping over angular momentum"); + maxLC_, y_0_, y_infinity_, eval_, params_); zeta_.reserve(maxLGreen_ + 1); omega_.reserve(maxLGreen_ + 1); for (int L = 0; L <= maxLGreen_; ++L) { - // First radial solution - LOG("Computing first radial solution L = " + pcm::to_string(L)); - TIMER_ON("computeZeta L = " + pcm::to_string(L)); - // Create an empty RadialSolution RadialFunction tmp_zeta_( - L, r_0_, r_infinity_, eval_, params_); + L, y_0_, y_infinity_, eval_, params_); zeta_.push_back(tmp_zeta_); - TIMER_OFF("computeZeta L = " + pcm::to_string(L)); - LOG("DONE: Computing first radial solution L = " + pcm::to_string(L)); - - // Second radial solution - LOG("Computing second radial solution L = " + pcm::to_string(L)); - TIMER_ON("computeOmega L = " + pcm::to_string(L)); - // Create an empty RadialSolution + } + for (int L = 0; L <= maxLGreen_; ++L) { RadialFunction tmp_omega_( - L, r_0_, r_infinity_, eval_, params_); + L, y_0_, y_infinity_, eval_, params_); omega_.push_back(tmp_omega_); - TIMER_OFF("computeOmega L = " + pcm::to_string(L)); - LOG("DONE: Computing second radial solution L = " + pcm::to_string(L)); } - TIMER_OFF("SphericalDiffuse: Looping over angular momentum"); - LOG("DONE: Computing radial solutions for Green's function"); } template @@ -323,25 +292,31 @@ double SphericalDiffuse::imagePotentialComponent_impl( cos_gamma = -1.0; double pl_x = Legendre::Pn(L, cos_gamma); + /* Zeta and Omega are now on a logarithmic scale We need to pass the + arguments in the correct scale and then use the chain rule to get + the proper derivative */ + double y1 = std::log(r1); + double y2 = std::log(r2); + /* Sample zeta_[L] */ double zeta1 = 0.0, zeta2 = 0.0, d_zeta2 = 0.0; /* Value of zeta_[L] at point with index 1 */ - pcm::tie(zeta1, pcm::ignore) = zeta_[L](r1); + pcm::tie(zeta1, pcm::ignore) = zeta_[L](y1); /* Value of zeta_[L] and its first derivative at point with index 2 */ - pcm::tie(zeta2, d_zeta2) = zeta_[L](r2); + pcm::tie(zeta2, d_zeta2) = zeta_[L](y2); /* Sample omega_[L] */ double omega1 = 0.0, omega2 = 0.0, d_omega2 = 0.0; /* Value of omega_[L] at point with index 1 */ - pcm::tie(omega1, pcm::ignore) = omega_[L](r1); + pcm::tie(omega1, pcm::ignore) = omega_[L](y1); /* Value of omega_[L] and its first derivative at point with index 2 */ - pcm::tie(omega2, d_omega2) = omega_[L](r2); + pcm::tie(omega2, d_omega2) = omega_[L](y2); double eps_r2 = 0.0; pcm::tie(eps_r2, pcm::ignore) = this->profile_(pp_shift.norm()); /* Evaluation of the Wronskian and the denominator */ - double denominator = (d_zeta2 - d_omega2) * std::pow(r2, 2) * eps_r2; + double denominator = (d_zeta2 - d_omega2) * r2 * eps_r2; double gr12 = 0.0; if (r1 < r2) { @@ -359,7 +334,6 @@ double SphericalDiffuse::imagePotentialComponent_impl( } gr12 = (gr12 - f_L / (r1 * Cr12)) * pl_x; } - return gr12; } @@ -370,26 +344,29 @@ double SphericalDiffuse::coefficient_impl( double r1 = (sp + this->origin_).norm(); double r2 = (pp + this->origin_).norm(); + double y1 = std::log(r1); + double y2 = std::log(r2); + /* Sample zetaC_ */ double zeta1 = 0.0, zeta2 = 0.0, d_zeta2 = 0.0; /* Value of zetaC_ at point with index 1 */ - pcm::tie(zeta1, pcm::ignore) = zetaC_(r1); + pcm::tie(zeta1, pcm::ignore) = zetaC_(y1); /* Value of zetaC_ and its first derivative at point with index 2 */ - pcm::tie(zeta2, d_zeta2) = zetaC_(r2); + pcm::tie(zeta2, d_zeta2) = zetaC_(y2); /* Sample omegaC_ */ double omega1 = 0.0, omega2 = 0.0, d_omega2 = 0.0; /* Value of omegaC_ at point with index 1 */ - pcm::tie(omega1, pcm::ignore) = omegaC_(r1); + pcm::tie(omega1, pcm::ignore) = omegaC_(y1); /* Value of omegaC_ and its first derivative at point with index 2 */ - pcm::tie(omega2, d_omega2) = omegaC_(r2); + pcm::tie(omega2, d_omega2) = omegaC_(y2); double tmp = 0.0, coeff = 0.0; double eps_r2 = 0.0; pcm::tie(eps_r2, pcm::ignore) = this->profile_(r2); /* Evaluation of the Wronskian and the denominator */ - double denominator = (d_zeta2 - d_omega2) * std::pow(r2, 2) * eps_r2; + double denominator = (d_zeta2 - d_omega2) * r2 * eps_r2; if (r1 < r2) { double f_L = r1 / r2; @@ -416,7 +393,8 @@ template class SphericalDiffuse; using dielectric_profile::OneLayerErf; template class SphericalDiffuse; -using dielectric_profile::MembraneTanh; -template class SphericalDiffuse; +using dielectric_profile::OneLayerLog; +template class SphericalDiffuse; + } // namespace green } // namespace pcm diff --git a/src/green/SphericalDiffuse.hpp b/src/green/SphericalDiffuse.hpp index 377c693c3..6e8c060dc 100644 --- a/src/green/SphericalDiffuse.hpp +++ b/src/green/SphericalDiffuse.hpp @@ -40,8 +40,8 @@ class Element; #include "GreenData.hpp" #include "GreensFunction.hpp" #include "InterfacesImpl.hpp" -#include "dielectric_profile/MembraneTanh.hpp" #include "dielectric_profile/OneLayerErf.hpp" +#include "dielectric_profile/OneLayerLog.hpp" #include "dielectric_profile/OneLayerTanh.hpp" namespace pcm { @@ -60,7 +60,7 @@ namespace green { * Green's function * at a pair of points, a translation of the sampling points is performed first. */ -template +template class SphericalDiffuse __final : public GreensFunction { public: /*! Constructor for a one-layer interface @@ -70,12 +70,7 @@ class SphericalDiffuse __final : public GreensFunction { * \param[in] c center of the diffuse layer * \param[in] o center of the sphere * \param[in] l maximum value of angular momentum - * \note For SFINAE to work correctly, this constructor **must be** in the header - * file. */ - template ::value>::type> SphericalDiffuse(double e1, double e2, double w, @@ -88,38 +83,7 @@ class SphericalDiffuse __final : public GreensFunction { maxLC_(2 * l) { initSphericalDiffuse(); } - /*! Constructor for a two-layer interface (membrane) - * \param[in] e1 left-side dielectric constant - * \param[in] e2 middle portion dielectric constant - * \param[in] e3 right-side dielectric constant - * \param[in] w12 width of the first interface layer - * \param[in] w23 width of the second interface layer - * \param[in] c12 center of the first diffuse layer - * \param[in] c23 center of the second diffuse layer - * \param[in] o center of the sphere - * \param[in] l maximum value of angular momentum - * \note For SFINAE to work correctly, this constructor **must be** in the header - * file. - */ - template ::value>::type> - SphericalDiffuse(double e1, - double e2, - double e3, - double w12, - double w23, - double c12, - double c23, - const Eigen::Vector3d & o, - int l) - : GreensFunction( - ProfilePolicy(e1, e2, e3, w12, w23, c12, c23)), - origin_(o), - maxLGreen_(l), - maxLC_(2 * l) { - initSphericalDiffuse(); - } + virtual ~SphericalDiffuse() {} virtual double permittivity() const __override __final { @@ -129,24 +93,28 @@ class SphericalDiffuse __final : public GreensFunction { friend std::ostream & operator<<(std::ostream & os, SphericalDiffuse & gf) { return gf.printObject(os); } + /*! \brief Returns Coulomb singularity separation coefficient * \param[in] source location of the source charge * \param[in] probe location of the probe charge */ double coefficientCoulomb(const Eigen::Vector3d & source, const Eigen::Vector3d & probe) const; + /*! \brief Returns singular part of the Green's function * \param[in] source location of the source charge * \param[in] probe location of the probe charge */ double Coulomb(const Eigen::Vector3d & source, const Eigen::Vector3d & probe) const; + /*! \brief Returns non-singular part of the Green's function (image potential) * \param[in] source location of the source charge * \param[in] probe location of the probe charge */ double imagePotential(const Eigen::Vector3d & source, const Eigen::Vector3d & probe) const; + /*! Returns value of the directional derivative of the * Coulomb singularity separation coefficient for the pair of points p1, p2: * \f$ \nabla_{\mathbf{p_2}}G(\mathbf{p}_1, \mathbf{p}_2)\cdot @@ -162,6 +130,7 @@ class SphericalDiffuse __final : public GreensFunction { double coefficientCoulombDerivative(const Eigen::Vector3d & direction, const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const; + /*! Returns value of the directional derivative of the * singular part of the Greens's function for the pair of points p1, p2: * \f$ \nabla_{\mathbf{p_2}}G(\mathbf{p}_1, \mathbf{p}_2)\cdot @@ -177,6 +146,7 @@ class SphericalDiffuse __final : public GreensFunction { double CoulombDerivative(const Eigen::Vector3d & direction, const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const; + /*! Returns value of the directional derivative of the * non-singular part (image potential) of the Greens's function for the pair of *points p1, p2: @@ -193,6 +163,7 @@ class SphericalDiffuse __final : public GreensFunction { double imagePotentialDerivative(const Eigen::Vector3d & direction, const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const; + /*! Handle to the dielectric profile evaluation */ pcm::tuple epsilon(const Eigen::Vector3d & point) const; void toFile(const std::string & prefix = ""); @@ -205,8 +176,8 @@ class SphericalDiffuse __final : public GreensFunction { * \note This takes care of the origin shift */ virtual Stencil operator()(Stencil * sp, Stencil * pp) const __override; - /*! Returns value of the kernel of the \f$\mathcal{D}\f$ integral operator for - * the + + /*! Returns value of the kernel of the \f$\mathcal{D}\f$ integral operator for the * pair of points p1, p2: * \f$ [\boldsymbol{\varepsilon}\nabla_{\mathbf{p_2}}G(\mathbf{p}_1, * \mathbf{p}_2)]\cdot \mathbf{n}_{\mathbf{p}_2}\f$ @@ -223,10 +194,13 @@ class SphericalDiffuse __final : public GreensFunction { const Eigen::Vector3d & p2) const __override; virtual KernelS exportKernelS_impl() const __override; + virtual KernelD exportKernelD_impl() const __override; + virtual DerivativeProbe exportDerivativeProbe_impl() const __override; virtual double singleLayer_impl(const Element & e, double factor) const __override; + virtual double doubleLayer_impl(const Element & e, double factor) const __override; virtual std::ostream & printObject(std::ostream & os) __override; @@ -242,16 +216,19 @@ class SphericalDiffuse __final : public GreensFunction { * to * obtain G */ int maxLGreen_; + /*! \brief First independent radial solution, used to build Green's function. * \note The vector has dimension maxLGreen_ and has r^l behavior */ std::vector > zeta_; + /*! \brief Second independent radial solution, used to build Green's function. * \note The vector has dimension maxLGreen_ and has r^(-l-1) behavior */ std::vector > omega_; + /*! \brief Returns L-th component of the radial part of the Green's function * \param[in] L angular momentum * \param[in] sp source point @@ -267,21 +244,23 @@ class SphericalDiffuse __final : public GreensFunction { const Eigen::Vector3d & pp, double Cr12) const; /*! @}*/ - /*! @{ Parameters and functions for the calculation of the Coulomb singularity * separation coefficient */ /*! Maximum angular momentum to obtain C(r, r'), needed to separate the Coulomb * singularity */ int maxLC_; // = 2 * maxLGreen_; + /*! \brief First independent radial solution, used to build coefficient. * \note This is needed to separate the Coulomb singularity and has r^l behavior */ RadialFunction zetaC_; + /*! \brief Second independent radial solution, used to build coefficient. * \note This is needed to separate the Coulomb singularity and has r^(-l-1) * behavior */ RadialFunction omegaC_; + /*! \brief Returns coefficient for the separation of the Coulomb singularity * \param[in] sp first point * \param[in] pp second point diff --git a/src/green/dielectric_profile/CMakeLists.txt b/src/green/dielectric_profile/CMakeLists.txt index a397ea7ac..e945e4143 100644 --- a/src/green/dielectric_profile/CMakeLists.txt +++ b/src/green/dielectric_profile/CMakeLists.txt @@ -1,9 +1,9 @@ # List of headers list(APPEND headers_list Anisotropic.hpp -MembraneTanh.hpp Metal.hpp OneLayerErf.hpp +OneLayerLog.hpp OneLayerTanh.hpp Sharp.hpp Uniform.hpp diff --git a/src/green/dielectric_profile/OneLayerErf.hpp b/src/green/dielectric_profile/OneLayerErf.hpp index 049141024..e5cbbe56e 100644 --- a/src/green/dielectric_profile/OneLayerErf.hpp +++ b/src/green/dielectric_profile/OneLayerErf.hpp @@ -115,6 +115,9 @@ class OneLayerErf { return pcm::make_tuple(value(r), derivative(r)); } double upperLimit() const { return domain_.second; } + double relativeWidth() const { + return width_ / std::abs(domain_.second - domain_.first); + } friend std::ostream & operator<<(std::ostream & os, OneLayerErf & th) { return th.printObject(os); } diff --git a/src/green/dielectric_profile/OneLayerLog.hpp b/src/green/dielectric_profile/OneLayerLog.hpp new file mode 100644 index 000000000..fef64ad26 --- /dev/null +++ b/src/green/dielectric_profile/OneLayerLog.hpp @@ -0,0 +1,111 @@ +/** + * PCMSolver, an API for the Polarizable Continuum Model + * Copyright (C) 2017 Roberto Di Remigio, Luca Frediani and collaborators. + * + * This file is part of PCMSolver. + * + * PCMSolver is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PCMSolver is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with PCMSolver. If not, see . + * + * For information on the complete list of contributors to the + * PCMSolver API, see: + */ + +#pragma once + +#include +#include + +#include "Config.hpp" + +#include + +/*! \file OneLayerLog.hpp + * \class OneLayerLog + * \brief A dielectric profile based on the Harrison and Fosso-Tande work \cite + * Fosso-Tande2013 + * \author Luca Frediani + * \date 2017 + */ + +namespace pcm { +namespace dielectric_profile { +class OneLayerLog { +private: + /// Dielectric constant on the left of the interface + double epsilon1_; + /// Dielectric constant one the right of the interface + double epsilon2_; + /// Width of the transition layer + double width_; + /// Center of the transition layer + double center_; + /*! Domain of the permittivity function + * This is formally \f$ [0, +\infty) \f$, for all practical purposes + * the permittivity function is equal to the epsilon2_ already at 6.0 * width_ + * Thus the upper limit in the domain_ is initialized as center_ + 12.0 * width_ + */ + std::pair domain_; + /*! Returns value of dielectric profile at given point + * \param[in] point where to evaluate the profile + */ + double value(double point) const { + double epsLog = std::log(epsilon2_ / epsilon1_); + double val = (1.0 + boost::math::erf((point - center_) / width_)) / 2.0; + double retval = epsilon1_ * std::exp(epsLog * val); // epsilon(r) + return retval; + } + /*! Returns value of derivative of dielectric profile at given point + * \param[in] point where to evaluate the derivative + */ + double derivative(double point) const { + double functionValue = value(point); + double epsLog = std::log(epsilon2_ / epsilon1_); + double factor = epsLog / (width_ * std::sqrt(M_PI)); + double t = (point - center_) / width_; + double val = std::exp(-std::pow(t, 2)); + return functionValue * factor * val; // first derivative of epsilon(r) + } + std::ostream & printObject(std::ostream & os) { + os << "Profile functional form: log" << std::endl; + os << "Permittivity left/inside = " << epsilon1_ << std::endl; + os << "Permittivity right/outside = " << epsilon2_ << std::endl; + os << "Profile width = " << width_ << " AU" << std::endl; + os << "Profile center = " << center_ << " AU"; + return os; + } + +public: + OneLayerLog() {} + OneLayerLog(double e1, double e2, double w, double c) + : epsilon1_(e1), + epsilon2_(e2), + width_(w / 6.0), + center_(c), + domain_(std::make_pair(0.0, center_ + 12.0 * width_)) {} + /*! Returns a tuple holding the permittivity and its derivative + * \param[in] r evaluation point + */ + pcm::tuple operator()(const double r) const { + return pcm::make_tuple(value(r), derivative(r)); + } + double upperLimit() const { return domain_.second; } + double relativeWidth() const { + return width_ / std::abs(domain_.second - domain_.first); + } + friend std::ostream & operator<<(std::ostream & os, OneLayerLog & th) { + return th.printObject(os); + } +}; +} // namespace dielectric_profile +} // namespace pcm diff --git a/src/green/dielectric_profile/OneLayerTanh.hpp b/src/green/dielectric_profile/OneLayerTanh.hpp index 21f5b41b0..f73bd39b5 100644 --- a/src/green/dielectric_profile/OneLayerTanh.hpp +++ b/src/green/dielectric_profile/OneLayerTanh.hpp @@ -113,6 +113,9 @@ class OneLayerTanh { return pcm::make_tuple(value(r), derivative(r)); } double upperLimit() const { return domain_.second; } + double relativeWidth() const { + return width_ / std::abs(domain_.second - domain_.first); + } friend std::ostream & operator<<(std::ostream & os, OneLayerTanh & th) { return th.printObject(os); } diff --git a/src/interface/Meddle.hpp b/src/interface/Meddle.hpp index 28fa71f3d..746bb23af 100644 --- a/src/interface/Meddle.hpp +++ b/src/interface/Meddle.hpp @@ -118,38 +118,46 @@ class PCMSolver_API Meddle __final { const PCMInput & host_input, const HostWriter & writer); ~Meddle(); + /*! \brief Getter for the molecule object */ Molecule molecule() const attribute(pure); + /*! \brief Getter for the number of finite elements composing the molecular cavity * \return the size of the cavity */ PCMSolverIndex getCavitySize() const attribute(pure); + /*! \brief Getter for the number of irreducible finite elements composing the * molecular cavity * \return the number of irreducible finite elements */ PCMSolverIndex getIrreducibleCavitySize() const attribute(pure); + /*! \brief Getter for the centers of the finite elements composing the molecular * cavity * \param[out] centers array holding the coordinates of the finite elements * centers */ void getCenters(double centers[]) const; + /*! \brief Getter for the center of the i-th finite element * \param[in] its index of the finite element * \param[out] center array holding the coordinates of the finite element center */ void getCenter(int its, double center[]) const; + /*! \brief Getter for the centers of the finite elements composing the molecular * cavity * \return a matrix with the finite elements centers (dimensions 3 x number of * finite elements) */ Eigen::Matrix3Xd getCenters() const attribute(pure); + /*! \brief Getter for the areas/weights of the finite elements * \param[out] areas array holding the weights/areas of the finite elements */ void getAreas(double areas[]) const; + /*! \brief Computes ASC given a MEP and the desired irreducible representation * \param[in] mep_name label of the MEP surface function * \param[in] asc_name label of the ASC surface function @@ -159,6 +167,7 @@ class PCMSolver_API Meddle __final { * and computes the corresponding ASC. */ void computeASC(const char * mep_name, const char * asc_name, int irrep) const; + /*! \brief Computes response ASC given a MEP and the desired irreducible * representation * \param[in] mep_name label of the MEP surface function @@ -172,6 +181,7 @@ class PCMSolver_API Meddle __final { void computeResponseASC(const char * mep_name, const char * asc_name, int irrep) const; + /*! \brief Computes the polarization energy * \param[in] mep_name label of the MEP surface function * \param[in] asc_name label of the ASC surface function @@ -186,6 +196,7 @@ class PCMSolver_API Meddle __final { * \return the ASC dipole, i.e. \sqrt{\sum_i \mu_i^2} */ double getASCDipole(const char * asc_name, double dipole[]) const; + /*! \brief Retrieves data wrapped in a given surface function * \param[in] size the size of the surface function * \param[in] values the values wrapped in the surface function @@ -194,6 +205,7 @@ class PCMSolver_API Meddle __final { void getSurfaceFunction(PCMSolverIndex size, double values[], const char * name) const; + /*! \brief Sets a surface function given data and label * \param[in] size the size of the surface function * \param[in] values the values to be wrapped in the surface function @@ -202,14 +214,17 @@ class PCMSolver_API Meddle __final { void setSurfaceFunction(PCMSolverIndex size, double values[], const char * name) const; + /*! \brief Prints surface function contents to host output * \param[in] name label of the surface function */ void printSurfaceFunction(const char * name) const; + /*! \brief Dumps all currently saved surface functions to NumPy arrays in .npy * files */ void saveSurfaceFunctions() const; + /*! \brief Dumps a surface function to NumPy array in .npy file * \param[in] name label of the surface function * @@ -217,6 +232,7 @@ class PCMSolver_API Meddle __final { * **without** .npy extension */ void saveSurfaceFunction(const char * name) const; + /*! \brief Loads a surface function from a .npy file * \param[in] name label of the surface function * @@ -224,9 +240,11 @@ class PCMSolver_API Meddle __final { * **without** .npy extension */ void loadSurfaceFunction(const char * name) const; + /*! \brief Prints citation and set up information */ void printInfo() const; + /*! \brief Writes timing results for the API */ void writeTimings() const; diff --git a/src/utils/MathUtils.hpp b/src/utils/MathUtils.hpp index 2c32136ec..770def5eb 100644 --- a/src/utils/MathUtils.hpp +++ b/src/utils/MathUtils.hpp @@ -303,14 +303,26 @@ inline double splineInterpolation(const double point, const std::vector & grid, const std::vector & function) { // Find nearest points on grid to the arbitrary point given - size_t index = std::distance(grid.begin(), - std::lower_bound(grid.begin(), grid.end(), point)) - - 1; + int index = + std::distance(grid.begin(), std::lower_bound(grid.begin(), grid.end(), point)); + + int imax = grid.size() - 1; + if (index <= 0) + index = 1; + if (index >= imax - 1) + index = imax - 2; // Parameters for the interpolating spline - Eigen::Vector3d x, y; - x << grid[index - 1], grid[index], grid[index + 1]; - y << function[index - 1], function[index], function[index + 1]; + Eigen::Vector4d x = (Eigen::Vector4d() << grid[index - 1], + grid[index], + grid[index + 1], + grid[index + 2]) + .finished(); + Eigen::Vector4d y = (Eigen::Vector4d() << function[index - 1], + function[index], + function[index + 1], + function[index + 2]) + .finished(); SplineFunction s(x, y); return s(point); diff --git a/tests/C_host/C_host-functions.h b/tests/C_host/C_host-functions.h index 57e926845..00e94c66d 100644 --- a/tests/C_host/C_host-functions.h +++ b/tests/C_host/C_host-functions.h @@ -51,7 +51,9 @@ typedef enum { false, true } bool; #define UNUSED_FUNCTION(x) UNUSED_##x #endif +#ifndef M_PI #define M_PI 3.14159265358979323846 +#endif void host_writer(const char * message); diff --git a/tests/bi_operators/bi_operators_collocation.cpp b/tests/bi_operators/bi_operators_collocation.cpp index 10dc972ac..b495f7b92 100644 --- a/tests/bi_operators/bi_operators_collocation.cpp +++ b/tests/bi_operators/bi_operators_collocation.cpp @@ -37,6 +37,7 @@ #include "green/SphericalDiffuse.hpp" #include "green/UniformDielectric.hpp" #include "green/Vacuum.hpp" +#include "green/dielectric_profile/OneLayerTanh.hpp" #include "utils/MathUtils.hpp" using namespace pcm; @@ -45,12 +46,15 @@ using cavity::GePolCavity; using green::Vacuum; using green::UniformDielectric; using green::SphericalDiffuse; +using dielectric_profile::OneLayerTanh; SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_operators][bi_operators_collocation]") { GIVEN("A GePol cavity for a single sphere in the origin") { double radius = 1.44; - Molecule molec = dummy<0>(1.44 / bohrToAngstrom()); + Eigen::Vector3d offset; + offset << 1.0, 2.0, 3.0; + Molecule molec = dummy<0>(1.44 / bohrToAngstrom(), offset); double area = 10.0; GePolCavity cavity = GePolCavity(molec, area, 0.0, 100.0); Eigen::MatrixXd results = Eigen::MatrixXd::Zero(cavity.size(), cavity.size()); @@ -117,11 +121,12 @@ SCENARIO("A collocation integrator with approximate diagonal elements", * by collocation of the spherical diffuse matrix representations of S and D */ AND_WHEN("the spherical diffuse with a tanh profile Green's function is used") { - double epsilon = 80.0; + double epsilon1 = 2.0; + double epsilon2 = 80.0; double width = 5.0; - double sphereRadius = 100.0; - SphericalDiffuse<> gf( - epsilon, epsilon, width, sphereRadius, Eigen::Vector3d::Zero(), 3); + double sphereRadius = 20.0; + SphericalDiffuse gf( + epsilon1, epsilon2, width, sphereRadius, Eigen::Vector3d::Zero(), 5); THEN("the matrix elements of S are") { results = op.computeS(cavity, gf); reference = diff --git a/tests/bi_operators/bi_operators_purisima.cpp b/tests/bi_operators/bi_operators_purisima.cpp index 9db0243ac..52bd0eb9f 100644 --- a/tests/bi_operators/bi_operators_purisima.cpp +++ b/tests/bi_operators/bi_operators_purisima.cpp @@ -34,7 +34,6 @@ #include "bi_operators/Purisima.hpp" #include "cavity/Element.hpp" #include "cavity/GePolCavity.hpp" -#include "green/SphericalDiffuse.hpp" #include "green/UniformDielectric.hpp" #include "green/Vacuum.hpp" #include "utils/MathUtils.hpp" @@ -44,7 +43,6 @@ using bi_operators::Purisima; using cavity::GePolCavity; using green::Vacuum; using green::UniformDielectric; -using green::SphericalDiffuse; SCENARIO( "A collocation integrator with diagonal elements according to Purisima for D", diff --git a/tests/bi_operators/tanhsphericaldiffuse_D_collocation.npy b/tests/bi_operators/tanhsphericaldiffuse_D_collocation.npy index 99ee729f6..a16abf62d 100644 Binary files a/tests/bi_operators/tanhsphericaldiffuse_D_collocation.npy and b/tests/bi_operators/tanhsphericaldiffuse_D_collocation.npy differ diff --git a/tests/bi_operators/tanhsphericaldiffuse_S_collocation.npy b/tests/bi_operators/tanhsphericaldiffuse_S_collocation.npy index ddb27c3c3..83cad39da 100644 Binary files a/tests/bi_operators/tanhsphericaldiffuse_S_collocation.npy and b/tests/bi_operators/tanhsphericaldiffuse_S_collocation.npy differ diff --git a/tests/bi_operators/uniformdielectric_D_collocation.npy b/tests/bi_operators/uniformdielectric_D_collocation.npy index 8e3a4de8b..6020f69ce 100644 Binary files a/tests/bi_operators/uniformdielectric_D_collocation.npy and b/tests/bi_operators/uniformdielectric_D_collocation.npy differ diff --git a/tests/bi_operators/uniformdielectric_D_purisima.npy b/tests/bi_operators/uniformdielectric_D_purisima.npy index fe3fabdf5..97251d44a 100644 Binary files a/tests/bi_operators/uniformdielectric_D_purisima.npy and b/tests/bi_operators/uniformdielectric_D_purisima.npy differ diff --git a/tests/bi_operators/uniformdielectric_S_collocation.npy b/tests/bi_operators/uniformdielectric_S_collocation.npy index 1585c6a75..496aed54f 100644 Binary files a/tests/bi_operators/uniformdielectric_S_collocation.npy and b/tests/bi_operators/uniformdielectric_S_collocation.npy differ diff --git a/tests/bi_operators/update_reference_files.cpp b/tests/bi_operators/update_reference_files.cpp index 02a3d1139..d7dbe6711 100644 --- a/tests/bi_operators/update_reference_files.cpp +++ b/tests/bi_operators/update_reference_files.cpp @@ -40,6 +40,7 @@ #include "green/SphericalDiffuse.hpp" #include "green/UniformDielectric.hpp" #include "green/Vacuum.hpp" +#include "green/dielectric_profile/OneLayerTanh.hpp" #include "utils/MathUtils.hpp" using namespace pcm; @@ -52,6 +53,7 @@ using green::UniformDielectric; using green::IonicLiquid; using green::AnisotropicLiquid; using green::SphericalDiffuse; +using dielectric_profile::OneLayerTanh; void save_vacuum_collocation(); void save_uniform_dielectric_collocation(); @@ -110,18 +112,20 @@ void save_uniform_dielectric_collocation() { } void save_tanh_spherical_diffuse_collocation() { - double epsilon = 80.0; + double epsilon1 = 2.0; + double epsilon2 = 80.0; double width = 5.0; - double sphereRadius = 100.0; - Molecule molec = dummy<0>(1.44 / bohrToAngstrom()); + double sphereRadius = 20.0; + SphericalDiffuse gf( + epsilon1, epsilon2, width, sphereRadius, Eigen::Vector3d::Zero(), 5); + Eigen::Vector3d offset; + offset << 1.0, 2.0, 3.0; + Molecule molec = dummy<0>(1.44 / bohrToAngstrom(), offset); double area = 10.0; GePolCavity cavity(molec, area, 0.0, 100.0); Collocation op; - SphericalDiffuse<> gf( - epsilon, epsilon, width, sphereRadius, Eigen::Vector3d::Zero(), 3); - Eigen::MatrixXd S_results = op.computeS(cavity, gf); cnpy::custom::npy_save("tanhsphericaldiffuse_S_collocation.npy", S_results); Eigen::MatrixXd D_results = op.computeD(cavity, gf); @@ -223,17 +227,20 @@ void save_anisotropic_liquid_numerical() { } void save_tanh_spherical_diffuse_numerical() { - double epsilon = 80.0; + double epsilon1 = 2.0; + double epsilon2 = 80.0; double width = 5.0; - double sphereRadius = 100.0; - Molecule molec = dummy<0>(1.44 / bohrToAngstrom()); + double sphereRadius = 10.0; + Eigen::Vector3d offset; + offset << 1.0, 2.0, 3.0; + Molecule molec = dummy<0>(1.44 / bohrToAngstrom(), offset); double area = 10.0; GePolCavity cavity(molec, area, 0.0, 100.0); Numerical op; - SphericalDiffuse<> gf( - epsilon, epsilon, width, sphereRadius, Eigen::Vector3d::Zero(), 3); + SphericalDiffuse gf( + epsilon1, epsilon2, width, sphereRadius, Eigen::Vector3d::Zero(), 3); Eigen::MatrixXd S_results = op.computeS(cavity, gf); cnpy::custom::npy_save("tanhsphericaldiffuse_S_numerical.npy", S_results); diff --git a/tests/bi_operators/vacuum_D_collocation.npy b/tests/bi_operators/vacuum_D_collocation.npy index b5f5498be..57fef2585 100644 Binary files a/tests/bi_operators/vacuum_D_collocation.npy and b/tests/bi_operators/vacuum_D_collocation.npy differ diff --git a/tests/bi_operators/vacuum_D_purisima.npy b/tests/bi_operators/vacuum_D_purisima.npy index 458185a5d..8562747e3 100644 Binary files a/tests/bi_operators/vacuum_D_purisima.npy and b/tests/bi_operators/vacuum_D_purisima.npy differ diff --git a/tests/bi_operators/vacuum_S_collocation.npy b/tests/bi_operators/vacuum_S_collocation.npy index b89386877..571d50f1a 100644 Binary files a/tests/bi_operators/vacuum_S_collocation.npy and b/tests/bi_operators/vacuum_S_collocation.npy differ diff --git a/tests/dielectric_profile/one_layer.cpp b/tests/dielectric_profile/one_layer.cpp index 3c214cef5..1907a2803 100644 --- a/tests/dielectric_profile/one_layer.cpp +++ b/tests/dielectric_profile/one_layer.cpp @@ -33,6 +33,7 @@ #include #include "green/dielectric_profile/OneLayerErf.hpp" +#include "green/dielectric_profile/OneLayerLog.hpp" #include "green/dielectric_profile/OneLayerTanh.hpp" double tanh_value(double point, double e1, double e2, double w, double c); @@ -41,6 +42,9 @@ double tanh_deriv(double point, double e1, double e2, double w, double c); double erf_value(double point, double e1, double e2, double w, double c); double erf_deriv(double point, double e1, double e2, double w, double c); +double log_value(double point, double e1, double e2, double w, double c); +double log_deriv(double point, double e1, double e2, double w, double c); + double distribution(double fMin, double fMax); using namespace pcm::dielectric_profile; @@ -50,48 +54,66 @@ SCENARIO("Diffuse permittivity single layers", "[dielectric_profile][one_layer]" std::srand(std::time(0)); double eps1 = 78.39; double eps2 = 1.0; - double center = 50.0; + double center = 15.0; double width = 10.0; - + double step = 0.5; + int nPoints = 61; /*! \class OneLayerTanh * \test \b TanhOneLayerTest tests the evaluation of the one layer hyperbolic * tangent profile against the analytic value */ WHEN("the sigmoidal profile is modelled by the hyperbolic tangent function") { OneLayerTanh diffuse(eps1, eps2, width, center); - double value = 0.0, deriv = 0.0; - double point = distribution(0.0, 100.0); - pcm::tie(value, deriv) = diffuse(point); - THEN("the value of the profile at a random point is") { - double analytic = tanh_value(point, eps1, eps2, width, center); - INFO(" The evaluation point is: " << point); - REQUIRE(value == Approx(analytic)); - } - AND_THEN("the value of the first derivative at a random point is") { - double analyticDeriv = tanh_deriv(point, eps1, eps2, width, center); - INFO(" The evaluation point is: " << point); - REQUIRE(deriv == Approx(analyticDeriv)); + THEN("the value of the dielectric profile and its derivative on a grid are") { + for (int i = 0; i < nPoints; i++) { + double point = step * i; + double value = 0.0, deriv = 0.0; + double analytic = tanh_value(point, eps1, eps2, width, center); + double analyticDeriv = tanh_deriv(point, eps1, eps2, width, center); + pcm::tie(value, deriv) = diffuse(point); + INFO(" The evaluation point is: " << point); + REQUIRE(value == Approx(analytic)); + REQUIRE(deriv == Approx(analyticDeriv)); + } } } - /*! \class OneLayerErf * \test \b TanhOneLayerTest tests the evaluation of the one layer hyperbolic * tangent profile against the analytic value */ WHEN("the sigmoidal profile is modelled by the error function") { OneLayerErf diffuse(eps1, eps2, width, center); - double value = 0.0, deriv = 0.0; - double point = distribution(0.0, 100.0); - pcm::tie(value, deriv) = diffuse(point); - THEN("the value of the profile at a random point is") { - double analytic = erf_value(point, eps1, eps2, width, center); - INFO(" The evaluation point is: " << point); - REQUIRE(value == Approx(analytic)); + THEN("the value of the dielectric profile and its derivative on a grid are") { + for (int i = 0; i < nPoints; i++) { + double point = step * i; + double value = 0.0, deriv = 0.0; + double analytic = erf_value(point, eps1, eps2, width, center); + double analyticDeriv = erf_deriv(point, eps1, eps2, width, center); + pcm::tie(value, deriv) = diffuse(point); + INFO(" The evaluation point is: " << point); + REQUIRE(value == Approx(analytic)); + REQUIRE(deriv == Approx(analyticDeriv)); + } } - AND_THEN("the value of the first derivative at a random point is") { - double analyticDeriv = erf_deriv(point, eps1, eps2, width, center); - INFO(" The evaluation point is: " << point); - REQUIRE(deriv == Approx(analyticDeriv)); + } + + /*! \class OneLayerLog + * \test \b LogOneLayerTest tests the evaluation of the one layer logarithmic + * profile against the analytic value + */ + WHEN("the sigmoidal profile is modelled by the lograrithmic function") { + OneLayerLog diffuse(eps1, eps2, width, center); + THEN("the value of the dielectric profile and its derivative on a grid are") { + for (int i = 0; i < nPoints; i++) { + double point = step * i; + double value = 0.0, deriv = 0.0; + double analytic = log_value(point, eps1, eps2, width, center); + double analyticDeriv = log_deriv(point, eps1, eps2, width, center); + pcm::tie(value, deriv) = diffuse(point); + INFO(" The evaluation point is: " << point); + REQUIRE(value == Approx(analytic)); + REQUIRE(deriv == Approx(analyticDeriv)); + } } } } @@ -104,6 +126,7 @@ double tanh_value(double point, double e1, double e2, double w, double c) { double tanh_r = std::tanh((point - c) / w); return (epsPlus + epsMinus * tanh_r); } + double tanh_deriv(double point, double e1, double e2, double w, double c) { w /= 6.0; double factor = (e2 - e1) / (2.0 * w); @@ -118,6 +141,7 @@ double erf_value(double point, double e1, double e2, double w, double c) { double val = pcm::erf((point - c) / w); return (epsPlus + epsMinus * val); } + double erf_deriv(double point, double e1, double e2, double w, double c) { w /= 6.0; double factor = (e2 - e1) / (w * std::sqrt(M_PI)); @@ -126,6 +150,24 @@ double erf_deriv(double point, double e1, double e2, double w, double c) { return (factor * val); } +double log_value(double point, double e1, double e2, double w, double c) { + w /= 6.0; + double epsLog = std::log(e2 / e1); + double val = (1.0 + pcm::erf((point - c) / w)) / 2.0; + double retval = e1 * std::exp(epsLog * val); // epsilon(r) + return retval; +} + +double log_deriv(double point, double e1, double e2, double w, double c) { + double functionValue = log_value(point, e1, e2, w, c); + w /= 6.0; + double epsLog = std::log(e2 / e1); + double factor = epsLog / (w * std::sqrt(M_PI)); + double t = (point - c) / w; + double val = std::exp(-std::pow(t, 2)); + return functionValue * factor * val; // first derivative of epsilon(r) +} + double distribution(double fMin, double fMax) { double f = (double)std::rand() / RAND_MAX; return fMin + f * (fMax - fMin); diff --git a/tests/green/CMakeLists.txt b/tests/green/CMakeLists.txt index 1e5815ba2..c86334323 100644 --- a/tests/green/CMakeLists.txt +++ b/tests/green/CMakeLists.txt @@ -5,6 +5,7 @@ endif() # green_spherical_diffuse.cpp test add_Catch_test(green_spherical_diffuse "green;green_spherical_diffuse") +set_tests_properties(green_spherical_diffuse PROPERTIES COST 100.0) # green_vacuum.cpp test add_Catch_test(green_vacuum "green;green_vacuum") diff --git a/tests/green/green_spherical_diffuse.cpp b/tests/green/green_spherical_diffuse.cpp index 371b9409b..1925d604f 100644 --- a/tests/green/green_spherical_diffuse.cpp +++ b/tests/green/green_spherical_diffuse.cpp @@ -32,7 +32,6 @@ #include "green/DerivativeTypes.hpp" #include "green/SphericalDiffuse.hpp" -#include "green/dielectric_profile/MembraneTanh.hpp" #include "green/dielectric_profile/OneLayerErf.hpp" #include "green/dielectric_profile/OneLayerTanh.hpp" @@ -40,12 +39,11 @@ using namespace pcm; using green::SphericalDiffuse; using dielectric_profile::OneLayerErf; using dielectric_profile::OneLayerTanh; -using dielectric_profile::MembraneTanh; SCENARIO("Evaluation of the spherical diffuse Green's function and its derivatives", "[green][green_spherical_diffuse]") { GIVEN("A permittivity profile modelled by the hyperbolic tangent function") { - int maxL = 3; + int maxL = 10; // High dielectric constant inside double eps1 = 80.0; // Low dielectric constant outside @@ -68,9 +66,10 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ probeNormal2.normalize(); WHEN("the spherical droplet is centered at the origin") { Eigen::Vector3d sphereCenter = Eigen::Vector3d::Zero(); - SphericalDiffuse<> gf(eps1, eps2, width, sphereRadius, sphereCenter, maxL); + SphericalDiffuse gf( + eps1, eps2, width, sphereRadius, sphereCenter, maxL); THEN("the value of the Green's function inside the droplet is") { - double value = 0.0125073117820161759; + double value = 0.0204265162808782985; double gf_value = gf.kernelS(source1, probe1); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -81,7 +80,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ REQUIRE(value == Approx(gf_value)); } AND_THEN("the value of the Green's function outside the droplet is") { - double value = 0.500045986670381581; + double value = 0.428395676083591359; double gf_value = gf.kernelS(source2, probe2); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -93,7 +92,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the probe " "point inside the droplet is") { - double derProbe = -0.0125062279977827817; + double derProbe = -0.0124999769449823939; double gf_derProbe = gf.derivativeProbe(probeNormal1, source1, probe1); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -105,7 +104,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "probe point outside the droplet is") { - double derProbe = -0.290055591821714032; + double derProbe = -0.288385047571004804; double gf_derProbe = gf.derivativeProbe(probeNormal2, source2, probe2); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -117,7 +116,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the source " "point inside the droplet is") { - double derSource = 0.0124986222807023373; + double derSource = 0.00937504646828998811; double gf_derSource = gf.derivativeSource(sourceNormal1, source1, probe1); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -129,7 +128,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "source point outside the droplet is") { - double derSource = 0.288797487450476176; + double derSource = 3.22957321418654297; double gf_derSource = gf.derivativeSource(sourceNormal2, source2, probe2); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -144,9 +143,10 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ AND_WHEN("the spherical droplet is centered away from the origin") { Eigen::Vector3d sphereCenter = (Eigen::Vector3d() << 25.0, 0.0, 0.0).finished(); - SphericalDiffuse<> gf(eps1, eps2, width, sphereRadius, sphereCenter, maxL); + SphericalDiffuse gf( + eps1, eps2, width, sphereRadius, sphereCenter, maxL); THEN("the value of the Green's function inside the droplet is") { - double value = 0.0125233347952455679; + double value = 0.0173358023608628994; double gf_value = gf.kernelS(source1, probe1); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -157,7 +157,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ REQUIRE(value == Approx(gf_value)); } AND_THEN("the value of the Green's function outside the droplet is") { - double value = 0.500029014239111391; + double value = 0.471193749836353093; double gf_value = gf.kernelS(source2, probe2); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -169,7 +169,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the probe " "point inside the droplet is") { - double derProbe = -0.0125024378794594271; + double derProbe = -0.0124834504454732209; double gf_derProbe = gf.derivativeProbe(probeNormal1, source1, probe1); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -181,7 +181,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "probe point outside the droplet is") { - double derProbe = -0.289998406246272378; + double derProbe = -0.290867341330436346; double gf_derProbe = gf.derivativeProbe(probeNormal2, source2, probe2); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -193,7 +193,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the source " "point inside the droplet is") { - double derSource = 0.0124899030161038094; + double derSource = 0.0124835522706361057; double gf_derSource = gf.derivativeSource(sourceNormal1, source1, probe1); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -205,7 +205,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "source point outside the droplet is") { - double derSource = 0.288655902260792629; + double derSource = 4.9830666203676266; double gf_derSource = gf.derivativeSource(sourceNormal2, source2, probe2); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -245,7 +245,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ SphericalDiffuse gf( eps1, eps2, width, sphereRadius, sphereCenter, maxL); THEN("the value of the Green's function inside the droplet is") { - double value = 0.0125073115838534744; + double value = 0.0204465601345453427; double gf_value = gf.kernelS(source1, probe1); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -256,7 +256,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ REQUIRE(value == Approx(gf_value)); } AND_THEN("the value of the Green's function outside the droplet is") { - double value = 0.499912361753220347; + double value = 16.4638334471119663; double gf_value = gf.kernelS(source2, probe2); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -268,7 +268,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the probe " "point inside the droplet is") { - double derProbe = -0.0125062686709680876; + double derProbe = -0.0124999769317464537; double gf_derProbe = gf.derivativeProbe(probeNormal1, source1, probe1); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -280,7 +280,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "probe point outside the droplet is") { - double derProbe = -0.289975568501799064; + double derProbe = -7.06834149583279725; double gf_derProbe = gf.derivativeProbe(probeNormal2, source2, probe2); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -292,7 +292,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the source " "point inside the droplet is") { - double derSource = 0.0124986220027042266; + double derSource = 0.00937504649521289646; double gf_derSource = gf.derivativeSource(sourceNormal1, source1, probe1); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -304,7 +304,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "source point outside the droplet is") { - double derSource = 0.288712932449142201; + double derSource = -10.8295013604120527; double gf_derSource = gf.derivativeSource(sourceNormal2, source2, probe2); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -322,7 +322,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ SphericalDiffuse gf( eps1, eps2, width, sphereRadius, sphereCenter, maxL); THEN("the value of the Green's function inside the droplet is") { - double value = 0.0125233447844991293; + double value = 0.0173558529449408631; double gf_value = gf.kernelS(source1, probe1); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -333,7 +333,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ REQUIRE(value == Approx(gf_value)); } AND_THEN("the value of the Green's function outside the droplet is") { - double value = 0.499897402784606149; + double value = -1.64961265861670991; double gf_value = gf.kernelS(source2, probe2); INFO("ref_value = " << std::setprecision( std::numeric_limits::digits10) @@ -345,7 +345,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the probe " "point inside the droplet is") { - double derProbe = -0.0125024373412441214; + double derProbe = -0.0124834509424368023; double gf_derProbe = gf.derivativeProbe(probeNormal1, source1, probe1); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -357,7 +357,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "probe point outside the droplet is") { - double derProbe = -0.289953249665575452; + double derProbe = 1.03455899307935972; double gf_derProbe = gf.derivativeProbe(probeNormal2, source2, probe2); INFO("ref_derProbe = " << std::setprecision(std::numeric_limits::digits10) @@ -369,7 +369,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } THEN("the value of the Green's function directional derivative wrt the source " "point inside the droplet is") { - double derSource = 0.0124899033273999371; + double derSource = 0.0124835526376168571; double gf_derSource = gf.derivativeSource(sourceNormal1, source1, probe1); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) @@ -381,7 +381,7 @@ SCENARIO("Evaluation of the spherical diffuse Green's function and its derivativ } AND_THEN("the value of the Green's function directional derivative wrt the " "source point outside the droplet is") { - double derSource = 0.288694045107451558; + double derSource = -6.97655723591150689; double gf_derSource = gf.derivativeSource(sourceNormal2, source2, probe2); INFO("ref_derSource = " << std::setprecision(std::numeric_limits::digits10) diff --git a/tests/iefpcm/CMakeLists.txt b/tests/iefpcm/CMakeLists.txt index a70a364b4..4eaee936b 100644 --- a/tests/iefpcm/CMakeLists.txt +++ b/tests/iefpcm/CMakeLists.txt @@ -11,6 +11,7 @@ add_Catch_test(iefpcm_anisotropic-symmetry "solver;iefpcm;iefpcm_anisotropic-sym # iefpcm_diffuse-gepol-point.cpp test add_Catch_test(iefpcm_diffuse-gepol-point "solver;iefpcm;iefpcm_diffuse-gepol-point;anisotropic") +set_tests_properties(iefpcm_diffuse-gepol-point PROPERTIES COST 200.0) # iefpcm_gepol-point.cpp test add_Catch_test(iefpcm_gepol-point "solver;iefpcm;iefpcm_gepol-point") diff --git a/tests/iefpcm/iefpcm_diffuse-gepol-point.cpp b/tests/iefpcm/iefpcm_diffuse-gepol-point.cpp index 6f2ed1541..2c8d27361 100644 --- a/tests/iefpcm/iefpcm_diffuse-gepol-point.cpp +++ b/tests/iefpcm/iefpcm_diffuse-gepol-point.cpp @@ -33,6 +33,7 @@ #include "green/DerivativeTypes.hpp" #include "green/SphericalDiffuse.hpp" #include "green/Vacuum.hpp" +#include "green/dielectric_profile/OneLayerTanh.hpp" #include "solver/IEFSolver.hpp" #include "utils/Molecule.hpp" @@ -42,16 +43,17 @@ using cavity::GePolCavity; using green::Vacuum; using green::SphericalDiffuse; using solver::IEFSolver; +using dielectric_profile::OneLayerTanh; SCENARIO("Test solver for the IEFPCM for a point charge in a spherical diffuse " "environment and a GePol cavity", "[solver][iefpcm][iefpcm_diffuse-gepol-point][anisotropic]") { GIVEN("An isotropic environment modelled as a spherical diffuse permittivity") { - Eigen::Vector3d origin = - (Eigen::Vector3d() << 68.0375, -21.1234, 56.6198).finished(); - double eps1 = 78.39; - double eps2 = 78.39; - double center = 100.0; + Eigen::Vector3d offset; + offset << 10.0, -5.00, 5.00; + double eps1 = 2.0; + double eps2 = 80.0; + double center = 10.0; double width = 5.0; Vacuum<> gf_i; bool symm = true; @@ -59,7 +61,7 @@ SCENARIO("Test solver for the IEFPCM for a point charge in a spherical diffuse " Collocation op; double charge = 8.0; - double totalASC = -charge * (eps1 - 1) / eps1; + double totalASC = -7.8740102704; /*! \class IEFSolver * \test \b pointChargeDiffuseGePol tests IEFSolver using a point charge with a * GePol cavity and a spherical diffuse interface @@ -68,17 +70,19 @@ SCENARIO("Test solver for the IEFPCM for a point charge in a spherical diffuse " */ WHEN("the spherical diffuse layer is centered at the origin and the charge is " "away from the origin") { - Molecule point = dummy<0>(2.929075493, origin); + Molecule point = dummy<0>(2.0, offset); double area = 1.0; double probeRadius = 0.0; double minRadius = 100.0; GePolCavity cavity(point, area, probeRadius, minRadius); - SphericalDiffuse<> gf_o(eps1, eps2, width, center, Eigen::Vector3d::Zero(), 3); + int maxL = 5; + SphericalDiffuse gf_o( + eps1, eps2, width, center, Eigen::Vector3d::Zero(), maxL); IEFSolver solver(symm); solver.buildSystemMatrix(cavity, gf_i, gf_o, op); int size = cavity.size(); - Eigen::VectorXd fake_mep = computeMEP(cavity.elements(), charge, origin); + Eigen::VectorXd fake_mep = computeMEP(cavity.elements(), charge, offset); for (int i = 0; i < size; ++i) { INFO("fake_mep(" << i << ") = " << fake_mep(i)); } @@ -93,19 +97,20 @@ SCENARIO("Test solver for the IEFPCM for a point charge in a spherical diffuse " CAPTURE(totalASC); CAPTURE(totalFakeASC); CAPTURE(totalASC - totalFakeASC); - REQUIRE(totalASC == Approx(totalFakeASC).epsilon(1.0e-03)); + REQUIRE(totalASC == Approx(totalFakeASC)); } } AND_WHEN("the spherical diffuse layers is centered away from the origin and the " "charge is at the origin") { - Molecule point = dummy<0>(2.929075493); + Molecule point = dummy<0>(2.0); double area = 1.0; double probeRadius = 0.0; double minRadius = 100.0; GePolCavity cavity(point, area, probeRadius, minRadius); - SphericalDiffuse<> gf_o(eps1, eps2, width, center, origin, 3); + int maxL = 5; + SphericalDiffuse gf_o(eps1, eps2, width, center, offset, maxL); IEFSolver solver(symm); solver.buildSystemMatrix(cavity, gf_i, gf_o, op); @@ -126,7 +131,7 @@ SCENARIO("Test solver for the IEFPCM for a point charge in a spherical diffuse " CAPTURE(totalASC); CAPTURE(totalFakeASC); CAPTURE(totalASC - totalFakeASC); - REQUIRE(totalASC == Approx(totalFakeASC).epsilon(1.0e-03)); + REQUIRE(totalASC == Approx(totalFakeASC)); } } } diff --git a/tools/pcmsolver.py.in b/tools/pcmsolver.py.in index 199d93903..3cfaea663 100644 --- a/tools/pcmsolver.py.in +++ b/tools/pcmsolver.py.in @@ -373,9 +373,9 @@ def setup_keywords(): green.add_kw('SPHEREPOSITION', 'DBL_ARRAY', [0.0, 0.0, 0.0]) # Dielectric profile type # Valid for: SPHERICALDIFFUSE - # Valid values: TANH, ERF - # Default: TANH - green.add_kw('PROFILE', 'STR', 'TANH') + # Valid values: TANH, ERF, LOG + # Default: LOG + green.add_kw('PROFILE', 'STR', 'LOG') # Static dielectric permittivity inside the interface # Valid for: SPHERICALDIFFUSE # Valid values: positive double greater than 1.0 @@ -415,7 +415,7 @@ def setup_keywords(): # Maximum angular momentum value # Valid for: SPHERICALDIFFUSE # Valid values: integer - green.add_kw('MAXL', 'INT', 30) + green.add_kw('MAXL', 'INT', 50) medium.add_sect(green) green_part = deepcopy(green) @@ -592,7 +592,7 @@ def verify_green(section): allowed = ('VACUUM', 'UNIFORMDIELECTRIC', 'SPHERICALDIFFUSE', 'METALSPHERE', 'GREENSFUNCTIONSUM') allowed_der = ('NUMERICAL', 'DERIVATIVE', 'GRADIENT', 'HESSIAN') - allowed_profiles = ('TANH', 'ERF') + allowed_profiles = ('TANH', 'ERF', 'LOG') green1 = section.fetch_sect('GREEN') green2 = section.fetch_sect('GREEN')