1 |
+ |
#define _FILE_OFFSET_BITS 64 |
2 |
|
#include <iostream> |
3 |
< |
#include <cmath> |
3 |
> |
#include <math.h> |
4 |
|
|
5 |
|
#include <stdio.h> |
6 |
|
#include <stdlib.h> |
11 |
|
|
12 |
|
#include "ReadWrite.hpp" |
13 |
|
#include "simError.h" |
14 |
+ |
#include "GenericData.hpp" |
15 |
|
|
16 |
|
#ifdef IS_MPI |
17 |
|
#include <mpi.h> |
41 |
|
painCave.isFatal = 1; |
42 |
|
simError(); |
43 |
|
} |
44 |
< |
|
44 |
> |
|
45 |
|
strcpy( c_in_name, in_name); |
46 |
|
#ifdef IS_MPI |
47 |
|
} |
48 |
< |
strcpy( checkPointMsg, "Infile opened for reading successfully." ); |
48 |
> |
else{ |
49 |
> |
sprintf( c_in_name, "mpiNodeParser_%d", worldRank ); |
50 |
> |
} |
51 |
> |
|
52 |
> |
strcpy( checkPointMsg, "Infile opened for reading successfully." ); |
53 |
|
MPIcheckPoint(); |
54 |
|
#endif |
55 |
< |
return; |
55 |
> |
return; |
56 |
|
} |
57 |
|
|
58 |
|
InitializeFromFile::~InitializeFromFile( ){ |
78 |
|
|
79 |
|
void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ |
80 |
|
|
81 |
< |
int i, j, done, which_node, which_atom; // loop counter |
81 |
> |
int i, j; |
82 |
|
|
77 |
– |
const int BUFFERSIZE = 2000; // size of the read buffer |
78 |
– |
int n_atoms; // the number of atoms |
79 |
– |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
83 |
|
#ifdef IS_MPI |
84 |
< |
char send_buffer[BUFFERSIZE]; |
85 |
< |
#endif |
84 |
> |
int done, which_node, which_atom; // loop counter |
85 |
> |
#endif //is_mpi |
86 |
|
|
87 |
< |
char *eof_test; // ptr to see when we reach the end of the file |
87 |
> |
const int BUFFERSIZE = 2000; // size of the read buffer |
88 |
> |
int nTotObjs; // the number of atoms |
89 |
> |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
90 |
> |
|
91 |
> |
char *eof_test; // ptr to see when we reach the end of the file |
92 |
|
char *parseErr; |
86 |
– |
int procIndex; |
87 |
– |
double currTime; |
88 |
– |
double boxMat[9]; |
89 |
– |
double theBoxMat3[3][3]; |
93 |
|
|
94 |
+ |
vector<StuntDouble*> integrableObjects; |
95 |
+ |
|
96 |
|
simnfo = the_simnfo; |
97 |
|
|
98 |
|
|
106 |
|
simError(); |
107 |
|
} |
108 |
|
|
109 |
< |
n_atoms = atoi( read_buffer ); |
109 |
> |
nTotObjs = atoi( read_buffer ); |
110 |
|
|
111 |
< |
Atom **atoms = simnfo->atoms; |
107 |
< |
DirectionalAtom* dAtom; |
108 |
< |
|
109 |
< |
if( n_atoms != simnfo->n_atoms ){ |
111 |
> |
if( nTotObjs != simnfo->getTotIntegrableObjects() ){ |
112 |
|
sprintf( painCave.errMsg, |
113 |
|
"Initialize from File error. %s n_atoms, %d, " |
114 |
|
"does not match the BASS file's n_atoms, %d.\n", |
115 |
< |
c_in_name, n_atoms, simnfo->n_atoms ); |
115 |
> |
c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); |
116 |
|
painCave.isFatal = 1; |
117 |
|
simError(); |
118 |
|
} |
119 |
< |
|
120 |
< |
//read the box mat from the comment line |
121 |
< |
|
119 |
> |
|
120 |
> |
//read the box mat from the comment line |
121 |
> |
|
122 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
123 |
|
if(eof_test == NULL){ |
124 |
|
sprintf( painCave.errMsg, |
127 |
|
simError(); |
128 |
|
} |
129 |
|
|
130 |
< |
parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
130 |
> |
parseErr = parseCommentLine( read_buffer, simnfo); |
131 |
|
if( parseErr != NULL ){ |
132 |
|
strcpy( painCave.errMsg, parseErr ); |
133 |
|
painCave.isFatal = 1; |
134 |
|
simError(); |
135 |
|
} |
136 |
|
|
137 |
< |
for(i=0;i<3;i++) |
136 |
< |
for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
137 |
> |
//parse dump lines |
138 |
|
|
139 |
< |
simnfo->setBoxM( theBoxMat3 ); |
139 |
< |
simnfo->setTime( currTime ); |
139 |
> |
for( i=0; i < simnfo->n_mol; i++){ |
140 |
|
|
141 |
+ |
integrableObjects = (simnfo->molecules[i]).getIntegrableObjects(); |
142 |
|
|
143 |
< |
for( i=0; i < n_atoms; i++){ |
143 |
< |
|
144 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
145 |
< |
if(eof_test == NULL){ |
146 |
< |
sprintf(painCave.errMsg, |
147 |
< |
"error in reading file %s\n" |
148 |
< |
"natoms = %d; index = %d\n" |
149 |
< |
"error reading the line from the file.\n", |
150 |
< |
c_in_name, n_atoms, i ); |
151 |
< |
painCave.isFatal = 1; |
152 |
< |
simError(); |
153 |
< |
} |
143 |
> |
for(j = 0; j < integrableObjects.size(); j++){ |
144 |
|
|
145 |
< |
|
146 |
< |
parseErr = parseDumpLine( read_buffer, i ); |
147 |
< |
if( parseErr != NULL ){ |
148 |
< |
strcpy( painCave.errMsg, parseErr ); |
149 |
< |
painCave.isFatal = 1; |
150 |
< |
simError(); |
145 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
146 |
> |
if(eof_test == NULL){ |
147 |
> |
sprintf(painCave.errMsg, |
148 |
> |
"error in reading file %s\n" |
149 |
> |
"natoms = %d; index = %d\n" |
150 |
> |
"error reading the line from the file.\n", |
151 |
> |
c_in_name, nTotObjs, i ); |
152 |
> |
painCave.isFatal = 1; |
153 |
> |
simError(); |
154 |
> |
} |
155 |
> |
|
156 |
> |
parseErr = parseDumpLine( read_buffer, integrableObjects[j]); |
157 |
> |
if( parseErr != NULL ){ |
158 |
> |
strcpy( painCave.errMsg, parseErr ); |
159 |
> |
painCave.isFatal = 1; |
160 |
> |
simError(); |
161 |
> |
} |
162 |
|
} |
163 |
|
} |
164 |
|
|
164 |
– |
|
165 |
|
// MPI Section of code.......... |
166 |
|
#else //IS_MPI |
167 |
|
|
170 |
|
|
171 |
|
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
172 |
|
int haveError; |
173 |
< |
|
173 |
> |
|
174 |
|
MPI_Status istatus; |
175 |
< |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
175 |
> |
int *MolToProcMap = mpiSim->getMolToProcMap(); |
176 |
> |
int localIndex; |
177 |
> |
int nCurObj; |
178 |
|
|
177 |
– |
|
179 |
|
haveError = 0; |
180 |
|
if (worldRank == 0) { |
181 |
|
|
182 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
183 |
|
if( eof_test == NULL ){ |
184 |
|
sprintf( painCave.errMsg, |
185 |
< |
"Error reading 1st line of %d \n ",c_in_name); |
185 |
> |
"Error reading 1st line of %s \n ",c_in_name); |
186 |
|
haveError = 1; |
187 |
|
simError(); |
188 |
|
} |
189 |
< |
|
190 |
< |
n_atoms = atoi( read_buffer ); |
191 |
< |
|
192 |
< |
Atom **atoms = simnfo->atoms; |
192 |
< |
DirectionalAtom* dAtom; |
193 |
< |
|
194 |
< |
// Check to see that the number of atoms in the intial configuration file is the |
189 |
> |
|
190 |
> |
nTotObjs = atoi( read_buffer ); |
191 |
> |
|
192 |
> |
// Check to see that the number of integrable objects in the intial configuration file is the |
193 |
|
// same as declared in simBass. |
194 |
< |
|
195 |
< |
if( n_atoms != mpiSim->getTotAtoms() ){ |
194 |
> |
|
195 |
> |
if( nTotObjs != simnfo->getTotIntegrableObjects()){ |
196 |
|
sprintf( painCave.errMsg, |
197 |
|
"Initialize from File error. %s n_atoms, %d, " |
198 |
|
"does not match the BASS file's n_atoms, %d.\n", |
199 |
< |
c_in_name, n_atoms, simnfo->n_atoms ); |
199 |
> |
c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); |
200 |
|
haveError= 1; |
201 |
|
simError(); |
202 |
|
} |
203 |
< |
|
204 |
< |
//read the boxMat from the comment line |
205 |
< |
|
203 |
> |
|
204 |
> |
//read the boxMat from the comment line |
205 |
> |
|
206 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
207 |
|
if(eof_test == NULL){ |
208 |
|
sprintf( painCave.errMsg, |
210 |
|
haveError = 1; |
211 |
|
simError(); |
212 |
|
} |
213 |
< |
|
214 |
< |
parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
213 |
> |
|
214 |
> |
//Every single processor will parse the comment line by itself |
215 |
> |
//By using this way, we might lose some efficiency, but if we want to add |
216 |
> |
//more parameters into comment line, we only need to modify function |
217 |
> |
//parseCommentLine |
218 |
> |
|
219 |
> |
MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); |
220 |
> |
|
221 |
> |
parseErr = parseCommentLine( read_buffer, simnfo); |
222 |
> |
|
223 |
|
if( parseErr != NULL ){ |
224 |
|
strcpy( painCave.errMsg, parseErr ); |
225 |
|
haveError = 1; |
226 |
|
simError(); |
227 |
|
} |
228 |
|
|
229 |
< |
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
230 |
< |
MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
231 |
< |
|
232 |
< |
if(haveError) nodeZeroError(); |
229 |
> |
for (i=0 ; i < mpiSim->getTotNmol(); i++) { |
230 |
> |
which_node = MolToProcMap[i]; |
231 |
> |
if(which_node == 0){ |
232 |
> |
//molecules belong to master node |
233 |
|
|
234 |
< |
for (i=0 ; i < mpiSim->getTotAtoms(); i++) { |
235 |
< |
|
236 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
237 |
< |
if(eof_test == NULL){ |
238 |
< |
sprintf(painCave.errMsg, |
239 |
< |
"error in reading file %s\n" |
234 |
< |
"natoms = %d; index = %d\n" |
235 |
< |
"error reading the line from the file.\n", |
236 |
< |
c_in_name, n_atoms, i ); |
237 |
< |
haveError= 1; |
238 |
< |
simError(); |
234 |
> |
localIndex = mpiSim->getGlobalToLocalMol(i); |
235 |
> |
|
236 |
> |
if(localIndex == -1) { |
237 |
> |
strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
238 |
> |
haveError = 1; |
239 |
> |
simError(); |
240 |
|
} |
240 |
– |
|
241 |
– |
if(haveError) nodeZeroError(); |
241 |
|
|
242 |
< |
// Get the Node number which wants this atom: |
243 |
< |
which_node = AtomToProcMap[i]; |
244 |
< |
if (which_node == 0) { |
245 |
< |
parseErr = parseDumpLine( read_buffer, i ); |
246 |
< |
if( parseErr != NULL ){ |
247 |
< |
strcpy( painCave.errMsg, parseErr ); |
248 |
< |
haveError = 1; |
249 |
< |
simError(); |
250 |
< |
} |
251 |
< |
if(haveError) nodeZeroError(); |
252 |
< |
} |
253 |
< |
|
254 |
< |
else { |
255 |
< |
|
256 |
< |
myStatus = 1; |
258 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
259 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
260 |
< |
MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
261 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
262 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
263 |
< |
MPI_COMM_WORLD); |
264 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
265 |
< |
MPI_COMM_WORLD, &istatus); |
266 |
< |
|
267 |
< |
if(!myStatus) nodeZeroError(); |
268 |
< |
} |
269 |
< |
} |
270 |
< |
myStatus = -1; |
271 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
272 |
< |
MPI_Send( &myStatus, 1, MPI_INT, j, |
273 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
274 |
< |
} |
275 |
< |
|
276 |
< |
} else { |
277 |
< |
|
278 |
< |
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
279 |
< |
MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
242 |
> |
integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); |
243 |
> |
for(j=0; j < integrableObjects.size(); j++){ |
244 |
> |
|
245 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
246 |
> |
if(eof_test == NULL){ |
247 |
> |
sprintf(painCave.errMsg, |
248 |
> |
"error in reading file %s\n" |
249 |
> |
"natoms = %d; index = %d\n" |
250 |
> |
"error reading the line from the file.\n", |
251 |
> |
c_in_name, nTotObjs, i ); |
252 |
> |
haveError= 1; |
253 |
> |
simError(); |
254 |
> |
} |
255 |
> |
|
256 |
> |
if(haveError) nodeZeroError(); |
257 |
|
|
258 |
< |
done = 0; |
259 |
< |
while (!done) { |
258 |
> |
parseDumpLine(read_buffer, integrableObjects[i]); |
259 |
> |
|
260 |
> |
} |
261 |
|
|
284 |
– |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
285 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
286 |
– |
|
287 |
– |
if(!myStatus) anonymousNodeDie(); |
288 |
– |
|
289 |
– |
if(myStatus < 0) break; |
262 |
|
|
263 |
< |
MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
264 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
265 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
263 |
> |
} |
264 |
> |
else{ |
265 |
> |
//molecule belongs to slave nodes |
266 |
> |
|
267 |
> |
MPI_Recv(&nCurObj, 1, MPI_INT, 0, |
268 |
|
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
269 |
|
|
270 |
< |
myStatus = 1; |
271 |
< |
parseErr = parseDumpLine( read_buffer, which_atom ); |
272 |
< |
if( parseErr != NULL ){ |
273 |
< |
strcpy( painCave.errMsg, parseErr ); |
274 |
< |
myStatus = 0;; |
275 |
< |
simError(); |
270 |
> |
for(j=0; j < integrableObjects.size(); j++){ |
271 |
> |
|
272 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
273 |
> |
if(eof_test == NULL){ |
274 |
> |
sprintf(painCave.errMsg, |
275 |
> |
"error in reading file %s\n" |
276 |
> |
"natoms = %d; index = %d\n" |
277 |
> |
"error reading the line from the file.\n", |
278 |
> |
c_in_name, nTotObjs, i ); |
279 |
> |
haveError= 1; |
280 |
> |
simError(); |
281 |
> |
} |
282 |
> |
|
283 |
> |
if(haveError) nodeZeroError(); |
284 |
> |
|
285 |
> |
MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
286 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
287 |
> |
|
288 |
> |
} |
289 |
> |
|
290 |
|
} |
291 |
|
|
304 |
– |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
305 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
306 |
– |
|
292 |
|
} |
293 |
+ |
|
294 |
|
} |
295 |
< |
|
296 |
< |
// last thing last, enable fatalities. |
297 |
< |
painCave.isEventLoop = 0; |
295 |
> |
else{ |
296 |
> |
//actions taken at slave nodes |
297 |
> |
for (i=0 ; i < mpiSim->getTotNmol(); i++) { |
298 |
> |
which_node = MolToProcMap[i]; |
299 |
> |
|
300 |
> |
if(which_node == worldRank){ |
301 |
> |
//molecule with global index i belongs to this processor |
302 |
> |
|
303 |
> |
localIndex = mpiSim->getGlobalToLocalMol(i); |
304 |
|
|
305 |
< |
for(i=0;i<3;i++) |
306 |
< |
for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
305 |
> |
if(localIndex == -1) { |
306 |
> |
sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank); |
307 |
> |
haveError = 1; |
308 |
> |
simError(); |
309 |
> |
} |
310 |
|
|
311 |
< |
simnfo->setBoxM( theBoxMat3 ); |
317 |
< |
simnfo->setTime( currTime ); |
311 |
> |
integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); |
312 |
|
|
313 |
< |
|
313 |
> |
nCurObj = integrableObjects.size(); |
314 |
> |
|
315 |
> |
MPI_Recv(&nCurObj, 1, MPI_INT, 0, |
316 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
317 |
> |
|
318 |
> |
for(j = 0; j < integrableObjects.size(); j++){ |
319 |
> |
|
320 |
> |
MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
321 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
322 |
> |
|
323 |
> |
parseErr = parseDumpLine(read_buffer, integrableObjects[j]); |
324 |
> |
|
325 |
> |
if( parseErr != NULL ){ |
326 |
> |
strcpy( painCave.errMsg, parseErr ); |
327 |
> |
simError(); |
328 |
> |
} |
329 |
> |
|
330 |
> |
} |
331 |
> |
|
332 |
> |
} |
333 |
> |
|
334 |
> |
} |
335 |
> |
|
336 |
> |
} |
337 |
|
#endif |
338 |
|
} |
339 |
|
|
340 |
< |
char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){ |
340 |
> |
char* InitializeFromFile::parseDumpLine(char* readLine, StuntDouble* sd){ |
341 |
|
|
342 |
< |
char *foo; // the pointer to the current string token |
343 |
< |
|
342 |
> |
char *foo; // the pointer to the current string token |
343 |
> |
|
344 |
|
double pos[3]; // position place holders |
345 |
|
double vel[3]; // velocity placeholders |
346 |
|
double q[4]; // the quaternions |
347 |
< |
double jx, jy, jz; // angular velocity placeholders; |
347 |
> |
double ji[3]; // angular velocity placeholders; |
348 |
|
double qSqr, qLength; // needed to normalize the quaternion vector. |
332 |
– |
|
333 |
– |
Atom **atoms = simnfo->atoms; |
334 |
– |
DirectionalAtom* dAtom; |
335 |
– |
|
336 |
– |
int j, n_atoms, atomIndex; |
349 |
|
|
338 |
– |
#ifdef IS_MPI |
339 |
– |
n_atoms = mpiSim->getTotAtoms(); |
340 |
– |
atomIndex=-1; |
341 |
– |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
342 |
– |
if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; |
343 |
– |
} |
344 |
– |
if (atomIndex == -1) { |
345 |
– |
sprintf( painCave.errMsg, |
346 |
– |
"Initialize from file error. Atom at index %d " |
347 |
– |
"in file %s does not exist on processor %d .\n", |
348 |
– |
globalIndex, c_in_name, mpiSim->getMyNode() ); |
349 |
– |
return strdup( painCave.errMsg ); |
350 |
– |
} |
351 |
– |
#else |
352 |
– |
n_atoms = simnfo->n_atoms; |
353 |
– |
atomIndex = globalIndex; |
354 |
– |
#endif // is_mpi |
350 |
|
|
351 |
|
// set the string tokenizer |
352 |
< |
|
352 |
> |
|
353 |
|
foo = strtok(readLine, " ,;\t"); |
354 |
< |
|
354 |
> |
|
355 |
|
// check the atom name to the current atom |
356 |
< |
|
357 |
< |
if( strcmp( foo, atoms[atomIndex]->getType() ) ){ |
358 |
< |
sprintf( painCave.errMsg, |
359 |
< |
"Initialize from file error. Atom %s at index %d " |
365 |
< |
"in file %s does not" |
356 |
> |
|
357 |
> |
if( strcmp( foo, sd->getType() ) ){ |
358 |
> |
sprintf( painCave.errMsg, |
359 |
> |
"Initialize from file error. Does not" |
360 |
|
" match the BASS atom %s.\n", |
361 |
< |
foo, atomIndex, c_in_name, atoms[atomIndex]->getType() ); |
361 |
> |
sd->getType() ); |
362 |
|
return strdup( painCave.errMsg ); |
363 |
|
} |
364 |
< |
|
364 |
> |
|
365 |
|
// get the positions |
366 |
|
|
367 |
|
foo = strtok(NULL, " ,;\t"); |
368 |
|
if(foo == NULL){ |
369 |
|
sprintf( painCave.errMsg, |
370 |
< |
"error in reading postition x from %s\n" |
371 |
< |
"natoms = %d, index = %d\n", |
378 |
< |
c_in_name, n_atoms, atomIndex ); |
370 |
> |
"error in reading postition x from %s\n", |
371 |
> |
c_in_name); |
372 |
|
return strdup( painCave.errMsg ); |
373 |
|
} |
374 |
|
pos[0] = atof( foo ); |
375 |
< |
|
375 |
> |
|
376 |
|
foo = strtok(NULL, " ,;\t"); |
377 |
|
if(foo == NULL){ |
378 |
|
sprintf( painCave.errMsg, |
379 |
< |
"error in reading postition y from %s\n" |
380 |
< |
"natoms = %d, index = %d\n", |
388 |
< |
c_in_name, n_atoms, atomIndex ); |
379 |
> |
"error in reading postition y from %s\n", |
380 |
> |
c_in_name); |
381 |
|
return strdup( painCave.errMsg ); |
382 |
|
} |
383 |
|
pos[1] = atof( foo ); |
384 |
< |
|
384 |
> |
|
385 |
|
foo = strtok(NULL, " ,;\t"); |
386 |
|
if(foo == NULL){ |
387 |
|
sprintf( painCave.errMsg, |
388 |
< |
"error in reading postition z from %s\n" |
389 |
< |
"natoms = %d, index = %d\n", |
398 |
< |
c_in_name, n_atoms, atomIndex ); |
388 |
> |
"error in reading postition z from %s\n", |
389 |
> |
c_in_name); |
390 |
|
return strdup( painCave.errMsg ); |
391 |
|
} |
392 |
< |
pos[2] = atof( foo ); |
392 |
> |
pos[2] = atof( foo ); |
393 |
|
|
394 |
|
|
395 |
|
// get the velocities |
397 |
|
foo = strtok(NULL, " ,;\t"); |
398 |
|
if(foo == NULL){ |
399 |
|
sprintf( painCave.errMsg, |
400 |
< |
"error in reading velocity x from %s\n" |
401 |
< |
"natoms = %d, index = %d\n", |
411 |
< |
c_in_name, n_atoms, atomIndex ); |
400 |
> |
"error in reading velocity x from %s\n", |
401 |
> |
c_in_name ); |
402 |
|
return strdup( painCave.errMsg ); |
403 |
|
} |
404 |
|
vel[0] = atof( foo ); |
405 |
< |
|
405 |
> |
|
406 |
|
foo = strtok(NULL, " ,;\t"); |
407 |
|
if(foo == NULL){ |
408 |
|
sprintf( painCave.errMsg, |
409 |
< |
"error in reading velocity y from %s\n" |
410 |
< |
"natoms = %d, index = %d\n", |
421 |
< |
c_in_name, n_atoms, atomIndex ); |
409 |
> |
"error in reading velocity x from %s\n", |
410 |
> |
c_in_name ); |
411 |
|
return strdup( painCave.errMsg ); |
412 |
|
} |
413 |
|
vel[1] = atof( foo ); |
414 |
< |
|
414 |
> |
|
415 |
|
foo = strtok(NULL, " ,;\t"); |
416 |
|
if(foo == NULL){ |
417 |
|
sprintf( painCave.errMsg, |
418 |
< |
"error in reading velocity z from %s\n" |
419 |
< |
"natoms = %d, index = %d\n", |
431 |
< |
c_in_name, n_atoms, atomIndex ); |
418 |
> |
"error in reading velocity x from %s\n", |
419 |
> |
c_in_name ); |
420 |
|
return strdup( painCave.errMsg ); |
421 |
|
} |
422 |
|
vel[2] = atof( foo ); |
423 |
< |
|
424 |
< |
|
423 |
> |
|
424 |
> |
|
425 |
> |
// add the positions and velocities to the atom |
426 |
> |
|
427 |
> |
sd->setPos( pos ); |
428 |
> |
sd->setVel( vel ); |
429 |
> |
|
430 |
> |
if (!sd->isDirectional()) |
431 |
> |
return NULL; |
432 |
> |
|
433 |
|
// get the quaternions |
434 |
< |
|
435 |
< |
if( atoms[atomIndex]->isDirectional() ){ |
436 |
< |
|
434 |
> |
|
435 |
> |
if( sd->isDirectional() ){ |
436 |
> |
|
437 |
|
foo = strtok(NULL, " ,;\t"); |
438 |
|
if(foo == NULL){ |
439 |
< |
sprintf(painCave.errMsg, |
440 |
< |
"error in reading quaternion 0 from %s\n" |
441 |
< |
"natoms = %d, index = %d\n", |
446 |
< |
c_in_name, n_atoms, atomIndex ); |
439 |
> |
sprintf( painCave.errMsg, |
440 |
> |
"error in reading velocity x from %s\n", |
441 |
> |
c_in_name ); |
442 |
|
return strdup( painCave.errMsg ); |
443 |
|
} |
444 |
|
q[0] = atof( foo ); |
445 |
< |
|
445 |
> |
|
446 |
|
foo = strtok(NULL, " ,;\t"); |
447 |
|
if(foo == NULL){ |
448 |
|
sprintf( painCave.errMsg, |
449 |
< |
"error in reading quaternion 1 from %s\n" |
450 |
< |
"natoms = %d, index = %d\n", |
456 |
< |
c_in_name, n_atoms, atomIndex ); |
449 |
> |
"error in reading velocity x from %s\n", |
450 |
> |
c_in_name ); |
451 |
|
return strdup( painCave.errMsg ); |
452 |
|
} |
453 |
|
q[1] = atof( foo ); |
454 |
< |
|
454 |
> |
|
455 |
|
foo = strtok(NULL, " ,;\t"); |
456 |
|
if(foo == NULL){ |
457 |
|
sprintf( painCave.errMsg, |
458 |
< |
"error in reading quaternion 2 from %s\n" |
459 |
< |
"natoms = %d, index = %d\n", |
466 |
< |
c_in_name, n_atoms, atomIndex ); |
458 |
> |
"error in reading velocity x from %s\n", |
459 |
> |
c_in_name ); |
460 |
|
return strdup( painCave.errMsg ); |
461 |
|
} |
462 |
|
q[2] = atof( foo ); |
463 |
< |
|
463 |
> |
|
464 |
|
foo = strtok(NULL, " ,;\t"); |
465 |
|
if(foo == NULL){ |
466 |
|
sprintf( painCave.errMsg, |
467 |
< |
"error in reading quaternion 3 from %s\n" |
468 |
< |
"natoms = %d, index = %d\n", |
476 |
< |
c_in_name, n_atoms, atomIndex ); |
467 |
> |
"error in reading velocity x from %s\n", |
468 |
> |
c_in_name ); |
469 |
|
return strdup( painCave.errMsg ); |
470 |
|
} |
471 |
|
q[3] = atof( foo ); |
472 |
< |
|
472 |
> |
|
473 |
|
// get the angular velocities |
474 |
< |
|
474 |
> |
|
475 |
|
foo = strtok(NULL, " ,;\t"); |
476 |
|
if(foo == NULL){ |
477 |
|
sprintf( painCave.errMsg, |
478 |
< |
"error in reading angular momentum jx from %s\n" |
479 |
< |
"natoms = %d, index = %d\n", |
488 |
< |
c_in_name, n_atoms, atomIndex ); |
478 |
> |
"error in reading velocity x from %s\n", |
479 |
> |
c_in_name ); |
480 |
|
return strdup( painCave.errMsg ); |
481 |
|
} |
482 |
< |
jx = atof( foo ); |
483 |
< |
|
482 |
> |
ji[0] = atof( foo ); |
483 |
> |
|
484 |
|
foo = strtok(NULL, " ,;\t"); |
485 |
|
if(foo == NULL){ |
486 |
|
sprintf( painCave.errMsg, |
487 |
< |
"error in reading angular momentum jy from %s\n" |
488 |
< |
"natoms = %d, index = %d\n", |
498 |
< |
c_in_name, n_atoms, atomIndex ); |
487 |
> |
"error in reading velocity x from %s\n", |
488 |
> |
c_in_name ); |
489 |
|
return strdup( painCave.errMsg ); |
490 |
|
} |
491 |
< |
jy = atof(foo ); |
492 |
< |
|
491 |
> |
ji[1] = atof(foo ); |
492 |
> |
|
493 |
|
foo = strtok(NULL, " ,;\t"); |
494 |
|
if(foo == NULL){ |
495 |
|
sprintf( painCave.errMsg, |
496 |
< |
"error in reading angular momentum jz from %s\n" |
497 |
< |
"natoms = %d, index = %d\n", |
508 |
< |
c_in_name, n_atoms, atomIndex ); |
496 |
> |
"error in reading velocity x from %s\n", |
497 |
> |
c_in_name ); |
498 |
|
return strdup( painCave.errMsg ); |
499 |
|
} |
500 |
< |
jz = atof( foo ); |
512 |
< |
|
513 |
< |
dAtom = ( DirectionalAtom* )atoms[atomIndex]; |
500 |
> |
ji[2] = atof( foo ); |
501 |
|
|
502 |
+ |
|
503 |
|
// check that the quaternion vector is normalized |
504 |
|
|
505 |
|
qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
506 |
< |
|
506 |
> |
|
507 |
|
qLength = sqrt( qSqr ); |
508 |
|
q[0] = q[0] / qLength; |
509 |
|
q[1] = q[1] / qLength; |
510 |
|
q[2] = q[2] / qLength; |
511 |
|
q[3] = q[3] / qLength; |
524 |
– |
|
525 |
– |
dAtom->setQ( q ); |
526 |
– |
|
527 |
– |
// add the angular velocities |
512 |
|
|
513 |
< |
dAtom->setJx( jx ); |
514 |
< |
dAtom->setJy( jy ); |
515 |
< |
dAtom->setJz( jz ); |
513 |
> |
// add quaternion and angular velocities |
514 |
> |
|
515 |
> |
sd->setQ( q ); |
516 |
> |
sd->setJ( ji ); |
517 |
|
} |
533 |
– |
|
534 |
– |
// add the positions and velocities to the atom |
535 |
– |
|
536 |
– |
atoms[atomIndex]->setPos( pos ); |
537 |
– |
atoms[atomIndex]->setVel( vel ); |
518 |
|
|
519 |
+ |
|
520 |
+ |
|
521 |
|
return NULL; |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
< |
char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], |
544 |
< |
double &time ){ |
525 |
> |
char* InitializeFromFile::parseCommentLine(char* readLine, SimInfo* entry_plug){ |
526 |
|
|
527 |
< |
char *foo; // the pointer to the current string token |
528 |
< |
int j; |
527 |
> |
double currTime; |
528 |
> |
double boxMat[9]; |
529 |
> |
double theBoxMat3[3][3]; |
530 |
> |
double chi; |
531 |
> |
double integralOfChidt; |
532 |
> |
double eta[9]; |
533 |
|
|
534 |
+ |
char *foo; // the pointer to the current string token |
535 |
+ |
|
536 |
|
// set the string tokenizer |
537 |
< |
|
537 |
> |
|
538 |
|
foo = strtok(readLine, " ,;\t"); |
539 |
|
// set the timeToken. |
540 |
|
|
544 |
|
c_in_name ); |
545 |
|
return strdup( painCave.errMsg ); |
546 |
|
} |
560 |
– |
time = atof( foo ); |
547 |
|
|
548 |
< |
// get the Hx vector |
549 |
< |
|
564 |
< |
foo = strtok(NULL, " ,;\t"); |
565 |
< |
if(foo == NULL){ |
566 |
< |
sprintf( painCave.errMsg, |
567 |
< |
"error in reading Hx[0] from %s\n", |
568 |
< |
c_in_name ); |
569 |
< |
return strdup( painCave.errMsg ); |
570 |
< |
} |
571 |
< |
boxMat[0] = atof( foo ); |
572 |
< |
|
573 |
< |
foo = strtok(NULL, " ,;\t"); |
574 |
< |
if(foo == NULL){ |
575 |
< |
sprintf( painCave.errMsg, |
576 |
< |
"error in reading Hx[1] from %s\n", |
577 |
< |
c_in_name ); |
578 |
< |
return strdup( painCave.errMsg ); |
579 |
< |
} |
580 |
< |
boxMat[1] = atof( foo ); |
581 |
< |
|
582 |
< |
foo = strtok(NULL, " ,;\t"); |
583 |
< |
if(foo == NULL){ |
584 |
< |
sprintf( painCave.errMsg, |
585 |
< |
"error in reading Hx[2] from %s\n", |
586 |
< |
c_in_name ); |
587 |
< |
return strdup( painCave.errMsg ); |
588 |
< |
} |
589 |
< |
boxMat[2] = atof( foo ); |
548 |
> |
currTime = atof( foo ); |
549 |
> |
entry_plug->setTime( currTime ); |
550 |
|
|
551 |
< |
// get the Hy vector |
551 |
> |
//get H-Matrix |
552 |
|
|
553 |
< |
foo = strtok(NULL, " ,;\t"); |
554 |
< |
if(foo == NULL){ |
555 |
< |
sprintf( painCave.errMsg, |
556 |
< |
"error in reading Hy[0] from %s\n", |
557 |
< |
c_in_name ); |
558 |
< |
return strdup( painCave.errMsg ); |
553 |
> |
for(int i = 0 ; i < 9; i++){ |
554 |
> |
foo = strtok(NULL, " ,;\t"); |
555 |
> |
if(foo == NULL){ |
556 |
> |
sprintf( painCave.errMsg, |
557 |
> |
"error in reading H[%d] from %s\n", i, c_in_name ); |
558 |
> |
return strdup( painCave.errMsg ); |
559 |
> |
} |
560 |
> |
boxMat[i] = atof( foo ); |
561 |
|
} |
600 |
– |
boxMat[3] = atof( foo ); |
601 |
– |
|
602 |
– |
foo = strtok(NULL, " ,;\t"); |
603 |
– |
if(foo == NULL){ |
604 |
– |
sprintf( painCave.errMsg, |
605 |
– |
"error in reading Hy[1] from %s\n", |
606 |
– |
c_in_name ); |
607 |
– |
return strdup( painCave.errMsg ); |
608 |
– |
} |
609 |
– |
boxMat[4] = atof( foo ); |
610 |
– |
|
611 |
– |
foo = strtok(NULL, " ,;\t"); |
612 |
– |
if(foo == NULL){ |
613 |
– |
sprintf( painCave.errMsg, |
614 |
– |
"error in reading Hy[2] from %s\n", |
615 |
– |
c_in_name ); |
616 |
– |
return strdup( painCave.errMsg ); |
617 |
– |
} |
618 |
– |
boxMat[5] = atof( foo ); |
562 |
|
|
563 |
< |
// get the Hz vector |
563 |
> |
for(int i=0;i<3;i++) |
564 |
> |
for(int j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
565 |
|
|
566 |
< |
foo = strtok(NULL, " ,;\t"); |
567 |
< |
if(foo == NULL){ |
568 |
< |
sprintf( painCave.errMsg, |
569 |
< |
"error in reading Hz[0] from %s\n", |
570 |
< |
c_in_name ); |
571 |
< |
return strdup( painCave.errMsg ); |
566 |
> |
//set H-Matrix |
567 |
> |
entry_plug->setBoxM( theBoxMat3 ); |
568 |
> |
|
569 |
> |
//get chi and integralOfChidt, they should appear by pair |
570 |
> |
|
571 |
> |
if( entry_plug->useInitXSstate ){ |
572 |
> |
foo = strtok(NULL, " ,;\t\n"); |
573 |
> |
if(foo != NULL){ |
574 |
> |
chi = atof(foo); |
575 |
> |
|
576 |
> |
foo = strtok(NULL, " ,;\t\n"); |
577 |
> |
if(foo == NULL){ |
578 |
> |
sprintf( painCave.errMsg, |
579 |
> |
"chi and integralOfChidt should appear by pair in %s\n", c_in_name ); |
580 |
> |
return strdup( painCave.errMsg ); |
581 |
> |
} |
582 |
> |
integralOfChidt = atof( foo ); |
583 |
> |
|
584 |
> |
//push chi and integralOfChidt into SimInfo::properties which can be |
585 |
> |
//retrieved by integrator later |
586 |
> |
DoubleData* chiValue = new DoubleData(); |
587 |
> |
chiValue->setID(CHIVALUE_ID); |
588 |
> |
chiValue->setData(chi); |
589 |
> |
entry_plug->addProperty(chiValue); |
590 |
> |
|
591 |
> |
DoubleData* integralOfChidtValue = new DoubleData(); |
592 |
> |
integralOfChidtValue->setID(INTEGRALOFCHIDT_ID); |
593 |
> |
integralOfChidtValue->setData(integralOfChidt); |
594 |
> |
entry_plug->addProperty(integralOfChidtValue); |
595 |
> |
|
596 |
> |
} |
597 |
> |
else |
598 |
> |
return NULL; |
599 |
> |
|
600 |
> |
//get eta |
601 |
> |
foo = strtok(NULL, " ,;\t\n"); |
602 |
> |
if(foo != NULL ){ |
603 |
> |
|
604 |
> |
for(int i = 0 ; i < 9; i++){ |
605 |
> |
|
606 |
> |
if(foo == NULL){ |
607 |
> |
sprintf( painCave.errMsg, |
608 |
> |
"error in reading eta[%d] from %s\n", i, c_in_name ); |
609 |
> |
return strdup( painCave.errMsg ); |
610 |
> |
} |
611 |
> |
eta[i] = atof( foo ); |
612 |
> |
foo = strtok(NULL, " ,;\t\n"); |
613 |
> |
} |
614 |
> |
} |
615 |
> |
else |
616 |
> |
return NULL; |
617 |
> |
|
618 |
> |
//push eta into SimInfo::properties which can be |
619 |
> |
//retrieved by integrator later |
620 |
> |
//entry_plug->setBoxM( theBoxMat3 ); |
621 |
> |
DoubleArrayData* etaValue = new DoubleArrayData(); |
622 |
> |
etaValue->setID(ETAVALUE_ID); |
623 |
> |
etaValue->setData(eta, 9); |
624 |
> |
entry_plug->addProperty(etaValue); |
625 |
|
} |
629 |
– |
boxMat[6] = atof( foo ); |
630 |
– |
|
631 |
– |
foo = strtok(NULL, " ,;\t"); |
632 |
– |
if(foo == NULL){ |
633 |
– |
sprintf( painCave.errMsg, |
634 |
– |
"error in reading Hz[1] from %s\n", |
635 |
– |
c_in_name ); |
636 |
– |
return strdup( painCave.errMsg ); |
637 |
– |
} |
638 |
– |
boxMat[7] = atof( foo ); |
639 |
– |
|
640 |
– |
foo = strtok(NULL, " ,;\t"); |
641 |
– |
if(foo == NULL){ |
642 |
– |
sprintf( painCave.errMsg, |
643 |
– |
"error in reading Hz[2] from %s\n", |
644 |
– |
c_in_name ); |
645 |
– |
return strdup( painCave.errMsg ); |
646 |
– |
} |
647 |
– |
boxMat[8] = atof( foo ); |
626 |
|
|
627 |
|
return NULL; |
628 |
|
} |
629 |
|
|
652 |
– |
|
630 |
|
#ifdef IS_MPI |
631 |
|
|
632 |
|
// a couple of functions to let us escape the read loop |
633 |
|
|
634 |
|
void initFile::nodeZeroError( void ){ |
635 |
|
int j, myStatus; |
636 |
< |
|
636 |
> |
|
637 |
|
myStatus = 0; |
638 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
639 |
< |
MPI_Send( &myStatus, 1, MPI_INT, j, |
638 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
639 |
> |
MPI_Send( &myStatus, 1, MPI_INT, j, |
640 |
|
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
641 |
< |
} |
665 |
< |
|
641 |
> |
} |
642 |
|
|
643 |
+ |
|
644 |
|
MPI_Finalize(); |
645 |
|
exit (0); |
646 |
< |
|
646 |
> |
|
647 |
|
} |
648 |
|
|
649 |
|
void initFile::anonymousNodeDie( void ){ |