ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/visitors/ZconsVisitor.cpp
Revision: 1767
Committed: Fri Jul 6 22:01:58 2012 UTC (13 years, 1 month ago) by gezelter
File size: 7947 byte(s)
Log Message:
Various fixes required to compile OpenMD with the MS Visual C++ compiler

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
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.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
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 #include "types/ZconsStamp.hpp"
48 namespace OpenMD {
49
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->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();
65 }
66
67 if (simParam->haveZconsTol()){
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 "\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->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));
86 }
87
88
89 //fill zatomToZmol_ array
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 }
100 }
101
102 zconsFilename_ = getPrefix(info_->getFinalConfigFileName()) + ".fz";
103
104 zconsReader_ = new ZConsReader(info);
105
106 if (zconsReader_->hasNextFrame())
107 zconsReader_->readNextFrame();
108
109 }
110
111 ZConsVisitor::~ZConsVisitor(){
112 if(!zconsReader_)
113 delete zconsReader_;
114
115 }
116
117 void ZConsVisitor::visit(Atom* atom){
118 std::string prefix;
119 if(isZconstraint(atom->getGlobalIndex(), prefix))
120 internalVisit(atom, prefix);
121 }
122
123 void ZConsVisitor::visit(DirectionalAtom* datom){
124 std::string prefix;
125
126 if(isZconstraint(datom->getGlobalIndex(), prefix))
127 internalVisit(datom, prefix);
128 }
129
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 }
139
140 void ZConsVisitor::update(){
141 Vector3d com;
142 std::map<int, ZConsState>::iterator i;
143 for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
144 i->second = zsMoving;
145 }
146
147 readZconsFile(currSnapshot_->getTime());
148
149 const std::vector<ZconsData>& fixedZmolData = zconsReader_->getFixedZMolData();
150 std::vector<ZconsData>::const_iterator j;
151 for (j = fixedZmolData.begin(); j != fixedZmolData.end(); ++j) {
152 std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex);
153 assert(k != zmolStates_.end());
154 k->second = zsFixed;
155 }
156
157 }
158
159 void ZConsVisitor::readZconsFile(RealType time) {
160 RealType tempTime;
161 while(zconsReader_->hasNextFrame()){
162 tempTime = zconsReader_->getCurTime();
163 if(tempTime >= time) {
164 return;
165 }
166
167 zconsReader_->readNextFrame();
168 }
169 }
170
171 void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){
172 GenericData* data;
173 AtomData* atomData;
174 AtomInfo* atomInfo;
175 std::vector<AtomInfo*>::iterator iter;
176
177 //if there is not atom data, just skip it
178 data = sd->getPropertyByName("ATOMDATA");
179 if(data != NULL){
180 atomData = dynamic_cast<AtomData*>(data);
181 if(atomData == NULL)
182 return;
183 }
184 else
185 return;
186
187 for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
188 (atomInfo->atomTypeName).insert(0, prefix);
189 }
190
191
192 bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){
193 std::string prefixString[] = {"ZF", "ZM"};
194 std::map<int, int>::iterator i = zatomToZmol_.find(atomIndex);
195 if (i == zatomToZmol_.end() ){
196 prefix = "";
197 return false;
198 } else {
199
200 std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second);
201 assert(j !=zmolStates_.end());
202 prefix = prefixString[j->second];
203 return true;
204 }
205 }
206
207 const std::string ZConsVisitor::toString(){
208 char buffer[65535];
209 std::string result;
210
211 sprintf(buffer ,"------------------------------------------------------------------\n");
212 result += buffer;
213
214 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
215 result += buffer;
216
217 sprintf(buffer , "number of zconstraint molecule: %d\n", (int) zmolStates_.size());
218 result += buffer;
219
220 sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol_);
221 result += buffer;
222
223 sprintf(buffer , "zconstraint sample time = %lf\n", zconsTime_);
224 result += buffer;
225
226 sprintf(buffer , "zconstraint output filename = %s\n", zconsFilename_.c_str());
227 result += buffer;
228
229 std::map<int, ZConsState>::iterator i;
230 int j = 0;
231 for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
232 sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first);
233 result += buffer;
234 }
235
236 sprintf(buffer ,"------------------------------------------------------------------\n");
237 result += buffer;
238
239 return result;
240 }
241
242
243 }//namespace OpenMD

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date