--- trunk/src/applications/hydrodynamics/ApproximationModel.cpp 2006/05/24 18:31:12 972 +++ trunk/src/applications/hydrodynamics/ApproximationModel.cpp 2008/01/16 20:19:28 1208 @@ -69,24 +69,23 @@ namespace oopse { } - bool ApproximationModel::calcHydroProps(Shape* shape, double viscosity, double temperature) { + bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { bool ret = true; - HydroProps cr; - HydroProps cd; + HydroProp* cr = new HydroProp(); + HydroProp* cd = new HydroProp(); calcHydroPropsAtCR(beads_, viscosity, temperature, cr); - //calcHydroPropsAtCD(beads_, viscosity, temperature, cd); + calcHydroPropsAtCD(beads_, viscosity, temperature, cd); setCR(cr); setCD(cd); - return true; } - bool ApproximationModel::calcHydroPropsAtCR(std::vector& beads, double viscosity, double temperature, HydroProps& cr) { + bool ApproximationModel::calcHydroPropsAtCR(std::vector& beads, RealType viscosity, RealType temperature, HydroProp* cr) { int nbeads = beads.size(); - DynamicRectMatrix B(3*nbeads, 3*nbeads); - DynamicRectMatrix C(3*nbeads, 3*nbeads); + DynamicRectMatrix B(3*nbeads, 3*nbeads); + DynamicRectMatrix C(3*nbeads, 3*nbeads); Mat3x3d I; I(0, 0) = 1.0; I(1, 1) = 1.0; @@ -97,15 +96,17 @@ namespace oopse { 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; + 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; - double constant = 8.0 * NumericConstant::PI * viscosity * rij; - Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant; + 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); + RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); Tij(0, 0) = constant; Tij(1, 1) = constant; Tij(2, 2) = constant; @@ -132,7 +133,7 @@ namespace oopse { //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); } @@ -144,18 +145,21 @@ namespace oopse { Xiott += Cij; Xiotr += U[i] * Cij; - //Xiorr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I; + // uncorrected here. Volume correction is added after we assemble Xiorr Xiorr += -U[i] * Cij * U[j]; } } + + // add the volume correction + Xiorr += (6.0 * viscosity * volume) * I; - const double convertConstant = 6.023; //convert poise.angstrom to amu/fs + const RealType convertConstant = 1.439326479e4; //converts Poise angstroms + // to kcal fs mol^-1 Angstrom^-1 + Xiott *= convertConstant; Xiotr *= convertConstant; Xiorr *= convertConstant; - - Mat3x3d tmp; Mat3x3d tmpInv; Vector3d tmpVec; @@ -185,8 +189,8 @@ namespace oopse { 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()); @@ -202,25 +206,32 @@ namespace oopse { Dr6x6.getSubMatrix(0, 3, Drrt); Dr6x6.getSubMatrix(3, 0, Drtr); Dr6x6.getSubMatrix(3, 3, Drrr); - double kt = OOPSEConstant::kB * temperature ; + RealType kt = OOPSEConstant::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 *= OOPSEConstant::kb * temperature; + //Xirtr *= OOPSEConstant::kb * temperature; + //Xirrr *= OOPSEConstant::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; @@ -246,11 +257,11 @@ namespace oopse { return true; } - bool ApproximationModel::calcHydroPropsAtCD(std::vector& beads, double viscosity, double temperature, HydroProps& cr) { + bool ApproximationModel::calcHydroPropsAtCD(std::vector& beads, RealType viscosity, RealType temperature, HydroProp* cd) { int nbeads = beads.size(); - DynamicRectMatrix B(3*nbeads, 3*nbeads); - DynamicRectMatrix C(3*nbeads, 3*nbeads); + DynamicRectMatrix B(3*nbeads, 3*nbeads); + DynamicRectMatrix C(3*nbeads, 3*nbeads); Mat3x3d I; I(0, 0) = 1.0; I(1, 1) = 1.0; @@ -261,15 +272,17 @@ namespace oopse { 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; + 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; - double constant = 8.0 * NumericConstant::PI * viscosity * rij; - Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant; + 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); + RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); Tij(0, 0) = constant; Tij(1, 1) = constant; Tij(2, 2) = constant; @@ -296,7 +309,7 @@ namespace oopse { //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); } @@ -308,17 +321,20 @@ namespace oopse { Xitt += Cij; Xitr += U[i] * Cij; - //Xirr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I; + // uncorrected here. Volume correction is added after we assemble Xiorr Xirr += -U[i] * Cij * U[j]; } } + // add the volume correction here: + Xirr += (6.0 * viscosity * volume) * I; - const double convertConstant = 6.023; //convert poise.angstrom to amu/fs + const RealType convertConstant = 1.439326479e4; //converts Poise angstroms + // to kcal fs mol^-1 Angstrom^-1 Xitt *= convertConstant; Xitr *= convertConstant; Xirr *= convertConstant; - double kt = OOPSEConstant::kB * temperature; + RealType kt = OOPSEConstant::kb * temperature; // in kcal mol^-1 Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O @@ -377,12 +393,12 @@ namespace oopse { 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; @@ -394,23 +410,29 @@ namespace oopse { //Xid /= OOPSEConstant::energyConvert; Xid *= OOPSEConstant::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; @@ -426,11 +448,11 @@ namespace oopse { 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;