ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/ApproximationModel.cpp
Revision: 2773
Committed: Thu May 25 16:27:27 2006 UTC (18 years, 2 months ago) by tim
File size: 15311 byte(s)
Log Message:
replace double with RealType

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