| 1 |
< |
/* |
| 2 |
< |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
< |
* |
| 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. 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 |
< |
*/ |
| 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 "io/DumpReader.hpp" |
| 43 |
> |
#include "io/RestReader.hpp" |
| 44 |
> |
#include "primitives/Molecule.hpp" |
| 45 |
> |
#include "restraints/ObjectRestraint.hpp" |
| 46 |
> |
#include "restraints/MolecularRestraint.hpp" |
| 47 |
|
|
| 48 |
< |
#define _LARGEFILE_SOURCE64 |
| 49 |
< |
#define _FILE_OFFSET_BITS 64 |
| 48 |
> |
namespace OpenMD { |
| 49 |
> |
|
| 50 |
> |
void RestReader::readReferenceStructure() { |
| 51 |
|
|
| 52 |
< |
#include <sys/types.h> |
| 46 |
< |
#include <sys/stat.h> |
| 52 |
> |
// some of this comes directly from DumpReader. |
| 53 |
|
|
| 54 |
< |
#include <iostream> |
| 55 |
< |
#include <math.h> |
| 54 |
> |
if (!isScanned_) |
| 55 |
> |
scanFile(); |
| 56 |
> |
|
| 57 |
> |
int storageLayout = info_->getSnapshotManager()->getStorageLayout(); |
| 58 |
> |
|
| 59 |
> |
if (storageLayout & DataStorage::dslPosition) { |
| 60 |
> |
needPos_ = true; |
| 61 |
> |
} else { |
| 62 |
> |
needPos_ = false; |
| 63 |
> |
} |
| 64 |
> |
|
| 65 |
> |
needVel_ = false; |
| 66 |
> |
|
| 67 |
> |
if (storageLayout & DataStorage::dslAmat || storageLayout & DataStorage::dslElectroFrame) { |
| 68 |
> |
needQuaternion_ = true; |
| 69 |
> |
} else { |
| 70 |
> |
needQuaternion_ = false; |
| 71 |
> |
} |
| 72 |
|
|
| 73 |
< |
#include <stdio.h> |
| 52 |
< |
#include <stdlib.h> |
| 53 |
< |
#include <string.h> |
| 73 |
> |
needAngMom_ = false; |
| 74 |
|
|
| 75 |
< |
#include "primitives/Molecule.hpp" |
| 76 |
< |
#include "utils/MemoryUtils.hpp" |
| 77 |
< |
#include "utils/StringTokenizer.hpp" |
| 58 |
< |
#include "io/RestReader.hpp" |
| 59 |
< |
#include "utils/simError.h" |
| 75 |
> |
// We need temporary storage to keep track of all StuntDouble positions |
| 76 |
> |
// in case some of the restraints are molecular (i.e. if they use |
| 77 |
> |
// multiple SD positions to determine restrained orientations or positions: |
| 78 |
|
|
| 79 |
< |
#ifdef IS_MPI |
| 80 |
< |
#include <mpi.h> |
| 63 |
< |
#define TAKE_THIS_TAG_CHAR 0 |
| 64 |
< |
#define TAKE_THIS_TAG_INT 1 |
| 65 |
< |
#define TAKE_THIS_TAG_DOUBLE 2 |
| 66 |
< |
#endif // is_mpi |
| 79 |
> |
all_pos_.clear(); |
| 80 |
> |
all_pos_.resize(info_->getNGlobalIntegrableObjects() ); |
| 81 |
|
|
| 68 |
– |
namespace oopse { |
| 69 |
– |
|
| 70 |
– |
RestReader::RestReader( SimInfo* info ) : info_(info){ |
| 71 |
– |
|
| 72 |
– |
idealName = "idealCrystal.in"; |
| 73 |
– |
|
| 74 |
– |
isScanned = false; |
| 75 |
– |
|
| 76 |
– |
#ifdef IS_MPI |
| 77 |
– |
if (worldRank == 0) { |
| 78 |
– |
#endif |
| 79 |
– |
|
| 80 |
– |
inIdealFile = fopen(idealName, "r"); |
| 81 |
– |
if(inIdealFile == NULL){ |
| 82 |
– |
sprintf(painCave.errMsg, |
| 83 |
– |
"RestReader: Cannot open file: %s\n", idealName); |
| 84 |
– |
painCave.isFatal = 1; |
| 85 |
– |
simError(); |
| 86 |
– |
} |
| 87 |
– |
|
| 88 |
– |
inIdealFileName = idealName; |
| 89 |
– |
#ifdef IS_MPI |
| 90 |
– |
} |
| 91 |
– |
strcpy( checkPointMsg, |
| 92 |
– |
"File \"idealCrystal.in\" opened successfully for reading." ); |
| 93 |
– |
MPIcheckPoint(); |
| 94 |
– |
#endif |
| 82 |
|
|
| 83 |
< |
return; |
| 84 |
< |
} |
| 85 |
< |
|
| 86 |
< |
RestReader :: ~RestReader( ){ |
| 100 |
< |
#ifdef IS_MPI |
| 101 |
< |
if (worldRank == 0) { |
| 102 |
< |
#endif |
| 103 |
< |
int error; |
| 104 |
< |
error = fclose( inIdealFile ); |
| 105 |
< |
|
| 106 |
< |
if( error ){ |
| 107 |
< |
sprintf( painCave.errMsg, |
| 108 |
< |
"Error closing %s\n", inIdealFileName.c_str()); |
| 109 |
< |
simError(); |
| 110 |
< |
} |
| 111 |
< |
|
| 112 |
< |
MemoryUtils::deletePointers(framePos); |
| 113 |
< |
|
| 114 |
< |
#ifdef IS_MPI |
| 115 |
< |
} |
| 116 |
< |
strcpy( checkPointMsg, "Restraint file closed successfully." ); |
| 117 |
< |
MPIcheckPoint(); |
| 118 |
< |
#endif |
| 119 |
< |
|
| 120 |
< |
return; |
| 121 |
< |
} |
| 122 |
< |
|
| 123 |
< |
|
| 124 |
< |
void RestReader :: readIdealCrystal(){ |
| 125 |
< |
|
| 126 |
< |
int i; |
| 127 |
< |
unsigned int j; |
| 83 |
> |
// Restraint files are just standard dump files, but with the reference |
| 84 |
> |
// structure stored in the first frame (frame 0). |
| 85 |
> |
// RestReader overloads readSet and explicitly handles all of the |
| 86 |
> |
// ObjectRestraints in that method: |
| 87 |
|
|
| 88 |
< |
#ifdef IS_MPI |
| 130 |
< |
int done, which_node, which_atom; // loop counter |
| 131 |
< |
#endif //is_mpi |
| 88 |
> |
readSet(0); |
| 89 |
|
|
| 90 |
< |
const int BUFFERSIZE = 2000; // size of the read buffer |
| 91 |
< |
int nTotObjs; // the number of atoms |
| 92 |
< |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
| 93 |
< |
|
| 94 |
< |
char *eof_test; // ptr to see when we reach the end of the file |
| 138 |
< |
char *parseErr; |
| 139 |
< |
|
| 140 |
< |
std::vector<StuntDouble*> integrableObjects; |
| 141 |
< |
|
| 90 |
> |
// all ObjectRestraints have been handled, now we have to worry about |
| 91 |
> |
// molecular restraints: |
| 92 |
> |
|
| 93 |
> |
SimInfo::MoleculeIterator i; |
| 94 |
> |
Molecule::IntegrableObjectIterator j; |
| 95 |
|
Molecule* mol; |
| 96 |
< |
StuntDouble* integrableObject; |
| 144 |
< |
SimInfo::MoleculeIterator mi; |
| 145 |
< |
Molecule::IntegrableObjectIterator ii; |
| 146 |
< |
|
| 147 |
< |
#ifndef IS_MPI |
| 148 |
< |
|
| 149 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 150 |
< |
if( eof_test == NULL ){ |
| 151 |
< |
sprintf( painCave.errMsg, |
| 152 |
< |
"RestraintReader error: error reading 1st line of \"%s\"\n", |
| 153 |
< |
inIdealFileName.c_str() ); |
| 154 |
< |
painCave.isFatal = 1; |
| 155 |
< |
simError(); |
| 156 |
< |
} |
| 157 |
< |
|
| 158 |
< |
nTotObjs = atoi( read_buffer ); |
| 159 |
< |
|
| 160 |
< |
if( nTotObjs != info_->getNGlobalIntegrableObjects() ){ |
| 161 |
< |
sprintf( painCave.errMsg, |
| 162 |
< |
"RestraintReader error. %s nIntegrable, %d, " |
| 163 |
< |
"does not match the meta-data file's nIntegrable, %d.\n", |
| 164 |
< |
inIdealFileName.c_str(), nTotObjs, |
| 165 |
< |
info_->getNGlobalIntegrableObjects()); |
| 166 |
< |
painCave.isFatal = 1; |
| 167 |
< |
simError(); |
| 168 |
< |
} |
| 169 |
< |
|
| 170 |
< |
// skip over the comment line |
| 171 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 172 |
< |
if(eof_test == NULL){ |
| 173 |
< |
sprintf( painCave.errMsg, |
| 174 |
< |
"error in reading commment in %s\n", inIdealFileName.c_str()); |
| 175 |
< |
painCave.isFatal = 1; |
| 176 |
< |
simError(); |
| 177 |
< |
} |
| 178 |
< |
|
| 179 |
< |
// parse the ideal crystal lines |
| 180 |
< |
/* |
| 181 |
< |
* Note: we assume that there is a one-to-one correspondence between |
| 182 |
< |
* integrable objects and lines in the idealCrystal.in file. Thermodynamic |
| 183 |
< |
* integration is only supported for simple rigid bodies. |
| 184 |
< |
*/ |
| 185 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 186 |
< |
mol = info_->nextMolecule(mi)) { |
| 187 |
< |
|
| 188 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 189 |
< |
integrableObject != NULL; |
| 190 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
| 191 |
< |
|
| 192 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 193 |
< |
if(eof_test == NULL){ |
| 194 |
< |
sprintf(painCave.errMsg, |
| 195 |
< |
"RestReader Error: error in reading file %s\n" |
| 196 |
< |
"natoms = %d; index = %d\n" |
| 197 |
< |
"error reading the line from the file.\n", |
| 198 |
< |
inIdealFileName.c_str(), nTotObjs, |
| 199 |
< |
integrableObject->getGlobalIndex() ); |
| 200 |
< |
painCave.isFatal = 1; |
| 201 |
< |
simError(); |
| 202 |
< |
} |
| 203 |
< |
|
| 204 |
< |
parseErr = parseIdealLine( read_buffer, integrableObject); |
| 205 |
< |
if( parseErr != NULL ){ |
| 206 |
< |
strcpy( painCave.errMsg, parseErr ); |
| 207 |
< |
painCave.isFatal = 1; |
| 208 |
< |
simError(); |
| 209 |
< |
} |
| 210 |
< |
} |
| 211 |
< |
} |
| 212 |
< |
|
| 213 |
< |
// MPI Section of code.......... |
| 214 |
< |
#else //IS_MPI |
| 215 |
< |
|
| 216 |
< |
// first thing first, suspend fatalities. |
| 217 |
< |
painCave.isEventLoop = 1; |
| 218 |
< |
|
| 219 |
< |
int masterNode = 0; |
| 220 |
< |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 221 |
< |
|
| 222 |
< |
MPI_Status istatus; |
| 223 |
< |
int nCurObj; |
| 224 |
< |
int nitems; |
| 225 |
< |
int haveError; |
| 96 |
> |
StuntDouble* sd; |
| 97 |
|
|
| 98 |
< |
nTotObjs = info_->getNGlobalIntegrableObjects(); |
| 99 |
< |
haveError = 0; |
| 98 |
> |
// no need to worry about parallel molecules, as molecules are not |
| 99 |
> |
// split across processor boundaries. Just loop over all molecules |
| 100 |
> |
// we know about: |
| 101 |
|
|
| 102 |
< |
if (worldRank == masterNode) { |
| 103 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 104 |
< |
if( eof_test == NULL ){ |
| 105 |
< |
sprintf( painCave.errMsg, |
| 106 |
< |
"Error reading 1st line of %s \n ",inIdealFileName.c_str()); |
| 235 |
< |
painCave.isFatal = 1; |
| 236 |
< |
simError(); |
| 237 |
< |
} |
| 102 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 103 |
> |
mol = info_->nextMolecule(i)) { |
| 104 |
> |
|
| 105 |
> |
// is this molecule restrained? |
| 106 |
> |
GenericData* data = mol->getPropertyByName("Restraint"); |
| 107 |
|
|
| 108 |
< |
nitems = atoi( read_buffer ); |
| 240 |
< |
|
| 241 |
< |
// Check to see that the number of integrable objects in the |
| 242 |
< |
// intial configuration file is the same as derived from the |
| 243 |
< |
// meta-data file. |
| 244 |
< |
if( nTotObjs != nitems){ |
| 245 |
< |
sprintf( painCave.errMsg, |
| 246 |
< |
"RestraintReader Error. %s nIntegrable, %d, " |
| 247 |
< |
"does not match the meta-data file's nIntegrable, %d.\n", |
| 248 |
< |
inIdealFileName.c_str(), nTotObjs, |
| 249 |
< |
info_->getNGlobalIntegrableObjects()); |
| 250 |
< |
painCave.isFatal = 1; |
| 251 |
< |
simError(); |
| 252 |
< |
} |
| 253 |
< |
|
| 254 |
< |
// skip over the comment line |
| 255 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 256 |
< |
if(eof_test == NULL){ |
| 257 |
< |
sprintf( painCave.errMsg, |
| 258 |
< |
"error in reading commment in %s\n", inIdealFileName.c_str()); |
| 259 |
< |
painCave.isFatal = 1; |
| 260 |
< |
simError(); |
| 261 |
< |
} |
| 108 |
> |
if (data != NULL) { |
| 109 |
|
|
| 110 |
< |
MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
| 110 |
> |
// make sure we can reinterpret the generic data as restraint data: |
| 111 |
|
|
| 112 |
< |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 113 |
< |
int which_node = info_->getMolToProc(i); |
| 114 |
< |
|
| 115 |
< |
if(which_node == masterNode){ |
| 116 |
< |
//molecules belong to master node |
| 117 |
< |
|
| 118 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
| 119 |
< |
|
| 120 |
< |
if(mol == NULL) { |
| 121 |
< |
sprintf(painCave.errMsg, |
| 122 |
< |
"RestReader Error: Molecule not found on node %d!\n", |
| 123 |
< |
worldRank); |
| 124 |
< |
painCave.isFatal = 1; |
| 125 |
< |
simError(); |
| 126 |
< |
} |
| 127 |
< |
|
| 128 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 129 |
< |
integrableObject != NULL; |
| 283 |
< |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 112 |
> |
RestraintData* restData= dynamic_cast<RestraintData*>(data); |
| 113 |
> |
|
| 114 |
> |
if (restData != NULL) { |
| 115 |
> |
|
| 116 |
> |
// make sure we can reinterpet the restraint data as a |
| 117 |
> |
// pointer to a MolecularRestraint: |
| 118 |
> |
|
| 119 |
> |
MolecularRestraint* mRest = dynamic_cast<MolecularRestraint*>(restData->getData()); |
| 120 |
> |
|
| 121 |
> |
if (mRest != NULL) { |
| 122 |
> |
|
| 123 |
> |
// now we need to pack the stunt doubles for the reference |
| 124 |
> |
// structure: |
| 125 |
> |
|
| 126 |
> |
std::vector<Vector3d> ref; |
| 127 |
> |
int count = 0; |
| 128 |
> |
RealType mass, mTot; |
| 129 |
> |
Vector3d COM(0.0); |
| 130 |
|
|
| 131 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 131 |
> |
mTot = 0.0; |
| 132 |
|
|
| 133 |
< |
if(eof_test == NULL){ |
| 134 |
< |
sprintf(painCave.errMsg, |
| 289 |
< |
"RestReader Error: error in reading file %s\n" |
| 290 |
< |
"natoms = %d; index = %d\n" |
| 291 |
< |
"error reading the line from the file.\n", |
| 292 |
< |
inIdealFileName.c_str(), nTotObjs, i ); |
| 293 |
< |
painCave.isFatal = 1; |
| 294 |
< |
simError(); |
| 295 |
< |
} |
| 296 |
< |
|
| 297 |
< |
parseIdealLine(read_buffer, integrableObject); |
| 298 |
< |
|
| 299 |
< |
} |
| 300 |
< |
|
| 301 |
< |
} else { |
| 302 |
< |
//molecule belongs to slave nodes |
| 303 |
< |
|
| 304 |
< |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
| 305 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 306 |
< |
|
| 307 |
< |
for(j = 0; j < nCurObj; j++){ |
| 133 |
> |
// loop over the stunt doubles in this molecule in the order we |
| 134 |
> |
// will be looping them in the restraint code: |
| 135 |
|
|
| 136 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
| 137 |
< |
if(eof_test == NULL){ |
| 138 |
< |
sprintf(painCave.errMsg, |
| 139 |
< |
"RestReader Error: error in reading file %s\n" |
| 140 |
< |
"natoms = %d; index = %d\n" |
| 141 |
< |
"error reading the line from the file.\n", |
| 142 |
< |
inIdealFileName.c_str(), nTotObjs, i ); |
| 143 |
< |
painCave.isFatal = 1; |
| 144 |
< |
simError(); |
| 136 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
| 137 |
> |
sd = mol->nextIntegrableObject(j)) { |
| 138 |
> |
|
| 139 |
> |
// push back the reference positions of the stunt |
| 140 |
> |
// doubles from the *globally* sorted array of |
| 141 |
> |
// positions: |
| 142 |
> |
|
| 143 |
> |
ref.push_back( all_pos_[sd->getGlobalIndex()] ); |
| 144 |
> |
|
| 145 |
> |
mass = sd->getMass(); |
| 146 |
> |
|
| 147 |
> |
COM = COM + mass * ref[count]; |
| 148 |
> |
mTot = mTot + mass; |
| 149 |
> |
count = count + 1; |
| 150 |
|
} |
| 151 |
|
|
| 152 |
< |
MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
| 321 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
| 322 |
< |
} |
| 323 |
< |
} |
| 324 |
< |
} |
| 325 |
< |
} else { |
| 326 |
< |
//actions taken at slave nodes |
| 327 |
< |
MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
| 152 |
> |
COM /= mTot; |
| 153 |
|
|
| 154 |
< |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 330 |
< |
int which_node = info_->getMolToProc(i); |
| 154 |
> |
mRest->setReferenceStructure(ref, COM); |
| 155 |
|
|
| 332 |
– |
if(which_node == worldRank){ |
| 333 |
– |
//molecule with global index i belongs to this processor |
| 334 |
– |
|
| 335 |
– |
mol = info_->getMoleculeByGlobalIndex(i); |
| 336 |
– |
|
| 337 |
– |
if(mol == NULL) { |
| 338 |
– |
sprintf(painCave.errMsg, |
| 339 |
– |
"RestReader Error: molecule not found on node %d\n", |
| 340 |
– |
worldRank); |
| 341 |
– |
painCave.isFatal = 1; |
| 342 |
– |
simError(); |
| 156 |
|
} |
| 344 |
– |
|
| 345 |
– |
nCurObj = mol->getNIntegrableObjects(); |
| 346 |
– |
|
| 347 |
– |
MPI_Send(&nCurObj, 1, MPI_INT, masterNode, |
| 348 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 349 |
– |
|
| 350 |
– |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 351 |
– |
integrableObject != NULL; |
| 352 |
– |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 353 |
– |
|
| 354 |
– |
MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, |
| 355 |
– |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
| 356 |
– |
|
| 357 |
– |
parseErr = parseIdealLine(read_buffer, integrableObject); |
| 358 |
– |
|
| 359 |
– |
if( parseErr != NULL ){ |
| 360 |
– |
strcpy( painCave.errMsg, parseErr ); |
| 361 |
– |
simError(); |
| 362 |
– |
} |
| 363 |
– |
} |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
} |
| 367 |
– |
#endif |
| 160 |
|
} |
| 369 |
– |
|
| 370 |
– |
char* RestReader::parseIdealLine(char* readLine, StuntDouble* sd){ |
| 371 |
– |
|
| 372 |
– |
RealType pos[3]; // position place holders |
| 373 |
– |
RealType q[4]; // the quaternions |
| 374 |
– |
RealType RfromQ[3][3]; // the rotation matrix |
| 375 |
– |
RealType normalize; // to normalize the reference unit vector |
| 376 |
– |
RealType uX, uY, uZ; // reference unit vector place holders |
| 377 |
– |
RealType uselessToken; |
| 378 |
– |
StringTokenizer tokenizer(readLine); |
| 379 |
– |
int nTokens; |
| 380 |
– |
|
| 381 |
– |
nTokens = tokenizer.countTokens(); |
| 161 |
|
|
| 162 |
< |
if (nTokens < 14) { |
| 163 |
< |
sprintf(painCave.errMsg, |
| 164 |
< |
"RestReader Error: Not enough Tokens.\n"); |
| 165 |
< |
painCave.isFatal = 1; |
| 166 |
< |
simError(); |
| 167 |
< |
} |
| 168 |
< |
|
| 169 |
< |
std::string name = tokenizer.nextToken(); |
| 162 |
> |
|
| 163 |
> |
|
| 164 |
> |
void RestReader::parseDumpLine(const std::string& line) { |
| 165 |
> |
StringTokenizer tokenizer(line); |
| 166 |
> |
int nTokens; |
| 167 |
> |
|
| 168 |
> |
nTokens = tokenizer.countTokens(); |
| 169 |
> |
|
| 170 |
> |
if (nTokens < 2) { |
| 171 |
> |
sprintf(painCave.errMsg, |
| 172 |
> |
"DumpReader Error: Not enough Tokens.\n%s\n", line.c_str()); |
| 173 |
> |
painCave.isFatal = 1; |
| 174 |
> |
simError(); |
| 175 |
> |
} |
| 176 |
|
|
| 177 |
< |
if (name != sd->getType()) { |
| 178 |
< |
|
| 179 |
< |
sprintf(painCave.errMsg, |
| 395 |
< |
"RestReader Error: Atom type [%s] in %s does not " |
| 396 |
< |
"match Atom Type [%s] in .md file.\n", |
| 397 |
< |
name.c_str(), inIdealFileName.c_str(), |
| 398 |
< |
sd->getType().c_str()); |
| 399 |
< |
painCave.isFatal = 1; |
| 400 |
< |
simError(); |
| 401 |
< |
} |
| 402 |
< |
|
| 403 |
< |
pos[0] = tokenizer.nextTokenAsDouble(); |
| 404 |
< |
pos[1] = tokenizer.nextTokenAsDouble(); |
| 405 |
< |
pos[2] = tokenizer.nextTokenAsDouble(); |
| 177 |
> |
int index = tokenizer.nextTokenAsInt(); |
| 178 |
> |
|
| 179 |
> |
StuntDouble* integrableObject = info_->getIOIndexToIntegrableObject(index); |
| 180 |
|
|
| 181 |
< |
// store the positions in the stuntdouble as generic data doubles |
| 182 |
< |
DoubleGenericData* refPosX = new DoubleGenericData(); |
| 183 |
< |
refPosX->setID("refPosX"); |
| 410 |
< |
refPosX->setData(pos[0]); |
| 411 |
< |
sd->addProperty(refPosX); |
| 181 |
> |
if (integrableObject == NULL) { |
| 182 |
> |
return; |
| 183 |
> |
} |
| 184 |
|
|
| 185 |
< |
DoubleGenericData* refPosY = new DoubleGenericData(); |
| 186 |
< |
refPosY->setID("refPosY"); |
| 187 |
< |
refPosY->setData(pos[1]); |
| 188 |
< |
sd->addProperty(refPosY); |
| 189 |
< |
|
| 190 |
< |
DoubleGenericData* refPosZ = new DoubleGenericData(); |
| 191 |
< |
refPosZ->setID("refPosZ"); |
| 192 |
< |
refPosZ->setData(pos[2]); |
| 193 |
< |
sd->addProperty(refPosZ); |
| 185 |
> |
std::string type = tokenizer.nextToken(); |
| 186 |
> |
int size = type.size(); |
| 187 |
> |
Vector3d pos; |
| 188 |
> |
Vector3d vel; |
| 189 |
> |
Quat4d q; |
| 190 |
> |
Vector3d ji; |
| 191 |
> |
Vector3d force; |
| 192 |
> |
Vector3d torque; |
| 193 |
> |
|
| 194 |
> |
for(int i = 0; i < size; ++i) { |
| 195 |
> |
switch(type[i]) { |
| 196 |
> |
|
| 197 |
> |
case 'p': { |
| 198 |
> |
pos[0] = tokenizer.nextTokenAsDouble(); |
| 199 |
> |
pos[1] = tokenizer.nextTokenAsDouble(); |
| 200 |
> |
pos[2] = tokenizer.nextTokenAsDouble(); |
| 201 |
> |
break; |
| 202 |
> |
} |
| 203 |
> |
case 'v' : { |
| 204 |
> |
vel[0] = tokenizer.nextTokenAsDouble(); |
| 205 |
> |
vel[1] = tokenizer.nextTokenAsDouble(); |
| 206 |
> |
vel[2] = tokenizer.nextTokenAsDouble(); |
| 207 |
> |
break; |
| 208 |
> |
} |
| 209 |
|
|
| 210 |
< |
// we don't need the velocities |
| 211 |
< |
uselessToken = tokenizer.nextTokenAsDouble(); |
| 212 |
< |
uselessToken = tokenizer.nextTokenAsDouble(); |
| 213 |
< |
uselessToken = tokenizer.nextTokenAsDouble(); |
| 214 |
< |
|
| 215 |
< |
if (sd->isDirectional()) { |
| 216 |
< |
|
| 217 |
< |
q[0] = tokenizer.nextTokenAsDouble(); |
| 218 |
< |
q[1] = tokenizer.nextTokenAsDouble(); |
| 219 |
< |
q[2] = tokenizer.nextTokenAsDouble(); |
| 220 |
< |
q[3] = tokenizer.nextTokenAsDouble(); |
| 221 |
< |
|
| 222 |
< |
// now build the rotation matrix and find the unit vectors |
| 223 |
< |
RfromQ[0][0] = q[0]*q[0] + q[1]*q[1] - q[2]*q[2] - q[3]*q[3]; |
| 224 |
< |
RfromQ[0][1] = 2*(q[1]*q[2] + q[0]*q[3]); |
| 225 |
< |
RfromQ[0][2] = 2*(q[1]*q[3] - q[0]*q[2]); |
| 226 |
< |
RfromQ[1][0] = 2*(q[1]*q[2] - q[0]*q[3]); |
| 227 |
< |
RfromQ[1][1] = q[0]*q[0] - q[1]*q[1] + q[2]*q[2] - q[3]*q[3]; |
| 228 |
< |
RfromQ[1][2] = 2*(q[2]*q[3] + q[0]*q[1]); |
| 229 |
< |
RfromQ[2][0] = 2*(q[1]*q[3] + q[0]*q[2]); |
| 230 |
< |
RfromQ[2][1] = 2*(q[2]*q[3] - q[0]*q[1]); |
| 231 |
< |
RfromQ[2][2] = q[0]*q[0] - q[1]*q[1] - q[2]*q[2] + q[3]*q[3]; |
| 232 |
< |
|
| 233 |
< |
normalize = sqrt(RfromQ[2][0]*RfromQ[2][0] + RfromQ[2][1]*RfromQ[2][1] |
| 234 |
< |
+ RfromQ[2][2]*RfromQ[2][2]); |
| 235 |
< |
uX = RfromQ[2][0]/normalize; |
| 236 |
< |
uY = RfromQ[2][1]/normalize; |
| 237 |
< |
uZ = RfromQ[2][2]/normalize; |
| 238 |
< |
|
| 239 |
< |
// store reference unit vectors as generic data in the stuntdouble |
| 240 |
< |
DoubleGenericData* refVectorX = new DoubleGenericData(); |
| 241 |
< |
refVectorX->setID("refVectorX"); |
| 242 |
< |
refVectorX->setData(uX); |
| 243 |
< |
sd->addProperty(refVectorX); |
| 244 |
< |
|
| 245 |
< |
DoubleGenericData* refVectorY = new DoubleGenericData(); |
| 246 |
< |
refVectorY->setID("refVectorY"); |
| 247 |
< |
refVectorY->setData(uY); |
| 248 |
< |
sd->addProperty(refVectorY); |
| 249 |
< |
|
| 250 |
< |
DoubleGenericData* refVectorZ = new DoubleGenericData(); |
| 251 |
< |
refVectorZ->setID("refVectorZ"); |
| 252 |
< |
refVectorZ->setData(uZ); |
| 253 |
< |
sd->addProperty(refVectorZ); |
| 254 |
< |
} |
| 255 |
< |
|
| 256 |
< |
// we don't need the angular velocities, so let's exit the line |
| 257 |
< |
return NULL; |
| 258 |
< |
} |
| 259 |
< |
|
| 260 |
< |
void RestReader::readZangle(){ |
| 261 |
< |
|
| 475 |
< |
int i; |
| 476 |
< |
unsigned int j; |
| 477 |
< |
int isPresent; |
| 478 |
< |
|
| 479 |
< |
Molecule* mol; |
| 480 |
< |
StuntDouble* integrableObject; |
| 481 |
< |
SimInfo::MoleculeIterator mi; |
| 482 |
< |
Molecule::IntegrableObjectIterator ii; |
| 483 |
< |
|
| 484 |
< |
#ifdef IS_MPI |
| 485 |
< |
int done, which_node, which_atom; // loop counter |
| 486 |
< |
int nProc; |
| 487 |
< |
MPI_Status istatus; |
| 488 |
< |
#endif //is_mpi |
| 489 |
< |
|
| 490 |
< |
const int BUFFERSIZE = 2000; // size of the read buffer |
| 491 |
< |
int nTotObjs; // the number of atoms |
| 492 |
< |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
| 493 |
< |
|
| 494 |
< |
char *eof_test; // ptr to see when we reach the end of the file |
| 495 |
< |
char *parseErr; |
| 496 |
< |
|
| 497 |
< |
std::vector<StuntDouble*> vecParticles; |
| 498 |
< |
std::vector<RealType> tempZangs; |
| 499 |
< |
|
| 500 |
< |
inAngFileName = info_->getRestFileName(); |
| 501 |
< |
|
| 502 |
< |
inAngFileName += "0"; |
| 503 |
< |
|
| 504 |
< |
// open the omega value file for reading |
| 505 |
< |
#ifdef IS_MPI |
| 506 |
< |
if (worldRank == 0) { |
| 507 |
< |
#endif |
| 508 |
< |
isPresent = 1; |
| 509 |
< |
inAngFile = fopen(inAngFileName.c_str(), "r"); |
| 510 |
< |
if(!inAngFile){ |
| 511 |
< |
sprintf(painCave.errMsg, |
| 512 |
< |
"Restraints Warning: %s file is not present\n" |
| 513 |
< |
"\tAll omega values will be initialized to zero. If the\n" |
| 514 |
< |
"\tsimulation is starting from the idealCrystal.in reference\n" |
| 515 |
< |
"\tconfiguration, this is the desired action. If this is not\n" |
| 516 |
< |
"\tthe case, the energy calculations will be incorrect.\n", |
| 517 |
< |
inAngFileName.c_str()); |
| 518 |
< |
painCave.severity = OOPSE_WARNING; |
| 519 |
< |
painCave.isFatal = 0; |
| 520 |
< |
simError(); |
| 521 |
< |
isPresent = 0; |
| 210 |
> |
case 'q' : { |
| 211 |
> |
if (integrableObject->isDirectional()) { |
| 212 |
> |
|
| 213 |
> |
q[0] = tokenizer.nextTokenAsDouble(); |
| 214 |
> |
q[1] = tokenizer.nextTokenAsDouble(); |
| 215 |
> |
q[2] = tokenizer.nextTokenAsDouble(); |
| 216 |
> |
q[3] = tokenizer.nextTokenAsDouble(); |
| 217 |
> |
|
| 218 |
> |
RealType qlen = q.length(); |
| 219 |
> |
if (qlen < OpenMD::epsilon) { //check quaternion is not equal to 0 |
| 220 |
> |
|
| 221 |
> |
sprintf(painCave.errMsg, |
| 222 |
> |
"DumpReader Error: initial quaternion error (q0^2 + q1^2 + q2^2 + q3^2) ~ 0\n"); |
| 223 |
> |
painCave.isFatal = 1; |
| 224 |
> |
simError(); |
| 225 |
> |
|
| 226 |
> |
} |
| 227 |
> |
|
| 228 |
> |
q.normalize(); |
| 229 |
> |
} |
| 230 |
> |
break; |
| 231 |
> |
} |
| 232 |
> |
case 'j' : { |
| 233 |
> |
if (integrableObject->isDirectional()) { |
| 234 |
> |
ji[0] = tokenizer.nextTokenAsDouble(); |
| 235 |
> |
ji[1] = tokenizer.nextTokenAsDouble(); |
| 236 |
> |
ji[2] = tokenizer.nextTokenAsDouble(); |
| 237 |
> |
} |
| 238 |
> |
break; |
| 239 |
> |
} |
| 240 |
> |
case 'f': { |
| 241 |
> |
force[0] = tokenizer.nextTokenAsDouble(); |
| 242 |
> |
force[1] = tokenizer.nextTokenAsDouble(); |
| 243 |
> |
force[2] = tokenizer.nextTokenAsDouble(); |
| 244 |
> |
|
| 245 |
> |
break; |
| 246 |
> |
} |
| 247 |
> |
case 't' : { |
| 248 |
> |
torque[0] = tokenizer.nextTokenAsDouble(); |
| 249 |
> |
torque[1] = tokenizer.nextTokenAsDouble(); |
| 250 |
> |
torque[2] = tokenizer.nextTokenAsDouble(); |
| 251 |
> |
|
| 252 |
> |
break; |
| 253 |
> |
} |
| 254 |
> |
default: { |
| 255 |
> |
sprintf(painCave.errMsg, |
| 256 |
> |
"DumpReader Error: %s is an unrecognized type\n", type.c_str()); |
| 257 |
> |
painCave.isFatal = 1; |
| 258 |
> |
simError(); |
| 259 |
> |
break; |
| 260 |
> |
} |
| 261 |
> |
|
| 262 |
|
} |
| 523 |
– |
|
| 524 |
– |
#ifdef IS_MPI |
| 525 |
– |
// let the other nodes know the status of the file search |
| 526 |
– |
MPI_Bcast(&isPresent, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 527 |
– |
#endif // is_mpi |
| 528 |
– |
|
| 529 |
– |
if (!isPresent) { |
| 530 |
– |
zeroZangle(); |
| 531 |
– |
return; |
| 532 |
– |
} |
| 533 |
– |
|
| 534 |
– |
#ifdef IS_MPI |
| 263 |
|
} |
| 264 |
+ |
|
| 265 |
+ |
// keep the position in case we need it for a molecular restraint: |
| 266 |
|
|
| 267 |
< |
// listen to node 0 to see if we should exit this function |
| 268 |
< |
if (worldRank != 0) { |
| 269 |
< |
MPI_Bcast(&isPresent, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 270 |
< |
if (!isPresent) { |
| 271 |
< |
zeroZangle(); |
| 272 |
< |
return; |
| 267 |
> |
all_pos_[index] = pos; |
| 268 |
> |
|
| 269 |
> |
// is this io restrained? |
| 270 |
> |
GenericData* data = integrableObject->getPropertyByName("Restraint"); |
| 271 |
> |
ObjectRestraint* oRest; |
| 272 |
> |
|
| 273 |
> |
if (data != NULL) { |
| 274 |
> |
// make sure we can reinterpret the generic data as restraint data: |
| 275 |
> |
RestraintData* restData= dynamic_cast<RestraintData*>(data); |
| 276 |
> |
if (restData != NULL) { |
| 277 |
> |
// make sure we can reinterpet the restraint data as a pointer to |
| 278 |
> |
// an ObjectRestraint: |
| 279 |
> |
oRest = dynamic_cast<ObjectRestraint*>(restData->getData()); |
| 280 |
> |
if (oRest != NULL) { |
| 281 |
> |
if (integrableObject->isDirectional()) { |
| 282 |
> |
oRest->setReferenceStructure(pos, q.toRotationMatrix3()); |
| 283 |
> |
} else { |
| 284 |
> |
oRest->setReferenceStructure(pos); |
| 285 |
> |
} |
| 286 |
> |
} |
| 287 |
|
} |
| 288 |
|
} |
| 289 |
< |
|
| 290 |
< |
strcpy( checkPointMsg, "zAngle file opened successfully for reading." ); |
| 291 |
< |
MPIcheckPoint(); |
| 292 |
< |
#endif |
| 293 |
< |
|
| 294 |
< |
#ifndef IS_MPI |
| 295 |
< |
|
| 296 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
| 297 |
< |
if( eof_test == NULL ){ |
| 298 |
< |
sprintf( painCave.errMsg, |
| 299 |
< |
"RestraintReader error: error reading 1st line of \"%s\"\n", |
| 300 |
< |
inAngFileName.c_str() ); |
| 301 |
< |
painCave.isFatal = 1; |
| 302 |
< |
simError(); |
| 289 |
> |
|
| 290 |
> |
} |
| 291 |
> |
|
| 292 |
> |
|
| 293 |
> |
|
| 294 |
> |
void RestReader::readFrameProperties(std::istream& inputStream) { |
| 295 |
> |
inputStream.getline(buffer, bufferSize); |
| 296 |
> |
std::string line(buffer); |
| 297 |
> |
|
| 298 |
> |
if (line.find("<FrameData>") == std::string::npos) { |
| 299 |
> |
sprintf(painCave.errMsg, |
| 300 |
> |
"DumpReader Error: Missing <FrameData>\n"); |
| 301 |
> |
painCave.isFatal = 1; |
| 302 |
> |
simError(); |
| 303 |
|
} |
| 304 |
< |
|
| 305 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
| 306 |
< |
while ( eof_test != NULL ) { |
| 307 |
< |
// check for and ignore blank lines |
| 308 |
< |
if ( read_buffer != NULL ) |
| 309 |
< |
tempZangs.push_back( atof(read_buffer) ); |
| 310 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
| 567 |
< |
} |
| 568 |
< |
|
| 569 |
< |
nTotObjs = info_->getNGlobalIntegrableObjects(); |
| 570 |
< |
|
| 571 |
< |
if( nTotObjs != tempZangs.size() ){ |
| 572 |
< |
sprintf( painCave.errMsg, |
| 573 |
< |
"RestraintReader zAngle reading error. %s nIntegrable, %d, " |
| 574 |
< |
"does not match the meta-data file's nIntegrable, %d.\n", |
| 575 |
< |
inAngFileName.c_str(), tempZangs.size(), nTotObjs ); |
| 576 |
< |
painCave.isFatal = 1; |
| 577 |
< |
simError(); |
| 578 |
< |
} |
| 579 |
< |
|
| 580 |
< |
// load the zAngles into the integrable objects |
| 581 |
< |
i = 0; |
| 582 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 583 |
< |
mol = info_->nextMolecule(mi)) { |
| 304 |
> |
|
| 305 |
> |
// restraints don't care about frame data (unless we need to wrap |
| 306 |
> |
// coordinates, but we'll worry about that later), so |
| 307 |
> |
// we'll just scan ahead until the end of the frame data: |
| 308 |
> |
|
| 309 |
> |
while(inputStream.getline(buffer, bufferSize)) { |
| 310 |
> |
line = buffer; |
| 311 |
|
|
| 312 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 313 |
< |
integrableObject != NULL; |
| 587 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
| 588 |
< |
|
| 589 |
< |
integrableObject->setZangle(tempZangs[i]); |
| 590 |
< |
i++; |
| 312 |
> |
if(line.find("</FrameData>") != std::string::npos) { |
| 313 |
> |
break; |
| 314 |
|
} |
| 315 |
+ |
|
| 316 |
|
} |
| 593 |
– |
|
| 594 |
– |
// MPI Section of code.......... |
| 595 |
– |
#else //IS_MPI |
| 596 |
– |
|
| 597 |
– |
// first thing first, suspend fatalities. |
| 598 |
– |
painCave.isEventLoop = 1; |
| 317 |
|
|
| 600 |
– |
int masterNode = 0; |
| 601 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 602 |
– |
int haveError; |
| 603 |
– |
int intObjIndex; |
| 604 |
– |
int intObjIndexTransfer; |
| 605 |
– |
|
| 606 |
– |
int nCurObj; |
| 607 |
– |
RealType angleTranfer; |
| 608 |
– |
|
| 609 |
– |
nTotObjs = info_->getNGlobalIntegrableObjects(); |
| 610 |
– |
haveError = 0; |
| 611 |
– |
|
| 612 |
– |
if (worldRank == masterNode) { |
| 613 |
– |
|
| 614 |
– |
eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
| 615 |
– |
if( eof_test == NULL ){ |
| 616 |
– |
sprintf( painCave.errMsg, |
| 617 |
– |
"Error reading 1st line of %s \n ",inAngFileName.c_str()); |
| 618 |
– |
haveError = 1; |
| 619 |
– |
simError(); |
| 620 |
– |
} |
| 621 |
– |
|
| 622 |
– |
// let node 0 load the temporary angle vector |
| 623 |
– |
eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
| 624 |
– |
while ( eof_test != NULL ) { |
| 625 |
– |
// check for and ignore blank lines |
| 626 |
– |
if ( read_buffer != NULL ) |
| 627 |
– |
tempZangs.push_back( atof(read_buffer) ); |
| 628 |
– |
eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
| 629 |
– |
} |
| 630 |
– |
|
| 631 |
– |
// Check to see that the number of integrable objects in the |
| 632 |
– |
// intial configuration file is the same as derived from the |
| 633 |
– |
// meta-data file. |
| 634 |
– |
if( nTotObjs != tempZangs.size() ){ |
| 635 |
– |
sprintf( painCave.errMsg, |
| 636 |
– |
"RestraintReader zAngle reading Error. %s nIntegrable, %d, " |
| 637 |
– |
"does not match the meta-data file's nIntegrable, %d.\n", |
| 638 |
– |
inAngFileName.c_str(), tempZangs.size(), nTotObjs); |
| 639 |
– |
haveError= 1; |
| 640 |
– |
simError(); |
| 641 |
– |
} |
| 642 |
– |
|
| 643 |
– |
// At this point, node 0 has a tempZangs vector completed, and |
| 644 |
– |
// everyone else has nada |
| 645 |
– |
|
| 646 |
– |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 647 |
– |
// Get the Node number which has this atom |
| 648 |
– |
which_node = info_->getMolToProc(i); |
| 649 |
– |
|
| 650 |
– |
if (which_node == masterNode) { |
| 651 |
– |
mol = info_->getMoleculeByGlobalIndex(i); |
| 652 |
– |
|
| 653 |
– |
if(mol == NULL) { |
| 654 |
– |
strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
| 655 |
– |
haveError = 1; |
| 656 |
– |
simError(); |
| 657 |
– |
} |
| 658 |
– |
|
| 659 |
– |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 660 |
– |
integrableObject != NULL; |
| 661 |
– |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 662 |
– |
intObjIndex = integrableObject->getGlobalIndex(); |
| 663 |
– |
integrableObject->setZangle(tempZangs[intObjIndex]); |
| 664 |
– |
} |
| 665 |
– |
|
| 666 |
– |
} else { |
| 667 |
– |
// I am MASTER OF THE UNIVERSE, but I don't own this molecule |
| 668 |
– |
// listen for the number of integrableObjects in the molecule |
| 669 |
– |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
| 670 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 671 |
– |
|
| 672 |
– |
for(j=0; j < nCurObj; j++){ |
| 673 |
– |
// listen for which integrableObject we need to send the value for |
| 674 |
– |
MPI_Recv(&intObjIndexTransfer, 1, MPI_INT, which_node, |
| 675 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 676 |
– |
angleTransfer = tempZangs[intObjIndexTransfer]; |
| 677 |
– |
// send the value to the node so it can initialize the object |
| 678 |
– |
MPI_Send(&angleTransfer, 1, MPI_REALTYPE, which_node, |
| 679 |
– |
TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); |
| 680 |
– |
} |
| 681 |
– |
} |
| 682 |
– |
} |
| 683 |
– |
} else { |
| 684 |
– |
// I am SLAVE TO THE MASTER |
| 685 |
– |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 686 |
– |
int which_node = info_->getMolToProc(i); |
| 687 |
– |
|
| 688 |
– |
if (which_node == worldRank) { |
| 689 |
– |
|
| 690 |
– |
// BUT I OWN THIS MOLECULE!!! |
| 691 |
– |
|
| 692 |
– |
mol = info_->getMoleculeByGlobalIndex(i); |
| 693 |
– |
|
| 694 |
– |
if(mol == NULL) { |
| 695 |
– |
sprintf(painCave.errMsg, |
| 696 |
– |
"RestReader Error: molecule not found on node %d\n", |
| 697 |
– |
worldRank); |
| 698 |
– |
painCave.isFatal = 1; |
| 699 |
– |
simError(); |
| 700 |
– |
} |
| 701 |
– |
|
| 702 |
– |
nCurObj = mol->getNIntegrableObjects(); |
| 703 |
– |
// send the number of integrableObjects in the molecule |
| 704 |
– |
MPI_Send(&nCurObj, 1, MPI_INT, 0, |
| 705 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 706 |
– |
|
| 707 |
– |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 708 |
– |
integrableObject != NULL; |
| 709 |
– |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 710 |
– |
intObjIndexTransfer = integrableObject->getGlobalIndex(); |
| 711 |
– |
// send the global index of the integrableObject |
| 712 |
– |
MPI_Send(&intObjIndexTransfer, 1, MPI_INT, 0, |
| 713 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 714 |
– |
// listen for the value we want to set locally |
| 715 |
– |
MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0, |
| 716 |
– |
TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); |
| 717 |
– |
|
| 718 |
– |
integrableObject->setZangle(angleTransfer); |
| 719 |
– |
} |
| 720 |
– |
} |
| 721 |
– |
} |
| 722 |
– |
} |
| 723 |
– |
#endif |
| 318 |
|
} |
| 725 |
– |
|
| 726 |
– |
void RestReader :: zeroZangle(){ |
| 727 |
– |
|
| 728 |
– |
int i; |
| 729 |
– |
unsigned int j; |
| 730 |
– |
int nTotObjs; // the number of atoms |
| 731 |
– |
|
| 732 |
– |
Molecule* mol; |
| 733 |
– |
StuntDouble* integrableObject; |
| 734 |
– |
SimInfo::MoleculeIterator mi; |
| 735 |
– |
Molecule::IntegrableObjectIterator ii; |
| 736 |
– |
|
| 737 |
– |
std::vector<StuntDouble*> vecParticles; |
| 738 |
– |
|
| 739 |
– |
#ifndef IS_MPI |
| 740 |
– |
// set all zAngles to 0.0 |
| 741 |
– |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 742 |
– |
mol = info_->nextMolecule(mi)) |
| 743 |
– |
|
| 744 |
– |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 745 |
– |
integrableObject != NULL; |
| 746 |
– |
integrableObject = mol->nextIntegrableObject(ii)) |
| 747 |
– |
integrableObject->setZangle( 0.0 ); |
| 748 |
– |
|
| 749 |
– |
|
| 750 |
– |
// MPI Section of code.......... |
| 751 |
– |
#else //IS_MPI |
| 752 |
– |
|
| 753 |
– |
// first thing first, suspend fatalities. |
| 754 |
– |
painCave.isEventLoop = 1; |
| 755 |
– |
|
| 756 |
– |
int masterNode = 0; |
| 757 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 758 |
– |
int haveError; |
| 759 |
– |
int which_node; |
| 760 |
– |
|
| 761 |
– |
MPI_Status istatus; |
| 762 |
– |
|
| 763 |
– |
int nCurObj; |
| 764 |
– |
RealType angleTranfer; |
| 765 |
– |
|
| 766 |
– |
nTotObjs = info_->getNGlobalIntegrableObjects(); |
| 767 |
– |
haveError = 0; |
| 768 |
– |
if (worldRank == masterNode) { |
| 319 |
|
|
| 320 |
< |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 321 |
< |
// Get the Node number which has this atom |
| 772 |
< |
which_node = info_->getMolToProc(i); |
| 773 |
< |
|
| 774 |
< |
// let's let node 0 pass out constant values to all the processors |
| 775 |
< |
if (worldRank == masterNode) { |
| 776 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
| 777 |
< |
|
| 778 |
< |
if(mol == NULL) { |
| 779 |
< |
strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
| 780 |
< |
haveError = 1; |
| 781 |
< |
simError(); |
| 782 |
< |
} |
| 783 |
< |
|
| 784 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 785 |
< |
integrableObject != NULL; |
| 786 |
< |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 787 |
< |
|
| 788 |
< |
integrableObject->setZangle( 0.0 ); |
| 789 |
< |
|
| 790 |
< |
} |
| 791 |
< |
|
| 792 |
< |
} else { |
| 793 |
< |
// I am MASTER OF THE UNIVERSE, but I don't own this molecule |
| 794 |
< |
|
| 795 |
< |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
| 796 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 797 |
< |
|
| 798 |
< |
for(j=0; j < nCurObj; j++){ |
| 799 |
< |
angleTransfer = 0.0; |
| 800 |
< |
MPI_Send(&angleTransfer, 1, MPI_REALTYPE, which_node, |
| 801 |
< |
TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); |
| 802 |
< |
|
| 803 |
< |
} |
| 804 |
< |
} |
| 805 |
< |
} |
| 806 |
< |
} else { |
| 807 |
< |
// I am SLAVE TO THE MASTER |
| 808 |
< |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 809 |
< |
int which_node = info_->getMolToProc(i); |
| 810 |
< |
|
| 811 |
< |
if (which_node == worldRank) { |
| 812 |
< |
|
| 813 |
< |
// BUT I OWN THIS MOLECULE!!! |
| 814 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
| 815 |
< |
|
| 816 |
< |
if(mol == NULL) { |
| 817 |
< |
sprintf(painCave.errMsg, |
| 818 |
< |
"RestReader Error: molecule not found on node %d\n", |
| 819 |
< |
worldRank); |
| 820 |
< |
painCave.isFatal = 1; |
| 821 |
< |
simError(); |
| 822 |
< |
} |
| 823 |
< |
|
| 824 |
< |
nCurObj = mol->getNIntegrableObjects(); |
| 825 |
< |
|
| 826 |
< |
MPI_Send(&nCurObj, 1, MPI_INT, 0, |
| 827 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 828 |
< |
|
| 829 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 830 |
< |
integrableObject != NULL; |
| 831 |
< |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 832 |
< |
|
| 833 |
< |
MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0, |
| 834 |
< |
TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); |
| 835 |
< |
vecParticles[j]->setZangle(angleTransfer); |
| 836 |
< |
} |
| 837 |
< |
} |
| 838 |
< |
} |
| 839 |
< |
} |
| 840 |
< |
#endif |
| 841 |
< |
} |
| 842 |
< |
|
| 843 |
< |
} // end namespace oopse |
| 320 |
> |
|
| 321 |
> |
}//end namespace OpenMD |