ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ForceFields.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/ForceFields.cpp (file contents):
Revision 423 by mmeineke, Thu Mar 27 20:12:15 2003 UTC vs.
Revision 1157 by tim, Tue May 11 20:33:41 2004 UTC

# Line 1 | Line 1
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"
# Line 15 | Line 24 | void ForceFields::calcRcut( void ){
24  
25   #ifdef IS_MPI
26    double tempBig = bigSigma;
27 <  MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX );
27 >  MPI_Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX,
28 >                 MPI_COMM_WORLD);
29   #endif  //is_mpi
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;
28 <  if(entry_plug->rCut > (entry_plug->box_z / 2.0))
29 <    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;
41  double* tau;
80    double* A;
81    double* u_l;
82 +  double* rc;
83 +  double* massRatio;
84 +  SimState* config;
85  
86 +  Molecule* myMols;
87 +  Atom** myAtoms;
88 +  int numAtom;
89 +  int curIndex;
90 +  double mtot;
91 +  int numMol;
92 +  int numCutoffGroups;
93 +  CutoffGroup* myCutoffGroup;
94 +  vector<CutoffGroup*>::iterator iterCutoff;
95 +  Atom* cutoffAtom;
96 +  vector<Atom*>::iterator iterAtom;  
97 +  double com[3];
98 +  double tempPos[3];
99 +  int atomIndex;
100 +  
101    short int passedCalcPot = (short int)calcPot;
102    short int passedCalcStress = (short int)calcStress;
103  
104 <  // forces are zeroed here, before any are acumulated.
104 >  // forces are zeroed here, before any are accumulated.
105    // NOTE: do not rezero the forces in Fortran.
106  
107    for(i=0; i<entry_plug->n_atoms; i++){
108 <    entry_plug->atoms[i]->zeroForces();
108 >    entry_plug->atoms[i]->zeroForces();    
109    }
110  
111 + #ifdef PROFILE
112 +  startProfile(pro7);
113 + #endif
114 +  
115    for(i=0; i<entry_plug->n_mol; i++ ){
116 <    entry_plug->molecules[i]->calc_forces();
116 >    // CalcForces in molecules takes care of mapping rigid body coordinates
117 >    // into atomic coordinates
118 >    entry_plug->molecules[i].calcForces();    
119    }
120  
121 <  frc = Atom::getFrcArray();
122 <  pos = Atom::getPosArray();
123 <  trq = Atom::getTrqArray();
62 <  A   = Atom::getAmatArray();
63 <  u_l = Atom::getUlArray();
121 > #ifdef PROFILE
122 >  endProfile( pro7 );
123 > #endif
124  
125 <  tau = entry_plug->tau;
126 <    
125 >  config = entry_plug->getConfiguration();
126 >  
127 >  frc = config->getFrcArray();
128 >  pos = config->getPosArray();
129 >  trq = config->getTrqArray();
130 >  A   = config->getAmatArray();
131 >  u_l = config->getUlArray();
132 >
133 >  if(entry_plug->haveCutoffGroups){
134 >    //if
135 >    myMols = entry_plug->molecules;
136 >    numMol = entry_plug->n_mol;
137 >    for(int i  = 0; i < numMol; i++){
138 >      numAtom = myMols[i].getNAtoms();
139 >      myAtoms = myMols[i].getMyAtoms();
140 >
141 >      
142 >      for(int j = 0; j < numAtom; j++){
143 > #ifdef IS_MPI
144 >        atomIndex = myAtoms[j]->getGlobalIndex();
145 > #else
146 >        atomIndex = myAtoms[j]->getIndex();
147 > #endif
148 >
149 >        if(myMols[i].belongToCutoffGroup(atomIndex))
150 >          continue;
151 >        else{
152 >          myAtoms[j]->getPos(tempPos);
153 >          myAtoms[j]->setRc(tempPos);
154 >        }
155 >          
156 >      }
157 >        
158 >      numCutoffGroups = myMols[i].getNCutoffGroups();
159 >      for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); myCutoffGroup != NULL;
160 >                                                    myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){
161 >        //get center of mass of the cutoff group
162 >        myCutoffGroup->getCOM(com);
163 >
164 >        for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom); cutoffAtom != NULL;
165 >                                             cutoffAtom = myCutoffGroup->beginAtom(iterAtom)){
166 >          cutoffAtom->setRc(com);
167 >        }  
168 >                                
169 >      }// end for(myCutoffGroup)
170 >      
171 >    }//end for(int i = 0)
172 >
173 >    rc = config->getRcArray();
174 >  }
175 >  else{
176 >    // center of mass of the group is the same as position of the atom  if cutoff group does not exist
177 >    rc = pos;
178 >  }
179 >  
180 >
181 >
182    isError = 0;
183    entry_plug->lrPot = 0.0;
184  
185 <  
185 >  for (i=0; i<9; i++) {
186 >    entry_plug->tau[i] = 0.0;
187 >  }
188 >
189 >
190 > #ifdef PROFILE
191 >  startProfile(pro8);
192 > #endif
193 >
194    fortranForceLoop( pos,
195 +                    rc,
196                      A,
197                      u_l,
198                      frc,
199                      trq,
200 <                    tau,
200 >                    entry_plug->tau,
201                      &(entry_plug->lrPot),
202                      &passedCalcPot,
203                      &passedCalcStress,
204                      &isError );
205  
206  
207 + #ifdef PROFILE
208 +  endProfile(pro8);
209 + #endif
210 +
211 +
212    if( isError ){
213      sprintf( painCave.errMsg,
214               "Error returned from the fortran force calculation.\n" );
# Line 87 | Line 216 | void ForceFields::doForces( int calcPot, int calcStres
216      simError();
217    }
218  
219 +  for(i=0; i<entry_plug->n_mol; i++ ){
220 +    entry_plug->molecules[i].atoms2rigidBodies();
221 +  }
222 +
223 +
224   #ifdef IS_MPI
225    sprintf( checkPointMsg,
226             "returned from the force calculation.\n" );
227    MPIcheckPoint();
228   #endif // is_mpi
229 +  
230  
231   }
232  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines