ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/nonbonded/SwitchingFunction.cpp
Revision: 2071
Committed: Sat Mar 7 21:41:51 2015 UTC (10 years, 1 month ago) by gezelter
File size: 5888 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

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, 234107 (2008).
39 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #include <cmath>
44 #include <iostream>
45 #include <cstdio>
46
47 #include "nonbonded/SwitchingFunction.hpp"
48 #include "utils/simError.h"
49
50 using namespace std;
51 namespace OpenMD {
52
53 SwitchingFunction::SwitchingFunction() : functionType_(cubic),
54 haveSpline_(false), isCubic_(true),
55 np_(150) {
56 switchSpline_ = new CubicSpline();
57 }
58
59 void SwitchingFunction::setSwitchType(SwitchingFunctionType sft) {
60 if ((sft == fifth_order_poly) || (sft == cubic)) {
61 if (haveSpline_) {
62 delete switchSpline_;
63 switchSpline_ = new CubicSpline();
64 setSwitch(rin_, rout_);
65 }
66 } else {
67 sprintf( painCave.errMsg,
68 "SwitchingFunction::setSwitchType was given unknown function type\n");
69 painCave.severity = OPENMD_ERROR;
70 painCave.isFatal = 1;
71 simError();
72 }
73 }
74
75 void SwitchingFunction::setSwitch(RealType rinner, RealType router) {
76 if (router < rinner) {
77 sprintf( painCave.errMsg,
78 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
79 "\tlarger than router (%lf).\n", rinner, router);
80 painCave.severity = OPENMD_ERROR;
81 painCave.isFatal = 1;
82 simError();
83 }
84 if (router < 0.0) {
85 sprintf( painCave.errMsg,
86 "SwitchingFunction::setSwitch was given router (%lf) which was\n"
87 "\tless than zero.\n", router);
88 painCave.severity = OPENMD_ERROR;
89 painCave.isFatal = 1;
90 simError();
91 }
92 if (rinner < 0.0) {
93 sprintf( painCave.errMsg,
94 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
95 "\tless than zero.\n", router);
96 painCave.severity = OPENMD_ERROR;
97 painCave.isFatal = 1;
98 simError();
99 }
100
101 rin_ = rinner;
102 rout_ = router;
103 rin2_ = rin_ * rin_;
104 rout2_ = rout_ * rout_;
105
106 if ((router - rinner) < 1.0e-8) {
107 // no reason to set up spline if the switching region is tiny
108 return;
109 }
110
111 // setup r -> sw lookup spline
112 if (functionType_ == fifth_order_poly) {
113 isCubic_ = false;
114 RealType c0 = 1.0;
115 RealType c3 = -10.0;
116 RealType c4 = 15.0;
117 RealType c5 = -6.0;
118
119 RealType dx, r, yval, rval, rval2, rval3, rval4, rval5;
120 RealType rvaldi, rvaldi2, rvaldi3, rvaldi4, rvaldi5;
121
122 dx = (rout_ - rin_) / RealType(np_-1);
123
124 for (int i = 0; i < np_; i++) {
125 r = rin_ + RealType(i)*dx;
126 rval = ( r - rin_ );
127 rval2 = rval*rval;
128 rval3 = rval2*rval;
129 rval4 = rval2*rval2;
130 rval5 = rval3*rval2;
131 rvaldi = 1.0 / ( rout_ - rin_ );
132 rvaldi2 = rvaldi*rvaldi;
133 rvaldi3 = rvaldi2*rvaldi;
134 rvaldi4 = rvaldi2*rvaldi2;
135 rvaldi5 = rvaldi3*rvaldi2;
136 yval= c0 + c3*rval3*rvaldi3 + c4*rval4*rvaldi4 + c5*rval5*rvaldi5;
137 switchSpline_->addPoint(r, yval);
138 }
139 } else {
140 // cubic splines only need 2 points to do a cubic switching function...
141 isCubic_ = true;
142 switchSpline_->addPoint(rin_, 1.0);
143 switchSpline_->addPoint(rout_, 0.0);
144 }
145 haveSpline_ = true;
146 return;
147 }
148
149 bool SwitchingFunction::getSwitch(const RealType &r2, RealType &sw,
150 RealType &dswdr, RealType &r) {
151
152 sw = 1.0;
153 dswdr = 0.0;
154
155 bool in_switching_region = false;
156
157 if (r2 > rin2_) {
158 if (r2 > rout2_) {
159 sw = 0.0;
160 } else {
161 in_switching_region = true;
162 r = sqrt(r2);
163 switchSpline_->getValueAndDerivativeAt(r, sw, dswdr);
164 }
165 }
166 return in_switching_region;
167 }
168 }

Properties

Name Value
svn:eol-style native