--- trunk/src/applications/hydrodynamics/ApproximationModel.cpp 2006/03/29 18:09:26 921 +++ trunk/src/applications/hydrodynamics/ApproximationModel.cpp 2012/08/31 21:16:10 1793 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,19 +28,29 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include "applications/hydrodynamics/ApproximationModel.hpp" #include "math/LU.hpp" #include "math/DynamicRectMatrix.hpp" #include "math/SquareMatrix3.hpp" -#include "utils/OOPSEConstant.hpp" -#include "applications/hydrodynamics/Spheric.hpp" -#include "applications/hydrodynamics/Ellipsoid.hpp" +#include "utils/PhysicalConstants.hpp" +#include "hydrodynamics/Sphere.hpp" +#include "hydrodynamics/Ellipsoid.hpp" #include "applications/hydrodynamics/CompositeShape.hpp" #include "math/LU.hpp" #include "utils/simError.h" -namespace oopse { +namespace OpenMD { /** * Reference: * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles: @@ -57,115 +58,104 @@ namespace oopse { * Biophysical Journal, 75(6), 3044, 1999 */ -ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){ - -} - -bool ApproximationModel::calcHydroProps(Spheric* spheric, double viscosity, double temperature) { - return internalCalcHydroProps(static_cast(spheric), viscosity, temperature); -} - -bool ApproximationModel::calcHydroProps(Ellipsoid* ellipsoid, double viscosity, double temperature) { - return internalCalcHydroProps(static_cast(ellipsoid), viscosity, temperature); -} -bool ApproximationModel::calcHydroProps(CompositeShape* compositeShape, double viscosity, double temperature) { - return internalCalcHydroProps(static_cast(compositeShape), viscosity, temperature); -} - -void ApproximationModel::init() { + ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){ + } + + void ApproximationModel::init() { if (!createBeads(beads_)) { sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n"); painCave.isFatal = 1; simError(); } - -} - -bool ApproximationModel::internalCalcHydroProps(Shape* shape, double viscosity, double temperature) { - - bool ret = true; - HydroProps cr; - HydroProps cd; + + } + + bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { + + HydroProp* cr = new HydroProp(); + HydroProp* cd = new HydroProp(); calcHydroPropsAtCR(beads_, viscosity, temperature, cr); calcHydroPropsAtCD(beads_, viscosity, temperature, cd); setCR(cr); setCD(cd); - return true; -} - -bool ApproximationModel::calcHydroPropsAtCR(std::vector& beads, double viscosity, double temperature, HydroProps& cr) { - - int nbeads = beads.size(); - DynamicRectMatrix B(3*nbeads, 3*nbeads); - DynamicRectMatrix C(3*nbeads, 3*nbeads); + } + + bool ApproximationModel::calcHydroPropsAtCR(std::vector& beads, RealType viscosity, RealType temperature, HydroProp* cr) { + + unsigned int nbeads = beads.size(); + DynamicRectMatrix B(3*nbeads, 3*nbeads); + DynamicRectMatrix C(3*nbeads, 3*nbeads); Mat3x3d I; I(0, 0) = 1.0; I(1, 1) = 1.0; I(2, 2) = 1.0; for (std::size_t i = 0; i < nbeads; ++i) { - for (std::size_t j = 0; j < nbeads; ++j) { - Mat3x3d Tij; + for (std::size_t j = 0; j < nbeads; ++j) { + Mat3x3d Tij; if (i != j ) { - Vector3d Rij = beads[i].pos - beads[j].pos; - double rij = Rij.length(); - double rij2 = rij * rij; - double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; - Mat3x3d tmpMat; - tmpMat = outProduct(Rij, Rij) / rij2; - double constant = 8.0 * NumericConstant::PI * viscosity * rij; - Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant; + Vector3d Rij = beads[i].pos - beads[j].pos; + RealType rij = Rij.length(); + RealType rij2 = rij * rij; + RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; + Mat3x3d tmpMat; + tmpMat = outProduct(Rij, Rij) / rij2; + RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; + RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; + RealType tmp2 = 1.0 - sumSigma2OverRij2; + Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; }else { - double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); - Tij(0, 0) = constant; - Tij(1, 1) = constant; - Tij(2, 2) = constant; + RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); + Tij(0, 0) = constant; + Tij(1, 1) = constant; + Tij(2, 2) = constant; } B.setSubMatrix(i*3, j*3, Tij); - } + } } - + //invert B Matrix invertMatrix(B, C); //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) std::vector U; - for (int i = 0; i < nbeads; ++i) { - Mat3x3d currU; - currU.setupSkewMat(beads[i].pos); - U.push_back(currU); + for (unsigned int i = 0; i < nbeads; ++i) { + Mat3x3d currU; + currU.setupSkewMat(beads[i].pos); + U.push_back(currU); } //calculate Xi matrix at arbitrary origin O Mat3x3d Xiott; Mat3x3d Xiorr; Mat3x3d Xiotr; - + //calculate the total volume - - double volume = 0.0; + + RealType volume = 0.0; for (std::vector::iterator iter = beads.begin(); iter != beads.end(); ++iter) { - volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); + volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); } - + for (std::size_t i = 0; i < nbeads; ++i) { - for (std::size_t j = 0; j < nbeads; ++j) { - Mat3x3d Cij; - C.getSubMatrix(i*3, j*3, Cij); - - Xiott += Cij; - Xiotr += U[i] * Cij; - Xiorr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I; - } + for (std::size_t j = 0; j < nbeads; ++j) { + Mat3x3d Cij; + C.getSubMatrix(i*3, j*3, Cij); + + Xiott += Cij; + Xiotr += U[i] * Cij; + // uncorrected here. Volume correction is added after we assemble Xiorr + Xiorr += -U[i] * Cij * U[j]; + } } - const double convertConstant = 6.023; //convert poise.angstrom to amu/fs - Xiott *= convertConstant; - Xiotr *= convertConstant; - Xiorr *= convertConstant; + // add the volume correction + Xiorr += (RealType(6.0) * viscosity * volume) * I; - + Xiott *= PhysicalConstants::viscoConvert; + Xiotr *= PhysicalConstants::viscoConvert; + Xiorr *= PhysicalConstants::viscoConvert; Mat3x3d tmp; Mat3x3d tmpInv; @@ -196,8 +186,8 @@ bool ApproximationModel::calcHydroPropsAtCR(std::vecto Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose(); - SquareMatrix Xir6x6; - SquareMatrix Dr6x6; + SquareMatrix Xir6x6; + SquareMatrix Dr6x6; Xir6x6.setSubMatrix(0, 0, Xirtt); Xir6x6.setSubMatrix(0, 3, Xirtr.transpose()); @@ -213,25 +203,32 @@ bool ApproximationModel::calcHydroPropsAtCR(std::vecto Dr6x6.getSubMatrix(0, 3, Drrt); Dr6x6.getSubMatrix(3, 0, Drtr); Dr6x6.getSubMatrix(3, 3, Drrr); - double kt = OOPSEConstant::kB * temperature ; + RealType kt = PhysicalConstants::kb * temperature ; // in kcal mol^-1 Drtt *= kt; Drrt *= kt; Drtr *= kt; Drrr *= kt; - Xirtt *= OOPSEConstant::kb * temperature; - Xirtr *= OOPSEConstant::kb * temperature; - Xirrr *= OOPSEConstant::kb * temperature; + //Xirtt *= PhysicalConstants::kb * temperature; + //Xirtr *= PhysicalConstants::kb * temperature; + //Xirrr *= PhysicalConstants::kb * temperature; + Mat6x6d Xi, D; - cr.center = ror; - cr.Xi.setSubMatrix(0, 0, Xirtt); - cr.Xi.setSubMatrix(0, 3, Xirtr); - cr.Xi.setSubMatrix(3, 0, Xirtr); - cr.Xi.setSubMatrix(3, 3, Xirrr); - cr.D.setSubMatrix(0, 0, Drtt); - cr.D.setSubMatrix(0, 3, Drrt); - cr.D.setSubMatrix(3, 0, Drtr); - cr.D.setSubMatrix(3, 3, Drrr); + cr->setCOR(ror); + + Xi.setSubMatrix(0, 0, Xirtt); + Xi.setSubMatrix(0, 3, Xirtr); + Xi.setSubMatrix(3, 0, Xirtr); + Xi.setSubMatrix(3, 3, Xirrr); + + cr->setXi(Xi); + + D.setSubMatrix(0, 0, Drtt); + D.setSubMatrix(0, 3, Drrt); + D.setSubMatrix(3, 0, Drtr); + D.setSubMatrix(3, 3, Drrr); + + cr->setD(D); std::cout << "-----------------------------------------\n"; std::cout << "center of resistance :" << std::endl; @@ -256,48 +253,50 @@ bool ApproximationModel::calcHydroPropsAtCR(std::vecto return true; } - -bool ApproximationModel::calcHydroPropsAtCD(std::vector& beads, double viscosity, double temperature, HydroProps& cr) { - - int nbeads = beads.size(); - DynamicRectMatrix B(3*nbeads, 3*nbeads); - DynamicRectMatrix C(3*nbeads, 3*nbeads); + + bool ApproximationModel::calcHydroPropsAtCD(std::vector& beads, RealType viscosity, RealType temperature, HydroProp* cd) { + + unsigned int nbeads = beads.size(); + DynamicRectMatrix B(3*nbeads, 3*nbeads); + DynamicRectMatrix C(3*nbeads, 3*nbeads); Mat3x3d I; I(0, 0) = 1.0; I(1, 1) = 1.0; I(2, 2) = 1.0; for (std::size_t i = 0; i < nbeads; ++i) { - for (std::size_t j = 0; j < nbeads; ++j) { - Mat3x3d Tij; - if (i != j ) { - Vector3d Rij = beads[i].pos - beads[j].pos; - double rij = Rij.length(); - double rij2 = rij * rij; - double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; - Mat3x3d tmpMat; - tmpMat = outProduct(Rij, Rij) / rij2; - double constant = 8.0 * NumericConstant::PI * viscosity * rij; - Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant; - }else { - double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); - Tij(0, 0) = constant; - Tij(1, 1) = constant; - Tij(2, 2) = constant; - } - B.setSubMatrix(i*3, j*3, Tij); + for (std::size_t j = 0; j < nbeads; ++j) { + Mat3x3d Tij; + if (i != j ) { + Vector3d Rij = beads[i].pos - beads[j].pos; + RealType rij = Rij.length(); + RealType rij2 = rij * rij; + RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; + Mat3x3d tmpMat; + tmpMat = outProduct(Rij, Rij) / rij2; + RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; + RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; + RealType tmp2 = 1.0 - sumSigma2OverRij2; + Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; + }else { + RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); + Tij(0, 0) = constant; + Tij(1, 1) = constant; + Tij(2, 2) = constant; } + B.setSubMatrix(i*3, j*3, Tij); + } } - + //invert B Matrix invertMatrix(B, C); - + //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) std::vector U; - for (int i = 0; i < nbeads; ++i) { - Mat3x3d currU; - currU.setupSkewMat(beads[i].pos); - U.push_back(currU); + for (unsigned int i = 0; i < nbeads; ++i) { + Mat3x3d currU; + currU.setupSkewMat(beads[i].pos); + U.push_back(currU); } //calculate Xi matrix at arbitrary origin O @@ -307,33 +306,35 @@ bool ApproximationModel::calcHydroPropsAtCD(std::vecto //calculate the total volume - double volume = 0.0; + RealType volume = 0.0; for (std::vector::iterator iter = beads.begin(); iter != beads.end(); ++iter) { - volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); + volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); } - + for (std::size_t i = 0; i < nbeads; ++i) { - for (std::size_t j = 0; j < nbeads; ++j) { - Mat3x3d Cij; - C.getSubMatrix(i*3, j*3, Cij); + for (std::size_t j = 0; j < nbeads; ++j) { + Mat3x3d Cij; + C.getSubMatrix(i*3, j*3, Cij); - Xitt += Cij; - Xitr += U[i] * Cij; - Xirr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I; - } + Xitt += Cij; + Xitr += U[i] * Cij; + // uncorrected here. Volume correction is added after we assemble Xiorr + Xirr += -U[i] * Cij * U[j]; + } } - - const double convertConstant = 6.023; //convert poise.angstrom to amu/fs - Xitt *= convertConstant; - Xitr *= convertConstant; - Xirr *= convertConstant; - - double kt = OOPSEConstant::kB * temperature; - + // add the volume correction here: + Xirr += (RealType(6.0) * viscosity * volume) * I; + + Xitt *= PhysicalConstants::viscoConvert; + Xitr *= PhysicalConstants::viscoConvert; + Xirr *= PhysicalConstants::viscoConvert; + + RealType kt = PhysicalConstants::kb * temperature; // in kcal mol^-1 + Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O - + const static Mat3x3d zeroMat(0.0); Mat3x3d XittInv(0.0); @@ -387,12 +388,12 @@ bool ApproximationModel::calcHydroPropsAtCD(std::vecto Ddrr = Dorr; Ddtr = Dotr + Dorr * Uod; - SquareMatrix Dd; + SquareMatrix Dd; Dd.setSubMatrix(0, 0, Ddtt); Dd.setSubMatrix(0, 3, Ddtr.transpose()); Dd.setSubMatrix(3, 0, Ddtr); Dd.setSubMatrix(3, 3, Ddrr); - SquareMatrix Xid; + SquareMatrix Xid; Ddtt *= kt; Ddtr *=kt; Ddrr *= kt; @@ -401,26 +402,32 @@ bool ApproximationModel::calcHydroPropsAtCD(std::vecto //Xidtt in units of kcal*fs*mol^-1*Ang^-2 - //Xid /= OOPSEConstant::energyConvert; - Xid *= OOPSEConstant::kb * temperature; + //Xid /= PhysicalConstants::energyConvert; + Xid *= PhysicalConstants::kb * temperature; - cr.center = rod; - cr.D.setSubMatrix(0, 0, Ddtt); - cr.D.setSubMatrix(0, 3, Ddtr); - cr.D.setSubMatrix(3, 0, Ddtr); - cr.D.setSubMatrix(3, 3, Ddrr); - cr.Xi = Xid; + Mat6x6d Xi, D; + cd->setCOR(rod); + + cd->setXi(Xid); + + D.setSubMatrix(0, 0, Ddtt); + D.setSubMatrix(0, 3, Ddtr); + D.setSubMatrix(3, 0, Ddtr); + D.setSubMatrix(3, 3, Ddrr); + + cd->setD(D); + std::cout << "viscosity = " << viscosity << std::endl; std::cout << "temperature = " << temperature << std::endl; std::cout << "center of diffusion :" << std::endl; std::cout << rod << std::endl; std::cout << "diffusion tensor at center of diffusion " << std::endl; - std::cout << "translation(A^2/fs) :" << std::endl; + std::cout << "translation(A^2 / fs) :" << std::endl; std::cout << Ddtt << std::endl; - std::cout << "translation-rotation(A^3/fs):" << std::endl; + std::cout << "translation-rotation(A / fs):" << std::endl; std::cout << Ddtr << std::endl; - std::cout << "rotation(A^4/fs):" << std::endl; + std::cout << "rotation(fs^-1):" << std::endl; std::cout << Ddrr << std::endl; std::cout << "resistance tensor at center of diffusion " << std::endl; @@ -436,28 +443,24 @@ bool ApproximationModel::calcHydroPropsAtCD(std::vecto Xid.getSubMatrix(3, 3, Xidrr); std::cout << Xidtt << std::endl; - std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-3):" << std::endl; + std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-1):" << std::endl; std::cout << Xidrt << std::endl; - std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-3):" << std::endl; + std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-1):" << std::endl; std::cout << Xidtr << std::endl; - std::cout << "rotation(kcal*fs*mol^-1*Ang^-4):" << std::endl; + std::cout << "rotation(kcal*fs*mol^-1):" << std::endl; std::cout << Xidrr << std::endl; return true; - -} + + } - -void ApproximationModel::writeBeads(std::ostream& os) { + void ApproximationModel::writeBeads(std::ostream& os) { std::vector::iterator iter; os << beads_.size() << std::endl; os << "Generated by Hydro" << std::endl; for (iter = beads_.begin(); iter != beads_.end(); ++iter) { - os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; + os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; } - + + } } - - - -}