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/flucq/FluctuatingChargePropagator.cpp (file contents):
Revision 1731 by gezelter, Thu May 31 12:25:30 2012 UTC vs.
Revision 1756 by gezelter, Mon Jun 18 18:23:20 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 >        fqConstraints_ = new FluctuatingChargeConstraints(info_);
71 >        
72 >      }
73 >    }
74 >  }
75 >
76 >  void FluctuatingChargePropagator::initialize() {
77 >
78      if (!hasFlucQ_) return;
79  
80      SimInfo::MoleculeIterator i;
# Line 58 | Line 82 | namespace OpenMD {
82      Molecule* mol;
83      Atom* atom;
84      
61    RealType totalFrc, totalMolFrc, constrainedFrc;
62
63    // accumulate the total system fluctuating charge forces
64    totalFrc = 0.0;
65
85      for (mol = info_->beginMolecule(i); mol != NULL;
86           mol = info_->nextMolecule(i)) {
68
87        for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
88             atom = mol->nextFluctuatingCharge(j)) {
89 <        totalFrc += atom->getFlucQFrc();
89 >        atom->setFlucQPos(0.0);
90 >        atom->setFlucQVel(0.0);
91        }
73
92      }
93  
94 < #ifdef IS_MPI
95 <    // in parallel, we need to add up the contributions from all
96 <    // processors:
97 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &totalFrc, 1, MPI::REALTYPE,
98 <                              MPI::SUM);
99 < #endif
100 <
101 <    // divide by the total number of fluctuating charges:
84 <    totalFrc /= info_->getNFluctuatingCharges();
94 >    std::cerr << "doing a minimization\n";
95 >    
96 >    fqConstraints_ = new FluctuatingChargeConstraints(info_);
97 >    FluctuatingChargeObjectiveFunction flucQobjf(info_, forceMan_, fqConstraints_);    
98 >    DynamicVector<RealType> initCoords = flucQobjf.setInitialCoords();
99 >    Problem problem(flucQobjf, *(new NoConstraint()), *(new NoStatus()), initCoords);
100 >    EndCriteria endCriteria(1000, 100, 1e-5, 1e-5, 1e-5);      
101 >    OptimizationMethod* minim = OptimizationFactory::getInstance()->createOptimization("SD", info_);
102  
103 <    for (mol = info_->beginMolecule(i); mol != NULL;
87 <         mol = info_->nextMolecule(i)) {    
88 <      
89 <      totalMolFrc = 0.0;
103 >    DumpStatusFunction dsf(info_);                           // we want a dump file written every iteration
104  
105 <      // molecular constraints can be done with a second loop.
106 <      if (mol->constrainTotalCharge()) {
107 <        for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
108 <             atom = mol->nextFluctuatingCharge(j)) {
95 <          totalMolFrc += atom->getFlucQFrc();
96 <        }
97 <        totalMolFrc /= mol->getNFluctuatingCharges();
98 <      }
99 <
105 >    minim->minimize(problem, endCriteria);
106 >    cerr << "Finished minimization\n";
107 >    for (mol = info_->beginMolecule(i); mol != NULL;
108 >         mol = info_->nextMolecule(i)) {
109        for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
110             atom = mol->nextFluctuatingCharge(j)) {
111 <        constrainedFrc = atom->getFlucQFrc() - totalFrc - totalMolFrc;
112 <        atom->setFlucQFrc(constrainedFrc);
104 <      }      
111 >        cerr << atom->getType() << "\tQ Pos: " << atom->getFlucQPos() << "\n";
112 >      }
113      }
114 +    // std::cerr << "after minim\n";
115 +    // for (mol = info_->beginMolecule(i); mol != NULL;
116 +    //      mol = info_->nextMolecule(i)) {
117 +    //   for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
118 +    //        atom = mol->nextFluctuatingCharge(j)) {
119 +    //     cerr << "q = " << atom->getFlucQPos(0.0) << "\n";
120 +    //   }
121 +    // }
122 +
123 +
124    }
125 +
126 +
127 +  void FluctuatingChargePropagator::applyConstraints() {
128 +    if (!hasFlucQ_) return;
129 +
130 +    fqConstraints_->applyConstraints();
131 +  }
132   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines