ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/hydrodynamics/ApproximationModel.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 5 months ago) by gezelter
File size: 15767 byte(s)
Log Message:
updated copyright notices

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] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #include "applications/hydrodynamics/ApproximationModel.hpp"
44 #include "math/LU.hpp"
45 #include "math/DynamicRectMatrix.hpp"
46 #include "math/SquareMatrix3.hpp"
47 #include "utils/PhysicalConstants.hpp"
48 #include "hydrodynamics/Sphere.hpp"
49 #include "hydrodynamics/Ellipsoid.hpp"
50 #include "applications/hydrodynamics/CompositeShape.hpp"
51 #include "math/LU.hpp"
52 #include "utils/simError.h"
53 namespace OpenMD {
54 /**
55 * Reference:
56 * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles:
57 * Comparison of Different Modeling and Computational Procedures.
58 * Biophysical Journal, 75(6), 3044, 1999
59 */
60
61 ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){
62 }
63
64 void ApproximationModel::init() {
65 if (!createBeads(beads_)) {
66 sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n");
67 painCave.isFatal = 1;
68 simError();
69 }
70
71 }
72
73 bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) {
74
75 bool ret = true;
76 HydroProp* cr = new HydroProp();
77 HydroProp* cd = new HydroProp();
78 calcHydroPropsAtCR(beads_, viscosity, temperature, cr);
79 calcHydroPropsAtCD(beads_, viscosity, temperature, cd);
80 setCR(cr);
81 setCD(cd);
82 return true;
83 }
84
85 bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* 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 // uncorrected here. Volume correction is added after we assemble Xiorr
150 Xiorr += -U[i] * Cij * U[j];
151 }
152 }
153
154 // add the volume correction
155 Xiorr += (6.0 * viscosity * volume) * I;
156
157 Xiott *= PhysicalConstants::viscoConvert;
158 Xiotr *= PhysicalConstants::viscoConvert;
159 Xiorr *= PhysicalConstants::viscoConvert;
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 = PhysicalConstants::kb * temperature ; // in kcal mol^-1
208 Drtt *= kt;
209 Drrt *= kt;
210 Drtr *= kt;
211 Drrr *= kt;
212 //Xirtt *= PhysicalConstants::kb * temperature;
213 //Xirtr *= PhysicalConstants::kb * temperature;
214 //Xirrr *= PhysicalConstants::kb * temperature;
215
216 Mat6x6d Xi, D;
217
218 cr->setCOR(ror);
219
220 Xi.setSubMatrix(0, 0, Xirtt);
221 Xi.setSubMatrix(0, 3, Xirtr);
222 Xi.setSubMatrix(3, 0, Xirtr);
223 Xi.setSubMatrix(3, 3, Xirrr);
224
225 cr->setXi(Xi);
226
227 D.setSubMatrix(0, 0, Drtt);
228 D.setSubMatrix(0, 3, Drrt);
229 D.setSubMatrix(3, 0, Drtr);
230 D.setSubMatrix(3, 3, Drrr);
231
232 cr->setD(D);
233
234 std::cout << "-----------------------------------------\n";
235 std::cout << "center of resistance :" << std::endl;
236 std::cout << ror << std::endl;
237 std::cout << "resistant tensor at center of resistance" << std::endl;
238 std::cout << "translation:" << std::endl;
239 std::cout << Xirtt << std::endl;
240 std::cout << "translation-rotation:" << std::endl;
241 std::cout << Xirtr << std::endl;
242 std::cout << "rotation:" << std::endl;
243 std::cout << Xirrr << std::endl;
244 std::cout << "diffusion tensor at center of resistance" << std::endl;
245 std::cout << "translation:" << std::endl;
246 std::cout << Drtt << std::endl;
247 std::cout << "rotation-translation:" << std::endl;
248 std::cout << Drrt << std::endl;
249 std::cout << "translation-rotation:" << std::endl;
250 std::cout << Drtr << std::endl;
251 std::cout << "rotation:" << std::endl;
252 std::cout << Drrr << std::endl;
253 std::cout << "-----------------------------------------\n";
254
255 return true;
256 }
257
258 bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cd) {
259
260 int nbeads = beads.size();
261 DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads);
262 DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads);
263 Mat3x3d I;
264 I(0, 0) = 1.0;
265 I(1, 1) = 1.0;
266 I(2, 2) = 1.0;
267
268 for (std::size_t i = 0; i < nbeads; ++i) {
269 for (std::size_t j = 0; j < nbeads; ++j) {
270 Mat3x3d Tij;
271 if (i != j ) {
272 Vector3d Rij = beads[i].pos - beads[j].pos;
273 RealType rij = Rij.length();
274 RealType rij2 = rij * rij;
275 RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;
276 Mat3x3d tmpMat;
277 tmpMat = outProduct(Rij, Rij) / rij2;
278 RealType constant = 8.0 * NumericConstant::PI * viscosity * rij;
279 RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0;
280 RealType tmp2 = 1.0 - sumSigma2OverRij2;
281 Tij = (tmp1 * I + tmp2 * tmpMat ) / constant;
282 }else {
283 RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius);
284 Tij(0, 0) = constant;
285 Tij(1, 1) = constant;
286 Tij(2, 2) = constant;
287 }
288 B.setSubMatrix(i*3, j*3, Tij);
289 }
290 }
291
292 //invert B Matrix
293 invertMatrix(B, C);
294
295 //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0)
296 std::vector<Mat3x3d> U;
297 for (int i = 0; i < nbeads; ++i) {
298 Mat3x3d currU;
299 currU.setupSkewMat(beads[i].pos);
300 U.push_back(currU);
301 }
302
303 //calculate Xi matrix at arbitrary origin O
304 Mat3x3d Xitt;
305 Mat3x3d Xirr;
306 Mat3x3d Xitr;
307
308 //calculate the total volume
309
310 RealType volume = 0.0;
311 for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) {
312 volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3);
313 }
314
315 for (std::size_t i = 0; i < nbeads; ++i) {
316 for (std::size_t j = 0; j < nbeads; ++j) {
317 Mat3x3d Cij;
318 C.getSubMatrix(i*3, j*3, Cij);
319
320 Xitt += Cij;
321 Xitr += U[i] * Cij;
322 // uncorrected here. Volume correction is added after we assemble Xiorr
323 Xirr += -U[i] * Cij * U[j];
324 }
325 }
326 // add the volume correction here:
327 Xirr += (6.0 * viscosity * volume) * I;
328
329 Xitt *= PhysicalConstants::viscoConvert;
330 Xitr *= PhysicalConstants::viscoConvert;
331 Xirr *= PhysicalConstants::viscoConvert;
332
333 RealType kt = PhysicalConstants::kb * temperature; // in kcal mol^-1
334
335 Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O
336 Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O
337 Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O
338
339 const static Mat3x3d zeroMat(0.0);
340
341 Mat3x3d XittInv(0.0);
342 XittInv = Xitt.inverse();
343
344 Mat3x3d XirrInv;
345 XirrInv = Xirr.inverse();
346
347 Mat3x3d tmp;
348 Mat3x3d tmpInv;
349 tmp = Xitt - Xitr.transpose() * XirrInv * Xitr;
350 tmpInv = tmp.inverse();
351
352 Dott = tmpInv;
353 Dotr = -XirrInv * Xitr * tmpInv;
354
355 tmp = Xirr - Xitr * XittInv * Xitr.transpose();
356 tmpInv = tmp.inverse();
357
358 Dorr = tmpInv;
359
360 //calculate center of diffusion
361 tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2);
362 tmp(0, 1) = - Dorr(0, 1);
363 tmp(0, 2) = -Dorr(0, 2);
364 tmp(1, 0) = -Dorr(0, 1);
365 tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2);
366 tmp(1, 2) = -Dorr(1, 2);
367 tmp(2, 0) = -Dorr(0, 2);
368 tmp(2, 1) = -Dorr(1, 2);
369 tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0);
370
371 Vector3d tmpVec;
372 tmpVec[0] = Dotr(1, 2) - Dotr(2, 1);
373 tmpVec[1] = Dotr(2, 0) - Dotr(0, 2);
374 tmpVec[2] = Dotr(0, 1) - Dotr(1, 0);
375
376 tmpInv = tmp.inverse();
377
378 Vector3d rod = tmpInv * tmpVec;
379
380 //calculate Diffusion Tensor at center of diffusion
381 Mat3x3d Uod;
382 Uod.setupSkewMat(rod);
383
384 Mat3x3d Ddtt; //translational diffusion tensor at diffusion center
385 Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center
386 Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor
387
388 Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr;
389 Ddrr = Dorr;
390 Ddtr = Dotr + Dorr * Uod;
391
392 SquareMatrix<RealType, 6> Dd;
393 Dd.setSubMatrix(0, 0, Ddtt);
394 Dd.setSubMatrix(0, 3, Ddtr.transpose());
395 Dd.setSubMatrix(3, 0, Ddtr);
396 Dd.setSubMatrix(3, 3, Ddrr);
397 SquareMatrix<RealType, 6> Xid;
398 Ddtt *= kt;
399 Ddtr *=kt;
400 Ddrr *= kt;
401 invertMatrix(Dd, Xid);
402
403
404
405 //Xidtt in units of kcal*fs*mol^-1*Ang^-2
406 //Xid /= PhysicalConstants::energyConvert;
407 Xid *= PhysicalConstants::kb * temperature;
408
409 Mat6x6d Xi, D;
410
411 cd->setCOR(rod);
412
413 cd->setXi(Xid);
414
415 D.setSubMatrix(0, 0, Ddtt);
416 D.setSubMatrix(0, 3, Ddtr);
417 D.setSubMatrix(3, 0, Ddtr);
418 D.setSubMatrix(3, 3, Ddrr);
419
420 cd->setD(D);
421
422 std::cout << "viscosity = " << viscosity << std::endl;
423 std::cout << "temperature = " << temperature << std::endl;
424 std::cout << "center of diffusion :" << std::endl;
425 std::cout << rod << std::endl;
426 std::cout << "diffusion tensor at center of diffusion " << std::endl;
427 std::cout << "translation(A^2 / fs) :" << std::endl;
428 std::cout << Ddtt << std::endl;
429 std::cout << "translation-rotation(A / fs):" << std::endl;
430 std::cout << Ddtr << std::endl;
431 std::cout << "rotation(fs^-1):" << std::endl;
432 std::cout << Ddrr << std::endl;
433
434 std::cout << "resistance tensor at center of diffusion " << std::endl;
435 std::cout << "translation(kcal*fs*mol^-1*Ang^-2) :" << std::endl;
436
437 Mat3x3d Xidtt;
438 Mat3x3d Xidrt;
439 Mat3x3d Xidtr;
440 Mat3x3d Xidrr;
441 Xid.getSubMatrix(0, 0, Xidtt);
442 Xid.getSubMatrix(0, 3, Xidrt);
443 Xid.getSubMatrix(3, 0, Xidtr);
444 Xid.getSubMatrix(3, 3, Xidrr);
445
446 std::cout << Xidtt << std::endl;
447 std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-1):" << std::endl;
448 std::cout << Xidrt << std::endl;
449 std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-1):" << std::endl;
450 std::cout << Xidtr << std::endl;
451 std::cout << "rotation(kcal*fs*mol^-1):" << std::endl;
452 std::cout << Xidrr << std::endl;
453
454 return true;
455
456 }
457
458 void ApproximationModel::writeBeads(std::ostream& os) {
459 std::vector<BeadParam>::iterator iter;
460 os << beads_.size() << std::endl;
461 os << "Generated by Hydro" << std::endl;
462 for (iter = beads_.begin(); iter != beads_.end(); ++iter) {
463 os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl;
464 }
465
466 }
467 }

Properties

Name Value
svn:keywords Author Id Revision Date