ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/nonbonded/SHAPES.cpp
Revision: 2033
Committed: Sat Nov 1 14:12:16 2014 UTC (10 years, 6 months ago) by gezelter
File size: 14374 byte(s)
Log Message:
Fixed a selection issue in ParticleTimeCorrFunc, other whitespace stuff

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 <stdio.h>
44 #include <string.h>
45
46 #include <cmath>
47 #include "nonbonded/SHAPES.hpp"
48 #include "nonbonded/LJ.hpp"
49 #include "utils/simError.h"
50
51 using namespace std;
52 namespace OpenMD {
53
54 SHAPES::SHAPES() {
55 initialized_ = false;
56 lMax_ = 64;
57 mMax_ = 64;
58 forceField_ = NULL;
59 }
60
61 void SHAPES::initialize() {
62
63 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
64 ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
65 ForceField::AtomTypeContainer::MapTypeIterator i;
66 AtomType* at;
67
68 // SHAPES handles all of the SHAPES-SHAPES interactions as well as
69 // SHAPES-LJ cross interactions:
70
71 for (at = atomTypes->beginType(i); at != NULL;
72 at = atomTypes->nextType(i)) {
73
74 if (at->isShape())
75 addShape(dynamic_cast<ShapeAtomType*>(at));
76
77 if (at->isLennardJones())
78 addLJ(at);
79
80 }
81
82 initialized_ = true;
83 }
84
85 void SHAPES::addShape(ShapeAtomType* atomType){
86 // add it to the map:
87 AtomTypeProperties atp = atomType->getATP();
88
89 if (atomType->isShape() ) {
90 pair<map<int,ShapeAtomType*>::iterator, bool> ret;
91 ret = ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, atomType));
92 if (ret.second == false) {
93 sprintf( painCave.errMsg,
94 "SHAPES already had a previous entry with ident %d\n",
95 atp.ident);
96 painCave.severity = OPENMD_INFO;
97 painCave.isFatal = 0;
98 simError();
99 }
100
101 ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, static_cast<ShapeAtomType*>(atomType)) );
102
103 } else if (atomType->isLennardJones()) {
104 RealType d1 = getLJSigma(atomType) / sqrt(2.0);
105 RealType e1 = getLJEpsilon(atomType);
106 } else {
107 sprintf( painCave.errMsg,
108 "SHAPES::addType was passed an atomType (%s) that does not\n"
109 "\tappear to be a SHAPES or Lennard-Jones atom.\n",
110 atomType->getName().c_str());
111 painCave.severity = OPENMD_ERROR;
112 painCave.isFatal = 1;
113 simError();
114 }
115 }
116
117
118 LJParam SHAPES::getLJParam(AtomType* atomType) {
119
120 // Do sanity checking on the AtomType we were passed before
121 // building any data structures:
122 if (!atomType->isLennardJones()) {
123 sprintf( painCave.errMsg,
124 "SHAPES::getLJParam was passed an atomType (%s) that does not\n"
125 "\tappear to be a Lennard-Jones atom.\n",
126 atomType->getName().c_str());
127 painCave.severity = OPENMD_ERROR;
128 painCave.isFatal = 1;
129 simError();
130 }
131
132 GenericData* data = atomType->getPropertyByName("LennardJones");
133 if (data == NULL) {
134 sprintf( painCave.errMsg, "SHAPES::getLJParam could not find Lennard-Jones\n"
135 "\tparameters for atomType %s.\n", atomType->getName().c_str());
136 painCave.severity = OPENMD_ERROR;
137 painCave.isFatal = 1;
138 simError();
139 }
140
141 LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
142 if (ljData == NULL) {
143 sprintf( painCave.errMsg,
144 "SHAPES::getLJParam could not convert GenericData to LJParam for\n"
145 "\tatom type %s\n", atomType->getName().c_str());
146 painCave.severity = OPENMD_ERROR;
147 painCave.isFatal = 1;
148 simError();
149 }
150
151 return ljData->getData();
152 }
153
154 RealType SHAPES::getLJEpsilon(AtomType* atomType) {
155 LJParam ljParam = getLJParam(atomType);
156 return ljParam.epsilon;
157 }
158 RealType SHAPES::getLJSigma(AtomType* atomType) {
159 LJParam ljParam = getLJParam(atomType);
160 return ljParam.sigma;
161 }
162
163 RealType SHAPES::getGayBerneCut(int atid) {
164 if (!initialized_) initialize();
165 std::map<int, AtomType*> :: const_iterator it;
166 it = SHAPESMap.find(atid);
167 if (it == SHAPESMap.end()) {
168 sprintf( painCave.errMsg,
169 "SHAPES::getGayBerneCut could not find atid %d in SHAPESMap\n",
170 (atid));
171 painCave.severity = OPENMD_ERROR;
172 painCave.isFatal = 1;
173 simError();
174 }
175
176 AtomType* atype = it->second;
177
178 RealType gbCut;
179
180 if (atype->isGayBerne()) {
181 GayBerneParam gb = getGayBerneParam(atype);
182
183 // sigma is actually sqrt(2) * l for prolate ellipsoids
184 gbCut = 2.5 * sqrt(2.0) * max(gb.SHAPES_l, gb.SHAPES_d);
185
186 } else if (atype->isLennardJones()) {
187 gbCut = 2.5 * LJ::Instance()->getSigma(atype);
188 }
189
190 return gbCut;
191 }
192
193
194 void SHAPES::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
195 RealType r, RealType r2, RealType sw,
196 RealType &vpair, RealType &pot,
197 RotMat3x3d A1, RotMat3x3d A2, Vector3d &f1,
198 Vector3d &t1, Vector3d &t2) {
199
200 if (!initialized_) initialize();
201
202 pair<AtomType*, AtomType*> key = make_pair(at1, at2);
203 SHAPESInteractionData mixer = MixingMap[key];
204
205 RealType r3 = r2 * r;
206 RealType r5 = r3 * r2;
207
208 Vector3d drdi = -d / r;
209 Vector3d drdui = V3Zero;
210 Vector3d drdj = d / r;
211 Vector3d drduj = V3Zero;
212
213 bool i_is_LJ = at1->isLennardJones();
214 bool j_is_LJ = at2->isLennardJones();
215
216 RealType sigma_i;
217 RealType s_i;
218 RealType eps_i;
219 Vector3d dsigmaidr;
220 Vector3d disgmaidu;
221 Vector3d dsidr;
222 Vector3d dsidu;
223 Vector3d depsidr;
224 Vector3d depsidu;
225
226 if (i_is_LJ) {
227 sigma_i = LJ::Instance()->getSigma(at1);
228 s_i = sigma_i;
229 epsilon_i = LJ::Instance()->getEpsilon(at1);
230 dsigmaidr = V3Zero;
231 dsigmaidu = V3Zero;
232 dsidr = V3Zero;
233 dsidu = V3Zero;
234 depsidr = V3Zero;
235 depsidu = V3Zero;
236 } else {
237
238 // rotate the inter-particle separation into the two different
239 // body-fixed coordinate systems:
240
241 Vector3d ri = A1 * d;
242
243 RealType xi = ri.x() / r;
244 RealType yi = ri.y() / r;
245 RealType zi = ri.z() / r;
246 RealType xi2 = xi * xi;
247 RealType yi2 = yi * yi;
248 RealType zi2 = zi * zi;
249 RealType cti = zi / r;
250
251 if (cti > 1.0) cti = 1.0;
252 if (cti < -1.0_dp) cti = -1.0;
253
254 Vector3d dctidr(-zi * xi / r3,
255 -zi * yi / r3,
256 1.0 / r - zi2 / r3);
257
258 Vector3d dctidu(yi / r,
259 -zi / r,
260 0.0);
261
262 // this is an attempt to try to truncate the singularity when
263 // sin(theta) is near 0.0:
264
265 RealType sti2 = 1.0 - cti*cti;
266 RealType proji;
267 Vector3d dcpidr, dcpidu, dspidr, dspidu;
268 if (fabs(sti2) < 1.0e-12) {
269 proji = sqrt(r * 1.0e-12);
270 dcpidr = Vector3d( 1.0 / proji, 0.0, 0.0);
271 dcpidu = Vector3d( xi / proji, 0.0, 0.0);
272 dspidr = Vector3d( 0.0, 1.0 / proji, 0.0);
273 dspidu = Vector3d (0.0, yi / proji, 0.0);
274 } else {
275 proji = sqrt(xi2 + yi2);
276 RealType proji3 = proji*proji*proji;
277 dcpidr = Vector3d(1.0_dp / proji - xi2 / proji3,
278 - xi * yi / proji3,
279 0.0);
280 dcpidu = Vector3d( xi / proji - (xi2 * xi) / proji3,
281 - (xi * yi2) / proji3,
282 0.0);
283 dspidr = Vector3d(- xi * yi / proji3,
284 1.0_dp / proji - yi2 / proji3,
285 0.0);
286 dspidu = Vector3d(- (yi * xi2) / proji3,
287 yi / proji - (yi2 * yi) / proji3,
288 0.0);
289 }
290
291 cpi = xi / proji;
292 dcpidr.z() = 0.0;
293 dcpidu.z() = 0.0;
294
295 spi = yi / proji;
296 dspidr.z() = 0.0;
297 dspidu.z() = 0.0;
298
299
300 RealType sigma0 = mixer.sigma0;
301 RealType dw = mixer.dw;
302 RealType eps0 = mixer.eps0;
303 RealType x2 = mixer.x2;
304 RealType xa2 = mixer.xa2;
305 RealType xai2 = mixer.xai2;
306 RealType xp2 = mixer.xp2;
307 RealType xpap2 = mixer.xpap2;
308 RealType xpapi2 = mixer.xpapi2;
309
310 Vector3d ul1 = A1.getRow(2);
311 Vector3d ul2 = A2.getRow(2);
312
313 RealType a, b, g;
314
315
316 if (i_is_LJ) {
317 a = 0.0;
318 ul1 = V3Zero;
319 } else {
320 a = dot(d, ul1);
321 }
322
323 if (j_is_LJ) {
324 b = 0.0;
325 ul2 = V3Zero;
326 } else {
327 b = dot(d, ul2);
328 }
329
330 if (i_is_LJ || j_is_LJ)
331 g = 0.0;
332 else
333 g = dot(ul1, ul2);
334
335 RealType au = a / r;
336 RealType bu = b / r;
337
338 RealType au2 = au * au;
339 RealType bu2 = bu * bu;
340 RealType g2 = g * g;
341
342 RealType H = (xa2 * au2 + xai2 * bu2 - 2.0*x2*au*bu*g) / (1.0 - x2*g2);
343 RealType Hp = (xpap2*au2 + xpapi2*bu2 - 2.0*xp2*au*bu*g) / (1.0 - xp2*g2);
344
345 RealType sigma = sigma0 / sqrt(1.0 - H);
346 RealType e1 = 1.0 / sqrt(1.0 - x2*g2);
347 RealType e2 = 1.0 - Hp;
348 RealType eps = eps0 * pow(e1,nu_) * pow(e2,mu_);
349 RealType BigR = dw*sigma0 / (r - sigma + dw*sigma0);
350
351 RealType R3 = BigR*BigR*BigR;
352 RealType R6 = R3*R3;
353 RealType R7 = R6 * BigR;
354 RealType R12 = R6*R6;
355 RealType R13 = R6*R7;
356
357 RealType U = vdwMult * 4.0 * eps * (R12 - R6);
358
359 RealType s3 = sigma*sigma*sigma;
360 RealType s03 = sigma0*sigma0*sigma0;
361
362 RealType pref1 = - vdwMult * 8.0 * eps * mu_ * (R12 - R6) / (e2 * r);
363
364 RealType pref2 = vdwMult * 8.0 * eps * s3 * (6.0*R13 - 3.0*R7) /(dw*r*s03);
365
366 RealType dUdr = - (pref1 * Hp + pref2 * (sigma0*sigma0*r/s3 + H));
367
368 RealType dUda = pref1 * (xpap2*au - xp2*bu*g) / (1.0 - xp2 * g2)
369 + pref2 * (xa2 * au - x2 *bu*g) / (1.0 - x2 * g2);
370
371 RealType dUdb = pref1 * (xpapi2*bu - xp2*au*g) / (1.0 - xp2 * g2)
372 + pref2 * (xai2 * bu - x2 *au*g) / (1.0 - x2 * g2);
373
374 RealType dUdg = 4.0 * eps * nu_ * (R12 - R6) * x2 * g / (1.0 - x2*g2)
375 + 8.0 * eps * mu_ * (R12 - R6) * (xp2*au*bu - Hp*xp2*g) /
376 (1.0 - xp2 * g2) / e2 + 8.0 * eps * s3 * (3.0 * R7 - 6.0 * R13) *
377 (x2 * au * bu - H * x2 * g) / (1.0 - x2 * g2) / (dw * s03);
378
379
380 Vector3d rhat = d / r;
381 Vector3d rxu1 = cross(d, ul1);
382 Vector3d rxu2 = cross(d, ul2);
383 Vector3d uxu = cross(ul1, ul2);
384
385 pot += U*sw;
386 f1 += dUdr * rhat + dUda * ul1 + dUdb * ul2;
387 t1 += dUda * rxu1 - dUdg * uxu;
388 t2 += dUdb * rxu2 - dUdg * uxu;
389 vpair += U*sw;
390
391 return;
392
393 }
394
395 void SHAPES::do_gb_pair(int *atid1, int *atid2, RealType *d, RealType *r,
396 RealType *r2, RealType *sw, RealType *vdwMult,
397 RealType *vpair, RealType *pot, RealType *A1,
398 RealType *A2, RealType *f1, RealType *t1, RealType *t2) {
399
400 if (!initialized_) initialize();
401
402 AtomType* atype1 = SHAPESMap[*atid1];
403 AtomType* atype2 = SHAPESMap[*atid2];
404
405 Vector3d disp(d);
406 Vector3d frc(f1);
407 Vector3d trq1(t1);
408 Vector3d trq2(t2);
409 RotMat3x3d Ai(A1);
410 RotMat3x3d Aj(A2);
411
412 // Fortran has the opposite matrix ordering from c++, so we'll use
413 // transpose here. When we finish the conversion to C++, this wrapper
414 // will disappear, as will the transpose below:
415
416 calcForce(atype1, atype2, disp, *r, *r2, *sw, *vdwMult, *vpair, *pot,
417 Ai, Aj, frc, trq1, trq1);
418
419 f1[0] = frc.x();
420 f1[1] = frc.y();
421 f1[2] = frc.z();
422
423 t1[0] = trq1.x();
424 t1[1] = trq1.y();
425 t1[2] = trq1.z();
426
427 t2[0] = trq2.x();
428 t2[1] = trq2.y();
429 t2[2] = trq2.z();
430
431 return;
432 }
433 }
434
435 extern "C" {
436
437 #define fortranGetGayBerneCut FC_FUNC(getgaybernecut, GETGAYBERNECUT)
438 #define fortranDoSHAPESPair FC_FUNC(do_gb_pair, DO_SHAPES_PAIR)
439
440 RealType fortranGetGayBerneCut(int* atid) {
441 return OpenMD::SHAPES::Instance()->getGayBerneCut(*atid);
442 }
443
444 void fortranDoSHAPESPair(int *atid1, int *atid2, RealType *d, RealType *r,
445 RealType *r2, RealType *sw, RealType *vdwMult,
446 RealType *vpair, RealType *pot, RealType *A1,
447 RealType *A2, RealType *f1, RealType *t1, RealType *t2){
448
449 return OpenMD::SHAPES::Instance()->do_gb_pair(atid1, atid2, d, r, r2, sw,
450 vdwMult, vpair, pot, A1, A2, f1,
451 t1, t2);
452 }
453 }

Properties

Name Value
svn:eol-style native