ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/integrators/LDForceManager.cpp
Revision: 2644
Committed: Mon Mar 20 19:12:14 2006 UTC (18 years, 3 months ago) by tim
File size: 10704 byte(s)
Log Message:
Verify the correctness of Ellipsoid's hydrodynamics properties

File Contents

# User Rev Content
1 tim 2611 /*
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     * 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
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41     #include <fstream>
42     #include "integrators/LDForceManager.hpp"
43     #include "math/CholeskyDecomposition.hpp"
44 tim 2632 #include "utils/OOPSEConstant.hpp"
45 tim 2611 namespace oopse {
46    
47     LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){
48     Globals* simParams = info->getSimParams();
49     std::map<std::string, HydroProp> hydroPropMap;
50     if (simParams->haveHydroPropFile()) {
51     hydroPropMap = parseFrictionFile(simParams->getHydroPropFile());
52     } else {
53     //error
54     }
55    
56     SimInfo::MoleculeIterator i;
57     Molecule::IntegrableObjectIterator j;
58     Molecule* mol;
59     StuntDouble* integrableObject;
60     for (mol = info->beginMolecule(i); mol != NULL; mol = info->nextMolecule(i)) {
61     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
62     integrableObject = mol->nextIntegrableObject(j)) {
63     std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
64     if (iter != hydroPropMap.end()) {
65     hydroProps_.push_back(iter->second);
66     } else {
67     //error
68     }
69    
70     }
71     }
72 tim 2632 variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt();
73 tim 2611 }
74     std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) {
75     std::map<std::string, HydroProp> props;
76     std::ifstream ifs(filename.c_str());
77     if (ifs.is_open()) {
78    
79     }
80    
81     const unsigned int BufferSize = 65535;
82     char buffer[BufferSize];
83     while (ifs.getline(buffer, BufferSize)) {
84     StringTokenizer tokenizer(buffer);
85     HydroProp currProp;
86 tim 2634 if (tokenizer.countTokens() >= 40) {
87 tim 2611 std::string atomName = tokenizer.nextToken();
88 tim 2634 currProp.cor[0] = tokenizer.nextTokenAsDouble();
89     currProp.cor[1] = tokenizer.nextTokenAsDouble();
90     currProp.cor[2] = tokenizer.nextTokenAsDouble();
91 tim 2644
92 tim 2634 currProp.Xirtt(0,0) = tokenizer.nextTokenAsDouble();
93     currProp.Xirtt(0,1) = tokenizer.nextTokenAsDouble();
94     currProp.Xirtt(0,2) = tokenizer.nextTokenAsDouble();
95     currProp.Xirtt(1,0) = tokenizer.nextTokenAsDouble();
96     currProp.Xirtt(1,1) = tokenizer.nextTokenAsDouble();
97     currProp.Xirtt(1,2) = tokenizer.nextTokenAsDouble();
98     currProp.Xirtt(2,0) = tokenizer.nextTokenAsDouble();
99     currProp.Xirtt(2,1) = tokenizer.nextTokenAsDouble();
100     currProp.Xirtt(2,2) = tokenizer.nextTokenAsDouble();
101 tim 2611
102 tim 2634 currProp.Xirrt(0,0) = tokenizer.nextTokenAsDouble();
103     currProp.Xirrt(0,1) = tokenizer.nextTokenAsDouble();
104     currProp.Xirrt(0,2) = tokenizer.nextTokenAsDouble();
105     currProp.Xirrt(1,0) = tokenizer.nextTokenAsDouble();
106     currProp.Xirrt(1,1) = tokenizer.nextTokenAsDouble();
107     currProp.Xirrt(1,2) = tokenizer.nextTokenAsDouble();
108     currProp.Xirrt(2,0) = tokenizer.nextTokenAsDouble();
109     currProp.Xirrt(2,1) = tokenizer.nextTokenAsDouble();
110     currProp.Xirrt(2,2) = tokenizer.nextTokenAsDouble();
111    
112     currProp.Xirtr(0,0) = tokenizer.nextTokenAsDouble();
113     currProp.Xirtr(0,1) = tokenizer.nextTokenAsDouble();
114     currProp.Xirtr(0,2) = tokenizer.nextTokenAsDouble();
115     currProp.Xirtr(1,0) = tokenizer.nextTokenAsDouble();
116     currProp.Xirtr(1,1) = tokenizer.nextTokenAsDouble();
117     currProp.Xirtr(1,2) = tokenizer.nextTokenAsDouble();
118     currProp.Xirtr(2,0) = tokenizer.nextTokenAsDouble();
119     currProp.Xirtr(2,1) = tokenizer.nextTokenAsDouble();
120     currProp.Xirtr(2,2) = tokenizer.nextTokenAsDouble();
121    
122     currProp.Xirrr(0,0) = tokenizer.nextTokenAsDouble();
123     currProp.Xirrr(0,1) = tokenizer.nextTokenAsDouble();
124     currProp.Xirrr(0,2) = tokenizer.nextTokenAsDouble();
125     currProp.Xirrr(1,0) = tokenizer.nextTokenAsDouble();
126     currProp.Xirrr(1,1) = tokenizer.nextTokenAsDouble();
127     currProp.Xirrr(1,2) = tokenizer.nextTokenAsDouble();
128     currProp.Xirrr(2,0) = tokenizer.nextTokenAsDouble();
129     currProp.Xirrr(2,1) = tokenizer.nextTokenAsDouble();
130     currProp.Xirrr(2,2) = tokenizer.nextTokenAsDouble();
131    
132     SquareMatrix<double, 6> Xir;
133     Xir.setSubMatrix(0, 0, currProp.Xirtt);
134     Xir.setSubMatrix(0, 3, currProp.Xirrt);
135     Xir.setSubMatrix(3, 0, currProp.Xirtr);
136     Xir.setSubMatrix(3, 3, currProp.Xirrr);
137     CholeskyDecomposition(Xir, currProp.S);
138    
139 tim 2611 props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp));
140     }
141     }
142    
143     return props;
144     }
145    
146     void LDForceManager::postCalculation() {
147     SimInfo::MoleculeIterator i;
148     Molecule::IntegrableObjectIterator j;
149     Molecule* mol;
150     StuntDouble* integrableObject;
151     Vector3d vel;
152     Vector3d pos;
153     Vector3d frc;
154     Mat3x3d A;
155 tim 2632 Mat3x3d Atrans;
156 tim 2611 Vector3d Tb;
157     Vector3d ji;
158     double mass;
159     unsigned int index = 0;
160     for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
161     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
162     integrableObject = mol->nextIntegrableObject(j)) {
163    
164     vel =integrableObject->getVel();
165     if (integrableObject->isDirectional()){
166     //calculate angular velocity in lab frame
167     Mat3x3d I = integrableObject->getI();
168     Vector3d angMom = integrableObject->getJ();
169     Vector3d omega;
170    
171     if (integrableObject->isLinear()) {
172     int linearAxis = integrableObject->linearAxis();
173     int l = (linearAxis +1 )%3;
174     int m = (linearAxis +2 )%3;
175     omega[l] = angMom[l] /I(l, l);
176     omega[m] = angMom[m] /I(m, m);
177    
178     } else {
179     omega[0] = angMom[0] /I(0, 0);
180     omega[1] = angMom[1] /I(1, 1);
181     omega[2] = angMom[2] /I(2, 2);
182     }
183    
184 tim 2634 //apply friction force and torque at center of resistance
185 tim 2611 A = integrableObject->getA();
186 tim 2632 Atrans = A.transpose();
187 tim 2634 Vector3d rcr = Atrans * hydroProps_[index].cor;
188     Vector3d vcdLab = vel + cross(omega, rcr);
189     Vector3d vcdBody = A* vcdLab;
190     Vector3d frictionForceBody = -(hydroProps_[index].Xirtt * vcdBody + hydroProps_[index].Xirrt * omega);
191     Vector3d frictionForceLab = Atrans*frictionForceBody;
192     integrableObject->addFrc(frictionForceLab);
193     Vector3d frictionTorqueBody = - (hydroProps_[index].Xirtr * vcdBody + hydroProps_[index].Xirrr * omega);
194     Vector3d frictionTorqueLab = Atrans*frictionTorqueBody;
195     integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab));
196    
197     //apply random force and torque at center of resistance
198     Vector3d randomForceBody;
199     Vector3d randomTorqueBody;
200     genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
201     Vector3d randomForceLab = Atrans*randomForceBody;
202     Vector3d randomTorqueLab = Atrans* randomTorqueBody;
203     integrableObject->addFrc(randomForceLab);
204     integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab ));
205    
206 tim 2611 } else {
207     //spheric atom
208 tim 2634 Vector3d frictionForce = -(hydroProps_[index].Xirtt *vel);
209 tim 2611 Vector3d randomForce;
210     Vector3d randomTorque;
211     genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
212 tim 2632
213 tim 2611 integrableObject->addFrc(frictionForce+randomForce);
214     }
215    
216     ++index;
217    
218     }
219     }
220    
221     ForceManager::postCalculation();
222    
223    
224    
225     }
226    
227     void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, double variance) {
228 tim 2632
229 tim 2634
230 tim 2632 Vector<double, 6> Z;
231     Vector<double, 6> generalForce;
232    
233    
234 tim 2611 Z[0] = randNumGen_.randNorm(0, variance);
235     Z[1] = randNumGen_.randNorm(0, variance);
236     Z[2] = randNumGen_.randNorm(0, variance);
237     Z[3] = randNumGen_.randNorm(0, variance);
238     Z[4] = randNumGen_.randNorm(0, variance);
239     Z[5] = randNumGen_.randNorm(0, variance);
240 tim 2632
241    
242 tim 2634 generalForce = hydroProps_[index].S*Z;
243 tim 2632
244 tim 2611 force[0] = generalForce[0];
245     force[1] = generalForce[1];
246     force[2] = generalForce[2];
247     torque[0] = generalForce[3];
248     torque[1] = generalForce[4];
249     torque[2] = generalForce[5];
250    
251     }
252    
253     }

Properties

Name Value
svn:executable *