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

Comparing branches/development/src/nonbonded/Electrostatic.cpp (file contents):
Revision 1787 by gezelter, Wed Aug 29 18:13:11 2012 UTC vs.
Revision 1823 by gezelter, Tue Jan 8 21:02:27 2013 UTC

# Line 106 | Line 106 | namespace OpenMD {
106      angstromToM_ = 1.0e-10;
107      debyeToCm_ = 3.33564095198e-30;
108      
109 <    // number of points for electrostatic splines
110 <    np_ = 100;
109 >    // Default number of points for electrostatic splines
110 >    np_ = 140;
111      
112      // variables to handle different summation methods for long-range
113      // electrostatics:
# Line 246 | Line 246 | namespace OpenMD {
246        b3c = (5.0 * b2c + pow(2.0*a2, 3) * expTerm * invArootPi) / r2;
247        b4c = (7.0 * b3c + pow(2.0*a2, 4) * expTerm * invArootPi) / r2;
248        b5c = (9.0 * b4c + pow(2.0*a2, 5) * expTerm * invArootPi) / r2;
249 <      selfMult_ = b0c  +  2.0 * a2 * invArootPi;
249 >      selfMult_ = b0c + a2 * invArootPi;
250      } else {
251        a2 = 0.0;
252        b0c = 1.0 / r;
# Line 279 | Line 279 | namespace OpenMD {
279      // working variables for Taylor expansion:
280      RealType rmRc, rmRc2, rmRc3, rmRc4;
281  
282 +    // Approximate using splines using a maximum of 0.1 Angstroms
283 +    // between points.
284 +    int nptest = int((cutoffRadius_ + 2.0) / 0.1);
285 +    np_ = (np_ > nptest) ? np_ : nptest;
286 +  
287      // Add a 2 angstrom safety window to deal with cutoffGroups that
288      // have charged atoms longer than the cutoffRadius away from each
289      // other.  Splining is almost certainly the best choice here.
# Line 499 | Line 504 | namespace OpenMD {
504        v33v.push_back(v33);
505        v34v.push_back(v34);
506        v35v.push_back(v35);
507 <
507 >      
508        v41v.push_back(v41);
509        v42v.push_back(v42);
510        v43v.push_back(v43);
# Line 693 | Line 698 | namespace OpenMD {
698      RealType pref;
699  
700      RealType DadDb, trQaQb, DadQbr, DbdQar;       // Cross-interaction scalars
701 +    RealType rQaQbr;
702      Vector3d DaxDb, DadQb, DbdQa, DaxQbr, DbxQar; // Cross-interaction vectors
703 <    Vector3d rQaQb, QaQbr, QaxQb;
703 >    Vector3d rQaQb, QaQbr, QaxQb, rQaxQbr;
704      Mat3x3d  QaQb;                                // Cross-interaction matrices
705  
706      RealType U(0.0);  // Potential
# Line 746 | Line 752 | namespace OpenMD {
752      // Obtain all of the required radial function values from the
753      // spline structures:
754      
755 <    if (a_is_Charge && b_is_Charge) {
756 <      v01 = v01s->getValueAt( *(idat.rij) );
755 >    // needed for fields (and forces):
756 >    if (a_is_Charge || b_is_Charge) {
757        v02 = v02s->getValueAt( *(idat.rij) );
758      }
759 <    if ((a_is_Charge && b_is_Dipole) || (b_is_Charge && a_is_Dipole)) {
754 <      v11 = v11s->getValueAt( *(idat.rij) );
759 >    if (a_is_Dipole || b_is_Dipole) {
760        v12 = v12s->getValueAt( *(idat.rij) );
761        v13 = v13s->getValueAt( *(idat.rij) );
762      }
763 <    if ((a_is_Charge && b_is_Quadrupole) ||
764 <        (b_is_Charge && a_is_Quadrupole) ||
765 <        (a_is_Dipole && b_is_Dipole)) {
763 >    if (a_is_Quadrupole || b_is_Quadrupole) {
764 >      v23 = v23s->getValueAt( *(idat.rij) );
765 >      v24 = v24s->getValueAt( *(idat.rij) );
766 >    }
767 >
768 >    // needed for potentials (and torques):
769 >    if (a_is_Charge && b_is_Charge) {
770 >      v01 = v01s->getValueAt( *(idat.rij) );
771 >    }
772 >    if ((a_is_Charge && b_is_Dipole) || (b_is_Charge && a_is_Dipole)) {
773 >      v11 = v11s->getValueAt( *(idat.rij) );
774 >    }
775 >    if ((a_is_Charge && b_is_Quadrupole) || (b_is_Charge && a_is_Quadrupole)) {
776        v21 = v21s->getValueAt( *(idat.rij) );
777        v22 = v22s->getValueAt( *(idat.rij) );
778 +    } else if (a_is_Dipole && b_is_Dipole) {
779 +      v21 = v21s->getValueAt( *(idat.rij) );
780 +      v22 = v22s->getValueAt( *(idat.rij) );
781        v23 = v23s->getValueAt( *(idat.rij) );
782        v24 = v24s->getValueAt( *(idat.rij) );
783      }
# Line 780 | Line 798 | namespace OpenMD {
798        v46 = v46s->getValueAt( *(idat.rij) );
799      }
800  
783
801      // calculate the single-site contributions (fields, etc).
802      
803      if (a_is_Charge) {
# Line 941 | Line 958 | namespace OpenMD {
958          F  -= pref * (DadDb * rhat + rdDb * D_a + rdDa * D_b)*v23;
959          F  -= pref * (rdDa * rdDb) * v24 * rhat;
960          Ta += pref * ( v21 * DaxDb - v22 * rdDb * rxDa);
961 <        Tb += pref * (-v21 * DaxDb + v22 * rdDa * rxDb);
961 >        Tb += pref * (-v21 * DaxDb - v22 * rdDa * rxDb);
962  
963          // Even if we excluded this pair from direct interactions, we
964          // still have the reaction-field-mediated dipole-dipole
# Line 995 | Line 1012 | namespace OpenMD {
1012          F  += pref * (rdDb * rdQar * rhat * v35);
1013          Ta += pref * ((-2.0*cross(DbdQa, rhat) + 2.0*DbxQar)*v31
1014                        + 2.0*rdDb*rxQar*v32);
1015 <        Tb += pref * ((trQa*rxDb + 2.0 * DbxQar)*v31 + rxDb*rdQar*v32);
1015 >        Tb += pref * ((trQa*rxDb - 2.0 * DbxQar)*v31 + rxDb*rdQar*v32);
1016        }
1017        if (b_is_Quadrupole) {
1018 <        pref = pre44_ * *(idat.electroMult);
1018 >        pref = pre44_ * *(idat.electroMult);  // yes
1019          QaQb = Q_a * Q_b;
1020          trQaQb = QaQb.trace();
1021          rQaQb = rhat * QaQb;
1022 <        QaQbr = QaQb * rhat;        
1022 >        QaQbr = QaQb * rhat;
1023          QaxQb = cross(Q_a, Q_b);
1024 <
1025 <        U  += pref * (trQa * trQb + 2.0*trQaQb) * v41;
1026 <        U  += pref * (trQa*rdQbr + trQb*rdQar  + 4.0*dot(rQa, Qbr)) * v42;
1024 >        rQaQbr = dot(rQa, Qbr);
1025 >        rQaxQbr = cross(rQa, Qbr);
1026 >        
1027 >        U  += pref * (trQa * trQb + 2.0 * trQaQb) * v41;
1028 >        U  += pref * (trQa * rdQbr + trQb * rdQar  + 4.0 * rQaQbr) * v42;
1029          U  += pref * (rdQar * rdQbr) * v43;
1030  
1031 <        F  += pref * (trQa*trQb*rhat + 2.0*trQaQb*rhat)*v44;
1032 <        F  += pref * (2.0*trQb*rQa + 2.0*trQa*rQb)*v44;
1033 <        F  += pref * (4.0* QaQb * rhat + 4.0 * rhat * QaQb)*v44;
1015 <        F  += pref * (trQa*rdQbr*rhat + trQb*rdQar*rhat
1016 <                      + 4.0*dot(rQa, Qbr)*rhat)*v45;
1017 <        F  += pref * (2.0*rQa*rdQbr + 2.0*rdQar*rQb)*v45;
1018 <        F  += pref * (rdQar*rdQbr*rhat) * v46;
1031 >        F  += pref * rhat * (trQa * trQb + 2.0 * trQaQb)*v44;
1032 >        F  += pref * rhat * (trQa * rdQbr + trQb * rdQar + 4.0 * rQaQbr)*v45;
1033 >        F  += pref * rhat * (rdQar * rdQbr)*v46;
1034  
1035 <        Ta += pref * (-4.0 * QaxQb  * v41);
1036 <        Ta += pref * (-2.0*trQb*cross(rQa, rhat)
1037 <                      + 4.0*cross(rhat, QaQbr)
1038 <                      - 4.0*cross(rQa, Qbr)) * v42;
1035 >        F  += pref * 2.0 * (trQb*rQa + trQa*rQb)*v44;
1036 >        F  += pref * 4.0 * (rQaQb + QaQbr)*v44;
1037 >        F  += pref * 2.0 * (rQa*rdQbr + rdQar*rQb)*v45;
1038 >
1039 >        Ta += pref * (- 4.0 * QaxQb * v41);
1040 >        Ta += pref * (- 2.0 * trQb * cross(rQa, rhat)
1041 >                      + 4.0 * cross(rhat, QaQbr)
1042 >                      - 4.0 * rQaxQbr) * v42;
1043          Ta += pref * 2.0 * cross(rhat,Qar) * rdQbr * v43;
1044  
1026        Tb += pref * (4.0 * QaxQb * v41);
1027        Tb += pref * (-2.0*trQa*cross(rQb, rhat)
1028                      - 4.0*cross(rQaQb, rhat)
1029                      + 4.0*cross(rQa, Qbr))*v42;
1030        Tb += pref * 2.0 * cross(rhat,Qbr) * rdQar * v43;        
1045  
1046 +        Tb += pref * (+ 4.0 * QaxQb * v41);
1047 +        Tb += pref * (- 2.0 * trQa * cross(rQb, rhat)
1048 +                      - 4.0 * cross(rQaQb, rhat)
1049 +                      + 4.0 * rQaxQbr) * v42;
1050 +        // Possible replacement for line 2 above:
1051 +        //             + 4.0 * cross(rhat, QbQar)
1052 +
1053 +        Tb += pref * 2.0 * cross(rhat,Qbr) * rdQar * v43;
1054 +
1055 +        //  cerr << " tsum = " << Ta + Tb - cross(  *(idat.d) , F ) << "\n";
1056        }
1057      }
1058  
# Line 1069 | Line 1093 | namespace OpenMD {
1093          *(idat.t2) += *(idat.sw) * indirect_Tb;
1094      }
1095      return;
1096 <  }  
1096 >  }
1097      
1098    void Electrostatic::calcSelfCorrection(SelfData &sdat) {
1099  
# Line 1112 | Line 1136 | namespace OpenMD {
1136        
1137      case esm_SHIFTED_FORCE:
1138      case esm_SHIFTED_POTENTIAL:
1139 <      if (i_is_Charge) {        
1140 <        self = -0.5 * selfMult_ * C_a * (C_a + *(sdat.skippedCharge)) * pre11_;
1139 >      if (i_is_Charge) {
1140 >        self = - selfMult_ * C_a * (C_a + *(sdat.skippedCharge)) * pre11_;
1141          (*(sdat.pot))[ELECTROSTATIC_FAMILY] += self;
1142        }
1143        break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines