ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/integrators/SMIPDForceManager.cpp
Revision: 1627
Committed: Tue Sep 13 22:05:04 2011 UTC (13 years, 7 months ago) by gezelter
File size: 8864 byte(s)
Log Message:
Splitting out ifstrstream into a header and an implementation.  This
means that much of the code that depends on it can be compiled only
once and the parallel I/O is concentrated into a few files.  To do
this, a number of files that relied on basic_ifstrstream to load the
mpi header had to be modified to manage their own headers.


File Contents

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

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date