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 |
< |
short int* doPotentialCalc )), |
58 |
< |
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 |
|
|
62 |
– |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
63 |
– |
double* sigma, int* status ), |
64 |
– |
void (*p2)( int *nLocal, int *identArray, int *isError ), |
65 |
– |
void (*p3)( double* positionArray,double* forceArray, |
66 |
– |
double* potentialEnergy, |
67 |
– |
short int* doPotentialCalc ) ); |
68 |
– |
|
69 |
– |
void (*newLJtype)( int* ident, double* mass, double* epslon, double* sigma, |
70 |
– |
int* status ); |
71 |
– |
|
72 |
– |
void (*initLJfortran) ( int *nLocal, int *identArray, int *isError ); |
73 |
– |
|
74 |
– |
LJ_FF* currentLJwrap; |
75 |
– |
|
76 |
– |
|
49 |
|
//**************************************************************** |
50 |
|
// begins the actual forcefield stuff. |
51 |
|
//**************************************************************** |
60 |
|
char errMsg[1000]; |
61 |
|
|
62 |
|
// do the funtion wrapping |
63 |
< |
currentLJwrap = this; |
92 |
< |
wrapMe(); |
63 |
> |
wrapMeFF( this ); |
64 |
|
|
65 |
|
#ifdef IS_MPI |
66 |
|
int i; |
156 |
|
#ifdef IS_MPI |
157 |
|
} |
158 |
|
#endif // is_mpi |
188 |
– |
} |
189 |
– |
|
190 |
– |
|
191 |
– |
void LJ_FF::wrapMe( void ){ |
192 |
– |
|
193 |
– |
char* currentFF = "LJ"; |
194 |
– |
int isError = 0; |
195 |
– |
|
196 |
– |
forcefactory_( currentFF, &isError, LJfunctionWrapper, strlen(currentFF) ); |
197 |
– |
|
198 |
– |
if( isError ){ |
199 |
– |
|
200 |
– |
sprintf( painCave.errMsg, |
201 |
– |
"LJ_FF error: an error was returned from fortran when the " |
202 |
– |
"the functions were being wrapped.\n" ); |
203 |
– |
painCave.isFatal = 1; |
204 |
– |
simError(); |
205 |
– |
} |
206 |
– |
|
207 |
– |
#ifdef IS_MPI |
208 |
– |
sprintf( checkPointMsg, "LJ_FF functions succesfully wrapped." ); |
209 |
– |
MPIcheckPoint(); |
210 |
– |
#endif // is_mpi |
211 |
– |
} |
212 |
– |
|
213 |
– |
|
214 |
– |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
215 |
– |
double* sigma, int* status ), |
216 |
– |
void (*p2)( int*, int*, int* ), |
217 |
– |
void (*p3)( double* positionArray,double* forceArray, |
218 |
– |
double* potentialEnergy, |
219 |
– |
short int* doPotentialCalc ) ){ |
220 |
– |
|
221 |
– |
|
222 |
– |
newLJtype = p1; |
223 |
– |
initLJfortran = p2; |
224 |
– |
currentLJwrap->setLJfortran( p3 ); |
159 |
|
} |
160 |
|
|
161 |
|
|
336 |
|
// call new A_types in fortran |
337 |
|
|
338 |
|
int isError; |
339 |
+ |
|
340 |
+ |
// dummy variables |
341 |
+ |
int isLJ = 1; |
342 |
+ |
int isDipole = 0; |
343 |
+ |
int isSSD = 0; |
344 |
+ |
int isGB = 0; |
345 |
+ |
double w0 = 0.0; |
346 |
+ |
double v0 = 0.0; |
347 |
+ |
double dipole = 0.0; |
348 |
+ |
|
349 |
+ |
|
350 |
|
currentAtomType = headAtomType; |
351 |
|
while( currentAtomType != NULL ){ |
352 |
|
|
353 |
|
if( currentAtomType->name[0] != '\0' ){ |
354 |
|
isError = 0; |
355 |
< |
newLJtype( &(currentAtomType->ident), |
356 |
< |
&(currentAtomType->mass), |
357 |
< |
&(currentAtomType->epslon), |
358 |
< |
&(currentAtomType->sigma), |
359 |
< |
&isError ); |
355 |
> |
newAtype( &(currentAtomType->ident), |
356 |
> |
&(currentAtomType->mass), |
357 |
> |
&(currentAtomType->epslon), |
358 |
> |
&(currentAtomType->sigma), |
359 |
> |
&isLJ, &isSSD, &isDipole, &isGB, &w0, &v0, &dipole, |
360 |
> |
&isError ); |
361 |
|
if( isError ){ |
362 |
|
sprintf( painCave.errMsg, |
363 |
|
"Error initializing the \"%s\" atom type in fortran\n", |
426 |
|
MPIcheckPoint(); |
427 |
|
#endif // is_mpi |
428 |
|
|
429 |
< |
initFortran(); |
429 |
> |
this->initFortran(); |
430 |
|
entry_plug->refreshSim(); |
431 |
< |
|
431 |
> |
|
432 |
|
} |
433 |
|
|
434 |
|
void LJ_FF::initializeBonds( bond_pair* the_bonds ){ |
473 |
|
|
474 |
|
} |
475 |
|
|
530 |
– |
|
476 |
|
void LJ_FF::fastForward( char* stopText, char* searchOwner ){ |
477 |
|
|
478 |
|
int foundText = 0; |
529 |
|
|
530 |
|
|
531 |
|
|
532 |
< |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ){ |
532 |
> |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){ |
533 |
|
|
534 |
|
char* the_token; |
535 |
|
|
568 |
|
return 1; |
569 |
|
} |
570 |
|
else return 0; |
626 |
– |
} |
627 |
– |
|
628 |
– |
|
629 |
– |
void LJ_FF::doForces( int calcPot ){ |
630 |
– |
|
631 |
– |
int i; |
632 |
– |
double* frc; |
633 |
– |
double* pos; |
634 |
– |
short int passedCalcPot = (short int)calcPot; |
635 |
– |
|
636 |
– |
// forces are zeroed here, before any are acumulated. |
637 |
– |
// NOTE: do not rezero the forces in Fortran. |
638 |
– |
|
639 |
– |
for(i=0; i<entry_plug->n_atoms; i++){ |
640 |
– |
entry_plug->atoms[i]->zeroForces(); |
641 |
– |
} |
642 |
– |
|
643 |
– |
frc = Atom::getFrcArray(); |
644 |
– |
pos = Atom::getPosArray(); |
645 |
– |
|
646 |
– |
// entry_plug->lrPot = -1; |
647 |
– |
doLJfortran( pos, frc, &(entry_plug->lrPot), &passedCalcPot ); |
648 |
– |
|
649 |
– |
|
650 |
– |
// fprintf( stderr, |
651 |
– |
// "lrPot = %lf\n", entry_plug->lrPot ); |
652 |
– |
|
571 |
|
} |
654 |
– |
|
655 |
– |
void LJ_FF::initFortran( void ){ |
656 |
– |
|
657 |
– |
int nLocal = entry_plug->n_atoms; |
658 |
– |
int *ident; |
659 |
– |
int isError; |
660 |
– |
int i; |
661 |
– |
|
662 |
– |
ident = new int[nLocal]; |
663 |
– |
|
664 |
– |
for(i=0; i<nLocal; i++){ |
665 |
– |
ident[i] = entry_plug->atoms[i]->getIdent(); |
666 |
– |
} |
667 |
– |
|
668 |
– |
isError = 0; |
669 |
– |
initLJfortran( &nLocal, ident, &isError ); |
670 |
– |
|
671 |
– |
if(isError){ |
672 |
– |
sprintf( painCave.errMsg, |
673 |
– |
"LJ_FF error: There was an error initializing the component list in fortran.\n" ); |
674 |
– |
painCave.isFatal = 1; |
675 |
– |
simError(); |
676 |
– |
} |
677 |
– |
|
678 |
– |
|
679 |
– |
#ifdef IS_MPI |
680 |
– |
sprintf( checkPointMsg, "LJ_FF successfully initialized the fortran component list.\n" ); |
681 |
– |
MPIcheckPoint(); |
682 |
– |
#endif // is_mpi |
683 |
– |
|
684 |
– |
delete[] ident; |
685 |
– |
|
686 |
– |
} |
687 |
– |
|