ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/SMIPDForceManager.cpp
Revision: 3515
Committed: Mon Jul 20 17:50:40 2009 UTC (16 years ago) by gezelter
File size: 8667 byte(s)
Log Message:
Latest version of SMIPD with gamma set to thermal conductivity

File Contents

# User Rev Content
1 chuckv 3450 /*
2     * Copyright (c) 2008 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 <iostream>
43     #include "integrators/SMIPDForceManager.hpp"
44     #include "utils/OOPSEConstant.hpp"
45     #include "math/ConvexHull.hpp"
46     #include "math/Triangle.hpp"
47    
48     namespace oopse {
49 gezelter 3481
50 gezelter 3504 SMIPDForceManager::SMIPDForceManager(SimInfo* info) : ForceManager(info) {
51    
52 chuckv 3450 simParams = info->getSimParams();
53 gezelter 3515 thermo = new Thermo(info);
54 chuckv 3482 veloMunge = new Velocitizer(info);
55 chuckv 3450
56     // Create Hull, Convex Hull for now, other options later.
57 gezelter 3481
58 chuckv 3450 surfaceMesh_ = new ConvexHull();
59    
60     /* Check that the simulation has target pressure and target
61 chuckv 3482 temperature set */
62 chuckv 3480
63 chuckv 3450 if (!simParams->haveTargetTemp()) {
64 gezelter 3481 sprintf(painCave.errMsg,
65     "SMIPDynamics error: You can't use the SMIPD integrator\n"
66     " without a targetTemp!\n");
67 chuckv 3450 painCave.isFatal = 1;
68     painCave.severity = OOPSE_ERROR;
69     simError();
70     } else {
71     targetTemp_ = simParams->getTargetTemp();
72     }
73 chuckv 3480
74 chuckv 3450 if (!simParams->haveTargetPressure()) {
75 gezelter 3481 sprintf(painCave.errMsg,
76     "SMIPDynamics error: You can't use the SMIPD integrator\n"
77     " without a targetPressure!\n");
78 chuckv 3450 painCave.isFatal = 1;
79     simError();
80     } else {
81 gezelter 3481 // Convert pressure from atm -> amu/(fs^2*Ang)
82     targetPressure_ = simParams->getTargetPressure() /
83     OOPSEConstant::pressureConvert;
84 chuckv 3450 }
85    
86     if (simParams->getUsePeriodicBoundaryConditions()) {
87 gezelter 3481 sprintf(painCave.errMsg,
88     "SMIPDynamics error: You can't use the SMIPD integrator\n"
89 gezelter 3515 " with periodic boundary conditions!\n");
90 chuckv 3450 painCave.isFatal = 1;
91     simError();
92     }
93 gezelter 3481
94 gezelter 3515 if (!simParams->haveThermalConductivity()) {
95 gezelter 3481 sprintf(painCave.errMsg,
96     "SMIPDynamics error: You can't use the SMIPD integrator\n"
97 gezelter 3515 " without a thermalConductivity!\n");
98 chuckv 3473 painCave.isFatal = 1;
99     painCave.severity = OOPSE_ERROR;
100     simError();
101 chuckv 3480 }else{
102 gezelter 3515 thermalConductivity_ = simParams->getThermalConductivity();
103 chuckv 3473 }
104 gezelter 3515
105     if (!simParams->haveThermalLength()) {
106     sprintf(painCave.errMsg,
107     "SMIPDynamics error: You can't use the SMIPD integrator\n"
108     " without a thermalLength!\n");
109     painCave.isFatal = 1;
110     painCave.severity = OOPSE_ERROR;
111     simError();
112     }else{
113     thermalLength_ = simParams->getThermalLength();
114     }
115 gezelter 3481
116 chuckv 3480 dt_ = simParams->getDt();
117 gezelter 3481
118     variance_ = 2.0 * OOPSEConstant::kb * targetTemp_ / dt_;
119 chuckv 3464
120 gezelter 3504 // Build a vector of integrable objects to determine if the are
121     // surface atoms
122 chuckv 3450 Molecule* mol;
123     StuntDouble* integrableObject;
124     SimInfo::MoleculeIterator i;
125 gezelter 3504 Molecule::IntegrableObjectIterator j;
126 chuckv 3480
127 gezelter 3481 for (mol = info_->beginMolecule(i); mol != NULL;
128     mol = info_->nextMolecule(i)) {
129     for (integrableObject = mol->beginIntegrableObject(j);
130     integrableObject != NULL;
131 chuckv 3450 integrableObject = mol->nextIntegrableObject(j)) {
132     localSites_.push_back(integrableObject);
133     }
134 gezelter 3481 }
135 chuckv 3450 }
136 chuckv 3482
137 chuckv 3450 void SMIPDForceManager::postCalculation(bool needStress){
138     SimInfo::MoleculeIterator i;
139     Molecule::IntegrableObjectIterator j;
140     Molecule* mol;
141     StuntDouble* integrableObject;
142 chuckv 3482
143 gezelter 3481 // Compute surface Mesh
144 chuckv 3450 surfaceMesh_->computeHull(localSites_);
145 chuckv 3482
146 gezelter 3481 // Get total area and number of surface stunt doubles
147     RealType area = surfaceMesh_->getArea();
148 chuckv 3482 int nSurfaceSDs = surfaceMesh_->getNs();
149 chuckv 3465 std::vector<Triangle> sMesh = surfaceMesh_->getMesh();
150 chuckv 3464 int nTriangles = sMesh.size();
151    
152 gezelter 3504 // Generate all of the necessary random forces
153 gezelter 3515 std::vector<RealType> randNums = genTriangleForces(nTriangles, variance_);
154 gezelter 3504
155 gezelter 3515 RealType instaTemp = thermo->getTemperature();
156    
157 chuckv 3482 // Loop over the mesh faces and apply external pressure to each
158     // of the faces
159 chuckv 3465 std::vector<Triangle>::iterator face;
160 chuckv 3459 std::vector<StuntDouble*>::iterator vertex;
161 gezelter 3504 int thisFacet = 0;
162 chuckv 3450 for (face = sMesh.begin(); face != sMesh.end(); ++face){
163    
164 chuckv 3465 Triangle thisTriangle = *face;
165     std::vector<StuntDouble*> vertexSDs = thisTriangle.getVertices();
166 chuckv 3473 RealType thisArea = thisTriangle.getArea();
167 chuckv 3465 Vector3d unitNormal = thisTriangle.getNormal();
168 chuckv 3459 unitNormal.normalize();
169 chuckv 3465 Vector3d centroid = thisTriangle.getCentroid();
170 gezelter 3504 Vector3d facetVel = thisTriangle.getFacetVelocity();
171 gezelter 3515 RealType thisMass = thisTriangle.getFacetMass();
172 gezelter 3504
173 gezelter 3515 // gamma is the drag coefficient normal to the face of the triangle
174     RealType gamma = thermalConductivity_ * thisMass * thisArea
175     / (2.0 * thermalLength_ * OOPSEConstant::kb);
176    
177     gamma *= fabs(1.0 - targetTemp_/instaTemp);
178    
179     RealType extPressure = - (targetPressure_ * thisArea) /
180     OOPSEConstant::energyConvert;
181 gezelter 3504
182 gezelter 3515 RealType randomForce = randNums[thisFacet++] * sqrt(gamma);
183     RealType dragForce = -gamma * dot(facetVel, unitNormal);
184 gezelter 3504
185 gezelter 3515 Vector3d langevinForce = (extPressure + randomForce + dragForce) *
186     unitNormal;
187    
188 gezelter 3504 // Apply triangle force to stuntdouble vertices
189 chuckv 3482 for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex){
190     if ((*vertex) != NULL){
191 gezelter 3504 Vector3d vertexForce = langevinForce / 3.0;
192     (*vertex)->addFrc(vertexForce);
193 chuckv 3482 if ((*vertex)->isDirectional()){
194 chuckv 3464 Vector3d vertexPos = (*vertex)->getPos();
195     Vector3d vertexCentroidVector = vertexPos - centroid;
196     (*vertex)->addTrq(cross(vertexCentroidVector,vertexForce));
197     }
198     }
199 chuckv 3450 }
200 chuckv 3459 }
201 gezelter 3515
202 chuckv 3482 veloMunge->removeComDrift();
203     veloMunge->removeAngularDrift();
204 gezelter 3515
205 chuckv 3459 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
206 chuckv 3473 currSnapshot->setVolume(surfaceMesh_->getVolume());
207 chuckv 3459 ForceManager::postCalculation(needStress);
208 chuckv 3450 }
209 gezelter 3504
210 gezelter 3515
211     std::vector<RealType> SMIPDForceManager::genTriangleForces(int nTriangles,
212 gezelter 3504 RealType variance)
213     {
214 chuckv 3482
215 gezelter 3504 // zero fill the random vector before starting:
216 gezelter 3515 std::vector<RealType> gaussRand;
217 gezelter 3504 gaussRand.resize(nTriangles);
218 gezelter 3515 std::fill(gaussRand.begin(), gaussRand.end(), 0.0);
219 chuckv 3482
220 gezelter 3504 #ifdef IS_MPI
221     if (worldRank == 0) {
222     #endif
223     for (int i = 0; i < nTriangles; i++) {
224 gezelter 3515 gaussRand[i] = randNumGen_.randNorm(0.0, variance);
225 gezelter 3504 }
226     #ifdef IS_MPI
227     }
228     #endif
229 chuckv 3482
230 gezelter 3504 // push these out to the other processors
231    
232     #ifdef IS_MPI
233     if (worldRank == 0) {
234 gezelter 3515 MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles, MPI::REALTYPE, 0);
235 gezelter 3504 } else {
236 gezelter 3515 MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles, MPI::REALTYPE, 0);
237 gezelter 3504 }
238     #endif
239    
240     return gaussRand;
241     }
242 chuckv 3450 }

Properties

Name Value
svn:executable *