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

Comparing:
trunk/src/visitors/ZconsVisitor.cpp (file contents), Revision 407 by gezelter, Tue Mar 8 21:07:49 2005 UTC vs.
branches/development/src/visitors/ZconsVisitor.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <cmath>
44   #include "visitors/ZconsVisitor.hpp"
45   #include "primitives/Molecule.hpp"
46   #include "utils/StringUtils.hpp"
47 < namespace oopse {
47 > #include "types/ZconsStamp.hpp"
48 > namespace OpenMD {
49  
50 < ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){
50 >  ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){
51  
52      visitorName = "ZConsVisitor";
53      currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
54      Globals* simParam = info_->getSimParams();
55  
56 <    if (simParam->haveZconstraintTime()){
57 <        zconsTime_ = simParam->getZconsTime();
56 >    if (simParam->haveZconsTime()){
57 >      zconsTime_ = simParam->getZconsTime();
58      }
59      else{
60 <        sprintf(painCave.errMsg,
61 <        "ZConstraint error: If you use a ZConstraint,\n"
62 <        "\tyou must set zconsTime.\n");
63 <        painCave.isFatal = 1;
64 <        simError();
60 >      sprintf(painCave.errMsg,
61 >              "ZConstraint error: If you use a ZConstraint,\n"
62 >              "\tyou must set zconsTime.\n");
63 >      painCave.isFatal = 1;
64 >      simError();
65      }
66  
67      if (simParam->haveZconsTol()){
68 <        zconsTol_ = simParam->getZconsTol();
68 >      zconsTol_ = simParam->getZconsTol();
69      }
70      else{
71 <        zconsTol_ = 0.01;
72 <        sprintf(painCave.errMsg,
73 <            "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
74 <            "\tOOPSE will use a default value of %f.\n"
75 <            "\tTo set the tolerance, use the zconsTol variable.\n",
76 <            zconsTol_);
77 <        painCave.isFatal = 0;
78 <        simError();      
71 >      zconsTol_ = 0.01;
72 >      sprintf(painCave.errMsg,
73 >              "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
74 >              "\tOpenMD will use a default value of %f.\n"
75 >              "\tTo set the tolerance, use the zconsTol variable.\n",
76 >              zconsTol_);
77 >      painCave.isFatal = 0;
78 >      simError();      
79      }    
80          
81 <    int nZconstraints = simParam->getNzConstraints();
82 <    ZconStamp** stamp = simParam->getZconStamp();
81 >    int nZconstraints = simParam->getNZconsStamps();
82 >    std::vector<ZConsStamp*> stamp = simParam->getZconsStamps();
83      for (int i = 0; i < nZconstraints; i++){
84 <        int zmolIndex = stamp[i]->getMolIndex();
85 <        zmolStates_.insert(std::make_pair(zmolIndex, zsMoving));
84 >      int zmolIndex = stamp[i]->getMolIndex();
85 >      zmolStates_.insert(std::make_pair(zmolIndex, zsMoving));
86      }
87  
88  
# Line 88 | Line 90 | ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisito
90      /** @todo only works for single version now*/
91      std::map<int, ZConsState>::iterator j;
92      for (j = zmolStates_.begin(); j != zmolStates_.end(); ++j) {
93 <        Molecule* mol = info_->getMoleculeByGlobalIndex(j->first);
94 <        assert(mol != NULL);
95 <        Molecule::AtomIterator ai;
96 <        Atom* at;
97 <        for (at = mol->beginAtom(ai); at != NULL; at = mol->nextAtom(ai)) {
98 <            zatomToZmol_.insert(std::make_pair(at->getGlobalIndex(), mol->getGlobalIndex()));
99 <        }
93 >      Molecule* mol = info_->getMoleculeByGlobalIndex(j->first);
94 >      assert(mol != NULL);
95 >      Molecule::AtomIterator ai;
96 >      Atom* at;
97 >      for (at = mol->beginAtom(ai); at != NULL; at = mol->nextAtom(ai)) {
98 >        zatomToZmol_.insert(std::make_pair(at->getGlobalIndex(), mol->getGlobalIndex()));
99 >      }
100      }
101  
102      zconsFilename_ = getPrefix(info_->getFinalConfigFileName()) + ".fz";
# Line 102 | Line 104 | ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisito
104      zconsReader_ = new ZConsReader(info);
105  
106      if (zconsReader_->hasNextFrame())
107 <        zconsReader_->readNextFrame();
107 >      zconsReader_->readNextFrame();
108    
109 < }
109 >  }
110  
111 < ZConsVisitor::~ZConsVisitor(){
112 <  if(!zconsReader_)
113 <    delete zconsReader_;
111 >  ZConsVisitor::~ZConsVisitor(){
112 >    if(!zconsReader_)
113 >      delete zconsReader_;
114    
115 < }
115 >  }
116  
117 < void ZConsVisitor::visit(Atom* atom){
117 >  void ZConsVisitor::visit(Atom* atom){
118      std::string prefix;
119      if(isZconstraint(atom->getGlobalIndex(), prefix))
120 <        internalVisit(atom, prefix);
121 < }
120 >      internalVisit(atom, prefix);
121 >  }
122  
123 < void ZConsVisitor::visit(DirectionalAtom* datom){
123 >  void ZConsVisitor::visit(DirectionalAtom* datom){
124      std::string prefix;
125  
126      if(isZconstraint(datom->getGlobalIndex(), prefix))
127 <        internalVisit(datom, prefix);
128 < }
127 >      internalVisit(datom, prefix);
128 >  }
129  
130 < void ZConsVisitor::visit(RigidBody* rb){
130 >  void ZConsVisitor::visit(RigidBody* rb){
131      std::string prefix;
132      std::vector<Atom*> atoms;
133  
134      atoms = rb->getAtoms();
135  
136      if(isZconstraint(atoms[0]->getGlobalIndex(), prefix))
137 <        internalVisit(rb, prefix);
138 < }
137 >      internalVisit(rb, prefix);
138 >  }
139  
140 < void ZConsVisitor::update(){
140 >  void ZConsVisitor::update(){
141      Molecule* mol;
142      Vector3d com;
143      ZConsState state;
144      std::map<int, ZConsState>::iterator i;
145      for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
146 <        i->second = zsMoving;
146 >      i->second = zsMoving;
147      }
148      
149      readZconsFile(currSnapshot_->getTime());
# Line 149 | Line 151 | void ZConsVisitor::update(){
151      const std::vector<ZconsData>& fixedZmolData = zconsReader_->getFixedZMolData();
152      std::vector<ZconsData>::const_iterator j;
153      for (j = fixedZmolData.begin(); j != fixedZmolData.end(); ++j) {
154 <        std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex);
155 <        assert(k != zmolStates_.end());
156 <        k->second = zsFixed;
154 >      std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex);
155 >      assert(k != zmolStates_.end());
156 >      k->second = zsFixed;
157      }
158      
159 < }
159 >  }
160  
161 < void ZConsVisitor::readZconsFile(double time) {
162 <    double tempTime;
161 >  void ZConsVisitor::readZconsFile(RealType time) {
162 >    RealType tempTime;
163      while(zconsReader_->hasNextFrame()){
164 <        tempTime = zconsReader_->getCurTime();
165 <        if(tempTime >= time) {
166 <            return;
167 <        }
164 >      tempTime = zconsReader_->getCurTime();
165 >      if(tempTime >= time) {
166 >        return;
167 >      }
168          
169 <        zconsReader_->readNextFrame();
169 >      zconsReader_->readNextFrame();
170      }
171 < }
171 >  }
172  
173 < void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){
173 >  void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){
174      GenericData* data;
175      AtomData* atomData;
176      AtomInfo* atomInfo;
# Line 177 | Line 179 | void ZConsVisitor::internalVisit(StuntDouble* sd, cons
179      //if there is not atom data, just skip it
180      data = sd->getPropertyByName("ATOMDATA");
181      if(data != NULL){
182 <        atomData = dynamic_cast<AtomData*>(data);  
183 <        if(atomData == NULL)
184 <            return;
185 <        }
182 >      atomData = dynamic_cast<AtomData*>(data);  
183 >      if(atomData == NULL)
184 >        return;
185 >    }
186      else
187 <        return;
187 >      return;
188  
189      for(atomInfo  = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
190 <        (atomInfo->atomTypeName).insert(0, prefix);
191 < }
190 >      (atomInfo->atomTypeName).insert(0, prefix);
191 >  }
192  
193  
194 < bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){
194 >  bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){
195      std::string prefixString[] = {"ZF", "ZM"};
196      std::map<int, int>::iterator i = zatomToZmol_.find(atomIndex);
197      if (i ==  zatomToZmol_.end() ){
198 <        prefix = "";
199 <        return false;
198 >      prefix = "";
199 >      return false;
200      } else {
201  
202 <        std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second);
203 <        assert(j !=zmolStates_.end());
204 <        prefix = prefixString[j->second];
205 <        return true;
202 >      std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second);
203 >      assert(j !=zmolStates_.end());
204 >      prefix = prefixString[j->second];
205 >      return true;
206      }
207 < }
207 >  }
208  
209 < const std::string ZConsVisitor::toString(){
209 >  const std::string ZConsVisitor::toString(){
210      char buffer[65535];
211      std::string result;
212  
# Line 214 | Line 216 | const std::string ZConsVisitor::toString(){
216      sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
217      result += buffer;
218  
219 <    sprintf(buffer , "number of zconstraint molecule: %d\n", zmolStates_.size());
219 >    sprintf(buffer , "number of zconstraint molecule: %d\n", (int) zmolStates_.size());
220      result += buffer;
221  
222      sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol_);
# Line 229 | Line 231 | const std::string ZConsVisitor::toString(){
231      std::map<int, ZConsState>::iterator i;
232      int j = 0;
233      for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
234 <        sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first);
235 <        result += buffer;
234 >      sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first);
235 >      result += buffer;
236      }
237    
238      sprintf(buffer ,"------------------------------------------------------------------\n");
239      result += buffer;
240  
241      return result;
242 < }
242 >  }
243  
244  
245 < }//namespace oopse
245 > }//namespace OpenMD

Comparing:
trunk/src/visitors/ZconsVisitor.cpp (property svn:keywords), Revision 407 by gezelter, Tue Mar 8 21:07:49 2005 UTC vs.
branches/development/src/visitors/ZconsVisitor.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines