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 1933 by gezelter, Fri Aug 23 15:59:23 2013 UTC vs.
Revision 1981 by gezelter, Mon Apr 14 18:32:51 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 1139 | Line 1153 | namespace OpenMD {
1153          
1154      if (i_is_Fluctuating) {
1155        C_a += *(sdat.flucQ);
1156 <      *(sdat.flucQfrc) -=  *(sdat.flucQ) * data.hardness + data.electronegativity;
1157 <      (*(sdat.excludedPot))[ELECTROSTATIC_FAMILY] += (*sdat.flucQ) *
1158 <        (*(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 1244 | Line 1260 | namespace OpenMD {
1260      vector<vector<RealType> > els;
1261      vector<vector<RealType> > ems;
1262      vector<vector<RealType> > ens;
1247
1263      
1264      int nMax = info_->getNAtoms();
1265      
# Line 1267 | Line 1282 | namespace OpenMD {
1282      Vector3d t( 2.0 * M_PI );
1283      t.Vdiv(t, box);
1284  
1270    
1285      SimInfo::MoleculeIterator mi;
1286      Molecule::AtomIterator ai;
1287      int i;
# Line 1440 | Line 1454 | namespace OpenMD {
1454                    Q = atom->getQuadrupole() * mPoleConverter;
1455                    Qk = Q * kVec;                  
1456                    qk = dot(kVec, Qk);
1457 <                  qxk[i] = cross(kVec, Qk);
1457 >                  qxk[i] = -cross(kVec, Qk);
1458                    qkc[i] = qk * ckr[i];
1459                    qks[i] = qk * skr[i];
1460                  }              
# Line 1457 | Line 1471 | namespace OpenMD {
1471              qkss = std::accumulate(qks.begin(),qks.end(),0.0);
1472              
1473   #ifdef IS_MPI
1474 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &ckcs, 1, MPI::REALTYPE,
1475 <                                      MPI::SUM);
1476 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &ckss, 1, MPI::REALTYPE,
1477 <                                      MPI::SUM);
1478 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &dkcs, 1, MPI::REALTYPE,
1479 <                                      MPI::SUM);
1480 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &dkss, 1, MPI::REALTYPE,
1481 <                                      MPI::SUM);
1482 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &qkcs, 1, MPI::REALTYPE,
1483 <                                      MPI::SUM);
1484 <            MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &qkss, 1, MPI::REALTYPE,
1485 <                                      MPI::SUM);
1474 >            MPI_Allreduce(MPI_IN_PLACE, &ckcs, 1, MPI_REALTYPE,
1475 >                          MPI_SUM, MPI_COMM_WORLD);
1476 >            MPI_Allreduce(MPI_IN_PLACE, &ckss, 1, MPI_REALTYPE,
1477 >                          MPI_SUM, MPI_COMM_WORLD);
1478 >            MPI_Allreduce(MPI_IN_PLACE, &dkcs, 1, MPI_REALTYPE,
1479 >                          MPI_SUM, MPI_COMM_WORLD);
1480 >            MPI_Allreduce(MPI_IN_PLACE, &dkss, 1, MPI_REALTYPE,
1481 >                          MPI_SUM, MPI_COMM_WORLD);
1482 >            MPI_Allreduce(MPI_IN_PLACE, &qkcs, 1, MPI_REALTYPE,
1483 >                          MPI_SUM, MPI_COMM_WORLD);
1484 >            MPI_Allreduce(MPI_IN_PLACE, &qkss, 1, MPI_REALTYPE,
1485 >                          MPI_SUM, MPI_COMM_WORLD);
1486   #endif        
1487              
1488              // Accumulate potential energy and virial contribution:
# Line 1502 | Line 1516 | namespace OpenMD {
1516                                              +skr[i]*(ckss+dkcs-qkss));
1517                
1518                  atom->addFrc( 4.0 * rvol * qfrc * kVec );
1519 <                
1519 >
1520 >                if (atom->isFluctuatingCharge()) {
1521 >                  atom->addFlucQFrc( - 2.0 * rvol * qtrq2 );
1522 >                }
1523 >                  
1524                  if (data.is_Dipole) {
1525                    atom->addTrq( 4.0 * rvol * qtrq1 * dxk[i] );
1526                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines