-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphene_initialization.cpp
137 lines (120 loc) · 4.46 KB
/
graphene_initialization.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
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include "constants.h"
#include "graphene_initialization.h"
using namespace std;
void graphene_initialization(nucleation_type *nucleation, configuration_type *configuration, bin_type *bin, long N, double *L, long max_atoms, long bins_x, long bins_y, int distinct_layers, int procedure, bool construct)
{
//procedure = 1 - for initialization of nucleation_type
//procedure = 2 - for initialization of configuration_type and bin_type
if (procedure == 1)
{
if (construct == true)
{
for (long i=0; i<N; i++)
{
nucleation[i].xy = new double [Dim];
nucleation[i].xy[0] = -1;//not really required
nucleation[i].xy[1] = -1;//not really required
nucleation[i].angle = -1;
nucleation[i].neighbors = new long *[quadrants];
for (int j=0; j<quadrants; j++)
{
nucleation[i].neighbors[j] = new long [nucl_neigh_count];
for (int k=0; k<nucl_neigh_count; k++)
{
nucleation[i].neighbors[j][k] = -1;
}
}
}
}
if (construct == false)
{
for (long i=0; i<N; i++)
{
for (int j=0; j<quadrants; j++)
{
delete [] nucleation[i].neighbors[j];
}
delete [] nucleation[i].xy;
delete [] nucleation[i].neighbors;
}
delete [] nucleation;
}
}
if (procedure == 2)
{
if (construct == true)
{
//initializing bin
for (int i=0; i<distinct_layers; i++)//each layer has its own bin
{
bin[i].next = new long [max_atoms];
bin[i].tot_bins = new long [Dim];
bin[i].tot_bins[0] = bins_x;
bin[i].tot_bins[1] = bins_y;
bin[i].bin_length = new double [Dim];
bin[i].total_atoms = 0;
for (int j=0; j<max_atoms; j++)
{
bin[i].next[j] = -1;
}
for (int j=0; j<Dim; j++)
{
bin[i].bin_length[j] = L[j]/bin->tot_bins[j];
}
bin[i].bin_list = new long *[bins_x];
for (long j=0; j<bins_x; j++)
{
bin[i].bin_list[j] = new long [bins_y];
for (long k=0; k<bins_y; k++)
{
bin[i].bin_list[j][k] = -1;
}
}
}
//initializing configuration
for (long i=0; i<max_atoms*distinct_layers; i++)//there is only configuration construct, i.e. the next layers data is input after multiples of max_atoms
{
configuration[i].r = new double [Dim];
configuration[i].bonded_atom = new long [3];
configuration[i].bonded_angle = new double [3];
configuration[i].neigh_count = 0;
configuration[i].saturated = false;
configuration[i].grain = -1;//check whether -1 is required
configuration[i].mirror_no = -1;//indicates whether it has a mirror in the higher layer, changed to true when its mirror in the next atom is accepted
for (int j=0; j<3; j++)
{
configuration[i].bonded_atom[j] = -1;
configuration[i].bonded_angle[j] = -1;//check whether -1 is required
}
}
}
if (construct == false)
{
for (long i=0; i<max_atoms*distinct_layers; i++)
{
delete [] configuration[i].r;
delete [] configuration[i].bonded_atom;
delete [] configuration[i].bonded_angle;
}
delete [] configuration;
for (int i=0; i<distinct_layers; i++)
{
for (long j=0; j<bins_x; j++)
{
delete [] bin[i].bin_list[j];
}
delete [] bin[i].bin_list;
delete [] bin[i].tot_bins;
delete [] bin[i].next;
delete [] bin[i].bin_length;
}
delete [] bin;
}
}
}