| 40 |
|
*/ |
| 41 |
|
|
| 42 |
|
#include <cmath> |
| 43 |
+ |
#include <iostream> |
| 44 |
|
|
| 45 |
|
#include "nonbonded/SwitchingFunction.hpp" |
| 46 |
|
#include "utils/simError.h" |
| 49 |
|
namespace OpenMD { |
| 50 |
|
|
| 51 |
|
SwitchingFunction::SwitchingFunction() : np_(150), haveSpline_(false), |
| 52 |
< |
isCubic_(true), functionType_(cubic) {} |
| 52 |
> |
isCubic_(true), functionType_(cubic) { |
| 53 |
> |
switchSpline_ = new CubicSpline(); |
| 54 |
> |
} |
| 55 |
|
|
| 56 |
|
void SwitchingFunction::setSwitchType(SwitchingFunctionType sft) { |
| 57 |
|
if ((sft == fifth_order_poly) || (sft == cubic)) { |
| 58 |
|
if (haveSpline_) { |
| 59 |
|
delete switchSpline_; |
| 60 |
+ |
switchSpline_ = new CubicSpline(); |
| 61 |
|
setSwitch(rin_, rout_); |
| 62 |
|
} |
| 63 |
|
} else { |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
// setup r -> sw lookup spline |
| 105 |
– |
CubicSpline* switchSpline_ = new CubicSpline(); |
| 109 |
|
if (functionType_ == fifth_order_poly) { |
| 110 |
|
isCubic_ = false; |
| 111 |
|
RealType c0 = 1.0; |
| 143 |
|
return; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
< |
bool SwitchingFunction::getSwitch(RealType r2, RealType sw, RealType dswdr, |
| 147 |
< |
RealType r) { |
| 146 |
> |
bool SwitchingFunction::getSwitch(const RealType &r2, RealType &sw, |
| 147 |
> |
RealType &dswdr, RealType &r) { |
| 148 |
> |
|
| 149 |
|
sw = 1.0; |
| 150 |
|
dswdr = 0.0; |
| 151 |
+ |
|
| 152 |
|
bool in_switching_region = false; |
| 153 |
|
|
| 154 |
|
if (r2 > rin2_) { |
| 155 |
|
if (r2 > rout2_) { |
| 156 |
|
sw = 0.0; |
| 152 |
– |
dswdr = 0.0; |
| 153 |
– |
return in_switching_region; |
| 157 |
|
} else { |
| 158 |
|
in_switching_region = true; |
| 159 |
|
r = sqrt(r2); |
| 160 |
|
pair<RealType, RealType> result = switchSpline_->getValueAndDerivativeAt(r); |
| 161 |
|
sw = result.first; |
| 162 |
|
dswdr = result.second; |
| 160 |
– |
return in_switching_region; |
| 163 |
|
} |
| 162 |
– |
} else { |
| 163 |
– |
return in_switching_region; |
| 164 |
|
} |
| 165 |
+ |
return in_switching_region; |
| 166 |
|
} |
| 167 |
|
} |