1 |
cli2 |
1360 |
/* |
2 |
|
|
* Copyright (c) 2009 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. Acknowledgement of the program authors must be made in any |
10 |
|
|
* publication of scientific results based in part on use of the |
11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
12 |
|
|
* the article in which the program was described (Matthew |
13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
|
|
* |
18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
40 |
|
|
*/ |
41 |
|
|
|
42 |
|
|
#include "restraints/ObjectRestraint.hpp" |
43 |
|
|
|
44 |
|
|
namespace oopse { |
45 |
|
|
|
46 |
|
|
void ObjectRestraint::calcForce(Vector3d struc) { |
47 |
|
|
|
48 |
|
|
pot_ = 0.0; |
49 |
|
|
|
50 |
|
|
if (restType_ & rtDisplacement) { |
51 |
|
|
Vector3d del = struc - refPos_; |
52 |
|
|
Vector3d frc = -kDisp_ * del; |
53 |
|
|
pot_ += 0.5 * kDisp_ * del.lengthSquare(); |
54 |
|
|
force_ = frc * scaleFactor_; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
void ObjectRestraint::calcForce(Vector3d struc, RotMat3x3d A) { |
59 |
|
|
|
60 |
|
|
calcForce(struc); |
61 |
|
|
|
62 |
|
|
// rtDisplacement is 1, so anything higher than that requires orientations: |
63 |
|
|
if (restType_ > 1) { |
64 |
|
|
|
65 |
|
|
Vector3d tBody(0.0); |
66 |
|
|
|
67 |
|
|
RotMat3x3d temp = A * refA_.transpose(); |
68 |
|
|
|
69 |
|
|
Quat4d quat = temp.toQuaternion(); |
70 |
|
|
|
71 |
|
|
RealType twistAngle, swingAngle; |
72 |
|
|
Vector3d swingAxis; |
73 |
|
|
RealType tw, swingX, swingY; |
74 |
|
|
|
75 |
|
|
quat.getTwistSwingAxisAngle(twistAngle, swingAngle, swingAxis); |
76 |
|
|
quat.toSwingTwist(tw, swingX, swingY); |
77 |
|
|
|
78 |
|
|
RealType dVdtwist, dVdswingX, dVdswingY; |
79 |
|
|
RealType dTwist, dSwingX, dSwingY; |
80 |
|
|
RealType p; |
81 |
|
|
Vector3d tTwist, tSwing; |
82 |
|
|
|
83 |
|
|
if (restType_ & rtTwist){ |
84 |
|
|
dTwist = twistAngle - twist0_; |
85 |
|
|
dVdtwist = kTwist_ * sin(dTwist); |
86 |
|
|
p = kTwist_ * (1.0 - cos(dTwist) ); |
87 |
|
|
pot_ += p; |
88 |
|
|
tBody -= dVdtwist * V3Z; |
89 |
|
|
restInfo_[rtTwist] = std::make_pair(twistAngle, p); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
if (restType_ & rtSwingX){ |
93 |
|
|
dSwingX = swingX - swingX0_; |
94 |
|
|
dVdswingX = kSwingX_ * 0.5 * sin(2.0 * dSwingX); |
95 |
|
|
p = 0.25 * kSwingX_ * (1.0 - cos(2.0 * dSwingX)); |
96 |
|
|
pot_ += p; |
97 |
|
|
tBody -= dVdswingX * V3X; |
98 |
|
|
restInfo_[rtSwingX] = std::make_pair(swingX, p); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
if (restType_ & rtSwingY){ |
102 |
|
|
dSwingY = swingY - swingY0_; |
103 |
|
|
dVdswingY = kSwingY_ * 0.5 * sin(2.0 * dSwingY); |
104 |
|
|
p = 0.25 * kSwingY_ * (1.0 - cos(2.0 * dSwingY)); |
105 |
|
|
pot_ += p; |
106 |
|
|
tBody -= dVdswingY * V3Y; |
107 |
|
|
restInfo_[rtSwingY] = std::make_pair(swingY, p); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
std::cerr << "sw = " << swingAngle << " tw = " << twistAngle << "\n"; |
111 |
|
|
std::cerr << "tbod = " << tBody << "\n"; |
112 |
|
|
Vector3d tLab = A.transpose() * tBody; |
113 |
|
|
torque_ = tLab * scaleFactor_; |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
} |