ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/visitors/AtomVisitor.cpp
Revision: 1873
Committed: Fri May 10 16:09:34 2013 UTC (11 years, 11 months ago) by gezelter
File size: 6938 byte(s)
Log Message:
Fixed a bug when there's no electric field being calculated.

File Contents

# User Rev Content
1 gezelter 507 /*
2 gezelter 246 * 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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 gezelter 246 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 gezelter 246 * 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 gezelter 1390 *
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 gezelter 1850 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 246 */
42    
43 gezelter 2 #include <cstring>
44 tim 3 #include "visitors/AtomVisitor.hpp"
45     #include "primitives/DirectionalAtom.hpp"
46     #include "primitives/RigidBody.hpp"
47 gezelter 1871 #include "types/FixedChargeAdapter.hpp"
48     #include "types/FluctuatingChargeAdapter.hpp"
49 gezelter 1787 #include "types/MultipoleAdapter.hpp"
50     #include "types/GayBerneAdapter.hpp"
51 gezelter 2
52 gezelter 1390 namespace OpenMD {
53 gezelter 1873
54     BaseAtomVisitor::BaseAtomVisitor(SimInfo* info) : BaseVisitor() {
55     storageLayout_ = info->getStorageLayout();
56     }
57    
58 gezelter 507 void BaseAtomVisitor::visit(RigidBody *rb) {
59     //vector<Atom*> myAtoms;
60     //vector<Atom*>::iterator atomIter;
61 tim 132
62 gezelter 507 //myAtoms = rb->getAtoms();
63 gezelter 2
64 gezelter 507 //for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
65     // (*atomIter)->accept(this);
66     }
67 gezelter 2
68 gezelter 507 void BaseAtomVisitor::setVisited(Atom *atom) {
69 gezelter 246 GenericData *data;
70     data = atom->getPropertyByName("VISITED");
71 gezelter 2
72 gezelter 246 //if visited property is not existed, add it as new property
73     if (data == NULL) {
74 gezelter 507 data = new GenericData();
75     data->setID("VISITED");
76     atom->addProperty(data);
77 gezelter 246 }
78 gezelter 507 }
79 gezelter 2
80 gezelter 507 bool BaseAtomVisitor::isVisited(Atom *atom) {
81 gezelter 246 GenericData *data;
82     data = atom->getPropertyByName("VISITED");
83     return data == NULL ? false : true;
84 gezelter 507 }
85 gezelter 2
86 gezelter 1455 //------------------------------------------------------------------------//
87    
88 gezelter 507 void DefaultAtomVisitor::visit(Atom *atom) {
89 gezelter 246 AtomData *atomData;
90     AtomInfo *atomInfo;
91 gezelter 1871 AtomType* atype = atom->getAtomType();
92    
93 gezelter 246 if (isVisited(atom))
94 gezelter 507 return;
95 gezelter 1455
96 gezelter 246 atomInfo = new AtomInfo;
97 gezelter 407 atomInfo->atomTypeName = atom->getType();
98 gezelter 1871 atomInfo->pos = atom->getPos();
99     atomInfo->vel = atom->getVel();
100     atomInfo->frc = atom->getFrc();
101     atomInfo->vec = V3Zero;
102 gezelter 1456 atomInfo->hasVelocity = true;
103     atomInfo->hasForce = true;
104 gezelter 1871
105     FixedChargeAdapter fca = FixedChargeAdapter(atype);
106     if ( fca.isFixedCharge() ) {
107     atomInfo->hasCharge = true;
108     atomInfo->charge = fca.getCharge();
109     }
110    
111     FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype);
112     if ( fqa.isFluctuatingCharge() ) {
113     atomInfo->hasCharge = true;
114     atomInfo->charge += atom->getFlucQPos();
115     }
116 gezelter 1873
117     if ((storageLayout_ & DataStorage::dslElectricField) &&
118     (atype->isElectrostatic())) {
119 gezelter 1871 atomInfo->hasElectricField = true;
120     atomInfo->eField = atom->getElectricField();
121     }
122    
123     atomData = new AtomData;
124     atomData->setID("ATOMDATA");
125 gezelter 246 atomData->addAtomInfo(atomInfo);
126 gezelter 1455
127 gezelter 246 atom->addProperty(atomData);
128 gezelter 1455
129 gezelter 246 setVisited(atom);
130 gezelter 507 }
131 gezelter 1455
132 gezelter 507 void DefaultAtomVisitor::visit(DirectionalAtom *datom) {
133 gezelter 246 AtomData *atomData;
134     AtomInfo *atomInfo;
135 gezelter 1871 AtomType* atype = datom->getAtomType();
136 gezelter 2
137 gezelter 246 if (isVisited(datom))
138 gezelter 507 return;
139 gezelter 1456
140 gezelter 1871 atomInfo = new AtomInfo;
141     atomInfo->atomTypeName = datom->getType();
142     atomInfo->pos = datom->getPos();
143     atomInfo->vel = datom->getVel();
144     atomInfo->frc = datom->getFrc();
145     atomInfo->hasVelocity = true;
146     atomInfo->hasForce = true;
147 gezelter 1787
148 gezelter 1871 FixedChargeAdapter fca = FixedChargeAdapter(atype);
149     if ( fca.isFixedCharge() ) {
150     atomInfo->hasCharge = true;
151     atomInfo->charge = fca.getCharge();
152     }
153    
154     FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype);
155     if ( fqa.isFluctuatingCharge() ) {
156     atomInfo->hasCharge = true;
157     atomInfo->charge += datom->getFlucQPos();
158     }
159    
160 gezelter 1873 if ((storageLayout_ & DataStorage::dslElectricField) &&
161     (atype->isElectrostatic())) {
162 gezelter 1871 atomInfo->hasElectricField = true;
163     atomInfo->eField = datom->getElectricField();
164     }
165    
166     GayBerneAdapter gba = GayBerneAdapter(atype);
167     MultipoleAdapter ma = MultipoleAdapter(atype);
168 gezelter 1787
169     if (gba.isGayBerne()) {
170 gezelter 1871 atomInfo->hasVector = true;
171     atomInfo->vec = datom->getA().transpose()*V3Z;
172 gezelter 1787 } else if (ma.isDipole()) {
173 gezelter 1871 atomInfo->hasVector = true;
174     atomInfo->vec = datom->getDipole();
175 gezelter 1814 } else if (ma.isQuadrupole()) {
176 gezelter 1871 atomInfo->hasVector = true;
177     atomInfo->vec = datom->getA().transpose()*V3Z;
178 tim 989 }
179 gezelter 2
180 gezelter 1872 atomData = new AtomData;
181     atomData->setID("ATOMDATA");
182 gezelter 246 atomData->addAtomInfo(atomInfo);
183 gezelter 1872
184 gezelter 246 datom->addProperty(atomData);
185    
186     setVisited(datom);
187 gezelter 507 }
188 gezelter 2
189 gezelter 507 const std::string DefaultAtomVisitor::toString() {
190 gezelter 246 char buffer[65535];
191     std::string result;
192 gezelter 2
193 gezelter 246 sprintf(buffer,
194 gezelter 1871 "--------------------------------------------------------------\n");
195 gezelter 246 result += buffer;
196 gezelter 2
197 gezelter 246 sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
198     result += buffer;
199 gezelter 2
200 gezelter 246 sprintf(buffer,
201     "Visitor Description: copy atom infomation into atom data\n");
202     result += buffer;
203 gezelter 2
204 gezelter 246 sprintf(buffer,
205 gezelter 1871 "--------------------------------------------------------------\n");
206 gezelter 246 result += buffer;
207 gezelter 2
208 gezelter 246 return result;
209 gezelter 507 }
210 gezelter 1390 } //namespace OpenMD

Properties

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