当前位置: 首页>>代码示例>>C++>>正文


C++ Boundary::shift方法代码示例

本文整理汇总了C++中Boundary::shift方法的典型用法代码示例。如果您正苦于以下问题:C++ Boundary::shift方法的具体用法?C++ Boundary::shift怎么用?C++ Boundary::shift使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Boundary的用法示例。


在下文中一共展示了Boundary::shift方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writeRings

void RingMaker::writeRings(std::ostream& out)
{
   Vector r, a, b;
   double beta = 1.0, length;
   int    bondType = 0;
   int    iMol, iAtom;

   out << "BOUNDARY" << std::endl;
   out << std::endl;
   out << "lengths " << boundary_ << std::endl;
   out << std::endl;
   out << "MOLECULES" << std::endl;
   out << std::endl;
   out << "species    " << 0 << std::endl;
   out << "nMolecule  " << nMolecule_ << std::endl;
   for (iMol = 0; iMol < nMolecule_; ++iMol) {
      out << std::endl;
      out << "molecule   " << iMol << std::endl;

      // Generate the trial bond vectors
      v_[nAtom_-1].zero();
      for (iAtom = 1; iAtom < nAtom_; ++iAtom) {
         random_.unitVector(v_[iAtom-1]);
         v_[iAtom-1] *= 
           bondPotential_.randomBondLength(&random_, beta, bondType);
         v_[nAtom_-1] += v_[iAtom-1];
      }
      length = bondPotential_.randomBondLength(&random_, beta, bondType);
      length = v_[nAtom_-1].abs() - length;
      if (length > 0.0) {
         length /= v_[nAtom_-1].abs() * double(nAtom_-1);
         v_[nAtom_-1] *= length;
      } else {
         v_[nAtom_-1].zero();
      }

      // Choose first atom at random
      boundary_.randomPosition(random_, r);

      // Output the atom positions
      out << r << std::endl;
      for (iAtom = 1; iAtom < nAtom_; ++iAtom) {
         v_[iAtom-1] -= v_[nAtom_-1];
         r += v_[iAtom-1];
         boundary_.shift(r);
         out << r << std::endl;
      }

   }

}
开发者ID:TaherGhasimakbari,项目名称:simpatico,代码行数:51,代码来源:RingMaker.cpp

示例2: tryPlaceAtom

   /**
   * Recursive function to try to place an atom.
   */
   bool Linear::tryPlaceAtom(Molecule& molecule, int atomId,
      DArray<double> exclusionRadius, System& system, CellList &cellList,
      BondPotential *bondPotentialPtr, const Boundary &boundary)
   {
      Atom& lastAtom = molecule.atom(atomId);
      Atom& thisAtom = molecule.atom(++atomId);
      Random& random = system.simulation().random();

      bool hasBeenPlaced = false;

      for (int iAttempt = 0; iAttempt < maxPlacementAttempts_; iAttempt++)
      {
         // draw a random bond vector
         int beta = 1;
         Vector v;
         random.unitVector(v);
         v *= bondPotentialPtr->randomBondLength(&random, beta,
            calculateBondTypeId(lastAtom.indexInMolecule()));

         Vector newPos;
         newPos = lastAtom.position();
         newPos += v;
         // shift into simulation cell
         boundary.shift(newPos);

         // check if the atom can be placed at the new position
         CellList::NeighborArray neighbors;
         cellList.getNeighbors(newPos, neighbors);
         int nNeighbor = neighbors.size();
         bool canBePlaced = true;
         for (int j = 0; j < nNeighbor; ++j) {
            Atom *jAtomPtr = neighbors[j];
         
            double r = sqrt(boundary.distanceSq(
               jAtomPtr->position(), newPos));
            if (r < (exclusionRadius[thisAtom.typeId()] +
               exclusionRadius[jAtomPtr->typeId()])) {
               canBePlaced = false;
               break;
            }
         } 
         if (canBePlaced) {
            // place the particle
            thisAtom.position() = newPos;

            // add to cell list
            cellList.addAtom(thisAtom);

            // are we add the end of the chain?
            if (atomId == molecule.nAtom()-1) 
              return true;
            
            // recursion step
            if (! tryPlaceAtom(molecule, atomId, exclusionRadius, system,
               cellList, bondPotentialPtr, boundary) ) {
               // If the next monomer cannot be inserted, delete this monomer
               // again
               cellList.deleteAtom(thisAtom);
            } else {
               hasBeenPlaced = true;
               break;
            }
         } 
      }

      return hasBeenPlaced;
   }
开发者ID:jmysona,项目名称:testing2,代码行数:70,代码来源:Linear.cpp


注:本文中的Boundary::shift方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。