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