14 |
|
#include "SRI.hpp" |
15 |
|
#include "simError.h" |
16 |
|
|
17 |
+ |
#include <fortranWrappers.hpp> |
18 |
|
|
18 |
– |
|
19 |
– |
// Declare the structures that will be passed by the parser and MPI |
20 |
– |
|
21 |
– |
typedef struct{ |
22 |
– |
char name[15]; |
23 |
– |
double mass; |
24 |
– |
double epslon; |
25 |
– |
double sigma; |
26 |
– |
int ident; |
27 |
– |
int last; // 0 -> default |
28 |
– |
// 1 -> in MPI: tells nodes to stop listening |
29 |
– |
} atomStruct; |
30 |
– |
|
31 |
– |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ); |
32 |
– |
|
19 |
|
#ifdef IS_MPI |
20 |
|
#include "mpiForceField.h" |
21 |
+ |
#endif // is_mpi |
22 |
|
|
36 |
– |
MPI_Datatype mpiAtomStructType; |
23 |
|
|
38 |
– |
#endif |
24 |
|
|
25 |
+ |
namespace { |
26 |
|
|
27 |
< |
// declaration of functions needed to wrap the fortran module |
27 |
> |
// Declare the structures that will be passed by the parser and MPI |
28 |
> |
|
29 |
> |
typedef struct{ |
30 |
> |
char name[15]; |
31 |
> |
double mass; |
32 |
> |
double epslon; |
33 |
> |
double sigma; |
34 |
> |
int ident; |
35 |
> |
int last; // 0 -> default |
36 |
> |
// 1 -> in MPI: tells nodes to stop listening |
37 |
> |
} atomStruct; |
38 |
|
|
39 |
< |
extern "C" { |
40 |
< |
void forcefactory_( char* forceName, |
41 |
< |
int* status, |
42 |
< |
void (*wrapFunction)( void (*p1)( int* ident, |
43 |
< |
double* mass, |
44 |
< |
double* epslon, |
45 |
< |
double* sigma, |
50 |
< |
int* status ), |
51 |
< |
void (*p2)( int *nLocal, |
52 |
< |
int *identArray, |
53 |
< |
int *isError ), |
54 |
< |
void (*p3)( double* positionArray, |
55 |
< |
double* forceArray, |
56 |
< |
double* potentialEnergy, |
57 |
< |
double* tau, |
58 |
< |
short int* doPotentialCalc, |
59 |
< |
int* isError)), |
60 |
< |
int forceNameLength ); |
39 |
> |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ); |
40 |
> |
|
41 |
> |
#ifdef IS_MPI |
42 |
> |
|
43 |
> |
MPI_Datatype mpiAtomStructType; |
44 |
> |
|
45 |
> |
#endif |
46 |
|
} |
47 |
|
|
48 |
|
|
64 |
– |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
65 |
– |
double* sigma, int* status ), |
66 |
– |
void (*p2)( int *nLocal, int *identArray, int *isError ), |
67 |
– |
void (*p3)( double* positionArray,double* forceArray, |
68 |
– |
double* potentialEnergy, double* tau, |
69 |
– |
short int* doPotentialCalc, int* isError ) ); |
70 |
– |
|
71 |
– |
void (*newLJtype)( int* ident, double* mass, double* epslon, double* sigma, |
72 |
– |
int* status ); |
73 |
– |
|
74 |
– |
void (*initLJfortran) ( int *nLocal, int *identArray, int *isError ); |
75 |
– |
|
76 |
– |
LJ_FF* currentLJwrap; |
77 |
– |
|
78 |
– |
|
49 |
|
//**************************************************************** |
50 |
|
// begins the actual forcefield stuff. |
51 |
|
//**************************************************************** |
60 |
|
char errMsg[1000]; |
61 |
|
|
62 |
|
// do the funtion wrapping |
63 |
< |
currentLJwrap = this; |
94 |
< |
wrapMe(); |
63 |
> |
wrapMeFF( this ); |
64 |
|
|
65 |
|
#ifdef IS_MPI |
66 |
|
int i; |
155 |
|
|
156 |
|
#ifdef IS_MPI |
157 |
|
} |
189 |
– |
#endif // is_mpi |
190 |
– |
} |
191 |
– |
|
192 |
– |
|
193 |
– |
void LJ_FF::wrapMe( void ){ |
194 |
– |
|
195 |
– |
char* currentFF = "LJ"; |
196 |
– |
int isError = 0; |
197 |
– |
|
198 |
– |
forcefactory_( currentFF, &isError, LJfunctionWrapper, strlen(currentFF) ); |
199 |
– |
|
200 |
– |
if( isError ){ |
201 |
– |
|
202 |
– |
sprintf( painCave.errMsg, |
203 |
– |
"LJ_FF error: an error was returned from fortran when the " |
204 |
– |
"the functions were being wrapped.\n" ); |
205 |
– |
painCave.isFatal = 1; |
206 |
– |
simError(); |
207 |
– |
} |
208 |
– |
|
209 |
– |
#ifdef IS_MPI |
210 |
– |
sprintf( checkPointMsg, "LJ_FF functions succesfully wrapped." ); |
211 |
– |
MPIcheckPoint(); |
158 |
|
#endif // is_mpi |
159 |
|
} |
214 |
– |
|
160 |
|
|
216 |
– |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
217 |
– |
double* sigma, int* status ), |
218 |
– |
void (*p2)( int*, int*, int* ), |
219 |
– |
void (*p3)( double* positionArray,double* forceArray, |
220 |
– |
double* potentialEnergy, |
221 |
– |
short int* doPotentialCalc ) ){ |
222 |
– |
|
223 |
– |
|
224 |
– |
newLJtype = p1; |
225 |
– |
initLJfortran = p2; |
226 |
– |
currentLJwrap->setLJfortran( p3 ); |
227 |
– |
} |
161 |
|
|
162 |
|
|
230 |
– |
|
163 |
|
void LJ_FF::initializeAtoms( void ){ |
164 |
|
|
165 |
|
class LinkedType { |
455 |
|
painCave.isFatal = 1; |
456 |
|
simError(); |
457 |
|
} |
458 |
+ |
#ifdef IS_MPI |
459 |
+ |
MPIcheckPoint(); |
460 |
+ |
#endif // is_mpi |
461 |
+ |
|
462 |
+ |
} |
463 |
+ |
|
464 |
+ |
void LJ_FF::doForces( int calcPot ){ |
465 |
+ |
|
466 |
+ |
int i, isError; |
467 |
+ |
double* frc; |
468 |
+ |
double* pos; |
469 |
+ |
double* tau; |
470 |
+ |
short int passedCalcPot = (short int)calcPot; |
471 |
+ |
|
472 |
+ |
// forces are zeroed here, before any are acumulated. |
473 |
+ |
// NOTE: do not rezero the forces in Fortran. |
474 |
+ |
|
475 |
+ |
for(i=0; i<entry_plug->n_atoms; i++){ |
476 |
+ |
entry_plug->atoms[i]->zeroForces(); |
477 |
+ |
} |
478 |
+ |
|
479 |
+ |
frc = Atom::getFrcArray(); |
480 |
+ |
pos = Atom::getPosArray(); |
481 |
+ |
tau = entry_plug->tau; |
482 |
+ |
|
483 |
+ |
isError = 0; |
484 |
+ |
doLJfortran( pos, frc, &(entry_plug->lrPot), tau, &passedCalcPot, &isError ); |
485 |
+ |
|
486 |
+ |
|
487 |
+ |
if( isError ){ |
488 |
+ |
sprintf( painCave.errMsg, |
489 |
+ |
"Error returned from the fortran force calculation.\n" ); |
490 |
+ |
painCave.isFatal = 1; |
491 |
+ |
simError(); |
492 |
+ |
} |
493 |
+ |
|
494 |
|
#ifdef IS_MPI |
495 |
+ |
sprintf( checkPointMsg, |
496 |
+ |
"returned from the force calculation.\n" ); |
497 |
|
MPIcheckPoint(); |
498 |
|
#endif // is_mpi |
499 |
|
|
500 |
|
} |
501 |
+ |
|
502 |
+ |
void LJ_FF::initFortran( void ){ |
503 |
+ |
|
504 |
+ |
int nLocal = entry_plug->n_atoms; |
505 |
+ |
int *ident; |
506 |
+ |
int isError; |
507 |
+ |
int i; |
508 |
|
|
509 |
+ |
ident = new int[nLocal]; |
510 |
|
|
511 |
+ |
for(i=0; i<nLocal; i++){ |
512 |
+ |
ident[i] = entry_plug->atoms[i]->getIdent(); |
513 |
+ |
} |
514 |
+ |
|
515 |
+ |
isError = 0; |
516 |
+ |
initLJfortran( &nLocal, ident, &isError ); |
517 |
+ |
|
518 |
+ |
if(isError){ |
519 |
+ |
sprintf( painCave.errMsg, |
520 |
+ |
"LJ_FF error: There was an error initializing the component list in fortran.\n" ); |
521 |
+ |
painCave.isFatal = 1; |
522 |
+ |
simError(); |
523 |
+ |
} |
524 |
+ |
|
525 |
+ |
|
526 |
+ |
#ifdef IS_MPI |
527 |
+ |
sprintf( checkPointMsg, "LJ_FF successfully initialized the fortran component list.\n" ); |
528 |
+ |
MPIcheckPoint(); |
529 |
+ |
#endif // is_mpi |
530 |
+ |
|
531 |
+ |
delete[] ident; |
532 |
+ |
|
533 |
+ |
} |
534 |
+ |
|
535 |
+ |
|
536 |
|
void LJ_FF::fastForward( char* stopText, char* searchOwner ){ |
537 |
|
|
538 |
|
int foundText = 0; |
589 |
|
|
590 |
|
|
591 |
|
|
592 |
< |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ){ |
592 |
> |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){ |
593 |
|
|
594 |
|
char* the_token; |
595 |
|
|
629 |
|
} |
630 |
|
else return 0; |
631 |
|
} |
629 |
– |
|
630 |
– |
|
631 |
– |
void LJ_FF::doForces( int calcPot ){ |
632 |
– |
|
633 |
– |
int i, isError; |
634 |
– |
double* frc; |
635 |
– |
double* pos; |
636 |
– |
double* tau; |
637 |
– |
short int passedCalcPot = (short int)calcPot; |
638 |
– |
|
639 |
– |
// forces are zeroed here, before any are acumulated. |
640 |
– |
// NOTE: do not rezero the forces in Fortran. |
641 |
– |
|
642 |
– |
for(i=0; i<entry_plug->n_atoms; i++){ |
643 |
– |
entry_plug->atoms[i]->zeroForces(); |
644 |
– |
} |
645 |
– |
|
646 |
– |
frc = Atom::getFrcArray(); |
647 |
– |
pos = Atom::getPosArray(); |
648 |
– |
tau = entry_plug->tau; |
649 |
– |
|
650 |
– |
isError = 0; |
651 |
– |
doLJfortran( pos, frc, &(entry_plug->lrPot), tau, &passedCalcPot, &isError ); |
652 |
– |
|
653 |
– |
|
654 |
– |
if( isError ){ |
655 |
– |
sprintf( painCave.errMsg, |
656 |
– |
"Error returned from the fortran force calculation.\n" ); |
657 |
– |
painCave.isFatal = 1; |
658 |
– |
simError(); |
659 |
– |
} |
660 |
– |
|
661 |
– |
#ifdef IS_MPI |
662 |
– |
sprintf( checkPointMsg, |
663 |
– |
"returned from the force calculation.\n" ); |
664 |
– |
MPIcheckPoint(); |
665 |
– |
#endif // is_mpi |
666 |
– |
|
667 |
– |
} |
668 |
– |
|
669 |
– |
void LJ_FF::initFortran( void ){ |
670 |
– |
|
671 |
– |
int nLocal = entry_plug->n_atoms; |
672 |
– |
int *ident; |
673 |
– |
int isError; |
674 |
– |
int i; |
675 |
– |
|
676 |
– |
ident = new int[nLocal]; |
677 |
– |
|
678 |
– |
for(i=0; i<nLocal; i++){ |
679 |
– |
ident[i] = entry_plug->atoms[i]->getIdent(); |
680 |
– |
} |
681 |
– |
|
682 |
– |
isError = 0; |
683 |
– |
initLJfortran( &nLocal, ident, &isError ); |
684 |
– |
|
685 |
– |
if(isError){ |
686 |
– |
sprintf( painCave.errMsg, |
687 |
– |
"LJ_FF error: There was an error initializing the component list in fortran.\n" ); |
688 |
– |
painCave.isFatal = 1; |
689 |
– |
simError(); |
690 |
– |
} |
691 |
– |
|
692 |
– |
|
693 |
– |
#ifdef IS_MPI |
694 |
– |
sprintf( checkPointMsg, "LJ_FF successfully initialized the fortran component list.\n" ); |
695 |
– |
MPIcheckPoint(); |
696 |
– |
#endif // is_mpi |
697 |
– |
|
698 |
– |
delete[] ident; |
699 |
– |
|
700 |
– |
} |
701 |
– |
|