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

Comparing branches/development/src/nonbonded/SHAPES.cpp (file contents):
Revision 1501 by gezelter, Wed Sep 15 19:32:10 2010 UTC vs.
Revision 1635 by gezelter, Thu Sep 15 16:24:03 2011 UTC

# Line 49 | Line 49 | namespace OpenMD {
49  
50   using namespace std;
51   namespace OpenMD {
52 <  
53 <  bool SHAPES::initialized_ = false;
54 <  int SHAPES::lMax_ = 64;
55 <  int SHAPES::mMax_ = 64;
56 <  ForceField* SHAPES::forceField_ = NULL;
57 <  map<int, AtomType*> SHAPES::ShapesMap;
58 <  map<pair<AtomType*, AtomType*>, SHAPESInteractionData> SHAPES::MixingMap;
59 <  
60 <  SHAPES* SHAPES::_instance = NULL;
61 <
62 <  SHAPES* SHAPES::Instance() {
63 <    if (!_instance) {
64 <      _instance = new SHAPES();
65 <    }
66 <    return _instance;
52 >
53 >  SHAPES::SHAPES() {
54 >    initialized_ = false;
55 >    lMax_ = 64;
56 >    mMax_ = 64;
57 >    forceField_ = NULL;
58    }
59 <
59 >  
60    void SHAPES::initialize() {    
61      
62      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
# Line 75 | Line 66 | namespace OpenMD {
66  
67      // SHAPES handles all of the SHAPES-SHAPES interactions as well as
68      // SHAPES-LJ cross interactions:
69 <
69 >    
70      for (at = atomTypes->beginType(i); at != NULL;
71           at = atomTypes->nextType(i)) {
72        
73 <      if (at->isShape() || at->isLennardJones())
74 <        addType(at);
73 >      if (at->isShape())
74 >        addShape(dynamic_cast<ShapeAtomType*>(at));
75 >
76 >      if (at->isLennardJones())
77 >        addLJ(at);
78 >      
79      }
80 <  
80 >    
81      initialized_ = true;
82    }
83 <      
84 <  void SHAPES::addType(AtomType* atomType){
83 >  
84 >  void SHAPES::addShape(ShapeAtomType* atomType){
85      // add it to the map:
86      AtomTypeProperties atp = atomType->getATP();    
87  
88 <    pair<map<int,AtomType*>::iterator,bool> ret;    
89 <    ret = ShapesMap.insert( pair<int, AtomType*>(atp.ident, atomType) );
90 <    if (ret.second == false) {
91 <      sprintf( painCave.errMsg,
92 <               "SHAPES already had a previous entry with ident %d\n",
93 <               atp.ident);
94 <      painCave.severity = OPENMD_INFO;
95 <      painCave.isFatal = 0;
96 <      simError();        
97 <    }  
98 <    
99 <    if (atomType->isShape()) {
100 <      ShapeAtomType* sAtomType = dynamic_cast<ShapeAtomType*>(atomType);
101 <      if (sAtomType == NULL) {
107 <        sprintf(painCave.errMsg,
108 <                "SHAPES:: Can't cast to ShapeAtomType");
109 <        painCave.severity = OPENMD_ERROR;
110 <        painCave.isFatal = 1;
111 <        simError();
112 <      }
113 <      ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, sAtomType) );
114 <
88 >    if (atomType->isShape() ) {
89 >      pair<map<int,ShapeAtomType*>::iterator, bool> ret;
90 >      ret = ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, atomType));
91 >      if (ret.second == false) {
92 >        sprintf( painCave.errMsg,
93 >                 "SHAPES already had a previous entry with ident %d\n",
94 >                 atp.ident);
95 >        painCave.severity = OPENMD_INFO;
96 >        painCave.isFatal = 0;
97 >        simError();        
98 >      }  
99 >      
100 >      ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, static_cast<ShapeAtomType*>(atomType)) );
101 >      
102      } else if (atomType->isLennardJones()) {
103 <      d1 = LJ::Instance()->getSigma(atomType) / sqrt(2.0);
104 <      e1 = LJ::Instance()->getEpsilon(atomType);
103 >      RealType d1 = getLJSigma(atomType) / sqrt(2.0);
104 >      RealType e1 = getLJEpsilon(atomType);
105      } else {
106        sprintf( painCave.errMsg,
107                 "SHAPES::addType was passed an atomType (%s) that does not\n"
108 <               "\tappear to be a Gay-Berne or Lennard-Jones atom.\n",
108 >               "\tappear to be a SHAPES or Lennard-Jones atom.\n",
109                 atomType->getName().c_str());
110        painCave.severity = OPENMD_ERROR;
111        painCave.isFatal = 1;
112        simError();
113 <    }
114 <      
113 >    }  
114 >  }
115 >  
116  
117 <    // Now, iterate over all known types and add to the mixing map:
117 >  LJParam SHAPES::getLJParam(AtomType* atomType) {
118      
119 <    map<int, AtomType*>::iterator it;
120 <    for( it = ShapesMap.begin(); it != SHAPESMap.end(); ++it) {
121 <      
122 <      AtomType* atype2 = (*it).second;
123 <      
124 <      RealType d2, l2, e2, er2, dw2;
125 <      
126 <      if (atype2->isGayBerne()) {
127 <        GayBerneParam gb2 = getGayBerneParam(atype2);
128 <        d2 = gb2.SHAPES_d;
129 <        l2 = gb2.SHAPES_l;
130 <        e2 = gb2.SHAPES_eps;
131 <        er2 = gb2.SHAPES_eps_ratio;
132 <        dw2 = gb2.SHAPES_dw;
133 <      } else if (atype2->isLennardJones()) {
134 <        d2 = LJ::Instance()->getSigma(atype2) / sqrt(2.0);
135 <        e2 = LJ::Instance()->getEpsilon(atype2);
136 <        l2 = d2;
137 <        er2 = 1.0;
138 <        dw2 = 1.0;
139 <      }
140 <                      
141 <      SHAPESInteractionData mixer;        
142 <      
143 <      //  Cleaver paper uses sqrt of squares to get sigma0 for
144 <      //  mixed interactions.
145 <            
146 <      mixer.sigma0 = sqrt(d1*d1 + d2*d2);
147 <      mixer.xa2 = (l1*l1 - d1*d1)/(l1*l1 + d2*d2);
148 <      mixer.xai2 = (l2*l2 - d2*d2)/(l2*l2 + d1*d1);
149 <      mixer.x2 = (l1*l1 - d1*d1) * (l2*l2 - d2*d2) /
150 <        ((l2*l2 + d1*d1) * (l1*l1 + d2*d2));
163 <
164 <      // assumed LB mixing rules for now:
165 <
166 <      mixer.dw = 0.5 * (dw1 + dw2);
167 <      mixer.eps0 = sqrt(e1 * e2);
168 <      
169 <      RealType er = sqrt(er1 * er2);
170 <      RealType ermu = pow(er,(1.0 / mu_));
171 <      RealType xp = (1.0 - ermu) / (1.0 + ermu);
172 <      RealType ap2 = 1.0 / (1.0 + ermu);
173 <      
174 <      mixer.xp2 = xp * xp;
175 <      mixer.xpap2 = xp * ap2;
176 <      mixer.xpapi2 = xp / ap2;
177 <
178 <      // only add this pairing if at least one of the atoms is a Gay-Berne atom
179 <
180 <      if (atomType->isGayBerne() || atype2->isGayBerne()) {
181 <
182 <        pair<AtomType*, AtomType*> key1, key2;
183 <        key1 = make_pair(atomType, atype2);
184 <        key2 = make_pair(atype2, atomType);
185 <        
186 <        MixingMap[key1] = mixer;
187 <        if (key2 != key1) {
188 <          MixingMap[key2] = mixer;
189 <        }
190 <      }
191 <    }      
119 >    // Do sanity checking on the AtomType we were passed before
120 >    // building any data structures:
121 >    if (!atomType->isLennardJones()) {
122 >      sprintf( painCave.errMsg,
123 >               "SHAPES::getLJParam was passed an atomType (%s) that does not\n"
124 >               "\tappear to be a Lennard-Jones atom.\n",
125 >               atomType->getName().c_str());
126 >      painCave.severity = OPENMD_ERROR;
127 >      painCave.isFatal = 1;
128 >      simError();
129 >    }
130 >    
131 >    GenericData* data = atomType->getPropertyByName("LennardJones");
132 >    if (data == NULL) {
133 >      sprintf( painCave.errMsg, "SHAPES::getLJParam could not find Lennard-Jones\n"
134 >               "\tparameters for atomType %s.\n", atomType->getName().c_str());
135 >      painCave.severity = OPENMD_ERROR;
136 >      painCave.isFatal = 1;
137 >      simError();
138 >    }
139 >    
140 >    LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
141 >    if (ljData == NULL) {
142 >      sprintf( painCave.errMsg,
143 >               "SHAPES::getLJParam could not convert GenericData to LJParam for\n"
144 >               "\tatom type %s\n", atomType->getName().c_str());
145 >      painCave.severity = OPENMD_ERROR;
146 >      painCave.isFatal = 1;
147 >      simError();          
148 >    }
149 >    
150 >    return ljData->getData();
151    }
152    
153 +  RealType SHAPES::getLJEpsilon(AtomType* atomType) {    
154 +    LJParam ljParam = getLJParam(atomType);
155 +    return ljParam.epsilon;
156 +  }
157 +  RealType SHAPES::getLJSigma(AtomType* atomType) {    
158 +    LJParam ljParam = getLJParam(atomType);
159 +    return ljParam.sigma;
160 +  }
161  
162    RealType SHAPES::getGayBerneCut(int atid) {
163      if (!initialized_) initialize();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines