ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/devel_omp/src/nonbonded/SwitchingFunction.cpp
Revision: 1595
Committed: Tue Jul 19 18:50:04 2011 UTC (13 years, 9 months ago) by chuckv
File size: 5929 byte(s)
Log Message:
Adding initial OpenMP support using new neighbor lists.


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 #include <stdio.h>
45
46 #include "nonbonded/SwitchingFunction.hpp"
47 #include "utils/simError.h"
48
49 using namespace std;
50 namespace OpenMD {
51
52 SwitchingFunction::SwitchingFunction() : np_(150), haveSpline_(false),
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 {
65 sprintf( painCave.errMsg,
66 "SwitchingFunction::setSwitchType was given unknown function type\n");
67 painCave.severity = OPENMD_ERROR;
68 painCave.isFatal = 1;
69 simError();
70 }
71 }
72
73 void SwitchingFunction::setSwitch(RealType rinner, RealType router) {
74 if (router < rinner) {
75 sprintf( painCave.errMsg,
76 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
77 "\tlarger than router (%lf).\n", rinner, router);
78 painCave.severity = OPENMD_ERROR;
79 painCave.isFatal = 1;
80 simError();
81 }
82 if (router < 0.0) {
83 sprintf( painCave.errMsg,
84 "SwitchingFunction::setSwitch was given router (%lf) which was\n"
85 "\tless than zero.\n", router);
86 painCave.severity = OPENMD_ERROR;
87 painCave.isFatal = 1;
88 simError();
89 }
90 if (rinner < 0.0) {
91 sprintf( painCave.errMsg,
92 "SwitchingFunction::setSwitch was given rinner (%lf) which was\n"
93 "\tless than zero.\n", router);
94 painCave.severity = OPENMD_ERROR;
95 painCave.isFatal = 1;
96 simError();
97 }
98
99 rin_ = rinner;
100 rout_ = router;
101 rin2_ = rin_ * rin_;
102 rout2_ = rout_ * rout_;
103
104 if ((router - rinner) < 1.0e-8) {
105 // no reason to set up spline if the switching region is tiny
106 return;
107 }
108
109 // setup r -> sw lookup spline
110 if (functionType_ == fifth_order_poly) {
111 isCubic_ = false;
112 RealType c0 = 1.0;
113 RealType c3 = -10.0;
114 RealType c4 = 15.0;
115 RealType c5 = -6.0;
116
117 RealType dx, r, yval, rval, rval2, rval3, rval4, rval5;
118 RealType rvaldi, rvaldi2, rvaldi3, rvaldi4, rvaldi5;
119
120 dx = (rout_ - rin_) / RealType(np_-1);
121
122 for (int i = 0; i < np_; i++) {
123 r = rin_ + RealType(i)*dx;
124 rval = ( r - rin_ );
125 rval2 = rval*rval;
126 rval3 = rval2*rval;
127 rval4 = rval2*rval2;
128 rval5 = rval3*rval2;
129 rvaldi = 1.0 / ( rout_ - rin_ );
130 rvaldi2 = rvaldi*rvaldi;
131 rvaldi3 = rvaldi2*rvaldi;
132 rvaldi4 = rvaldi2*rvaldi2;
133 rvaldi5 = rvaldi3*rvaldi2;
134 yval= c0 + c3*rval3*rvaldi3 + c4*rval4*rvaldi4 + c5*rval5*rvaldi5;
135 switchSpline_->addPoint(r, yval);
136 }
137 } else {
138 // cubic splines only need 2 points to do a cubic switching function...
139 isCubic_ = true;
140 switchSpline_->addPoint(rin_, 1.0);
141 switchSpline_->addPoint(rout_, 0.0);
142 }
143 haveSpline_ = true;
144 return;
145 }
146
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;
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;
164 }
165 }
166 return in_switching_region;
167 }
168 }

Properties

Name Value
svn:eol-style native