1 |
#include <cstdlib> |
2 |
|
3 |
#ifdef IS_MPI |
4 |
#include <mpi.h> |
5 |
#endif // is_mpi |
6 |
|
7 |
|
8 |
#include "simError.h" |
9 |
#include "ForceFields.hpp" |
10 |
#include "Atom.hpp" |
11 |
#include "fortranWrappers.hpp" |
12 |
|
13 |
|
14 |
void ForceFields::calcRcut( void ){ |
15 |
|
16 |
#ifdef IS_MPI |
17 |
double tempBig = bigSigma; |
18 |
MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX ); |
19 |
#endif //is_mpi |
20 |
|
21 |
//calc rCut and rList |
22 |
|
23 |
entry_plug->rCut = 2.5 bigSigma; |
24 |
if(entry_plug->rCut > (entry_plug->box_x / 2.0)) |
25 |
entry_plug->rCut = entry_plug->box_x / 2.0; |
26 |
if(entry_plug->rCut > (entry_plug->box_y / 2.0)) |
27 |
entry_plug->rCut = entry_plug->box_y / 2.0; |
28 |
if(entry_plug->rCut > (entry_plug->box_z / 2.0)) |
29 |
entry_plug->rCut = entry_plug->box_z / 2.0; |
30 |
|
31 |
entry_plug->rList = entry_plug->rCut + 1.0; |
32 |
|
33 |
} |
34 |
|
35 |
void ForceFields::doForces( int calcPot, int calcStress ){ |
36 |
|
37 |
int i, isError; |
38 |
double* frc; |
39 |
double* pos; |
40 |
double* trq; |
41 |
double* tau; |
42 |
double* A; |
43 |
double* u_l; |
44 |
|
45 |
short int passedCalcPot = (short int)calcPot; |
46 |
short int passedCalcStress = (short int)calcStress; |
47 |
|
48 |
// forces are zeroed here, before any are acumulated. |
49 |
// NOTE: do not rezero the forces in Fortran. |
50 |
|
51 |
for(i=0; i<entry_plug->n_atoms; i++){ |
52 |
entry_plug->atoms[i]->zeroForces(); |
53 |
} |
54 |
|
55 |
for(i=0; i<entry_plug->n_SRI; i++ ){ |
56 |
entry_plug->sr_interactions[i]->calc_forces(); |
57 |
} |
58 |
|
59 |
frc = Atom::getFrcArray(); |
60 |
pos = Atom::getPosArray(); |
61 |
trq = Atom::getTrqArray(); |
62 |
A = Atom::getAmatArray(); |
63 |
u_l = Atom::getUlArray(); |
64 |
|
65 |
tau = entry_plug->tau; |
66 |
|
67 |
isError = 0; |
68 |
entry_plug->lrPot = 0.0; |
69 |
|
70 |
|
71 |
fortranForceLoop( pos, |
72 |
A, |
73 |
u_l, |
74 |
frc, |
75 |
trq, |
76 |
tau, |
77 |
&(entry_plug->lrPot), |
78 |
&passedCalcPot, |
79 |
&passedCalcStress, |
80 |
&isError ); |
81 |
|
82 |
|
83 |
if( isError ){ |
84 |
sprintf( painCave.errMsg, |
85 |
"Error returned from the fortran force calculation.\n" ); |
86 |
painCave.isFatal = 1; |
87 |
simError(); |
88 |
} |
89 |
|
90 |
#ifdef IS_MPI |
91 |
sprintf( checkPointMsg, |
92 |
"returned from the force calculation.\n" ); |
93 |
MPIcheckPoint(); |
94 |
#endif // is_mpi |
95 |
|
96 |
} |
97 |
|
98 |
|
99 |
void ForceFields::initFortran(int ljMixPolicy, int useReactionField ){ |
100 |
|
101 |
int isError; |
102 |
|
103 |
isError = 0; |
104 |
initFortranFF( &ljMixPolicy, &useReactionField, &isError ); |
105 |
|
106 |
if(isError){ |
107 |
sprintf( painCave.errMsg, |
108 |
"ForceField error: There was an error initializing the forceField in fortran.\n" ); |
109 |
painCave.isFatal = 1; |
110 |
simError(); |
111 |
} |
112 |
|
113 |
|
114 |
#ifdef IS_MPI |
115 |
sprintf( checkPointMsg, "ForceField successfully initialized the fortran component list.\n" ); |
116 |
MPIcheckPoint(); |
117 |
#endif // is_mpi |
118 |
|
119 |
} |