Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

fcclattice.cpp

Go to the documentation of this file.
00001 /***************************************************************************************************
00002 *****           Copyright (C) 2005 John Schneiderman <JohnMS@member.fsf.org>                   *****
00003 *****                                                                                          *****
00004 *****           This program is free software; you can redistribute it and/or modify           *****
00005 *****           it under the terms of the GNU General Public License as published by           *****
00006 *****           the Free Software Foundation; either version 2 of the License, or              *****
00007 *****           (at your option) any later version.                                            *****
00008 *****                                                                                          *****
00009 *****           This program is distributed in the hope that it will be useful,                *****
00010 *****           but WITHOUT ANY WARRANTY; without even the implied warranty of                 *****
00011 *****           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  *****
00012 *****           GNU General Public License for more details.                                   *****
00013 *****                                                                                          *****
00014 *****           You should have received a copy of the GNU General Public License              *****
00015 *****           along with this program; if not, write to the Free Software                    *****
00016 *****           Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA     *****
00017 ***************************************************************************************************/
00018 #include "fcclattice.h"
00019 #include "cluster.h"
00020 #include "coordinate.h"
00021 #include <cmath>
00022 
00023 FCC_Lattice::FCC_Lattice()
00024 {}
00025 
00026 void FCC_Lattice::createLattice(int baseSize, double reducedDensity, Cluster &cluster) const
00027 {
00028     double latticeSize = 0.0;//The size of the lattice.
00029     Coordinate start1, start2, start3, start4;//The positions for the first group of atoms
00030     int numAtoms = 0;//The number of atoms in the cluster.
00031 
00032     cluster.clear();
00033     latticeSize = pow((4.0/reducedDensity),(1.0/3.0));
00034     int size = 4 * int(pow((double)baseSize, 3.0));
00035     for (int i = 0; i < size; i++)
00036         cluster.addAtom(Atom());
00037     start2.x=start1.x+(latticeSize/2.0);
00038     start2.y=start2.y+(latticeSize/2.0);
00039     start2.z=start1.z;
00040     start3.x=start1.x;
00041     start3.y=start1.y+(latticeSize/2.0);
00042     start3.z=start1.z+(latticeSize/2.0);
00043     start4.x=start1.x+(latticeSize/2.0);
00044     start4.y=start1.y;
00045     start4.z=start1.z+(latticeSize/2.0);
00046     for (int i = 0; i < baseSize; i++)
00047         for (int j = 0; j < baseSize; j++)
00048             for (int k = 0; k < baseSize; k++)
00049             {
00050                 cluster[numAtoms].properties.position.x = start1.x+double(i)*latticeSize;
00051                 cluster[numAtoms].properties.position.y = start1.y+double(j)*latticeSize;
00052                 cluster[numAtoms].properties.position.z = start1.z+double(k)*latticeSize;
00053                 numAtoms++;
00054             }
00055     for (int i = 0; i < baseSize; i++)
00056         for (int j = 0; j < baseSize; j++)
00057             for (int k = 0; k < baseSize; k++)
00058             {
00059                 cluster[numAtoms].properties.position.x = start2.x+double(i)*latticeSize;
00060                 cluster[numAtoms].properties.position.y = start2.y+double(j)*latticeSize;
00061                 cluster[numAtoms].properties.position.z = start2.z+double(k)*latticeSize;
00062                 numAtoms++;
00063             }
00064     for (int i = 0; i < baseSize; i++)
00065         for (int j = 0; j < baseSize; j++)
00066             for (int k = 0; k < baseSize; k++)
00067             {
00068                 cluster[numAtoms].properties.position.x = start3.x+double(i)*latticeSize;
00069                 cluster[numAtoms].properties.position.y = start3.y+double(j)*latticeSize;
00070                 cluster[numAtoms].properties.position.z = start3.z+double(k)*latticeSize;
00071                 numAtoms++;
00072             }
00073     for (int i = 0; i < baseSize; i++)
00074         for (int j = 0; j < baseSize; j++)
00075             for (int k = 0; k < baseSize; k++)
00076             {
00077                 cluster[numAtoms].properties.position.x = start4.x+double(i)*latticeSize;
00078                 cluster[numAtoms].properties.position.y = start4.y+double(j)*latticeSize;
00079                 cluster[numAtoms].properties.position.z = start4.z+double(k)*latticeSize;
00080                 numAtoms++;
00081             }
00082     cluster.calculateCentreMass();
00083     cluster.setPositionCentreMass(Coordinate(0.0, 0.0, 0.0));
00084     adjustPosCenMass(cluster);
00085     cluster.calculateCentreMass();
00086 }
00087 
00088 void FCC_Lattice::adjustPosCenMass(Cluster& cluster) const
00089 {
00090     Coordinate centre;//The positions of the centre of mass.
00091 
00092     for (int i = 0; i < cluster.size(); i++)
00093         centre += cluster[i].properties.position;
00094     centre /= cluster.size();
00095     for (int i = 0; i < cluster.size(); i++)
00096         cluster[i].properties.position -= (centre + cluster.positionCentreMass());
00097 }

Generated on Tue Mar 28 23:28:03 2006 for ClusterSim by  doxygen 1.4.4