| 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 | 
| 9 | 
> | 
 * 1. Redistributions of source code must retain the above copyright | 
| 10 | 
  | 
 *    notice, this list of conditions and the following disclaimer. | 
| 11 | 
  | 
 * | 
| 12 | 
< | 
 * 3. Redistributions in binary form must reproduce the above copyright | 
| 12 | 
> | 
 * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | 
  | 
 *    notice, this list of conditions and the following disclaimer in the | 
| 14 | 
  | 
 *    documentation and/or other materials provided with the | 
| 15 | 
  | 
 *    distribution. | 
| 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 | 
+ | 
 * | 
| 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 | 
+ | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).           | 
| 39 | 
+ | 
 * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | 
+ | 
 * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | 
  | 
 */ | 
| 42 | 
  | 
 | 
| 43 | 
  | 
#include "applications/hydrodynamics/ApproximationModel.hpp"  | 
| 44 | 
  | 
#include "math/LU.hpp" | 
| 45 | 
  | 
#include "math/DynamicRectMatrix.hpp" | 
| 46 | 
  | 
#include "math/SquareMatrix3.hpp" | 
| 47 | 
< | 
#include "utils/OOPSEConstant.hpp" | 
| 48 | 
< | 
#include "applications/hydrodynamics/Spheric.hpp" | 
| 49 | 
< | 
#include "applications/hydrodynamics/Ellipsoid.hpp" | 
| 47 | 
> | 
#include "utils/PhysicalConstants.hpp" | 
| 48 | 
> | 
#include "hydrodynamics/Sphere.hpp" | 
| 49 | 
> | 
#include "hydrodynamics/Ellipsoid.hpp" | 
| 50 | 
  | 
#include "applications/hydrodynamics/CompositeShape.hpp" | 
| 51 | 
  | 
#include "math/LU.hpp" | 
| 52 | 
< | 
namespace oopse { | 
| 52 | 
> | 
#include "utils/simError.h" | 
| 53 | 
> | 
namespace OpenMD { | 
| 54 | 
  | 
/** | 
| 55 | 
  | 
 * Reference: | 
| 56 | 
  | 
 * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles: | 
| 58 | 
  | 
 * Biophysical Journal, 75(6), 3044, 1999 | 
| 59 | 
  | 
 */ | 
| 60 | 
  | 
 | 
| 61 | 
< | 
ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){ | 
| 62 | 
< | 
/* | 
| 63 | 
< | 
    DynamicProperty::const_iterator iter; | 
| 64 | 
< | 
 | 
| 63 | 
< | 
    iter = extraParams.find("Viscosity"); | 
| 64 | 
< | 
    if (iter != extraParams.end()) { | 
| 65 | 
< | 
        boost::any param = iter->second; | 
| 66 | 
< | 
        viscosity = boost::any_cast<double>(param); | 
| 67 | 
< | 
    }else { | 
| 68 | 
< | 
        std::cout << "ApproximationModel Error\n" ; | 
| 69 | 
< | 
    } | 
| 70 | 
< | 
 | 
| 71 | 
< | 
    iter = extraParams.find("Temperature"); | 
| 72 | 
< | 
    if (iter != extraParams.end()) { | 
| 73 | 
< | 
        boost::any param = iter->second; | 
| 74 | 
< | 
        temperature = boost::any_cast<double>(param); | 
| 75 | 
< | 
    }else { | 
| 76 | 
< | 
        std::cout << "ApproximationModel Error\n" ; | 
| 77 | 
< | 
    }     | 
| 78 | 
< | 
*/ | 
| 79 | 
< | 
} | 
| 80 | 
< | 
 | 
| 81 | 
< | 
bool ApproximationModel::calcHydroProps(Spheric* spheric, double viscosity, double temperature) { | 
| 82 | 
< | 
    return internalCalcHydroProps(static_cast<Shape*>(spheric), viscosity, temperature); | 
| 83 | 
< | 
} | 
| 84 | 
< | 
 | 
| 85 | 
< | 
bool ApproximationModel::calcHydroProps(Ellipsoid* ellipsoid, double viscosity, double temperature) { | 
| 86 | 
< | 
    return internalCalcHydroProps(static_cast<Shape*>(ellipsoid), viscosity, temperature); | 
| 87 | 
< | 
} | 
| 88 | 
< | 
bool ApproximationModel::calcHydroProps(CompositeShape* compositeShape, double viscosity, double temperature) { | 
| 89 | 
< | 
    return internalCalcHydroProps(static_cast<Shape*>(compositeShape), viscosity, temperature); | 
| 90 | 
< | 
} | 
| 91 | 
< | 
 | 
| 92 | 
< | 
  | 
| 93 | 
< | 
bool ApproximationModel::internalCalcHydroProps(Shape* shape, double viscosity, double temperature) { | 
| 61 | 
> | 
  ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){     | 
| 62 | 
> | 
  } | 
| 63 | 
> | 
   | 
| 64 | 
> | 
  void ApproximationModel::init() { | 
| 65 | 
  | 
    if (!createBeads(beads_)) { | 
| 66 | 
< | 
        std::cout << "can not create beads" << std::endl; | 
| 67 | 
< | 
        return false; | 
| 66 | 
> | 
      sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n"); | 
| 67 | 
> | 
      painCave.isFatal = 1; | 
| 68 | 
> | 
      simError();         | 
| 69 | 
  | 
    } | 
| 70 | 
< | 
 | 
| 70 | 
> | 
     | 
| 71 | 
> | 
  } | 
| 72 | 
> | 
   | 
| 73 | 
> | 
  bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { | 
| 74 | 
> | 
     | 
| 75 | 
  | 
    bool ret = true; | 
| 76 | 
< | 
    HydroProps cr; | 
| 77 | 
< | 
    HydroProps cd; | 
| 76 | 
> | 
    HydroProp* cr = new HydroProp(); | 
| 77 | 
> | 
    HydroProp* cd = new HydroProp(); | 
| 78 | 
  | 
    calcHydroPropsAtCR(beads_, viscosity, temperature, cr); | 
| 79 | 
  | 
    calcHydroPropsAtCD(beads_, viscosity, temperature, cd); | 
| 80 | 
  | 
    setCR(cr); | 
| 81 | 
  | 
    setCD(cd); | 
| 106 | 
– | 
     | 
| 82 | 
  | 
    return true;     | 
| 83 | 
< | 
} | 
| 84 | 
< | 
 | 
| 85 | 
< | 
bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, double viscosity, double temperature, HydroProps& cr) { | 
| 86 | 
< | 
 | 
| 87 | 
< | 
    int nbeads = beads.size(); | 
| 88 | 
< | 
    DynamicRectMatrix<double> B(3*nbeads, 3*nbeads); | 
| 89 | 
< | 
    DynamicRectMatrix<double> C(3*nbeads, 3*nbeads); | 
| 83 | 
> | 
  } | 
| 84 | 
> | 
   | 
| 85 | 
> | 
  bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cr) { | 
| 86 | 
> | 
     | 
| 87 | 
> | 
    unsigned int nbeads = beads.size(); | 
| 88 | 
> | 
    DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); | 
| 89 | 
> | 
    DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); | 
| 90 | 
  | 
    Mat3x3d I; | 
| 91 | 
  | 
    I(0, 0) = 1.0; | 
| 92 | 
  | 
    I(1, 1) = 1.0; | 
| 93 | 
  | 
    I(2, 2) = 1.0; | 
| 94 | 
  | 
     | 
| 95 | 
  | 
    for (std::size_t i = 0; i < nbeads; ++i) { | 
| 96 | 
< | 
        for (std::size_t j = 0; j < nbeads; ++j) { | 
| 97 | 
< | 
            Mat3x3d Tij; | 
| 96 | 
> | 
      for (std::size_t j = 0; j < nbeads; ++j) { | 
| 97 | 
> | 
        Mat3x3d Tij; | 
| 98 | 
  | 
            if (i != j ) { | 
| 99 | 
< | 
                Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 100 | 
< | 
                double rij = Rij.length(); | 
| 101 | 
< | 
                double rij2 = rij * rij; | 
| 102 | 
< | 
                double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;                 | 
| 103 | 
< | 
                Mat3x3d tmpMat; | 
| 104 | 
< | 
                tmpMat = outProduct(Rij, Rij) / rij2; | 
| 105 | 
< | 
                double constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 106 | 
< | 
                Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant; | 
| 99 | 
> | 
              Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 100 | 
> | 
              RealType rij = Rij.length(); | 
| 101 | 
> | 
              RealType rij2 = rij * rij; | 
| 102 | 
> | 
              RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;                 | 
| 103 | 
> | 
              Mat3x3d tmpMat; | 
| 104 | 
> | 
              tmpMat = outProduct(Rij, Rij) / rij2; | 
| 105 | 
> | 
              RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 106 | 
> | 
              RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; | 
| 107 | 
> | 
              RealType tmp2 = 1.0 - sumSigma2OverRij2; | 
| 108 | 
> | 
              Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; | 
| 109 | 
  | 
            }else { | 
| 110 | 
< | 
                double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 111 | 
< | 
                Tij(0, 0) = constant; | 
| 112 | 
< | 
                Tij(1, 1) = constant; | 
| 113 | 
< | 
                Tij(2, 2) = constant; | 
| 110 | 
> | 
              RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 111 | 
> | 
              Tij(0, 0) = constant; | 
| 112 | 
> | 
              Tij(1, 1) = constant; | 
| 113 | 
> | 
              Tij(2, 2) = constant; | 
| 114 | 
  | 
            } | 
| 115 | 
  | 
            B.setSubMatrix(i*3, j*3, Tij); | 
| 116 | 
< | 
        } | 
| 116 | 
> | 
      } | 
| 117 | 
  | 
    } | 
| 118 | 
< | 
 | 
| 118 | 
> | 
     | 
| 119 | 
  | 
    //invert B Matrix | 
| 120 | 
  | 
    invertMatrix(B, C); | 
| 121 | 
  | 
     | 
| 122 | 
  | 
    //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) | 
| 123 | 
  | 
    std::vector<Mat3x3d> U; | 
