14 |
|
#include "SRI.hpp" |
15 |
|
#include "simError.h" |
16 |
|
|
17 |
+ |
#include <fortranWrappers.hpp> |
18 |
+ |
|
19 |
|
#ifdef IS_MPI |
20 |
|
#include "mpiForceField.h" |
21 |
|
#endif // is_mpi |
45 |
|
#endif |
46 |
|
} |
47 |
|
|
46 |
– |
// declaration of functions needed to wrap the fortran module |
48 |
|
|
48 |
– |
extern "C" { |
49 |
– |
void forcefactory_( char* forceName, |
50 |
– |
int* status, |
51 |
– |
void (*wrapFunction)( void (*p1)( int* ident, |
52 |
– |
double* mass, |
53 |
– |
double* epslon, |
54 |
– |
double* sigma, |
55 |
– |
int* status ), |
56 |
– |
void (*p2)( int *nLocal, |
57 |
– |
int *identArray, |
58 |
– |
int *isError ), |
59 |
– |
void (*p3)( double* positionArray, |
60 |
– |
double* forceArray, |
61 |
– |
double* potentialEnergy, |
62 |
– |
double* tau, |
63 |
– |
short int* doPotentialCalc, |
64 |
– |
int* isError)), |
65 |
– |
int forceNameLength ); |
66 |
– |
} |
67 |
– |
|
68 |
– |
|
69 |
– |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
70 |
– |
double* sigma, int* status ), |
71 |
– |
void (*p2)( int *nLocal, int *identArray, int *isError ), |
72 |
– |
void (*p3)( double* positionArray,double* forceArray, |
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 ); |
78 |
– |
|
79 |
– |
void (*initLJfortran) ( int *nLocal, int *identArray, int *isError ); |
80 |
– |
|
81 |
– |
LJ_FF* currentLJwrap; |
82 |
– |
|
83 |
– |
|
49 |
|
//**************************************************************** |
50 |
|
// begins the actual forcefield stuff. |
51 |
|
//**************************************************************** |
60 |
|
char errMsg[1000]; |
61 |
|
|
62 |
|
// do the funtion wrapping |
63 |
< |
currentLJwrap = this; |
99 |
< |
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, |
146 |
< |
"Error opening the force field parameter file: %s\n" |
147 |
< |
"Have you tried setting the FORCE_PARAM_PATH environment " |
148 |
< |
"vairable?\n", |
149 |
< |
fileName ); |
150 |
< |
painCave.isFatal = 1; |
151 |
< |
simError(); |
109 |
> |
STR_DEFINE(ffPath, FRC_PATH ); |
110 |
|
} |
111 |
|
|
112 |
|
|
153 |
|
} |
154 |
|
|
155 |
|
|
198 |
– |
void LJ_FF::wrapMe( void ){ |
199 |
– |
|
200 |
– |
char* currentFF = "LJ"; |
201 |
– |
int isError = 0; |
202 |
– |
|
203 |
– |
forcefactory_( currentFF, &isError, LJfunctionWrapper, strlen(currentFF) ); |
156 |
|
|
205 |
– |
if( isError ){ |
206 |
– |
|
207 |
– |
sprintf( painCave.errMsg, |
208 |
– |
"LJ_FF error: an error was returned from fortran when the " |
209 |
– |
"the functions were being wrapped.\n" ); |
210 |
– |
painCave.isFatal = 1; |
211 |
– |
simError(); |
212 |
– |
} |
213 |
– |
|
214 |
– |
#ifdef IS_MPI |
215 |
– |
sprintf( checkPointMsg, "LJ_FF functions succesfully wrapped." ); |
216 |
– |
MPIcheckPoint(); |
217 |
– |
#endif // is_mpi |
218 |
– |
} |
219 |
– |
|
220 |
– |
|
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*,double*,double*,double*, |
225 |
– |
short int*, int* ) ){ |
226 |
– |
|
227 |
– |
|
228 |
– |
newLJtype = p1; |
229 |
– |
initLJfortran = p2; |
230 |
– |
currentLJwrap->setLJfortran( p3 ); |
231 |
– |
} |
232 |
– |
|
233 |
– |
|
234 |
– |
|
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 ){ |
461 |
|
painCave.isFatal = 1; |
462 |
|
simError(); |
463 |
|
} |
530 |
– |
#ifdef IS_MPI |
531 |
– |
MPIcheckPoint(); |
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 |
– |
|
464 |
|
#ifdef IS_MPI |
567 |
– |
sprintf( checkPointMsg, |
568 |
– |
"returned from the force calculation.\n" ); |
465 |
|
MPIcheckPoint(); |
466 |
|
#endif // is_mpi |
467 |
|
|
468 |
|
} |
573 |
– |
|
574 |
– |
void LJ_FF::initFortran( void ){ |
575 |
– |
|
576 |
– |
int nLocal = entry_plug->n_atoms; |
577 |
– |
int *ident; |
578 |
– |
int isError; |
579 |
– |
int i; |
469 |
|
|
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 |
– |
|
470 |
|
void LJ_FF::fastForward( char* stopText, char* searchOwner ){ |
471 |
|
|
472 |
|
int foundText = 0; |