# | Line 1 | Line 1 | |
---|---|---|
1 | #include <iostream> | |
2 | < | #include <cmath> |
2 | > | #include <math.h> |
3 | ||
4 | #include <stdio.h> | |
5 | #include <stdlib.h> | |
# | Line 26 | Line 26 | using namespace initFile; | |
26 | ||
27 | #endif // is_mpi | |
28 | ||
29 | < | InitializeFromFile :: InitializeFromFile( char *in_name ){ |
29 | > | InitializeFromFile::InitializeFromFile( char *in_name ){ |
30 | > | |
31 | #ifdef IS_MPI | |
32 | if (worldRank == 0) { | |
33 | #endif | |
# | Line 48 | Line 49 | InitializeFromFile :: InitializeFromFile( char *in_nam | |
49 | return; | |
50 | } | |
51 | ||
52 | < | InitializeFromFile :: ~InitializeFromFile( ){ |
52 | > | InitializeFromFile::~InitializeFromFile( ){ |
53 | #ifdef IS_MPI | |
54 | if (worldRank == 0) { | |
55 | #endif | |
# | Line 69 | Line 70 | InitializeFromFile :: ~InitializeFromFile( ){ | |
70 | } | |
71 | ||
72 | ||
73 | < | void InitializeFromFile :: read_xyz( SimInfo* the_simnfo ){ |
73 | > | void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ |
74 | ||
75 | < | int i, j, done, which_node, which_atom; // loop counter |
75 | > | int i, j; |
76 | > | |
77 | > | #ifdef IS_MPI |
78 | > | int done, which_node, which_atom; // loop counter |
79 | > | #endif //is_mpi |
80 | ||
81 | const int BUFFERSIZE = 2000; // size of the read buffer | |
82 | int n_atoms; // the number of atoms | |
83 | char read_buffer[BUFFERSIZE]; //the line buffer for reading | |
79 | – | #ifdef IS_MPI |
80 | – | char send_buffer[BUFFERSIZE]; |
81 | – | #endif |
84 | ||
85 | char *eof_test; // ptr to see when we reach the end of the file | |
86 | char *parseErr; | |
87 | < | int procIndex; |
87 | > | |
88 | > | double currTime; |
89 | double boxMat[9]; | |
90 | < | |
90 | > | double theBoxMat3[3][3]; |
91 | ||
92 | simnfo = the_simnfo; | |
93 | ||
# | Line 100 | Line 103 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
103 | } | |
104 | ||
105 | n_atoms = atoi( read_buffer ); | |
103 | – | |
104 | – | Atom **atoms = simnfo->atoms; |
105 | – | DirectionalAtom* dAtom; |
106 | ||
107 | if( n_atoms != simnfo->n_atoms ){ | |
108 | sprintf( painCave.errMsg, | |
# | Line 123 | Line 123 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
123 | simError(); | |
124 | } | |
125 | ||
126 | < | parseErr = parseBoxLine( read_buffer, boxMat ); |
126 | > | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
127 | if( parseErr != NULL ){ | |
128 | strcpy( painCave.errMsg, parseErr ); | |
129 | painCave.isFatal = 1; | |
130 | simError(); | |
131 | } | |
132 | ||
133 | < | simnfo->setBoxM( boxMat ); |
133 | > | for(i=0;i<3;i++) |
134 | > | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
135 | ||
136 | + | simnfo->setBoxM( theBoxMat3 ); |
137 | + | simnfo->setTime( currTime ); |
138 | ||
139 | + | |
140 | for( i=0; i < n_atoms; i++){ | |
141 | ||
142 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
# | Line 175 | Line 179 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
179 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
180 | if( eof_test == NULL ){ | |
181 | sprintf( painCave.errMsg, | |
182 | < | "Error reading 1st line of %d \n ",c_in_name); |
182 | > | "Error reading 1st line of %s \n ",c_in_name); |
183 | haveError = 1; | |
184 | simError(); | |
185 | } | |
186 | ||
187 | n_atoms = atoi( read_buffer ); | |
188 | ||
185 | – | Atom **atoms = simnfo->atoms; |
186 | – | DirectionalAtom* dAtom; |
187 | – | |
189 | // Check to see that the number of atoms in the intial configuration file is the | |
190 | // same as declared in simBass. | |
191 | ||
# | Line 207 | Line 208 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
208 | simError(); | |
209 | } | |
210 | ||
211 | < | parseErr = parseBoxLine( read_buffer, boxMat ); |
211 | > | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
212 | if( parseErr != NULL ){ | |
213 | strcpy( painCave.errMsg, parseErr ); | |
214 | haveError = 1; | |
# | Line 215 | Line 216 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
216 | } | |
217 | ||
218 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); | |
219 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
220 | ||
221 | if(haveError) nodeZeroError(); | |
222 | ||
# | Line 269 | Line 271 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
271 | } else { | |
272 | ||
273 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); | |
274 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
275 | ||
276 | done = 0; | |
277 | while (!done) { | |
# | Line 301 | Line 304 | void InitializeFromFile :: read_xyz( SimInfo* the_simn | |
304 | ||
305 | // last thing last, enable fatalities. | |
306 | painCave.isEventLoop = 0; | |
307 | < | simnfo->setBoxM( boxMat ); |
307 | > | |
308 | > | for(i=0;i<3;i++) |
309 | > | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
310 | > | |
311 | > | simnfo->setBoxM( theBoxMat3 ); |
312 | > | simnfo->setTime( currTime ); |
313 | ||
314 | ||
315 | #endif | |
# | Line 311 | Line 319 | char* InitializeFromFile::parseDumpLine(char* readLine | |
319 | ||
320 | char *foo; // the pointer to the current string token | |
321 | ||
322 | < | double rx, ry, rz; // position place holders |
323 | < | double vx, vy, vz; // velocity placeholders |
322 | > | double pos[3]; // position place holders |
323 | > | double vel[3]; // velocity placeholders |
324 | double q[4]; // the quaternions | |
325 | double jx, jy, jz; // angular velocity placeholders; | |
326 | double qSqr, qLength; // needed to normalize the quaternion vector. | |
# | Line 320 | Line 328 | char* InitializeFromFile::parseDumpLine(char* readLine | |
328 | Atom **atoms = simnfo->atoms; | |
329 | DirectionalAtom* dAtom; | |
330 | ||
331 | < | int j, n_atoms, atomIndex; |
331 | > | int n_atoms, atomIndex; |
332 | ||
333 | #ifdef IS_MPI | |
334 | + | int j; |
335 | + | |
336 | n_atoms = mpiSim->getTotAtoms(); | |
337 | atomIndex=-1; | |
338 | for (j=0; j < mpiSim->getMyNlocal(); j++) { | |
# | Line 365 | Line 375 | char* InitializeFromFile::parseDumpLine(char* readLine | |
375 | c_in_name, n_atoms, atomIndex ); | |
376 | return strdup( painCave.errMsg ); | |
377 | } | |
378 | < | rx = atof( foo ); |
378 | > | pos[0] = atof( foo ); |
379 | ||
380 | foo = strtok(NULL, " ,;\t"); | |
381 | if(foo == NULL){ | |
# | Line 375 | Line 385 | char* InitializeFromFile::parseDumpLine(char* readLine | |
385 | c_in_name, n_atoms, atomIndex ); | |
386 | return strdup( painCave.errMsg ); | |
387 | } | |
388 | < | ry = atof( foo ); |
388 | > | pos[1] = atof( foo ); |
389 | ||
390 | foo = strtok(NULL, " ,;\t"); | |
391 | if(foo == NULL){ | |
# | Line 385 | Line 395 | char* InitializeFromFile::parseDumpLine(char* readLine | |
395 | c_in_name, n_atoms, atomIndex ); | |
396 | return strdup( painCave.errMsg ); | |
397 | } | |
398 | < | rz = atof( foo ); |
398 | > | pos[2] = atof( foo ); |
399 | ||
400 | ||
401 | // get the velocities | |
# | Line 398 | Line 408 | char* InitializeFromFile::parseDumpLine(char* readLine | |
408 | c_in_name, n_atoms, atomIndex ); | |
409 | return strdup( painCave.errMsg ); | |
410 | } | |
411 | < | vx = atof( foo ); |
411 | > | vel[0] = atof( foo ); |
412 | ||
413 | foo = strtok(NULL, " ,;\t"); | |
414 | if(foo == NULL){ | |
# | Line 408 | Line 418 | char* InitializeFromFile::parseDumpLine(char* readLine | |
418 | c_in_name, n_atoms, atomIndex ); | |
419 | return strdup( painCave.errMsg ); | |
420 | } | |
421 | < | vy = atof( foo ); |
421 | > | vel[1] = atof( foo ); |
422 | ||
423 | foo = strtok(NULL, " ,;\t"); | |
424 | if(foo == NULL){ | |
# | Line 418 | Line 428 | char* InitializeFromFile::parseDumpLine(char* readLine | |
428 | c_in_name, n_atoms, atomIndex ); | |
429 | return strdup( painCave.errMsg ); | |
430 | } | |
431 | < | vz = atof( foo ); |
431 | > | vel[2] = atof( foo ); |
432 | ||
433 | ||
434 | // get the quaternions | |
# | Line 520 | Line 530 | char* InitializeFromFile::parseDumpLine(char* readLine | |
530 | ||
531 | // add the positions and velocities to the atom | |
532 | ||
533 | < | atoms[atomIndex]->setX( rx ); |
534 | < | atoms[atomIndex]->setY( ry ); |
525 | < | atoms[atomIndex]->setZ( rz ); |
526 | < | |
527 | < | atoms[atomIndex]->set_vx( vx ); |
528 | < | atoms[atomIndex]->set_vy( vy ); |
529 | < | atoms[atomIndex]->set_vz( vz ); |
533 | > | atoms[atomIndex]->setPos( pos ); |
534 | > | atoms[atomIndex]->setVel( vel ); |
535 | ||
536 | return NULL; | |
537 | } | |
538 | ||
539 | ||
540 | < | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9]){ |
540 | > | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], |
541 | > | double &time ){ |
542 | ||
543 | char *foo; // the pointer to the current string token | |
538 | – | int j; |
544 | ||
545 | // set the string tokenizer | |
546 | ||
547 | foo = strtok(readLine, " ,;\t"); | |
548 | < | // ignore the first token which is the time stamp. |
548 | > | // set the timeToken. |
549 | ||
550 | + | if(foo == NULL){ |
551 | + | sprintf( painCave.errMsg, |
552 | + | "error in reading Time from %s\n", |
553 | + | c_in_name ); |
554 | + | return strdup( painCave.errMsg ); |
555 | + | } |
556 | + | time = atof( foo ); |
557 | ||
558 | // get the Hx vector | |
559 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |