| 13 |
|
|
| 14 |
|
|
| 15 |
|
InitializeFromFile :: InitializeFromFile( char *in_name ){ |
| 16 |
+ |
#ifdef IS_MPI |
| 17 |
+ |
if (worldRank == 0) { |
| 18 |
+ |
#endif |
| 19 |
|
|
| 20 |
|
c_in_file = fopen(in_name, "r"); |
| 21 |
|
if(c_in_file == NULL){ |
| 26 |
|
} |
| 27 |
|
|
| 28 |
|
strcpy( c_in_name, in_name); |
| 29 |
+ |
#ifdef IS_MPI |
| 30 |
+ |
} |
| 31 |
+ |
strcpy( checkPointMsg, "Infile opened for reading successfully." ); |
| 32 |
+ |
MPIcheckPoint(); |
| 33 |
+ |
#endif |
| 34 |
|
return; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
InitializeFromFile :: ~InitializeFromFile( ){ |
| 38 |
< |
|
| 38 |
> |
#ifdef IS_MPI |
| 39 |
> |
if (worldRank == 0) { |
| 40 |
> |
#endif |
| 41 |
|
int error; |
| 42 |
|
error = fclose( c_in_file ); |
| 43 |
|
if( error ){ |
| 45 |
|
"Error closing %s\n", c_in_name ); |
| 46 |
|
simError(); |
| 47 |
|
} |
| 48 |
+ |
#ifdef IS_MPI |
| 49 |
+ |
} |
| 50 |
+ |
strcpy( checkPointMsg, "Infile closed successfully." ); |
| 51 |
+ |
MPIcheckPoint(); |
| 52 |
+ |
#endif |
| 53 |
+ |
|
| 54 |
|
return; |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
< |
void InitializeFromFile :: read_xyz( SimInfo* entry_plug ){ |
| 58 |
> |
void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){ |
| 59 |
|
|
| 60 |
|
int i; // loop counter |
| 61 |
|
|
| 62 |
|
int n_atoms; // the number of atoms |
| 63 |
|
char read_buffer[2000]; //the line buffer for reading |
| 64 |
+ |
#ifdef IS_MPI |
| 65 |
+ |
char send_buffer[2000]; |
| 66 |
+ |
#endif |
| 67 |
+ |
|
| 68 |
|
char *eof_test; // ptr to see when we reach the end of the file |
| 69 |
|
char *foo; // the pointer to the current string token |
| 70 |
|
|
| 74 |
|
double jx, jy, jz; // angular velocity placeholders; |
| 75 |
|
double qSqr, qLength; // needed to normalize the quaternion vector. |
| 76 |
|
|
| 77 |
+ |
entry_plug = the_entry_plug |
| 78 |
+ |
|
| 79 |
+ |
|
| 80 |
+ |
#ifndef IS_MPI |
| 81 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 82 |
|
if( eof_test == NULL ){ |
| 83 |
|
std::cerr << "error reading 1st line of" << c_in_name << "\n"; |
| 320 |
|
atoms[i]->set_vz( vz ); |
| 321 |
|
|
| 322 |
|
} |
| 323 |
+ |
|
| 324 |
+ |
|
| 325 |
+ |
// MPI Section of code.......... |
| 326 |
+ |
#else //IS_MPI |
| 327 |
+ |
|
| 328 |
+ |
|
| 329 |
+ |
|
| 330 |
+ |
|
| 331 |
+ |
if (worldRank == 0) { |
| 332 |
+ |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 333 |
+ |
if( eof_test == NULL ){ |
| 334 |
+ |
sprintf( painCave.errMsg, |
| 335 |
+ |
"Error reading 1st line of %d \n ",c_in_name); |
| 336 |
+ |
painCave.isFatal = 1; |
| 337 |
+ |
simError(); |
| 338 |
+ |
} |
| 339 |
+ |
|
| 340 |
+ |
(void)sscanf(read_buffer, "%d", &n_atoms); |
| 341 |
+ |
|
| 342 |
+ |
Atom **atoms = entry_plug->atoms; |
| 343 |
+ |
DirectionalAtom* dAtom; |
| 344 |
+ |
|
| 345 |
+ |
if( n_atoms != entry_plug->n_atoms ){ |
| 346 |
+ |
sprintf( painCave.errMsg, |
| 347 |
+ |
"Initialize from File error. %s n_atoms, %d, " |
| 348 |
+ |
"does not match the BASS file's n_atoms, %d.\n", |
| 349 |
+ |
c_in_name, n_atoms, entry_plug->n_atoms ); |
| 350 |
+ |
painCave.isFatal = 1; |
| 351 |
+ |
simError(); |
| 352 |
+ |
} |
| 353 |
+ |
|
| 354 |
+ |
//read and toss the comment line |
| 355 |
+ |
|
| 356 |
+ |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 357 |
+ |
if(eof_test == NULL){ |
| 358 |
+ |
sprintf( painCave.errMsg, |
| 359 |
+ |
"error in reading commment in %s\n", c_in_name); |
| 360 |
+ |
painCave.isFatal = 1; |
| 361 |
+ |
simError(); |
| 362 |
+ |
} |
| 363 |
+ |
} |
| 364 |
+ |
for( i=0; i < n_atoms; i++){ |
| 365 |
+ |
|
| 366 |
+ |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 367 |
+ |
if(eof_test == NULL){ |
| 368 |
+ |
sprintf(painCave.errMsg, |
| 369 |
+ |
"error in reading file %s\n" |
| 370 |
+ |
"natoms = %d; index = %d\n" |
| 371 |
+ |
"error reading the line from the file.\n", |
| 372 |
+ |
c_in_name, n_atoms, i ); |
| 373 |
+ |
painCave.isFatal = 1; |
| 374 |
+ |
simError(); |
| 375 |
+ |
} |
| 376 |
+ |
|
| 377 |
+ |
foo = strtok(read_buffer, " ,;\t"); |
| 378 |
+ |
|
| 379 |
+ |
// check the atom name to the current atom |
| 380 |
+ |
|
| 381 |
+ |
if( strcmp( foo, atoms[i]->getType() ) ){ |
| 382 |
+ |
sprintf( painCave.errMsg, |
| 383 |
+ |
"Initialize from file error. Atom %s at index %d " |
| 384 |
+ |
"in file %s does not" |
| 385 |
+ |
" match the BASS atom %s.\n", |
| 386 |
+ |
foo, i, c_in_name, atoms[i]->getType() ); |
| 387 |
+ |
painCave.isFatal = 1; |
| 388 |
+ |
simError(); |
| 389 |
+ |
} |
| 390 |
+ |
|
| 391 |
+ |
// get the positions |
| 392 |
+ |
|
| 393 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 394 |
+ |
if(foo == NULL){ |
| 395 |
+ |
sprintf( painCave.errMsg, |
| 396 |
+ |
"error in reading postition x from %s\n" |
| 397 |
+ |
"natoms = %d, index = %d\n", |
| 398 |
+ |
c_in_name, n_atoms, i ); |
| 399 |
+ |
painCave.isFatal = 1; |
| 400 |
+ |
simError(); |
| 401 |
+ |
} |
| 402 |
+ |
(void)sscanf( foo, "%lf", &rx ); |
| 403 |
+ |
|
| 404 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 405 |
+ |
if(foo == NULL){ |
| 406 |
+ |
sprintf( painCave.errMsg, |
| 407 |
+ |
"error in reading postition y from %s\n" |
| 408 |
+ |
"natoms = %d, index = %d\n", |
| 409 |
+ |
c_in_name, n_atoms, i ); |
| 410 |
+ |
painCave.isFatal = 1; |
| 411 |
+ |
simError(); |
| 412 |
+ |
} |
| 413 |
+ |
(void)sscanf( foo, "%lf", &ry ); |
| 414 |
+ |
|
| 415 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 416 |
+ |
if(foo == NULL){ |
| 417 |
+ |
sprintf( painCave.errMsg, |
| 418 |
+ |
"error in reading postition z from %s\n" |
| 419 |
+ |
"natoms = %d, index = %d\n", |
| 420 |
+ |
c_in_name, n_atoms, i ); |
| 421 |
+ |
painCave.isFatal = 1; |
| 422 |
+ |
simError(); |
| 423 |
+ |
} |
| 424 |
+ |
(void)sscanf( foo, "%lf", &rz ); |
| 425 |
+ |
|
| 426 |
+ |
// get the velocities |
| 427 |
+ |
|
| 428 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 429 |
+ |
if(foo == NULL){ |
| 430 |
+ |
sprintf( painCave.errMsg, |
| 431 |
+ |
"error in reading velocity x from %s\n" |
| 432 |
+ |
"natoms = %d, index = %d\n", |
| 433 |
+ |
c_in_name, n_atoms, i ); |
| 434 |
+ |
painCave.isFatal = 1; |
| 435 |
+ |
simError(); |
| 436 |
+ |
} |
| 437 |
+ |
(void)sscanf( foo, "%lf", &vx ); |
| 438 |
+ |
|
| 439 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 440 |
+ |
if(foo == NULL){ |
| 441 |
+ |
sprintf( painCave.errMsg, |
| 442 |
+ |
"error in reading velocity y from %s\n" |
| 443 |
+ |
"natoms = %d, index = %d\n", |
| 444 |
+ |
c_in_name, n_atoms, i ); |
| 445 |
+ |
painCave.isFatal = 1; |
| 446 |
+ |
simError(); |
| 447 |
+ |
} |
| 448 |
+ |
(void)sscanf( foo, "%lf", &vy ); |
| 449 |
+ |
|
| 450 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 451 |
+ |
if(foo == NULL){ |
| 452 |
+ |
sprintf( painCave.errMsg, |
| 453 |
+ |
"error in reading velocity z from %s\n" |
| 454 |
+ |
"natoms = %d, index = %d\n", |
| 455 |
+ |
c_in_name, n_atoms, i ); |
| 456 |
+ |
painCave.isFatal = 1; |
| 457 |
+ |
simError(); |
| 458 |
+ |
} |
| 459 |
+ |
(void)sscanf( foo, "%lf", &vz ); |
| 460 |
+ |
|
| 461 |
+ |
|
| 462 |
+ |
// get the quaternions |
| 463 |
+ |
|
| 464 |
+ |
if( atoms[i]->isDirectional() ){ |
| 465 |
+ |
|
| 466 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 467 |
+ |
if(foo == NULL){ |
| 468 |
+ |
sprintf(painCave.errMsg, |
| 469 |
+ |
"error in reading quaternion 0 from %s\n" |
| 470 |
+ |
"natoms = %d, index = %d\n", |
| 471 |
+ |
c_in_name, n_atoms, i ); |
| 472 |
+ |
painCave.isFatal = 1; |
| 473 |
+ |
simError(); |
| 474 |
+ |
} |
| 475 |
+ |
(void)sscanf( foo, "%lf", &q[0] ); |
| 476 |
+ |
|
| 477 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 478 |
+ |
if(foo == NULL){ |
| 479 |
+ |
sprintf( painCave.errMsg, |
| 480 |
+ |
"error in reading quaternion 1 from %s\n" |
| 481 |
+ |
"natoms = %d, index = %d\n", |
| 482 |
+ |
c_in_name, n_atoms, i ); |
| 483 |
+ |
painCave.isFatal = 1; |
| 484 |
+ |
simError(); |
| 485 |
+ |
} |
| 486 |
+ |
(void)sscanf( foo, "%lf", &q[1] ); |
| 487 |
+ |
|
| 488 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 489 |
+ |
if(foo == NULL){ |
| 490 |
+ |
sprintf( painCave.errMsg, |
| 491 |
+ |
"error in reading quaternion 2 from %s\n" |
| 492 |
+ |
"natoms = %d, index = %d\n", |
| 493 |
+ |
c_in_name, n_atoms, i ); |
| 494 |
+ |
painCave.isFatal = 1; |
| 495 |
+ |
simError(); |
| 496 |
+ |
} |
| 497 |
+ |
(void)sscanf( foo, "%lf", &q[2] ); |
| 498 |
+ |
|
| 499 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 500 |
+ |
if(foo == NULL){ |
| 501 |
+ |
sprintf( painCave.errMsg, |
| 502 |
+ |
"error in reading quaternion 3 from %s\n" |
| 503 |
+ |
"natoms = %d, index = %d\n", |
| 504 |
+ |
c_in_name, n_atoms, i ); |
| 505 |
+ |
painCave.isFatal = 1; |
| 506 |
+ |
simError(); |
| 507 |
+ |
} |
| 508 |
+ |
(void)sscanf( foo, "%lf", &q[3] ); |
| 509 |
+ |
|
| 510 |
+ |
// get the angular velocities |
| 511 |
+ |
|
| 512 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 513 |
+ |
if(foo == NULL){ |
| 514 |
+ |
sprintf( painCave.errMsg, |
| 515 |
+ |
"error in reading angular momentum jx from %s\n" |
| 516 |
+ |
"natoms = %d, index = %d\n", |
| 517 |
+ |
c_in_name, n_atoms, i ); |
| 518 |
+ |
painCave.isFatal = 1; |
| 519 |
+ |
simError(); |
| 520 |
+ |
} |
| 521 |
+ |
(void)sscanf( foo, "%lf", &jx ); |
| 522 |
+ |
|
| 523 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 524 |
+ |
if(foo == NULL){ |
| 525 |
+ |
sprintf( painCave.errMsg, |
| 526 |
+ |
"error in reading angular momentum jy from %s\n" |
| 527 |
+ |
"natoms = %d, index = %d\n", |
| 528 |
+ |
c_in_name, n_atoms, i ); |
| 529 |
+ |
painCave.isFatal = 1; |
| 530 |
+ |
simError(); |
| 531 |
+ |
} |
| 532 |
+ |
(void)sscanf( foo, "%lf", &jy ); |
| 533 |
+ |
|
| 534 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 535 |
+ |
if(foo == NULL){ |
| 536 |
+ |
sprintf( painCave.errMsg, |
| 537 |
+ |
"error in reading angular momentum jz from %s\n" |
| 538 |
+ |
"natoms = %d, index = %d\n", |
| 539 |
+ |
c_in_name, n_atoms, i ); |
| 540 |
+ |
painCave.isFatal = 1; |
| 541 |
+ |
simError(); |
| 542 |
+ |
} |
| 543 |
+ |
(void)sscanf( foo, "%lf", &jz ); |
| 544 |
+ |
|
| 545 |
+ |
dAtom = ( DirectionalAtom* )atoms[i]; |
| 546 |
+ |
|
| 547 |
+ |
// check that the quaternion vector is normalized |
| 548 |
+ |
|
| 549 |
+ |
qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
| 550 |
+ |
|
| 551 |
+ |
qLength = sqrt( qSqr ); |
| 552 |
+ |
q[0] = q[0] / qLength; |
| 553 |
+ |
q[1] = q[1] / qLength; |
| 554 |
+ |
q[2] = q[2] / qLength; |
| 555 |
+ |
q[3] = q[3] / qLength; |
| 556 |
+ |
|
| 557 |
+ |
dAtom->setQ( q ); |
| 558 |
+ |
|
| 559 |
+ |
// add the angular velocities |
| 560 |
+ |
|
| 561 |
+ |
dAtom->setJx( jx ); |
| 562 |
+ |
dAtom->setJy( jy ); |
| 563 |
+ |
dAtom->setJz( jz ); |
| 564 |
+ |
} |
| 565 |
+ |
|
| 566 |
+ |
// add the positions and velocities to the atom |
| 567 |
+ |
|
| 568 |
+ |
atoms[i]->setX( rx ); |
| 569 |
+ |
atoms[i]->setY( ry ); |
| 570 |
+ |
atoms[i]->setZ( rz ); |
| 571 |
+ |
|
| 572 |
+ |
atoms[i]->set_vx( vx ); |
| 573 |
+ |
atoms[i]->set_vy( vy ); |
| 574 |
+ |
atoms[i]->set_vz( vz ); |
| 575 |
+ |
|
| 576 |
+ |
} |
| 577 |
+ |
#endif |
| 578 |
|
} |
| 579 |
+ |
|
| 580 |
+ |
char* IntitializeFromFile::parseDumpLine(char* readLine); |