5 |
|
#include <iostream> |
6 |
|
using namespace std; |
7 |
|
|
8 |
+ |
#ifdef IS_MPI |
9 |
+ |
#include <mpi.h> |
10 |
+ |
#include <mpi++.h> |
11 |
+ |
#endif //is_mpi |
12 |
+ |
|
13 |
|
#include "ForceFields.hpp" |
14 |
|
#include "SRI.hpp" |
15 |
|
#include "simError.h" |
16 |
|
|
17 |
< |
// Declare the structures that will be passed by the parser and MPI |
17 |
> |
#ifdef IS_MPI |
18 |
> |
#include "mpiForceField.h" |
19 |
> |
#endif // is_mpi |
20 |
|
|
14 |
– |
typedef struct{ |
15 |
– |
char name[15]; |
16 |
– |
double mass; |
17 |
– |
double epslon; |
18 |
– |
double sigma; |
19 |
– |
int ident; |
20 |
– |
int last; // 0 -> default |
21 |
– |
// 1 -> in MPI: tells nodes to stop listening |
22 |
– |
} atomStruct; |
21 |
|
|
24 |
– |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ); |
22 |
|
|
23 |
< |
#ifdef IS_MPI |
27 |
< |
#include "mpiForceField.h" |
23 |
> |
namespace { |
24 |
|
|
25 |
< |
MPI_Datatype mpiAtomStructType; |
25 |
> |
// Declare the structures that will be passed by the parser and MPI |
26 |
> |
|
27 |
> |
typedef struct{ |
28 |
> |
char name[15]; |
29 |
> |
double mass; |
30 |
> |
double epslon; |
31 |
> |
double sigma; |
32 |
> |
int ident; |
33 |
> |
int last; // 0 -> default |
34 |
> |
// 1 -> in MPI: tells nodes to stop listening |
35 |
> |
} atomStruct; |
36 |
|
|
37 |
+ |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ); |
38 |
+ |
|
39 |
+ |
#ifdef IS_MPI |
40 |
+ |
|
41 |
+ |
MPI_Datatype mpiAtomStructType; |
42 |
+ |
|
43 |
|
#endif |
44 |
+ |
} |
45 |
|
|
33 |
– |
|
46 |
|
// declaration of functions needed to wrap the fortran module |
47 |
|
|
48 |
|
extern "C" { |
59 |
|
void (*p3)( double* positionArray, |
60 |
|
double* forceArray, |
61 |
|
double* potentialEnergy, |
62 |
< |
short int* doPotentialCalc )), |
62 |
> |
double* tau, |
63 |
> |
short int* doPotentialCalc, |
64 |
> |
int* isError)), |
65 |
|
int forceNameLength ); |
66 |
|
} |
67 |
|
|
70 |
|
double* sigma, int* status ), |
71 |
|
void (*p2)( int *nLocal, int *identArray, int *isError ), |
72 |
|
void (*p3)( double* positionArray,double* forceArray, |
73 |
< |
double* potentialEnergy, |
74 |
< |
short int* doPotentialCalc ) ); |
73 |
> |
double* potentialEnergy, double* tau, |
74 |
> |
short int* doPotentialCalc, int* isError ) ); |
75 |
|
|
76 |
|
void (*newLJtype)( int* ident, double* mass, double* epslon, double* sigma, |
77 |
|
int* status ); |
221 |
|
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
222 |
|
double* sigma, int* status ), |
223 |
|
void (*p2)( int*, int*, int* ), |
224 |
< |
void (*p3)( double* positionArray,double* forceArray, |
225 |
< |
double* potentialEnergy, |
212 |
< |
short int* doPotentialCalc ) ){ |
224 |
> |
void (*p3)( double*,double*,double*,double*, |
225 |
> |
short int*, int* ) ){ |
226 |
|
|
227 |
|
|
228 |
|
newLJtype = p1; |
532 |
|
#endif // is_mpi |
533 |
|
|
534 |
|
} |
535 |
+ |
|
536 |
+ |
void LJ_FF::doForces( int calcPot ){ |
537 |
+ |
|
538 |
+ |
int i, isError; |
539 |
+ |
double* frc; |
540 |
+ |
double* pos; |
541 |
+ |
double* tau; |
542 |
+ |
short int passedCalcPot = (short int)calcPot; |
543 |
+ |
|
544 |
+ |
// forces are zeroed here, before any are acumulated. |
545 |
+ |
// NOTE: do not rezero the forces in Fortran. |
546 |
+ |
|
547 |
+ |
for(i=0; i<entry_plug->n_atoms; i++){ |
548 |
+ |
entry_plug->atoms[i]->zeroForces(); |
549 |
+ |
} |
550 |
+ |
|
551 |
+ |
frc = Atom::getFrcArray(); |
552 |
+ |
pos = Atom::getPosArray(); |
553 |
+ |
tau = entry_plug->tau; |
554 |
|
|
555 |
+ |
isError = 0; |
556 |
+ |
doLJfortran( pos, frc, &(entry_plug->lrPot), tau, &passedCalcPot, &isError ); |
557 |
|
|
558 |
+ |
|
559 |
+ |
if( isError ){ |
560 |
+ |
sprintf( painCave.errMsg, |
561 |
+ |
"Error returned from the fortran force calculation.\n" ); |
562 |
+ |
painCave.isFatal = 1; |
563 |
+ |
simError(); |
564 |
+ |
} |
565 |
+ |
|
566 |
+ |
#ifdef IS_MPI |
567 |
+ |
sprintf( checkPointMsg, |
568 |
+ |
"returned from the force calculation.\n" ); |
569 |
+ |
MPIcheckPoint(); |
570 |
+ |
#endif // is_mpi |
571 |
+ |
|
572 |
+ |
} |
573 |
+ |
|
574 |
+ |
void LJ_FF::initFortran( void ){ |
575 |
+ |
|
576 |
+ |
int nLocal = entry_plug->n_atoms; |
577 |
+ |
int *ident; |
578 |
+ |
int isError; |
579 |
+ |
int i; |
580 |
+ |
|
581 |
+ |
ident = new int[nLocal]; |
582 |
+ |
|
583 |
+ |
for(i=0; i<nLocal; i++){ |
584 |
+ |
ident[i] = entry_plug->atoms[i]->getIdent(); |
585 |
+ |
} |
586 |
+ |
|
587 |
+ |
isError = 0; |
588 |
+ |
initLJfortran( &nLocal, ident, &isError ); |
589 |
+ |
|
590 |
+ |
if(isError){ |
591 |
+ |
sprintf( painCave.errMsg, |
592 |
+ |
"LJ_FF error: There was an error initializing the component list in fortran.\n" ); |
593 |
+ |
painCave.isFatal = 1; |
594 |
+ |
simError(); |
595 |
+ |
} |
596 |
+ |
|
597 |
+ |
|
598 |
+ |
#ifdef IS_MPI |
599 |
+ |
sprintf( checkPointMsg, "LJ_FF successfully initialized the fortran component list.\n" ); |
600 |
+ |
MPIcheckPoint(); |
601 |
+ |
#endif // is_mpi |
602 |
+ |
|
603 |
+ |
delete[] ident; |
604 |
+ |
|
605 |
+ |
} |
606 |
+ |
|
607 |
+ |
|
608 |
|
void LJ_FF::fastForward( char* stopText, char* searchOwner ){ |
609 |
|
|
610 |
|
int foundText = 0; |
661 |
|
|
662 |
|
|
663 |
|
|
664 |
< |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ){ |
664 |
> |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){ |
665 |
|
|
666 |
|
char* the_token; |
667 |
|
|
701 |
|
} |
702 |
|
else return 0; |
703 |
|
} |
620 |
– |
|
621 |
– |
|
622 |
– |
void LJ_FF::doForces( int calcPot ){ |
623 |
– |
|
624 |
– |
int i; |
625 |
– |
double* frc; |
626 |
– |
double* pos; |
627 |
– |
short int passedCalcPot = (short int)calcPot; |
628 |
– |
|
629 |
– |
// forces are zeroed here, before any are acumulated. |
630 |
– |
// NOTE: do not rezero the forces in Fortran. |
631 |
– |
|
632 |
– |
for(i=0; i<entry_plug->n_atoms; i++){ |
633 |
– |
entry_plug->atoms[i]->zeroForces(); |
634 |
– |
} |
635 |
– |
|
636 |
– |
frc = Atom::getFrcArray(); |
637 |
– |
pos = Atom::getPosArray(); |
638 |
– |
|
639 |
– |
// entry_plug->lrPot = -1; |
640 |
– |
doLJfortran( pos, frc, &(entry_plug->lrPot), &passedCalcPot ); |
641 |
– |
|
642 |
– |
|
643 |
– |
// fprintf( stderr, |
644 |
– |
// "lrPot = %lf\n", entry_plug->lrPot ); |
645 |
– |
|
646 |
– |
} |
647 |
– |
|
648 |
– |
void LJ_FF::initFortran( void ){ |
649 |
– |
|
650 |
– |
int nLocal = entry_plug->n_atoms; |
651 |
– |
int *ident; |
652 |
– |
int isError; |
653 |
– |
int i; |
654 |
– |
|
655 |
– |
ident = new int[nLocal]; |
656 |
– |
|
657 |
– |
for(i=0; i<nLocal; i++){ |
658 |
– |
ident[i] = entry_plug->atoms[i]->getIdent(); |
659 |
– |
} |
660 |
– |
|
661 |
– |
isError = 0; |
662 |
– |
initLJfortran( &nLocal, ident, &isError ); |
663 |
– |
|
664 |
– |
if(isError){ |
665 |
– |
sprintf( painCave.errMsg, |
666 |
– |
"LJ_FF error: There was an error initializing the component list in fortran.\n" ); |
667 |
– |
painCave.isFatal = 1; |
668 |
– |
simError(); |
669 |
– |
} |
670 |
– |
|
671 |
– |
|
672 |
– |
#ifdef IS_MPI |
673 |
– |
sprintf( checkPointMsg, "LJ_FF successfully initialized the fortran component list.\n" ); |
674 |
– |
MPIcheckPoint(); |
675 |
– |
#endif // is_mpi |
676 |
– |
|
677 |
– |
delete[] ident; |
678 |
– |
|
679 |
– |
} |
680 |
– |
|