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 |
> |
#include <fortranWrappers.hpp> |
18 |
|
|
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; |
23 |
– |
|
24 |
– |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ); |
25 |
– |
|
19 |
|
#ifdef IS_MPI |
20 |
|
#include "mpiForceField.h" |
21 |
+ |
#endif // is_mpi |
22 |
|
|
29 |
– |
MPI_Datatype mpiAtomStructType; |
23 |
|
|
31 |
– |
#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, |
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 ); |
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 |
|
|
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 |
– |
|
49 |
|
//**************************************************************** |
50 |
|
// begins the actual forcefield stuff. |
51 |
|
//**************************************************************** |
60 |
|
char errMsg[1000]; |
61 |
|
|
62 |
|
// do the funtion wrapping |
63 |
< |
currentLJwrap = this; |
85 |
< |
wrapMe(); |
63 |
> |
wrapMeFF( this ); |
64 |
|
|
65 |
|
#ifdef IS_MPI |
66 |
|
int i; |
106 |
|
|
107 |
|
ffPath = getenv( ffPath_env ); |
108 |
|
if( ffPath == NULL ) { |
109 |
< |
sprintf( painCave.errMsg, |
132 |
< |
"Error opening the force field parameter file: %s\n" |
133 |
< |
"Have you tried setting the FORCE_PARAM_PATH environment " |
134 |
< |
"vairable?\n", |
135 |
< |
fileName ); |
136 |
< |
painCave.isFatal = 1; |
137 |
< |
simError(); |
109 |
> |
STR_DEFINE(ffPath, FRC_PATH ); |
110 |
|
} |
111 |
|
|
112 |
|
|
153 |
|
} |
154 |
|
|
155 |
|
|
184 |
– |
void LJ_FF::wrapMe( void ){ |
185 |
– |
|
186 |
– |
char* currentFF = "LJ"; |
187 |
– |
int isError = 0; |
188 |
– |
|
189 |
– |
forcefactory_( currentFF, &isError, LJfunctionWrapper, strlen(currentFF) ); |
156 |
|
|
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 |
– |
|
157 |
|
void LJ_FF::initializeAtoms( void ){ |
158 |
|
|
159 |
|
class LinkedType { |
330 |
|
// call new A_types in fortran |
331 |
|
|
332 |
|
int isError; |
333 |
+ |
|
334 |
+ |
// dummy variables |
335 |
+ |
int isLJ = 1; |
336 |
+ |
int isDipole = 0; |
337 |
+ |
int isSSD = 0; |
338 |
+ |
int isGB = 0; |
339 |
+ |
double w0 = 0.0; |
340 |
+ |
double v0 = 0.0; |
341 |
+ |
double dipole = 0.0; |
342 |
+ |
|
343 |
+ |
|
344 |
|
currentAtomType = headAtomType; |
345 |
|
while( currentAtomType != NULL ){ |
346 |
|
|
347 |
|
if( currentAtomType->name[0] != '\0' ){ |
348 |
|
isError = 0; |
349 |
< |
newLJtype( &(currentAtomType->ident), |
350 |
< |
&(currentAtomType->mass), |
351 |
< |
&(currentAtomType->epslon), |
352 |
< |
&(currentAtomType->sigma), |
353 |
< |
&isError ); |
349 |
> |
newAtype( &(currentAtomType->ident), |
350 |
> |
&(currentAtomType->mass), |
351 |
> |
&(currentAtomType->epslon), |
352 |
> |
&(currentAtomType->sigma), |
353 |
> |
&isLJ, &isSSD, &isDipole, &isGB, &w0, &v0, &dipole, |
354 |
> |
&isError ); |
355 |
|
if( isError ){ |
356 |
|
sprintf( painCave.errMsg, |
357 |
|
"Error initializing the \"%s\" atom type in fortran\n", |
420 |
|
MPIcheckPoint(); |
421 |
|
#endif // is_mpi |
422 |
|
|
423 |
< |
initFortran(); |
423 |
> |
this->initFortran(); |
424 |
|
entry_plug->refreshSim(); |
425 |
< |
|
425 |
> |
|
426 |
|
} |
427 |
|
|
428 |
|
void LJ_FF::initializeBonds( bond_pair* the_bonds ){ |
467 |
|
|
468 |
|
} |
469 |
|
|
523 |
– |
|
470 |
|
void LJ_FF::fastForward( char* stopText, char* searchOwner ){ |
471 |
|
|
472 |
|
int foundText = 0; |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
< |
int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ){ |
526 |
> |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){ |
527 |
|
|
528 |
|
char* the_token; |
529 |
|
|
562 |
|
return 1; |
563 |
|
} |
564 |
|
else return 0; |
619 |
– |
} |
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 |
– |
|
565 |
|
} |
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 |
– |
|