ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/integrators/LangevinHullForceManager.cpp
Revision: 1858
Committed: Wed Apr 3 21:32:13 2013 UTC (12 years, 1 month ago) by gezelter
File size: 10364 byte(s)
Log Message:
Some bugfixes for cell-linked-list-style neighbor lists when the simulation
doesn't use periodic boundary conditions.   Cleaning up some of the Hull
stuff while we're in there.

File Contents

# User Rev Content
1 gezelter 1629 /*
2     * Copyright (c) 2008, 2009, 2010 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. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * 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     *
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 gezelter 1850 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 1629 */
42     #include <fstream>
43     #include <iostream>
44     #include "integrators/LangevinHullForceManager.hpp"
45     #include "utils/PhysicalConstants.hpp"
46     #include "math/ConvexHull.hpp"
47     #include "math/AlphaHull.hpp"
48     #include "math/Triangle.hpp"
49     #include "math/CholeskyDecomposition.hpp"
50     #ifdef IS_MPI
51     #include <mpi.h>
52     #endif
53    
54 gezelter 1858 using namespace std;
55 gezelter 1629 namespace OpenMD {
56 gezelter 1858
57     LangevinHullForceManager::LangevinHullForceManager(SimInfo* info) :
58     ForceManager(info) {
59 gezelter 1629
60     simParams = info->getSimParams();
61     veloMunge = new Velocitizer(info);
62    
63     // Create Hull, Convex Hull for now, other options later.
64    
65     stringToEnumMap_["Convex"] = hullConvex;
66     stringToEnumMap_["AlphaShape"] = hullAlphaShape;
67     stringToEnumMap_["Unknown"] = hullUnknown;
68    
69     const std::string ht = simParams->getHULL_Method();
70    
71     std::map<std::string, HullTypeEnum>::iterator iter;
72     iter = stringToEnumMap_.find(ht);
73 gezelter 1858 hullType_ = (iter == stringToEnumMap_.end()) ?
74     LangevinHullForceManager::hullUnknown : iter->second;
75    
76 gezelter 1629 switch(hullType_) {
77     case hullConvex :
78     surfaceMesh_ = new ConvexHull();
79     break;
80     case hullAlphaShape :
81     surfaceMesh_ = new AlphaHull(simParams->getAlpha());
82     break;
83     case hullUnknown :
84     default :
85 gezelter 1858 sprintf(painCave.errMsg,
86     "LangevinHallForceManager: Unknown Hull_Method was requested!\n");
87     painCave.isFatal = 1;
88     simError();
89 gezelter 1629 break;
90     }
91 gezelter 1858
92     doThermalCoupling_ = true;
93     doPressureCoupling_ = true;
94    
95 gezelter 1629 /* Check that the simulation has target pressure and target
96 gezelter 1858 temperature set */
97 gezelter 1629 if (!simParams->haveTargetTemp()) {
98     sprintf(painCave.errMsg,
99 gezelter 1858 "LangevinHullForceManager: no targetTemp (K) was set.\n"
100     "\tOpenMD is turning off the thermal coupling to the bath.\n");
101     painCave.isFatal = 0;
102     painCave.severity = OPENMD_INFO;
103 gezelter 1629 simError();
104 gezelter 1858 doThermalCoupling_ = false;
105 gezelter 1629 } else {
106     targetTemp_ = simParams->getTargetTemp();
107     }
108    
109     if (!simParams->haveTargetPressure()) {
110     sprintf(painCave.errMsg,
111 gezelter 1858 "LangevinHullForceManager: no targetPressure (atm) was set.\n"
112     "\tOpenMD is turning off the pressure coupling to the bath.\n");
113     painCave.isFatal = 0;
114     painCave.severity = OPENMD_INFO;
115 gezelter 1629 simError();
116 gezelter 1858 doPressureCoupling_ = false;
117 gezelter 1629 } else {
118     // Convert pressure from atm -> amu/(fs^2*Ang)
119     targetPressure_ = simParams->getTargetPressure() /
120     PhysicalConstants::pressureConvert;
121     }
122    
123     if (simParams->getUsePeriodicBoundaryConditions()) {
124     sprintf(painCave.errMsg,
125 gezelter 1858 "LangevinHallForceManager: You can't use the Langevin Hull\n"
126     "\tintegrator with periodic boundary conditions turned on!\n");
127 gezelter 1629 painCave.isFatal = 1;
128     simError();
129     }
130    
131     if (!simParams->haveViscosity()) {
132     sprintf(painCave.errMsg,
133 gezelter 1858 "LangevinHullForceManager: no viscosity was set.\n"
134     "\tOpenMD is turning off the thermal coupling to the bath.\n");
135     painCave.isFatal = 0;
136     painCave.severity = OPENMD_INFO;
137 gezelter 1629 simError();
138 gezelter 1858 doThermalCoupling_ = false;
139 gezelter 1629 }else{
140     viscosity_ = simParams->getViscosity();
141     }
142    
143 gezelter 1855 if ( fabs(viscosity_) < 1e-6 ) {
144     sprintf(painCave.errMsg,
145     "LangevinHullDynamics: The bath viscosity was set lower than\n"
146     "\t1e-6 poise. OpenMD is turning off the thermal coupling to\n"
147 gezelter 1856 "\tthe bath.\n");
148 gezelter 1855 painCave.isFatal = 0;
149     painCave.severity = OPENMD_INFO;
150     simError();
151     doThermalCoupling_ = false;
152     }
153    
154 gezelter 1629 dt_ = simParams->getDt();
155    
156 gezelter 1858 if (doThermalCoupling_)
157     variance_ = 2.0 * PhysicalConstants::kb * targetTemp_ / dt_;
158 gezelter 1629
159     // Build a vector of integrable objects to determine if the are
160     // surface atoms
161     Molecule* mol;
162 gezelter 1767 StuntDouble* sd;
163 gezelter 1629 SimInfo::MoleculeIterator i;
164     Molecule::IntegrableObjectIterator j;
165 gezelter 1858
166 gezelter 1629 for (mol = info_->beginMolecule(i); mol != NULL;
167     mol = info_->nextMolecule(i)) {
168 gezelter 1767 for (sd = mol->beginIntegrableObject(j);
169     sd != NULL;
170     sd = mol->nextIntegrableObject(j)) {
171     localSites_.push_back(sd);
172 gezelter 1629 }
173 gezelter 1858 }
174    
175     // We need to make an initial guess at the bounding box in order
176     // to compute long range forces in ForceMatrixDecomposition:
177    
178     // Compute surface Mesh
179     surfaceMesh_->computeHull(localSites_);
180     Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
181     currSnapshot->setBoundingBox(surfaceMesh_->getBoundingBox());
182 gezelter 1629 }
183 gezelter 1858
184 gezelter 1629 void LangevinHullForceManager::postCalculation(){
185    
186 gezelter 1858 int nTriangles, thisFacet;
187     RealType area, thisArea, thisMass;
188     vector<Triangle> sMesh;
189     Triangle thisTriangle;
190     vector<Triangle>::iterator face;
191     vector<StuntDouble*> vertexSDs;
192     vector<StuntDouble*>::iterator vertex;
193    
194     Vector3d unitNormal, centroid, facetVel;
195     Vector3d langevinForce, vertexForce;
196     Vector3d extPressure, randomForce, dragForce;
197    
198     Mat3x3d hydroTensor, S;
199     vector<Vector3d> randNums;
200    
201 gezelter 1629 // Compute surface Mesh
202     surfaceMesh_->computeHull(localSites_);
203    
204     // Get total area and number of surface stunt doubles
205 gezelter 1858 area = surfaceMesh_->getArea();
206     sMesh = surfaceMesh_->getMesh();
207     nTriangles = sMesh.size();
208 gezelter 1629
209 gezelter 1858 if (doThermalCoupling_) {
210     // Generate all of the necessary random forces
211     randNums = genTriangleForces(nTriangles, variance_);
212     }
213    
214     // Loop over the mesh faces
215     thisFacet = 0;
216 gezelter 1629 for (face = sMesh.begin(); face != sMesh.end(); ++face){
217 gezelter 1858 thisTriangle = *face;
218     vertexSDs = thisTriangle.getVertices();
219     thisArea = thisTriangle.getArea();
220     unitNormal = thisTriangle.getUnitNormal();
221     centroid = thisTriangle.getCentroid();
222     facetVel = thisTriangle.getFacetVelocity();
223     thisMass = thisTriangle.getFacetMass();
224 gezelter 1760
225 gezelter 1858 langevinForce = V3Zero;
226 gezelter 1629
227 gezelter 1858 if (doPressureCoupling_) {
228     extPressure = -unitNormal * (targetPressure_ * thisArea) /
229     PhysicalConstants::energyConvert;
230     langevinForce += extPressure;
231     }
232    
233 gezelter 1855 if (doThermalCoupling_) {
234 gezelter 1858 hydroTensor = thisTriangle.computeHydrodynamicTensor(viscosity_);
235     hydroTensor *= PhysicalConstants::viscoConvert;
236     CholeskyDecomposition(hydroTensor, S);
237 gezelter 1855 randomForce = S * randNums[thisFacet++];
238     dragForce = -hydroTensor * facetVel;
239 gezelter 1858 langevinForce += randomForce + dragForce;
240 gezelter 1855 }
241 gezelter 1629
242     // Apply triangle force to stuntdouble vertices
243     for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex){
244     if ((*vertex) != NULL){
245 gezelter 1858 vertexForce = langevinForce / RealType(3.0);
246 gezelter 1629 (*vertex)->addFrc(vertexForce);
247     }
248     }
249     }
250    
251     veloMunge->removeComDrift();
252     veloMunge->removeAngularDrift();
253    
254     Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
255 gezelter 1858 currSnapshot->setVolume(surfaceMesh_->getVolume());
256 gezelter 1856 currSnapshot->setHullVolume(surfaceMesh_->getVolume());
257 gezelter 1858 // update the bounding box for use by ForceMatrixDecomposition:
258     currSnapshot->setBoundingBox(surfaceMesh_->getBoundingBox());
259 gezelter 1629 ForceManager::postCalculation();
260     }
261    
262 gezelter 1858 vector<Vector3d> LangevinHullForceManager::genTriangleForces(int nTriangles,
263     RealType var) {
264 gezelter 1629 // zero fill the random vector before starting:
265 gezelter 1858 vector<Vector3d> gaussRand;
266 gezelter 1629 gaussRand.resize(nTriangles);
267     std::fill(gaussRand.begin(), gaussRand.end(), V3Zero);
268    
269     #ifdef IS_MPI
270     if (worldRank == 0) {
271     #endif
272     for (int i = 0; i < nTriangles; i++) {
273 gezelter 1858 gaussRand[i][0] = randNumGen_.randNorm(0.0, var);
274     gaussRand[i][1] = randNumGen_.randNorm(0.0, var);
275     gaussRand[i][2] = randNumGen_.randNorm(0.0, var);
276 gezelter 1629 }
277     #ifdef IS_MPI
278     }
279     #endif
280    
281     // push these out to the other processors
282    
283     #ifdef IS_MPI
284     if (worldRank == 0) {
285     MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles*3, MPI::REALTYPE, 0);
286     } else {
287     MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles*3, MPI::REALTYPE, 0);
288     }
289     #endif
290    
291     return gaussRand;
292     }
293     }

Properties

Name Value
svn:eol-style native
svn:executable *