| 124 | 
< | 
    for (int i = 0; i < nbeads; ++i) { | 
| 125 | 
< | 
        Mat3x3d currU; | 
| 126 | 
< | 
        currU.setupSkewMat(beads[i].pos); | 
| 127 | 
< | 
        U.push_back(currU); | 
| 124 | 
> | 
    for (unsigned int i = 0; i < nbeads; ++i) { | 
| 125 | 
> | 
      Mat3x3d currU; | 
| 126 | 
> | 
      currU.setupSkewMat(beads[i].pos); | 
| 127 | 
> | 
      U.push_back(currU); | 
| 128 | 
  | 
    } | 
| 129 | 
  | 
     | 
| 130 | 
  | 
    //calculate Xi matrix at arbitrary origin O | 
| 131 | 
  | 
    Mat3x3d Xiott; | 
| 132 | 
  | 
    Mat3x3d Xiorr; | 
| 133 | 
  | 
    Mat3x3d Xiotr; | 
| 134 | 
< | 
 | 
| 134 | 
> | 
     | 
| 135 | 
  | 
    //calculate the total volume | 
| 136 | 
< | 
 | 
| 137 | 
< | 
    double volume = 0.0; | 
| 136 | 
> | 
     | 
| 137 | 
> | 
    RealType volume = 0.0; | 
| 138 | 
  | 
    for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { | 
| 139 | 
< | 
        volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 139 | 
> | 
      volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 140 | 
  | 
    } | 
| 141 | 
< | 
         | 
| 141 | 
> | 
     | 
| 142 | 
  | 
    for (std::size_t i = 0; i < nbeads; ++i) { | 
| 143 | 
< | 
        for (std::size_t j = 0; j < nbeads; ++j) { | 
| 144 | 
< | 
            Mat3x3d Cij; | 
| 145 | 
< | 
            C.getSubMatrix(i*3, j*3, Cij); | 
| 146 | 
< | 
             | 
| 147 | 
< | 
            Xiott += Cij; | 
| 148 | 
< | 
            Xiotr += U[i] * Cij; | 
| 149 | 
< | 
            Xiorr += -U[i] * Cij * U[j] + (6 * viscosity * volume) * I;             | 
| 150 | 
< | 
        } | 
| 143 | 
> | 
      for (std::size_t j = 0; j < nbeads; ++j) { | 
| 144 | 
> | 
        Mat3x3d Cij; | 
| 145 | 
> | 
        C.getSubMatrix(i*3, j*3, Cij); | 
| 146 | 
> | 
         | 
| 147 | 
> | 
        Xiott += Cij; | 
| 148 | 
> | 
        Xiotr += U[i] * Cij; | 
| 149 | 
> | 
        // uncorrected here.  Volume correction is added after we assemble Xiorr | 
| 150 | 
> | 
        Xiorr += -U[i] * Cij * U[j];  | 
| 151 | 
> | 
      } | 
| 152 | 
  | 
    } | 
| 153 | 
  | 
 | 
| 154 | 
< | 
    const double convertConstant = 6.023; //convert poise.angstrom to amu/fs | 
| 155 | 
< | 
    Xiott *= convertConstant; | 
| 178 | 
< | 
    Xiotr *= convertConstant; | 
| 179 | 
< | 
    Xiorr *= convertConstant; | 
| 154 | 
> | 
    // add the volume correction | 
| 155 | 
> | 
    Xiorr += (RealType(6.0) * viscosity * volume) * I;     | 
| 156 | 
  | 
     | 
| 157 | 
< | 
 | 
| 157 | 
> | 
    Xiott *= PhysicalConstants::viscoConvert; | 
| 158 | 
> | 
    Xiotr *= PhysicalConstants::viscoConvert; | 
| 159 | 
> | 
    Xiorr *= PhysicalConstants::viscoConvert; | 
| 160 | 
  | 
     | 
| 161 | 
  | 
    Mat3x3d tmp; | 
| 162 | 
  | 
    Mat3x3d tmpInv; | 
| 187 | 
  | 
    Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose(); | 
| 188 | 
  | 
     | 
| 189 | 
  | 
 | 
| 190 | 
< | 
    SquareMatrix<double,6> Xir6x6; | 
| 191 | 
< | 
    SquareMatrix<double,6> Dr6x6; | 
| 190 | 
> | 
    SquareMatrix<RealType,6> Xir6x6; | 
| 191 | 
> | 
    SquareMatrix<RealType,6> Dr6x6; | 
| 192 | 
  | 
 | 
| 193 | 
  | 
    Xir6x6.setSubMatrix(0, 0, Xirtt); | 
| 194 | 
  | 
    Xir6x6.setSubMatrix(0, 3, Xirtr.transpose()); | 
| 204 | 
  | 
    Dr6x6.getSubMatrix(0, 3, Drrt); | 
| 205 | 
  | 
    Dr6x6.getSubMatrix(3, 0, Drtr); | 
| 206 | 
  | 
    Dr6x6.getSubMatrix(3, 3, Drrr); | 
| 207 | 
< | 
    double kt = OOPSEConstant::kB * temperature ; | 
| 207 | 
> | 
    RealType kt = PhysicalConstants::kb * temperature ; // in kcal mol^-1 | 
| 208 | 
  | 
    Drtt *= kt; | 
| 209 | 
  | 
    Drrt *= kt; | 
| 210 | 
  | 
    Drtr *= kt; | 
| 211 | 
  | 
    Drrr *= kt; | 
| 212 | 
< | 
    Xirtt *= OOPSEConstant::kb * temperature; | 
| 213 | 
< | 
    Xirtr *= OOPSEConstant::kb * temperature; | 
| 214 | 
< | 
    Xirrr *= OOPSEConstant::kb * temperature; | 
| 212 | 
> | 
    //Xirtt *= PhysicalConstants::kb * temperature; | 
| 213 | 
> | 
    //Xirtr *= PhysicalConstants::kb * temperature; | 
| 214 | 
> | 
    //Xirrr *= PhysicalConstants::kb * temperature; | 
| 215 | 
  | 
     | 
| 216 | 
+ | 
    Mat6x6d Xi, D; | 
| 217 | 
  | 
 | 
| 218 | 
< | 
    cr.center = ror; | 
| 219 | 
< | 
    cr.Xi.setSubMatrix(0, 0, Xirtt); | 
| 220 | 
< | 
    cr.Xi.setSubMatrix(0, 3, Xirtr); | 
| 221 | 
< | 
    cr.Xi.setSubMatrix(3, 0, Xirtr); | 
| 222 | 
< | 
    cr.Xi.setSubMatrix(3, 3, Xirrr); | 
| 223 | 
< | 
    cr.D.setSubMatrix(0, 0, Drtt); | 
| 224 | 
< | 
    cr.D.setSubMatrix(0, 3, Drrt); | 
| 225 | 
< | 
    cr.D.setSubMatrix(3, 0, Drtr); | 
| 226 | 
< | 
    cr.D.setSubMatrix(3, 3, Drrr);     | 
| 218 | 
> | 
    cr->setCOR(ror); | 
| 219 | 
> | 
 | 
| 220 | 
> | 
    Xi.setSubMatrix(0, 0, Xirtt); | 
| 221 | 
> | 
    Xi.setSubMatrix(0, 3, Xirtr); | 
| 222 | 
> | 
    Xi.setSubMatrix(3, 0, Xirtr); | 
| 223 | 
> | 
    Xi.setSubMatrix(3, 3, Xirrr); | 
| 224 | 
> | 
 | 
| 225 | 
> | 
    cr->setXi(Xi); | 
| 226 | 
> | 
 | 
| 227 | 
> | 
    D.setSubMatrix(0, 0, Drtt); | 
| 228 | 
> | 
    D.setSubMatrix(0, 3, Drrt); | 
| 229 | 
> | 
    D.setSubMatrix(3, 0, Drtr); | 
| 230 | 
> | 
    D.setSubMatrix(3, 3, Drrr);     | 
| 231 | 
> | 
 | 
| 232 | 
> | 
    cr->setD(D); | 
| 233 | 
  | 
     | 
| 234 | 
  | 
    std::cout << "-----------------------------------------\n"; | 
| 235 | 
  | 
    std::cout << "center of resistance :" << std::endl; | 
| 254 | 
  | 
 | 
| 255 | 
  | 
    return true; | 
| 256 | 
  | 
} | 
| 257 | 
< | 
 | 
