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