forked from ITA-Solar/rh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paschen.c
213 lines (159 loc) · 5.47 KB
/
paschen.c
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
/* ------- file: -------------------------- paschen.c ---------------
Version: rh2.0
Author: Han Uitenbroek ([email protected])
Last modified: Wed Aug 5 09:57:21 2009 --
-------------------------- ----------RH-- */
/* --- Routines for implementing the incomplete Paschen-Back effect.
See: E. Landi Degl'Innocenti & M. Landolfi, 2004
"Polarization in Spectral Lines", Kluwer
Section 3.4
-- -------------- */
#include <stdlib.h>
#include <math.h>
#include "rh.h"
#include "atom.h"
#include "error.h"
#include "constant.h"
#define N_MAX_ITER_TQLI 30
#define SIGN(a, b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
/* --- Function prototypes -- -------------- */
double Pythag(double a, double b);
void tqli(double *d, double *e, int N, double **z);
void Paschen(double L, double S, double *E0, double B,
Paschenstruct *ps);
/* --- Global variables -- -------------- */
extern char messageStr[];
/* ------- begin -------------------------- Paschen_Back.c ---------- */
void Paschen_Back()
{
}
/* ------- end ---------------------------- Paschen_Back.c ---------- */
/* ------- begin -------------------------- Paschen.c --------------- */
void Paschen(double L, double S, double *E0, double B, Paschenstruct *ps)
{
register int M, j, jp;
int Mindex;
double Larmor, *ud, J, Jp, Jmin, Jmax, Ja, Jb;
/* --- See: E. Landi Degl'Innocenti & M. Landolfi, 2004
"Polarization in Spectral Lines", Kluwer
Eqs. 3.57 and 3.58
-- -------------- */
/* --- Larmor frequency in energy units (J) -- -------------- */
Larmor = (HPLANCK * Q_ELECTRON / (4.0 * PI *M_ELECTRON)) * B;
Jmin = fabs(L - S);
Jmax = L + S;
Mindex = 0;
for (M = -Jmax; M <=Jmax; M++) {
Ja = MAX(fabs(M), Jmin);
Jb = Jmax;
ps[Mindex].Nj = (int)(Jb - Ja) + 1;
ps[Mindex].eigenval = (double *) malloc(ps[Mindex].Nj * sizeof(double));
ps[Mindex].C = matrix_double(ps[Mindex].Nj, ps[Mindex].Nj);
ud = (double *) malloc(ps[Mindex].Nj * sizeof(double));
for (j = 0; j < ps[Mindex].Nj; j++) {
J = Ja + j;
ps[Mindex].eigenval[j] += E0[j] +
Larmor * (M + (((int) (2*J + L + S + M)) % 2 ? -1.0 : 1.0) *
(2.0*J + 1.0) * sqrt(S * (S + 1.0) * (2.0*S + 1.0)) *
w3js(J, J, 1.0, -M, M, 0.0) * w6js(J, J, 1.0, S, S, L));
}
if (ps[Mindex].Nj > 1) {
for (jp = 1; jp < ps[Mindex].Nj; jp++) {
Jp = Ja + jp;
J = Jp - 1.0;
ud[jp] = Larmor * (((int) (J + Jp + L + S + M)) % 2 ? -1.0 : 1.0) *
sqrt((2.0*J +1.0) * (2.0*Jp + 1.0) * S * (S + 1.0) * (2.0*S + 1.0)) *
w3js(J, Jp, 2.0, -M, M, 0.0) * w6js(J, Jp, 1.0, S, S, L);
}
}
for (j = 0; j < ps[Mindex].Nj; j++) ps[Mindex].C[j][j] = 1.0;
tqli(ps[Mindex].eigenval, ud, ps[Mindex].Nj, ps[Mindex].C);
free(ud);
Mindex++;
}
}
/* ------- end ---------------------------- Paschen.c --------------- */
/* ------- begin -------------------------- Pythag.c ---------------- */
double Pythag(double a, double b)
{
double absa, absb;
/* --- Returns sqrt(a^2 + b^2) without destructive
under- or overflow.
See: Press, Flannery, Teukolsky and Vetterling, 1992
Numerical Recipes in C,
The art of scientific computing, p. 70
-- -------------- */
absa = fabs(a);
absb = fabs(b);
if (absa > absb)
return absa * sqrt(1.0 + SQ(absb / absa));
else
return ((absb == 0.0) ? 0.0 : absb * sqrt(1.0 + SQ(absa / absb)));
}
/* ------- end ---------------------------- Pythag.c ---------------- */
/* ------- begin -------------------------- tqli.c ------------------ */
void tqli(double *d, double *e, int N, double **z)
{
const char routineName[] = "tqli";
register int m, l, iter, i, k;
double s, r, p, g, f, dd, c, b;
/* --- Tridiagonal QL implicit eigenvector decomposition (tqli.c).
See: Press, Flannery, Teukolsky and Vetterling, 1992
Numerical Recipes in C,
The art of scientific computing, p. 480
Note: Modified for proper C indexing starting at 0.
-- -------------- */
if (N == 1) return;
for (i = 1; i < N; i++) e[i - 1] = e[i];
e[N-1] = 0.0;
for (l = 0; l < N; l++) {
iter = 0;
do {
for (m = l; m < N - 1; m++) {
dd = fabs(d[m]) + fabs(d[m + 1]);
if ((double)(fabs(e[m]) + dd) == dd) break;
}
if (m != l) {
if (iter++ == N_MAX_ITER_TQLI) {
sprintf(messageStr,
" Too many iterations in tqli: %d\n", iter-1);
Error(ERROR_LEVEL_2, routineName, messageStr);
}
g = (d[l + 1] - d[l]) / (2.0 * e[l]);
r = Pythag(g, 1.0);
g = d[m] - d[l] + e[l] / (g + SIGN(r, g));
c = 1.0;
s = 1.0;
p = 0.0;
for (i = m-1; i >= l; i--) {
f = s * e[i];
b = c * e[i];
r = Pythag(f, g);
e[i + 1] = r;
if (r == 0.0) {
d[i + 1] -= p;
e[m] = 0.0;
break;
}
s = f / r;
c = g / r;
g = d[i + 1] - p;
r = (d[i] - g) * s + 2.0 * c * b;
p = s * r;
d[i + 1] = g + p;
g = c * r - b;
for (k = 0; k < N; k++) {
f = z[k][i + 1];
z[k][i + 1] = s * z[k][i] + c * f;
z[k][i] = c * z[k][i] - s * f;
}
}
if (r == 0.0 && i >= l) continue;
d[l] -= p;
e[l] = g;
e[m] = 0.0;
}
} while (m != l);
}
}
/* ------- end ---------------------------- tqli.c ------------------ */