ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/SMIPDForceManager.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/integrators/SMIPDForceManager.cpp (file contents):
Revision 3514 by gezelter, Wed May 13 22:27:29 2009 UTC vs.
Revision 3515 by gezelter, Mon Jul 20 17:50:40 2009 UTC

# Line 41 | Line 41
41   #include <fstream>
42   #include <iostream>
43   #include "integrators/SMIPDForceManager.hpp"
44 #include "math/CholeskyDecomposition.hpp"
44   #include "utils/OOPSEConstant.hpp"
45   #include "math/ConvexHull.hpp"
46   #include "math/Triangle.hpp"
# Line 51 | Line 50 | namespace oopse {
50    SMIPDForceManager::SMIPDForceManager(SimInfo* info) : ForceManager(info) {
51  
52      simParams = info->getSimParams();
53 +    thermo = new Thermo(info);
54      veloMunge = new Velocitizer(info);
55      
56      // Create Hull, Convex Hull for now, other options later.
# Line 86 | Line 86 | namespace oopse {
86      if (simParams->getUsePeriodicBoundaryConditions()) {
87        sprintf(painCave.errMsg,
88                "SMIPDynamics error: You can't use the SMIPD integrator\n"
89 <              "   with periodic boundary conditions!\n");    
89 >              "   with periodic boundary conditions!\n");    
90        painCave.isFatal = 1;
91        simError();
92      }
93      
94 <    if (!simParams->haveViscosity()) {
94 >    if (!simParams->haveThermalConductivity()) {
95        sprintf(painCave.errMsg,
96                "SMIPDynamics error: You can't use the SMIPD integrator\n"
97 <              "   without a viscosity!\n");
97 >              "   without a thermalConductivity!\n");
98        painCave.isFatal = 1;
99        painCave.severity = OOPSE_ERROR;
100        simError();
101      }else{
102 <      viscosity_ = simParams->getViscosity();
102 >      thermalConductivity_ = simParams->getThermalConductivity();
103      }
104 +
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      
116      dt_ = simParams->getDt();
117    
# Line 139 | Line 150 | namespace oopse {
150      int nTriangles = sMesh.size();
151  
152      // Generate all of the necessary random forces
153 <    std::vector<Vector3d>  randNums = genTriangleForces(nTriangles, variance_);
153 >    std::vector<RealType>  randNums = genTriangleForces(nTriangles, variance_);
154  
155 +    RealType instaTemp = thermo->getTemperature();
156 +
157      // Loop over the mesh faces and apply external pressure to each
158      // of the faces
159      std::vector<Triangle>::iterator face;
# Line 155 | Line 168 | namespace oopse {
168        unitNormal.normalize();
169        Vector3d centroid = thisTriangle.getCentroid();
170        Vector3d facetVel = thisTriangle.getFacetVelocity();
171 +      RealType thisMass = thisTriangle.getFacetMass();
172  
173 <      Mat3x3d hydroTensor = thisTriangle.computeHydrodynamicTensor(viscosity_);
173 >      // 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  
182 <      hydroTensor *= OOPSEConstant::viscoConvert;
183 <      Mat3x3d S;
163 <      CholeskyDecomposition(hydroTensor, S);
182 >      RealType randomForce = randNums[thisFacet++] * sqrt(gamma);
183 >      RealType dragForce = -gamma * dot(facetVel, unitNormal);
184  
185 <      Vector3d extPressure = -unitNormal*(targetPressure_ * thisArea)/OOPSEConstant::energyConvert;      
186 <      Vector3d randomForce = S * randNums[thisFacet++];
187 <      Vector3d dragForce = -hydroTensor * facetVel;
168 <
169 <      Vector3d langevinForce = (extPressure + randomForce + dragForce);
170 <
185 >      Vector3d langevinForce = (extPressure + randomForce + dragForce) *
186 >        unitNormal;
187 >      
188        // Apply triangle force to stuntdouble vertices
189        for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex){
190          if ((*vertex) != NULL){
# Line 181 | Line 198 | namespace oopse {
198          }  
199        }
200      }
201 <        
201 >    
202      veloMunge->removeComDrift();
203      veloMunge->removeAngularDrift();
204 <
204 >    
205      Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
206      currSnapshot->setVolume(surfaceMesh_->getVolume());    
207      ForceManager::postCalculation(needStress);  
208    }
192
209    
210 <  std::vector<Vector3d> SMIPDForceManager::genTriangleForces(int nTriangles,
210 >  
211 >  std::vector<RealType> SMIPDForceManager::genTriangleForces(int nTriangles,
212                                                               RealType variance)
213    {
214      
215      // zero fill the random vector before starting:
216 <    std::vector<Vector3d> gaussRand;
216 >    std::vector<RealType> gaussRand;
217      gaussRand.resize(nTriangles);
218 <    std::fill(gaussRand.begin(), gaussRand.end(), V3Zero);
218 >    std::fill(gaussRand.begin(), gaussRand.end(), 0.0);
219      
220   #ifdef IS_MPI
221      if (worldRank == 0) {
222   #endif
206      RealType rx, ry, rz;
223        for (int i = 0; i < nTriangles; i++) {
224 <        rx = randNumGen_.randNorm(0.0, variance);
209 <        ry = randNumGen_.randNorm(0.0, variance);
210 <        rz = randNumGen_.randNorm(0.0, variance);
211 <        gaussRand[i][0] = rx;
212 <        gaussRand[i][1] = ry;
213 <        gaussRand[i][2] = rz;
224 >        gaussRand[i] = randNumGen_.randNorm(0.0, variance);
225        }
226   #ifdef IS_MPI
227      }
# Line 220 | Line 231 | namespace oopse {
231      
232   #ifdef IS_MPI
233      if (worldRank == 0) {
234 <      MPI_Bcast(&gaussRand[0], nTriangles*3 , MPI_REALTYPE, 0, MPI_COMM_WORLD);
234 >      MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles, MPI::REALTYPE, 0);
235      } else {
236 <      MPI_Bcast(&gaussRand[0], nTriangles*3, MPI_REALTYPE, 0, MPI_COMM_WORLD);
236 >      MPI::COMM_WORLD.Bcast(&gaussRand[0], nTriangles, MPI::REALTYPE, 0);
237      }
238   #endif
239      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines