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