# | Line 1 | Line 1 | |
---|---|---|
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> | |
# | Line 26 | Line 27 | using namespace initFile; | |
27 | ||
28 | #endif // is_mpi | |
29 | ||
30 | < | InitializeFromFile :: InitializeFromFile( char *in_name ){ |
30 | > | InitializeFromFile::InitializeFromFile( char *in_name ){ |
31 | > | |
32 | #ifdef IS_MPI | |
33 | if (worldRank == 0) { | |
34 | #endif | |
# | Line 48 | Line 50 | InitializeFromFile :: InitializeFromFile( char *in_nam | |
50 | return; | |
51 | } | |
52 | ||
53 | < | InitializeFromFile :: ~InitializeFromFile( ){ |
53 | > | InitializeFromFile::~InitializeFromFile( ){ |
54 | #ifdef IS_MPI | |
55 | if (worldRank == 0) { | |
56 | #endif | |
# | Line 71 | Line 73 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
73 | ||
74 | void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ | |
75 | ||
76 | < | int i, j, done, which_node, which_atom; // loop counter |
76 | > | int i, j; |
77 | > | |
78 | > | #ifdef IS_MPI |
79 | > | int done, which_node, which_atom; // loop counter |
80 | > | #endif //is_mpi |
81 | ||
82 | const int BUFFERSIZE = 2000; // size of the read buffer | |
83 | int n_atoms; // the number of atoms | |
84 | char read_buffer[BUFFERSIZE]; //the line buffer for reading | |
79 | – | #ifdef IS_MPI |
80 | – | char send_buffer[BUFFERSIZE]; |
81 | – | #endif |
85 | ||
86 | char *eof_test; // ptr to see when we reach the end of the file | |
87 | char *parseErr; | |
88 | < | int procIndex; |
88 | > | |
89 | > | double currTime; |
90 | double boxMat[9]; | |
91 | double theBoxMat3[3][3]; | |
92 | ||
# | Line 101 | Line 105 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
105 | ||
106 | n_atoms = atoi( read_buffer ); | |
107 | ||
104 | – | Atom **atoms = simnfo->atoms; |
105 | – | DirectionalAtom* dAtom; |
106 | – | |
108 | if( n_atoms != simnfo->n_atoms ){ | |
109 | sprintf( painCave.errMsg, | |
110 | "Initialize from File error. %s n_atoms, %d, " | |
# | Line 123 | Line 124 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
124 | simError(); | |
125 | } | |
126 | ||
127 | < | parseErr = parseBoxLine( read_buffer, boxMat ); |
127 | > | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
128 | if( parseErr != NULL ){ | |
129 | strcpy( painCave.errMsg, parseErr ); | |
130 | painCave.isFatal = 1; | |
# | Line 134 | Line 135 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
135 | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; | |
136 | ||
137 | simnfo->setBoxM( theBoxMat3 ); | |
138 | + | simnfo->setTime( currTime ); |
139 | ||
140 | ||
141 | for( i=0; i < n_atoms; i++){ | |
# | Line 178 | Line 180 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
180 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
181 | if( eof_test == NULL ){ | |
182 | sprintf( painCave.errMsg, | |
183 | < | "Error reading 1st line of %d \n ",c_in_name); |
183 | > | "Error reading 1st line of %s \n ",c_in_name); |
184 | haveError = 1; | |
185 | simError(); | |
186 | } | |
187 | ||
188 | n_atoms = atoi( read_buffer ); | |
189 | ||
188 | – | Atom **atoms = simnfo->atoms; |
189 | – | DirectionalAtom* dAtom; |
190 | – | |
190 | // Check to see that the number of atoms in the intial configuration file is the | |
191 | // same as declared in simBass. | |
192 | ||
# | Line 210 | Line 209 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
209 | simError(); | |
210 | } | |
211 | ||
212 | < | parseErr = parseBoxLine( read_buffer, boxMat ); |
212 | > | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
213 | if( parseErr != NULL ){ | |
214 | strcpy( painCave.errMsg, parseErr ); | |
215 | haveError = 1; | |
# | Line 218 | Line 217 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
217 | } | |
218 | ||
219 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); | |
220 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
221 | ||
222 | if(haveError) nodeZeroError(); | |
223 | ||
# | Line 272 | Line 272 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
272 | } else { | |
273 | ||
274 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); | |
275 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
276 | ||
277 | done = 0; | |
278 | while (!done) { | |
# | Line 309 | Line 310 | void InitializeFromFile :: readInit( SimInfo* the_simn | |
310 | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; | |
311 | ||
312 | simnfo->setBoxM( theBoxMat3 ); | |
313 | + | simnfo->setTime( currTime ); |
314 | ||
315 | ||
316 | #endif | |
# | Line 318 | Line 320 | char* InitializeFromFile::parseDumpLine(char* readLine | |
320 | ||
321 | char *foo; // the pointer to the current string token | |
322 | ||
323 | < | double rx, ry, rz; // position place holders |
324 | < | double vx, vy, vz; // velocity placeholders |
323 | > | double pos[3]; // position place holders |
324 | > | double vel[3]; // velocity placeholders |
325 | double q[4]; // the quaternions | |
326 | double jx, jy, jz; // angular velocity placeholders; | |
327 | double qSqr, qLength; // needed to normalize the quaternion vector. | |
# | Line 327 | Line 329 | char* InitializeFromFile::parseDumpLine(char* readLine | |
329 | Atom **atoms = simnfo->atoms; | |
330 | DirectionalAtom* dAtom; | |
331 | ||
332 | < | int j, n_atoms, atomIndex; |
332 | > | int n_atoms, atomIndex; |
333 | ||
334 | #ifdef IS_MPI | |
335 | + | int j; |
336 | + | |
337 | n_atoms = mpiSim->getTotAtoms(); | |
338 | atomIndex=-1; | |
339 | for (j=0; j < mpiSim->getMyNlocal(); j++) { | |
# | Line 372 | Line 376 | char* InitializeFromFile::parseDumpLine(char* readLine | |
376 | c_in_name, n_atoms, atomIndex ); | |
377 | return strdup( painCave.errMsg ); | |
378 | } | |
379 | < | rx = atof( foo ); |
379 | > | pos[0] = atof( foo ); |
380 | ||
381 | foo = strtok(NULL, " ,;\t"); | |
382 | if(foo == NULL){ | |
# | Line 382 | Line 386 | char* InitializeFromFile::parseDumpLine(char* readLine | |
386 | c_in_name, n_atoms, atomIndex ); | |
387 | return strdup( painCave.errMsg ); | |
388 | } | |
389 | < | ry = atof( foo ); |
389 | > | pos[1] = atof( foo ); |
390 | ||
391 | foo = strtok(NULL, " ,;\t"); | |
392 | if(foo == NULL){ | |
# | Line 392 | Line 396 | char* InitializeFromFile::parseDumpLine(char* readLine | |
396 | c_in_name, n_atoms, atomIndex ); | |
397 | return strdup( painCave.errMsg ); | |
398 | } | |
399 | < | rz = atof( foo ); |
399 | > | pos[2] = atof( foo ); |
400 | ||
401 | ||
402 | // get the velocities | |
# | Line 405 | Line 409 | char* InitializeFromFile::parseDumpLine(char* readLine | |
409 | c_in_name, n_atoms, atomIndex ); | |
410 | return strdup( painCave.errMsg ); | |
411 | } | |
412 | < | vx = atof( foo ); |
412 | > | vel[0] = atof( foo ); |
413 | ||
414 | foo = strtok(NULL, " ,;\t"); | |
415 | if(foo == NULL){ | |
# | Line 415 | Line 419 | char* InitializeFromFile::parseDumpLine(char* readLine | |
419 | c_in_name, n_atoms, atomIndex ); | |
420 | return strdup( painCave.errMsg ); | |
421 | } | |
422 | < | vy = atof( foo ); |
422 | > | vel[1] = atof( foo ); |
423 | ||
424 | foo = strtok(NULL, " ,;\t"); | |
425 | if(foo == NULL){ | |
# | Line 425 | Line 429 | char* InitializeFromFile::parseDumpLine(char* readLine | |
429 | c_in_name, n_atoms, atomIndex ); | |
430 | return strdup( painCave.errMsg ); | |
431 | } | |
432 | < | vz = atof( foo ); |
432 | > | vel[2] = atof( foo ); |
433 | ||
434 | ||
435 | // get the quaternions | |
# | Line 527 | Line 531 | char* InitializeFromFile::parseDumpLine(char* readLine | |
531 | ||
532 | // add the positions and velocities to the atom | |
533 | ||
534 | < | atoms[atomIndex]->setX( rx ); |
535 | < | atoms[atomIndex]->setY( ry ); |
532 | < | atoms[atomIndex]->setZ( rz ); |
533 | < | |
534 | < | atoms[atomIndex]->set_vx( vx ); |
535 | < | atoms[atomIndex]->set_vy( vy ); |
536 | < | atoms[atomIndex]->set_vz( vz ); |
534 | > | atoms[atomIndex]->setPos( pos ); |
535 | > | atoms[atomIndex]->setVel( vel ); |
536 | ||
537 | return NULL; | |
538 | } | |
539 | ||
540 | ||
541 | < | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9]){ |
541 | > | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], |
542 | > | double &time ){ |
543 | ||
544 | char *foo; // the pointer to the current string token | |
545 | – | int j; |
545 | ||
546 | // set the string tokenizer | |
547 | ||
# | Line 555 | Line 554 | char* InitializeFromFile::parseBoxLine(char* readLine, | |
554 | c_in_name ); | |
555 | return strdup( painCave.errMsg ); | |
556 | } | |
557 | < | simnfo->setTime( atof( foo ) ); |
557 | > | time = atof( foo ); |
558 | ||
559 | // get the Hx vector | |
560 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |