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 1925 by gezelter, Wed Aug 7 15:24:16 2013 UTC vs.
Revision 1969 by gezelter, Wed Feb 26 14:14:50 2014 UTC

# Line 40 | Line 40
40   * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43 + #ifdef IS_MPI
44 + #include <mpi.h>
45 + #endif
46 +
47   #include <stdio.h>
48   #include <string.h>
49  
# Line 57 | Line 61
61   #include "math/erfc.hpp"
62   #include "math/SquareMatrix.hpp"
63   #include "primitives/Molecule.hpp"
64 < #ifdef IS_MPI
61 < #include <mpi.h>
62 < #endif
64 > #include "flucq/FluctuatingChargeForces.hpp"
65  
66   namespace OpenMD {
67    
# Line 69 | Line 71 | namespace OpenMD {
71                                    haveDampingAlpha_(false),
72                                    haveDielectric_(false),
73                                    haveElectroSplines_(false)
74 <  {}
74 >  {
75 >    flucQ_ = new FluctuatingChargeForces(info_);
76 >  }
77    
78 +  void Electrostatic::setForceField(ForceField *ff) {
79 +    forceField_ = ff;
80 +    flucQ_->setForceField(forceField_);
81 +  }
82 +
83 +  void Electrostatic::setSimulatedAtomTypes(set<AtomType*> &simtypes) {
84 +    simTypes_ = simtypes;
85 +    flucQ_->setSimulatedAtomTypes(simTypes_);
86 +  }
87 +
88    void Electrostatic::initialize() {
89      
90      Globals* simParams_ = info_->getSimParams();
# Line 765 | Line 779 | namespace OpenMD {
779  
780      // Excluded potential that is still computed for fluctuating charges
781      excluded_Pot= 0.0;
768
782  
783      // some variables we'll need independent of electrostatic type:
784  
# Line 887 | Line 900 | namespace OpenMD {
900          Ea += pre14_ * (trQb * rhat * dv21 + 2.0 * Qbr * v22or
901                          + rdQbr * rhat * (dv22 - 2.0*v22or));
902      }
903 <    
903 >        
904 >
905      if ((a_is_Fluctuating || b_is_Fluctuating) && idat.excluded) {
906        J = Jij[FQtids[idat.atid1]][FQtids[idat.atid2]];
907      }    
908 <    
908 >
909      if (a_is_Charge) {    
910        
911        if (b_is_Charge) {
912          pref =  pre11_ * *(idat.electroMult);      
913          U  += C_a * C_b * pref * v01;
914          F  += C_a * C_b * pref * dv01 * rhat;
915 <        
915 >
916          // If this is an excluded pair, there are still indirect
917          // interactions via the reaction field we must worry about:
918  
# Line 907 | Line 921 | namespace OpenMD {
921            indirect_Pot += rfContrib;
922            indirect_F   += rfContrib * 2.0 * ri * rhat;
923          }
924 <        
924 >
925          // Fluctuating charge forces are handled via Coulomb integrals
926          // for excluded pairs (i.e. those connected via bonds) and
927          // with the standard charge-charge interaction otherwise.
928  
929 <        if (idat.excluded) {          
929 >        if (idat.excluded) {
930            if (a_is_Fluctuating || b_is_Fluctuating) {
931              coulInt = J->getValueAt( *(idat.rij) );
932 <            if (a_is_Fluctuating)  dUdCa += coulInt * C_b;
933 <            if (b_is_Fluctuating)  dUdCb += coulInt * C_a;
934 <            excluded_Pot += C_a * C_b * coulInt;
921 <          }          
932 >            if (a_is_Fluctuating) dUdCa += C_b * coulInt;
933 >            if (b_is_Fluctuating) dUdCb += C_a * coulInt;          
934 >          }
935          } else {
936            if (a_is_Fluctuating) dUdCa += C_b * pref * v01;
937 <          if (a_is_Fluctuating) dUdCb += C_a * pref * v01;
938 <        }
937 >          if (b_is_Fluctuating) dUdCb += C_a * pref * v01;
938 >        }              
939        }
940  
941        if (b_is_Dipole) {
# Line 988 | Line 1001 | namespace OpenMD {
1001          F  -= pref * (rdDa * rdDb) * (dv22 - 2.0*v22or) * rhat;
1002          Ta += pref * ( v21 * DaxDb - v22 * rdDb * rxDa);
1003          Tb += pref * (-v21 * DaxDb - v22 * rdDa * rxDb);
991
1004          // Even if we excluded this pair from direct interactions, we
1005          // still have the reaction-field-mediated dipole-dipole
1006          // interaction:
# Line 1048 | Line 1060 | namespace OpenMD {
1060          trQaQb = QaQb.trace();
1061          rQaQb = rhat * QaQb;
1062          QaQbr = QaQb * rhat;
1063 <        QaxQb = cross(Q_a, Q_b);
1063 >        QaxQb = mCross(Q_a, Q_b);
1064          rQaQbr = dot(rQa, Qbr);
1065          rQaxQbr = cross(rQa, Qbr);
1066          
# Line 1079 | Line 1091 | namespace OpenMD {
1091          //             + 4.0 * cross(rhat, QbQar)
1092  
1093          Tb += pref * 2.0 * cross(rhat,Qbr) * rdQar * v43;
1082
1094        }
1095      }
1096  
# Line 1142 | Line 1153 | namespace OpenMD {
1153          
1154      if (i_is_Fluctuating) {
1155        C_a += *(sdat.flucQ);
1156 <      // dVdFQ is really a force, so this is negative the derivative
1157 <      *(sdat.dVdFQ) -=  *(sdat.flucQ) * data.hardness + data.electronegativity;
1158 <      (*(sdat.excludedPot))[ELECTROSTATIC_FAMILY] += (*sdat.flucQ) *
1159 <        (*(sdat.flucQ) * data.hardness * 0.5 + data.electronegativity);
1156 >
1157 >      flucQ_->getSelfInteraction(sdat.atid, *(sdat.flucQ),  
1158 >                                 (*(sdat.excludedPot))[ELECTROSTATIC_FAMILY],
1159 >                                 *(sdat.flucQfrc) );
1160 >
1161      }
1162  
1163      switch (summationMethod_) {
# Line 1441 | Line 1453 | namespace OpenMD {
1453                    dks[i] = dk * skr[i];
1454                  }
1455                  if (data.is_Quadrupole) {
1456 <                  Q = atom->getQuadrupole();
1457 <                  Q *= mPoleConverter;
1446 <                  Qk = Q * kVec;
1456 >                  Q = atom->getQuadrupole() * mPoleConverter;
1457 >                  Qk = Q * kVec;                  
1458                    qk = dot(kVec, Qk);
1459 <                  qxk[i] = cross(kVec, Qk);
1459 >                  qxk[i] = -cross(kVec, Qk);
1460                    qkc[i] = qk * ckr[i];
1461                    qks[i] = qk * skr[i];
1462                  }              
# Line 1462 | Line 1473 | namespace OpenMD {
1473              qkss = std::accumulate(qks.begin(),qks.end(),0.0);
1474              
1475   #ifdef IS_MPI
1476 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &ckcs, 1, MPI::REALTYPE,
1477 <                                      MPI::SUM);
1478 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &ckss, 1, MPI::REALTYPE,
1479 <                                      MPI::SUM);
1480 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &dkcs, 1, MPI::REALTYPE,
1481 <                                      MPI::SUM);
1482 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &dkss, 1, MPI::REALTYPE,
1483 <                                      MPI::SUM);
1484 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &qkcs, 1, MPI::REALTYPE,
1485 <                                      MPI::SUM);
1486 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &qkss, 1, MPI::REALTYPE,
1487 <                                      MPI::SUM);
1476 >            MPI_Allreduce(MPI_IN_PLACE, &ckcs, 1, MPI_REALTYPE,
1477 >                          MPI_SUM, MPI_COMM_WORLD);
1478 >            MPI_Allreduce(MPI_IN_PLACE, &ckss, 1, MPI_REALTYPE,
1479 >                          MPI_SUM, MPI_COMM_WORLD);
1480 >            MPI_Allreduce(MPI_IN_PLACE, &dkcs, 1, MPI_REALTYPE,
1481 >                          MPI_SUM, MPI_COMM_WORLD);
1482 >            MPI_Allreduce(MPI_IN_PLACE, &dkss, 1, MPI_REALTYPE,
1483 >                          MPI_SUM, MPI_COMM_WORLD);
1484 >            MPI_Allreduce(MPI_IN_PLACE, &qkcs, 1, MPI_REALTYPE,
1485 >                          MPI_SUM, MPI_COMM_WORLD);
1486 >            MPI_Allreduce(MPI_IN_PLACE, &qkss, 1, MPI_REALTYPE,
1487 >                          MPI_SUM, MPI_COMM_WORLD);
1488   #endif        
1489              
1490              // Accumulate potential energy and virial contribution:
# Line 1504 | Line 1515 | namespace OpenMD {
1515                  RealType qtrq1 = AK[kk]*(skr[i]*(ckcs-dkss-qkcs)
1516                                           -ckr[i]*(ckss+dkcs-qkss));
1517                  RealType qtrq2 = 2.0*AK[kk]*(ckr[i]*(ckcs-dkss-qkcs)
1518 <                                             +skr[i]*(ckss+dkcs-qkss));
1518 >                                            +skr[i]*(ckss+dkcs-qkss));
1519                
1520                  atom->addFrc( 4.0 * rvol * qfrc * kVec );
1521                  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines