Setting up an FCC lattice in a simulation

Click For Summary
The discussion focuses on setting up an initial configuration for a Monte Carlo simulation of hard spheres using a face-centered cubic (fcc) lattice in C++. The user seeks an efficient method to generate the lattice structure, specifically the coordinates of the lattice sites. The proposed approach involves utilizing three lattice vectors to establish the first three nearest neighbors, followed by systematic combinations to derive the remaining neighbors. The user shares a C++ routine that writes the coordinates of fcc lattice sites to an output file, detailing the necessary initializations and nested loops for generating the coordinates layer by layer, column by column, and row by row. The code effectively calculates the positions based on the lattice constant and the specified number of rows, columns, and layers, ensuring a comprehensive output for the simulation setup.
SchroedingersLion
Messages
211
Reaction score
56
Greetings,

for a Monte Carlo simulation of N hard spheres, I want to set up the initial configuration as a fcc lattice. I am thinking about how to do it most efficiently.

Here is the lattice structure:
fcc-coordination-number-nearest-neighbours.svg


The 3 lattice vectors, each one pointing to a different type of the 12 nearest neighbors (see colors in picture), are given by
$$\vec a_{1}=\frac a 2 \begin{pmatrix} 0 \\ 1 \\ 1 \end{pmatrix},
\vec a_{2}=\frac a 2 \begin {pmatrix} 1 \\ 0 \\ 1 \end {pmatrix},
\vec a_{3}=\frac a 2 \begin {pmatrix} 1 \\ 1 \\ 0 \end {pmatrix}
$$

How would you do this most easily in C++?

My first idea was to simply set up the nearest neighbors. First, I use the three lattice vectors separately to set up the first 3 nearest neighbors. Then I combine two of them to get the other 9. Then I combine all 3 to get the next-nearest neighbors.

But what then? I have to repeat these steps with different pre-factors in the linear combinations, but I don't know how to do it systematically in a loop.Regards,
SL
 
Technology news on Phys.org
Ok, in case someone needs this as well, here is my routine:

Code:
#include <fstream>
#include <string>

//function that writes the coordinates of fcc lattice sites with given
//lattice constant, numbers of rows, columns and layers to an output file

using namespace std;

void generate_fcc(double a, int rows, int columns, int layers){

ofstream fcc("fcc_coordinates_a=" + to_string(a) + "_" +
             to_string(rows) + "rows_" + to_string(columns) + "columns_" + to_string(layers) + "layers.dat");

//necessary initializations to get coordinates of 1st particle after incrementations at beginning of loops
double x0=-a, y0=-a, z0=-a, x1, y1, z1=-a/2;

// print coordinates, layer by layer, columns by columns, row by row
for (int i=0; i<layers; i++){
        z0+=a;
        z1+=a;

        x0=-a;

        for (int j=0; j<columns; j++){
            x0+=a;
            x1=x0 + a/2;

            y0=-a;

            for (int k=0; k<rows; k++){
                y0+=a;
                y1=y0 + a/2;

                fcc << x0 << "\t" << y0 << "\t" << z0 << endl;
                fcc << x1 << "\t" << y1 << "\t" << z0 << endl;
                fcc << x0 << "\t" << y1 << "\t" << z1 << endl;
                fcc << x1 << "\t" << y0 << "\t" << z1 << endl;
            }
        }
}

fcc.close();
}
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 8 ·
Replies
8
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
2K
Replies
3
Views
3K