| 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 |
| 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. |
| 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] Vardeman & Gezelter, in progress (2009). |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
|
#include <cmath> |
| 43 |
|
#include "visitors/ZconsVisitor.hpp" |
| 44 |
|
#include "primitives/Molecule.hpp" |
| 45 |
|
#include "utils/StringUtils.hpp" |
| 46 |
< |
namespace oopse { |
| 46 |
> |
#include "types/ZconsStamp.hpp" |
| 47 |
> |
namespace OpenMD { |
| 48 |
|
|
| 49 |
< |
ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){ |
| 49 |
> |
ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){ |
| 50 |
|
|
| 51 |
|
visitorName = "ZConsVisitor"; |
| 52 |
|
currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 53 |
|
Globals* simParam = info_->getSimParams(); |
| 54 |
|
|
| 55 |
< |
if (simParam->haveZconstraintTime()){ |
| 56 |
< |
zconsTime_ = simParam->getZconsTime(); |
| 55 |
> |
if (simParam->haveZconsTime()){ |
| 56 |
> |
zconsTime_ = simParam->getZconsTime(); |
| 57 |
|
} |
| 58 |
|
else{ |
| 59 |
< |
sprintf(painCave.errMsg, |
| 60 |
< |
"ZConstraint error: If you use a ZConstraint,\n" |
| 61 |
< |
"\tyou must set zconsTime.\n"); |
| 62 |
< |
painCave.isFatal = 1; |
| 63 |
< |
simError(); |
| 59 |
> |
sprintf(painCave.errMsg, |
| 60 |
> |
"ZConstraint error: If you use a ZConstraint,\n" |
| 61 |
> |
"\tyou must set zconsTime.\n"); |
| 62 |
> |
painCave.isFatal = 1; |
| 63 |
> |
simError(); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
if (simParam->haveZconsTol()){ |
| 67 |
< |
zconsTol_ = simParam->getZconsTol(); |
| 67 |
> |
zconsTol_ = simParam->getZconsTol(); |
| 68 |
|
} |
| 69 |
|
else{ |
| 70 |
< |
zconsTol_ = 0.01; |
| 71 |
< |
sprintf(painCave.errMsg, |
| 72 |
< |
"ZConstraint Warning: Tolerance for z-constraint method is not specified.\n" |
| 73 |
< |
"\tOOPSE will use a default value of %f.\n" |
| 74 |
< |
"\tTo set the tolerance, use the zconsTol variable.\n", |
| 75 |
< |
zconsTol_); |
| 76 |
< |
painCave.isFatal = 0; |
| 77 |
< |
simError(); |
| 70 |
> |
zconsTol_ = 0.01; |
| 71 |
> |
sprintf(painCave.errMsg, |
| 72 |
> |
"ZConstraint Warning: Tolerance for z-constraint method is not specified.\n" |
| 73 |
> |
"\tOpenMD will use a default value of %f.\n" |
| 74 |
> |
"\tTo set the tolerance, use the zconsTol variable.\n", |
| 75 |
> |
zconsTol_); |
| 76 |
> |
painCave.isFatal = 0; |
| 77 |
> |
simError(); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
< |
int nZconstraints = simParam->getNzConstraints(); |
| 81 |
< |
ZconStamp** stamp = simParam->getZconStamp(); |
| 80 |
> |
int nZconstraints = simParam->getNZconsStamps(); |
| 81 |
> |
std::vector<ZConsStamp*> stamp = simParam->getZconsStamps(); |
| 82 |
|
for (int i = 0; i < nZconstraints; i++){ |
| 83 |
< |
int zmolIndex = stamp[i]->getMolIndex(); |
| 84 |
< |
zmolStates_.insert(std::make_pair(zmolIndex, zsMoving)); |
| 83 |
> |
int zmolIndex = stamp[i]->getMolIndex(); |
| 84 |
> |
zmolStates_.insert(std::make_pair(zmolIndex, zsMoving)); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
|
| 89 |
|
/** @todo only works for single version now*/ |
| 90 |
|
std::map<int, ZConsState>::iterator j; |
| 91 |
|
for (j = zmolStates_.begin(); j != zmolStates_.end(); ++j) { |
| 92 |
< |
Molecule* mol = info_->getMoleculeByGlobalIndex(j->first); |
| 93 |
< |
assert(mol != NULL); |
| 94 |
< |
Molecule::AtomIterator ai; |
| 95 |
< |
Atom* at; |
| 96 |
< |
for (at = mol->beginAtom(ai); at != NULL; at = mol->nextAtom(ai)) { |
| 97 |
< |
zatomToZmol_.insert(std::make_pair(at->getGlobalIndex(), mol->getGlobalIndex())); |
| 98 |
< |
} |
| 92 |
> |
Molecule* mol = info_->getMoleculeByGlobalIndex(j->first); |
| 93 |
> |
assert(mol != NULL); |
| 94 |
> |
Molecule::AtomIterator ai; |
| 95 |
> |
Atom* at; |
| 96 |
> |
for (at = mol->beginAtom(ai); at != NULL; at = mol->nextAtom(ai)) { |
| 97 |
> |
zatomToZmol_.insert(std::make_pair(at->getGlobalIndex(), mol->getGlobalIndex())); |
| 98 |
> |
} |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
zconsFilename_ = getPrefix(info_->getFinalConfigFileName()) + ".fz"; |
| 103 |
|
zconsReader_ = new ZConsReader(info); |
| 104 |
|
|
| 105 |
|
if (zconsReader_->hasNextFrame()) |
| 106 |
< |
zconsReader_->readNextFrame(); |
| 106 |
> |
zconsReader_->readNextFrame(); |
| 107 |
|
|
| 108 |
< |
} |
| 108 |
> |
} |
| 109 |
|
|
| 110 |
< |
ZConsVisitor::~ZConsVisitor(){ |
| 111 |
< |
if(!zconsReader_) |
| 112 |
< |
delete zconsReader_; |
| 110 |
> |
ZConsVisitor::~ZConsVisitor(){ |
| 111 |
> |
if(!zconsReader_) |
| 112 |
> |
delete zconsReader_; |
| 113 |
|
|
| 114 |
< |
} |
| 114 |
> |
} |
| 115 |
|
|
| 116 |
< |
void ZConsVisitor::visit(Atom* atom){ |
| 116 |
> |
void ZConsVisitor::visit(Atom* atom){ |
| 117 |
|
std::string prefix; |
| 118 |
|
if(isZconstraint(atom->getGlobalIndex(), prefix)) |
| 119 |
< |
internalVisit(atom, prefix); |
| 120 |
< |
} |
| 119 |
> |
internalVisit(atom, prefix); |
| 120 |
> |
} |
| 121 |
|
|
| 122 |
< |
void ZConsVisitor::visit(DirectionalAtom* datom){ |
| 122 |
> |
void ZConsVisitor::visit(DirectionalAtom* datom){ |
| 123 |
|
std::string prefix; |
| 124 |
|
|
| 125 |
|
if(isZconstraint(datom->getGlobalIndex(), prefix)) |
| 126 |
< |
internalVisit(datom, prefix); |
| 127 |
< |
} |
| 126 |
> |
internalVisit(datom, prefix); |
| 127 |
> |
} |
| 128 |
|
|
| 129 |
< |
void ZConsVisitor::visit(RigidBody* rb){ |
| 129 |
> |
void ZConsVisitor::visit(RigidBody* rb){ |
| 130 |
|
std::string prefix; |
| 131 |
|
std::vector<Atom*> atoms; |
| 132 |
|
|
| 133 |
|
atoms = rb->getAtoms(); |
| 134 |
|
|
| 135 |
|
if(isZconstraint(atoms[0]->getGlobalIndex(), prefix)) |
| 136 |
< |
internalVisit(rb, prefix); |
| 137 |
< |
} |
| 136 |
> |
internalVisit(rb, prefix); |
| 137 |
> |
} |
| 138 |
|
|
| 139 |
< |
void ZConsVisitor::update(){ |
| 139 |
> |
void ZConsVisitor::update(){ |
| 140 |
|
Molecule* mol; |
| 141 |
|
Vector3d com; |
| 142 |
|
ZConsState state; |
| 143 |
|
std::map<int, ZConsState>::iterator i; |
| 144 |
|
for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) { |
| 145 |
< |
i->second = zsMoving; |
| 145 |
> |
i->second = zsMoving; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
readZconsFile(currSnapshot_->getTime()); |
| 150 |
|
const std::vector<ZconsData>& fixedZmolData = zconsReader_->getFixedZMolData(); |
| 151 |
|
std::vector<ZconsData>::const_iterator j; |
| 152 |
|
for (j = fixedZmolData.begin(); j != fixedZmolData.end(); ++j) { |
| 153 |
< |
std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex); |
| 154 |
< |
assert(k != zmolStates_.end()); |
| 155 |
< |
k->second = zsFixed; |
| 153 |
> |
std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex); |
| 154 |
> |
assert(k != zmolStates_.end()); |
| 155 |
> |
k->second = zsFixed; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
< |
} |
| 158 |
> |
} |
| 159 |
|
|
| 160 |
< |
void ZConsVisitor::readZconsFile(double time) { |
| 161 |
< |
double tempTime; |
| 160 |
> |
void ZConsVisitor::readZconsFile(RealType time) { |
| 161 |
> |
RealType tempTime; |
| 162 |
|
while(zconsReader_->hasNextFrame()){ |
| 163 |
< |
tempTime = zconsReader_->getCurTime(); |
| 164 |
< |
if(tempTime >= time) { |
| 165 |
< |
return; |
| 166 |
< |
} |
| 163 |
> |
tempTime = zconsReader_->getCurTime(); |
| 164 |
> |
if(tempTime >= time) { |
| 165 |
> |
return; |
| 166 |
> |
} |
| 167 |
|
|
| 168 |
< |
zconsReader_->readNextFrame(); |
| 168 |
> |
zconsReader_->readNextFrame(); |
| 169 |
|
} |
| 170 |
< |
} |
| 170 |
> |
} |
| 171 |
|
|
| 172 |
< |
void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){ |
| 172 |
> |
void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){ |
| 173 |
|
GenericData* data; |
| 174 |
|
AtomData* atomData; |
| 175 |
|
AtomInfo* atomInfo; |
| 178 |
|
//if there is not atom data, just skip it |
| 179 |
|
data = sd->getPropertyByName("ATOMDATA"); |
| 180 |
|
if(data != NULL){ |
| 181 |
< |
atomData = dynamic_cast<AtomData*>(data); |
| 182 |
< |
if(atomData == NULL) |
| 183 |
< |
return; |
| 184 |
< |
} |
| 181 |
> |
atomData = dynamic_cast<AtomData*>(data); |
| 182 |
> |
if(atomData == NULL) |
| 183 |
> |
return; |
| 184 |
> |
} |
| 185 |
|
else |
| 186 |
< |
return; |
| 186 |
> |
return; |
| 187 |
|
|
| 188 |
|
for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter)) |
| 189 |
< |
(atomInfo->atomTypeName).insert(0, prefix); |
| 190 |
< |
} |
| 189 |
> |
(atomInfo->atomTypeName).insert(0, prefix); |
| 190 |
> |
} |
| 191 |
|
|
| 192 |
|
|
| 193 |
< |
bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){ |
| 193 |
> |
bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){ |
| 194 |
|
std::string prefixString[] = {"ZF", "ZM"}; |
| 195 |
|
std::map<int, int>::iterator i = zatomToZmol_.find(atomIndex); |
| 196 |
|
if (i == zatomToZmol_.end() ){ |
| 197 |
< |
prefix = ""; |
| 198 |
< |
return false; |
| 197 |
> |
prefix = ""; |
| 198 |
> |
return false; |
| 199 |
|
} else { |
| 200 |
|
|
| 201 |
< |
std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second); |
| 202 |
< |
assert(j !=zmolStates_.end()); |
| 203 |
< |
prefix = prefixString[j->second]; |
| 204 |
< |
return true; |
| 201 |
> |
std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second); |
| 202 |
> |
assert(j !=zmolStates_.end()); |
| 203 |
> |
prefix = prefixString[j->second]; |
| 204 |
> |
return true; |
| 205 |
|
} |
| 206 |
< |
} |
| 206 |
> |
} |
| 207 |
|
|
| 208 |
< |
const std::string ZConsVisitor::toString(){ |
| 208 |
> |
const std::string ZConsVisitor::toString(){ |
| 209 |
|
char buffer[65535]; |
| 210 |
|
std::string result; |
| 211 |
|
|
| 215 |
|
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
| 216 |
|
result += buffer; |
| 217 |
|
|
| 218 |
< |
sprintf(buffer , "number of zconstraint molecule: %d\n", zmolStates_.size()); |
| 218 |
> |
sprintf(buffer , "number of zconstraint molecule: %d\n", (int) zmolStates_.size()); |
| 219 |
|
result += buffer; |
| 220 |
|
|
| 221 |
|
sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol_); |
| 230 |
|
std::map<int, ZConsState>::iterator i; |
| 231 |
|
int j = 0; |
| 232 |
|
for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) { |
| 233 |
< |
sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first); |
| 234 |
< |
result += buffer; |
| 233 |
> |
sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first); |
| 234 |
> |
result += buffer; |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
sprintf(buffer ,"------------------------------------------------------------------\n"); |
| 238 |
|
result += buffer; |
| 239 |
|
|
| 240 |
|
return result; |
| 241 |
< |
} |
| 241 |
> |
} |
| 242 |
|
|
| 243 |
|
|
| 244 |
< |
}//namespace oopse |
| 244 |
> |
}//namespace OpenMD |