ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/nonbonded/Electrostatic.cpp
(Generate patch)

Comparing trunk/src/nonbonded/Electrostatic.cpp (file contents):
Revision 1915 by gezelter, Mon Jul 29 17:55:17 2013 UTC vs.
Revision 1923 by gezelter, Mon Aug 5 16:13:46 2013 UTC

# Line 677 | Line 677 | namespace OpenMD {
677        FQtids[atid] = fqtid;
678        Jij[fqtid].resize(nFlucq_);
679  
680 <      // Now, iterate over all known fluctuating and add to the coulomb integral map:
680 >      // Now, iterate over all known fluctuating and add to the
681 >      // coulomb integral map:
682        
683        std::set<int>::iterator it;
684        for( it = FQtypes.begin(); it != FQtypes.end(); ++it) {    
# Line 1165 | Line 1166 | namespace OpenMD {
1166      case esm_SHIFTED_FORCE:
1167      case esm_SHIFTED_POTENTIAL:
1168      case esm_TAYLOR_SHIFTED:
1169 +    case esm_EWALD_FULL:
1170        if (i_is_Charge)
1171          self += selfMult1_ * pre11_ * C_a * (C_a + *(sdat.skippedCharge));      
1172        if (i_is_Dipole)
# Line 1192 | Line 1194 | namespace OpenMD {
1194    }
1195  
1196  
1197 <  void Electrostatic::ReciprocalSpaceSum () {
1197 >  void Electrostatic::ReciprocalSpaceSum(potVec& pot) {
1198      
1199      RealType kPot = 0.0;
1200      RealType kVir = 0.0;
# Line 1217 | Line 1219 | namespace OpenMD {
1219      Vector3d box = hmat.diagonals();
1220      RealType boxMax = box.max();
1221      
1222 <    //int kMax = int(pow(dampingAlpha_,2)*cutoffRadius_ * boxMax / M_PI);
1223 <    const int kMax = 5;
1222 >    //int kMax = int(2.0 * M_PI / (pow(dampingAlpha_,2)*cutoffRadius_ * boxMax) );
1223 >    int kMax = 7;
1224      int kSqMax = kMax*kMax + 2;
1225      
1226      int kLimit = kMax+1;
# Line 1252 | Line 1254 | namespace OpenMD {
1254      
1255      Vector3d t( 2.0 * M_PI );
1256      t.Vdiv(t, box);
1257 +
1258      
1259      SimInfo::MoleculeIterator mi;
1260      Molecule::AtomIterator ai;
# Line 1260 | Line 1263 | namespace OpenMD {
1263      Vector3d tt;
1264      Vector3d w;
1265      Vector3d u;
1266 +    Vector3d a;
1267 +    Vector3d b;
1268      
1269      for (Molecule* mol = info_->beginMolecule(mi); mol != NULL;
1270           mol = info_->nextMolecule(mi)) {
# Line 1271 | Line 1276 | namespace OpenMD {
1276          info_->getSnapshotManager()->getCurrentSnapshot()->wrapVector(r);
1277          
1278          tt.Vmul(t, r);
1279 +
1280          
1281          eCos[1][i] = Vector3d(1.0, 1.0, 1.0);
1282          eSin[1][i] = Vector3d(0.0, 0.0, 0.0);
1283          eCos[2][i] = Vector3d(cos(tt.x()), cos(tt.y()), cos(tt.z()));
1284          eSin[2][i] = Vector3d(sin(tt.x()), sin(tt.y()), sin(tt.z()));
1285 <        u = 2.0 * eCos[1][i];
1286 <        eCos[3][i].Vmul(u, eCos[2][i]);
1287 <        eSin[3][i].Vmul(u, eSin[2][i]);      
1285 >
1286 >        u = eCos[2][i];
1287 >        w = eSin[2][i];
1288          
1289          for(int l = 3; l <= kLimit; l++) {
1290 <          w.Vmul(u, eCos[l-1][i]);
1291 <          eCos[l][i] = w - eCos[l-2][i];
1292 <          w.Vmul(u, eSin[l-1][i]);
1293 <          eSin[l][i] = w - eSin[l-2][i];
1290 >          eCos[l][i].x() = eCos[l-1][i].x()*eCos[2][i].x() - eSin[l-1][i].x()*eSin[2][i].x();
1291 >          eCos[l][i].y() = eCos[l-1][i].y()*eCos[2][i].y() - eSin[l-1][i].y()*eSin[2][i].y();
1292 >          eCos[l][i].z() = eCos[l-1][i].z()*eCos[2][i].z() - eSin[l-1][i].z()*eSin[2][i].z();
1293 >          
1294 >          eSin[l][i].x() = eSin[l-1][i].x()*eCos[2][i].x() + eCos[l-1][i].x()*eSin[2][i].x();
1295 >          eSin[l][i].y() = eSin[l-1][i].y()*eCos[2][i].y() + eCos[l-1][i].y()*eSin[2][i].y();
1296 >          eSin[l][i].z() = eSin[l-1][i].z()*eCos[2][i].z() + eCos[l-1][i].z()*eSin[2][i].z();
1297 >
1298 >
1299 >          // a.Vmul(eCos[l-1][i], u);
1300 >          // b.Vmul(eSin[l-1][i], w);
1301 >          // eCos[l][i] = a - b;
1302 >          // a.Vmul(eSin[l-1][i], u);
1303 >          // b.Vmul(eCos[l-1][i], w);
1304 >          // eSin[l][i] = a + b;
1305 >        
1306          }
1307        }
1308      }
# Line 1332 | Line 1350 | namespace OpenMD {
1350      int mMin = kLimit;
1351      int nMin = kLimit + 1;
1352      for (int l = 1; l <= kLimit; l++) {
1353 <      int ll =l - 1;
1353 >      int ll = l - 1;
1354        RealType rl = xcl * float(ll);
1355        for (int mmm = mMin; mmm <= kLim2; mmm++) {
1356          int mm = mmm - kLimit;
# Line 1348 | Line 1366 | namespace OpenMD {
1366              if(mm < 0) {
1367                clm[i] = eCos[l][i].x()*eCos[m][i].y()
1368                       + eSin[l][i].x()*eSin[m][i].y();
1369 <              slm[i] = eCos[l][i].x()*eCos[m][i].y()
1369 >              slm[i] = eSin[l][i].x()*eCos[m][i].y()
1370                       - eSin[m][i].y()*eCos[l][i].x();
1371              } else {
1372                clm[i] = eCos[l][i].x()*eCos[m][i].y()
1373                       - eSin[l][i].x()*eSin[m][i].y();
1374                slm[i] = eSin[l][i].x()*eCos[m][i].y()
1375 <                     + eSin[m][i].y()*eCos[l][i].x();
1375 >                     + eSin[m][i].y()*eCos[l][i].x();              
1376              }
1377            }
1378          }
# Line 1390 | Line 1408 | namespace OpenMD {
1408                   mol = info_->nextMolecule(mi)) {
1409                for(Atom* atom = mol->beginAtom(ai); atom != NULL;
1410                    atom = mol->nextAtom(ai)) {
1411 <                i = atom->getGlobalIndex();
1411 >                i = atom->getLocalIndex();
1412                  int atid = atom->getAtomType()->getIdent();
1413                  ElectrostaticAtomData data = ElectrostaticMap[Etids[atid]];
1414                                
# Line 1398 | Line 1416 | namespace OpenMD {
1416                    RealType C = data.fixedCharge;
1417                    if (atom->isFluctuatingCharge()) C += atom->getFlucQPos();
1418                    ckc[i] = C * ckr[i];
1419 <                  cks[i] = C * cks[i];
1419 >                  cks[i] = C * skr[i];
1420                  }
1421                  
1422                  if (data.is_Dipole) {
# Line 1418 | Line 1436 | namespace OpenMD {
1436                  }              
1437                }
1438              }
1439 <            
1439 >
1440              // calculate vector sums
1441              
1442              RealType ckcs = std::accumulate(ckc.begin(),ckc.end(),0.0);
# Line 1427 | Line 1445 | namespace OpenMD {
1445              RealType dkss = std::accumulate(dks.begin(),dks.end(),0.0);
1446              RealType qkcs = std::accumulate(qkc.begin(),qkc.end(),0.0);
1447              RealType qkss = std::accumulate(qks.begin(),qks.end(),0.0);
1448 +
1449              
1450   #ifdef IS_MPI
1451              MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &ckcs, 1, MPI::REALTYPE,
# Line 1444 | Line 1463 | namespace OpenMD {
1463   #endif        
1464              
1465              // Accumulate potential energy and virial contribution:
1466 <            
1448 <            //cerr << "l, m, n = " << l << " " << m << " " << n << "\n";
1449 <            cerr << "kVec = " << kVec << "\n";
1450 <            cerr << "ckss = " << ckss << " ckcs = " << ckcs << "\n";
1466 >
1467              kPot += 2.0 * rvol * AK[kk]*((ckss+dkcs-qkss)*(ckss+dkcs-qkss)
1468                                           + (ckcs-dkss-qkcs)*(ckcs-dkss-qkss));
1469 <            //cerr << "kspace pot = " << kPot << "\n";
1469 >
1470              kVir -= 2.0 * rvol * AK[kk]*(ckcs*ckcs+ckss*ckss
1471                                           +4.0*(ckss*dkcs-ckcs*dkss)
1472                                           +3.0*(dkcs*dkcs+dkss*dkss)
# Line 1470 | Line 1486 | namespace OpenMD {
1486                  ElectrostaticAtomData data = ElectrostaticMap[Etids[atid]];
1487                  
1488                  RealType qfrc = AK[kk]*((cks[i]+dkc[i]-qks[i])*(ckcs-dkss-qkcs)
1489 <                                        - (ckc[i]-dks[i]-qkc[i])*(ckss+dkcs-qkss));
1489 >                                     - (ckc[i]-dks[i]-qkc[i])*(ckss+dkcs-qkss));
1490                  RealType qtrq1 = AK[kk]*(skr[i]*(ckcs-dkss-qkcs)
1491                                           -ckr[i]*(ckss+dkcs-qkss));
1492                  RealType qtrq2 = 2.0*AK[kk]*(ckr[i]*(ckcs-dkss-qkcs)+
1493                                               skr[i]*(ckss+dkcs-qkss));
1494 <                
1479 <                
1494 >              
1495                  atom->addFrc( 4.0 * rvol * qfrc * kVec );
1496                  
1497                  if (data.is_Dipole) {
# Line 1489 | Line 1504 | namespace OpenMD {
1504              }
1505            }
1506          }
1507 +        nMin = 1;
1508        }
1509 +      mMin = 1;
1510      }
1511 +    cerr << "kPot = " << kPot << "\n";
1512 +    pot[ELECTROSTATIC_FAMILY] += kPot;  
1513    }
1514   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines