1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <fstream>
#include <string>
#include <vector>
//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;
vector<double> x0_values(columns), y0_values(rows), z0_values(layers),
x1_values(columns), y1_values(rows), z1_values(layers);
// print coordinates, layer by layer, columns by columns, row by row
for (int i=0; i<layers; i++){
z0+=a;
z1+=a;
z0_values.at(i)=z0;
z1_values.at(i)=z1;
x0=-a;
for (int j=0; j<columns; j++){
x0+=a;
x1=x0 + a/2;
x0_values.at(j)=x0;
x1_values.at(j)=x1;
y0=-a;
for (int k=0; k<rows; k++){
y0+=a;
y1=y0 + a/2;
y0_values.at(k)=y0;
y1_values.at(k)=y1;
fcc << x0_values.at(j) << "\t" << y0_values.at(k) << "\t" << z0_values.at(i) << endl;
fcc << x1_values.at(j) << "\t" << y1_values.at(k) << "\t" << z0_values.at(i) << endl;
fcc << x0_values.at(j) << "\t" << y1_values.at(k) << "\t" << z1_values.at(i) << endl;
fcc << x1_values.at(j) << "\t" << y0_values.at(k) << "\t" << z1_values.at(i) << endl;
}
}
}
fcc.close();
}
|