-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cpp
More file actions
151 lines (118 loc) · 3.74 KB
/
Functions.cpp
File metadata and controls
151 lines (118 loc) · 3.74 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
#include <vector>
#include <iostream>
#include <algorithm>
#include "Functions.h"
//*****
void v_zero_sort( std::vector<std::vector<double&>>& pot)
{
std::vector<std::vector<double&>> ad;
for (int i =0; i<= pot.size();++1)
ad[i] = {pot[0], pot[1], pot[2], pot[3]};
}
//*****Ôóíöčč äâčćĺíč˙********************************************************************
//Ýňŕ ôóíęöč˙ çŕäŕĺň ňî÷ęó ďđčńîĺäčíĺíč˙, ĺńëč ýíĺđăč˙ âçŕčěîäĺéńňâč˙ äîńňŕňî÷íŕ
size_t direction(Molecule mol, Field field)
{
std::vector<std::vector<double&>> pot;
//Sluchay, kogda chastitsa peremeshaetsa strogo po Oy
if (mol.dir[0] == 0)
{
//To, kuda budet dvigatsa chasstitsa
if (mol.dir[1] == 1) size_t y = y.mol + 1;
if (mol.dir[1] == -1) size_t y = y.mol - 1;
(pot[0][0], pot[0][1], pot[2], pot[0][3]) = (field[mol.x][mol.y][mol.z][1], mol.x, mol.y, mol.z);
for (size_t x = mol.x - 1; x <= mol.x + 1; ++x)
for (size_t z = mol.z - 1, size_t i = 1; z <= mol.z + 1; ++z, ++i )
{
if (field[x][y][z][0] == 1) continue; // ďđîńňĺéřĺě ńëó÷ŕĺ ńâîáîäíŕ˙ ÷ŕńňčöŕ íĺ ěîćĺň âűáčňü óćĺ çŕęđĺďë¸ííóţ
(pot[i][0], pot[i][1], pot[i][2], pot[i][3]) = (field[x][y][z][1], x, y, z);
}
}
//Sluchay, kogda chastitsa peremeshaetsa srtogo po Ox
if (mol.dir[0] != 0 && mol.dir[1] != 1)
{
if (mol.dir[1] == 1) size_t x = x.mol + 1;
if (mol.dir[1] == -1) size_t x = x.mol - 1;
(pot[0][0], pot[0][1], pot[2], pot[0][3]) = (field[mol.x][mol.y][mol.z][1], mol.x, mol.y, mol.z);
for (size_t y = mol.x; y <= mol.y + 1; ++y)
for (size_t z = mol.z - 1, size_t i = 1; z <= mol.z + 1; ++z, ++i )
{
if (field[x][y][z][0] == 1) continue; // ďđîńňĺéřĺě ńëó÷ŕĺ ńâîáîäíŕ˙ ÷ŕńňčöŕ íĺ ěîćĺň âűáčňü óćĺ çŕęđĺďë¸ííóţ
(pot[i][0], pot[i][1], pot[i][2], pot[i][3]) = (field[x][y][z][1], x, y, z);
}
}
//Sluchay, kogda chastitsa dvigaetsa po diagonali
else
{
return 0;
}
//Ńîđňčđîâęŕ (Äîďóńňčě, ÷ňî ďîńëĺ íĺ¸ âĺęňîđ áóäĺň îňńîđňčđîâŕí ďî ěĺđâűě ýëĺěĺíňŕě)
v_zero_sort(pot)
//Âűáîđ íŕďđŕâëĺíč˙
p_r = (rand() % 100) / 100;
//Ěŕńńčâ ń âĺđî˙ňíîńň˙ěč
double p[pot.size() + 1];
for (i = 0; i <= pot.size(); p[pot.size()] += pot[i], ++i);
for (i = 0; i<=pot.size();p[i] = pot[i] / p[pot.size()], ++i);
if( p_r >= p[0])
{
field[pot[1]][pot[2]][pot[3]][0] = 1;
return 1;
}
if( p_r <= p[p.size() - 1])
{
field[pot[1]][pot[2]][pot[3]][0] = 1;
return 1;
}
else
for (size_t j = 1; j <= p.size(); ++j)
if ( r< p[i] && p >= p[i+1])
{
field[pot[1]][pot[2]][pot[3]][0] = 1;
return 1;
}
}
//Eta funkciya otvechaet za peremeshenie chasticy
size_t movement(Molecule mol, Field field)
{
//Energiya, obladaya kotoroy chastitsa uzhe ne mozhet svobodno dvigatsa
double crit_energy;
//Proverka na vozmozhnost dvizheniya
if (mol.energy - mol.delta_en <= crit_energy)
{
direction(mol, field);
}
}
//*****Ôóíęöčč ęëŕńńŕ Field***************************************************************
Field::Field() { set_size(100, 100, 100); }
Field::Field(size_t len, size_t wid, size_t hei)
{
set_size(len, wid, hei);
}
void Field::set_size(size_t len, size_t wid, size_t hei)
{
size[0] = len; //x_size
size[1] = wid; //y_size
size[2] = hei; //z_size
}
size_t& Field::get_size_x()
{ return size[0]; }
size_t& Field::get_size_y()
{ return size[1]; }
size_t& Field::get_size_z()
{ return size[2]; }
std::vector<std::vector<std::vector<double>>>& Field::operator[](size_t i)
{
return zone[i];
}
//*****Ôóíęöčč ęëŕńńŕ Molecule***********************************************************
Molecule::Molecule(Field field)
{
x = rand() % field.size[0];
y = rand() % field.size[1];
z = 0;
}
void Molecule::En_loss()
{
energy -= delta_en;
}