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, 3 months 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

# User Rev Content
1 tim 2634 /*
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 gezelter 2768 #include "hydrodynamics/Sphere.hpp"
48     #include "hydrodynamics/Ellipsoid.hpp"
49 tim 2634 #include "applications/hydrodynamics/CompositeShape.hpp"
50     #include "math/LU.hpp"
51 tim 2675 #include "utils/simError.h"
52 tim 2634 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 gezelter 2768 ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){
61     }
62    
63     void ApproximationModel::init() {
64 tim 2634 if (!createBeads(beads_)) {
65 tim 2675 sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n");
66     painCave.isFatal = 1;
67     simError();
68 tim 2634 }
69 gezelter 2768
70     }
71    
72 tim 2773 bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) {
73 gezelter 2768
74 tim 2634 bool ret = true;
75 gezelter 2787 HydroProp* cr;
76     HydroProp* cd;
77 tim 2634 calcHydroPropsAtCR(beads_, viscosity, temperature, cr);
78 tim 2749 //calcHydroPropsAtCD(beads_, viscosity, temperature, cd);
79 tim 2634 setCR(cr);
80     setCD(cd);
81    
82     return true;
83 gezelter 2768 }
84    
85 gezelter 2787 bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cr) {
86 gezelter 2768
87 tim 2634 int nbeads = beads.size();
88 tim 2773 DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads);
89     DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads);
90 tim 2634 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 gezelter 2768 for (std::size_t j = 0; j < nbeads; ++j) {
97     Mat3x3d Tij;
98 tim 2634 if (i != j ) {
99 gezelter 2768 Vector3d Rij = beads[i].pos - beads[j].pos;
100 tim 2773 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 gezelter 2768 Mat3x3d tmpMat;
104     tmpMat = outProduct(Rij, Rij) / rij2;
105 tim 2773 RealType constant = 8.0 * NumericConstant::PI * viscosity * rij;
106 tim 2774 RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0;
107     RealType tmp2 = 1.0 - sumSigma2OverRij2;
108     Tij = (tmp1 * I + tmp2 * tmpMat ) / constant;
109 tim 2634 }else {
110 tim 2773 RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius);
111 gezelter 2768 Tij(0, 0) = constant;
112     Tij(1, 1) = constant;
113     Tij(2, 2) = constant;
114 tim 2634 }
115     B.setSubMatrix(i*3, j*3, Tij);
116 gezelter 2768 }
117 tim 2634 }
118 gezelter 2768
119 tim 2634 //invert B Matrix
120     invertMatrix(B, C);
121 tim 2650
122 tim 2634 //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 gezelter 2768 Mat3x3d currU;
126     currU.setupSkewMat(beads[i].pos);
127     U.push_back(currU);
128 tim 2634 }
129    
130     //calculate Xi matrix at arbitrary origin O
131     Mat3x3d Xiott;
132     Mat3x3d Xiorr;
133     Mat3x3d Xiotr;
134 gezelter 2768
135 tim 2634 //calculate the total volume
136 gezelter 2768
137 tim 2773 RealType volume = 0.0;
138 tim 2634 for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) {
139 gezelter 2768 volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3);
140 tim 2634 }
141 gezelter 2768
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 tim 2634
147 gezelter 2768 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 tim 2634 }
153 gezelter 2768
154 tim 2773 const RealType convertConstant = 6.023; //convert poise.angstrom to amu/fs
155 tim 2634 Xiott *= convertConstant;
156     Xiotr *= convertConstant;
157     Xiorr *= convertConstant;
158    
159    
160 gezelter 2768
161 tim 2634 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 tim 2773 SquareMatrix<RealType,6> Xir6x6;
191     SquareMatrix<RealType,6> Dr6x6;
192 tim 2634
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 tim 2773 RealType kt = OOPSEConstant::kB * temperature ;
208 tim 2634 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 gezelter 2787 Mat6x6d Xi, D;
217 tim 2634
218 gezelter 2787 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 tim 2634
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 gezelter 2768
258 gezelter 2787 bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cr) {
259 gezelter 2768
260 tim 2634 int nbeads = beads.size();
261 tim 2773 DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads);
262     DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads);
263 tim 2634 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 gezelter 2768 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 tim 2773 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 gezelter 2768 Mat3x3d tmpMat;
277     tmpMat = outProduct(Rij, Rij) / rij2;
278 tim 2773 RealType constant = 8.0 * NumericConstant::PI * viscosity * rij;
279 tim 2774 RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0;
280     RealType tmp2 = 1.0 - sumSigma2OverRij2;
281     Tij = (tmp1 * I + tmp2 * tmpMat ) / constant;
282 gezelter 2768 }else {
283 tim 2773 RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius);
284 gezelter 2768 Tij(0, 0) = constant;
285     Tij(1, 1) = constant;
286     Tij(2, 2) = constant;
287 tim 2634 }
288 gezelter 2768 B.setSubMatrix(i*3, j*3, Tij);
289     }
290 tim 2634 }
291 gezelter 2768
292 tim 2634 //invert B Matrix
293     invertMatrix(B, C);
294 gezelter 2768
295 tim 2634 //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 gezelter 2768 Mat3x3d currU;
299     currU.setupSkewMat(beads[i].pos);
300     U.push_back(currU);
301 tim 2634 }
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 tim 2773 RealType volume = 0.0;
311 tim 2634 for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) {
312 gezelter 2768 volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3);
313 tim 2634 }
314 gezelter 2768
315 tim 2634 for (std::size_t i = 0; i < nbeads; ++i) {
316 gezelter 2768 for (std::size_t j = 0; j < nbeads; ++j) {
317     Mat3x3d Cij;
318     C.getSubMatrix(i*3, j*3, Cij);
319 tim 2634
320 gezelter 2768 Xitt += Cij;
321     Xitr += U[i] * Cij;
322 tim 2749 //Xirr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I;
323 gezelter 2768 Xirr += -U[i] * Cij * U[j];
324     }
325 tim 2634 }
326 gezelter 2768
327 tim 2773 const RealType convertConstant = 6.023; //convert poise.angstrom to amu/fs
328 tim 2634 Xitt *= convertConstant;
329     Xitr *= convertConstant;
330     Xirr *= convertConstant;
331 gezelter 2768
332 tim 2773 RealType kt = OOPSEConstant::kB * temperature;
333 gezelter 2768
334 tim 2634 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 gezelter 2768
338 tim 2634 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 tim 2773 SquareMatrix<RealType, 6> Dd;
392 tim 2634 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 tim 2773 SquareMatrix<RealType, 6> Xid;
397 tim 2634 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 gezelter 2787 Mat6x6d Xi, D;
409 tim 2634
410 gezelter 2787 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 tim 2634 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 gezelter 2768
455     }
456 tim 2634
457 gezelter 2768 void ApproximationModel::writeBeads(std::ostream& os) {
458 tim 2634 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 gezelter 2768 os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl;
463 tim 2634 }
464 gezelter 2768
465     }
466 tim 2634 }