-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathcs_create_crystal_structure2.cpp
195 lines (170 loc) · 6.62 KB
/
cs_create_crystal_structure2.cpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//-----------------------------------------------------------------------------
//
// Vampire - A code for atomistic simulation of magnetic materials
//
// Copyright (C) 2009-2012 R.F.L.Evans
//
// Email:[email protected]
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// ----------------------------------------------------------------------------
//
// Vampire Header files
#include "create.hpp"
#include "errors.hpp"
#include "material.hpp"
#include "vio.hpp"
#include "vmath.hpp"
#include "vmpi.hpp"
// Standard Libraries
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
// Internal create header
#include "internal.hpp"
namespace cs{
int create_crystal_structure(std::vector<cs::catom_t> & catom_array){
//----------------------------------------------------------
// check calling of routine if error checking is activated
//----------------------------------------------------------
if(err::check==true){std::cout << "cs::create_crystal_structure has been called" << std::endl;}
int min_bounds[3];
int max_bounds[3];
#ifdef MPICF
if(vmpi::mpi_mode==0){
min_bounds[0] = int(vmpi::min_dimensions[0]/unit_cell.dimensions[0]);
min_bounds[1] = int(vmpi::min_dimensions[1]/unit_cell.dimensions[1]);
min_bounds[2] = int(vmpi::min_dimensions[2]/unit_cell.dimensions[2]);
max_bounds[0] = vmath::iceil(vmpi::max_dimensions[0]/unit_cell.dimensions[0]);
max_bounds[1] = vmath::iceil(vmpi::max_dimensions[1]/unit_cell.dimensions[1]);
max_bounds[2] = vmath::iceil(vmpi::max_dimensions[2]/unit_cell.dimensions[2]);
}
else{
min_bounds[0]=0;
min_bounds[1]=0;
min_bounds[2]=0;
max_bounds[0]=cs::total_num_unit_cells[0];
max_bounds[1]=cs::total_num_unit_cells[1];
max_bounds[2]=cs::total_num_unit_cells[2];
}
#else
min_bounds[0]=0;
min_bounds[1]=0;
min_bounds[2]=0;
max_bounds[0]=cs::total_num_unit_cells[0];
max_bounds[1]=cs::total_num_unit_cells[1];
max_bounds[2]=cs::total_num_unit_cells[2];
#endif
cs::local_num_unit_cells[0]=max_bounds[0]-min_bounds[0];
cs::local_num_unit_cells[1]=max_bounds[1]-min_bounds[1];
cs::local_num_unit_cells[2]=max_bounds[2]-min_bounds[2];
int num_atoms=cs::local_num_unit_cells[0]*cs::local_num_unit_cells[1]*cs::local_num_unit_cells[2]*unit_cell.atom.size();
// set catom_array size
catom_array.reserve(num_atoms);
// Initialise atoms number
int atom=0;
// find maximum height lh_category
unsigned int maxlh=0;
for(unsigned int uca=0;uca<unit_cell.atom.size();uca++) if(unit_cell.atom[uca].hc > maxlh) maxlh = unit_cell.atom[uca].hc;
maxlh+=1;
// Duplicate unit cell
for(int z=min_bounds[2];z<max_bounds[2];z++){
for(int y=min_bounds[1];y<max_bounds[1];y++){
for(int x=min_bounds[0];x<max_bounds[0];x++){
// need to change this to accept non-orthogonal lattices
// Loop over atoms in unit cell
for(unsigned int uca=0;uca<unit_cell.atom.size();uca++){
double cx = (double(x)+unit_cell.atom[uca].x)*unit_cell.dimensions[0];
double cy = (double(y)+unit_cell.atom[uca].y)*unit_cell.dimensions[1];
double cz = (double(z)+unit_cell.atom[uca].z)*unit_cell.dimensions[2];
#ifdef MPICF
if(vmpi::mpi_mode==0){
// only generate atoms within allowed dimensions
if( (cx>=vmpi::min_dimensions[0] && cx<vmpi::max_dimensions[0]) &&
(cy>=vmpi::min_dimensions[1] && cy<vmpi::max_dimensions[1]) &&
(cz>=vmpi::min_dimensions[2] && cz<vmpi::max_dimensions[2])){
#endif
if((cx<cs::system_dimensions[0]) && (cy<cs::system_dimensions[1]) && (cz<cs::system_dimensions[2])){
catom_array.push_back(cs::catom_t());
catom_array[atom].x=cx;
catom_array[atom].y=cy;
catom_array[atom].z=cz;
//std::cout << atom << "\t" << cx << "\t" << cy <<"\t" << cz << std::endl;
catom_array[atom].material=unit_cell.atom[uca].mat;
catom_array[atom].uc_id=uca;
catom_array[atom].lh_category=unit_cell.atom[uca].hc+z*maxlh;
catom_array[atom].uc_category=unit_cell.atom[uca].mat; // determine initial material (uc_category) for unit cell
catom_array[atom].scx=x;
catom_array[atom].scy=y;
catom_array[atom].scz=z;
atom++;
}
#ifdef MPICF
}
}
else{
if((cx<cs::system_dimensions[0]) && (cy<cs::system_dimensions[1]) && (cz<cs::system_dimensions[2])){
catom_array.push_back(cs::catom_t());
catom_array[atom].x=cx;
catom_array[atom].y=cy;
catom_array[atom].z=cz;
catom_array[atom].material=unit_cell.atom[uca].mat;
catom_array[atom].uc_id=uca;
catom_array[atom].lh_category=unit_cell.atom[uca].hc+z*maxlh;
catom_array[atom].uc_category=unit_cell.atom[uca].mat; // determine initial material (uc_category) for unit cell
catom_array[atom].scx=x;
catom_array[atom].scy=y;
catom_array[atom].scz=z;
catom_array[atom].include=false; // assume no atoms until classification complete
atom++;
}
}
#endif
}
}
}
}
// Check to see if actual and expected number of atoms agree, if not trim the excess
if(atom!=num_atoms){
std::vector<cs::catom_t> tmp_catom_array(num_atoms);
tmp_catom_array=catom_array;
catom_array.resize(atom);
for(int a=0;a<atom;a++){
catom_array[a]=tmp_catom_array[a];
}
tmp_catom_array.resize(0);
}
// assign materials by layer
create::internal::layers(catom_array);
// Check to see if any atoms have been generated
if(atom==0){
terminaltextcolor(RED);
std::cout << "Error - no atoms have been generated, increase system dimensions!" << std::endl;
terminaltextcolor(WHITE);
zlog << zTs() << "Error: No atoms have been generated. Increase system dimensions." << std::endl;
err::vexit();
}
// Now unselect all atoms by default for particle shape cutting
for(unsigned int atom=0;atom<catom_array.size();atom++){
catom_array[atom].include=false;
}
return EXIT_SUCCESS;
}
} // end of namespace cs