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. 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 |
#include <fstream> |
42 |
#include "integrators/LDForceManager.hpp" |
43 |
#include "math/CholeskyDecomposition.hpp" |
44 |
#include "utils/OOPSEConstant.hpp" |
45 |
namespace oopse { |
46 |
|
47 |
LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){ |
48 |
Globals* simParams = info->getSimParams(); |
49 |
std::map<std::string, HydroProp> hydroPropMap; |
50 |
if (simParams->haveHydroPropFile()) { |
51 |
hydroPropMap = parseFrictionFile(simParams->getHydroPropFile()); |
52 |
} else { |
53 |
//error |
54 |
} |
55 |
|
56 |
SimInfo::MoleculeIterator i; |
57 |
Molecule::IntegrableObjectIterator j; |
58 |
Molecule* mol; |
59 |
StuntDouble* integrableObject; |
60 |
for (mol = info->beginMolecule(i); mol != NULL; mol = info->nextMolecule(i)) { |
61 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
62 |
integrableObject = mol->nextIntegrableObject(j)) { |
63 |
std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType()); |
64 |
if (iter != hydroPropMap.end()) { |
65 |
hydroProps_.push_back(iter->second); |
66 |
} else { |
67 |
//error |
68 |
} |
69 |
|
70 |
} |
71 |
} |
72 |
variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt(); |
73 |
} |
74 |
std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) { |
75 |
std::map<std::string, HydroProp> props; |
76 |
std::ifstream ifs(filename.c_str()); |
77 |
if (ifs.is_open()) { |
78 |
|
79 |
} |
80 |
|
81 |
const unsigned int BufferSize = 65535; |
82 |
char buffer[BufferSize]; |
83 |
Mat3x3d Ddtt; |
84 |
Mat3x3d Ddtr; |
85 |
Mat3x3d Ddrr; |
86 |
while (ifs.getline(buffer, BufferSize)) { |
87 |
StringTokenizer tokenizer(buffer); |
88 |
HydroProp currProp; |
89 |
if (tokenizer.countTokens() >= 40) { |
90 |
std::string atomName = tokenizer.nextToken(); |
91 |
currProp.cor[0] = tokenizer.nextTokenAsDouble(); |
92 |
currProp.cor[1] = tokenizer.nextTokenAsDouble(); |
93 |
currProp.cor[2] = tokenizer.nextTokenAsDouble(); |
94 |
|
95 |
|
96 |
Ddtt(0,0) = tokenizer.nextTokenAsDouble(); |
97 |
Ddtt(0,1) = tokenizer.nextTokenAsDouble(); |
98 |
Ddtt(0,2) = tokenizer.nextTokenAsDouble(); |
99 |
Ddtt(1,0) = tokenizer.nextTokenAsDouble(); |
100 |
Ddtt(1,1) = tokenizer.nextTokenAsDouble(); |
101 |
Ddtt(1,2) = tokenizer.nextTokenAsDouble(); |
102 |
Ddtt(2,0) = tokenizer.nextTokenAsDouble(); |
103 |
Ddtt(2,1) = tokenizer.nextTokenAsDouble(); |
104 |
Ddtt(2,2) = tokenizer.nextTokenAsDouble(); |
105 |
|
106 |
Ddtr(0,0) = tokenizer.nextTokenAsDouble(); |
107 |
Ddtr(0,1) = tokenizer.nextTokenAsDouble(); |
108 |
Ddtr(0,2) = tokenizer.nextTokenAsDouble(); |
109 |
Ddtr(1,0) = tokenizer.nextTokenAsDouble(); |
110 |
Ddtr(1,1) = tokenizer.nextTokenAsDouble(); |
111 |
Ddtr(1,2) = tokenizer.nextTokenAsDouble(); |
112 |
Ddtr(2,0) = tokenizer.nextTokenAsDouble(); |
113 |
Ddtr(2,1) = tokenizer.nextTokenAsDouble(); |
114 |
Ddtr(2,2) = tokenizer.nextTokenAsDouble(); |
115 |
|
116 |
Ddrr(0,0) = tokenizer.nextTokenAsDouble(); |
117 |
Ddrr(0,1) = tokenizer.nextTokenAsDouble(); |
118 |
Ddrr(0,2) = tokenizer.nextTokenAsDouble(); |
119 |
Ddrr(1,0) = tokenizer.nextTokenAsDouble(); |
120 |
Ddrr(1,1) = tokenizer.nextTokenAsDouble(); |
121 |
Ddrr(1,2) = tokenizer.nextTokenAsDouble(); |
122 |
Ddrr(2,0) = tokenizer.nextTokenAsDouble(); |
123 |
Ddrr(2,1) = tokenizer.nextTokenAsDouble(); |
124 |
Ddrr(2,2) = tokenizer.nextTokenAsDouble(); |
125 |
|
126 |
currProp.Xirtt(0,0) = tokenizer.nextTokenAsDouble(); |
127 |
currProp.Xirtt(0,1) = tokenizer.nextTokenAsDouble(); |
128 |
currProp.Xirtt(0,2) = tokenizer.nextTokenAsDouble(); |
129 |
currProp.Xirtt(1,0) = tokenizer.nextTokenAsDouble(); |
130 |
currProp.Xirtt(1,1) = tokenizer.nextTokenAsDouble(); |
131 |
currProp.Xirtt(1,2) = tokenizer.nextTokenAsDouble(); |
132 |
currProp.Xirtt(2,0) = tokenizer.nextTokenAsDouble(); |
133 |
currProp.Xirtt(2,1) = tokenizer.nextTokenAsDouble(); |
134 |
currProp.Xirtt(2,2) = tokenizer.nextTokenAsDouble(); |
135 |
|
136 |
currProp.Xirrt(0,0) = tokenizer.nextTokenAsDouble(); |
137 |
currProp.Xirrt(0,1) = tokenizer.nextTokenAsDouble(); |
138 |
currProp.Xirrt(0,2) = tokenizer.nextTokenAsDouble(); |
139 |
currProp.Xirrt(1,0) = tokenizer.nextTokenAsDouble(); |
140 |
currProp.Xirrt(1,1) = tokenizer.nextTokenAsDouble(); |
141 |
currProp.Xirrt(1,2) = tokenizer.nextTokenAsDouble(); |
142 |
currProp.Xirrt(2,0) = tokenizer.nextTokenAsDouble(); |
143 |
currProp.Xirrt(2,1) = tokenizer.nextTokenAsDouble(); |
144 |
currProp.Xirrt(2,2) = tokenizer.nextTokenAsDouble(); |
145 |
|
146 |
currProp.Xirtr(0,0) = tokenizer.nextTokenAsDouble(); |
147 |
currProp.Xirtr(0,1) = tokenizer.nextTokenAsDouble(); |
148 |
currProp.Xirtr(0,2) = tokenizer.nextTokenAsDouble(); |
149 |
currProp.Xirtr(1,0) = tokenizer.nextTokenAsDouble(); |
150 |
currProp.Xirtr(1,1) = tokenizer.nextTokenAsDouble(); |
151 |
currProp.Xirtr(1,2) = tokenizer.nextTokenAsDouble(); |
152 |
currProp.Xirtr(2,0) = tokenizer.nextTokenAsDouble(); |
153 |
currProp.Xirtr(2,1) = tokenizer.nextTokenAsDouble(); |
154 |
currProp.Xirtr(2,2) = tokenizer.nextTokenAsDouble(); |
155 |
|
156 |
currProp.Xirrr(0,0) = tokenizer.nextTokenAsDouble(); |
157 |
currProp.Xirrr(0,1) = tokenizer.nextTokenAsDouble(); |
158 |
currProp.Xirrr(0,2) = tokenizer.nextTokenAsDouble(); |
159 |
currProp.Xirrr(1,0) = tokenizer.nextTokenAsDouble(); |
160 |
currProp.Xirrr(1,1) = tokenizer.nextTokenAsDouble(); |
161 |
currProp.Xirrr(1,2) = tokenizer.nextTokenAsDouble(); |
162 |
currProp.Xirrr(2,0) = tokenizer.nextTokenAsDouble(); |
163 |
currProp.Xirrr(2,1) = tokenizer.nextTokenAsDouble(); |
164 |
currProp.Xirrr(2,2) = tokenizer.nextTokenAsDouble(); |
165 |
|
166 |
SquareMatrix<double, 6> Xir; |
167 |
Xir.setSubMatrix(0, 0, currProp.Xirtt); |
168 |
Xir.setSubMatrix(0, 3, currProp.Xirrt); |
169 |
Xir.setSubMatrix(3, 0, currProp.Xirtr); |
170 |
Xir.setSubMatrix(3, 3, currProp.Xirrr); |
171 |
CholeskyDecomposition(Xir, currProp.S); |
172 |
|
173 |
props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp)); |
174 |
} |
175 |
} |
176 |
|
177 |
return props; |
178 |
} |
179 |
|
180 |
void LDForceManager::postCalculation() { |
181 |
SimInfo::MoleculeIterator i; |
182 |
Molecule::IntegrableObjectIterator j; |
183 |
Molecule* mol; |
184 |
StuntDouble* integrableObject; |
185 |
Vector3d vel; |
186 |
Vector3d pos; |
187 |
Vector3d frc; |
188 |
Mat3x3d A; |
189 |
Mat3x3d Atrans; |
190 |
Vector3d Tb; |
191 |
Vector3d ji; |
192 |
double mass; |
193 |
unsigned int index = 0; |
194 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
195 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
196 |
integrableObject = mol->nextIntegrableObject(j)) { |
197 |
|
198 |
vel =integrableObject->getVel(); |
199 |
if (integrableObject->isDirectional()){ |
200 |
//calculate angular velocity in lab frame |
201 |
Mat3x3d I = integrableObject->getI(); |
202 |
Vector3d angMom = integrableObject->getJ(); |
203 |
Vector3d omega; |
204 |
|
205 |
if (integrableObject->isLinear()) { |
206 |
int linearAxis = integrableObject->linearAxis(); |
207 |
int l = (linearAxis +1 )%3; |
208 |
int m = (linearAxis +2 )%3; |
209 |
omega[l] = angMom[l] /I(l, l); |
210 |
omega[m] = angMom[m] /I(m, m); |
211 |
|
212 |
} else { |
213 |
omega[0] = angMom[0] /I(0, 0); |
214 |
omega[1] = angMom[1] /I(1, 1); |
215 |
omega[2] = angMom[2] /I(2, 2); |
216 |
} |
217 |
|
218 |
//apply friction force and torque at center of resistance |
219 |
A = integrableObject->getA(); |
220 |
Atrans = A.transpose(); |
221 |
Vector3d rcr = Atrans * hydroProps_[index].cor; |
222 |
Vector3d vcdLab = vel + cross(omega, rcr); |
223 |
Vector3d vcdBody = A* vcdLab; |
224 |
Vector3d frictionForceBody = -(hydroProps_[index].Xirtt * vcdBody + hydroProps_[index].Xirrt * omega); |
225 |
Vector3d frictionForceLab = Atrans*frictionForceBody; |
226 |
integrableObject->addFrc(frictionForceLab); |
227 |
Vector3d frictionTorqueBody = - (hydroProps_[index].Xirtr * vcdBody + hydroProps_[index].Xirrr * omega); |
228 |
Vector3d frictionTorqueLab = Atrans*frictionTorqueBody; |
229 |
integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab)); |
230 |
|
231 |
//apply random force and torque at center of resistance |
232 |
Vector3d randomForceBody; |
233 |
Vector3d randomTorqueBody; |
234 |
genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_); |
235 |
Vector3d randomForceLab = Atrans*randomForceBody; |
236 |
Vector3d randomTorqueLab = Atrans* randomTorqueBody; |
237 |
integrableObject->addFrc(randomForceLab); |
238 |
integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab )); |
239 |
|
240 |
} else { |
241 |
//spheric atom |
242 |
Vector3d frictionForce = -(hydroProps_[index].Xirtt *vel); |
243 |
Vector3d randomForce; |
244 |
Vector3d randomTorque; |
245 |
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
246 |
|
247 |
integrableObject->addFrc(frictionForce+randomForce); |
248 |
} |
249 |
|
250 |
++index; |
251 |
|
252 |
} |
253 |
} |
254 |
|
255 |
ForceManager::postCalculation(); |
256 |
|
257 |
|
258 |
|
259 |
} |
260 |
|
261 |
void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, double variance) { |
262 |
|
263 |
|
264 |
Vector<double, 6> Z; |
265 |
Vector<double, 6> generalForce; |
266 |
|
267 |
|
268 |
Z[0] = randNumGen_.randNorm(0, variance); |
269 |
Z[1] = randNumGen_.randNorm(0, variance); |
270 |
Z[2] = randNumGen_.randNorm(0, variance); |
271 |
Z[3] = randNumGen_.randNorm(0, variance); |
272 |
Z[4] = randNumGen_.randNorm(0, variance); |
273 |
Z[5] = randNumGen_.randNorm(0, variance); |
274 |
|
275 |
|
276 |
generalForce = hydroProps_[index].S*Z; |
277 |
|
278 |
force[0] = generalForce[0]; |
279 |
force[1] = generalForce[1]; |
280 |
force[2] = generalForce[2]; |
281 |
torque[0] = generalForce[3]; |
282 |
torque[1] = generalForce[4]; |
283 |
torque[2] = generalForce[5]; |
284 |
|
285 |
} |
286 |
|
287 |
} |