ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/nonbonded/LJ.cpp
(Generate patch)

Comparing trunk/src/nonbonded/LJ.cpp (file contents):
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 2069 by gezelter, Thu Mar 5 16:30:23 2015 UTC

# Line 80 | Line 80 | namespace OpenMD {
80    }
81  
82    void LJ::initialize() {    
83    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
84    ForceField::AtomTypeContainer::MapTypeIterator i;
85    AtomType* at;
83  
84 <    for (at = atomTypes->beginType(i); at != NULL;
85 <         at = atomTypes->nextType(i)) {
86 <      LennardJonesAdapter lja = LennardJonesAdapter(at);
87 <      if (lja.isLennardJones()){
88 <         addType(at);
89 <      }
84 >    LJtypes.clear();
85 >    LJtids.clear();
86 >    MixingMap.clear();
87 >    nLJ_ = 0;
88 >
89 >    LJtids.resize( forceField_->getNAtomType(), -1);
90 >
91 >    set<AtomType*>::iterator at;
92 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
93 >      if ((*at)->isLennardJones()) nLJ_++;
94      }
95 +
96 +    MixingMap.resize(nLJ_);
97 +
98 +    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
99 +      if ((*at)->isLennardJones()) addType(*at);      
100 +    }
101 +
102      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
103      ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
104      NonBondedInteractionType* nbt;
105      ForceField::NonBondedInteractionTypeContainer::KeyType keys;
106  
99
107      for (nbt = nbiTypes->beginType(j); nbt != NULL;
108           nbt = nbiTypes->nextType(j)) {
109  
# Line 125 | Line 132 | namespace OpenMD {
132      }  
133      initialized_ = true;
134    }
128      
135  
136  
137    void LJ::addType(AtomType* atomType){
138      LennardJonesAdapter lja1 = LennardJonesAdapter(atomType);
133
134    RealType sigma1 = lja1.getSigma();
135    RealType epsilon1 = lja1.getEpsilon();
139      
140      // add it to the map:
141 <
142 <    pair<map<int,AtomType*>::iterator,bool> ret;    
143 <    ret = LJMap.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) );
141 >    int atid = atomType->getIdent();
142 >    int ljtid = LJtypes.size();
143 >  
144 >    pair<set<int>::iterator,bool> ret;    
145 >    ret = LJtypes.insert( atid );
146      if (ret.second == false) {
147        sprintf( painCave.errMsg,
148                 "LJ already had a previous entry with ident %d\n",
149 <               atomType->getIdent());
149 >               atid) ;
150        painCave.severity = OPENMD_INFO;
151        painCave.isFatal = 0;
152        simError();        
153      }
154 <    
154 >
155 >    LJtids[atid] = ljtid;
156 >    MixingMap[ljtid].resize( nLJ_ );
157 >
158      // Now, iterate over all known types and add to the mixing map:
159      
160 <    std::map<int, AtomType*>::iterator it;
161 <    for( it = LJMap.begin(); it != LJMap.end(); ++it) {
154 <      
155 <      AtomType* atype2 = (*it).second;
160 >    std::set<int>::iterator it;
161 >    for( it = LJtypes.begin(); it != LJtypes.end(); ++it) {
162  
163 +      int ljtid2 = LJtids[ (*it) ];
164 +      AtomType* atype2 = forceField_->getAtomType( (*it) );
165 +
166        LJInteractionData mixer;
167        mixer.sigma = getSigma(atomType, atype2);
168        mixer.epsilon = getEpsilon(atomType, atype2);
169        mixer.sigmai = 1.0 / mixer.sigma;
170        mixer.explicitlySet = false;
171 +      MixingMap[ljtid2].resize( nLJ_ );
172  
173 <      std::pair<AtomType*, AtomType*> key1, key2;
174 <      key1 = std::make_pair(atomType, atype2);
175 <      key2 = std::make_pair(atype2, atomType);
166 <      
167 <      MixingMap[key1] = mixer;
168 <      if (key2 != key1) {
169 <        MixingMap[key2] = mixer;
173 >      MixingMap[ljtid][ljtid2] = mixer;
174 >      if (ljtid2 != ljtid) {
175 >        MixingMap[ljtid2][ljtid] = mixer;
176        }
177      }      
178    }
# Line 179 | Line 185 | namespace OpenMD {
185      mixer.sigmai = 1.0 / mixer.sigma;
186      mixer.explicitlySet = true;
187  
188 <    std::pair<AtomType*, AtomType*> key1, key2;
189 <    key1 = std::make_pair(atype1, atype2);
190 <    key2 = std::make_pair(atype2, atype1);
188 >    int atid1 = atype1->getIdent();
189 >    int atid2 = atype2->getIdent();
190 >
191 >    int ljtid1, ljtid2;
192 >
193 >    pair<set<int>::iterator,bool> ret;    
194 >    ret = LJtypes.insert( atid1 );
195 >    if (ret.second == false) {
196 >      // already had this type in the LJMap, just get the ljtid:
197 >      ljtid1 = LJtids[ atid1 ];
198 >    } else {
199 >      // didn't already have it, so make a new one and assign it:
200 >      ljtid1 = nLJ_;
201 >      LJtids[atid1] = nLJ_;
202 >      nLJ_++;
203 >    }
204 >
205 >    ret = LJtypes.insert( atid2 );
206 >    if (ret.second == false) {
207 >      // already had this type in the LJMap, just get the ljtid:
208 >      ljtid2 = LJtids[ atid2 ];
209 >    } else {
210 >      // didn't already have it, so make a new one and assign it:
211 >      ljtid2 = nLJ_;
212 >      LJtids[atid2] = nLJ_;
213 >      nLJ_++;
214 >    }
215      
216 <    MixingMap[key1] = mixer;
217 <    if (key2 != key1) {
218 <      MixingMap[key2] = mixer;
216 >    MixingMap.resize(nLJ_);
217 >    MixingMap[ljtid1].resize(nLJ_);
218 >
219 >    MixingMap[ljtid1][ljtid2] = mixer;
220 >    if (ljtid2 != ljtid1) {
221 >      MixingMap[ljtid2].resize(nLJ_);
222 >      MixingMap[ljtid2][ljtid1] = mixer;
223      }    
224    }
225  
226    void LJ::calcForce(InteractionData &idat) {
227      if (!initialized_) initialize();
194    map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it;
195    it = MixingMap.find( idat.atypes );
228      
229 <    if (it != MixingMap.end())  {
198 <      
199 <      LJInteractionData mixer = (*it).second;
200 <      
201 <      RealType sigmai = mixer.sigmai;
202 <      RealType epsilon = mixer.epsilon;
203 <      
204 <      RealType ros;
205 <      RealType rcos;
206 <      RealType myPot = 0.0;
207 <      RealType myPotC = 0.0;
208 <      RealType myDeriv = 0.0;
209 <      RealType myDerivC = 0.0;
210 <    
211 <      ros = *(idat.rij) * sigmai;    
212 <      
213 <      getLJfunc(ros, myPot, myDeriv);
214 <      
215 <      if (idat.shiftedPot) {
216 <        rcos = *(idat.rcut) * sigmai;
217 <        getLJfunc(rcos, myPotC, myDerivC);
218 <        myDerivC = 0.0;
219 <      } else if (idat.shiftedForce) {
220 <        rcos = *(idat.rcut) * sigmai;
221 <        getLJfunc(rcos, myPotC, myDerivC);
222 <        myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
223 <      } else {
224 <        myPotC = 0.0;
225 <        myDerivC = 0.0;        
226 <      }
229 >    LJInteractionData &mixer = MixingMap[LJtids[idat.atid1]][LJtids[idat.atid2]];
230  
231 <      RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
232 <      *(idat.vpair) += pot_temp;
233 <      
234 <      RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
235 <                                                                myDerivC)*sigmai;      
236 <
237 <      (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
238 <      *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
231 >    RealType sigmai = mixer.sigmai;
232 >    RealType epsilon = mixer.epsilon;
233 >    
234 >    RealType ros;
235 >    RealType rcos;
236 >    RealType myPot = 0.0;
237 >    RealType myPotC = 0.0;
238 >    RealType myDeriv = 0.0;
239 >    RealType myDerivC = 0.0;
240 >    
241 >    ros = *(idat.rij) * sigmai;    
242 >    
243 >    getLJfunc(ros, myPot, myDeriv);
244 >    
245 >    if (idat.shiftedPot) {
246 >      rcos = *(idat.rcut) * sigmai;
247 >      getLJfunc(rcos, myPotC, myDerivC);
248 >      myDerivC = 0.0;
249 >    } else if (idat.shiftedForce) {
250 >      rcos = *(idat.rcut) * sigmai;
251 >      getLJfunc(rcos, myPotC, myDerivC);
252 >      myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
253 >    } else {
254 >      myPotC = 0.0;
255 >      myDerivC = 0.0;        
256      }
257 +    
258 +    RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
259 +    *(idat.vpair) += pot_temp;
260 +    
261 +    RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
262 +                                                              myDerivC)*sigmai;      
263 +    (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
264 +    *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
265 +    
266      return;
267    }
268    
# Line 254 | Line 283 | namespace OpenMD {
283    
284    RealType LJ::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
285      if (!initialized_) initialize();  
286 <    map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it;
287 <    it = MixingMap.find(atypes);
288 <    if (it == MixingMap.end())
289 <      return 0.0;
290 <    else  {
291 <      LJInteractionData mixer = (*it).second;
286 >    
287 >    int atid1 = atypes.first->getIdent();
288 >    int atid2 = atypes.second->getIdent();
289 >    int ljtid1 = LJtids[atid1];
290 >    int ljtid2 = LJtids[atid2];
291 >    
292 >    if (ljtid1 == -1 || ljtid2 == -1) return 0.0;
293 >    else {      
294 >      LJInteractionData mixer = MixingMap[ljtid1][ljtid2];
295        return 2.5 * mixer.sigma;
296      }
297    }
298 <
298 >  
299   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines