45#include "nonbonded/SwitchingFunction.hpp"
51#include "utils/simError.h"
56 SwitchingFunction::SwitchingFunction() :
57 functionType_(cubic), haveSpline_(false), isCubic_(true), np_(150) {
58 switchSpline_ = std::make_shared<CubicSpline>();
61 void SwitchingFunction::setSwitchType(SwitchingFunctionType sft) {
62 if ((sft == fifth_order_poly) || (sft == cubic)) {
64 switchSpline_ = std::make_shared<CubicSpline>();
65 setSwitch(rin_, rout_);
69 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
70 "SwitchingFunction::setSwitchType was given unknown function type\n");
71 painCave.severity = OPENMD_ERROR;
77 void SwitchingFunction::setSwitch(RealType rinner, RealType router) {
78 if (router < rinner) {
79 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
80 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
81 "\tlarger than router (%lf).\n",
83 painCave.severity = OPENMD_ERROR;
88 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
89 "SwitchingFunction::setSwitch was given router (%lf) which was\n"
90 "\tless than zero.\n",
92 painCave.severity = OPENMD_ERROR;
97 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
98 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
99 "\tless than zero.\n",
101 painCave.severity = OPENMD_ERROR;
102 painCave.isFatal = 1;
109 rout2_ = rout_ * rout_;
111 if ((router - rinner) < 1.0e-8) {
117 if (functionType_ == fifth_order_poly) {
124 RealType dx, r, yval, rval, rval2, rval3, rval4, rval5;
125 RealType rvaldi, rvaldi2, rvaldi3, rvaldi4, rvaldi5;
127 dx = (rout_ - rin_) / RealType(np_ - 1);
129 for (
int i = 0; i < np_; i++) {
130 r = rin_ + RealType(i) * dx;
133 rval3 = rval2 * rval;
134 rval4 = rval2 * rval2;
135 rval5 = rval3 * rval2;
136 rvaldi = 1.0 / (rout_ - rin_);
137 rvaldi2 = rvaldi * rvaldi;
138 rvaldi3 = rvaldi2 * rvaldi;
139 rvaldi4 = rvaldi2 * rvaldi2;
140 rvaldi5 = rvaldi3 * rvaldi2;
141 yval = c0 + c3 * rval3 * rvaldi3 + c4 * rval4 * rvaldi4 +
142 c5 * rval5 * rvaldi5;
143 switchSpline_->addPoint(r, yval);
148 switchSpline_->addPoint(rin_, 1.0);
149 switchSpline_->addPoint(rout_, 0.0);
155 bool SwitchingFunction::getSwitch(
const RealType& r2, RealType& sw,
156 RealType& dswdr, RealType& r) {
160 bool in_switching_region =
false;
166 in_switching_region =
true;
168 switchSpline_->getValueAndDerivativeAt(r, sw, dswdr);
171 return in_switching_region;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.