ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/integrators/SMIPDForceManager.cpp
Revision: 1398
Committed: Tue Dec 8 22:17:02 2009 UTC (15 years, 4 months ago) by gezelter
Original Path: trunk/src/integrators/SMIPDForceManager.cpp
File size: 8083 byte(s)
Log Message:
Parallel bugfix in RestraintForceManager
Reverted back to hydrodynamics on triangular plates for SMIPDForceManager
Removed thermalLength and thermalConductivity keywords from Globals.
Bug tracking in openmdformat (not yet resolved).

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 gezelter 1398 #include "math/CholeskyDecomposition.hpp"
48 chuckv 1293
49 gezelter 1390 namespace OpenMD {
50 gezelter 1324
51 gezelter 1344 SMIPDForceManager::SMIPDForceManager(SimInfo* info) : ForceManager(info) {
52    
53 chuckv 1293 simParams = info->getSimParams();
54 chuckv 1325 veloMunge = new Velocitizer(info);
55 chuckv 1293
56     // Create Hull, Convex Hull for now, other options later.
57 gezelter 1324
58 chuckv 1293 surfaceMesh_ = new ConvexHull();
59    
60     /* Check that the simulation has target pressure and target
61 chuckv 1325 temperature set */
62 chuckv 1323
63 chuckv 1293 if (!simParams->haveTargetTemp()) {
64 gezelter 1324 sprintf(painCave.errMsg,
65     "SMIPDynamics error: You can't use the SMIPD integrator\n"
66 gezelter 1357 "\twithout a targetTemp (K)!\n");
67 chuckv 1293 painCave.isFatal = 1;
68 gezelter 1390 painCave.severity = OPENMD_ERROR;
69 chuckv 1293 simError();
70     } else {
71     targetTemp_ = simParams->getTargetTemp();
72     }
73 chuckv 1323
74 chuckv 1293 if (!simParams->haveTargetPressure()) {
75 gezelter 1324 sprintf(painCave.errMsg,
76     "SMIPDynamics error: You can't use the SMIPD integrator\n"
77 gezelter 1357 "\twithout a targetPressure (atm)!\n");
78 chuckv 1293 painCave.isFatal = 1;
79     simError();
80     } else {
81 gezelter 1324 // Convert pressure from atm -> amu/(fs^2*Ang)
82     targetPressure_ = simParams->getTargetPressure() /
83 gezelter 1390 PhysicalConstants::pressureConvert;
84 chuckv 1293 }
85    
86     if (simParams->getUsePeriodicBoundaryConditions()) {
87 gezelter 1324 sprintf(painCave.errMsg,
88     "SMIPDynamics error: You can't use the SMIPD integrator\n"
89 gezelter 1357 "\twith periodic boundary conditions!\n");
90 chuckv 1293 painCave.isFatal = 1;
91     simError();
92     }
93 gezelter 1324
94 gezelter 1398 if (!simParams->haveViscosity()) {
95 gezelter 1324 sprintf(painCave.errMsg,
96     "SMIPDynamics error: You can't use the SMIPD integrator\n"
97 gezelter 1398 "\twithout a viscosity!\n");
98 chuckv 1316 painCave.isFatal = 1;
99 gezelter 1390 painCave.severity = OPENMD_ERROR;
100 chuckv 1316 simError();
101 chuckv 1323 }else{
102 gezelter 1398 viscosity_ = simParams->getViscosity();
103 chuckv 1316 }
104 gezelter 1324
105 chuckv 1323 dt_ = simParams->getDt();
106 gezelter 1324
107 gezelter 1390 variance_ = 2.0 * PhysicalConstants::kb * targetTemp_ / dt_;
108 chuckv 1307
109 gezelter 1344 // Build a vector of integrable objects to determine if the are
110     // surface atoms
111 chuckv 1293 Molecule* mol;
112     StuntDouble* integrableObject;
113     SimInfo::MoleculeIterator i;
114 gezelter 1344 Molecule::IntegrableObjectIterator j;
115 chuckv 1323
116 gezelter 1324 for (mol = info_->beginMolecule(i); mol != NULL;
117     mol = info_->nextMolecule(i)) {
118     for (integrableObject = mol->beginIntegrableObject(j);
119     integrableObject != NULL;
120 chuckv 1293 integrableObject = mol->nextIntegrableObject(j)) {
121     localSites_.push_back(integrableObject);
122     }
123 gezelter 1324 }
124 chuckv 1293 }
125 chuckv 1325
126 chuckv 1293 void SMIPDForceManager::postCalculation(bool needStress){
127     SimInfo::MoleculeIterator i;
128     Molecule::IntegrableObjectIterator j;
129     Molecule* mol;
130     StuntDouble* integrableObject;
131 chuckv 1325
132 gezelter 1324 // Compute surface Mesh
133 chuckv 1293 surfaceMesh_->computeHull(localSites_);
134 chuckv 1325
135 gezelter 1324 // Get total area and number of surface stunt doubles
136     RealType area = surfaceMesh_->getArea();
137 chuckv 1308 std::vector<Triangle> sMesh = surfaceMesh_->getMesh();
138 chuckv 1307 int nTriangles = sMesh.size();
139    
140 gezelter 1344 // Generate all of the necessary random forces
141 gezelter 1398 std::vector<Vector3d> randNums = genTriangleForces(nTriangles, variance_);
142 gezelter 1344
143 chuckv 1325 // Loop over the mesh faces and apply external pressure to each
144     // of the faces
145 chuckv 1308 std::vector<Triangle>::iterator face;
146 chuckv 1302 std::vector<StuntDouble*>::iterator vertex;
147 gezelter 1344 int thisFacet = 0;
148 chuckv 1293 for (face = sMesh.begin(); face != sMesh.end(); ++face){
149 chuckv 1308 Triangle thisTriangle = *face;
150     std::vector<StuntDouble*> vertexSDs = thisTriangle.getVertices();
151 chuckv 1316 RealType thisArea = thisTriangle.getArea();
152 chuckv 1308 Vector3d unitNormal = thisTriangle.getNormal();
153 chuckv 1302 unitNormal.normalize();
154 chuckv 1308 Vector3d centroid = thisTriangle.getCentroid();
155 gezelter 1344 Vector3d facetVel = thisTriangle.getFacetVelocity();
156 gezelter 1355 RealType thisMass = thisTriangle.getFacetMass();
157 gezelter 1398 Mat3x3d hydroTensor = thisTriangle.computeHydrodynamicTensor(viscosity_);
158    
159     hydroTensor *= PhysicalConstants::viscoConvert;
160     Mat3x3d S;
161     CholeskyDecomposition(hydroTensor, S);
162    
163     Vector3d extPressure = -unitNormal * (targetPressure_ * thisArea) /
164     PhysicalConstants::energyConvert;
165 gezelter 1344
166 gezelter 1398 Vector3d randomForce = S * randNums[thisFacet++];
167     Vector3d dragForce = -hydroTensor * facetVel;
168 gezelter 1377
169 gezelter 1398 Vector3d langevinForce = (extPressure + randomForce + dragForce);
170 gezelter 1355
171 chuckv 1375 // Apply triangle force to stuntdouble vertices
172 chuckv 1325 for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex){
173 chuckv 1375 if ((*vertex) != NULL){
174 gezelter 1344 Vector3d vertexForce = langevinForce / 3.0;
175     (*vertex)->addFrc(vertexForce);
176 chuckv 1307 }
177 chuckv 1293 }
178 chuckv 1302 }
179 gezelter 1355
180 chuckv 1325 veloMunge->removeComDrift();
181     veloMunge->removeAngularDrift();
182 gezelter 1355
183 chuckv 1302 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
184 chuckv 1316 currSnapshot->setVolume(surfaceMesh_->getVolume());
185 chuckv 1302 ForceManager::postCalculation(needStress);
186 chuckv 1293 }
187 gezelter 1344
188 gezelter 1355
189 gezelter 1398 std::vector<Vector3d> SMIPDForceManager::genTriangleForces(int nTriangles,
190 gezelter 1344 RealType variance)
191     {
192 chuckv 1325
193 gezelter 1344 // zero fill the random vector before starting:
194 gezelter 1398 std::vector<Vector3d> gaussRand;
195 gezelter 1344 gaussRand.resize(nTriangles);
196 gezelter 1398 std::fill(gaussRand.begin(), gaussRand.end(), V3Zero);
197 chuckv 1325
198 gezelter 1344 #ifdef IS_MPI
199     if (worldRank == 0) {
200     #endif
201     for (int i = 0; i < nTriangles; i++) {
202 gezelter 1398 gaussRand[i][0] = randNumGen_.randNorm(0.0, variance);
203     gaussRand[i][1] = randNumGen_.randNorm(0.0, variance);
204     gaussRand[i][2] = randNumGen_.randNorm(0.0, variance);
205 gezelter 1344 }
206     #ifdef IS_MPI
207     }
208     #endif
209 chuckv 1325
210 gezelter 1344 // push these out to the other processors
211    
212     #ifdef IS_MPI
213     if (worldRank == 0) {
214 gezelter 1398 MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles*3, MPI::REALTYPE, 0);
215 gezelter 1344 } else {
216 gezelter 1398 MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles*3, MPI::REALTYPE, 0);
217 gezelter 1344 }
218     #endif
219    
220     return gaussRand;
221     }
222 chuckv 1293 }

Properties

Name Value
svn:executable *