-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_diamond.cpp
More file actions
51 lines (45 loc) · 1.59 KB
/
gen_diamond.cpp
File metadata and controls
51 lines (45 loc) · 1.59 KB
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
#include <iostream>
#include <vector>
#include <array>
#include <omp.h> // OpenMP
struct Vec3 { double x,y,z; };
int main(int argc, char* argv[]) {
if (argc!=2) { std::cerr<<"Usage: "<<argv[0]<<" <N>\n"; return 1; }
int N = std::stoi(argv[1]);
double a = 1.0;
// FCC sites and two‐atom basis
std::vector<Vec3> fcc = {{0,0,0},{0,0.5,0.5},{0.5,0,0.5},{0.5,0.5,0}};
std::vector<Vec3> basis = {{0,0,0},{0.25,0.25,0.25}};
// precompute total points: N^3 * fcc.size() * basis.size()
size_t totalPts = size_t(N)*N*N * fcc.size() * basis.size();
std::vector<Vec3> pts(totalPts);
// parallel fill with a collapsed loop
#pragma omp parallel for collapse(3)
for(int i=0; i<N; ++i){
for(int j=0; j<N; ++j){
for(int k=0; k<N; ++k){
size_t cellIdx = (size_t(i)*N + j)*N + k;
size_t baseOffset = cellIdx * (fcc.size()*basis.size());
for(size_t fi=0; fi<fcc.size(); ++fi){
double fx0 = (i + fcc[fi].x)*a;
double fy0 = (j + fcc[fi].y)*a;
double fz0 = (k + fcc[fi].z)*a;
for(size_t bi=0; bi<basis.size(); ++bi){
auto &b = basis[bi];
Vec3 p { fx0 + b.x*a,
fy0 + b.y*a,
fz0 + b.z*a };
size_t idx = baseOffset + fi*basis.size() + bi;
pts[idx] = p;
}
}
}
}
}
// pass to TetGen
std::cout<<pts.size()<<" 3 0 0\n";
for(size_t i=0;i<pts.size();++i){
auto &p = pts[i];
std::cout<<(i+1)<<" "<<p.x<<" "<<p.y<<" "<<p.z<<"\n";
}
}