| 258 | 
< | 
bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, double viscosity, double temperature, HydroProps& cr) { | 
| 259 | 
< | 
 | 
| 260 | 
< | 
    int nbeads = beads.size(); | 
| 261 | 
< | 
    DynamicRectMatrix<double> B(3*nbeads, 3*nbeads); | 
| 262 | 
< | 
    DynamicRectMatrix<double> C(3*nbeads, 3*nbeads); | 
| 257 | 
> | 
   | 
| 258 | 
> | 
  bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cd) { | 
| 259 | 
> | 
     | 
| 260 | 
> | 
    unsigned int nbeads = beads.size(); | 
| 261 | 
> | 
    DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); | 
| 262 | 
> | 
    DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); | 
| 263 | 
  | 
    Mat3x3d I; | 
| 264 | 
  | 
    I(0, 0) = 1.0; | 
| 265 | 
  | 
    I(1, 1) = 1.0; | 
| 266 | 
  | 
    I(2, 2) = 1.0; | 
| 267 | 
  | 
     | 
| 268 | 
  | 
    for (std::size_t i = 0; i < nbeads; ++i) { | 
| 269 | 
< | 
        for (std::size_t j = 0; j < nbeads; ++j) { | 
| 270 | 
< | 
            Mat3x3d Tij; | 
| 271 | 
< | 
            if (i != j ) { | 
| 272 | 
< | 
                Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 273 | 
< | 
                double rij = Rij.length(); | 
| 274 | 
< | 
                double rij2 = rij * rij; | 
| 275 | 
< | 
                double sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;                 | 
| 276 | 
< | 
                Mat3x3d tmpMat; | 
| 277 | 
< | 
                tmpMat = outProduct(Rij, Rij) / rij2; | 
| 278 | 
< | 
                double constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 279 | 
< | 
                Tij = ((1.0 + sumSigma2OverRij2/3.0) * I + (1.0 - sumSigma2OverRij2) * tmpMat ) / constant; | 
| 280 | 
< | 
            }else { | 
| 281 | 
< | 
                double constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 282 | 
< | 
                Tij(0, 0) = constant; | 
| 283 | 
< | 
                Tij(1, 1) = constant; | 
| 284 | 
< | 
                Tij(2, 2) = constant; | 
| 285 | 
< | 
            } | 
| 286 | 
< | 
            B.setSubMatrix(i*3, j*3, Tij); | 
| 269 | 
> | 
      for (std::size_t j = 0; j < nbeads; ++j) { | 
| 270 | 
> | 
        Mat3x3d Tij; | 
| 271 | 
> | 
        if (i != j ) { | 
| 272 | 
> | 
          Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 273 | 
> | 
          RealType rij = Rij.length(); | 
| 274 | 
> | 
          RealType rij2 = rij * rij; | 
| 275 | 
> | 
          RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2;                 | 
| 276 | 
> | 
          Mat3x3d tmpMat; | 
| 277 | 
> | 
          tmpMat = outProduct(Rij, Rij) / rij2; | 
| 278 | 
> | 
          RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 279 | 
> | 
          RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; | 
| 280 | 
> | 
          RealType tmp2 = 1.0 - sumSigma2OverRij2; | 
| 281 | 
> | 
          Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; | 
| 282 | 
> | 
        }else { | 
| 283 | 
> | 
          RealType 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 | 
< | 
 | 
| 291 | 
> | 
     | 
| 292 | 
  | 
    //invert B Matrix | 
| 293 | 
  | 
    invertMatrix(B, C); | 
| 294 | 
< | 
 | 
| 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); | 
| 297 | 
> | 
    for (unsigned 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 | 
| 307 | 
  | 
 | 
| 308 | 
  | 
    //calculate the total volume | 
| 309 | 
  | 
 | 
| 310 | 
< | 
    double volume = 0.0; | 
| 310 | 
> | 
    RealType 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); | 
| 312 | 
> | 
      volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 313 | 
  | 
    } | 
| 314 | 
< | 
         | 
| 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); | 
| 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 | 
< | 
        } | 
| 320 | 
> | 
        Xitt += Cij; | 
| 321 | 
> | 
        Xitr += U[i] * Cij; | 
| 322 | 
> | 
        // uncorrected here.  Volume correction is added after we assemble Xiorr | 
| 323 | 
> | 
        Xirr += -U[i] * Cij * U[j]; | 
| 324 | 
> | 
      } | 
| 325 | 
  | 
    } | 
| 326 | 
< | 
 | 
| 327 | 
< | 
    const double convertConstant = 6.023; //convert poise.angstrom to amu/fs | 
| 328 | 
< | 
    Xitt *= convertConstant; | 
| 329 | 
< | 
    Xitr *= convertConstant; | 
| 330 | 
< | 
    Xirr *= convertConstant; | 
| 331 | 
< | 
 | 
| 332 | 
< | 
    double kt = OOPSEConstant::kB * temperature; | 
| 333 | 
< | 
 | 
| 326 | 
> | 
    // add the volume correction here: | 
| 327 | 
> | 
    Xirr += (RealType(6.0) * viscosity * volume) * I;     | 
| 328 | 
> | 
     | 
| 329 | 
> | 
    Xitt *= PhysicalConstants::viscoConvert; | 
| 330 | 
> | 
    Xitr *= PhysicalConstants::viscoConvert; | 
| 331 | 
> | 
    Xirr *= PhysicalConstants::viscoConvert; | 
| 332 | 
> | 
     | 
| 333 | 
> | 
    RealType kt = PhysicalConstants::kb * temperature; // in kcal mol^-1 | 
| 334 | 
> | 
     | 
| 335 | 
  | 
    Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O | 
| 336 | 
  | 
    Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O | 
| 337 | 
  | 
    Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O | 
| 338 | 
< | 
 | 
| 338 | 
> | 
     | 
| 339 | 
  | 
    const static Mat3x3d zeroMat(0.0); | 
| 340 | 
  | 
     | 
| 341 | 
  | 
    Mat3x3d XittInv(0.0); | 
| 389 | 
  | 
    Ddrr = Dorr; | 
| 390 | 
  | 
    Ddtr = Dotr + Dorr * Uod; | 
| 391 | 
  | 
 | 
| 392 | 
< | 
    SquareMatrix<double, 6> Dd; | 
| 392 | 
> | 
    SquareMatrix<RealType, 6> Dd; | 
| 393 | 
  | 
    Dd.setSubMatrix(0, 0, Ddtt); | 
| 394 | 
  | 
    Dd.setSubMatrix(0, 3, Ddtr.transpose()); | 
| 395 | 
  | 
    Dd.setSubMatrix(3, 0, Ddtr); | 
| 396 | 
  | 
    Dd.setSubMatrix(3, 3, Ddrr);     | 
| 397 | 
< | 
    SquareMatrix<double, 6> Xid; | 
| 397 | 
> | 
    SquareMatrix<RealType, 6> Xid; | 
| 398 | 
  | 
    Ddtt *= kt; | 
| 399 | 
  | 
    Ddtr *=kt; | 
| 400 | 
  | 
    Ddrr *= kt; | 
| 403 | 
  | 
 | 
| 404 | 
  | 
 | 
| 405 | 
  | 
    //Xidtt in units of kcal*fs*mol^-1*Ang^-2 | 
| 406 | 
< | 
    //Xid /= OOPSEConstant::energyConvert; | 
| 407 | 
< | 
    Xid *= OOPSEConstant::kb * temperature; | 
| 406 | 
> | 
    //Xid /= PhysicalConstants::energyConvert; | 
| 407 | 
> | 
    Xid *= PhysicalConstants::kb * temperature; | 
| 408 | 
  | 
 | 
| 409 | 
< | 
    cr.center = rod; | 
| 421 | 
< | 
    cr.D.setSubMatrix(0, 0, Ddtt); | 
| 422 | 
< | 
    cr.D.setSubMatrix(0, 3, Ddtr); | 
| 423 | 
< | 
    cr.D.setSubMatrix(3, 0, Ddtr); | 
| 424 | 
< | 
    cr.D.setSubMatrix(3, 3, Ddrr); | 
| 425 | 
< | 
    cr.Xi = Xid; | 
| 409 | 
> | 
    Mat6x6d Xi, D; | 
| 410 | 
  | 
 | 
| 411 | 
+ | 
    cd->setCOR(rod); | 
| 412 | 
+ | 
 | 
| 413 | 
+ | 
    cd->setXi(Xid); | 
| 414 | 
+ | 
 | 
| 415 | 
+ | 
    D.setSubMatrix(0, 0, Ddtt); | 
| 416 | 
+ | 
    D.setSubMatrix(0, 3, Ddtr); | 
| 417 | 
+ | 
    D.setSubMatrix(3, 0, Ddtr); | 
| 418 | 
+ | 
    D.setSubMatrix(3, 3, Ddrr); | 
| 419 | 
+ | 
 | 
| 420 | 
+ | 
    cd->setD(D); | 
| 421 | 
+ | 
 | 
| 422 | 
  | 
    std::cout << "viscosity = " << viscosity << std::endl; | 
| 423 | 
  | 
    std::cout << "temperature = " << temperature << std::endl; | 
| 424 | 
  | 
    std::cout << "center of diffusion :" << std::endl; | 
| 425 | 
  | 
    std::cout << rod << std::endl; | 
| 426 | 
  | 
    std::cout << "diffusion tensor at center of diffusion " << std::endl; | 
| 427 | 
< | 
    std::cout << "translation(A^2/fs) :" << std::endl; | 
| 427 | 
> | 
    std::cout << "translation(A^2 / fs) :" << std::endl; | 
| 428 | 
  | 
    std::cout << Ddtt << std::endl; | 
| 429 | 
< | 
    std::cout << "translation-rotation(A^3/fs):" << std::endl; | 
| 429 | 
> | 
    std::cout << "translation-rotation(A / fs):" << std::endl; | 
| 430 | 
  | 
    std::cout << Ddtr << std::endl; | 
| 431 | 
< | 
    std::cout << "rotation(A^4/fs):" << std::endl; | 
| 431 | 
> | 
    std::cout << "rotation(fs^-1):" << std::endl; | 
| 432 | 
  | 
    std::cout << Ddrr << std::endl; | 
| 433 | 
  | 
 | 
| 434 | 
  | 
    std::cout << "resistance tensor at center of diffusion " << std::endl; | 
| 444 | 
  | 
    Xid.getSubMatrix(3, 3, Xidrr); | 
| 445 | 
  | 
 | 
| 446 | 
  | 
    std::cout << Xidtt << std::endl; | 
| 447 | 
< | 
    std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-3):" << std::endl; | 
| 447 | 
> | 
    std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-1):" << std::endl; | 
| 448 | 
  | 
    std::cout << Xidrt << std::endl; | 
| 449 | 
< | 
    std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-3):" << std::endl; | 
| 449 | 
> | 
    std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-1):" << std::endl; | 
| 450 | 
  | 
    std::cout << Xidtr << std::endl; | 
| 451 | 
< | 
    std::cout << "rotation(kcal*fs*mol^-1*Ang^-4):" << std::endl; | 
| 451 | 
> | 
    std::cout << "rotation(kcal*fs*mol^-1):" << std::endl; | 
| 452 | 
  | 
    std::cout << Xidrr << std::endl; | 
| 453 | 
  | 
 | 
| 454 | 
  | 
    return true; | 
| 455 | 
< | 
       | 
| 456 | 
< | 
} | 
| 455 | 
> | 
     | 
| 456 | 
> | 
  } | 
| 457 | 
  | 
 | 
| 458 | 
< | 
/* | 
| 464 | 
< | 
void ApproximationModel::writeBeads(std::ostream& os) { | 
| 458 | 
> | 
  void ApproximationModel::writeBeads(std::ostream& os) { | 
| 459 | 
  | 
    std::vector<BeadParam>::iterator iter; | 
| 460 | 
  | 
    os << beads_.size() << std::endl; | 
| 461 | 
  | 
    os << "Generated by Hydro" << std::endl; | 
| 462 | 
  | 
    for (iter = beads_.begin(); iter != beads_.end(); ++iter) { | 
| 463 | 
< | 
        os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; | 
| 463 | 
> | 
      os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; | 
| 464 | 
  | 
    } | 
| 465 | 
< | 
 | 
| 465 | 
> | 
     | 
| 466 | 
> | 
  }     | 
| 467 | 
  | 
} | 
| 473 | 
– | 
*/ | 
| 474 | 
– | 
 | 
| 475 | 
– | 
 | 
| 476 | 
– | 
} |