-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathold_pons_field_decay.cpp
More file actions
217 lines (162 loc) · 6.07 KB
/
old_pons_field_decay.cpp
File metadata and controls
217 lines (162 loc) · 6.07 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <cmath>
#include "stars.h"
#include <iostream>
#include <fstream>
using namespace std;
double min (double a, double b) {
if (a >= b)
return b;
else
return a;
}
//-----------------------------------------------------------------
double MFDOldPons::get_P (double t, double B, double i_incl, double P) {
double P_res, I, tmp, beta, k1, k2, k3, fractpart, intpart;
double h_yr, h_sec, sum, alpha, B_min, epart, tau_hall_part;
double B_0, diff_p, diff_p1, diff_p2, diff_p3, diff_p4;
double B_diff, diff_t, alpha1, beta1, diff_b, extra_diff_b;
double lin_approx_b;
int pos_b, pos_t, int_t;
pos_b = 1 + (int) (B / 2.0e11);
if (pos_b == 0)
pos_b = 1;
else if (pos_b > 74)
pos_b = 74;
pos_t = (int) t / 1000. - 1;
int_t = 0;
if (pos_t <= 0)
pos_t = 0;
else if (pos_t > 10000 - 6) {
int_t = pos_t - 10000;
pos_t = 10000 - 6;
}
// for ( int i=9000; i < 10000; i++)
// cout << pointer_b[76*i]<<endl;
diff_b = B - pointer_b[pos_b];
extra_diff_b = 0;
if (pos_b >= 74) {
extra_diff_b = B / 1.5e13;
diff_b = 0;
}
diff_t = t - pointer_b[76*pos_t];
if (pos_t > 10000 - 6)
diff_t = 0;
diff_p1 = pointer_delta[75 * pos_t + pos_b];
diff_p2 = pointer_delta[75 * pos_t + pos_b + 1];
diff_p3 = pointer_delta[75 * (pos_t + 1) + pos_b];
diff_p4 = pointer_delta[75 * (pos_t + 1) + pos_b + 1];
alpha1 = 1.0 - diff_b/2.0e11;
beta1 = 1.0 - diff_t/1000.0;
diff_p = beta1 * (alpha1 * diff_p1 + (1 - alpha1) * diff_p2 ) + (1-beta1) * (alpha1 * diff_p3 + (1 - alpha1) * diff_p4);
if (extra_diff_b == 0)
P_res = sqrt(P*P + diff_p + int_t*1000.0 * 3.2e7 * 1.6e-39 * pow(pointer_b[76*pos_t + pos_b], 2.0));
else
P_res = sqrt(P*P + diff_p*pow(extra_diff_b, 2.0));
// cout << "B is "<< B << ", but we used " << pointer_b[pos_b] <<" and pos_b is "<< pos_b<<endl;
// cout << "Now B is "<< pointer_b[76*pos_t + pos_b] << ", or f(t) = "<< pointer_b[76*pos_t + pos_b] / pointer_b[pos_b]<<endl;
// cout << "t is "<< t << ", but we used " << pointer_b[76*pos_t] << ", and pos_t is "<< pos_t<< " and int_t is "<< int_t << endl;
// cout << "diff_p is "<<diff_p<<" and P_res is "<< P_res <<endl;
// cout << "Additional contribution is "<< int_t*1000.0 * 3.2e7 * 1.6e-39 * pow(pointer_b[76*pos_t + pos_b], 2.0) << endl;
return P_res;
}
//-------------------------------------------------------------------
double MFDOldPons::get_incl (double t, double B, double i_incl, double P) {
return i_incl;
}
//-------------------------------------------------------------------
double MFDOldPons::get_dot_P (double t, double B, double i_incl, double P) {
double res, I, beta = 1.6e-39;
I=1e45;
res = beta * pow(get_B(t, B, i_incl, P), 2.0) / get_P (t, B, i_incl, P);
return res;
}
//-------------------------------------------------------------------
//------------------------------------------------------------------
double MFDOldPons::get_B (double t, double B, double i_incl, double P) {
double res_B, tau_hall_part, B_min, epart;
int pos_b, pos_t, int_t;
double diff_p1, diff_p2, diff_p3, diff_p4, extra_diff_b;
double diff_p, diff_t, alpha1, beta1, diff_b;
pos_b = 1 + (int) (B / 2.0e11);
if (pos_b == 0)
pos_b = 1;
else if (pos_b > 74)
pos_b = 74;
pos_t = (int) t / 1000. - 1;
if (pos_t <= 0)
pos_t = 0;
else if (pos_t > 10000 - 6) {
int_t = pos_t - 10000;
pos_t = 10000 - 6;
}
diff_b = B - pointer_b[pos_b];
extra_diff_b = 0;
if (pos_b >= 74) {
extra_diff_b = B/1.5e13;
diff_b = 0;
}
diff_t = t - pointer_b[76*pos_t];
//cout << diff_t<<endl;
if (diff_t > 1000)
diff_t = 0;
// cout << diff_t<<endl;
diff_p1 = pointer_b[76 * pos_t + pos_b];
diff_p2 = pointer_b[76 * pos_t + pos_b + 1];
diff_p3 = pointer_b[76 * (pos_t + 1) + pos_b];
diff_p4 = pointer_b[76 * (pos_t + 1) + pos_b + 1];
alpha1 = 1.0 - diff_b/2.0e11;
beta1 = 1.0 - diff_t/1000.0;
if (extra_diff_b == 0)
diff_p = beta1 * (alpha1 * diff_p1 + (1 - alpha1) * diff_p2 ) + (1-beta1) * (alpha1 * diff_p3 + (1 - alpha1) * diff_p4);
else
diff_p = extra_diff_b * (beta1 * diff_p1 + (1.0-beta1)*diff_p3);
res_B = diff_p;
// res_B = pointer_b[76*pos_t + pos_b];
return res_B;
}
//------------------------------------------------------------------
void MFDOldPons::print_description (ostream * out) {
*out<<"#// Model of magnetic field decay is the same as in article //"<<endl;
*out<<"#// by Chashkina & Popov (2012) with modification in a //"<<endl;
*out<<"#// that first - Hall decay and Coper pair decay, then //"<<endl;
*out<<"#// decay because of impurities in crust. //"<<endl;
*out<<"#//----------------------------------------------------------//"<<endl;
}
void MFDOldPons::print_parameters (ostream * out) {
*out<<"#// Parameters of magnetic field decay //"<<endl;
*out<<"#//----------------------------------------------------------//"<<endl;
*out<<"#// We read decay model from decay_curve.txt file //"<<endl;
*out<<"#//----------------------------------------------------------//"<<endl;
}
MFDOldPons::MFDOldPons (vector <double> * values) {
ifstream in ("decay_curve.txt");
//double data_per [10000][75];
//double data_b [10000][76];
double * data_b;
double * s;
s = new double [10000*75];
data_b = new double [10000*76];
for (int j = 0; j < 10000; j++) {
for (int i = 0; i < 76; i++) {
if (i==0)
in >> data_b [j*76];
else {
in >> data_b [j*76 + i];
in >> s [j*75 + i - 1];
}
}
}
//cout << data_b[0][0] << endl;
//cout << data_b[1][0] << endl;
//cout << data_b[2][0] << endl;
//cout << data_b[3][0] << endl;
//cout << s[0] << endl;
//cout << s[75] << endl;
//cout << s[2*75] << endl;
//cout << s[3*75] << endl;
//pointer_b = &data_b[0][0];
pointer_b = data_b;
//for ( int i = 7000; i < 10000; i++ )
// cout << pointer_b[76*i] << endl;
pointer_delta = s;
}