| 44 |
|
#include "primitives/Molecule.hpp" |
| 45 |
|
namespace oopse { |
| 46 |
|
|
| 47 |
< |
TimeCorrFunc::TimeCorrFunc(SimInfo* info, const std::string& filename, |
| 48 |
< |
const std::string& sele1, const std::string& sele2, int storageLayout) |
| 47 |
> |
TimeCorrFunc::TimeCorrFunc(SimInfo* info, const std::string& filename, |
| 48 |
> |
const std::string& sele1, const std::string& sele2, int storageLayout) |
| 49 |
|
: info_(info), storageLayout_(storageLayout), dumpFilename_(filename), selectionScript1_(sele1), |
| 50 |
|
selectionScript2_(sele2), evaluator1_(info), evaluator2_(info), seleMan1_(info), seleMan2_(info){ |
| 51 |
|
|
| 52 |
< |
int nAtoms = info->getNGlobalAtoms(); |
| 53 |
< |
int nRigidBodies = info->getNGlobalRigidBodies(); |
| 54 |
< |
int nStuntDoubles = nAtoms + nRigidBodies; |
| 52 |
> |
int nAtoms = info->getNGlobalAtoms(); |
| 53 |
> |
int nRigidBodies = info->getNGlobalRigidBodies(); |
| 54 |
> |
int nStuntDoubles = nAtoms + nRigidBodies; |
| 55 |
|
|
| 56 |
< |
std::set<AtomType*> atomTypes = info->getUniqueAtomTypes(); |
| 57 |
< |
std::set<AtomType*>::iterator i; |
| 58 |
< |
bool hasDirectionalAtom = false; |
| 59 |
< |
bool hasMultipole = false; |
| 60 |
< |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
| 56 |
> |
std::set<AtomType*> atomTypes = info->getUniqueAtomTypes(); |
| 57 |
> |
std::set<AtomType*>::iterator i; |
| 58 |
> |
bool hasDirectionalAtom = false; |
| 59 |
> |
bool hasMultipole = false; |
| 60 |
> |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
| 61 |
|
if ((*i)->isDirectional()){ |
| 62 |
< |
hasDirectionalAtom = true; |
| 62 |
> |
hasDirectionalAtom = true; |
| 63 |
|
} |
| 64 |
|
if ((*i)->isMultipole()){ |
| 65 |
< |
hasMultipole = true; |
| 65 |
> |
hasMultipole = true; |
| 66 |
|
} |
| 67 |
< |
} |
| 67 |
> |
} |
| 68 |
|
|
| 69 |
< |
if (nRigidBodies > 0 || hasDirectionalAtom) { |
| 69 |
> |
if (nRigidBodies > 0 || hasDirectionalAtom) { |
| 70 |
|
storageLayout_ |= DataStorage::dslAmat; |
| 71 |
< |
} |
| 72 |
< |
if (hasMultipole) { |
| 71 |
> |
} |
| 72 |
> |
if (hasMultipole) { |
| 73 |
|
storageLayout_ |= DataStorage::dslElectroFrame; |
| 74 |
|
if (nRigidBodies > 0) { |
| 75 |
< |
storageLayout_ |= DataStorage::dslAngularMomentum; |
| 75 |
> |
storageLayout_ |= DataStorage::dslAngularMomentum; |
| 76 |
|
} |
| 77 |
< |
} |
| 77 |
> |
} |
| 78 |
> |
if(nRigidBodies > 0 && storageLayout_ & DataStorage::dslVelocity) { |
| 79 |
> |
storageLayout_ |= DataStorage::dslAngularMomentum; |
| 80 |
> |
} |
| 81 |
|
|
| 82 |
< |
bsMan_ = new BlockSnapshotManager(info, dumpFilename_, storageLayout_); |
| 83 |
< |
info_->setSnapshotManager(bsMan_); |
| 82 |
> |
bsMan_ = new BlockSnapshotManager(info, dumpFilename_, storageLayout_); |
| 83 |
> |
info_->setSnapshotManager(bsMan_); |
| 84 |
|
|
| 85 |
< |
//if selection is static, we only need to evaluate it once |
| 86 |
< |
if (!evaluator1_.isDynamic()) { |
| 85 |
> |
evaluator1_.loadScriptString(selectionScript1_); |
| 86 |
> |
evaluator2_.loadScriptString(selectionScript2_); |
| 87 |
> |
|
| 88 |
> |
//if selection is static, we only need to evaluate it once |
| 89 |
> |
if (!evaluator1_.isDynamic()) { |
| 90 |
|
seleMan1_.setSelectionSet(evaluator1_.evaluate()); |
| 91 |
|
validateSelection(seleMan1_); |
| 92 |
< |
} else { |
| 93 |
< |
sprintf(painCave.errMsg, |
| 92 |
> |
} else { |
| 93 |
> |
sprintf(painCave.errMsg, |
| 94 |
|
"TimeCorrFunc Error: dynamic selection is not supported\n"); |
| 95 |
< |
painCave.isFatal = 1; |
| 96 |
< |
simError(); |
| 97 |
< |
} |
| 95 |
> |
painCave.isFatal = 1; |
| 96 |
> |
simError(); |
| 97 |
> |
} |
| 98 |
|
|
| 99 |
< |
if (!evaluator2_.isDynamic()) { |
| 99 |
> |
if (!evaluator2_.isDynamic()) { |
| 100 |
|
seleMan2_.setSelectionSet(evaluator2_.evaluate()); |
| 101 |
|
validateSelection(seleMan2_); |
| 102 |
< |
} else { |
| 103 |
< |
sprintf(painCave.errMsg, |
| 102 |
> |
} else { |
| 103 |
> |
sprintf(painCave.errMsg, |
| 104 |
|
"TimeCorrFunc Error: dynamic selection is not supported\n"); |
| 105 |
< |
painCave.isFatal = 1; |
| 106 |
< |
simError(); |
| 107 |
< |
} |
| 105 |
> |
painCave.isFatal = 1; |
| 106 |
> |
simError(); |
| 107 |
> |
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
< |
/**@todo Fixed Me */ |
| 112 |
< |
Globals* simParams = info_->getSimParams(); |
| 113 |
< |
if (simParams->haveSampleTime()){ |
| 111 |
> |
/**@todo Fix Me */ |
| 112 |
> |
Globals* simParams = info_->getSimParams(); |
| 113 |
> |
if (simParams->haveSampleTime()){ |
| 114 |
|
deltaTime_ = simParams->getSampleTime(); |
| 115 |
< |
} else { |
| 116 |
< |
sprintf(painCave.errMsg, |
| 115 |
> |
} else { |
| 116 |
> |
sprintf(painCave.errMsg, |
| 117 |
|
"TimeCorrFunc::writeCorrelate Error: can not figure out deltaTime\n"); |
| 118 |
< |
painCave.isFatal = 1; |
| 119 |
< |
simError(); |
| 120 |
< |
} |
| 118 |
> |
painCave.isFatal = 1; |
| 119 |
> |
simError(); |
| 120 |
> |
} |
| 121 |
|
|
| 122 |
< |
int nframes = bsMan_->getNFrames(); |
| 123 |
< |
nTimeBins_ = nframes; |
| 124 |
< |
histogram_.resize(nTimeBins_); |
| 125 |
< |
count_.resize(nTimeBins_); |
| 126 |
< |
time_.resize(nTimeBins_); |
| 122 |
> |
int nframes = bsMan_->getNFrames(); |
| 123 |
> |
nTimeBins_ = nframes; |
| 124 |
> |
histogram_.resize(nTimeBins_); |
| 125 |
> |
count_.resize(nTimeBins_); |
| 126 |
> |
time_.resize(nTimeBins_); |
| 127 |
|
|
| 128 |
< |
for (int i = 0; i < nTimeBins_; ++i) { |
| 128 |
> |
for (int i = 0; i < nTimeBins_; ++i) { |
| 129 |
|
time_[i] = i * deltaTime_; |
| 130 |
< |
} |
| 130 |
> |
} |
| 131 |
|
|
| 132 |
< |
} |
| 132 |
> |
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
< |
void TimeCorrFunc::doCorrelate() { |
| 135 |
> |
void TimeCorrFunc::doCorrelate() { |
| 136 |
|
preCorrelate(); |
| 137 |
|
|
| 138 |
|
int nblocks = bsMan_->getNBlocks(); |
| 139 |
|
|
| 140 |
|
for (int i = 0; i < nblocks; ++i) { |
| 141 |
< |
bsMan_->loadBlock(i); |
| 136 |
< |
for (int j = i; j < nblocks; ++j) { |
| 137 |
< |
bsMan_->loadBlock(j); |
| 138 |
< |
correlateBlocks(i, j); |
| 141 |
> |
bsMan_->loadBlock(i); |
| 142 |
|
|
| 143 |
< |
if (i != j) { |
| 144 |
< |
//if i equals to j, the block is still used, should not unload it |
| 145 |
< |
bsMan_->unloadBlock(j); |
| 146 |
< |
} |
| 147 |
< |
} |
| 148 |
< |
bsMan_->unloadBlock(i); |
| 143 |
> |
for (int j = i; j < nblocks; ++j) { |
| 144 |
> |
bsMan_->loadBlock(j); |
| 145 |
> |
correlateBlocks(i, j); |
| 146 |
> |
bsMan_->unloadBlock(j); |
| 147 |
> |
} |
| 148 |
> |
|
| 149 |
> |
bsMan_->unloadBlock(i); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
postCorrelate(); |
| 153 |
|
|
| 154 |
|
writeCorrelate(); |
| 155 |
< |
} |
| 155 |
> |
} |
| 156 |
|
|
| 157 |
< |
void TimeCorrFunc::correlateBlocks(int block1, int block2) { |
| 157 |
> |
void TimeCorrFunc::correlateBlocks(int block1, int block2) { |
| 158 |
|
|
| 159 |
< |
int jstart, jend; |
| 156 |
< |
|
| 157 |
< |
assert(bsMan_->isBlockActive(block1) && bsMan_->isBlockActive(block2)); |
| 159 |
> |
int jstart, jend; |
| 160 |
|
|
| 161 |
< |
SnapshotBlock snapshotBlock1 = bsMan_->getSnapshotBlock(block1); |
| 160 |
< |
SnapshotBlock snapshotBlock2 = bsMan_->getSnapshotBlock(block2); |
| 161 |
> |
assert(bsMan_->isBlockActive(block1) && bsMan_->isBlockActive(block2)); |
| 162 |
|
|
| 163 |
< |
jend = snapshotBlock2.second; |
| 164 |
< |
|
| 164 |
< |
for (int i = snapshotBlock1.first; i < snapshotBlock1.second; ++i) { |
| 165 |
< |
|
| 166 |
< |
//evaluate selection if it is dynamic |
| 167 |
< |
if (evaluator1_.isDynamic()) { |
| 168 |
< |
seleMan1_.setSelectionSet(evaluator1_.evaluate()); |
| 169 |
< |
validateSelection(seleMan1_); |
| 170 |
< |
} |
| 171 |
< |
|
| 172 |
< |
//update the position or velocity of the atoms belong to rigid bodies |
| 173 |
< |
updateFrame(i); |
| 174 |
< |
|
| 175 |
< |
// if the two blocks are the same, we don't want to correlate |
| 176 |
< |
// backwards in time, so start j at the same frame as i |
| 163 |
> |
SnapshotBlock snapshotBlock1 = bsMan_->getSnapshotBlock(block1); |
| 164 |
> |
SnapshotBlock snapshotBlock2 = bsMan_->getSnapshotBlock(block2); |
| 165 |
|
|
| 166 |
< |
if (block1 == block2) |
| 167 |
< |
jstart = i; |
| 168 |
< |
else |
| 169 |
< |
jstart = snapshotBlock2.first; |
| 182 |
< |
|
| 183 |
< |
for(int j = jstart; j < jend; ++j) { |
| 184 |
< |
//evaluate selection |
| 185 |
< |
if (!evaluator2_.isDynamic()) { |
| 186 |
< |
seleMan2_.setSelectionSet(evaluator2_.evaluate()); |
| 187 |
< |
validateSelection(seleMan2_); |
| 188 |
< |
} |
| 166 |
> |
jend = snapshotBlock2.second; |
| 167 |
> |
|
| 168 |
> |
for (int i = snapshotBlock1.first; i < snapshotBlock1.second; ++i) { |
| 169 |
> |
|
| 170 |
|
//update the position or velocity of the atoms belong to rigid bodies |
| 171 |
< |
updateFrame(j); |
| 172 |
< |
|
| 173 |
< |
correlateFrames(i, j); |
| 171 |
> |
updateFrame(i); |
| 172 |
> |
|
| 173 |
> |
// if the two blocks are the same, we don't want to correlate |
| 174 |
> |
// backwards in time, so start j at the same frame as i |
| 175 |
> |
if (block1 == block2) { |
| 176 |
> |
jstart = i; |
| 177 |
> |
} else { |
| 178 |
> |
jstart = snapshotBlock2.first; |
| 179 |
> |
} |
| 180 |
> |
|
| 181 |
> |
for(int j = jstart; j < jend; ++j) { |
| 182 |
> |
//update the position or velocity of the atoms belong to rigid bodies |
| 183 |
> |
updateFrame(j); |
| 184 |
> |
|
| 185 |
> |
correlateFrames(i, j); |
| 186 |
> |
} |
| 187 |
|
} |
| 188 |
|
} |
| 195 |
– |
} |
| 189 |
|
|
| 190 |
< |
void TimeCorrFunc::updateFrame(int frame){ |
| 190 |
> |
void TimeCorrFunc::updateFrame(int frame){ |
| 191 |
|
Molecule* mol; |
| 192 |
|
RigidBody* rb; |
| 193 |
|
SimInfo::MoleculeIterator mi; |
| 195 |
|
|
| 196 |
|
/** @todo need improvement */ |
| 197 |
|
if (storageLayout_ & DataStorage::dslPosition) { |
| 198 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 198 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 199 |
|
|
| 200 |
< |
//change the positions of atoms which belong to the rigidbodies |
| 201 |
< |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 202 |
< |
rb->updateAtoms(frame); |
| 203 |
< |
} |
| 204 |
< |
} |
| 200 |
> |
//change the positions of atoms which belong to the rigidbodies |
| 201 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 202 |
> |
rb->updateAtoms(frame); |
| 203 |
> |
} |
| 204 |
> |
} |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
if (storageLayout_ & DataStorage::dslVelocity) { |
| 208 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 208 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 209 |
|
|
| 210 |
< |
//change the positions of atoms which belong to the rigidbodies |
| 211 |
< |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 212 |
< |
rb->updateAtomVel(frame); |
| 213 |
< |
} |
| 214 |
< |
} |
| 210 |
> |
//change the positions of atoms which belong to the rigidbodies |
| 211 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 212 |
> |
rb->updateAtomVel(frame); |
| 213 |
> |
} |
| 214 |
> |
} |
| 215 |
|
|
| 216 |
|
} |
| 217 |
|
|
| 218 |
< |
} |
| 218 |
> |
} |
| 219 |
|
|
| 220 |
|
|
| 221 |
< |
void TimeCorrFunc::preCorrelate() { |
| 221 |
> |
void TimeCorrFunc::preCorrelate() { |
| 222 |
|
std::fill(histogram_.begin(), histogram_.end(), 0.0); |
| 223 |
|
std::fill(count_.begin(), count_.end(), 0); |
| 224 |
< |
} |
| 224 |
> |
} |
| 225 |
|
|
| 226 |
< |
void TimeCorrFunc::postCorrelate() { |
| 226 |
> |
void TimeCorrFunc::postCorrelate() { |
| 227 |
|
for (int i =0 ; i < nTimeBins_; ++i) { |
| 228 |
< |
if (count_[i] > 0) { |
| 229 |
< |
histogram_[i] /= count_[i]; |
| 230 |
< |
} |
| 228 |
> |
if (count_[i] > 0) { |
| 229 |
> |
histogram_[i] /= count_[i]; |
| 230 |
> |
} |
| 231 |
|
} |
| 232 |
< |
} |
| 232 |
> |
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
< |
void TimeCorrFunc::writeCorrelate() { |
| 235 |
> |
void TimeCorrFunc::writeCorrelate() { |
| 236 |
|
std::ofstream ofs(outputFilename_.c_str()); |
| 237 |
|
|
| 238 |
|
if (ofs.is_open()) { |
| 239 |
|
|
| 240 |
< |
ofs << "#" << getCorrFuncType() << "\n"; |
| 241 |
< |
ofs << "#selection script1: \"" << selectionScript1_ <<"\"\tselection script2: \"" << selectionScript2_ << "\"\n"; |
| 242 |
< |
ofs << "#extra information: " << extra_ << "\n"; |
| 243 |
< |
ofs << "#time\tcorrVal\n"; |
| 240 |
> |
ofs << "#" << getCorrFuncType() << "\n"; |
| 241 |
> |
ofs << "#selection script1: \"" << selectionScript1_ <<"\"\tselection script2: \"" << selectionScript2_ << "\"\n"; |
| 242 |
> |
ofs << "#extra information: " << extra_ << "\n"; |
| 243 |
> |
ofs << "#time\tcorrVal\n"; |
| 244 |
|
|
| 245 |
< |
for (int i = 0; i < nTimeBins_; ++i) { |
| 246 |
< |
ofs << time_[i] << "\t" << histogram_[i] << "\n"; |
| 247 |
< |
} |
| 245 |
> |
for (int i = 0; i < nTimeBins_; ++i) { |
| 246 |
> |
ofs << time_[i] << "\t" << histogram_[i] << "\n"; |
| 247 |
> |
} |
| 248 |
|
|
| 249 |
|
} else { |
| 250 |
< |
sprintf(painCave.errMsg, |
| 251 |
< |
"TimeCorrFunc::writeCorrelate Error: fail to open %s\n", outputFilename_.c_str()); |
| 252 |
< |
painCave.isFatal = 1; |
| 253 |
< |
simError(); |
| 250 |
> |
sprintf(painCave.errMsg, |
| 251 |
> |
"TimeCorrFunc::writeCorrelate Error: fail to open %s\n", outputFilename_.c_str()); |
| 252 |
> |
painCave.isFatal = 1; |
| 253 |
> |
simError(); |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
ofs.close(); |
| 257 |
< |
} |
| 257 |
> |
} |
| 258 |
|
|
| 259 |
|
} |