1 | /** |
---|
2 | Computes the (magnetic) scattering form sld (n and m) profile |
---|
3 | */ |
---|
4 | #include <stdio.h> |
---|
5 | #include <math.h> |
---|
6 | #include "sld2i.h" |
---|
7 | #include "libfunc.h" |
---|
8 | #include "librefl.h" |
---|
9 | /** |
---|
10 | * Constructor for GenI |
---|
11 | * |
---|
12 | * binning |
---|
13 | * //@param qx: array of Qx values |
---|
14 | * //@param qy: array of Qy values |
---|
15 | * //@param qz: array of Qz values |
---|
16 | * @param x: array of x values |
---|
17 | * @param y: array of y values |
---|
18 | * @param z: array of z values |
---|
19 | * @param sldn: array of sld n |
---|
20 | * @param mx: array of sld mx |
---|
21 | * @param my: array of sld my |
---|
22 | * @param mz: array of sld mz |
---|
23 | * @param in_spin: ratio of up spin in Iin |
---|
24 | * @param out_spin: ratio of up spin in Iout |
---|
25 | * @param s_theta: angle (from x-axis) of the up spin in degree |
---|
26 | */ |
---|
27 | void initGenI(GenI* this, int is_avg, int npix, double* x, double* y, double* z, double* sldn, |
---|
28 | double* mx, double* my, double* mz, double* voli, |
---|
29 | double in_spin, double out_spin, |
---|
30 | double s_theta) { |
---|
31 | this->is_avg = is_avg; |
---|
32 | this->n_pix = npix; |
---|
33 | this->x_val = x; |
---|
34 | this->y_val = y; |
---|
35 | this->z_val = z; |
---|
36 | this->sldn_val = sldn; |
---|
37 | this->mx_val = mx; |
---|
38 | this->my_val = my; |
---|
39 | this->mz_val = mz; |
---|
40 | this->vol_pix = voli; |
---|
41 | this->inspin = in_spin; |
---|
42 | this->outspin = out_spin; |
---|
43 | this->stheta = s_theta; |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Compute 2D anisotropic |
---|
48 | */ |
---|
49 | void genicomXY(GenI* this, int npoints, double *qx, double *qy, double *I_out){ |
---|
50 | //npoints is given negative for angular averaging |
---|
51 | // Assumes that q doesn't have qz component and sld_n is all real |
---|
52 | //double q = 0.0; |
---|
53 | //double Pi = 4.0*atan(1.0); |
---|
54 | polar_sld b_sld; |
---|
55 | double qr = 0.0; |
---|
56 | complex iqr = cassign(0.0, 0.0); |
---|
57 | complex ephase = cassign(0.0, 0.0); |
---|
58 | complex comp_sld = cassign(0.0, 0.0); |
---|
59 | |
---|
60 | complex sumj_uu; |
---|
61 | complex sumj_ud; |
---|
62 | complex sumj_du; |
---|
63 | complex sumj_dd; |
---|
64 | complex temp_fi; |
---|
65 | |
---|
66 | double count = 0.0; |
---|
67 | int i, j; |
---|
68 | |
---|
69 | //Assume that pixel volumes are given in vol_pix in A^3 unit |
---|
70 | //int x_size = 0; //in Ang |
---|
71 | //int y_size = 0; //in Ang |
---|
72 | //int z_size = 0; //in Ang |
---|
73 | |
---|
74 | // Loop over q-values and multiply apply matrix |
---|
75 | |
---|
76 | //printf("npoints: %d, npix: %d\n", npoints, this->n_pix); |
---|
77 | for(i=0; i<npoints; i++){ |
---|
78 | //I_out[i] = 0.0; |
---|
79 | sumj_uu = cassign(0.0, 0.0); |
---|
80 | sumj_ud = cassign(0.0, 0.0); |
---|
81 | sumj_du = cassign(0.0, 0.0); |
---|
82 | sumj_dd = cassign(0.0, 0.0); |
---|
83 | //printf("i: %d\n", i); |
---|
84 | //q = sqrt(qx[i]*qx[i] + qy[i]*qy[i]); // + qz[i]*qz[i]); |
---|
85 | |
---|
86 | for(j=0; j<this->n_pix; j++){ |
---|
87 | //printf("j: %d\n", j); |
---|
88 | if (this->sldn_val[j]!=0.0 |
---|
89 | ||this->mx_val[j]!=0.0 |
---|
90 | ||this->my_val[j]!=0.0 |
---|
91 | ||this->mz_val[j]!=0.0) |
---|
92 | { |
---|
93 | //anisotropic |
---|
94 | temp_fi = cassign(0.0, 0.0); |
---|
95 | b_sld = cal_msld(0, qx[i], qy[i], this->sldn_val[j], |
---|
96 | this->mx_val[j], this->my_val[j], this->mz_val[j], |
---|
97 | this->inspin, this->outspin, this->stheta); |
---|
98 | qr = (qx[i]*this->x_val[j] + qy[i]*this->y_val[j]); |
---|
99 | iqr = cassign(0.0, qr); |
---|
100 | ephase = cplx_exp(iqr); |
---|
101 | |
---|
102 | //Let's multiply pixel(atomic) volume here |
---|
103 | ephase = rcmult(this->vol_pix[j], ephase); |
---|
104 | //up_up |
---|
105 | if (this->inspin > 0.0 && this->outspin > 0.0){ |
---|
106 | comp_sld = cassign(b_sld.uu, 0.0); |
---|
107 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
108 | sumj_uu = cplx_add(sumj_uu, temp_fi); |
---|
109 | } |
---|
110 | //down_down |
---|
111 | if (this->inspin < 1.0 && this->outspin < 1.0){ |
---|
112 | comp_sld = cassign(b_sld.dd, 0.0); |
---|
113 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
114 | sumj_dd = cplx_add(sumj_dd, temp_fi); |
---|
115 | } |
---|
116 | //up_down |
---|
117 | if (this->inspin > 0.0 && this->outspin < 1.0){ |
---|
118 | comp_sld = cassign(b_sld.re_ud, b_sld.im_ud); |
---|
119 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
120 | sumj_ud = cplx_add(sumj_ud, temp_fi); |
---|
121 | } |
---|
122 | //down_up |
---|
123 | if (this->inspin < 1.0 && this->outspin > 0.0){ |
---|
124 | comp_sld = cassign(b_sld.re_du, b_sld.im_du); |
---|
125 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
126 | sumj_du = cplx_add(sumj_du, temp_fi); |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | if (i == 0){ |
---|
131 | count += this->vol_pix[j]; |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | //printf("aa%d=%g %g %d\n", i, (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im), (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im), count); |
---|
136 | |
---|
137 | I_out[i] = (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im); |
---|
138 | I_out[i] += (sumj_ud.re*sumj_ud.re + sumj_ud.im*sumj_ud.im); |
---|
139 | I_out[i] += (sumj_du.re*sumj_du.re + sumj_du.im*sumj_du.im); |
---|
140 | I_out[i] += (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im); |
---|
141 | |
---|
142 | I_out[i] *= (1.0E+8 / count); //in cm (unit) / number; //to be multiplied by vol_pix |
---|
143 | } |
---|
144 | //printf("count = %d %g %g %g %g\n", count, this->sldn_val[0],this->mx_val[0], this->my_val[0], this->mz_val[0]); |
---|
145 | } |
---|
146 | /** |
---|
147 | * Compute 1D isotropic |
---|
148 | * Isotropic: Assumes all slds are real (no magnetic) |
---|
149 | * Also assumes there is no polarization: No dependency on spin |
---|
150 | */ |
---|
151 | void genicom(GenI* this, int npoints, double *q, double *I_out){ |
---|
152 | //npoints is given negative for angular averaging |
---|
153 | // Assumes that q doesn't have qz component and sld_n is all real |
---|
154 | //double Pi = 4.0*atan(1.0); |
---|
155 | double qr = 0.0; |
---|
156 | double sumj; |
---|
157 | double sld_j = 0.0; |
---|
158 | double count = 0.0; |
---|
159 | int i, j, k; |
---|
160 | |
---|
161 | //Assume that pixel volumes are given in vol_pix in A^3 unit |
---|
162 | // Loop over q-values and multiply apply matrix |
---|
163 | for(i=0; i<npoints; i++){ |
---|
164 | sumj =0.0; |
---|
165 | for(j=0; j<this->n_pix; j++){ |
---|
166 | //Isotropic: Assumes all slds are real (no magnetic) |
---|
167 | //Also assumes there is no polarization: No dependency on spin |
---|
168 | if (this->is_avg == 1){ |
---|
169 | // approximation for a spherical symmetric particle |
---|
170 | qr = sqrt(this->x_val[j]*this->x_val[j]+this->y_val[j]*this->y_val[j]+this->z_val[j]*this->z_val[j])*q[i]; |
---|
171 | if (qr > 0.0){ |
---|
172 | qr = sin(qr) / qr; |
---|
173 | sumj += this->sldn_val[j] * this->vol_pix[j] * qr; |
---|
174 | } |
---|
175 | else{ |
---|
176 | sumj += this->sldn_val[j] * this->vol_pix[j]; |
---|
177 | } |
---|
178 | } |
---|
179 | else{ |
---|
180 | //full calculation |
---|
181 | //pragma omp parallel for |
---|
182 | for(k=0; k<this->n_pix; k++){ |
---|
183 | sld_j = this->sldn_val[j] * this->sldn_val[k] * this->vol_pix[j] * this->vol_pix[k]; |
---|
184 | qr = (this->x_val[j]-this->x_val[k])*(this->x_val[j]-this->x_val[k])+ |
---|
185 | (this->y_val[j]-this->y_val[k])*(this->y_val[j]-this->y_val[k])+ |
---|
186 | (this->z_val[j]-this->z_val[k])*(this->z_val[j]-this->z_val[k]); |
---|
187 | qr = sqrt(qr) * q[i]; |
---|
188 | if (qr > 0.0){ |
---|
189 | sumj += sld_j*sin(qr)/qr; |
---|
190 | } |
---|
191 | else{ |
---|
192 | sumj += sld_j; |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | if (i == 0){ |
---|
197 | count += this->vol_pix[j]; |
---|
198 | } |
---|
199 | } |
---|
200 | I_out[i] = sumj; |
---|
201 | if (this->is_avg == 1) { |
---|
202 | I_out[i] *= sumj; |
---|
203 | } |
---|
204 | I_out[i] *= (1.0E+8 / count); //in cm (unit) / number; //to be multiplied by vol_pix |
---|
205 | } |
---|
206 | //printf("count = %d %g %g %g %g\n", count, sldn_val[0],mx_val[0], my_val[0], mz_val[0]); |
---|
207 | } |
---|