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