db7fac3f24
git-svn-id: https://openfoam-extend.svn.sourceforge.net/svnroot/openfoam-extend/trunk/Core/OpenFOAM-1.5-dev@1731 e4e07f05-0c2f-0410-a05a-b8ba57e0c909
217 lines
5.9 KiB
C
217 lines
5.9 KiB
C
labelVector iN(0,0,0);
|
|
|
|
vector gap = (vector::one)*pow((numberDensity/4.0),-(1.0/3.0));
|
|
|
|
#include "origin.H"
|
|
|
|
// Info<< "gap = " << gap << endl;
|
|
|
|
// Special treatment is required for the first position, i.e. iteration zero.
|
|
|
|
if (n == 0)
|
|
{
|
|
latticePosition.x() = (iN.x() * gap.x());
|
|
|
|
latticePosition.y() = (iN.y() * gap.y());
|
|
|
|
latticePosition.z() = (iN.z() * gap.z());
|
|
|
|
// Placing 4 molecules in each unit cell, using the algorithm from
|
|
// D. Rapaport, The Art of Molecular Dynamics Simulation, 2nd Ed, p68
|
|
|
|
for (label iU = 0; iU < 4; iU++)
|
|
{
|
|
vector unitCellLatticePosition = latticePosition;
|
|
|
|
if (iU != 3)
|
|
{
|
|
if (iU != 0)
|
|
{
|
|
unitCellLatticePosition.x() += 0.5 * gap.x();
|
|
}
|
|
|
|
if (iU != 1)
|
|
{
|
|
unitCellLatticePosition.y() += 0.5 * gap.y();
|
|
}
|
|
|
|
if (iU != 2)
|
|
{
|
|
unitCellLatticePosition.z() += 0.5 * gap.z();
|
|
}
|
|
}
|
|
|
|
if (originSpecifies == "corner")
|
|
{
|
|
unitCellLatticePosition -= 0.25*gap;
|
|
}
|
|
|
|
// Info << nl << n << ", " << unitCellLatticePosition;
|
|
|
|
globalPosition =
|
|
origin + transform(latticeToGlobal,unitCellLatticePosition);
|
|
|
|
partOfLayerInBounds = mesh_.bounds().contains(globalPosition);
|
|
|
|
if
|
|
(
|
|
findIndex(mesh_.cellZones()[cZ], mesh_.findCell(globalPosition))
|
|
!= -1
|
|
)
|
|
{
|
|
molsPlacedThisIteration++;
|
|
|
|
initialPositions.append(globalPosition);
|
|
|
|
initialCelli.append(mesh_.findCell(globalPosition));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Place top and bottom caps.
|
|
|
|
for (iN.z() = -n; iN.z() <= n; iN.z() += 2*n)
|
|
{
|
|
for (iN.y() = -n; iN.y() <= n; iN.y()++)
|
|
{
|
|
for (iN.x() = -n; iN.x() <= n; iN.x()++)
|
|
{
|
|
latticePosition.x() = (iN.x() * gap.x());
|
|
|
|
latticePosition.y() = (iN.y() * gap.y());
|
|
|
|
latticePosition.z() = (iN.z() * gap.z());
|
|
|
|
for (label iU = 0; iU < 4; iU++)
|
|
{
|
|
vector unitCellLatticePosition = latticePosition;
|
|
|
|
if (iU != 3)
|
|
{
|
|
if (iU != 0)
|
|
{
|
|
unitCellLatticePosition.x() += 0.5 * gap.x();
|
|
}
|
|
|
|
if (iU != 1)
|
|
{
|
|
unitCellLatticePosition.y() += 0.5 * gap.y();
|
|
}
|
|
|
|
if (iU != 2)
|
|
{
|
|
unitCellLatticePosition.z() += 0.5 * gap.z();
|
|
}
|
|
}
|
|
|
|
if (originSpecifies == "corner")
|
|
{
|
|
unitCellLatticePosition -= 0.25*gap;
|
|
}
|
|
|
|
globalPosition =
|
|
origin
|
|
+ transform(latticeToGlobal,unitCellLatticePosition);
|
|
|
|
partOfLayerInBounds =
|
|
mesh_.bounds().contains(globalPosition);
|
|
|
|
if
|
|
(
|
|
findIndex
|
|
(
|
|
mesh_.cellZones()[cZ],
|
|
mesh_.findCell(globalPosition)
|
|
)
|
|
!= -1
|
|
)
|
|
{
|
|
molsPlacedThisIteration++;
|
|
|
|
initialPositions.append(globalPosition);
|
|
|
|
initialCelli.append(mesh_.findCell(globalPosition));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Placing sides
|
|
|
|
for (iN.z() = -(n-1); iN.z() <= (n-1); iN.z()++)
|
|
{
|
|
for (label iR = 0; iR <= 2*n -1; iR++)
|
|
{
|
|
latticePosition.x() = (n * gap.x());
|
|
|
|
latticePosition.y() = ((-n + (iR + 1)) * gap.y());
|
|
|
|
latticePosition.z() = (iN.z() * gap.z());
|
|
|
|
for (label iK = 0; iK < 4; iK++)
|
|
{
|
|
for (label iU = 0; iU < 4; iU++)
|
|
{
|
|
vector unitCellLatticePosition = latticePosition;
|
|
|
|
if (iU != 3)
|
|
{
|
|
if (iU != 0)
|
|
{
|
|
unitCellLatticePosition.x() += 0.5 * gap.x();
|
|
}
|
|
|
|
if (iU != 1)
|
|
{
|
|
unitCellLatticePosition.y() += 0.5 * gap.y();
|
|
}
|
|
|
|
if (iU != 2)
|
|
{
|
|
unitCellLatticePosition.z() += 0.5 * gap.z();
|
|
}
|
|
}
|
|
|
|
if (originSpecifies == "corner")
|
|
{
|
|
unitCellLatticePosition -= 0.25*gap;
|
|
}
|
|
|
|
globalPosition =
|
|
origin
|
|
+ transform(latticeToGlobal,unitCellLatticePosition);
|
|
|
|
partOfLayerInBounds =
|
|
mesh_.bounds().contains(globalPosition);
|
|
|
|
if
|
|
(
|
|
findIndex
|
|
(
|
|
mesh_.cellZones()[cZ],
|
|
mesh_.findCell(globalPosition)
|
|
)
|
|
!= -1
|
|
)
|
|
{
|
|
molsPlacedThisIteration++;
|
|
|
|
initialPositions.append(globalPosition);
|
|
|
|
initialCelli.append(mesh_.findCell(globalPosition));
|
|
}
|
|
}
|
|
|
|
latticePosition =
|
|
vector
|
|
(
|
|
- latticePosition.y(),
|
|
latticePosition.x(),
|
|
latticePosition.z()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|