| 9 |
|
#include "SRI.hpp" |
| 10 |
|
#include "simError.h" |
| 11 |
|
|
| 12 |
– |
|
| 12 |
|
// Declare the structures that will be passed by the parser and MPI |
| 13 |
|
|
| 14 |
|
typedef struct{ |
| 24 |
|
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ); |
| 25 |
|
|
| 26 |
|
#ifdef IS_MPI |
| 28 |
– |
|
| 27 |
|
#include "mpiForceField.h" |
| 28 |
|
|
| 29 |
|
MPI_Datatype mpiAtomStructType; |
| 36 |
|
extern "C" { |
| 37 |
|
void forcefactory_( char* forceName, |
| 38 |
|
int* status, |
| 39 |
< |
void (*wrapFunction)( void (* |
| 39 |
> |
void (*wrapFunction)( void (*p1)( int* ident, |
| 40 |
> |
double* mass, |
| 41 |
> |
double* epslon, |
| 42 |
> |
double* sigma, |
| 43 |
> |
int* status ), |
| 44 |
> |
void (*p2)( int *nLocal, |
| 45 |
> |
int *identArray, |
| 46 |
> |
int *isError ), |
| 47 |
> |
void (*p3)( double* positionArray, |
| 48 |
> |
double* forceArray, |
| 49 |
> |
double* potentialEnergy, |
| 50 |
> |
short int* doPotentialCalc )), |
| 51 |
> |
int forceNameLength ); |
| 52 |
> |
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
+ |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
| 56 |
+ |
double* sigma, int* status ), |
| 57 |
+ |
void (*p2)( int *nLocal, int *identArray, int *isError ), |
| 58 |
+ |
void (*p3)( double* positionArray,double* forceArray, |
| 59 |
+ |
double* potentialEnergy, |
| 60 |
+ |
short int* doPotentialCalc ) ); |
| 61 |
|
|
| 62 |
+ |
void (*newLJtype)( int* ident, double* mass, double* epslon, double* sigma, |
| 63 |
+ |
int* status ); |
| 64 |
+ |
|
| 65 |
+ |
void (*initLJfortran) ( int *nLocal, int *identArray, int *isError ); |
| 66 |
+ |
|
| 67 |
+ |
LJ_FF* currentLJwrap; |
| 68 |
+ |
|
| 69 |
+ |
|
| 70 |
+ |
//**************************************************************** |
| 71 |
+ |
// begins the actual forcefield stuff. |
| 72 |
+ |
//**************************************************************** |
| 73 |
+ |
|
| 74 |
+ |
|
| 75 |
|
LJ_FF::LJ_FF(){ |
| 76 |
|
|
| 77 |
|
char fileName[200]; |
| 80 |
|
char temp[200]; |
| 81 |
|
char errMsg[1000]; |
| 82 |
|
|
| 83 |
+ |
// do the funtion wrapping |
| 84 |
+ |
currentLJwrap = this; |
| 85 |
+ |
wrapMe(); |
| 86 |
+ |
|
| 87 |
|
#ifdef IS_MPI |
| 88 |
|
int i; |
| 89 |
|
|
| 176 |
|
fclose( frcFile ); |
| 177 |
|
|
| 178 |
|
#ifdef IS_MPI |
| 179 |
+ |
} |
| 180 |
+ |
#endif // is_mpi |
| 181 |
+ |
} |
| 182 |
+ |
|
| 183 |
+ |
|
| 184 |
+ |
void LJ_FF::wrapMe( void ){ |
| 185 |
+ |
|
| 186 |
+ |
char* currentFF = "LJ"; |
| 187 |
+ |
int isError = 0; |
| 188 |
+ |
|
| 189 |
+ |
forcefactory_( currentFF, &isError, LJfunctionWrapper, strlen(currentFF) ); |
| 190 |
+ |
|
| 191 |
+ |
if( isError ){ |
| 192 |
+ |
|
| 193 |
+ |
sprintf( painCave.errMsg, |
| 194 |
+ |
"LJ_FF error: an error was returned from fortran when the " |
| 195 |
+ |
"the functions were being wrapped.\n" ); |
| 196 |
+ |
painCave.isFatal = 1; |
| 197 |
+ |
simError(); |
| 198 |
|
} |
| 199 |
+ |
|
| 200 |
+ |
#ifdef IS_MPI |
| 201 |
+ |
sprintf( checkPointMsg, "LJ_FF functions succesfully wrapped." ); |
| 202 |
+ |
MPIcheckPoint(); |
| 203 |
|
#endif // is_mpi |
| 204 |
|
} |
| 205 |
+ |
|
| 206 |
|
|
| 207 |
+ |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
| 208 |
+ |
double* sigma, int* status ), |
| 209 |
+ |
void (*p2)( int*, int*, int* ), |
| 210 |
+ |
void (*p3)( double* positionArray,double* forceArray, |
| 211 |
+ |
double* potentialEnergy, |
| 212 |
+ |
short int* doPotentialCalc ) ){ |
| 213 |
+ |
|
| 214 |
+ |
|
| 215 |
+ |
newLJtype = p1; |
| 216 |
+ |
initLJfortran = p2; |
| 217 |
+ |
currentLJwrap->setLJfortran( p3 ); |
| 218 |
+ |
} |
| 219 |
+ |
|
| 220 |
+ |
|
| 221 |
+ |
|
| 222 |
|
void LJ_FF::initializeAtoms( void ){ |
| 223 |
|
|
| 224 |
|
class LinkedType { |
| 241 |
|
// check for duplicates |
| 242 |
|
|
| 243 |
|
if( !strcmp( info.name, name ) ){ |
| 244 |
< |
sprintf( simError.painCave, |
| 244 |
> |
sprintf( painCave.errMsg, |
| 245 |
|
"Duplicate LJ atom type \"%s\" found in " |
| 246 |
|
"the LJ_FF param file./n", |
| 247 |
|
name ); |
| 306 |
|
|
| 307 |
|
headAtomType = new LinkedType; |
| 308 |
|
|
| 309 |
< |
fastFoward( "AtomTypes", "initializeAtoms" ); |
| 309 |
> |
fastForward( "AtomTypes", "initializeAtoms" ); |
| 310 |
|
|
| 311 |
|
// we are now at the AtomTypes section. |
| 312 |
|
|
| 378 |
|
#endif // is_mpi |
| 379 |
|
|
| 380 |
|
// call new A_types in fortran |
| 381 |
+ |
|
| 382 |
+ |
int isError; |
| 383 |
+ |
currentAtomType = headAtomType; |
| 384 |
+ |
while( currentAtomType != NULL ){ |
| 385 |
+ |
|
| 386 |
+ |
if( currentAtomType->name[0] != '\0' ){ |
| 387 |
+ |
isError = 0; |
| 388 |
+ |
newLJtype( &(currentAtomType->ident), |
| 389 |
+ |
&(currentAtomType->mass), |
| 390 |
+ |
&(currentAtomType->epslon), |
| 391 |
+ |
&(currentAtomType->sigma), |
| 392 |
+ |
&isError ); |
| 393 |
+ |
if( isError ){ |
| 394 |
+ |
sprintf( painCave.errMsg, |
| 395 |
+ |
"Error initializing the \"%s\" atom type in fortran\n", |
| 396 |
+ |
currentAtomType->name ); |
| 397 |
+ |
painCave.isFatal = 1; |
| 398 |
+ |
simError(); |
| 399 |
+ |
} |
| 400 |
+ |
} |
| 401 |
+ |
currentAtomType = currentAtomType->next; |
| 402 |
+ |
} |
| 403 |
+ |
|
| 404 |
+ |
#ifdef IS_MPI |
| 405 |
+ |
sprintf( checkPointMsg, |
| 406 |
+ |
"LJ_FF atom structures successfully sent to fortran\n" ); |
| 407 |
+ |
MPIcheckPoint(); |
| 408 |
+ |
#endif // is_mpi |
| 409 |
|
|
| 410 |
+ |
|
| 411 |
|
|
| 412 |
|
// initialize the atoms |
| 413 |
|
|
| 414 |
+ |
double bigSigma = 0.0; |
| 415 |
|
Atom* thisAtom; |
| 416 |
|
|
| 417 |
|
for( i=0; i<nAtoms; i++ ){ |
| 430 |
|
the_atoms[i]->setSigma( currentAtomType->sigma ); |
| 431 |
|
the_atoms[i]->setIdent( currentAtomType->ident ); |
| 432 |
|
the_atoms[i]->setLJ(); |
| 433 |
+ |
|
| 434 |
+ |
if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma; |
| 435 |
|
} |
| 436 |
|
|
| 437 |
+ |
|
| 438 |
+ |
#ifdef IS_MPI |
| 439 |
+ |
double tempBig = bigSigma; |
| 440 |
+ |
MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX ); |
| 441 |
+ |
#endif //is_mpi |
| 442 |
|
|
| 443 |
+ |
//calc rCut and rList |
| 444 |
+ |
|
| 445 |
+ |
entry_plug->rCut = 2.5 * bigSigma; |
| 446 |
+ |
if(entry_plug->rCut > (entry_plug->box_x / 2.0)) entry_plug->rCut = entry_plug->box_x / 2.0; |
| 447 |
+ |
if(entry_plug->rCut > (entry_plug->box_y / 2.0)) entry_plug->rCut = entry_plug->box_y / 2.0; |
| 448 |
+ |
if(entry_plug->rCut > (entry_plug->box_z / 2.0)) entry_plug->rCut = entry_plug->box_z / 2.0; |
| 449 |
+ |
|
| 450 |
+ |
entry_plug->rList = entry_plug->rCut + 1.0; |
| 451 |
+ |
|
| 452 |
|
// clean up the memory |
| 453 |
|
|
| 454 |
|
delete headAtomType; |
| 458 |
|
MPIcheckPoint(); |
| 459 |
|
#endif // is_mpi |
| 460 |
|
|
| 461 |
+ |
initFortran(); |
| 462 |
+ |
entry_plug->refreshSim(); |
| 463 |
+ |
|
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
void LJ_FF::initializeBonds( bond_pair* the_bonds ){ |
| 602 |
|
} |
| 603 |
|
else return 0; |
| 604 |
|
} |
| 605 |
+ |
|
| 606 |
+ |
|
| 607 |
+ |
void LJ_FF::doForces( int calcPot ){ |
| 608 |
+ |
|
| 609 |
+ |
int i; |
| 610 |
+ |
double* frc; |
| 611 |
+ |
double* pos; |
| 612 |
+ |
short int passedCalcPot = (short int)calcPot; |
| 613 |
+ |
|
| 614 |
+ |
// forces are zeroed here, before any are acumulated. |
| 615 |
+ |
// NOTE: do not rezero the forces in Fortran. |
| 616 |
+ |
|
| 617 |
+ |
for(i=0; i<entry_plug->n_atoms; i++){ |
| 618 |
+ |
entry_plug->atoms[i]->zeroForces(); |
| 619 |
+ |
} |
| 620 |
+ |
|
| 621 |
+ |
frc = Atom::getFrcArray(); |
| 622 |
+ |
pos = Atom::getPosArray(); |
| 623 |
+ |
|
| 624 |
+ |
// entry_plug->lrPot = -1; |
| 625 |
+ |
doLJfortran( pos, frc, &(entry_plug->lrPot), &passedCalcPot ); |
| 626 |
+ |
|
| 627 |
+ |
|
| 628 |
+ |
// fprintf( stderr, |
| 629 |
+ |
// "lrPot = %lf\n", entry_plug->lrPot ); |
| 630 |
+ |
|
| 631 |
+ |
} |
| 632 |
+ |
|
| 633 |
+ |
void LJ_FF::initFortran( void ){ |
| 634 |
+ |
|
| 635 |
+ |
int nLocal = entry_plug->n_atoms; |
| 636 |
+ |
int *ident; |
| 637 |
+ |
int isError; |
| 638 |
+ |
int i; |
| 639 |
+ |
|
| 640 |
+ |
ident = new int[nLocal]; |
| 641 |
+ |
|
| 642 |
+ |
for(i=0; i<nLocal; i++){ |
| 643 |
+ |
ident[i] = entry_plug->atoms[i]->getIdent(); |
| 644 |
+ |
} |
| 645 |
+ |
|
| 646 |
+ |
isError = 0; |
| 647 |
+ |
initLJfortran( &nLocal, ident, &isError ); |
| 648 |
+ |
|
| 649 |
+ |
if(isError){ |
| 650 |
+ |
sprintf( painCave.errMsg, |
| 651 |
+ |
"LJ_FF error: There was an error initializing the component list in fortran.\n" ); |
| 652 |
+ |
painCave.isFatal = 1; |
| 653 |
+ |
simError(); |
| 654 |
+ |
} |
| 655 |
+ |
|
| 656 |
+ |
|
| 657 |
+ |
#ifdef IS_MPI |
| 658 |
+ |
sprintf( checkPointMsg, "LJ_FF successfully initialized the fortran component list.\n" ); |
| 659 |
+ |
MPIcheckPoint(); |
| 660 |
+ |
#endif // is_mpi |
| 661 |
+ |
|
| 662 |
+ |
delete[] ident; |
| 663 |
+ |
|
| 664 |
+ |
} |
| 665 |
+ |
|