ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/ApproximationModel.cpp
Revision: 2749
Committed: Wed May 10 01:44:48 2006 UTC (18 years, 3 months ago) by tim
File size: 15983 byte(s)
Log Message:
adding a gay-berne switch to Dump2XYZ

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     #include "applications/hydrodynamics/Spheric.hpp"
48     #include "applications/hydrodynamics/Ellipsoid.hpp"
49     #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     ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){
61    
62     }
63    
64     bool ApproximationModel::calcHydroProps(Spheric* spheric, double viscosity, double temperature) {
65     return internalCalcHydroProps(static_cast<Shape*>(spheric), viscosity, temperature);
66     }
67    
68     bool ApproximationModel::calcHydroProps(Ellipsoid* ellipsoid, double viscosity, double temperature) {
69     return internalCalcHydroProps(static_cast<Shape*>(ellipsoid), viscosity, temperature);
70     }
71     bool ApproximationModel::calcHydroProps(CompositeShape* compositeShape, double viscosity, double temperature) {
72     return internalCalcHydroProps(static_cast<Shape*>(compositeShape), viscosity, temperature);
73     }
74    
75 tim 2675 void ApproximationModel::init() {
76 tim 2634 if (!createBeads(beads_)) {
77 tim 2675 sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n");
78     painCave.isFatal = 1;
79     simError();
80 tim 2634 }
81    
82 tim 2675 }
83    
84     bool ApproximationModel::internalCalcHydroProps(Shape* shape, double viscosity, double temperature) {
85    
86 tim 2634 bool ret = true;
87     HydroProps cr;
88     HydroProps cd;
89     calcHydroPropsAtCR(beads_, viscosity, temperature, cr);
90 tim 2749 //calcHydroPropsAtCD(beads_, viscosity, temperature, cd);
91 tim 2634 setCR(cr);
92     setCD(cd);
93    
94     return true;
95     }
96    
97     bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, double viscosity, double temperature, HydroProps& cr) {
98    
99     int nbeads = beads.size();
100     DynamicRectMatrix<double> B(3*nbeads, 3*nbeads);
101     DynamicRectMatrix<double> C(3*nbeads, 3*nbeads);
102     Mat3x3d I;
103     I(0, 0) = 1.0;
104     I(1, 1) = 1.0;
105     I(2, 2) = 1.0;
106    
107     for (std::size_t i = 0; i < nbeads; ++i) {
108     for (std::size_t j = 0; j < nbeads; ++j) {
109     Mat3x3d Tij;
110     if (i != j ) {
111     Vector3d Rij = beads[i].pos - beads[j].pos;
112     double rij = Rij.length();
113     double rij2 = rij * rij;
114 tim 2650 double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;
115 tim 2634 Mat3x3d tmpMat;
116     tmpMat = outProduct(Rij, Rij) / rij2;
117     double constant = 8.0 * NumericConstant::PI * viscosity * rij;
118     Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant;
119     }else {
120     double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius);
121     Tij(0, 0) = constant;
122     Tij(1, 1) = constant;
123     Tij(2, 2) = constant;
124     }
125     B.setSubMatrix(i*3, j*3, Tij);
126     }
127     }
128    
129     //invert B Matrix
130     invertMatrix(B, C);
131 tim 2650
132 tim 2634 //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0)
133     std::vector<Mat3x3d> U;
134     for (int i = 0; i < nbeads; ++i) {
135     Mat3x3d currU;
136     currU.setupSkewMat(beads[i].pos);
137     U.push_back(currU);
138     }
139    
140     //calculate Xi matrix at arbitrary origin O
141     Mat3x3d Xiott;
142     Mat3x3d Xiorr;
143     Mat3x3d Xiotr;
144    
145     //calculate the total volume
146    
147     double volume = 0.0;
148     for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) {
149     volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3);
150     }
151    
152     for (std::size_t i = 0; i < nbeads; ++i) {
153     for (std::size_t j = 0; j < nbeads; ++j) {
154     Mat3x3d Cij;
155     C.getSubMatrix(i*3, j*3, Cij);
156    
157     Xiott += Cij;
158     Xiotr += U[i] * Cij;
159 tim 2749 //Xiorr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I;
160     Xiorr += -U[i] * Cij * U[j];
161 tim 2634 }
162     }
163    
164     const double convertConstant = 6.023; //convert poise.angstrom to amu/fs
165     Xiott *= convertConstant;
166     Xiotr *= convertConstant;
167     Xiorr *= convertConstant;
168    
169    
170    
171     Mat3x3d tmp;
172     Mat3x3d tmpInv;
173     Vector3d tmpVec;
174     tmp(0, 0) = Xiott(1, 1) + Xiott(2, 2);
175     tmp(0, 1) = - Xiott(0, 1);
176     tmp(0, 2) = -Xiott(0, 2);
177     tmp(1, 0) = -Xiott(0, 1);
178     tmp(1, 1) = Xiott(0, 0) + Xiott(2, 2);
179     tmp(1, 2) = -Xiott(1, 2);
180     tmp(2, 0) = -Xiott(0, 2);
181     tmp(2, 1) = -Xiott(1, 2);
182     tmp(2, 2) = Xiott(1, 1) + Xiott(0, 0);
183     tmpVec[0] = Xiotr(2, 1) - Xiotr(1, 2);
184     tmpVec[1] = Xiotr(0, 2) - Xiotr(2, 0);
185     tmpVec[2] = Xiotr(1, 0) - Xiotr(0, 1);
186     tmpInv = tmp.inverse();
187     Vector3d ror = tmpInv * tmpVec; //center of resistance
188     Mat3x3d Uor;
189     Uor.setupSkewMat(ror);
190    
191     Mat3x3d Xirtt;
192     Mat3x3d Xirrr;
193     Mat3x3d Xirtr;
194    
195     Xirtt = Xiott;
196     Xirtr = (Xiotr - Uor * Xiott);
197     Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose();
198    
199    
200     SquareMatrix<double,6> Xir6x6;
201     SquareMatrix<double,6> Dr6x6;
202    
203     Xir6x6.setSubMatrix(0, 0, Xirtt);
204     Xir6x6.setSubMatrix(0, 3, Xirtr.transpose());
205     Xir6x6.setSubMatrix(3, 0, Xirtr);
206     Xir6x6.setSubMatrix(3, 3, Xirrr);
207    
208     invertMatrix(Xir6x6, Dr6x6);
209     Mat3x3d Drtt;
210     Mat3x3d Drtr;
211     Mat3x3d Drrt;
212     Mat3x3d Drrr;
213     Dr6x6.getSubMatrix(0, 0, Drtt);
214     Dr6x6.getSubMatrix(0, 3, Drrt);
215     Dr6x6.getSubMatrix(3, 0, Drtr);
216     Dr6x6.getSubMatrix(3, 3, Drrr);
217     double kt = OOPSEConstant::kB * temperature ;
218     Drtt *= kt;
219     Drrt *= kt;
220     Drtr *= kt;
221     Drrr *= kt;
222     Xirtt *= OOPSEConstant::kb * temperature;
223     Xirtr *= OOPSEConstant::kb * temperature;
224     Xirrr *= OOPSEConstant::kb * temperature;
225    
226    
227     cr.center = ror;
228     cr.Xi.setSubMatrix(0, 0, Xirtt);
229     cr.Xi.setSubMatrix(0, 3, Xirtr);
230     cr.Xi.setSubMatrix(3, 0, Xirtr);
231     cr.Xi.setSubMatrix(3, 3, Xirrr);
232     cr.D.setSubMatrix(0, 0, Drtt);
233     cr.D.setSubMatrix(0, 3, Drrt);
234     cr.D.setSubMatrix(3, 0, Drtr);
235     cr.D.setSubMatrix(3, 3, Drrr);
236    
237     std::cout << "-----------------------------------------\n";
238     std::cout << "center of resistance :" << std::endl;
239     std::cout << ror << std::endl;
240     std::cout << "resistant tensor at center of resistance" << std::endl;
241     std::cout << "translation:" << std::endl;
242     std::cout << Xirtt << std::endl;
243     std::cout << "translation-rotation:" << std::endl;
244     std::cout << Xirtr << std::endl;
245     std::cout << "rotation:" << std::endl;
246     std::cout << Xirrr << std::endl;
247     std::cout << "diffusion tensor at center of resistance" << std::endl;
248     std::cout << "translation:" << std::endl;
249     std::cout << Drtt << std::endl;
250     std::cout << "rotation-translation:" << std::endl;
251     std::cout << Drrt << std::endl;
252     std::cout << "translation-rotation:" << std::endl;
253     std::cout << Drtr << std::endl;
254     std::cout << "rotation:" << std::endl;
255     std::cout << Drrr << std::endl;
256     std::cout << "-----------------------------------------\n";
257    
258     return true;
259     }
260    
261     bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, double viscosity, double temperature, HydroProps& cr) {
262    
263     int nbeads = beads.size();
264     DynamicRectMatrix<double> B(3*nbeads, 3*nbeads);
265     DynamicRectMatrix<double> C(3*nbeads, 3*nbeads);
266     Mat3x3d I;
267     I(0, 0) = 1.0;
268     I(1, 1) = 1.0;
269     I(2, 2) = 1.0;
270    
271     for (std::size_t i = 0; i < nbeads; ++i) {
272     for (std::size_t j = 0; j < nbeads; ++j) {
273     Mat3x3d Tij;
274     if (i != j ) {
275     Vector3d Rij = beads[i].pos - beads[j].pos;
276     double rij = Rij.length();
277     double rij2 = rij * rij;
278 tim 2650 double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;
279 tim 2634 Mat3x3d tmpMat;
280     tmpMat = outProduct(Rij, Rij) / rij2;
281     double constant = 8.0 * NumericConstant::PI * viscosity * rij;
282     Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant;
283     }else {
284     double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius);
285     Tij(0, 0) = constant;
286     Tij(1, 1) = constant;
287     Tij(2, 2) = constant;
288     }
289     B.setSubMatrix(i*3, j*3, Tij);
290     }
291     }
292    
293     //invert B Matrix
294     invertMatrix(B, C);
295    
296     //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0)
297     std::vector<Mat3x3d> U;
298     for (int i = 0; i < nbeads; ++i) {
299     Mat3x3d currU;
300     currU.setupSkewMat(beads[i].pos);
301     U.push_back(currU);
302     }
303    
304     //calculate Xi matrix at arbitrary origin O
305     Mat3x3d Xitt;
306     Mat3x3d Xirr;
307     Mat3x3d Xitr;
308    
309     //calculate the total volume
310    
311     double volume = 0.0;
312     for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) {
313     volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3);
314     }
315    
316     for (std::size_t i = 0; i < nbeads; ++i) {
317     for (std::size_t j = 0; j < nbeads; ++j) {
318     Mat3x3d Cij;
319     C.getSubMatrix(i*3, j*3, Cij);
320    
321     Xitt += Cij;
322     Xitr += U[i] * Cij;
323 tim 2749 //Xirr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I;
324     Xirr += -U[i] * Cij * U[j];
325 tim 2634 }
326     }
327    
328     const double convertConstant = 6.023; //convert poise.angstrom to amu/fs
329     Xitt *= convertConstant;
330     Xitr *= convertConstant;
331     Xirr *= convertConstant;
332    
333     double kt = OOPSEConstant::kB * temperature;
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<double, 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<double, 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 /= OOPSEConstant::energyConvert;
407     Xid *= OOPSEConstant::kb * temperature;
408    
409     cr.center = rod;
410     cr.D.setSubMatrix(0, 0, Ddtt);
411     cr.D.setSubMatrix(0, 3, Ddtr);
412     cr.D.setSubMatrix(3, 0, Ddtr);
413     cr.D.setSubMatrix(3, 3, Ddrr);
414     cr.Xi = Xid;
415    
416     std::cout << "viscosity = " << viscosity << std::endl;
417     std::cout << "temperature = " << temperature << std::endl;
418     std::cout << "center of diffusion :" << std::endl;
419     std::cout << rod << std::endl;
420     std::cout << "diffusion tensor at center of diffusion " << std::endl;
421     std::cout << "translation(A^2/fs) :" << std::endl;
422     std::cout << Ddtt << std::endl;
423     std::cout << "translation-rotation(A^3/fs):" << std::endl;
424     std::cout << Ddtr << std::endl;
425     std::cout << "rotation(A^4/fs):" << std::endl;
426     std::cout << Ddrr << std::endl;
427    
428     std::cout << "resistance tensor at center of diffusion " << std::endl;
429     std::cout << "translation(kcal*fs*mol^-1*Ang^-2) :" << std::endl;
430    
431     Mat3x3d Xidtt;
432     Mat3x3d Xidrt;
433     Mat3x3d Xidtr;
434     Mat3x3d Xidrr;
435     Xid.getSubMatrix(0, 0, Xidtt);
436     Xid.getSubMatrix(0, 3, Xidrt);
437     Xid.getSubMatrix(3, 0, Xidtr);
438     Xid.getSubMatrix(3, 3, Xidrr);
439    
440     std::cout << Xidtt << std::endl;
441     std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-3):" << std::endl;
442     std::cout << Xidrt << std::endl;
443     std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-3):" << std::endl;
444     std::cout << Xidtr << std::endl;
445     std::cout << "rotation(kcal*fs*mol^-1*Ang^-4):" << std::endl;
446     std::cout << Xidrr << std::endl;
447    
448     return true;
449    
450     }
451    
452 tim 2665
453 tim 2634 void ApproximationModel::writeBeads(std::ostream& os) {
454     std::vector<BeadParam>::iterator iter;
455     os << beads_.size() << std::endl;
456     os << "Generated by Hydro" << std::endl;
457     for (iter = beads_.begin(); iter != beads_.end(); ++iter) {
458     os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl;
459     }
460    
461     }
462    
463    
464 tim 2665
465 tim 2634 }