ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/visitors/ZconsVisitor.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 8 months ago) by gezelter
File size: 7988 byte(s)
Log Message:
updated copyright notices

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 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;
147 }
148
149 readZconsFile(currSnapshot_->getTime());
150
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;
157 }
158
159 }
160
161 void ZConsVisitor::readZconsFile(RealType time) {
162 RealType tempTime;
163 while(zconsReader_->hasNextFrame()){
164 tempTime = zconsReader_->getCurTime();
165 if(tempTime >= time) {
166 return;
167 }
168
169 zconsReader_->readNextFrame();
170 }
171 }
172
173 void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){
174 GenericData* data;
175 AtomData* atomData;
176 AtomInfo* atomInfo;
177 std::vector<AtomInfo*>::iterator iter;
178
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 }
186 else
187 return;
188
189 for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
190 (atomInfo->atomTypeName).insert(0, prefix);
191 }
192
193
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;
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;
206 }
207 }
208
209 const std::string ZConsVisitor::toString(){
210 char buffer[65535];
211 std::string result;
212
213 sprintf(buffer ,"------------------------------------------------------------------\n");
214 result += buffer;
215
216 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
217 result += buffer;
218
219 sprintf(buffer , "number of zconstraint molecule: %d\n", (int) zmolStates_.size());
220 result += buffer;
221
222 sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol_);
223 result += buffer;
224
225 sprintf(buffer , "zconstraint sample time = %lf\n", zconsTime_);
226 result += buffer;
227
228 sprintf(buffer , "zconstraint output filename = %s\n", zconsFilename_.c_str());
229 result += buffer;
230
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;
236 }
237
238 sprintf(buffer ,"------------------------------------------------------------------\n");
239 result += buffer;
240
241 return result;
242 }
243
244
245 }//namespace OpenMD

Properties

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