-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLatticeVariables.cpp
More file actions
170 lines (137 loc) · 4.47 KB
/
Copy pathLatticeVariables.cpp
File metadata and controls
170 lines (137 loc) · 4.47 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
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
#include<LatticeVariables.h>
#include<Utils.h>
#include<KDTree.h>
#include<cmath> //isfinite
#include<cfloat>
#include<cassert>
using std::isfinite;
//---------------------------------------------------------------------
LatticeVariables::LatticeVariables() : lmin(0.0), lmax(0.0), size(0), lattice_id(-1)
{ }
//---------------------------------------------------------------------
LatticeVariables::~LatticeVariables()
{ }
//---------------------------------------------------------------------
void
LatticeVariables::Clear()
{
lmin = lmax = 0.0;
size = 0;
lattice_id = -1;
siteid.resize(0);
matid.resize(0);
l.resize(0);
q.resize(0);
q0.resize(0);
// p.resize(0);
sigma.resize(0);
tag.resize(0);
diffusive.resize(0);
species_id.resize(0);
x.resize(0);
gamma.resize(0);
}
//---------------------------------------------------------------------
void
LatticeVariables::FindBoundingBoxAndSize()
{
lmin = DBL_MAX;
lmax = -DBL_MAX;
for(auto&& l0 : l) {
for(int i=0; i<3; i++) {
if(l0[i]<lmin[i])
lmin[i] = l0[i];
if(l0[i]>lmax[i])
lmax[i] = l0[i];
}
}
size = l.size();
assert((int)siteid.size() == size);
assert((int)matid.size() == size);
assert((int)q.size() == size);
assert((int)q0.size() == size);
assert((int)sigma.size() == size);
assert((int)tag.size() == size);
assert((int)diffusive.size() == size);
assert((int)species_id.size() == size);
assert((int)x.size() == size);
assert((int)gamma.size() == size);
}
//---------------------------------------------------------------------
int
LatticeVariables::RemoveConflictingSites(std::vector<Vec3D> &q2, double dmin)
{
int nErased(0);
//------------------------------------
// Step 1: Storing q2 in a KDTree
//------------------------------------
std::vector<PointIn3D> q2_copy;
q2_copy.reserve(q2.size());
for(int i=0; i<(int)q2.size(); i++)
q2_copy.push_back(PointIn3D(i, q2[i]));
KDTree<PointIn3D,3> tree(q2_copy.size(), q2_copy.data());
//------------------------------------
// Step 2: Nearest-neighbor search
//------------------------------------
PointIn3D candidate;
int found;
std::vector<bool> stay(size, true);
assert(size==(int)q.size());
for(int i=0; i<size; i++) {
if(tree.findCandidatesWithin(q[i], &candidate, 1, dmin)>0) {
stay[i] = false;
nErased++;
}
}
if(nErased==0) //nothing to erase
return nErased;
size = size - nErased;
// reset the vectors
std::vector<int> siteid_2 = siteid; siteid.resize(size);
std::vector<int> matid_2 = matid; matid.resize(size);
std::vector<Vec3D> l_2 = l; l.resize(size);
std::vector<Vec3D> q_2 = q; q.resize(size);
std::vector<Vec3D> q0_2 = q0; q0.resize(size);
//std::vector<Vec3D> p_2 = p; p.resize(size);
std::vector<double> sigma_2 = sigma; sigma.resize(size);
std::vector<int> tag_2 = tag; tag.resize(size);
std::vector<std::vector<int> > diffusive_2 = diffusive; diffusive.resize(size);
std::vector<std::vector<int> > species_id_2 = species_id; species_id.resize(size);
std::vector<std::vector<double> > x_2 = x; x.resize(size);
std::vector<std::vector<double> > gamma_2 = gamma; gamma.resize(size);
int counter = 0;
for(int i=0; i<(int)stay.size(); i++) {
if(stay[i]) {
siteid[counter] = siteid_2[i];
matid[counter] = matid_2[i];
l[counter] = l_2[i];
q[counter] = q_2[i];
q0[counter] = q0_2[i];
// p[counter] = p_2[i];
sigma[counter] = sigma_2[i];
tag[counter] = tag_2[i];
diffusive[counter] = diffusive_2[i];
species_id[counter] = species_id_2[i];
x[counter] = x_2[i];
gamma[counter] = gamma_2[i];
counter++;
}
}
// sanity checks
assert(counter==size);
found = false;
for(auto&& xi : x) {
if((int)xi.size() == nSpecies_max) {
found = true;
break;
}
}
if(!found) {
print_error("*** Error: After removing overlapping sites on Lattice[%d], nSpecies_max has reduced.\n",
lattice_id);
exit_mpi();
}
FindBoundingBoxAndSize(); //update lmin, lmax
return nErased;
}
//---------------------------------------------------------------------