ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/SwitchingFunction.cpp
Revision: 1581
Committed: Mon Jun 13 22:13:12 2011 UTC (13 years, 10 months ago) by gezelter
File size: 5910 byte(s)
Log Message:
bug fixes

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 * [4] Vardeman & Gezelter, in progress (2009).
40 */
41
42 #include <cmath>
43 #include <iostream>
44
45 #include "nonbonded/SwitchingFunction.hpp"
46 #include "utils/simError.h"
47
48 using namespace std;
49 namespace OpenMD {
50
51 SwitchingFunction::SwitchingFunction() : np_(150), haveSpline_(false),
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 {
64 sprintf( painCave.errMsg,
65 "SwitchingFunction::setSwitchType was given unknown function type\n");
66 painCave.severity = OPENMD_ERROR;
67 painCave.isFatal = 1;
68 simError();
69 }
70 }
71
72 void SwitchingFunction::setSwitch(RealType rinner, RealType router) {
73 if (router < rinner) {
74 sprintf( painCave.errMsg,
75 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
76 "\tlarger than router (%lf).\n", rinner, router);
77 painCave.severity = OPENMD_ERROR;
78 painCave.isFatal = 1;
79 simError();
80 }
81 if (router < 0.0) {
82 sprintf( painCave.errMsg,
83 "SwitchingFunction::setSwitch was given router (%lf) which was\n"
84 "\tless than zero.\n", router);
85 painCave.severity = OPENMD_ERROR;
86 painCave.isFatal = 1;
87 simError();
88 }
89 if (rinner < 0.0) {
90 sprintf( painCave.errMsg,
91 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
92 "\tless than zero.\n", router);
93 painCave.severity = OPENMD_ERROR;
94 painCave.isFatal = 1;
95 simError();
96 }
97
98 rin_ = rinner;
99 rout_ = router;
100 rin2_ = rin_ * rin_;
101 rout2_ = rout_ * rout_;
102
103 if ((router - rinner) < 1.0e-8) {
104 // no reason to set up spline if the switching region is tiny
105 return;
106 }
107
108 // setup r -> sw lookup spline
109 if (functionType_ == fifth_order_poly) {
110 isCubic_ = false;
111 RealType c0 = 1.0;
112 RealType c3 = -10.0;
113 RealType c4 = 15.0;
114 RealType c5 = -6.0;
115
116 RealType dx, r, yval, rval, rval2, rval3, rval4, rval5;
117 RealType rvaldi, rvaldi2, rvaldi3, rvaldi4, rvaldi5;
118
119 dx = (rout_ - rin_) / RealType(np_-1);
120
121 for (int i = 0; i < np_; i++) {
122 r = rin_ + RealType(i)*dx;
123 rval = ( r - rin_ );
124 rval2 = rval*rval;
125 rval3 = rval2*rval;
126 rval4 = rval2*rval2;
127 rval5 = rval3*rval2;
128 rvaldi = 1.0 / ( rout_ - rin_ );
129 rvaldi2 = rvaldi*rvaldi;
130 rvaldi3 = rvaldi2*rvaldi;
131 rvaldi4 = rvaldi2*rvaldi2;
132 rvaldi5 = rvaldi3*rvaldi2;
133 yval= c0 + c3*rval3*rvaldi3 + c4*rval4*rvaldi4 + c5*rval5*rvaldi5;
134 switchSpline_->addPoint(r, yval);
135 }
136 } else {
137 // cubic splines only need 2 points to do a cubic switching function...
138 isCubic_ = true;
139 switchSpline_->addPoint(rin_, 1.0);
140 switchSpline_->addPoint(rout_, 0.0);
141 }
142 haveSpline_ = true;
143 return;
144 }
145
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;
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;
163 }
164 }
165 return in_switching_region;
166 }
167 }

Properties

Name Value
svn:eol-style native