| 1 | tim | 906 | /* | 
| 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 | gezelter | 1390 | * 1. Redistributions of source code must retain the above copyright | 
| 10 | tim | 906 | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  |  | * | 
| 12 | gezelter | 1390 | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | tim | 906 | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  |  | *    documentation and/or other materials provided with the | 
| 15 |  |  | *    distribution. | 
| 16 |  |  | * | 
| 17 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 18 |  |  | * kind. All express or implied conditions, representations and | 
| 19 |  |  | * warranties, including any implied warranty of merchantability, | 
| 20 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 23 |  |  | * using, modifying or distributing the software or its | 
| 24 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 25 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 27 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 28 |  |  | * arising out of the use of or inability to use software, even if the | 
| 29 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 30 |  |  | * such damages. | 
| 31 | gezelter | 1390 | * | 
| 32 |  |  | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 |  |  | * research, please cite the appropriate papers when you publish your | 
| 34 |  |  | * work.  Good starting points are: | 
| 35 |  |  | * | 
| 36 |  |  | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 |  |  | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | gezelter | 1879 | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | gezelter | 1782 | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 |  |  | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | tim | 906 | */ | 
| 42 |  |  |  | 
| 43 |  |  | #include "applications/hydrodynamics/ApproximationModel.hpp" | 
| 44 |  |  | #include "math/LU.hpp" | 
| 45 |  |  | #include "math/DynamicRectMatrix.hpp" | 
| 46 |  |  | #include "math/SquareMatrix3.hpp" | 
| 47 | gezelter | 1390 | #include "utils/PhysicalConstants.hpp" | 
| 48 | gezelter | 972 | #include "hydrodynamics/Sphere.hpp" | 
| 49 |  |  | #include "hydrodynamics/Ellipsoid.hpp" | 
| 50 | tim | 906 | #include "applications/hydrodynamics/CompositeShape.hpp" | 
| 51 |  |  | #include "math/LU.hpp" | 
| 52 | tim | 921 | #include "utils/simError.h" | 
| 53 | gezelter | 1390 | namespace OpenMD { | 
| 54 | tim | 906 | /** | 
| 55 |  |  | * Reference: | 
| 56 |  |  | * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles: | 
| 57 |  |  | * Comparison of Different Modeling and Computational Procedures. | 
| 58 |  |  | * Biophysical Journal, 75(6), 3044, 1999 | 
| 59 |  |  | */ | 
| 60 |  |  |  | 
| 61 | gezelter | 972 | ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){ | 
| 62 |  |  | } | 
| 63 |  |  |  | 
| 64 |  |  | void ApproximationModel::init() { | 
| 65 | tim | 906 | if (!createBeads(beads_)) { | 
| 66 | tim | 921 | sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n"); | 
| 67 |  |  | painCave.isFatal = 1; | 
| 68 |  |  | simError(); | 
| 69 | tim | 906 | } | 
| 70 | gezelter | 972 |  | 
| 71 |  |  | } | 
| 72 |  |  |  | 
| 73 | tim | 977 | bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { | 
| 74 | gezelter | 972 |  | 
| 75 | xsun | 1177 | HydroProp* cr = new HydroProp(); | 
| 76 |  |  | HydroProp* cd = new HydroProp(); | 
| 77 | tim | 906 | calcHydroPropsAtCR(beads_, viscosity, temperature, cr); | 
| 78 | xsun | 1177 | calcHydroPropsAtCD(beads_, viscosity, temperature, cd); | 
| 79 | tim | 906 | setCR(cr); | 
| 80 |  |  | setCD(cd); | 
| 81 |  |  | return true; | 
| 82 | gezelter | 972 | } | 
| 83 |  |  |  | 
| 84 | gezelter | 981 | bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cr) { | 
| 85 | gezelter | 972 |  | 
| 86 | gezelter | 1782 | unsigned int nbeads = beads.size(); | 
| 87 | tim | 977 | DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); | 
| 88 |  |  | DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); | 
| 89 | tim | 906 | Mat3x3d I; | 
| 90 |  |  | I(0, 0) = 1.0; | 
| 91 |  |  | I(1, 1) = 1.0; | 
| 92 |  |  | I(2, 2) = 1.0; | 
| 93 |  |  |  | 
| 94 |  |  | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 95 | gezelter | 972 | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 96 |  |  | Mat3x3d Tij; | 
| 97 | tim | 906 | if (i != j ) { | 
| 98 | gezelter | 972 | Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 99 | tim | 977 | RealType rij = Rij.length(); | 
| 100 |  |  | RealType rij2 = rij * rij; | 
| 101 |  |  | RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; | 
| 102 | gezelter | 972 | Mat3x3d tmpMat; | 
| 103 |  |  | tmpMat = outProduct(Rij, Rij) / rij2; | 
| 104 | tim | 977 | RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 105 | tim | 978 | RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; | 
| 106 |  |  | RealType tmp2 = 1.0 - sumSigma2OverRij2; | 
| 107 |  |  | Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; | 
| 108 | tim | 906 | }else { | 
| 109 | tim | 977 | RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 110 | gezelter | 972 | Tij(0, 0) = constant; | 
| 111 |  |  | Tij(1, 1) = constant; | 
| 112 |  |  | Tij(2, 2) = constant; | 
| 113 | tim | 906 | } | 
| 114 |  |  | B.setSubMatrix(i*3, j*3, Tij); | 
| 115 | gezelter | 972 | } | 
| 116 | tim | 906 | } | 
| 117 | gezelter | 972 |  | 
| 118 | tim | 906 | //invert B Matrix | 
| 119 |  |  | invertMatrix(B, C); | 
| 120 | tim | 910 |  | 
| 121 | tim | 906 | //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) | 
| 122 |  |  | std::vector<Mat3x3d> U; | 
| 123 | gezelter | 1782 | for (unsigned int i = 0; i < nbeads; ++i) { | 
| 124 | gezelter | 972 | Mat3x3d currU; | 
| 125 |  |  | currU.setupSkewMat(beads[i].pos); | 
| 126 |  |  | U.push_back(currU); | 
| 127 | tim | 906 | } | 
| 128 |  |  |  | 
| 129 |  |  | //calculate Xi matrix at arbitrary origin O | 
| 130 |  |  | Mat3x3d Xiott; | 
| 131 |  |  | Mat3x3d Xiorr; | 
| 132 |  |  | Mat3x3d Xiotr; | 
| 133 | gezelter | 972 |  | 
| 134 | tim | 906 | //calculate the total volume | 
| 135 | gezelter | 972 |  | 
| 136 | tim | 977 | RealType volume = 0.0; | 
| 137 | tim | 906 | for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { | 
| 138 | gezelter | 972 | volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 139 | tim | 906 | } | 
| 140 | gezelter | 972 |  | 
| 141 |  |  | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 142 |  |  | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 143 |  |  | Mat3x3d Cij; | 
| 144 |  |  | C.getSubMatrix(i*3, j*3, Cij); | 
| 145 | tim | 906 |  | 
| 146 | gezelter | 972 | Xiott += Cij; | 
| 147 |  |  | Xiotr += U[i] * Cij; | 
| 148 | xsun | 1208 | // uncorrected here.  Volume correction is added after we assemble Xiorr | 
| 149 | gezelter | 972 | Xiorr += -U[i] * Cij * U[j]; | 
| 150 |  |  | } | 
| 151 | tim | 906 | } | 
| 152 | xsun | 1208 |  | 
| 153 |  |  | // add the volume correction | 
| 154 | gezelter | 1782 | Xiorr += (RealType(6.0) * viscosity * volume) * I; | 
| 155 | gezelter | 972 |  | 
| 156 | gezelter | 1390 | Xiott *= PhysicalConstants::viscoConvert; | 
| 157 |  |  | Xiotr *= PhysicalConstants::viscoConvert; | 
| 158 |  |  | Xiorr *= PhysicalConstants::viscoConvert; | 
| 159 | tim | 906 |  | 
| 160 |  |  | Mat3x3d tmp; | 
| 161 |  |  | Mat3x3d tmpInv; | 
| 162 |  |  | Vector3d tmpVec; | 
| 163 |  |  | tmp(0, 0) = Xiott(1, 1) + Xiott(2, 2); | 
| 164 |  |  | tmp(0, 1) = - Xiott(0, 1); | 
| 165 |  |  | tmp(0, 2) = -Xiott(0, 2); | 
| 166 |  |  | tmp(1, 0) = -Xiott(0, 1); | 
| 167 |  |  | tmp(1, 1) = Xiott(0, 0)  + Xiott(2, 2); | 
| 168 |  |  | tmp(1, 2) = -Xiott(1, 2); | 
| 169 |  |  | tmp(2, 0) = -Xiott(0, 2); | 
| 170 |  |  | tmp(2, 1) = -Xiott(1, 2); | 
| 171 |  |  | tmp(2, 2) = Xiott(1, 1) + Xiott(0, 0); | 
| 172 |  |  | tmpVec[0] = Xiotr(2, 1) - Xiotr(1, 2); | 
| 173 |  |  | tmpVec[1] = Xiotr(0, 2) - Xiotr(2, 0); | 
| 174 |  |  | tmpVec[2] = Xiotr(1, 0) - Xiotr(0, 1); | 
| 175 |  |  | tmpInv = tmp.inverse(); | 
| 176 |  |  | Vector3d ror = tmpInv * tmpVec; //center of resistance | 
| 177 |  |  | Mat3x3d Uor; | 
| 178 |  |  | Uor.setupSkewMat(ror); | 
| 179 |  |  |  | 
| 180 |  |  | Mat3x3d Xirtt; | 
| 181 |  |  | Mat3x3d Xirrr; | 
| 182 |  |  | Mat3x3d Xirtr; | 
| 183 |  |  |  | 
| 184 |  |  | Xirtt = Xiott; | 
| 185 |  |  | Xirtr = (Xiotr - Uor * Xiott); | 
| 186 |  |  | Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose(); | 
| 187 |  |  |  | 
| 188 |  |  |  | 
| 189 | tim | 977 | SquareMatrix<RealType,6> Xir6x6; | 
| 190 |  |  | SquareMatrix<RealType,6> Dr6x6; | 
| 191 | tim | 906 |  | 
| 192 |  |  | Xir6x6.setSubMatrix(0, 0, Xirtt); | 
| 193 |  |  | Xir6x6.setSubMatrix(0, 3, Xirtr.transpose()); | 
| 194 |  |  | Xir6x6.setSubMatrix(3, 0, Xirtr); | 
| 195 |  |  | Xir6x6.setSubMatrix(3, 3, Xirrr); | 
| 196 |  |  |  | 
| 197 |  |  | invertMatrix(Xir6x6, Dr6x6); | 
| 198 |  |  | Mat3x3d Drtt; | 
| 199 |  |  | Mat3x3d Drtr; | 
| 200 |  |  | Mat3x3d Drrt; | 
| 201 |  |  | Mat3x3d Drrr; | 
| 202 |  |  | Dr6x6.getSubMatrix(0, 0, Drtt); | 
| 203 |  |  | Dr6x6.getSubMatrix(0, 3, Drrt); | 
| 204 |  |  | Dr6x6.getSubMatrix(3, 0, Drtr); | 
| 205 |  |  | Dr6x6.getSubMatrix(3, 3, Drrr); | 
| 206 | gezelter | 1390 | RealType kt = PhysicalConstants::kb * temperature ; // in kcal mol^-1 | 
| 207 | tim | 906 | Drtt *= kt; | 
| 208 |  |  | Drrt *= kt; | 
| 209 |  |  | Drtr *= kt; | 
| 210 |  |  | Drrr *= kt; | 
| 211 | gezelter | 1390 | //Xirtt *= PhysicalConstants::kb * temperature; | 
| 212 |  |  | //Xirtr *= PhysicalConstants::kb * temperature; | 
| 213 |  |  | //Xirrr *= PhysicalConstants::kb * temperature; | 
| 214 | tim | 906 |  | 
| 215 | gezelter | 981 | Mat6x6d Xi, D; | 
| 216 | tim | 906 |  | 
| 217 | gezelter | 981 | cr->setCOR(ror); | 
| 218 |  |  |  | 
| 219 |  |  | Xi.setSubMatrix(0, 0, Xirtt); | 
| 220 |  |  | Xi.setSubMatrix(0, 3, Xirtr); | 
| 221 |  |  | Xi.setSubMatrix(3, 0, Xirtr); | 
| 222 |  |  | Xi.setSubMatrix(3, 3, Xirrr); | 
| 223 |  |  |  | 
| 224 |  |  | cr->setXi(Xi); | 
| 225 |  |  |  | 
| 226 |  |  | D.setSubMatrix(0, 0, Drtt); | 
| 227 |  |  | D.setSubMatrix(0, 3, Drrt); | 
| 228 |  |  | D.setSubMatrix(3, 0, Drtr); | 
| 229 |  |  | D.setSubMatrix(3, 3, Drrr); | 
| 230 |  |  |  | 
| 231 |  |  | cr->setD(D); | 
| 232 | tim | 906 |  | 
| 233 |  |  | std::cout << "-----------------------------------------\n"; | 
| 234 |  |  | std::cout << "center of resistance :" << std::endl; | 
| 235 |  |  | std::cout << ror << std::endl; | 
| 236 |  |  | std::cout << "resistant tensor at center of resistance" << std::endl; | 
| 237 |  |  | std::cout << "translation:" << std::endl; | 
| 238 |  |  | std::cout << Xirtt << std::endl; | 
| 239 |  |  | std::cout << "translation-rotation:" << std::endl; | 
| 240 |  |  | std::cout << Xirtr << std::endl; | 
| 241 |  |  | std::cout << "rotation:" << std::endl; | 
| 242 |  |  | std::cout << Xirrr << std::endl; | 
| 243 |  |  | std::cout << "diffusion tensor at center of resistance" << std::endl; | 
| 244 |  |  | std::cout << "translation:" << std::endl; | 
| 245 |  |  | std::cout << Drtt << std::endl; | 
| 246 |  |  | std::cout << "rotation-translation:" << std::endl; | 
| 247 |  |  | std::cout << Drrt << std::endl; | 
| 248 |  |  | std::cout << "translation-rotation:" << std::endl; | 
| 249 |  |  | std::cout << Drtr << std::endl; | 
| 250 |  |  | std::cout << "rotation:" << std::endl; | 
| 251 |  |  | std::cout << Drrr << std::endl; | 
| 252 |  |  | std::cout << "-----------------------------------------\n"; | 
| 253 |  |  |  | 
| 254 |  |  | return true; | 
| 255 |  |  | } | 
| 256 | gezelter | 972 |  | 
| 257 | xsun | 1177 | bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cd) { | 
| 258 | gezelter | 972 |  | 
| 259 | gezelter | 1782 | unsigned int nbeads = beads.size(); | 
| 260 | tim | 977 | DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); | 
| 261 |  |  | DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); | 
| 262 | tim | 906 | Mat3x3d I; | 
| 263 |  |  | I(0, 0) = 1.0; | 
| 264 |  |  | I(1, 1) = 1.0; | 
| 265 |  |  | I(2, 2) = 1.0; | 
| 266 |  |  |  | 
| 267 |  |  | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 268 | gezelter | 972 | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 269 |  |  | Mat3x3d Tij; | 
| 270 |  |  | if (i != j ) { | 
| 271 |  |  | Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 272 | tim | 977 | RealType rij = Rij.length(); | 
| 273 |  |  | RealType rij2 = rij * rij; | 
| 274 |  |  | RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; | 
| 275 | gezelter | 972 | Mat3x3d tmpMat; | 
| 276 |  |  | tmpMat = outProduct(Rij, Rij) / rij2; | 
| 277 | tim | 977 | RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 278 | tim | 978 | RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; | 
| 279 |  |  | RealType tmp2 = 1.0 - sumSigma2OverRij2; | 
| 280 |  |  | Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; | 
| 281 | gezelter | 972 | }else { | 
| 282 | tim | 977 | RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 283 | gezelter | 972 | Tij(0, 0) = constant; | 
| 284 |  |  | Tij(1, 1) = constant; | 
| 285 |  |  | Tij(2, 2) = constant; | 
| 286 | tim | 906 | } | 
| 287 | gezelter | 972 | B.setSubMatrix(i*3, j*3, Tij); | 
| 288 |  |  | } | 
| 289 | tim | 906 | } | 
| 290 | gezelter | 972 |  | 
| 291 | tim | 906 | //invert B Matrix | 
| 292 |  |  | invertMatrix(B, C); | 
| 293 | gezelter | 972 |  | 
| 294 | tim | 906 | //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) | 
| 295 |  |  | std::vector<Mat3x3d> U; | 
| 296 | gezelter | 1782 | for (unsigned int i = 0; i < nbeads; ++i) { | 
| 297 | gezelter | 972 | Mat3x3d currU; | 
| 298 |  |  | currU.setupSkewMat(beads[i].pos); | 
| 299 |  |  | U.push_back(currU); | 
| 300 | tim | 906 | } | 
| 301 |  |  |  | 
| 302 |  |  | //calculate Xi matrix at arbitrary origin O | 
| 303 |  |  | Mat3x3d Xitt; | 
| 304 |  |  | Mat3x3d Xirr; | 
| 305 |  |  | Mat3x3d Xitr; | 
| 306 |  |  |  | 
| 307 |  |  | //calculate the total volume | 
| 308 |  |  |  | 
| 309 | tim | 977 | RealType volume = 0.0; | 
| 310 | tim | 906 | for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { | 
| 311 | gezelter | 972 | volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 312 | tim | 906 | } | 
| 313 | gezelter | 972 |  | 
| 314 | tim | 906 | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 315 | gezelter | 972 | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 316 |  |  | Mat3x3d Cij; | 
| 317 |  |  | C.getSubMatrix(i*3, j*3, Cij); | 
| 318 | tim | 906 |  | 
| 319 | gezelter | 972 | Xitt += Cij; | 
| 320 |  |  | Xitr += U[i] * Cij; | 
| 321 | xsun | 1208 | // uncorrected here.  Volume correction is added after we assemble Xiorr | 
| 322 | gezelter | 972 | Xirr += -U[i] * Cij * U[j]; | 
| 323 |  |  | } | 
| 324 | tim | 906 | } | 
| 325 | xsun | 1208 | // add the volume correction here: | 
| 326 | gezelter | 1782 | Xirr += (RealType(6.0) * viscosity * volume) * I; | 
| 327 | gezelter | 972 |  | 
| 328 | gezelter | 1390 | Xitt *= PhysicalConstants::viscoConvert; | 
| 329 |  |  | Xitr *= PhysicalConstants::viscoConvert; | 
| 330 |  |  | Xirr *= PhysicalConstants::viscoConvert; | 
| 331 | gezelter | 972 |  | 
| 332 | gezelter | 1390 | RealType kt = PhysicalConstants::kb * temperature; // in kcal mol^-1 | 
| 333 | gezelter | 972 |  | 
| 334 | tim | 906 | 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 | 972 |  | 
| 338 | tim | 906 | 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 | 977 | SquareMatrix<RealType, 6> Dd; | 
| 392 | tim | 906 | 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 | 977 | SquareMatrix<RealType, 6> Xid; | 
| 397 | tim | 906 | 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 | gezelter | 1390 | //Xid /= PhysicalConstants::energyConvert; | 
| 406 |  |  | Xid *= PhysicalConstants::kb * temperature; | 
| 407 | tim | 906 |  | 
| 408 | gezelter | 981 | Mat6x6d Xi, D; | 
| 409 | tim | 906 |  | 
| 410 | xsun | 1177 | cd->setCOR(rod); | 
| 411 | gezelter | 981 |  | 
| 412 | xsun | 1177 | cd->setXi(Xid); | 
| 413 | gezelter | 981 |  | 
| 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 | xsun | 1177 | cd->setD(D); | 
| 420 | gezelter | 981 |  | 
| 421 | tim | 906 | 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 | xsun | 1208 | std::cout << "translation(A^2 / fs) :" << std::endl; | 
| 427 | tim | 906 | std::cout << Ddtt << std::endl; | 
| 428 | xsun | 1208 | std::cout << "translation-rotation(A / fs):" << std::endl; | 
| 429 | tim | 906 | std::cout << Ddtr << std::endl; | 
| 430 | xsun | 1208 | std::cout << "rotation(fs^-1):" << std::endl; | 
| 431 | tim | 906 | 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 | xsun | 1208 | std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-1):" << std::endl; | 
| 447 | tim | 906 | std::cout << Xidrt << std::endl; | 
| 448 | xsun | 1208 | std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-1):" << std::endl; | 
| 449 | tim | 906 | std::cout << Xidtr << std::endl; | 
| 450 | xsun | 1208 | std::cout << "rotation(kcal*fs*mol^-1):" << std::endl; | 
| 451 | tim | 906 | std::cout << Xidrr << std::endl; | 
| 452 |  |  |  | 
| 453 |  |  | return true; | 
| 454 | gezelter | 972 |  | 
| 455 |  |  | } | 
| 456 | tim | 906 |  | 
| 457 | gezelter | 972 | void ApproximationModel::writeBeads(std::ostream& os) { | 
| 458 | tim | 906 | 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 | 972 | os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; | 
| 463 | tim | 906 | } | 
| 464 | gezelter | 972 |  | 
| 465 |  |  | } | 
| 466 | tim | 906 | } |