1 |
< |
#include <cstdlib> |
1 |
> |
#include <iostream> |
2 |
|
|
3 |
+ |
using namespace std; |
4 |
+ |
|
5 |
+ |
|
6 |
+ |
#include <stdlib.h> |
7 |
+ |
|
8 |
|
#ifdef IS_MPI |
9 |
|
#include <mpi.h> |
10 |
|
#endif // is_mpi |
11 |
|
|
12 |
|
|
13 |
+ |
#ifdef PROFILE |
14 |
+ |
#include "mdProfile.hpp" |
15 |
+ |
#endif |
16 |
+ |
|
17 |
|
#include "simError.h" |
18 |
|
#include "ForceFields.hpp" |
19 |
|
#include "Atom.hpp" |
30 |
|
|
31 |
|
//calc rCut and rList |
32 |
|
|
33 |
< |
entry_plug->rCut = 2.5 * bigSigma; |
34 |
< |
if(entry_plug->rCut > (entry_plug->box_x / 2.0)) |
35 |
< |
entry_plug->rCut = entry_plug->box_x / 2.0; |
36 |
< |
if(entry_plug->rCut > (entry_plug->box_y / 2.0)) |
37 |
< |
entry_plug->rCut = entry_plug->box_y / 2.0; |
29 |
< |
if(entry_plug->rCut > (entry_plug->box_z / 2.0)) |
30 |
< |
entry_plug->rCut = entry_plug->box_z / 2.0; |
33 |
> |
entry_plug->setDefaultRcut( 2.5 * bigSigma ); |
34 |
> |
|
35 |
> |
} |
36 |
> |
|
37 |
> |
void ForceFields::setRcut( double LJrcut ) { |
38 |
|
|
39 |
< |
entry_plug->rList = entry_plug->rCut + 1.0; |
39 |
> |
#ifdef IS_MPI |
40 |
> |
double tempBig = bigSigma; |
41 |
> |
MPI_Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX, |
42 |
> |
MPI_COMM_WORLD); |
43 |
> |
#endif //is_mpi |
44 |
|
|
45 |
+ |
if (LJrcut < 2.5 * bigSigma) { |
46 |
+ |
sprintf( painCave.errMsg, |
47 |
+ |
"Setting Lennard-Jones cutoff radius to %lf.\n" |
48 |
+ |
"\tThis value is smaller than %lf, which is\n" |
49 |
+ |
"\t2.5 * bigSigma, where bigSigma is the largest\n" |
50 |
+ |
"\tvalue of sigma present in the simulation.\n" |
51 |
+ |
"\tThis is potentially a problem since the LJ potential may\n" |
52 |
+ |
"\tbe appreciable at this distance. If you don't want the\n" |
53 |
+ |
"\tsmaller cutoff, change the LJrcut variable.\n", |
54 |
+ |
LJrcut, 2.5*bigSigma); |
55 |
+ |
painCave.isFatal = 0; |
56 |
+ |
simError(); |
57 |
+ |
} else { |
58 |
+ |
sprintf( painCave.errMsg, |
59 |
+ |
"Setting Lennard-Jones cutoff radius to %lf.\n" |
60 |
+ |
"\tThis value is larger than %lf, which is\n" |
61 |
+ |
"\t2.5 * bigSigma, where bigSigma is the largest\n" |
62 |
+ |
"\tvalue of sigma present in the simulation. This should\n" |
63 |
+ |
"\tnot be a problem, but could adversely effect performance.\n", |
64 |
+ |
LJrcut, 2.5*bigSigma); |
65 |
+ |
painCave.isFatal = 0; |
66 |
+ |
simError(); |
67 |
+ |
} |
68 |
+ |
|
69 |
+ |
//calc rCut and rList |
70 |
+ |
|
71 |
+ |
entry_plug->setDefaultRcut( LJrcut ); |
72 |
|
} |
73 |
|
|
74 |
|
void ForceFields::doForces( int calcPot, int calcStress ){ |
75 |
|
|
76 |
< |
int i, isError; |
76 |
> |
int i, j, isError; |
77 |
|
double* frc; |
78 |
|
double* pos; |
79 |
|
double* trq; |
42 |
– |
double* tau; |
80 |
|
double* A; |
81 |
< |
double* u_l;; |
82 |
< |
DirectionalAtom* dAtom; |
81 |
> |
double* u_l; |
82 |
> |
double* rc; |
83 |
> |
double* massRatio; |
84 |
> |
double factor; |
85 |
> |
SimState* config; |
86 |
|
|
87 |
< |
double ut[3]; |
88 |
< |
|
89 |
< |
//u_l = new double[entry_plug->n_atoms]; |
90 |
< |
|
87 |
> |
Molecule* myMols; |
88 |
> |
Atom** myAtoms; |
89 |
> |
int numAtom; |
90 |
> |
int curIndex; |
91 |
> |
double mtot; |
92 |
> |
int numMol; |
93 |
> |
int numCutoffGroups; |
94 |
> |
CutoffGroup* myCutoffGroup; |
95 |
> |
vector<CutoffGroup*>::iterator iterCutoff; |
96 |
> |
double com[3]; |
97 |
> |
vector<double> rcGroup; |
98 |
> |
|
99 |
|
short int passedCalcPot = (short int)calcPot; |
100 |
|
short int passedCalcStress = (short int)calcStress; |
101 |
|
|
102 |
< |
// forces are zeroed here, before any are acumulated. |
102 |
> |
// forces are zeroed here, before any are accumulated. |
103 |
|
// NOTE: do not rezero the forces in Fortran. |
104 |
|
|
57 |
– |
|
105 |
|
for(i=0; i<entry_plug->n_atoms; i++){ |
106 |
< |
entry_plug->atoms[i]->zeroForces(); |
60 |
< |
|
61 |
< |
// if( entry_plug->atoms[i]->isDirectional() ){ |
62 |
< |
// dAtom = (DirectionalAtom *)entry_plug->atoms[i]; |
63 |
< |
// dAtom->getU(ut); |
64 |
< |
|
65 |
< |
|
66 |
< |
// if(dAtom->getIndex()== 1){ |
67 |
< |
// std::cerr << "atom 2's u_l = " << ut[0] << ", " << ut[1] |
68 |
< |
// << ", " << ut[2] << "\n"; |
69 |
< |
// } |
70 |
< |
// } |
71 |
< |
|
106 |
> |
entry_plug->atoms[i]->zeroForces(); |
107 |
|
} |
108 |
|
|
109 |
+ |
#ifdef PROFILE |
110 |
+ |
startProfile(pro7); |
111 |
+ |
#endif |
112 |
+ |
|
113 |
|
for(i=0; i<entry_plug->n_mol; i++ ){ |
114 |
< |
entry_plug->molecules[i].calcForces(); |
114 |
> |
// CalcForces in molecules takes care of mapping rigid body coordinates |
115 |
> |
// into atomic coordinates |
116 |
> |
entry_plug->molecules[i].calcForces(); |
117 |
|
} |
118 |
|
|
119 |
< |
frc = Atom::getFrcArray(); |
120 |
< |
pos = Atom::getPosArray(); |
121 |
< |
trq = Atom::getTrqArray(); |
81 |
< |
A = Atom::getAmatArray(); |
82 |
< |
u_l = Atom::getUlArray(); |
83 |
< |
tau = entry_plug->tau; |
119 |
> |
#ifdef PROFILE |
120 |
> |
endProfile( pro7 ); |
121 |
> |
#endif |
122 |
|
|
123 |
+ |
config = entry_plug->getConfiguration(); |
124 |
|
|
125 |
+ |
frc = config->getFrcArray(); |
126 |
+ |
pos = config->getPosArray(); |
127 |
+ |
trq = config->getTrqArray(); |
128 |
+ |
A = config->getAmatArray(); |
129 |
+ |
u_l = config->getUlArray(); |
130 |
+ |
|
131 |
+ |
if(entry_plug->haveCutoffGroups){ |
132 |
+ |
myMols = entry_plug->molecules; |
133 |
+ |
numMol = entry_plug->n_mol; |
134 |
+ |
for(int i = 0; i < numMol; i++){ |
135 |
+ |
|
136 |
+ |
numCutoffGroups = myMols[i].getNCutoffGroups(); |
137 |
+ |
for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); myCutoffGroup != NULL; |
138 |
+ |
myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){ |
139 |
+ |
//get center of mass of the cutoff group |
140 |
+ |
myCutoffGroup->getCOM(com); |
141 |
+ |
|
142 |
+ |
rcGroup.push_back(com[0]); |
143 |
+ |
rcGroup.push_back(com[1]); |
144 |
+ |
rcGroup.push_back(com[2]); |
145 |
+ |
|
146 |
+ |
}// end for(myCutoffGroup) |
147 |
+ |
|
148 |
+ |
}//end for(int i = 0) |
149 |
+ |
|
150 |
+ |
rc = &rcGroup[0]; |
151 |
+ |
} |
152 |
+ |
else{ |
153 |
+ |
// center of mass of the group is the same as position of the atom if cutoff group does not exist |
154 |
+ |
rc = pos; |
155 |
+ |
} |
156 |
+ |
|
157 |
+ |
|
158 |
+ |
|
159 |
|
isError = 0; |
160 |
|
entry_plug->lrPot = 0.0; |
88 |
– |
tau[0] = 0.0; |
89 |
– |
tau[1] = 0.0; |
90 |
– |
tau[2] = 0.0; |
91 |
– |
|
161 |
|
|
162 |
+ |
for (i=0; i<9; i++) { |
163 |
+ |
entry_plug->tau[i] = 0.0; |
164 |
+ |
} |
165 |
|
|
166 |
< |
|
166 |
> |
|
167 |
> |
#ifdef PROFILE |
168 |
> |
startProfile(pro8); |
169 |
> |
#endif |
170 |
> |
|
171 |
|
fortranForceLoop( pos, |
172 |
+ |
rc, |
173 |
|
A, |
174 |
|
u_l, |
175 |
|
frc, |
176 |
|
trq, |
177 |
< |
tau, |
177 |
> |
entry_plug->tau, |
178 |
|
&(entry_plug->lrPot), |
179 |
|
&passedCalcPot, |
180 |
|
&passedCalcStress, |
181 |
|
&isError ); |
182 |
|
|
183 |
|
|
184 |
< |
// delete[] u_l; |
184 |
> |
#ifdef PROFILE |
185 |
> |
endProfile(pro8); |
186 |
> |
#endif |
187 |
|
|
188 |
+ |
|
189 |
|
if( isError ){ |
190 |
|
sprintf( painCave.errMsg, |
191 |
|
"Error returned from the fortran force calculation.\n" ); |
193 |
|
simError(); |
194 |
|
} |
195 |
|
|
196 |
+ |
for(i=0; i<entry_plug->n_mol; i++ ){ |
197 |
+ |
entry_plug->molecules[i].atoms2rigidBodies(); |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
|
201 |
+ |
if (entry_plug->useSolidThermInt && !entry_plug->useLiquidThermInt) { |
202 |
+ |
|
203 |
+ |
factor = pow(entry_plug->thermIntLambda, entry_plug->thermIntK); |
204 |
+ |
for (i=0; i < entry_plug->integrableObjects.size(); i++) { |
205 |
+ |
for (j=0; j< 3; j++) |
206 |
+ |
frc[3*i + j] *= factor; |
207 |
+ |
if (entry_plug->integrableObjects[i]->isDirectional()) { |
208 |
+ |
for (j=0; j< 3; j++) |
209 |
+ |
trq[3*i + j] *= factor; |
210 |
+ |
} |
211 |
+ |
} |
212 |
+ |
entry_plug->vRaw = entry_plug->lrPot; |
213 |
+ |
entry_plug->lrPot *= factor; |
214 |
+ |
entry_plug->lrPot += entry_plug->restraint->Calc_Restraint_Forces(entry_plug->integrableObjects); |
215 |
+ |
entry_plug->vHarm = entry_plug->restraint->getVharm(); |
216 |
+ |
} |
217 |
+ |
|
218 |
+ |
if (entry_plug->useLiquidThermInt) { |
219 |
+ |
|
220 |
+ |
factor = pow(entry_plug->thermIntLambda, entry_plug->thermIntK); |
221 |
+ |
for (i=0; i < entry_plug->integrableObjects.size(); i++) { |
222 |
+ |
for (j=0; j< 3; j++) |
223 |
+ |
frc[3*i + j] *= factor; |
224 |
+ |
if (entry_plug->integrableObjects[i]->isDirectional()) { |
225 |
+ |
for (j=0; j< 3; j++) |
226 |
+ |
trq[3*i + j] *= factor; |
227 |
+ |
} |
228 |
+ |
} |
229 |
+ |
entry_plug->vRaw = entry_plug->lrPot; |
230 |
+ |
entry_plug->lrPot *= factor; |
231 |
+ |
entry_plug->lrPot += entry_plug->restraint->Calc_Restraint_Forces(entry_plug->integrableObjects); |
232 |
+ |
entry_plug->vHarm = entry_plug->restraint->getVharm(); |
233 |
+ |
} |
234 |
+ |
|
235 |
|
#ifdef IS_MPI |
236 |
|
sprintf( checkPointMsg, |
237 |
|
"returned from the force calculation.\n" ); |
238 |
|
MPIcheckPoint(); |
239 |
|
#endif // is_mpi |
240 |
+ |
|
241 |
|
|
242 |
|
} |
243 |
|
|
263 |
|
#endif // is_mpi |
264 |
|
|
265 |
|
} |
266 |
+ |
|
267 |
+ |
|
268 |
+ |
void ForceFields::initRestraints(){ |
269 |
+ |
int i; |
270 |
+ |
// store the initial info. |
271 |
+ |
// set the omega values to zero |
272 |
+ |
for (i=0; i<entry_plug->integrableObjects.size(); i++) |
273 |
+ |
entry_plug->integrableObjects[i]->setZangle( 0.0 ); |
274 |
+ |
|
275 |
+ |
entry_plug->restraint->Store_Init_Info(entry_plug->integrableObjects); |
276 |
+ |
|
277 |
+ |
} |
278 |
+ |
|
279 |
+ |
void ForceFields::dumpzAngle(){ |
280 |
+ |
|
281 |
+ |
// store the initial info. |
282 |
+ |
entry_plug->restraint->Write_zAngle_File(entry_plug->integrableObjects); |
283 |
+ |
|
284 |
+ |
} |