ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/ApproximationModel.cpp
Revision: 2675
Committed: Wed Mar 29 18:09:26 2006 UTC (18 years, 5 months ago) by tim
File size: 15917 byte(s)
Log Message:
(1) RoughShell Model is working; (20)Adding a new option into Hydro which allows user to generate the beads only

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 "applications/hydrodynamics/Spheric.hpp"
48 #include "applications/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
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 void ApproximationModel::init() {
76 if (!createBeads(beads_)) {
77 sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n");
78 painCave.isFatal = 1;
79 simError();
80 }
81
82 }
83
84 bool ApproximationModel::internalCalcHydroProps(Shape* shape, double viscosity, double temperature) {
85
86 bool ret = true;
87 HydroProps cr;
88 HydroProps cd;
89 calcHydroPropsAtCR(beads_, viscosity, temperature, cr);
90 calcHydroPropsAtCD(beads_, viscosity, temperature, cd);
91 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 double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;
115 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
132 //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 Xiorr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I;
160 }
161 }
162
163 const double convertConstant = 6.023; //convert poise.angstrom to amu/fs
164 Xiott *= convertConstant;
165 Xiotr *= convertConstant;
166 Xiorr *= convertConstant;
167
168
169
170 Mat3x3d tmp;
171 Mat3x3d tmpInv;
172 Vector3d tmpVec;
173 tmp(0, 0) = Xiott(1, 1) + Xiott(2, 2);
174 tmp(0, 1) = - Xiott(0, 1);
175 tmp(0, 2) = -Xiott(0, 2);
176 tmp(1, 0) = -Xiott(0, 1);
177 tmp(1, 1) = Xiott(0, 0) + Xiott(2, 2);
178 tmp(1, 2) = -Xiott(1, 2);
179 tmp(2, 0) = -Xiott(0, 2);
180 tmp(2, 1) = -Xiott(1, 2);
181 tmp(2, 2) = Xiott(1, 1) + Xiott(0, 0);
182 tmpVec[0] = Xiotr(2, 1) - Xiotr(1, 2);
183 tmpVec[1] = Xiotr(0, 2) - Xiotr(2, 0);
184 tmpVec[2] = Xiotr(1, 0) - Xiotr(0, 1);
185 tmpInv = tmp.inverse();
186 Vector3d ror = tmpInv * tmpVec; //center of resistance
187 Mat3x3d Uor;
188 Uor.setupSkewMat(ror);
189
190 Mat3x3d Xirtt;
191 Mat3x3d Xirrr;
192 Mat3x3d Xirtr;
193
194 Xirtt = Xiott;
195 Xirtr = (Xiotr - Uor * Xiott);
196 Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose();
197
198
199 SquareMatrix<double,6> Xir6x6;
200 SquareMatrix<double,6> Dr6x6;
201
202 Xir6x6.setSubMatrix(0, 0, Xirtt);
203 Xir6x6.setSubMatrix(0, 3, Xirtr.transpose());
204 Xir6x6.setSubMatrix(3, 0, Xirtr);
205 Xir6x6.setSubMatrix(3, 3, Xirrr);
206
207 invertMatrix(Xir6x6, Dr6x6);
208 Mat3x3d Drtt;
209 Mat3x3d Drtr;
210 Mat3x3d Drrt;
211 Mat3x3d Drrr;
212 Dr6x6.getSubMatrix(0, 0, Drtt);
213 Dr6x6.getSubMatrix(0, 3, Drrt);
214 Dr6x6.getSubMatrix(3, 0, Drtr);
215 Dr6x6.getSubMatrix(3, 3, Drrr);
216 double kt = OOPSEConstant::kB * temperature ;
217 Drtt *= kt;
218 Drrt *= kt;
219 Drtr *= kt;
220 Drrr *= kt;
221 Xirtt *= OOPSEConstant::kb * temperature;
222 Xirtr *= OOPSEConstant::kb * temperature;
223 Xirrr *= OOPSEConstant::kb * temperature;
224
225
226 cr.center = ror;
227 cr.Xi.setSubMatrix(0, 0, Xirtt);
228 cr.Xi.setSubMatrix(0, 3, Xirtr);
229 cr.Xi.setSubMatrix(3, 0, Xirtr);
230 cr.Xi.setSubMatrix(3, 3, Xirrr);
231 cr.D.setSubMatrix(0, 0, Drtt);
232 cr.D.setSubMatrix(0, 3, Drrt);
233 cr.D.setSubMatrix(3, 0, Drtr);
234 cr.D.setSubMatrix(3, 3, Drrr);
235
236 std::cout << "-----------------------------------------\n";
237 std::cout << "center of resistance :" << std::endl;
238 std::cout << ror << std::endl;
239 std::cout << "resistant tensor at center of resistance" << std::endl;
240 std::cout << "translation:" << std::endl;
241 std::cout << Xirtt << std::endl;
242 std::cout << "translation-rotation:" << std::endl;
243 std::cout << Xirtr << std::endl;
244 std::cout << "rotation:" << std::endl;
245 std::cout << Xirrr << std::endl;
246 std::cout << "diffusion tensor at center of resistance" << std::endl;
247 std::cout << "translation:" << std::endl;
248 std::cout << Drtt << std::endl;
249 std::cout << "rotation-translation:" << std::endl;
250 std::cout << Drrt << std::endl;
251 std::cout << "translation-rotation:" << std::endl;
252 std::cout << Drtr << std::endl;
253 std::cout << "rotation:" << std::endl;
254 std::cout << Drrr << std::endl;
255 std::cout << "-----------------------------------------\n";
256
257 return true;
258 }
259
260 bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, double viscosity, double temperature, HydroProps& cr) {
261
262 int nbeads = beads.size();
263 DynamicRectMatrix<double> B(3*nbeads, 3*nbeads);
264 DynamicRectMatrix<double> C(3*nbeads, 3*nbeads);
265 Mat3x3d I;
266 I(0, 0) = 1.0;
267 I(1, 1) = 1.0;
268 I(2, 2) = 1.0;
269
270 for (std::size_t i = 0; i < nbeads; ++i) {
271 for (std::size_t j = 0; j < nbeads; ++j) {
272 Mat3x3d Tij;
273 if (i != j ) {
274 Vector3d Rij = beads[i].pos - beads[j].pos;
275 double rij = Rij.length();
276 double rij2 = rij * rij;
277 double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;
278 Mat3x3d tmpMat;
279 tmpMat = outProduct(Rij, Rij) / rij2;
280 double constant = 8.0 * NumericConstant::PI * viscosity * rij;
281 Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant;
282 }else {
283 double 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 double 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 }
324 }
325
326 const double convertConstant = 6.023; //convert poise.angstrom to amu/fs
327 Xitt *= convertConstant;
328 Xitr *= convertConstant;
329 Xirr *= convertConstant;
330
331 double kt = OOPSEConstant::kB * temperature;
332
333 Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O
334 Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O
335 Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O
336
337 const static Mat3x3d zeroMat(0.0);
338
339 Mat3x3d XittInv(0.0);
340 XittInv = Xitt.inverse();
341
342 Mat3x3d XirrInv;
343 XirrInv = Xirr.inverse();
344
345 Mat3x3d tmp;
346 Mat3x3d tmpInv;
347 tmp = Xitt - Xitr.transpose() * XirrInv * Xitr;
348 tmpInv = tmp.inverse();
349
350 Dott = tmpInv;
351 Dotr = -XirrInv * Xitr * tmpInv;
352
353 tmp = Xirr - Xitr * XittInv * Xitr.transpose();
354 tmpInv = tmp.inverse();
355
356 Dorr = tmpInv;
357
358 //calculate center of diffusion
359 tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2);
360 tmp(0, 1) = - Dorr(0, 1);
361 tmp(0, 2) = -Dorr(0, 2);
362 tmp(1, 0) = -Dorr(0, 1);
363 tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2);
364 tmp(1, 2) = -Dorr(1, 2);
365 tmp(2, 0) = -Dorr(0, 2);
366 tmp(2, 1) = -Dorr(1, 2);
367 tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0);
368
369 Vector3d tmpVec;
370 tmpVec[0] = Dotr(1, 2) - Dotr(2, 1);
371 tmpVec[1] = Dotr(2, 0) - Dotr(0, 2);
372 tmpVec[2] = Dotr(0, 1) - Dotr(1, 0);
373
374 tmpInv = tmp.inverse();
375
376 Vector3d rod = tmpInv * tmpVec;
377
378 //calculate Diffusion Tensor at center of diffusion
379 Mat3x3d Uod;
380 Uod.setupSkewMat(rod);
381
382 Mat3x3d Ddtt; //translational diffusion tensor at diffusion center
383 Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center
384 Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor
385
386 Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr;
387 Ddrr = Dorr;
388 Ddtr = Dotr + Dorr * Uod;
389
390 SquareMatrix<double, 6> Dd;
391 Dd.setSubMatrix(0, 0, Ddtt);
392 Dd.setSubMatrix(0, 3, Ddtr.transpose());
393 Dd.setSubMatrix(3, 0, Ddtr);
394 Dd.setSubMatrix(3, 3, Ddrr);
395 SquareMatrix<double, 6> Xid;
396 Ddtt *= kt;
397 Ddtr *=kt;
398 Ddrr *= kt;
399 invertMatrix(Dd, Xid);
400
401
402
403 //Xidtt in units of kcal*fs*mol^-1*Ang^-2
404 //Xid /= OOPSEConstant::energyConvert;
405 Xid *= OOPSEConstant::kb * temperature;
406
407 cr.center = rod;
408 cr.D.setSubMatrix(0, 0, Ddtt);
409 cr.D.setSubMatrix(0, 3, Ddtr);
410 cr.D.setSubMatrix(3, 0, Ddtr);
411 cr.D.setSubMatrix(3, 3, Ddrr);
412 cr.Xi = Xid;
413
414 std::cout << "viscosity = " << viscosity << std::endl;
415 std::cout << "temperature = " << temperature << std::endl;
416 std::cout << "center of diffusion :" << std::endl;
417 std::cout << rod << std::endl;
418 std::cout << "diffusion tensor at center of diffusion " << std::endl;
419 std::cout << "translation(A^2/fs) :" << std::endl;
420 std::cout << Ddtt << std::endl;
421 std::cout << "translation-rotation(A^3/fs):" << std::endl;
422 std::cout << Ddtr << std::endl;
423 std::cout << "rotation(A^4/fs):" << std::endl;
424 std::cout << Ddrr << std::endl;
425
426 std::cout << "resistance tensor at center of diffusion " << std::endl;
427 std::cout << "translation(kcal*fs*mol^-1*Ang^-2) :" << std::endl;
428
429 Mat3x3d Xidtt;
430 Mat3x3d Xidrt;
431 Mat3x3d Xidtr;
432 Mat3x3d Xidrr;
433 Xid.getSubMatrix(0, 0, Xidtt);
434 Xid.getSubMatrix(0, 3, Xidrt);
435 Xid.getSubMatrix(3, 0, Xidtr);
436 Xid.getSubMatrix(3, 3, Xidrr);
437
438 std::cout << Xidtt << std::endl;
439 std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-3):" << std::endl;
440 std::cout << Xidrt << std::endl;
441 std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-3):" << std::endl;
442 std::cout << Xidtr << std::endl;
443 std::cout << "rotation(kcal*fs*mol^-1*Ang^-4):" << std::endl;
444 std::cout << Xidrr << std::endl;
445
446 return true;
447
448 }
449
450
451 void ApproximationModel::writeBeads(std::ostream& os) {
452 std::vector<BeadParam>::iterator iter;
453 os << beads_.size() << std::endl;
454 os << "Generated by Hydro" << std::endl;
455 for (iter = beads_.begin(); iter != beads_.end(); ++iter) {
456 os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl;
457 }
458
459 }
460
461
462
463 }