--- trunk/src/applications/hydrodynamics/HydrodynamicsModel.cpp 2006/02/24 21:17:05 893 +++ trunk/src/applications/hydrodynamics/HydrodynamicsModel.cpp 2006/06/05 18:24:45 981 @@ -38,246 +38,137 @@ * University of Notre Dame has been advised of the possibility of * such damages. */ +#include "applications/hydrodynamics/HydrodynamicsModel.hpp" +#include "hydrodynamics/Shape.hpp" +#include "hydrodynamics/Sphere.hpp" +#include "hydrodynamics/Ellipsoid.hpp" +#include "applications/hydrodynamics/CompositeShape.hpp" -#include "applications/hydrodynamics/HydrodynamicsModel.hpp" -#include "math/LU.hpp" -#include "math/DynamicRectMatrix.hpp" -#include "math/SquareMatrix3.hpp" -#include "utils/OOPSEConstant.hpp" namespace oopse { -/** - * Reference: - * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles: - * Comparison of Different Modeling and Computational Procedures. - * Biophysical Journal, 75(6), 3044, 1999 - */ + + bool HydrodynamicsModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { + return false; + } + + void HydrodynamicsModel::writeHydroProps(std::ostream& os) { -HydrodynamicsModel::HydrodynamicsModel(StuntDouble* sd, const DynamicProperty& extraParams) : sd_(sd){ - DynamicProperty::const_iterator iter; - - iter = extraParams.find("Viscosity"); - if (iter != extraParams.end()) { - boost::any param = iter->second; - viscosity_ = boost::any_cast(param); - }else { - std::cout << "HydrodynamicsModel Error\n" ; - } - - iter = extraParams.find("Temperature"); - if (iter != extraParams.end()) { - boost::any param = iter->second; - temperature_ = boost::any_cast(param); - }else { - std::cout << "HydrodynamicsModel Error\n" ; - } -} - -bool HydrodynamicsModel::calcHydrodyanmicsProps() { - if (!createBeads(beads_)) { - std::cout << "can not create beads" << std::endl; - return false; - } + Vector3d center; + Mat6x6d Xi, D; - 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; + os << sd_->getType() << "\t"; - 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_[i].radius*beads_[i].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); - std::cout << Tij << std::endl; - } - } + //center of resistance - std::cout << "B=\n" - << B << std::endl; - //invert B Matrix - invertMatrix(B, C); + center = cr_->getCOR(); - std::cout << "C=\n" - << C << std::endl; - - //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); - } + os << center[0] << "\t" << center[1] << "\t" << center[2] << "\t"; - //calculate Xi matrix at arbitrary origin O - Mat3x3d Xitt; - Mat3x3d Xirr; - Mat3x3d Xitr; + //resistance tensor at center of resistance + //translation - //calculate the total volume + Xi = cr_->getXi(); - double 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); - } - - 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); - - Xitt += Cij; - Xitr += U[i] * Cij; - Xirr += -U[i] * Cij * U[j]; - //Xirr += -U[i] * Cij * U[j] + (0.166*6 * viscosity_ * volume) * I; - } - } + os << Xi(0, 0) << "\t" << Xi(0, 1) << "\t" << Xi(0, 2) << "\t" + << Xi(1, 0) << "\t" << Xi(1, 1) << "\t" << Xi(1, 2) << "\t" + << Xi(2, 0) << "\t" << Xi(2, 1) << "\t" << Xi(2, 2) << "\t"; + + //rotation-translation + os << Xi(0, 3) << "\t" << Xi(0, 4) << "\t" << Xi(0, 5) << "\t" + << Xi(1, 3) << "\t" << Xi(1, 4) << "\t" << Xi(1, 5) << "\t" + << Xi(2, 3) << "\t" << Xi(2, 4) << "\t" << Xi(2, 5) << "\t"; + + //translation-rotation + os << Xi(3, 0) << "\t" << Xi(3, 1) << "\t" << Xi(3, 2) << "\t" + << Xi(4, 0) << "\t" << Xi(4, 1) << "\t" << Xi(4, 2) << "\t" + << Xi(5, 0) << "\t" << Xi(5, 1) << "\t" << Xi(5, 2) << "\t"; + + //rotation + os << Xi(3, 3) << "\t" << Xi(3, 4) << "\t" << Xi(3, 5) << "\t" + << Xi(4, 3) << "\t" << Xi(4, 4) << "\t" << Xi(4, 5) << "\t" + << Xi(5, 3) << "\t" << Xi(5, 4) << "\t" << Xi(5, 5) << "\t"; + + + //diffusion tensor at center of resistance + //translation - //invert Xi to get Diffusion Tensor at arbitrary origin O - RectMatrix Xi; - RectMatrix Do; - Xi.setSubMatrix(0, 0, Xitt); - Xi.setSubMatrix(0, 3, Xitr.transpose()); - Xi.setSubMatrix(3, 0, Xitr); - Xi.setSubMatrix(3, 3, Xirr); - //invertMatrix(Xi, Do); - double kt = OOPSEConstant::kB * temperature_ * 1.66E-2; - //Do *= kt; + D = cr_->getD(); - - 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); + os << D(0, 0) << "\t" << D(0, 1) << "\t" << D(0, 2) << "\t" + << D(1, 0) << "\t" << D(1, 1) << "\t" << D(1, 2) << "\t" + << D(2, 0) << "\t" << D(2, 1) << "\t" << D(2, 2) << "\t"; - Mat3x3d XittInv(0.0); - XittInv = Xitt.inverse(); + //rotation-translation + os << D(0, 3) << "\t" << D(0, 4) << "\t" << D(0, 5) << "\t" + << D(1, 3) << "\t" << D(1, 4) << "\t" << D(1, 5) << "\t" + << D(2, 3) << "\t" << D(2, 4) << "\t" << D(2, 5) << "\t"; - //Xirr may not be inverted,if it one of the diagonal element is zero, for example - //( a11 a12 0) - //( a21 a22 0) - //( 0 0 0) - Mat3x3d XirrInv; - XirrInv = Xirr.inverse(); + //translation-rotation + os << D(3, 0) << "\t" << D(3, 1) << "\t" << D(3, 2) << "\t" + << D(4, 0) << "\t" << D(4, 1) << "\t" << D(4, 2) << "\t" + << D(5, 0) << "\t" << D(5, 1) << "\t" << D(5, 2) << "\t"; + + //rotation + os << D(3, 3) << "\t" << D(3, 4) << "\t" << D(3, 5) << "\t" + << D(4, 3) << "\t" << D(4, 4) << "\t" << D(4, 5) << "\t" + << D(5, 3) << "\t" << D(5, 4) << "\t" << D(5, 5) << "\t"; + + //--------------------------------------------------------------------- + + //center of diffusion - Mat3x3d tmp; - Mat3x3d tmpInv; - tmp = Xitt - Xitr.transpose() * XirrInv * Xitr; - tmpInv = tmp.inverse(); + center = cd_->getCOR(); - Dott = kt * tmpInv; - Dotr = -kt*XirrInv * Xitr * tmpInv* 1.0E8; - - tmp = Xirr - Xitr * XittInv * Xitr.transpose(); - tmpInv = tmp.inverse(); + os << center[0] << "\t" << center[1] << "\t" << center[2] << "\t"; - Dorr = kt * tmpInv*1.0E16; + //resistance tensor at center of diffusion + //translation - //Do.getSubMatrix(0, 0 , Dott); - //Do.getSubMatrix(3, 0, Dotr); - //Do.getSubMatrix(3, 3, Dorr); + Xi = cd_->getXi(); - //calculate center of diffusion - tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2); - tmp(0, 1) = - Dorr(0, 1); - tmp(0, 2) = -Dorr(0, 2); - tmp(1, 0) = -Dorr(0, 1); - tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2); - tmp(1, 2) = -Dorr(1, 2); - tmp(2, 0) = -Dorr(0, 2); - tmp(2, 1) = -Dorr(1, 2); - tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0); - - Vector3d tmpVec; - tmpVec[0] = Dotr(1, 2) - Dotr(2, 1); - tmpVec[1] = Dotr(2, 0) - Dotr(0, 2); - tmpVec[2] = Dotr(0, 1) - Dotr(1, 0); - - tmpInv = tmp.inverse(); + os << Xi(0, 0) << "\t" << Xi(0, 1) << "\t" << Xi(0, 2) << "\t" + << Xi(1, 0) << "\t" << Xi(1, 1) << "\t" << Xi(1, 2) << "\t" + << Xi(2, 0) << "\t" << Xi(2, 1) << "\t" << Xi(2, 2) << "\t"; - Vector3d rod = tmpInv * tmpVec; - - //calculate Diffusion Tensor at center of diffusion - Mat3x3d Uod; - Uod.setupSkewMat(rod); + //rotation-translation + os << Xi(0, 3) << "\t" << Xi(0, 4) << "\t" << Xi(0, 5) << "\t" + << Xi(1, 3) << "\t" << Xi(1, 4) << "\t" << Xi(1, 5) << "\t" + << Xi(2, 3) << "\t" << Xi(2, 4) << "\t" << Xi(2, 5) << "\t"; - Mat3x3d Ddtt; //translational diffusion tensor at diffusion center - Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center - Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor + //translation-rotation + os << Xi(3, 0) << "\t" << Xi(3, 1) << "\t" << Xi(3, 2) << "\t" + << Xi(4, 0) << "\t" << Xi(4, 1) << "\t" << Xi(4, 2) << "\t" + << Xi(5, 0) << "\t" << Xi(5, 1) << "\t" << Xi(5, 2) << "\t"; - Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr; - Ddrr = Dorr; - Ddtr = Dotr + Dorr * Uod; + //rotation + os << Xi(3, 3) << "\t" << Xi(3, 4) << "\t" << Xi(3, 5) << "\t" + << Xi(4, 3) << "\t" << Xi(4, 4) << "\t" << Xi(4, 5) << "\t" + << Xi(5, 3) << "\t" << Xi(5, 4) << "\t" << Xi(5, 5) << "\t"; - props_.diffCenter = rod; - props_.transDiff = Ddtt; - props_.transRotDiff = Ddtr; - props_.rotDiff = Ddrr; + + //diffusion tensor at center of diffusion + //translation - return true; -} + D = cd_->getD(); -void HydrodynamicsModel::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; - } - -} - -void HydrodynamicsModel::writeDiffCenterAndDiffTensor(std::ostream& os) { - os << "//viscosity = " << viscosity_ << std::endl; - os << "//temperature = " << temperature_<< std::endl; - std::vector::iterator iter; - os << sd_->getType() << "\n"; - - os << "//diffusion center" << std::endl; - os << props_.diffCenter << std::endl; - - os << "//translational diffusion tensor" << std::endl; - os << props_.transDiff << std::endl; - - os << "//translation-rotation coupling diffusion tensor" << std::endl; - os << props_.transRotDiff << std::endl; - - os << "//rotational diffusion tensor" << std::endl; - os << props_.rotDiff << std::endl; + os << D(0, 0) << "\t" << D(0, 1) << "\t" << D(0, 2) << "\t" + << D(1, 0) << "\t" << D(1, 1) << "\t" << D(1, 2) << "\t" + << D(2, 0) << "\t" << D(2, 1) << "\t" << D(2, 2) << "\t"; - /* - os << props_.diffCenter[0] << "\t" << props_.diffCenter[1] << "\t" << props_.diffCenter[2] << "\n" - - os << props_.transDiff(0, 0) << "\t" << props_.transDiff(0, 1) << "\t" << props_.transDiff(0, 2) << "\t" - << props_.transDiff(1, 0) << "\t" << props_.transDiff(1, 1) << "\t" << props_.transDiff(1, 2) << "\t" - << props_.transDiff(2, 0) << "\t" << props_.transDiff(2, 1) << "\t" << props_.transDiff(2, 2) << "\n"; + //rotation-translation + os << D(0, 3) << "\t" << D(0, 4) << "\t" << D(0, 5) << "\t" + << D(1, 3) << "\t" << D(1, 4) << "\t" << D(1, 5) << "\t" + << D(2, 3) << "\t" << D(2, 4) << "\t" << D(2, 5) << "\t"; - os << props_.transRotDiff(0, 0) << "\t" << props_.transRotDiff(0, 1) << "\t" << props_.transRotDiff(0, 2) << "\t" - << props_.transRotDiff(1, 0) << "\t" << props_.transRotDiff(1, 1) << "\t" << props_.transRotDiff(1, 2) << "\t" - << props_.transRotDiff(2, 0) << "\t" << props_.transRotDiff(2, 1) << "\t" << props_.transRotDiff(2, 2) << "\t" - - os << props_.rotDiff(0, 0) << "\t" << props_.rotDiff(0, 1) << "\t" << props_.rotDiff(0, 2) << "\t" - << props_.rotDiff(1, 0) << "\t" << props_.rotDiff(1, 1) << "\t" << props_.rotDiff(1, 2) << "\t" - << props_.rotDiff(2, 0) << "\t" << props_.rotDiff(2, 1) << "\t" << props_.rotDiff(2, 2) << ";" - << std::endl; - */ + //translation-rotation + os << D(3, 0) << "\t" << D(3, 1) << "\t" << D(3, 2) << "\t" + << D(4, 0) << "\t" << D(4, 1) << "\t" << D(4, 2) << "\t" + << D(5, 0) << "\t" << D(5, 1) << "\t" << D(5, 2) << "\t"; + + //rotation + os << D(3, 3) << "\t" << D(3, 4) << "\t" << D(3, 5) << "\t" + << D(4, 3) << "\t" << D(4, 4) << "\t" << D(4, 5) << "\t" + << D(5, 3) << "\t" << D(5, 4) << "\t" << D(5, 5) << "\n"; + + } + } - -}