-
Notifications
You must be signed in to change notification settings - Fork 0
/
binning.cpp
129 lines (97 loc) · 3.41 KB
/
binning.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
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include "loadconfig.h"
#include "constants.h"
#include "initializenl.h"
#include "neighcalculation.h"
#include "binning.h"
using namespace std;
void binning (neighborlist_type *neighlist, config_type *fromfile, potential *run_parameters, bin_type *bin)
{
int *temp_bin;
temp_bin = new int [Dim];//saves the bin number temporarily
double *bin_length;
bin_length = new double [Dim];//length of each bin
//deleting the old bin list
for (int i=0; i<bin->tot_bins[0]; i++)
{
for (int j=0; j<bin->tot_bins[1]; j++)
{
delete [] bin->bin_no[i][j];
}
delete [] bin->bin_no[i];
}
//identifying the number of bins, so that if there are multiple bins in the cell, they are sized such that only the nearest neighbor needs to scanned for neighborlist
for (int i=0; i<Dim; i++)
{
bin->tot_bins[i]= floor(fromfile->L[i]/(run_parameters->rc+run_parameters->rb));
if (bin->tot_bins[i]==0) {bin->tot_bins[i]=1;}
bin_length[i] = fromfile->L[i]/bin->tot_bins[i];
}
//allocating memory based on the number of bins in each dimension
bin->bin_no = new long **[bin->tot_bins[0]];
for (int i=0; i< bin->tot_bins[0]; i++)
{
bin->bin_no[i] = new long *[bin->tot_bins[1]];
for (int j=0; j<bin->tot_bins[1]; j++)
{
bin->bin_no[i][j] = new long [bin->tot_bins[2]];
for (int k=0; k<bin->tot_bins[2]; k++)
{
bin->bin_no[i][j][k]=-1;
}
}
}
//setting the bin next to default -1 value
for (long i=0; i<fromfile->N; i++)
{
bin->next[i] = -1;
}
//re-allocating the atoms to the primary cell
for (long i=0; i<fromfile->N; i++)
{
for (int j=0; j<Dim; j++)
{
double quotient;
quotient = floor(fromfile->r[i][j]/fromfile->L[j]);
fromfile->r[i][j] -= quotient*fromfile->L[j];
if (fromfile->r[i][j] > fromfile->L[j] || fromfile->r[i][j] < 0) {cout << fromfile->r[i][j] << " atoms not in primary cell" << endl; abort();}
}
}
//saving the binning configuration for future use in max displacement
for (long i=0; i<fromfile->N; i++)
{
for (int j=0; j<Dim; j++)
{
fromfile->xr[i][j]=fromfile->r[i][j];
}
}
//binning the atoms
for (long i=0; i<fromfile->N; i++)
{
for (int j=0; j<Dim; j++) // single atom taken
{
temp_bin[j]= floor(fromfile->r[i][j]/bin_length[j]);
if (temp_bin[j]>(bin->tot_bins[j]-1) || temp_bin[j]<0) {cout << "Check binnning" << endl; abort();}//to compensate for any truncation related errors
}
//adding it to the identified bin
if (bin->bin_no[temp_bin[0]][temp_bin[1]][temp_bin[2]] == -1)
{
bin->bin_no[temp_bin[0]][temp_bin[1]][temp_bin[2]]=i;
}
else
{
long j = bin->bin_no[temp_bin[0]][temp_bin[1]][temp_bin[2]];
while (bin->next[j] != -1)
{
j = bin->next[j];
}
bin->next[j]=i;
}
}
neighcalculation(neighlist,fromfile, run_parameters, bin);//sending for neighborlist calculation
}