This repository was archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLatticeBuilder.cpp
More file actions
137 lines (115 loc) · 4.28 KB
/
Copy pathLatticeBuilder.cpp
File metadata and controls
137 lines (115 loc) · 4.28 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// LatticeBuilder.cpp: implementation of the LatticeBuilder class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LatticeRelaxation.h"
#include "LatticeBuilder.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LatticeBuilder::~LatticeBuilder()
{
}
bool LatticeBuilder::isAtomInCell(double _x, double _y, double _z, double x, double y, double z) {
x -= _x;
y -= _y;
z -= _z;
return ((x >= 0.0f && x <= 1.0f) && (y >= 0.0f && y <= 1.0f) && (z >= 0.0f && z <= 1.0f));
}
bool LatticeBuilder::isAtomRepresentable(double x, double y, double z) {
x += 0.5;
y += 0.5;
z += 0.5;
return (
isAtomInCell( 0.0f,0.0f, 0.0f,x,y,z) ||
isAtomInCell( 1.0f,0.0f, 0.0f,x,y,z) ||
isAtomInCell( 0.0f,1.0f, 0.0f,x,y,z) ||
isAtomInCell( 1.0f,1.0f, 0.0f,x,y,z) ||
isAtomInCell( 1.0f,0.0f,-1.0f,x,y,z) ||
isAtomInCell(-1.0f,0.0f, 1.0f,x,y,z) ||
isAtomInCell(-1.0f,1.0f, 1.0f,x,y,z) );
}
bool LatticeBuilder::isAtomMoveable(double x, double y, double z) {
return ((x >= -2.0f && x <= 2.0f) && (y >= -2.0f && y <= 2.0f) && (z >= -2.0f && z <= 2.0f));
}
Atom* LatticeBuilder::buildAtom(AtomType* atomType, double x, double y, double z) {
return new Atom(atomType,2.86 * Vector(x, y, z),isAtomRepresentable(x,y,z),isAtomMoveable(x,y,z));
}
Lattice* LatticeBuilder::buildBCCLattice(double moveableRadius, double totalRadius) {
Lattice* lattice = new Lattice();
lattice->a0 = 2.86;
AtomType* feAtomType = new AtomType("Fe", 92.76);
feAtomType->color = RGB(0x99,0x99,0x99);
double ceilTotalRadius = ceil(totalRadius);
for (float x = -ceilTotalRadius; x <= ceilTotalRadius; x += 1.0f) {
for (float y = -ceilTotalRadius; y <= ceilTotalRadius; y += 1.0f) {
for (float z = -ceilTotalRadius; z <= ceilTotalRadius; z += 1.0f) {
Vector coordinates(x,y,z);
double r = coordinates.getLength();
if (r > totalRadius) continue;
Atom* atom = new Atom(feAtomType, 2.86 * coordinates,isAtomRepresentable(x,y,z), r <= moveableRadius);
lattice->atoms.push_back(atom);
}
}
}
ceilTotalRadius -= 0.5;
for (x = -ceilTotalRadius; x <= ceilTotalRadius; x += 1.0f) {
for (float y = -ceilTotalRadius; y <= ceilTotalRadius; y += 1.0f) {
for (float z = -ceilTotalRadius; z <= ceilTotalRadius; z += 1.0f) {
Vector coordinates(x,y,z);
double r = coordinates.getLength();
if (r > totalRadius) continue;
Atom* atom = new Atom(feAtomType, 2.86 * coordinates,isAtomRepresentable(x,y,z), r <= moveableRadius);
lattice->atoms.push_back(atom);
}
}
}
/*
for (float x = -4.0f; x <= 4.0f; x += 1.0f) {
for (float y = -4.0f; y <= 4.0f; y += 1.0f) {
for (float z = -4.0f; z <= 4.0f; z += 1.0f) {
lattice->atoms.push_back(buildAtom(feAtomType,x,y,z));
}
}
}
for (x = -3.5f; x <= 3.5f; x += 1.0f) {
for (float y = -3.5f; y <= 3.5f; y += 1.0f) {
for (float z = -3.5f; z <= 3.5f; z += 1.0f) {
lattice->atoms.push_back(buildAtom(feAtomType,x,y,z));
}
}
}
*/
return lattice;
}
Lattice* LatticeBuilder::buildFCCLattice(double moveableRadius, double totalRadius)
{
Lattice* lattice = new Lattice();
lattice->a0 = 2.86;
AtomType* feAtomType = new AtomType("Fe", 92.76);
feAtomType->color = RGB(0x99,0x99,0x99);
for (float x = -totalRadius; x <= totalRadius; x += 0.5f) {
for (float y = -totalRadius; y <= totalRadius; y += 0.5f) {
for (float z = -totalRadius; z <= totalRadius; z += 0.5f) {
bool xInt = x == ceil(x);
bool yInt = y == ceil(y);
bool zInt = z == ceil(z);
if (xInt && yInt && zInt) continue;
if (xInt && !yInt && !zInt) continue;
if (!xInt && yInt && !zInt) continue;
if (!xInt && !yInt && zInt) continue;
Vector coordinates(x,y,z);
double r = coordinates.getLength();
if (r > totalRadius) continue;
Atom* atom = new Atom(feAtomType, 2.86 * coordinates,isAtomRepresentable(x,y,z), r <= moveableRadius);
lattice->atoms.push_back(atom);
}
}
}
return lattice;
}