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

Comparing:
branches/development/src/integrators/FluctuatingChargePropagator.cpp (file contents), Revision 1718 by gezelter, Thu May 24 01:29:59 2012 UTC vs.
branches/development/src/flucq/FluctuatingChargePropagator.cpp (file contents), Revision 1739 by gezelter, Tue Jun 5 17:58:55 2012 UTC

# Line 40 | Line 40
40   * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43 < #include "FluctuatingChargePropagator.hpp"
44 < #include "primitives/Molecule.hpp"
45 < #include "utils/simError.h"
46 < #include "utils/PhysicalConstants.hpp"
43 > #include "flucq/FluctuatingChargePropagator.hpp"
44 > #include "flucq/FluctuatingChargeObjectiveFunction.hpp"
45 > #include "optimization/Constraint.hpp"
46 > #include "optimization/Problem.hpp"
47 > #include "optimization/EndCriteria.hpp"
48 > #include "optimization/StatusFunction.hpp"
49 > #include "optimization/OptimizationFactory.hpp"
50 >
51 >
52 >
53   #ifdef IS_MPI
54   #include <mpi.h>
55   #endif
56  
57 + using namespace QuantLib;
58   namespace OpenMD {
59  
60 <  void FluctuatingChargePropagator::applyConstraints() {
60 >  FluctuatingChargePropagator::FluctuatingChargePropagator(SimInfo* info,
61 >                                                           ForceManager* fm) :
62 >    info_(info), forceMan_(fm), hasFlucQ_(false) {
63 >    
64 >    if (info_->usesFluctuatingCharges()) {
65 >      if (info_->getNFluctuatingCharges() > 0) {
66 >        
67 >        hasFlucQ_ = true;
68 >        Globals* simParams = info_->getSimParams();
69 >        fqParams_ = simParams->getFluctuatingChargeParameters();
70 >        
71 >      }
72 >    }
73 >  }
74 >
75 >  void FluctuatingChargePropagator::initialize() {
76 >
77      if (!hasFlucQ_) return;
78  
79      SimInfo::MoleculeIterator i;
# Line 58 | Line 81 | namespace OpenMD {
81      Molecule* mol;
82      Atom* atom;
83      
61    RealType totalFrc, totalMolFrc, constrainedFrc;
62
63    // accumulate the total system fluctuating charge forces
64    totalFrc = 0.0;
65
84      for (mol = info_->beginMolecule(i); mol != NULL;
85           mol = info_->nextMolecule(i)) {
68
86        for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
87             atom = mol->nextFluctuatingCharge(j)) {
88 <        totalFrc += atom->getFlucQFrc();
88 >        atom->setFlucQPos(0.0);
89 >        atom->setFlucQVel(0.0);
90        }
73
91      }
92  
93 < #ifdef IS_MPI
94 <    // in parallel, we need to add up the contributions from all
95 <    // processors:
96 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &totalFrc, 1, MPI::REALTYPE,
97 <                              MPI::SUM);
98 < #endif
99 <
83 <    // divide by the total number of fluctuating charges:
84 <    totalFrc /= info_->getNFluctuatingCharges();
93 >    std::cerr << "doing a minimization\n";
94 >    
95 >    FluctuatingChargeObjectiveFunction flucQobjf(info_, forceMan_, fqConstraints_);    
96 >    DynamicVector<RealType> initCoords = flucQobjf.setInitialCoords();
97 >    Problem problem(flucQobjf, *(new NoConstraint()), *(new NoStatus()), initCoords);
98 >    EndCriteria endCriteria(1000, 100, 1e-5, 1e-5, 1e-5);      
99 >    OptimizationMethod* minim = OptimizationFactory::getInstance()->createOptimization("SD", info_);
100  
101 <    for (mol = info_->beginMolecule(i); mol != NULL;
87 <         mol = info_->nextMolecule(i)) {    
88 <      
89 <      totalMolFrc = 0.0;
101 >    minim->minimize(problem, endCriteria);
102  
103 <      // molecular constraints can be done with a second loop.
92 <      if (mol->constrainTotalCharge()) {
93 <        for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
94 <             atom = mol->nextFluctuatingCharge(j)) {
95 <          totalMolFrc += atom->getFlucQFrc();
96 <        }
97 <        totalMolFrc /= mol->getNFluctuatingCharges();
98 <      }
103 >  }
104  
105 <      for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
106 <           atom = mol->nextFluctuatingCharge(j)) {
107 <        constrainedFrc = atom->getFlucQFrc() - totalFrc - totalMolFrc;
108 <        atom->setFlucQFrc(constrainedFrc);
109 <      }      
105 <    }
105 >
106 >  void FluctuatingChargePropagator::applyConstraints() {
107 >    if (!hasFlucQ_) return;
108 >
109 >    fqConstraints_->applyConstraints();
110    }
111   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines