ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/HydrodynamicsModel.cpp
Revision: 2597
Committed: Thu Feb 23 23:16:43 2006 UTC (18 years, 4 months ago) by tim
File size: 9986 byte(s)
Log Message:
Bead Model is working

File Contents

# User Rev Content
1 tim 2596 /*
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/HydrodynamicsModel.hpp"
43     #include "math/LU.hpp"
44     #include "math/DynamicRectMatrix.hpp"
45     #include "math/SquareMatrix3.hpp"
46 tim 2597 #include "utils/OOPSEConstant.hpp"
47 tim 2596 namespace oopse {
48     /**
49     * Reference:
50     * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles:
51     * Comparison of Different Modeling and Computational Procedures.
52     * Biophysical Journal, 75(6), 3044, 1999
53     */
54 tim 2597
55     HydrodynamicsModel::HydrodynamicsModel(StuntDouble* sd, const DynamicProperty& extraParams) : sd_(sd){
56     DynamicProperty::const_iterator iter;
57    
58     iter = extraParams.find("Viscosity");
59     if (iter != extraParams.end()) {
60     boost::any param = iter->second;
61     viscosity_ = boost::any_cast<double>(param);
62     }else {
63     std::cout << "HydrodynamicsModel Error\n" ;
64     }
65    
66     iter = extraParams.find("Temperature");
67     if (iter != extraParams.end()) {
68     boost::any param = iter->second;
69     temperature_ = boost::any_cast<double>(param);
70     }else {
71     std::cout << "HydrodynamicsModel Error\n" ;
72     }
73     }
74    
75     bool HydrodynamicsModel::calcHydrodyanmicsProps() {
76 tim 2596 if (!createBeads(beads_)) {
77     std::cout << "can not create beads" << std::endl;
78     return false;
79     }
80    
81     int nbeads = beads_.size();
82     DynamicRectMatrix<double> B(3*nbeads, 3*nbeads);
83     DynamicRectMatrix<double> C(3*nbeads, 3*nbeads);
84     Mat3x3d I;
85 tim 2597 I(0, 0) = 1.0;
86     I(1, 1) = 1.0;
87     I(2, 2) = 1.0;
88    
89 tim 2596 for (std::size_t i = 0; i < nbeads; ++i) {
90     for (std::size_t j = 0; j < nbeads; ++j) {
91     Mat3x3d Tij;
92     if (i != j ) {
93     Vector3d Rij = beads_[i].pos - beads_[j].pos;
94     double rij = Rij.length();
95     double rij2 = rij * rij;
96     double sumSigma2OverRij2 = ((beads_[i].radius*beads_[i].radius) + (beads_[i].radius*beads_[i].radius)) / rij2;
97     Mat3x3d tmpMat;
98     tmpMat = outProduct(beads_[i].pos, beads_[j].pos) / rij2;
99 tim 2597 double constant = 8.0 * NumericConstant::PI * viscosity_ * rij;
100 tim 2596 Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant;
101     }else {
102 tim 2597 double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity_ * beads_[i].radius);
103 tim 2596 Tij(0, 0) = constant;
104     Tij(1, 1) = constant;
105     Tij(2, 2) = constant;
106     }
107     B.setSubMatrix(i*3, j*3, Tij);
108     }
109     }
110    
111     //invert B Matrix
112     invertMatrix(B, C);
113     //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0)
114     std::vector<Mat3x3d> U;
115     for (int i = 0; i < nbeads; ++i) {
116     Mat3x3d currU;
117     currU.setupSkewMat(beads_[i].pos);
118     U.push_back(currU);
119     }
120    
121     //calculate Xi matrix at arbitrary origin O
122     Mat3x3d Xitt;
123     Mat3x3d Xirr;
124     Mat3x3d Xitr;
125    
126     for (std::size_t i = 0; i < nbeads; ++i) {
127     for (std::size_t j = 0; j < nbeads; ++j) {
128     Mat3x3d Cij;
129     C.getSubMatrix(i*3, j*3, Cij);
130    
131     Xitt += Cij;
132     Xirr += U[i] * Cij;
133     Xitr += U[i] * Cij * U[j];
134     }
135     }
136    
137     //invert Xi to get Diffusion Tensor at arbitrary origin O
138     RectMatrix<double, 6, 6> Xi;
139     RectMatrix<double, 6, 6> Do;
140     Xi.setSubMatrix(0, 0, Xitt);
141     Xi.setSubMatrix(0, 3, Xitr.transpose());
142     Xi.setSubMatrix(3, 0, Xitr);
143 tim 2597 Xi.setSubMatrix(3, 3, Xirr);
144     //invertMatrix(Xi, Do);
145     double kt = OOPSEConstant::kB * temperature_ * 1.66E-2;
146     //Do *= kt;
147 tim 2596
148 tim 2597
149 tim 2596 Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O
150     Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O
151     Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O
152    
153 tim 2597 Mat3x3d XirrInv(0.0);
154     Mat3x3d XirrCopy;
155     XirrCopy = Xirr;
156    
157     Mat3x3d XittInv(0.0);
158     Mat3x3d XittCopy;
159     XittCopy = Xitt;
160     invertMatrix(XittCopy, XittInv);
161    
162     Mat3x3d tmp;
163     Mat3x3d tmpInv;
164     tmp = Xitt - Xitr.transpose() * XirrInv * Xitr;
165    
166     const static Mat3x3d zeroMat(0.0);
167     if (!invertMatrix(tmp, tmpInv)) {
168     tmpInv = zeroMat;
169     }
170    
171     Dott = kt * tmpInv;
172     Dotr = -kt*XirrInv * Xitr * tmpInv;
173    
174     tmp = Xirr - Xitr * XittInv * Xitr.transpose();
175    
176     if(!invertMatrix(tmp, tmpInv)) {
177     tmpInv = zeroMat;
178     }
179     Dorr = kt * tmpInv;
180    
181     //Do.getSubMatrix(0, 0 , Dott);
182     //Do.getSubMatrix(3, 0, Dotr);
183     //Do.getSubMatrix(3, 3, Dorr);
184    
185 tim 2596 //calculate center of diffusion
186 tim 2597 tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2);
187     tmp(0, 1) = - Dorr(0, 1);
188     tmp(0, 2) = -Dorr(0, 2);
189     tmp(1, 0) = -Dorr(0, 1);
190     tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2);
191     tmp(1, 2) = -Dorr(1, 2);
192     tmp(2, 0) = -Dorr(0, 2);
193     tmp(2, 1) = -Dorr(1, 2);
194     tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0);
195 tim 2596
196     Vector3d tmpVec;
197     tmpVec[0] = Dotr(1, 2) - Dotr(2, 1);
198     tmpVec[1] = Dotr(2, 0) - Dotr(0, 2);
199     tmpVec[2] = Dotr(0, 1) - Dotr(1, 0);
200    
201 tim 2597 if(!invertMatrix(tmp, tmpInv)) {
202     tmpInv = zeroMat;
203     }
204    
205     Vector3d rod = tmpInv * tmpVec;
206    
207 tim 2596 //calculate Diffusion Tensor at center of diffusion
208     Mat3x3d Uod;
209     Uod.setupSkewMat(rod);
210    
211     Mat3x3d Ddtt; //translational diffusion tensor at diffusion center
212     Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center
213     Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor
214    
215     Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr;
216     Ddrr = Dorr;
217     Ddtr = Dotr + Dorr * Uod;
218    
219     props_.diffCenter = rod;
220     props_.transDiff = Ddtt;
221     props_.transRotDiff = Ddtr;
222     props_.rotDiff = Ddrr;
223    
224     return true;
225     }
226    
227     void HydrodynamicsModel::writeBeads(std::ostream& os) {
228 tim 2597 std::vector<BeadParam>::iterator iter;
229     os << beads_.size() << std::endl;
230     os << "Generated by Hydro" << std::endl;
231     for (iter = beads_.begin(); iter != beads_.end(); ++iter) {
232     os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl;
233     }
234 tim 2596
235     }
236    
237     void HydrodynamicsModel::writeDiffCenterAndDiffTensor(std::ostream& os) {
238 tim 2597 os << "//viscosity = " << viscosity_ << std::endl;
239     os << "//temperature = " << temperature_<< std::endl;
240     std::vector<BeadParam>::iterator iter;
241     os << sd_->getType() << "\n";
242 tim 2596
243 tim 2597 os << "//diffusion center" << std::endl;
244     os << props_.diffCenter << std::endl;
245    
246     os << "//translational diffusion tensor" << std::endl;
247     os << props_.transDiff << std::endl;
248    
249     os << "//translational diffusion tensor" << std::endl;
250     os << props_.transRotDiff << std::endl;
251    
252     os << "//rotational diffusion tensor" << std::endl;
253     os << props_.rotDiff << std::endl;
254    
255     /*
256     os << props_.diffCenter[0] << "\t" << props_.diffCenter[1] << "\t" << props_.diffCenter[2] << "\n"
257    
258     os << props_.transDiff(0, 0) << "\t" << props_.transDiff(0, 1) << "\t" << props_.transDiff(0, 2) << "\t"
259     << props_.transDiff(1, 0) << "\t" << props_.transDiff(1, 1) << "\t" << props_.transDiff(1, 2) << "\t"
260     << props_.transDiff(2, 0) << "\t" << props_.transDiff(2, 1) << "\t" << props_.transDiff(2, 2) << "\n";
261    
262     os << props_.transRotDiff(0, 0) << "\t" << props_.transRotDiff(0, 1) << "\t" << props_.transRotDiff(0, 2) << "\t"
263     << props_.transRotDiff(1, 0) << "\t" << props_.transRotDiff(1, 1) << "\t" << props_.transRotDiff(1, 2) << "\t"
264     << props_.transRotDiff(2, 0) << "\t" << props_.transRotDiff(2, 1) << "\t" << props_.transRotDiff(2, 2) << "\t"
265    
266     os << props_.rotDiff(0, 0) << "\t" << props_.rotDiff(0, 1) << "\t" << props_.rotDiff(0, 2) << "\t"
267     << props_.rotDiff(1, 0) << "\t" << props_.rotDiff(1, 1) << "\t" << props_.rotDiff(1, 2) << "\t"
268     << props_.rotDiff(2, 0) << "\t" << props_.rotDiff(2, 1) << "\t" << props_.rotDiff(2, 2) << ";"
269     << std::endl;
270     */
271 tim 2596 }
272    
273     }

Properties

Name Value
svn:executable *