ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/integrators/SMIPDForceManager.cpp
Revision: 1390
Committed: Wed Nov 25 20:02:06 2009 UTC (15 years, 5 months ago) by gezelter
Original Path: trunk/src/integrators/SMIPDForceManager.cpp
File size: 8487 byte(s)
Log Message:
Almost all of the changes necessary to create OpenMD out of our old
project (OOPSE-4)

File Contents

# User Rev Content
1 chuckv 1293 /*
2 chuckv 1375 * Copyright (c) 2008, 2009 The University of Notre Dame. All Rights Reserved.
3 chuckv 1293 *
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 chuckv 1293 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 chuckv 1293 * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
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 gezelter 1390 *
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] Vardeman & Gezelter, in progress (2009).
40 chuckv 1293 */
41     #include <fstream>
42     #include <iostream>
43     #include "integrators/SMIPDForceManager.hpp"
44 gezelter 1390 #include "utils/PhysicalConstants.hpp"
45 chuckv 1293 #include "math/ConvexHull.hpp"
46     #include "math/Triangle.hpp"
47    
48 gezelter 1390 namespace OpenMD {
49 gezelter 1324
50 gezelter 1344 SMIPDForceManager::SMIPDForceManager(SimInfo* info) : ForceManager(info) {
51    
52 chuckv 1293 simParams = info->getSimParams();
53 chuckv 1325 veloMunge = new Velocitizer(info);
54 chuckv 1293
55     // Create Hull, Convex Hull for now, other options later.
56 gezelter 1324
57 chuckv 1293 surfaceMesh_ = new ConvexHull();
58    
59     /* Check that the simulation has target pressure and target
60 chuckv 1325 temperature set */
61 chuckv 1323
62 chuckv 1293 if (!simParams->haveTargetTemp()) {
63 gezelter 1324 sprintf(painCave.errMsg,
64     "SMIPDynamics error: You can't use the SMIPD integrator\n"
65 gezelter 1357 "\twithout a targetTemp (K)!\n");
66 chuckv 1293 painCave.isFatal = 1;
67 gezelter 1390 painCave.severity = OPENMD_ERROR;
68 chuckv 1293 simError();
69     } else {
70     targetTemp_ = simParams->getTargetTemp();
71     }
72 chuckv 1323
73 chuckv 1293 if (!simParams->haveTargetPressure()) {
74 gezelter 1324 sprintf(painCave.errMsg,
75     "SMIPDynamics error: You can't use the SMIPD integrator\n"
76 gezelter 1357 "\twithout a targetPressure (atm)!\n");
77 chuckv 1293 painCave.isFatal = 1;
78     simError();
79     } else {
80 gezelter 1324 // Convert pressure from atm -> amu/(fs^2*Ang)
81     targetPressure_ = simParams->getTargetPressure() /
82 gezelter 1390 PhysicalConstants::pressureConvert;
83 chuckv 1293 }
84    
85     if (simParams->getUsePeriodicBoundaryConditions()) {
86 gezelter 1324 sprintf(painCave.errMsg,
87     "SMIPDynamics error: You can't use the SMIPD integrator\n"
88 gezelter 1357 "\twith periodic boundary conditions!\n");
89 chuckv 1293 painCave.isFatal = 1;
90     simError();
91     }
92 gezelter 1324
93 gezelter 1355 if (!simParams->haveThermalConductivity()) {
94 gezelter 1324 sprintf(painCave.errMsg,
95     "SMIPDynamics error: You can't use the SMIPD integrator\n"
96 gezelter 1357 "\twithout a thermalConductivity (W m^-1 K^-1)!\n");
97 chuckv 1316 painCave.isFatal = 1;
98 gezelter 1390 painCave.severity = OPENMD_ERROR;
99 chuckv 1316 simError();
100 chuckv 1323 }else{
101 gezelter 1356 thermalConductivity_ = simParams->getThermalConductivity() *
102 gezelter 1390 PhysicalConstants::thermalConductivityConvert;
103 chuckv 1316 }
104 gezelter 1355
105     if (!simParams->haveThermalLength()) {
106     sprintf(painCave.errMsg,
107     "SMIPDynamics error: You can't use the SMIPD integrator\n"
108 gezelter 1357 "\twithout a thermalLength (Angstroms)!\n");
109 gezelter 1355 painCave.isFatal = 1;
110 gezelter 1390 painCave.severity = OPENMD_ERROR;
111 gezelter 1355 simError();
112     }else{
113     thermalLength_ = simParams->getThermalLength();
114     }
115 gezelter 1324
116 chuckv 1323 dt_ = simParams->getDt();
117 gezelter 1324
118 gezelter 1390 variance_ = 2.0 * PhysicalConstants::kb * targetTemp_ / dt_;
119 chuckv 1307
120 gezelter 1344 // Build a vector of integrable objects to determine if the are
121     // surface atoms
122 chuckv 1293 Molecule* mol;
123     StuntDouble* integrableObject;
124     SimInfo::MoleculeIterator i;
125 gezelter 1344 Molecule::IntegrableObjectIterator j;
126 chuckv 1323
127 gezelter 1324 for (mol = info_->beginMolecule(i); mol != NULL;
128     mol = info_->nextMolecule(i)) {
129     for (integrableObject = mol->beginIntegrableObject(j);
130     integrableObject != NULL;
131 chuckv 1293 integrableObject = mol->nextIntegrableObject(j)) {
132     localSites_.push_back(integrableObject);
133     }
134 gezelter 1324 }
135 chuckv 1293 }
136 chuckv 1325
137 chuckv 1293 void SMIPDForceManager::postCalculation(bool needStress){
138     SimInfo::MoleculeIterator i;
139     Molecule::IntegrableObjectIterator j;
140     Molecule* mol;
141     StuntDouble* integrableObject;
142 chuckv 1325
143 gezelter 1324 // Compute surface Mesh
144 chuckv 1293 surfaceMesh_->computeHull(localSites_);
145 chuckv 1325
146 gezelter 1324 // Get total area and number of surface stunt doubles
147     RealType area = surfaceMesh_->getArea();
148 chuckv 1308 std::vector<Triangle> sMesh = surfaceMesh_->getMesh();
149 chuckv 1307 int nTriangles = sMesh.size();
150    
151 gezelter 1344 // Generate all of the necessary random forces
152 gezelter 1355 std::vector<RealType> randNums = genTriangleForces(nTriangles, variance_);
153 gezelter 1344
154 chuckv 1325 // Loop over the mesh faces and apply external pressure to each
155     // of the faces
156 chuckv 1308 std::vector<Triangle>::iterator face;
157 chuckv 1302 std::vector<StuntDouble*>::iterator vertex;
158 gezelter 1344 int thisFacet = 0;
159 chuckv 1293 for (face = sMesh.begin(); face != sMesh.end(); ++face){
160 chuckv 1308 Triangle thisTriangle = *face;
161     std::vector<StuntDouble*> vertexSDs = thisTriangle.getVertices();
162 chuckv 1316 RealType thisArea = thisTriangle.getArea();
163 chuckv 1308 Vector3d unitNormal = thisTriangle.getNormal();
164 chuckv 1302 unitNormal.normalize();
165 chuckv 1308 Vector3d centroid = thisTriangle.getCentroid();
166 gezelter 1344 Vector3d facetVel = thisTriangle.getFacetVelocity();
167 gezelter 1355 RealType thisMass = thisTriangle.getFacetMass();
168 gezelter 1390 // Mat3x3d hydroTens = thisTriangle.computeHydrodynamicTensor(viscosity);
169 gezelter 1344
170 gezelter 1355 // gamma is the drag coefficient normal to the face of the triangle
171 gezelter 1357 RealType gamma = thermalConductivity_ * thisMass * thisArea
172 gezelter 1390 / (2.0 * thermalLength_ * PhysicalConstants::kB);
173 gezelter 1377
174 gezelter 1355 RealType extPressure = - (targetPressure_ * thisArea) /
175 gezelter 1390 PhysicalConstants::energyConvert;
176 gezelter 1355 RealType randomForce = randNums[thisFacet++] * sqrt(gamma);
177     RealType dragForce = -gamma * dot(facetVel, unitNormal);
178 gezelter 1344
179 gezelter 1355 Vector3d langevinForce = (extPressure + randomForce + dragForce) *
180     unitNormal;
181    
182 chuckv 1375 // Apply triangle force to stuntdouble vertices
183 chuckv 1325 for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex){
184 chuckv 1375 if ((*vertex) != NULL){
185 gezelter 1344 Vector3d vertexForce = langevinForce / 3.0;
186     (*vertex)->addFrc(vertexForce);
187 chuckv 1307 }
188 chuckv 1293 }
189 chuckv 1302 }
190 gezelter 1355
191 chuckv 1325 veloMunge->removeComDrift();
192     veloMunge->removeAngularDrift();
193 gezelter 1355
194 chuckv 1302 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
195 chuckv 1316 currSnapshot->setVolume(surfaceMesh_->getVolume());
196 chuckv 1302 ForceManager::postCalculation(needStress);
197 chuckv 1293 }
198 gezelter 1344
199 gezelter 1355
200     std::vector<RealType> SMIPDForceManager::genTriangleForces(int nTriangles,
201 gezelter 1344 RealType variance)
202     {
203 chuckv 1325
204 gezelter 1344 // zero fill the random vector before starting:
205 gezelter 1355 std::vector<RealType> gaussRand;
206 gezelter 1344 gaussRand.resize(nTriangles);
207 gezelter 1355 std::fill(gaussRand.begin(), gaussRand.end(), 0.0);
208 chuckv 1325
209 gezelter 1344 #ifdef IS_MPI
210     if (worldRank == 0) {
211     #endif
212     for (int i = 0; i < nTriangles; i++) {
213 gezelter 1355 gaussRand[i] = randNumGen_.randNorm(0.0, variance);
214 gezelter 1344 }
215     #ifdef IS_MPI
216     }
217     #endif
218 chuckv 1325
219 gezelter 1344 // push these out to the other processors
220    
221     #ifdef IS_MPI
222     if (worldRank == 0) {
223 gezelter 1355 MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles, MPI::REALTYPE, 0);
224 gezelter 1344 } else {
225 gezelter 1355 MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles, MPI::REALTYPE, 0);
226 gezelter 1344 }
227     #endif
228    
229     return gaussRand;
230     }
231 chuckv 1293 }

Properties

Name Value
svn:executable *