-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildgrids.cpp
133 lines (104 loc) · 3.74 KB
/
buildgrids.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
#include "dragoncello.h"
void DRAGONCELLO::buildXGrid() {
cout << "x in " << xmin / kpc << " ... " << xmax / kpc << " kpc" << endl;
deltax = (xmax - xmin)/(nx-1);
for (int ix=0; ix<nx; ix++) {
x_vec.push_back(xmin + ix * deltax);
}
ixsun = lower_bound(x_vec.begin(), x_vec.end(), x_Sun) - x_vec.begin();
for (int ix = 0; ix < nx; ++ix) {
if (ix < nx-1)
deltaxUp.push_back(x_vec[ix+1] - x_vec[ix]);
else
deltaxUp.push_back(x_vec[ix] - x_vec[ix-1]);
if (ix > 0)
deltaxDown.push_back(x_vec[ix] - x_vec[ix-1]);
else
deltaxDown.push_back(x_vec[1] - x_vec[0]);
deltaxCentral.push_back(0.5 * (deltaxDown.back() + deltaxUp.back()));
}
}
void DRAGONCELLO::buildYGrid() {
cout << "y in " << ymin / kpc << " ... " << ymax / kpc << " kpc" << endl;
if (ny > 1) {
cout << " !!! W A R N I N G !!! " << endl;
cout << " - - - - - - - - - - - - - - " << endl;
cout << " 3D version NOT AVAILABLE " << endl;
exit(0);
//deltay = (ymax - ymin) / (ny - 1);
//for (int iy=0; iy<ny; iy++)
// y_vec.push_back(ymin + iy*deltay);
}
else {
deltay = 0;
y_vec.push_back(0);
}
iysun = lower_bound(y_vec.begin(), y_vec.end(), y_Sun) - y_vec.begin();
for (int iy=0; iy<ny; ++iy) {
if (iy < ny-1)
deltayUp.push_back(y_vec[iy+1] - y_vec[iy]);
else
deltayUp.push_back(y_vec[iy] - y_vec[iy-1]);
if (iy > 0)
deltayDown.push_back(y_vec[iy] - y_vec[iy-1]);
else
deltayDown.push_back(y_vec[1] - y_vec[0]);
deltayCentral.push_back(0.5 * (deltayDown.back() + deltayUp.back()));
}
}
void DRAGONCELLO::buildZGrid() {
cout << "z in " << zmin / kpc << " ... " << zmax / kpc << " kpc" << endl;
deltaz = (zmax - zmin) / (nz - 1);
for (int iz=0; iz<nz; ++iz) {
z_vec.push_back(zmin + iz * deltaz);
//cout << z_vec[iz]/kpc << endl;
}
izsun = lower_bound(z_vec.begin(), z_vec.end(), z_Sun) - z_vec.begin();
for (int iz = 0; iz < nz; ++iz) {
if (iz < nz-1)
deltazUp.push_back(z_vec[iz+1] - z_vec[iz]);
else
deltazUp.push_back(z_vec[iz] - z_vec[iz-1]); //CHECK!!!
if (iz > 0)
deltazDown.push_back(z_vec[iz] - z_vec[iz-1]);
else
deltazDown.push_back(z_vec[1] - z_vec[0]); //CHECK!!!
deltazCentral.push_back(0.5 * (deltazDown.back() + deltazUp.back()));
}
}
void DRAGONCELLO::buildPGrid() {
cout << "p in " << pmin / GeV << " ... " << pmax / GeV << " GeV" << endl;
deltaLogp = exp(log(pmax / pmin) / (np - 1));
for (int ip = 0; ip < np; ip++) {
p_vec.push_back(exp(log(pmin) + ip * log(deltaLogp)));
cout << p_vec[ip]/GeV << endl;
}
ipLocal = lower_bound(p_vec.begin(), p_vec.end(), localFluxMomentum) - p_vec.begin();
}
void DRAGONCELLO::initEmptyGrids() {
int nelements = nx * ny * nz * np;
N.resize(nelements,0.);
N_previous.resize(nelements,0);
sourceTerm.resize(nelements,0);
b_r.resize(nx*ny*nz,0);
b_phi.resize(nx*ny*nz,0);
b_x.resize(nx*ny*nz,0);
b_y.resize(nx*ny*nz,0);
b_z.resize(nx*ny*nz,0);
Dpara.resize(nelements,0);
Dperp.resize(nelements,0);
D_rr.resize(nelements,0);
D_rz.resize(nelements,0);
D_xx.resize(nelements,0);
D_xz.resize(nelements,0);
D_zz.resize(nelements,0);
u_r.resize(nelements,0);
u_x.resize(nelements,0);
u_z.resize(nelements,0);
diffusionCoefficient.resize(nelements,0);
diffusionCoefficient_xx.resize(nelements,0);
diffusionCoefficient_zz.resize(nelements,0);
reaccelerationCoefficient.resize(nelements,0);
energyLossTerm.resize(nelements,0);
analyticalSolution.resize(nelements,0.);
}