ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/ApproximationModel.cpp
Revision: 2787
Committed: Mon Jun 5 18:24:45 2006 UTC (18 years, 1 month ago) by gezelter
File size: 15475 byte(s)
Log Message:
Massive changes for GB code with multiple ellipsoid types (a la
Cleaver's paper).

Also, changes in hydrodynamics code to make HydroProp a somewhat
smarter class (rather than just a struct).

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. 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 HydroProp* cr;
76 HydroProp* 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, 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 //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 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* cr) {
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 //Xirr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I;
323 Xirr += -U[i] * Cij * U[j];
324 }
325 }
326
327 const RealType convertConstant = 6.023; //convert poise.angstrom to amu/fs
328 Xitt *= convertConstant;
329 Xitr *= convertConstant;
330 Xirr *= convertConstant;
331
332 RealType kt = OOPSEConstant::kB * temperature;
333
334 Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O
335 Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O
336 Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O
337
338 const static Mat3x3d zeroMat(0.0);
339
340 Mat3x3d XittInv(0.0);
341 XittInv = Xitt.inverse();
342
343 Mat3x3d XirrInv;
344 XirrInv = Xirr.inverse();
345
346 Mat3x3d tmp;
347 Mat3x3d tmpInv;
348 tmp = Xitt - Xitr.transpose() * XirrInv * Xitr;
349 tmpInv = tmp.inverse();
350
351 Dott = tmpInv;
352 Dotr = -XirrInv * Xitr * tmpInv;
353
354 tmp = Xirr - Xitr * XittInv * Xitr.transpose();
355 tmpInv = tmp.inverse();
356
357 Dorr = tmpInv;
358
359 //calculate center of diffusion
360 tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2);
361 tmp(0, 1) = - Dorr(0, 1);
362 tmp(0, 2) = -Dorr(0, 2);
363 tmp(1, 0) = -Dorr(0, 1);
364 tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2);
365 tmp(1, 2) = -Dorr(1, 2);
366 tmp(2, 0) = -Dorr(0, 2);
367 tmp(2, 1) = -Dorr(1, 2);
368 tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0);
369
370 Vector3d tmpVec;
371 tmpVec[0] = Dotr(1, 2) - Dotr(2, 1);
372 tmpVec[1] = Dotr(2, 0) - Dotr(0, 2);
373 tmpVec[2] = Dotr(0, 1) - Dotr(1, 0);
374
375 tmpInv = tmp.inverse();
376
377 Vector3d rod = tmpInv * tmpVec;
378
379 //calculate Diffusion Tensor at center of diffusion
380 Mat3x3d Uod;
381 Uod.setupSkewMat(rod);
382
383 Mat3x3d Ddtt; //translational diffusion tensor at diffusion center
384 Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center
385 Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor
386
387 Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr;
388 Ddrr = Dorr;
389 Ddtr = Dotr + Dorr * Uod;
390
391 SquareMatrix<RealType, 6> Dd;
392 Dd.setSubMatrix(0, 0, Ddtt);
393 Dd.setSubMatrix(0, 3, Ddtr.transpose());
394 Dd.setSubMatrix(3, 0, Ddtr);
395 Dd.setSubMatrix(3, 3, Ddrr);
396 SquareMatrix<RealType, 6> Xid;
397 Ddtt *= kt;
398 Ddtr *=kt;
399 Ddrr *= kt;
400 invertMatrix(Dd, Xid);
401
402
403
404 //Xidtt in units of kcal*fs*mol^-1*Ang^-2
405 //Xid /= OOPSEConstant::energyConvert;
406 Xid *= OOPSEConstant::kb * temperature;
407
408 Mat6x6d Xi, D;
409
410 cr->setCOR(rod);
411
412 cr->setXi(Xid);
413
414 D.setSubMatrix(0, 0, Ddtt);
415 D.setSubMatrix(0, 3, Ddtr);
416 D.setSubMatrix(3, 0, Ddtr);
417 D.setSubMatrix(3, 3, Ddrr);
418
419 cr->setD(D);
420
421 std::cout << "viscosity = " << viscosity << std::endl;
422 std::cout << "temperature = " << temperature << std::endl;
423 std::cout << "center of diffusion :" << std::endl;
424 std::cout << rod << std::endl;
425 std::cout << "diffusion tensor at center of diffusion " << std::endl;
426 std::cout << "translation(A^2/fs) :" << std::endl;
427 std::cout << Ddtt << std::endl;
428 std::cout << "translation-rotation(A^3/fs):" << std::endl;
429 std::cout << Ddtr << std::endl;
430 std::cout << "rotation(A^4/fs):" << std::endl;
431 std::cout << Ddrr << std::endl;
432
433 std::cout << "resistance tensor at center of diffusion " << std::endl;
434 std::cout << "translation(kcal*fs*mol^-1*Ang^-2) :" << std::endl;
435
436 Mat3x3d Xidtt;
437 Mat3x3d Xidrt;
438 Mat3x3d Xidtr;
439 Mat3x3d Xidrr;
440 Xid.getSubMatrix(0, 0, Xidtt);
441 Xid.getSubMatrix(0, 3, Xidrt);
442 Xid.getSubMatrix(3, 0, Xidtr);
443 Xid.getSubMatrix(3, 3, Xidrr);
444
445 std::cout << Xidtt << std::endl;
446 std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-3):" << std::endl;
447 std::cout << Xidrt << std::endl;
448 std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-3):" << std::endl;
449 std::cout << Xidtr << std::endl;
450 std::cout << "rotation(kcal*fs*mol^-1*Ang^-4):" << std::endl;
451 std::cout << Xidrr << std::endl;
452
453 return true;
454
455 }
456
457 void ApproximationModel::writeBeads(std::ostream& os) {
458 std::vector<BeadParam>::iterator iter;
459 os << beads_.size() << std::endl;
460 os << "Generated by Hydro" << std::endl;
461 for (iter = beads_.begin(); iter != beads_.end(); ++iter) {
462 os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl;
463 }
464
465 }
466 }