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

Comparing trunk/src/nonbonded/SC.cpp (file contents):
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 1895 by gezelter, Mon Jul 1 21:09:37 2013 UTC

# Line 58 | Line 58 | namespace OpenMD {
58      initialized_ = false;
59  
60      MixingMap.clear();
61 <    SCMap.clear();
62 <    SClist.clear();
61 >    SCtypes.clear();
62 >    SCdata.clear();
63 >    SCtids.clear();
64    }
65          
66    RealType SC::getM(AtomType* atomType1, AtomType* atomType2) {    
# Line 102 | Line 103 | namespace OpenMD {
103      return sqrt(epsilon1 * epsilon2);
104    }
105  
106 <  void SC::initialize() {
106 >  void SC::initialize() {      
107      // find all of the SC atom Types:
108 <    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
109 <    ForceField::AtomTypeContainer::MapTypeIterator i;
110 <    AtomType* at;
108 >    SCtypes.clear();
109 >    SCtids.clear();
110 >    SCdata.clear();
111 >    MixingMap.clear();
112 >    nSC_ = 0;
113  
114 <    for (at = atomTypes->beginType(i); at != NULL;
115 <         at = atomTypes->nextType(i)) {
116 <      SuttonChenAdapter sca = SuttonChenAdapter(at);
117 <      if (sca.isSuttonChen())
118 <        addType(at);
119 <    }    
114 >    SCtids.resize( forceField_->getNAtomType(), -1);
115 >
116 >    set<AtomType*>::iterator at;
117 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
118 >      if ((*at)->isSC()) nSC_++;
119 >    }
120 >    SCdata.resize(nSC_);
121 >    MixingMap.resize(nSC_);
122 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
123 >      if ((*at)->isSC()) addType((*at));
124 >    }
125      initialized_ = true;
126    }
127    
# Line 130 | Line 138 | namespace OpenMD {
138      scAtomData.alpha = sca.getAlpha();
139      scAtomData.epsilon = sca.getEpsilon();
140      scAtomData.rCut = 2.0 * scAtomData.alpha;
141 <
141 >
142      // add it to the map:
143 +    int atid = atomType->getIdent();
144 +    int sctid = SCtypes.size();
145  
146 <    pair<map<int,AtomType*>::iterator,bool> ret;    
147 <    ret = SClist.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) );
146 >    pair<set<int>::iterator,bool> ret;    
147 >    ret = SCtypes.insert( atid );
148      if (ret.second == false) {
149        sprintf( painCave.errMsg,
150                 "SC already had a previous entry with ident %d\n",
151 <               atomType->getIdent() );
151 >               atid );
152        painCave.severity = OPENMD_INFO;
153        painCave.isFatal = 0;
154        simError();        
155      }
146
147    SCMap[atomType] = scAtomData;
156      
157 +    SCtids[atid] = sctid;
158 +    SCdata[sctid] = scAtomData;
159 +    MixingMap[sctid].resize(nSC_);
160 +    
161      // Now, iterate over all known types and add to the mixing map:
162      
163 <    map<AtomType*, SCAtomData>::iterator it;
164 <    for( it = SCMap.begin(); it != SCMap.end(); ++it) {
163 >    std::set<int>::iterator it;
164 >    for( it = SCtypes.begin(); it != SCtypes.end(); ++it) {
165        
166 <      AtomType* atype2 = (*it).first;
166 >      int sctid2 = SCtids[ (*it) ];
167 >      AtomType* atype2 = forceField_->getAtomType( (*it) );
168        
169        SCInteractionData mixer;
170  
# Line 190 | Line 203 | namespace OpenMD {
203  
204        mixer.explicitlySet = false;
205  
206 <      pair<AtomType*, AtomType*> key1, key2;
194 <      key1 = make_pair(atomType, atype2);
195 <      key2 = make_pair(atype2, atomType);
206 >      MixingMap[sctid2].resize( nSC_ );
207        
208 <      MixingMap[key1] = mixer;
209 <      if (key2 != key1) {
210 <        MixingMap[key2] = mixer;
208 >      MixingMap[sctid][sctid2] = mixer;
209 >      if (sctid2 != sctid) {
210 >        MixingMap[sctid2][sctid] = mixer;
211        }
212      }      
213      return;
# Line 247 | Line 258 | namespace OpenMD {
258      
259      mixer.explicitlySet = true;
260  
261 <    pair<AtomType*, AtomType*> key1, key2;
262 <    key1 = make_pair(atype1, atype2);
263 <    key2 = make_pair(atype2, atype1);
264 <    
265 <    MixingMap[key1] = mixer;
266 <    if (key2 != key1) {
256 <      MixingMap[key2] = mixer;
261 >    int sctid1 = SCtids[ atype1->getIdent() ];
262 >    int sctid2 = SCtids[ atype2->getIdent() ];
263 >
264 >    MixingMap[sctid1][sctid2] = mixer;
265 >    if (sctid2 != sctid1) {
266 >      MixingMap[sctid2][sctid1] = mixer;
267      }    
268      return;
269    }
# Line 261 | Line 271 | namespace OpenMD {
271    void SC::calcDensity(InteractionData &idat) {
272      
273      if (!initialized_) initialize();
274 +    int sctid1 = SCtids[idat.atid1];
275 +    int sctid2 = SCtids[idat.atid2];
276      
277 <    SCInteractionData mixer = MixingMap[ idat.atypes ];
277 >    SCInteractionData &mixer = MixingMap[sctid1][sctid2];
278  
279      RealType rcij = mixer.rCut;
280  
# Line 279 | Line 291 | namespace OpenMD {
291  
292      if (!initialized_) initialize();
293  
294 <    SCAtomData data1 = SCMap[sdat.atype];
294 >    SCAtomData &data1 = SCdata[SCtids[sdat.atid]];
295    
296      RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) );
297      *(sdat.frho) = u;
# Line 298 | Line 310 | namespace OpenMD {
310      
311      if (!initialized_) initialize();
312      
313 <    SCAtomData data1 = SCMap[idat.atypes.first];
314 <    SCAtomData data2 = SCMap[idat.atypes.second];
313 >    int &sctid1 = SCtids[idat.atid1];
314 >    int &sctid2 = SCtids[idat.atid2];
315  
316 <    SCInteractionData mixer = MixingMap[idat.atypes];
316 >    SCAtomData &data1 = SCdata[sctid1];
317 >    SCAtomData &data2 = SCdata[sctid2];
318  
319 +    SCInteractionData &mixer = MixingMap[sctid1][sctid2];
320 +
321      RealType rcij = mixer.rCut;
322  
323      if ( *(idat.rij)  < rcij) {
324 <      RealType vcij = mixer.vCut;
324 >      RealType vcij = mixer.vCut;
325 >      RealType rhtmp, drhodr, vptmp, dvpdr;
326        
327 <      pair<RealType, RealType> res;
327 >      mixer.phi->getValueAndDerivativeAt( *(idat.rij), rhtmp, drhodr );      
328 >      mixer.V->getValueAndDerivativeAt( *(idat.rij), vptmp, dvpdr);
329        
313      res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) );
314      RealType rhtmp = res.first;
315      RealType drhodr = res.second;
316      
317      res = mixer.V->getValueAndDerivativeAt( *(idat.rij) );
318      RealType vptmp = res.first;
319      RealType dvpdr = res.second;
320      
330        RealType pot_temp = vptmp - vcij;
331        *(idat.vpair) += pot_temp;
332        
# Line 351 | Line 360 | namespace OpenMD {
360    RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
361      if (!initialized_) initialize();  
362  
363 <    map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it;
364 <    it = MixingMap.find(atypes);
365 <    if (it == MixingMap.end())
363 >    int atid1 = atypes.first->getIdent();
364 >    int atid2 = atypes.second->getIdent();
365 >    int &sctid1 = SCtids[atid1];
366 >    int &sctid2 = SCtids[atid2];
367 >    
368 >    if (sctid1 == -1 || sctid2 == -1) {
369        return 0.0;
370 <    else  {
371 <      SCInteractionData mixer = (*it).second;
360 <      return mixer.rCut;
370 >    } else {
371 >      return MixingMap[sctid1][sctid2].rCut;
372      }
373    }
374   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines