Пример #1
0
void P2OrderParameter::process() {
    Molecule* mol;
    RigidBody* rb;
    SimInfo::MoleculeIterator mi;
    Molecule::RigidBodyIterator rbIter;
    StuntDouble* sd1;
    StuntDouble* sd2;
    int ii;
    int jj;
    int vecCount;
    bool usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions();

    DumpReader reader(info_, dumpFilename_);
    int nFrames = reader.getNFrames();

    for (int i = 0; i < nFrames; i += step_) {
        reader.readFrame(i);
        currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();

        for (mol = info_->beginMolecule(mi); mol != NULL;
                mol = info_->nextMolecule(mi)) {
            //change the positions of atoms which belong to the rigidbodies
            for (rb = mol->beginRigidBody(rbIter); rb != NULL;
                    rb = mol->nextRigidBody(rbIter)) {
                rb->updateAtoms();
            }
        }

        Mat3x3d orderTensor(0.0);
        vecCount = 0;

        seleMan1_.setSelectionSet(evaluator1_.evaluate());

        if (doVect_) {

            for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
                    sd1 = seleMan1_.nextSelected(ii)) {
                if (sd1->isDirectional()) {
                    Vector3d vec = sd1->getA().transpose()*V3Z;

                    vec.normalize();
                    orderTensor += outProduct(vec, vec);
                    vecCount++;
                }
            }

            orderTensor /= vecCount;

        } else {

            if (doOffset_) {

                for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
                        sd1 = seleMan1_.nextSelected(ii)) {

                    // This will require careful rewriting if StaticProps is
                    // ever parallelized.  For an example, see
                    // Thermo::getTaggedAtomPairDistance

                    int sd2Index = sd1->getGlobalIndex() + seleOffset_;
                    sd2 = info_->getIOIndexToIntegrableObject(sd2Index);

                    Vector3d vec = sd1->getPos() - sd2->getPos();

                    if (usePeriodicBoundaryConditions_)
                        currentSnapshot_->wrapVector(vec);

                    vec.normalize();

                    orderTensor +=outProduct(vec, vec);
                    vecCount++;
                }

                orderTensor /= vecCount;
            } else {

                seleMan2_.setSelectionSet(evaluator2_.evaluate());

                if (seleMan1_.getSelectionCount() != seleMan2_.getSelectionCount() ) {
                    sprintf( painCave.errMsg,
                             "In frame %d, the number of selected StuntDoubles are\n"
                             "\tnot the same in --sele1 and sele2\n", i);
                    painCave.severity = OPENMD_INFO;
                    painCave.isFatal = 0;
                    simError();
                }

                for (sd1 = seleMan1_.beginSelected(ii),
                        sd2 = seleMan2_.beginSelected(jj);
                        sd1 != NULL && sd2 != NULL;
                        sd1 = seleMan1_.nextSelected(ii),
                        sd2 = seleMan2_.nextSelected(jj)) {

                    Vector3d vec = sd1->getPos() - sd2->getPos();

                    if (usePeriodicBoundaryConditions_)
                        currentSnapshot_->wrapVector(vec);

                    vec.normalize();

                    orderTensor +=outProduct(vec, vec);
                    vecCount++;
                }

                orderTensor /= vecCount;
            }
        }

        if (vecCount == 0) {
            sprintf( painCave.errMsg,
                     "In frame %d, the number of selected vectors was zero.\n"
                     "\tThis will not give a meaningful order parameter.", i);
            painCave.severity = OPENMD_ERROR;
            painCave.isFatal = 1;
            simError();
        }

        orderTensor -= (RealType)(1.0/3.0) * Mat3x3d::identity();

        Vector3d eigenvalues;
        Mat3x3d eigenvectors;

        Mat3x3d::diagonalize(orderTensor, eigenvalues, eigenvectors);

        int which(-1);
        RealType maxEval = 0.0;
        for(int k = 0; k< 3; k++) {
            if(fabs(eigenvalues[k]) > maxEval) {
                which = k;
                maxEval = fabs(eigenvalues[k]);
            }
        }
        RealType p2 = 1.5 * maxEval;

        //the eigen vector is already normalized in SquareMatrix3::diagonalize
        Vector3d director = eigenvectors.getColumn(which);
        if (director[0] < 0) {
            director.negate();
        }

        RealType angle = 0.0;
        vecCount = 0;

        if (doVect_) {
            for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
                    sd1 = seleMan1_.nextSelected(ii)) {
                if (sd1->isDirectional()) {
                    Vector3d vec = sd1->getA().transpose()*V3Z;
                    vec.normalize();
                    angle += acos(dot(vec, director));
                    vecCount++;
                }
            }
            angle = angle/(vecCount*NumericConstant::PI)*180.0;

        } else {
            if (doOffset_) {

                for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
                        sd1 = seleMan1_.nextSelected(ii)) {

                    // This will require careful rewriting if StaticProps is
                    // ever parallelized.  For an example, see
                    // Thermo::getTaggedAtomPairDistance

                    int sd2Index = sd1->getGlobalIndex() + seleOffset_;
                    sd2 = info_->getIOIndexToIntegrableObject(sd2Index);

                    Vector3d vec = sd1->getPos() - sd2->getPos();
                    if (usePeriodicBoundaryConditions_)
                        currentSnapshot_->wrapVector(vec);
                    vec.normalize();
                    angle += acos(dot(vec, director)) ;
                    vecCount++;
                }
                angle = angle / (vecCount * NumericConstant::PI) * 180.0;

            } else {

                for (sd1 = seleMan1_.beginSelected(ii),
                        sd2 = seleMan2_.beginSelected(jj);
                        sd1 != NULL && sd2 != NULL;
                        sd1 = seleMan1_.nextSelected(ii),
                        sd2 = seleMan2_.nextSelected(jj)) {

                    Vector3d vec = sd1->getPos() - sd2->getPos();
                    if (usePeriodicBoundaryConditions_)
                        currentSnapshot_->wrapVector(vec);
                    vec.normalize();
                    angle += acos(dot(vec, director)) ;
                    vecCount++;
                }
                angle = angle / (vecCount * NumericConstant::PI) * 180.0;
            }
        }

        OrderParam param;
        param.p2 = p2;
        param.director = director;
        param.angle = angle;

        orderParams_.push_back(param);

    }

    writeP2();

}
Пример #2
0
  void MomentumCorrFunc::correlateFrames(int frame1, int frame2) {
    SimInfo::MoleculeIterator mi1;
    SimInfo::MoleculeIterator mi2;
    Molecule* mol1;
    Molecule* mol2;
    Molecule::AtomIterator ai1;
    Molecule::AtomIterator ai2;
    Atom* atom1;
    Atom* atom2;

    std::vector<Vector3d> atomPositions1;
    std::vector<Vector3d> atomPositions2;
    std::vector<Vector3d> atomVelocity1;
    std::vector<Vector3d> atomVelocity2;
    int thisAtom1, thisAtom2;

    Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
    Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);

    assert(snapshot1 && snapshot2);

    RealType time1 = snapshot1->getTime();
    RealType time2 = snapshot2->getTime();
       
    int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);

    updateFrame(frame1);       
    atomPositions1.clear();
    for (mol1 = info_->beginMolecule(mi1); mol1 != NULL; 
         mol1 = info_->nextMolecule(mi1)) {
      for(atom1 = mol1->beginAtom(ai1); atom1 != NULL; 
          atom1 = mol1->nextAtom(ai1)) {        
        atomPositions1.push_back(atom1->getPos(frame1));
        atomVelocity1.push_back(atom1->getVel(frame1));
      }
    }
    updateFrame(frame2);       
    atomPositions2.clear();
    for (mol2 = info_->beginMolecule(mi2); mol2 != NULL; 
         mol2 = info_->nextMolecule(mi2)) {
      for(atom2 = mol2->beginAtom(ai2); atom2 != NULL; 
          atom2 = mol2->nextAtom(ai2)) {        
        atomPositions2.push_back(atom2->getPos(frame2));
        atomVelocity2.push_back(atom2->getVel(frame2));
      }
    }

    thisAtom1 = 0;

    for (mol1 = info_->beginMolecule(mi1); mol1 != NULL; 
         mol1 = info_->nextMolecule(mi1)) {
      for(atom1 = mol1->beginAtom(ai1); atom1 != NULL; 
          atom1 = mol1->nextAtom(ai1)) {
        
        Vector3d r1 = atomPositions1[thisAtom1];
        Vector3d p1 = atom1->getMass() * atomVelocity1[thisAtom1];

     	thisAtom2 = 0;

        for (mol2 = info_->beginMolecule(mi2); mol2 != NULL; 
             mol2 = info_->nextMolecule(mi2)) {
          for(atom2 = mol2->beginAtom(ai2); atom2 != NULL; 
              atom2 = mol2->nextAtom(ai2)) {
            
            Vector3d r2 = atomPositions2[thisAtom2];
            Vector3d p2 = atom2->getMass()  * atomVelocity1[thisAtom1];

            Vector3d deltaPos = (r2-r1);
            Vector3d dp2( deltaPos.x() * deltaPos.x(),
                          deltaPos.y() * deltaPos.y(),
                          deltaPos.z() * deltaPos.z());
            Vector3d pprod( p1.x() * p2.x(),
                            p1.y() * p2.y(),
                            p1.z() * p2.z());
            
            histogram_[timeBin] += outProduct(dp2, pprod);
                                           
            thisAtom2++;                    
          }
        }
        
        thisAtom1++;
      } 
    }
    
    count_[timeBin]++;
    
  }