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