ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/LDForceManager.cpp
Revision: 2632
Committed: Thu Mar 16 22:50:48 2006 UTC (18 years, 4 months ago) by tim
File size: 13095 byte(s)
Log Message:
LagevinDynamics is working?

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     if (tokenizer.countTokens() >= 67) {
87     std::string atomName = tokenizer.nextToken();
88     currProp.cod[0] = tokenizer.nextTokenAsDouble();
89     currProp.cod[1] = tokenizer.nextTokenAsDouble();
90     currProp.cod[2] = tokenizer.nextTokenAsDouble();
91    
92     currProp.Ddtt(0,0) = tokenizer.nextTokenAsDouble();
93     currProp.Ddtt(0,1) = tokenizer.nextTokenAsDouble();
94     currProp.Ddtt(0,2) = tokenizer.nextTokenAsDouble();
95     currProp.Ddtt(1,0) = tokenizer.nextTokenAsDouble();
96     currProp.Ddtt(1,1) = tokenizer.nextTokenAsDouble();
97     currProp.Ddtt(1,2) = tokenizer.nextTokenAsDouble();
98     currProp.Ddtt(2,0) = tokenizer.nextTokenAsDouble();
99     currProp.Ddtt(2,1) = tokenizer.nextTokenAsDouble();
100     currProp.Ddtt(2,2) = tokenizer.nextTokenAsDouble();
101    
102     currProp.Ddtr(0,0) = tokenizer.nextTokenAsDouble();
103     currProp.Ddtr(0,1) = tokenizer.nextTokenAsDouble();
104     currProp.Ddtr(0,2) = tokenizer.nextTokenAsDouble();
105     currProp.Ddtr(1,0) = tokenizer.nextTokenAsDouble();
106     currProp.Ddtr(1,1) = tokenizer.nextTokenAsDouble();
107     currProp.Ddtr(1,2) = tokenizer.nextTokenAsDouble();
108     currProp.Ddtr(2,0) = tokenizer.nextTokenAsDouble();
109     currProp.Ddtr(2,1) = tokenizer.nextTokenAsDouble();
110     currProp.Ddtr(2,2) = tokenizer.nextTokenAsDouble();
111    
112     currProp.Ddrr(0,0) = tokenizer.nextTokenAsDouble();
113     currProp.Ddrr(0,1) = tokenizer.nextTokenAsDouble();
114     currProp.Ddrr(0,2) = tokenizer.nextTokenAsDouble();
115     currProp.Ddrr(1,0) = tokenizer.nextTokenAsDouble();
116     currProp.Ddrr(1,1) = tokenizer.nextTokenAsDouble();
117     currProp.Ddrr(1,2) = tokenizer.nextTokenAsDouble();
118     currProp.Ddrr(2,0) = tokenizer.nextTokenAsDouble();
119     currProp.Ddrr(2,1) = tokenizer.nextTokenAsDouble();
120     currProp.Ddrr(2,2) = tokenizer.nextTokenAsDouble();
121    
122     currProp.Xidtt(0,0) = tokenizer.nextTokenAsDouble();
123     currProp.Xidtt(0,1) = tokenizer.nextTokenAsDouble();
124     currProp.Xidtt(0,2) = tokenizer.nextTokenAsDouble();
125     currProp.Xidtt(1,0) = tokenizer.nextTokenAsDouble();
126     currProp.Xidtt(1,1) = tokenizer.nextTokenAsDouble();
127     currProp.Xidtt(1,2) = tokenizer.nextTokenAsDouble();
128     currProp.Xidtt(2,0) = tokenizer.nextTokenAsDouble();
129     currProp.Xidtt(2,1) = tokenizer.nextTokenAsDouble();
130     currProp.Xidtt(2,2) = tokenizer.nextTokenAsDouble();
131    
132     currProp.Xidrt(0,0) = tokenizer.nextTokenAsDouble();
133     currProp.Xidrt(0,1) = tokenizer.nextTokenAsDouble();
134     currProp.Xidrt(0,2) = tokenizer.nextTokenAsDouble();
135     currProp.Xidrt(1,0) = tokenizer.nextTokenAsDouble();
136     currProp.Xidrt(1,1) = tokenizer.nextTokenAsDouble();
137     currProp.Xidrt(1,2) = tokenizer.nextTokenAsDouble();
138     currProp.Xidrt(2,0) = tokenizer.nextTokenAsDouble();
139     currProp.Xidrt(2,1) = tokenizer.nextTokenAsDouble();
140     currProp.Xidrt(2,2) = tokenizer.nextTokenAsDouble();
141    
142     currProp.Xidtr(0,0) = tokenizer.nextTokenAsDouble();
143     currProp.Xidtr(0,1) = tokenizer.nextTokenAsDouble();
144     currProp.Xidtr(0,2) = tokenizer.nextTokenAsDouble();
145     currProp.Xidtr(1,0) = tokenizer.nextTokenAsDouble();
146     currProp.Xidtr(1,1) = tokenizer.nextTokenAsDouble();
147     currProp.Xidtr(1,2) = tokenizer.nextTokenAsDouble();
148     currProp.Xidtr(2,0) = tokenizer.nextTokenAsDouble();
149     currProp.Xidtr(2,1) = tokenizer.nextTokenAsDouble();
150     currProp.Xidtr(2,2) = tokenizer.nextTokenAsDouble();
151    
152     currProp.Xidrr(0,0) = tokenizer.nextTokenAsDouble();
153     currProp.Xidrr(0,1) = tokenizer.nextTokenAsDouble();
154     currProp.Xidrr(0,2) = tokenizer.nextTokenAsDouble();
155     currProp.Xidrr(1,0) = tokenizer.nextTokenAsDouble();
156     currProp.Xidrr(1,1) = tokenizer.nextTokenAsDouble();
157     currProp.Xidrr(1,2) = tokenizer.nextTokenAsDouble();
158     currProp.Xidrr(2,0) = tokenizer.nextTokenAsDouble();
159     currProp.Xidrr(2,1) = tokenizer.nextTokenAsDouble();
160     currProp.Xidrr(2,2) = tokenizer.nextTokenAsDouble();
161     props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp));
162     }
163     }
164    
165     return props;
166     }
167    
168     void LDForceManager::postCalculation() {
169     SimInfo::MoleculeIterator i;
170     Molecule::IntegrableObjectIterator j;
171     Molecule* mol;
172     StuntDouble* integrableObject;
173     Vector3d vel;
174     Vector3d pos;
175     Vector3d frc;
176     Mat3x3d A;
177 tim 2632 Mat3x3d Atrans;
178 tim 2611 Vector3d Tb;
179     Vector3d ji;
180     double mass;
181     unsigned int index = 0;
182     for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
183     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
184     integrableObject = mol->nextIntegrableObject(j)) {
185    
186     vel =integrableObject->getVel();
187     if (integrableObject->isDirectional()){
188     //calculate angular velocity in lab frame
189     Mat3x3d I = integrableObject->getI();
190     Vector3d angMom = integrableObject->getJ();
191     Vector3d omega;
192    
193     if (integrableObject->isLinear()) {
194     int linearAxis = integrableObject->linearAxis();
195     int l = (linearAxis +1 )%3;
196     int m = (linearAxis +2 )%3;
197     omega[l] = angMom[l] /I(l, l);
198     omega[m] = angMom[m] /I(m, m);
199    
200     } else {
201     omega[0] = angMom[0] /I(0, 0);
202     omega[1] = angMom[1] /I(1, 1);
203     omega[2] = angMom[2] /I(2, 2);
204     }
205    
206     //apply friction force and torque at center of diffusion
207     A = integrableObject->getA();
208 tim 2632 Atrans = A.transpose();
209     Vector3d rcd = Atrans * hydroProps_[index].cod;
210 tim 2611 Vector3d vcd = vel + cross(omega, rcd);
211 tim 2632 vcd = A* vcd;
212 tim 2611 Vector3d frictionForce = -(hydroProps_[index].Xidtt * vcd + hydroProps_[index].Xidrt * omega);
213 tim 2632 frictionForce = Atrans*frictionForce;
214 tim 2611 integrableObject->addFrc(frictionForce);
215     Vector3d frictionTorque = - (hydroProps_[index].Xidtr * vcd + hydroProps_[index].Xidrr * omega);
216 tim 2632 frictionTorque = Atrans*frictionTorque;
217     integrableObject->addTrq(frictionTorque+ cross(rcd, frictionForce));
218 tim 2611
219     //apply random force and torque at center of diffustion
220     Vector3d randomForce;
221     Vector3d randomTorque;
222     genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
223 tim 2632 randomForce = Atrans*randomForce;
224     randomTorque = Atrans* randomTorque;
225     integrableObject->addFrc(randomForce);
226 tim 2611 integrableObject->addTrq(randomTorque + cross(rcd, randomForce ));
227    
228     } else {
229     //spheric atom
230     Vector3d frictionForce = -(hydroProps_[index].Xidtt *vel);
231     Vector3d randomForce;
232     Vector3d randomTorque;
233     genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
234 tim 2632
235     //randomForce /= OOPSEConstant::energyConvert;
236     //randomTorque /= OOPSEConstant::energyConvert;
237 tim 2611 integrableObject->addFrc(frictionForce+randomForce);
238     }
239    
240     ++index;
241    
242     }
243     }
244    
245     ForceManager::postCalculation();
246    
247    
248    
249     }
250    
251     void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, double variance) {
252 tim 2632 /*
253 tim 2611 SquareMatrix<double, 6> Dd;
254     SquareMatrix<double, 6> S;
255     Vector<double, 6> Z;
256     Vector<double, 6> generalForce;
257     Dd.setSubMatrix(0, 0, hydroProps_[index].Ddtt);
258     Dd.setSubMatrix(0, 3, hydroProps_[index].Ddtr.transpose());
259     Dd.setSubMatrix(3, 0, hydroProps_[index].Ddtr);
260     Dd.setSubMatrix(3, 3, hydroProps_[index].Ddrr);
261     CholeskyDecomposition(Dd, S);
262 tim 2632 */
263    
264     SquareMatrix<double, 6> Xid;
265     SquareMatrix<double, 6> S;
266     Vector<double, 6> Z;
267     Vector<double, 6> generalForce;
268     Xid.setSubMatrix(0, 0, hydroProps_[index].Xidtt);
269     Xid.setSubMatrix(0, 3, hydroProps_[index].Xidrt);
270     Xid.setSubMatrix(3, 0, hydroProps_[index].Xidtr);
271     Xid.setSubMatrix(3, 3, hydroProps_[index].Xidrr);
272     CholeskyDecomposition(Xid, S);
273    
274     /*
275     Xid *= variance;
276     Z[0] = randNumGen_.randNorm(0, 1.0);
277     Z[1] = randNumGen_.randNorm(0, 1.0);
278     Z[2] = randNumGen_.randNorm(0, 1.0);
279     Z[3] = randNumGen_.randNorm(0, 1.0);
280     Z[4] = randNumGen_.randNorm(0, 1.0);
281     Z[5] = randNumGen_.randNorm(0, 1.0);
282     */
283    
284 tim 2611 Z[0] = randNumGen_.randNorm(0, variance);
285     Z[1] = randNumGen_.randNorm(0, variance);
286     Z[2] = randNumGen_.randNorm(0, variance);
287     Z[3] = randNumGen_.randNorm(0, variance);
288     Z[4] = randNumGen_.randNorm(0, variance);
289     Z[5] = randNumGen_.randNorm(0, variance);
290 tim 2632
291    
292 tim 2611 generalForce = S*Z;
293 tim 2632
294 tim 2611 force[0] = generalForce[0];
295     force[1] = generalForce[1];
296     force[2] = generalForce[2];
297     torque[0] = generalForce[3];
298     torque[1] = generalForce[4];
299     torque[2] = generalForce[5];
300    
301     }
302    
303     }

Properties

Name Value
svn:executable *