33 |
|
#endif |
34 |
|
|
35 |
|
|
36 |
+ |
// declaration of functions needed to wrap the fortran module |
37 |
+ |
|
38 |
+ |
extern "C" { |
39 |
+ |
void forcefactory_( char* forceName, |
40 |
+ |
int* status, |
41 |
+ |
void (*wrapFunction)( void (*p1)( int* ident, |
42 |
+ |
double* mass, |
43 |
+ |
double* epslon, |
44 |
+ |
double* sigma, |
45 |
+ |
int* status ), |
46 |
+ |
void (*p2)( void ), |
47 |
+ |
void (*p3)( double* positionArray, |
48 |
+ |
double* forceArray, |
49 |
+ |
double* potentialEnergy, |
50 |
+ |
short int* doPotentialCalc )), |
51 |
+ |
int forceNameLength ); |
52 |
+ |
} |
53 |
+ |
|
54 |
+ |
|
55 |
+ |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
56 |
+ |
double* sigma, int* status ), |
57 |
+ |
void (*p2)( void ), |
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)( void ); |
66 |
+ |
|
67 |
+ |
LJ_FF* currentLJwrap; |
68 |
+ |
|
69 |
+ |
|
70 |
+ |
//**************************************************************** |
71 |
+ |
// begins the actual forcefield stuff. |
72 |
+ |
//**************************************************************** |
73 |
+ |
|
74 |
|
LJ_FF::LJ_FF(){ |
75 |
|
|
76 |
|
char fileName[200]; |
79 |
|
char temp[200]; |
80 |
|
char errMsg[1000]; |
81 |
|
|
82 |
+ |
// do the funtion wrapping |
83 |
+ |
currentLJwrap = this; |
84 |
+ |
wrapMe(); |
85 |
+ |
|
86 |
|
#ifdef IS_MPI |
87 |
|
int i; |
88 |
|
|
179 |
|
#endif // is_mpi |
180 |
|
} |
181 |
|
|
182 |
+ |
|
183 |
+ |
void LJ_FF::wrapMe( void ){ |
184 |
+ |
|
185 |
+ |
char* currentFF = "LJ"; |
186 |
+ |
int isError = 0; |
187 |
+ |
|
188 |
+ |
forcefactory_( currentFF, &isError, LJfunctionWrapper, strlen(currentFF) ); |
189 |
+ |
|
190 |
+ |
if( isError ){ |
191 |
+ |
|
192 |
+ |
sprintf( painCave.errMsg, |
193 |
+ |
"LJ_FF error: an error was returned from fortran when the " |
194 |
+ |
"the functions were being wrapped.\n" ); |
195 |
+ |
painCave.isFatal = 1; |
196 |
+ |
simError(); |
197 |
+ |
} |
198 |
+ |
|
199 |
+ |
#ifdef IS_MPI |
200 |
+ |
sprintf( checkPointMsg, "LJ_FF functions succesfully wrapped." ); |
201 |
+ |
MPIcheckPoint(); |
202 |
+ |
#endif // is_mpi |
203 |
+ |
} |
204 |
+ |
|
205 |
+ |
|
206 |
+ |
void LJfunctionWrapper( void (*p1)( int* ident, double* mass, double* epslon, |
207 |
+ |
double* sigma, int* status ), |
208 |
+ |
void (*p2)( void ), |
209 |
+ |
void (*p3)( double* positionArray,double* forceArray, |
210 |
+ |
double* potentialEnergy, |
211 |
+ |
short int* doPotentialCalc ) ){ |
212 |
+ |
|
213 |
+ |
|
214 |
+ |
p1 = newLJtype; |
215 |
+ |
p2 = initLJfortran; |
216 |
+ |
this->setLJfortran( p3 ); |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
|
220 |
+ |
|
221 |
|
void LJ_FF::initializeAtoms( void ){ |
222 |
|
|
223 |
|
class LinkedType { |
376 |
|
} |
377 |
|
#endif // is_mpi |
378 |
|
|
379 |
+ |
// call new A_types in fortran |
380 |
|
|
381 |
+ |
int isError; |
382 |
+ |
currentAtomType = headAtomType; |
383 |
+ |
while( currentAtomType != NULL ){ |
384 |
+ |
|
385 |
+ |
if( currentAtomType->name[0] != NULL ){ |
386 |
+ |
isError = 0; |
387 |
+ |
newLJtype( &(currentAtomType->ident), |
388 |
+ |
&(currentAtomType->mass), |
389 |
+ |
&(currentAtomType->epslon), |
390 |
+ |
&(currentAtomType->sigma), |
391 |
+ |
isError ); |
392 |
+ |
if( isError ){ |
393 |
+ |
sprintf( painCave.errMsg, |
394 |
+ |
"Error initializing the \"%s\" atom type in fortran\n", |
395 |
+ |
currentAtomType->name ); |
396 |
+ |
painCave.isFatal = 1; |
397 |
+ |
simError(); |
398 |
+ |
} |
399 |
+ |
} |
400 |
+ |
currentAtomType = currentAtomType->next; |
401 |
+ |
} |
402 |
+ |
|
403 |
+ |
#ifdef IS_MPI |
404 |
+ |
sprintf( checkPointMsg, |
405 |
+ |
"LJ_FF atom structures successfully sent to fortran\n" ); |
406 |
+ |
MPIcheckPoint(); |
407 |
+ |
#endif // is_mpi |
408 |
+ |
|
409 |
+ |
|
410 |
+ |
|
411 |
|
// initialize the atoms |
412 |
|
|
413 |
|
Atom* thisAtom; |
581 |
|
} |
582 |
|
else return 0; |
583 |
|
} |
584 |
+ |
|
585 |
+ |
|
586 |
+ |
void LJ_FF::doForces( void ){ |
587 |
+ |
|
588 |
+ |
int i; |
589 |
+ |
double* frc; |
590 |
+ |
double* pos; |
591 |
+ |
double potE; |
592 |
+ |
short int calcPot = 0; |
593 |
+ |
|
594 |
+ |
// forces are zeroed here, before any are acumulated. |
595 |
+ |
// NOTE: do not rezero the forces in Fortran. |
596 |
+ |
|
597 |
+ |
for(i=0; i<entry_plug->n_atoms; i++){ |
598 |
+ |
entry_plug->atoms[i]->zeroForces(); |
599 |
+ |
} |
600 |
+ |
|
601 |
+ |
frc = Atom::getFrcArray(); |
602 |
+ |
pos = Atom::getPosArray(); |
603 |
+ |
|
604 |
+ |
doLJfortran( pos, frc, potE, calcPot ); |
605 |
+ |
} |
606 |
+ |
|