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

Comparing trunk/src/selection/SelectionEvaluator.cpp (file contents):
Revision 1903 by gezelter, Tue Jul 16 18:58:08 2013 UTC vs.
Revision 2052 by gezelter, Fri Jan 9 19:06:35 2015 UTC

# Line 58 | Line 58 | namespace OpenMD {
58      : info(si), nameFinder(info), distanceFinder(info), hullFinder(info),
59        indexFinder(info), hasSurfaceArea_(false),
60        isLoaded_(false){    
61 <      nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies();
62 <    }            
63 <
61 >    nObjects.push_back(info->getNGlobalAtoms() + info->getNGlobalRigidBodies());
62 >    nObjects.push_back(info->getNGlobalBonds());
63 >    nObjects.push_back(info->getNGlobalBends());
64 >    nObjects.push_back(info->getNGlobalTorsions());
65 >    nObjects.push_back(info->getNGlobalInversions());
66 >    nObjects.push_back(info->getNGlobalMolecules());    
67 >  }
68 >  
69    bool SelectionEvaluator::loadScript(const std::string& filename,
70                                        const std::string& script) {
71      clearDefinitionsAndLoadPredefined();
# Line 127 | Line 132 | namespace OpenMD {
132      return loadScript(filename, script);
133    }
134    
135 <  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){
135 >  void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs){
136      
137      while ( pc < aatoken.size()) {
138        statement = aatoken[pc++];
# Line 148 | Line 153 | namespace OpenMD {
153  
154    }
155  
156 <  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs, int frame){
156 >  void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs, int frame){
157      
158      while ( pc < aatoken.size()) {
159        statement = aatoken[pc++];
# Line 169 | Line 174 | namespace OpenMD {
174  
175    }
176  
177 <  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
177 >  SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code,
178                                               int pcStart) {
179 <    OpenMDBitSet bs;
180 <    std::stack<OpenMDBitSet> stack;
179 >    SelectionSet bs = createSelectionSets();
180 >    std::stack<SelectionSet> stack;
181 >    vector<int> bsSize = bs.size();
182    
183      for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
184        Token instruction = code[pc];
# Line 184 | Line 190 | namespace OpenMD {
190          break;
191        case Token::all:
192          bs = allInstruction();
193 <        stack.push(bs);            
193 >        stack.push(bs);
194          break;
195        case Token::none:
196 <        bs = OpenMDBitSet(nStuntDouble);
197 <        stack.push(bs);            
196 >        bs = createSelectionSets();
197 >        stack.push(bs);
198          break;
199        case Token::opOr:
200 <        bs = stack.top();
201 <        stack.pop();
202 <        stack.top() |= bs;
200 >          bs= stack.top();
201 >          stack.pop();
202 >          stack.top() |= bs;
203          break;
204        case Token::opAnd:
205 <        bs = stack.top();
206 <        stack.pop();
207 <        stack.top() &= bs;
205 >          bs = stack.top();
206 >          stack.pop();
207 >          stack.top() &= bs;
208          break;
209        case Token::opNot:
210 <        stack.top().flip();
210 >          stack.top().flip();
211          break;
212        case Token::within:
213          withinInstruction(instruction, stack.top());
214          break;
215        case Token::hull:
216 <        stack.push(hull());
216 >          stack.push(hull());
217          break;
218          //case Token::selected:
219          //  stack.push(getSelectionSet());
220          //  break;
221        case Token::name:
222 <        stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
222 >          stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
223          break;
224        case Token::index:
225 <        stack.push(indexInstruction(instruction.value));
225 >          stack.push(indexInstruction(instruction.value));
226          break;
227        case Token::identifier:
228 <        stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
228 >          stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
229          break;
230        case Token::opLT:
231        case Token::opLE:
# Line 240 | Line 246 | namespace OpenMD {
246    }
247  
248  
249 <  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
249 >  SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code,
250                                                int pcStart, int frame) {
251 <    OpenMDBitSet bs;
252 <    std::stack<OpenMDBitSet> stack;
251 >    SelectionSet bs = createSelectionSets();
252 >    std::stack<SelectionSet> stack;
253    
254      for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
255        Token instruction = code[pc];
# Line 258 | Line 264 | namespace OpenMD {
264          stack.push(bs);            
265          break;
266        case Token::none:
267 <        bs = OpenMDBitSet(nStuntDouble);
267 >        bs = SelectionSet(nObjects);
268          stack.push(bs);            
269          break;
270        case Token::opOr:
# Line 312 | Line 318 | namespace OpenMD {
318  
319  
320  
321 <  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
321 >  SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
322      int comparator = instruction.tok;
323      int property = instruction.intValue;
324      float comparisonValue = boost::any_cast<float>(instruction.value);
325 <    OpenMDBitSet bs(nStuntDouble);
325 >    SelectionSet bs = createSelectionSets();
326      bs.clearAll();
327      
328      SimInfo::MoleculeIterator mi;
# Line 342 | Line 348 | namespace OpenMD {
348      return bs;
349    }
350  
351 <  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) {
351 >  SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) {
352      int comparator = instruction.tok;
353      int property = instruction.intValue;
354      float comparisonValue = boost::any_cast<float>(instruction.value);
355 <    OpenMDBitSet bs(nStuntDouble);
355 >    SelectionSet bs = createSelectionSets();
356      bs.clearAll();
357      
358      SimInfo::MoleculeIterator mi;
# Line 372 | Line 378 | namespace OpenMD {
378      return bs;
379    }
380  
381 <  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
381 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
382                                             int property, int comparator,
383                                             float comparisonValue) {
384      RealType propertyValue = 0.0;
385      Vector3d pos;
386 +
387      switch (property) {
388      case Token::mass:
389        propertyValue = sd->getMass();
# Line 446 | Line 453 | namespace OpenMD {
453        match = propertyValue != comparisonValue;
454        break;
455      }
456 +
457      if (match)
458 <      bs.setBitOn(sd->getGlobalIndex());
458 >      bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
459  
460      
461    }
462  
463 <  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
463 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
464                                             int property, int comparator,
465                                             float comparisonValue, int frame) {
466      RealType propertyValue = 0.0;
# Line 528 | Line 536 | namespace OpenMD {
536        break;
537      }
538      if (match)
539 <      bs.setBitOn(sd->getGlobalIndex());
539 >      bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
540  
541      
542    }
543  
544    void SelectionEvaluator::withinInstruction(const Token& instruction,
545 <                                             OpenMDBitSet& bs){
545 >                                             SelectionSet& bs){
546      
547      boost::any withinSpec = instruction.value;
548      float distance;
# Line 551 | Line 559 | namespace OpenMD {
559    }
560  
561    void SelectionEvaluator::withinInstruction(const Token& instruction,
562 <                                             OpenMDBitSet& bs, int frame){
562 >                                             SelectionSet& bs, int frame){
563      
564      boost::any withinSpec = instruction.value;
565      float distance;
# Line 608 | Line 616 | namespace OpenMD {
616      }
617    }
618  
619 <  void SelectionEvaluator::select(OpenMDBitSet& bs){
619 >  void SelectionEvaluator::select(SelectionSet& bs){
620      bs = expression(statement, 1);
621    }
622  
623 <  void SelectionEvaluator::select(OpenMDBitSet& bs, int frame){
623 >  void SelectionEvaluator::select(SelectionSet& bs, int frame){
624      bs = expression(statement, 1, frame);
625    }
626    
627 <  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){
627 >  SelectionSet SelectionEvaluator::lookupValue(const std::string& variable){
628      
629 <    OpenMDBitSet bs(nStuntDouble);
629 >    SelectionSet bs = createSelectionSets();
630      std::map<std::string, boost::any>::iterator i = variables.find(variable);
631      
632      if (i != variables.end()) {
633 <      if (i->second.type() == typeid(OpenMDBitSet)) {
634 <        return boost::any_cast<OpenMDBitSet>(i->second);
633 >      if (i->second.type() == typeid(SelectionSet)) {
634 >        return boost::any_cast<SelectionSet>(i->second);
635        } else if (i->second.type() ==  typeid(std::vector<Token>)){
636          bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
637          i->second =  bs; /**@todo fixme */
# Line 636 | Line 644 | namespace OpenMD {
644      return bs;
645    }
646    
647 <  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){    
647 >  SelectionSet SelectionEvaluator::nameInstruction(const std::string& name){    
648      return nameFinder.match(name);    
649    }    
650  
# Line 657 | Line 665 | namespace OpenMD {
665      //predefine();
666    }
667  
668 <  OpenMDBitSet SelectionEvaluator::evaluate() {
669 <    OpenMDBitSet bs(nStuntDouble);
668 >  SelectionSet SelectionEvaluator::createSelectionSets() {
669 >    SelectionSet ss(nObjects);
670 >    return ss;
671 >  }
672 >
673 >  SelectionSet SelectionEvaluator::evaluate() {
674 >    SelectionSet bs = createSelectionSets();
675      if (isLoaded_) {
676        pc = 0;
677        instructionDispatchLoop(bs);
# Line 666 | Line 679 | namespace OpenMD {
679      return bs;
680    }
681  
682 <  OpenMDBitSet SelectionEvaluator::evaluate(int frame) {
683 <    OpenMDBitSet bs(nStuntDouble);
682 >  SelectionSet SelectionEvaluator::evaluate(int frame) {
683 >    SelectionSet bs = createSelectionSets();
684      if (isLoaded_) {
685        pc = 0;
686        instructionDispatchLoop(bs, frame);
# Line 675 | Line 688 | namespace OpenMD {
688      return bs;
689    }
690  
691 <  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
692 <    OpenMDBitSet bs(nStuntDouble);
691 >  SelectionSet SelectionEvaluator::indexInstruction(const boost::any& value) {
692 >    SelectionSet bs = createSelectionSets();
693  
694      if (value.type() == typeid(int)) {
695        int index = boost::any_cast<int>(value);
696 <      if (index < 0 || index >= bs.size()) {
696 >      if (index < 0 || index >= bs.bitsets_[STUNTDOUBLE].size()) {
697          invalidIndex(index);
698        } else {
699          bs = indexFinder.find(index);
# Line 688 | Line 701 | namespace OpenMD {
701      } else if (value.type() == typeid(std::pair<int, int>)) {
702        std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
703        assert(indexRange.first <= indexRange.second);
704 <      if (indexRange.first < 0 || indexRange.second >= bs.size()) {
704 >      if (indexRange.first < 0 ||
705 >          indexRange.second >= bs.bitsets_[STUNTDOUBLE].size()) {
706          invalidIndexRange(indexRange);
707        }else {
708          bs = indexFinder.find(indexRange.first, indexRange.second);
# Line 698 | Line 712 | namespace OpenMD {
712      return bs;
713    }
714  
715 <  OpenMDBitSet SelectionEvaluator::allInstruction() {
716 <    OpenMDBitSet bs(nStuntDouble);
715 >  SelectionSet SelectionEvaluator::allInstruction() {
716 >    SelectionSet ss = createSelectionSets();
717  
718      SimInfo::MoleculeIterator mi;
705    Molecule* mol;
719      Molecule::AtomIterator ai;
707    Atom* atom;
720      Molecule::RigidBodyIterator rbIter;
721 +    Molecule::BondIterator bondIter;
722 +    Molecule::BendIterator bendIter;
723 +    Molecule::TorsionIterator torsionIter;
724 +    Molecule::InversionIterator inversionIter;
725 +
726 +    Molecule* mol;
727 +    Atom* atom;
728      RigidBody* rb;
729 +    Bond* bond;
730 +    Bend* bend;
731 +    Torsion* torsion;
732 +    Inversion* inversion;    
733  
734      // Doing the loop insures that we're actually on this processor.
735  
736      for (mol = info->beginMolecule(mi); mol != NULL;
737           mol = info->nextMolecule(mi)) {
715
738        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
739 <        bs.setBitOn(atom->getGlobalIndex());
740 <      }
719 <    
739 >        ss.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
740 >      }    
741        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
742             rb = mol->nextRigidBody(rbIter)) {
743 <        bs.setBitOn(rb->getGlobalIndex());
743 >        ss.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
744        }
745 +      for (bond = mol->beginBond(bondIter); bond != NULL;
746 +           bond = mol->nextBond(bondIter)) {
747 +        ss.bitsets_[BOND].setBitOn(bond->getGlobalIndex());
748 +      }  
749 +      for (bend = mol->beginBend(bendIter); bend != NULL;
750 +           bend = mol->nextBend(bendIter)) {
751 +        ss.bitsets_[BEND].setBitOn(bend->getGlobalIndex());
752 +      }  
753 +      for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
754 +           torsion = mol->nextTorsion(torsionIter)) {
755 +        ss.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex());
756 +      }  
757 +      for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
758 +           inversion = mol->nextInversion(inversionIter)) {
759 +        ss.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
760 +      }
761 +      ss.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());
762      }
763  
764 <    return bs;
764 >    return ss;
765    }
766  
767 <  OpenMDBitSet SelectionEvaluator::hull() {
768 <    OpenMDBitSet bs(nStuntDouble);
767 >  SelectionSet SelectionEvaluator::hull() {
768 >    SelectionSet bs = createSelectionSets();
769      
770      bs = hullFinder.findHull();
771      surfaceArea_ = hullFinder.getSurfaceArea();
# Line 736 | Line 774 | namespace OpenMD {
774    }
775  
776  
777 <  OpenMDBitSet SelectionEvaluator::hull(int frame) {
778 <    OpenMDBitSet bs(nStuntDouble);
777 >  SelectionSet SelectionEvaluator::hull(int frame) {
778 >    SelectionSet bs = createSelectionSets();
779      
780      bs = hullFinder.findHull(frame);
781  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines