本文整理汇总了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;
}
}
}
示例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;
}