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 1505 by gezelter, Sun Oct 3 22:18:59 2010 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) );
88 >    pair<map<int,ShapeAtomType*>::iterator, bool> ret;
89 >    ret = shapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, atomType));
90      if (ret.second == false) {
91 <      sprintf( painCave.errMsg,
91 >      sprintf( painCave.errmsg,
92                 "SHAPES already had a previous entry with ident %d\n",
93                 atp.ident);
94        painCave.severity = OPENMD_INFO;
# Line 101 | Line 96 | namespace OpenMD {
96        simError();        
97      }  
98      
99 <    if (atomType->isShape()) {
100 <      ShapeAtomType* sAtomType = dynamic_cast<ShapeAtomType*>(atomType);
101 <      if (sAtomType == NULL) {
102 <        sprintf(painCave.errMsg,
103 <                "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 <
115 <    } else if (atomType->isLennardJones()) {
116 <      d1 = LJ::Instance()->getSigma(atomType) / sqrt(2.0);
117 <      e1 = LJ::Instance()->getEpsilon(atomType);
99 >    ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, sAtomType) );
100 >    
101 >  } else if (atomType->isLennardJones()) {
102 >      d1 = getLJSigma(atomType) / sqrt(2.0);
103 >      e1 = getLJEpsilon(atomType);
104      } else {
105        sprintf( painCave.errMsg,
106                 "SHAPES::addType was passed an atomType (%s) that does not\n"
107 <               "\tappear to be a Gay-Berne or Lennard-Jones atom.\n",
107 >               "\tappear to be a SHAPES or Lennard-Jones atom.\n",
108                 atomType->getName().c_str());
109        painCave.severity = OPENMD_ERROR;
110        painCave.isFatal = 1;
111        simError();
112 <    }
113 <      
112 >    }  
113 >  }
114 >  
115  
116 <    // Now, iterate over all known types and add to the mixing map:
116 >  LJParam SHAPES::getLJParam(AtomType* atomType) {
117      
118 <    map<int, AtomType*>::iterator it;
119 <    for( it = ShapesMap.begin(); it != SHAPESMap.end(); ++it) {
120 <      
121 <      AtomType* atype2 = (*it).second;
122 <      
123 <      RealType d2, l2, e2, er2, dw2;
124 <      
125 <      if (atype2->isGayBerne()) {
126 <        GayBerneParam gb2 = getGayBerneParam(atype2);
127 <        d2 = gb2.SHAPES_d;
128 <        l2 = gb2.SHAPES_l;
129 <        e2 = gb2.SHAPES_eps;
130 <        er2 = gb2.SHAPES_eps_ratio;
131 <        dw2 = gb2.SHAPES_dw;
132 <      } else if (atype2->isLennardJones()) {
133 <        d2 = LJ::Instance()->getSigma(atype2) / sqrt(2.0);
134 <        e2 = LJ::Instance()->getEpsilon(atype2);
135 <        l2 = d2;
136 <        er2 = 1.0;
137 <        dw2 = 1.0;
138 <      }
139 <                      
140 <      SHAPESInteractionData mixer;        
141 <      
142 <      //  Cleaver paper uses sqrt of squares to get sigma0 for
143 <      //  mixed interactions.
144 <            
145 <      mixer.sigma0 = sqrt(d1*d1 + d2*d2);
146 <      mixer.xa2 = (l1*l1 - d1*d1)/(l1*l1 + d2*d2);
147 <      mixer.xai2 = (l2*l2 - d2*d2)/(l2*l2 + d1*d1);
148 <      mixer.x2 = (l1*l1 - d1*d1) * (l2*l2 - d2*d2) /
149 <        ((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 <    }      
118 >    // Do sanity checking on the AtomType we were passed before
119 >    // building any data structures:
120 >    if (!atomType->isLennardJones()) {
121 >      sprintf( painCave.errMsg,
122 >               "SHAPES::getLJParam was passed an atomType (%s) that does not\n"
123 >               "\tappear to be a Lennard-Jones atom.\n",
124 >               atomType->getName().c_str());
125 >      painCave.severity = OPENMD_ERROR;
126 >      painCave.isFatal = 1;
127 >      simError();
128 >    }
129 >    
130 >    GenericData* data = atomType->getPropertyByName("LennardJones");
131 >    if (data == NULL) {
132 >      sprintf( painCave.errMsg, "SHAPES::getLJParam could not find Lennard-Jones\n"
133 >               "\tparameters for atomType %s.\n", atomType->getName().c_str());
134 >      painCave.severity = OPENMD_ERROR;
135 >      painCave.isFatal = 1;
136 >      simError();
137 >    }
138 >    
139 >    LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
140 >    if (ljData == NULL) {
141 >      sprintf( painCave.errMsg,
142 >               "SHAPES::getLJParam could not convert GenericData to LJParam for\n"
143 >               "\tatom type %s\n", atomType->getName().c_str());
144 >      painCave.severity = OPENMD_ERROR;
145 >      painCave.isFatal = 1;
146 >      simError();          
147 >    }
148 >    
149 >    return ljData->getData();
150    }
151    
152 +  RealType SHAPES::getLJEpsilon(AtomType* atomType) {    
153 +    LJParam ljParam = getLJParam(atomType);
154 +    return ljParam.epsilon;
155 +  }
156 +  RealType SHAPES::getLJSigma(AtomType* atomType) {    
157 +    LJParam ljParam = getLJParam(atomType);
158 +    return ljParam.sigma;
159 +  }
160  
161    RealType SHAPES::getGayBerneCut(int atid) {
162      if (!initialized_) initialize();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines