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 |
|
42 |
#include "applications/hydrodynamics/ApproximationModel.hpp" |
43 |
#include "math/LU.hpp" |
44 |
#include "math/DynamicRectMatrix.hpp" |
45 |
#include "math/SquareMatrix3.hpp" |
46 |
#include "utils/OOPSEConstant.hpp" |
47 |
#include "hydrodynamics/Sphere.hpp" |
48 |
#include "hydrodynamics/Ellipsoid.hpp" |
49 |
#include "applications/hydrodynamics/CompositeShape.hpp" |
50 |
#include "math/LU.hpp" |
51 |
#include "utils/simError.h" |
52 |
namespace oopse { |
53 |
/** |
54 |
* Reference: |
55 |
* Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles: |
56 |
* Comparison of Different Modeling and Computational Procedures. |
57 |
* Biophysical Journal, 75(6), 3044, 1999 |
58 |
*/ |
59 |
|
60 |
ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){ |
61 |
} |
62 |
|
63 |
void ApproximationModel::init() { |
64 |
if (!createBeads(beads_)) { |
65 |
sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n"); |
66 |
painCave.isFatal = 1; |
67 |
simError(); |
68 |
} |
69 |
|
70 |
} |
71 |
|
72 |
bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { |
73 |
|
74 |
bool ret = true; |
75 |
HydroProps cr; |
76 |
HydroProps cd; |
77 |
calcHydroPropsAtCR(beads_, viscosity, temperature, cr); |
78 |
//calcHydroPropsAtCD(beads_, viscosity, temperature, cd); |
79 |
setCR(cr); |
80 |
setCD(cd); |
81 |
|
82 |
return true; |
83 |
} |
84 |
|
85 |
bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProps& cr) { |
86 |
|
87 |
int nbeads = beads.size(); |
88 |
DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); |
89 |
DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); |
90 |
Mat3x3d I; |
91 |
I(0, 0) = 1.0; |
92 |
I(1, 1) = 1.0; |
93 |
I(2, 2) = 1.0; |
94 |
|
95 |
for (std::size_t i = 0; i < nbeads; ++i) { |
96 |
for (std::size_t j = 0; j < nbeads; ++j) { |
97 |
Mat3x3d Tij; |
98 |
if (i != j ) { |
99 |
Vector3d Rij = beads[i].pos - beads[j].pos; |
100 |
RealType rij = Rij.length(); |
101 |
RealType rij2 = rij * rij; |
102 |
RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; |
103 |
Mat3x3d tmpMat; |
104 |
tmpMat = outProduct(Rij, Rij) / rij2; |
105 |
RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; |
106 |
RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; |
107 |
RealType tmp2 = 1.0 - sumSigma2OverRij2; |
108 |
Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; |
109 |
}else { |
110 |
RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); |
111 |
Tij(0, 0) = constant; |
112 |
Tij(1, 1) = constant; |
113 |
Tij(2, 2) = constant; |
114 |
} |
115 |
B.setSubMatrix(i*3, j*3, Tij); |
116 |
} |
117 |
} |
118 |
|
119 |
//invert B Matrix |
120 |
invertMatrix(B, C); |
121 |
|
122 |
//prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) |
123 |
std::vector<Mat3x3d> U; |
124 |
for (int i = 0; i < nbeads; ++i) { |
125 |
Mat3x3d currU; |
126 |
currU.setupSkewMat(beads[i].pos); |
127 |
U.push_back(currU); |
128 |
} |
129 |
|
130 |
//calculate Xi matrix at arbitrary origin O |
131 |
Mat3x3d Xiott; |
132 |
Mat3x3d Xiorr; |
133 |
Mat3x3d Xiotr; |
134 |
|
135 |
//calculate the total volume |
136 |
|
137 |
RealType volume = 0.0; |
138 |
for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { |
139 |
volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); |
140 |
} |
141 |
|
142 |
for (std::size_t i = 0; i < nbeads; ++i) { |
143 |
for (std::size_t j = 0; j < nbeads; ++j) { |
144 |
Mat3x3d Cij; |
145 |
C.getSubMatrix(i*3, j*3, Cij); |
146 |
|
147 |
Xiott += Cij; |
148 |
Xiotr += U[i] * Cij; |
149 |
//Xiorr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I; |
150 |
Xiorr += -U[i] * Cij * U[j]; |
151 |
} |
152 |
} |
153 |
|
154 |
const RealType convertConstant = 6.023; //convert poise.angstrom to amu/fs |
155 |
Xiott *= convertConstant; |
156 |
Xiotr *= convertConstant; |
157 |
Xiorr *= convertConstant; |
158 |
|
159 |
|
160 |
|
161 |
Mat3x3d tmp; |
162 |
Mat3x3d tmpInv; |
163 |
Vector3d tmpVec; |
164 |
tmp(0, 0) = Xiott(1, 1) + Xiott(2, 2); |
165 |
tmp(0, 1) = - Xiott(0, 1); |
166 |
tmp(0, 2) = -Xiott(0, 2); |
167 |
tmp(1, 0) = -Xiott(0, 1); |
168 |
tmp(1, 1) = Xiott(0, 0) + Xiott(2, 2); |
169 |
tmp(1, 2) = -Xiott(1, 2); |
170 |
tmp(2, 0) = -Xiott(0, 2); |
171 |
tmp(2, 1) = -Xiott(1, 2); |
172 |
tmp(2, 2) = Xiott(1, 1) + Xiott(0, 0); |
173 |
tmpVec[0] = Xiotr(2, 1) - Xiotr(1, 2); |
174 |
tmpVec[1] = Xiotr(0, 2) - Xiotr(2, 0); |
175 |
tmpVec[2] = Xiotr(1, 0) - Xiotr(0, 1); |
176 |
tmpInv = tmp.inverse(); |
177 |
Vector3d ror = tmpInv * tmpVec; //center of resistance |
178 |
Mat3x3d Uor; |
179 |
Uor.setupSkewMat(ror); |
180 |
|
181 |
Mat3x3d Xirtt; |
182 |
Mat3x3d Xirrr; |
183 |
Mat3x3d Xirtr; |
184 |
|
185 |
Xirtt = Xiott; |
186 |
Xirtr = (Xiotr - Uor * Xiott); |
187 |
Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose(); |
188 |
|
189 |
|
190 |
SquareMatrix<RealType,6> Xir6x6; |
191 |
SquareMatrix<RealType,6> Dr6x6; |
192 |
|
193 |
Xir6x6.setSubMatrix(0, 0, Xirtt); |
194 |
Xir6x6.setSubMatrix(0, 3, Xirtr.transpose()); |
195 |
Xir6x6.setSubMatrix(3, 0, Xirtr); |
196 |
Xir6x6.setSubMatrix(3, 3, Xirrr); |
197 |
|
198 |
invertMatrix(Xir6x6, Dr6x6); |
199 |
Mat3x3d Drtt; |
200 |
Mat3x3d Drtr; |
201 |
Mat3x3d Drrt; |
202 |
Mat3x3d Drrr; |
203 |
Dr6x6.getSubMatrix(0, 0, Drtt); |
204 |
Dr6x6.getSubMatrix(0, 3, Drrt); |
205 |
Dr6x6.getSubMatrix(3, 0, Drtr); |
206 |
Dr6x6.getSubMatrix(3, 3, Drrr); |
207 |
RealType kt = OOPSEConstant::kB * temperature ; |
208 |
Drtt *= kt; |
209 |
Drrt *= kt; |
210 |
Drtr *= kt; |
211 |
Drrr *= kt; |
212 |
Xirtt *= OOPSEConstant::kb * temperature; |
213 |
Xirtr *= OOPSEConstant::kb * temperature; |
214 |
Xirrr *= OOPSEConstant::kb * temperature; |
215 |
|
216 |
|
217 |
cr.center = ror; |
218 |
cr.Xi.setSubMatrix(0, 0, Xirtt); |
219 |
cr.Xi.setSubMatrix(0, 3, Xirtr); |
220 |
cr.Xi.setSubMatrix(3, 0, Xirtr); |
221 |
cr.Xi.setSubMatrix(3, 3, Xirrr); |
222 |
cr.D.setSubMatrix(0, 0, Drtt); |
223 |
cr.D.setSubMatrix(0, 3, Drrt); |
224 |
cr.D.setSubMatrix(3, 0, Drtr); |
225 |
cr.D.setSubMatrix(3, 3, Drrr); |
226 |
|
227 |
std::cout << "-----------------------------------------\n"; |
228 |
std::cout << "center of resistance :" << std::endl; |
229 |
std::cout << ror << std::endl; |
230 |
std::cout << "resistant tensor at center of resistance" << std::endl; |
231 |
std::cout << "translation:" << std::endl; |
232 |
std::cout << Xirtt << std::endl; |
233 |
std::cout << "translation-rotation:" << std::endl; |
234 |
std::cout << Xirtr << std::endl; |
235 |
std::cout << "rotation:" << std::endl; |
236 |
std::cout << Xirrr << std::endl; |
237 |
std::cout << "diffusion tensor at center of resistance" << std::endl; |
238 |
std::cout << "translation:" << std::endl; |
239 |
std::cout << Drtt << std::endl; |
240 |
std::cout << "rotation-translation:" << std::endl; |
241 |
std::cout << Drrt << std::endl; |
242 |
std::cout << "translation-rotation:" << std::endl; |
243 |
std::cout << Drtr << std::endl; |
244 |
std::cout << "rotation:" << std::endl; |
245 |
std::cout << Drrr << std::endl; |
246 |
std::cout << "-----------------------------------------\n"; |
247 |
|
248 |
return true; |
249 |
} |
250 |
|
251 |
bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProps& cr) { |
252 |
|
253 |
int nbeads = beads.size(); |
254 |
DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); |
255 |
DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); |
256 |
Mat3x3d I; |
257 |
I(0, 0) = 1.0; |
258 |
I(1, 1) = 1.0; |
259 |
I(2, 2) = 1.0; |
260 |
|
261 |
for (std::size_t i = 0; i < nbeads; ++i) { |
262 |
for (std::size_t j = 0; j < nbeads; ++j) { |
263 |
Mat3x3d Tij; |
264 |
if (i != j ) { |
265 |
Vector3d Rij = beads[i].pos - beads[j].pos; |
266 |
RealType rij = Rij.length(); |
267 |
RealType rij2 = rij * rij; |
268 |
RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; |
269 |
Mat3x3d tmpMat; |
270 |
tmpMat = outProduct(Rij, Rij) / rij2; |
271 |
RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; |
272 |
RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; |
273 |
RealType tmp2 = 1.0 - sumSigma2OverRij2; |
274 |
Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; |
275 |
}else { |
276 |
RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); |
277 |
Tij(0, 0) = constant; |
278 |
Tij(1, 1) = constant; |
279 |
Tij(2, 2) = constant; |
280 |
} |
281 |
B.setSubMatrix(i*3, j*3, Tij); |
282 |
} |
283 |
} |
284 |
|
285 |
//invert B Matrix |
286 |
invertMatrix(B, C); |
287 |
|
288 |
//prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) |
289 |
std::vector<Mat3x3d> U; |
290 |
for (int i = 0; i < nbeads; ++i) { |
291 |
Mat3x3d currU; |
292 |
currU.setupSkewMat(beads[i].pos); |
293 |
U.push_back(currU); |
294 |
} |
295 |
|
296 |
//calculate Xi matrix at arbitrary origin O |
297 |
Mat3x3d Xitt; |
298 |
Mat3x3d Xirr; |
299 |
Mat3x3d Xitr; |
300 |
|
301 |
//calculate the total volume |
302 |
|
303 |
RealType volume = 0.0; |
304 |
for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { |
305 |
volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); |
306 |
} |
307 |
|
308 |
for (std::size_t i = 0; i < nbeads; ++i) { |
309 |
for (std::size_t j = 0; j < nbeads; ++j) { |
310 |
Mat3x3d Cij; |
311 |
C.getSubMatrix(i*3, j*3, Cij); |
312 |
|
313 |
Xitt += Cij; |
314 |
Xitr += U[i] * Cij; |
315 |
//Xirr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I; |
316 |
Xirr += -U[i] * Cij * U[j]; |
317 |
} |
318 |
} |
319 |
|
320 |
const RealType convertConstant = 6.023; //convert poise.angstrom to amu/fs |
321 |
Xitt *= convertConstant; |
322 |
Xitr *= convertConstant; |
323 |
Xirr *= convertConstant; |
324 |
|
325 |
RealType kt = OOPSEConstant::kB * temperature; |
326 |
|
327 |
Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O |
328 |
Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O |
329 |
Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O |
330 |
|
331 |
const static Mat3x3d zeroMat(0.0); |
332 |
|
333 |
Mat3x3d XittInv(0.0); |
334 |
XittInv = Xitt.inverse(); |
335 |
|
336 |
Mat3x3d XirrInv; |
337 |
XirrInv = Xirr.inverse(); |
338 |
|
339 |
Mat3x3d tmp; |
340 |
Mat3x3d tmpInv; |
341 |
tmp = Xitt - Xitr.transpose() * XirrInv * Xitr; |
342 |
tmpInv = tmp.inverse(); |
343 |
|
344 |
Dott = tmpInv; |
345 |
Dotr = -XirrInv * Xitr * tmpInv; |
346 |
|
347 |
tmp = Xirr - Xitr * XittInv * Xitr.transpose(); |
348 |
tmpInv = tmp.inverse(); |
349 |
|
350 |
Dorr = tmpInv; |
351 |
|
352 |
//calculate center of diffusion |
353 |
tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2); |
354 |
tmp(0, 1) = - Dorr(0, 1); |
355 |
tmp(0, 2) = -Dorr(0, 2); |
356 |
tmp(1, 0) = -Dorr(0, 1); |
357 |
tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2); |
358 |
tmp(1, 2) = -Dorr(1, 2); |
359 |
tmp(2, 0) = -Dorr(0, 2); |
360 |
tmp(2, 1) = -Dorr(1, 2); |
361 |
tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0); |
362 |
|
363 |
Vector3d tmpVec; |
364 |
tmpVec[0] = Dotr(1, 2) - Dotr(2, 1); |
365 |
tmpVec[1] = Dotr(2, 0) - Dotr(0, 2); |
366 |
tmpVec[2] = Dotr(0, 1) - Dotr(1, 0); |
367 |
|
368 |
tmpInv = tmp.inverse(); |
369 |
|
370 |
Vector3d rod = tmpInv * tmpVec; |
371 |
|
372 |
//calculate Diffusion Tensor at center of diffusion |
373 |
Mat3x3d Uod; |
374 |
Uod.setupSkewMat(rod); |
375 |
|
376 |
Mat3x3d Ddtt; //translational diffusion tensor at diffusion center |
377 |
Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center |
378 |
Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor |
379 |
|
380 |
Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr; |
381 |
Ddrr = Dorr; |
382 |
Ddtr = Dotr + Dorr * Uod; |
383 |
|
384 |
SquareMatrix<RealType, 6> Dd; |
385 |
Dd.setSubMatrix(0, 0, Ddtt); |
386 |
Dd.setSubMatrix(0, 3, Ddtr.transpose()); |
387 |
Dd.setSubMatrix(3, 0, Ddtr); |
388 |
Dd.setSubMatrix(3, 3, Ddrr); |
389 |
SquareMatrix<RealType, 6> Xid; |
390 |
Ddtt *= kt; |
391 |
Ddtr *=kt; |
392 |
Ddrr *= kt; |
393 |
invertMatrix(Dd, Xid); |
394 |
|
395 |
|
396 |
|
397 |
//Xidtt in units of kcal*fs*mol^-1*Ang^-2 |
398 |
//Xid /= OOPSEConstant::energyConvert; |
399 |
Xid *= OOPSEConstant::kb * temperature; |
400 |
|
401 |
cr.center = rod; |
402 |
cr.D.setSubMatrix(0, 0, Ddtt); |
403 |
cr.D.setSubMatrix(0, 3, Ddtr); |
404 |
cr.D.setSubMatrix(3, 0, Ddtr); |
405 |
cr.D.setSubMatrix(3, 3, Ddrr); |
406 |
cr.Xi = Xid; |
407 |
|
408 |
std::cout << "viscosity = " << viscosity << std::endl; |
409 |
std::cout << "temperature = " << temperature << std::endl; |
410 |
std::cout << "center of diffusion :" << std::endl; |
411 |
std::cout << rod << std::endl; |
412 |
std::cout << "diffusion tensor at center of diffusion " << std::endl; |
413 |
std::cout << "translation(A^2/fs) :" << std::endl; |
414 |
std::cout << Ddtt << std::endl; |
415 |
std::cout << "translation-rotation(A^3/fs):" << std::endl; |
416 |
std::cout << Ddtr << std::endl; |
417 |
std::cout << "rotation(A^4/fs):" << std::endl; |
418 |
std::cout << Ddrr << std::endl; |
419 |
|
420 |
std::cout << "resistance tensor at center of diffusion " << std::endl; |
421 |
std::cout << "translation(kcal*fs*mol^-1*Ang^-2) :" << std::endl; |
422 |
|
423 |
Mat3x3d Xidtt; |
424 |
Mat3x3d Xidrt; |
425 |
Mat3x3d Xidtr; |
426 |
Mat3x3d Xidrr; |
427 |
Xid.getSubMatrix(0, 0, Xidtt); |
428 |
Xid.getSubMatrix(0, 3, Xidrt); |
429 |
Xid.getSubMatrix(3, 0, Xidtr); |
430 |
Xid.getSubMatrix(3, 3, Xidrr); |
431 |
|
432 |
std::cout << Xidtt << std::endl; |
433 |
std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-3):" << std::endl; |
434 |
std::cout << Xidrt << std::endl; |
435 |
std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-3):" << std::endl; |
436 |
std::cout << Xidtr << std::endl; |
437 |
std::cout << "rotation(kcal*fs*mol^-1*Ang^-4):" << std::endl; |
438 |
std::cout << Xidrr << std::endl; |
439 |
|
440 |
return true; |
441 |
|
442 |
} |
443 |
|
444 |
void ApproximationModel::writeBeads(std::ostream& os) { |
445 |
std::vector<BeadParam>::iterator iter; |
446 |
os << beads_.size() << std::endl; |
447 |
os << "Generated by Hydro" << std::endl; |
448 |
for (iter = beads_.begin(); iter != beads_.end(); ++iter) { |
449 |
os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; |
450 |
} |
451 |
|
452 |
} |
453 |
} |